2 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "RenderScrollbarTheme.h"
28 #include "RenderScrollbar.h"
29 #include "ScrollbarThemeClient.h"
30 #include <wtf/StdLibExtras.h>
34 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme()
36 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ());
40 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(ScrollbarThemeClient* scrollbar, int& beforeSize, int& afterSize)
42 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart);
43 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart);
44 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart);
45 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart);
46 if (scrollbar->orientation() == HorizontalScrollbar) {
47 beforeSize = firstButton.width() + secondButton.width();
48 afterSize = thirdButton.width() + fourthButton.width();
50 beforeSize = firstButton.height() + secondButton.height();
51 afterSize = thirdButton.height() + fourthButton.height();
55 bool RenderScrollbarTheme::hasButtons(ScrollbarThemeClient* scrollbar)
59 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize);
60 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height());
63 bool RenderScrollbarTheme::hasThumb(ScrollbarThemeClient* scrollbar)
65 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0;
68 int RenderScrollbarTheme::minimumThumbLength(ScrollbarThemeClient* scrollbar)
70 return toRenderScrollbar(scrollbar)->minimumThumbLength();
73 IntRect RenderScrollbarTheme::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
75 return toRenderScrollbar(scrollbar)->buttonRect(partType);
78 IntRect RenderScrollbarTheme::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
80 return toRenderScrollbar(scrollbar)->buttonRect(partType);
83 IntRect RenderScrollbarTheme::trackRect(ScrollbarThemeClient* scrollbar, bool)
85 if (!hasButtons(scrollbar))
86 return scrollbar->frameRect();
90 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength);
92 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength);
95 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(ScrollbarThemeClient* scrollbar, const IntRect& rect)
97 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(BackTrackPart, rect);
98 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(ForwardTrackPart, rect);
99 IntRect result = rect;
100 if (scrollbar->orientation() == HorizontalScrollbar) {
101 result.setX(backRect.x());
102 result.setWidth(forwardRect.maxX() - backRect.x());
104 result.setY(backRect.y());
105 result.setHeight(forwardRect.maxY() - backRect.y());
110 void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect)
113 context->fillRect(cornerRect, Color::white, ColorSpaceDeviceRGB);
116 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
118 toRenderScrollbar(scrollbar)->paintPart(context, ScrollbarBGPart, scrollbar->frameRect());
121 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
123 toRenderScrollbar(scrollbar)->paintPart(context, TrackBGPart, rect);
126 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
128 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
131 void RenderScrollbarTheme::paintButton(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
133 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
136 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
138 toRenderScrollbar(scrollbar)->paintPart(context, ThumbPart, rect);
141 void RenderScrollbarTheme::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
143 ScrollbarTheme::theme()->paintTickmarks(context, scrollbar, rect);