• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 Apple Inc. All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
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.
12  *
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.
24  */
25 
26 #include "config.h"
27 #include "RenderScrollbarTheme.h"
28 #include "RenderScrollbar.h"
29 #include <wtf/StdLibExtras.h>
30 
31 namespace WebCore {
32 
renderScrollbarTheme()33 RenderScrollbarTheme* RenderScrollbarTheme::renderScrollbarTheme()
34 {
35     DEFINE_STATIC_LOCAL(RenderScrollbarTheme, theme, ());
36     return &theme;
37 }
38 
buttonSizesAlongTrackAxis(Scrollbar * scrollbar,int & beforeSize,int & afterSize)39 void RenderScrollbarTheme::buttonSizesAlongTrackAxis(Scrollbar* scrollbar, int& beforeSize, int& afterSize)
40 {
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();
48     } else {
49         beforeSize = firstButton.height() + secondButton.height();
50         afterSize = thirdButton.height() + fourthButton.height();
51     }
52 }
53 
hasButtons(Scrollbar * scrollbar)54 bool RenderScrollbarTheme::hasButtons(Scrollbar* scrollbar)
55 {
56     int startSize;
57     int endSize;
58     buttonSizesAlongTrackAxis(scrollbar, startSize, endSize);
59     return (startSize + endSize) <= (scrollbar->orientation() == HorizontalScrollbar ? scrollbar->width() : scrollbar->height());
60 }
61 
hasThumb(Scrollbar * scrollbar)62 bool RenderScrollbarTheme::hasThumb(Scrollbar* scrollbar)
63 {
64     return trackLength(scrollbar) - thumbLength(scrollbar) >= 0;
65 }
66 
minimumThumbLength(Scrollbar * scrollbar)67 int RenderScrollbarTheme::minimumThumbLength(Scrollbar* scrollbar)
68 {
69     return toRenderScrollbar(scrollbar)->minimumThumbLength();
70 }
71 
backButtonRect(Scrollbar * scrollbar,ScrollbarPart partType,bool)72 IntRect RenderScrollbarTheme::backButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool)
73 {
74     return toRenderScrollbar(scrollbar)->buttonRect(partType);
75 }
76 
forwardButtonRect(Scrollbar * scrollbar,ScrollbarPart partType,bool)77 IntRect RenderScrollbarTheme::forwardButtonRect(Scrollbar* scrollbar, ScrollbarPart partType, bool)
78 {
79     return toRenderScrollbar(scrollbar)->buttonRect(partType);
80 }
81 
trackRect(Scrollbar * scrollbar,bool)82 IntRect RenderScrollbarTheme::trackRect(Scrollbar* scrollbar, bool)
83 {
84     if (!hasButtons(scrollbar))
85         return scrollbar->frameRect();
86 
87     int startLength;
88     int endLength;
89     buttonSizesAlongTrackAxis(scrollbar, startLength, endLength);
90 
91     return toRenderScrollbar(scrollbar)->trackRect(startLength, endLength);
92 }
93 
constrainTrackRectToTrackPieces(Scrollbar * scrollbar,const IntRect & rect)94 IntRect RenderScrollbarTheme::constrainTrackRectToTrackPieces(Scrollbar* scrollbar, const IntRect& rect)
95 {
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.right() - backRect.x());
102     } else {
103         result.setY(backRect.y());
104         result.setHeight(forwardRect.bottom() - backRect.y());
105     }
106     return result;
107 }
108 
paintScrollCorner(ScrollView *,GraphicsContext * context,const IntRect & cornerRect)109 void RenderScrollbarTheme::paintScrollCorner(ScrollView*, GraphicsContext* context, const IntRect& cornerRect)
110 {
111     // FIXME: Implement.
112     context->fillRect(cornerRect, Color::white, DeviceColorSpace);
113 }
114 
paintScrollbarBackground(GraphicsContext * context,Scrollbar * scrollbar)115 void RenderScrollbarTheme::paintScrollbarBackground(GraphicsContext* context, Scrollbar* scrollbar)
116 {
117     toRenderScrollbar(scrollbar)->paintPart(context, ScrollbarBGPart, scrollbar->frameRect());
118 }
119 
paintTrackBackground(GraphicsContext * context,Scrollbar * scrollbar,const IntRect & rect)120 void RenderScrollbarTheme::paintTrackBackground(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
121 {
122     toRenderScrollbar(scrollbar)->paintPart(context, TrackBGPart, rect);
123 }
124 
paintTrackPiece(GraphicsContext * context,Scrollbar * scrollbar,const IntRect & rect,ScrollbarPart part)125 void RenderScrollbarTheme::paintTrackPiece(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
126 {
127     toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
128 }
129 
paintButton(GraphicsContext * context,Scrollbar * scrollbar,const IntRect & rect,ScrollbarPart part)130 void RenderScrollbarTheme::paintButton(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
131 {
132     toRenderScrollbar(scrollbar)->paintPart(context, part, rect);
133 }
134 
paintThumb(GraphicsContext * context,Scrollbar * scrollbar,const IntRect & rect)135 void RenderScrollbarTheme::paintThumb(GraphicsContext* context, Scrollbar* scrollbar, const IntRect& rect)
136 {
137     toRenderScrollbar(scrollbar)->paintPart(context, ThumbPart, rect);
138 }
139 
140 }
141