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.
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_pump_dispatcher.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"
17 #include "ui/aura/device_list_updater_aurax11.h"
27 class InputStateLookup;
31 // Creates a platform-specific native event dispatcher.
32 base::MessagePumpDispatcher* CreateDispatcher();
34 // A singleton object that tracks general state within Aura.
35 // TODO(beng): manage RootWindows.
36 class AURA_EXPORT Env : public ui::EventTarget {
41 static void CreateInstance();
42 static Env* GetInstance();
43 static void DeleteInstance();
45 void AddObserver(EnvObserver* observer);
46 void RemoveObserver(EnvObserver* observer);
48 void set_mouse_button_flags(int mouse_button_flags) {
49 mouse_button_flags_ = mouse_button_flags;
51 // Returns true if a mouse button is down. This may query the native OS,
52 // otherwise it uses |mouse_button_flags_|.
53 bool IsMouseButtonDown() const;
55 // Gets/sets the last mouse location seen in a mouse event in the screen
57 const gfx::Point& last_mouse_location() const { return last_mouse_location_; }
58 void set_last_mouse_location(const gfx::Point& last_mouse_location) {
59 last_mouse_location_ = last_mouse_location;
62 // Whether any touch device is currently down.
63 bool is_touch_down() const { return is_touch_down_; }
64 void set_touch_down(bool value) { is_touch_down_ = value; }
66 // Returns the native event dispatcher. The result should only be passed to
67 // base::RunLoop(dispatcher), or used to dispatch an event by
68 // |Dispatch(const NativeEvent&)| on it. It must never be stored.
69 base::MessagePumpDispatcher* GetDispatcher();
71 // Invoked by RootWindow when its host is activated.
72 void RootWindowActivated(RootWindow* root_window);
75 friend class test::EnvTestHelper;
77 friend class WindowTreeHost;
81 // Called by the Window when it is initialized. Notifies observers.
82 void NotifyWindowInitialized(Window* window);
84 // Called by the RootWindow when it is initialized. Notifies observers.
85 void NotifyRootWindowInitialized(RootWindow* root_window);
87 // Overridden from ui::EventTarget:
88 virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
89 virtual ui::EventTarget* GetParentTarget() OVERRIDE;
90 virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE;
91 virtual ui::EventTargeter* GetEventTargeter() OVERRIDE;
93 ObserverList<EnvObserver> observers_;
94 scoped_ptr<base::MessagePumpDispatcher> dispatcher_;
96 static Env* instance_;
97 int mouse_button_flags_;
98 // Location of last mouse event, in screen coordinates.
99 gfx::Point last_mouse_location_;
103 DeviceListUpdaterAuraX11 device_list_updater_aurax11_;
106 scoped_ptr<InputStateLookup> input_state_lookup_;
108 DISALLOW_COPY_AND_ASSIGN(Env);
113 #endif // UI_AURA_ENV_H_