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

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

Issue 2878083003: VR Shell: Allow UI elements to determine hit testing. (Closed)
Patch Set: Remove unrelated changes 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
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/android/vr_shell/ui_elements/close_button.h" 5 #include "chrome/browser/android/vr_shell/ui_elements/close_button.h"
6 6
7 #include "base/memory/ptr_util.h" 7 #include "base/memory/ptr_util.h"
8 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h" 8 #include "chrome/browser/android/vr_shell/textures/close_button_texture.h"
9 9
10 namespace vr_shell { 10 namespace vr_shell {
11 11
12 CloseButton::CloseButton(base::Callback<void()> click_handler) 12 CloseButton::CloseButton(base::Callback<void()> click_handler)
13 : TexturedElement(256), 13 : TexturedElement(256),
14 texture_(base::MakeUnique<CloseButtonTexture>()), 14 texture_(base::MakeUnique<CloseButtonTexture>()),
15 click_handler_(click_handler) {} 15 click_handler_(click_handler) {}
16 16
17 CloseButton::~CloseButton() = default; 17 CloseButton::~CloseButton() = default;
18 18
19 void CloseButton::OnHoverEnter(gfx::PointF position) { 19 void CloseButton::OnHoverEnter(const gfx::PointF& position) {
20 hover_ = true; 20 OnStateUpdated(position);
21 OnStateUpdated();
22 } 21 }
23 22
24 void CloseButton::OnHoverLeave() { 23 void CloseButton::OnHoverLeave() {
25 hover_ = false; 24 OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(),
26 OnStateUpdated(); 25 std::numeric_limits<float>::max()));
27 } 26 }
28 27
29 void CloseButton::OnButtonDown(gfx::PointF position) { 28 void CloseButton::OnMove(const gfx::PointF& position) {
30 down_ = true; 29 OnStateUpdated(position);
31 OnStateUpdated();
32 } 30 }
33 31
34 void CloseButton::OnButtonUp(gfx::PointF position) { 32 void CloseButton::OnButtonDown(const gfx::PointF& position) {
33 down_ = true;
34 OnStateUpdated(position);
35 }
36
37 void CloseButton::OnButtonUp(const gfx::PointF& position) {
35 down_ = false; 38 down_ = false;
36 OnStateUpdated(); 39 OnStateUpdated(position);
37 if (position.x() < 0 || position.x() > 1.0f) 40 if (HitTest(position))
38 return; 41 click_handler_.Run();
39 if (position.y() < 0 || position.y() > 1.0f) 42 }
40 return; 43
41 click_handler_.Run(); 44 bool CloseButton::HitTest(const gfx::PointF& point) const {
45 return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25;
42 } 46 }
43 47
44 UiTexture* CloseButton::GetTexture() const { 48 UiTexture* CloseButton::GetTexture() const {
45 return texture_.get(); 49 return texture_.get();
46 } 50 }
47 51
48 void CloseButton::OnStateUpdated() { 52 void CloseButton::OnStateUpdated(const gfx::PointF& position) {
49 int flags = hover_ ? CloseButtonTexture::FLAG_HOVER : 0; 53 bool hitting = HitTest(position);
50 flags |= (down_ && hover_) ? CloseButtonTexture::FLAG_DOWN : 0; 54 bool down = hitting ? down_ : false;
55
56 int flags = hitting ? CloseButtonTexture::FLAG_HOVER : 0;
57 flags |= down ? CloseButtonTexture::FLAG_DOWN : 0;
51 if (!texture_->SetDrawFlags(flags)) 58 if (!texture_->SetDrawFlags(flags))
52 return; 59 return;
53 UpdateTexture(); 60 UpdateTexture();
54 } 61 }
55 62
56 } // namespace vr_shell 63 } // 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