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

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

Issue 2480993002: Clean up some NativeTheme code. (Closed)
Patch Set: no notreached Created 4 years, 1 month 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_dark_aura.cc » ('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"
(...skipping 24 matching lines...) Expand all
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
64 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); 45 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1);
65 46
66 } // namespace 47 } // namespace
67 48
68 // static 49 // static
69 NativeTheme* NativeTheme::GetInstanceForWeb() { 50 NativeTheme* NativeTheme::GetInstanceForWeb() {
51 return NativeThemeAura::web_instance();
52 }
53
54 #if !defined(OS_WIN)
55 // static
56 NativeTheme* NativeTheme::GetInstanceForNativeUi() {
70 return NativeThemeAura::instance(); 57 return NativeThemeAura::instance();
71 } 58 }
59 #endif
60
61 // static
62 NativeThemeAura* NativeThemeAura::instance() {
63 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, (false));
64 return &s_native_theme;
65 }
72 66
73 // static 67 // static
74 NativeThemeAura* NativeThemeAura::instance() { 68 NativeThemeAura* NativeThemeAura::web_instance() {
75 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); 69 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme_for_web,
76 return &s_native_theme; 70 (IsOverlayScrollbarEnabled()));
71 return &s_native_theme_for_web;
77 } 72 }
78 73
79 NativeThemeAura::NativeThemeAura() { 74 NativeThemeAura::NativeThemeAura(bool use_overlay_scrollbars)
75 : use_overlay_scrollbars_(use_overlay_scrollbars) {
80 // We don't draw scrollbar buttons. 76 // We don't draw scrollbar buttons.
81 #if defined(OS_CHROMEOS) 77 #if defined(OS_CHROMEOS)
82 set_scrollbar_button_length(0); 78 set_scrollbar_button_length(0);
83 #endif 79 #endif
84 80
85 if (IsOverlayScrollbarEnabled()) { 81 if (use_overlay_scrollbars_) {
86 scrollbar_width_ = 82 scrollbar_width_ =
87 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; 83 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2;
88 } 84 }
89 85
90 // Images and alphas declarations assume the following order. 86 // Images and alphas declarations assume the following order.
91 static_assert(kDisabled == 0, "states unexpectedly changed"); 87 static_assert(kDisabled == 0, "states unexpectedly changed");
92 static_assert(kHovered == 1, "states unexpectedly changed"); 88 static_assert(kHovered == 1, "states unexpectedly changed");
93 static_assert(kNormal == 2, "states unexpectedly changed"); 89 static_assert(kNormal == 2, "states unexpectedly changed");
94 static_assert(kPressed == 3, "states unexpectedly changed"); 90 static_assert(kPressed == 3, "states unexpectedly changed");
95 } 91 }
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 PaintArrow(canvas, rect, direction, arrow_color); 163 PaintArrow(canvas, rect, direction, arrow_color);
168 } 164 }
169 165
170 void NativeThemeAura::PaintScrollbarTrack( 166 void NativeThemeAura::PaintScrollbarTrack(
171 SkCanvas* canvas, 167 SkCanvas* canvas,
172 Part part, 168 Part part,
173 State state, 169 State state,
174 const ScrollbarTrackExtraParams& extra_params, 170 const ScrollbarTrackExtraParams& extra_params,
175 const gfx::Rect& rect) const { 171 const gfx::Rect& rect) const {
176 // Overlay Scrollbar should never paint a scrollbar track. 172 // Overlay Scrollbar should never paint a scrollbar track.
177 DCHECK(!IsOverlayScrollbarEnabled()); 173 DCHECK(!use_overlay_scrollbars_);
178 SkPaint paint; 174 SkPaint paint;
179 paint.setColor(kTrackColor); 175 paint.setColor(kTrackColor);
180 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); 176 canvas->drawIRect(gfx::RectToSkIRect(rect), paint);
181 } 177 }
182 178
183 void NativeThemeAura::PaintScrollbarThumb( 179 void NativeThemeAura::PaintScrollbarThumb(
184 SkCanvas* canvas, 180 SkCanvas* canvas,
185 Part part, 181 Part part,
186 State state, 182 State state,
187 const gfx::Rect& rect, 183 const gfx::Rect& rect,
188 ScrollbarOverlayColorTheme theme) const { 184 ScrollbarOverlayColorTheme theme) const {
189 // Do not paint if state is disabled. 185 // Do not paint if state is disabled.
190 if (state == kDisabled) 186 if (state == kDisabled)
191 return; 187 return;
192 188
193 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); 189 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb");
194 190
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;
202 case NativeTheme::kNumStates:
203 break;
204 }
205
195 gfx::Rect thumb_rect(rect); 206 gfx::Rect thumb_rect(rect);
196 SkColor thumb_color; 207 SkColor thumb_color;
197 SkAlpha thumb_alpha = ThumbAlphaForState(state); 208 if (overlay) {
198
199 if (IsOverlayScrollbarEnabled()) {
200 thumb_color = kOverlayScrollbarThumbColor[theme]; 209 thumb_color = kOverlayScrollbarThumbColor[theme];
201 210
202 // In overlay mode, draw a stroke (border). 211 // In overlay mode, draw a stroke (border).
203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; 212 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth;
204 SkPaint paint; 213 SkPaint paint;
205 paint.setColor( 214 paint.setColor(
206 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); 215 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha));
207 paint.setStyle(SkPaint::kStroke_Style); 216 paint.setStyle(SkPaint::kStroke_Style);
208 paint.setStrokeWidth(kStrokeWidth); 217 paint.setStrokeWidth(kStrokeWidth);
209 218
(...skipping 20 matching lines...) Expand all
230 239
231 SkPaint paint; 240 SkPaint paint;
232 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); 241 paint.setColor(SkColorSetA(thumb_color, thumb_alpha));
233 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); 242 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
234 } 243 }
235 244
236 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, 245 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
237 State state, 246 State state,
238 const gfx::Rect& rect) const { 247 const gfx::Rect& rect) const {
239 // Overlay Scrollbar should never paint a scrollbar corner. 248 // Overlay Scrollbar should never paint a scrollbar corner.
240 DCHECK(!IsOverlayScrollbarEnabled()); 249 DCHECK(!use_overlay_scrollbars_);
241 SkPaint paint; 250 SkPaint paint;
242 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); 251 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC));
243 canvas->drawIRect(RectToSkIRect(rect), paint); 252 canvas->drawIRect(RectToSkIRect(rect), paint);
244 } 253 }
245 254
246 gfx::Size NativeThemeAura::GetPartSize(Part part, 255 gfx::Size NativeThemeAura::GetPartSize(Part part,
247 State state, 256 State state,
248 const ExtraParams& extra) const { 257 const ExtraParams& extra) const {
249 if (IsOverlayScrollbarEnabled()) { 258 if (use_overlay_scrollbars_) {
250 constexpr int minimum_length = 259 constexpr int minimum_length =
251 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; 260 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth;
252 261
253 // Aura overlay scrollbars need a slight tweak from the base sizes. 262 // Aura overlay scrollbars need a slight tweak from the base sizes.
254 switch (part) { 263 switch (part) {
255 case kScrollbarHorizontalThumb: 264 case kScrollbarHorizontalThumb:
256 return gfx::Size(minimum_length, scrollbar_width_); 265 return gfx::Size(minimum_length, scrollbar_width_);
257 case kScrollbarVerticalThumb: 266 case kScrollbarVerticalThumb:
258 return gfx::Size(scrollbar_width_, minimum_length); 267 return gfx::Size(scrollbar_width_, minimum_length);
268
259 default: 269 default:
260 // TODO(bokan): We should probably make sure code using overlay 270 // TODO(bokan): We should probably make sure code using overlay
261 // scrollbars isn't asking for part sizes that don't exist. This 271 // scrollbars isn't asking for part sizes that don't exist.
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.
265 // crbug.com/657159. 272 // crbug.com/657159.
266 break; 273 break;
267 } 274 }
268 } 275 }
269 276
270 return NativeThemeBase::GetPartSize(part, state, extra); 277 return NativeThemeBase::GetPartSize(part, state, extra);
271 } 278 }
272 279
273 } // namespace ui 280 } // namespace ui
OLDNEW
« no previous file with comments | « ui/native_theme/native_theme_aura.h ('k') | ui/native_theme/native_theme_dark_aura.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698