Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(244)

Side by Side Diff: apps/shell/browser/shell_desktop_controller.cc

Issue 308783002: Removes the dependency to WMTestHelper from app shell. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment fix Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "apps/shell/browser/shell_desktop_controller.h" 5 #include "apps/shell/browser/shell_desktop_controller.h"
6 6
7 #include "apps/shell/browser/shell_app_window.h" 7 #include "apps/shell/browser/shell_app_window.h"
8 #include "content/public/browser/context_factory.h" 8 #include "content/public/browser/context_factory.h"
9 #include "ui/aura/client/cursor_client.h" 9 #include "ui/aura/client/cursor_client.h"
10 #include "ui/aura/client/default_capture_client.h"
10 #include "ui/aura/env.h" 11 #include "ui/aura/env.h"
11 #include "ui/aura/layout_manager.h" 12 #include "ui/aura/layout_manager.h"
12 #include "ui/aura/test/test_screen.h" 13 #include "ui/aura/test/test_screen.h"
13 #include "ui/aura/window.h" 14 #include "ui/aura/window.h"
14 #include "ui/aura/window_event_dispatcher.h" 15 #include "ui/aura/window_event_dispatcher.h"
15 #include "ui/aura/window_tree_host.h" 16 #include "ui/aura/window_tree_host.h"
16 #include "ui/base/cursor/cursor.h" 17 #include "ui/base/cursor/cursor.h"
17 #include "ui/base/cursor/image_cursors.h" 18 #include "ui/base/cursor/image_cursors.h"
18 #include "ui/base/ime/input_method_initializer.h" 19 #include "ui/base/ime/input_method_initializer.h"
19 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gfx/screen.h" 21 #include "ui/gfx/screen.h"
22 #include "ui/wm/core/base_focus_rules.h"
23 #include "ui/wm/core/compound_event_filter.h"
21 #include "ui/wm/core/cursor_manager.h" 24 #include "ui/wm/core/cursor_manager.h"
25 #include "ui/wm/core/default_activation_client.h"
26 #include "ui/wm/core/focus_controller.h"
27 #include "ui/wm/core/input_method_event_filter.h"
22 #include "ui/wm/core/native_cursor_manager.h" 28 #include "ui/wm/core/native_cursor_manager.h"
23 #include "ui/wm/core/native_cursor_manager_delegate.h" 29 #include "ui/wm/core/native_cursor_manager_delegate.h"
24 #include "ui/wm/core/user_activity_detector.h" 30 #include "ui/wm/core/user_activity_detector.h"
25 #include "ui/wm/test/wm_test_helper.h"
26 31
27 #if defined(OS_CHROMEOS) 32 #if defined(OS_CHROMEOS)
28 #include "ui/chromeos/user_activity_power_manager_notifier.h" 33 #include "ui/chromeos/user_activity_power_manager_notifier.h"
29 #include "ui/display/types/chromeos/display_mode.h" 34 #include "ui/display/types/chromeos/display_mode.h"
30 #include "ui/display/types/chromeos/display_snapshot.h" 35 #include "ui/display/types/chromeos/display_snapshot.h"
31 #endif 36 #endif
32 37
33 namespace apps { 38 namespace apps {
34 namespace { 39 namespace {
35 40
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 host_->SetCursor(cursor); 136 host_->SetCursor(cursor);
132 } 137 }
133 138
134 aura::WindowTreeHost* host_; // Not owned. 139 aura::WindowTreeHost* host_; // Not owned.
135 140
136 scoped_ptr<ui::ImageCursors> image_cursors_; 141 scoped_ptr<ui::ImageCursors> image_cursors_;
137 142
138 DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager); 143 DISALLOW_COPY_AND_ASSIGN(ShellNativeCursorManager);
139 }; 144 };
140 145
146 class AppsFocusRules : public wm::BaseFocusRules {
147 public:
148 AppsFocusRules() {}
149
150 virtual bool SupportsChildActivation(aura::Window* window) const OVERRIDE {
151 return true;
152 }
153
154 private:
155 DISALLOW_COPY_AND_ASSIGN(AppsFocusRules);
156 };
157
141 ShellDesktopController* g_instance = NULL; 158 ShellDesktopController* g_instance = NULL;
142 159
143 } // namespace 160 } // namespace
144 161
145 ShellDesktopController::ShellDesktopController() { 162 ShellDesktopController::ShellDesktopController() {
146 #if defined(OS_CHROMEOS) 163 #if defined(OS_CHROMEOS)
147 display_configurator_.reset(new ui::DisplayConfigurator); 164 display_configurator_.reset(new ui::DisplayConfigurator);
148 display_configurator_->Init(false); 165 display_configurator_->Init(false);
149 display_configurator_->ForceInitialConfigure(0); 166 display_configurator_->ForceInitialConfigure(0);
150 display_configurator_->AddObserver(this); 167 display_configurator_->AddObserver(this);
151 #endif 168 #endif
152 CreateRootWindow(); 169 aura::Env::CreateInstance(true);
153 170 aura::Env::GetInstance()->set_context_factory(content::GetContextFactory());
154 cursor_manager_.reset(
155 new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>(
156 new ShellNativeCursorManager(GetWindowTreeHost()))));
157 cursor_manager_->SetDisplay(
158 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay());
159 cursor_manager_->SetCursor(ui::kCursorPointer);
160 aura::client::SetCursorClient(
161 GetWindowTreeHost()->window(), cursor_manager_.get());
162
163 user_activity_detector_.reset(new wm::UserActivityDetector);
164 GetWindowTreeHost()->event_processor()->GetRootTarget()->AddPreTargetHandler(
165 user_activity_detector_.get());
166 #if defined(OS_CHROMEOS)
167 user_activity_notifier_.reset(
168 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
169 #endif
170 171
171 g_instance = this; 172 g_instance = this;
172 } 173 }
173 174
174 ShellDesktopController::~ShellDesktopController() { 175 ShellDesktopController::~ShellDesktopController() {
175 // The app window must be explicitly closed before desktop teardown. 176 // The app window must be explicitly closed before desktop teardown.
176 DCHECK(!app_window_); 177 DCHECK(!app_window_);
177 g_instance = NULL; 178 g_instance = NULL;
178 GetWindowTreeHost()->event_processor()->GetRootTarget() 179 host_->event_processor()->GetRootTarget()->RemovePreTargetHandler(
179 ->RemovePreTargetHandler(user_activity_detector_.get()); 180 user_activity_detector_.get());
180 DestroyRootWindow(); 181 DestroyRootWindow();
181 aura::Env::DeleteInstance(); 182 aura::Env::DeleteInstance();
182 } 183 }
183 184
184 // static 185 // static
185 ShellDesktopController* ShellDesktopController::instance() { 186 ShellDesktopController* ShellDesktopController::instance() {
186 return g_instance; 187 return g_instance;
187 } 188 }
188 189
189 ShellAppWindow* ShellDesktopController::CreateAppWindow( 190 ShellAppWindow* ShellDesktopController::CreateAppWindow(
190 content::BrowserContext* context) { 191 content::BrowserContext* context) {
191 aura::Window* root_window = GetWindowTreeHost()->window(); 192 aura::Window* root_window = host_->window();
192 193
193 app_window_.reset(new ShellAppWindow); 194 app_window_.reset(new ShellAppWindow);
194 app_window_->Init(context, root_window->bounds().size()); 195 app_window_->Init(context, root_window->bounds().size());
195 196
196 // Attach the web contents view to our window hierarchy. 197 // Attach the web contents view to our window hierarchy.
197 aura::Window* content = app_window_->GetNativeWindow(); 198 aura::Window* content = app_window_->GetNativeWindow();
198 root_window->AddChild(content); 199 root_window->AddChild(content);
199 content->Show(); 200 content->Show();
200 201
201 return app_window_.get(); 202 return app_window_.get();
202 } 203 }
203 204
204 void ShellDesktopController::CloseAppWindow() { app_window_.reset(); } 205 void ShellDesktopController::CloseAppWindow() { app_window_.reset(); }
205 206
206 aura::WindowTreeHost* ShellDesktopController::GetWindowTreeHost() { 207 aura::Window* ShellDesktopController::GetDefaultParent(
207 return wm_test_helper_->host(); 208 aura::Window* context,
209 aura::Window* window,
210 const gfx::Rect& bounds) {
211 return host_->window();
208 } 212 }
209 213
210 #if defined(OS_CHROMEOS) 214 #if defined(OS_CHROMEOS)
211 void ShellDesktopController::OnDisplayModeChanged( 215 void ShellDesktopController::OnDisplayModeChanged(
212 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) { 216 const std::vector<ui::DisplayConfigurator::DisplayState>& displays) {
213 gfx::Size size = GetPrimaryDisplaySize(); 217 gfx::Size size = GetPrimaryDisplaySize();
214 if (!size.IsEmpty()) 218 if (!size.IsEmpty())
215 wm_test_helper_->host()->UpdateRootWindowSize(size); 219 host_->UpdateRootWindowSize(size);
216 } 220 }
217 #endif 221 #endif
218 222
219 void ShellDesktopController::CreateRootWindow() { 223 void ShellDesktopController::CreateRootWindow() {
220 test_screen_.reset(aura::TestScreen::Create()); 224 test_screen_.reset(aura::TestScreen::Create());
221 // TODO(jamescook): Replace this with a real Screen implementation. 225 // TODO(jamescook): Replace this with a real Screen implementation.
222 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get()); 226 gfx::Screen::SetScreenInstance(gfx::SCREEN_TYPE_NATIVE, test_screen_.get());
223 // TODO(jamescook): Initialize a real input method. 227 // TODO(jamescook): Initialize a real input method.
224 ui::InitializeInputMethodForTesting(); 228 ui::InitializeInputMethodForTesting();
225 229
226 // Set up basic pieces of ui::wm. 230 // Set up basic pieces of ui::wm.
227 gfx::Size size = GetPrimaryDisplaySize(); 231 gfx::Size size = GetPrimaryDisplaySize();
228 if (size.IsEmpty()) 232 if (size.IsEmpty())
229 size = gfx::Size(800, 600); 233 size = gfx::Size(800, 600);
230 wm_test_helper_.reset( 234
231 new wm::WMTestHelper(size, content::GetContextFactory())); 235 host_.reset(aura::WindowTreeHost::Create(gfx::Rect(size)));
236 host_->InitHost();
237 aura::client::SetWindowTreeClient(host_->window(), this);
238 root_window_event_filter_.reset(new wm::CompoundEventFilter);
239 host_->window()->AddPreTargetHandler(root_window_event_filter_.get());
240 InitWindowManager();
241
242 // Ensure the X window gets mapped.
243 host_->Show();
244 }
245
246 void ShellDesktopController::InitWindowManager() {
247 focus_client_.reset(new wm::FocusController(new AppsFocusRules()));
248 aura::client::SetFocusClient(host_->window(), focus_client_.get());
249
250 input_method_filter_.reset(
251 new wm::InputMethodEventFilter(host_->GetAcceleratedWidget()));
252 input_method_filter_->SetInputMethodPropertyInRootWindow(host_->window());
253 root_window_event_filter_->AddHandler(input_method_filter_.get());
254
255 new wm::DefaultActivationClient(host_->window());
256
257 capture_client_.reset(
258 new aura::client::DefaultCaptureClient(host_->window()));
232 259
233 // Ensure new windows fill the display. 260 // Ensure new windows fill the display.
234 aura::WindowTreeHost* host = wm_test_helper_->host(); 261 host_->window()->SetLayoutManager(new FillLayout);
235 host->window()->SetLayoutManager(new FillLayout);
236 262
237 // Ensure the X window gets mapped. 263 cursor_manager_.reset(
238 host->Show(); 264 new wm::CursorManager(scoped_ptr<wm::NativeCursorManager>(
265 new ShellNativeCursorManager(host_.get()))));
266 cursor_manager_->SetDisplay(
267 gfx::Screen::GetNativeScreen()->GetPrimaryDisplay());
268 cursor_manager_->SetCursor(ui::kCursorPointer);
269 aura::client::SetCursorClient(host_->window(), cursor_manager_.get());
270
271 user_activity_detector_.reset(new wm::UserActivityDetector);
272 host_->event_processor()->GetRootTarget()->AddPreTargetHandler(
273 user_activity_detector_.get());
274 #if defined(OS_CHROMEOS)
275 user_activity_notifier_.reset(
276 new ui::UserActivityPowerManagerNotifier(user_activity_detector_.get()));
277 #endif
239 } 278 }
240 279
241 void ShellDesktopController::DestroyRootWindow() { 280 void ShellDesktopController::DestroyRootWindow() {
242 wm_test_helper_.reset(); 281 if (input_method_filter_)
282 root_window_event_filter_->RemoveHandler(input_method_filter_.get());
283 root_window_event_filter_.reset();
284 capture_client_.reset();
285 input_method_filter_.reset();
286 focus_client_.reset();
287 cursor_manager_.reset();
288 #if defined(OS_CHROMEOS)
289 user_activity_notifier_.reset();
290 #endif
291 user_activity_detector_.reset();
292 host_.reset();
243 ui::ShutdownInputMethodForTesting(); 293 ui::ShutdownInputMethodForTesting();
244 } 294 }
245 295
246 gfx::Size ShellDesktopController::GetPrimaryDisplaySize() { 296 gfx::Size ShellDesktopController::GetPrimaryDisplaySize() {
247 #if defined(OS_CHROMEOS) 297 #if defined(OS_CHROMEOS)
248 const std::vector<ui::DisplayConfigurator::DisplayState>& displays = 298 const std::vector<ui::DisplayConfigurator::DisplayState>& displays =
249 display_configurator_->cached_displays(); 299 display_configurator_->cached_displays();
250 if (displays.empty()) 300 if (displays.empty())
251 return gfx::Size(); 301 return gfx::Size();
252 const ui::DisplayMode* mode = displays[0].display->current_mode(); 302 const ui::DisplayMode* mode = displays[0].display->current_mode();
253 return mode ? mode->size() : gfx::Size(); 303 return mode ? mode->size() : gfx::Size();
254 #else 304 #else
255 return gfx::Size(); 305 return gfx::Size();
256 #endif 306 #endif
257 } 307 }
258 308
259 } // namespace apps 309 } // namespace apps
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698