event_handler.cc 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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. #include "ui/events/event_handler.h"
  5. #include "base/logging.h"
  6. #include "base/strings/string_util.h"
  7. #include "ui/events/event.h"
  8. #include "ui/events/event_dispatcher.h"
  9. namespace ui {
  10. EventHandler::EventHandler() = default;
  11. EventHandler::~EventHandler() {
  12. while (!dispatchers_.empty()) {
  13. EventDispatcher* dispatcher = dispatchers_.top();
  14. dispatchers_.pop();
  15. dispatcher->OnHandlerDestroyed(this);
  16. }
  17. }
  18. void EventHandler::OnEvent(Event* event) {
  19. // You may uncomment the following line if more detailed logging is necessary
  20. // for diagnosing event processing. This code is a critical path and the added
  21. // overhead from the logging can introduce other issues. Please do not commit
  22. // with the following line commented without first discussing with OWNERs.
  23. // See crbug/1210633 for details.
  24. // VLOG(5) << GetLogContext() << "::OnEvent(" << event->ToString() << ")";
  25. if (event->IsKeyEvent())
  26. OnKeyEvent(event->AsKeyEvent());
  27. else if (event->IsMouseEvent())
  28. OnMouseEvent(event->AsMouseEvent());
  29. else if (event->IsScrollEvent())
  30. OnScrollEvent(event->AsScrollEvent());
  31. else if (event->IsTouchEvent())
  32. OnTouchEvent(event->AsTouchEvent());
  33. else if (event->IsGestureEvent())
  34. OnGestureEvent(event->AsGestureEvent());
  35. else if (event->IsCancelModeEvent())
  36. OnCancelMode(event->AsCancelModeEvent());
  37. }
  38. void EventHandler::OnKeyEvent(KeyEvent* event) {
  39. }
  40. void EventHandler::OnMouseEvent(MouseEvent* event) {
  41. }
  42. void EventHandler::OnScrollEvent(ScrollEvent* event) {
  43. }
  44. void EventHandler::OnTouchEvent(TouchEvent* event) {
  45. }
  46. void EventHandler::OnGestureEvent(GestureEvent* event) {
  47. }
  48. void EventHandler::OnCancelMode(CancelModeEvent* event) {
  49. }
  50. base::StringPiece EventHandler::GetLogContext() const {
  51. return "(Unknown EventHandler)"; // Please override
  52. }
  53. } // namespace ui