Chromium Code Reviews| Index: chrome/browser/android/vr_shell/ui_elements/exit_prompt.cc |
| diff --git a/chrome/browser/android/vr_shell/ui_elements/exit_prompt.cc b/chrome/browser/android/vr_shell/ui_elements/exit_prompt.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..2df115c9dc573d8cf40e1a8a45a0f225147c149e |
| --- /dev/null |
| +++ b/chrome/browser/android/vr_shell/ui_elements/exit_prompt.cc |
| @@ -0,0 +1,69 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/android/vr_shell/ui_elements/exit_prompt.h" |
| + |
| +#include "base/memory/ptr_util.h" |
| +#include "chrome/browser/android/vr_shell/textures/exit_prompt_texture.h" |
| + |
| +namespace vr_shell { |
| + |
| +ExitPrompt::ExitPrompt(int preferred_width, |
| + const base::Callback<void()>& primary_button_callback, |
| + const base::Callback<void()>& secondary_buttton_callback) |
| + : TexturedElement(preferred_width), |
| + texture_(base::MakeUnique<ExitPromptTexture>()), |
| + primary_button_callback_(primary_button_callback), |
| + secondary_buttton_callback_(secondary_buttton_callback) {} |
| + |
| +ExitPrompt::~ExitPrompt() = default; |
| + |
| +void ExitPrompt::OnHoverEnter(const gfx::PointF& position) { |
| + OnStateUpdated(position); |
| +} |
| + |
| +void ExitPrompt::OnHoverLeave() { |
| + OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(), |
| + std::numeric_limits<float>::max())); |
| +} |
| + |
| +void ExitPrompt::OnMove(const gfx::PointF& position) { |
| + OnStateUpdated(position); |
| +} |
| + |
| +void ExitPrompt::OnButtonDown(const gfx::PointF& position) { |
| + if (texture_->HitsPrimaryButton(position)) |
| + primary_down_ = true; |
| + else if (texture_->HitsSecondaryButton(position)) |
| + secondary_down_ = true; |
| + OnStateUpdated(position); |
| +} |
| + |
| +void ExitPrompt::OnButtonUp(const gfx::PointF& position) { |
| + primary_down_ = false; |
| + secondary_down_ = false; |
| + |
| + OnStateUpdated(position); |
| + if (texture_->HitsPrimaryButton(position)) |
|
cjgrant
2017/06/02 04:16:36
Don't we want to check that a particular button is
ymalik
2017/06/02 21:14:31
Yeah totally. Fixed.
|
| + primary_button_callback_.Run(); |
| + else if (texture_->HitsSecondaryButton(position)) |
| + secondary_buttton_callback_.Run(); |
| +} |
| + |
| +void ExitPrompt::OnStateUpdated(const gfx::PointF& position) { |
| + const bool primary_hovered = texture_->HitsPrimaryButton(position); |
| + const bool secondary_hovered = texture_->HitsSecondaryButton(position); |
| + |
| + texture_->SetPrimaryHovered(primary_hovered); |
| + texture_->SetPrimaryPressed(primary_hovered ? primary_down_ : false); |
| + texture_->SetSecondaryHovered(secondary_hovered); |
| + texture_->SetSecondaryPressed(secondary_hovered ? secondary_down_ : false); |
| + UpdateTexture(); |
| +} |
| + |
| +UiTexture* ExitPrompt::GetTexture() const { |
| + return texture_.get(); |
| +} |
| + |
| +} // namespace vr_shell |