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

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

Issue 18003003: Message center re-organized (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 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.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/ui/views/message_center/web_notification_tray.h"
9 #include "grit/ui_strings.h"
10 #include "ui/base/l10n/l10n_util.h"
11 #include "ui/gfx/size.h"
12 #include "ui/message_center/views/message_bubble_base.h"
13 #include "ui/message_center/views/message_center_bubble.h"
14 #include "ui/views/bubble/bubble_delegate.h"
15 #include "ui/views/bubble/tray_bubble_view.h"
16 #include "ui/views/widget/widget.h"
17 #include "ui/views/widget/widget_observer.h"
18
19 #if defined(OS_WIN)
20 #include "ui/views/win/hwnd_util.h"
21 #endif
22
23 namespace message_center {
24
25 namespace internal {
26
27 NotificationBubbleWrapper::NotificationBubbleWrapper(
28 WebNotificationTray* tray,
29 scoped_ptr<message_center::MessageBubbleBase> bubble,
30 BubbleType bubble_type)
31 : bubble_(bubble.Pass()),
32 bubble_type_(bubble_type),
33 bubble_view_(NULL),
34 bubble_widget_(NULL),
35 tray_(tray) {
36 // Windows-specific initialization.
37 views::TrayBubbleView::AnchorAlignment anchor_alignment =
38 tray_->GetAnchorAlignment();
39 views::TrayBubbleView::InitParams init_params =
40 bubble_->GetInitParams(anchor_alignment);
41 init_params.close_on_deactivate = false;
42 init_params.arrow_alignment = views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE;
43 init_params.arrow_paint_type = views::BubbleBorder::PAINT_NONE;
44 // TODO(dewittj): Show big shadow without blocking clicks.
45 init_params.shadow = views::BubbleBorder::NO_SHADOW;
46
47 bubble_view_ = views::TrayBubbleView::Create(
48 tray_->GetBubbleWindowContainer(), NULL, this, &init_params);
49
50 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_);
51
52 #if defined(OS_WIN)
53 // Remove the bubbles for Notifications and Notification Center from taskbar
54 // and alt-tab rotation.
55 HWND hwnd = views::HWNDForWidget(bubble_widget_);
56 LONG_PTR ex_styles = ::GetWindowLongPtr(hwnd, GWL_EXSTYLE);
57 ex_styles |= WS_EX_TOOLWINDOW;
58 ::SetWindowLongPtr(hwnd, GWL_EXSTYLE, ex_styles);
59 #endif
60
61 bubble_widget_->AddObserver(this);
62 bubble_widget_->StackAtTop();
63 bubble_widget_->SetAlwaysOnTop(true);
64 // Popups should appear on top of everything, but not disturb the user's
65 // focus since they could appear at any time. Message Center is always
66 // shown as a result of user action so it can be activated here.
67 if (bubble_type_ != BUBBLE_TYPE_POPUP)
68 bubble_widget_->Activate();
69 bubble_view_->InitializeAndShowBubble();
70
71 bubble_view_->set_close_on_deactivate(true);
72 bubble_->InitializeContents(bubble_view_);
73 }
74
75 NotificationBubbleWrapper::~NotificationBubbleWrapper() {
76 bubble_.reset();
77 if (bubble_widget_) {
78 bubble_widget_->RemoveObserver(this);
79 bubble_widget_->Close();
80 }
81 }
82
83 void NotificationBubbleWrapper::OnWidgetDestroying(views::Widget* widget) {
84 DCHECK_EQ(widget, bubble_widget_);
85 bubble_widget_->RemoveObserver(this);
86 bubble_widget_ = NULL;
87 tray_->HideBubbleWithView(bubble_view_);
88 }
89
90 void NotificationBubbleWrapper::BubbleViewDestroyed() {
91 bubble_->BubbleViewDestroyed();
92 }
93
94 void NotificationBubbleWrapper::OnMouseEnteredView() {
95 bubble_->OnMouseEnteredView();
96 }
97
98 void NotificationBubbleWrapper::OnMouseExitedView() {
99 bubble_->OnMouseExitedView();
100 }
101
102 string16 NotificationBubbleWrapper::GetAccessibleNameForBubble() {
103 return l10n_util::GetStringUTF16(IDS_MESSAGE_CENTER_ACCESSIBLE_NAME);
104 }
105
106 gfx::Rect NotificationBubbleWrapper::GetAnchorRect(
107 views::Widget* anchor_widget,
108 AnchorType anchor_type,
109 AnchorAlignment anchor_alignment) {
110 if (bubble_type_ == BUBBLE_TYPE_POPUP)
111 return tray_->GetPopupAnchor();
112 return tray_->GetMessageCenterAnchor();
113 }
114
115 void NotificationBubbleWrapper::HideBubble(
116 const views::TrayBubbleView* bubble_view) {
117 tray_->HideBubbleWithView(bubble_view);
118 }
119
120 } // namespace internal
121
122 } // namespace message_center
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698