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 <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 base::string16 GetDisplayInfoLine(int64_t display_id) { | 72 base::string16 GetDisplayInfoLine(int64_t display_id) { |
73 const DisplayInfo& display_info = | 73 const DisplayInfo& display_info = |
74 GetDisplayManager()->GetDisplayInfo(display_id); | 74 GetDisplayManager()->GetDisplayInfo(display_id); |
75 if (GetDisplayManager()->mirroring_display_id() == display_id) | 75 if (GetDisplayManager()->mirroring_display_id() == display_id) |
76 return GetDisplayName(display_id); | 76 return GetDisplayName(display_id); |
77 | 77 |
78 base::string16 size_text = GetDisplaySize(display_id); | 78 base::string16 size_text = GetDisplaySize(display_id); |
79 base::string16 display_data; | 79 base::string16 display_data; |
80 if (display_info.has_overscan()) { | 80 if (display_info.has_overscan()) { |
81 display_data = l10n_util::GetStringFUTF16( | 81 display_data = l10n_util::GetStringFUTF16( |
82 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, | 82 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, size_text, |
83 size_text, | |
84 l10n_util::GetStringUTF16( | 83 l10n_util::GetStringUTF16( |
85 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); | 84 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); |
86 } else { | 85 } else { |
87 display_data = size_text; | 86 display_data = size_text; |
88 } | 87 } |
89 | 88 |
90 return l10n_util::GetStringFUTF16( | 89 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, |
91 IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY, | 90 GetDisplayName(display_id), display_data); |
92 GetDisplayName(display_id), | |
93 display_data); | |
94 } | 91 } |
95 | 92 |
96 base::string16 GetAllDisplayInfo() { | 93 base::string16 GetAllDisplayInfo() { |
97 DisplayManager* display_manager = GetDisplayManager(); | 94 DisplayManager* display_manager = GetDisplayManager(); |
98 std::vector<base::string16> lines; | 95 std::vector<base::string16> lines; |
99 int64_t internal_id = display::Display::kInvalidDisplayID; | 96 int64_t internal_id = display::Display::kInvalidDisplayID; |
100 // Make sure to show the internal display first. | 97 // Make sure to show the internal display first. |
101 if (!display_manager->IsInUnifiedMode() && | 98 if (!display_manager->IsInUnifiedMode() && |
102 display::Display::IsInternalDisplayId( | 99 display::Display::IsInternalDisplayId( |
103 display_manager->first_display_id())) { | 100 display_manager->first_display_id())) { |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
135 } | 132 } |
136 } | 133 } |
137 | 134 |
138 } // namespace | 135 } // namespace |
139 | 136 |
140 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; | 137 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; |
141 | 138 |
142 class DisplayView : public ActionableView { | 139 class DisplayView : public ActionableView { |
143 public: | 140 public: |
144 explicit DisplayView() { | 141 explicit DisplayView() { |
145 SetLayoutManager(new views::BoxLayout( | 142 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
146 views::BoxLayout::kHorizontal, | 143 kTrayPopupPaddingHorizontal, 0, |
147 kTrayPopupPaddingHorizontal, 0, | 144 kTrayPopupPaddingBetweenItems)); |
148 kTrayPopupPaddingBetweenItems)); | |
149 | 145 |
150 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 146 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
151 image_ = new FixedSizedImageView(0, kTrayPopupItemHeight); | 147 image_ = new FixedSizedImageView(0, kTrayPopupItemHeight); |
152 image_->SetImage( | 148 image_->SetImage( |
153 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); | 149 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia()); |
154 AddChildView(image_); | 150 AddChildView(image_); |
155 | 151 |
156 label_ = new views::Label(); | 152 label_ = new views::Label(); |
157 label_->SetMultiLine(true); | 153 label_->SetMultiLine(true); |
158 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 154 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
208 } | 204 } |
209 | 205 |
210 // The external display name may have an annotation of "(width x height)" in | 206 // The external display name may have an annotation of "(width x height)" in |
211 // case that the display is rotated or its resolution is changed. | 207 // case that the display is rotated or its resolution is changed. |
212 base::string16 name = GetDisplayName(external_id); | 208 base::string16 name = GetDisplayName(external_id); |
213 const DisplayInfo& display_info = | 209 const DisplayInfo& display_info = |
214 display_manager->GetDisplayInfo(external_id); | 210 display_manager->GetDisplayInfo(external_id); |
215 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 || | 211 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 || |
216 display_info.configured_ui_scale() != 1.0f || | 212 display_info.configured_ui_scale() != 1.0f || |
217 !display_info.overscan_insets_in_dip().IsEmpty()) { | 213 !display_info.overscan_insets_in_dip().IsEmpty()) { |
218 name = l10n_util::GetStringFUTF16( | 214 name = |
219 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | 215 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, |
220 name, GetDisplaySize(external_id)); | 216 name, GetDisplaySize(external_id)); |
221 } else if (display_info.overscan_insets_in_dip().IsEmpty() && | 217 } else if (display_info.overscan_insets_in_dip().IsEmpty() && |
222 display_info.has_overscan()) { | 218 display_info.has_overscan()) { |
223 name = l10n_util::GetStringFUTF16( | 219 name = l10n_util::GetStringFUTF16( |
224 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, | 220 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name, |
225 name, l10n_util::GetStringUTF16( | 221 l10n_util::GetStringUTF16( |
226 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); | 222 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN)); |
227 } | 223 } |
228 | 224 |
229 return name; | 225 return name; |
230 } | 226 } |
231 | 227 |
232 static base::string16 GetTrayDisplayMessage( | 228 static base::string16 GetTrayDisplayMessage( |
233 base::string16* additional_message_out) { | 229 base::string16* additional_message_out) { |
234 DisplayManager* display_manager = GetDisplayManager(); | 230 DisplayManager* display_manager = GetDisplayManager(); |
235 if (display_manager->GetNumDisplays() > 1) { | 231 if (display_manager->GetNumDisplays() > 1) { |
236 if (display::Display::HasInternalDisplay()) { | 232 if (display::Display::HasInternalDisplay()) { |
237 return l10n_util::GetStringFUTF16( | 233 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, |
238 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED, GetExternalDisplayName()); | 234 GetExternalDisplayName()); |
239 } | 235 } |
240 return l10n_util::GetStringUTF16( | 236 return l10n_util::GetStringUTF16( |
241 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); | 237 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL); |
242 } | 238 } |
243 | 239 |
244 if (display_manager->IsInMirrorMode()) { | 240 if (display_manager->IsInMirrorMode()) { |
245 if (display::Display::HasInternalDisplay()) { | 241 if (display::Display::HasInternalDisplay()) { |
246 return l10n_util::GetStringFUTF16( | 242 return l10n_util::GetStringFUTF16( |
247 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, | 243 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING, |
248 GetDisplayName(display_manager->mirroring_display_id())); | 244 GetDisplayName(display_manager->mirroring_display_id())); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
283 } | 279 } |
284 | 280 |
285 // Overridden from ActionableView. | 281 // Overridden from ActionableView. |
286 bool PerformAction(const ui::Event& event) override { | 282 bool PerformAction(const ui::Event& event) override { |
287 OpenSettings(); | 283 OpenSettings(); |
288 return true; | 284 return true; |
289 } | 285 } |
290 | 286 |
291 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { | 287 void OnBoundsChanged(const gfx::Rect& previous_bounds) override { |
292 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - | 288 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 - |
293 kTrayPopupPaddingBetweenItems - image_->GetPreferredSize().width(); | 289 kTrayPopupPaddingBetweenItems - |
| 290 image_->GetPreferredSize().width(); |
294 label_->SizeToFit(label_max_width); | 291 label_->SizeToFit(label_max_width); |
295 } | 292 } |
296 | 293 |
297 views::ImageView* image_; | 294 views::ImageView* image_; |
298 views::Label* label_; | 295 views::Label* label_; |
299 | 296 |
300 DISALLOW_COPY_AND_ASSIGN(DisplayView); | 297 DISALLOW_COPY_AND_ASSIGN(DisplayView); |
301 }; | 298 }; |
302 | 299 |
303 TrayDisplay::TrayDisplay(SystemTray* system_tray) | 300 TrayDisplay::TrayDisplay(SystemTray* system_tray) |
304 : SystemTrayItem(system_tray), | 301 : SystemTrayItem(system_tray), default_(NULL) { |
305 default_(NULL) { | |
306 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); | 302 Shell::GetInstance()->window_tree_host_manager()->AddObserver(this); |
307 UpdateDisplayInfo(NULL); | 303 UpdateDisplayInfo(NULL); |
308 } | 304 } |
309 | 305 |
310 TrayDisplay::~TrayDisplay() { | 306 TrayDisplay::~TrayDisplay() { |
311 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); | 307 Shell::GetInstance()->window_tree_host_manager()->RemoveObserver(this); |
312 } | 308 } |
313 | 309 |
314 void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { | 310 void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { |
315 if (old_info) | 311 if (old_info) |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
378 | 374 |
379 // Found nothing special | 375 // Found nothing special |
380 return false; | 376 return false; |
381 } | 377 } |
382 | 378 |
383 void TrayDisplay::CreateOrUpdateNotification( | 379 void TrayDisplay::CreateOrUpdateNotification( |
384 const base::string16& message, | 380 const base::string16& message, |
385 const base::string16& additional_message) { | 381 const base::string16& additional_message) { |
386 // Always remove the notification to make sure the notification appears | 382 // Always remove the notification to make sure the notification appears |
387 // as a popup in any situation. | 383 // as a popup in any situation. |
388 message_center::MessageCenter::Get()->RemoveNotification( | 384 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, |
389 kNotificationId, false /* by_user */); | 385 false /* by_user */); |
390 | 386 |
391 if (message.empty() && additional_message.empty()) | 387 if (message.empty() && additional_message.empty()) |
392 return; | 388 return; |
393 | 389 |
394 // Don't display notifications for accelerometer triggered screen rotations. | 390 // Don't display notifications for accelerometer triggered screen rotations. |
395 // See http://crbug.com/364949 | 391 // See http://crbug.com/364949 |
396 if (Shell::GetInstance() | 392 if (Shell::GetInstance() |
397 ->screen_orientation_controller() | 393 ->screen_orientation_controller() |
398 ->ignore_display_configuration_updates()) { | 394 ->ignore_display_configuration_updates()) { |
399 return; | 395 return; |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
454 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { | 450 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { |
455 views::View* view = default_; | 451 views::View* view = default_; |
456 if (view) { | 452 if (view) { |
457 view->GetAccessibleState(state); | 453 view->GetAccessibleState(state); |
458 return true; | 454 return true; |
459 } | 455 } |
460 return false; | 456 return false; |
461 } | 457 } |
462 | 458 |
463 } // namespace ash | 459 } // namespace ash |
OLD | NEW |