2
* Copyright (C) 2008 Apple Inc. All Rights Reserved.
3
* Copyright (C) 2008, 2009 Google Inc.
5
* Redistribution and use in source and binary forms, with or without
6
* modification, are permitted provided that the following conditions
8
* 1. Redistributions of source code must retain the above copyright
9
* notice, this list of conditions and the following disclaimer.
10
* 2. Redistributions in binary form must reproduce the above copyright
11
* notice, this list of conditions and the following disclaimer in the
12
* documentation and/or other materials provided with the distribution.
14
* THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
15
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
18
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
#include "ScrollbarThemeChromium.h"
30
#include "PlatformMouseEvent.h"
31
#include "ScrollableArea.h"
32
#include "Scrollbar.h"
33
#include "ScrollbarThemeComposite.h"
35
// -----------------------------------------------------------------------------
36
// This file contains scrollbar theme code that is cross platform. Additional
37
// members of ScrollbarThemeChromium can be found in the platform specific files
38
// -----------------------------------------------------------------------------
42
bool ScrollbarThemeChromium::hasThumb(ScrollbarThemeClient* scrollbar)
44
// This method is just called as a paint-time optimization to see if
45
// painting the thumb can be skipped. We don't have to be exact here.
46
return thumbLength(scrollbar) > 0;
49
IntRect ScrollbarThemeChromium::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool)
51
// Windows and Linux just have single arrows.
52
if (part == BackButtonEndPart)
55
IntSize size = buttonSize(scrollbar);
56
return IntRect(scrollbar->x(), scrollbar->y(), size.width(), size.height());
59
IntRect ScrollbarThemeChromium::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart part, bool)
61
// Windows and Linux just have single arrows.
62
if (part == ForwardButtonStartPart)
65
IntSize size = buttonSize(scrollbar);
67
if (scrollbar->orientation() == HorizontalScrollbar) {
68
x = scrollbar->x() + scrollbar->width() - size.width();
72
y = scrollbar->y() + scrollbar->height() - size.height();
74
return IntRect(x, y, size.width(), size.height());
77
IntRect ScrollbarThemeChromium::trackRect(ScrollbarThemeClient* scrollbar, bool)
79
IntSize bs = buttonSize(scrollbar);
80
// The buttons at the top and bottom of the scrollbar are square, so the
81
// thickness of the scrollbar is also their height.
82
int thickness = scrollbarThickness(scrollbar->controlSize());
83
if (scrollbar->orientation() == HorizontalScrollbar) {
84
// Once the scrollbar becomes smaller than the natural size of the
85
// two buttons, the track disappears.
86
if (scrollbar->width() < 2 * thickness)
88
return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->width() - 2 * bs.width(), thickness);
90
if (scrollbar->height() < 2 * thickness)
92
return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height() - 2 * bs.height());
95
void ScrollbarThemeChromium::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
97
// Just assume a forward track part. We only paint the track as a single piece when there is no thumb.
98
if (!hasThumb(scrollbar))
99
paintTrackPiece(context, scrollbar, rect, ForwardTrackPart);
102
void ScrollbarThemeChromium::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
104
if (scrollbar->orientation() != VerticalScrollbar)
107
if (rect.height() <= 0 || rect.width() <= 0)
108
return; // nothing to draw on.
110
// Get the tickmarks for the frameview.
111
Vector<IntRect> tickmarks;
112
scrollbar->getTickmarks(tickmarks);
113
if (!tickmarks.size())
116
GraphicsContextStateSaver stateSaver(*context);
117
context->setShouldAntialias(false);
119
for (Vector<IntRect>::const_iterator i = tickmarks.begin(); i != tickmarks.end(); ++i) {
120
// Calculate how far down (in %) the tick-mark should appear.
121
const float percent = static_cast<float>(i->y()) / scrollbar->totalSize();
123
// Calculate how far down (in pixels) the tick-mark should appear.
124
const int yPos = rect.y() + (rect.height() * percent);
126
context->setFillColor(Color(0xCC, 0xAA, 0x00, 0xFF), ColorSpaceDeviceRGB);
127
FloatRect tickRect(rect.x(), yPos, rect.width(), 3);
128
context->fillRect(tickRect);
130
context->setFillColor(Color(0xFF, 0xDD, 0x00, 0xFF), ColorSpaceDeviceRGB);
131
FloatRect tickStroke(rect.x(), yPos + 1, rect.width(), 1);
132
context->fillRect(tickStroke);
136
} // namespace WebCore