summaryrefslogtreecommitdiffstats
path: root/ash/monitor
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 22:29:24 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-03-24 22:29:24 +0000
commit899b93b7fcbb911e8205818aef1eeb64fd62cbce (patch)
treec5bba732d62288a1938f2c07934045fb184dff25 /ash/monitor
parentea6fec35535b5f4d5b5476cea382f9d4968c7e68 (diff)
downloadchromium_src-899b93b7fcbb911e8205818aef1eeb64fd62cbce.zip
chromium_src-899b93b7fcbb911e8205818aef1eeb64fd62cbce.tar.gz
chromium_src-899b93b7fcbb911e8205818aef1eeb64fd62cbce.tar.bz2
Don't delete Primary monitor and it's root window when
# of monitors goes zero. BUG=none TEST=nonoe Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=128684 Review URL: https://chromiumcodereview.appspot.com/9835068 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@128786 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/monitor')
-rw-r--r--ash/monitor/monitor_controller.cc16
-rw-r--r--ash/monitor/multi_monitor_manager.cc8
-rw-r--r--ash/monitor/multi_monitor_manager_unittest.cc58
3 files changed, 76 insertions, 6 deletions
diff --git a/ash/monitor/monitor_controller.cc b/ash/monitor/monitor_controller.cc
index 397e5ab..3ebfea4 100644
--- a/ash/monitor/monitor_controller.cc
+++ b/ash/monitor/monitor_controller.cc
@@ -58,6 +58,11 @@ void MonitorController::OnMonitorBoundsChanged(const aura::Monitor* monitor) {
}
void MonitorController::OnMonitorAdded(aura::Monitor* monitor) {
+ if (root_windows_.empty()) {
+ root_windows_[monitor] = Shell::GetRootWindow();
+ Shell::GetRootWindow()->SetHostBounds(monitor->bounds());
+ return;
+ }
aura::RootWindow* root = aura::Env::GetInstance()->monitor_manager()->
CreateRootWindowForMonitor(monitor);
root_windows_[monitor] = root;
@@ -66,8 +71,15 @@ void MonitorController::OnMonitorAdded(aura::Monitor* monitor) {
void MonitorController::OnMonitorRemoved(const aura::Monitor* monitor) {
aura::RootWindow* root = root_windows_[monitor];
- root_windows_.erase(monitor);
- delete root;
+ DCHECK(root);
+ // Primary monitor should never be removed by MonitorManager.
+ DCHECK(root != Shell::GetRootWindow());
+ // Monitor for root window will be deleted when the Primary RootWindow
+ // is deleted by the Shell.
+ if (root != Shell::GetRootWindow()) {
+ root_windows_.erase(monitor);
+ delete root;
+ }
}
void MonitorController::Init() {
diff --git a/ash/monitor/multi_monitor_manager.cc b/ash/monitor/multi_monitor_manager.cc
index 926aac1..01a9f02 100644
--- a/ash/monitor/multi_monitor_manager.cc
+++ b/ash/monitor/multi_monitor_manager.cc
@@ -90,11 +90,15 @@ void MultiMonitorManager::OnNativeMonitorsChanged(
NotifyMonitorAdded(monitor);
}
} else {
- // Monitors are removed.
- while (monitors_.size() > new_monitors.size()) {
+ // Monitors are removed. We keep the monitor for the primary
+ // monitor (at index 0) because it needs the monitor information
+ // even if it doesn't exit.
+ while (monitors_.size() > new_monitors.size() && monitors_.size() > 1) {
Monitor* monitor = monitors_.back();
// Monitor object is deleted in OnWindowDestroying.
NotifyMonitorRemoved(monitor);
+ DCHECK(find(monitors_.begin(), monitors_.end(), monitor) ==
+ monitors_.end());
}
}
}
diff --git a/ash/monitor/multi_monitor_manager_unittest.cc b/ash/monitor/multi_monitor_manager_unittest.cc
index 336f91c..afd0013 100644
--- a/ash/monitor/multi_monitor_manager_unittest.cc
+++ b/ash/monitor/multi_monitor_manager_unittest.cc
@@ -13,6 +13,7 @@
#include "ui/aura/env.h"
#include "ui/aura/monitor.h"
#include "ui/aura/root_window.h"
+#include "ui/aura/window_observer.h"
namespace ash {
namespace test {
@@ -38,16 +39,22 @@ vector<const aura::Monitor*> CreateMonitorsFromString(
} // namespace
class MultiMonitorManagerTest : public test::AshTestBase,
- public aura::MonitorObserver {
+ public aura::MonitorObserver,
+ public aura::WindowObserver {
public:
- MultiMonitorManagerTest() : removed_count_(0U) {}
+ MultiMonitorManagerTest()
+ : removed_count_(0U),
+ root_window_destroyed_(false) {
+ }
virtual ~MultiMonitorManagerTest() {}
virtual void SetUp() OVERRIDE {
AshTestBase::SetUp();
monitor_manager()->AddObserver(this);
+ Shell::GetRootWindow()->AddObserver(this);
}
virtual void TearDown() OVERRIDE {
+ Shell::GetRootWindow()->RemoveObserver(this);
monitor_manager()->RemoveObserver(this);
AshTestBase::TearDown();
}
@@ -67,6 +74,11 @@ class MultiMonitorManagerTest : public test::AshTestBase,
changed_.clear();
added_.clear();
removed_count_ = 0U;
+ root_window_destroyed_ = false;
+ }
+
+ bool root_window_destroyed() const {
+ return root_window_destroyed_;
}
// aura::MonitorObserver overrides:
@@ -80,6 +92,12 @@ class MultiMonitorManagerTest : public test::AshTestBase,
++removed_count_;
}
+ // aura::WindowObserver overrides:
+ virtual void OnWindowDestroying(aura::Window* window) {
+ ASSERT_EQ(Shell::GetRootWindow(), window);
+ root_window_destroyed_ = true;
+ }
+
void UpdateMonitor(const std::string str) {
vector<const aura::Monitor*> monitors = CreateMonitorsFromString(str);
monitor_manager()->OnNativeMonitorsChanged(monitors);
@@ -90,6 +108,7 @@ class MultiMonitorManagerTest : public test::AshTestBase,
vector<const Monitor*> changed_;
vector<const Monitor*> added_;
size_t removed_count_;
+ bool root_window_destroyed_;
DISALLOW_COPY_AND_ASSIGN(MultiMonitorManagerTest);
};
@@ -135,6 +154,41 @@ TEST_F(MultiMonitorManagerTest, NativeMonitorTest) {
EXPECT_EQ("1 0 1", GetCountSummary());
EXPECT_EQ(monitor_manager()->GetMonitorAt(0), changed()[0]);
EXPECT_EQ("0,0 800x300", changed()[0]->bounds().ToString());
+ reset();
+
+ // # of monitor can go to zero when screen is off.
+ const vector<const Monitor*> empty;
+ monitor_manager()->OnNativeMonitorsChanged(empty);
+ EXPECT_EQ(1U, monitor_manager()->GetNumMonitors());
+ EXPECT_EQ("0 0 0", GetCountSummary());
+ EXPECT_FALSE(root_window_destroyed());
+ // Monitor configuration stays the same
+ EXPECT_EQ("0,0 800x300",
+ monitor_manager()->GetMonitorAt(0)->bounds().ToString());
+ reset();
+
+ // Connect to monitor again
+ UpdateMonitor("100+100-500x400");
+ EXPECT_EQ(1U, monitor_manager()->GetNumMonitors());
+ EXPECT_EQ("1 0 0", GetCountSummary());
+ EXPECT_FALSE(root_window_destroyed());
+ EXPECT_EQ("100,100 500x400", changed()[0]->bounds().ToString());
+ reset();
+
+ // Go back to zero and wake up with multiple monitors.
+ monitor_manager()->OnNativeMonitorsChanged(empty);
+ EXPECT_EQ(1U, monitor_manager()->GetNumMonitors());
+ EXPECT_FALSE(root_window_destroyed());
+ reset();
+
+ // Add secondary.
+ UpdateMonitor("0+0-1000x600,1000+0-600x400");
+ EXPECT_EQ(2U, monitor_manager()->GetNumMonitors());
+ EXPECT_EQ("0,0 1000x600",
+ monitor_manager()->GetMonitorAt(0)->bounds().ToString());
+ EXPECT_EQ("1000,0 600x400",
+ monitor_manager()->GetMonitorAt(1)->bounds().ToString());
+ reset();
aura::MonitorManager::set_use_fullscreen_host_window(false);
}