Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(9)

Side by Side Diff: third_party/WebKit/Source/platform/scroll/ScrollbarThemeAura.cpp

Issue 1550983002: Revert of Make ScrollbarThemeAura selectively invalidate scrollbar parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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
48 static bool useMockTheme() 46 static bool useMockTheme()
49 { 47 {
50 return LayoutTestSupport::isRunningLayoutTest(); 48 return LayoutTestSupport::isRunningLayoutTest();
51 } 49 }
52 50
53 // Contains a flag indicating whether WebThemeEngine should paint a UI widget
54 // for a scrollbar part, and if so, what part and state apply.
55 //
56 // If the PartPaintingParams are not affected by a change in the scrollbar
57 // state, then the corresponding scrollbar part does not need to be repainted.
58 struct PartPaintingParams {
59 PartPaintingParams()
60 : shouldPaint(false)
61 , part(WebThemeEngine::PartScrollbarDownArrow)
62 , state(WebThemeEngine::StateNormal) {}
63 PartPaintingParams(WebThemeEngine::Part part, WebThemeEngine::State state)
64 : shouldPaint(true)
65 , part(part)
66 , state(state) {}
67
68 bool shouldPaint;
69 WebThemeEngine::Part part;
70 WebThemeEngine::State state;
71 };
72
73 bool operator==(const PartPaintingParams& a, const PartPaintingParams& b)
74 {
75 return (!a.shouldPaint && !b.shouldPaint) || std::tie(a.shouldPaint, a.part, a.state) == std::tie(b.shouldPaint, b.part, b.state);
76 }
77
78 bool operator!=(const PartPaintingParams& a, const PartPaintingParams& b)
79 {
80 return !(a == b);
81 }
82
83 PartPaintingParams buttonPartPaintingParams(const ScrollbarThemeClient& scrollba r, float position, ScrollbarPart part)
84 {
85 WebThemeEngine::Part paintPart;
86 WebThemeEngine::State state = WebThemeEngine::StateNormal;
87 bool checkMin = false;
88 bool checkMax = false;
89
90 if (scrollbar.orientation() == HorizontalScrollbar) {
91 if (part == BackButtonStartPart) {
92 paintPart = WebThemeEngine::PartScrollbarLeftArrow;
93 checkMin = true;
94 } else if (useMockTheme() && part != ForwardButtonEndPart) {
95 return PartPaintingParams();
96 } else {
97 paintPart = WebThemeEngine::PartScrollbarRightArrow;
98 checkMax = true;
99 }
100 } else {
101 if (part == BackButtonStartPart) {
102 paintPart = WebThemeEngine::PartScrollbarUpArrow;
103 checkMin = true;
104 } else if (useMockTheme() && part != ForwardButtonEndPart) {
105 return PartPaintingParams();
106 } else {
107 paintPart = WebThemeEngine::PartScrollbarDownArrow;
108 checkMax = true;
109 }
110 }
111
112 if (useMockTheme() && !scrollbar.enabled()) {
113 state = WebThemeEngine::StateDisabled;
114 } else if (!useMockTheme() && ((checkMin && (position <= 0))
115 || (checkMax && position >= scrollbar.maximum()))) {
116 state = WebThemeEngine::StateDisabled;
117 } else {
118 if (part == scrollbar.pressedPart())
119 state = WebThemeEngine::StatePressed;
120 else if (part == scrollbar.hoveredPart())
121 state = WebThemeEngine::StateHover;
122 }
123
124 return PartPaintingParams(paintPart, state);
125 }
126
127 } // namespace
128
129 ScrollbarTheme& ScrollbarTheme::nativeTheme() 51 ScrollbarTheme& ScrollbarTheme::nativeTheme()
130 { 52 {
131 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { 53 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) {
132 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest)); 54 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest));
133 return theme; 55 return theme;
134 } 56 }
135 57
136 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); 58 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ());
137 return theme; 59 return theme;
138 } 60 }
139 61
140 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) 62 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize)
141 { 63 {
142 // Horiz and Vert scrollbars are the same thickness. 64 // Horiz and Vert scrollbars are the same thickness.
143 // 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). 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).
144 if (useMockTheme()) 66 if (useMockTheme())
145 return 15; 67 return 15;
146 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack); 68 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack);
147 return scrollbarSize.width(); 69 return scrollbarSize.width();
148 } 70 }
149 71
150 bool ScrollbarThemeAura::shouldRepaintAllPartsOnInvalidation() const
151 {
152 // This theme can separately handle thumb invalidation.
153 return false;
154 }
155
156 ScrollbarPart ScrollbarThemeAura::invalidateOnThumbPositionChange(const Scrollba rThemeClient& scrollbar, float oldPosition, float newPosition) const
157 {
158 ScrollbarPart invalidParts = NoPart;
159 ASSERT(buttonsPlacement() == WebScrollbarButtonsPlacementSingle);
160 static const ScrollbarPart kButtonParts[] = {BackButtonStartPart, ForwardBut tonEndPart};
161 for (ScrollbarPart part : kButtonParts) {
162 if (buttonPartPaintingParams(scrollbar, oldPosition, part) != buttonPart PaintingParams(scrollbar, newPosition, part))
163 invalidParts = static_cast<ScrollbarPart>(invalidParts | part);
164 }
165 return invalidParts;
166 }
167
168 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType) 72 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType)
169 { 73 {
170 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType ); 74 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType );
171 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) 75 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe))
172 return; 76 return;
173 77
174 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); 78 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect);
175 79
176 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal; 80 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal;
177 81
178 if (useMockTheme() && !scrollbar.enabled()) 82 if (useMockTheme() && !scrollbar.enabled())
179 state = WebThemeEngine::StateDisabled; 83 state = WebThemeEngine::StateDisabled;
180 84
181 IntRect alignRect = trackRect(scrollbar, false); 85 IntRect alignRect = trackRect(scrollbar, false);
182 WebThemeEngine::ExtraParams extraParams; 86 WebThemeEngine::ExtraParams extraParams;
183 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); 87 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart);
184 extraParams.scrollbarTrack.trackX = alignRect.x(); 88 extraParams.scrollbarTrack.trackX = alignRect.x();
185 extraParams.scrollbarTrack.trackY = alignRect.y(); 89 extraParams.scrollbarTrack.trackY = alignRect.y();
186 extraParams.scrollbarTrack.trackWidth = alignRect.width(); 90 extraParams.scrollbarTrack.trackWidth = alignRect.width();
187 extraParams.scrollbarTrack.trackHeight = alignRect.height(); 91 extraParams.scrollbarTrack.trackHeight = alignRect.height();
188 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); 92 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams);
189 } 93 }
190 94
191 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part) 95 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part)
192 { 96 {
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
193 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part); 124 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part);
194 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) 125 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe))
195 return; 126 return;
196 PartPaintingParams params = buttonPartPaintingParams(scrollbar, scrollbar.cu rrentPos(), part); 127
197 if (!params.shouldPaint)
198 return;
199 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); 128 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect);
200 Platform::current()->themeEngine()->paint(gc.canvas(), params.part, params.s tate, WebRect(rect), 0); 129
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);
201 } 142 }
202 143
203 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect) 144 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect)
204 { 145 {
205 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb)) 146 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb))
206 return; 147 return;
207 148
208 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect); 149 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect);
209 150
210 WebThemeEngine::State state; 151 WebThemeEngine::State state;
(...skipping 24 matching lines...) Expand all
235 if (scrollbar.orientation() == VerticalScrollbar) { 176 if (scrollbar.orientation() == VerticalScrollbar) {
236 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb); 177 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb);
237 return size.height(); 178 return size.height();
238 } 179 }
239 180
240 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb); 181 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb);
241 return size.width(); 182 return size.width();
242 } 183 }
243 184
244 } // namespace blink 185 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698