blob: f1357f025ce766f061a9106e1df66898c8e593a9 [file] [log] [blame]
Avi Drissman3e1a26c2022-09-15 20:26:031// Copyright 2012 The Chromium Authors
[email protected]2dca2dc92012-11-20 17:13:082// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]86ccbd42013-09-18 18:11:545#include "ui/events/event_handler.h"
[email protected]2dca2dc92012-11-20 17:13:086
Helmut Januschka36619c12024-04-24 14:33:197#include <string_view>
8
Allen Bauer054f2cf2020-12-14 20:37:479#include "base/logging.h"
10#include "base/strings/string_util.h"
[email protected]86ccbd42013-09-18 18:11:5411#include "ui/events/event.h"
12#include "ui/events/event_dispatcher.h"
[email protected]bdba4052012-12-01 07:04:4713
[email protected]2dca2dc92012-11-20 17:13:0814namespace ui {
15
Scott Violet51c954272021-05-18 19:24:1116EventHandler::EventHandler() = default;
[email protected]2dca2dc92012-11-20 17:13:0817
18EventHandler::~EventHandler() {
[email protected]16bdf0592012-12-10 23:49:1219 while (!dispatchers_.empty()) {
20 EventDispatcher* dispatcher = dispatchers_.top();
21 dispatchers_.pop();
22 dispatcher->OnHandlerDestroyed(this);
23 }
[email protected]2dca2dc92012-11-20 17:13:0824}
25
[email protected]bdb6d25c2012-12-03 20:29:4626void EventHandler::OnEvent(Event* event) {
Allen Bauer1492bd052021-06-28 19:19:4027 // 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]bdba4052012-12-01 07:04:4733 if (event->IsKeyEvent())
kylixrdd47244c2016-10-04 16:59:5134 OnKeyEvent(event->AsKeyEvent());
[email protected]bdb6d25c2012-12-03 20:29:4635 else if (event->IsMouseEvent())
kylixrdd47244c2016-10-04 16:59:5136 OnMouseEvent(event->AsMouseEvent());
[email protected]bdb6d25c2012-12-03 20:29:4637 else if (event->IsScrollEvent())
kylixrdd47244c2016-10-04 16:59:5138 OnScrollEvent(event->AsScrollEvent());
[email protected]bdb6d25c2012-12-03 20:29:4639 else if (event->IsTouchEvent())
kylixrdd47244c2016-10-04 16:59:5140 OnTouchEvent(event->AsTouchEvent());
[email protected]bdb6d25c2012-12-03 20:29:4641 else if (event->IsGestureEvent())
[email protected]34a11092014-07-17 06:57:0842 OnGestureEvent(event->AsGestureEvent());
kylixrdd47244c2016-10-04 16:59:5143 else if (event->IsCancelModeEvent())
44 OnCancelMode(event->AsCancelModeEvent());
[email protected]4fda7de92012-11-21 16:58:5045}
46
[email protected]5eebaf42012-12-14 17:16:2147void EventHandler::OnKeyEvent(KeyEvent* event) {
[email protected]2dca2dc92012-11-20 17:13:0848}
49
[email protected]d44efe02012-12-18 06:08:1850void EventHandler::OnMouseEvent(MouseEvent* event) {
[email protected]2dca2dc92012-11-20 17:13:0851}
52
[email protected]6f34b4832012-12-14 16:18:0853void EventHandler::OnScrollEvent(ScrollEvent* event) {
[email protected]2dca2dc92012-11-20 17:13:0854}
55
[email protected]6f34b4832012-12-14 16:18:0856void EventHandler::OnTouchEvent(TouchEvent* event) {
[email protected]2dca2dc92012-11-20 17:13:0857}
58
[email protected]e93b70cc2012-12-04 05:08:3059void EventHandler::OnGestureEvent(GestureEvent* event) {
[email protected]2dca2dc92012-11-20 17:13:0860}
61
[email protected]af5e25272013-02-21 01:17:3662void EventHandler::OnCancelMode(CancelModeEvent* event) {
63}
64
Helmut Januschka36619c12024-04-24 14:33:1965std::string_view EventHandler::GetLogContext() const {
Allen Bauer054f2cf2020-12-14 20:37:4766 return "(Unknown EventHandler)"; // Please override
67}
68
[email protected]2dca2dc92012-11-20 17:13:0869} // namespace ui