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

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: . 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::OnHoverEnter(const gfx::PointF& position) {
23 OnStateUpdated(position);
24 }
25
26 void ExitPrompt::OnHoverLeave() {
27 OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(),
28 std::numeric_limits<float>::max()));
29 }
30
31 void ExitPrompt::OnMove(const gfx::PointF& position) {
32 OnStateUpdated(position);
33 }
34
35 void ExitPrompt::OnButtonDown(const gfx::PointF& position) {
36 if (texture_->HitsPrimaryButton(position))
37 primary_down_ = true;
38 else if (texture_->HitsSecondaryButton(position))
39 secondary_down_ = true;
40 OnStateUpdated(position);
41 }
42
43 void ExitPrompt::OnButtonUp(const gfx::PointF& position) {
44 primary_down_ = false;
45 secondary_down_ = false;
46
47 OnStateUpdated(position);
48 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.
49 primary_button_callback_.Run();
50 else if (texture_->HitsSecondaryButton(position))
51 secondary_buttton_callback_.Run();
52 }
53
54 void ExitPrompt::OnStateUpdated(const gfx::PointF& position) {
55 const bool primary_hovered = texture_->HitsPrimaryButton(position);
56 const bool secondary_hovered = texture_->HitsSecondaryButton(position);
57
58 texture_->SetPrimaryHovered(primary_hovered);
59 texture_->SetPrimaryPressed(primary_hovered ? primary_down_ : false);
60 texture_->SetSecondaryHovered(secondary_hovered);
61 texture_->SetSecondaryPressed(secondary_hovered ? secondary_down_ : false);
62 UpdateTexture();
63 }
64
65 UiTexture* ExitPrompt::GetTexture() const {
66 return texture_.get();
67 }
68
69 } // namespace vr_shell
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698