OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray.h" |
6 | 6 |
7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
8 #include "base/prefs/pref_service.h" | 8 #include "base/prefs/pref_service.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
11 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
12 #include "chrome/browser/status_icons/status_icon.h" | 12 #include "chrome/browser/status_icons/status_icon.h" |
13 #include "chrome/browser/status_icons/status_icon_menu_model.h" | 13 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
14 #include "chrome/browser/status_icons/status_tray.h" | 14 #include "chrome/browser/status_icons/status_tray.h" |
15 #include "chrome/common/pref_names.h" | 15 #include "chrome/common/pref_names.h" |
16 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
17 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
18 #include "grit/generated_resources.h" | 18 #include "grit/generated_resources.h" |
19 #include "grit/theme_resources.h" | 19 #include "grit/theme_resources.h" |
20 #include "grit/ui_strings.h" | 20 #include "grit/ui_strings.h" |
21 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
23 #include "ui/gfx/canvas.h" | 23 #include "ui/gfx/canvas.h" |
24 #include "ui/gfx/image/image_skia_operations.h" | 24 #include "ui/gfx/image/image_skia_operations.h" |
25 #include "ui/gfx/rect.h" | 25 #include "ui/gfx/rect.h" |
26 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
27 #include "ui/gfx/size.h" | 27 #include "ui/gfx/size.h" |
28 #include "ui/message_center/message_center_tray.h" | 28 #include "ui/message_center/message_center_tray.h" |
29 #include "ui/message_center/message_center_tray_delegate.h" | 29 #include "ui/message_center/message_center_tray_delegate.h" |
| 30 #include "ui/message_center/views/desktop_popup_alignment_delegate.h" |
30 #include "ui/message_center/views/message_popup_collection.h" | 31 #include "ui/message_center/views/message_popup_collection.h" |
31 #include "ui/views/widget/widget.h" | 32 #include "ui/views/widget/widget.h" |
32 | 33 |
33 namespace { | 34 namespace { |
34 | 35 |
35 // Tray constants | 36 // Tray constants |
36 const int kScreenEdgePadding = 2; | 37 const int kScreenEdgePadding = 2; |
37 | 38 |
38 // Number of pixels the message center is offset from the mouse. | 39 // Number of pixels the message center is offset from the mouse. |
39 const int kMouseOffset = 5; | 40 const int kMouseOffset = 5; |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
128 } | 129 } |
129 | 130 |
130 WebNotificationTray::WebNotificationTray(PrefService* local_state) | 131 WebNotificationTray::WebNotificationTray(PrefService* local_state) |
131 : message_center_delegate_(NULL), | 132 : message_center_delegate_(NULL), |
132 status_icon_(NULL), | 133 status_icon_(NULL), |
133 status_icon_menu_(NULL), | 134 status_icon_menu_(NULL), |
134 should_update_tray_content_(true) { | 135 should_update_tray_content_(true) { |
135 message_center_tray_.reset( | 136 message_center_tray_.reset( |
136 new MessageCenterTray(this, g_browser_process->message_center())); | 137 new MessageCenterTray(this, g_browser_process->message_center())); |
137 last_quiet_mode_state_ = message_center()->IsQuietMode(); | 138 last_quiet_mode_state_ = message_center()->IsQuietMode(); |
| 139 alignment_delegate_.reset(new message_center::DesktopPopupAlignmentDelegate); |
138 popup_collection_.reset(new message_center::MessagePopupCollection( | 140 popup_collection_.reset(new message_center::MessagePopupCollection( |
139 NULL, message_center(), message_center_tray_.get(), false)); | 141 NULL, message_center(), message_center_tray_.get(), |
| 142 alignment_delegate_.get())); |
140 | 143 |
141 #if defined(OS_WIN) | 144 #if defined(OS_WIN) |
142 // |local_state| can be NULL in tests. | 145 // |local_state| can be NULL in tests. |
143 if (local_state) { | 146 if (local_state) { |
144 did_force_tray_visible_.reset(new BooleanPrefMember()); | 147 did_force_tray_visible_.reset(new BooleanPrefMember()); |
145 did_force_tray_visible_->Init(prefs::kMessageCenterForcedOnTaskbar, | 148 did_force_tray_visible_->Init(prefs::kMessageCenterForcedOnTaskbar, |
146 local_state); | 149 local_state); |
147 } | 150 } |
148 #endif | 151 #endif |
149 title_ = l10n_util::GetStringFUTF16( | 152 title_ = l10n_util::GetStringFUTF16( |
150 IDS_MESSAGE_CENTER_FOOTER_WITH_PRODUCT_TITLE, | 153 IDS_MESSAGE_CENTER_FOOTER_WITH_PRODUCT_TITLE, |
151 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); | 154 l10n_util::GetStringUTF16(IDS_SHORT_PRODUCT_NAME)); |
152 } | 155 } |
153 | 156 |
154 WebNotificationTray::~WebNotificationTray() { | 157 WebNotificationTray::~WebNotificationTray() { |
155 // Reset this early so that delegated events during destruction don't cause | 158 // Reset this early so that delegated events during destruction don't cause |
156 // problems. | 159 // problems. |
157 popup_collection_.reset(); | 160 popup_collection_.reset(); |
158 message_center_tray_.reset(); | 161 message_center_tray_.reset(); |
159 DestroyStatusIcon(); | 162 DestroyStatusIcon(); |
160 } | 163 } |
161 | 164 |
162 message_center::MessageCenter* WebNotificationTray::message_center() { | 165 message_center::MessageCenter* WebNotificationTray::message_center() { |
163 return message_center_tray_->message_center(); | 166 return message_center_tray_->message_center(); |
164 } | 167 } |
165 | 168 |
166 bool WebNotificationTray::ShowPopups() { | 169 bool WebNotificationTray::ShowPopups() { |
| 170 alignment_delegate_->StartObserving(gfx::Screen::GetNativeScreen()); |
167 popup_collection_->DoUpdateIfPossible(); | 171 popup_collection_->DoUpdateIfPossible(); |
168 return true; | 172 return true; |
169 } | 173 } |
170 | 174 |
171 void WebNotificationTray::HidePopups() { | 175 void WebNotificationTray::HidePopups() { |
172 DCHECK(popup_collection_.get()); | 176 DCHECK(popup_collection_.get()); |
173 popup_collection_->MarkAllPopupsShown(); | 177 popup_collection_->MarkAllPopupsShown(); |
174 } | 178 } |
175 | 179 |
176 bool WebNotificationTray::ShowMessageCenter() { | 180 bool WebNotificationTray::ShowMessageCenter() { |
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 status_icon_menu_ = menu.get(); | 394 status_icon_menu_ = menu.get(); |
391 status_icon->SetContextMenu(menu.Pass()); | 395 status_icon->SetContextMenu(menu.Pass()); |
392 } | 396 } |
393 | 397 |
394 MessageCenterWidgetDelegate* | 398 MessageCenterWidgetDelegate* |
395 WebNotificationTray::GetMessageCenterWidgetDelegateForTest() { | 399 WebNotificationTray::GetMessageCenterWidgetDelegateForTest() { |
396 return message_center_delegate_; | 400 return message_center_delegate_; |
397 } | 401 } |
398 | 402 |
399 } // namespace message_center | 403 } // namespace message_center |
OLD | NEW |