OLD | NEW |
| (Empty) |
1 // Copyright 2016 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 #include "ash/wm/aura/wm_root_window_controller_aura.h" | |
6 | |
7 #include "ash/common/wm/wm_root_window_controller_observer.h" | |
8 #include "ash/display/window_tree_host_manager.h" | |
9 #include "ash/root_window_controller.h" | |
10 #include "ash/shelf/shelf.h" | |
11 #include "ash/shelf/shelf_widget.h" | |
12 #include "ash/shell.h" | |
13 #include "ash/wm/aura/wm_globals_aura.h" | |
14 #include "ash/wm/aura/wm_shelf_aura.h" | |
15 #include "ash/wm/aura/wm_window_aura.h" | |
16 #include "ash/wm/workspace_controller.h" | |
17 #include "ui/aura/window.h" | |
18 #include "ui/aura/window_property.h" | |
19 #include "ui/events/event_targeter.h" | |
20 #include "ui/events/event_utils.h" | |
21 | |
22 DECLARE_WINDOW_PROPERTY_TYPE(ash::wm::WmRootWindowControllerAura*); | |
23 | |
24 namespace ash { | |
25 namespace wm { | |
26 | |
27 // TODO(sky): it likely makes more sense to hang this off RootWindowSettings. | |
28 DEFINE_OWNED_WINDOW_PROPERTY_KEY(ash::wm::WmRootWindowControllerAura, | |
29 kWmRootWindowControllerKey, | |
30 nullptr); | |
31 | |
32 WmRootWindowControllerAura::WmRootWindowControllerAura( | |
33 RootWindowController* root_window_controller) | |
34 : root_window_controller_(root_window_controller) { | |
35 root_window_controller_->GetRootWindow()->SetProperty( | |
36 kWmRootWindowControllerKey, this); | |
37 Shell::GetInstance()->AddShellObserver(this); | |
38 } | |
39 | |
40 WmRootWindowControllerAura::~WmRootWindowControllerAura() { | |
41 Shell::GetInstance()->RemoveShellObserver(this); | |
42 } | |
43 | |
44 // static | |
45 const WmRootWindowControllerAura* WmRootWindowControllerAura::Get( | |
46 const aura::Window* window) { | |
47 if (!window) | |
48 return nullptr; | |
49 | |
50 RootWindowController* root_window_controller = | |
51 GetRootWindowController(window); | |
52 if (!root_window_controller) | |
53 return nullptr; | |
54 | |
55 WmRootWindowControllerAura* wm_root_window_controller = | |
56 root_window_controller->GetRootWindow()->GetProperty( | |
57 kWmRootWindowControllerKey); | |
58 if (wm_root_window_controller) | |
59 return wm_root_window_controller; | |
60 | |
61 // WmRootWindowControllerAura is owned by the RootWindowController's window. | |
62 return new WmRootWindowControllerAura(root_window_controller); | |
63 } | |
64 | |
65 bool WmRootWindowControllerAura::HasShelf() { | |
66 return root_window_controller_->shelf_widget() != nullptr; | |
67 } | |
68 | |
69 WmGlobals* WmRootWindowControllerAura::GetGlobals() { | |
70 return WmGlobals::Get(); | |
71 } | |
72 | |
73 WorkspaceWindowState WmRootWindowControllerAura::GetWorkspaceWindowState() { | |
74 return root_window_controller_->workspace_controller()->GetWindowState(); | |
75 } | |
76 | |
77 AlwaysOnTopController* WmRootWindowControllerAura::GetAlwaysOnTopController() { | |
78 return root_window_controller_->always_on_top_controller(); | |
79 } | |
80 | |
81 WmShelf* WmRootWindowControllerAura::GetShelf() { | |
82 return root_window_controller_->shelf_widget() | |
83 ? root_window_controller_->shelf_widget()->shelf()->wm_shelf() | |
84 : nullptr; | |
85 } | |
86 | |
87 WmWindow* WmRootWindowControllerAura::GetWindow() { | |
88 return WmWindowAura::Get(root_window_controller_->GetRootWindow()); | |
89 } | |
90 | |
91 void WmRootWindowControllerAura::ConfigureWidgetInitParamsForContainer( | |
92 views::Widget* widget, | |
93 int shell_container_id, | |
94 views::Widget::InitParams* init_params) { | |
95 init_params->parent = Shell::GetContainer( | |
96 root_window_controller_->GetRootWindow(), shell_container_id); | |
97 } | |
98 | |
99 WmWindow* WmRootWindowControllerAura::FindEventTarget( | |
100 const gfx::Point& location_in_screen) { | |
101 gfx::Point location_in_root = | |
102 GetWindow()->ConvertPointFromScreen(location_in_screen); | |
103 aura::Window* root = root_window_controller_->GetRootWindow(); | |
104 ui::MouseEvent test_event(ui::ET_MOUSE_MOVED, location_in_root, | |
105 location_in_root, ui::EventTimeForNow(), | |
106 ui::EF_NONE, ui::EF_NONE); | |
107 ui::EventTarget* event_handler = static_cast<ui::EventTarget*>(root) | |
108 ->GetEventTargeter() | |
109 ->FindTargetForEvent(root, &test_event); | |
110 return WmWindowAura::Get(static_cast<aura::Window*>(event_handler)); | |
111 } | |
112 | |
113 void WmRootWindowControllerAura::AddObserver( | |
114 WmRootWindowControllerObserver* observer) { | |
115 observers_.AddObserver(observer); | |
116 } | |
117 | |
118 void WmRootWindowControllerAura::RemoveObserver( | |
119 WmRootWindowControllerObserver* observer) { | |
120 observers_.RemoveObserver(observer); | |
121 } | |
122 | |
123 void WmRootWindowControllerAura::OnDisplayWorkAreaInsetsChanged() { | |
124 FOR_EACH_OBSERVER(WmRootWindowControllerObserver, observers_, | |
125 OnWorkAreaChanged()); | |
126 } | |
127 | |
128 void WmRootWindowControllerAura::OnFullscreenStateChanged( | |
129 bool is_fullscreen, | |
130 aura::Window* root_window) { | |
131 if (root_window != root_window_controller_->GetRootWindow()) | |
132 return; | |
133 | |
134 FOR_EACH_OBSERVER(WmRootWindowControllerObserver, observers_, | |
135 OnFullscreenStateChanged(is_fullscreen)); | |
136 } | |
137 | |
138 void WmRootWindowControllerAura::OnShelfAlignmentChanged( | |
139 aura::Window* root_window) { | |
140 if (root_window != root_window_controller_->GetRootWindow()) | |
141 return; | |
142 | |
143 FOR_EACH_OBSERVER(WmRootWindowControllerObserver, observers_, | |
144 OnShelfAlignmentChanged()); | |
145 } | |
146 | |
147 } // namespace wm | |
148 } // namespace ash | |
OLD | NEW |