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/strings/string16.h" | 9 #include "base/strings/string16.h" |
9 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 11 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/status_icons/status_icon.h" | 12 #include "chrome/browser/status_icons/status_icon.h" |
12 #include "chrome/browser/status_icons/status_icon_menu_model.h" | 13 #include "chrome/browser/status_icons/status_icon_menu_model.h" |
13 #include "chrome/browser/status_icons/status_tray.h" | 14 #include "chrome/browser/status_icons/status_tray.h" |
| 15 #include "chrome/common/pref_names.h" |
14 #include "content/public/browser/notification_service.h" | 16 #include "content/public/browser/notification_service.h" |
15 #include "grit/chromium_strings.h" | 17 #include "grit/chromium_strings.h" |
16 #include "grit/theme_resources.h" | 18 #include "grit/theme_resources.h" |
17 #include "grit/ui_strings.h" | 19 #include "grit/ui_strings.h" |
18 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
19 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
20 #include "ui/gfx/canvas.h" | 22 #include "ui/gfx/canvas.h" |
21 #include "ui/gfx/image/image_skia_operations.h" | 23 #include "ui/gfx/image/image_skia_operations.h" |
22 #include "ui/gfx/rect.h" | 24 #include "ui/gfx/rect.h" |
23 #include "ui/gfx/screen.h" | 25 #include "ui/gfx/screen.h" |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
114 anchor_alignment = | 116 anchor_alignment = |
115 (Alignment)(anchor_alignment | | 117 (Alignment)(anchor_alignment | |
116 (center.x() > corner.x() ? ALIGNMENT_LEFT : ALIGNMENT_RIGHT)); | 118 (center.x() > corner.x() ? ALIGNMENT_LEFT : ALIGNMENT_RIGHT)); |
117 | 119 |
118 return anchor_alignment; | 120 return anchor_alignment; |
119 } | 121 } |
120 | 122 |
121 } // namespace internal | 123 } // namespace internal |
122 | 124 |
123 MessageCenterTrayDelegate* CreateMessageCenterTray() { | 125 MessageCenterTrayDelegate* CreateMessageCenterTray() { |
124 return new WebNotificationTray(); | 126 return new WebNotificationTray(g_browser_process->local_state()); |
125 } | 127 } |
126 | 128 |
127 WebNotificationTray::WebNotificationTray() | 129 WebNotificationTray::WebNotificationTray(PrefService* local_state) |
128 : message_center_delegate_(NULL), | 130 : message_center_delegate_(NULL), |
129 status_icon_(NULL), | 131 status_icon_(NULL), |
130 status_icon_menu_(NULL), | 132 status_icon_menu_(NULL), |
131 message_center_visible_(false), | 133 message_center_visible_(false), |
132 should_update_tray_content_(true) { | 134 should_update_tray_content_(true) { |
133 message_center_tray_.reset( | 135 message_center_tray_.reset( |
134 new MessageCenterTray(this, g_browser_process->message_center())); | 136 new MessageCenterTray(this, g_browser_process->message_center())); |
135 last_quiet_mode_state_ = message_center()->IsQuietMode(); | 137 last_quiet_mode_state_ = message_center()->IsQuietMode(); |
| 138 #if defined(OS_WIN) |
| 139 // |local_state| can be NULL in tests. |
| 140 if (local_state) { |
| 141 did_force_tray_visible_.Init(prefs::kMessageCenterForcedOnTaskbar, |
| 142 local_state); |
| 143 } |
| 144 #endif |
136 } | 145 } |
137 | 146 |
138 WebNotificationTray::~WebNotificationTray() { | 147 WebNotificationTray::~WebNotificationTray() { |
139 // Reset this early so that delegated events during destruction don't cause | 148 // Reset this early so that delegated events during destruction don't cause |
140 // problems. | 149 // problems. |
141 message_center_tray_.reset(); | 150 message_center_tray_.reset(); |
142 DestroyStatusIcon(); | 151 DestroyStatusIcon(); |
143 } | 152 } |
144 | 153 |
145 message_center::MessageCenter* WebNotificationTray::message_center() { | 154 message_center::MessageCenter* WebNotificationTray::message_center() { |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
334 if (!status_tray) | 343 if (!status_tray) |
335 return; | 344 return; |
336 | 345 |
337 status_icon_ = status_tray->CreateStatusIcon( | 346 status_icon_ = status_tray->CreateStatusIcon( |
338 StatusTray::NOTIFICATION_TRAY_ICON, image, tool_tip); | 347 StatusTray::NOTIFICATION_TRAY_ICON, image, tool_tip); |
339 if (!status_icon_) | 348 if (!status_icon_) |
340 return; | 349 return; |
341 | 350 |
342 status_icon_->AddObserver(this); | 351 status_icon_->AddObserver(this); |
343 AddQuietModeMenu(status_icon_); | 352 AddQuietModeMenu(status_icon_); |
| 353 #if defined(OS_WIN) |
| 354 if (!*did_force_tray_visible_) { |
| 355 EnforceStatusIconVisible(); |
| 356 did_force_tray_visible_.SetValue(true); |
| 357 } |
| 358 #endif |
344 } | 359 } |
345 | 360 |
346 void WebNotificationTray::DestroyStatusIcon() { | 361 void WebNotificationTray::DestroyStatusIcon() { |
347 if (!status_icon_) | 362 if (!status_icon_) |
348 return; | 363 return; |
349 | 364 |
350 status_icon_->RemoveObserver(this); | 365 status_icon_->RemoveObserver(this); |
351 StatusTray* status_tray = g_browser_process->status_tray(); | 366 StatusTray* status_tray = g_browser_process->status_tray(); |
352 if (status_tray) | 367 if (status_tray) |
353 status_tray->RemoveStatusIcon(status_icon_); | 368 status_tray->RemoveStatusIcon(status_icon_); |
(...skipping 16 matching lines...) Expand all Loading... |
370 status_icon_menu_ = menu.get(); | 385 status_icon_menu_ = menu.get(); |
371 status_icon->SetContextMenu(menu.Pass()); | 386 status_icon->SetContextMenu(menu.Pass()); |
372 } | 387 } |
373 | 388 |
374 MessageCenterWidgetDelegate* | 389 MessageCenterWidgetDelegate* |
375 WebNotificationTray::GetMessageCenterWidgetDelegateForTest() { | 390 WebNotificationTray::GetMessageCenterWidgetDelegateForTest() { |
376 return message_center_delegate_; | 391 return message_center_delegate_; |
377 } | 392 } |
378 | 393 |
379 } // namespace message_center | 394 } // namespace message_center |
OLD | NEW |