Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. | 2 * Copyright (c) 2008, 2009, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 29 */ | 29 */ |
| 30 | 30 |
| 31 #include "config.h" | 31 #include "config.h" |
| 32 #include "core/platform/ScrollbarThemeGtkOrAura.h" | 32 #include "core/platform/ScrollbarThemeGtkOrAura.h" |
| 33 | 33 |
| 34 #include "RuntimeEnabledFeatures.h" | 34 #include "RuntimeEnabledFeatures.h" |
| 35 #include "core/platform/ScrollbarThemeOverlay.h" | 35 #include "core/platform/ScrollbarThemeOverlay.h" |
| 36 #include "core/platform/graphics/GraphicsContext.h" | 36 #include "core/platform/graphics/GraphicsContext.h" |
| 37 #include "platform/LayoutTestSupport.h" | |
| 37 #include "platform/PlatformMouseEvent.h" | 38 #include "platform/PlatformMouseEvent.h" |
| 38 #include "platform/scroll/ScrollbarThemeClient.h" | 39 #include "platform/scroll/ScrollbarThemeClient.h" |
| 39 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 40 #include "public/platform/WebRect.h" | 41 #include "public/platform/WebRect.h" |
| 41 #include "public/platform/default/WebThemeEngine.h" | 42 #include "public/platform/default/WebThemeEngine.h" |
| 42 | 43 |
| 43 namespace WebCore { | 44 namespace WebCore { |
| 44 | 45 |
| 45 ScrollbarTheme* ScrollbarTheme::nativeTheme() | 46 ScrollbarTheme* ScrollbarTheme::nativeTheme() |
| 46 { | 47 { |
| 47 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | 48 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { |
| 48 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest, Color(128, 128, 128, 192))); | 49 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest, Color(128, 128, 128, 192))); |
| 49 return &theme; | 50 return &theme; |
| 50 } | 51 } |
| 51 | 52 |
| 52 DEFINE_STATIC_LOCAL(ScrollbarThemeGtkOrAura, theme, ()); | 53 DEFINE_STATIC_LOCAL(ScrollbarThemeGtkOrAura, theme, ()); |
| 53 return &theme; | 54 return &theme; |
| 54 } | 55 } |
| 55 | 56 |
| 56 int ScrollbarThemeGtkOrAura::scrollbarThickness(ScrollbarControlSize controlSize ) | 57 int ScrollbarThemeGtkOrAura::scrollbarThickness(ScrollbarControlSize controlSize ) |
| 57 { | 58 { |
| 58 // Horiz and Vert scrollbars are the same thickness. | 59 // Horiz and Vert scrollbars are the same thickness. |
| 59 IntSize scrollbarSize = WebKit::Platform::current()->themeEngine()->getSize( WebKit::WebThemeEngine::PartScrollbarVerticalTrack); | 60 IntSize scrollbarSize = WebKit::Platform::current()->themeEngine()->getSize( WebKit::WebThemeEngine::PartScrollbarVerticalTrack); |
| 60 return scrollbarSize.width(); | 61 return scrollbarSize.width(); |
| 61 } | 62 } |
| 62 | 63 |
| 63 void ScrollbarThemeGtkOrAura::paintTrackPiece(GraphicsContext* gc, ScrollbarThem eClient* scrollbar, const IntRect& rect, ScrollbarPart partType) | 64 void ScrollbarThemeGtkOrAura::paintTrackPiece(GraphicsContext* gc, ScrollbarThem eClient* scrollbar, const IntRect& rect, ScrollbarPart partType) |
| 64 { | 65 { |
| 65 WebKit::WebThemeEngine::State state = scrollbar->hoveredPart() == partType ? WebKit::WebThemeEngine::StateHover : WebKit::WebThemeEngine::StateNormal; | 66 WebKit::WebThemeEngine::State state = scrollbar->hoveredPart() == partType ? WebKit::WebThemeEngine::StateHover : WebKit::WebThemeEngine::StateNormal; |
| 67 | |
| 68 if (isRunningLayoutTest()) { | |
| 69 if (!scrollbar->enabled()) | |
| 70 state = WebKit::WebThemeEngine::StateDisabled; | |
| 71 else if (scrollbar->hoveredPart() == partType) | |
| 72 state = WebKit::WebThemeEngine::StateHot; | |
| 73 else if (scrollbar->hoveredPart() != NoPart) | |
| 74 state = WebKit::WebThemeEngine::StateHover; | |
| 75 else | |
| 76 state = WebKit::WebThemeEngine::StateNormal; | |
| 77 } | |
| 78 | |
| 66 IntRect alignRect = trackRect(scrollbar, false); | 79 IntRect alignRect = trackRect(scrollbar, false); |
| 67 WebKit::WebThemeEngine::ExtraParams extraParams; | 80 WebKit::WebThemeEngine::ExtraParams extraParams; |
| 68 WebKit::WebCanvas* canvas = gc->canvas(); | 81 WebKit::WebCanvas* canvas = gc->canvas(); |
| 82 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); | |
| 69 extraParams.scrollbarTrack.trackX = alignRect.x(); | 83 extraParams.scrollbarTrack.trackX = alignRect.x(); |
| 70 extraParams.scrollbarTrack.trackY = alignRect.y(); | 84 extraParams.scrollbarTrack.trackY = alignRect.y(); |
| 71 extraParams.scrollbarTrack.trackWidth = alignRect.width(); | 85 extraParams.scrollbarTrack.trackWidth = alignRect.width(); |
| 72 extraParams.scrollbarTrack.trackHeight = alignRect.height(); | 86 extraParams.scrollbarTrack.trackHeight = alignRect.height(); |
| 73 WebKit::Platform::current()->themeEngine()->paint(canvas, scrollbar->orienta tion() == HorizontalScrollbar ? WebKit::WebThemeEngine::PartScrollbarHorizontalT rack : WebKit::WebThemeEngine::PartScrollbarVerticalTrack, state, WebKit::WebRec t(rect), &extraParams); | 87 WebKit::Platform::current()->themeEngine()->paint(canvas, scrollbar->orienta tion() == HorizontalScrollbar ? WebKit::WebThemeEngine::PartScrollbarHorizontalT rack : WebKit::WebThemeEngine::PartScrollbarVerticalTrack, state, WebKit::WebRec t(rect), &extraParams); |
| 74 } | 88 } |
| 75 | 89 |
| 76 void ScrollbarThemeGtkOrAura::paintButton(GraphicsContext* gc, ScrollbarThemeCli ent* scrollbar, const IntRect& rect, ScrollbarPart part) | 90 void ScrollbarThemeGtkOrAura::paintButton(GraphicsContext* gc, ScrollbarThemeCli ent* scrollbar, const IntRect& rect, ScrollbarPart part) |
| 77 { | 91 { |
| 78 WebKit::WebThemeEngine::Part paintPart; | 92 WebKit::WebThemeEngine::Part paintPart; |
| 79 WebKit::WebThemeEngine::State state = WebKit::WebThemeEngine::StateNormal; | 93 WebKit::WebThemeEngine::State state = WebKit::WebThemeEngine::StateNormal; |
| 80 WebKit::WebCanvas* canvas = gc->canvas(); | 94 WebKit::WebCanvas* canvas = gc->canvas(); |
| 95 | |
| 96 if (isRunningLayoutTest()) { | |
| 97 if (scrollbar->orientation() == HorizontalScrollbar) { | |
| 98 if (part == BackButtonStartPart) | |
| 99 paintPart = WebKit::WebThemeEngine::PartScrollbarLeftArrow; | |
| 100 else if (part == ForwardButtonEndPart) | |
| 101 paintPart = WebKit::WebThemeEngine::PartScrollbarRightArrow; | |
| 102 else | |
| 103 return; | |
| 104 } else { | |
| 105 if (part == BackButtonStartPart) | |
| 106 paintPart = WebKit::WebThemeEngine::PartScrollbarUpArrow; | |
| 107 else if (part == ForwardButtonEndPart) | |
| 108 paintPart = WebKit::WebThemeEngine::PartScrollbarDownArrow; | |
| 109 else | |
| 110 return; | |
| 111 } | |
| 112 | |
| 113 if (!scrollbar->enabled()) { | |
| 114 state = WebKit::WebThemeEngine::StateDisabled; | |
| 115 } else { | |
| 116 if (part == scrollbar->pressedPart()) | |
| 117 state = WebKit::WebThemeEngine::StatePressed; | |
| 118 else if (part == scrollbar->hoveredPart()) | |
| 119 state = WebKit::WebThemeEngine::StateDisabled; | |
| 120 else if (NoPart != scrollbar->hoveredPart()) | |
| 121 state = WebKit::WebThemeEngine::StateHover; | |
| 122 } | |
| 123 WebKit::Platform::current()->themeEngine()->paint(canvas, paintPart, sta te, WebKit::WebRect(rect), 0); | |
|
jamesr
2013/11/06 21:54:09
how is this code different from the non-testing co
Dirk Pranke
2013/11/06 22:29:11
Are you referring to just lines 123-124, or the wh
jamesr
2013/11/06 23:16:15
Let's optimize for how the code is in this patch,
Dirk Pranke
2013/11/06 23:46:38
Okay, I was pretty sure that keeping all the code
| |
| 124 return; | |
| 125 } | |
| 126 | |
| 81 bool checkMin = false; | 127 bool checkMin = false; |
| 82 bool checkMax = false; | 128 bool checkMax = false; |
| 83 if (scrollbar->orientation() == HorizontalScrollbar) { | 129 if (scrollbar->orientation() == HorizontalScrollbar) { |
| 84 if (part == BackButtonStartPart) { | 130 if (part == BackButtonStartPart) { |
| 85 paintPart = WebKit::WebThemeEngine::PartScrollbarLeftArrow; | 131 paintPart = WebKit::WebThemeEngine::PartScrollbarLeftArrow; |
| 86 checkMin = true; | 132 checkMin = true; |
| 87 } else { | 133 } else { |
| 88 paintPart = WebKit::WebThemeEngine::PartScrollbarRightArrow; | 134 paintPart = WebKit::WebThemeEngine::PartScrollbarRightArrow; |
| 89 checkMax = true; | 135 checkMax = true; |
| 90 } | 136 } |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 109 WebKit::Platform::current()->themeEngine()->paint(canvas, paintPart, state, WebKit::WebRect(rect), 0); | 155 WebKit::Platform::current()->themeEngine()->paint(canvas, paintPart, state, WebKit::WebRect(rect), 0); |
| 110 } | 156 } |
| 111 | 157 |
| 112 void ScrollbarThemeGtkOrAura::paintThumb(GraphicsContext* gc, ScrollbarThemeClie nt* scrollbar, const IntRect& rect) | 158 void ScrollbarThemeGtkOrAura::paintThumb(GraphicsContext* gc, ScrollbarThemeClie nt* scrollbar, const IntRect& rect) |
| 113 { | 159 { |
| 114 WebKit::WebThemeEngine::State state; | 160 WebKit::WebThemeEngine::State state; |
| 115 WebKit::WebCanvas* canvas = gc->canvas(); | 161 WebKit::WebCanvas* canvas = gc->canvas(); |
| 116 if (scrollbar->pressedPart() == ThumbPart) | 162 if (scrollbar->pressedPart() == ThumbPart) |
| 117 state = WebKit::WebThemeEngine::StatePressed; | 163 state = WebKit::WebThemeEngine::StatePressed; |
| 118 else if (scrollbar->hoveredPart() == ThumbPart) | 164 else if (scrollbar->hoveredPart() == ThumbPart) |
| 119 state = WebKit::WebThemeEngine::StateHover; | 165 state = isRunningLayoutTest() ? WebKit::WebThemeEngine::StateHot : WebKi t::WebThemeEngine::StateHover; |
|
jamesr
2013/11/06 21:54:09
i think you should teach the mock WebThemeEngine t
Dirk Pranke
2013/11/06 22:29:11
I don't think I can. The theme engine is told whet
jamesr
2013/11/06 23:16:15
It looks like what you want to do is treat StateHo
| |
| 120 else | 166 else |
| 121 state = WebKit::WebThemeEngine::StateNormal; | 167 state = WebKit::WebThemeEngine::StateNormal; |
| 122 WebKit::Platform::current()->themeEngine()->paint(canvas, scrollbar->orienta tion() == HorizontalScrollbar ? WebKit::WebThemeEngine::PartScrollbarHorizontalT humb : WebKit::WebThemeEngine::PartScrollbarVerticalThumb, state, WebKit::WebRec t(rect), 0); | 168 WebKit::Platform::current()->themeEngine()->paint(canvas, scrollbar->orienta tion() == HorizontalScrollbar ? WebKit::WebThemeEngine::PartScrollbarHorizontalT humb : WebKit::WebThemeEngine::PartScrollbarVerticalThumb, state, WebKit::WebRec t(rect), 0); |
| 123 } | 169 } |
| 124 | 170 |
| 125 bool ScrollbarThemeGtkOrAura::shouldCenterOnThumb(ScrollbarThemeClient*, const P latformMouseEvent& evt) | 171 bool ScrollbarThemeGtkOrAura::shouldCenterOnThumb(ScrollbarThemeClient*, const P latformMouseEvent& evt) |
| 126 { | 172 { |
| 127 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == Mi ddleButton); | 173 return (evt.shiftKey() && evt.button() == LeftButton) || (evt.button() == Mi ddleButton); |
| 128 } | 174 } |
| 129 | 175 |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 144 if (scrollbar->orientation() == VerticalScrollbar) { | 190 if (scrollbar->orientation() == VerticalScrollbar) { |
| 145 IntSize size = WebKit::Platform::current()->themeEngine()->getSize(WebKi t::WebThemeEngine::PartScrollbarVerticalThumb); | 191 IntSize size = WebKit::Platform::current()->themeEngine()->getSize(WebKi t::WebThemeEngine::PartScrollbarVerticalThumb); |
| 146 return size.height(); | 192 return size.height(); |
| 147 } | 193 } |
| 148 | 194 |
| 149 IntSize size = WebKit::Platform::current()->themeEngine()->getSize(WebKit::W ebThemeEngine::PartScrollbarHorizontalThumb); | 195 IntSize size = WebKit::Platform::current()->themeEngine()->getSize(WebKit::W ebThemeEngine::PartScrollbarHorizontalThumb); |
| 150 return size.width(); | 196 return size.width(); |
| 151 } | 197 } |
| 152 | 198 |
| 153 } // namespace WebCore | 199 } // namespace WebCore |
| OLD | NEW |