This source file includes following definitions.
- hasThumb
- backButtonRect
- forwardButtonRect
- trackRect
- paintTrackBackground
- paintTickmarks
#include "config.h"
#include "platform/scroll/ScrollbarThemeNonMacCommon.h"
#include "platform/PlatformMouseEvent.h"
#include "platform/graphics/GraphicsContextStateSaver.h"
#include "platform/scroll/ScrollableArea.h"
#include "platform/scroll/ScrollbarThemeClient.h"
namespace WebCore {
bool ScrollbarThemeNonMacCommon::hasThumb(ScrollbarThemeClient* scrollbar)
{
return thumbLength(scrollbar) > 0;
}
IntRect ScrollbarThemeNonMacCommon::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool)
{
if (part == BackButtonEndPart)
return IntRect();
IntSize size = buttonSize(scrollbar);
return IntRect(scrollbar->x(), scrollbar->y(), size.width(), size.height());
}
IntRect ScrollbarThemeNonMacCommon::forwardButtonRect(ScrollbarThemeClient* 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 ScrollbarThemeNonMacCommon::trackRect(ScrollbarThemeClient* scrollbar, bool)
{
IntSize bs = buttonSize(scrollbar);
int thickness = scrollbarThickness(scrollbar->controlSize());
if (scrollbar->orientation() == HorizontalScrollbar) {
if (scrollbar->width() <= 2 * bs.width() + 1)
return IntRect();
return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->width() - 2 * bs.width(), thickness);
}
if (scrollbar->height() <= 2 * bs.height() + 1)
return IntRect();
return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height() - 2 * bs.height());
}
void ScrollbarThemeNonMacCommon::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
{
if (!hasThumb(scrollbar))
paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
}
void ScrollbarThemeNonMacCommon::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
{
if (scrollbar->orientation() != VerticalScrollbar)
return;
if (rect.height() <= 0 || rect.width() <= 0)
return;
Vector<IntRect> tickmarks;
scrollbar->getTickmarks(tickmarks);
if (!tickmarks.size())
return;
GraphicsContextStateSaver stateSaver(*context);
context->setShouldAntialias(false);
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);
context->setFillColor(Color(0xCC, 0xAA, 0x00, 0xFF));
FloatRect tickRect(rect.x(), yPos, rect.width(), 3);
context->fillRect(tickRect);
context->setFillColor(Color(0xFF, 0xDD, 0x00, 0xFF));
FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1);
context->fillRect(tickStroke);
}
}
}