Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/system/chromeos/tray_display.h" | 5 #include "ash/system/chromeos/tray_display.h" |
| 6 | 6 |
| 7 #include "ash/display/display_controller.h" | 7 #include "ash/display/display_controller.h" |
| 8 #include "ash/display/display_manager.h" | 8 #include "ash/display/display_manager.h" |
| 9 #include "ash/screen_ash.h" | |
| 10 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 11 #include "ash/system/tray/fixed_sized_image_view.h" | 10 #include "ash/system/tray/fixed_sized_image_view.h" |
| 12 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 13 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 14 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
| 15 #include "base/chromeos/chromeos_version.h" | 14 #include "base/chromeos/chromeos_version.h" |
| 16 #include "base/utf_string_conversions.h" | 15 #include "base/utf_string_conversions.h" |
| 17 #include "chromeos/display/output_configurator.h" | |
| 18 #include "grit/ash_resources.h" | 16 #include "grit/ash_resources.h" |
| 19 #include "grit/ash_strings.h" | 17 #include "grit/ash_strings.h" |
| 20 #include "ui/aura/env.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 22 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/base/x/x11_util.h" | |
| 24 #include "ui/gfx/image/image.h" | |
| 25 #include "ui/views/controls/image_view.h" | |
| 26 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 27 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
| 28 | 22 |
| 29 namespace ash { | 23 namespace ash { |
| 30 namespace internal { | 24 namespace internal { |
| 25 namespace { | |
| 26 | |
| 27 TrayDisplayMode GetCurrentTrayDisplayMode() { | |
| 28 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | |
| 29 if (display_manager->GetNumDisplays() > 1) | |
| 30 return TRAY_DISPLAY_EXTENDED; | |
| 31 | |
| 32 if (display_manager->IsMirrored()) | |
| 33 return TRAY_DISPLAY_MIRRORED; | |
| 34 | |
| 35 int64 first_id = display_manager->first_display_id(); | |
| 36 if (display_manager->HasInternalDisplay() && | |
| 37 !display_manager->IsInternalDisplayId(first_id)) { | |
| 38 return TRAY_DISPLAY_DOCKED; | |
| 39 } | |
| 40 | |
| 41 return TRAY_DISPLAY_SINGLE; | |
| 42 } | |
| 43 | |
| 44 } | |
|
stevenjb
2013/05/31 21:43:11
nit: // namespace
Jun Mukai
2013/05/31 21:50:17
Done.
| |
| 31 | 45 |
| 32 class DisplayView : public ash::internal::ActionableView { | 46 class DisplayView : public ash::internal::ActionableView { |
| 33 public: | 47 public: |
| 34 explicit DisplayView(user::LoginStatus login_status) | 48 explicit DisplayView(user::LoginStatus login_status) |
| 35 : login_status_(login_status) { | 49 : login_status_(login_status) { |
| 36 SetLayoutManager(new | 50 SetLayoutManager(new |
| 37 views::BoxLayout(views::BoxLayout::kHorizontal, | 51 views::BoxLayout(views::BoxLayout::kHorizontal, |
| 38 ash::kTrayPopupPaddingHorizontal, 0, | 52 ash::kTrayPopupPaddingHorizontal, 0, |
| 39 ash::kTrayPopupPaddingBetweenItems)); | 53 ash::kTrayPopupPaddingBetweenItems)); |
| 40 | 54 |
| 41 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 55 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 42 image_ = | 56 image_ = |
| 43 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); | 57 new ash::internal::FixedSizedImageView(0, ash::kTrayPopupItemHeight); |
| 44 image_->SetImage( | 58 image_->SetImage( |
| 45 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); | 59 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); |
| 46 AddChildView(image_); | 60 AddChildView(image_); |
| 47 label_ = new views::Label(); | 61 label_ = new views::Label(); |
| 48 label_->SetMultiLine(true); | 62 label_->SetMultiLine(true); |
| 49 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 63 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 50 AddChildView(label_); | 64 AddChildView(label_); |
| 51 Update(); | 65 Update(); |
| 52 } | 66 } |
| 53 | 67 |
| 54 virtual ~DisplayView() {} | 68 virtual ~DisplayView() {} |
| 55 | 69 |
| 56 void Update() { | 70 void Update() { |
| 57 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 71 switch (GetCurrentTrayDisplayMode()) { |
| 58 if (display_manager->num_connected_displays() == 1) { | 72 case TRAY_DISPLAY_SINGLE: |
| 59 // TODO(oshima|mukai): Support single display mode for overscan alignment. | 73 // TODO(oshima|mukai): Support single display mode for overscan |
| 60 SetVisible(false); | 74 // alignment. |
| 61 return; | 75 SetVisible(false); |
| 76 return; | |
| 77 case TRAY_DISPLAY_EXTENDED: | |
| 78 if (Shell::GetInstance()->display_manager()->HasInternalDisplay()) { | |
| 79 label_->SetText(l10n_util::GetStringFUTF16( | |
| 80 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName())); | |
| 81 } else { | |
| 82 label_->SetText(l10n_util::GetStringUTF16( | |
| 83 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL)); | |
| 84 } | |
| 85 break; | |
| 86 case TRAY_DISPLAY_MIRRORED: | |
| 87 if (Shell::GetInstance()->display_manager()->HasInternalDisplay()) { | |
| 88 label_->SetText(l10n_util::GetStringFUTF16( | |
| 89 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName())); | |
| 90 } else { | |
| 91 label_->SetText(l10n_util::GetStringUTF16( | |
| 92 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL)); | |
| 93 } | |
| 94 break; | |
| 95 case TRAY_DISPLAY_DOCKED: | |
| 96 label_->SetText(l10n_util::GetStringFUTF16( | |
| 97 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.
| |
| 62 } | 98 } |
| 63 SetVisible(true); | 99 SetVisible(true); |
| 64 if (display_manager->IsMirrored()) { | |
| 65 label_->SetText(l10n_util::GetStringFUTF16( | |
| 66 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, GetExternalDisplayName())); | |
| 67 } else { | |
| 68 label_->SetText(l10n_util::GetStringFUTF16( | |
| 69 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName())); | |
| 70 } | |
| 71 } | |
| 72 | |
| 73 chromeos::OutputState InferOutputState() const { | |
| 74 return Shell::GetScreen()->GetNumDisplays() == 1 ? | |
| 75 chromeos::STATE_SINGLE : chromeos::STATE_DUAL_EXTENDED; | |
| 76 } | 100 } |
| 77 | 101 |
| 78 private: | 102 private: |
| 79 // Returns the name of the currently connected external display. | 103 // Returns the name of the currently connected external display. |
| 80 base::string16 GetExternalDisplayName() const { | 104 base::string16 GetExternalDisplayName() const { |
| 81 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); | 105 DisplayManager* display_manager = Shell::GetInstance()->display_manager(); |
| 82 int64 external_id = display_manager->mirrored_display().id(); | 106 int64 external_id = display_manager->mirrored_display().id(); |
| 83 | 107 |
| 84 if (external_id == gfx::Display::kInvalidDisplayID) { | 108 if (external_id == gfx::Display::kInvalidDisplayID) { |
| 85 int64 internal_display_id = gfx::Display::InternalDisplayId(); | 109 int16 first_display_id = display_manager->first_display_id(); |
| 86 int64 first_display_id = display_manager->first_display_id(); | 110 if (!display_manager->HasInternalDisplay()) { |
| 87 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { | 111 external_id = first_display_id; |
| 88 int64 id = display_manager->GetDisplayAt(i)->id(); | 112 } else { |
| 89 if (id != internal_display_id && id != first_display_id) { | 113 int64 internal_display_id = gfx::Display::InternalDisplayId(); |
| 90 external_id = id; | 114 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { |
| 91 break; | 115 int64 id = display_manager->GetDisplayAt(i)->id(); |
| 116 if (id != internal_display_id && id != first_display_id) { | |
| 117 external_id = id; | |
| 118 break; | |
| 119 } | |
| 92 } | 120 } |
| 93 } | 121 } |
| 94 } | 122 } |
| 123 | |
| 95 if (external_id != gfx::Display::kInvalidDisplayID) | 124 if (external_id != gfx::Display::kInvalidDisplayID) |
| 96 return UTF8ToUTF16(display_manager->GetDisplayNameForId(external_id)); | 125 return UTF8ToUTF16(display_manager->GetDisplayNameForId(external_id)); |
| 97 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); | 126 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME); |
| 98 } | 127 } |
| 99 | 128 |
| 100 // Overridden from ActionableView. | 129 // Overridden from ActionableView. |
| 101 virtual bool PerformAction(const ui::Event& event) OVERRIDE { | 130 virtual bool PerformAction(const ui::Event& event) OVERRIDE { |
| 102 if (login_status_ == ash::user::LOGGED_IN_USER || | 131 if (login_status_ == ash::user::LOGGED_IN_USER || |
| 103 login_status_ == ash::user::LOGGED_IN_OWNER || | 132 login_status_ == ash::user::LOGGED_IN_OWNER || |
| 104 login_status_ == ash::user::LOGGED_IN_GUEST) { | 133 login_status_ == ash::user::LOGGED_IN_GUEST) { |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 118 user::LoginStatus login_status_; | 147 user::LoginStatus login_status_; |
| 119 views::ImageView* image_; | 148 views::ImageView* image_; |
| 120 views::Label* label_; | 149 views::Label* label_; |
| 121 | 150 |
| 122 DISALLOW_COPY_AND_ASSIGN(DisplayView); | 151 DISALLOW_COPY_AND_ASSIGN(DisplayView); |
| 123 }; | 152 }; |
| 124 | 153 |
| 125 TrayDisplay::TrayDisplay(SystemTray* system_tray) | 154 TrayDisplay::TrayDisplay(SystemTray* system_tray) |
| 126 : SystemTrayItem(system_tray), | 155 : SystemTrayItem(system_tray), |
| 127 default_(NULL) { | 156 default_(NULL) { |
| 128 Shell::GetScreen()->AddObserver(this); | 157 current_mode_ = GetCurrentTrayDisplayMode(); |
| 129 Shell::GetInstance()->output_configurator()->AddObserver(this); | 158 Shell::GetInstance()->display_controller()->AddObserver(this); |
| 130 } | 159 } |
| 131 | 160 |
| 132 TrayDisplay::~TrayDisplay() { | 161 TrayDisplay::~TrayDisplay() { |
| 133 Shell::GetScreen()->RemoveObserver(this); | 162 Shell::GetInstance()->display_controller()->RemoveObserver(this); |
| 134 Shell::GetInstance()->output_configurator()->RemoveObserver(this); | |
| 135 } | 163 } |
| 136 | 164 |
| 137 views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { | 165 views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { |
| 138 default_ = new DisplayView(status); | 166 default_ = new DisplayView(status); |
| 139 return default_; | 167 return default_; |
| 140 } | 168 } |
| 141 | 169 |
| 170 views::View* TrayDisplay::CreateDetailedView(user::LoginStatus status) { | |
| 171 return new DisplayView(status); | |
| 172 } | |
| 173 | |
| 142 void TrayDisplay::DestroyDefaultView() { | 174 void TrayDisplay::DestroyDefaultView() { |
| 143 default_ = NULL; | 175 default_ = NULL; |
| 144 } | 176 } |
| 145 | 177 |
| 146 void TrayDisplay::OnDisplayBoundsChanged(const gfx::Display& display) { | 178 void TrayDisplay::OnDisplayConfigurationChanged() { |
| 147 if (default_) | 179 TrayDisplayMode new_mode = GetCurrentTrayDisplayMode(); |
| 148 default_->Update(); | 180 if (current_mode_ != new_mode && new_mode != TRAY_DISPLAY_SINGLE) |
| 181 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | |
| 182 current_mode_ = new_mode; | |
| 149 } | 183 } |
| 150 | 184 |
| 151 void TrayDisplay::OnDisplayAdded(const gfx::Display& new_display) { | |
| 152 if (default_) | |
| 153 default_->Update(); | |
| 154 } | |
| 155 | |
| 156 void TrayDisplay::OnDisplayRemoved(const gfx::Display& old_display) { | |
| 157 if (default_) | |
| 158 default_->Update(); | |
| 159 } | |
| 160 | |
| 161 #if defined(OS_CHROMEOS) | |
| 162 void TrayDisplay::OnDisplayModeChanged() { | |
| 163 if (default_) | |
| 164 default_->Update(); | |
| 165 } | |
| 166 #endif | |
| 167 | |
| 168 } // namespace internal | 185 } // namespace internal |
| 169 } // namespace ash | 186 } // namespace ash |
| OLD | NEW |