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

Unified Diff: ui/views/scoped_target_handler.cc

Issue 1411833006: Refactoring to make adding ink drop animations easier (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Refactor ink drop animations (nits in ui/views/ Created 5 years, 1 month 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
« no previous file with comments | « ui/views/scoped_target_handler.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/scoped_target_handler.cc
diff --git a/ui/views/scoped_target_handler.cc b/ui/views/scoped_target_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..180a8a8779327c2ff125058a64ded9d6d0be50d7
--- /dev/null
+++ b/ui/views/scoped_target_handler.cc
@@ -0,0 +1,67 @@
+// Copyright 2015 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 "ui/views/scoped_target_handler.h"
+
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+#include "ui/events/event_target.h"
+#include "ui/views/view.h"
+
+namespace views {
+
+ScopedTargetHandler::ScopedTargetHandler(View* view,
+ ui::EventHandler* handler)
+ : destroyed_flag_(NULL), view_(view), new_handler_(handler){
+ original_handler_ = view_->SetTargetHandler(this);
+}
+
+ScopedTargetHandler::~ScopedTargetHandler() {
+ EventHandler* handler = view_->SetTargetHandler(original_handler_);
+ DCHECK_EQ(this, handler);
+ if (destroyed_flag_)
+ *destroyed_flag_ = true;
+}
+
+void ScopedTargetHandler::OnEvent(ui::Event* event) {
+ bool destroyed = false;
+ destroyed_flag_ = &destroyed;
+
+ if (original_handler_)
+ original_handler_->OnEvent(event);
+ else
+ EventHandler::OnEvent(event);
+
+ if (destroyed)
+ return;
+ destroyed_flag_ = NULL;
+
+ new_handler_->OnEvent(event);
+}
+
+void ScopedTargetHandler::OnKeyEvent(ui::KeyEvent* event) {
+ static_cast<EventHandler*>(view_)->OnKeyEvent(event);
+}
+
+void ScopedTargetHandler::OnMouseEvent(ui::MouseEvent* event) {
+ static_cast<EventHandler*>(view_)->OnMouseEvent(event);
+}
+
+void ScopedTargetHandler::OnScrollEvent(ui::ScrollEvent* event) {
+ static_cast<EventHandler*>(view_)->OnScrollEvent(event);
+}
+
+void ScopedTargetHandler::OnTouchEvent(ui::TouchEvent* event) {
+ static_cast<EventHandler*>(view_)->OnTouchEvent(event);
+}
+
+void ScopedTargetHandler::OnGestureEvent(ui::GestureEvent* event) {
+ static_cast<EventHandler*>(view_)->OnGestureEvent(event);
+}
+
+void ScopedTargetHandler::OnCancelMode(ui::CancelModeEvent* event) {
+ static_cast<EventHandler*>(view_)->OnCancelMode(event);
+}
+
+} // namespace views
« no previous file with comments | « ui/views/scoped_target_handler.h ('k') | ui/views/view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698