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 5 #ifndef UI_VIEWS_COREWM_COMPOUND_EVENT_FILTER_H_ 6 #define UI_VIEWS_COREWM_COMPOUND_EVENT_FILTER_H_ 7 8 #include "base/compiler_specific.h" 9 #include "base/observer_list.h" 10 #include "ui/base/events/event.h" 11 #include "ui/base/events/event_handler.h" 12 #include "ui/gfx/native_widget_types.h" 13 #include "ui/views/views_export.h" 14 15 namespace aura { 16 class CursorManager; 17 class RootWindow; 18 } 19 20 namespace ui { 21 class GestureEvent; 22 class KeyEvent; 23 class LocatedEvent; 24 class MouseEvent; 25 class TouchEvent; 26 } 27 28 namespace views { 29 namespace corewm { 30 31 // CompoundEventFilter gets all events first and can provide actions to those 32 // events. It implements global features such as click to activate a window and 33 // cursor change when moving mouse. 34 // Additional event filters can be added to CompoundEventFilter. Events will 35 // pass through those additional filters in their addition order and could be 36 // consumed by any of those filters. If an event is consumed by a filter, the 37 // rest of the filter(s) and CompoundEventFilter will not see the consumed 38 // event. 39 class VIEWS_EXPORT CompoundEventFilter : public ui::EventHandler { 40 public: 41 CompoundEventFilter(); 42 virtual ~CompoundEventFilter(); 43 44 // Returns the cursor for the specified component. 45 static gfx::NativeCursor CursorForWindowComponent(int window_component); 46 47 // Used to allow a mouse event to show the cursor even when 48 // the cursor is hidden by |CursorClient::ShowCursor(false)|. 49 void set_cursor_hidden_by_filter(bool cursor_hidden_by_filter) { 50 cursor_hidden_by_filter_ = cursor_hidden_by_filter; 51 } 52 53 // Adds/removes additional event filters. This does not take ownership of 54 // the EventHandler. 55 // NOTE: These handlers are deprecated. Use env::AddPreTargetEventHandler etc. 56 // instead. 57 void AddHandler(ui::EventHandler* filter); 58 void RemoveHandler(ui::EventHandler* filter); 59 60 private: 61 // Updates the cursor if the target provides a custom one, and provides 62 // default resize cursors for window edges. 63 void UpdateCursor(aura::Window* target, ui::MouseEvent* event); 64 65 // Dispatches event to additional filters. 66 void FilterKeyEvent(ui::KeyEvent* event); 67 void FilterMouseEvent(ui::MouseEvent* event); 68 void FilterTouchEvent(ui::TouchEvent* event); 69 70 // Sets the visibility of the cursor if the event is not synthesized and 71 // 1) it's hiding (show=false) when the cursor is currently shown, or 72 // 2) it's showing (show=true) if the cursor is previously hidden 73 // by this event filter (see |cursor_hidden_by_filter_|), 74 // so that it doesn't change the cursor visibility if the cursor was 75 // intentionally hidden by other components. 76 void SetCursorVisibilityOnEvent(aura::Window* target, 77 ui::Event* event, 78 bool show); 79 80 // Enables or disables mouse events if the event is not synthesized. 81 void SetMouseEventsEnableStateOnEvent(aura::Window* target, 82 ui::Event* event, 83 bool enable); 84 85 // Overridden from ui::EventHandler: 86 virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE; 87 virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE; 88 virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE; 89 virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE; 90 virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE; 91 92 // Additional pre-target event handlers. 93 ObserverList<ui::EventHandler, true> handlers_; 94 95 // True if the cursur was hidden by the filter. 96 bool cursor_hidden_by_filter_; 97 98 DISALLOW_COPY_AND_ASSIGN(CompoundEventFilter); 99 }; 100 101 } // namespace corewm 102 } // namespace views 103 104 #endif // UI_VIEWS_COREWM_COMPOUND_EVENT_FILTER_H_ 105