2 * Copyright (c) 2008, 2009, Google 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 are
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
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.
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.
32 #include "platform/scroll/ScrollbarThemeGtkOrAura.h"
34 #include "RuntimeEnabledFeatures.h"
35 #include "platform/LayoutTestSupport.h"
36 #include "platform/PlatformMouseEvent.h"
37 #include "platform/graphics/GraphicsContext.h"
38 #include "platform/scroll/ScrollbarThemeClient.h"
39 #include "platform/scroll/ScrollbarThemeOverlay.h"
40 #include "public/platform/Platform.h"
41 #include "public/platform/WebRect.h"
42 #include "public/platform/WebThemeEngine.h"
46 static bool useMockTheme()
48 return isRunningLayoutTest();
51 ScrollbarTheme* ScrollbarTheme::nativeTheme()
53 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) {
55 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (3, 4, ScrollbarThemeOverlay::DisallowHitTest));
57 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarThemeOverlay::AllowHitTest, Color(128, 128, 128, 192)));
62 DEFINE_STATIC_LOCAL(ScrollbarThemeGtkOrAura, theme, ());
66 int ScrollbarThemeGtkOrAura::scrollbarThickness(ScrollbarControlSize controlSize)
68 // Horiz and Vert scrollbars are the same thickness.
69 // In unit tests we don't have the mock theme engine (because of layering violations), so we hard code the size (see bug 327470).
72 IntSize scrollbarSize = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartScrollbarVerticalTrack);
73 return scrollbarSize.width();
76 void ScrollbarThemeGtkOrAura::paintTrackPiece(GraphicsContext* gc, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart partType)
78 blink::WebThemeEngine::State state = scrollbar->hoveredPart() == partType ? blink::WebThemeEngine::StateHover : blink::WebThemeEngine::StateNormal;
80 if (useMockTheme() && !scrollbar->enabled())
81 state = blink::WebThemeEngine::StateDisabled;
83 IntRect alignRect = trackRect(scrollbar, false);
84 blink::WebThemeEngine::ExtraParams extraParams;
85 blink::WebCanvas* canvas = gc->canvas();
86 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart);
87 extraParams.scrollbarTrack.trackX = alignRect.x();
88 extraParams.scrollbarTrack.trackY = alignRect.y();
89 extraParams.scrollbarTrack.trackWidth = alignRect.width();
90 extraParams.scrollbarTrack.trackHeight = alignRect.height();
91 blink::Platform::current()->themeEngine()->paint(canvas, scrollbar->orientation() == HorizontalScrollbar ? blink::WebThemeEngine::PartScrollbarHorizontalTrack : blink::WebThemeEngine::PartScrollbarVerticalTrack, state, blink::WebRect(rect), &extraParams);
94 void ScrollbarThemeGtkOrAura::paintButton(GraphicsContext* gc, ScrollbarThemeClient* scrollbar, const IntRect& rect, ScrollbarPart part)
96 blink::WebThemeEngine::Part paintPart;
97 blink::WebThemeEngine::State state = blink::WebThemeEngine::StateNormal;
98 blink::WebCanvas* canvas = gc->canvas();
99 bool checkMin = false;
100 bool checkMax = false;
102 if (scrollbar->orientation() == HorizontalScrollbar) {
103 if (part == BackButtonStartPart) {
104 paintPart = blink::WebThemeEngine::PartScrollbarLeftArrow;
106 } else if (useMockTheme() && part != ForwardButtonEndPart) {
109 paintPart = blink::WebThemeEngine::PartScrollbarRightArrow;
113 if (part == BackButtonStartPart) {
114 paintPart = blink::WebThemeEngine::PartScrollbarUpArrow;
116 } else if (useMockTheme() && part != ForwardButtonEndPart) {
119 paintPart = blink::WebThemeEngine::PartScrollbarDownArrow;
123 if (useMockTheme() && !scrollbar->enabled()) {
124 state = blink::WebThemeEngine::StateDisabled;
125 } else if (!useMockTheme() && ((checkMin && (scrollbar->currentPos() <= 0))
126 || (checkMax && scrollbar->currentPos() >= scrollbar->maximum()))) {
127 state = blink::WebThemeEngine::StateDisabled;
129 if (part == scrollbar->pressedPart())
130 state = blink::WebThemeEngine::StatePressed;
131 else if (part == scrollbar->hoveredPart())
132 state = blink::WebThemeEngine::StateHover;
134 blink::Platform::current()->themeEngine()->paint(canvas, paintPart, state, blink::WebRect(rect), 0);
137 void ScrollbarThemeGtkOrAura::paintThumb(GraphicsContext* gc, ScrollbarThemeClient* scrollbar, const IntRect& rect)
139 blink::WebThemeEngine::State state;
140 blink::WebCanvas* canvas = gc->canvas();
141 if (scrollbar->pressedPart() == ThumbPart)
142 state = blink::WebThemeEngine::StatePressed;
143 else if (scrollbar->hoveredPart() == ThumbPart)
144 state = blink::WebThemeEngine::StateHover;
146 state = blink::WebThemeEngine::StateNormal;
147 blink::Platform::current()->themeEngine()->paint(canvas, scrollbar->orientation() == HorizontalScrollbar ? blink::WebThemeEngine::PartScrollbarHorizontalThumb : blink::WebThemeEngine::PartScrollbarVerticalThumb, state, blink::WebRect(rect), 0);
150 bool ScrollbarThemeGtkOrAura::shouldCenterOnThumb(ScrollbarThemeClient*, const PlatformMouseEvent& evt)
152 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == MiddleButton);
155 IntSize ScrollbarThemeGtkOrAura::buttonSize(ScrollbarThemeClient* scrollbar)
157 if (scrollbar->orientation() == VerticalScrollbar) {
158 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartScrollbarUpArrow);
159 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? scrollbar->height() / 2 : size.height());
162 // HorizontalScrollbar
163 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartScrollbarLeftArrow);
164 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() / 2 : size.width(), size.height());
167 int ScrollbarThemeGtkOrAura::minimumThumbLength(ScrollbarThemeClient* scrollbar)
169 if (scrollbar->orientation() == VerticalScrollbar) {
170 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartScrollbarVerticalThumb);
171 return size.height();
174 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::WebThemeEngine::PartScrollbarHorizontalThumb);
178 } // namespace WebCore