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

Unified 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: remove Singleton references, merge Delegate/Observer, style cleanup. 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 side-by-side diff with in-line comments
Download patch
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..7aa52659b88fcea253a7b482287c62efe03af56c
--- /dev/null
+++ b/chrome/browser/ui/views/message_center/notification_bubble_wrapper_win.cc
@@ -0,0 +1,102 @@
+// 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);
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
+
+ bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
+ bubble_widget_->AddObserver(this);
+ bubble_widget_->StackAtTop();
+ bubble_widget_->SetAlwaysOnTop(true);
+ 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.
+ 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;
+ }
+}
+
+void NotificationBubbleWrapperWin::OnWidgetClosing(views::Widget* widget) {
+ bubble_widget_->RemoveObserver(this);
+ bubble_widget_ = NULL;
+ tray_->HideBubbleWithView(bubble_view_);
+}
+
+void NotificationBubbleWrapperWin::BubbleViewDestroyed() {
+ bubble_->BubbleViewDestroyed();
+}
+
+void NotificationBubbleWrapperWin::OnMouseEnteredView() {
+ bubble_->OnMouseEnteredView();
+};
+
+void NotificationBubbleWrapperWin::OnMouseExitedView() {
+ bubble_->OnMouseExitedView();
+}
+
+string16 NotificationBubbleWrapperWin::GetAccessibleNameForBubble() {
+ // TODO(dewittj): Get a string resource.
+ 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.
+}
+
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
+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);
+}
+
+void NotificationBubbleWrapperWin::HideBubble(
+ const views::TrayBubbleView* bubble_view) {
+ tray_->HideBubbleWithView(bubble_view);
+}
+
+} // namespace internal
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698