| 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 "base/trace_event/trace_event.h" | 11 #include "base/trace_event/trace_event.h" |
| 12 #include "build/build_config.h" | 12 #include "build/build_config.h" |
| 13 #include "cc/paint/paint_canvas.h" |
| 14 #include "cc/paint/paint_flags.h" |
| 13 #include "ui/base/layout.h" | 15 #include "ui/base/layout.h" |
| 14 #include "ui/base/material_design/material_design_controller.h" | 16 #include "ui/base/material_design/material_design_controller.h" |
| 15 #include "ui/gfx/animation/tween.h" | 17 #include "ui/gfx/animation/tween.h" |
| 16 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/color_palette.h" | 19 #include "ui/gfx/color_palette.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 19 #include "ui/gfx/geometry/size.h" | 21 #include "ui/gfx/geometry/size.h" |
| 20 #include "ui/gfx/image/image_skia.h" | 22 #include "ui/gfx/image/image_skia.h" |
| 21 #include "ui/gfx/path.h" | 23 #include "ui/gfx/path.h" |
| 22 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 (IsOverlayScrollbarEnabled())); | 90 (IsOverlayScrollbarEnabled())); |
| 89 return &s_native_theme_for_web; | 91 return &s_native_theme_for_web; |
| 90 } | 92 } |
| 91 | 93 |
| 92 // This implementation returns hardcoded colors. | 94 // This implementation returns hardcoded colors. |
| 93 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { | 95 SkColor NativeThemeAura::GetSystemColor(ColorId color_id) const { |
| 94 return GetAuraColor(color_id, this); | 96 return GetAuraColor(color_id, this); |
| 95 } | 97 } |
| 96 | 98 |
| 97 void NativeThemeAura::PaintMenuPopupBackground( | 99 void NativeThemeAura::PaintMenuPopupBackground( |
| 98 SkCanvas* canvas, | 100 cc::PaintCanvas* canvas, |
| 99 const gfx::Size& size, | 101 const gfx::Size& size, |
| 100 const MenuBackgroundExtraParams& menu_background) const { | 102 const MenuBackgroundExtraParams& menu_background) const { |
| 101 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); | 103 SkColor color = GetSystemColor(NativeTheme::kColorId_MenuBackgroundColor); |
| 102 if (menu_background.corner_radius > 0) { | 104 if (menu_background.corner_radius > 0) { |
| 103 SkPaint paint; | 105 cc::PaintFlags paint; |
| 104 paint.setStyle(SkPaint::kFill_Style); | 106 paint.setStyle(cc::PaintFlags::kFill_Style); |
| 105 paint.setFlags(SkPaint::kAntiAlias_Flag); | 107 paint.setAntiAlias(true); |
| 106 paint.setColor(color); | 108 paint.setColor(color); |
| 107 | 109 |
| 108 gfx::Path path; | 110 gfx::Path path; |
| 109 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), | 111 SkRect rect = SkRect::MakeWH(SkIntToScalar(size.width()), |
| 110 SkIntToScalar(size.height())); | 112 SkIntToScalar(size.height())); |
| 111 SkScalar radius = SkIntToScalar(menu_background.corner_radius); | 113 SkScalar radius = SkIntToScalar(menu_background.corner_radius); |
| 112 SkScalar radii[8] = {radius, radius, radius, radius, | 114 SkScalar radii[8] = {radius, radius, radius, radius, |
| 113 radius, radius, radius, radius}; | 115 radius, radius, radius, radius}; |
| 114 path.addRoundRect(rect, radii); | 116 path.addRoundRect(rect, radii); |
| 115 | 117 |
| 116 canvas->drawPath(path, paint); | 118 canvas->drawPath(path, paint); |
| 117 } else { | 119 } else { |
| 118 canvas->drawColor(color, SkBlendMode::kSrc); | 120 canvas->drawColor(color, SkBlendMode::kSrc); |
| 119 } | 121 } |
| 120 } | 122 } |
| 121 | 123 |
| 122 void NativeThemeAura::PaintMenuItemBackground( | 124 void NativeThemeAura::PaintMenuItemBackground( |
| 123 SkCanvas* canvas, | 125 cc::PaintCanvas* canvas, |
| 124 State state, | 126 State state, |
| 125 const gfx::Rect& rect, | 127 const gfx::Rect& rect, |
| 126 const MenuItemExtraParams& menu_item) const { | 128 const MenuItemExtraParams& menu_item) const { |
| 127 CommonThemePaintMenuItemBackground(this, canvas, state, rect, menu_item); | 129 CommonThemePaintMenuItemBackground(this, canvas, state, rect, menu_item); |
| 128 } | 130 } |
| 129 | 131 |
| 130 void NativeThemeAura::PaintArrowButton(SkCanvas* canvas, | 132 void NativeThemeAura::PaintArrowButton(cc::PaintCanvas* canvas, |
| 131 const gfx::Rect& rect, | 133 const gfx::Rect& rect, |
| 132 Part direction, | 134 Part direction, |
| 133 State state) const { | 135 State state) const { |
| 134 SkColor bg_color = kTrackColor; | 136 SkColor bg_color = kTrackColor; |
| 135 // Aura-win uses slightly different arrow colors. | 137 // Aura-win uses slightly different arrow colors. |
| 136 SkColor arrow_color = gfx::kPlaceholderColor; | 138 SkColor arrow_color = gfx::kPlaceholderColor; |
| 137 switch (state) { | 139 switch (state) { |
| 138 case kDisabled: | 140 case kDisabled: |
| 139 arrow_color = GetArrowColor(state); | 141 arrow_color = GetArrowColor(state); |
| 140 break; | 142 break; |
| 141 case kHovered: | 143 case kHovered: |
| 142 bg_color = SkColorSetRGB(0xD2, 0xD2, 0xD2); | 144 bg_color = SkColorSetRGB(0xD2, 0xD2, 0xD2); |
| 143 // Fall through. | 145 // Fall through. |
| 144 case kNormal: | 146 case kNormal: |
| 145 arrow_color = SkColorSetRGB(0x50, 0x50, 0x50); | 147 arrow_color = SkColorSetRGB(0x50, 0x50, 0x50); |
| 146 break; | 148 break; |
| 147 case kPressed: | 149 case kPressed: |
| 148 bg_color = SkColorSetRGB(0x78, 0x78, 0x78); | 150 bg_color = SkColorSetRGB(0x78, 0x78, 0x78); |
| 149 arrow_color = SK_ColorWHITE; | 151 arrow_color = SK_ColorWHITE; |
| 150 break; | 152 break; |
| 151 case kNumStates: | 153 case kNumStates: |
| 152 break; | 154 break; |
| 153 } | 155 } |
| 154 DCHECK_NE(arrow_color, gfx::kPlaceholderColor); | 156 DCHECK_NE(arrow_color, gfx::kPlaceholderColor); |
| 155 | 157 |
| 156 SkPaint paint; | 158 cc::PaintFlags paint; |
| 157 paint.setColor(bg_color); | 159 paint.setColor(bg_color); |
| 158 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 160 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| 159 | 161 |
| 160 PaintArrow(canvas, rect, direction, arrow_color); | 162 PaintArrow(canvas, rect, direction, arrow_color); |
| 161 } | 163 } |
| 162 | 164 |
| 163 void NativeThemeAura::PaintScrollbarTrack( | 165 void NativeThemeAura::PaintScrollbarTrack( |
| 164 SkCanvas* canvas, | 166 cc::PaintCanvas* canvas, |
| 165 Part part, | 167 Part part, |
| 166 State state, | 168 State state, |
| 167 const ScrollbarTrackExtraParams& extra_params, | 169 const ScrollbarTrackExtraParams& extra_params, |
| 168 const gfx::Rect& rect) const { | 170 const gfx::Rect& rect) const { |
| 169 // Overlay Scrollbar should never paint a scrollbar track. | 171 // Overlay Scrollbar should never paint a scrollbar track. |
| 170 DCHECK(!use_overlay_scrollbars_); | 172 DCHECK(!use_overlay_scrollbars_); |
| 171 SkPaint paint; | 173 cc::PaintFlags paint; |
| 172 paint.setColor(kTrackColor); | 174 paint.setColor(kTrackColor); |
| 173 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 175 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
| 174 } | 176 } |
| 175 | 177 |
| 176 void NativeThemeAura::PaintScrollbarThumb( | 178 void NativeThemeAura::PaintScrollbarThumb( |
| 177 SkCanvas* canvas, | 179 cc::PaintCanvas* canvas, |
| 178 Part part, | 180 Part part, |
| 179 State state, | 181 State state, |
| 180 const gfx::Rect& rect, | 182 const gfx::Rect& rect, |
| 181 ScrollbarOverlayColorTheme theme) const { | 183 ScrollbarOverlayColorTheme theme) const { |
| 182 // Do not paint if state is disabled. | 184 // Do not paint if state is disabled. |
| 183 if (state == kDisabled) | 185 if (state == kDisabled) |
| 184 return; | 186 return; |
| 185 | 187 |
| 186 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 188 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
| 187 | 189 |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 thumb_alpha = kOverlayScrollbarFillAlphaPressed; | 226 thumb_alpha = kOverlayScrollbarFillAlphaPressed; |
| 225 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; | 227 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; |
| 226 break; | 228 break; |
| 227 case NativeTheme::kNumStates: | 229 case NativeTheme::kNumStates: |
| 228 NOTREACHED(); | 230 NOTREACHED(); |
| 229 break; | 231 break; |
| 230 } | 232 } |
| 231 | 233 |
| 232 // In overlay mode, draw a stroke (border). | 234 // In overlay mode, draw a stroke (border). |
| 233 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 235 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
| 234 SkPaint paint; | 236 cc::PaintFlags paint; |
| 235 paint.setColor( | 237 paint.setColor( |
| 236 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); | 238 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); |
| 237 paint.setStyle(SkPaint::kStroke_Style); | 239 paint.setStyle(cc::PaintFlags::kStroke_Style); |
| 238 paint.setStrokeWidth(kStrokeWidth); | 240 paint.setStrokeWidth(kStrokeWidth); |
| 239 | 241 |
| 240 gfx::RectF stroke_rect(thumb_rect); | 242 gfx::RectF stroke_rect(thumb_rect); |
| 241 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 243 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
| 242 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 244 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
| 243 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 245 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
| 244 | 246 |
| 245 // Inset the all the edges edges so we fill-in the stroke below. | 247 // Inset the all the edges edges so we fill-in the stroke below. |
| 246 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 248 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
| 247 } else { | 249 } else { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 268 const int extra_padding = | 270 const int extra_padding = |
| 269 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 271 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
| 270 if (part == NativeTheme::kScrollbarVerticalThumb) | 272 if (part == NativeTheme::kScrollbarVerticalThumb) |
| 271 thumb_rect.Inset(kThumbPadding, extra_padding); | 273 thumb_rect.Inset(kThumbPadding, extra_padding); |
| 272 else | 274 else |
| 273 thumb_rect.Inset(extra_padding, kThumbPadding); | 275 thumb_rect.Inset(extra_padding, kThumbPadding); |
| 274 | 276 |
| 275 thumb_color = SK_ColorBLACK; | 277 thumb_color = SK_ColorBLACK; |
| 276 } | 278 } |
| 277 | 279 |
| 278 SkPaint paint; | 280 cc::PaintFlags paint; |
| 279 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); | 281 paint.setColor(SkColorSetA(thumb_color, thumb_alpha)); |
| 280 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); | 282 canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint); |
| 281 } | 283 } |
| 282 | 284 |
| 283 void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas, | 285 void NativeThemeAura::PaintScrollbarCorner(cc::PaintCanvas* canvas, |
| 284 State state, | 286 State state, |
| 285 const gfx::Rect& rect) const { | 287 const gfx::Rect& rect) const { |
| 286 // Overlay Scrollbar should never paint a scrollbar corner. | 288 // Overlay Scrollbar should never paint a scrollbar corner. |
| 287 DCHECK(!use_overlay_scrollbars_); | 289 DCHECK(!use_overlay_scrollbars_); |
| 288 SkPaint paint; | 290 cc::PaintFlags paint; |
| 289 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); | 291 paint.setColor(SkColorSetRGB(0xDC, 0xDC, 0xDC)); |
| 290 canvas->drawIRect(RectToSkIRect(rect), paint); | 292 canvas->drawIRect(RectToSkIRect(rect), paint); |
| 291 } | 293 } |
| 292 | 294 |
| 293 gfx::Size NativeThemeAura::GetPartSize(Part part, | 295 gfx::Size NativeThemeAura::GetPartSize(Part part, |
| 294 State state, | 296 State state, |
| 295 const ExtraParams& extra) const { | 297 const ExtraParams& extra) const { |
| 296 if (use_overlay_scrollbars_) { | 298 if (use_overlay_scrollbars_) { |
| 297 constexpr int minimum_length = | 299 constexpr int minimum_length = |
| 298 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; | 300 kOverlayScrollbarMinimumLength + 2 * kOverlayScrollbarStrokeWidth; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 309 // scrollbars isn't asking for part sizes that don't exist. | 311 // scrollbars isn't asking for part sizes that don't exist. |
| 310 // crbug.com/657159. | 312 // crbug.com/657159. |
| 311 break; | 313 break; |
| 312 } | 314 } |
| 313 } | 315 } |
| 314 | 316 |
| 315 return NativeThemeBase::GetPartSize(part, state, extra); | 317 return NativeThemeBase::GetPartSize(part, state, extra); |
| 316 } | 318 } |
| 317 | 319 |
| 318 } // namespace ui | 320 } // namespace ui |
| OLD | NEW |