| Index: ash/system/chromeos/screen_layout_observer.cc
|
| diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/screen_layout_observer.cc
|
| similarity index 46%
|
| copy from ash/system/chromeos/tray_display.cc
|
| copy to ash/system/chromeos/screen_layout_observer.cc
|
| index dc5a11d3a078feb22d3e6879cfe29dad7df5e667..8511732b0b0dfeb9da66044dbf8ca9a3eede6bd8 100644
|
| --- a/ash/system/chromeos/tray_display.cc
|
| +++ b/ash/system/chromeos/screen_layout_observer.cc
|
| @@ -2,7 +2,7 @@
|
| // Use of this source code is governed by a BSD-style license that can be
|
| // found in the LICENSE file.
|
|
|
| -#include "ash/system/chromeos/tray_display.h"
|
| +#include "ash/system/chromeos/screen_layout_observer.h"
|
|
|
| #include <memory>
|
| #include <utility>
|
| @@ -11,9 +11,7 @@
|
| #include "ash/common/metrics/user_metrics_action.h"
|
| #include "ash/common/system/chromeos/devicetype_utils.h"
|
| #include "ash/common/system/system_notifier.h"
|
| -#include "ash/common/system/tray/actionable_view.h"
|
| #include "ash/common/system/tray/fixed_sized_image_view.h"
|
| -#include "ash/common/system/tray/system_tray.h"
|
| #include "ash/common/system/tray/system_tray_delegate.h"
|
| #include "ash/common/system/tray/tray_constants.h"
|
| #include "ash/common/system/tray/tray_notification_view.h"
|
| @@ -32,9 +30,6 @@
|
| #include "ui/message_center/message_center.h"
|
| #include "ui/message_center/notification.h"
|
| #include "ui/message_center/notification_delegate.h"
|
| -#include "ui/views/controls/image_view.h"
|
| -#include "ui/views/controls/label.h"
|
| -#include "ui/views/layout/box_layout.h"
|
|
|
| using message_center::Notification;
|
|
|
| @@ -67,51 +62,6 @@ base::string16 GetDisplaySize(int64_t display_id) {
|
| return base::UTF8ToUTF16(display->size().ToString());
|
| }
|
|
|
| -// Returns 1-line information for the specified display, like
|
| -// "InternalDisplay: 1280x750"
|
| -base::string16 GetDisplayInfoLine(int64_t display_id) {
|
| - const display::ManagedDisplayInfo& display_info =
|
| - GetDisplayManager()->GetDisplayInfo(display_id);
|
| - if (GetDisplayManager()->mirroring_display_id() == display_id)
|
| - return GetDisplayName(display_id);
|
| -
|
| - base::string16 size_text = GetDisplaySize(display_id);
|
| - base::string16 display_data;
|
| - if (display_info.has_overscan()) {
|
| - display_data = l10n_util::GetStringFUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, size_text,
|
| - l10n_util::GetStringUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
|
| - } else {
|
| - display_data = size_text;
|
| - }
|
| -
|
| - return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
|
| - GetDisplayName(display_id), display_data);
|
| -}
|
| -
|
| -base::string16 GetAllDisplayInfo() {
|
| - DisplayManager* display_manager = GetDisplayManager();
|
| - std::vector<base::string16> lines;
|
| - int64_t internal_id = display::Display::kInvalidDisplayID;
|
| - // Make sure to show the internal display first.
|
| - if (!display_manager->IsInUnifiedMode() &&
|
| - display::Display::IsInternalDisplayId(
|
| - display_manager->first_display_id())) {
|
| - internal_id = display_manager->first_display_id();
|
| - lines.push_back(GetDisplayInfoLine(internal_id));
|
| - }
|
| -
|
| - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
|
| - int64_t id = display_manager->GetDisplayAt(i).id();
|
| - if (id == internal_id)
|
| - continue;
|
| - lines.push_back(GetDisplayInfoLine(id));
|
| - }
|
| -
|
| - return base::JoinString(lines, base::ASCIIToUTF16("\n"));
|
| -}
|
| -
|
| // Attempts to open the display settings, returns true if successful.
|
| bool OpenSettings() {
|
| // switch is intentionally introduced without default, to cause an error when
|
| @@ -147,188 +97,99 @@ void OpenSettingsFromNotification() {
|
| }
|
| }
|
|
|
| -} // namespace
|
| -
|
| -const char TrayDisplay::kNotificationId[] = "chrome://settings/display";
|
| -
|
| -class DisplayView : public ActionableView {
|
| - public:
|
| - explicit DisplayView() {
|
| - SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
|
| - kTrayPopupPaddingHorizontal, 0,
|
| - kTrayPopupPaddingBetweenItems));
|
| -
|
| - ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
|
| - image_ =
|
| - new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
|
| - image_->SetImage(
|
| - bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia());
|
| - AddChildView(image_);
|
| -
|
| - label_ = new views::Label();
|
| - label_->SetMultiLine(true);
|
| - label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| - AddChildView(label_);
|
| - Update();
|
| - }
|
| -
|
| - ~DisplayView() override {}
|
| +// Returns the name of the currently connected external display. This should not
|
| +// be used when the external display is used for mirroring.
|
| +base::string16 GetExternalDisplayName() {
|
| + DisplayManager* display_manager = GetDisplayManager();
|
| + DCHECK(!display_manager->IsInMirrorMode());
|
|
|
| - void Update() {
|
| - base::string16 message = GetTrayDisplayMessage(NULL);
|
| - if (message.empty() && ShouldShowFirstDisplayInfo())
|
| - message = GetDisplayInfoLine(GetDisplayManager()->first_display_id());
|
| - SetVisible(!message.empty());
|
| - label_->SetText(message);
|
| - SetAccessibleName(message);
|
| - Layout();
|
| + int64_t external_id = display::Display::kInvalidDisplayID;
|
| + for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
|
| + int64_t id = display_manager->GetDisplayAt(i).id();
|
| + if (!display::Display::IsInternalDisplayId(id)) {
|
| + external_id = id;
|
| + break;
|
| + }
|
| }
|
|
|
| - const views::Label* label() const { return label_; }
|
| -
|
| - // Overridden from views::View.
|
| - bool GetTooltipText(const gfx::Point& p,
|
| - base::string16* tooltip) const override {
|
| - base::string16 tray_message = GetTrayDisplayMessage(NULL);
|
| - base::string16 display_message = GetAllDisplayInfo();
|
| - if (tray_message.empty() && display_message.empty())
|
| - return false;
|
| + if (external_id == display::Display::kInvalidDisplayID)
|
| + return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
|
|
|
| - *tooltip = tray_message + base::ASCIIToUTF16("\n") + display_message;
|
| - return true;
|
| + // The external display name may have an annotation of "(width x height)" in
|
| + // case that the display is rotated or its resolution is changed.
|
| + base::string16 name = GetDisplayName(external_id);
|
| + const display::ManagedDisplayInfo& display_info =
|
| + display_manager->GetDisplayInfo(external_id);
|
| + if (display_info.GetActiveRotation() != display::Display::ROTATE_0 ||
|
| + display_info.configured_ui_scale() != 1.0f ||
|
| + !display_info.overscan_insets_in_dip().IsEmpty()) {
|
| + name =
|
| + l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
|
| + name, GetDisplaySize(external_id));
|
| + } else if (display_info.overscan_insets_in_dip().IsEmpty() &&
|
| + display_info.has_overscan()) {
|
| + name = l10n_util::GetStringFUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name,
|
| + l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
|
| }
|
|
|
| - // Returns the name of the currently connected external display.
|
| - // This should not be used when the external display is used for
|
| - // mirroring.
|
| - static base::string16 GetExternalDisplayName() {
|
| - DisplayManager* display_manager = GetDisplayManager();
|
| - DCHECK(!display_manager->IsInMirrorMode());
|
| -
|
| - int64_t external_id = display::Display::kInvalidDisplayID;
|
| - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
|
| - int64_t id = display_manager->GetDisplayAt(i).id();
|
| - if (!display::Display::IsInternalDisplayId(id)) {
|
| - external_id = id;
|
| - break;
|
| - }
|
| - }
|
| -
|
| - if (external_id == display::Display::kInvalidDisplayID) {
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
|
| - }
|
| + return name;
|
| +}
|
|
|
| - // The external display name may have an annotation of "(width x height)" in
|
| - // case that the display is rotated or its resolution is changed.
|
| - base::string16 name = GetDisplayName(external_id);
|
| - const display::ManagedDisplayInfo& display_info =
|
| - display_manager->GetDisplayInfo(external_id);
|
| - if (display_info.GetActiveRotation() != display::Display::ROTATE_0 ||
|
| - display_info.configured_ui_scale() != 1.0f ||
|
| - !display_info.overscan_insets_in_dip().IsEmpty()) {
|
| - name =
|
| - l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
|
| - name, GetDisplaySize(external_id));
|
| - } else if (display_info.overscan_insets_in_dip().IsEmpty() &&
|
| - display_info.has_overscan()) {
|
| - name = l10n_util::GetStringFUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name,
|
| - l10n_util::GetStringUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
|
| +base::string16 GetDisplayMessage(base::string16* additional_message_out) {
|
| + DisplayManager* display_manager = GetDisplayManager();
|
| + if (display_manager->GetNumDisplays() > 1) {
|
| + if (display::Display::HasInternalDisplay()) {
|
| + return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
|
| + GetExternalDisplayName());
|
| }
|
| -
|
| - return name;
|
| + return l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
|
| }
|
|
|
| - static base::string16 GetTrayDisplayMessage(
|
| - base::string16* additional_message_out) {
|
| - DisplayManager* display_manager = GetDisplayManager();
|
| - if (display_manager->GetNumDisplays() > 1) {
|
| - if (display::Display::HasInternalDisplay()) {
|
| - return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
|
| - GetExternalDisplayName());
|
| - }
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
|
| + if (display_manager->IsInMirrorMode()) {
|
| + if (display::Display::HasInternalDisplay()) {
|
| + return l10n_util::GetStringFUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
|
| + GetDisplayName(display_manager->mirroring_display_id()));
|
| }
|
| -
|
| - if (display_manager->IsInMirrorMode()) {
|
| - if (display::Display::HasInternalDisplay()) {
|
| - return l10n_util::GetStringFUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
|
| - GetDisplayName(display_manager->mirroring_display_id()));
|
| - }
|
| - return l10n_util::GetStringUTF16(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
|
| - }
|
| -
|
| - if (display_manager->IsInUnifiedMode())
|
| - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED);
|
| -
|
| - int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
|
| - if (display::Display::HasInternalDisplay() &&
|
| - !(display::Display::IsInternalDisplayId(primary_id))) {
|
| - if (additional_message_out) {
|
| - *additional_message_out = ash::SubstituteChromeOSDeviceType(
|
| - IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION);
|
| - }
|
| - return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
|
| - }
|
| -
|
| - return base::string16();
|
| + return l10n_util::GetStringUTF16(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
|
| }
|
|
|
| - private:
|
| - bool ShouldShowFirstDisplayInfo() const {
|
| - const int64_t first_display_id = GetDisplayManager()->first_display_id();
|
| -
|
| - const display::ManagedDisplayInfo& display_info =
|
| - GetDisplayManager()->GetDisplayInfo(first_display_id);
|
| - return (display_info.GetActiveRotation() != display::Display::ROTATE_0 &&
|
| - (display_info.active_rotation_source() !=
|
| - display::Display::ROTATION_SOURCE_ACCELEROMETER ||
|
| - !display::Display::IsInternalDisplayId(first_display_id))) ||
|
| - display_info.configured_ui_scale() != 1.0f ||
|
| - !display_info.overscan_insets_in_dip().IsEmpty() ||
|
| - display_info.has_overscan();
|
| - }
|
| + if (display_manager->IsInUnifiedMode())
|
| + return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED);
|
|
|
| - // Overridden from ActionableView.
|
| - bool PerformAction(const ui::Event& event) override {
|
| - WmShell::Get()->RecordUserMetricsAction(
|
| - UMA_STATUS_AREA_DISPLAY_DEFAULT_SELECTED);
|
| - if (OpenSettings()) {
|
| - WmShell::Get()->RecordUserMetricsAction(
|
| - UMA_STATUS_AREA_DISPLAY_DEFAULT_SHOW_SETTINGS);
|
| + int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
|
| + if (display::Display::HasInternalDisplay() &&
|
| + !(display::Display::IsInternalDisplayId(primary_id))) {
|
| + if (additional_message_out) {
|
| + *additional_message_out = ash::SubstituteChromeOSDeviceType(
|
| + IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION);
|
| }
|
| - return true;
|
| + return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
|
| }
|
|
|
| - void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
|
| - int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 -
|
| - kTrayPopupPaddingBetweenItems -
|
| - image_->GetPreferredSize().width();
|
| - label_->SizeToFit(label_max_width);
|
| - }
|
| + return base::string16();
|
| +}
|
|
|
| - views::ImageView* image_;
|
| - views::Label* label_;
|
| +} // namespace
|
|
|
| - DISALLOW_COPY_AND_ASSIGN(DisplayView);
|
| -};
|
| +const char ScreenLayoutObserver::kNotificationId[] =
|
| + "chrome://settings/display";
|
|
|
| -TrayDisplay::TrayDisplay(SystemTray* system_tray)
|
| - : SystemTrayItem(system_tray, UMA_DISPLAY), default_(nullptr) {
|
| +ScreenLayoutObserver::ScreenLayoutObserver() {
|
| WmShell::Get()->AddDisplayObserver(this);
|
| UpdateDisplayInfo(NULL);
|
| }
|
|
|
| -TrayDisplay::~TrayDisplay() {
|
| +ScreenLayoutObserver::~ScreenLayoutObserver() {
|
| WmShell::Get()->RemoveDisplayObserver(this);
|
| }
|
|
|
| -void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) {
|
| +void ScreenLayoutObserver::UpdateDisplayInfo(
|
| + ScreenLayoutObserver::DisplayInfoMap* old_info) {
|
| if (old_info)
|
| old_info->swap(display_info_);
|
| display_info_.clear();
|
| @@ -340,14 +201,14 @@ void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) {
|
| }
|
| }
|
|
|
| -bool TrayDisplay::GetDisplayMessageForNotification(
|
| - const TrayDisplay::DisplayInfoMap& old_info,
|
| +bool ScreenLayoutObserver::GetDisplayMessageForNotification(
|
| + const ScreenLayoutObserver::DisplayInfoMap& old_info,
|
| base::string16* message_out,
|
| base::string16* additional_message_out) {
|
| // Display is added or removed. Use the same message as the one in
|
| // the system tray.
|
| if (display_info_.size() != old_info.size()) {
|
| - *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out);
|
| + *message_out = GetDisplayMessage(additional_message_out);
|
| return true;
|
| }
|
|
|
| @@ -356,9 +217,9 @@ bool TrayDisplay::GetDisplayMessageForNotification(
|
| DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first);
|
| // The display's number is same but different displays. This happens
|
| // for the transition between docked mode and mirrored display. Falls back
|
| - // to GetTrayDisplayMessage().
|
| + // to GetDisplayMessage().
|
| if (old_iter == old_info.end()) {
|
| - *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out);
|
| + *message_out = GetDisplayMessage(additional_message_out);
|
| return true;
|
| }
|
|
|
| @@ -397,7 +258,7 @@ bool TrayDisplay::GetDisplayMessageForNotification(
|
| return false;
|
| }
|
|
|
| -void TrayDisplay::CreateOrUpdateNotification(
|
| +void ScreenLayoutObserver::CreateOrUpdateNotification(
|
| const base::string16& message,
|
| const base::string16& additional_message) {
|
| // Always remove the notification to make sure the notification appears
|
| @@ -434,23 +295,10 @@ void TrayDisplay::CreateOrUpdateNotification(
|
| std::move(notification));
|
| }
|
|
|
| -views::View* TrayDisplay::CreateDefaultView(LoginStatus status) {
|
| - DCHECK(default_ == NULL);
|
| - default_ = new DisplayView();
|
| - return default_;
|
| -}
|
| -
|
| -void TrayDisplay::DestroyDefaultView() {
|
| - default_ = NULL;
|
| -}
|
| -
|
| -void TrayDisplay::OnDisplayConfigurationChanged() {
|
| +void ScreenLayoutObserver::OnDisplayConfigurationChanged() {
|
| DisplayInfoMap old_info;
|
| UpdateDisplayInfo(&old_info);
|
|
|
| - if (default_)
|
| - default_->Update();
|
| -
|
| if (!WmShell::Get()
|
| ->system_tray_delegate()
|
| ->ShouldShowDisplayNotification()) {
|
| @@ -463,20 +311,4 @@ void TrayDisplay::OnDisplayConfigurationChanged() {
|
| CreateOrUpdateNotification(message, additional_message);
|
| }
|
|
|
| -base::string16 TrayDisplay::GetDefaultViewMessage() const {
|
| - if (!default_ || !default_->visible())
|
| - return base::string16();
|
| -
|
| - return static_cast<DisplayView*>(default_)->label()->text();
|
| -}
|
| -
|
| -bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) {
|
| - views::View* view = default_;
|
| - if (view) {
|
| - view->GetAccessibleState(state);
|
| - return true;
|
| - }
|
| - return false;
|
| -}
|
| -
|
| } // namespace ash
|
|
|