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

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

Issue 1558493002: Reland: Make ScrollbarThemeAura selectively invalidate scrollbar parts. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix ScrollableAreaTest.InvalidatesCompositedScrollbarsIfPartsNeedRepaint for Oilpan 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
46 static bool useMockTheme() 48 static bool useMockTheme()
47 { 49 {
48 return LayoutTestSupport::isRunningLayoutTest(); 50 return LayoutTestSupport::isRunningLayoutTest();
49 } 51 }
50 52
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
51 ScrollbarTheme& ScrollbarTheme::nativeTheme() 129 ScrollbarTheme& ScrollbarTheme::nativeTheme()
52 { 130 {
53 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) { 131 if (RuntimeEnabledFeatures::overlayScrollbarsEnabled()) {
54 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest)); 132 DEFINE_STATIC_LOCAL(ScrollbarThemeOverlay, theme, (10, 0, ScrollbarTheme Overlay::AllowHitTest));
55 return theme; 133 return theme;
56 } 134 }
57 135
58 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ()); 136 DEFINE_STATIC_LOCAL(ScrollbarThemeAura, theme, ());
59 return theme; 137 return theme;
60 } 138 }
61 139
62 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize) 140 int ScrollbarThemeAura::scrollbarThickness(ScrollbarControlSize controlSize)
63 { 141 {
64 // Horiz and Vert scrollbars are the same thickness. 142 // 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). 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).
66 if (useMockTheme()) 144 if (useMockTheme())
67 return 15; 145 return 15;
68 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack); 146 IntSize scrollbarSize = Platform::current()->themeEngine()->getSize(WebTheme Engine::PartScrollbarVerticalTrack);
69 return scrollbarSize.width(); 147 return scrollbarSize.width();
70 } 148 }
71 149
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
72 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType) 168 void ScrollbarThemeAura::paintTrackPiece(GraphicsContext& gc, const ScrollbarThe meClient& scrollbar, const IntRect& rect, ScrollbarPart partType)
73 { 169 {
74 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType ); 170 DisplayItem::Type displayItemType = trackPiecePartToDisplayItemType(partType );
75 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) 171 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe))
76 return; 172 return;
77 173
78 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); 174 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect);
79 175
80 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal; 176 WebThemeEngine::State state = scrollbar.hoveredPart() == partType ? WebTheme Engine::StateHover : WebThemeEngine::StateNormal;
81 177
82 if (useMockTheme() && !scrollbar.enabled()) 178 if (useMockTheme() && !scrollbar.enabled())
83 state = WebThemeEngine::StateDisabled; 179 state = WebThemeEngine::StateDisabled;
84 180
85 IntRect alignRect = trackRect(scrollbar, false); 181 IntRect alignRect = trackRect(scrollbar, false);
86 WebThemeEngine::ExtraParams extraParams; 182 WebThemeEngine::ExtraParams extraParams;
87 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart); 183 extraParams.scrollbarTrack.isBack = (partType == BackTrackPart);
88 extraParams.scrollbarTrack.trackX = alignRect.x(); 184 extraParams.scrollbarTrack.trackX = alignRect.x();
89 extraParams.scrollbarTrack.trackY = alignRect.y(); 185 extraParams.scrollbarTrack.trackY = alignRect.y();
90 extraParams.scrollbarTrack.trackWidth = alignRect.width(); 186 extraParams.scrollbarTrack.trackWidth = alignRect.width();
91 extraParams.scrollbarTrack.trackHeight = alignRect.height(); 187 extraParams.scrollbarTrack.trackHeight = alignRect.height();
92 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams); 188 Platform::current()->themeEngine()->paint(gc.canvas(), scrollbar.orientation () == HorizontalScrollbar ? WebThemeEngine::PartScrollbarHorizontalTrack : WebTh emeEngine::PartScrollbarVerticalTrack, state, WebRect(rect), &extraParams);
93 } 189 }
94 190
95 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part) 191 void ScrollbarThemeAura::paintButton(GraphicsContext& gc, const ScrollbarThemeCl ient& scrollbar, const IntRect& rect, ScrollbarPart part)
96 { 192 {
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); 193 DisplayItem::Type displayItemType = buttonPartToDisplayItemType(part);
125 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe)) 194 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, displayItemTy pe))
126 return; 195 return;
127 196 PartPaintingParams params = buttonPartPaintingParams(scrollbar, scrollbar.cu rrentPos(), part);
197 if (!params.shouldPaint)
198 return;
128 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect); 199 DrawingRecorder recorder(gc, scrollbar, displayItemType, rect);
129 200 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 } 201 }
143 202
144 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect) 203 void ScrollbarThemeAura::paintThumb(GraphicsContext& gc, const ScrollbarThemeCli ent& scrollbar, const IntRect& rect)
145 { 204 {
146 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb)) 205 if (DrawingRecorder::useCachedDrawingIfPossible(gc, scrollbar, DisplayItem:: ScrollbarThumb))
147 return; 206 return;
148 207
149 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect); 208 DrawingRecorder recorder(gc, scrollbar, DisplayItem::ScrollbarThumb, rect);
150 209
151 WebThemeEngine::State state; 210 WebThemeEngine::State state;
(...skipping 24 matching lines...) Expand all
176 if (scrollbar.orientation() == VerticalScrollbar) { 235 if (scrollbar.orientation() == VerticalScrollbar) {
177 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb); 236 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngin e::PartScrollbarVerticalThumb);
178 return size.height(); 237 return size.height();
179 } 238 }
180 239
181 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb); 240 IntSize size = Platform::current()->themeEngine()->getSize(WebThemeEngine::P artScrollbarHorizontalThumb);
182 return size.width(); 241 return size.width();
183 } 242 }
184 243
185 } // namespace blink 244 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698