| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ash/system/web_notification/web_notification_tray.h" | 5 #include "ash/common/system/web_notification/web_notification_tray.h" |
| 6 | 6 |
| 7 #include "ash/common/ash_switches.h" | 7 #include "ash/common/ash_switches.h" |
| 8 #include "ash/common/material_design/material_design_controller.h" | 8 #include "ash/common/material_design/material_design_controller.h" |
| 9 #include "ash/common/session/session_state_delegate.h" | 9 #include "ash/common/session/session_state_delegate.h" |
| 10 #include "ash/common/shelf/shelf_constants.h" | 10 #include "ash/common/shelf/shelf_constants.h" |
| 11 #include "ash/common/shelf/wm_shelf.h" | 11 #include "ash/common/shelf/wm_shelf.h" |
| 12 #include "ash/common/shelf/wm_shelf_util.h" | 12 #include "ash/common/shelf/wm_shelf_util.h" |
| 13 #include "ash/common/shell_window_ids.h" | 13 #include "ash/common/shell_window_ids.h" |
| 14 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" | 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 16 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
| 17 #include "ash/common/system/tray/tray_utils.h" | 17 #include "ash/common/system/tray/tray_utils.h" |
| 18 #include "ash/common/system/web_notification/ash_popup_alignment_delegate.h" |
| 18 #include "ash/common/wm_lookup.h" | 19 #include "ash/common/wm_lookup.h" |
| 19 #include "ash/common/wm_root_window_controller.h" | 20 #include "ash/common/wm_root_window_controller.h" |
| 20 #include "ash/common/wm_shell.h" | 21 #include "ash/common/wm_shell.h" |
| 21 #include "ash/common/wm_window.h" | 22 #include "ash/common/wm_window.h" |
| 22 #include "ash/system/status_area_widget.h" | |
| 23 #include "ash/system/tray/system_tray.h" | 23 #include "ash/system/tray/system_tray.h" |
| 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | |
| 25 #include "base/auto_reset.h" | 24 #include "base/auto_reset.h" |
| 26 #include "base/i18n/number_formatting.h" | 25 #include "base/i18n/number_formatting.h" |
| 27 #include "base/i18n/rtl.h" | 26 #include "base/i18n/rtl.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 28 #include "base/threading/thread_task_runner_handle.h" |
| 30 #include "grit/ash_strings.h" | 29 #include "grit/ash_strings.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/display/display.h" | 31 #include "ui/display/display.h" |
| 33 #include "ui/display/screen.h" | 32 #include "ui/display/screen.h" |
| 34 #include "ui/gfx/paint_vector_icon.h" | 33 #include "ui/gfx/paint_vector_icon.h" |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 195 |
| 197 bool is_bubble_visible_; | 196 bool is_bubble_visible_; |
| 198 int unread_count_; | 197 int unread_count_; |
| 199 | 198 |
| 200 views::ImageView no_unread_icon_; | 199 views::ImageView no_unread_icon_; |
| 201 views::Label unread_label_; | 200 views::Label unread_label_; |
| 202 | 201 |
| 203 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | 202 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
| 204 }; | 203 }; |
| 205 | 204 |
| 206 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) | 205 WebNotificationTray::WebNotificationTray(WmShelf* shelf, |
| 207 : TrayBackgroundView(status_area_widget->wm_shelf()), | 206 WmWindow* status_area_window, |
| 208 status_area_widget_(status_area_widget), | 207 SystemTray* system_tray) |
| 209 button_(NULL), | 208 : TrayBackgroundView(shelf), |
| 209 status_area_window_(status_area_window), |
| 210 system_tray_(system_tray), |
| 211 button_(nullptr), |
| 210 show_message_center_on_unlock_(false), | 212 show_message_center_on_unlock_(false), |
| 211 should_update_tray_content_(false), | 213 should_update_tray_content_(false), |
| 212 should_block_shelf_auto_hide_(false) { | 214 should_block_shelf_auto_hide_(false) { |
| 213 DCHECK(status_area_widget_); | 215 DCHECK(shelf); |
| 216 DCHECK(status_area_window_); |
| 217 DCHECK(system_tray_); |
| 214 button_ = new WebNotificationButton(this); | 218 button_ = new WebNotificationButton(this); |
| 215 button_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | | 219 button_->set_triggerable_event_flags(ui::EF_LEFT_MOUSE_BUTTON | |
| 216 ui::EF_RIGHT_MOUSE_BUTTON); | 220 ui::EF_RIGHT_MOUSE_BUTTON); |
| 217 tray_container()->AddChildView(button_); | 221 tray_container()->AddChildView(button_); |
| 218 button_->SetFocusBehavior(FocusBehavior::NEVER); | 222 button_->SetFocusBehavior(FocusBehavior::NEVER); |
| 219 SetContentsBackground(); | 223 SetContentsBackground(); |
| 220 tray_container()->SetBorder(views::Border::NullBorder()); | 224 tray_container()->SetBorder(views::Border::NullBorder()); |
| 221 message_center_tray_.reset(new message_center::MessageCenterTray( | 225 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 222 this, message_center::MessageCenter::Get())); | 226 this, message_center::MessageCenter::Get())); |
| 223 WmShelf* shelf = WmLookup::Get() | |
| 224 ->GetWindowForWidget(status_area_widget) | |
| 225 ->GetRootWindowController() | |
| 226 ->GetShelf(); | |
| 227 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); | 227 popup_alignment_delegate_.reset(new AshPopupAlignmentDelegate(shelf)); |
| 228 popup_collection_.reset(new message_center::MessagePopupCollection( | 228 popup_collection_.reset(new message_center::MessagePopupCollection( |
| 229 message_center(), message_center_tray_.get(), | 229 message_center(), message_center_tray_.get(), |
| 230 popup_alignment_delegate_.get())); | 230 popup_alignment_delegate_.get())); |
| 231 const display::Display& display = WmLookup::Get() | 231 const display::Display& display = |
| 232 ->GetWindowForWidget(status_area_widget) | 232 status_area_window_->GetDisplayNearestWindow(); |
| 233 ->GetDisplayNearestWindow(); | |
| 234 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), | 233 popup_alignment_delegate_->StartObserving(display::Screen::GetScreen(), |
| 235 display); | 234 display); |
| 236 OnMessageCenterTrayChanged(); | 235 OnMessageCenterTrayChanged(); |
| 237 } | 236 } |
| 238 | 237 |
| 239 WebNotificationTray::~WebNotificationTray() { | 238 WebNotificationTray::~WebNotificationTray() { |
| 240 // Release any child views that might have back pointers before ~View(). | 239 // Release any child views that might have back pointers before ~View(). |
| 241 message_center_bubble_.reset(); | 240 message_center_bubble_.reset(); |
| 242 popup_alignment_delegate_.reset(); | 241 popup_alignment_delegate_.reset(); |
| 243 popup_collection_.reset(); | 242 popup_collection_.reset(); |
| 244 } | 243 } |
| 245 | 244 |
| 246 // Public methods. | 245 // Public methods. |
| 247 | 246 |
| 248 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { | 247 bool WebNotificationTray::ShowMessageCenterInternal(bool show_settings) { |
| 249 if (!ShouldShowMessageCenter()) | 248 if (!ShouldShowMessageCenter()) |
| 250 return false; | 249 return false; |
| 251 | 250 |
| 252 should_block_shelf_auto_hide_ = true; | 251 should_block_shelf_auto_hide_ = true; |
| 253 message_center::MessageCenterBubble* message_center_bubble = | 252 message_center::MessageCenterBubble* message_center_bubble = |
| 254 new message_center::MessageCenterBubble(message_center(), | 253 new message_center::MessageCenterBubble(message_center(), |
| 255 message_center_tray_.get(), true); | 254 message_center_tray_.get(), true); |
| 256 | 255 |
| 257 int max_height; | 256 int max_height; |
| 258 if (IsHorizontalAlignment(shelf()->GetAlignment())) { | 257 if (IsHorizontalAlignment(shelf()->GetAlignment())) { |
| 259 max_height = shelf()->GetIdealBounds().y(); | 258 max_height = shelf()->GetIdealBounds().y(); |
| 260 } else { | 259 } else { |
| 261 // Assume the status area and bubble bottoms are aligned when vertical. | 260 // Assume the status area and bubble bottoms are aligned when vertical. |
| 262 WmWindow* status_area_window = | |
| 263 WmLookup::Get()->GetWindowForWidget(status_area_widget_); | |
| 264 gfx::Rect bounds_in_root = | 261 gfx::Rect bounds_in_root = |
| 265 status_area_window->GetRootWindow()->ConvertRectFromScreen( | 262 status_area_window_->GetRootWindow()->ConvertRectFromScreen( |
| 266 status_area_window->GetBoundsInScreen()); | 263 status_area_window_->GetBoundsInScreen()); |
| 267 max_height = bounds_in_root.bottom(); | 264 max_height = bounds_in_root.bottom(); |
| 268 } | 265 } |
| 269 message_center_bubble->SetMaxHeight( | 266 message_center_bubble->SetMaxHeight( |
| 270 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); | 267 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); |
| 271 if (show_settings) | 268 if (show_settings) |
| 272 message_center_bubble->SetSettingsVisible(); | 269 message_center_bubble->SetSettingsVisible(); |
| 273 message_center_bubble_.reset( | 270 message_center_bubble_.reset( |
| 274 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 271 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 275 | 272 |
| 276 status_area_widget_->SetHideSystemNotifications(true); | 273 system_tray_->SetHideNotifications(true); |
| 277 shelf()->UpdateAutoHideState(); | 274 shelf()->UpdateAutoHideState(); |
| 278 button_->SetBubbleVisible(true); | 275 button_->SetBubbleVisible(true); |
| 279 SetDrawBackgroundAsActive(true); | 276 SetDrawBackgroundAsActive(true); |
| 280 return true; | 277 return true; |
| 281 } | 278 } |
| 282 | 279 |
| 283 bool WebNotificationTray::ShowMessageCenter() { | 280 bool WebNotificationTray::ShowMessageCenter() { |
| 284 return ShowMessageCenterInternal(false /* show_settings */); | 281 return ShowMessageCenterInternal(false /* show_settings */); |
| 285 } | 282 } |
| 286 | 283 |
| 287 void WebNotificationTray::HideMessageCenter() { | 284 void WebNotificationTray::HideMessageCenter() { |
| 288 if (!message_center_bubble()) | 285 if (!message_center_bubble()) |
| 289 return; | 286 return; |
| 290 SetDrawBackgroundAsActive(false); | 287 SetDrawBackgroundAsActive(false); |
| 291 message_center_bubble_.reset(); | 288 message_center_bubble_.reset(); |
| 292 should_block_shelf_auto_hide_ = false; | 289 should_block_shelf_auto_hide_ = false; |
| 293 show_message_center_on_unlock_ = false; | 290 show_message_center_on_unlock_ = false; |
| 294 status_area_widget_->SetHideSystemNotifications(false); | 291 system_tray_->SetHideNotifications(false); |
| 295 shelf()->UpdateAutoHideState(); | 292 shelf()->UpdateAutoHideState(); |
| 296 button_->SetBubbleVisible(false); | 293 button_->SetBubbleVisible(false); |
| 297 } | 294 } |
| 298 | 295 |
| 299 void WebNotificationTray::SetSystemTrayHeight(int height) { | 296 void WebNotificationTray::SetTrayBubbleHeight(int height) { |
| 300 popup_alignment_delegate_->SetSystemTrayHeight(height); | 297 popup_alignment_delegate_->SetTrayBubbleHeight(height); |
| 301 } | 298 } |
| 302 | 299 |
| 303 int WebNotificationTray::system_tray_height_for_test() const { | 300 int WebNotificationTray::tray_bubble_height_for_test() const { |
| 304 return popup_alignment_delegate_->system_tray_height_for_test(); | 301 return popup_alignment_delegate_->tray_bubble_height_for_test(); |
| 305 } | 302 } |
| 306 | 303 |
| 307 bool WebNotificationTray::ShowPopups() { | 304 bool WebNotificationTray::ShowPopups() { |
| 308 if (message_center_bubble()) | 305 if (message_center_bubble()) |
| 309 return false; | 306 return false; |
| 310 | 307 |
| 311 popup_collection_->DoUpdateIfPossible(); | 308 popup_collection_->DoUpdateIfPossible(); |
| 312 return true; | 309 return true; |
| 313 } | 310 } |
| 314 | 311 |
| 315 void WebNotificationTray::HidePopups() { | 312 void WebNotificationTray::HidePopups() { |
| 316 DCHECK(popup_collection_.get()); | 313 DCHECK(popup_collection_.get()); |
| 317 popup_collection_->MarkAllPopupsShown(); | 314 popup_collection_->MarkAllPopupsShown(); |
| 318 } | 315 } |
| 319 | 316 |
| 320 // Private methods. | 317 // Private methods. |
| 321 | 318 |
| 322 bool WebNotificationTray::ShouldShowMessageCenter() { | 319 bool WebNotificationTray::ShouldShowMessageCenter() { |
| 323 return !(status_area_widget_->system_tray() && | 320 return !system_tray_->HasNotificationBubble(); |
| 324 status_area_widget_->system_tray()->HasNotificationBubble()); | |
| 325 } | 321 } |
| 326 | 322 |
| 327 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { | 323 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { |
| 328 return should_block_shelf_auto_hide_; | 324 return should_block_shelf_auto_hide_; |
| 329 } | 325 } |
| 330 | 326 |
| 331 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 327 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| 332 return (message_center_bubble() && | 328 return (message_center_bubble() && |
| 333 message_center_bubble()->bubble()->IsVisible()); | 329 message_center_bubble()->bubble()->IsVisible()); |
| 334 } | 330 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 495 button_->SetUnreadCount(message_center->UnreadNotificationCount()); | 491 button_->SetUnreadCount(message_center->UnreadNotificationCount()); |
| 496 if (IsMessageCenterBubbleVisible()) | 492 if (IsMessageCenterBubbleVisible()) |
| 497 button_->SetState(views::CustomButton::STATE_PRESSED); | 493 button_->SetState(views::CustomButton::STATE_PRESSED); |
| 498 else | 494 else |
| 499 button_->SetState(views::CustomButton::STATE_NORMAL); | 495 button_->SetState(views::CustomButton::STATE_NORMAL); |
| 500 | 496 |
| 501 SetVisible(IsLoggedIn()); | 497 SetVisible(IsLoggedIn()); |
| 502 Layout(); | 498 Layout(); |
| 503 SchedulePaint(); | 499 SchedulePaint(); |
| 504 if (IsLoggedIn()) | 500 if (IsLoggedIn()) |
| 505 status_area_widget_->system_tray()->SetNextFocusableView(this); | 501 system_tray_->SetNextFocusableView(this); |
| 506 } | 502 } |
| 507 | 503 |
| 508 void WebNotificationTray::ClickedOutsideBubble() { | 504 void WebNotificationTray::ClickedOutsideBubble() { |
| 509 // Only hide the message center | 505 // Only hide the message center |
| 510 if (!message_center_bubble()) | 506 if (!message_center_bubble()) |
| 511 return; | 507 return; |
| 512 | 508 |
| 513 message_center_tray_->HideMessageCenterBubble(); | 509 message_center_tray_->HideMessageCenterBubble(); |
| 514 } | 510 } |
| 515 | 511 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 533 | 529 |
| 534 message_center::MessageCenterBubble* | 530 message_center::MessageCenterBubble* |
| 535 WebNotificationTray::GetMessageCenterBubbleForTest() { | 531 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 536 if (!message_center_bubble()) | 532 if (!message_center_bubble()) |
| 537 return NULL; | 533 return NULL; |
| 538 return static_cast<message_center::MessageCenterBubble*>( | 534 return static_cast<message_center::MessageCenterBubble*>( |
| 539 message_center_bubble()->bubble()); | 535 message_center_bubble()->bubble()); |
| 540 } | 536 } |
| 541 | 537 |
| 542 } // namespace ash | 538 } // namespace ash |
| OLD | NEW |