ScrollbarThemeChromium.cpp [plain text]
#include "config.h"
#include "ScrollbarThemeChromium.h"
#include "ChromiumBridge.h"
#include "PlatformMouseEvent.h"
#include "Scrollbar.h"
#include "ScrollbarClient.h"
#include "ScrollbarThemeComposite.h"
namespace WebCore {
ScrollbarTheme* ScrollbarTheme::nativeTheme()
{
static ScrollbarThemeChromium theme;
return &theme;
}
ScrollbarThemeChromium::ScrollbarThemeChromium()
{
}
ScrollbarThemeChromium::~ScrollbarThemeChromium()
{
}
void ScrollbarThemeChromium::themeChanged()
{
}
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();
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->client()->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.topLeft().y() + (rect.height() * percent);
IntPoint tick(scrollbar->x(), yPos);
context->drawImage(dash.get(), tick);
}
context->restore();
}
void ScrollbarThemeChromium::paintScrollCorner(ScrollView* view, GraphicsContext* context, const IntRect& cornerRect)
{
ScrollbarTheme::paintScrollCorner(view, context, cornerRect);
}
bool ScrollbarThemeChromium::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
{
return evt.shiftKey() && evt.button() == LeftButton;
}
IntSize ScrollbarThemeChromium::buttonSize(Scrollbar* scrollbar)
{
int thickness = scrollbarThickness();
#if !defined(__linux__)
const int kLayoutTestModeGirth = 17;
int girth = ChromiumBridge::layoutTestMode() ? kLayoutTestModeGirth : thickness;
#else
int girth = thickness;
#endif
if (scrollbar->orientation() == HorizontalScrollbar) {
int width = scrollbar->width() < 2 * girth ? scrollbar->width() / 2 : girth;
return IntSize(width, thickness);
}
int height = scrollbar->height() < 2 * girth ? scrollbar->height() / 2 : girth;
return IntSize(thickness, height);
}
}