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

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

Powered by Google App Engine
This is Rietveld 408576698