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 17 matching lines...) Expand all Loading... | |
| 28 | 28 |
| 29 namespace { | 29 namespace { |
| 30 | 30 |
| 31 // Constants for painting overlay scrollbars. Other properties needed outside | 31 // Constants for painting overlay scrollbars. Other properties needed outside |
| 32 // this painting code are defined in overlay_scrollbar_constants_aura.h. | 32 // this painting code are defined in overlay_scrollbar_constants_aura.h. |
| 33 constexpr int kOverlayScrollbarStrokeWidth = 1; | 33 constexpr int kOverlayScrollbarStrokeWidth = 1; |
| 34 constexpr int kOverlayScrollbarMinimumLength = 12; | 34 constexpr int kOverlayScrollbarMinimumLength = 12; |
| 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 constexpr SkColor kOverlayScrollbarThumbColor = SK_ColorBLACK; | 38 constexpr SkColor kOverlayScrollbarThumbDarkColor = SK_ColorBLACK; |
| 39 constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE; | 39 constexpr SkColor kOverlayScrollbarThumbLightColor = SK_ColorWHITE; |
| 40 constexpr SkColor kOverlayScrollbarStrokeDarkColor = SK_ColorWHITE; | |
| 41 constexpr SkColor kOverlayScrollbarStrokeLightColor = SK_ColorBLACK; | |
| 42 | |
| 40 | 43 |
| 41 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | 44 SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
| 42 bool overlay = IsOverlayScrollbarEnabled(); | 45 bool overlay = IsOverlayScrollbarEnabled(); |
| 43 switch (state) { | 46 switch (state) { |
| 44 case NativeTheme::kDisabled: | 47 case NativeTheme::kDisabled: |
| 45 return 0x00; | 48 return 0x00; |
| 46 case NativeTheme::kHovered: | 49 case NativeTheme::kHovered: |
| 47 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 50 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
| 48 case NativeTheme::kNormal: | 51 case NativeTheme::kNormal: |
| 49 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; | 52 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 170 State state, | 173 State state, |
| 171 const ScrollbarTrackExtraParams& extra_params, | 174 const ScrollbarTrackExtraParams& extra_params, |
| 172 const gfx::Rect& rect) const { | 175 const gfx::Rect& rect) const { |
| 173 // Overlay Scrollbar should never paint a scrollbar track. | 176 // Overlay Scrollbar should never paint a scrollbar track. |
| 174 DCHECK(!IsOverlayScrollbarEnabled()); | 177 DCHECK(!IsOverlayScrollbarEnabled()); |
| 175 SkPaint paint; | 178 SkPaint paint; |
| 176 paint.setColor(kTrackColor); | 179 paint.setColor(kTrackColor); |
| 177 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 180 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| 178 } | 181 } |
| 179 | 182 |
| 180 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | 183 void NativeThemeAura::PaintScrollbarThumb( |
| 181 Part part, | 184 SkCanvas* canvas, |
| 182 State state, | 185 Part part, |
| 183 const gfx::Rect& rect) const { | 186 State state, |
| 187 const gfx::Rect& rect, | |
| 188 ScrollbarOverlayColorTheme theme) const { | |
| 184 // Do not paint if state is disabled. | 189 // Do not paint if state is disabled. |
| 185 if (state == kDisabled) | 190 if (state == kDisabled) |
| 186 return; | 191 return; |
| 187 | 192 |
| 188 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); | 193 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
| 189 } | |
| 190 | 194 |
| 191 void NativeThemeAura::PaintScrollbarThumbStateTransition( | |
| 192 SkCanvas* canvas, | |
| 193 Part part, | |
| 194 State start_state, | |
| 195 State end_state, | |
| 196 double progress, | |
| 197 const gfx::Rect& rect) const { | |
| 198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); | |
| 199 gfx::Rect thumb_rect(rect); | 195 gfx::Rect thumb_rect(rect); |
| 200 SkColor thumb_color; | 196 SkColor thumb_color; |
| 197 double progress = 1.0; | |
|
bokan
2016/10/27 18:29:53
Remove this and the IntValueBetween calls since th
| |
| 198 | |
| 201 if (IsOverlayScrollbarEnabled()) { | 199 if (IsOverlayScrollbarEnabled()) { |
| 200 SkColor stroke_color; | |
| 201 if (theme == ScrollbarOverlayColorThemeLight) { | |
| 202 thumb_color = kOverlayScrollbarThumbLightColor; | |
| 203 stroke_color = kOverlayScrollbarStrokeLightColor; | |
| 204 } else { | |
| 205 thumb_color = kOverlayScrollbarThumbDarkColor; | |
| 206 stroke_color = kOverlayScrollbarStrokeDarkColor; | |
| 207 } | |
| 208 | |
| 202 // In overlay mode, draw a stroke (border). | 209 // In overlay mode, draw a stroke (border). |
| 203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 210 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
| 204 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( | 211 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( |
| 205 progress, ThumbAlphaForState(start_state), | 212 progress, ThumbAlphaForState(state), |
| 206 ThumbAlphaForState(end_state)); | 213 ThumbAlphaForState(state)); |
| 214 | |
| 207 SkPaint paint; | 215 SkPaint paint; |
| 208 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha)); | 216 paint.setColor(SkColorSetA(stroke_color, stroke_alpha)); |
| 209 paint.setStyle(SkPaint::kStroke_Style); | 217 paint.setStyle(SkPaint::kStroke_Style); |
| 210 paint.setStrokeWidth(kStrokeWidth); | 218 paint.setStrokeWidth(kStrokeWidth); |
| 211 | 219 |
| 212 gfx::RectF stroke_rect(thumb_rect); | 220 gfx::RectF stroke_rect(thumb_rect); |
| 213 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 221 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
| 214 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 222 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
| 215 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 223 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
| 216 | 224 |
| 217 // Inset the all the edges edges so we fill-in the stroke below. | 225 // Inset the all the edges edges so we fill-in the stroke below. |
| 218 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 226 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
| 219 thumb_color = kOverlayScrollbarThumbColor; | 227 |
| 220 } else { | 228 } else { |
| 221 // If there are no scrollbuttons then provide some padding so that the thumb | 229 // If there are no scrollbuttons then provide some padding so that the thumb |
| 222 // doesn't touch the top of the track. | 230 // doesn't touch the top of the track. |
| 223 const int kThumbPadding = 2; | 231 const int kThumbPadding = 2; |
| 224 const int extra_padding = | 232 const int extra_padding = |
| 225 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 233 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
| 226 if (part == NativeTheme::kScrollbarVerticalThumb) | 234 if (part == NativeTheme::kScrollbarVerticalThumb) |
| 227 thumb_rect.Inset(kThumbPadding, extra_padding); | 235 thumb_rect.Inset(kThumbPadding, extra_padding); |
| 228 else | 236 else |
| 229 thumb_rect.Inset(extra_padding, kThumbPadding); | 237 thumb_rect.Inset(extra_padding, kThumbPadding); |
| 230 | 238 |
| 231 thumb_color = SK_ColorBLACK; | 239 thumb_color = SK_ColorBLACK; |
| 232 } | 240 } |
| 233 | 241 |
| 234 SkPaint paint; | 242 SkPaint paint; |
| 235 SkAlpha alpha = gfx::Tween::IntValueBetween( | 243 SkAlpha alpha = gfx::Tween::IntValueBetween( |
| 236 progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state)); | 244 progress, ThumbAlphaForState(state), ThumbAlphaForState(state)); |
| 237 paint.setColor(SkColorSetA(thumb_color, alpha)); | 245 paint.setColor(SkColorSetA(thumb_color, alpha)); |
| 238 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 246 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
| 239 } | 247 } |
| 240 | 248 |
| 241 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 249 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, |
| 242 State state, | 250 State state, |
| 243 const gfx::Rect& rect) const { | 251 const gfx::Rect& rect) const { |
| 244 // Overlay Scrollbar should never paint a scrollbar corner. | 252 // Overlay Scrollbar should never paint a scrollbar corner. |
| 245 DCHECK(!IsOverlayScrollbarEnabled()); | 253 DCHECK(!IsOverlayScrollbarEnabled()); |
| 246 SkPaint paint; | 254 SkPaint paint; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 269 // branch return 0 for parts that don't exist or assert NOTREACHED. | 277 // branch return 0 for parts that don't exist or assert NOTREACHED. |
| 270 // crbug.com/657159. | 278 // crbug.com/657159. |
| 271 break; | 279 break; |
| 272 } | 280 } |
| 273 } | 281 } |
| 274 | 282 |
| 275 return NativeThemeBase::GetPartSize(part, state, extra); | 283 return NativeThemeBase::GetPartSize(part, state, extra); |
| 276 } | 284 } |
| 277 | 285 |
| 278 } // namespace ui | 286 } // namespace ui |
| OLD | NEW |