Avi Drissman | 3e1a26c | 2022-09-15 20:26:03 | [diff] [blame] | 1 | // Copyright 2012 The Chromium Authors |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | // found in the LICENSE file. | ||||
4 | |||||
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 5 | #include "ui/events/event_handler.h" |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 6 | |
Helmut Januschka | 36619c1 | 2024-04-24 14:33:19 | [diff] [blame] | 7 | #include <string_view> |
8 | |||||
Allen Bauer | 054f2cf | 2020-12-14 20:37:47 | [diff] [blame] | 9 | #include "base/logging.h" |
10 | #include "base/strings/string_util.h" | ||||
[email protected] | 86ccbd4 | 2013-09-18 18:11:54 | [diff] [blame] | 11 | #include "ui/events/event.h" |
12 | #include "ui/events/event_dispatcher.h" | ||||
[email protected] | bdba405 | 2012-12-01 07:04:47 | [diff] [blame] | 13 | |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 14 | namespace ui { |
15 | |||||
Scott Violet | 51c95427 | 2021-05-18 19:24:11 | [diff] [blame] | 16 | EventHandler::EventHandler() = default; |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 17 | |
18 | EventHandler::~EventHandler() { | ||||
[email protected] | 16bdf059 | 2012-12-10 23:49:12 | [diff] [blame] | 19 | while (!dispatchers_.empty()) { |
20 | EventDispatcher* dispatcher = dispatchers_.top(); | ||||
21 | dispatchers_.pop(); | ||||
22 | dispatcher->OnHandlerDestroyed(this); | ||||
23 | } | ||||
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 24 | } |
25 | |||||
[email protected] | bdb6d25c | 2012-12-03 20:29:46 | [diff] [blame] | 26 | void EventHandler::OnEvent(Event* event) { |
Allen Bauer | 1492bd05 | 2021-06-28 19:19:40 | [diff] [blame] | 27 | // You may uncomment the following line if more detailed logging is necessary |
28 | // for diagnosing event processing. This code is a critical path and the added | ||||
29 | // overhead from the logging can introduce other issues. Please do not commit | ||||
30 | // with the following line commented without first discussing with OWNERs. | ||||
31 | // See crbug/1210633 for details. | ||||
32 | // VLOG(5) << GetLogContext() << "::OnEvent(" << event->ToString() << ")"; | ||||
[email protected] | bdba405 | 2012-12-01 07:04:47 | [diff] [blame] | 33 | if (event->IsKeyEvent()) |
kylixrd | d47244c | 2016-10-04 16:59:51 | [diff] [blame] | 34 | OnKeyEvent(event->AsKeyEvent()); |
[email protected] | bdb6d25c | 2012-12-03 20:29:46 | [diff] [blame] | 35 | else if (event->IsMouseEvent()) |
kylixrd | d47244c | 2016-10-04 16:59:51 | [diff] [blame] | 36 | OnMouseEvent(event->AsMouseEvent()); |
[email protected] | bdb6d25c | 2012-12-03 20:29:46 | [diff] [blame] | 37 | else if (event->IsScrollEvent()) |
kylixrd | d47244c | 2016-10-04 16:59:51 | [diff] [blame] | 38 | OnScrollEvent(event->AsScrollEvent()); |
[email protected] | bdb6d25c | 2012-12-03 20:29:46 | [diff] [blame] | 39 | else if (event->IsTouchEvent()) |
kylixrd | d47244c | 2016-10-04 16:59:51 | [diff] [blame] | 40 | OnTouchEvent(event->AsTouchEvent()); |
[email protected] | bdb6d25c | 2012-12-03 20:29:46 | [diff] [blame] | 41 | else if (event->IsGestureEvent()) |
[email protected] | 34a1109 | 2014-07-17 06:57:08 | [diff] [blame] | 42 | OnGestureEvent(event->AsGestureEvent()); |
kylixrd | d47244c | 2016-10-04 16:59:51 | [diff] [blame] | 43 | else if (event->IsCancelModeEvent()) |
44 | OnCancelMode(event->AsCancelModeEvent()); | ||||
[email protected] | 4fda7de9 | 2012-11-21 16:58:50 | [diff] [blame] | 45 | } |
46 | |||||
[email protected] | 5eebaf4 | 2012-12-14 17:16:21 | [diff] [blame] | 47 | void EventHandler::OnKeyEvent(KeyEvent* event) { |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 48 | } |
49 | |||||
[email protected] | d44efe0 | 2012-12-18 06:08:18 | [diff] [blame] | 50 | void EventHandler::OnMouseEvent(MouseEvent* event) { |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 51 | } |
52 | |||||
[email protected] | 6f34b483 | 2012-12-14 16:18:08 | [diff] [blame] | 53 | void EventHandler::OnScrollEvent(ScrollEvent* event) { |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 54 | } |
55 | |||||
[email protected] | 6f34b483 | 2012-12-14 16:18:08 | [diff] [blame] | 56 | void EventHandler::OnTouchEvent(TouchEvent* event) { |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 57 | } |
58 | |||||
[email protected] | e93b70cc | 2012-12-04 05:08:30 | [diff] [blame] | 59 | void EventHandler::OnGestureEvent(GestureEvent* event) { |
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 60 | } |
61 | |||||
[email protected] | af5e2527 | 2013-02-21 01:17:36 | [diff] [blame] | 62 | void EventHandler::OnCancelMode(CancelModeEvent* event) { |
63 | } | ||||
64 | |||||
Helmut Januschka | 36619c1 | 2024-04-24 14:33:19 | [diff] [blame] | 65 | std::string_view EventHandler::GetLogContext() const { |
Allen Bauer | 054f2cf | 2020-12-14 20:37:47 | [diff] [blame] | 66 | return "(Unknown EventHandler)"; // Please override |
67 | } | ||||
68 | |||||
[email protected] | 2dca2dc9 | 2012-11-20 17:13:08 | [diff] [blame] | 69 | } // namespace ui |