Skip to content

Commit

Permalink
Show message to indicate that mirriring with more than 3 display is n…
Browse files Browse the repository at this point in the history
…ot supported.

BUG=608027
TEST=covered by unit test

Review-Url: https://codereview.chromium.org/1952353003
Cr-Commit-Position: refs/heads/master@{#392136}
  • Loading branch information
mitoshima authored and Commit bot committed May 6, 2016
1 parent 4202cfc commit 211a822
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 84 deletions.
3 changes: 3 additions & 0 deletions ash/ash_chromeos_strings.grdp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,9 @@ Press Shift + Alt to switch.
<message name="IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING" desc="An error message to show that the system failed to enter the extended desktop mode or unknown status. Please translate the parentized text.">
Dear Monitor, it's not working out between us. (That monitor is not supported. Click to send a feedback report.)
</message>
<message name="IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED" desc="A message used to explain that mirroring with more than two displays is not supported.">
Mirroring with more than two displays is not supported.
</message>
<message name="IDS_ASH_DISPLAY_RESOLUTION_CHANGE_ACCEPT" desc="A button label shown in the notification for the resolution change to accept the change">
Accept
</message>
Expand Down
9 changes: 9 additions & 0 deletions ash/display/display_configuration_controller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/display/display_animator.h"
#include "ash/display/display_manager.h"
#include "ash/display/display_util.h"
#include "ash/rotator/screen_rotation_animator.h"
#include "ash/screen_util.h"
#include "base/time/time.h"
Expand All @@ -14,6 +15,7 @@
#if defined(OS_CHROMEOS)
#include "ash/display/display_animator_chromeos.h"
#include "base/sys_info.h"
#include "grit/ash_strings.h"
#endif

namespace {
Expand Down Expand Up @@ -81,6 +83,13 @@ void DisplayConfigurationController::SetDisplayLayout(

void DisplayConfigurationController::SetMirrorMode(bool mirror,
bool user_action) {
if (display_manager_->num_connected_displays() > 2) {
#if defined(OS_CHROMEOS)
if (user_action)
ShowDisplayErrorNotification(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED);
#endif
return;
}
if (display_manager_->num_connected_displays() <= 1 ||
display_manager_->IsInMirrorMode() == mirror || IsLimited()) {
return;
Expand Down
83 changes: 5 additions & 78 deletions ash/display/display_error_observer_chromeos.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,52 +4,11 @@

#include "ash/display/display_error_observer_chromeos.h"

#include <cinttypes>
#include <memory>
#include <utility>

#include "ash/new_window_delegate.h"
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "ash/display/display_util.h"
#include "base/strings/string_number_conversions.h"
#include "grit/ash_resources.h"
#include "grit/ash_strings.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_delegate.h"
#include "ui/message_center/notification_list.h"

using message_center::Notification;

namespace ash {
namespace {

const char kDisplayErrorNotificationId[] = "chrome://settings/display/error";

// A notification delegate that will start the feedback app when the notication
// is clicked.
class DisplayErrorNotificationDelegate
: public message_center::NotificationDelegate {
public:
DisplayErrorNotificationDelegate() = default;

// message_center::NotificationDelegate:
bool HasClickedListener() override { return true; }

void Click() override {
ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
}

private:
// Private destructor since NotificationDelegate is ref-counted.
~DisplayErrorNotificationDelegate() override = default;

DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate);
};

} // namespace

DisplayErrorObserver::DisplayErrorObserver() {
}
Expand All @@ -68,42 +27,10 @@ void DisplayErrorObserver::OnDisplayModeChangeFailed(
<< ".";
}

// Always remove the notification to make sure the notification appears
// as a popup in any situation.
message_center::MessageCenter::Get()->RemoveNotification(
kDisplayErrorNotificationId, false /* by_user */);

int message_id = (new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR) ?
IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING :
IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING;

ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
std::unique_ptr<Notification> notification(new Notification(
message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId,
base::string16(), // title
l10n_util::GetStringUTF16(message_id),
bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
base::string16(), // display_source
GURL(),
message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
system_notifier::kNotifierDisplayError),
message_center::RichNotificationData(),
new DisplayErrorNotificationDelegate));
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
}

base::string16
DisplayErrorObserver::GetDisplayErrorNotificationMessageForTest() {
message_center::NotificationList::Notifications notifications =
message_center::MessageCenter::Get()->GetVisibleNotifications();
for (message_center::NotificationList::Notifications::const_iterator iter =
notifications.begin(); iter != notifications.end(); ++iter) {
if ((*iter)->id() == kDisplayErrorNotificationId)
return (*iter)->message();
}

return base::string16();
ShowDisplayErrorNotification(
(new_state == ui::MULTIPLE_DISPLAY_STATE_DUAL_MIRROR)
? IDS_ASH_DISPLAY_FAILURE_ON_MIRRORING
: IDS_ASH_DISPLAY_FAILURE_ON_NON_MIRRORING);
}

} // namespace ash
4 changes: 0 additions & 4 deletions ash/display/display_error_observer_chromeos.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class ASH_EXPORT DisplayErrorObserver
ui::MultipleDisplayState failed_new_state) override;

private:
friend class DisplayErrorObserverTest;

base::string16 GetDisplayErrorNotificationMessageForTest();

DISALLOW_COPY_AND_ASSIGN(DisplayErrorObserver);
};

Expand Down
3 changes: 2 additions & 1 deletion ash/display/display_error_observer_chromeos_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#include "ash/display/display_error_observer_chromeos.h"

