OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef UI_AURA_ENV_H_ | 5 #ifndef UI_AURA_ENV_H_ |
6 #define UI_AURA_ENV_H_ | 6 #define UI_AURA_ENV_H_ |
7 | 7 |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
10 #include "base/observer_list.h" | 10 #include "base/observer_list.h" |
11 #include "ui/aura/aura_export.h" | 11 #include "ui/aura/aura_export.h" |
12 #include "ui/events/event_handler.h" | 12 #include "ui/events/event_handler.h" |
13 #include "ui/events/event_target.h" | 13 #include "ui/events/event_target.h" |
14 #include "ui/gfx/point.h" | 14 #include "ui/gfx/point.h" |
15 | 15 |
16 #if defined(USE_X11) | 16 #if defined(USE_X11) |
17 #include "ui/aura/device_list_updater_aurax11.h" | 17 #include "ui/aura/device_list_updater_aurax11.h" |
18 #endif | 18 #endif |
19 | 19 |
20 namespace aura { | 20 namespace aura { |
21 class EnvObserver; | 21 class EnvObserver; |
22 class RootWindow; | 22 class RootWindow; |
23 class Window; | 23 class Window; |
24 | 24 |
25 #if !defined(USE_X11) | 25 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11) |
26 // Creates a platform-specific native event dispatcher. | 26 // Creates a platform-specific native event dispatcher. |
27 base::MessageLoop::Dispatcher* CreateDispatcher(); | 27 base::MessageLoop::Dispatcher* CreateDispatcher(); |
28 #endif | 28 #endif |
29 | 29 |
30 // A singleton object that tracks general state within Aura. | 30 // A singleton object that tracks general state within Aura. |
31 // TODO(beng): manage RootWindows. | 31 // TODO(beng): manage RootWindows. |
32 class AURA_EXPORT Env : public ui::EventTarget { | 32 class AURA_EXPORT Env : public ui::EventTarget { |
33 public: | 33 public: |
34 Env(); | 34 Env(); |
35 virtual ~Env(); | 35 virtual ~Env(); |
36 | 36 |
| 37 static void CreateInstance(); |
37 static Env* GetInstance(); | 38 static Env* GetInstance(); |
38 static void DeleteInstance(); | 39 static void DeleteInstance(); |
39 | 40 |
40 void AddObserver(EnvObserver* observer); | 41 void AddObserver(EnvObserver* observer); |
41 void RemoveObserver(EnvObserver* observer); | 42 void RemoveObserver(EnvObserver* observer); |
42 | 43 |
43 bool is_mouse_button_down() const { return mouse_button_flags_ != 0; } | 44 bool is_mouse_button_down() const { return mouse_button_flags_ != 0; } |
44 void set_mouse_button_flags(int mouse_button_flags) { | 45 void set_mouse_button_flags(int mouse_button_flags) { |
45 mouse_button_flags_ = mouse_button_flags; | 46 mouse_button_flags_ = mouse_button_flags; |
46 } | 47 } |
47 | 48 |
48 // Gets/sets the last mouse location seen in a mouse event in the screen | 49 // Gets/sets the last mouse location seen in a mouse event in the screen |
49 // coordinates. | 50 // coordinates. |
50 const gfx::Point& last_mouse_location() const { return last_mouse_location_; } | 51 const gfx::Point& last_mouse_location() const { return last_mouse_location_; } |
51 void set_last_mouse_location(const gfx::Point& last_mouse_location) { | 52 void set_last_mouse_location(const gfx::Point& last_mouse_location) { |
52 last_mouse_location_ = last_mouse_location; | 53 last_mouse_location_ = last_mouse_location; |
53 } | 54 } |
54 | 55 |
55 // Whether any touch device is currently down. | 56 // Whether any touch device is currently down. |
56 bool is_touch_down() const { return is_touch_down_; } | 57 bool is_touch_down() const { return is_touch_down_; } |
57 void set_touch_down(bool value) { is_touch_down_ = value; } | 58 void set_touch_down(bool value) { is_touch_down_ = value; } |
58 | 59 |
59 | 60 |
60 // Returns the native event dispatcher. The result should only be passed to | 61 // Returns the native event dispatcher. The result should only be passed to |
61 // base::RunLoop(dispatcher), or used to dispatch an event by | 62 // base::RunLoop(dispatcher), or used to dispatch an event by |
62 // |Dispatch(const NativeEvent&)| on it. It must never be stored. | 63 // |Dispatch(const NativeEvent&)| on it. It must never be stored. |
| 64 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \ |
| 65 !defined(USE_GTK_MESSAGE_PUMP) |
63 base::MessageLoop::Dispatcher* GetDispatcher(); | 66 base::MessageLoop::Dispatcher* GetDispatcher(); |
| 67 #endif |
64 | 68 |
65 // Invoked by RootWindow when its host is activated. | 69 // Invoked by RootWindow when its host is activated. |
66 void RootWindowActivated(RootWindow* root_window); | 70 void RootWindowActivated(RootWindow* root_window); |
67 | 71 |
68 private: | 72 private: |
69 friend class Window; | 73 friend class Window; |
70 friend class RootWindow; | 74 friend class RootWindow; |
71 | 75 |
72 void Init(); | 76 void Init(); |
73 | 77 |
74 // Called by the Window when it is initialized. Notifies observers. | 78 // Called by the Window when it is initialized. Notifies observers. |
75 void NotifyWindowInitialized(Window* window); | 79 void NotifyWindowInitialized(Window* window); |
76 | 80 |
77 // Called by the RootWindow when it is initialized. Notifies observers. | 81 // Called by the RootWindow when it is initialized. Notifies observers. |
78 void NotifyRootWindowInitialized(RootWindow* root_window); | 82 void NotifyRootWindowInitialized(RootWindow* root_window); |
79 | 83 |
80 // Overridden from ui::EventTarget: | 84 // Overridden from ui::EventTarget: |
81 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; | 85 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE; |
82 virtual ui::EventTarget* GetParentTarget() OVERRIDE; | 86 virtual ui::EventTarget* GetParentTarget() OVERRIDE; |
83 | 87 |
84 ObserverList<EnvObserver> observers_; | 88 ObserverList<EnvObserver> observers_; |
85 #if !defined(USE_X11) | 89 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11) |
86 scoped_ptr<base::MessageLoop::Dispatcher> dispatcher_; | 90 scoped_ptr<base::MessageLoop::Dispatcher> dispatcher_; |
87 #endif | 91 #endif |
88 | 92 |
89 static Env* instance_; | 93 static Env* instance_; |
90 int mouse_button_flags_; | 94 int mouse_button_flags_; |
91 // Location of last mouse event, in screen coordinates. | 95 // Location of last mouse event, in screen coordinates. |
92 gfx::Point last_mouse_location_; | 96 gfx::Point last_mouse_location_; |
93 bool is_touch_down_; | 97 bool is_touch_down_; |
94 | 98 |
95 #if defined(USE_X11) | 99 #if defined(USE_X11) |
96 DeviceListUpdaterAuraX11 device_list_updater_aurax11_; | 100 DeviceListUpdaterAuraX11 device_list_updater_aurax11_; |
97 #endif | 101 #endif |
98 | 102 |
99 DISALLOW_COPY_AND_ASSIGN(Env); | 103 DISALLOW_COPY_AND_ASSIGN(Env); |
100 }; | 104 }; |
101 | 105 |
102 } // namespace aura | 106 } // namespace aura |
103 | 107 |
104 #endif // UI_AURA_ENV_H_ | 108 #endif // UI_AURA_ENV_H_ |
OLD | NEW |