event_handler.h 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. // Copyright (c) 2012 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. #ifndef UI_EVENTS_EVENT_HANDLER_H_
  5. #define UI_EVENTS_EVENT_HANDLER_H_
  6. #include <vector>
  7. #include "base/containers/stack.h"
  8. #include "base/strings/string_piece.h"
  9. #include "ui/events/events_export.h"
  10. namespace ui {
  11. class CancelModeEvent;
  12. class Event;
  13. class EventDispatcher;
  14. class EventTarget;
  15. class GestureEvent;
  16. class KeyEvent;
  17. class MouseEvent;
  18. class ScrollEvent;
  19. class TouchEvent;
  20. // Dispatches events to appropriate targets. The default implementations of
  21. // all of the specific handlers (e.g. OnKeyEvent, OnMouseEvent) do nothing.
  22. class EVENTS_EXPORT EventHandler {
  23. public:
  24. EventHandler();
  25. EventHandler(const EventHandler&) = delete;
  26. EventHandler& operator=(const EventHandler&) = delete;
  27. virtual ~EventHandler();
  28. // This is called for all events. The default implementation routes the event
  29. // to one of the event-specific callbacks (OnKeyEvent, OnMouseEvent etc.). If
  30. // this is overridden, then normally, the override should chain into the
  31. // default implementation for un-handled events.
  32. virtual void OnEvent(Event* event);
  33. virtual void OnKeyEvent(KeyEvent* event);
  34. virtual void OnMouseEvent(MouseEvent* event);
  35. virtual void OnScrollEvent(ScrollEvent* event);
  36. virtual void OnTouchEvent(TouchEvent* event);
  37. virtual void OnGestureEvent(GestureEvent* event);
  38. virtual void OnCancelMode(CancelModeEvent* event);
  39. // Returns information about the implementing class or scope for diagnostic
  40. // logging purposes.
  41. virtual base::StringPiece GetLogContext() const;
  42. private:
  43. friend class EventDispatcher;
  44. friend class EventTarget;
  45. // EventDispatcher pushes itself on the top of this stack while dispatching
  46. // events to this then pops itself off when done.
  47. base::stack<EventDispatcher*> dispatchers_;
  48. };
  49. using EventHandlerList = std::vector<EventHandler*>;
  50. } // namespace ui
  51. #endif // UI_EVENTS_EVENT_HANDLER_H_