| Index: chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc
|
| diff --git a/chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc b/chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..0c797cee313fb1a67a1c292803ad7e200c6321f1
|
| --- /dev/null
|
| +++ b/chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc
|
| @@ -0,0 +1,113 @@
|
| +// Copyright (c) 2013 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.h"
|
| +
|
| +#include "base/utf_string_conversions.h"
|
| +#include "chrome/browser/ui/views/message_center/web_notification_tray_win.h"
|
| +#include "ui/gfx/size.h"
|
| +#include "ui/message_center/message_bubble_base.h"
|
| +#include "ui/views/bubble/bubble_delegate.h"
|
| +#include "ui/views/bubble/tray_bubble_view.h"
|
| +#include "ui/views/widget/widget.h"
|
| +#include "ui/views/widget/widget_observer.h"
|
| +
|
| +namespace ui {
|
| +
|
| +namespace internal {
|
| +
|
| +NotificationBubbleWrapperWin::NotificationBubbleWrapperWin(
|
| + WebNotificationTrayWin* tray,
|
| + message_center::MessageBubbleBase* bubble,
|
| + AnchorType anchor_type)
|
| + : tray_(tray) {
|
| + bubble_.reset(bubble);
|
| +
|
| + // Windows-specific initialization.
|
| + views::TrayBubbleView::AnchorAlignment anchor_alignment =
|
| + tray->GetAnchorAlignment();
|
| + views::TrayBubbleView::InitParams init_params =
|
| + bubble->GetInitParams(anchor_alignment);
|
| + init_params.anchor_type = anchor_type;
|
| + init_params.close_on_deactivate = false;
|
| + init_params.arrow_alignment =
|
| + views::BubbleBorder::ALIGN_ARROW_TO_MID_ANCHOR;
|
| + // TODO(dewittj): Show big shadow without blocking clicks.
|
| + init_params.shadow = views::BubbleBorder::NO_SHADOW;
|
| +
|
| + bubble_view_ = views::TrayBubbleView::Create(
|
| + tray->GetBubbleWindowContainer(), NULL, this, &init_params);
|
| +
|
| + bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
|
| + bubble_widget_->AddObserver(this);
|
| + bubble_widget_->StackAtTop();
|
| + bubble_widget_->SetAlwaysOnTop(true);
|
| + bubble_widget_->Activate();
|
| + bubble_view_->InitializeAndShowBubble();
|
| +
|
| + bubble_view_->set_close_on_deactivate(true);
|
| + bubble->InitializeContents(bubble_view_);
|
| +}
|
| +
|
| +NotificationBubbleWrapperWin::~NotificationBubbleWrapperWin() {
|
| + bubble_.reset();
|
| + if (bubble_widget_) {
|
| + bubble_widget_->RemoveObserver(this);
|
| + bubble_widget_->Close();
|
| + bubble_widget_ = NULL;
|
| + }
|
| +}
|
| +
|
| +// Overridden from views::WidgetObserver.
|
| +void NotificationBubbleWrapperWin::OnWidgetClosing(views::Widget* widget) {
|
| + bubble_widget_->RemoveObserver(this);
|
| + bubble_widget_ = NULL;
|
| + tray_->HideBubbleWithView(bubble_view_);
|
| +}
|
| +
|
| +// TrayBubbleView::Delegate implementation.
|
| +// Called when the view is destroyed. Any pointers to the view should be
|
| +// cleared when this gets called.
|
| +void NotificationBubbleWrapperWin::BubbleViewDestroyed() {
|
| + bubble_->BubbleViewDestroyed();
|
| +}
|
| +
|
| +// Called when the mouse enters/exits the view.
|
| +void NotificationBubbleWrapperWin::OnMouseEnteredView() {
|
| + bubble_->OnMouseEnteredView();
|
| +};
|
| +
|
| +void NotificationBubbleWrapperWin::OnMouseExitedView() {
|
| + bubble_->OnMouseExitedView();
|
| +}
|
| +
|
| +// Called from GetAccessibleState(); should return the appropriate
|
| +// accessible name for the bubble.
|
| +string16 NotificationBubbleWrapperWin::GetAccessibleNameForBubble() {
|
| + // TODO(dewittj): get a string resource.
|
| + return ASCIIToUTF16("Windows Notification Center");
|
| +}
|
| +
|
| +// Passes responsibility for BubbleDelegateView::GetAnchorRect to the
|
| +// delegate.
|
| +gfx::Rect NotificationBubbleWrapperWin::GetAnchorRect(
|
| + views::Widget* anchor_widget,
|
| + AnchorType anchor_type,
|
| + AnchorAlignment anchor_alignment) {
|
| + gfx::Size size = bubble_view_->GetPreferredSize();
|
| + return tray_->GetAnchorRect(size,
|
| + anchor_type,
|
| + anchor_alignment);
|
| +}
|
| +
|
| +// Called when a bubble wants to hide/destroy itself (e.g. last visible
|
| +// child view was closed).
|
| +void NotificationBubbleWrapperWin::HideBubble(
|
| + const views::TrayBubbleView* bubble_view) {
|
| + tray_->HideBubbleWithView(bubble_view);
|
| +}
|
| +
|
| +} // namespace internal
|
| +
|
| +} // namespace ui
|
|
|