OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win .h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.h" | |
9 #include "ui/gfx/size.h" | |
10 #include "ui/message_center/message_bubble_base.h" | |
11 #include "ui/views/bubble/bubble_delegate.h" | |
12 #include "ui/views/bubble/tray_bubble_view.h" | |
13 #include "ui/views/widget/widget.h" | |
14 #include "ui/views/widget/widget_observer.h" | |
15 | |
16 namespace ui { | |
17 | |
18 namespace internal { | |
19 | |
20 NotificationBubbleWrapperWin::NotificationBubbleWrapperWin( | |
21 WebNotificationTrayWin* tray, | |
22 message_center::MessageBubbleBase* bubble, | |
23 AnchorType anchor_type) | |
24 : tray_(tray) { | |
25 bubble_.reset(bubble); | |
26 | |
27 // Windows-specific initialization. | |
28 views::TrayBubbleView::AnchorAlignment anchor_alignment = | |
29 tray->GetAnchorAlignment(); | |
30 views::TrayBubbleView::InitParams init_params = | |
31 bubble->GetInitParams(anchor_alignment); | |
32 init_params.anchor_type = anchor_type; | |
33 init_params.close_on_deactivate = false; | |
34 init_params.arrow_alignment = | |
35 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR; | |
36 // TODO(dewittj): Show big shadow without blocking clicks. | |
37 init_params.shadow = views::BubbleBorder::NO_SHADOW; | |
38 | |
39 bubble_view_ = views::TrayBubbleView::Create( | |
40 tray->GetBubbleWindowContainer(), NULL, this, &init_params); | |
Pete Williamson
2013/01/23 19:52:16
So who owns the bubble_view_? The .h file says it
dewittj
2013/01/23 22:07:52
The Widget is indeed responsible for destruction o
| |
41 | |
42 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | |
43 bubble_widget_->AddObserver(this); | |
44 bubble_widget_->StackAtTop(); | |
45 bubble_widget_->SetAlwaysOnTop(true); | |
46 bubble_widget_->Activate(); | |
Pete Williamson
2013/01/23 19:52:16
If we always do these 4 steps, we should consider
dewittj
2013/01/23 22:07:52
These are always done on Windows only.
| |
47 bubble_view_->InitializeAndShowBubble(); | |
48 | |
49 bubble_view_->set_close_on_deactivate(true); | |
50 bubble->InitializeContents(bubble_view_); | |
51 } | |
52 | |
53 NotificationBubbleWrapperWin::~NotificationBubbleWrapperWin() { | |
54 bubble_.reset(); | |
55 if (bubble_widget_) { | |
56 bubble_widget_->RemoveObserver(this); | |
57 bubble_widget_->Close(); | |
58 bubble_widget_ = NULL; | |
59 } | |
60 } | |
61 | |
62 void NotificationBubbleWrapperWin::OnWidgetClosing(views::Widget* widget) { | |
63 bubble_widget_->RemoveObserver(this); | |
64 bubble_widget_ = NULL; | |
65 tray_->HideBubbleWithView(bubble_view_); | |
66 } | |
67 | |
68 void NotificationBubbleWrapperWin::BubbleViewDestroyed() { | |
69 bubble_->BubbleViewDestroyed(); | |
70 } | |
71 | |
72 void NotificationBubbleWrapperWin::OnMouseEnteredView() { | |
73 bubble_->OnMouseEnteredView(); | |
74 }; | |
75 | |
76 void NotificationBubbleWrapperWin::OnMouseExitedView() { | |
77 bubble_->OnMouseExitedView(); | |
78 } | |
79 | |
80 string16 NotificationBubbleWrapperWin::GetAccessibleNameForBubble() { | |
81 // TODO(dewittj): Get a string resource. | |
82 return ASCIIToUTF16("Windows Notification Center"); | |
Pete Williamson
2013/01/23 19:52:16
This string should be a constant at the top of the
dewittj
2013/01/23 22:07:52
Done.
| |
83 } | |
84 | |
Pete Williamson
2013/01/23 19:52:16
Again, I wonder why we need an anchor rect. It se
dewittj
2013/01/23 22:07:52
At the moment on Windows, only a point is required
| |
85 gfx::Rect NotificationBubbleWrapperWin::GetAnchorRect( | |
86 views::Widget* anchor_widget, | |
87 AnchorType anchor_type, | |
88 AnchorAlignment anchor_alignment) { | |
89 gfx::Size size = bubble_view_->GetPreferredSize(); | |
90 return tray_->GetAnchorRect(size, | |
91 anchor_type, | |
92 anchor_alignment); | |
93 } | |
94 | |
95 void NotificationBubbleWrapperWin::HideBubble( | |
96 const views::TrayBubbleView* bubble_view) { | |
97 tray_->HideBubbleWithView(bubble_view); | |
98 } | |
99 | |
100 } // namespace internal | |
101 | |
102 } // namespace ui | |
OLD | NEW |