Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1968)

Unified Diff: ash/system/chromeos/screen_layout_observer.cc

Issue 2217713002: Remove the system menu display settings row (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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 47%
rename from ash/system/chromeos/tray_display.cc
rename to ash/system/chromeos/screen_layout_observer.cc
index 0e3001d2e47bbfd0ba72523026930c2f2b4b8182..1c5fc3fd61884cc1702e826f07eaf12dba290006 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>
@@ -67,51 +67,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 DisplayInfo& 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,
James Cook 2016/08/05 17:00:24 Are these strings still used? If not, remove them
yiyix 2016/08/13 05:28:51 Done.
- l10n_util::GetStringUTF16(
- IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
James Cook 2016/08/05 17:00:24 ditto
yiyix 2016/08/13 05:28:50 This string is used for notification. When user tr
- } else {
- display_data = size_text;
- }
-
- return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
James Cook 2016/08/05 17:00:24 ditto
yiyix 2016/08/13 05:28:50 Done.
- 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
@@ -149,186 +104,96 @@ 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 {}
+base::string16 GetExternalDisplayName() {
James Cook 2016/08/05 17:00:24 Is the old function comment still relevant? If so,
yiyix 2016/08/13 05:28:50 Done.
+ 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;
-
- *tooltip = tray_message + base::ASCIIToUTF16("\n") + display_message;
- return true;
+ if (external_id == display::Display::kInvalidDisplayID) {
+ return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
}
- // 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);
- }
-
- // 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 DisplayInfo& 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));
- }
-
- 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 DisplayInfo& 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));
}
- 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);
- }
+ return name;
+}
- 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);
+base::string16 GetDisplayMessage(base::string16* additional_message_out) {
James Cook 2016/08/05 17:00:24 ditto re: anonymous namespace
yiyix 2016/08/13 05:28:51 Done.
+ 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->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);
+ 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 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 DisplayInfo& 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);
- }
-
- views::ImageView* image_;
- views::Label* label_;
+ return base::string16();
+}
- 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 +205,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 +221,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 +262,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 +299,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 +315,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

Powered by Google App Engine
This is Rietveld 408576698