OLD | NEW |
---|---|
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/display_controller.h" | 5 #include "ash/display/display_controller.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <map> | 9 #include <map> |
10 | 10 |
(...skipping 21 matching lines...) Expand all Loading... | |
32 #include "ui/aura/client/screen_position_client.h" | 32 #include "ui/aura/client/screen_position_client.h" |
33 #include "ui/aura/window.h" | 33 #include "ui/aura/window.h" |
34 #include "ui/aura/window_event_dispatcher.h" | 34 #include "ui/aura/window_event_dispatcher.h" |
35 #include "ui/aura/window_property.h" | 35 #include "ui/aura/window_property.h" |
36 #include "ui/aura/window_tracker.h" | 36 #include "ui/aura/window_tracker.h" |
37 #include "ui/aura/window_tree_host.h" | 37 #include "ui/aura/window_tree_host.h" |
38 #include "ui/compositor/compositor.h" | 38 #include "ui/compositor/compositor.h" |
39 #include "ui/compositor/compositor_vsync_manager.h" | 39 #include "ui/compositor/compositor_vsync_manager.h" |
40 #include "ui/gfx/display.h" | 40 #include "ui/gfx/display.h" |
41 #include "ui/gfx/screen.h" | 41 #include "ui/gfx/screen.h" |
42 #include "ui/wm/core/coordinate_conversion.h" | |
42 #include "ui/wm/public/activation_client.h" | 43 #include "ui/wm/public/activation_client.h" |
43 | 44 |
44 #if defined(OS_CHROMEOS) | 45 #if defined(OS_CHROMEOS) |
45 #include "ash/display/display_configurator_animation.h" | 46 #include "ash/display/display_configurator_animation.h" |
46 #include "base/sys_info.h" | 47 #include "base/sys_info.h" |
47 #include "base/time/time.h" | 48 #include "base/time/time.h" |
48 #endif // defined(OS_CHROMEOS) | 49 #endif // defined(OS_CHROMEOS) |
49 | 50 |
50 #if defined(USE_X11) | 51 #if defined(USE_X11) |
51 #include "ui/base/x/x11_util.h" | 52 #include "ui/base/x/x11_util.h" |
(...skipping 477 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
529 std::vector<DisplayInfo> display_info_list; | 530 std::vector<DisplayInfo> display_info_list; |
530 display_info_list.push_back(display_manager->GetDisplayInfo( | 531 display_info_list.push_back(display_manager->GetDisplayInfo( |
531 primary_display_id)); | 532 primary_display_id)); |
532 display_info_list.push_back(display_manager->GetDisplayInfo( | 533 display_info_list.push_back(display_manager->GetDisplayInfo( |
533 ScreenUtil::GetSecondaryDisplay().id())); | 534 ScreenUtil::GetSecondaryDisplay().id())); |
534 GetDisplayManager()->set_force_bounds_changed(true); | 535 GetDisplayManager()->set_force_bounds_changed(true); |
535 GetDisplayManager()->UpdateDisplays(display_info_list); | 536 GetDisplayManager()->UpdateDisplays(display_info_list); |
536 GetDisplayManager()->set_force_bounds_changed(false); | 537 GetDisplayManager()->set_force_bounds_changed(false); |
537 } | 538 } |
538 | 539 |
539 void DisplayController::EnsurePointerInDisplays() { | 540 void DisplayController::EnsurePointerInDisplays() { |
Jun Mukai
2015/02/19 18:07:55
This does not "ensure" pointers in displays anymor
| |
540 // If the mouse is currently on a display in native location, | 541 // If the mouse is currently on a display in native location, |
541 // use the same native location. Otherwise find the display closest | 542 // use the same native location. Otherwise find the display closest |
542 // to the current cursor location in screen coordinates. | 543 // to the current cursor location in screen coordinates. |
543 | 544 |
544 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); | 545 gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint(); |
545 gfx::Point target_location_in_native; | 546 gfx::Point target_location_in_native; |
546 int64 closest_distance_squared = -1; | 547 int64 closest_distance_squared = -1; |
547 DisplayManager* display_manager = GetDisplayManager(); | 548 DisplayManager* display_manager = GetDisplayManager(); |
548 | 549 |
549 aura::Window* dst_root_window = NULL; | 550 aura::Window* dst_root_window = NULL; |
(...skipping 12 matching lines...) Expand all Loading... | |
562 // Use the distance squared from the center of the dislay. This is not | 563 // Use the distance squared from the center of the dislay. This is not |
563 // exactly "closest" display, but good enough to pick one | 564 // exactly "closest" display, but good enough to pick one |
564 // appropriate (and there are at most two displays). | 565 // appropriate (and there are at most two displays). |
565 // We don't care about actual distance, only relative to other displays, so | 566 // We don't care about actual distance, only relative to other displays, so |
566 // using the LengthSquared() is cheaper than Length(). | 567 // using the LengthSquared() is cheaper than Length(). |
567 | 568 |
568 int64 distance_squared = (center - point_in_screen).LengthSquared(); | 569 int64 distance_squared = (center - point_in_screen).LengthSquared(); |
569 if (closest_distance_squared < 0 || | 570 if (closest_distance_squared < 0 || |
570 closest_distance_squared > distance_squared) { | 571 closest_distance_squared > distance_squared) { |
571 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 572 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
572 aura::client::ScreenPositionClient* client = | 573 ::wm::ConvertPointFromScreen(root_window, ¢er); |
573 aura::client::GetScreenPositionClient(root_window); | |
574 client->ConvertPointFromScreen(root_window, ¢er); | |
575 root_window->GetHost()->ConvertPointToNativeScreen(¢er); | 574 root_window->GetHost()->ConvertPointToNativeScreen(¢er); |
576 dst_root_window = root_window; | 575 dst_root_window = root_window; |
577 target_location_in_native = center; | 576 target_location_in_native = center; |
578 closest_distance_squared = distance_squared; | 577 closest_distance_squared = distance_squared; |
579 } | 578 } |
580 } | 579 } |
580 | |
581 gfx::Point target_location_in_root = target_location_in_native; | |
581 dst_root_window->GetHost()->ConvertPointFromNativeScreen( | 582 dst_root_window->GetHost()->ConvertPointFromNativeScreen( |
582 &target_location_in_native); | 583 &target_location_in_root); |
583 dst_root_window->MoveCursorTo(target_location_in_native); | 584 |
585 #if defined(USE_OZONE) | |
Jun Mukai
2015/02/19 01:50:06
This check itself doesn't look ozone specific -- a
pkotwicz
2015/02/19 02:43:43
Ozone moves the mouse for us if the mouse's native
Jun Mukai
2015/02/19 02:57:24
Hm, okay. For display swapping, I guess the X11 ba
| |
586 gfx::Point target_location_in_screen = target_location_in_root; | |
587 ::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen); | |
588 | |
589 // Do not move the cursor if the cursor's location did not change. This avoids | |
590 // moving (and showing) the cursor on startup. | |
591 // |cursor_location_in_native_coords_for_restore_| may refer to a different | |
592 // display than when it was set. This occurs when swapping the primary | |
593 // display. Ozone takes care of moving the cursor in this case. | |
594 if (target_location_in_native != | |
595 cursor_location_in_native_coords_for_restore_ || | |
596 target_location_in_screen != | |
597 cursor_location_in_screen_coords_for_restore_) { | |
598 dst_root_window->MoveCursorTo(target_location_in_root); | |
599 } | |
600 #else | |
601 // X11 does not move the cursor if | |
602 // |cursor_location_in_native_coords_for_restore_| refers to a different | |
603 // display than when it was set. | |
Jun Mukai
2015/02/19 18:07:55
Could you add a comment why we should move the cur
| |
604 dst_root_window->MoveCursorTo(target_location_in_root); | |
605 #endif | |
584 } | 606 } |
585 | 607 |
586 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( | 608 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( |
587 const aura::Window* window, | 609 const aura::Window* window, |
588 const gfx::Insets& insets) { | 610 const gfx::Insets& insets) { |
589 const aura::Window* root_window = window->GetRootWindow(); | 611 const aura::Window* root_window = window->GetRootWindow(); |
590 int64 id = GetRootWindowSettings(root_window)->display_id; | 612 int64 id = GetRootWindowSettings(root_window)->display_id; |
591 // if id is |kInvaildDisplayID|, it's being deleted. | 613 // if id is |kInvaildDisplayID|, it's being deleted. |
592 DCHECK(id != gfx::Display::kInvalidDisplayID); | 614 DCHECK(id != gfx::Display::kInvalidDisplayID); |
593 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); | 615 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
706 // to handle the cursor_window at all. See: http://crbug.com/412910 | 728 // to handle the cursor_window at all. See: http://crbug.com/412910 |
707 if (!cursor_window_controller_->is_cursor_compositing_enabled()) | 729 if (!cursor_window_controller_->is_cursor_compositing_enabled()) |
708 cursor_window_controller_->UpdateContainer(); | 730 cursor_window_controller_->UpdateContainer(); |
709 } | 731 } |
710 | 732 |
711 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { | 733 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { |
712 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); | 734 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); |
713 focus_activation_store_->Store(clear_focus); | 735 focus_activation_store_->Store(clear_focus); |
714 gfx::Screen* screen = Shell::GetScreen(); | 736 gfx::Screen* screen = Shell::GetScreen(); |
715 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); | 737 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); |
738 cursor_location_in_screen_coords_for_restore_ = point_in_screen; | |
739 | |
740 gfx::Point point_in_native = point_in_screen; | |
716 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); | 741 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); |
717 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); | 742 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); |
718 | 743 ::wm::ConvertPointFromScreen(root_window, &point_in_native); |
719 aura::client::ScreenPositionClient* client = | 744 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native); |
720 aura::client::GetScreenPositionClient(root_window); | 745 cursor_location_in_native_coords_for_restore_ = point_in_native; |
721 client->ConvertPointFromScreen(root_window, &point_in_screen); | |
722 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_screen); | |
723 cursor_location_in_native_coords_for_restore_ = point_in_screen; | |
724 } | 746 } |
725 | 747 |
726 void DisplayController::PostDisplayConfigurationChange() { | 748 void DisplayController::PostDisplayConfigurationChange() { |
727 if (limiter_) | 749 if (limiter_) |
728 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); | 750 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); |
729 | 751 |
730 focus_activation_store_->Restore(); | 752 focus_activation_store_->Restore(); |
731 | 753 |
732 DisplayManager* display_manager = GetDisplayManager(); | 754 DisplayManager* display_manager = GetDisplayManager(); |
733 DisplayLayoutStore* layout_store = display_manager->layout_store(); | 755 DisplayLayoutStore* layout_store = display_manager->layout_store(); |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
810 std::string name = | 832 std::string name = |
811 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; | 833 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; |
812 gfx::AcceleratedWidget xwindow = | 834 gfx::AcceleratedWidget xwindow = |
813 root_windows[i]->GetHost()->GetAcceleratedWidget(); | 835 root_windows[i]->GetHost()->GetAcceleratedWidget(); |
814 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); | 836 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); |
815 } | 837 } |
816 #endif | 838 #endif |
817 } | 839 } |
818 | 840 |
819 } // namespace ash | 841 } // namespace ash |
OLD | NEW |