Chromium Code Reviews| Index: ui/native_theme/native_theme_aura.cc |
| diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc |
| index 77cd79229cc2ec96cc1b2e2b48064d291cc230d5..dc7166e6c491181340db32218f2f768dc48c7bab 100644 |
| --- a/ui/native_theme/native_theme_aura.cc |
| +++ b/ui/native_theme/native_theme_aura.cc |
| @@ -42,43 +42,47 @@ |
| constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
| SK_ColorBLACK}; |
| +SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
| + bool overlay = IsOverlayScrollbarEnabled(); |
| + switch (state) { |
| + case NativeTheme::kDisabled: |
| + return 0x00; |
| + case NativeTheme::kHovered: |
| + return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
| + case NativeTheme::kNormal: |
| + return overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
| + case NativeTheme::kPressed: |
| + return overlay ? kOverlayScrollbarAlphaPressed : 0x80; |
| + case NativeTheme::kNumStates: |
| + break; |
| + } |
| + |
| + NOTREACHED(); |
| + return 0xFF; |
| +} |
| + |
| const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
| } // namespace |
| // static |
| NativeTheme* NativeTheme::GetInstanceForWeb() { |
| - return NativeThemeAura::web_instance(); |
| -} |
| - |
| -#if !defined(OS_WIN) |
| -// static |
| -NativeTheme* NativeTheme::GetInstanceForNativeUi() { |
| return NativeThemeAura::instance(); |
| } |
| -#endif |
| // static |
| NativeThemeAura* NativeThemeAura::instance() { |
| - CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, (false)); |
| + CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); |
| return &s_native_theme; |
| } |
| -// static |
| -NativeThemeAura* NativeThemeAura::web_instance() { |
| - CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme_for_web, |
| - (IsOverlayScrollbarEnabled())); |
| - return &s_native_theme_for_web; |
| -} |
| - |
| -NativeThemeAura::NativeThemeAura(bool use_overlay_scrollbars) |
| - : use_overlay_scrollbars_(use_overlay_scrollbars) { |
| +NativeThemeAura::NativeThemeAura() { |
| // We don't draw scrollbar buttons. |
| #if defined(OS_CHROMEOS) |
| set_scrollbar_button_length(0); |
| #endif |
| - if (use_overlay_scrollbars_) { |
| + if (IsOverlayScrollbarEnabled()) { |
| scrollbar_width_ = |
| kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; |
| } |
| @@ -170,7 +174,7 @@ |
| const ScrollbarTrackExtraParams& extra_params, |
| const gfx::Rect& rect) const { |
| // Overlay Scrollbar should never paint a scrollbar track. |
| - DCHECK(!use_overlay_scrollbars_); |
| + DCHECK(!IsOverlayScrollbarEnabled()); |
| SkPaint paint; |
| paint.setColor(kTrackColor); |
| canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| @@ -188,24 +192,11 @@ |
| TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
| - SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
| - const bool overlay = use_overlay_scrollbars_; |
| - switch (state) { |
| - case NativeTheme::kDisabled: |
| - thumb_alpha = SK_AlphaTRANSPARENT; |
| - case NativeTheme::kHovered: |
| - thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
| - case NativeTheme::kNormal: |
| - thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
| - case NativeTheme::kPressed: |
| - thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; |
|
Evan Stade
2016/11/08 01:36:40
the bug is no breaks in this switch :[
|
| - case NativeTheme::kNumStates: |
| - break; |
| - } |
| - |
| gfx::Rect thumb_rect(rect); |
| SkColor thumb_color; |
| - if (overlay) { |
| + SkAlpha thumb_alpha = ThumbAlphaForState(state); |
| + |
| + if (IsOverlayScrollbarEnabled()) { |
| thumb_color = kOverlayScrollbarThumbColor[theme]; |
| // In overlay mode, draw a stroke (border). |
| @@ -246,7 +237,7 @@ |
| State state, |
| const gfx::Rect& rect) const { |
| // Overlay Scrollbar should never paint a scrollbar corner. |
| - DCHECK(!use_overlay_scrollbars_); |
| + DCHECK(!IsOverlayScrollbarEnabled()); |
| SkPaint paint; |
| paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
| canvas->drawIRect(RectToSkIRect(rect), paint); |
| @@ -255,7 +246,7 @@ |
| gfx::Size NativeThemeAura::GetPartSize(Part part, |
| State state, |
| const ExtraParams& extra) const { |
| - if (use_overlay_scrollbars_) { |
| + if (IsOverlayScrollbarEnabled()) { |
| constexpr int minimum_length = |
| kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; |
| @@ -265,10 +256,12 @@ |
| return gfx::Size(minimum_length, scrollbar_width_); |
| case kScrollbarVerticalThumb: |
| return gfx::Size(scrollbar_width_, minimum_length); |
| - |
| default: |
| // TODO(bokan): We should probably make sure code using overlay |
| - // scrollbars isn't asking for part sizes that don't exist. |
| + // scrollbars isn't asking for part sizes that don't exist. This |
| + // currently breaks in Views layout code which indicates they aren't |
| + // overlay aware yet. The Views code should be fixed and either this |
| + // branch return 0 for parts that don't exist or assert NOTREACHED. |
| // crbug.com/657159. |
| break; |
| } |