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" |
(...skipping 17 matching lines...) Expand all Loading... |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Constants for painting overlay scrollbars. Other properties needed outside | 31 // Constants for painting overlay scrollbars. Other properties needed outside |
32 // this painting code are defined in overlay_scrollbar_constants_aura.h. | 32 // this painting code are defined in overlay_scrollbar_constants_aura.h. |
33 constexpr int kOverlayScrollbarStrokeWidth = 1; | 33 constexpr int kOverlayScrollbarStrokeWidth = 1; |
34 constexpr int kOverlayScrollbarMinimumLength = 12; | 34 constexpr int kOverlayScrollbarMinimumLength = 12; |
35 constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D; | 35 constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D; |
36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80; | 36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80; |
37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80; | 37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80; |
38 constexpr SkColor kOverlayScrollbarThumbColor = SK_ColorBLACK; | 38 |
39 constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE; | 39 // Indexed by ScrollbarOverlayColorTheme. |
| 40 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
| 41 SK_ColorWHITE}; |
| 42 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
| 43 SK_ColorBLACK}; |
40 | 44 |
41 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | 45 SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
42 bool overlay = IsOverlayScrollbarEnabled(); | 46 bool overlay = IsOverlayScrollbarEnabled(); |
43 switch (state) { | 47 switch (state) { |
44 case NativeTheme::kDisabled: | 48 case NativeTheme::kDisabled: |
45 return 0x00; | 49 return 0x00; |
46 case NativeTheme::kHovered: | 50 case NativeTheme::kHovered: |
47 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 51 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
48 case NativeTheme::kNormal: | 52 case NativeTheme::kNormal: |
49 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; | 53 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
(...skipping 16 matching lines...) Expand all Loading... |
66 return NativeThemeAura::instance(); | 70 return NativeThemeAura::instance(); |
67 } | 71 } |
68 | 72 |
69 // static | 73 // static |
70 NativeThemeAura* NativeThemeAura::instance() { | 74 NativeThemeAura* NativeThemeAura::instance() { |
71 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); | 75 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); |
72 return &s_native_theme; | 76 return &s_native_theme; |
73 } | 77 } |
74 | 78 |
75 NativeThemeAura::NativeThemeAura() { | 79 NativeThemeAura::NativeThemeAura() { |
76 // We don't draw scrollbar buttons. | 80 // We don't draw scrollbar buttons. |
77 #if defined(OS_CHROMEOS) | 81 #if defined(OS_CHROMEOS) |
78 set_scrollbar_button_length(0); | 82 set_scrollbar_button_length(0); |
79 #endif | 83 #endif |
80 | 84 |
81 if (IsOverlayScrollbarEnabled()) { | 85 if (IsOverlayScrollbarEnabled()) { |
82 scrollbar_width_ = | 86 scrollbar_width_ = |
83 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; | 87 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; |
84 } | 88 } |
85 | 89 |
86 // Images and alphas declarations assume the following order. | 90 // Images and alphas declarations assume the following order. |
87 static_assert(kDisabled == 0, "states unexpectedly changed"); | 91 static_assert(kDisabled == 0, "states unexpectedly changed"); |
88 static_assert(kHovered == 1, "states unexpectedly changed"); | 92 static_assert(kHovered == 1, "states unexpectedly changed"); |
89 static_assert(kNormal == 2, "states unexpectedly changed"); | 93 static_assert(kNormal == 2, "states unexpectedly changed"); |
90 static_assert(kPressed == 3, "states unexpectedly changed"); | 94 static_assert(kPressed == 3, "states unexpectedly changed"); |
91 } | 95 } |
92 | 96 |
93 NativeThemeAura::~NativeThemeAura() { | 97 NativeThemeAura::~NativeThemeAura() {} |
94 } | |
95 | 98 |
96 // This implementation returns hardcoded colors. | 99 // This implementation returns hardcoded colors. |
97 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { | 100 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { |
98 return GetAuraColor(color_id, this); | 101 return GetAuraColor(color_id, this); |
99 } | 102 } |
100 | 103 |
101 void NativeThemeAura::PaintMenuPopupBackground( | 104 void NativeThemeAura::PaintMenuPopupBackground( |
102 SkCanvas* canvas, | 105 SkCanvas* canvas, |
103 const gfx::Size& size, | 106 const gfx::Size& size, |
104 const MenuBackgroundExtraParams& menu_background) const { | 107 const MenuBackgroundExtraParams& menu_background) const { |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 State state, | 173 State state, |
171 const ScrollbarTrackExtraParams& extra_params, | 174 const ScrollbarTrackExtraParams& extra_params, |
172 const gfx::Rect& rect) const { | 175 const gfx::Rect& rect) const { |
173 // Overlay Scrollbar should never paint a scrollbar track. | 176 // Overlay Scrollbar should never paint a scrollbar track. |
174 DCHECK(!IsOverlayScrollbarEnabled()); | 177 DCHECK(!IsOverlayScrollbarEnabled()); |
175 SkPaint paint; | 178 SkPaint paint; |
176 paint.setColor(kTrackColor); | 179 paint.setColor(kTrackColor); |
177 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 180 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
178 } | 181 } |
179 | 182 |
180 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | 183 void NativeThemeAura::PaintScrollbarThumb( |
181 Part part, | 184 SkCanvas* canvas, |
182 State state, | 185 Part part, |
183 const gfx::Rect& rect) const { | 186 State state, |
| 187 const gfx::Rect& rect, |
| 188 ScrollbarOverlayColorTheme theme) const { |
184 // Do not paint if state is disabled. | 189 // Do not paint if state is disabled. |
185 if (state == kDisabled) | 190 if (state == kDisabled) |
186 return; | 191 return; |
187 | 192 |
188 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); | 193 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
189 } | |
190 | 194 |
191 void NativeThemeAura::PaintScrollbarThumbStateTransition( | |
192 SkCanvas* canvas, | |
193 Part part, | |
194 State start_state, | |
195 State end_state, | |
196 double progress, | |
197 const gfx::Rect& rect) const { | |
198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); | |
199 gfx::Rect thumb_rect(rect); | 195 gfx::Rect thumb_rect(rect); |
200 SkColor thumb_color; | 196 SkColor thumb_color; |
| 197 SkAlpha thumb_alpha = ThumbAlphaForState(state); |
| 198 |
201 if (IsOverlayScrollbarEnabled()) { | 199 if (IsOverlayScrollbarEnabled()) { |
| 200 thumb_color = kOverlayScrollbarThumbColor[theme]; |
| 201 |
202 // In overlay mode, draw a stroke (border). | 202 // In overlay mode, draw a stroke (border). |
203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
204 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( | |
205 progress, ThumbAlphaForState(start_state), | |
206 ThumbAlphaForState(end_state)); | |
207 SkPaint paint; | 204 SkPaint paint; |
208 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha)); | 205 paint.setColor( |
| 206 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); |
209 paint.setStyle(SkPaint::kStroke_Style); | 207 paint.setStyle(SkPaint::kStroke_Style); |
210 paint.setStrokeWidth(kStrokeWidth); | 208 paint.setStrokeWidth(kStrokeWidth); |
211 | 209 |
212 gfx::RectF stroke_rect(thumb_rect); | 210 gfx::RectF stroke_rect(thumb_rect); |
213 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 211 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
214 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 212 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
215 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 213 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
216 | 214 |
217 // Inset the all the edges edges so we fill-in the stroke below. | 215 // Inset the all the edges edges so we fill-in the stroke below. |
218 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 216 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
219 thumb_color = kOverlayScrollbarThumbColor; | |
220 } else { | 217 } else { |
221 // If there are no scrollbuttons then provide some padding so that the thumb | 218 // If there are no scrollbuttons then provide some padding so that the thumb |
222 // doesn't touch the top of the track. | 219 // doesn't touch the top of the track. |
223 const int kThumbPadding = 2; | 220 const int kThumbPadding = 2; |
224 const int extra_padding = | 221 const int extra_padding = |
225 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 222 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
226 if (part == NativeTheme::kScrollbarVerticalThumb) | 223 if (part == NativeTheme::kScrollbarVerticalThumb) |
227 thumb_rect.Inset(kThumbPadding, extra_padding); | 224 thumb_rect.Inset(kThumbPadding, extra_padding); |
228 else | 225 else |
229 thumb_rect.Inset(extra_padding, kThumbPadding); | 226 thumb_rect.Inset(extra_padding, kThumbPadding); |
230 | 227 |
231 thumb_color = SK_ColorBLACK; | 228 thumb_color = SK_ColorBLACK; |
232 } | 229 } |
233 | 230 |
234 SkPaint paint; | 231 SkPaint paint; |
235 SkAlpha alpha = gfx::Tween::IntValueBetween( | 232 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); |
236 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state)); | |
237 paint.setColor(SkColorSetA(thumb_color, alpha)); | |
238 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 233 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
239 } | 234 } |
240 | 235 |
241 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 236 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
242 State state, | 237 State state, |
243 const gfx::Rect& rect) const { | 238 const gfx::Rect& rect) const { |
244 // Overlay Scrollbar should never paint a scrollbar corner. | 239 // Overlay Scrollbar should never paint a scrollbar corner. |
245 DCHECK(!IsOverlayScrollbarEnabled()); | 240 DCHECK(!IsOverlayScrollbarEnabled()); |
246 SkPaint paint; | 241 SkPaint paint; |
247 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); | 242 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
(...skipping 21 matching lines...) Expand all Loading... |
269 // branch return 0 for parts that don't exist or assert NOTREACHED. | 264 // branch return 0 for parts that don't exist or assert NOTREACHED. |
270 // crbug.com/657159. | 265 // crbug.com/657159. |
271 break; | 266 break; |
272 } | 267 } |
273 } | 268 } |
274 | 269 |
275 return NativeThemeBase::GetPartSize(part, state, extra); | 270 return NativeThemeBase::GetPartSize(part, state, extra); |
276 } | 271 } |
277 | 272 |
278 } // namespace ui | 273 } // namespace ui |
OLD | NEW |