Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "chrome/browser/android/vr_shell/textures/close_button_texture.h" | 5 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" |
| 6 | 6 |
| 7 #include "cc/paint/skia_paint_canvas.h" | 7 #include "cc/paint/skia_paint_canvas.h" |
| 8 #include "chrome/browser/android/vr_shell/color_scheme.h" | |
| 8 #include "chrome/browser/android/vr_shell/ui_elements/button.h" | 9 #include "chrome/browser/android/vr_shell/ui_elements/button.h" |
| 9 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| 10 #include "ui/gfx/geometry/point_f.h" | 11 #include "ui/gfx/geometry/point_f.h" |
| 11 #include "ui/gfx/geometry/rect.h" | 12 #include "ui/gfx/geometry/rect.h" |
| 12 #include "ui/gfx/geometry/vector2d.h" | 13 #include "ui/gfx/geometry/vector2d.h" |
| 13 #include "ui/gfx/paint_vector_icon.h" | 14 #include "ui/gfx/paint_vector_icon.h" |
| 14 #include "ui/gfx/vector_icon_types.h" | 15 #include "ui/gfx/vector_icon_types.h" |
| 15 #include "ui/vector_icons/vector_icons.h" | 16 #include "ui/vector_icons/vector_icons.h" |
| 16 | 17 |
| 17 namespace vr_shell { | 18 namespace vr_shell { |
| 18 | 19 |
| 19 namespace { | 20 namespace { |
| 20 | 21 |
| 21 const SkColor kBackgroundColor = SK_ColorWHITE; | |
| 22 const SkColor kBackgroundColorHover = 0xFFE5E5E5; | |
| 23 const SkColor kBackgroundColorDown = 0xFFD5D5D5; | |
| 24 const SkColor kForegroundColor = 0xFF444444; | |
| 25 constexpr float kIconScaleFactor = 0.75; | 22 constexpr float kIconScaleFactor = 0.75; |
| 26 | 23 |
| 27 } // namespace | 24 } // namespace |
| 28 | 25 |
| 29 CloseButtonTexture::CloseButtonTexture() = default; | 26 CloseButtonTexture::CloseButtonTexture() = default; |
| 30 | 27 |
| 31 CloseButtonTexture::~CloseButtonTexture() = default; | 28 CloseButtonTexture::~CloseButtonTexture() = default; |
| 32 | 29 |
| 30 const ColorScheme& CloseButtonTexture::color_scheme() const { | |
| 31 return ColorScheme::GetColorScheme(mode()); | |
| 32 } | |
| 33 | |
| 33 void CloseButtonTexture::Draw(SkCanvas* sk_canvas, | 34 void CloseButtonTexture::Draw(SkCanvas* sk_canvas, |
| 34 const gfx::Size& texture_size) { | 35 const gfx::Size& texture_size) { |
| 35 DCHECK_EQ(texture_size.height(), texture_size.width()); | 36 DCHECK_EQ(texture_size.height(), texture_size.width()); |
| 36 cc::SkiaPaintCanvas paint_canvas(sk_canvas); | 37 cc::SkiaPaintCanvas paint_canvas(sk_canvas); |
| 37 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 38 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
| 38 gfx::Canvas* canvas = &gfx_canvas; | 39 gfx::Canvas* canvas = &gfx_canvas; |
| 39 | 40 |
| 40 size_.set_height(texture_size.height()); | 41 size_.set_height(texture_size.height()); |
| 41 size_.set_width(texture_size.width()); | 42 size_.set_width(texture_size.width()); |
| 42 | 43 |
| 43 cc::PaintFlags flags; | 44 cc::PaintFlags flags; |
| 44 SkColor color = hovered() ? kBackgroundColorHover : kBackgroundColor; | 45 SkColor color = hovered() ? color_scheme().element_background_hover |
|
cjgrant
2017/05/31 15:39:28
In a ymalik@ CL, another element changed this tern
amp
2017/06/02 01:08:35
I think I saw that but it felt like slightly diffe
| |
| 45 color = pressed() ? kBackgroundColorDown : color; | 46 : color_scheme().element_background; |
| 47 color = pressed() ? color_scheme().element_background_down : color; | |
| 46 flags.setColor(color); | 48 flags.setColor(color); |
| 47 canvas->DrawCircle(gfx::PointF(size_.width() / 2, size_.height() / 2), | 49 canvas->DrawCircle(gfx::PointF(size_.width() / 2, size_.height() / 2), |
| 48 size_.width() / 2, flags); | 50 size_.width() / 2, flags); |
| 49 | 51 |
| 50 canvas->Save(); | 52 canvas->Save(); |
| 51 canvas->Translate(gfx::Vector2d(size_.height() * (1 - kIconScaleFactor) / 2, | 53 canvas->Translate(gfx::Vector2d(size_.height() * (1 - kIconScaleFactor) / 2, |
| 52 size_.height() * (1 - kIconScaleFactor) / 2)); | 54 size_.height() * (1 - kIconScaleFactor) / 2)); |
| 53 PaintVectorIcon(canvas, ui::kCloseIcon, size_.height() * kIconScaleFactor, | 55 PaintVectorIcon(canvas, ui::kCloseIcon, size_.height() * kIconScaleFactor, |
| 54 kForegroundColor); | 56 color_scheme().element_foreground); |
| 55 canvas->Restore(); | 57 canvas->Restore(); |
| 56 } | 58 } |
| 57 | 59 |
| 58 gfx::Size CloseButtonTexture::GetPreferredTextureSize(int maximum_width) const { | 60 gfx::Size CloseButtonTexture::GetPreferredTextureSize(int maximum_width) const { |
| 59 return gfx::Size(maximum_width, maximum_width); | 61 return gfx::Size(maximum_width, maximum_width); |
| 60 } | 62 } |
| 61 | 63 |
| 62 gfx::SizeF CloseButtonTexture::GetDrawnSize() const { | 64 gfx::SizeF CloseButtonTexture::GetDrawnSize() const { |
| 63 return size_; | 65 return size_; |
| 64 } | 66 } |
| 65 | 67 |
| 66 bool CloseButtonTexture::HitTest(const gfx::PointF& point) const { | 68 bool CloseButtonTexture::HitTest(const gfx::PointF& point) const { |
| 67 return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25; | 69 return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25; |
| 68 } | 70 } |
| 69 | 71 |
| 70 } // namespace vr_shell | 72 } // namespace vr_shell |
| OLD | NEW |