| 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 constexpr float kIconScaleFactor = 0.5; |
| 22 const SkColor kBackgroundColorHover = 0xFFE5E5E5; | |
| 23 const SkColor kBackgroundColorDown = 0xFFD5D5D5; | |
| 24 const SkColor kForegroundColor = 0xFF444444; | |
| 25 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 |
| 33 void CloseButtonTexture::Draw(SkCanvas* sk_canvas, | 30 void CloseButtonTexture::Draw(SkCanvas* sk_canvas, |
| 34 const gfx::Size& texture_size) { | 31 const gfx::Size& texture_size) { |
| 35 DCHECK_EQ(texture_size.height(), texture_size.width()); | 32 DCHECK_EQ(texture_size.height(), texture_size.width()); |
| 36 cc::SkiaPaintCanvas paint_canvas(sk_canvas); | 33 cc::SkiaPaintCanvas paint_canvas(sk_canvas); |
| 37 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); | 34 gfx::Canvas gfx_canvas(&paint_canvas, 1.0f); |
| 38 gfx::Canvas* canvas = &gfx_canvas; | 35 gfx::Canvas* canvas = &gfx_canvas; |
| 39 | 36 |
| 40 size_.set_height(texture_size.height()); | 37 size_.set_height(texture_size.height()); |
| 41 size_.set_width(texture_size.width()); | 38 size_.set_width(texture_size.width()); |
| 42 | 39 |
| 43 cc::PaintFlags flags; | 40 cc::PaintFlags flags; |
| 44 SkColor color = hovered() ? kBackgroundColorHover : kBackgroundColor; | 41 SkColor color = hovered() ? color_scheme().element_background_hover |
| 45 color = pressed() ? kBackgroundColorDown : color; | 42 : color_scheme().element_background; |
| 43 color = pressed() ? color_scheme().element_background_down : color; |
| 46 flags.setColor(color); | 44 flags.setColor(color); |
| 47 canvas->DrawCircle(gfx::PointF(size_.width() / 2, size_.height() / 2), | 45 canvas->DrawCircle(gfx::PointF(size_.width() / 2, size_.height() / 2), |
| 48 size_.width() / 2, flags); | 46 size_.width() / 2, flags); |
| 49 | 47 |
| 50 canvas->Save(); | 48 canvas->Save(); |
| 51 canvas->Translate(gfx::Vector2d(size_.height() * (1 - kIconScaleFactor) / 2, | 49 canvas->Translate(gfx::Vector2d(size_.height() * (1 - kIconScaleFactor) / 2, |
| 52 size_.height() * (1 - kIconScaleFactor) / 2)); | 50 size_.height() * (1 - kIconScaleFactor) / 2)); |
| 53 PaintVectorIcon(canvas, ui::kCloseIcon, size_.height() * kIconScaleFactor, | 51 PaintVectorIcon(canvas, ui::kCloseIcon, size_.height() * kIconScaleFactor, |
| 54 kForegroundColor); | 52 color_scheme().element_foreground); |
| 55 canvas->Restore(); | 53 canvas->Restore(); |
| 56 } | 54 } |
| 57 | 55 |
| 58 gfx::Size CloseButtonTexture::GetPreferredTextureSize(int maximum_width) const { | 56 gfx::Size CloseButtonTexture::GetPreferredTextureSize(int maximum_width) const { |
| 59 return gfx::Size(maximum_width, maximum_width); | 57 return gfx::Size(maximum_width, maximum_width); |
| 60 } | 58 } |
| 61 | 59 |
| 62 gfx::SizeF CloseButtonTexture::GetDrawnSize() const { | 60 gfx::SizeF CloseButtonTexture::GetDrawnSize() const { |
| 63 return size_; | 61 return size_; |
| 64 } | 62 } |
| 65 | 63 |
| 66 bool CloseButtonTexture::HitTest(const gfx::PointF& point) const { | 64 bool CloseButtonTexture::HitTest(const gfx::PointF& point) const { |
| 67 return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25; | 65 return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25; |
| 68 } | 66 } |
| 69 | 67 |
| 70 } // namespace vr_shell | 68 } // namespace vr_shell |
| OLD | NEW |