Cleanup: Update the path to insets and point headers.
[chromium-blink-merge.git] / ui / aura / env.h
blob4ae2d694f0ff67db75c8dd8ec5a5f5d2f65edbea
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/observer_list.h"
10 #include "base/supports_user_data.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/geometry/point.h"
16 namespace ui {
17 class ContextFactory;
18 class PlatformEventSource;
20 namespace aura {
22 namespace test {
23 class EnvTestHelper;
26 class EnvObserver;
27 class InputStateLookup;
28 class Window;
29 class WindowTreeHost;
31 // A singleton object that tracks general state within Aura.
32 class AURA_EXPORT Env : public ui::EventTarget, public base::SupportsUserData {
33 public:
34 // Creates the single Env instance (if it hasn't been created yet). If
35 // |create_event_source| is true a PlatformEventSource is created.
36 // TODO(sky): nuke |create_event_source|. Only necessary while mojo's
37 // nativeviewportservice lives in the same process as the viewmanager.
38 static void CreateInstance(bool create_event_source);
39 static Env* GetInstance();
40 static void DeleteInstance();
42 void AddObserver(EnvObserver* observer);
43 void RemoveObserver(EnvObserver* observer);
45 int mouse_button_flags() const { return mouse_button_flags_; }
46 void set_mouse_button_flags(int mouse_button_flags) {
47 mouse_button_flags_ = mouse_button_flags;
49 // Returns true if a mouse button is down. This may query the native OS,
50 // otherwise it uses |mouse_button_flags_|.
51 bool IsMouseButtonDown() const;
53 // Gets/sets the last mouse location seen in a mouse event in the screen
54 // coordinates.
55 const gfx::Point& last_mouse_location() const { return last_mouse_location_; }
56 void set_last_mouse_location(const gfx::Point& last_mouse_location) {
57 last_mouse_location_ = last_mouse_location;
60 // Whether any touch device is currently down.
61 bool is_touch_down() const { return is_touch_down_; }
62 void set_touch_down(bool value) { is_touch_down_ = value; }
64 void set_context_factory(ui::ContextFactory* context_factory) {
65 context_factory_ = context_factory;
67 ui::ContextFactory* context_factory() { return context_factory_; }
69 private:
70 friend class test::EnvTestHelper;
71 friend class Window;
72 friend class WindowTreeHost;
74 Env();
75 ~Env() override;
77 // See description of CreateInstance() for deatils of |create_event_source|.
78 void Init(bool create_event_source);
80 // Called by the Window when it is initialized. Notifies observers.
81 void NotifyWindowInitialized(Window* window);
83 // Called by the WindowTreeHost when it is initialized. Notifies observers.
84 void NotifyHostInitialized(WindowTreeHost* host);
86 // Invoked by WindowTreeHost when it is activated. Notifies observers.
87 void NotifyHostActivated(WindowTreeHost* host);
89 // Overridden from ui::EventTarget:
90 bool CanAcceptEvent(const ui::Event& event) override;
91 ui::EventTarget* GetParentTarget() override;
92 scoped_ptr<ui::EventTargetIterator> GetChildIterator() const override;
93 ui::EventTargeter* GetEventTargeter() override;
95 ObserverList<EnvObserver> observers_;
97 int mouse_button_flags_;
98 // Location of last mouse event, in screen coordinates.
99 gfx::Point last_mouse_location_;
100 bool is_touch_down_;
102 scoped_ptr<InputStateLookup> input_state_lookup_;
103 scoped_ptr<ui::PlatformEventSource> event_source_;
105 ui::ContextFactory* context_factory_;
107 DISALLOW_COPY_AND_ASSIGN(Env);
110 } // namespace aura
112 #endif // UI_AURA_ENV_H_