| 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 15 matching lines...) Expand all Loading... |
| 26 #include "ui/native_theme/common_theme.h" | 26 #include "ui/native_theme/common_theme.h" |
| 27 #include "ui/native_theme/native_theme_switches.h" | 27 #include "ui/native_theme/native_theme_switches.h" |
| 28 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" | 28 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" |
| 29 | 29 |
| 30 namespace ui { | 30 namespace ui { |
| 31 | 31 |
| 32 namespace { | 32 namespace { |
| 33 | 33 |
| 34 // Constants for painting overlay scrollbars. Other properties needed outside | 34 // Constants for painting overlay scrollbars. Other properties needed outside |
| 35 // this painting code are defined in overlay_scrollbar_constants_aura.h. | 35 // this painting code are defined in overlay_scrollbar_constants_aura.h. |
| 36 constexpr int kOverlayScrollbarStrokeWidth = 1; | |
| 37 constexpr int kOverlayScrollbarMinimumLength = 32; | 36 constexpr int kOverlayScrollbarMinimumLength = 32; |
| 38 | 37 |
| 39 // 2 pixel border with 1 pixel center patch. The border is 2 pixels despite the | 38 // 2 pixel border with 1 pixel center patch. The border is 2 pixels despite the |
| 40 // stroke width being 1 so that the inner pixel can match the center tile | 39 // stroke width being 1 so that the inner pixel can match the center tile |
| 41 // color. This prevents color interpolation between the patches. | 40 // color. This prevents color interpolation between the patches. |
| 42 constexpr int kOverlayScrollbarBorderPatchWidth = 2; | 41 constexpr int kOverlayScrollbarBorderPatchWidth = 2; |
| 43 constexpr int kOverlayScrollbarCenterPatchSize = 1; | 42 constexpr int kOverlayScrollbarCenterPatchSize = 1; |
| 44 | 43 |
| 45 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | 44 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
| 46 | 45 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 66 | 65 |
| 67 NativeThemeAura::NativeThemeAura(bool use_overlay_scrollbars) | 66 NativeThemeAura::NativeThemeAura(bool use_overlay_scrollbars) |
| 68 : use_overlay_scrollbars_(use_overlay_scrollbars) { | 67 : use_overlay_scrollbars_(use_overlay_scrollbars) { |
| 69 // We don't draw scrollbar buttons. | 68 // We don't draw scrollbar buttons. |
| 70 #if defined(OS_CHROMEOS) | 69 #if defined(OS_CHROMEOS) |
| 71 set_scrollbar_button_length(0); | 70 set_scrollbar_button_length(0); |
| 72 #endif | 71 #endif |
| 73 | 72 |
| 74 if (use_overlay_scrollbars_) { | 73 if (use_overlay_scrollbars_) { |
| 75 scrollbar_width_ = | 74 scrollbar_width_ = |
| 76 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth * 2; | 75 kOverlayScrollbarThumbWidthPressed + kOverlayScrollbarStrokeWidth; |
| 77 } | 76 } |
| 78 | 77 |
| 79 // Images and alphas declarations assume the following order. | 78 // Images and alphas declarations assume the following order. |
| 80 static_assert(kDisabled == 0, "states unexpectedly changed"); | 79 static_assert(kDisabled == 0, "states unexpectedly changed"); |
| 81 static_assert(kHovered == 1, "states unexpectedly changed"); | 80 static_assert(kHovered == 1, "states unexpectedly changed"); |
| 82 static_assert(kNormal == 2, "states unexpectedly changed"); | 81 static_assert(kNormal == 2, "states unexpectedly changed"); |
| 83 static_assert(kPressed == 3, "states unexpectedly changed"); | 82 static_assert(kPressed == 3, "states unexpectedly changed"); |
| 84 } | 83 } |
| 85 | 84 |
| 86 NativeThemeAura::~NativeThemeAura() {} | 85 NativeThemeAura::~NativeThemeAura() {} |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 192 if (state == kDisabled) | 191 if (state == kDisabled) |
| 193 return; | 192 return; |
| 194 | 193 |
| 195 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 194 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
| 196 | 195 |
| 197 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | 196 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
| 198 gfx::Rect thumb_rect(rect); | 197 gfx::Rect thumb_rect(rect); |
| 199 SkColor thumb_color; | 198 SkColor thumb_color; |
| 200 | 199 |
| 201 if (use_overlay_scrollbars_) { | 200 if (use_overlay_scrollbars_) { |
| 202 // Constants used for painting overlay scrollbar thumb. | |
| 203 constexpr SkAlpha kOverlayScrollbarFillAlphaNormal = 0x80; | |
| 204 constexpr SkAlpha kOverlayScrollbarFillAlphaHovered = 0xB3; | |
| 205 constexpr SkAlpha kOverlayScrollbarFillAlphaPressed = 0xB3; | |
| 206 constexpr SkAlpha kOverlayScrollbarStrokeAlphaNormal = 0x4D; | |
| 207 constexpr SkAlpha kOverlayScrollbarStrokeAlphaHovered = 0x80; | |
| 208 constexpr SkAlpha kOverlayScrollbarStrokeAlphaPressed = 0x80; | |
| 209 | |
| 210 // Indexed by ScrollbarOverlayColorTheme. | 201 // Indexed by ScrollbarOverlayColorTheme. |
| 211 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | 202 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
| 212 SK_ColorWHITE}; | 203 SK_ColorWHITE}; |
| 213 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | 204 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
| 214 SK_ColorBLACK}; | 205 SK_ColorBLACK}; |
| 215 | 206 |
| 216 thumb_color = kOverlayScrollbarThumbColor[theme]; | 207 thumb_color = kOverlayScrollbarThumbColor[theme]; |
| 217 | 208 |
| 218 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; | 209 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; |
| 219 switch (state) { | 210 switch (state) { |
| 220 case NativeTheme::kDisabled: | 211 case NativeTheme::kDisabled: |
| 221 thumb_alpha = SK_AlphaTRANSPARENT; | 212 thumb_alpha = SK_AlphaTRANSPARENT; |
| 222 stroke_alpha = SK_AlphaTRANSPARENT; | 213 stroke_alpha = SK_AlphaTRANSPARENT; |
| 223 break; | 214 break; |
| 224 case NativeTheme::kHovered: | 215 case NativeTheme::kHovered: |
| 225 thumb_alpha = kOverlayScrollbarFillAlphaHovered; | 216 thumb_alpha = SK_AlphaOPAQUE * kOverlayScrollbarThumbHoverAlpha; |
| 226 stroke_alpha = kOverlayScrollbarStrokeAlphaHovered; | 217 stroke_alpha = SK_AlphaOPAQUE * kOverlayScrollbarStrokeHoverAlpha; |
| 227 break; | 218 break; |
| 228 case NativeTheme::kNormal: | 219 case NativeTheme::kNormal: |
| 229 thumb_alpha = kOverlayScrollbarFillAlphaNormal; | 220 thumb_alpha = SK_AlphaOPAQUE * kOverlayScrollbarThumbNormalAlpha; |
| 230 stroke_alpha = kOverlayScrollbarStrokeAlphaNormal; | 221 stroke_alpha = SK_AlphaOPAQUE * kOverlayScrollbarStrokeNormalAlpha; |
| 231 break; | 222 break; |
| 232 case NativeTheme::kPressed: | 223 case NativeTheme::kPressed: |
| 233 thumb_alpha = kOverlayScrollbarFillAlphaPressed; | 224 thumb_alpha = SK_AlphaOPAQUE * kOverlayScrollbarThumbHoverAlpha; |
| 234 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; | 225 stroke_alpha = SK_AlphaOPAQUE * kOverlayScrollbarStrokeHoverAlpha; |
| 235 break; | 226 break; |
| 236 case NativeTheme::kNumStates: | 227 case NativeTheme::kNumStates: |
| 237 NOTREACHED(); | 228 NOTREACHED(); |
| 238 break; | 229 break; |
| 239 } | 230 } |
| 240 | 231 |
| 241 // In overlay mode, draw a stroke (border). | 232 // In overlay mode, draw a stroke (border). |
| 242 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 233 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
| 243 cc::PaintFlags flags; | 234 cc::PaintFlags flags; |
| 244 flags.setColor( | 235 flags.setColor( |
| 245 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); | 236 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); |
| 246 flags.setStyle(cc::PaintFlags::kStroke_Style); | 237 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 247 flags.setStrokeWidth(kStrokeWidth); | 238 flags.setStrokeWidth(kStrokeWidth); |
| 248 | 239 |
| 249 gfx::RectF stroke_rect(thumb_rect); | 240 gfx::RectF stroke_rect(thumb_rect); |
| 250 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 241 gfx::InsetsF stroke_insets(kStrokeWidth / 2.f); |
| 251 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 242 // The edge to which the scrollbar is attached shouldn't have a border. |
| 243 gfx::Insets edge_adjust_insets; |
| 244 if (part == NativeTheme::kScrollbarHorizontalThumb) |
| 245 edge_adjust_insets = gfx::Insets(0, 0, -kStrokeWidth, 0); |
| 246 else |
| 247 edge_adjust_insets = gfx::Insets(0, 0, 0, -kStrokeWidth); |
| 248 stroke_rect.Inset(stroke_insets + edge_adjust_insets); |
| 252 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), flags); | 249 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), flags); |
| 253 | 250 |
| 254 // Inset the all the edges edges so we fill-in the stroke below. | 251 // Inset the all the edges edges so we fill-in the stroke below. |
| 255 // The edge to which the scrollbar is attached shouldn't have a border. | |
| 256 // For left vertical scrollbar, we will horizontally flip the canvas in | 252 // For left vertical scrollbar, we will horizontally flip the canvas in |
| 257 // ScrollbarThemeOverlay::paintThumb. | 253 // ScrollbarThemeOverlay::paintThumb. |
| 258 gfx::Insets insets(kStrokeWidth); | 254 gfx::Insets fill_insets(kStrokeWidth); |
| 259 if (part == NativeTheme::kScrollbarHorizontalThumb) | 255 thumb_rect.Inset(fill_insets + edge_adjust_insets); |
| 260 insets -= gfx::Insets(0, 0, kStrokeWidth, 0); | |
| 261 else | |
| 262 insets -= gfx::Insets(0, 0, 0, kStrokeWidth); | |
| 263 | |
| 264 thumb_rect.Inset(insets); | |
| 265 } else { | 256 } else { |
| 266 switch (state) { | 257 switch (state) { |
| 267 case NativeTheme::kDisabled: | 258 case NativeTheme::kDisabled: |
| 268 thumb_alpha = SK_AlphaTRANSPARENT; | 259 thumb_alpha = SK_AlphaTRANSPARENT; |
| 269 break; | 260 break; |
| 270 case NativeTheme::kHovered: | 261 case NativeTheme::kHovered: |
| 271 thumb_alpha = 0x4D; | 262 thumb_alpha = 0x4D; |
| 272 break; | 263 break; |
| 273 case NativeTheme::kNormal: | 264 case NativeTheme::kNormal: |
| 274 thumb_alpha = 0x33; | 265 thumb_alpha = 0x33; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 350 | 341 |
| 351 gfx::Rect NativeThemeAura::GetNinePatchAperture(Part part) const { | 342 gfx::Rect NativeThemeAura::GetNinePatchAperture(Part part) const { |
| 352 DCHECK(SupportsNinePatch(part)); | 343 DCHECK(SupportsNinePatch(part)); |
| 353 | 344 |
| 354 return gfx::Rect( | 345 return gfx::Rect( |
| 355 kOverlayScrollbarBorderPatchWidth, kOverlayScrollbarBorderPatchWidth, | 346 kOverlayScrollbarBorderPatchWidth, kOverlayScrollbarBorderPatchWidth, |
| 356 kOverlayScrollbarCenterPatchSize, kOverlayScrollbarCenterPatchSize); | 347 kOverlayScrollbarCenterPatchSize, kOverlayScrollbarCenterPatchSize); |
| 357 } | 348 } |
| 358 | 349 |
| 359 } // namespace ui | 350 } // namespace ui |
| OLD | NEW |