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/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/system/system_notifier.h" | 10 #include "ash/system/system_notifier.h" |
11 #include "ash/system/tray/actionable_view.h" | 11 #include "ash/system/tray/actionable_view.h" |
12 #include "ash/system/tray/fixed_sized_image_view.h" | 12 #include "ash/system/tray/fixed_sized_image_view.h" |
13 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
14 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
15 #include "ash/system/tray/tray_constants.h" | 15 #include "ash/system/tray/tray_constants.h" |
16 #include "ash/system/tray/tray_notification_view.h" | 16 #include "ash/system/tray/tray_notification_view.h" |
17 #include "ash/wm/maximize_mode/maximize_mode_controller.h" | |
17 #include "base/bind.h" | 18 #include "base/bind.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "base/strings/utf_string_conversions.h" | 20 #include "base/strings/utf_string_conversions.h" |
20 #include "grit/ash_resources.h" | 21 #include "grit/ash_resources.h" |
21 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
22 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
23 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
24 #include "ui/message_center/message_center.h" | 25 #include "ui/message_center/message_center.h" |
25 #include "ui/message_center/notification.h" | 26 #include "ui/message_center/notification.h" |
26 #include "ui/message_center/notification_delegate.h" | 27 #include "ui/message_center/notification_delegate.h" |
(...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
118 case user::LOGGED_IN_OWNER: | 119 case user::LOGGED_IN_OWNER: |
119 case user::LOGGED_IN_GUEST: | 120 case user::LOGGED_IN_GUEST: |
120 case user::LOGGED_IN_RETAIL_MODE: | 121 case user::LOGGED_IN_RETAIL_MODE: |
121 case user::LOGGED_IN_PUBLIC: | 122 case user::LOGGED_IN_PUBLIC: |
122 case user::LOGGED_IN_LOCALLY_MANAGED: | 123 case user::LOGGED_IN_LOCALLY_MANAGED: |
123 case user::LOGGED_IN_KIOSK_APP: | 124 case user::LOGGED_IN_KIOSK_APP: |
124 Shell::GetInstance()->system_tray_delegate()->ShowDisplaySettings(); | 125 Shell::GetInstance()->system_tray_delegate()->ShowDisplaySettings(); |
125 } | 126 } |
126 } | 127 } |
127 | 128 |
129 // A message centre notification blocker used to suppress display notifications. | |
130 // NOTE: This class should NOT be inherited because the destructor causes | |
131 // observers to call back in to the instance being destroyed. | |
132 class ScopedNotificationBlocker | |
133 : public message_center::NotificationBlocker { | |
134 public: | |
135 ScopedNotificationBlocker(); | |
136 virtual ~ScopedNotificationBlocker(); | |
137 | |
138 // Overrides from message_center::NotificationBlocker: | |
jonross
2014/05/14 01:00:39
nit: use the newer style
// message_center::Notif
bruthig
2014/05/14 18:48:49
Done.
| |
139 virtual bool ShouldShowNotificationAsPopup( | |
140 const message_center::NotifierId& notifier_id) const OVERRIDE; | |
141 virtual bool ShouldShowNotification( | |
142 const message_center::NotifierId& notifier_id) const OVERRIDE; | |
143 | |
144 private: | |
145 // When true notifications should be shown | |
146 bool should_show_notifications_; | |
147 | |
148 DISALLOW_COPY_AND_ASSIGN(ScopedNotificationBlocker); | |
149 }; | |
150 | |
151 ScopedNotificationBlocker::ScopedNotificationBlocker() | |
152 : message_center::NotificationBlocker( | |
153 message_center::MessageCenter::Get()), | |
154 should_show_notifications_(false) { | |
155 NotifyBlockingStateChanged(); | |
156 } | |
157 | |
158 ScopedNotificationBlocker::~ScopedNotificationBlocker() { | |
159 should_show_notifications_ = true; | |
160 NotifyBlockingStateChanged(); | |
jonross
2014/05/14 01:00:39
Does this trigger calls to the subsequent methods?
bruthig
2014/05/14 18:48:49
Yes it does. NotifyBlockingStateChanged will caus
| |
161 } | |
162 | |
163 bool ScopedNotificationBlocker::ShouldShowNotificationAsPopup( | |
164 const message_center::NotifierId& notifier_id) const { | |
165 if (notifier_id.id == system_notifier::kNotifierDisplay) | |
166 return should_show_notifications_; | |
167 return true; | |
168 } | |
169 | |
170 bool ScopedNotificationBlocker::ShouldShowNotification( | |
171 const message_center::NotifierId& notifier_id) const { | |
172 if (notifier_id.id == system_notifier::kNotifierDisplay) | |
173 return should_show_notifications_; | |
174 return message_center::NotificationBlocker::ShouldShowNotification( | |
175 notifier_id); | |
176 } | |
177 | |
128 } // namespace | 178 } // namespace |
129 | 179 |
130 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; | 180 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; |
131 | 181 |
132 class DisplayView : public ActionableView { | 182 class DisplayView : public ActionableView { |
133 public: | 183 public: |
134 explicit DisplayView() { | 184 explicit DisplayView() { |
135 SetLayoutManager(new views::BoxLayout( | 185 SetLayoutManager(new views::BoxLayout( |
136 views::BoxLayout::kHorizontal, | 186 views::BoxLayout::kHorizontal, |
137 kTrayPopupPaddingHorizontal, 0, | 187 kTrayPopupPaddingHorizontal, 0, |
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
381 message, | 431 message, |
382 additional_message, | 432 additional_message, |
383 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), | 433 bundle.GetImageNamed(IDR_AURA_NOTIFICATION_DISPLAY), |
384 base::string16(), // display_source | 434 base::string16(), // display_source |
385 message_center::NotifierId( | 435 message_center::NotifierId( |
386 message_center::NotifierId::SYSTEM_COMPONENT, | 436 message_center::NotifierId::SYSTEM_COMPONENT, |
387 system_notifier::kNotifierDisplay), | 437 system_notifier::kNotifierDisplay), |
388 message_center::RichNotificationData(), | 438 message_center::RichNotificationData(), |
389 new message_center::HandleNotificationClickedDelegate( | 439 new message_center::HandleNotificationClickedDelegate( |
390 base::Bind(&OpenSettings)))); | 440 base::Bind(&OpenSettings)))); |
391 message_center::MessageCenter::Get()->AddNotification(notification.Pass()); | 441 |
442 message_center::MessageCenter* message_center = | |
443 message_center::MessageCenter::Get(); | |
444 ash::MaximizeModeController* maximize_mode_controller = | |
jonross
2014/05/14 01:00:39
nit: This is in the namespace of ash, don't need t
bruthig
2014/05/14 18:48:49
Done.
| |
445 ash::Shell::GetInstance()->maximize_mode_controller(); | |
446 // Check to see if the display notification popups should be blocked. This | |
447 // is used for things like suppressing redundant notifications for screen | |
448 // rotations caused by accelerometer events. | |
449 if (maximize_mode_controller && | |
450 !maximize_mode_controller->show_display_notifications()) { | |
451 ScopedNotificationBlocker notification_blocker; | |
452 message_center->AddNotification(notification.Pass()); | |
453 message_center->MarkSinglePopupAsShown(kNotificationId, false); | |
jonross
2014/05/14 01:00:39
nit: comment on the meaning of false. In general f
flackr
2014/05/14 01:48:33
Not sure that we prefer enums for this on or off o
bruthig
2014/05/14 18:48:49
Done.
| |
454 } else { | |
455 message_center->AddNotification(notification.Pass()); | |
456 } | |
392 } | 457 } |
393 | 458 |
394 views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { | 459 views::View* TrayDisplay::CreateDefaultView(user::LoginStatus status) { |
395 DCHECK(default_ == NULL); | 460 DCHECK(default_ == NULL); |
396 default_ = new DisplayView(); | 461 default_ = new DisplayView(); |
397 return default_; | 462 return default_; |
398 } | 463 } |
399 | 464 |
400 void TrayDisplay::DestroyDefaultView() { | 465 void TrayDisplay::DestroyDefaultView() { |
401 default_ = NULL; | 466 default_ = NULL; |
(...skipping 27 matching lines...) Expand all Loading... | |
429 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { | 494 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) { |
430 views::View* view = default_; | 495 views::View* view = default_; |
431 if (view) { | 496 if (view) { |
432 view->GetAccessibleState(state); | 497 view->GetAccessibleState(state); |
433 return true; | 498 return true; |
434 } | 499 } |
435 return false; | 500 return false; |
436 } | 501 } |
437 | 502 |
438 } // namespace ash | 503 } // namespace ash |
OLD | NEW |