Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / aura / env.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_AURA_ENV_H_
6 #define UI_AURA_ENV_H_
7
8 #include "base/memory/scoped_ptr.h"
9 #include "base/observer_list.h"
10 #include "ui/aura/aura_export.h"
11 #include "ui/events/event_handler.h"
12 #include "ui/events/event_target.h"
13 #include "ui/gfx/point.h"
14
15 #if defined(USE_X11)
16 #include "ui/aura/device_list_updater_aurax11.h"
17 #endif
18
19 namespace aura {
20
21 namespace test {
22 class EnvTestHelper;
23 }
24
25 class EnvObserver;
26 class InputStateLookup;
27 class RootWindow;
28 class Window;
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 void CreateInstance();
38   static Env* GetInstance();
39   static void DeleteInstance();
40
41   void AddObserver(EnvObserver* observer);
42   void RemoveObserver(EnvObserver* observer);
43
44   void set_mouse_button_flags(int mouse_button_flags) {
45     mouse_button_flags_ = mouse_button_flags;
46   }
47   // Returns true if a mouse button is down. This may query the native OS,
48   // otherwise it uses |mouse_button_flags_|.
49   bool IsMouseButtonDown() const;
50
51   // Gets/sets the last mouse location seen in a mouse event in the screen
52   // coordinates.
53   const gfx::Point& last_mouse_location() const { return last_mouse_location_; }
54   void set_last_mouse_location(const gfx::Point& last_mouse_location) {
55     last_mouse_location_ = last_mouse_location;
56   }
57
58   // Whether any touch device is currently down.
59   bool is_touch_down() const { return is_touch_down_; }
60   void set_touch_down(bool value) { is_touch_down_ = value; }
61
62   // Invoked by RootWindow when its host is activated.
63   void RootWindowActivated(RootWindow* root_window);
64
65  private:
66   friend class test::EnvTestHelper;
67   friend class Window;
68   friend class WindowTreeHost;
69
70   void Init();
71
72   // Called by the Window when it is initialized. Notifies observers.
73   void NotifyWindowInitialized(Window* window);
74
75   // Called by the RootWindow when it is initialized. Notifies observers.
76   void NotifyRootWindowInitialized(RootWindow* root_window);
77
78   // Overridden from ui::EventTarget:
79   virtual bool CanAcceptEvent(const ui::Event& event) OVERRIDE;
80   virtual ui::EventTarget* GetParentTarget() OVERRIDE;
81   virtual scoped_ptr<ui::EventTargetIterator> GetChildIterator() const OVERRIDE;
82   virtual ui::EventTargeter* GetEventTargeter() OVERRIDE;
83
84   ObserverList<EnvObserver> observers_;
85
86   static Env* instance_;
87   int mouse_button_flags_;
88   // Location of last mouse event, in screen coordinates.
89   gfx::Point last_mouse_location_;
90   bool is_touch_down_;
91
92 #if defined(USE_X11)
93   DeviceListUpdaterAuraX11 device_list_updater_aurax11_;
94 #endif
95
96   scoped_ptr<InputStateLookup> input_state_lookup_;
97
98   DISALLOW_COPY_AND_ASSIGN(Env);
99 };
100
101 }  // namespace aura
102
103 #endif  // UI_AURA_ENV_H_