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 25 matching lines...) Expand all Loading... | |
| 36 #include "platform/graphics/GraphicsContext.h" | 36 #include "platform/graphics/GraphicsContext.h" |
| 37 #include "platform/graphics/paint/DrawingRecorder.h" | 37 #include "platform/graphics/paint/DrawingRecorder.h" |
| 38 #include "platform/scroll/ScrollbarThemeClient.h" | 38 #include "platform/scroll/ScrollbarThemeClient.h" |
| 39 #include "platform/scroll/ScrollbarThemeOverlay.h" | 39 #include "platform/scroll/ScrollbarThemeOverlay.h" |
| 40 #include "public/platform/Platform.h" | 40 #include "public/platform/Platform.h" |
| 41 #include "public/platform/WebRect.h" | 41 #include "public/platform/WebRect.h" |
| 42 #include "public/platform/WebThemeEngine.h" | 42 #include "public/platform/WebThemeEngine.h" |
| 43 | 43 |
| 44 namespace blink { | 44 namespace blink { |
| 45 | 45 |
| 46 namespace { | |
| 47 | |
| 46 static bool useMockTheme() | 48 static bool useMockTheme() |
| 47 { | 49 { |
| 48 return LayoutTestSupport::isRunningLayoutTest(); | 50 return LayoutTestSupport::isRunningLayoutTest(); |
| 49 } | 51 } |
| 50 | 52 |
| 53 struct PartPaintingParams { | |
|
skobes
2015/12/28 17:48:39
This could use a comment or two.
jbroman
2015/12/29 16:45:14
Done.
| |
| 54 PartPaintingParams() | |
| 55 : shouldPaint(false) | |
| 56 , part(WebThemeEngine::PartScrollbarDownArrow) | |
| 57 , state(WebThemeEngine::StateNormal) {} | |
| 58 PartPaintingParams(WebThemeEngine::Part part, WebThemeEngine::State state) | |
| 59 : shouldPaint(true) | |
| 60 , part(part) | |
| 61 , state(state) {} | |
| 62 | |
| 63 bool shouldPaint; | |
| 64 WebThemeEngine::Part part; | |
| 65 WebThemeEngine::State state; | |
| 66 }; | |
| 67 | |
| 68 bool operator==(const PartPaintingParams& a, const PartPaintingParams& b) | |
| 69 { | |
| 70 return (!a.shouldPaint && !b.shouldPaint) || std::tie(a.shouldPaint, a.part, a.state) == std::tie(b.shouldPaint, b.part, b.state); | |
| 71 } | |
| 72 | |
| 73 bool operator!=(const PartPaintingParams& a, const PartPaintingParams& b) | |
| 74 { | |
| 75 return !(a == b); | |
| 76 } | |
| 77 | |
| 78 PartPaintingParams buttonPartPaintingParams(const ScrollbarThemeClient& scrollba r, float position, ScrollbarPart part) | |
| 79 { | |
| 80 WebThemeEngine::Part paintPart; | |
| 81 WebThemeEngine::State state = WebThemeEngine::StateNormal; | |
| 82 bool checkMin = false; | |
| 83 bool checkMax = false; | |
| 84 | |
| 85 if (scrollbar.orientation() == HorizontalScrollbar) { | |
| 86 if (part == BackButtonStartPart) { | |
| 87 paintPart = WebThemeEngine::PartScrollbarLeftArrow; | |
| 88 checkMin = true; | |
| 89 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 90 return PartPaintingParams(); | |
| 91 } else { | |
| 92 paintPart = WebThemeEngine::PartScrollbarRightArrow; | |
| 93 checkMax = true; | |
| 94 } | |
| 95 } else { | |
| 96 if (part == BackButtonStartPart) { | |
| 97 paintPart = WebThemeEngine::PartScrollbarUpArrow; | |
| 98 checkMin = true; | |
| 99 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 100 return PartPaintingParams(); | |
| 101 } else { | |
| 102 paintPart = WebThemeEngine::PartScrollbarDownArrow; | |
| 103 checkMax = true; | |
| 104 } | |
| 105 } | |
| 106 | |
| 107 if (useMockTheme() && !scrollbar.enabled()) { | |
| 108 state = WebThemeEngine::StateDisabled; | |
| 109 } else if (!useMockTheme() && ((checkMin && (position <= 0)) | |
| 110 || (checkMax && position >= scrollbar.maximum()))) { | |
| 111 state = WebThemeEngine::StateDisabled; | |
| 112 } else { | |
| 113 if (part == scrollbar.pressedPart()) | |
| 114 state = WebThemeEngine::StatePressed; | |
| 115 else if (part == scrollbar.hoveredPart()) | |
| 116 state = WebThemeEngine::StateHover; | |
| 117 } | |
| 118 | |
| 119 return PartPaintingParams(paintPart, state); | |
| 120 } | |
| 121 | |
| 122 } // namespace | |
| 123 | |
| 51 ScrollbarTheme& ScrollbarTheme::nativeTheme() | 124 ScrollbarTheme& ScrollbarTheme::nativeTheme() |
| 52 { | 125 { |
| 53 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { | 126 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { |
| 54 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest)); | 127 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest)); |
| 55 return theme; | 128 return theme; |
| 56 } | 129 } |
| 57 | 130 |
| 58 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); | 131 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); |
| 59 return theme; | 132 return theme; |
| 60 } | 133 } |
| 61 | 134 |
| 62 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) | 135 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) |
| 63 { | 136 { |
| 64 // Horiz and Vert scrollbars are the same thickness. | 137 // Horiz and Vert scrollbars are the same thickness. |
| 65 // In unit tests we don't have the mock theme engine (because of layering vi olations), so we hard code the size (see bug 327470). | 138 // In unit tests we don't have the mock theme engine (because of layering vi olations), so we hard code the size (see bug 327470). |
| 66 if (useMockTheme()) | 139 if (useMockTheme()) |
| 67 return 15; | 140 return 15; |
| 68 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack); | 141 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack); |
| 69 return scrollbarSize.width(); | 142 return scrollbarSize.width(); |
| 70 } | 143 } |
| 71 | 144 |
| 145 bool ScrollbarThemeAura::shouldRepaintAllPartsOnInvalidation() const | |
| 146 { | |
| 147 // This theme can separately handle thumb invalidation. | |
| 148 return false; | |
| 149 } | |
| 150 | |
| 151 ScrollbarPart ScrollbarThemeAura::invalidateOnThumbPositionChange(const Scrollba rThemeClient& scrollbar, float oldPosition, float newPosition) const | |
| 152 { | |
| 153 ScrollbarPart invalidParts = NoPart; | |
| 154 ASSERT(buttonsPlacement() == WebScrollbarButtonsPlacementSingle); | |
| 155 static const ScrollbarPart kButtonParts[] = {BackButtonStartPart, ForwardBut tonEndPart}; | |
| 156 for (ScrollbarPart part : kButtonParts) { | |
| 157 if (buttonPartPaintingParams(scrollbar, oldPosition, part) != buttonPart PaintingParams(scrollbar, newPosition, part)) | |
| 158 invalidParts = static_cast<ScrollbarPart>(invalidParts | part); | |
| 159 } | |
| 160 return invalidParts; | |
| 161 } | |
| 162 | |
| 72 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType) | 163 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType) |
| 73 { | 164 { |
| 74 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType ); | 165 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType ); |
| 75 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) | 166 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) |
| 76 return; | 167 return; |
| 77 | 168 |
| 78 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); | 169 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); |
| 79 | 170 |
| 80 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal; | 171 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal; |
| 81 | 172 |
| 82 if (useMockTheme() && !scrollbar.enabled()) | 173 if (useMockTheme() && !scrollbar.enabled()) |
| 83 state = WebThemeEngine::StateDisabled; | 174 state = WebThemeEngine::StateDisabled; |
| 84 | 175 |
| 85 IntRect alignRect = trackRect(scrollbar, false); | 176 IntRect alignRect = trackRect(scrollbar, false); |
| 86 WebThemeEngine::ExtraParams extraParams; | 177 WebThemeEngine::ExtraParams extraParams; |
| 87 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); | 178 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); |
| 88 extraParams.scrollbarTrack.trackX = alignRect.x(); | 179 extraParams.scrollbarTrack.trackX = alignRect.x(); |
| 89 extraParams.scrollbarTrack.trackY = alignRect.y(); | 180 extraParams.scrollbarTrack.trackY = alignRect.y(); |
| 90 extraParams.scrollbarTrack.trackWidth = alignRect.width(); | 181 extraParams.scrollbarTrack.trackWidth = alignRect.width(); |
| 91 extraParams.scrollbarTrack.trackHeight = alignRect.height(); | 182 extraParams.scrollbarTrack.trackHeight = alignRect.height(); |
| 92 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); | 183 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); |
| 93 } | 184 } |
| 94 | 185 |
| 95 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part) | 186 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part) |
| 96 { | 187 { |
| 97 WebThemeEngine::Part paintPart; | |
| 98 WebThemeEngine::State state = WebThemeEngine::StateNormal; | |
| 99 bool checkMin = false; | |
| 100 bool checkMax = false; | |
| 101 | |
| 102 if (scrollbar.orientation() == HorizontalScrollbar) { | |
| 103 if (part == BackButtonStartPart) { | |
| 104 paintPart = WebThemeEngine::PartScrollbarLeftArrow; | |
| 105 checkMin = true; | |
| 106 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 107 return; | |
| 108 } else { | |
| 109 paintPart = WebThemeEngine::PartScrollbarRightArrow; | |
| 110 checkMax = true; | |
| 111 } | |
| 112 } else { | |
| 113 if (part == BackButtonStartPart) { | |
| 114 paintPart = WebThemeEngine::PartScrollbarUpArrow; | |
| 115 checkMin = true; | |
| 116 } else if (useMockTheme() && part != ForwardButtonEndPart) { | |
| 117 return; | |
| 118 } else { | |
| 119 paintPart = WebThemeEngine::PartScrollbarDownArrow; | |
| 120 checkMax = true; | |
| 121 } | |
| 122 } | |
| 123 | |
| 124 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part); | 188 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part); |
| 125 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) | 189 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) |
| 126 return; | 190 return; |
| 127 | 191 PartPaintingParams params = buttonPartPaintingParams(scrollbar, scrollbar.cu rrentPos(), part); |
| 192 if (!params.shouldPaint) | |
| 193 return; | |
| 128 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); | 194 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); |
| 129 | 195 Platform::current()->themeEngine()->paint(gc.canvas(), params.part, params.s tate, WebRect(rect), 0); |
| 130 if (useMockTheme() && !scrollbar.enabled()) { | |
| 131 state = WebThemeEngine::StateDisabled; | |
| 132 } else if (!useMockTheme() && ((checkMin && (scrollbar.currentPos() <= 0)) | |
| 133 || (checkMax && scrollbar.currentPos() >= scrollbar.maximum()))) { | |
| 134 state = WebThemeEngine::StateDisabled; | |
| 135 } else { | |
| 136 if (part == scrollbar.pressedPart()) | |
| 137 state = WebThemeEngine::StatePressed; | |
| 138 else if (part == scrollbar.hoveredPart()) | |
| 139 state = WebThemeEngine::StateHover; | |
| 140 } | |
| 141 Platform::current()->themeEngine()->paint(gc.canvas(), paintPart, state, Web Rect(rect), 0); | |
| 142 } | 196 } |
| 143 | 197 |
| 144 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect) | 198 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect) |
| 145 { | 199 { |
| 146 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb)) | 200 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb)) |
| 147 return; | 201 return; |
| 148 | 202 |
| 149 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect); | 203 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect); |
| 150 | 204 |
| 151 WebThemeEngine::State state; | 205 WebThemeEngine::State state; |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 176 if (scrollbar.orientation() == VerticalScrollbar) { | 230 if (scrollbar.orientation() == VerticalScrollbar) { |
| 177 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb); | 231 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb); |
| 178 return size.height(); | 232 return size.height(); |
| 179 } | 233 } |
| 180 | 234 |
| 181 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb); | 235 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb); |
| 182 return size.width(); | 236 return size.width(); |
| 183 } | 237 } |
| 184 | 238 |
| 185 } // namespace blink | 239 } // namespace blink |
| OLD | NEW |