Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(370)

Side by Side Diff: chrome/browser/android/vr_shell/ui_elements/exit_prompt.cc

Issue 2913633002: [vr] Clicking on the security icon should prompt the user to bail out of VR (Closed)
Patch Set: rebase Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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/exit_prompt.h"
6
7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/android/vr_shell/textures/exit_prompt_texture.h"
9
10 namespace vr_shell {
11
12 ExitPrompt::ExitPrompt(int preferred_width,
13 const base::Callback<void()>& primary_button_callback,
14 const base::Callback<void()>& secondary_buttton_callback)
15 : TexturedElement(preferred_width),
16 texture_(base::MakeUnique<ExitPromptTexture>()),
17 primary_button_callback_(primary_button_callback),
18 secondary_buttton_callback_(secondary_buttton_callback) {}
19
20 ExitPrompt::~ExitPrompt() = default;
21
22 void ExitPrompt::SetTextureForTesting(ExitPromptTexture* texture) {
23 texture_.reset(texture);
24 }
25
26 void ExitPrompt::OnHoverEnter(const gfx::PointF& position) {
27 OnStateUpdated(position);
28 }
29
30 void ExitPrompt::OnHoverLeave() {
31 OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(),
32 std::numeric_limits<float>::max()));
33 }
34
35 void ExitPrompt::OnMove(const gfx::PointF& position) {
36 OnStateUpdated(position);
37 }
38
39 void ExitPrompt::OnButtonDown(const gfx::PointF& position) {
40 if (texture_->HitsPrimaryButton(position))
41 primary_down_ = true;
42 else if (texture_->HitsSecondaryButton(position))
43 secondary_down_ = true;
44 OnStateUpdated(position);
45 }
46
47 void ExitPrompt::OnButtonUp(const gfx::PointF& position) {
48 if (primary_down_ && texture_->HitsPrimaryButton(position))
49 primary_button_callback_.Run();
50 else if (secondary_down_ && texture_->HitsSecondaryButton(position))
51 secondary_buttton_callback_.Run();
52
53 primary_down_ = false;
54 secondary_down_ = false;
55
56 OnStateUpdated(position);
57 }
58
59 void ExitPrompt::OnStateUpdated(const gfx::PointF& position) {
60 const bool primary_hovered = texture_->HitsPrimaryButton(position);
61 const bool secondary_hovered = texture_->HitsSecondaryButton(position);
62
63 texture_->SetPrimaryButtonHovered(primary_hovered);
64 texture_->SetPrimaryButtonPressed(primary_hovered ? primary_down_ : false);
65 texture_->SetSecondaryButtonHovered(secondary_hovered);
66 texture_->SetSecondaryButtonPressed(secondary_hovered ? secondary_down_
67 : false);
68 UpdateTexture();
69 }
70
71 UiTexture* ExitPrompt::GetTexture() const {
72 return texture_.get();
73 }
74
75 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698