| 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 | |
| 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 Loading... |
| 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 break; |
| 197 case NativeTheme::kHovered: |
| 198 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
| 199 break; |
| 200 case NativeTheme::kNormal: |
| 201 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
| 202 break; |
| 203 case NativeTheme::kPressed: |
| 204 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; |
| 205 break; |
| 206 case NativeTheme::kNumStates: |
| 207 NOTREACHED(); |
| 208 break; |
| 209 } |
| 210 |
| 195 gfx::Rect thumb_rect(rect); | 211 gfx::Rect thumb_rect(rect); |
| 196 SkColor thumb_color; | 212 SkColor thumb_color; |
| 197 SkAlpha thumb_alpha = ThumbAlphaForState(state); | 213 if (overlay) { |
| 198 | |
| 199 if (IsOverlayScrollbarEnabled()) { | |
| 200 thumb_color = kOverlayScrollbarThumbColor[theme]; | 214 thumb_color = kOverlayScrollbarThumbColor[theme]; |
| 201 | 215 |
| 202 // In overlay mode, draw a stroke (border). | 216 // In overlay mode, draw a stroke (border). |
| 203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 217 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
| 204 SkPaint paint; | 218 SkPaint paint; |
| 205 paint.setColor( | 219 paint.setColor( |
| 206 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); | 220 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); |
| 207 paint.setStyle(SkPaint::kStroke_Style); | 221 paint.setStyle(SkPaint::kStroke_Style); |
| 208 paint.setStrokeWidth(kStrokeWidth); | 222 paint.setStrokeWidth(kStrokeWidth); |
| 209 | 223 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 230 | 244 |
| 231 SkPaint paint; | 245 SkPaint paint; |
| 232 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); | 246 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); |
| 233 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 247 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
| 234 } | 248 } |
| 235 | 249 |
| 236 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 250 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
| 237 State state, | 251 State state, |
| 238 const gfx::Rect& rect) const { | 252 const gfx::Rect& rect) const { |
| 239 // Overlay Scrollbar should never paint a scrollbar corner. | 253 // Overlay Scrollbar should never paint a scrollbar corner. |
| 240 DCHECK(!IsOverlayScrollbarEnabled()); | 254 DCHECK(!use_overlay_scrollbars_); |
| 241 SkPaint paint; | 255 SkPaint paint; |
| 242 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); | 256 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
| 243 canvas->drawIRect(RectToSkIRect(rect), paint); | 257 canvas->drawIRect(RectToSkIRect(rect), paint); |
| 244 } | 258 } |
| 245 | 259 |
| 246 gfx::Size NativeThemeAura::GetPartSize(Part part, | 260 gfx::Size NativeThemeAura::GetPartSize(Part part, |
| 247 State state, | 261 State state, |
| 248 const ExtraParams& extra) const { | 262 const ExtraParams& extra) const { |
| 249 if (IsOverlayScrollbarEnabled()) { | 263 if (use_overlay_scrollbars_) { |
| 250 constexpr int minimum_length = | 264 constexpr int minimum_length = |
| 251 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; | 265 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; |
| 252 | 266 |
| 253 // Aura overlay scrollbars need a slight tweak from the base sizes. | 267 // Aura overlay scrollbars need a slight tweak from the base sizes. |
| 254 switch (part) { | 268 switch (part) { |
| 255 case kScrollbarHorizontalThumb: | 269 case kScrollbarHorizontalThumb: |
| 256 return gfx::Size(minimum_length, scrollbar_width_); | 270 return gfx::Size(minimum_length, scrollbar_width_); |
| 257 case kScrollbarVerticalThumb: | 271 case kScrollbarVerticalThumb: |
| 258 return gfx::Size(scrollbar_width_, minimum_length); | 272 return gfx::Size(scrollbar_width_, minimum_length); |
| 273 |
| 259 default: | 274 default: |
| 260 // TODO(bokan): We should probably make sure code using overlay | 275 // TODO(bokan): We should probably make sure code using overlay |
| 261 // scrollbars isn't asking for part sizes that don't exist. This | 276 // 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. | 277 // crbug.com/657159. |
| 266 break; | 278 break; |
| 267 } | 279 } |
| 268 } | 280 } |
| 269 | 281 |
| 270 return NativeThemeBase::GetPartSize(part, state, extra); | 282 return NativeThemeBase::GetPartSize(part, state, extra); |
| 271 } | 283 } |
| 272 | 284 |
| 273 } // namespace ui | 285 } // namespace ui |
| OLD | NEW |