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/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/point.h"
18 class PlatformEventSource
;
27 class InputStateLookup
;
31 // A singleton object that tracks general state within Aura.
32 class AURA_EXPORT Env
: public ui::EventTarget
, public base::SupportsUserData
{
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 const 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
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_
; }
70 friend class test::EnvTestHelper
;
72 friend class WindowTreeHost
;
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 virtual bool CanAcceptEvent(const ui::Event
& event
) OVERRIDE
;
91 virtual ui::EventTarget
* GetParentTarget() OVERRIDE
;
92 virtual scoped_ptr
<ui::EventTargetIterator
> GetChildIterator() const OVERRIDE
;
93 virtual 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_
;
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
);
112 #endif // UI_AURA_ENV_H_