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

Side by Side Diff: ash/system/status_area_widget.cc

Issue 10546125: Add WebNotificationTray to the status area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Make WebNotificationTray::Bubble a Widget::Observer; address nits Created 8 years, 6 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 | Annotate | Revision Log
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/status_area_widget.h" 5 #include "ash/system/status_area_widget.h"
6 6
7 #include "ash/root_window_controller.h" 7 #include "ash/root_window_controller.h"
8 #include "ash/shell.h" 8 #include "ash/shell.h"
9 #include "ash/shell_delegate.h" 9 #include "ash/shell_delegate.h"
10 #include "ash/shell_window_ids.h" 10 #include "ash/shell_window_ids.h"
11 #include "ash/system/bluetooth/bluetooth_observer.h" 11 #include "ash/system/bluetooth/bluetooth_observer.h"
12 #include "ash/system/network/network_observer.h" 12 #include "ash/system/network/network_observer.h"
13 #include "ash/system/status_area_widget_delegate.h" 13 #include "ash/system/status_area_widget_delegate.h"
14 #include "ash/system/tray/system_tray.h" 14 #include "ash/system/tray/system_tray.h"
15 #include "ash/system/tray/system_tray_delegate.h" 15 #include "ash/system/tray/system_tray_delegate.h"
16 #include "ash/system/web_notification/web_notification_tray.h"
16 #include "base/i18n/time_formatting.h" 17 #include "base/i18n/time_formatting.h"
17 #include "base/utf_string_conversions.h" 18 #include "base/utf_string_conversions.h"
18 #include "ui/aura/window.h" 19 #include "ui/aura/window.h"
19 20
20 namespace ash { 21 namespace ash {
21 22
22 namespace { 23 namespace {
23 24
24 class DummySystemTrayDelegate : public SystemTrayDelegate { 25 class DummySystemTrayDelegate : public SystemTrayDelegate {
25 public: 26 public:
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
275 276
276 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate); 277 DISALLOW_COPY_AND_ASSIGN(DummySystemTrayDelegate);
277 }; 278 };
278 279
279 } // namespace 280 } // namespace
280 281
281 namespace internal { 282 namespace internal {
282 283
283 StatusAreaWidget::StatusAreaWidget() 284 StatusAreaWidget::StatusAreaWidget()
284 : widget_delegate_(new internal::StatusAreaWidgetDelegate), 285 : widget_delegate_(new internal::StatusAreaWidgetDelegate),
285 system_tray_(NULL) { 286 system_tray_(NULL),
287 web_notification_tray_(NULL) {
286 views::Widget::InitParams params( 288 views::Widget::InitParams params(
287 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); 289 views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
288 params.delegate = widget_delegate_; 290 params.delegate = widget_delegate_;
289 params.parent = 291 params.parent =
290 Shell::GetPrimaryRootWindowController()->GetContainer( 292 Shell::GetPrimaryRootWindowController()->GetContainer(
291 ash::internal::kShellWindowId_StatusContainer); 293 ash::internal::kShellWindowId_StatusContainer);
292 params.transparent = true; 294 params.transparent = true;
293 Init(params); 295 Init(params);
294 set_focus_on_creation(false); 296 set_focus_on_creation(false);
295 SetContentsView(widget_delegate_); 297 SetContentsView(widget_delegate_);
296 GetNativeView()->SetName("StatusAreaWidget"); 298 GetNativeView()->SetName("StatusAreaWidget");
297 } 299 }
298 300
299 StatusAreaWidget::~StatusAreaWidget() { 301 StatusAreaWidget::~StatusAreaWidget() {
300 } 302 }
301 303
302 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) { 304 void StatusAreaWidget::CreateTrayViews(ShellDelegate* shell_delegate) {
305 AddWebNotificationTray(new WebNotificationTray(this));
303 AddSystemTray(new SystemTray(), shell_delegate); 306 AddSystemTray(new SystemTray(), shell_delegate);
304 } 307 }
305 308
306 void StatusAreaWidget::Shutdown() { 309 void StatusAreaWidget::Shutdown() {
307 // Destroy the trays early, causing them to be removed from the view 310 // Destroy the trays early, causing them to be removed from the view
308 // hierarchy. Do not used scoped pointers since we don't want to destroy them 311 // hierarchy. Do not used scoped pointers since we don't want to destroy them
309 // in the destructor if Shutdown() is not called (e.g. in tests). 312 // in the destructor if Shutdown() is not called (e.g. in tests).
310 delete system_tray_; 313 delete system_tray_;
311 system_tray_ = NULL; 314 system_tray_ = NULL;
315 delete web_notification_tray_;
316 web_notification_tray_ = NULL;
312 } 317 }
313 318
314 void StatusAreaWidget::AddSystemTray(SystemTray* system_tray, 319 void StatusAreaWidget::AddSystemTray(SystemTray* system_tray,
315 ShellDelegate* shell_delegate) { 320 ShellDelegate* shell_delegate) {
316 system_tray_ = system_tray; 321 system_tray_ = system_tray;
317 widget_delegate_->AddTray(system_tray); 322 widget_delegate_->AddTray(system_tray);
318 system_tray_->Initialize(); // Called after added to widget. 323 system_tray_->Initialize(); // Called after added to widget.
319 324
320 if (shell_delegate) { 325 if (shell_delegate) {
321 system_tray_delegate_.reset( 326 system_tray_delegate_.reset(
322 shell_delegate->CreateSystemTrayDelegate(system_tray)); 327 shell_delegate->CreateSystemTrayDelegate(system_tray));
323 } 328 }
324 if (!system_tray_delegate_.get()) 329 if (!system_tray_delegate_.get())
325 system_tray_delegate_.reset(new DummySystemTrayDelegate()); 330 system_tray_delegate_.reset(new DummySystemTrayDelegate());
326 331
327 system_tray->CreateItems(); // Called after delegate is created. 332 system_tray->CreateItems(); // Called after delegate is created.
328 } 333 }
329 334
335 void StatusAreaWidget::AddWebNotificationTray(
336 WebNotificationTray* web_notification_tray) {
337 web_notification_tray_ = web_notification_tray;
338 widget_delegate_->AddTray(web_notification_tray);
339 }
340
330 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { 341 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) {
331 widget_delegate_->set_alignment(alignment); 342 widget_delegate_->set_alignment(alignment);
332 widget_delegate_->UpdateLayout(); 343 widget_delegate_->UpdateLayout();
344 if (system_tray_)
345 system_tray_->SetShelfAlignment(alignment);
346 if (web_notification_tray_)
347 web_notification_tray_->SetShelfAlignment(alignment);
348 }
349
350 void StatusAreaWidget::SetPaintsBackground(
351 bool value,
352 internal::BackgroundAnimator::ChangeType change_type) {
353 if (system_tray_)
354 system_tray_->SetPaintsBackground(value, change_type);
355 if (web_notification_tray_)
356 web_notification_tray_->SetPaintsBackground(value, change_type);
357 }
358
359 void StatusAreaWidget::ShowWebNotificationBubble(UserAction user_action) {
360 if (system_tray_ && system_tray_->IsBubbleVisible()) {
361 // User actions should always hide the system tray bubble first.
362 DCHECK(user_action != USER_ACTION);
363 // Don't immediately show the web notification bubble if the system tray
364 // bubble is visible.
365 return;
366 }
367 DCHECK(web_notification_tray_);
368 web_notification_tray_->ShowBubble();
369 // Disable showing system notifications while viewing web notifications.
370 if (system_tray_)
371 system_tray_->SetHideNotifications(true);
372 }
373
374 void StatusAreaWidget::HideWebNotificationBubble() {
375 DCHECK(web_notification_tray_);
376 web_notification_tray_->HideBubble();
377 // Show any hidden or suppressed system notifications.
378 if (system_tray_)
379 system_tray_->SetHideNotifications(false);
333 } 380 }
334 381
335 } // namespace internal 382 } // namespace internal
336 } // namespace ash 383 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698