| OLD | NEW |
| (Empty) |
| 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 "core/platform/ScrollbarThemeGtkOrAura.h" | |
| 33 | |
| 34 #include "RuntimeEnabledFeatures.h" | |
| 35 #include "core/platform/ScrollbarThemeOverlay.h" | |
| 36 #include "core/platform/graphics/GraphicsContext.h" | |
| 37 #include "platform/LayoutTestSupport.h" | |
| 38 #include "platform/PlatformMouseEvent.h" | |
| 39 #include "platform/scroll/ScrollbarThemeClient.h" | |
| 40 #include "public/platform/Platform.h" | |
| 41 #include "public/platform/WebRect.h" | |
| 42 #include "public/platform/default/WebThemeEngine.h" | |
| 43 | |
| 44 namespace WebCore { | |
| 45 | |
| 46 static bool useMockTheme() | |
| 47 { | |
| 48 return isRunningLayoutTest(); | |
| 49 } | |
| 50 | |
| 51 ScrollbarTheme* ScrollbarTheme::nativeTheme() | |
| 52 { | |
| 53 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | |
| 54 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme
Overlay::AllowHitTest, Color(128, 128, 128, 192))); | |
| 55 return &theme; | |
| 56 } | |
| 57 | |
| 58 DEFINE_STATIC_LOCAL(ScrollbarThemeGtkOrAura, theme, ()); | |
| 59 return &theme; | |
| 60 } | |
| 61 | |
| 62 int ScrollbarThemeGtkOrAura::scrollbarThickness(ScrollbarControlSize controlSize
) | |
| 63 { | |
| 64 // Horiz and Vert scrollbars are the same thickness. | |
| 65 IntSize scrollbarSize = blink::Platform::current()->themeEngine()->getSize(b
link::WebThemeEngine::PartScrollbarVerticalTrack); | |
| 66 return scrollbarSize.width(); | |
| 67 } | |
| 68 | |
| 69 void ScrollbarThemeGtkOrAura::paintTrackPiece(GraphicsContext* gc, ScrollbarThem
eClient* scrollbar, const IntRect& rect, ScrollbarPart partType) | |
| 70 { | |
| 71 blink::WebThemeEngine::State state = scrollbar->hoveredPart() == partType ?
blink::WebThemeEngine::StateHover : blink::WebThemeEngine::StateNormal; | |
| 72 | |
| 73 if (useMockTheme() && !scrollbar->enabled()) | |
| 74 state = blink::WebThemeEngine::StateDisabled; | |
| 75 | |
| 76 IntRect alignRect = trackRect(scrollbar, false); | |
| 77 blink::WebThemeEngine::ExtraParams extraParams; | |
| 78 blink::WebCanvas* canvas = gc->canvas(); | |
| 79 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); | |
| 80 extraParams.scrollbarTrack.trackX = alignRect.x(); | |
| 81 extraParams.scrollbarTrack.trackY = alignRect.y(); | |
| 82 extraParams.scrollbarTrack.trackWidth = alignRect.width(); | |
| 83 extraParams.scrollbarTrack.trackHeight = alignRect.height(); | |
| 84 blink::Platform::current()->themeEngine()->paint(canvas, scrollbar->orientat
ion() == HorizontalScrollbar ? blink::WebThemeEngine::PartScrollbarHorizontalTra
ck : blink::WebThemeEngine::PartScrollbarVerticalTrack, state, blink::WebRect(re
ct), &extraParams); | |
| 85 } | |
| 86 | |
| 87 void ScrollbarThemeGtkOrAura::paintButton(GraphicsContext* gc, ScrollbarThemeCli
ent* scrollbar, const IntRect& rect, ScrollbarPart part) | |
| 88 { | |
| 89 blink::WebThemeEngine::Part paintPart; | |
| 90 blink::WebThemeEngine::State state = blink::WebThemeEngine::StateNormal; | |
| 91 blink::WebCanvas* canvas = gc->canvas(); | |
| 92 bool checkMin = false; | |
| 93 bool checkMax = false; | |
| 94 | |
| 95 if (scrollbar->orientation() == HorizontalScrollbar) { | |
| 96 if (part == BackButtonStartPart) { | |
| 97 paintPart = blink::WebThemeEngine::PartScrollbarLeftArrow; | |
| 98 checkMin = true; | |
| 99 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 100 return; | |
| 101 } else { | |
| 102 paintPart = blink::WebThemeEngine::PartScrollbarRightArrow; | |
| 103 checkMax = true; | |
| 104 } | |
| 105 } else { | |
| 106 if (part == BackButtonStartPart) { | |
| 107 paintPart = blink::WebThemeEngine::PartScrollbarUpArrow; | |
| 108 checkMin = true; | |
| 109 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 110 return; | |
| 111 } else { | |
| 112 paintPart = blink::WebThemeEngine::PartScrollbarDownArrow; | |
| 113 checkMax = true; | |
| 114 } | |
| 115 } | |
| 116 if (useMockTheme() && !scrollbar->enabled()) { | |
| 117 state = blink::WebThemeEngine::StateDisabled; | |
| 118 } else if (!useMockTheme() && ((checkMin && (scrollbar->currentPos() <= 0)) | |
| 119 || (checkMax && scrollbar->currentPos() == scrollbar->maximum()))) { | |
| 120 state = blink::WebThemeEngine::StateDisabled; | |
| 121 } else { | |
| 122 if (part == scrollbar->pressedPart()) | |
| 123 state = blink::WebThemeEngine::StatePressed; | |
| 124 else if (part == scrollbar->hoveredPart()) | |
| 125 state = blink::WebThemeEngine::StateHover; | |
| 126 } | |
| 127 blink::Platform::current()->themeEngine()->paint(canvas, paintPart, state, b
link::WebRect(rect), 0); | |
| 128 } | |
| 129 | |
| 130 void ScrollbarThemeGtkOrAura::paintThumb(GraphicsContext* gc, ScrollbarThemeClie
nt* scrollbar, const IntRect& rect) | |
| 131 { | |
| 132 blink::WebThemeEngine::State state; | |
| 133 blink::WebCanvas* canvas = gc->canvas(); | |
| 134 if (scrollbar->pressedPart() == ThumbPart) | |
| 135 state = blink::WebThemeEngine::StatePressed; | |
| 136 else if (scrollbar->hoveredPart() == ThumbPart) | |
| 137 state = blink::WebThemeEngine::StateHover; | |
| 138 else | |
| 139 state = blink::WebThemeEngine::StateNormal; | |
| 140 blink::Platform::current()->themeEngine()->paint(canvas, scrollbar->orientat
ion() == HorizontalScrollbar ? blink::WebThemeEngine::PartScrollbarHorizontalThu
mb : blink::WebThemeEngine::PartScrollbarVerticalThumb, state, blink::WebRect(re
ct), 0); | |
| 141 } | |
| 142 | |
| 143 bool ScrollbarThemeGtkOrAura::shouldCenterOnThumb(ScrollbarThemeClient*, const P
latformMouseEvent& evt) | |
| 144 { | |
| 145 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == Mi
ddleButton); | |
| 146 } | |
| 147 | |
| 148 IntSize ScrollbarThemeGtkOrAura::buttonSize(ScrollbarThemeClient* scrollbar) | |
| 149 { | |
| 150 if (scrollbar->orientation() == VerticalScrollbar) { | |
| 151 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink:
:WebThemeEngine::PartScrollbarUpArrow); | |
| 152 return IntSize(size.width(), scrollbar->height() < 2 * size.height() ? s
crollbar->height() / 2 : size.height()); | |
| 153 } | |
| 154 | |
| 155 // HorizontalScrollbar | |
| 156 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::Web
ThemeEngine::PartScrollbarLeftArrow); | |
| 157 return IntSize(scrollbar->width() < 2 * size.width() ? scrollbar->width() /
2 : size.width(), size.height()); | |
| 158 } | |
| 159 | |
| 160 int ScrollbarThemeGtkOrAura::minimumThumbLength(ScrollbarThemeClient* scrollbar) | |
| 161 { | |
| 162 if (scrollbar->orientation() == VerticalScrollbar) { | |
| 163 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink:
:WebThemeEngine::PartScrollbarVerticalThumb); | |
| 164 return size.height(); | |
| 165 } | |
| 166 | |
| 167 IntSize size = blink::Platform::current()->themeEngine()->getSize(blink::Web
ThemeEngine::PartScrollbarHorizontalThumb); | |
| 168 return size.width(); | |
| 169 } | |
| 170 | |
| 171 } // namespace WebCore | |
| OLD | NEW |