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 #ifndef UI_EVENTS_SCOPED_TARGET_HANDLER_H_ |
| 6 #define UI_EVENTS_SCOPED_TARGET_HANDLER_H_ |
| 7 |
| 8 #include "base/macros.h" |
| 9 #include "ui/events/event_handler.h" |
| 10 #include "ui/events/events_export.h" |
| 11 |
| 12 namespace ui { |
| 13 |
| 14 class EventTarget; |
| 15 |
| 16 // An EventHandler that replaces an EventTarget's target handler with itself |
| 17 // to pass events to both the original handlers and an additional new |
| 18 // EventHandler. |
| 19 class EVENTS_EXPORT ScopedTargetHandler : public EventHandler { |
| 20 public: |
| 21 ScopedTargetHandler(EventTarget* target, EventHandler* new_handler); |
| 22 ~ScopedTargetHandler() override; |
| 23 |
| 24 // ui::EventHandler: |
| 25 void OnEvent(ui::Event* event) override; |
| 26 void OnKeyEvent(ui::KeyEvent* event) override; |
| 27 void OnMouseEvent(ui::MouseEvent* event) override; |
| 28 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 29 void OnTouchEvent(ui::TouchEvent* event) override; |
| 30 void OnGestureEvent(ui::GestureEvent* event) override; |
| 31 void OnCancelMode(ui::CancelModeEvent* event) override; |
| 32 |
| 33 private: |
| 34 // If non-null the destructor sets this to true. This is set while handling |
| 35 // an event and used to detect if |this| has been deleted. |
| 36 bool* destroyed_flag_; |
| 37 |
| 38 // An EventTarget that has its target handler replaced with |this| for a life |
| 39 // time of |this|. |
| 40 EventTarget* target_; |
| 41 |
| 42 // An EventHandler that gets restored on |target_| when |this| is destroyed. |
| 43 EventHandler* original_handler_; |
| 44 |
| 45 // A new handler that gets events in addition to the |original_handler_| or |
| 46 // |target_|. |
| 47 EventHandler* new_handler_; |
| 48 |
| 49 DISALLOW_COPY_AND_ASSIGN(ScopedTargetHandler); |
| 50 }; |
| 51 |
| 52 } // namespace ui |
| 53 |
| 54 #endif // UI_EVENTS_SCOPED_TARGET_HANDLER_H_ |
OLD | NEW |