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

Side by Side Diff: ui/native_theme/native_theme_aura.cc

Issue 2523673004: [NOT FOR COMMIT] Fully replace SkCanvas uses.
Patch Set: Support Android build. Created 4 years 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
« no previous file with comments | « ui/native_theme/native_theme_aura.h ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/native_theme/native_theme_aura.h" 5 #include "ui/native_theme/native_theme_aura.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/trace_event/trace_event.h" 11 #include "base/trace_event/trace_event.h"
12 #include "build/build_config.h" 12 #include "build/build_config.h"
13 #include "skia/ext/cdl_paint.h"
13 #include "ui/base/layout.h" 14 #include "ui/base/layout.h"
14 #include "ui/base/material_design/material_design_controller.h" 15 #include "ui/base/material_design/material_design_controller.h"
15 #include "ui/gfx/animation/tween.h" 16 #include "ui/gfx/animation/tween.h"
16 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
17 #include "ui/gfx/color_palette.h" 18 #include "ui/gfx/color_palette.h"
18 #include "ui/gfx/geometry/rect.h" 19 #include "ui/gfx/geometry/rect.h"
19 #include "ui/gfx/geometry/size.h" 20 #include "ui/gfx/geometry/size.h"
20 #include "ui/gfx/image/image_skia.h" 21 #include "ui/gfx/image/image_skia.h"
21 #include "ui/gfx/path.h" 22 #include "ui/gfx/path.h"
22 #include "ui/gfx/skia_util.h" 23 #include "ui/gfx/skia_util.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
91 } 92 }
92 93
93 NativeThemeAura::~NativeThemeAura() {} 94 NativeThemeAura::~NativeThemeAura() {}
94 95
95 // This implementation returns hardcoded colors. 96 // This implementation returns hardcoded colors.
96 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { 97 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const {
97 return GetAuraColor(color_id, this); 98 return GetAuraColor(color_id, this);
98 } 99 }
99 100
100 void NativeThemeAura::PaintMenuPopupBackground( 101 void NativeThemeAura::PaintMenuPopupBackground(
101 SkCanvas* canvas, 102 CdlCanvas* canvas,
102 const gfx::Size& size, 103 const gfx::Size& size,
103 const MenuBackgroundExtraParams& menu_background) const { 104 const MenuBackgroundExtraParams& menu_background) const {
104 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); 105 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor);
105 if (menu_background.corner_radius > 0) { 106 if (menu_background.corner_radius > 0) {
106 SkPaint paint; 107 CdlPaint paint;
107 paint.setStyle(SkPaint::kFill_Style); 108 paint.setStyle(CdlPaint::kFill_Style);
108 paint.setFlags(SkPaint::kAntiAlias_Flag); 109 paint.setAntiAlias(true);
109 paint.setColor(color); 110 paint.setColor(color);
110 111
111 gfx::Path path; 112 gfx::Path path;
112 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), 113 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()),
113 SkIntToScalar(size.height())); 114 SkIntToScalar(size.height()));
114 SkScalar radius = SkIntToScalar(menu_background.corner_radius); 115 SkScalar radius = SkIntToScalar(menu_background.corner_radius);
115 SkScalar radii[8] = {radius, radius, radius, radius, 116 SkScalar radii[8] = {radius, radius, radius, radius,
116 radius, radius, radius, radius}; 117 radius, radius, radius, radius};
117 path.addRoundRect(rect, radii); 118 path.addRoundRect(rect, radii);
118 119
119 canvas->drawPath(path, paint); 120 canvas->drawPath(path, paint);
120 } else { 121 } else {
121 canvas->drawColor(color, SkBlendMode::kSrc); 122 canvas->drawColor(color, SkBlendMode::kSrc);
122 } 123 }
123 } 124 }
124 125
125 void NativeThemeAura::PaintMenuItemBackground( 126 void NativeThemeAura::PaintMenuItemBackground(
126 SkCanvas* canvas, 127 CdlCanvas* canvas,
127 State state, 128 State state,
128 const gfx::Rect& rect, 129 const gfx::Rect& rect,
129 const MenuItemExtraParams& menu_item) const { 130 const MenuItemExtraParams& menu_item) const {
130 CommonThemePaintMenuItemBackground(this, canvas, state, rect, menu_item); 131 CommonThemePaintMenuItemBackground(this, canvas, state, rect, menu_item);
131 } 132 }
132 133
133 void NativeThemeAura::PaintArrowButton(SkCanvas* canvas, 134 void NativeThemeAura::PaintArrowButton(CdlCanvas* canvas,
134 const gfx::Rect& rect, 135 const gfx::Rect& rect,
135 Part direction, 136 Part direction,
136 State state) const { 137 State state) const {
137 SkColor bg_color = kTrackColor; 138 SkColor bg_color = kTrackColor;
138 // Aura-win uses slightly different arrow colors. 139 // Aura-win uses slightly different arrow colors.
139 SkColor arrow_color = gfx::kPlaceholderColor; 140 SkColor arrow_color = gfx::kPlaceholderColor;
140 switch (state) { 141 switch (state) {
141 case kDisabled: 142 case kDisabled:
142 arrow_color = GetArrowColor(state); 143 arrow_color = GetArrowColor(state);
143 break; 144 break;
144 case kHovered: 145 case kHovered:
145 bg_color = SkColorSetRGB(0xD2, 0xD2, 0xD2); 146 bg_color = SkColorSetRGB(0xD2, 0xD2, 0xD2);
146 // Fall through. 147 // Fall through.
147 case kNormal: 148 case kNormal:
148 arrow_color = SkColorSetRGB(0x50, 0x50, 0x50); 149 arrow_color = SkColorSetRGB(0x50, 0x50, 0x50);
149 break; 150 break;
150 case kPressed: 151 case kPressed:
151 bg_color = SkColorSetRGB(0x78, 0x78, 0x78); 152 bg_color = SkColorSetRGB(0x78, 0x78, 0x78);
152 arrow_color = SK_ColorWHITE; 153 arrow_color = SK_ColorWHITE;
153 break; 154 break;
154 case kNumStates: 155 case kNumStates:
155 break; 156 break;
156 } 157 }
157 DCHECK_NE(arrow_color, gfx::kPlaceholderColor); 158 DCHECK_NE(arrow_color, gfx::kPlaceholderColor);
158 159
159 SkPaint paint; 160 CdlPaint paint;
160 paint.setColor(bg_color); 161 paint.setColor(bg_color);
161 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); 162 canvas->drawIRect(gfx::RectToSkIRect(rect), paint);
162 163
163 PaintArrow(canvas, rect, direction, arrow_color); 164 PaintArrow(canvas, rect, direction, arrow_color);
164 } 165 }
165 166
166 void NativeThemeAura::PaintScrollbarTrack( 167 void NativeThemeAura::PaintScrollbarTrack(
167 SkCanvas* canvas, 168 CdlCanvas* canvas,
168 Part part, 169 Part part,
169 State state, 170 State state,
170 const ScrollbarTrackExtraParams& extra_params, 171 const ScrollbarTrackExtraParams& extra_params,
171 const gfx::Rect& rect) const { 172 const gfx::Rect& rect) const {
172 // Overlay Scrollbar should never paint a scrollbar track. 173 // Overlay Scrollbar should never paint a scrollbar track.
173 DCHECK(!use_overlay_scrollbars_); 174 DCHECK(!use_overlay_scrollbars_);
174 SkPaint paint; 175 CdlPaint paint;
175 paint.setColor(kTrackColor); 176 paint.setColor(kTrackColor);
176 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); 177 canvas->drawIRect(gfx::RectToSkIRect(rect), paint);
177 } 178 }
178 179
179 void NativeThemeAura::PaintScrollbarThumb( 180 void NativeThemeAura::PaintScrollbarThumb(
180 SkCanvas* canvas, 181 CdlCanvas* canvas,
181 Part part, 182 Part part,
182 State state, 183 State state,
183 const gfx::Rect& rect, 184 const gfx::Rect& rect,
184 ScrollbarOverlayColorTheme theme) const { 185 ScrollbarOverlayColorTheme theme) const {
185 // Do not paint if state is disabled. 186 // Do not paint if state is disabled.
186 if (state == kDisabled) 187 if (state == kDisabled)
187 return; 188 return;
188 189
189 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); 190 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb");
190 191
(...skipping 17 matching lines...) Expand all
208 break; 209 break;
209 } 210 }
210 211
211 gfx::Rect thumb_rect(rect); 212 gfx::Rect thumb_rect(rect);
212 SkColor thumb_color; 213 SkColor thumb_color;
213 if (overlay) { 214 if (overlay) {
214 thumb_color = kOverlayScrollbarThumbColor[theme]; 215 thumb_color = kOverlayScrollbarThumbColor[theme];
215 216
216 // In overlay mode, draw a stroke (border). 217 // In overlay mode, draw a stroke (border).
217 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; 218 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth;
218 SkPaint paint; 219 CdlPaint paint;
219 paint.setColor( 220 paint.setColor(
220 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); 221 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha));
221 paint.setStyle(SkPaint::kStroke_Style); 222 paint.setStyle(CdlPaint::kStroke_Style);
222 paint.setStrokeWidth(kStrokeWidth); 223 paint.setStrokeWidth(kStrokeWidth);
223 224
224 gfx::RectF stroke_rect(thumb_rect); 225 gfx::RectF stroke_rect(thumb_rect);
225 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; 226 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f;
226 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); 227 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth);
227 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); 228 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint);
228 229
229 // Inset the all the edges edges so we fill-in the stroke below. 230 // Inset the all the edges edges so we fill-in the stroke below.
230 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); 231 thumb_rect.Inset(kStrokeWidth, kStrokeWidth);
231 } else { 232 } else {
232 // If there are no scrollbuttons then provide some padding so that the thumb 233 // If there are no scrollbuttons then provide some padding so that the thumb
233 // doesn't touch the top of the track. 234 // doesn't touch the top of the track.
234 const int kThumbPadding = 2; 235 const int kThumbPadding = 2;
235 const int extra_padding = 236 const int extra_padding =
236 (scrollbar_button_length() == 0) ? kThumbPadding : 0; 237 (scrollbar_button_length() == 0) ? kThumbPadding : 0;
237 if (part == NativeTheme::kScrollbarVerticalThumb) 238 if (part == NativeTheme::kScrollbarVerticalThumb)
238 thumb_rect.Inset(kThumbPadding, extra_padding); 239 thumb_rect.Inset(kThumbPadding, extra_padding);
239 else 240 else
240 thumb_rect.Inset(extra_padding, kThumbPadding); 241 thumb_rect.Inset(extra_padding, kThumbPadding);
241 242
242 thumb_color = SK_ColorBLACK; 243 thumb_color = SK_ColorBLACK;
243 } 244 }
244 245
245 SkPaint paint; 246 CdlPaint paint;
246 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); 247 paint.setColor(SkColorSetA(thumb_color, thumb_alpha));
247 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); 248 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
248 } 249 }
249 250
250 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, 251 void NativeThemeAura::PaintScrollbarCorner(CdlCanvas* canvas,
251 State state, 252 State state,
252 const gfx::Rect& rect) const { 253 const gfx::Rect& rect) const {
253 // Overlay Scrollbar should never paint a scrollbar corner. 254 // Overlay Scrollbar should never paint a scrollbar corner.
254 DCHECK(!use_overlay_scrollbars_); 255 DCHECK(!use_overlay_scrollbars_);
255 SkPaint paint; 256 CdlPaint paint;
256 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); 257 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC));
257 canvas->drawIRect(RectToSkIRect(rect), paint); 258 canvas->drawIRect(RectToSkIRect(rect), paint);
258 } 259 }
259 260
260 gfx::Size NativeThemeAura::GetPartSize(Part part, 261 gfx::Size NativeThemeAura::GetPartSize(Part part,
261 State state, 262 State state,
262 const ExtraParams& extra) const { 263 const ExtraParams& extra) const {
263 if (use_overlay_scrollbars_) { 264 if (use_overlay_scrollbars_) {
264 constexpr int minimum_length = 265 constexpr int minimum_length =
265 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; 266 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth;
(...skipping 10 matching lines...) Expand all
276 // scrollbars isn't asking for part sizes that don't exist. 277 // scrollbars isn't asking for part sizes that don't exist.
277 // crbug.com/657159. 278 // crbug.com/657159.
278 break; 279 break;
279 } 280 }
280 } 281 }
281 282
282 return NativeThemeBase::GetPartSize(part, state, extra); 283 return NativeThemeBase::GetPartSize(part, state, extra);
283 } 284 }
284 285
285 } // namespace ui 286 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_aura.h ('k') | ui/native_theme/native_theme_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698