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 dc7166e6c491181340db32218f2f768dc48c7bab..1d67f96215de85480619e42fc3b87eb88d5ad851 100644 |
| --- a/ui/native_theme/native_theme_aura.cc |
| +++ b/ui/native_theme/native_theme_aura.cc |
| @@ -42,47 +42,43 @@ constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
| 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, ()); |
| + CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, (false)); |
| return &s_native_theme; |
| } |
| -NativeThemeAura::NativeThemeAura() { |
| +// 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) { |
| // We don't draw scrollbar buttons. |
| #if defined(OS_CHROMEOS) |
| set_scrollbar_button_length(0); |
| #endif |
| - if (IsOverlayScrollbarEnabled()) { |
| + if (use_overlay_scrollbars_) { |
| scrollbar_width_ = |
| kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; |
| } |
| @@ -174,7 +170,7 @@ void NativeThemeAura::PaintScrollbarTrack( |
| const ScrollbarTrackExtraParams& extra_params, |
| const gfx::Rect& rect) const { |
| // Overlay Scrollbar should never paint a scrollbar track. |
| - DCHECK(!IsOverlayScrollbarEnabled()); |
| + DCHECK(!use_overlay_scrollbars_); |
| SkPaint paint; |
| paint.setColor(kTrackColor); |
| canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| @@ -192,11 +188,29 @@ void NativeThemeAura::PaintScrollbarThumb( |
| 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; |
| + break; |
| + case NativeTheme::kHovered: |
| + thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
| + break; |
| + case NativeTheme::kNormal: |
| + thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
| + break; |
| + case NativeTheme::kPressed: |
| + thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; |
| + break; |
|
Evan Stade
2016/11/08 01:42:29
these breaks were missing from the first patch.
|
| + case NativeTheme::kNumStates: |
| + NOTREACHED(); |
| + break; |
| + } |
| + |
| gfx::Rect thumb_rect(rect); |
| SkColor thumb_color; |
| - SkAlpha thumb_alpha = ThumbAlphaForState(state); |
| - |
| - if (IsOverlayScrollbarEnabled()) { |
| + if (overlay) { |
| thumb_color = kOverlayScrollbarThumbColor[theme]; |
| // In overlay mode, draw a stroke (border). |
| @@ -237,7 +251,7 @@ void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
| State state, |
| const gfx::Rect& rect) const { |
| // Overlay Scrollbar should never paint a scrollbar corner. |
| - DCHECK(!IsOverlayScrollbarEnabled()); |
| + DCHECK(!use_overlay_scrollbars_); |
| SkPaint paint; |
| paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
| canvas->drawIRect(RectToSkIRect(rect), paint); |
| @@ -246,7 +260,7 @@ void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
| gfx::Size NativeThemeAura::GetPartSize(Part part, |
| State state, |
| const ExtraParams& extra) const { |
| - if (IsOverlayScrollbarEnabled()) { |
| + if (use_overlay_scrollbars_) { |
| constexpr int minimum_length = |
| kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; |
| @@ -256,12 +270,10 @@ gfx::Size NativeThemeAura::GetPartSize(Part part, |
| 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. 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. |
| + // scrollbars isn't asking for part sizes that don't exist. |
| // crbug.com/657159. |
| break; |
| } |