ScrollbarThemeChromiumLinux.cpp [plain text]
#include "config.h"
#include "ScrollbarThemeChromiumLinux.h"
#include "PlatformBridge.h"
#include "PlatformMouseEvent.h"
#include "Scrollbar.h"
namespace WebCore {
ScrollbarTheme* ScrollbarTheme::nativeTheme()
{
static ScrollbarThemeChromiumLinux theme;
return &theme;
}
int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize)
{
IntSize scrollbarSize = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarVerticalTrack);
return scrollbarSize.width();
}
void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
{
PlatformBridge::ThemePaintState state = scrollbar->hoveredPart() == partType ? PlatformBridge::StateHover : PlatformBridge::StateNormal;
IntRect alignRect = trackRect(scrollbar, false);
PlatformBridge::ThemePaintExtraParams extraParams;
extraParams.scrollbarTrack.trackX = alignRect.x();
extraParams.scrollbarTrack.trackY = alignRect.y();
extraParams.scrollbarTrack.trackWidth = alignRect.width();
extraParams.scrollbarTrack.trackHeight = alignRect.height();
PlatformBridge::paintThemePart(
gc,
scrollbar->orientation() == HorizontalScrollbar ? PlatformBridge::PartScrollbarHorizontalTrack : PlatformBridge::PartScrollbarVerticalTrack,
state,
rect,
&extraParams);
}
void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
{
PlatformBridge::ThemePart paintPart;
PlatformBridge::ThemePaintState state = PlatformBridge::StateNormal;
bool checkMin = false;
bool checkMax = false;
if (scrollbar->orientation() == HorizontalScrollbar) {
if (part == BackButtonStartPart) {
paintPart = PlatformBridge::PartScrollbarLeftArrow;
checkMin = true;
} else {
paintPart = PlatformBridge::PartScrollbarRightArrow;
checkMax = true;
}
} else {
if (part == BackButtonStartPart) {
paintPart = PlatformBridge::PartScrollbarUpArrow;
checkMin = true;
} else {
paintPart = PlatformBridge::PartScrollbarDownArrow;
checkMax = true;
}
}
if ((checkMin && (scrollbar->currentPos() <= 0))
|| (checkMax && scrollbar->currentPos() == scrollbar->maximum())) {
state = PlatformBridge::StateDisabled;
} else {
if (part == scrollbar->pressedPart())
state = PlatformBridge::StatePressed;
else if (part == scrollbar->hoveredPart())
state = PlatformBridge::StateHover;
}
PlatformBridge::paintThemePart(gc, paintPart, state, rect, 0);
}
void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
{
PlatformBridge::ThemePaintState state;
if (scrollbar->pressedPart() == ThumbPart)
state = PlatformBridge::StatePressed;
else if (scrollbar->hoveredPart() == ThumbPart)
state = PlatformBridge::StateHover;
else
state = PlatformBridge::StateNormal;
PlatformBridge::paintThemePart(
gc,
scrollbar->orientation() == HorizontalScrollbar ? PlatformBridge::PartScrollbarHorizontalThumb : PlatformBridge::PartScrollbarVerticalThumb,
state,
rect,
0);
}
bool ScrollbarThemeChromiumLinux::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
{
return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == MiddleButton);
}
IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar)
{
if (scrollbar->orientation() == VerticalScrollbar) {
IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarUpArrow);
return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? scrollbar->height() / 2 : size.height());
}
IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarLeftArrow);
return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() / 2 : size.width(), size.height());
}
int ScrollbarThemeChromiumLinux::minimumThumbLength(Scrollbar* scrollbar)
{
if (scrollbar->orientation() == VerticalScrollbar) {
IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarVerticalThumb);
return size.height();
}
IntSize size = PlatformBridge::getThemePartSize(PlatformBridge::PartScrollbarHorizontalThumb);
return size.width();
}
}