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

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

Issue 11028134: Re-factor Ash Message Center code part 2/4 (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 8 years, 2 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/web_notification/web_notification_bubble.h" 5 #include "ash/system/web_notification/web_notification_bubble.h"
6 6
7 #include "ash/system/tray/tray_bubble_wrapper.h"
7 #include "ash/system/tray/tray_constants.h" 8 #include "ash/system/tray/tray_constants.h"
8 #include "ash/system/web_notification/web_notification_tray.h" 9 #include "ash/system/web_notification/web_notification_tray.h"
9 #include "ash/system/web_notification/web_notification_view.h" 10 #include "ash/system/web_notification/web_notification_view.h"
10 #include "base/bind.h" 11 #include "base/bind.h"
11 #include "ui/views/widget/widget.h" 12 #include "ui/views/widget/widget.h"
12 #include "ui/views/widget/widget_observer.h" 13 #include "ui/views/widget/widget_observer.h"
13 14
14 namespace ash { 15 namespace ash {
15 16
16 using internal::TrayBubbleView;
17
18 namespace message_center { 17 namespace message_center {
19 18
20 // Delay laying out the WebNotificationBubble until all notifications have been 19 // Delay laying out the WebNotificationBubble until all notifications have been
21 // added and icons have had a chance to load. 20 // added and icons have had a chance to load.
22 const int kUpdateDelayMs = 50; 21 const int kUpdateDelayMs = 50;
23 22
24 WebNotificationBubble::WebNotificationBubble(WebNotificationTray* tray) 23 WebNotificationBubble::WebNotificationBubble(WebNotificationTray* tray)
25 : tray_(tray), 24 : tray_(tray),
26 bubble_view_(NULL), 25 bubble_view_(NULL),
27 bubble_widget_(NULL),
28 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { 26 ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) {
29 } 27 }
30 28
31 void WebNotificationBubble::Initialize(views::View* contents_view) { 29 void WebNotificationBubble::Initialize(views::View* contents_view) {
32 DCHECK(bubble_view_); 30 DCHECK(bubble_view_);
33
34 bubble_view_->AddChildView(contents_view); 31 bubble_view_->AddChildView(contents_view);
35 32
36 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); 33 bubble_wrapper_.reset(new internal::TrayBubbleWrapper(tray_, bubble_view_));
37 bubble_widget_->AddObserver(this);
38
39 InitializeAndShowBubble(bubble_widget_, bubble_view_, tray_);
40 UpdateBubbleView(); 34 UpdateBubbleView();
41 } 35 }
42 36
43 WebNotificationBubble::~WebNotificationBubble() { 37 WebNotificationBubble::~WebNotificationBubble() {
44 if (bubble_view_) 38 if (bubble_view_)
45 bubble_view_->reset_host(); 39 bubble_view_->reset_delegate();
46 if (bubble_widget_) {
47 bubble_widget_->RemoveObserver(this);
48 bubble_widget_->Close();
49 }
50 } 40 }
51 41
52 void WebNotificationBubble::ScheduleUpdate() { 42 void WebNotificationBubble::ScheduleUpdate() {
53 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update. 43 weak_ptr_factory_.InvalidateWeakPtrs(); // Cancel any pending update.
54 MessageLoop::current()->PostDelayedTask( 44 MessageLoop::current()->PostDelayedTask(
55 FROM_HERE, 45 FROM_HERE,
56 base::Bind(&WebNotificationBubble::UpdateBubbleView, 46 base::Bind(&WebNotificationBubble::UpdateBubbleView,
57 weak_ptr_factory_.GetWeakPtr()), 47 weak_ptr_factory_.GetWeakPtr()),
58 base::TimeDelta::FromMilliseconds(kUpdateDelayMs)); 48 base::TimeDelta::FromMilliseconds(kUpdateDelayMs));
59 } 49 }
60 50
61 bool WebNotificationBubble::IsVisible() const { 51 bool WebNotificationBubble::IsVisible() const {
62 return bubble_widget_ && bubble_widget_->IsVisible(); 52 return bubble_view() && bubble_view()->GetWidget()->IsVisible();
63 } 53 }
64 54
65 void WebNotificationBubble::BubbleViewDestroyed() { 55 void WebNotificationBubble::BubbleViewDestroyed() {
66 bubble_view_ = NULL; 56 bubble_view_ = NULL;
67 } 57 }
68 58
69 void WebNotificationBubble::OnMouseEnteredView() { 59 void WebNotificationBubble::OnMouseEnteredView() {
70 } 60 }
71 61
72 void WebNotificationBubble::OnMouseExitedView() { 62 void WebNotificationBubble::OnMouseExitedView() {
73 } 63 }
74 64
75 void WebNotificationBubble::OnClickedOutsideView() {
76 // May delete |this|.
77 tray_->HideMessageCenterBubble();
78 }
79
80 string16 WebNotificationBubble::GetAccessibleName() { 65 string16 WebNotificationBubble::GetAccessibleName() {
81 return tray_->GetAccessibleName(); 66 return tray_->GetAccessibleName();
82 } 67 }
83 68
84 // Overridden from views::WidgetObserver: 69 gfx::Rect WebNotificationBubble::GetAnchorRect(
85 void WebNotificationBubble::OnWidgetClosing(views::Widget* widget) { 70 views::Widget* anchor_widget,
86 CHECK_EQ(bubble_widget_, widget); 71 TrayBubbleView::AnchorType anchor_type,
87 bubble_widget_ = NULL; 72 TrayBubbleView::AnchorAlignment anchor_alignment) {
88 tray_->HideBubble(this); // Will destroy |this|. 73 return tray_->GetAnchorRect(anchor_widget, anchor_type, anchor_alignment);
89 } 74 }
90 75
91 TrayBubbleView::InitParams WebNotificationBubble::GetInitParams() { 76 TrayBubbleView::InitParams WebNotificationBubble::GetInitParams() {
77 TrayBubbleView::AnchorAlignment anchor_alignment =
78 tray_->GetAnchorAlignment();
92 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY, 79 TrayBubbleView::InitParams init_params(TrayBubbleView::ANCHOR_TYPE_TRAY,
93 tray_->shelf_alignment()); 80 anchor_alignment,
81 kTrayPopupWidth);
94 init_params.top_color = kBackgroundColor; 82 init_params.top_color = kBackgroundColor;
95 init_params.arrow_color = kHeaderBackgroundColorDark; 83 init_params.arrow_color = kHeaderBackgroundColorDark;
96 init_params.bubble_width = kWebNotificationWidth; 84 init_params.bubble_width = kWebNotificationWidth;
97 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { 85 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
98 views::View* anchor = tray_->tray_container(); 86 views::View* anchor = tray_->tray_container();
99 gfx::Point bounds(anchor->width() / 2, 0); 87 gfx::Point bounds(anchor->width() / 2, 0);
100 88
101 views::View::ConvertPointToWidget(anchor, &bounds); 89 views::View::ConvertPointToWidget(anchor, &bounds);
102 init_params.arrow_offset = bounds.x(); 90 init_params.arrow_offset = bounds.x();
103 } 91 }
104 return init_params; 92 return init_params;
105 } 93 }
106 94
107 } // namespace message_center 95 } // namespace message_center
108 96
109 } // namespace ash 97 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/web_notification/web_notification_bubble.h ('k') | ash/system/web_notification/web_notification_tray.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698