ScrollbarThemeChromium.cpp [plain text]
#include "config.h"
#include "ScrollbarThemeChromium.h"
#include "PlatformBridge.h"
#include "PlatformMouseEvent.h"
#include "ScrollableArea.h"
#include "Scrollbar.h"
#include "ScrollbarThemeComposite.h"
namespace WebCore {
bool ScrollbarThemeChromium::hasThumb(Scrollbar* scrollbar)
{
return thumbLength(scrollbar) > 0;
}
IntRect ScrollbarThemeChromium::backButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
{
if (part == BackButtonEndPart)
return IntRect();
IntSize size = buttonSize(scrollbar);
return IntRect(scrollbar->x(), scrollbar->y(), size.width(), size.height());
}
IntRect ScrollbarThemeChromium::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart part, bool)
{
if (part == ForwardButtonStartPart)
return IntRect();
IntSize size = buttonSize(scrollbar);
int x, y;
if (scrollbar->orientation() == HorizontalScrollbar) {
x = scrollbar->x() + scrollbar->width() - size.width();
y = scrollbar->y();
} else {
x = scrollbar->x();
y = scrollbar->y() + scrollbar->height() - size.height();
}
return IntRect(x, y, size.width(), size.height());
}
IntRect ScrollbarThemeChromium::trackRect(Scrollbar* scrollbar, bool)
{
IntSize bs = buttonSize(scrollbar);
int thickness = scrollbarThickness(scrollbar->controlSize());
if (scrollbar->orientation() == HorizontalScrollbar) {
if (scrollbar->width() < 2 * thickness)
return IntRect();
return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->width() - 2 * bs.width(), thickness);
}
if (scrollbar->height() < 2 * thickness)
return IntRect();
return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height() - 2 * bs.height());
}
void ScrollbarThemeChromium::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
{
if (!hasThumb(scrollbar))
paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
}
void ScrollbarThemeChromium::paintTickmarks(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
{
if (scrollbar->orientation() != VerticalScrollbar)
return;
if (rect.height() <= 0 || rect.width() <= 0)
return;
Vector<IntRect> tickmarks;
scrollbar->scrollableArea()->getTickmarks(tickmarks);
if (!tickmarks.size())
return;
static RefPtr<Image> dash = Image::loadPlatformResource("tickmarkDash");
if (dash->isNull()) {
ASSERT_NOT_REACHED();
return;
}
context->save();
for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.end(); ++i) {
const float percent = static_cast<float>(i->y()) / scrollbar->totalSize();
const int yPos = rect.y() + (rect.height() * percent);
IntPoint tick(scrollbar->x(), yPos);
context->drawImage(dash.get(), ColorSpaceDeviceRGB, tick);
}
context->restore();
}
}