| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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_win.h" | 5 #include "chrome/browser/ui/views/message_center/web_notification_tray_win.h" |
| 6 | 6 |
| 7 #include "base/i18n/number_formatting.h" | 7 #include "base/i18n/number_formatting.h" |
| 8 #include "base/string16.h" | 8 #include "base/string16.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| 11 #include "chrome/browser/status_icons/status_icon.h" | 11 #include "chrome/browser/status_icons/status_icon.h" |
| 12 #include "chrome/browser/status_icons/status_tray.h" | 12 #include "chrome/browser/status_icons/status_tray.h" |
| 13 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win
.h" | 13 #include "chrome/browser/ui/views/message_center/notification_bubble_wrapper_win
.h" |
| 14 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" | 14 #include "chrome/browser/ui/views/status_icons/status_icon_win.h" |
| 15 #include "grit/chromium_strings.h" | 15 #include "grit/chromium_strings.h" |
| 16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
| 17 #include "grit/ui_strings.h" | 17 #include "grit/ui_strings.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/models/simple_menu_model.h" | 19 #include "ui/base/models/simple_menu_model.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 20 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/base/win/hwnd_util.h" | 21 #include "ui/base/win/hwnd_util.h" |
| 22 #include "ui/gfx/image/image_skia_operations.h" | 22 #include "ui/gfx/image/image_skia_operations.h" |
| 23 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
| 24 #include "ui/message_center/message_center_tray.h" | 24 #include "ui/message_center/message_center_tray.h" |
| 25 #include "ui/message_center/message_center_tray_delegate.h" | 25 #include "ui/message_center/message_center_tray_delegate.h" |
| 26 #include "ui/message_center/views/message_bubble_base.h" | 26 #include "ui/message_center/views/message_bubble_base.h" |
| 27 #include "ui/message_center/views/message_center_bubble.h" | 27 #include "ui/message_center/views/message_center_bubble.h" |
| 28 #include "ui/message_center/views/message_popup_bubble.h" | 28 #include "ui/message_center/views/message_popup_collection.h" |
| 29 #include "ui/views/widget/widget.h" | 29 #include "ui/views/widget/widget.h" |
| 30 | 30 |
| 31 namespace { | 31 namespace { |
| 32 | 32 |
| 33 // Tray constants | 33 // Tray constants |
| 34 const int kScreenEdgePadding = 2; | 34 const int kScreenEdgePadding = 2; |
| 35 | 35 |
| 36 gfx::Rect GetCornerAnchorRect() { | 36 gfx::Rect GetCornerAnchorRect() { |
| 37 // TODO(dewittj): Use the preference to determine which corner to anchor from. | 37 // TODO(dewittj): Use the preference to determine which corner to anchor from. |
| 38 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 38 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 StatusTray* status_tray = g_browser_process->status_tray(); | 109 StatusTray* status_tray = g_browser_process->status_tray(); |
| 110 status_tray->RemoveStatusIcon(status_icon_); | 110 status_tray->RemoveStatusIcon(status_icon_); |
| 111 status_icon_ = NULL; | 111 status_icon_ = NULL; |
| 112 } | 112 } |
| 113 | 113 |
| 114 message_center::MessageCenter* WebNotificationTrayWin::message_center() { | 114 message_center::MessageCenter* WebNotificationTrayWin::message_center() { |
| 115 return message_center_tray_->message_center(); | 115 return message_center_tray_->message_center(); |
| 116 } | 116 } |
| 117 | 117 |
| 118 bool WebNotificationTrayWin::ShowPopups() { | 118 bool WebNotificationTrayWin::ShowPopups() { |
| 119 scoped_ptr<message_center::MessagePopupBubble> bubble( | 119 popup_collection_.reset( |
| 120 new message_center::MessagePopupBubble(message_center())); | 120 new message_center::MessagePopupCollection(NULL, message_center())); |
| 121 popup_bubble_.reset(new internal::NotificationBubbleWrapperWin( | |
| 122 this, | |
| 123 bubble.Pass(), | |
| 124 internal::NotificationBubbleWrapperWin::BUBBLE_TYPE_POPUP)); | |
| 125 return true; | 121 return true; |
| 126 } | 122 } |
| 127 | 123 |
| 128 void WebNotificationTrayWin::HidePopups() { | 124 void WebNotificationTrayWin::HidePopups() { |
| 129 popup_bubble_.reset(); | 125 popup_collection_.reset(); |
| 130 } | 126 } |
| 131 | 127 |
| 132 bool WebNotificationTrayWin::ShowMessageCenter() { | 128 bool WebNotificationTrayWin::ShowMessageCenter() { |
| 133 scoped_ptr<message_center::MessageCenterBubble> bubble( | 129 scoped_ptr<message_center::MessageCenterBubble> bubble( |
| 134 new message_center::MessageCenterBubble(message_center())); | 130 new message_center::MessageCenterBubble(message_center())); |
| 135 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 131 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 136 gfx::Rect work_area = screen->GetPrimaryDisplay().work_area(); | 132 gfx::Rect work_area = screen->GetPrimaryDisplay().work_area(); |
| 137 views::TrayBubbleView::AnchorAlignment alignment = GetAnchorAlignment(); | 133 views::TrayBubbleView::AnchorAlignment alignment = GetAnchorAlignment(); |
| 138 | 134 |
| 139 int max_height = work_area.height(); | 135 int max_height = work_area.height(); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 166 void WebNotificationTrayWin::HideMessageCenter() { | 162 void WebNotificationTrayWin::HideMessageCenter() { |
| 167 message_center_bubble_.reset(); | 163 message_center_bubble_.reset(); |
| 168 } | 164 } |
| 169 | 165 |
| 170 void WebNotificationTrayWin::UpdateMessageCenter() { | 166 void WebNotificationTrayWin::UpdateMessageCenter() { |
| 171 if (message_center_bubble_.get()) | 167 if (message_center_bubble_.get()) |
| 172 message_center_bubble_->bubble()->ScheduleUpdate(); | 168 message_center_bubble_->bubble()->ScheduleUpdate(); |
| 173 } | 169 } |
| 174 | 170 |
| 175 void WebNotificationTrayWin::UpdatePopups() { | 171 void WebNotificationTrayWin::UpdatePopups() { |
| 176 if (popup_bubble_.get()) | 172 if (popup_collection_.get()) |
| 177 popup_bubble_->bubble()->ScheduleUpdate(); | 173 popup_collection_->UpdatePopups(); |
| 178 }; | 174 }; |
| 179 | 175 |
| 180 void WebNotificationTrayWin::OnMessageCenterTrayChanged() { | 176 void WebNotificationTrayWin::OnMessageCenterTrayChanged() { |
| 181 UpdateStatusIcon(); | 177 UpdateStatusIcon(); |
| 182 } | 178 } |
| 183 | 179 |
| 184 gfx::Rect WebNotificationTrayWin::GetMessageCenterAnchor() { | 180 gfx::Rect WebNotificationTrayWin::GetMessageCenterAnchor() { |
| 185 return GetMouseAnchorRect(mouse_click_point_); | 181 return GetMouseAnchorRect(mouse_click_point_); |
| 186 } | 182 } |
| 187 | 183 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); | 229 gfx::Screen* screen = gfx::Screen::GetNativeScreen(); |
| 234 mouse_click_point_ = screen->GetCursorScreenPoint(); | 230 mouse_click_point_ = screen->GetCursorScreenPoint(); |
| 235 message_center_tray_->ToggleMessageCenterBubble(); | 231 message_center_tray_->ToggleMessageCenterBubble(); |
| 236 } | 232 } |
| 237 | 233 |
| 238 void WebNotificationTrayWin::HideBubbleWithView( | 234 void WebNotificationTrayWin::HideBubbleWithView( |
| 239 const views::TrayBubbleView* bubble_view) { | 235 const views::TrayBubbleView* bubble_view) { |
| 240 if (message_center_bubble_.get() && | 236 if (message_center_bubble_.get() && |
| 241 bubble_view == message_center_bubble_->bubble_view()) { | 237 bubble_view == message_center_bubble_->bubble_view()) { |
| 242 message_center_tray_->HideMessageCenterBubble(); | 238 message_center_tray_->HideMessageCenterBubble(); |
| 243 } else if (popup_bubble_.get() && | |
| 244 bubble_view == popup_bubble_->bubble_view()) { | |
| 245 message_center_tray_->HidePopupBubble(); | |
| 246 } | 239 } |
| 247 } | 240 } |
| 248 | 241 |
| 249 void WebNotificationTrayWin::AddQuietModeMenu(StatusIcon* status_icon) { | 242 void WebNotificationTrayWin::AddQuietModeMenu(StatusIcon* status_icon) { |
| 250 DCHECK(status_icon); | 243 DCHECK(status_icon); |
| 251 status_icon->SetContextMenu(message_center_tray_->CreateQuietModeMenu()); | 244 status_icon->SetContextMenu(message_center_tray_->CreateQuietModeMenu()); |
| 252 } | 245 } |
| 253 | 246 |
| 254 message_center::MessageCenterBubble* | 247 message_center::MessageCenterBubble* |
| 255 WebNotificationTrayWin::GetMessageCenterBubbleForTest() { | 248 WebNotificationTrayWin::GetMessageCenterBubbleForTest() { |
| 256 if (!message_center_bubble_.get()) | 249 if (!message_center_bubble_.get()) |
| 257 return NULL; | 250 return NULL; |
| 258 return static_cast<message_center::MessageCenterBubble*>( | 251 return static_cast<message_center::MessageCenterBubble*>( |
| 259 message_center_bubble_->bubble()); | 252 message_center_bubble_->bubble()); |
| 260 } | 253 } |
| 261 | 254 |
| 262 message_center::MessagePopupBubble* | |
| 263 WebNotificationTrayWin::GetPopupBubbleForTest() { | |
| 264 if (!popup_bubble_.get()) | |
| 265 return NULL; | |
| 266 return static_cast<message_center::MessagePopupBubble*>( | |
| 267 popup_bubble_->bubble()); | |
| 268 } | |
| 269 | |
| 270 } // namespace message_center | 255 } // namespace message_center |
| OLD | NEW |