Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/events/scoped_target_handler.h" | |
| 6 | |
| 7 #include "ui/events/event.h" | |
| 8 #include "ui/events/event_handler.h" | |
| 9 #include "ui/events/event_target.h" | |
| 10 | |
| 11 namespace ui { | |
| 12 | |
| 13 ScopedTargetHandler::ScopedTargetHandler(EventTarget* target, | |
| 14 EventHandler* handler) | |
| 15 : destroyed_flag_(NULL), target_(target), new_handler_(handler){ | |
| 16 original_handler_ = target_->SetTargetHandler(this); | |
| 17 } | |
| 18 | |
| 19 ScopedTargetHandler::~ScopedTargetHandler() { | |
| 20 EventHandler* handler = target_->SetTargetHandler(original_handler_); | |
| 21 DCHECK_EQ(this, handler); | |
| 22 if (destroyed_flag_) | |
| 23 *destroyed_flag_ = true; | |
| 24 } | |
| 25 | |
| 26 void ScopedTargetHandler::OnEvent(ui::Event* event) { | |
| 27 bool destroyed = false; | |
| 28 destroyed_flag_ = &destroyed; | |
| 29 | |
| 30 if (original_handler_) | |
| 31 original_handler_->OnEvent(event); | |
| 32 else | |
| 33 EventHandler::OnEvent(event); | |
| 34 | |
| 35 if (destroyed) | |
| 36 return; | |
| 37 destroyed_flag_ = NULL; | |
| 38 | |
| 39 new_handler_->OnEvent(event); | |
| 40 } | |
|
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
| |
| 41 | |
| 42 void ScopedTargetHandler::OnKeyEvent(ui::KeyEvent* event) { | |
| 43 static_cast<EventHandler*>(target_)->OnKeyEvent(event); | |
| 44 } | |
| 45 | |
| 46 void ScopedTargetHandler::OnMouseEvent(ui::MouseEvent* event) { | |
| 47 static_cast<EventHandler*>(target_)->OnMouseEvent(event); | |
| 48 } | |
| 49 | |
| 50 void ScopedTargetHandler::OnScrollEvent(ui::ScrollEvent* event) { | |
| 51 static_cast<EventHandler*>(target_)->OnScrollEvent(event); | |
| 52 } | |
| 53 | |
| 54 void ScopedTargetHandler::OnTouchEvent(ui::TouchEvent* event) { | |
| 55 static_cast<EventHandler*>(target_)->OnTouchEvent(event); | |
| 56 } | |
| 57 | |
| 58 void ScopedTargetHandler::OnGestureEvent(ui::GestureEvent* event) { | |
| 59 static_cast<EventHandler*>(target_)->OnGestureEvent(event); | |
| 60 } | |
| 61 | |
| 62 void ScopedTargetHandler::OnCancelMode(ui::CancelModeEvent* event) { | |
| 63 static_cast<EventHandler*>(target_)->OnCancelMode(event); | |
| 64 } | |
| 65 | |
| 66 } // namespace ui | |
| OLD | NEW |