Add synchronous Widget closing event
[chromium-blink-merge.git] / chrome / browser / ui / views / message_center / notification_bubble_wrapper_win.cc
bloba5f9d38261504b12833a2882a7df7b12e94456f1
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.
5 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.h"
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"
16 namespace {
18 const char kAccessibleNameForBubble[] = "Windows Notification Center";
22 namespace message_center {
24 namespace internal {
26 NotificationBubbleWrapperWin::NotificationBubbleWrapperWin(
27 WebNotificationTrayWin* tray,
28 scoped_ptr<message_center::MessageBubbleBase> bubble,
29 AnchorType anchor_type)
30 : bubble_(bubble.Pass()),
31 bubble_view_(NULL),
32 bubble_widget_(NULL),
33 tray_(tray) {
34 // Windows-specific initialization.
35 views::TrayBubbleView::AnchorAlignment anchor_alignment =
36 tray->GetAnchorAlignment();
37 views::TrayBubbleView::InitParams init_params =
38 bubble_->GetInitParams(anchor_alignment);
39 init_params.anchor_type = anchor_type;
40 init_params.close_on_deactivate = false;
41 init_params.arrow_alignment =
42 views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR;
43 // TODO(dewittj): Show big shadow without blocking clicks.
44 init_params.shadow = views::BubbleBorder::NO_SHADOW;
46 bubble_view_ = views::TrayBubbleView::Create(
47 tray->GetBubbleWindowContainer(), NULL, this, &init_params);
49 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
50 bubble_widget_->AddObserver(this);
51 bubble_widget_->StackAtTop();
52 bubble_widget_->SetAlwaysOnTop(true);
53 bubble_widget_->Activate();
54 bubble_view_->InitializeAndShowBubble();
56 bubble_view_->set_close_on_deactivate(true);
57 bubble_->InitializeContents(bubble_view_);
60 NotificationBubbleWrapperWin::~NotificationBubbleWrapperWin() {
61 bubble_.reset();
62 if (bubble_widget_) {
63 bubble_widget_->RemoveObserver(this);
64 bubble_widget_->Close();
68 void NotificationBubbleWrapperWin::OnWidgetDestroying(views::Widget* widget) {
69 DCHECK_EQ(widget, bubble_widget_);
70 bubble_widget_->RemoveObserver(this);
71 bubble_widget_ = NULL;
72 tray_->HideBubbleWithView(bubble_view_);
75 void NotificationBubbleWrapperWin::BubbleViewDestroyed() {
76 bubble_->BubbleViewDestroyed();
79 void NotificationBubbleWrapperWin::OnMouseEnteredView() {
80 bubble_->OnMouseEnteredView();
83 void NotificationBubbleWrapperWin::OnMouseExitedView() {
84 bubble_->OnMouseExitedView();
87 string16 NotificationBubbleWrapperWin::GetAccessibleNameForBubble() {
88 // TODO(dewittj): Get a string resource.
89 return ASCIIToUTF16(kAccessibleNameForBubble);
92 gfx::Rect NotificationBubbleWrapperWin::GetAnchorRect(
93 views::Widget* anchor_widget,
94 AnchorType anchor_type,
95 AnchorAlignment anchor_alignment) {
96 gfx::Size size = bubble_view_->GetPreferredSize();
97 return tray_->GetAnchorRect(size,
98 anchor_type,
99 anchor_alignment);
102 void NotificationBubbleWrapperWin::HideBubble(
103 const views::TrayBubbleView* bubble_view) {
104 tray_->HideBubbleWithView(bubble_view);
107 } // namespace internal
109 } // namespace message_center