Commit 9f994b9a authored by mukai@chromium.org's avatar mukai@chromium.org

Updates the list of display info in TrayDisplay even if notification is prevented.

BUG=270200
R=oshima@chromium.org, stevenjb@chromium.org
TEST=new test case covers

Review URL: https://chromiumcodereview.appspot.com/22908004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217143 0039d316-1c4b-4281-b951-d872f2087c98
parent a49a7aff
...@@ -326,21 +326,28 @@ TrayDisplay::TrayDisplay(SystemTray* system_tray) ...@@ -326,21 +326,28 @@ TrayDisplay::TrayDisplay(SystemTray* system_tray)
: SystemTrayItem(system_tray), : SystemTrayItem(system_tray),
default_(NULL) { default_(NULL) {
Shell::GetInstance()->display_controller()->AddObserver(this); Shell::GetInstance()->display_controller()->AddObserver(this);
UpdateDisplayInfo(NULL);
} }
TrayDisplay::~TrayDisplay() { TrayDisplay::~TrayDisplay() {
Shell::GetInstance()->display_controller()->RemoveObserver(this); Shell::GetInstance()->display_controller()->RemoveObserver(this);
} }
bool TrayDisplay::GetDisplayMessageForNotification(base::string16* message) { void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) {
if (old_info)
old_info->swap(display_info_);
display_info_.clear();
DisplayManager* display_manager = GetDisplayManager(); DisplayManager* display_manager = GetDisplayManager();
DisplayInfoMap old_info;
old_info.swap(display_info_);
for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
int64 id = display_manager->GetDisplayAt(i).id(); int64 id = display_manager->GetDisplayAt(i).id();
display_info_[id] = display_manager->GetDisplayInfo(id); display_info_[id] = display_manager->GetDisplayInfo(id);
} }
}
bool TrayDisplay::GetDisplayMessageForNotification(
base::string16* message,
const TrayDisplay::DisplayInfoMap& old_info) {
// Display is added or removed. Use the same message as the one in // Display is added or removed. Use the same message as the one in
// the system tray. // the system tray.
if (display_info_.size() != old_info.size()) { if (display_info_.size() != old_info.size()) {
...@@ -405,13 +412,16 @@ void TrayDisplay::DestroyDefaultView() { ...@@ -405,13 +412,16 @@ void TrayDisplay::DestroyDefaultView() {
} }
void TrayDisplay::OnDisplayConfigurationChanged() { void TrayDisplay::OnDisplayConfigurationChanged() {
DisplayInfoMap old_info;
UpdateDisplayInfo(&old_info);
if (!Shell::GetInstance()->system_tray_delegate()-> if (!Shell::GetInstance()->system_tray_delegate()->
ShouldShowDisplayNotification()) { ShouldShowDisplayNotification()) {
return; return;
} }
base::string16 message; base::string16 message;
if (GetDisplayMessageForNotification(&message)) if (GetDisplayMessageForNotification(&message, old_info))
UpdateDisplayNotification(message); UpdateDisplayNotification(message);
} }
......
...@@ -37,11 +37,17 @@ class ASH_EXPORT TrayDisplay : public SystemTrayItem, ...@@ -37,11 +37,17 @@ class ASH_EXPORT TrayDisplay : public SystemTrayItem,
typedef std::map<int64, DisplayInfo> DisplayInfoMap; typedef std::map<int64, DisplayInfo> DisplayInfoMap;
// Checks the current display settings and determine what message should be // Scans the current display info and updates |display_info_|. Sets the
// shown for notification. Returns true if there's a meaningful change. Note // previous data to |old_info| if it's not NULL.
// that it's possible to return true and set |message| to empty, which means void UpdateDisplayInfo(DisplayInfoMap* old_info);
// the notification should be removed.
bool GetDisplayMessageForNotification(base::string16* message); // Compares the current display settings with |old_info| and determine what
// message should be shown for notification. Returns true if there's a
// meaningful change. Note that it's possible to return true and set |message|
// to empty, which means the notification should be removed.
bool GetDisplayMessageForNotification(
base::string16* message,
const DisplayInfoMap& old_info);
// Overridden from SystemTrayItem. // Overridden from SystemTrayItem.
virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE; virtual views::View* CreateDefaultView(user::LoginStatus status) OVERRIDE;
......
...@@ -437,5 +437,24 @@ TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) { ...@@ -437,5 +437,24 @@ TEST_F(TrayDisplayTest, DisplayConfigurationChangedTwice) {
EXPECT_TRUE(GetDisplayNotificationText().empty()); EXPECT_TRUE(GetDisplayNotificationText().empty());
} }
TEST_F(TrayDisplayTest, UpdateAfterSuppressDisplayNotification) {
UpdateDisplay("400x400,200x200");
test::TestSystemTrayDelegate* tray_delegate =
static_cast<test::TestSystemTrayDelegate*>(
Shell::GetInstance()->system_tray_delegate());
tray_delegate->set_should_show_display_notification(true);
// rotate the second.
UpdateDisplay("400x400,200x200/r");
EXPECT_EQ(
l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED,
GetSecondDisplayName(),
l10n_util::GetStringUTF16(
IDS_ASH_STATUS_TRAY_DISPLAY_ORIENTATION_90)),
GetDisplayNotificationText());
}
} // namespace internal } // namespace internal
} // namespace ash } // namespace ash
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment