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