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