• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2008, 2009, Google 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 are
6  * met:
7  *
8  *     * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *     * Redistributions in binary form must reproduce the above
11  * copyright notice, this list of conditions and the following disclaimer
12  * in the documentation and/or other materials provided with the
13  * distribution.
14  *     * Neither the name of Google Inc. nor the names of its
15  * contributors may be used to endorse or promote products derived from
16  * this software without specific prior written permission.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  */
30 
31 #include "config.h"
32 #include "ScrollbarThemeChromiumLinux.h"
33 
34 #include "PlatformContextSkia.h"
35 #include "PlatformMouseEvent.h"
36 #include "Scrollbar.h"
37 #include "TransformationMatrix.h"
38 
39 namespace WebCore {
40 
nativeTheme()41 ScrollbarTheme* ScrollbarTheme::nativeTheme()
42 {
43     static ScrollbarThemeChromiumLinux theme;
44     return &theme;
45 }
46 
scrollbarThickness(ScrollbarControlSize controlSize)47 int ScrollbarThemeChromiumLinux::scrollbarThickness(ScrollbarControlSize controlSize)
48 {
49     return 15;
50 }
51 
drawVertLine(SkCanvas * canvas,int x,int y1,int y2,const SkPaint & paint)52 static void drawVertLine(SkCanvas* canvas, int x, int y1, int y2, const SkPaint& paint)
53 {
54     SkIRect skrect;
55     skrect.set(x, y1, x + 1, y2 + 1);
56     canvas->drawIRect(skrect, paint);
57 }
58 
drawHorizLine(SkCanvas * canvas,int x1,int x2,int y,const SkPaint & paint)59 static void drawHorizLine(SkCanvas* canvas, int x1, int x2, int y, const SkPaint& paint)
60 {
61     SkIRect skrect;
62     skrect.set(x1, y, x2 + 1, y + 1);
63     canvas->drawIRect(skrect, paint);
64 }
65 
drawBox(SkCanvas * canvas,const IntRect & rect,const SkPaint & paint)66 static void drawBox(SkCanvas* canvas, const IntRect& rect, const SkPaint& paint)
67 {
68     const int right = rect.x() + rect.width() - 1;
69     const int bottom = rect.y() + rect.height() - 1;
70     drawHorizLine(canvas, rect.x(), right, rect.y(), paint);
71     drawVertLine(canvas, right, rect.y(), bottom, paint);
72     drawHorizLine(canvas, rect.x(), right, bottom, paint);
73     drawVertLine(canvas, rect.x(), rect.y(), bottom, paint);
74 }
75 
trackRect(Scrollbar * scrollbar,bool)76 IntRect ScrollbarThemeChromium::trackRect(Scrollbar* scrollbar, bool)
77 {
78     IntSize bs = buttonSize(scrollbar);
79     int thickness = scrollbarThickness(scrollbar->controlSize());
80     if (scrollbar->orientation() == HorizontalScrollbar)
81         return IntRect(scrollbar->x() + bs.width(), scrollbar->y(), scrollbar->width(), thickness);
82     return IntRect(scrollbar->x(), scrollbar->y() + bs.height(), thickness, scrollbar->height());
83 }
84 
paintTrackPiece(GraphicsContext * gc,Scrollbar * scrollbar,const IntRect & rect,ScrollbarPart partType)85 void ScrollbarThemeChromiumLinux::paintTrackPiece(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart partType)
86 {
87     SkCanvas* const canvas = gc->platformContext()->canvas();
88     SkPaint paint;
89     SkIRect skrect;
90 
91     skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
92     paint.setARGB(0xff, 0xe3, 0xdd, 0xd8);
93     canvas->drawIRect(skrect, paint);
94 
95     paint.setARGB(0xff, 0xc5, 0xba, 0xb0);
96     drawBox(canvas, rect, paint);
97 }
98 
paintButton(GraphicsContext * gc,Scrollbar * scrollbar,const IntRect & rect,ScrollbarPart part)99 void ScrollbarThemeChromiumLinux::paintButton(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect, ScrollbarPart part)
100 {
101     // We don't use buttons
102 }
103 
paintThumb(GraphicsContext * gc,Scrollbar * scrollbar,const IntRect & rect)104 void ScrollbarThemeChromiumLinux::paintThumb(GraphicsContext* gc, Scrollbar* scrollbar, const IntRect& rect)
105 {
106     const bool hovered = scrollbar->hoveredPart() == ThumbPart;
107     const int midx = rect.x() + rect.width() / 2;
108     const int midy = rect.y() + rect.height() / 2;
109     const bool vertical = scrollbar->orientation() == VerticalScrollbar;
110     SkCanvas* const canvas = gc->platformContext()->canvas();
111 
112     SkPaint paint;
113     if (hovered)
114         paint.setARGB(0xff, 0xff, 0xff, 0xff);
115     else
116         paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
117 
118     SkIRect skrect;
119     if (vertical)
120         skrect.set(rect.x(), rect.y(), midx + 1, rect.y() + rect.height());
121     else
122         skrect.set(rect.x(), rect.y(), rect.x() + rect.width(), midy + 1);
123 
124     canvas->drawIRect(skrect, paint);
125 
126     if (hovered)
127         paint.setARGB(0xff, 0xf4, 0xf2, 0xef);
128     else
129         paint.setARGB(0xff, 0xea, 0xe5, 0xe0);
130 
131     if (vertical)
132         skrect.set(midx + 1, rect.y(), rect.x() + rect.width(), rect.y() + rect.height());
133     else
134         skrect.set(rect.x(), midy + 1, rect.x() + rect.width(), rect.y() + rect.height());
135 
136     canvas->drawIRect(skrect, paint);
137 
138     paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
139     drawBox(canvas, rect, paint);
140 
141     if (rect.height() > 10 && rect.width() > 10) {
142         paint.setARGB(0xff, 0x9d, 0x96, 0x8e);
143         drawHorizLine(canvas, midx - 1, midx + 3, midy, paint);
144         drawHorizLine(canvas, midx - 1, midx + 3, midy - 3, paint);
145         drawHorizLine(canvas, midx - 1, midx + 3, midy + 3, paint);
146     }
147 }
148 
shouldCenterOnThumb(Scrollbar *,const PlatformMouseEvent & evt)149 bool ScrollbarThemeChromiumLinux::shouldCenterOnThumb(Scrollbar*, const PlatformMouseEvent& evt)
150 {
151     return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == MiddleButton);
152 }
153 
buttonSize(Scrollbar * scrollbar)154 IntSize ScrollbarThemeChromiumLinux::buttonSize(Scrollbar* scrollbar)
155 {
156     // On Linux, we don't use buttons
157     return IntSize(0, 0);
158 }
159 
minimumThumbLength(Scrollbar * scrollbar)160 int ScrollbarThemeChromiumLinux::minimumThumbLength(Scrollbar* scrollbar)
161 {
162     // This matches Firefox on Linux.
163     return 2 * scrollbarThickness(scrollbar->controlSize());
164 }
165 
166 } // namespace WebCore
167