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/web_notification/web_notification_tray.h" | 5 #include "ash/system/web_notification/web_notification_tray.h" |
6 | 6 |
7 #include "ash/system/status_area_widget.h" | 7 #include "ash/system/status_area_widget.h" |
8 #include "ash/system/tray/tray_bubble_view.h" | 8 #include "ash/system/tray/tray_bubble_view.h" |
9 #include "ash/system/tray/tray_constants.h" | 9 #include "ash/system/tray/tray_constants.h" |
10 #include "ash/system/tray/tray_views.h" | 10 #include "ash/system/tray/tray_views.h" |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 !notification.display_source.empty()) { | 335 !notification.display_source.empty()) { |
336 menu_button_ = new views::MenuButton(NULL, string16(), this, true); | 336 menu_button_ = new views::MenuButton(NULL, string16(), this, true); |
337 menu_button_->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 2)); | 337 menu_button_->set_border(views::Border::CreateEmptyBorder(0, 0, 0, 2)); |
338 } | 338 } |
339 | 339 |
340 views::GridLayout* layout = new views::GridLayout(this); | 340 views::GridLayout* layout = new views::GridLayout(this); |
341 SetLayoutManager(layout); | 341 SetLayoutManager(layout); |
342 | 342 |
343 views::ColumnSet* columns = layout->AddColumnSet(0); | 343 views::ColumnSet* columns = layout->AddColumnSet(0); |
344 | 344 |
345 int padding_width = kTrayPopupPaddingHorizontal/2; | 345 const int padding_width = kTrayPopupPaddingHorizontal/2; |
346 columns->AddPaddingColumn(0, padding_width); | 346 columns->AddPaddingColumn(0, padding_width); |
347 | 347 |
348 // Notification Icon. | 348 // Notification Icon. |
349 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | 349 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, |
350 0, /* resize percent */ | 350 0, /* resize percent */ |
351 views::GridLayout::FIXED, | 351 views::GridLayout::FIXED, |
352 kWebNotificationIconSize, kWebNotificationIconSize); | 352 kWebNotificationIconSize, kWebNotificationIconSize); |
353 | 353 |
354 columns->AddPaddingColumn(0, padding_width); | 354 columns->AddPaddingColumn(0, padding_width); |
355 | 355 |
356 // Notification message text. | 356 // Notification message text. |
357 int message_width = kWebNotificationWidth - kWebNotificationIconSize - | 357 const int message_width = kWebNotificationWidth - kWebNotificationIconSize - |
358 kWebNotificationButtonWidth - (padding_width * 3); | 358 kWebNotificationButtonWidth - (padding_width * 3); |
359 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, | 359 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::LEADING, |
360 100, /* resize percent */ | 360 100, /* resize percent */ |
361 views::GridLayout::FIXED, message_width, message_width); | 361 views::GridLayout::FIXED, message_width, message_width); |
362 | 362 |
363 columns->AddPaddingColumn(0, padding_width); | 363 columns->AddPaddingColumn(0, padding_width); |
364 | 364 |
365 // Close and menu buttons. | 365 // Close and menu buttons. |
366 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | 366 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, |
367 0, /* resize percent */ | 367 0, /* resize percent */ |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
478 | 478 |
479 private: | 479 private: |
480 WebNotificationTray* tray_; | 480 WebNotificationTray* tray_; |
481 TrayPopupTextButton* close_all_button_; | 481 TrayPopupTextButton* close_all_button_; |
482 | 482 |
483 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); | 483 DISALLOW_COPY_AND_ASSIGN(WebNotificationButtonView); |
484 }; | 484 }; |
485 | 485 |
486 } // namespace internal | 486 } // namespace internal |
487 | 487 |
| 488 using internal::TrayBubbleView; |
488 using internal::WebNotificationList; | 489 using internal::WebNotificationList; |
489 using internal::WebNotificationView; | 490 using internal::WebNotificationView; |
490 | 491 |
491 class WebNotificationTray::BubbleContentsView : public views::View { | 492 class WebNotificationTray::BubbleContentsView : public views::View { |
492 public: | 493 public: |
493 explicit BubbleContentsView(WebNotificationTray* tray) | 494 explicit BubbleContentsView(WebNotificationTray* tray) |
494 : tray_(tray) { | 495 : tray_(tray) { |
495 set_border(views::Border::CreateSolidSidedBorder( | 496 set_border(views::Border::CreateSolidSidedBorder( |
496 1, 1, 1, 1, ash::kBorderDarkColor)); | 497 1, 1, 1, 1, ash::kBorderDarkColor)); |
497 | 498 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
539 } | 540 } |
540 | 541 |
541 WebNotificationTray* tray_; | 542 WebNotificationTray* tray_; |
542 internal::FixedSizedScrollView* scroller_; | 543 internal::FixedSizedScrollView* scroller_; |
543 views::View* scroll_content_; | 544 views::View* scroll_content_; |
544 internal::WebNotificationButtonView* button_view_; | 545 internal::WebNotificationButtonView* button_view_; |
545 | 546 |
546 DISALLOW_COPY_AND_ASSIGN(BubbleContentsView); | 547 DISALLOW_COPY_AND_ASSIGN(BubbleContentsView); |
547 }; | 548 }; |
548 | 549 |
549 class WebNotificationTray::Bubble : public internal::TrayBubbleView::Host, | 550 class WebNotificationTray::Bubble : public TrayBubbleView::Host, |
550 public views::Widget::Observer { | 551 public views::Widget::Observer { |
551 public: | 552 public: |
552 explicit Bubble(WebNotificationTray* tray) | 553 explicit Bubble(WebNotificationTray* tray) |
553 : tray_(tray), | 554 : tray_(tray), |
554 bubble_view_(NULL), | 555 bubble_view_(NULL), |
555 bubble_widget_(NULL), | 556 bubble_widget_(NULL), |
556 contents_view_(NULL), | 557 contents_view_(NULL), |
557 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { | 558 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { |
558 views::View* anchor = tray->tray_container(); | 559 views::View* anchor = tray->tray_container(); |
559 views::BubbleBorder::ArrowLocation arrow_location; | 560 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, |
560 int arrow_offset = 0; | 561 tray->shelf_alignment()); |
| 562 init_params.bubble_width = kWebNotificationWidth; |
| 563 init_params.max_height = kWebNotificationBubbleMaxHeight; |
561 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 564 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
562 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; | 565 gfx::Point bounds(anchor->width() / 2, 0); |
563 arrow_offset = anchor->GetContentsBounds().width() / 2; | 566 ConvertPointToWidget(anchor, &bounds); |
564 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 567 init_params.arrow_offset = bounds.x(); |
565 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | |
566 } else { | |
567 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | |
568 } | 568 } |
569 bubble_view_ = new internal::TrayBubbleView( | 569 bubble_view_ = TrayBubbleView::Create(anchor, this, init_params); |
570 anchor, arrow_location, this, false, kWebNotificationWidth); | |
571 bubble_view_->SetMaxHeight(kWebNotificationBubbleMaxHeight); | |
572 | |
573 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | |
574 | |
575 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | |
576 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | |
577 bubble_view_->SetBubbleBorder(arrow_offset); | |
578 | |
579 bubble_widget_->AddObserver(this); | |
580 | 570 |
581 contents_view_ = new BubbleContentsView(tray); | 571 contents_view_ = new BubbleContentsView(tray); |
582 bubble_view_->AddChildView(contents_view_); | 572 bubble_view_->AddChildView(contents_view_); |
583 | 573 |
584 InitializeHost(bubble_widget_, tray_); | 574 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
| 575 bubble_widget_->AddObserver(this); |
| 576 |
| 577 InitializeAndShowBubble(bubble_widget_, bubble_view_, tray_); |
585 | 578 |
586 ScheduleUpdate(); | 579 ScheduleUpdate(); |
587 } | 580 } |
588 | 581 |
589 virtual ~Bubble() { | 582 virtual ~Bubble() { |
590 if (bubble_view_) | 583 if (bubble_view_) |
591 bubble_view_->reset_host(); | 584 bubble_view_->reset_host(); |
592 if (bubble_widget_) { | 585 if (bubble_widget_) { |
593 bubble_widget_->RemoveObserver(this); | 586 bubble_widget_->RemoveObserver(this); |
594 bubble_widget_->Close(); | 587 bubble_widget_->Close(); |
(...skipping 10 matching lines...) Expand all Loading... |
605 } | 598 } |
606 | 599 |
607 views::Widget* bubble_widget() const { return bubble_widget_; } | 600 views::Widget* bubble_widget() const { return bubble_widget_; } |
608 | 601 |
609 // Overridden from TrayBubbleView::Host. | 602 // Overridden from TrayBubbleView::Host. |
610 virtual void BubbleViewDestroyed() OVERRIDE { | 603 virtual void BubbleViewDestroyed() OVERRIDE { |
611 bubble_view_ = NULL; | 604 bubble_view_ = NULL; |
612 contents_view_ = NULL; | 605 contents_view_ = NULL; |
613 } | 606 } |
614 | 607 |
615 virtual gfx::Rect GetAnchorRect() const OVERRIDE { | |
616 gfx::Rect anchor_rect = tray_->tray_container()->GetBoundsInScreen(); | |
617 return anchor_rect; | |
618 } | |
619 | |
620 virtual void OnMouseEnteredView() OVERRIDE { | 608 virtual void OnMouseEnteredView() OVERRIDE { |
621 } | 609 } |
622 | 610 |
623 virtual void OnMouseExitedView() OVERRIDE { | 611 virtual void OnMouseExitedView() OVERRIDE { |
624 } | 612 } |
625 | 613 |
626 virtual void OnClickedOutsideView() OVERRIDE { | 614 virtual void OnClickedOutsideView() OVERRIDE { |
627 // May delete |this|. | 615 // May delete |this|. |
628 tray_->status_area_widget()->HideWebNotificationBubble(); | 616 tray_->status_area_widget()->HideWebNotificationBubble(); |
629 } | 617 } |
630 | 618 |
631 // Overridden from views::Widget::Observer. | 619 // Overridden from views::Widget::Observer. |
632 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { | 620 virtual void OnWidgetClosing(views::Widget* widget) OVERRIDE { |
633 CHECK_EQ(bubble_widget_, widget); | 621 CHECK_EQ(bubble_widget_, widget); |
634 bubble_widget_ = NULL; | 622 bubble_widget_ = NULL; |
635 tray_->HideBubble(); // Will destroy |this|. | 623 tray_->HideBubble(); // Will destroy |this|. |
636 } | 624 } |
637 | 625 |
638 private: | 626 private: |
639 void UpdateBubbleView() { | 627 void UpdateBubbleView() { |
640 contents_view_->Update(tray_->notification_list()->notifications()); | 628 contents_view_->Update(tray_->notification_list()->notifications()); |
641 bubble_view_->Show(); | 629 bubble_view_->Show(); |
642 bubble_view_->UpdateBubble(); | 630 bubble_view_->UpdateBubble(); |
643 } | 631 } |
644 | 632 |
645 WebNotificationTray* tray_; | 633 WebNotificationTray* tray_; |
646 internal::TrayBubbleView* bubble_view_; | 634 TrayBubbleView* bubble_view_; |
647 views::Widget* bubble_widget_; | 635 views::Widget* bubble_widget_; |
648 BubbleContentsView* contents_view_; | 636 BubbleContentsView* contents_view_; |
649 base::WeakPtrFactory<Bubble> weak_ptr_factory_; | 637 base::WeakPtrFactory<Bubble> weak_ptr_factory_; |
650 | 638 |
651 DISALLOW_COPY_AND_ASSIGN(Bubble); | 639 DISALLOW_COPY_AND_ASSIGN(Bubble); |
652 }; | 640 }; |
653 | 641 |
654 WebNotificationTray::WebNotificationTray( | 642 WebNotificationTray::WebNotificationTray( |
655 internal::StatusAreaWidget* status_area_widget) | 643 internal::StatusAreaWidget* status_area_widget) |
656 : status_area_widget_(status_area_widget), | 644 : status_area_widget_(status_area_widget), |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
870 UpdateIcon(); | 858 UpdateIcon(); |
871 if (!bubble()) | 859 if (!bubble()) |
872 return; | 860 return; |
873 if (GetNotificationCount() == 0) | 861 if (GetNotificationCount() == 0) |
874 status_area_widget_->HideWebNotificationBubble(); | 862 status_area_widget_->HideWebNotificationBubble(); |
875 else | 863 else |
876 bubble_->ScheduleUpdate(); | 864 bubble_->ScheduleUpdate(); |
877 } | 865 } |
878 | 866 |
879 } // namespace ash | 867 } // namespace ash |
OLD | NEW |