Chromium Code Reviews| Index: ash/system/chromeos/tray_display.cc |
| diff --git a/ash/system/chromeos/tray_display.cc b/ash/system/chromeos/tray_display.cc |
| index 84f53692df06a6b9727ffffcd058a4fb1d313f13..c1b819f71cb9147e12133a144221af3d41505310 100644 |
| --- a/ash/system/chromeos/tray_display.cc |
| +++ b/ash/system/chromeos/tray_display.cc |
| @@ -6,7 +6,6 @@ |
| #include "ash/display/display_controller.h" |
| #include "ash/display/display_manager.h" |
| -#include "ash/screen_ash.h" |
| #include "ash/shell.h" |
| #include "ash/system/tray/fixed_sized_image_view.h" |
| #include "ash/system/tray/system_tray.h" |
| @@ -14,20 +13,35 @@ |
| #include "ash/system/tray/tray_constants.h" |
| #include "base/chromeos/chromeos_version.h" |
| #include "base/utf_string_conversions.h" |
| -#include "chromeos/display/output_configurator.h" |
| #include "grit/ash_resources.h" |
| #include "grit/ash_strings.h" |
| -#include "ui/aura/env.h" |
| #include "ui/base/l10n/l10n_util.h" |
| #include "ui/base/resource/resource_bundle.h" |
| -#include "ui/base/x/x11_util.h" |
| -#include "ui/gfx/image/image.h" |
| -#include "ui/views/controls/image_view.h" |
| #include "ui/views/controls/label.h" |
| #include "ui/views/layout/box_layout.h" |
| namespace ash { |
| namespace internal { |
| +namespace { |
| + |
| +TrayDisplayMode GetCurrentTrayDisplayMode() { |
| + DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| + if (display_manager->GetNumDisplays() > 1) |
| + return TRAY_DISPLAY_EXTENDED; |
| + |
| + if (display_manager->IsMirrored()) |
| + return TRAY_DISPLAY_MIRRORED; |
| + |
| + int64 first_id = display_manager->first_display_id(); |
| + if (display_manager->HasInternalDisplay() && |
| + !display_manager->IsInternalDisplayId(first_id)) { |
| + return TRAY_DISPLAY_DOCKED; |
| + } |
| + |
| + return TRAY_DISPLAY_SINGLE; |
| +} |
| + |
| +} |
|
stevenjb
2013/05/31 21:43:11
nit: // namespace
Jun Mukai
2013/05/31 21:50:17
Done.
|
| class DisplayView : public ash::internal::ActionableView { |
| public: |
| @@ -54,25 +68,35 @@ class DisplayView : public ash::internal::ActionableView { |
| virtual ~DisplayView() {} |
| void Update() { |
| - DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| - if (display_manager->num_connected_displays() == 1) { |
| - // TODO(oshima|mukai): Support single display mode for overscan alignment. |
| - SetVisible(false); |
| - return; |
| + switch (GetCurrentTrayDisplayMode()) { |
| + case TRAY_DISPLAY_SINGLE: |
| + // TODO(oshima|mukai): Support single display mode for overscan |
| + // alignment. |
| + SetVisible(false); |
| + return; |
| + case TRAY_DISPLAY_EXTENDED: |
| + if (Shell::GetInstance()->display_manager()->HasInternalDisplay()) { |
| + label_->SetText(l10n_util::GetStringFUTF16( |
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName())); |
| + } else { |
| + label_->SetText(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL)); |
| + } |
| + break; |
| + case TRAY_DISPLAY_MIRRORED: |
| + if (Shell::GetInstance()->display_manager()->HasInternalDisplay()) { |
| + label_->SetText(l10n_util::GetStringFUTF16( |
| + IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName())); |
| + } else { |
| + label_->SetText(l10n_util::GetStringUTF16( |
| + IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL)); |
| + } |
| + break; |
| + case TRAY_DISPLAY_DOCKED: |
| + label_->SetText(l10n_util::GetStringFUTF16( |
| + IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED, GetExternalDisplayName())); |
|
stevenjb
2013/05/31 21:43:11
nit: break; (for consistency)
Jun Mukai
2013/05/31 21:50:17
Done.
|
| } |
| SetVisible(true); |
| - if (display_manager->IsMirrored()) { |
| - label_->SetText(l10n_util::GetStringFUTF16( |
| - IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName())); |
| - } else { |
| - label_->SetText(l10n_util::GetStringFUTF16( |
| - IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName())); |
| - } |
| - } |
| - |
| - chromeos::OutputState InferOutputState() const { |
| - return Shell::GetScreen()->GetNumDisplays() == 1 ? |
| - chromeos::STATE_SINGLE : chromeos::STATE_DUAL_EXTENDED; |
| } |
| private: |
| @@ -82,16 +106,21 @@ class DisplayView : public ash::internal::ActionableView { |
| int64 external_id = display_manager->mirrored_display().id(); |
| if (external_id == gfx::Display::kInvalidDisplayID) { |
| - int64 internal_display_id = gfx::Display::InternalDisplayId(); |
| - int64 first_display_id = display_manager->first_display_id(); |
| - for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| - int64 id = display_manager->GetDisplayAt(i)->id(); |
| - if (id != internal_display_id && id != first_display_id) { |
| - external_id = id; |
| - break; |
| + int16 first_display_id = display_manager->first_display_id(); |
| + if (!display_manager->HasInternalDisplay()) { |
| + external_id = first_display_id; |
| + } else { |
| + int64 internal_display_id = gfx::Display::InternalDisplayId(); |
| + for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| + int64 id = display_manager->GetDisplayAt(i)->id(); |
| + if (id != internal_display_id && id != first_display_id) { |
| + external_id = id; |
| + break; |
| + } |
| } |
| } |
| } |
| + |
| if (external_id != gfx::Display::kInvalidDisplayID) |
| return UTF8ToUTF16(display_manager->GetDisplayNameForId(external_id)); |
| return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| @@ -125,13 +154,12 @@ class DisplayView : public ash::internal::ActionableView { |
| TrayDisplay::TrayDisplay(SystemTray* system_tray) |
| : SystemTrayItem(system_tray), |
| default_(NULL) { |
| - Shell::GetScreen()->AddObserver(this); |
| - Shell::GetInstance()->output_configurator()->AddObserver(this); |
| + current_mode_ = GetCurrentTrayDisplayMode(); |
| + Shell::GetInstance()->display_controller()->AddObserver(this); |
| } |
| TrayDisplay::~TrayDisplay() { |
| - Shell::GetScreen()->RemoveObserver(this); |
| - Shell::GetInstance()->output_configurator()->RemoveObserver(this); |
| + Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| } |
| views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { |
| @@ -139,31 +167,20 @@ views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { |
| return default_; |
| } |
| -void TrayDisplay::DestroyDefaultView() { |
| - default_ = NULL; |
| +views::View* TrayDisplay::CreateDetailedView(user::LoginStatus status) { |
| + return new DisplayView(status); |
| } |
| -void TrayDisplay::OnDisplayBoundsChanged(const gfx::Display& display) { |
| - if (default_) |
| - default_->Update(); |
| -} |
| - |
| -void TrayDisplay::OnDisplayAdded(const gfx::Display& new_display) { |
| - if (default_) |
| - default_->Update(); |
| -} |
| - |
| -void TrayDisplay::OnDisplayRemoved(const gfx::Display& old_display) { |
| - if (default_) |
| - default_->Update(); |
| +void TrayDisplay::DestroyDefaultView() { |
| + default_ = NULL; |
| } |
| -#if defined(OS_CHROMEOS) |
| -void TrayDisplay::OnDisplayModeChanged() { |
| - if (default_) |
| - default_->Update(); |
| +void TrayDisplay::OnDisplayConfigurationChanged() { |
| + TrayDisplayMode new_mode = GetCurrentTrayDisplayMode(); |
| + if (current_mode_ != new_mode && new_mode != TRAY_DISPLAY_SINGLE) |
| + PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| + current_mode_ = new_mode; |
| } |
| -#endif |
| } // namespace internal |
| } // namespace ash |