Chromium Code Reviews| 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 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 179 cc::PaintFlags flags; | 179 cc::PaintFlags flags; |
| 180 flags.setColor(kTrackColor); | 180 flags.setColor(kTrackColor); |
| 181 canvas->drawIRect(gfx::RectToSkIRect(rect), flags); | 181 canvas->drawIRect(gfx::RectToSkIRect(rect), flags); |
| 182 } | 182 } |
| 183 | 183 |
| 184 void NativeThemeAura::PaintScrollbarThumb( | 184 void NativeThemeAura::PaintScrollbarThumb( |
| 185 cc::PaintCanvas* canvas, | 185 cc::PaintCanvas* canvas, |
| 186 Part part, | 186 Part part, |
| 187 State state, | 187 State state, |
| 188 const gfx::Rect& rect, | 188 const gfx::Rect& rect, |
| 189 ScrollbarOverlayColorTheme theme) const { | 189 const NativeTheme::ScrollbarThumbExtraParams& params) const { |
| 190 // Do not paint if state is disabled. | 190 // Do not paint if state is disabled. |
| 191 if (state == kDisabled) | 191 if (state == kDisabled) |
| 192 return; | 192 return; |
| 193 | 193 |
| 194 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 194 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
| 195 | 195 |
| 196 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | 196 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
| 197 gfx::Rect thumb_rect(rect); | 197 gfx::Rect thumb_rect(rect); |
| 198 SkColor thumb_color; | 198 SkColor thumb_color; |
| 199 | 199 |
| 200 if (use_overlay_scrollbars_) { | 200 if (use_overlay_scrollbars_) { |
| 201 // Constants used for painting overlay scrollbar thumb. | 201 // Constants used for painting overlay scrollbar thumb. |
| 202 constexpr SkAlpha kOverlayScrollbarFillAlphaNormal = 0x4D; | 202 constexpr SkAlpha kOverlayScrollbarFillAlphaNormal = 0x4D; |
| 203 constexpr SkAlpha kOverlayScrollbarFillAlphaHovered = 0x80; | 203 constexpr SkAlpha kOverlayScrollbarFillAlphaHovered = 0x80; |
| 204 constexpr SkAlpha kOverlayScrollbarFillAlphaPressed = 0x80; | 204 constexpr SkAlpha kOverlayScrollbarFillAlphaPressed = 0x80; |
| 205 constexpr SkAlpha kOverlayScrollbarStrokeAlphaNormal = 0x4D; | 205 constexpr SkAlpha kOverlayScrollbarStrokeAlphaNormal = 0x4D; |
| 206 constexpr SkAlpha kOverlayScrollbarStrokeAlphaHovered = 0x58; | 206 constexpr SkAlpha kOverlayScrollbarStrokeAlphaHovered = 0x58; |
| 207 constexpr SkAlpha kOverlayScrollbarStrokeAlphaPressed = 0x80; | 207 constexpr SkAlpha kOverlayScrollbarStrokeAlphaPressed = 0x80; |
| 208 | 208 |
| 209 // Indexed by ScrollbarOverlayColorTheme. | 209 // Indexed by ScrollbarOverlayColorTheme. |
| 210 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | 210 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
| 211 SK_ColorWHITE}; | 211 SK_ColorWHITE}; |
| 212 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | 212 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
| 213 SK_ColorBLACK}; | 213 SK_ColorBLACK}; |
| 214 | 214 |
| 215 thumb_color = kOverlayScrollbarThumbColor[theme]; | 215 thumb_color = kOverlayScrollbarThumbColor[params.scrollbar_theme]; |
| 216 | 216 |
| 217 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; | 217 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; |
| 218 switch (state) { | 218 switch (state) { |
| 219 case NativeTheme::kDisabled: | 219 case NativeTheme::kDisabled: |
| 220 thumb_alpha = SK_AlphaTRANSPARENT; | 220 thumb_alpha = SK_AlphaTRANSPARENT; |
| 221 stroke_alpha = SK_AlphaTRANSPARENT; | 221 stroke_alpha = SK_AlphaTRANSPARENT; |
| 222 break; | 222 break; |
| 223 case NativeTheme::kHovered: | 223 case NativeTheme::kHovered: |
| 224 thumb_alpha = kOverlayScrollbarFillAlphaHovered; | 224 thumb_alpha = kOverlayScrollbarFillAlphaHovered; |
| 225 stroke_alpha = kOverlayScrollbarStrokeAlphaHovered; | 225 stroke_alpha = kOverlayScrollbarStrokeAlphaHovered; |
| 226 break; | 226 break; |
| 227 case NativeTheme::kNormal: | 227 case NativeTheme::kNormal: |
| 228 thumb_alpha = kOverlayScrollbarFillAlphaNormal; | 228 thumb_alpha = kOverlayScrollbarFillAlphaNormal; |
| 229 stroke_alpha = kOverlayScrollbarStrokeAlphaNormal; | 229 stroke_alpha = kOverlayScrollbarStrokeAlphaNormal; |
| 230 break; | 230 break; |
| 231 case NativeTheme::kPressed: | 231 case NativeTheme::kPressed: |
| 232 thumb_alpha = kOverlayScrollbarFillAlphaPressed; | 232 thumb_alpha = kOverlayScrollbarFillAlphaPressed; |
| 233 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; | 233 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; |
| 234 break; | 234 break; |
| 235 case NativeTheme::kNumStates: | 235 case NativeTheme::kNumStates: |
| 236 NOTREACHED(); | 236 NOTREACHED(); |
| 237 break; | 237 break; |
| 238 } | 238 } |
| 239 | 239 |
| 240 // In overlay mode, draw a stroke (border). | 240 // In overlay mode, draw a stroke (border). |
| 241 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 241 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
| 242 cc::PaintFlags flags; | 242 cc::PaintFlags flags; |
| 243 flags.setColor( | 243 flags.setColor(SkColorSetA( |
| 244 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); | 244 kOverlayScrollbarStrokeColor[params.scrollbar_theme], stroke_alpha)); |
| 245 flags.setStyle(cc::PaintFlags::kStroke_Style); | 245 flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 246 flags.setStrokeWidth(kStrokeWidth); | 246 flags.setStrokeWidth(kStrokeWidth); |
| 247 | 247 |
| 248 int leftStrokeWidth, topStrokeWidth, rightStrokeWidth, bottomStrokeWidth; | |
| 249 leftStrokeWidth = topStrokeWidth = rightStrokeWidth = bottomStrokeWidth = | |
| 250 kStrokeWidth; | |
| 251 | |
| 252 // Flush the stroke when it close to border. | |
|
bokan
2017/03/23 21:34:41
A better comment would be "The edge to which the s
| |
| 253 if (part == NativeTheme::kScrollbarVerticalThumb) { | |
| 254 if (params.isLeftVerticalScrollbar) | |
| 255 leftStrokeWidth = 0; | |
| 256 else | |
| 257 rightStrokeWidth = 0; | |
| 258 } else { | |
| 259 bottomStrokeWidth = 0; | |
| 260 } | |
| 261 | |
| 248 gfx::RectF stroke_rect(thumb_rect); | 262 gfx::RectF stroke_rect(thumb_rect); |
| 249 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 263 stroke_rect.Inset(leftStrokeWidth / 2.f, topStrokeWidth / 2.f, |
|
bokan
2017/03/23 21:34:41
The drawRect call below is the one that draws the
| |
| 250 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 264 rightStrokeWidth / 2.f, bottomStrokeWidth / 2.f); |
| 251 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), flags); | 265 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), flags); |
| 252 | 266 |
| 253 // Inset the all the edges edges so we fill-in the stroke below. | 267 // Inset the all the edges edges so we fill-in the stroke below. |
| 254 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 268 thumb_rect.Inset(leftStrokeWidth, topStrokeWidth, rightStrokeWidth, |
| 269 bottomStrokeWidth); | |
| 255 } else { | 270 } else { |
| 256 switch (state) { | 271 switch (state) { |
| 257 case NativeTheme::kDisabled: | 272 case NativeTheme::kDisabled: |
| 258 thumb_alpha = SK_AlphaTRANSPARENT; | 273 thumb_alpha = SK_AlphaTRANSPARENT; |
| 259 break; | 274 break; |
| 260 case NativeTheme::kHovered: | 275 case NativeTheme::kHovered: |
| 261 thumb_alpha = 0x4D; | 276 thumb_alpha = 0x4D; |
| 262 break; | 277 break; |
| 263 case NativeTheme::kNormal: | 278 case NativeTheme::kNormal: |
| 264 thumb_alpha = 0x33; | 279 thumb_alpha = 0x33; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 340 | 355 |
| 341 gfx::Rect NativeThemeAura::GetNinePatchAperture(Part part) const { | 356 gfx::Rect NativeThemeAura::GetNinePatchAperture(Part part) const { |
| 342 DCHECK(SupportsNinePatch(part)); | 357 DCHECK(SupportsNinePatch(part)); |
| 343 | 358 |
| 344 return gfx::Rect( | 359 return gfx::Rect( |
| 345 kOverlayScrollbarBorderPatchWidth, kOverlayScrollbarBorderPatchWidth, | 360 kOverlayScrollbarBorderPatchWidth, kOverlayScrollbarBorderPatchWidth, |
| 346 kOverlayScrollbarCenterPatchSize, kOverlayScrollbarCenterPatchSize); | 361 kOverlayScrollbarCenterPatchSize, kOverlayScrollbarCenterPatchSize); |
| 347 } | 362 } |
| 348 | 363 |
| 349 } // namespace ui | 364 } // namespace ui |
| OLD | NEW |