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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/android/vr_shell/ui_elements/close_button.cc
diff --git a/chrome/browser/android/vr_shell/ui_elements/close_button.cc b/chrome/browser/android/vr_shell/ui_elements/close_button.cc
index ff71c55168fcd5baa4466a3301c17e07f02f9d4b..ae8075bb2daea1969fb02c3f69a709462d49afb1 100644
--- a/chrome/browser/android/vr_shell/ui_elements/close_button.cc
+++ b/chrome/browser/android/vr_shell/ui_elements/close_button.cc
@@ -16,38 +16,45 @@ CloseButton::CloseButton(base::Callback<void()> click_handler)
CloseButton::~CloseButton() = default;
-void CloseButton::OnHoverEnter(gfx::PointF position) {
- hover_ = true;
- OnStateUpdated();
+void CloseButton::OnHoverEnter(const gfx::PointF& position) {
+ OnStateUpdated(position);
}
void CloseButton::OnHoverLeave() {
- hover_ = false;
- OnStateUpdated();
+ OnStateUpdated(gfx::PointF(std::numeric_limits<float>::max(),
+ std::numeric_limits<float>::max()));
}
-void CloseButton::OnButtonDown(gfx::PointF position) {
+void CloseButton::OnMove(const gfx::PointF& position) {
+ OnStateUpdated(position);
+}
+
+void CloseButton::OnButtonDown(const gfx::PointF& position) {
down_ = true;
- OnStateUpdated();
+ OnStateUpdated(position);
}
-void CloseButton::OnButtonUp(gfx::PointF position) {
+void CloseButton::OnButtonUp(const gfx::PointF& position) {
down_ = false;
- OnStateUpdated();
- if (position.x() < 0 || position.x() > 1.0f)
- return;
- if (position.y() < 0 || position.y() > 1.0f)
- return;
- click_handler_.Run();
+ OnStateUpdated(position);
+ if (HitTest(position))
+ click_handler_.Run();
+}
+
+bool CloseButton::HitTest(const gfx::PointF& point) const {
+ return (point - gfx::PointF(0.5, 0.5)).LengthSquared() < 0.25;
}
UiTexture* CloseButton::GetTexture() const {
return texture_.get();
}
-void CloseButton::OnStateUpdated() {
- int flags = hover_ ? CloseButtonTexture::FLAG_HOVER : 0;
- flags |= (down_ && hover_) ? CloseButtonTexture::FLAG_DOWN : 0;
+void CloseButton::OnStateUpdated(const gfx::PointF& position) {
+ bool hitting = HitTest(position);
+ bool down = hitting ? down_ : false;
+
+ int flags = hitting ? CloseButtonTexture::FLAG_HOVER : 0;
+ flags |= down ? CloseButtonTexture::FLAG_DOWN : 0;
if (!texture_->SetDrawFlags(flags))
return;
UpdateTexture();
« 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