Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / ui / wm / core / compound_event_filter.h
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_WM_CORE_COMPOUND_EVENT_FILTER_H_
6 #define UI_WM_CORE_COMPOUND_EVENT_FILTER_H_
7
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"
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 wm {
29
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
39 // event.
40 class WM_EXPORT CompoundEventFilter : public ui::EventHandler {
41  public:
42   CompoundEventFilter();
43   virtual ~CompoundEventFilter();
44
45   // Returns the cursor for the specified component.
46   static gfx::NativeCursor CursorForWindowComponent(int window_component);
47
48   // Adds/removes additional event filters. This does not take ownership of
49   // the EventHandler.
50   // NOTE: These handlers are deprecated. Use env::AddPreTargetEventHandler etc.
51   // instead.
52   void AddHandler(ui::EventHandler* filter);
53   void RemoveHandler(ui::EventHandler* filter);
54
55  private:
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);
59
60   // Dispatches event to additional filters.
61   void FilterKeyEvent(ui::KeyEvent* event);
62   void FilterMouseEvent(ui::MouseEvent* event);
63   void FilterTouchEvent(ui::TouchEvent* event);
64
65   // Sets the visibility of the cursor if the event is not synthesized.
66   void SetCursorVisibilityOnEvent(aura::Window* target,
67                                   ui::Event* event,
68                                   bool show);
69
70   // Enables or disables mouse events if the event is not synthesized.
71   void SetMouseEventsEnableStateOnEvent(aura::Window* target,
72                                         ui::Event* event,
73                                         bool enable);
74
75   // Overridden from ui::EventHandler:
76   virtual void OnKeyEvent(ui::KeyEvent* event) OVERRIDE;
77   virtual void OnMouseEvent(ui::MouseEvent* event) OVERRIDE;
78   virtual void OnScrollEvent(ui::ScrollEvent* event) OVERRIDE;
79   virtual void OnTouchEvent(ui::TouchEvent* event) OVERRIDE;
80   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
81
82   // Additional pre-target event handlers.
83   ObserverList<ui::EventHandler, true> handlers_;
84
85   // True if the cursur was hidden by the filter.
86   bool cursor_hidden_by_filter_;
87
88   DISALLOW_COPY_AND_ASSIGN(CompoundEventFilter);
89 };
90
91 }  // namespace wm
92
93 #endif  // UI_WM_CORE_COMPOUND_EVENT_FILTER_H_