summaryrefslogtreecommitdiffstats
path: root/ash/display
diff options
context:
space:
mode:
authoroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-19 16:40:19 +0000
committeroshima@chromium.org <oshima@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-03-19 16:40:19 +0000
commit832533522200888ff004f1ceac10d730d58010f6 (patch)
tree92fa966968c0887b50c4bd050b35899c5c493755 /ash/display
parent18cdb0e4680927e33e8484364a6ec1cf9f77d91e (diff)
downloadchromium_src-832533522200888ff004f1ceac10d730d58010f6.zip
chromium_src-832533522200888ff004f1ceac10d730d58010f6.tar.gz
chromium_src-832533522200888ff004f1ceac10d730d58010f6.tar.bz2
Save display preference when all display configuration changes has been completed.
Add OnDisplayConfigurationChanged to DisplayController::Observer Save primary only in ExtededDesktop mode TBR=sky@chromium.org BUG=196818 TEST=covered by test, and also tested manually. Review URL: https://chromiumcodereview.appspot.com/12438016 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@189040 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/display')
-rw-r--r--ash/display/display_controller.cc9
-rw-r--r--ash/display/display_controller.h8
-rw-r--r--ash/display/display_controller_unittest.cc54
-rw-r--r--ash/display/display_manager.cc27
4 files changed, 76 insertions, 22 deletions
diff --git a/ash/display/display_controller.cc b/ash/display/display_controller.cc
index 2db32f7..551214d 100644
--- a/ash/display/display_controller.cc
+++ b/ash/display/display_controller.cc
@@ -457,6 +457,7 @@ void DisplayController::SetDefaultDisplayLayout(const DisplayLayout& layout) {
default_display_layout_ = layout;
NotifyDisplayConfigurationChanging();
UpdateDisplayBoundsForLayout();
+ NotifyDisplayConfigurationChanged();
}
}
@@ -498,6 +499,7 @@ void DisplayController::SetLayoutForCurrentDisplays(
paired_layouts_[pair] = to_set;
NotifyDisplayConfigurationChanging();
UpdateDisplayBoundsForLayout();
+ NotifyDisplayConfigurationChanged();
}
}
@@ -670,7 +672,6 @@ void DisplayController::OnDisplayBoundsChanged(const gfx::Display& display) {
GetDisplayManager()->GetDisplayInfo(display);
DCHECK(!display_info.bounds_in_pixel().IsEmpty());
- NotifyDisplayConfigurationChanging();
UpdateDisplayBoundsForLayout();
aura::RootWindow* root = root_windows_[display.id()];
root->SetHostBoundsAndInsetsAndRootWindowScale(
@@ -684,7 +685,6 @@ void DisplayController::OnDisplayAdded(const gfx::Display& display) {
if (limiter_.get())
limiter_->SetThrottleTimeout(kAfterDisplayChangeThrottleTimeoutMs);
- NotifyDisplayConfigurationChanging();
if (primary_root_window_for_replace_) {
DCHECK(root_windows_.empty());
primary_display_id = display.id();
@@ -715,7 +715,6 @@ void DisplayController::OnDisplayRemoved(const gfx::Display& display) {
aura::RootWindow* root_to_delete = root_windows_[display.id()];
DCHECK(root_to_delete) << display.ToString();
- NotifyDisplayConfigurationChanging();
// Display for root window will be deleted when the Primary RootWindow
// is deleted by the Shell.
@@ -847,6 +846,10 @@ void DisplayController::NotifyDisplayConfigurationChanging() {
FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanging());
}
+void DisplayController::NotifyDisplayConfigurationChanged() {
+ FOR_EACH_OBSERVER(Observer, observers_, OnDisplayConfigurationChanged());
+}
+
void DisplayController::RegisterLayoutForDisplayIdPairInternal(
int64 id1,
int64 id2,
diff --git a/ash/display/display_controller.h b/ash/display/display_controller.h
index eb6f487..f58dc12 100644
--- a/ash/display/display_controller.h
+++ b/ash/display/display_controller.h
@@ -30,6 +30,7 @@ template <typename T> class JSONValueConverter;
namespace ash {
namespace internal {
+class DisplayManager;
class RootWindowController;
}
@@ -79,6 +80,10 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
// but before the change is applied to aura/ash.
virtual void OnDisplayConfigurationChanging() = 0;
+ // Invoked when the all display configuration changes
+ // have been applied.
+ virtual void OnDisplayConfigurationChanged() {};
+
protected:
virtual ~Observer() {}
};
@@ -180,6 +185,8 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
virtual void OnDisplayRemoved(const gfx::Display& display) OVERRIDE;
private:
+ friend class internal::DisplayManager;
+
// Create a root window for given |display|.
aura::RootWindow* CreateRootWindowForDisplay(const gfx::Display& display);
@@ -190,6 +197,7 @@ class ASH_EXPORT DisplayController : public gfx::DisplayObserver {
void UpdateDisplayBoundsForLayout();
void NotifyDisplayConfigurationChanging();
+ void NotifyDisplayConfigurationChanged();
void SetLayoutForDisplayIdPair(const DisplayIdPair& display_pair,
const DisplayLayout& layout);
diff --git a/ash/display/display_controller_unittest.cc b/ash/display/display_controller_unittest.cc
index 23d6c20..d1713f0 100644
--- a/ash/display/display_controller_unittest.cc
+++ b/ash/display/display_controller_unittest.cc
@@ -27,7 +27,7 @@ namespace {
class TestObserver : public DisplayController::Observer {
public:
- TestObserver() : count_(0) {
+ TestObserver() : changing_count_(0), changed_count_(0) {
Shell::GetInstance()->display_controller()->AddObserver(this);
}
@@ -36,17 +36,23 @@ class TestObserver : public DisplayController::Observer {
}
virtual void OnDisplayConfigurationChanging() OVERRIDE {
- ++count_;
+ ++changing_count_;
+ }
+
+ virtual void OnDisplayConfigurationChanged() OVERRIDE {
+ ++changed_count_;
}
int CountAndReset() {
- int c = count_;
- count_ = 0;
+ EXPECT_EQ(changing_count_, changed_count_);
+ int c = changing_count_;
+ changing_count_ = changed_count_ = 0;
return c;
}
private:
- int count_;
+ int changing_count_;
+ int changed_count_;
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
@@ -127,7 +133,7 @@ TEST_F(DisplayControllerShutdownTest, Shutdown) {
TEST_F(DisplayControllerTest, SecondaryDisplayLayout) {
TestObserver observer;
UpdateDisplay("500x500,400x400");
- EXPECT_EQ(2, observer.CountAndReset()); // resize and add
+ EXPECT_EQ(1, observer.CountAndReset()); // resize and add
gfx::Display* secondary_display =
Shell::GetInstance()->display_manager()->GetDisplayAt(1);
gfx::Insets insets(5, 5, 5, 5);
@@ -198,10 +204,11 @@ TEST_F(DisplayControllerTest, BoundsUpdated) {
TestObserver observer;
SetSecondaryDisplayLayout(DisplayLayout::BOTTOM);
UpdateDisplay("200x200,300x300"); // layout, resize and add.
- EXPECT_EQ(3, observer.CountAndReset());
+ EXPECT_EQ(2, observer.CountAndReset());
- gfx::Display* secondary_display =
- Shell::GetInstance()->display_manager()->GetDisplayAt(1);
+ internal::DisplayManager* display_manager =
+ Shell::GetInstance()->display_manager();
+ gfx::Display* secondary_display = display_manager->GetDisplayAt(1);
gfx::Insets insets(5, 5, 5, 5);
secondary_display->UpdateWorkAreaFromInsets(insets);
@@ -210,7 +217,7 @@ TEST_F(DisplayControllerTest, BoundsUpdated) {
EXPECT_EQ("5,205 290x290", GetSecondaryDisplay().work_area().ToString());
UpdateDisplay("400x400,200x200");
- EXPECT_EQ(2, observer.CountAndReset()); // two resizes
+ EXPECT_EQ(1, observer.CountAndReset()); // two resizes
EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ("0,400 200x200", GetSecondaryDisplay().bounds().ToString());
if (!ash::Shell::IsLauncherPerDisplayEnabled())
@@ -228,11 +235,30 @@ TEST_F(DisplayControllerTest, BoundsUpdated) {
EXPECT_EQ("0,0 400x400", GetPrimaryDisplay().bounds().ToString());
EXPECT_EQ(1, Shell::GetScreen()->GetNumDisplays());
- UpdateDisplay("500x500,700x700");
- EXPECT_EQ(2, observer.CountAndReset());
+ UpdateDisplay("400x500,700x700*2");
+ EXPECT_EQ(1, observer.CountAndReset());
ASSERT_EQ(2, Shell::GetScreen()->GetNumDisplays());
- EXPECT_EQ("0,0 500x500", GetPrimaryDisplay().bounds().ToString());
- EXPECT_EQ("0,500 700x700", GetSecondaryDisplay().bounds().ToString());
+ EXPECT_EQ("0,0 400x500", GetPrimaryDisplay().bounds().ToString());
+ EXPECT_EQ("0,500 350x350", GetSecondaryDisplay().bounds().ToString());
+
+ // No change
+ UpdateDisplay("400x500,700x700*2");
+ EXPECT_EQ(0, observer.CountAndReset());
+
+ // Rotation
+ int64 primary_id = GetPrimaryDisplay().id();
+ display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
+ EXPECT_EQ(1, observer.CountAndReset());
+ display_manager->SetDisplayRotation(primary_id, gfx::Display::ROTATE_90);
+ EXPECT_EQ(0, observer.CountAndReset());
+
+ // UI scale
+ int64 secondary_id = GetSecondaryDisplay().id();
+ gfx::Display::SetInternalDisplayId(secondary_id);
+ display_manager->SetDisplayUIScale(secondary_id, 1.25f);
+ EXPECT_EQ(1, observer.CountAndReset());
+ display_manager->SetDisplayUIScale(secondary_id, 1.25f);
+ EXPECT_EQ(0, observer.CountAndReset());
}
TEST_F(DisplayControllerTest, InvertLayout) {
diff --git a/ash/display/display_manager.cc b/ash/display/display_manager.cc
index ad92a5e..bf4d188 100644
--- a/ash/display/display_manager.cc
+++ b/ash/display/display_manager.cc
@@ -179,8 +179,11 @@ void DisplayManager::SetDisplayRotation(int64 display_id,
for (DisplayList::const_iterator iter = displays_.begin();
iter != displays_.end(); ++iter) {
DisplayInfo info = GetDisplayInfo(*iter);
- if (info.id() == display_id)
+ if (info.id() == display_id) {
+ if (info.rotation() == rotation)
+ return;
info.set_rotation(rotation);
+ }
display_info_list.push_back(info);
}
UpdateDisplays(display_info_list);
@@ -194,8 +197,11 @@ void DisplayManager::SetDisplayUIScale(int64 display_id,
for (DisplayList::const_iterator iter = displays_.begin();
iter != displays_.end(); ++iter) {
DisplayInfo info = GetDisplayInfo(*iter);
- if (info.id() == display_id)
+ if (info.id() == display_id) {
+ if (info.ui_scale() == ui_scale)
+ return;
info.set_ui_scale(ui_scale);
+ }
display_info_list.push_back(info);
}
UpdateDisplays(display_info_list);
@@ -217,9 +223,12 @@ bool DisplayManager::IsDisplayUIScalingEnabled() const {
// 2x density (currently Pixel).
int64 display_id = gfx::Display::InternalDisplayId();
#if defined(OS_CHROMEOS)
- // On linux desktop, allow ui scaling on the first dislpay.
- if (!base::chromeos::IsRunningOnChromeOS())
+ // On linux desktop, allow ui scaling on the first dislpay if an internal
+ // display isn't specified.
+ if (display_id == gfx::Display::kInvalidDisplayID &&
+ !base::chromeos::IsRunningOnChromeOS()) {
display_id = Shell::GetInstance()->display_manager()->first_display_id();
+ }
#endif
return GetDisplayForId(display_id).device_scale_factor() == 2.0f;
}
@@ -371,6 +380,12 @@ void DisplayManager::UpdateDisplays(
// being removed are accessed during shutting down the root.
displays_.insert(displays_.end(), removed_displays.begin(),
removed_displays.end());
+ DisplayController* display_controller =
+ Shell::GetInstance()->display_controller();
+ // |display_controller| is NULL during the bootstrap.
+ if (display_controller)
+ display_controller->NotifyDisplayConfigurationChanging();
+
for (DisplayList::const_reverse_iterator iter = removed_displays.rbegin();
iter != removed_displays.rend(); ++iter) {
Shell::GetInstance()->screen()->NotifyDisplayRemoved(displays_.back());
@@ -384,8 +399,10 @@ void DisplayManager::UpdateDisplays(
iter != changed_display_indices.end(); ++iter) {
Shell::GetInstance()->screen()->NotifyBoundsChanged(displays_[*iter]);
}
- EnsurePointerInDisplays();
+ if (display_controller)
+ display_controller->NotifyDisplayConfigurationChanged();
+ EnsurePointerInDisplays();
#if defined(USE_X11) && defined(OS_CHROMEOS)
if (!changed_display_indices.empty() && base::chromeos::IsRunningOnChromeOS())
ui::ClearX11DefaultRootWindow();