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

Side by Side Diff: chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc

Issue 11819048: Implement message center on Windows (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Now with more tests, and corrected copyright notices. Created 7 years, 11 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
(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);
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();
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 // Overridden from views::WidgetObserver.
63 void NotificationBubbleWrapperWin::OnWidgetClosing(views::Widget* widget) {
64 bubble_widget_->RemoveObserver(this);
65 bubble_widget_ = NULL;
66 tray_->HideBubbleWithView(bubble_view_);
67 }
68
69 // TrayBubbleView::Delegate implementation.
70 // Called when the view is destroyed. Any pointers to the view should be
71 // cleared when this gets called.
72 void NotificationBubbleWrapperWin::BubbleViewDestroyed() {
73 bubble_->BubbleViewDestroyed();
74 }
75
76 // Called when the mouse enters/exits the view.
77 void NotificationBubbleWrapperWin::OnMouseEnteredView() {
78 bubble_->OnMouseEnteredView();
79 };
80
81 void NotificationBubbleWrapperWin::OnMouseExitedView() {
82 bubble_->OnMouseExitedView();
83 }
84
85 // Called from GetAccessibleState(); should return the appropriate
86 // accessible name for the bubble.
87 string16 NotificationBubbleWrapperWin::GetAccessibleNameForBubble() {
88 // TODO(dewittj): get a string resource.
89 return ASCIIToUTF16("Windows Notification Center");
90 }
91
92 // Passes responsibility for BubbleDelegateView::GetAnchorRect to the
93 // delegate.
94 gfx::Rect NotificationBubbleWrapperWin::GetAnchorRect(
95 views::Widget* anchor_widget,
96 AnchorType anchor_type,
97 AnchorAlignment anchor_alignment) {
98 gfx::Size size = bubble_view_->GetPreferredSize();
99 return tray_->GetAnchorRect(size,
100 anchor_type,
101 anchor_alignment);
102 }
103
104 // Called when a bubble wants to hide/destroy itself (e.g. last visible
105 // child view was closed).
106 void NotificationBubbleWrapperWin::HideBubble(
107 const views::TrayBubbleView* bubble_view) {
108 tray_->HideBubbleWithView(bubble_view);
109 }
110
111 } // namespace internal
112
113 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698