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

Side by Side Diff: ash/display/window_tree_host_manager.cc

Issue 1924703002: Rename gfx::Display/Screen to display::Display/Screen in ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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 "ash/display/window_tree_host_manager.h" 5 #include "ash/display/window_tree_host_manager.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cmath> 8 #include <cmath>
9 #include <map> 9 #include <map>
10 #include <memory> 10 #include <memory>
(...skipping 26 matching lines...) Expand all
37 #include "ui/aura/client/capture_client.h" 37 #include "ui/aura/client/capture_client.h"
38 #include "ui/aura/client/focus_client.h" 38 #include "ui/aura/client/focus_client.h"
39 #include "ui/aura/client/screen_position_client.h" 39 #include "ui/aura/client/screen_position_client.h"
40 #include "ui/aura/window.h" 40 #include "ui/aura/window.h"
41 #include "ui/aura/window_event_dispatcher.h" 41 #include "ui/aura/window_event_dispatcher.h"
42 #include "ui/aura/window_property.h" 42 #include "ui/aura/window_property.h"
43 #include "ui/aura/window_tracker.h" 43 #include "ui/aura/window_tracker.h"
44 #include "ui/aura/window_tree_host.h" 44 #include "ui/aura/window_tree_host.h"
45 #include "ui/base/ime/input_method_factory.h" 45 #include "ui/base/ime/input_method_factory.h"
46 #include "ui/compositor/compositor.h" 46 #include "ui/compositor/compositor.h"
47 #include "ui/display/display.h"
47 #include "ui/display/manager/display_layout.h" 48 #include "ui/display/manager/display_layout.h"
48 #include "ui/gfx/display.h" 49 #include "ui/display/screen.h"
49 #include "ui/gfx/screen.h"
50 #include "ui/wm/core/coordinate_conversion.h" 50 #include "ui/wm/core/coordinate_conversion.h"
51 #include "ui/wm/public/activation_client.h" 51 #include "ui/wm/public/activation_client.h"
52 52
53 #if defined(USE_X11) 53 #if defined(USE_X11)
54 #include "ui/base/x/x11_util.h" 54 #include "ui/base/x/x11_util.h"
55 #include "ui/gfx/x/x11_types.h" // nogncheck 55 #include "ui/gfx/x/x11_types.h" // nogncheck
56 56
57 // Including this at the bottom to avoid other 57 // Including this at the bottom to avoid other
58 // potential conflict with chrome headers. 58 // potential conflict with chrome headers.
59 #include <X11/extensions/Xrandr.h> 59 #include <X11/extensions/Xrandr.h>
(...skipping 17 matching lines...) Expand all
77 #if defined(USE_OZONE) && defined(OS_CHROMEOS) 77 #if defined(USE_OZONE) && defined(OS_CHROMEOS)
78 // Add 20% more cursor motion on non-integrated displays. 78 // Add 20% more cursor motion on non-integrated displays.
79 const float kCursorMultiplierForExternalDisplays = 1.2f; 79 const float kCursorMultiplierForExternalDisplays = 1.2f;
80 #endif 80 #endif
81 81
82 DisplayManager* GetDisplayManager() { 82 DisplayManager* GetDisplayManager() {
83 return Shell::GetInstance()->display_manager(); 83 return Shell::GetInstance()->display_manager();
84 } 84 }
85 85
86 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host, 86 void SetDisplayPropertiesOnHost(AshWindowTreeHost* ash_host,
87 const gfx::Display& display) { 87 const display::Display& display) {
88 DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display.id()); 88 DisplayInfo info = GetDisplayManager()->GetDisplayInfo(display.id());
89 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); 89 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
90 #if defined(OS_CHROMEOS) 90 #if defined(OS_CHROMEOS)
91 #if defined(USE_X11) 91 #if defined(USE_X11)
92 // Native window property (Atom in X11) that specifies the display's 92 // Native window property (Atom in X11) that specifies the display's
93 // rotation, scale factor and if it's internal display. They are 93 // rotation, scale factor and if it's internal display. They are
94 // read and used by touchpad/mouse driver directly on X (contact 94 // read and used by touchpad/mouse driver directly on X (contact
95 // adlr@ for more details on touchpad/mouse driver side). The value 95 // adlr@ for more details on touchpad/mouse driver side). The value
96 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2 96 // of the rotation is one of 0 (normal), 1 (90 degrees clockwise), 2
97 // (180 degree) or 3 (270 degrees clockwise). The value of the 97 // (180 degree) or 3 (270 degrees clockwise). The value of the
98 // scale factor is in percent (100, 140, 200 etc). 98 // scale factor is in percent (100, 140, 200 etc).
99 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION"; 99 const char kRotationProp[] = "_CHROME_DISPLAY_ROTATION";
100 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR"; 100 const char kScaleFactorProp[] = "_CHROME_DISPLAY_SCALE_FACTOR";
101 const char kInternalProp[] = "_CHROME_DISPLAY_INTERNAL"; 101 const char kInternalProp[] = "_CHROME_DISPLAY_INTERNAL";
102 const char kCARDINAL[] = "CARDINAL"; 102 const char kCARDINAL[] = "CARDINAL";
103 int xrandr_rotation = RR_Rotate_0; 103 int xrandr_rotation = RR_Rotate_0;
104 switch (info.GetActiveRotation()) { 104 switch (info.GetActiveRotation()) {
105 case gfx::Display::ROTATE_0: 105 case display::Display::ROTATE_0:
106 xrandr_rotation = RR_Rotate_0; 106 xrandr_rotation = RR_Rotate_0;
107 break; 107 break;
108 case gfx::Display::ROTATE_90: 108 case display::Display::ROTATE_90:
109 xrandr_rotation = RR_Rotate_90; 109 xrandr_rotation = RR_Rotate_90;
110 break; 110 break;
111 case gfx::Display::ROTATE_180: 111 case display::Display::ROTATE_180:
112 xrandr_rotation = RR_Rotate_180; 112 xrandr_rotation = RR_Rotate_180;
113 break; 113 break;
114 case gfx::Display::ROTATE_270: 114 case display::Display::ROTATE_270:
115 xrandr_rotation = RR_Rotate_270; 115 xrandr_rotation = RR_Rotate_270;
116 break; 116 break;
117 } 117 }
118 118
119 int internal = display.IsInternal() ? 1 : 0; 119 int internal = display.IsInternal() ? 1 : 0;
120 gfx::AcceleratedWidget xwindow = host->GetAcceleratedWidget(); 120 gfx::AcceleratedWidget xwindow = host->GetAcceleratedWidget();
121 ui::SetIntProperty(xwindow, kInternalProp, kCARDINAL, internal); 121 ui::SetIntProperty(xwindow, kInternalProp, kCARDINAL, internal);
122 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, xrandr_rotation); 122 ui::SetIntProperty(xwindow, kRotationProp, kCARDINAL, xrandr_rotation);
123 ui::SetIntProperty(xwindow, kScaleFactorProp, kCARDINAL, 123 ui::SetIntProperty(xwindow, kScaleFactorProp, kCARDINAL,
124 100 * display.device_scale_factor()); 124 100 * display.device_scale_factor());
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 }; 231 };
232 232
233 //////////////////////////////////////////////////////////////////////////////// 233 ////////////////////////////////////////////////////////////////////////////////
234 // WindowTreeHostManager 234 // WindowTreeHostManager
235 235
236 WindowTreeHostManager::WindowTreeHostManager() 236 WindowTreeHostManager::WindowTreeHostManager()
237 : primary_tree_host_for_replace_(nullptr), 237 : primary_tree_host_for_replace_(nullptr),
238 focus_activation_store_(new FocusActivationStore()), 238 focus_activation_store_(new FocusActivationStore()),
239 cursor_window_controller_(new CursorWindowController()), 239 cursor_window_controller_(new CursorWindowController()),
240 mirror_window_controller_(new MirrorWindowController()), 240 mirror_window_controller_(new MirrorWindowController()),
241 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID), 241 cursor_display_id_for_restore_(display::Display::kInvalidDisplayID),
242 weak_ptr_factory_(this) { 242 weak_ptr_factory_(this) {
243 // Reset primary display to make sure that tests don't use 243 // Reset primary display to make sure that tests don't use
244 // stale display info from previous tests. 244 // stale display info from previous tests.
245 primary_display_id = gfx::Display::kInvalidDisplayID; 245 primary_display_id = display::Display::kInvalidDisplayID;
246 } 246 }
247 247
248 WindowTreeHostManager::~WindowTreeHostManager() {} 248 WindowTreeHostManager::~WindowTreeHostManager() {}
249 249
250 void WindowTreeHostManager::Start() { 250 void WindowTreeHostManager::Start() {
251 gfx::Screen::GetScreen()->AddObserver(this); 251 display::Screen::GetScreen()->AddObserver(this);
252 Shell::GetInstance()->display_manager()->set_delegate(this); 252 Shell::GetInstance()->display_manager()->set_delegate(this);
253 } 253 }
254 254
255 void WindowTreeHostManager::Shutdown() { 255 void WindowTreeHostManager::Shutdown() {
256 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown()); 256 FOR_EACH_OBSERVER(Observer, observers_, OnWindowTreeHostManagerShutdown());
257 257
258 // Unset the display manager's delegate here because 258 // Unset the display manager's delegate here because
259 // DisplayManager outlives WindowTreeHostManager. 259 // DisplayManager outlives WindowTreeHostManager.
260 Shell::GetInstance()->display_manager()->set_delegate(nullptr); 260 Shell::GetInstance()->display_manager()->set_delegate(nullptr);
261 261
262 cursor_window_controller_.reset(); 262 cursor_window_controller_.reset();
263 mirror_window_controller_.reset(); 263 mirror_window_controller_.reset();
264 264
265 gfx::Screen::GetScreen()->RemoveObserver(this); 265 display::Screen::GetScreen()->RemoveObserver(this);
266 266
267 int64_t primary_id = gfx::Screen::GetScreen()->GetPrimaryDisplay().id(); 267 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
268 268
269 // Delete non primary root window controllers first, then 269 // Delete non primary root window controllers first, then
270 // delete the primary root window controller. 270 // delete the primary root window controller.
271 aura::Window::Windows root_windows = 271 aura::Window::Windows root_windows =
272 WindowTreeHostManager::GetAllRootWindows(); 272 WindowTreeHostManager::GetAllRootWindows();
273 std::vector<RootWindowController*> to_delete; 273 std::vector<RootWindowController*> to_delete;
274 RootWindowController* primary_rwc = nullptr; 274 RootWindowController* primary_rwc = nullptr;
275 for (aura::Window::Windows::iterator iter = root_windows.begin(); 275 for (aura::Window::Windows::iterator iter = root_windows.begin();
276 iter != root_windows.end(); ++iter) { 276 iter != root_windows.end(); ++iter) {
277 RootWindowController* rwc = GetRootWindowController(*iter); 277 RootWindowController* rwc = GetRootWindowController(*iter);
278 if (GetRootWindowSettings(*iter)->display_id == primary_id) 278 if (GetRootWindowSettings(*iter)->display_id == primary_id)
279 primary_rwc = rwc; 279 primary_rwc = rwc;
280 else 280 else
281 to_delete.push_back(rwc); 281 to_delete.push_back(rwc);
282 } 282 }
283 CHECK(primary_rwc); 283 CHECK(primary_rwc);
284 284
285 STLDeleteElements(&to_delete); 285 STLDeleteElements(&to_delete);
286 delete primary_rwc; 286 delete primary_rwc;
287 } 287 }
288 288
289 void WindowTreeHostManager::CreatePrimaryHost( 289 void WindowTreeHostManager::CreatePrimaryHost(
290 const AshWindowTreeHostInitParams& init_params) { 290 const AshWindowTreeHostInitParams& init_params) {
291 const gfx::Display& primary_candidate = 291 const display::Display& primary_candidate =
292 GetDisplayManager()->GetPrimaryDisplayCandidate(); 292 GetDisplayManager()->GetPrimaryDisplayCandidate();
293 primary_display_id = primary_candidate.id(); 293 primary_display_id = primary_candidate.id();
294 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); 294 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id);
295 AddWindowTreeHostForDisplay(primary_candidate, init_params); 295 AddWindowTreeHostForDisplay(primary_candidate, init_params);
296 } 296 }
297 297
298 void WindowTreeHostManager::InitHosts() { 298 void WindowTreeHostManager::InitHosts() {
299 RootWindowController::CreateForPrimaryDisplay( 299 RootWindowController::CreateForPrimaryDisplay(
300 window_tree_hosts_[primary_display_id]); 300 window_tree_hosts_[primary_display_id]);
301 DisplayManager* display_manager = GetDisplayManager(); 301 DisplayManager* display_manager = GetDisplayManager();
302 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 302 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
303 const gfx::Display& display = display_manager->GetDisplayAt(i); 303 const display::Display& display = display_manager->GetDisplayAt(i);
304 if (primary_display_id != display.id()) { 304 if (primary_display_id != display.id()) {
305 AshWindowTreeHost* ash_host = 305 AshWindowTreeHost* ash_host =
306 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); 306 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams());
307 RootWindowController::CreateForSecondaryDisplay(ash_host); 307 RootWindowController::CreateForSecondaryDisplay(ash_host);
308 } 308 }
309 } 309 }
310 310
311 FOR_EACH_OBSERVER(Observer, observers_, OnDisplaysInitialized()); 311 FOR_EACH_OBSERVER(Observer, observers_, OnDisplaysInitialized());
312 } 312 }
313 313
314 void WindowTreeHostManager::AddObserver(Observer* observer) { 314 void WindowTreeHostManager::AddObserver(Observer* observer) {
315 observers_.AddObserver(observer); 315 observers_.AddObserver(observer);
316 } 316 }
317 317
318 void WindowTreeHostManager::RemoveObserver(Observer* observer) { 318 void WindowTreeHostManager::RemoveObserver(Observer* observer) {
319 observers_.RemoveObserver(observer); 319 observers_.RemoveObserver(observer);
320 } 320 }
321 321
322 // static 322 // static
323 int64_t WindowTreeHostManager::GetPrimaryDisplayId() { 323 int64_t WindowTreeHostManager::GetPrimaryDisplayId() {
324 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); 324 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id);
325 return primary_display_id; 325 return primary_display_id;
326 } 326 }
327 327
328 aura::Window* WindowTreeHostManager::GetPrimaryRootWindow() { 328 aura::Window* WindowTreeHostManager::GetPrimaryRootWindow() {
329 return GetRootWindowForDisplayId(primary_display_id); 329 return GetRootWindowForDisplayId(primary_display_id);
330 } 330 }
331 331
332 aura::Window* WindowTreeHostManager::GetRootWindowForDisplayId(int64_t id) { 332 aura::Window* WindowTreeHostManager::GetRootWindowForDisplayId(int64_t id) {
333 AshWindowTreeHost* host = GetAshWindowTreeHostForDisplayId(id); 333 AshWindowTreeHost* host = GetAshWindowTreeHostForDisplayId(id);
334 CHECK(host); 334 CHECK(host);
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
387 RootWindowController* controller = 387 RootWindowController* controller =
388 GetRootWindowController(GetWindow(it->second)); 388 GetRootWindowController(GetWindow(it->second));
389 if (controller) 389 if (controller)
390 controllers.push_back(controller); 390 controllers.push_back(controller);
391 } 391 }
392 return controllers; 392 return controllers;
393 } 393 }
394 394
395 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) { 395 void WindowTreeHostManager::SetPrimaryDisplayId(int64_t id) {
396 // TODO(oshima): Move primary display management to DisplayManager. 396 // TODO(oshima): Move primary display management to DisplayManager.
397 DCHECK_NE(gfx::Display::kInvalidDisplayID, id); 397 DCHECK_NE(display::Display::kInvalidDisplayID, id);
398 if (id == gfx::Display::kInvalidDisplayID || primary_display_id == id || 398 if (id == display::Display::kInvalidDisplayID || primary_display_id == id ||
399 window_tree_hosts_.size() < 2) { 399 window_tree_hosts_.size() < 2) {
400 return; 400 return;
401 } 401 }
402 // TODO(oshima): Implement swapping primary for 2> displays. 402 // TODO(oshima): Implement swapping primary for 2> displays.
403 if (GetDisplayManager()->GetNumDisplays() > 2) 403 if (GetDisplayManager()->GetNumDisplays() > 2)
404 return; 404 return;
405 405
406 const gfx::Display& new_primary_display = 406 const display::Display& new_primary_display =
407 GetDisplayManager()->GetDisplayForId(id); 407 GetDisplayManager()->GetDisplayForId(id);
408 if (!new_primary_display.is_valid()) { 408 if (!new_primary_display.is_valid()) {
409 LOG(ERROR) << "Invalid or non-existent display is requested:" 409 LOG(ERROR) << "Invalid or non-existent display is requested:"
410 << new_primary_display.ToString(); 410 << new_primary_display.ToString();
411 return; 411 return;
412 } 412 }
413 413
414 DisplayManager* display_manager = GetDisplayManager(); 414 DisplayManager* display_manager = GetDisplayManager();
415 DCHECK(new_primary_display.is_valid()); 415 DCHECK(new_primary_display.is_valid());
416 DCHECK(display_manager->GetDisplayForId(new_primary_display.id()).is_valid()); 416 DCHECK(display_manager->GetDisplayForId(new_primary_display.id()).is_valid());
417 417
418 AshWindowTreeHost* non_primary_host = 418 AshWindowTreeHost* non_primary_host =
419 window_tree_hosts_[new_primary_display.id()]; 419 window_tree_hosts_[new_primary_display.id()];
420 LOG_IF(ERROR, !non_primary_host) 420 LOG_IF(ERROR, !non_primary_host)
421 << "Unknown display is requested in SetPrimaryDisplay: id=" 421 << "Unknown display is requested in SetPrimaryDisplay: id="
422 << new_primary_display.id(); 422 << new_primary_display.id();
423 if (!non_primary_host) 423 if (!non_primary_host)
424 return; 424 return;
425 425
426 gfx::Display old_primary_display = 426 display::Display old_primary_display =
427 gfx::Screen::GetScreen()->GetPrimaryDisplay(); 427 display::Screen::GetScreen()->GetPrimaryDisplay();
428 DCHECK_EQ(old_primary_display.id(), primary_display_id); 428 DCHECK_EQ(old_primary_display.id(), primary_display_id);
429 429
430 // Swap root windows between current and new primary display. 430 // Swap root windows between current and new primary display.
431 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id]; 431 AshWindowTreeHost* primary_host = window_tree_hosts_[primary_display_id];
432 CHECK(primary_host); 432 CHECK(primary_host);
433 CHECK_NE(primary_host, non_primary_host); 433 CHECK_NE(primary_host, non_primary_host);
434 434
435 window_tree_hosts_[new_primary_display.id()] = primary_host; 435 window_tree_hosts_[new_primary_display.id()] = primary_host;
436 GetRootWindowSettings(GetWindow(primary_host))->display_id = 436 GetRootWindowSettings(GetWindow(primary_host))->display_id =
437 new_primary_display.id(); 437 new_primary_display.id();
(...skipping 27 matching lines...) Expand all
465 GetDisplayManager()->set_force_bounds_changed(true); 465 GetDisplayManager()->set_force_bounds_changed(true);
466 GetDisplayManager()->UpdateDisplays(); 466 GetDisplayManager()->UpdateDisplays();
467 GetDisplayManager()->set_force_bounds_changed(false); 467 GetDisplayManager()->set_force_bounds_changed(false);
468 } 468 }
469 469
470 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() { 470 void WindowTreeHostManager::UpdateMouseLocationAfterDisplayChange() {
471 // If the mouse is currently on a display in native location, 471 // If the mouse is currently on a display in native location,
472 // use the same native location. Otherwise find the display closest 472 // use the same native location. Otherwise find the display closest
473 // to the current cursor location in screen coordinates. 473 // to the current cursor location in screen coordinates.
474 474
475 gfx::Point point_in_screen = gfx::Screen::GetScreen()->GetCursorScreenPoint(); 475 gfx::Point point_in_screen =
476 display::Screen::GetScreen()->GetCursorScreenPoint();
476 gfx::Point target_location_in_native; 477 gfx::Point target_location_in_native;
477 int64_t closest_distance_squared = -1; 478 int64_t closest_distance_squared = -1;
478 DisplayManager* display_manager = GetDisplayManager(); 479 DisplayManager* display_manager = GetDisplayManager();
479 480
480 aura::Window* dst_root_window = nullptr; 481 aura::Window* dst_root_window = nullptr;
481 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 482 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
482 const gfx::Display& display = display_manager->GetDisplayAt(i); 483 const display::Display& display = display_manager->GetDisplayAt(i);
483 const DisplayInfo display_info = 484 const DisplayInfo display_info =
484 display_manager->GetDisplayInfo(display.id()); 485 display_manager->GetDisplayInfo(display.id());
485 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); 486 aura::Window* root_window = GetRootWindowForDisplayId(display.id());
486 if (display_info.bounds_in_native().Contains( 487 if (display_info.bounds_in_native().Contains(
487 cursor_location_in_native_coords_for_restore_)) { 488 cursor_location_in_native_coords_for_restore_)) {
488 dst_root_window = root_window; 489 dst_root_window = root_window;
489 target_location_in_native = cursor_location_in_native_coords_for_restore_; 490 target_location_in_native = cursor_location_in_native_coords_for_restore_;
490 break; 491 break;
491 } 492 }
492 gfx::Point center = display.bounds().CenterPoint(); 493 gfx::Point center = display.bounds().CenterPoint();
(...skipping 15 matching lines...) Expand all
508 } 509 }
509 } 510 }
510 511
511 gfx::Point target_location_in_root = target_location_in_native; 512 gfx::Point target_location_in_root = target_location_in_native;
512 dst_root_window->GetHost()->ConvertPointFromNativeScreen( 513 dst_root_window->GetHost()->ConvertPointFromNativeScreen(
513 &target_location_in_root); 514 &target_location_in_root);
514 515
515 #if defined(USE_OZONE) 516 #if defined(USE_OZONE)
516 gfx::Point target_location_in_screen = target_location_in_root; 517 gfx::Point target_location_in_screen = target_location_in_root;
517 ::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen); 518 ::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen);
518 const gfx::Display& target_display = 519 const display::Display& target_display =
519 display_manager->FindDisplayContainingPoint(target_location_in_screen); 520 display_manager->FindDisplayContainingPoint(target_location_in_screen);
520 // If the original location isn't on any of new display, let ozone move 521 // If the original location isn't on any of new display, let ozone move
521 // the cursor. 522 // the cursor.
522 if (!target_display.is_valid()) 523 if (!target_display.is_valid())
523 return; 524 return;
524 int64_t target_display_id = target_display.id(); 525 int64_t target_display_id = target_display.id();
525 526
526 // Do not move the cursor if the cursor's location did not change. This avoids 527 // Do not move the cursor if the cursor's location did not change. This avoids
527 // moving (and showing) the cursor: 528 // moving (and showing) the cursor:
528 // - At startup. 529 // - At startup.
(...skipping 23 matching lines...) Expand all
552 dst_root_window->MoveCursorTo(target_location_in_root); 553 dst_root_window->MoveCursorTo(target_location_in_root);
553 #endif 554 #endif
554 } 555 }
555 556
556 bool WindowTreeHostManager::UpdateWorkAreaOfDisplayNearestWindow( 557 bool WindowTreeHostManager::UpdateWorkAreaOfDisplayNearestWindow(
557 const aura::Window* window, 558 const aura::Window* window,
558 const gfx::Insets& insets) { 559 const gfx::Insets& insets) {
559 const aura::Window* root_window = window->GetRootWindow(); 560 const aura::Window* root_window = window->GetRootWindow();
560 int64_t id = GetRootWindowSettings(root_window)->display_id; 561 int64_t id = GetRootWindowSettings(root_window)->display_id;
561 // if id is |kInvaildDisplayID|, it's being deleted. 562 // if id is |kInvaildDisplayID|, it's being deleted.
562 DCHECK(id != gfx::Display::kInvalidDisplayID); 563 DCHECK(id != display::Display::kInvalidDisplayID);
563 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); 564 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets);
564 } 565 }
565 566
566 void WindowTreeHostManager::OnDisplayAdded(const gfx::Display& display) { 567 void WindowTreeHostManager::OnDisplayAdded(const display::Display& display) {
567 #if defined(OS_CHROMEOS) 568 #if defined(OS_CHROMEOS)
568 // If we're switching from/to offscreen WTH, we need to 569 // If we're switching from/to offscreen WTH, we need to
569 // create new WTH for primary display instead of reusing. 570 // create new WTH for primary display instead of reusing.
570 if (primary_tree_host_for_replace_ && 571 if (primary_tree_host_for_replace_ &&
571 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) 572 (GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_))
572 ->display_id == DisplayManager::kUnifiedDisplayId || 573 ->display_id == DisplayManager::kUnifiedDisplayId ||
573 display.id() == DisplayManager::kUnifiedDisplayId)) { 574 display.id() == DisplayManager::kUnifiedDisplayId)) {
574 DCHECK_EQ(gfx::Display::kInvalidDisplayID, primary_display_id); 575 DCHECK_EQ(display::Display::kInvalidDisplayID, primary_display_id);
575 primary_display_id = display.id(); 576 primary_display_id = display.id();
576 577
577 AshWindowTreeHost* ash_host = 578 AshWindowTreeHost* ash_host =
578 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); 579 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams());
579 RootWindowController::CreateForSecondaryDisplay(ash_host); 580 RootWindowController::CreateForSecondaryDisplay(ash_host);
580 581
581 // Magnifier controllers keep pointers to the current root window. 582 // Magnifier controllers keep pointers to the current root window.
582 // Update them here to avoid accessing them later. 583 // Update them here to avoid accessing them later.
583 Shell::GetInstance()->magnification_controller()->SwitchTargetRootWindow( 584 Shell::GetInstance()->magnification_controller()->SwitchTargetRootWindow(
584 ash_host->AsWindowTreeHost()->window(), false); 585 ash_host->AsWindowTreeHost()->window(), false);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_; 623 window_tree_hosts_[display.id()] = primary_tree_host_for_replace_;
623 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_)) 624 GetRootWindowSettings(GetWindow(primary_tree_host_for_replace_))
624 ->display_id = display.id(); 625 ->display_id = display.id();
625 primary_tree_host_for_replace_ = nullptr; 626 primary_tree_host_for_replace_ = nullptr;
626 const DisplayInfo& display_info = 627 const DisplayInfo& display_info =
627 GetDisplayManager()->GetDisplayInfo(display.id()); 628 GetDisplayManager()->GetDisplayInfo(display.id());
628 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; 629 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()];
629 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); 630 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native());
630 SetDisplayPropertiesOnHost(ash_host, display); 631 SetDisplayPropertiesOnHost(ash_host, display);
631 } else { 632 } else {
632 if (primary_display_id == gfx::Display::kInvalidDisplayID) 633 if (primary_display_id == display::Display::kInvalidDisplayID)
633 primary_display_id = display.id(); 634 primary_display_id = display.id();
634 DCHECK(!window_tree_hosts_.empty()); 635 DCHECK(!window_tree_hosts_.empty());
635 AshWindowTreeHost* ash_host = 636 AshWindowTreeHost* ash_host =
636 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams()); 637 AddWindowTreeHostForDisplay(display, AshWindowTreeHostInitParams());
637 RootWindowController::CreateForSecondaryDisplay(ash_host); 638 RootWindowController::CreateForSecondaryDisplay(ash_host);
638 } 639 }
639 } 640 }
640 641
641 void WindowTreeHostManager::DeleteHost(AshWindowTreeHost* host_to_delete) { 642 void WindowTreeHostManager::DeleteHost(AshWindowTreeHost* host_to_delete) {
642 ClearDisplayPropertiesOnHost(host_to_delete); 643 ClearDisplayPropertiesOnHost(host_to_delete);
643 RootWindowController* controller = 644 RootWindowController* controller =
644 GetRootWindowController(GetWindow(host_to_delete)); 645 GetRootWindowController(GetWindow(host_to_delete));
645 DCHECK(controller); 646 DCHECK(controller);
646 controller->MoveWindowsTo(GetPrimaryRootWindow()); 647 controller->MoveWindowsTo(GetPrimaryRootWindow());
647 // Delete most of root window related objects, but don't delete 648 // Delete most of root window related objects, but don't delete
648 // root window itself yet because the stack may be using it. 649 // root window itself yet because the stack may be using it.
649 controller->Shutdown(); 650 controller->Shutdown();
650 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, controller); 651 base::ThreadTaskRunnerHandle::Get()->DeleteSoon(FROM_HERE, controller);
651 } 652 }
652 653
653 void WindowTreeHostManager::OnDisplayRemoved(const gfx::Display& display) { 654 void WindowTreeHostManager::OnDisplayRemoved(const display::Display& display) {
654 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()]; 655 AshWindowTreeHost* host_to_delete = window_tree_hosts_[display.id()];
655 CHECK(host_to_delete) << display.ToString(); 656 CHECK(host_to_delete) << display.ToString();
656 657
657 // When the primary root window's display is removed, move the primary 658 // When the primary root window's display is removed, move the primary
658 // root to the other display. 659 // root to the other display.
659 if (primary_display_id == display.id()) { 660 if (primary_display_id == display.id()) {
660 // Temporarily store the primary root window in 661 // Temporarily store the primary root window in
661 // |primary_root_window_for_replace_| when replacing the display. 662 // |primary_root_window_for_replace_| when replacing the display.
662 if (window_tree_hosts_.size() == 1) { 663 if (window_tree_hosts_.size() == 1) {
663 primary_display_id = gfx::Display::kInvalidDisplayID; 664 primary_display_id = display::Display::kInvalidDisplayID;
664 primary_tree_host_for_replace_ = host_to_delete; 665 primary_tree_host_for_replace_ = host_to_delete;
665 // Display for root window will be deleted when the Primary RootWindow 666 // Display for root window will be deleted when the Primary RootWindow
666 // is deleted by the Shell. 667 // is deleted by the Shell.
667 window_tree_hosts_.erase(display.id()); 668 window_tree_hosts_.erase(display.id());
668 return; 669 return;
669 } 670 }
670 for (const auto& pair : window_tree_hosts_) { 671 for (const auto& pair : window_tree_hosts_) {
671 if (pair.first != display.id()) { 672 if (pair.first != display.id()) {
672 primary_display_id = pair.first; 673 primary_display_id = pair.first;
673 break; 674 break;
674 } 675 }
675 } 676 }
676 CHECK_NE(gfx::Display::kInvalidDisplayID, primary_display_id); 677 CHECK_NE(display::Display::kInvalidDisplayID, primary_display_id);
677 678
678 AshWindowTreeHost* primary_host = host_to_delete; 679 AshWindowTreeHost* primary_host = host_to_delete;
679 // Delete the other host instead. 680 // Delete the other host instead.
680 host_to_delete = window_tree_hosts_[primary_display_id]; 681 host_to_delete = window_tree_hosts_[primary_display_id];
681 GetRootWindowSettings(GetWindow(host_to_delete))->display_id = display.id(); 682 GetRootWindowSettings(GetWindow(host_to_delete))->display_id = display.id();
682 683
683 // Setup primary root. 684 // Setup primary root.
684 window_tree_hosts_[primary_display_id] = primary_host; 685 window_tree_hosts_[primary_display_id] = primary_host;
685 GetRootWindowSettings(GetWindow(primary_host))->display_id = 686 GetRootWindowSettings(GetWindow(primary_host))->display_id =
686 primary_display_id; 687 primary_display_id;
687 688
688 OnDisplayMetricsChanged( 689 OnDisplayMetricsChanged(
689 GetDisplayManager()->GetDisplayForId(primary_display_id), 690 GetDisplayManager()->GetDisplayForId(primary_display_id),
690 DISPLAY_METRIC_BOUNDS); 691 DISPLAY_METRIC_BOUNDS);
691 } 692 }
692 693
693 DeleteHost(host_to_delete); 694 DeleteHost(host_to_delete);
694 695
695 // The window tree host should be erased at last because some handlers can 696 // The window tree host should be erased at last because some handlers can
696 // access to the host through GetRootWindowForDisplayId() during 697 // access to the host through GetRootWindowForDisplayId() during
697 // MoveWindowsTo(). See http://crbug.com/415222 698 // MoveWindowsTo(). See http://crbug.com/415222
698 window_tree_hosts_.erase(display.id()); 699 window_tree_hosts_.erase(display.id());
699 } 700 }
700 701
701 void WindowTreeHostManager::OnDisplayMetricsChanged(const gfx::Display& display, 702 void WindowTreeHostManager::OnDisplayMetricsChanged(
702 uint32_t metrics) { 703 const display::Display& display,
704 uint32_t metrics) {
703 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION | 705 if (!(metrics & (DISPLAY_METRIC_BOUNDS | DISPLAY_METRIC_ROTATION |
704 DISPLAY_METRIC_DEVICE_SCALE_FACTOR))) 706 DISPLAY_METRIC_DEVICE_SCALE_FACTOR)))
705 return; 707 return;
706 const DisplayInfo& display_info = 708 const DisplayInfo& display_info =
707 GetDisplayManager()->GetDisplayInfo(display.id()); 709 GetDisplayManager()->GetDisplayInfo(display.id());
708 DCHECK(!display_info.bounds_in_native().IsEmpty()); 710 DCHECK(!display_info.bounds_in_native().IsEmpty());
709 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()]; 711 AshWindowTreeHost* ash_host = window_tree_hosts_[display.id()];
710 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native()); 712 ash_host->AsWindowTreeHost()->SetBounds(display_info.bounds_in_native());
711 SetDisplayPropertiesOnHost(ash_host, display); 713 SetDisplayPropertiesOnHost(ash_host, display);
712 } 714 }
713 715
714 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) { 716 void WindowTreeHostManager::OnHostResized(const aura::WindowTreeHost* host) {
715 gfx::Display display = gfx::Screen::GetScreen()->GetDisplayNearestWindow( 717 display::Display display =
716 const_cast<aura::Window*>(host->window())); 718 display::Screen::GetScreen()->GetDisplayNearestWindow(
719 const_cast<aura::Window*>(host->window()));
717 720
718 DisplayManager* display_manager = GetDisplayManager(); 721 DisplayManager* display_manager = GetDisplayManager();
719 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) { 722 if (display_manager->UpdateDisplayBounds(display.id(), host->GetBounds())) {
720 mirror_window_controller_->UpdateWindow(); 723 mirror_window_controller_->UpdateWindow();
721 cursor_window_controller_->UpdateContainer(); 724 cursor_window_controller_->UpdateContainer();
722 } 725 }
723 } 726 }
724 727
725 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay( 728 void WindowTreeHostManager::CreateOrUpdateMirroringDisplay(
726 const DisplayInfoList& info_list) { 729 const DisplayInfoList& info_list) {
(...skipping 12 matching lines...) Expand all
739 // always on the desktop display (the visible cursor on the non-desktop 742 // always on the desktop display (the visible cursor on the non-desktop
740 // display is drawn through compositor mirroring). Therefore, it's unnecessary 743 // display is drawn through compositor mirroring). Therefore, it's unnecessary
741 // to handle the cursor_window at all. See: http://crbug.com/412910 744 // to handle the cursor_window at all. See: http://crbug.com/412910
742 if (!cursor_window_controller_->is_cursor_compositing_enabled()) 745 if (!cursor_window_controller_->is_cursor_compositing_enabled())
743 cursor_window_controller_->UpdateContainer(); 746 cursor_window_controller_->UpdateContainer();
744 } 747 }
745 748
746 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) { 749 void WindowTreeHostManager::PreDisplayConfigurationChange(bool clear_focus) {
747 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); 750 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
748 focus_activation_store_->Store(clear_focus); 751 focus_activation_store_->Store(clear_focus);
749 gfx::Screen* screen = gfx::Screen::GetScreen(); 752 display::Screen* screen = display::Screen::GetScreen();
750 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); 753 gfx::Point point_in_screen = screen->GetCursorScreenPoint();
751 cursor_location_in_screen_coords_for_restore_ = point_in_screen; 754 cursor_location_in_screen_coords_for_restore_ = point_in_screen;
752 755
753 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); 756 display::Display display = screen->GetDisplayNearestPoint(point_in_screen);
754 cursor_display_id_for_restore_ = display.id(); 757 cursor_display_id_for_restore_ = display.id();
755 758
756 gfx::Point point_in_native = point_in_screen; 759 gfx::Point point_in_native = point_in_screen;
757 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); 760 aura::Window* root_window = GetRootWindowForDisplayId(display.id());
758 ::wm::ConvertPointFromScreen(root_window, &point_in_native); 761 ::wm::ConvertPointFromScreen(root_window, &point_in_native);
759 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); 762 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native);
760 cursor_location_in_native_coords_for_restore_ = point_in_native; 763 cursor_location_in_native_coords_for_restore_ = point_in_native;
761 } 764 }
762 765
763 void WindowTreeHostManager::PostDisplayConfigurationChange() { 766 void WindowTreeHostManager::PostDisplayConfigurationChange() {
764 focus_activation_store_->Restore(); 767 focus_activation_store_->Restore();
765 768
766 DisplayManager* display_manager = GetDisplayManager(); 769 DisplayManager* display_manager = GetDisplayManager();
767 DisplayLayoutStore* layout_store = display_manager->layout_store(); 770 DisplayLayoutStore* layout_store = display_manager->layout_store();
768 if (display_manager->num_connected_displays() > 1) { 771 if (display_manager->num_connected_displays() > 1) {
769 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList(); 772 display::DisplayIdList list = display_manager->GetCurrentDisplayIdList();
770 const display::DisplayLayout& layout = 773 const display::DisplayLayout& layout =
771 layout_store->GetRegisteredDisplayLayout(list); 774 layout_store->GetRegisteredDisplayLayout(list);
772 layout_store->UpdateMultiDisplayState( 775 layout_store->UpdateMultiDisplayState(
773 list, display_manager->IsInMirrorMode(), layout.default_unified); 776 list, display_manager->IsInMirrorMode(), layout.default_unified);
774 if (gfx::Screen::GetScreen()->GetNumDisplays() > 1) { 777 if (display::Screen::GetScreen()->GetNumDisplays() > 1) {
775 SetPrimaryDisplayId(layout.primary_id == gfx::Display::kInvalidDisplayID 778 SetPrimaryDisplayId(layout.primary_id ==
779 display::Display::kInvalidDisplayID
776 ? list[0] 780 ? list[0]
777 : layout.primary_id); 781 : layout.primary_id);
778 } 782 }
779 } 783 }
780 784
781 for (const gfx::Display& display : display_manager->active_display_list()) { 785 for (const display::Display& display :
786 display_manager->active_display_list()) {
782 bool output_is_secure = 787 bool output_is_secure =
783 !display_manager->IsInMirrorMode() && display.IsInternal(); 788 !display_manager->IsInMirrorMode() && display.IsInternal();
784 GetAshWindowTreeHostForDisplayId(display.id()) 789 GetAshWindowTreeHostForDisplayId(display.id())
785 ->AsWindowTreeHost() 790 ->AsWindowTreeHost()
786 ->compositor() 791 ->compositor()
787 ->SetOutputIsSecure(output_is_secure); 792 ->SetOutputIsSecure(output_is_secure);
788 } 793 }
789 794
790 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged()); 795 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged());
791 UpdateMouseLocationAfterDisplayChange(); 796 UpdateMouseLocationAfterDisplayChange();
792 } 797 }
793 798
794 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME( 799 ui::EventDispatchDetails WindowTreeHostManager::DispatchKeyEventPostIME(
795 ui::KeyEvent* event) { 800 ui::KeyEvent* event) {
796 // Getting the active root window to dispatch the event. This isn't 801 // Getting the active root window to dispatch the event. This isn't
797 // significant as the event will be sent to the window resolved by 802 // significant as the event will be sent to the window resolved by
798 // aura::client::FocusClient which is FocusController in ash. 803 // aura::client::FocusClient which is FocusController in ash.
799 aura::Window* active_window = wm::GetActiveWindow(); 804 aura::Window* active_window = wm::GetActiveWindow();
800 aura::Window* root_window = active_window ? active_window->GetRootWindow() 805 aura::Window* root_window = active_window ? active_window->GetRootWindow()
801 : Shell::GetPrimaryRootWindow(); 806 : Shell::GetPrimaryRootWindow();
802 return root_window->GetHost()->DispatchKeyEventPostIME(event); 807 return root_window->GetHost()->DispatchKeyEventPostIME(event);
803 } 808 }
804 809
805 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay( 810 AshWindowTreeHost* WindowTreeHostManager::AddWindowTreeHostForDisplay(
806 const gfx::Display& display, 811 const display::Display& display,
807 const AshWindowTreeHostInitParams& init_params) { 812 const AshWindowTreeHostInitParams& init_params) {
808 static int host_count = 0; 813 static int host_count = 0;
809 const DisplayInfo& display_info = 814 const DisplayInfo& display_info =
810 GetDisplayManager()->GetDisplayInfo(display.id()); 815 GetDisplayManager()->GetDisplayInfo(display.id());
811 AshWindowTreeHostInitParams params_with_bounds(init_params); 816 AshWindowTreeHostInitParams params_with_bounds(init_params);
812 params_with_bounds.initial_bounds = display_info.bounds_in_native(); 817 params_with_bounds.initial_bounds = display_info.bounds_in_native();
813 params_with_bounds.offscreen = 818 params_with_bounds.offscreen =
814 display.id() == DisplayManager::kUnifiedDisplayId; 819 display.id() == DisplayManager::kUnifiedDisplayId;
815 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds); 820 AshWindowTreeHost* ash_host = AshWindowTreeHost::Create(params_with_bounds);
816 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost(); 821 aura::WindowTreeHost* host = ash_host->AsWindowTreeHost();
(...skipping 24 matching lines...) Expand all
841 SetDisplayPropertiesOnHost(ash_host, display); 846 SetDisplayPropertiesOnHost(ash_host, display);
842 847
843 #if defined(OS_CHROMEOS) 848 #if defined(OS_CHROMEOS)
844 if (switches::ConstrainPointerToRoot()) 849 if (switches::ConstrainPointerToRoot())
845 ash_host->ConfineCursorToRootWindow(); 850 ash_host->ConfineCursorToRootWindow();
846 #endif 851 #endif
847 return ash_host; 852 return ash_host;
848 } 853 }
849 854
850 } // namespace ash 855 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/window_tree_host_manager.h ('k') | ash/display/window_tree_host_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698