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