summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 08:03:49 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-07-11 08:03:49 +0000
commitd41e889e115f5fa11be38f0f2415b0521919f8ab (patch)
tree5b90db8bdb5c72b78ebf1e711e0ff150c781bf5d /ash
parent4b2fdb154e90f0c6bb11ac68185491f4503ce3dc (diff)
downloadchromium_src-d41e889e115f5fa11be38f0f2415b0521919f8ab.zip
chromium_src-d41e889e115f5fa11be38f0f2415b0521919f8ab.tar.gz
chromium_src-d41e889e115f5fa11be38f0f2415b0521919f8ab.tar.bz2
1) Simplify mouse cursor restoration
It used to move the mouse to the same location in screen coordinates, but the case this would make sense is extremely rare, especially with close lid mode. Instead, it simply use the same native location if the mouse is still on one of display, or move to the center of closest display if it ever becomes outside of the display. 2) DisplayManager::Init has been renamed InitFromCommandLine and changed to use the same Init process as on device. This should allow us to detect errors on bots, that used to happen only on device. 3) removed unnecessary includes,dead code. TBR=derat@chromium.org, mukai@chromium.org BUG=253991 TEST=updated existing tests to match new behavior. Review URL: https://codereview.chromium.org/18358006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@211047 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash')
-rw-r--r--ash/display/display_controller.cc87
-rw-r--r--ash/display/display_controller.h16
-rw-r--r--ash/display/display_controller_unittest.cc2
-rw-r--r--ash/display/display_info.cc2
-rw-r--r--ash/display/display_manager.cc80
-rw-r--r--ash/display/display_manager.h9
-rw-r--r--ash/display/display_manager_unittest.cc55
-rw-r--r--ash/shell.cc4
8 files changed, 109 insertions, 146 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index 45c1540..6056e07 100644
--- a/ash/display/display_controller.cc
+++ b/ash/display/display_controller.cc
@@ -274,11 +274,6 @@ int DisplayController::GetNumDisplays() {
return GetDisplayManager()->GetNumDisplays();
}
-// static
-bool DisplayController::HasPrimaryDisplay() {
- return primary_display_id != gfx::Display::kInvalidDisplayID;
-}
-
void DisplayController::InitPrimaryDisplay() {
const gfx::Display* primary_candidate =
GetDisplayManager()->GetPrimaryDisplayCandidate();
@@ -556,21 +551,25 @@ gfx::Display* DisplayController::GetSecondaryDisplay() {
}
void DisplayController::EnsurePointerInDisplays() {
- // Don't try to move the pointer during the boot/startup.
- if (!HasPrimaryDisplay())
- return;
- gfx::Point location_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
- gfx::Point target_location;
+ // If the mouse is currently on a display in native location,
+ // use the same native location. Otherwise find the display closest
+ // to the current cursor location in screen coordinates.
+
+ gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
+ gfx::Point target_location_in_native;
int64 closest_distance_squared = -1;
internal::DisplayManager* display_manager = GetDisplayManager();
aura::RootWindow* dst_root_window = NULL;
for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
const gfx::Display* display = display_manager->GetDisplayAt(i);
+ const internal::DisplayInfo display_info =
+ display_manager->GetDisplayInfo(display->id());
aura::RootWindow* root_window = GetRootWindowForDisplayId(display->id());
- if (display->bounds().Contains(location_in_screen)) {
+ if (display_info.bounds_in_pixel().Contains(
+ cursor_location_in_native_coords_for_restore_)) {
dst_root_window = root_window;
- target_location = location_in_screen;
+ target_location_in_native = cursor_location_in_native_coords_for_restore_;
break;
}
gfx::Point center = display->bounds().CenterPoint();
@@ -580,55 +579,21 @@ void DisplayController::EnsurePointerInDisplays() {
// We don't care about actual distance, only relative to other displays, so
// using the LengthSquared() is cheaper than Length().
- int64 distance_squared = (center - location_in_screen).LengthSquared();
+ int64 distance_squared = (center - point_in_screen).LengthSquared();
if (closest_distance_squared < 0 ||
closest_distance_squared > distance_squared) {
+ aura::RootWindow* root_window = GetRootWindowForDisplayId(display->id());
+ aura::client::ScreenPositionClient* client =
+ aura::client::GetScreenPositionClient(root_window);
+ client->ConvertPointFromScreen(root_window, &center);
+ root_window->ConvertPointToNativeScreen(&center);
dst_root_window = root_window;
- target_location = center;
+ target_location_in_native = center;
closest_distance_squared = distance_squared;
}
}
- DCHECK(dst_root_window);
- aura::client::ScreenPositionClient* client =
- aura::client::GetScreenPositionClient(dst_root_window);
- client->ConvertPointFromScreen(dst_root_window, &target_location);
- dst_root_window->MoveCursorTo(target_location);
-}
-
-gfx::Point DisplayController::GetNativeMouseCursorLocation() const {
- if (in_bootstrap())
- return gfx::Point();
-
- gfx::Point location = Shell::GetScreen()->GetCursorScreenPoint();
- const gfx::Display& display =
- Shell::GetScreen()->GetDisplayNearestPoint(location);
- const aura::RootWindow* root_window =
- root_windows_.find(display.id())->second;
- aura::client::ScreenPositionClient* client =
- aura::client::GetScreenPositionClient(root_window);
- client->ConvertPointFromScreen(root_window, &location);
- root_window->ConvertPointToNativeScreen(&location);
- return location;
-}
-
-void DisplayController::UpdateMouseCursor(const gfx::Point& point_in_native) {
- if (in_bootstrap())
- return;
-
- std::vector<aura::RootWindow*> root_windows = GetAllRootWindows();
- for (std::vector<aura::RootWindow*>::iterator iter = root_windows.begin();
- iter != root_windows.end();
- ++iter) {
- aura::RootWindow* root_window = *iter;
- gfx::Rect bounds_in_native(root_window->GetHostOrigin(),
- root_window->GetHostSize());
- if (bounds_in_native.Contains(point_in_native)) {
- gfx::Point point(point_in_native);
- root_window->ConvertPointFromNativeScreen(&point);
- root_window->MoveCursorTo(point);
- break;
- }
- }
+ dst_root_window->ConvertPointFromNativeScreen(&target_location_in_native);
+ dst_root_window->MoveCursorTo(target_location_in_native);
}
void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
@@ -753,6 +718,17 @@ void DisplayController::NotifyDisplayConfigurationChanging() {
return;
FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
focus_activation_store_->Store();
+
+ gfx::Point point_in_screen = Shell::GetScreen()->GetCursorScreenPoint();
+ gfx::Display display =
+ Shell::GetScreen()->GetDisplayNearestPoint(point_in_screen);
+ aura::RootWindow* root_window = GetRootWindowForDisplayId(display.id());
+
+ aura::client::ScreenPositionClient* client =
+ aura::client::GetScreenPositionClient(root_window);
+ client->ConvertPointFromScreen(root_window, &point_in_screen);
+ root_window->ConvertPointToNativeScreen(&point_in_screen);
+ cursor_location_in_native_coords_for_restore_ = point_in_screen;
}
void DisplayController::NotifyDisplayConfigurationChanged() {
@@ -785,6 +761,7 @@ void DisplayController::NotifyDisplayConfigurationChanged() {
}
FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged());
UpdateHostWindowNames();
+ EnsurePointerInDisplays();
}
void DisplayController::OnFadeOutForSwapDisplayFinished() {
diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h
index a5bf8d0..a0b1477 100644
--- a/ash/display/display_controller.h
+++ b/ash/display/display_controller.h
@@ -17,6 +17,7 @@
#include "base/observer_list.h"
#include "base/time/time.h"
#include "ui/gfx/display_observer.h"
+#include "ui/gfx/point.h"
namespace aura {
class Display;
@@ -31,7 +32,6 @@ template <typename T> class JSONValueConverter;
namespace gfx {
class Display;
class Insets;
-class Point;
}
namespace ash {
@@ -75,9 +75,6 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
// ash::Shell is deleted.
static int GetNumDisplays();
- // True if the primary display has been initialized.
- static bool HasPrimaryDisplay();
-
// Initializes primary display.
void InitPrimaryDisplay();
@@ -141,12 +138,6 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
// the center of the nearest display if it's outside of all displays.
void EnsurePointerInDisplays();
- gfx::Point GetNativeMouseCursorLocation() const;
-
- // Update the current cursor image that is sutable for the given
- // |point_in_native|.
- void UpdateMouseCursor(const gfx::Point& point_in_native);
-
// aura::DisplayObserver overrides:
virtual void OnDisplayBoundsChanged(
const gfx::Display& display) OVERRIDE;
@@ -208,6 +199,11 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
scoped_ptr<internal::FocusActivationStore> focus_activation_store_;
+ // Stores the curent cursor location (in native coordinates) used to
+ // restore the cursor location when display configuration
+ // changed.
+ gfx::Point cursor_location_in_native_coords_for_restore_;
+
DISALLOW_COPY_AND_ASSIGN(DisplayController);
};
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
index 74be2b0..697779c 100644
--- a/ash/display/display_controller_unittest.cc
+++ b/ash/display/display_controller_unittest.cc
@@ -368,7 +368,7 @@ TEST_F(DisplayControllerTest, MirroredLayout) {
EXPECT_EQ(
2U, Shell::GetInstance()->display_manager()->num_connected_displays());
- UpdateDisplay("500x500,1+0-500x500");
+ UpdateDisplay("1+0-500x500,1+0-500x500");
EXPECT_TRUE(display_controller->GetCurrentDisplayLayout().mirrored);
EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
EXPECT_EQ(
diff --git a/ash/display/display_info.cc b/ash/display/display_info.cc
index a177000..d886a59 100644
--- a/ash/display/display_info.cc
+++ b/ash/display/display_info.cc
@@ -203,7 +203,7 @@ gfx::Insets DisplayInfo::GetOverscanInsetsInPixel() const {
std::string DisplayInfo::ToString() const {
int rotation_degree = static_cast<int>(rotation_) * 90;
return base::StringPrintf(
- "DisplayInfo[%lld] bounds=%s, size=%s, scale=%f, "
+ "DisplayInfo[%lld] native bounds=%s, size=%s, scale=%f, "
"overscan=%s, rotation=%d, ui-scale=%f",
static_cast<long long int>(id_),
bounds_in_pixel_.ToString().c_str(),
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index 5a491c4..d773147 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -18,16 +18,13 @@
#include "base/auto_reset.h"
#include "base/command_line.h"
#include "base/logging.h"
-#include "base/stl_util.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_split.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "grit/ash_strings.h"
#include "ui/aura/client/screen_position_client.h"
-#include "ui/aura/env.h"
#include "ui/aura/root_window.h"
-#include "ui/aura/root_window_host.h"
#include "ui/aura/window_property.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/display.h"
@@ -47,7 +44,6 @@
#if defined(OS_WIN)
#include "base/win/windows_version.h"
-#include "ui/aura/remote_root_window_host_win.h"
#endif
DECLARE_WINDOW_PROPERTY_TYPE(int64);
@@ -147,7 +143,6 @@ DisplayManager::DisplayManager()
#if defined(OS_CHROMEOS)
change_display_upon_host_resize_ = !base::chromeos::IsRunningOnChromeOS();
#endif
- Init();
}
DisplayManager::~DisplayManager() {
@@ -198,6 +193,27 @@ float DisplayManager::GetNextUIScale(const DisplayInfo& info, bool up) {
return 1.0f;
}
+void DisplayManager::InitFromCommandLine() {
+ DisplayInfoList info_list;
+
+ const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
+ switches::kAshHostWindowBounds);
+ vector<string> parts;
+ base::SplitString(size_str, ',', &parts);
+ for (vector<string>::const_iterator iter = parts.begin();
+ iter != parts.end(); ++iter) {
+ info_list.push_back(DisplayInfo::CreateFromSpec(*iter));
+ }
+ if (info_list.empty()) {
+ info_list.push_back(
+ DisplayInfo::CreateFromSpec(std::string() /* default */));
+ }
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal))
+ gfx::Display::SetInternalDisplayId(info_list[0].id());
+ OnNativeDisplaysChanged(info_list);
+}
+
void DisplayManager::UpdateDisplayBoundsForLayout(
const DisplayLayout& layout,
const gfx::Display& primary_display,
@@ -205,8 +221,6 @@ void DisplayManager::UpdateDisplayBoundsForLayout(
DCHECK_EQ("0,0", primary_display.bounds().origin().ToString());
const gfx::Rect& primary_bounds = primary_display.bounds();
- DisplayController::GetPrimaryDisplay().bounds();
-
const gfx::Rect& secondary_bounds = secondary_display->bounds();
gfx::Point new_secondary_origin = primary_bounds.origin();
@@ -402,7 +416,8 @@ void DisplayManager::OnNativeDisplaysChanged(
return;
}
first_display_id_ = updated_displays[0].id();
- std::set<int> y_coords;
+ std::set<gfx::Point> origins;
+
if (updated_displays.size() == 1) {
VLOG(1) << "OnNativeDisplaysChanged(1):" << updated_displays[0].ToString();
} else {
@@ -420,13 +435,13 @@ void DisplayManager::OnNativeDisplaysChanged(
++iter) {
if (!internal_display_connected)
internal_display_connected = IsInternalDisplayId(iter->id());
- // Mirrored monitors have the same y coordinates.
- int y = iter->bounds_in_pixel().y();
- if (y_coords.find(y) != y_coords.end()) {
+ // Mirrored monitors have the same origins.
+ gfx::Point origin = iter->bounds_in_pixel().origin();
+ if (origins.find(origin) != origins.end()) {
InsertAndUpdateDisplayInfo(*iter);
mirrored_display_ = CreateDisplayFromDisplayInfoById(iter->id());
} else {
- y_coords.insert(y);
+ origins.insert(origin);
new_display_info_list.push_back(*iter);
}
}
@@ -477,7 +492,6 @@ void DisplayManager::UpdateDisplays(
DisplayInfoList::const_iterator new_info_iter = new_display_info_list.begin();
DisplayList new_displays;
- bool update_mouse_location = false;
scoped_ptr<MirrorWindowCreator> mirror_window_creater;
@@ -507,7 +521,6 @@ void DisplayManager::UpdateDisplays(
removed_displays.push_back(*curr_iter);
++curr_iter;
}
- update_mouse_location = true;
continue;
}
@@ -522,7 +535,6 @@ void DisplayManager::UpdateDisplays(
// more displays in current list.
removed_displays.push_back(*curr_iter);
++curr_iter;
- update_mouse_location = true;
} else if (curr_iter->id() == new_info_iter->id()) {
const gfx::Display& current_display = *curr_iter;
// Copy the info because |CreateDisplayFromInfo| updates the instance.
@@ -545,11 +557,6 @@ void DisplayManager::UpdateDisplays(
new_display.GetSizeInPixel()) ||
(current_display.rotation() != new_display.rotation())) {
- // Don't update mouse location if the display size has
- // changed due to rotation or zooming.
- if (host_window_bounds_changed)
- update_mouse_location = true;
-
changed_display_indices.push_back(new_displays.size());
}
@@ -561,7 +568,6 @@ void DisplayManager::UpdateDisplays(
// more displays in current list between ids, which means it is deleted.
removed_displays.push_back(*curr_iter);
++curr_iter;
- update_mouse_location = true;
} else {
// more displays in new list between ids, which means it is added.
added_display_indices.push_back(new_displays.size());
@@ -587,9 +593,7 @@ void DisplayManager::UpdateDisplays(
DisplayController* display_controller =
Shell::GetInstance()->display_controller();
- gfx::Point mouse_location_in_native;
display_controller->NotifyDisplayConfigurationChanging();
- mouse_location_in_native = display_controller->GetNativeMouseCursorLocation();
size_t updated_index;
if (UpdateSecondaryDisplayBoundsForLayout(&new_displays, &updated_index) &&
@@ -632,10 +636,6 @@ void DisplayManager::UpdateDisplays(
Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]);
}
display_controller->NotifyDisplayConfigurationChanged();
- if (update_mouse_location)
- display_controller->EnsurePointerInDisplays();
- else
- display_controller->UpdateMouseCursor(mouse_location_in_native);
#if defined(USE_X11) && defined(OS_CHROMEOS)
if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS())
@@ -829,25 +829,6 @@ void DisplayManager::SetSoftwareMirroring(bool enabled) {
mirrored_display_ = gfx::Display();
}
-void DisplayManager::Init() {
- // TODO(oshima): Move this logic to DisplayChangeObserver.
- const string size_str = CommandLine::ForCurrentProcess()->GetSwitchValueASCII(
- switches::kAshHostWindowBounds);
- vector<string> parts;
- base::SplitString(size_str, ',', &parts);
- for (vector<string>::const_iterator iter = parts.begin();
- iter != parts.end(); ++iter) {
- AddDisplayFromSpec(*iter);
- }
- if (displays_.empty())
- AddDisplayFromSpec(std::string() /* default */);
- first_display_id_ = displays_[0].id();
- CommandLine* command_line = CommandLine::ForCurrentProcess();
- if (command_line->HasSwitch(switches::kAshUseFirstDisplayAsInternal))
- gfx::Display::SetInternalDisplayId(first_display_id_);
- num_connected_displays_ = displays_.size();
-}
-
gfx::Display& DisplayManager::FindDisplayForRootWindow(
const aura::RootWindow* root_window) {
int64 id = root_window->GetProperty(kDisplayIdKey);
@@ -880,13 +861,6 @@ void DisplayManager::AddMirrorDisplayInfoIfAny(
display_info_list->push_back(GetDisplayInfo(mirrored_display_.id()));
}
-void DisplayManager::AddDisplayFromSpec(const std::string& spec) {
- DisplayInfo display_info = DisplayInfo::CreateFromSpec(spec);
- InsertAndUpdateDisplayInfo(display_info);
- gfx::Display display = CreateDisplayFromDisplayInfoById(display_info.id());
- displays_.push_back(display);
-}
-
void DisplayManager::InsertAndUpdateDisplayInfo(const DisplayInfo& new_info) {
std::map<int64, DisplayInfo>::iterator info =
display_info_.find(new_info.id());
diff --git a/ash/display/display_manager.h b/ash/display/display_manager.h
index 8a1b3f7..2d99e04 100644
--- a/ash/display/display_manager.h
+++ b/ash/display/display_manager.h
@@ -76,6 +76,10 @@ class ASH_EXPORT DisplayManager :
// Returns the display id of the first display in the outupt list.
int64 first_display_id() const { return first_display_id_; }
+ // Initializes displays using command line flag, or uses
+ // defualt if no options are specified.
+ void InitFromCommandLine();
+
// True if the given |display| is currently connected.
bool IsActiveDisplay(const gfx::Display& display) const;
@@ -213,8 +217,6 @@ private:
change_display_upon_host_resize_ = value;
}
- void Init();
-
gfx::Display& FindDisplayForRootWindow(const aura::RootWindow* root);
gfx::Display& FindDisplayForId(int64 id);
@@ -222,9 +224,6 @@ private:
// mirroring is in use.
void AddMirrorDisplayInfoIfAny(std::vector<DisplayInfo>* display_info_list);
- // Refer to |CreateDisplayFromSpec| API for the format of |spec|.
- void AddDisplayFromSpec(const std::string& spec);
-
// Inserts and update the DisplayInfo according to the overscan
// state. Note that The DisplayInfo stored in the |internal_display_info_|
// can be different from |new_info| (due to overscan state), so
diff --git a/ash/display/display_manager_unittest.cc b/ash/display/display_manager_unittest.cc
index 935258c..de22618 100644
--- a/ash/display/display_manager_unittest.cc
+++ b/ash/display/display_manager_unittest.cc
@@ -600,10 +600,16 @@ TEST_F(DisplayManagerTest, MAYBE_TestNativeDisplaysChangedNoInternal) {
ash::Shell::GetPrimaryRootWindow()->GetHostSize().ToString());
}
-TEST_F(DisplayManagerTest, EnsurePointerInDisplays) {
- if (!SupportsMultipleDisplays())
- return;
+#if defined(OS_WIN)
+// Tests that rely on the actual host size/location does not work on windows.
+#define MAYBE_EnsurePointerInDisplays DISABLED_EnsurePointerInDisplays
+#define MAYBE_EnsurePointerInDisplays_2ndOnLeft DISABLED_EnsurePointerInDisplays_2ndOnLeft
+#else
+#define MAYBE_EnsurePointerInDisplays EnsurePointerInDisplays
+#define MAYBE_EnsurePointerInDisplays_2ndOnLeft EnsurePointerInDisplays_2ndOnLeft
+#endif
+TEST_F(DisplayManagerTest, MAYBE_EnsurePointerInDisplays) {
UpdateDisplay("200x200,300x300");
Shell::RootWindowList root_windows = Shell::GetAllRootWindows();
@@ -615,19 +621,19 @@ TEST_F(DisplayManagerTest, EnsurePointerInDisplays) {
generator.MoveMouseToInHost(350, 150);
EXPECT_EQ("350,150", env->last_mouse_location().ToString());
- // A mouse pointer will be inside 2nd display.
+ // A mouse pointer will stay in the 2nd display.
UpdateDisplay("300x300,200x200");
- EXPECT_EQ("350,150", env->last_mouse_location().ToString());
+ EXPECT_EQ("450,50", env->last_mouse_location().ToString());
// A mouse pointer will be outside of displays and move to the
// center of 2nd display.
UpdateDisplay("300x300,100x100");
EXPECT_EQ("350,50", env->last_mouse_location().ToString());
- // 2nd display was disconnected, but the mouse pointer says in the
- // 1st display.
+ // 2nd display was disconnected, and the cursor is
+ // now in the 1st display.
UpdateDisplay("400x400");
- EXPECT_EQ("350,50", env->last_mouse_location().ToString());
+ EXPECT_EQ("50,350", env->last_mouse_location().ToString());
// 1st display's resolution has changed, and the mouse pointer is
// now outside. Move the mouse pointer to the center of 1st display.
@@ -638,15 +644,12 @@ TEST_F(DisplayManagerTest, EnsurePointerInDisplays) {
generator.MoveMouseToInHost(150, 290);
EXPECT_EQ("150,290", env->last_mouse_location().ToString());
- // The mouse pointer is outside and closest display is 1st one.
+ // The mouse pointer is now on 2nd display.
UpdateDisplay("300x280,200x200");
- EXPECT_EQ("150,140", env->last_mouse_location().ToString());
+ EXPECT_EQ("450,10", env->last_mouse_location().ToString());
}
-TEST_F(DisplayManagerTest, EnsurePointerInDisplays_2ndOnLeft) {
- if (!SupportsMultipleDisplays())
- return;
-
+TEST_F(DisplayManagerTest, MAYBE_EnsurePointerInDisplays_2ndOnLeft) {
// Set the 2nd display on the left.
DisplayLayoutStore* layout_store =
Shell::GetInstance()->display_manager()->layout_store();
@@ -663,12 +666,12 @@ TEST_F(DisplayManagerTest, EnsurePointerInDisplays_2ndOnLeft) {
aura::Env* env = aura::Env::GetInstance();
// Set the initial position.
- root_windows[0]->MoveCursorTo(gfx::Point(-150, 150));
- EXPECT_EQ("-150,150", env->last_mouse_location().ToString());
+ root_windows[0]->MoveCursorTo(gfx::Point(-150, 250));
+ EXPECT_EQ("-150,250", env->last_mouse_location().ToString());
- // A mouse pointer will be in 2nd display.
- UpdateDisplay("300x300,200x200");
- EXPECT_EQ("-150,150", env->last_mouse_location().ToString());
+ // A mouse pointer will stay in 2nd display.
+ UpdateDisplay("300x300,200x300");
+ EXPECT_EQ("-50,150", env->last_mouse_location().ToString());
// A mouse pointer will be outside of displays and move to the
// center of 2nd display.
@@ -866,6 +869,11 @@ TEST_F(DisplayManagerTest, MAYBE_UpdateMouseCursorAfterRotateZoom) {
UpdateDisplay("300x200/r,200x150/l");
EXPECT_EQ("249,50", env->last_mouse_location().ToString());
+ // The native location is now outside, so move to the center
+ // of closest display.
+ UpdateDisplay("300x200/r,100x50/l");
+ EXPECT_EQ("225,50", env->last_mouse_location().ToString());
+
// Make sure just zooming will not change native location.
UpdateDisplay("600x400*2,400x300");
@@ -877,9 +885,14 @@ TEST_F(DisplayManagerTest, MAYBE_UpdateMouseCursorAfterRotateZoom) {
// Test on 2nd display.
UpdateDisplay("600x400,400x300*2");
- generator2.MoveMouseToInHost(200, 100);
- EXPECT_EQ("700,50", env->last_mouse_location().ToString());
+ generator2.MoveMouseToInHost(200, 250);
+ EXPECT_EQ("700,125", env->last_mouse_location().ToString());
UpdateDisplay("600x400,400x300*2@1.5");
+ EXPECT_EQ("750,187", env->last_mouse_location().ToString());
+
+ // The native location is now outside, so move to the
+ // center of closest display.
+ UpdateDisplay("600x400,400x200*2@1.5");
EXPECT_EQ("750,75", env->last_mouse_location().ToString());
}
diff --git a/ash/shell.cc b/ash/shell.cc
index a53fc5c..97450b8 100644
--- a/ash/shell.cc
+++ b/ash/shell.cc
@@ -438,6 +438,7 @@ void Shell::Init() {
CommandLine* command_line = CommandLine::ForCurrentProcess();
delegate_->PreInit();
+ bool display_initialized = false;
#if defined(OS_CHROMEOS) && defined(USE_X11)
output_configurator_animation_.reset(
new internal::OutputConfiguratorAnimation());
@@ -454,8 +455,11 @@ void Shell::Init() {
output_configurator_->set_mirroring_controller(display_manager_.get());
output_configurator_->Start();
display_change_observer_->OnDisplayModeChanged();
+ display_initialized = true;
}
#endif
+ if (!display_initialized)
+ display_manager_->InitFromCommandLine();
// Install the custom factory first so that views::FocusManagers for Tray,
// Launcher, and WallPaper could be created by the factory.