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

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

Issue 2878543002: Refactor VR Shell Input. Locks input to click/scroll targets. (Closed)
Patch Set: Address comments Created 3 years, 7 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/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
OLDNEW
« no previous file with comments | « chrome/browser/android/vr_shell/ui_elements/close_button.h ('k') | chrome/browser/android/vr_shell/ui_elements/ui_element.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698