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

Side by Side 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: merge Created 4 years, 3 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 unified diff | Download patch
OLDNEW
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/screen_layout_observer.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
11 #include "ash/common/metrics/user_metrics_action.h" 11 #include "ash/common/metrics/user_metrics_action.h"
12 #include "ash/common/system/chromeos/devicetype_utils.h" 12 #include "ash/common/system/chromeos/devicetype_utils.h"
13 #include "ash/common/system/system_notifier.h" 13 #include "ash/common/system/system_notifier.h"
14 #include "ash/common/system/tray/actionable_view.h"
15 #include "ash/common/system/tray/fixed_sized_image_view.h" 14 #include "ash/common/system/tray/fixed_sized_image_view.h"
16 #include "ash/common/system/tray/system_tray.h"
17 #include "ash/common/system/tray/system_tray_delegate.h" 15 #include "ash/common/system/tray/system_tray_delegate.h"
18 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
19 #include "ash/common/system/tray/tray_notification_view.h" 17 #include "ash/common/system/tray/tray_notification_view.h"
20 #include "ash/common/wm_shell.h" 18 #include "ash/common/wm_shell.h"
21 #include "ash/display/display_manager.h" 19 #include "ash/display/display_manager.h"
22 #include "ash/display/screen_orientation_controller_chromeos.h" 20 #include "ash/display/screen_orientation_controller_chromeos.h"
23 #include "ash/shell.h" 21 #include "ash/shell.h"
24 #include "base/bind.h" 22 #include "base/bind.h"
25 #include "base/strings/string_util.h" 23 #include "base/strings/string_util.h"
26 #include "base/strings/utf_string_conversions.h" 24 #include "base/strings/utf_string_conversions.h"
27 #include "grit/ash_resources.h" 25 #include "grit/ash_resources.h"
28 #include "grit/ash_strings.h" 26 #include "grit/ash_strings.h"
29 #include "ui/base/l10n/l10n_util.h" 27 #include "ui/base/l10n/l10n_util.h"
30 #include "ui/base/resource/resource_bundle.h" 28 #include "ui/base/resource/resource_bundle.h"
31 #include "ui/display/display.h" 29 #include "ui/display/display.h"
32 #include "ui/message_center/message_center.h" 30 #include "ui/message_center/message_center.h"
33 #include "ui/message_center/notification.h" 31 #include "ui/message_center/notification.h"
34 #include "ui/message_center/notification_delegate.h" 32 #include "ui/message_center/notification_delegate.h"
35 #include "ui/views/controls/image_view.h"
36 #include "ui/views/controls/label.h"
37 #include "ui/views/layout/box_layout.h"
38 33
39 using message_center::Notification; 34 using message_center::Notification;
40 35
41 namespace ash { 36 namespace ash {
42 namespace { 37 namespace {
43 38
44 DisplayManager* GetDisplayManager() { 39 DisplayManager* GetDisplayManager() {
45 return Shell::GetInstance()->display_manager(); 40 return Shell::GetInstance()->display_manager();
46 } 41 }
47 42
(...skipping 12 matching lines...) Expand all
60 // to empty string if this happens on release build. 55 // to empty string if this happens on release build.
61 bool mirroring = display_manager->mirroring_display_id() == display_id; 56 bool mirroring = display_manager->mirroring_display_id() == display_id;
62 DCHECK(!mirroring); 57 DCHECK(!mirroring);
63 if (mirroring) 58 if (mirroring)
64 return base::string16(); 59 return base::string16();
65 60
66 DCHECK(display->is_valid()); 61 DCHECK(display->is_valid());
67 return base::UTF8ToUTF16(display->size().ToString()); 62 return base::UTF8ToUTF16(display->size().ToString());
68 } 63 }
69 64
70 // Returns 1-line information for the specified display, like
71 // "InternalDisplay: 1280x750"
72 base::string16 GetDisplayInfoLine(int64_t display_id) {
73 const display::ManagedDisplayInfo& display_info =
74 GetDisplayManager()->GetDisplayInfo(display_id);
75 if (GetDisplayManager()->mirroring_display_id() == display_id)
76 return GetDisplayName(display_id);
77
78 base::string16 size_text = GetDisplaySize(display_id);
79 base::string16 display_data;
80 if (display_info.has_overscan()) {
81 display_data = l10n_util::GetStringFUTF16(
82 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION, size_text,
83 l10n_util::GetStringUTF16(
84 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
85 } else {
86 display_data = size_text;
87 }
88
89 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_SINGLE_DISPLAY,
90 GetDisplayName(display_id), display_data);
91 }
92
93 base::string16 GetAllDisplayInfo() {
94 DisplayManager* display_manager = GetDisplayManager();
95 std::vector<base::string16> lines;
96 int64_t internal_id = display::Display::kInvalidDisplayID;
97 // Make sure to show the internal display first.
98 if (!display_manager->IsInUnifiedMode() &&
99 display::Display::IsInternalDisplayId(
100 display_manager->first_display_id())) {
101 internal_id = display_manager->first_display_id();
102 lines.push_back(GetDisplayInfoLine(internal_id));
103 }
104
105 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
106 int64_t id = display_manager->GetDisplayAt(i).id();
107 if (id == internal_id)
108 continue;
109 lines.push_back(GetDisplayInfoLine(id));
110 }
111
112 return base::JoinString(lines, base::ASCIIToUTF16("\n"));
113 }
114
115 // Attempts to open the display settings, returns true if successful. 65 // Attempts to open the display settings, returns true if successful.
116 bool OpenSettings() { 66 bool OpenSettings() {
117 // switch is intentionally introduced without default, to cause an error when 67 // switch is intentionally introduced without default, to cause an error when
118 // a new type of login status is introduced. 68 // a new type of login status is introduced.
119 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) { 69 switch (WmShell::Get()->system_tray_delegate()->GetUserLoginStatus()) {
120 case LoginStatus::NOT_LOGGED_IN: 70 case LoginStatus::NOT_LOGGED_IN:
121 case LoginStatus::LOCKED: 71 case LoginStatus::LOCKED:
122 return false; 72 return false;
123 73
124 case LoginStatus::USER: 74 case LoginStatus::USER:
(...skipping 15 matching lines...) Expand all
140 // Callback to handle a user selecting the notification view. 90 // Callback to handle a user selecting the notification view.
141 void OpenSettingsFromNotification() { 91 void OpenSettingsFromNotification() {
142 WmShell::Get()->RecordUserMetricsAction( 92 WmShell::Get()->RecordUserMetricsAction(
143 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SELECTED); 93 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SELECTED);
144 if (OpenSettings()) { 94 if (OpenSettings()) {
145 WmShell::Get()->RecordUserMetricsAction( 95 WmShell::Get()->RecordUserMetricsAction(
146 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS); 96 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_SHOW_SETTINGS);
147 } 97 }
148 } 98 }
149 99
100 // Returns the name of the currently connected external display. This should not
101 // be used when the external display is used for mirroring.
102 base::string16 GetExternalDisplayName() {
103 DisplayManager* display_manager = GetDisplayManager();
104 DCHECK(!display_manager->IsInMirrorMode());
105
106 int64_t external_id = display::Display::kInvalidDisplayID;
107 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
108 int64_t id = display_manager->GetDisplayAt(i).id();
109 if (!display::Display::IsInternalDisplayId(id)) {
110 external_id = id;
111 break;
112 }
113 }
114
115 if (external_id == display::Display::kInvalidDisplayID)
116 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
117
118 // The external display name may have an annotation of "(width x height)" in
119 // case that the display is rotated or its resolution is changed.
120 base::string16 name = GetDisplayName(external_id);
121 const display::ManagedDisplayInfo& display_info =
122 display_manager->GetDisplayInfo(external_id);
123 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 ||
124 display_info.configured_ui_scale() != 1.0f ||
125 !display_info.overscan_insets_in_dip().IsEmpty()) {
126 name =
127 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
128 name, GetDisplaySize(external_id));
129 } else if (display_info.overscan_insets_in_dip().IsEmpty() &&
130 display_info.has_overscan()) {
131 name = l10n_util::GetStringFUTF16(
132 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name,
133 l10n_util::GetStringUTF16(
134 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
135 }
136
137 return name;
138 }
139
140 base::string16 GetDisplayMessage(base::string16* additional_message_out) {
141 DisplayManager* display_manager = GetDisplayManager();
142 if (display_manager->GetNumDisplays() > 1) {
143 if (display::Display::HasInternalDisplay()) {
144 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
145 GetExternalDisplayName());
146 }
147 return l10n_util::GetStringUTF16(
148 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
149 }
150
151 if (display_manager->IsInMirrorMode()) {
152 if (display::Display::HasInternalDisplay()) {
153 return l10n_util::GetStringFUTF16(
154 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
155 GetDisplayName(display_manager->mirroring_display_id()));
156 }
157 return l10n_util::GetStringUTF16(
158 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
159 }
160
161 if (display_manager->IsInUnifiedMode())
162 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED);
163
164 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
165 if (display::Display::HasInternalDisplay() &&
166 !(display::Display::IsInternalDisplayId(primary_id))) {
167 if (additional_message_out) {
168 *additional_message_out = ash::SubstituteChromeOSDeviceType(
169 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION);
170 }
171 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
172 }
173
174 return base::string16();
175 }
176
150 } // namespace 177 } // namespace
151 178
152 const char TrayDisplay::kNotificationId[] = "chrome://settings/display"; 179 const char ScreenLayoutObserver::kNotificationId[] =
180 "chrome://settings/display";
153 181
154 class DisplayView : public ActionableView { 182 ScreenLayoutObserver::ScreenLayoutObserver() {
155 public:
156 explicit DisplayView() {
157 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
158 kTrayPopupPaddingHorizontal, 0,
159 kTrayPopupPaddingBetweenItems));
160
161 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
162 image_ =
163 new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT));
164 image_->SetImage(
165 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DISPLAY).ToImageSkia());
166 AddChildView(image_);
167
168 label_ = new views::Label();
169 label_->SetMultiLine(true);
170 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
171 AddChildView(label_);
172 Update();
173 }
174
175 ~DisplayView() override {}
176
177 void Update() {
178 base::string16 message = GetTrayDisplayMessage(NULL);
179 if (message.empty() && ShouldShowFirstDisplayInfo())
180 message = GetDisplayInfoLine(GetDisplayManager()->first_display_id());
181 SetVisible(!message.empty());
182 label_->SetText(message);
183 SetAccessibleName(message);
184 Layout();
185 }
186
187 const views::Label* label() const { return label_; }
188
189 // Overridden from views::View.
190 bool GetTooltipText(const gfx::Point& p,
191 base::string16* tooltip) const override {
192 base::string16 tray_message = GetTrayDisplayMessage(NULL);
193 base::string16 display_message = GetAllDisplayInfo();
194 if (tray_message.empty() && display_message.empty())
195 return false;
196
197 *tooltip = tray_message + base::ASCIIToUTF16("\n") + display_message;
198 return true;
199 }
200
201 // Returns the name of the currently connected external display.
202 // This should not be used when the external display is used for
203 // mirroring.
204 static base::string16 GetExternalDisplayName() {
205 DisplayManager* display_manager = GetDisplayManager();
206 DCHECK(!display_manager->IsInMirrorMode());
207
208 int64_t external_id = display::Display::kInvalidDisplayID;
209 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
210 int64_t id = display_manager->GetDisplayAt(i).id();
211 if (!display::Display::IsInternalDisplayId(id)) {
212 external_id = id;
213 break;
214 }
215 }
216
217 if (external_id == display::Display::kInvalidDisplayID) {
218 return l10n_util::GetStringUTF16(
219 IDS_ASH_STATUS_TRAY_UNKNOWN_DISPLAY_NAME);
220 }
221
222 // The external display name may have an annotation of "(width x height)" in
223 // case that the display is rotated or its resolution is changed.
224 base::string16 name = GetDisplayName(external_id);
225 const display::ManagedDisplayInfo& display_info =
226 display_manager->GetDisplayInfo(external_id);
227 if (display_info.GetActiveRotation() != display::Display::ROTATE_0 ||
228 display_info.configured_ui_scale() != 1.0f ||
229 !display_info.overscan_insets_in_dip().IsEmpty()) {
230 name =
231 l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME,
232 name, GetDisplaySize(external_id));
233 } else if (display_info.overscan_insets_in_dip().IsEmpty() &&
234 display_info.has_overscan()) {
235 name = l10n_util::GetStringFUTF16(
236 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATED_NAME, name,
237 l10n_util::GetStringUTF16(
238 IDS_ASH_STATUS_TRAY_DISPLAY_ANNOTATION_OVERSCAN));
239 }
240
241 return name;
242 }
243
244 static base::string16 GetTrayDisplayMessage(
245 base::string16* additional_message_out) {
246 DisplayManager* display_manager = GetDisplayManager();
247 if (display_manager->GetNumDisplays() > 1) {
248 if (display::Display::HasInternalDisplay()) {
249 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED,
250 GetExternalDisplayName());
251 }
252 return l10n_util::GetStringUTF16(
253 IDS_ASH_STATUS_TRAY_DISPLAY_EXTENDED_NO_INTERNAL);
254 }
255
256 if (display_manager->IsInMirrorMode()) {
257 if (display::Display::HasInternalDisplay()) {
258 return l10n_util::GetStringFUTF16(
259 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING,
260 GetDisplayName(display_manager->mirroring_display_id()));
261 }
262 return l10n_util::GetStringUTF16(
263 IDS_ASH_STATUS_TRAY_DISPLAY_MIRRORING_NO_INTERNAL);
264 }
265
266 if (display_manager->IsInUnifiedMode())
267 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_UNIFIED);
268
269 int64_t primary_id = display::Screen::GetScreen()->GetPrimaryDisplay().id();
270 if (display::Display::HasInternalDisplay() &&
271 !(display::Display::IsInternalDisplayId(primary_id))) {
272 if (additional_message_out) {
273 *additional_message_out = ash::SubstituteChromeOSDeviceType(
274 IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED_DESCRIPTION);
275 }
276 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISPLAY_DOCKED);
277 }
278
279 return base::string16();
280 }
281
282 private:
283 bool ShouldShowFirstDisplayInfo() const {
284 const int64_t first_display_id = GetDisplayManager()->first_display_id();
285
286 const display::ManagedDisplayInfo& display_info =
287 GetDisplayManager()->GetDisplayInfo(first_display_id);
288 return (display_info.GetActiveRotation() != display::Display::ROTATE_0 &&
289 (display_info.active_rotation_source() !=
290 display::Display::ROTATION_SOURCE_ACCELEROMETER ||
291 !display::Display::IsInternalDisplayId(first_display_id))) ||
292 display_info.configured_ui_scale() != 1.0f ||
293 !display_info.overscan_insets_in_dip().IsEmpty() ||
294 display_info.has_overscan();
295 }
296
297 // Overridden from ActionableView.
298 bool PerformAction(const ui::Event& event) override {
299 WmShell::Get()->RecordUserMetricsAction(
300 UMA_STATUS_AREA_DISPLAY_DEFAULT_SELECTED);
301 if (OpenSettings()) {
302 WmShell::Get()->RecordUserMetricsAction(
303 UMA_STATUS_AREA_DISPLAY_DEFAULT_SHOW_SETTINGS);
304 }
305 return true;
306 }
307
308 void OnBoundsChanged(const gfx::Rect& previous_bounds) override {
309 int label_max_width = bounds().width() - kTrayPopupPaddingHorizontal * 2 -
310 kTrayPopupPaddingBetweenItems -
311 image_->GetPreferredSize().width();
312 label_->SizeToFit(label_max_width);
313 }
314
315 views::ImageView* image_;
316 views::Label* label_;
317
318 DISALLOW_COPY_AND_ASSIGN(DisplayView);
319 };
320
321 TrayDisplay::TrayDisplay(SystemTray* system_tray)
322 : SystemTrayItem(system_tray, UMA_DISPLAY), default_(nullptr) {
323 WmShell::Get()->AddDisplayObserver(this); 183 WmShell::Get()->AddDisplayObserver(this);
324 UpdateDisplayInfo(NULL); 184 UpdateDisplayInfo(NULL);
325 } 185 }
326 186
327 TrayDisplay::~TrayDisplay() { 187 ScreenLayoutObserver::~ScreenLayoutObserver() {
328 WmShell::Get()->RemoveDisplayObserver(this); 188 WmShell::Get()->RemoveDisplayObserver(this);
329 } 189 }
330 190
331 void TrayDisplay::UpdateDisplayInfo(TrayDisplay::DisplayInfoMap* old_info) { 191 void ScreenLayoutObserver::UpdateDisplayInfo(
192 ScreenLayoutObserver::DisplayInfoMap* old_info) {
332 if (old_info) 193 if (old_info)
333 old_info->swap(display_info_); 194 old_info->swap(display_info_);
334 display_info_.clear(); 195 display_info_.clear();
335 196
336 DisplayManager* display_manager = GetDisplayManager(); 197 DisplayManager* display_manager = GetDisplayManager();
337 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) { 198 for (size_t i = 0; i < display_manager->GetNumDisplays(); ++i) {
338 int64_t id = display_manager->GetDisplayAt(i).id(); 199 int64_t id = display_manager->GetDisplayAt(i).id();
339 display_info_[id] = display_manager->GetDisplayInfo(id); 200 display_info_[id] = display_manager->GetDisplayInfo(id);
340 } 201 }
341 } 202 }
342 203
343 bool TrayDisplay::GetDisplayMessageForNotification( 204 bool ScreenLayoutObserver::GetDisplayMessageForNotification(
344 const TrayDisplay::DisplayInfoMap& old_info, 205 const ScreenLayoutObserver::DisplayInfoMap& old_info,
345 base::string16* message_out, 206 base::string16* message_out,
346 base::string16* additional_message_out) { 207 base::string16* additional_message_out) {
347 // Display is added or removed. Use the same message as the one in 208 // Display is added or removed. Use the same message as the one in
348 // the system tray. 209 // the system tray.
349 if (display_info_.size() != old_info.size()) { 210 if (display_info_.size() != old_info.size()) {
350 *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); 211 *message_out = GetDisplayMessage(additional_message_out);
351 return true; 212 return true;
352 } 213 }
353 214
354 for (DisplayInfoMap::const_iterator iter = display_info_.begin(); 215 for (DisplayInfoMap::const_iterator iter = display_info_.begin();
355 iter != display_info_.end(); ++iter) { 216 iter != display_info_.end(); ++iter) {
356 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first); 217 DisplayInfoMap::const_iterator old_iter = old_info.find(iter->first);
357 // The display's number is same but different displays. This happens 218 // The display's number is same but different displays. This happens
358 // for the transition between docked mode and mirrored display. Falls back 219 // for the transition between docked mode and mirrored display. Falls back
359 // to GetTrayDisplayMessage(). 220 // to GetDisplayMessage().
360 if (old_iter == old_info.end()) { 221 if (old_iter == old_info.end()) {
361 *message_out = DisplayView::GetTrayDisplayMessage(additional_message_out); 222 *message_out = GetDisplayMessage(additional_message_out);
362 return true; 223 return true;
363 } 224 }
364 225
365 if (iter->second.configured_ui_scale() != 226 if (iter->second.configured_ui_scale() !=
366 old_iter->second.configured_ui_scale()) { 227 old_iter->second.configured_ui_scale()) {
367 *additional_message_out = l10n_util::GetStringFUTF16( 228 *additional_message_out = l10n_util::GetStringFUTF16(
368 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED, 229 IDS_ASH_STATUS_TRAY_DISPLAY_RESOLUTION_CHANGED,
369 GetDisplayName(iter->first), GetDisplaySize(iter->first)); 230 GetDisplayName(iter->first), GetDisplaySize(iter->first));
370 return true; 231 return true;
371 } 232 }
(...skipping 18 matching lines...) Expand all
390 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetDisplayName(iter->first), 251 IDS_ASH_STATUS_TRAY_DISPLAY_ROTATED, GetDisplayName(iter->first),
391 l10n_util::GetStringUTF16(rotation_text_id)); 252 l10n_util::GetStringUTF16(rotation_text_id));
392 return true; 253 return true;
393 } 254 }
394 } 255 }
395 256
396 // Found nothing special 257 // Found nothing special
397 return false; 258 return false;
398 } 259 }
399 260
400 void TrayDisplay::CreateOrUpdateNotification( 261 void ScreenLayoutObserver::CreateOrUpdateNotification(
401 const base::string16& message, 262 const base::string16& message,
402 const base::string16& additional_message) { 263 const base::string16& additional_message) {
403 // Always remove the notification to make sure the notification appears 264 // Always remove the notification to make sure the notification appears
404 // as a popup in any situation. 265 // as a popup in any situation.
405 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId, 266 message_center::MessageCenter::Get()->RemoveNotification(kNotificationId,
406 false /* by_user */); 267 false /* by_user */);
407 268
408 if (message.empty() && additional_message.empty()) 269 if (message.empty() && additional_message.empty())
409 return; 270 return;
410 271
(...skipping 16 matching lines...) Expand all
427 message_center::RichNotificationData(), 288 message_center::RichNotificationData(),
428 new message_center::HandleNotificationClickedDelegate( 289 new message_center::HandleNotificationClickedDelegate(
429 base::Bind(&OpenSettingsFromNotification)))); 290 base::Bind(&OpenSettingsFromNotification))));
430 291
431 WmShell::Get()->RecordUserMetricsAction( 292 WmShell::Get()->RecordUserMetricsAction(
432 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_CREATED); 293 UMA_STATUS_AREA_DISPLAY_NOTIFICATION_CREATED);
433 message_center::MessageCenter::Get()->AddNotification( 294 message_center::MessageCenter::Get()->AddNotification(
434 std::move(notification)); 295 std::move(notification));
435 } 296 }
436 297
437 views::View* TrayDisplay::CreateDefaultView(LoginStatus status) { 298 void ScreenLayoutObserver::OnDisplayConfigurationChanged() {
438 DCHECK(default_ == NULL);
439 default_ = new DisplayView();
440 return default_;
441 }
442
443 void TrayDisplay::DestroyDefaultView() {
444 default_ = NULL;
445 }
446
447 void TrayDisplay::OnDisplayConfigurationChanged() {
448 DisplayInfoMap old_info; 299 DisplayInfoMap old_info;
449 UpdateDisplayInfo(&old_info); 300 UpdateDisplayInfo(&old_info);
450 301
451 if (default_)
452 default_->Update();
453
454 if (!WmShell::Get() 302 if (!WmShell::Get()
455 ->system_tray_delegate() 303 ->system_tray_delegate()
456 ->ShouldShowDisplayNotification()) { 304 ->ShouldShowDisplayNotification()) {
457 return; 305 return;
458 } 306 }
459 307
460 base::string16 message; 308 base::string16 message;
461 base::string16 additional_message; 309 base::string16 additional_message;
462 if (GetDisplayMessageForNotification(old_info, &message, &additional_message)) 310 if (GetDisplayMessageForNotification(old_info, &message, &additional_message))
463 CreateOrUpdateNotification(message, additional_message); 311 CreateOrUpdateNotification(message, additional_message);
464 } 312 }
465 313
466 base::string16 TrayDisplay::GetDefaultViewMessage() const {
467 if (!default_ || !default_->visible())
468 return base::string16();
469
470 return static_cast<DisplayView*>(default_)->label()->text();
471 }
472
473 bool TrayDisplay::GetAccessibleStateForTesting(ui::AXViewState* state) {
474 views::View* view = default_;
475 if (view) {
476 view->GetAccessibleState(state);
477 return true;
478 }
479 return false;
480 }
481
482 } // namespace ash 314 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/screen_layout_observer.h ('k') | ash/system/chromeos/screen_layout_observer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698