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