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 "core/rendering/RenderScrollbarTheme.h"
29 #include "core/paint/ScrollbarPainter.h"
30 #include "core/rendering/RenderScrollbar.h"
31 #include "platform/graphics/GraphicsContext.h"
32 #include "platform/scroll/ScrollbarThemeClient.h"
33 #include "wtf/StdLibExtras.h"
37 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme()
39 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ());
43 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(ScrollbarThemeClient* scrollbar, int& beforeSize, int& afterSize)
45 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart);
46 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart);
47 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart);
48 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart);
49 if (scrollbar->orientation() == HorizontalScrollbar) {
50 beforeSize = firstButton.width() + secondButton.width();
51 afterSize = thirdButton.width() + fourthButton.width();
53 beforeSize = firstButton.height() + secondButton.height();
54 afterSize = thirdButton.height() + fourthButton.height();
58 bool RenderScrollbarTheme::hasButtons(ScrollbarThemeClient* scrollbar)
62 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize);
63 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height());
66 bool RenderScrollbarTheme::hasThumb(ScrollbarThemeClient* scrollbar)
68 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0;
71 int RenderScrollbarTheme::minimumThumbLength(ScrollbarThemeClient* scrollbar)
73 return toRenderScrollbar(scrollbar)->minimumThumbLength();
76 IntRect RenderScrollbarTheme::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
78 return toRenderScrollbar(scrollbar)->buttonRect(partType);
81 IntRect RenderScrollbarTheme::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
83 return toRenderScrollbar(scrollbar)->buttonRect(partType);
86 IntRect RenderScrollbarTheme::trackRect(ScrollbarThemeClient* scrollbar, bool)
88 if (!hasButtons(scrollbar))
89 return scrollbar->frameRect();
93 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength);
95 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength);
98 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(ScrollbarThemeClient* scrollbar, const IntRect& rect)
100 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(BackTrackPart, rect);
101 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(ForwardTrackPart, rect);
102 IntRect result = rect;
103 if (scrollbar->orientation() == HorizontalScrollbar) {
104 result.setX(backRect.x());
105 result.setWidth(forwardRect.maxX() - backRect.x());
107 result.setY(backRect.y());
108 result.setHeight(forwardRect.maxY() - backRect.y());
113 void RenderScrollbarTheme::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
116 context->fillRect(cornerRect, Color::white);
119 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
121 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, ScrollbarBGPart, scrollbar->frameRect());
124 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
126 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, TrackBGPart, rect);
129 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
131 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, part, rect);
134 void RenderScrollbarTheme::paintButton(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
136 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, part, rect);
139 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
141 ScrollbarPainter(*toRenderScrollbar(scrollbar)).paintPart(context, ThumbPart, rect);
144 void RenderScrollbarTheme::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
146 ScrollbarTheme::theme()->paintTickmarks(context, scrollbar, rect);