summaryrefslogtreecommitdiffstats
path: root/ash
diff options
context:
space:
mode:
authorjonross <jonross@chromium.org>2015-04-09 15:21:13 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-09 22:21:46 +0000
commit86d410a6c6aab450259f210e8fe6fb8c3f6e7651 (patch)
tree07bb0887cd3b37d2a7b8069e41f7a7ecc03c1380 /ash
parent49cac9b06ec43030b706432b5d98fd2e6621d63c (diff)
downloadchromium_src-86d410a6c6aab450259f210e8fe6fb8c3f6e7651.zip
chromium_src-86d410a6c6aab450259f210e8fe6fb8c3f6e7651.tar.gz
chromium_src-86d410a6c6aab450259f210e8fe6fb8c3f6e7651.tar.bz2
Have TrayRotationLock account for delayed Display Configurations
With the move to ozone the reading of display configurations is now asynchronous. Due to this the status tray can be created before the internal display is known. Update TrayRotationLock to check display id at runtime for visibility, instead of at creation time. This will allow it to properly display on Ozone builds. TEST=TrayRotationLockTest.InternalDisplayNotAvailableAtCreation BUG=470674 Review URL: https://codereview.chromium.org/1070153002 Cr-Commit-Position: refs/heads/master@{#324523}
Diffstat (limited to 'ash')
-rw-r--r--ash/system/chromeos/rotation/tray_rotation_lock.cc26
-rw-r--r--ash/system/chromeos/rotation/tray_rotation_lock.h4
-rw-r--r--ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc30
3 files changed, 44 insertions, 16 deletions
diff --git a/ash/system/chromeos/rotation/tray_rotation_lock.cc b/ash/system/chromeos/rotation/tray_rotation_lock.cc
index dc2254d..e860976 100644
--- a/ash/system/chromeos/rotation/tray_rotation_lock.cc
+++ b/ash/system/chromeos/rotation/tray_rotation_lock.cc
@@ -95,21 +95,12 @@ void RotationLockDefaultView::UpdateImage() {
} // namespace tray
TrayRotationLock::TrayRotationLock(SystemTray* system_tray)
- : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED),
- on_primary_display_(false) {
- gfx::NativeView native_view = system_tray->GetWidget()->GetNativeView();
- gfx::Display parent_display = Shell::GetScreen()->
- GetDisplayNearestWindow(native_view);
-
- on_primary_display_ = parent_display.IsInternal();
-
- if (on_primary_display_)
- Shell::GetInstance()->AddShellObserver(this);
+ : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_AUTO_ROTATION_LOCKED) {
+ Shell::GetInstance()->AddShellObserver(this);
}
TrayRotationLock::~TrayRotationLock() {
- if (on_primary_display_)
- Shell::GetInstance()->RemoveShellObserver(this);
+ Shell::GetInstance()->RemoveShellObserver(this);
}
void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) {
@@ -117,7 +108,7 @@ void TrayRotationLock::OnRotationLockChanged(bool rotation_locked) {
}
views::View* TrayRotationLock::CreateDefaultView(user::LoginStatus status) {
- if (on_primary_display_)
+ if (OnPrimaryDisplay())
return new tray::RotationLockDefaultView(this);
return NULL;
}
@@ -138,7 +129,7 @@ bool TrayRotationLock::GetInitialVisibility() {
}
bool TrayRotationLock::ShouldBeVisible() {
- return on_primary_display_ &&
+ return OnPrimaryDisplay() &&
Shell::GetInstance()
->maximize_mode_controller()
->IsMaximizeModeWindowManagerEnabled() &&
@@ -147,4 +138,11 @@ bool TrayRotationLock::ShouldBeVisible() {
->rotation_locked();
}
+bool TrayRotationLock::OnPrimaryDisplay() const {
+ gfx::NativeView native_view = system_tray()->GetWidget()->GetNativeView();
+ gfx::Display parent_display =
+ Shell::GetScreen()->GetDisplayNearestWindow(native_view);
+ return parent_display.IsInternal();
+}
+
} // namespace ash
diff --git a/ash/system/chromeos/rotation/tray_rotation_lock.h b/ash/system/chromeos/rotation/tray_rotation_lock.h
index b9d7884..236e9ed 100644
--- a/ash/system/chromeos/rotation/tray_rotation_lock.h
+++ b/ash/system/chromeos/rotation/tray_rotation_lock.h
@@ -49,8 +49,8 @@ class ASH_EXPORT TrayRotationLock
// locked.
bool ShouldBeVisible();
- // True if this has been created by a SystemTray on the primary display.
- bool on_primary_display_;
+ // True if this is owned by a SystemTray on the primary display.
+ bool OnPrimaryDisplay() const;
DISALLOW_COPY_AND_ASSIGN(TrayRotationLock);
};
diff --git a/ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc b/ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc
index f551a1b..6938469 100644
--- a/ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc
+++ b/ash/system/chromeos/rotation/tray_rotation_lock_unittest.cc
@@ -42,6 +42,9 @@ class TrayRotationLockTest : public test::AshTestBase {
return default_view_.get();
}
+ // Creates the tray view associated to |tray_rotation_lock|.
+ views::View* CreateTrayView(TrayRotationLock* tray_rotation_lock);
+
// Sets up a TrayRotationLock, its tray view, and its default view, for the
// given SystemTray and its display. On a primary display all will be
// created. On a secondary display both the tray view and default view will
@@ -65,6 +68,12 @@ class TrayRotationLockTest : public test::AshTestBase {
DISALLOW_COPY_AND_ASSIGN(TrayRotationLockTest);
};
+views::View* TrayRotationLockTest::CreateTrayView(
+ TrayRotationLock* tray_rotation_lock) {
+ return tray_rotation_lock->CreateTrayView(
+ StatusAreaWidgetTestHelper::GetUserLoginStatus());
+}
+
void TrayRotationLockTest::SetUpForStatusAreaWidget(
StatusAreaWidget* status_area_widget) {
tray_.reset(new TrayRotationLock(status_area_widget->system_tray()));
@@ -222,4 +231,25 @@ TEST_F(TrayRotationLockTest, PerformActionOnDefaultView) {
maximize_mode_controller->EnableMaximizeModeWindowManager(false);
}
+// Tests that when the tray is created without the internal display being known,
+// that it will still display correctly once the internal display is known.
+TEST_F(TrayRotationLockTest, InternalDisplayNotAvailableAtCreation) {
+ int64 internal_display_id = gfx::Display::InternalDisplayId();
+ TearDownViews();
+ gfx::Display::SetInternalDisplayId(gfx::Display::kInvalidDisplayID);
+
+ scoped_ptr<TrayRotationLock> tray(new TrayRotationLock(
+ StatusAreaWidgetTestHelper::GetStatusAreaWidget()->system_tray()));
+
+ gfx::Display::SetInternalDisplayId(internal_display_id);
+ scoped_ptr<views::View> tray_view(CreateTrayView(tray.get()));
+ scoped_ptr<views::View> default_view(tray->CreateDefaultView(
+ StatusAreaWidgetTestHelper::GetUserLoginStatus()));
+ EXPECT_TRUE(default_view);
+ Shell::GetInstance()
+ ->maximize_mode_controller()
+ ->EnableMaximizeModeWindowManager(true);
+ EXPECT_TRUE(default_view->visible());
+}
+
} // namespace ash