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/geometry/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 Env
* GetInstanceDontCreate();
41 static void DeleteInstance();
43 void AddObserver(EnvObserver
* observer
);
44 void RemoveObserver(EnvObserver
* observer
);
46 int mouse_button_flags() const { return mouse_button_flags_
; }
47 void set_mouse_button_flags(int mouse_button_flags
) {
48 mouse_button_flags_
= mouse_button_flags
;
50 // Returns true if a mouse button is down. This may query the native OS,
51 // otherwise it uses |mouse_button_flags_|.
52 bool IsMouseButtonDown() const;
54 // Gets/sets the last mouse location seen in a mouse event in the screen
56 const gfx::Point
& last_mouse_location() const { return last_mouse_location_
; }
57 void set_last_mouse_location(const gfx::Point
& last_mouse_location
) {
58 last_mouse_location_
= last_mouse_location
;
61 // Whether any touch device is currently down.
62 bool is_touch_down() const { return is_touch_down_
; }
63 void set_touch_down(bool value
) { is_touch_down_
= value
; }
65 void set_context_factory(ui::ContextFactory
* context_factory
) {
66 context_factory_
= context_factory
;
68 ui::ContextFactory
* context_factory() { return context_factory_
; }
71 friend class test::EnvTestHelper
;
73 friend class WindowTreeHost
;
78 // See description of CreateInstance() for deatils of |create_event_source|.
79 void Init(bool create_event_source
);
81 // Called by the Window when it is initialized. Notifies observers.
82 void NotifyWindowInitialized(Window
* window
);
84 // Called by the WindowTreeHost when it is initialized. Notifies observers.
85 void NotifyHostInitialized(WindowTreeHost
* host
);
87 // Invoked by WindowTreeHost when it is activated. Notifies observers.
88 void NotifyHostActivated(WindowTreeHost
* host
);
90 // Overridden from ui::EventTarget:
91 bool CanAcceptEvent(const ui::Event
& event
) override
;
92 ui::EventTarget
* GetParentTarget() override
;
93 scoped_ptr
<ui::EventTargetIterator
> GetChildIterator() const override
;
94 ui::EventTargeter
* GetEventTargeter() override
;
96 base::ObserverList
<EnvObserver
> observers_
;
98 int mouse_button_flags_
;
99 // Location of last mouse event, in screen coordinates.
100 gfx::Point last_mouse_location_
;
103 scoped_ptr
<InputStateLookup
> input_state_lookup_
;
104 scoped_ptr
<ui::PlatformEventSource
> event_source_
;
106 ui::ContextFactory
* context_factory_
;
108 DISALLOW_COPY_AND_ASSIGN(Env
);
113 #endif // UI_AURA_ENV_H_