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.
5 #ifndef UI_WM_CORE_COMPOUND_EVENT_FILTER_H_
6 #define UI_WM_CORE_COMPOUND_EVENT_FILTER_H_
8 #include "base/compiler_specific.h"
9 #include "base/observer_list.h"
10 #include "ui/events/event.h"
11 #include "ui/events/event_handler.h"
12 #include "ui/gfx/native_widget_types.h"
13 #include "ui/wm/wm_export.h"
30 // TODO(beng): This class should die. AddEventHandler() on the root Window
31 // should be used instead.
32 // CompoundEventFilter gets all events first and can provide actions to those
33 // events. It implements global features such as click to activate a window and
34 // cursor change when moving mouse.
35 // Additional event filters can be added to CompoundEventFilter. Events will
36 // pass through those additional filters in their addition order and could be
37 // consumed by any of those filters. If an event is consumed by a filter, the
38 // rest of the filter(s) and CompoundEventFilter will not see the consumed
40 class WM_EXPORT CompoundEventFilter : public ui::EventHandler {
42 CompoundEventFilter();
43 ~CompoundEventFilter() override;
45 // Returns the cursor for the specified component.
46 static gfx::NativeCursor CursorForWindowComponent(int window_component);
48 // Adds/removes additional event filters. This does not take ownership of
50 // NOTE: These handlers are deprecated. Use env::AddPreTargetEventHandler etc.
52 void AddHandler(ui::EventHandler* filter);
53 void RemoveHandler(ui::EventHandler* filter);
56 // Updates the cursor if the target provides a custom one, and provides
57 // default resize cursors for window edges.
58 void UpdateCursor(aura::Window* target, ui::MouseEvent* event);
60 // Dispatches event to additional filters.
61 void FilterKeyEvent(ui::KeyEvent* event);
62 void FilterMouseEvent(ui::MouseEvent* event);
63 void FilterTouchEvent(ui::TouchEvent* event);
65 // Sets the visibility of the cursor if the event is not synthesized.
66 void SetCursorVisibilityOnEvent(aura::Window* target,
70 // Enables or disables mouse events if the event is not synthesized.
71 void SetMouseEventsEnableStateOnEvent(aura::Window* target,
75 // Overridden from ui::EventHandler:
76 void OnKeyEvent(ui::KeyEvent* event) override;
77 void OnMouseEvent(ui::MouseEvent* event) override;
78 void OnScrollEvent(ui::ScrollEvent* event) override;
79 void OnTouchEvent(ui::TouchEvent* event) override;
80 void OnGestureEvent(ui::GestureEvent* event) override;
82 // Additional pre-target event handlers.
83 ObserverList<ui::EventHandler, true> handlers_;
85 // True if the cursur was hidden by the filter.
86 bool cursor_hidden_by_filter_;
88 DISALLOW_COPY_AND_ASSIGN(CompoundEventFilter);
93 #endif // UI_WM_CORE_COMPOUND_EVENT_FILTER_H_