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/RenderScrollbar.h"
28 #include "core/rendering/RenderScrollbarTheme.h"
29 #include "platform/graphics/GraphicsContext.h"
30 #include "platform/scroll/ScrollbarThemeClient.h"
31 #include "wtf/StdLibExtras.h"
35 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme()
37 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ());
41 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(ScrollbarThemeClient* scrollbar, int& beforeSize, int& afterSize)
43 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart);
44 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart);
45 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart);
46 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart);
47 if (scrollbar->orientation() == HorizontalScrollbar) {
48 beforeSize = firstButton.width() + secondButton.width();
49 afterSize = thirdButton.width() + fourthButton.width();
51 beforeSize = firstButton.height() + secondButton.height();
52 afterSize = thirdButton.height() + fourthButton.height();
56 bool RenderScrollbarTheme::hasButtons(ScrollbarThemeClient* scrollbar)
60 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize);
61 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height());
64 bool RenderScrollbarTheme::hasThumb(ScrollbarThemeClient* scrollbar)
66 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0;
69 int RenderScrollbarTheme::minimumThumbLength(ScrollbarThemeClient* scrollbar)
71 return toRenderScrollbar(scrollbar)->minimumThumbLength();
74 IntRect RenderScrollbarTheme::backButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
76 return toRenderScrollbar(scrollbar)->buttonRect(partType);
79 IntRect RenderScrollbarTheme::forwardButtonRect(ScrollbarThemeClient* scrollbar, ScrollbarPart partType, bool)
81 return toRenderScrollbar(scrollbar)->buttonRect(partType);
84 IntRect RenderScrollbarTheme::trackRect(ScrollbarThemeClient* scrollbar, bool)
86 if (!hasButtons(scrollbar))
87 return scrollbar->frameRect();
91 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength);
93 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength);
96 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(ScrollbarThemeClient* scrollbar, const IntRect& rect)
98 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(BackTrackPart, rect);
99 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(ForwardTrackPart, rect);
100 IntRect result = rect;
101 if (scrollbar->orientation() == HorizontalScrollbar) {
102 result.setX(backRect.x());
103 result.setWidth(forwardRect.maxX() - backRect.x());
105 result.setY(backRect.y());
106 result.setHeight(forwardRect.maxY() - backRect.y());
111 void RenderScrollbarTheme::paintScrollCorner(GraphicsContext* context, const IntRect& cornerRect)
114 context->fillRect(cornerRect, Color::white);
117 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar)
119 toRenderScrollbar(scrollbar)->paintPart(context, ScrollbarBGPart, scrollbar->frameRect());
122 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
124 toRenderScrollbar(scrollbar)->paintPart(context, TrackBGPart, rect);
127 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
129 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
132 void RenderScrollbarTheme::paintButton(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
134 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
137 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
139 toRenderScrollbar(scrollbar)->paintPart(context, ThumbPart, rect);
142 void RenderScrollbarTheme::paintTickmarks(GraphicsContext* context, ScrollbarThemeClient* scrollbar, const IntRect& rect)
144 ScrollbarTheme::theme()->paintTickmarks(context, scrollbar, rect);