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 <wtf/StdLibExtras.h>
33 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme()
35 DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ());
39 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(Scrollbar* scrollbar, int& beforeSize, int& afterSize)
41 IntRect firstButton = backButtonRect(scrollbar, BackButtonStartPart);
42 IntRect secondButton = forwardButtonRect(scrollbar, ForwardButtonStartPart);
43 IntRect thirdButton = backButtonRect(scrollbar, BackButtonEndPart);
44 IntRect fourthButton = forwardButtonRect(scrollbar, ForwardButtonEndPart);
45 if (scrollbar->orientation() == HorizontalScrollbar) {
46 beforeSize = firstButton.width() + secondButton.width();
47 afterSize = thirdButton.width() + fourthButton.width();
49 beforeSize = firstButton.height() + secondButton.height();
50 afterSize = thirdButton.height() + fourthButton.height();
54 bool RenderScrollbarTheme::hasButtons(Scrollbar* scrollbar)
58 buttonSizesAlongTrackAxis(scrollbar, startSize, endSize);
59 return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height());
62 bool RenderScrollbarTheme::hasThumb(Scrollbar* scrollbar)
64 return trackLength(scrollbar) - thumbLength(scrollbar) >= 0;
67 int RenderScrollbarTheme::minimumThumbLength(Scrollbar* scrollbar)
69 return toRenderScrollbar(scrollbar)->minimumThumbLength();
72 IntRect RenderScrollbarTheme::backButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool)
74 return toRenderScrollbar(scrollbar)->buttonRect(partType);
77 IntRect RenderScrollbarTheme::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool)
79 return toRenderScrollbar(scrollbar)->buttonRect(partType);
82 IntRect RenderScrollbarTheme::trackRect(Scrollbar* scrollbar, bool)
84 if (!hasButtons(scrollbar))
85 return scrollbar->frameRect();
89 buttonSizesAlongTrackAxis(scrollbar, startLength, endLength);
91 return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength);
94 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(Scrollbar* scrollbar, const IntRect& rect)
96 IntRect backRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(BackTrackPart, rect);
97 IntRect forwardRect = toRenderScrollbar(scrollbar)->trackPieceRectWithMargins(ForwardTrackPart, rect);
98 IntRect result = rect;
99 if (scrollbar->orientation() == HorizontalScrollbar) {
100 result.setX(backRect.x());
101 result.setWidth(forwardRect.maxX() - backRect.x());
103 result.setY(backRect.y());
104 result.setHeight(forwardRect.maxY() - backRect.y());
109 void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect)
112 context->fillRect(cornerRect, Color::white, ColorSpaceDeviceRGB);
115 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
117 toRenderScrollbar(scrollbar)->paintPart(context, ScrollbarBGPart, scrollbar->frameRect());
120 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
122 toRenderScrollbar(scrollbar)->paintPart(context, TrackBGPart, rect);
125 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
127 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
130 void RenderScrollbarTheme::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
132 toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
135 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
137 toRenderScrollbar(scrollbar)->paintPart(context, ThumbPart, rect);