#include "ash/display/display_util.h"
#include "ash/shell.h"
#include "ash/test/ash_test_base.h"
#include "grit/ash_strings.h"
Expand Down Expand Up @@ -31,7 +32,7 @@ class DisplayErrorObserverTest : public test::AshTestBase {
DisplayErrorObserver* observer() { return observer_.get(); }

base::string16 GetMessageContents() {
return observer_->GetDisplayErrorNotificationMessageForTest();
return GetDisplayErrorNotificationMessageForTest();
}

private:
Expand Down
10 changes: 9 additions & 1 deletion ash/display/display_manager_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "ash/accelerators/accelerator_commands.h"
#include "ash/ash_switches.h"
#include "ash/display/display_configuration_controller.h"
#include "ash/display/display_info.h"
#include "ash/display/display_layout_store.h"
#include "ash/display/display_util.h"
Expand All @@ -22,10 +23,12 @@
#include "base/format_macros.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/stringprintf.h"
#include "grit/ash_strings.h"
#include "ui/aura/client/aura_constants.h"
#include "ui/aura/env.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/display/display.h"
#include "ui/display/display_observer.h"
#include "ui/display/manager/display_layout_builder.h"
Expand Down Expand Up @@ -453,9 +456,14 @@ TEST_F(DisplayManagerTest, NoMirrorInThreeDisplays) {
return;

UpdateDisplay("640x480,320x200,400x300");
display_manager()->SetMirrorMode(true);
ash::Shell::GetInstance()->display_configuration_controller()->SetMirrorMode(
true, true);
EXPECT_FALSE(display_manager()->IsInMirrorMode());
EXPECT_EQ(3u, display_manager()->GetNumDisplays());
#if defined(OS_CHROMEOS)
EXPECT_EQ(l10n_util::GetStringUTF16(IDS_ASH_DISPLAY_MIRRORING_NOT_SUPPORTED),
GetDisplayErrorNotificationMessageForTest());
#endif
}

TEST_F(DisplayManagerTest, OverscanInsetsTest) {
Expand Down
65 changes: 65 additions & 0 deletions ash/display/display_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
#include "ash/display/display_info.h"
#include "ash/display/display_manager.h"
#include "ash/host/ash_window_tree_host.h"
#include "ash/new_window_delegate.h"
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "base/strings/string_number_conversions.h"
#include "grit/ash_resources.h"
#include "ui/aura/env.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/display/display.h"
#include "ui/gfx/geometry/point.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/gfx/geometry/size_conversions.h"
#include "ui/message_center/message_center.h"
#include "ui/message_center/notification.h"
#include "ui/message_center/notification_delegate.h"
#include "ui/message_center/notification_list.h"
#include "ui/wm/core/coordinate_conversion.h"

#if defined(OS_CHROMEOS)
Expand All @@ -26,6 +35,29 @@
namespace ash {
namespace {

const char kDisplayErrorNotificationId[] = "chrome://settings/display/error";

// A notification delegate that will start the feedback app when the notication
// is clicked.
class DisplayErrorNotificationDelegate
: public message_center::NotificationDelegate {
public:
DisplayErrorNotificationDelegate() = default;

// message_center::NotificationDelegate:
bool HasClickedListener() override { return true; }

void Click() override {
ash::Shell::GetInstance()->new_window_delegate()->OpenFeedbackPage();
}

private:
// Private destructor since NotificationDelegate is ref-counted.
~DisplayErrorNotificationDelegate() override = default;

DISALLOW_COPY_AND_ASSIGN(DisplayErrorNotificationDelegate);
};

// List of value UI Scale values. Scales for 2x are equivalent to 640,
// 800, 1024, 1280, 1440, 1600 and 1920 pixel width respectively on
// 2560 pixel width 2x density display. Please see crbug.com/233375
Expand Down Expand Up @@ -407,4 +439,37 @@ bool CompareDisplayIds(int64_t id1, int64_t id2) {
(index_1 < index_2 && !display::Display::IsInternalDisplayId(id2));
}

void ShowDisplayErrorNotification(int message_id) {
// Always remove the notification to make sure the notification appears
// as a popup in any situation.
message_center::MessageCenter::Get()->RemoveNotification(
kDisplayErrorNotificationId, false /* by_user */);

ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
std::unique_ptr<message_center::Notification> notification(
new message_center::Notification(
message_center::NOTIFICATION_TYPE_SIMPLE, kDisplayErrorNotificationId,
base::string16(), // title
l10n_util::GetStringUTF16(message_id),
bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY),
base::string16(), // display_source
GURL(), message_center::NotifierId(
message_center::NotifierId::SYSTEM_COMPONENT,
system_notifier::kNotifierDisplayError),
message_center::RichNotificationData(),
new DisplayErrorNotificationDelegate));
message_center::MessageCenter::Get()->AddNotification(
std::move(notification));
}

base::string16 GetDisplayErrorNotificationMessageForTest() {
message_center::NotificationList::Notifications notifications =
message_center::MessageCenter::Get()->GetVisibleNotifications();
for (auto const notification : notifications) {
if (notification->id() == kDisplayErrorNotificationId)
return notification->message();
}
return base::string16();
}

} // namespace ash
5 changes: 5 additions & 0 deletions ash/display/display_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ ASH_EXPORT std::string DisplayIdListToString(
// 2) output index of id1 < output index of id2 and id2 isn't internal.
ASH_EXPORT bool CompareDisplayIds(int64_t id1, int64_t id2);

// Shows the notification message for display related issues.
void ShowDisplayErrorNotification(int message_id);

ASH_EXPORT base::string16 GetDisplayErrorNotificationMessageForTest();

} // namespace ash

#endif // ASH_DISPLAY_DISPLAY_UTIL_H_

0 comments on commit 211a822

Please sign in to comment.