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 24 matching lines...) Expand all Loading... | |
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 | 38 |
39 // Indexed by ScrollbarOverlayColorTheme. | 39 // Indexed by ScrollbarOverlayColorTheme. |
40 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | 40 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
41 SK_ColorWHITE}; | 41 SK_ColorWHITE}; |
42 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | 42 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
43 SK_ColorBLACK}; | 43 SK_ColorBLACK}; |
44 | 44 |
45 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | |
46 bool overlay = IsOverlayScrollbarEnabled(); | |
47 switch (state) { | |
48 case NativeTheme::kDisabled: | |
49 return 0x00; | |
50 case NativeTheme::kHovered: | |
51 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | |
52 case NativeTheme::kNormal: | |
53 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; | |
54 case NativeTheme::kPressed: | |
55 return overlay ? kOverlayScrollbarAlphaPressed : 0x80; | |
56 case NativeTheme::kNumStates: | |
57 break; | |
58 } | |
59 | |
60 NOTREACHED(); | |
61 return 0xFF; | |
62 } | |
63 | |
45 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | 64 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
46 | 65 |
47 } // namespace | 66 } // namespace |
48 | 67 |
49 // static | 68 // static |
50 NativeTheme* NativeTheme::GetInstanceForWeb() { | 69 NativeTheme* NativeTheme::GetInstanceForWeb() { |
51 return NativeThemeAura::web_instance(); | |
52 } | |
53 | |
54 #if !defined(OS_WIN) | |
55 // static | |
56 NativeTheme* NativeTheme::GetInstanceForNativeUi() { | |
57 return NativeThemeAura::instance(); | 70 return NativeThemeAura::instance(); |
58 } | 71 } |
59 #endif | |
60 | 72 |
61 // static | 73 // static |
62 NativeThemeAura* NativeThemeAura::instance() { | 74 NativeThemeAura* NativeThemeAura::instance() { |
63 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, (false)); | 75 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); |
64 return &s_native_theme; | 76 return &s_native_theme; |
65 } | 77 } |
66 | 78 |
67 // static | 79 NativeThemeAura::NativeThemeAura() { |
68 NativeThemeAura* NativeThemeAura::web_instance() { | |
69 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme_for_web, | |
70 (IsOverlayScrollbarEnabled())); | |
71 return &s_native_theme_for_web; | |
72 } | |
73 | |
74 NativeThemeAura::NativeThemeAura(bool use_overlay_scrollbars) | |
75 : use_overlay_scrollbars_(use_overlay_scrollbars) { | |
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 (use_overlay_scrollbars_) { | 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 } |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 PaintArrow(canvas, rect, direction, arrow_color); | 167 PaintArrow(canvas, rect, direction, arrow_color); |
164 } | 168 } |
165 | 169 |
166 void NativeThemeAura::PaintScrollbarTrack( | 170 void NativeThemeAura::PaintScrollbarTrack( |
167 SkCanvas* canvas, | 171 SkCanvas* canvas, |
168 Part part, | 172 Part part, |
169 State state, | 173 State state, |
170 const ScrollbarTrackExtraParams& extra_params, | 174 const ScrollbarTrackExtraParams& extra_params, |
171 const gfx::Rect& rect) const { | 175 const gfx::Rect& rect) const { |
172 // Overlay Scrollbar should never paint a scrollbar track. | 176 // Overlay Scrollbar should never paint a scrollbar track. |
173 DCHECK(!use_overlay_scrollbars_); | 177 DCHECK(!IsOverlayScrollbarEnabled()); |
174 SkPaint paint; | 178 SkPaint paint; |
175 paint.setColor(kTrackColor); | 179 paint.setColor(kTrackColor); |
176 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 180 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
177 } | 181 } |
178 | 182 |
179 void NativeThemeAura::PaintScrollbarThumb( | 183 void NativeThemeAura::PaintScrollbarThumb( |
180 SkCanvas* canvas, | 184 SkCanvas* canvas, |
181 Part part, | 185 Part part, |
182 State state, | 186 State state, |
183 const gfx::Rect& rect, | 187 const gfx::Rect& rect, |
184 ScrollbarOverlayColorTheme theme) const { | 188 ScrollbarOverlayColorTheme theme) const { |
185 // Do not paint if state is disabled. | 189 // Do not paint if state is disabled. |
186 if (state == kDisabled) | 190 if (state == kDisabled) |
187 return; | 191 return; |
188 | 192 |
189 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 193 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
190 | 194 |
191 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | |
192 const bool overlay = use_overlay_scrollbars_; | |
193 switch (state) { | |
194 case NativeTheme::kDisabled: | |
195 thumb_alpha = SK_AlphaTRANSPARENT; | |
196 case NativeTheme::kHovered: | |
197 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | |
198 case NativeTheme::kNormal: | |
199 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; | |
200 case NativeTheme::kPressed: | |
201 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; | |
Evan Stade
2016/11/08 01:36:40
the bug is no breaks in this switch :[
| |
202 case NativeTheme::kNumStates: | |
203 break; | |
204 } | |
205 | |
206 gfx::Rect thumb_rect(rect); | 195 gfx::Rect thumb_rect(rect); |
207 SkColor thumb_color; | 196 SkColor thumb_color; |
208 if (overlay) { | 197 SkAlpha thumb_alpha = ThumbAlphaForState(state); |
198 | |
199 if (IsOverlayScrollbarEnabled()) { | |
209 thumb_color = kOverlayScrollbarThumbColor[theme]; | 200 thumb_color = kOverlayScrollbarThumbColor[theme]; |
210 | 201 |
211 // In overlay mode, draw a stroke (border). | 202 // In overlay mode, draw a stroke (border). |
212 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
213 SkPaint paint; | 204 SkPaint paint; |
214 paint.setColor( | 205 paint.setColor( |
215 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); | 206 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); |
216 paint.setStyle(SkPaint::kStroke_Style); | 207 paint.setStyle(SkPaint::kStroke_Style); |
217 paint.setStrokeWidth(kStrokeWidth); | 208 paint.setStrokeWidth(kStrokeWidth); |
218 | 209 |
(...skipping 20 matching lines...) Expand all Loading... | |
239 | 230 |
240 SkPaint paint; | 231 SkPaint paint; |
241 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); | 232 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); |
242 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 233 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
243 } | 234 } |
244 | 235 |
245 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 236 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
246 State state, | 237 State state, |
247 const gfx::Rect& rect) const { | 238 const gfx::Rect& rect) const { |
248 // Overlay Scrollbar should never paint a scrollbar corner. | 239 // Overlay Scrollbar should never paint a scrollbar corner. |
249 DCHECK(!use_overlay_scrollbars_); | 240 DCHECK(!IsOverlayScrollbarEnabled()); |
250 SkPaint paint; | 241 SkPaint paint; |
251 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); | 242 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
252 canvas->drawIRect(RectToSkIRect(rect), paint); | 243 canvas->drawIRect(RectToSkIRect(rect), paint); |
253 } | 244 } |
254 | 245 |
255 gfx::Size NativeThemeAura::GetPartSize(Part part, | 246 gfx::Size NativeThemeAura::GetPartSize(Part part, |
256 State state, | 247 State state, |
257 const ExtraParams& extra) const { | 248 const ExtraParams& extra) const { |
258 if (use_overlay_scrollbars_) { | 249 if (IsOverlayScrollbarEnabled()) { |
259 constexpr int minimum_length = | 250 constexpr int minimum_length = |
260 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; | 251 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; |
261 | 252 |
262 // Aura overlay scrollbars need a slight tweak from the base sizes. | 253 // Aura overlay scrollbars need a slight tweak from the base sizes. |
263 switch (part) { | 254 switch (part) { |
264 case kScrollbarHorizontalThumb: | 255 case kScrollbarHorizontalThumb: |
265 return gfx::Size(minimum_length, scrollbar_width_); | 256 return gfx::Size(minimum_length, scrollbar_width_); |
266 case kScrollbarVerticalThumb: | 257 case kScrollbarVerticalThumb: |
267 return gfx::Size(scrollbar_width_, minimum_length); | 258 return gfx::Size(scrollbar_width_, minimum_length); |
268 | |
269 default: | 259 default: |
270 // TODO(bokan): We should probably make sure code using overlay | 260 // TODO(bokan): We should probably make sure code using overlay |
271 // scrollbars isn't asking for part sizes that don't exist. | 261 // scrollbars isn't asking for part sizes that don't exist. This |
262 // currently breaks in Views layout code which indicates they aren't | |
263 // overlay aware yet. The Views code should be fixed and either this | |
264 // branch return 0 for parts that don't exist or assert NOTREACHED. | |
272 // crbug.com/657159. | 265 // crbug.com/657159. |
273 break; | 266 break; |
274 } | 267 } |
275 } | 268 } |
276 | 269 |
277 return NativeThemeBase::GetPartSize(part, state, extra); | 270 return NativeThemeBase::GetPartSize(part, state, extra); |
278 } | 271 } |
279 | 272 |
280 } // namespace ui | 273 } // namespace ui |
OLD | NEW |