OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/android/vr_shell/ui_elements/close_button.h" |
| 6 |
| 7 #include "base/memory/ptr_util.h" |
| 8 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" |
| 9 |
| 10 namespace vr_shell { |
| 11 |
| 12 CloseButton::CloseButton(base::Callback<void()> click_handler) |
| 13 : TexturedElement(256), |
| 14 texture_(base::MakeUnique<CloseButtonTexture>()), |
| 15 click_handler_(click_handler) {} |
| 16 |
| 17 CloseButton::~CloseButton() = default; |
| 18 |
| 19 void CloseButton::OnHoverEnter(gfx::PointF position) { |
| 20 hover_ = true; |
| 21 OnStateUpdated(); |
| 22 } |
| 23 |
| 24 void CloseButton::OnHoverLeave() { |
| 25 hover_ = false; |
| 26 OnStateUpdated(); |
| 27 } |
| 28 |
| 29 void CloseButton::OnButtonDown(gfx::PointF position) { |
| 30 down_ = true; |
| 31 OnStateUpdated(); |
| 32 } |
| 33 |
| 34 void CloseButton::OnButtonUp(gfx::PointF position) { |
| 35 down_ = false; |
| 36 OnStateUpdated(); |
| 37 if (position.x() < 0 || position.x() > 1.0f) |
| 38 return; |
| 39 if (position.y() < 0 || position.y() > 1.0f) |
| 40 return; |
| 41 click_handler_.Run(); |
| 42 } |
| 43 |
| 44 UiTexture* CloseButton::GetTexture() const { |
| 45 return texture_.get(); |
| 46 } |
| 47 |
| 48 void CloseButton::OnStateUpdated() { |
| 49 int flags = hover_ ? CloseButtonTexture::FLAG_HOVER : 0; |
| 50 flags |= (down_ && hover_) ? CloseButtonTexture::FLAG_DOWN : 0; |
| 51 if (!texture_->SetDrawFlags(flags)) |
| 52 return; |
| 53 Update(); |
| 54 } |
| 55 |
| 56 } // namespace vr_shell |
OLD | NEW |