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

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

Issue 2421913002: Change Aura overlay scrollbars from solid color to painted scrollbars. (Closed)
Patch Set: Rebase Created 4 years, 2 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
« 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 "build/build_config.h" 12 #include "build/build_config.h"
12 #include "ui/base/layout.h" 13 #include "ui/base/layout.h"
13 #include "ui/base/material_design/material_design_controller.h" 14 #include "ui/base/material_design/material_design_controller.h"
14 #include "ui/gfx/animation/tween.h" 15 #include "ui/gfx/animation/tween.h"
15 #include "ui/gfx/canvas.h" 16 #include "ui/gfx/canvas.h"
16 #include "ui/gfx/color_palette.h" 17 #include "ui/gfx/color_palette.h"
17 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
18 #include "ui/gfx/geometry/size.h" 19 #include "ui/gfx/geometry/size.h"
19 #include "ui/gfx/image/image_skia.h" 20 #include "ui/gfx/image/image_skia.h"
20 #include "ui/gfx/path.h" 21 #include "ui/gfx/path.h"
21 #include "ui/gfx/skia_util.h" 22 #include "ui/gfx/skia_util.h"
22 #include "ui/native_theme/common_theme.h" 23 #include "ui/native_theme/common_theme.h"
23 #include "ui/native_theme/native_theme_switches.h" 24 #include "ui/native_theme/native_theme_switches.h"
25 #include "ui/native_theme/overlay_scrollbar_constants_aura.h"
24 26
25 namespace ui { 27 namespace ui {
26 28
27 namespace { 29 namespace {
28 30
31 // Constants for painting overlay scrollbars. Other properties needed outside
32 // this painting code are defined in overlay_scrollbar_constants_aura.h.
33 constexpr int kOverlayScrollbarStrokeWidth = 1;
34 constexpr int kOverlayScrollbarMinimumLength = 12;
35 constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D;
36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80;
37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80;
38 constexpr SkColor kOverlayScrollbarThumbColor = SK_ColorBLACK;
39 constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE;
40
29 SkAlpha ThumbAlphaForState(NativeTheme::State state) { 41 SkAlpha ThumbAlphaForState(NativeTheme::State state) {
30 bool overlay = IsOverlayScrollbarEnabled(); 42 bool overlay = IsOverlayScrollbarEnabled();
31 switch (state) { 43 switch (state) {
32 case NativeTheme::kDisabled: 44 case NativeTheme::kDisabled:
33 return 0x00; 45 return 0x00;
34 case NativeTheme::kHovered: 46 case NativeTheme::kHovered:
35 return overlay ? 0xB2 : 0x4D; 47 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D;
36 case NativeTheme::kNormal: 48 case NativeTheme::kNormal:
37 return overlay ? 0x8C : 0x33; 49 return overlay ? kOverlayScrollbarAlphaNormal : 0x33;
38 case NativeTheme::kPressed: 50 case NativeTheme::kPressed:
39 return overlay ? 0xB2 : 0x80; 51 return overlay ? kOverlayScrollbarAlphaPressed : 0x80;
40 case NativeTheme::kNumStates: 52 case NativeTheme::kNumStates:
41 break; 53 break;
42 } 54 }
43
44 NOTREACHED();
45 return 0xFF;
46 }
47
48 SkAlpha ThumbStrokeAlphaForState(NativeTheme::State state) {
49 DCHECK(IsOverlayScrollbarEnabled());
50 switch (state) {
51 case NativeTheme::kDisabled:
52 return 0x00;
53 case NativeTheme::kHovered:
54 case NativeTheme::kPressed:
55 return 0x33;
56 case NativeTheme::kNormal:
57 return 0x26;
58 case NativeTheme::kNumStates:
59 break;
60 }
61 55
62 NOTREACHED(); 56 NOTREACHED();
63 return 0xFF; 57 return 0xFF;
64 } 58 }
65 59
66 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); 60 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1);
67 61
68 } // namespace 62 } // namespace
69 63
70 // static 64 // static
71 NativeTheme* NativeTheme::GetInstanceForWeb() { 65 NativeTheme* NativeTheme::GetInstanceForWeb() {
72 return NativeThemeAura::instance(); 66 return NativeThemeAura::instance();
73 } 67 }
74 68
75 // static 69 // static
76 NativeThemeAura* NativeThemeAura::instance() { 70 NativeThemeAura* NativeThemeAura::instance() {
77 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); 71 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ());
78 return &s_native_theme; 72 return &s_native_theme;
79 } 73 }
80 74
81 NativeThemeAura::NativeThemeAura() { 75 NativeThemeAura::NativeThemeAura() {
82 // We don't draw scrollbar buttons. 76 // We don't draw scrollbar buttons.
83 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
84 set_scrollbar_button_length(0); 78 set_scrollbar_button_length(0);
85 #endif 79 #endif
86 80
81 if (IsOverlayScrollbarEnabled()) {
82 scrollbar_width_ =
83 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2;
84 }
85
87 // Images and alphas declarations assume the following order. 86 // Images and alphas declarations assume the following order.
88 static_assert(kDisabled == 0, "states unexpectedly changed"); 87 static_assert(kDisabled == 0, "states unexpectedly changed");
89 static_assert(kHovered == 1, "states unexpectedly changed"); 88 static_assert(kHovered == 1, "states unexpectedly changed");
90 static_assert(kNormal == 2, "states unexpectedly changed"); 89 static_assert(kNormal == 2, "states unexpectedly changed");
91 static_assert(kPressed == 3, "states unexpectedly changed"); 90 static_assert(kPressed == 3, "states unexpectedly changed");
92 } 91 }
93 92
94 NativeThemeAura::~NativeThemeAura() { 93 NativeThemeAura::~NativeThemeAura() {
95 } 94 }
96 95
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); 188 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect);
190 } 189 }
191 190
192 void NativeThemeAura::PaintScrollbarThumbStateTransition( 191 void NativeThemeAura::PaintScrollbarThumbStateTransition(
193 SkCanvas* canvas, 192 SkCanvas* canvas,
194 Part part, 193 Part part,
195 State start_state, 194 State start_state,
196 State end_state, 195 State end_state,
197 double progress, 196 double progress,
198 const gfx::Rect& rect) const { 197 const gfx::Rect& rect) const {
198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition");
199 gfx::Rect thumb_rect(rect); 199 gfx::Rect thumb_rect(rect);
200 SkColor thumb_color;
200 if (IsOverlayScrollbarEnabled()) { 201 if (IsOverlayScrollbarEnabled()) {
201 // In overlay mode, draw a stroke (border). 202 // In overlay mode, draw a stroke (border).
202 const int kStrokeWidth = 1; 203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth;
203 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( 204 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween(
204 progress, ThumbStrokeAlphaForState(start_state), 205 progress, ThumbAlphaForState(start_state),
205 ThumbStrokeAlphaForState(end_state)); 206 ThumbAlphaForState(end_state));
206 SkPaint paint; 207 SkPaint paint;
207 paint.setColor(SkColorSetA(SK_ColorWHITE, stroke_alpha)); 208 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha));
208 paint.setStyle(SkPaint::kStroke_Style); 209 paint.setStyle(SkPaint::kStroke_Style);
209 paint.setStrokeWidth(kStrokeWidth); 210 paint.setStrokeWidth(kStrokeWidth);
210 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
211 211
212 thumb_rect.Inset(kStrokeWidth, kStrokeWidth, kStrokeWidth, kStrokeWidth); 212 gfx::RectF stroke_rect(thumb_rect);
213 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f;
214 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth);
215 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint);
216
217 // Inset the all the edges edges so we fill-in the stroke below.
218 thumb_rect.Inset(kStrokeWidth, kStrokeWidth);
219 thumb_color = kOverlayScrollbarThumbColor;
213 } else { 220 } else {
214 // If there are no scrollbuttons then provide some padding so that the thumb 221 // If there are no scrollbuttons then provide some padding so that the thumb
215 // doesn't touch the top of the track. 222 // doesn't touch the top of the track.
216 const int kThumbPadding = 2; 223 const int kThumbPadding = 2;
217 const int extra_padding = 224 const int extra_padding =
218 (scrollbar_button_length() == 0) ? kThumbPadding : 0; 225 (scrollbar_button_length() == 0) ? kThumbPadding : 0;
219 if (part == NativeTheme::kScrollbarVerticalThumb) 226 if (part == NativeTheme::kScrollbarVerticalThumb)
220 thumb_rect.Inset(kThumbPadding, extra_padding); 227 thumb_rect.Inset(kThumbPadding, extra_padding);
221 else 228 else
222 thumb_rect.Inset(extra_padding, kThumbPadding); 229 thumb_rect.Inset(extra_padding, kThumbPadding);
230
231 thumb_color = SK_ColorBLACK;
223 } 232 }
224 233
225 SkPaint paint; 234 SkPaint paint;
226 SkAlpha alpha = gfx::Tween::IntValueBetween( 235 SkAlpha alpha = gfx::Tween::IntValueBetween(
227 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state)); 236 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state));
228 paint.setColor(SkColorSetA(SK_ColorBLACK, alpha)); 237 paint.setColor(SkColorSetA(thumb_color, alpha));
229 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); 238 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
230 } 239 }
231 240
232 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, 241 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
233 State state, 242 State state,
234 const gfx::Rect& rect) const { 243 const gfx::Rect& rect) const {
235 // Overlay Scrollbar should never paint a scrollbar corner. 244 // Overlay Scrollbar should never paint a scrollbar corner.
236 DCHECK(!IsOverlayScrollbarEnabled()); 245 DCHECK(!IsOverlayScrollbarEnabled());
237 SkPaint paint; 246 SkPaint paint;
238 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); 247 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC));
239 canvas->drawIRect(RectToSkIRect(rect), paint); 248 canvas->drawIRect(RectToSkIRect(rect), paint);
240 } 249 }
241 250
251 gfx::Size NativeThemeAura::GetPartSize(Part part,
252 State state,
253 const ExtraParams& extra) const {
254 if (IsOverlayScrollbarEnabled()) {
255 constexpr int minimum_length =
256 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth;
257
258 // Aura overlay scrollbars need a slight tweak from the base sizes.
259 switch (part) {
260 case kScrollbarHorizontalThumb:
261 return gfx::Size(minimum_length, scrollbar_width_);
262 case kScrollbarVerticalThumb:
263 return gfx::Size(scrollbar_width_, minimum_length);
264 default:
265 // TODO(bokan): We should probably make sure code using overlay
266 // scrollbars isn't asking for part sizes that don't exist. This
267 // currently breaks in Views layout code which indicates they aren't
268 // overlay aware yet. The Views code should be fixed and either this
269 // branch return 0 for parts that don't exist or assert NOTREACHED.
270 // crbug.com/657159.
271 break;
272 }
273 }
274
275 return NativeThemeBase::GetPartSize(part, state, extra);
276 }
277
242 } // namespace ui 278 } // 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