| 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" |
| 11 #include "build/build_config.h" | 11 #include "build/build_config.h" |
| 12 #include "ui/base/layout.h" | 12 #include "ui/base/layout.h" |
| 13 #include "ui/base/material_design/material_design_controller.h" | 13 #include "ui/base/material_design/material_design_controller.h" |
| 14 #include "ui/gfx/animation/tween.h" | 14 #include "ui/gfx/animation/tween.h" |
| 15 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
| 16 #include "ui/gfx/color_palette.h" | 16 #include "ui/gfx/color_palette.h" |
| 17 #include "ui/gfx/geometry/rect.h" | 17 #include "ui/gfx/geometry/rect.h" |
| 18 #include "ui/gfx/geometry/size.h" | 18 #include "ui/gfx/geometry/size.h" |
| 19 #include "ui/gfx/image/image_skia.h" | 19 #include "ui/gfx/image/image_skia.h" |
| 20 #include "ui/gfx/path.h" | 20 #include "ui/gfx/path.h" |
| 21 #include "ui/gfx/skia_util.h" | 21 #include "ui/gfx/skia_util.h" |
| 22 #include "ui/native_theme/common_theme.h" | 22 #include "ui/native_theme/common_theme.h" |
| 23 #include "ui/native_theme/material_design_constants.h" |
| 23 #include "ui/native_theme/native_theme_switches.h" | 24 #include "ui/native_theme/native_theme_switches.h" |
| 24 | 25 |
| 25 namespace ui { | 26 namespace ui { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | 30 SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
| 30 bool overlay = IsOverlayScrollbarEnabled(); | 31 bool overlay = IsOverlayScrollbarEnabled(); |
| 31 switch (state) { | 32 switch (state) { |
| 32 case NativeTheme::kDisabled: | 33 case NativeTheme::kDisabled: |
| 33 return 0x00; | 34 return 0x00; |
| 34 case NativeTheme::kHovered: | 35 case NativeTheme::kHovered: |
| 35 return overlay ? 0xB2 : 0x4D; | 36 return overlay ? kMDScrollbarAlphaHovered : 0x4D; |
| 36 case NativeTheme::kNormal: | 37 case NativeTheme::kNormal: |
| 37 return overlay ? 0x8C : 0x33; | 38 return overlay ? kMDScrollbarAlphaNormal : 0x33; |
| 38 case NativeTheme::kPressed: | 39 case NativeTheme::kPressed: |
| 39 return overlay ? 0xB2 : 0x80; | 40 return overlay ? kMDScrollbarAlphaPressed : 0x80; |
| 40 case NativeTheme::kNumStates: | 41 case NativeTheme::kNumStates: |
| 41 break; | 42 break; |
| 42 } | 43 } |
| 43 | 44 |
| 44 NOTREACHED(); | 45 NOTREACHED(); |
| 45 return 0xFF; | 46 return 0xFF; |
| 46 } | 47 } |
| 47 | 48 |
| 48 SkAlpha ThumbStrokeAlphaForState(NativeTheme::State state) { | 49 SkAlpha ThumbStrokeAlphaForState(NativeTheme::State state) { |
| 49 DCHECK(IsOverlayScrollbarEnabled()); | 50 DCHECK(IsOverlayScrollbarEnabled()); |
| 50 switch (state) { | 51 switch (state) { |
| 51 case NativeTheme::kDisabled: | 52 case NativeTheme::kDisabled: |
| 52 return 0x00; | 53 return 0x00; |
| 53 case NativeTheme::kHovered: | 54 case NativeTheme::kHovered: |
| 55 return kMDScrollbarAlphaHovered; |
| 54 case NativeTheme::kPressed: | 56 case NativeTheme::kPressed: |
| 55 return 0x33; | 57 return kMDScrollbarAlphaPressed; |
| 56 case NativeTheme::kNormal: | 58 case NativeTheme::kNormal: |
| 57 return 0x26; | 59 return kMDScrollbarAlphaNormal; |
| 58 case NativeTheme::kNumStates: | 60 case NativeTheme::kNumStates: |
| 59 break; | 61 break; |
| 60 } | 62 } |
| 61 | 63 |
| 62 NOTREACHED(); | 64 NOTREACHED(); |
| 63 return 0xFF; | 65 return 0xFF; |
| 64 } | 66 } |
| 65 | 67 |
| 66 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | 68 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
| 67 | 69 |
| 68 } // namespace | 70 } // namespace |
| 69 | 71 |
| 70 // static | 72 // static |
| 71 NativeTheme* NativeTheme::GetInstanceForWeb() { | 73 NativeTheme* NativeTheme::GetInstanceForWeb() { |
| 72 return NativeThemeAura::instance(); | 74 return NativeThemeAura::instance(); |
| 73 } | 75 } |
| 74 | 76 |
| 75 // static | 77 // static |
| 76 NativeThemeAura* NativeThemeAura::instance() { | 78 NativeThemeAura* NativeThemeAura::instance() { |
| 77 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); | 79 CR_DEFINE_STATIC_LOCAL(NativeThemeAura, s_native_theme, ()); |
| 78 return &s_native_theme; | 80 return &s_native_theme; |
| 79 } | 81 } |
| 80 | 82 |
| 81 NativeThemeAura::NativeThemeAura() { | 83 NativeThemeAura::NativeThemeAura() { |
| 82 // We don't draw scrollbar buttons. | 84 // We don't draw scrollbar buttons. |
| 83 #if defined(OS_CHROMEOS) | 85 #if defined(OS_CHROMEOS) |
| 84 set_scrollbar_button_length(0); | 86 set_scrollbar_button_length(0); |
| 85 #endif | 87 #endif |
| 86 | 88 |
| 89 if (IsOverlayScrollbarEnabled()) { |
| 90 scrollbar_width_ = |
| 91 kMDScrollbarThumbWidthPressed + kMDScrollbarStrokeWidth * 2; |
| 92 } |
| 93 |
| 87 // Images and alphas declarations assume the following order. | 94 // Images and alphas declarations assume the following order. |
| 88 static_assert(kDisabled == 0, "states unexpectedly changed"); | 95 static_assert(kDisabled == 0, "states unexpectedly changed"); |
| 89 static_assert(kHovered == 1, "states unexpectedly changed"); | 96 static_assert(kHovered == 1, "states unexpectedly changed"); |
| 90 static_assert(kNormal == 2, "states unexpectedly changed"); | 97 static_assert(kNormal == 2, "states unexpectedly changed"); |
| 91 static_assert(kPressed == 3, "states unexpectedly changed"); | 98 static_assert(kPressed == 3, "states unexpectedly changed"); |
| 92 } | 99 } |
| 93 | 100 |
| 94 NativeThemeAura::~NativeThemeAura() { | 101 NativeThemeAura::~NativeThemeAura() { |
| 95 } | 102 } |
| 96 | 103 |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 // Overlay Scrollbar should never paint a scrollbar track. | 181 // Overlay Scrollbar should never paint a scrollbar track. |
| 175 DCHECK(!IsOverlayScrollbarEnabled()); | 182 DCHECK(!IsOverlayScrollbarEnabled()); |
| 176 SkPaint paint; | 183 SkPaint paint; |
| 177 paint.setColor(kTrackColor); | 184 paint.setColor(kTrackColor); |
| 178 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 185 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| 179 } | 186 } |
| 180 | 187 |
| 181 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | 188 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, |
| 182 Part part, | 189 Part part, |
| 183 State state, | 190 State state, |
| 184 const gfx::Rect& rect) const { | 191 const gfx::Rect& rect, |
| 192 ScrollbarOverlayStyle style) const { |
| 185 // Do not paint if state is disabled. | 193 // Do not paint if state is disabled. |
| 186 if (state == kDisabled) | 194 if (state == kDisabled) |
| 187 return; | 195 return; |
| 188 | 196 |
| 189 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); | 197 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect, |
| 198 style); |
| 190 } | 199 } |
| 191 | 200 |
| 192 void NativeThemeAura::PaintScrollbarThumbStateTransition( | 201 void NativeThemeAura::PaintScrollbarThumbStateTransition( |
| 193 SkCanvas* canvas, | 202 SkCanvas* canvas, |
| 194 Part part, | 203 Part part, |
| 195 State start_state, | 204 State start_state, |
| 196 State end_state, | 205 State end_state, |
| 197 double progress, | 206 double progress, |
| 198 const gfx::Rect& rect) const { | 207 const gfx::Rect& rect, |
| 208 ScrollbarOverlayStyle style) const { |
| 199 gfx::Rect thumb_rect(rect); | 209 gfx::Rect thumb_rect(rect); |
| 210 SkColor thumb_color; |
| 200 if (IsOverlayScrollbarEnabled()) { | 211 if (IsOverlayScrollbarEnabled()) { |
| 201 // In overlay mode, draw a stroke (border). | 212 // In overlay mode, draw a stroke (border). |
| 202 const int kStrokeWidth = 1; | 213 const int kStrokeWidth = kMDScrollbarStrokeWidth; |
| 203 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( | 214 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( |
| 204 progress, ThumbStrokeAlphaForState(start_state), | 215 progress, ThumbStrokeAlphaForState(start_state), |
| 205 ThumbStrokeAlphaForState(end_state)); | 216 ThumbStrokeAlphaForState(end_state)); |
| 206 SkPaint paint; | 217 SkPaint paint; |
| 207 paint.setColor(SkColorSetA(SK_ColorWHITE, stroke_alpha)); | 218 paint.setColor(SkColorSetA(kMDScrollbarStrokeColor, stroke_alpha)); |
| 208 paint.setStyle(SkPaint::kStroke_Style); | 219 paint.setStyle(SkPaint::kStroke_Style); |
| 209 paint.setStrokeWidth(kStrokeWidth); | 220 paint.setStrokeWidth(kStrokeWidth); |
| 221 |
| 222 // When stroking in skia, there's some surprising behavior so we need to |
| 223 // inset the right and bottom edges first. See the discussion here: |
| 224 // https://groups.google.com/forum/#!topic/skia-discuss/HGZcc3Z7w1Q |
| 225 thumb_rect.Inset(0, 0, kStrokeWidth, kStrokeWidth); |
| 210 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 226 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
| 211 | 227 |
| 212 thumb_rect.Inset(kStrokeWidth, kStrokeWidth, kStrokeWidth, kStrokeWidth); | 228 // Inset the top and left edges for filling in the stroke below. |
| 229 thumb_rect.Inset(kStrokeWidth, kStrokeWidth, 0, 0); |
| 230 |
| 231 // thumb_color = kMDScrollbarThumbColor; |
| 232 if (style == ScrollbarOverlayStyleLight) |
| 233 thumb_color = SK_ColorWHITE; |
| 234 else |
| 235 thumb_color = SK_ColorBLACK; |
| 213 } else { | 236 } else { |
| 214 // If there are no scrollbuttons then provide some padding so that the thumb | 237 // If there are no scrollbuttons then provide some padding so that the thumb |
| 215 // doesn't touch the top of the track. | 238 // doesn't touch the top of the track. |
| 216 const int kThumbPadding = 2; | 239 const int kThumbPadding = 2; |
| 217 const int extra_padding = | 240 const int extra_padding = |
| 218 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 241 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
| 219 if (part == NativeTheme::kScrollbarVerticalThumb) | 242 if (part == NativeTheme::kScrollbarVerticalThumb) |
| 220 thumb_rect.Inset(kThumbPadding, extra_padding); | 243 thumb_rect.Inset(kThumbPadding, extra_padding); |
| 221 else | 244 else |
| 222 thumb_rect.Inset(extra_padding, kThumbPadding); | 245 thumb_rect.Inset(extra_padding, kThumbPadding); |
| 246 |
| 247 thumb_color = SK_ColorBLACK; |
| 223 } | 248 } |
| 224 | 249 |
| 225 SkPaint paint; | 250 SkPaint paint; |
| 226 SkAlpha alpha = gfx::Tween::IntValueBetween( | 251 SkAlpha alpha = gfx::Tween::IntValueBetween( |
| 227 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state)); | 252 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state)); |
| 228 paint.setColor(SkColorSetA(SK_ColorBLACK, alpha)); | 253 paint.setColor(SkColorSetA(thumb_color, alpha)); |
| 229 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 254 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
| 230 } | 255 } |
| 231 | 256 |
| 232 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 257 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
| 233 State state, | 258 State state, |
| 234 const gfx::Rect& rect) const { | 259 const gfx::Rect& rect) const { |
| 235 // Overlay Scrollbar should never paint a scrollbar corner. | 260 // Overlay Scrollbar should never paint a scrollbar corner. |
| 236 DCHECK(!IsOverlayScrollbarEnabled()); | 261 DCHECK(!IsOverlayScrollbarEnabled()); |
| 237 SkPaint paint; | 262 SkPaint paint; |
| 238 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); | 263 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
| 239 canvas->drawIRect(RectToSkIRect(rect), paint); | 264 canvas->drawIRect(RectToSkIRect(rect), paint); |
| 240 } | 265 } |
| 241 | 266 |
| 242 } // namespace ui | 267 } // namespace ui |
| OLD | NEW |