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

Unified Diff: ui/events/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 (comments 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
Index: ui/events/scoped_target_handler.cc
diff --git a/ui/events/scoped_target_handler.cc b/ui/events/scoped_target_handler.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bb39440a890572bdcadf6adf74408e0a6feb7550
--- /dev/null
+++ b/ui/events/scoped_target_handler.cc
@@ -0,0 +1,66 @@
+// 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/events/scoped_target_handler.h"
+
+#include "ui/events/event.h"
+#include "ui/events/event_handler.h"
+#include "ui/events/event_target.h"
+
+namespace ui {
+
+ScopedTargetHandler::ScopedTargetHandler(EventTarget* target,
+ EventHandler* handler)
+ : destroyed_flag_(NULL), target_(target), new_handler_(handler){
+ original_handler_ = target_->SetTargetHandler(this);
+}
+
+ScopedTargetHandler::~ScopedTargetHandler() {
+ EventHandler* handler = target_->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);
+}
sadrul 2015/11/25 22:38:58 I think this should just be: if (original_handl
varkha 2015/11/26 00:05:46 I don't think so. |original_handler_| here is a de
sadrul 2015/11/26 17:48:19 Ah, I see what you mean. But sending event directl
varkha 2015/11/26 22:12:40 As we talked offline - passing in a View instead o
+
+void ScopedTargetHandler::OnKeyEvent(ui::KeyEvent* event) {
+ static_cast<EventHandler*>(target_)->OnKeyEvent(event);
+}
+
+void ScopedTargetHandler::OnMouseEvent(ui::MouseEvent* event) {
+ static_cast<EventHandler*>(target_)->OnMouseEvent(event);
+}
+
+void ScopedTargetHandler::OnScrollEvent(ui::ScrollEvent* event) {
+ static_cast<EventHandler*>(target_)->OnScrollEvent(event);
+}
+
+void ScopedTargetHandler::OnTouchEvent(ui::TouchEvent* event) {
+ static_cast<EventHandler*>(target_)->OnTouchEvent(event);
+}
+
+void ScopedTargetHandler::OnGestureEvent(ui::GestureEvent* event) {
+ static_cast<EventHandler*>(target_)->OnGestureEvent(event);
+}
+
+void ScopedTargetHandler::OnCancelMode(ui::CancelModeEvent* event) {
+ static_cast<EventHandler*>(target_)->OnCancelMode(event);
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698