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

Side by Side Diff: ash/system/web_notification/web_notification_tray.cc

Issue 2091933002: mash: Convert TrayBackgroundView to wm common types (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 4 years, 5 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/web_notification/web_notification_tray.h" 5 #include "ash/system/web_notification/web_notification_tray.h"
6 6
7 #include "ash/common/ash_switches.h" 7 #include "ash/common/ash_switches.h"
8 #include "ash/common/material_design/material_design_controller.h" 8 #include "ash/common/material_design/material_design_controller.h"
9 #include "ash/common/session/session_state_delegate.h" 9 #include "ash/common/session/session_state_delegate.h"
10 #include "ash/common/shelf/shelf_constants.h" 10 #include "ash/common/shelf/shelf_constants.h"
11 #include "ash/common/shelf/wm_shelf.h" 11 #include "ash/common/shelf/wm_shelf.h"
12 #include "ash/common/shelf/wm_shelf_util.h" 12 #include "ash/common/shelf/wm_shelf_util.h"
13 #include "ash/common/shell_window_ids.h" 13 #include "ash/common/shell_window_ids.h"
14 #include "ash/common/system/tray/system_tray_delegate.h"
15 #include "ash/common/system/tray/tray_bubble_wrapper.h"
14 #include "ash/common/system/tray/tray_constants.h" 16 #include "ash/common/system/tray/tray_constants.h"
15 #include "ash/common/system/tray/tray_utils.h" 17 #include "ash/common/system/tray/tray_utils.h"
16 #include "ash/common/wm_lookup.h" 18 #include "ash/common/wm_lookup.h"
17 #include "ash/common/wm_root_window_controller.h" 19 #include "ash/common/wm_root_window_controller.h"
18 #include "ash/common/wm_shell.h" 20 #include "ash/common/wm_shell.h"
19 #include "ash/common/wm_window.h" 21 #include "ash/common/wm_window.h"
20 #include "ash/system/status_area_widget.h" 22 #include "ash/system/status_area_widget.h"
21 #include "ash/system/tray/system_tray.h" 23 #include "ash/system/tray/system_tray.h"
22 #include "ash/system/tray/tray_background_view.h"
23 #include "ash/system/tray/tray_bubble_wrapper.h"
24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h"
25 #include "base/auto_reset.h" 25 #include "base/auto_reset.h"
26 #include "base/i18n/number_formatting.h" 26 #include "base/i18n/number_formatting.h"
27 #include "base/i18n/rtl.h" 27 #include "base/i18n/rtl.h"
28 #include "base/strings/utf_string_conversions.h" 28 #include "base/strings/utf_string_conversions.h"
29 #include "base/threading/thread_task_runner_handle.h" 29 #include "base/threading/thread_task_runner_handle.h"
30 #include "grit/ash_strings.h" 30 #include "grit/ash_strings.h"
31 #include "ui/base/l10n/l10n_util.h" 31 #include "ui/base/l10n/l10n_util.h"
32 #include "ui/display/display.h" 32 #include "ui/display/display.h"
33 #include "ui/display/screen.h" 33 #include "ui/display/screen.h"
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after
198 bool is_bubble_visible_; 198 bool is_bubble_visible_;
199 int unread_count_; 199 int unread_count_;
200 200
201 views::ImageView no_unread_icon_; 201 views::ImageView no_unread_icon_;
202 views::Label unread_label_; 202 views::Label unread_label_;
203 203
204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); 204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton);
205 }; 205 };
206 206
207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) 207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget)
208 : TrayBackgroundView(status_area_widget), 208 : TrayBackgroundView(status_area_widget->wm_shelf()),
209 status_area_widget_(status_area_widget),
209 button_(NULL), 210 button_(NULL),
210 show_message_center_on_unlock_(false), 211 show_message_center_on_unlock_(false),
211 should_update_tray_content_(false), 212 should_update_tray_content_(false),
212 should_block_shelf_auto_hide_(false) { 213 should_block_shelf_auto_hide_(false) {
214 DCHECK(status_area_widget_);
213 button_ = new WebNotificationButton(this); 215 button_ = new WebNotificationButton(this);
214 button_->set_triggerable_event_flags( 216 button_->set_triggerable_event_flags(
215 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); 217 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON);
216 tray_container()->AddChildView(button_); 218 tray_container()->AddChildView(button_);
217 SetContentsBackground(); 219 SetContentsBackground();
218 tray_container()->SetBorder(views::Border::NullBorder()); 220 tray_container()->SetBorder(views::Border::NullBorder());
219 message_center_tray_.reset(new message_center::MessageCenterTray( 221 message_center_tray_.reset(new message_center::MessageCenterTray(
220 this, 222 this,
221 message_center::MessageCenter::Get())); 223 message_center::MessageCenter::Get()));
222 WmShelf* shelf = WmLookup::Get() 224 WmShelf* shelf = WmLookup::Get()
(...skipping 26 matching lines...) Expand all
249 if (!ShouldShowMessageCenter()) 251 if (!ShouldShowMessageCenter())
250 return false; 252 return false;
251 253
252 should_block_shelf_auto_hide_ = true; 254 should_block_shelf_auto_hide_ = true;
253 message_center::MessageCenterBubble* message_center_bubble = 255 message_center::MessageCenterBubble* message_center_bubble =
254 new message_center::MessageCenterBubble( 256 new message_center::MessageCenterBubble(
255 message_center(), 257 message_center(),
256 message_center_tray_.get(), 258 message_center_tray_.get(),
257 true); 259 true);
258 260
259 WmShelf* shelf = GetShelf();
260 int max_height; 261 int max_height;
261 if (IsHorizontalAlignment(shelf->GetAlignment())) { 262 if (IsHorizontalAlignment(shelf()->GetAlignment())) {
262 max_height = shelf->GetIdealBounds().y(); 263 max_height = shelf()->GetIdealBounds().y();
263 } else { 264 } else {
264 // Assume the status area and bubble bottoms are aligned when vertical. 265 // Assume the status area and bubble bottoms are aligned when vertical.
265 WmWindow* status_area_window = 266 WmWindow* status_area_window =
266 WmLookup::Get()->GetWindowForWidget(status_area_widget()); 267 WmLookup::Get()->GetWindowForWidget(status_area_widget_);
267 gfx::Rect bounds_in_root = 268 gfx::Rect bounds_in_root =
268 status_area_window->GetRootWindow()->ConvertRectFromScreen( 269 status_area_window->GetRootWindow()->ConvertRectFromScreen(
269 status_area_window->GetBoundsInScreen()); 270 status_area_window->GetBoundsInScreen());
270 max_height = bounds_in_root.bottom(); 271 max_height = bounds_in_root.bottom();
271 } 272 }
272 message_center_bubble->SetMaxHeight( 273 message_center_bubble->SetMaxHeight(
273 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); 274 std::max(0, max_height - GetTrayConstant(TRAY_SPACING)));
274 if (show_settings) 275 if (show_settings)
275 message_center_bubble->SetSettingsVisible(); 276 message_center_bubble->SetSettingsVisible();
276 message_center_bubble_.reset( 277 message_center_bubble_.reset(
277 new WebNotificationBubbleWrapper(this, message_center_bubble)); 278 new WebNotificationBubbleWrapper(this, message_center_bubble));
278 279
279 status_area_widget()->SetHideSystemNotifications(true); 280 status_area_widget_->SetHideSystemNotifications(true);
280 shelf->UpdateAutoHideState(); 281 shelf()->UpdateAutoHideState();
281 button_->SetBubbleVisible(true); 282 button_->SetBubbleVisible(true);
282 SetDrawBackgroundAsActive(true); 283 SetDrawBackgroundAsActive(true);
283 return true; 284 return true;
284 } 285 }
285 286
286 bool WebNotificationTray::ShowMessageCenter() { 287 bool WebNotificationTray::ShowMessageCenter() {
287 return ShowMessageCenterInternal(false /* show_settings */); 288 return ShowMessageCenterInternal(false /* show_settings */);
288 } 289 }
289 290
290 void WebNotificationTray::HideMessageCenter() { 291 void WebNotificationTray::HideMessageCenter() {
291 if (!message_center_bubble()) 292 if (!message_center_bubble())
292 return; 293 return;
293 SetDrawBackgroundAsActive(false); 294 SetDrawBackgroundAsActive(false);
294 message_center_bubble_.reset(); 295 message_center_bubble_.reset();
295 should_block_shelf_auto_hide_ = false; 296 should_block_shelf_auto_hide_ = false;
296 show_message_center_on_unlock_ = false; 297 show_message_center_on_unlock_ = false;
297 status_area_widget()->SetHideSystemNotifications(false); 298 status_area_widget_->SetHideSystemNotifications(false);
298 GetShelf()->UpdateAutoHideState(); 299 shelf()->UpdateAutoHideState();
299 button_->SetBubbleVisible(false); 300 button_->SetBubbleVisible(false);
300 } 301 }
301 302
302 void WebNotificationTray::SetSystemTrayHeight(int height) { 303 void WebNotificationTray::SetSystemTrayHeight(int height) {
303 popup_alignment_delegate_->SetSystemTrayHeight(height); 304 popup_alignment_delegate_->SetSystemTrayHeight(height);
304 } 305 }
305 306
306 int WebNotificationTray::system_tray_height_for_test() const { 307 int WebNotificationTray::system_tray_height_for_test() const {
307 return popup_alignment_delegate_->system_tray_height_for_test(); 308 return popup_alignment_delegate_->system_tray_height_for_test();
308 } 309 }
309 310
310 bool WebNotificationTray::ShowPopups() { 311 bool WebNotificationTray::ShowPopups() {
311 if (message_center_bubble()) 312 if (message_center_bubble())
312 return false; 313 return false;
313 314
314 popup_collection_->DoUpdateIfPossible(); 315 popup_collection_->DoUpdateIfPossible();
315 return true; 316 return true;
316 } 317 }
317 318
318 void WebNotificationTray::HidePopups() { 319 void WebNotificationTray::HidePopups() {
319 DCHECK(popup_collection_.get()); 320 DCHECK(popup_collection_.get());
320 popup_collection_->MarkAllPopupsShown(); 321 popup_collection_->MarkAllPopupsShown();
321 } 322 }
322 323
323 // Private methods. 324 // Private methods.
324 325
325 bool WebNotificationTray::ShouldShowMessageCenter() { 326 bool WebNotificationTray::ShouldShowMessageCenter() {
326 return !(status_area_widget()->system_tray() && 327 return !(status_area_widget_->system_tray() &&
327 status_area_widget()->system_tray()->HasNotificationBubble()); 328 status_area_widget_->system_tray()->HasNotificationBubble());
328 } 329 }
329 330
330 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { 331 bool WebNotificationTray::ShouldBlockShelfAutoHide() const {
331 return should_block_shelf_auto_hide_; 332 return should_block_shelf_auto_hide_;
332 } 333 }
333 334
334 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { 335 bool WebNotificationTray::IsMessageCenterBubbleVisible() const {
335 return (message_center_bubble() && 336 return (message_center_bubble() &&
336 message_center_bubble()->bubble()->IsVisible()); 337 message_center_bubble()->bubble()->IsVisible());
337 } 338 }
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
512 return; 513 return;
513 514
514 message_center_tray_->HideMessageCenterBubble(); 515 message_center_tray_->HideMessageCenterBubble();
515 } 516 }
516 517
517 message_center::MessageCenter* WebNotificationTray::message_center() const { 518 message_center::MessageCenter* WebNotificationTray::message_center() const {
518 return message_center_tray_->message_center(); 519 return message_center_tray_->message_center();
519 } 520 }
520 521
521 bool WebNotificationTray::IsLoggedIn() const { 522 bool WebNotificationTray::IsLoggedIn() const {
522 return status_area_widget()->login_status() != LoginStatus::NOT_LOGGED_IN && 523 WmShell* shell = WmShell::Get();
523 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); 524 // TODO(jamescook): Should this also check LoginState::LOCKED?
525 return shell->system_tray_delegate()->GetUserLoginStatus() !=
526 LoginStatus::NOT_LOGGED_IN &&
527 !shell->GetSessionStateDelegate()->IsInSecondaryLoginScreen();
524 } 528 }
525 529
526 // Methods for testing 530 // Methods for testing
527 531
528 bool WebNotificationTray::IsPopupVisible() const { 532 bool WebNotificationTray::IsPopupVisible() const {
529 return message_center_tray_->popups_visible(); 533 return message_center_tray_->popups_visible();
530 } 534 }
531 535
532 message_center::MessageCenterBubble* 536 message_center::MessageCenterBubble*
533 WebNotificationTray::GetMessageCenterBubbleForTest() { 537 WebNotificationTray::GetMessageCenterBubbleForTest() {
534 if (!message_center_bubble()) 538 if (!message_center_bubble())
535 return NULL; 539 return NULL;
536 return static_cast<message_center::MessageCenterBubble*>( 540 return static_cast<message_center::MessageCenterBubble*>(
537 message_center_bubble()->bubble()); 541 message_center_bubble()->bubble());
538 } 542 }
539 543
540 } // namespace ash 544 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_tray.h ('k') | chrome/browser/chromeos/ui/focus_ring_controller.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698