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

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

Issue 902123002: Fix initial hiding and centering cursor on Ozone (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 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
« no previous file with comments | « ash/display/display_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/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
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 207 matching lines...) Expand 10 before | Expand all | Expand 10 after
259 } 260 }
260 261
261 //////////////////////////////////////////////////////////////////////////////// 262 ////////////////////////////////////////////////////////////////////////////////
262 // DisplayController 263 // DisplayController
263 264
264 DisplayController::DisplayController() 265 DisplayController::DisplayController()
265 : primary_tree_host_for_replace_(NULL), 266 : primary_tree_host_for_replace_(NULL),
266 focus_activation_store_(new FocusActivationStore()), 267 focus_activation_store_(new FocusActivationStore()),
267 cursor_window_controller_(new CursorWindowController()), 268 cursor_window_controller_(new CursorWindowController()),
268 mirror_window_controller_(new MirrorWindowController()), 269 mirror_window_controller_(new MirrorWindowController()),
270 cursor_display_id_for_restore_(gfx::Display::kInvalidDisplayID),
269 weak_ptr_factory_(this) { 271 weak_ptr_factory_(this) {
270 #if defined(OS_CHROMEOS) 272 #if defined(OS_CHROMEOS)
271 if (base::SysInfo::IsRunningOnChromeOS()) 273 if (base::SysInfo::IsRunningOnChromeOS())
272 limiter_.reset(new DisplayChangeLimiter); 274 limiter_.reset(new DisplayChangeLimiter);
273 #endif 275 #endif
274 // Reset primary display to make sure that tests don't use 276 // Reset primary display to make sure that tests don't use
275 // stale display info from previous tests. 277 // stale display info from previous tests.
276 primary_display_id = gfx::Display::kInvalidDisplayID; 278 primary_display_id = gfx::Display::kInvalidDisplayID;
277 } 279 }
278 280
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
562 // Use the distance squared from the center of the dislay. This is not 564 // Use the distance squared from the center of the dislay. This is not
563 // exactly "closest" display, but good enough to pick one 565 // exactly "closest" display, but good enough to pick one
564 // appropriate (and there are at most two displays). 566 // appropriate (and there are at most two displays).
565 // We don't care about actual distance, only relative to other displays, so 567 // We don't care about actual distance, only relative to other displays, so
566 // using the LengthSquared() is cheaper than Length(). 568 // using the LengthSquared() is cheaper than Length().
567 569
568 int64 distance_squared = (center - point_in_screen).LengthSquared(); 570 int64 distance_squared = (center - point_in_screen).LengthSquared();
569 if (closest_distance_squared < 0 || 571 if (closest_distance_squared < 0 ||
570 closest_distance_squared > distance_squared) { 572 closest_distance_squared > distance_squared) {
571 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); 573 aura::Window* root_window = GetRootWindowForDisplayId(display.id());
572 aura::client::ScreenPositionClient* client = 574 ::wm::ConvertPointFromScreen(root_window, &center);
573 aura::client::GetScreenPositionClient(root_window);
574 client->ConvertPointFromScreen(root_window, &center);
575 root_window->GetHost()->ConvertPointToNativeScreen(&center); 575 root_window->GetHost()->ConvertPointToNativeScreen(&center);
576 dst_root_window = root_window; 576 dst_root_window = root_window;
577 target_location_in_native = center; 577 target_location_in_native = center;
578 closest_distance_squared = distance_squared; 578 closest_distance_squared = distance_squared;
579 } 579 }
580 } 580 }
581
582 gfx::Point target_location_in_root = target_location_in_native;
581 dst_root_window->GetHost()->ConvertPointFromNativeScreen( 583 dst_root_window->GetHost()->ConvertPointFromNativeScreen(
582 &target_location_in_native); 584 &target_location_in_root);
583 dst_root_window->MoveCursorTo(target_location_in_native); 585
586 #if defined(USE_OZONE)
587 gfx::Point target_location_in_screen = target_location_in_root;
588 ::wm::ConvertPointToScreen(dst_root_window, &target_location_in_screen);
589 int64 target_display_id =
590 display_manager->FindDisplayContainingPoint(target_location_in_screen)
591 .id();
592
593 // Do not move the cursor if the cursor's location did not change. This avoids
594 // moving (and showing) the cursor on startup.
595 // - |cursor_location_in_screen_coords_for_restore_| is checked to ensure that
596 // the cursor is moved when the cursor's native position does not change but
597 // the scale factor or rotation of the display it is on have changed.
598 // - |cursor_display_id_for_restore_| is checked to ensure that the cursor is
599 // moved when the cursor's native position and screen position do not change
600 // but the display that it is on has changed. This occurs when swapping the
601 // primary display.
602 if (target_location_in_native !=
603 cursor_location_in_native_coords_for_restore_ ||
604 target_location_in_screen !=
605 cursor_location_in_screen_coords_for_restore_ ||
606 target_display_id != cursor_display_id_for_restore_) {
607 dst_root_window->MoveCursorTo(target_location_in_root);
608 }
609 #else
610 dst_root_window->MoveCursorTo(target_location_in_root);
611 #endif
584 } 612 }
585 613
586 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow( 614 bool DisplayController::UpdateWorkAreaOfDisplayNearestWindow(
587 const aura::Window* window, 615 const aura::Window* window,
588 const gfx::Insets& insets) { 616 const gfx::Insets& insets) {
589 const aura::Window* root_window = window->GetRootWindow(); 617 const aura::Window* root_window = window->GetRootWindow();
590 int64 id = GetRootWindowSettings(root_window)->display_id; 618 int64 id = GetRootWindowSettings(root_window)->display_id;
591 // if id is |kInvaildDisplayID|, it's being deleted. 619 // if id is |kInvaildDisplayID|, it's being deleted.
592 DCHECK(id != gfx::Display::kInvalidDisplayID); 620 DCHECK(id != gfx::Display::kInvalidDisplayID);
593 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets); 621 return GetDisplayManager()->UpdateWorkAreaOfDisplay(id, insets);
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 // to handle the cursor_window at all. See: http://crbug.com/412910 734 // to handle the cursor_window at all. See: http://crbug.com/412910
707 if (!cursor_window_controller_->is_cursor_compositing_enabled()) 735 if (!cursor_window_controller_->is_cursor_compositing_enabled())
708 cursor_window_controller_->UpdateContainer(); 736 cursor_window_controller_->UpdateContainer();
709 } 737 }
710 738
711 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) { 739 void DisplayController::PreDisplayConfigurationChange(bool clear_focus) {
712 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging()); 740 FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
713 focus_activation_store_->Store(clear_focus); 741 focus_activation_store_->Store(clear_focus);
714 gfx::Screen* screen = Shell::GetScreen(); 742 gfx::Screen* screen = Shell::GetScreen();
715 gfx::Point point_in_screen = screen->GetCursorScreenPoint(); 743 gfx::Point point_in_screen = screen->GetCursorScreenPoint();
744 cursor_location_in_screen_coords_for_restore_ = point_in_screen;
745
716 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen); 746 gfx::Display display = screen->GetDisplayNearestPoint(point_in_screen);
747 cursor_display_id_for_restore_ = display.id();
748
749 gfx::Point point_in_native = point_in_screen;
717 aura::Window* root_window = GetRootWindowForDisplayId(display.id()); 750 aura::Window* root_window = GetRootWindowForDisplayId(display.id());
718 751 ::wm::ConvertPointFromScreen(root_window, &point_in_native);
719 aura::client::ScreenPositionClient* client = 752 root_window->GetHost()->ConvertPointToNativeScreen(&point_in_native);
720 aura::client::GetScreenPositionClient(root_window); 753 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 } 754 }
725 755
726 void DisplayController::PostDisplayConfigurationChange() { 756 void DisplayController::PostDisplayConfigurationChange() {
727 if (limiter_) 757 if (limiter_)
728 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs); 758 limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs);
729 759
730 focus_activation_store_->Restore(); 760 focus_activation_store_->Restore();
731 761
732 DisplayManager* display_manager = GetDisplayManager(); 762 DisplayManager* display_manager = GetDisplayManager();
733 DisplayLayoutStore* layout_store = display_manager->layout_store(); 763 DisplayLayoutStore* layout_store = display_manager->layout_store();
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 std::string name = 840 std::string name =
811 root_windows[i] == primary ? "aura_root_0" : "aura_root_x"; 841 root_windows[i] == primary ? "aura_root_0" : "aura_root_x";
812 gfx::AcceleratedWidget xwindow = 842 gfx::AcceleratedWidget xwindow =
813 root_windows[i]->GetHost()->GetAcceleratedWidget(); 843 root_windows[i]->GetHost()->GetAcceleratedWidget();
814 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str()); 844 XStoreName(gfx::GetXDisplay(), xwindow, name.c_str());
815 } 845 }
816 #endif 846 #endif
817 } 847 }
818 848
819 } // namespace ash 849 } // namespace ash
OLDNEW
« no previous file with comments | « ash/display/display_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698