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

Unified 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 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
new file mode 100644
index 0000000000000000000000000000000000000000..cc2549f3f99e938e93150893c86ef8926158446b
--- /dev/null
+++ b/chrome/browser/android/vr_shell/ui_elements/close_button.cc
@@ -0,0 +1,56 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/android/vr_shell/ui_elements/close_button.h"
+
+#include "base/memory/ptr_util.h"
+#include "chrome/browser/android/vr_shell/textures/close_button_texture.h"
+
+namespace vr_shell {
+
+CloseButton::CloseButton(base::Callback<void()> click_handler)
+ : TexturedElement(256),
+ texture_(base::MakeUnique<CloseButtonTexture>()),
+ click_handler_(click_handler) {}
+
+CloseButton::~CloseButton() = default;
+
+void CloseButton::OnHoverEnter(gfx::PointF position) {
+ hover_ = true;
+ OnStateUpdated();
+}
+
+void CloseButton::OnHoverLeave() {
+ hover_ = false;
+ OnStateUpdated();
+}
+
+void CloseButton::OnButtonDown(gfx::PointF position) {
+ down_ = true;
+ OnStateUpdated();
+}
+
+void CloseButton::OnButtonUp(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();
+}
+
+UiTexture* CloseButton::GetTexture() const {
+ return texture_.get();
+}
+
+void CloseButton::OnStateUpdated() {
+ int flags = hover_ ? CloseButtonTexture::FLAG_HOVER : 0;
+ flags |= (down_ && hover_) ? CloseButtonTexture::FLAG_DOWN : 0;
+ if (!texture_->SetDrawFlags(flags))
+ return;
+ Update();
+}
+
+} // namespace vr_shell
« 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