Get foreground tab on Android
[chromium-blink-merge.git] / ui / aura / env.h
blob4968d3990e19656e9744e39578ad34027a32f842
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_AURA_ENV_H_
6 #define UI_AURA_ENV_H_
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/observer_list.h"
11 #include "ui/aura/aura_export.h"
12 #include "ui/events/event_handler.h"
13 #include "ui/events/event_target.h"
14 #include "ui/gfx/point.h"
16 #if defined(USE_X11)
17 #include "ui/aura/device_list_updater_aurax11.h"
18 #endif
20 namespace aura {
22 namespace test {
23 class EnvTestHelper;
26 class EnvObserver;
27 class InputStateLookup;
28 class RootWindow;
29 class Window;
31 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11)
32 // Creates a platform-specific native event dispatcher.
33 base::MessageLoop::Dispatcher* CreateDispatcher();
34 #endif
36 // A singleton object that tracks general state within Aura.
37 // TODO(beng): manage RootWindows.
38 class AURA_EXPORT Env : public ui::EventTarget {
39 public:
40 Env();
41 virtual ~Env();
43 static void CreateInstance();
44 static Env* GetInstance();
45 static void DeleteInstance();
47 void AddObserver(EnvObserver* observer);
48 void RemoveObserver(EnvObserver* observer);
50 void set_mouse_button_flags(int mouse_button_flags) {
51 mouse_button_flags_ = mouse_button_flags;
53 // Returns true if a mouse button is down. This may query the native OS,
54 // otherwise it uses |mouse_button_flags_|.
55 bool IsMouseButtonDown() const;
57 // Gets/sets the last mouse location seen in a mouse event in the screen
58 // coordinates.
59 const gfx::Point& last_mouse_location() const { return last_mouse_location_; }
60 void set_last_mouse_location(const gfx::Point& last_mouse_location) {
61 last_mouse_location_ = last_mouse_location;
64 // Whether any touch device is currently down.
65 bool is_touch_down() const { return is_touch_down_; }
66 void set_touch_down(bool value) { is_touch_down_ = value; }
68 // Returns the native event dispatcher. The result should only be passed to
69 // base::RunLoop(dispatcher), or used to dispatch an event by
70 // |Dispatch(const NativeEvent&)| on it. It must never be stored.
71 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && \
72 !defined(USE_GTK_MESSAGE_PUMP)
73 base::MessageLoop::Dispatcher* GetDispatcher();
74 #endif
76 // Invoked by RootWindow when its host is activated.
77 void RootWindowActivated(RootWindow* root_window);
79 private:
80 friend class test::EnvTestHelper;
81 friend class Window;
82 friend class RootWindow;
84 void Init();
86 // Called by the Window when it is initialized. Notifies observers.
87 void NotifyWindowInitialized(Window* window);
89 // Called by the RootWindow when it is initialized. Notifies observers.
90 void NotifyRootWindowInitialized(RootWindow* root_window);
92 // Overridden from ui::EventTarget:
93 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
94 virtual ui::EventTarget* GetParentTarget() OVERRIDE;
96 ObserverList<EnvObserver> observers_;
97 #if !defined(OS_MACOSX) && !defined(OS_ANDROID) && !defined(USE_X11)
98 scoped_ptr<base::MessageLoop::Dispatcher> dispatcher_;
99 #endif
101 static Env* instance_;
102 int mouse_button_flags_;
103 // Location of last mouse event, in screen coordinates.
104 gfx::Point last_mouse_location_;
105 bool is_touch_down_;
107 #if defined(USE_X11)
108 DeviceListUpdaterAuraX11 device_list_updater_aurax11_;
109 #endif
111 scoped_ptr<InputStateLookup> input_state_lookup_;
113 DISALLOW_COPY_AND_ASSIGN(Env);
116 } // namespace aura
118 #endif // UI_AURA_ENV_H_