| 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/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" |
| 15 #include "ash/common/system/tray/tray_bubble_wrapper.h" |
| 14 #include "ash/common/system/tray/tray_constants.h" | 16 #include "ash/common/system/tray/tray_constants.h" |
| 15 #include "ash/common/system/tray/tray_utils.h" | 17 #include "ash/common/system/tray/tray_utils.h" |
| 16 #include "ash/common/wm_lookup.h" | 18 #include "ash/common/wm_lookup.h" |
| 17 #include "ash/common/wm_root_window_controller.h" | 19 #include "ash/common/wm_root_window_controller.h" |
| 18 #include "ash/common/wm_shell.h" | 20 #include "ash/common/wm_shell.h" |
| 19 #include "ash/common/wm_window.h" | 21 #include "ash/common/wm_window.h" |
| 20 #include "ash/system/status_area_widget.h" | 22 #include "ash/system/status_area_widget.h" |
| 21 #include "ash/system/tray/system_tray.h" | 23 #include "ash/system/tray/system_tray.h" |
| 22 #include "ash/system/tray/tray_background_view.h" | |
| 23 #include "ash/system/tray/tray_bubble_wrapper.h" | |
| 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" | 24 #include "ash/system/web_notification/ash_popup_alignment_delegate.h" |
| 25 #include "base/auto_reset.h" | 25 #include "base/auto_reset.h" |
| 26 #include "base/i18n/number_formatting.h" | 26 #include "base/i18n/number_formatting.h" |
| 27 #include "base/i18n/rtl.h" | 27 #include "base/i18n/rtl.h" |
| 28 #include "base/strings/utf_string_conversions.h" | 28 #include "base/strings/utf_string_conversions.h" |
| 29 #include "base/threading/thread_task_runner_handle.h" | 29 #include "base/threading/thread_task_runner_handle.h" |
| 30 #include "grit/ash_strings.h" | 30 #include "grit/ash_strings.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "ui/display/display.h" | 32 #include "ui/display/display.h" |
| 33 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| (...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 198 bool is_bubble_visible_; | 198 bool is_bubble_visible_; |
| 199 int unread_count_; | 199 int unread_count_; |
| 200 | 200 |
| 201 views::ImageView no_unread_icon_; | 201 views::ImageView no_unread_icon_; |
| 202 views::Label unread_label_; | 202 views::Label unread_label_; |
| 203 | 203 |
| 204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); | 204 DISALLOW_COPY_AND_ASSIGN(WebNotificationButton); |
| 205 }; | 205 }; |
| 206 | 206 |
| 207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) | 207 WebNotificationTray::WebNotificationTray(StatusAreaWidget* status_area_widget) |
| 208 : TrayBackgroundView(status_area_widget), | 208 : TrayBackgroundView(status_area_widget->wm_shelf()), |
| 209 status_area_widget_(status_area_widget), |
| 209 button_(NULL), | 210 button_(NULL), |
| 210 show_message_center_on_unlock_(false), | 211 show_message_center_on_unlock_(false), |
| 211 should_update_tray_content_(false), | 212 should_update_tray_content_(false), |
| 212 should_block_shelf_auto_hide_(false) { | 213 should_block_shelf_auto_hide_(false) { |
| 214 DCHECK(status_area_widget_); |
| 213 button_ = new WebNotificationButton(this); | 215 button_ = new WebNotificationButton(this); |
| 214 button_->set_triggerable_event_flags( | 216 button_->set_triggerable_event_flags( |
| 215 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); | 217 ui::EF_LEFT_MOUSE_BUTTON | ui::EF_RIGHT_MOUSE_BUTTON); |
| 216 tray_container()->AddChildView(button_); | 218 tray_container()->AddChildView(button_); |
| 217 button_->SetFocusBehavior(FocusBehavior::NEVER); | 219 button_->SetFocusBehavior(FocusBehavior::NEVER); |
| 218 SetContentsBackground(); | 220 SetContentsBackground(); |
| 219 tray_container()->SetBorder(views::Border::NullBorder()); | 221 tray_container()->SetBorder(views::Border::NullBorder()); |
| 220 message_center_tray_.reset(new message_center::MessageCenterTray( | 222 message_center_tray_.reset(new message_center::MessageCenterTray( |
| 221 this, | 223 this, |
| 222 message_center::MessageCenter::Get())); | 224 message_center::MessageCenter::Get())); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 250 if (!ShouldShowMessageCenter()) | 252 if (!ShouldShowMessageCenter()) |
| 251 return false; | 253 return false; |
| 252 | 254 |
| 253 should_block_shelf_auto_hide_ = true; | 255 should_block_shelf_auto_hide_ = true; |
| 254 message_center::MessageCenterBubble* message_center_bubble = | 256 message_center::MessageCenterBubble* message_center_bubble = |
| 255 new message_center::MessageCenterBubble( | 257 new message_center::MessageCenterBubble( |
| 256 message_center(), | 258 message_center(), |
| 257 message_center_tray_.get(), | 259 message_center_tray_.get(), |
| 258 true); | 260 true); |
| 259 | 261 |
| 260 WmShelf* shelf = GetShelf(); | |
| 261 int max_height; | 262 int max_height; |
| 262 if (IsHorizontalAlignment(shelf->GetAlignment())) { | 263 if (IsHorizontalAlignment(shelf()->GetAlignment())) { |
| 263 max_height = shelf->GetIdealBounds().y(); | 264 max_height = shelf()->GetIdealBounds().y(); |
| 264 } else { | 265 } else { |
| 265 // Assume the status area and bubble bottoms are aligned when vertical. | 266 // Assume the status area and bubble bottoms are aligned when vertical. |
| 266 WmWindow* status_area_window = | 267 WmWindow* status_area_window = |
| 267 WmLookup::Get()->GetWindowForWidget(status_area_widget()); | 268 WmLookup::Get()->GetWindowForWidget(status_area_widget_); |
| 268 gfx::Rect bounds_in_root = | 269 gfx::Rect bounds_in_root = |
| 269 status_area_window->GetRootWindow()->ConvertRectFromScreen( | 270 status_area_window->GetRootWindow()->ConvertRectFromScreen( |
| 270 status_area_window->GetBoundsInScreen()); | 271 status_area_window->GetBoundsInScreen()); |
| 271 max_height = bounds_in_root.bottom(); | 272 max_height = bounds_in_root.bottom(); |
| 272 } | 273 } |
| 273 message_center_bubble->SetMaxHeight( | 274 message_center_bubble->SetMaxHeight( |
| 274 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); | 275 std::max(0, max_height - GetTrayConstant(TRAY_SPACING))); |
| 275 if (show_settings) | 276 if (show_settings) |
| 276 message_center_bubble->SetSettingsVisible(); | 277 message_center_bubble->SetSettingsVisible(); |
| 277 message_center_bubble_.reset( | 278 message_center_bubble_.reset( |
| 278 new WebNotificationBubbleWrapper(this, message_center_bubble)); | 279 new WebNotificationBubbleWrapper(this, message_center_bubble)); |
| 279 | 280 |
| 280 status_area_widget()->SetHideSystemNotifications(true); | 281 status_area_widget_->SetHideSystemNotifications(true); |
| 281 shelf->UpdateAutoHideState(); | 282 shelf()->UpdateAutoHideState(); |
| 282 button_->SetBubbleVisible(true); | 283 button_->SetBubbleVisible(true); |
| 283 SetDrawBackgroundAsActive(true); | 284 SetDrawBackgroundAsActive(true); |
| 284 return true; | 285 return true; |
| 285 } | 286 } |
| 286 | 287 |
| 287 bool WebNotificationTray::ShowMessageCenter() { | 288 bool WebNotificationTray::ShowMessageCenter() { |
| 288 return ShowMessageCenterInternal(false /* show_settings */); | 289 return ShowMessageCenterInternal(false /* show_settings */); |
| 289 } | 290 } |
| 290 | 291 |
| 291 void WebNotificationTray::HideMessageCenter() { | 292 void WebNotificationTray::HideMessageCenter() { |
| 292 if (!message_center_bubble()) | 293 if (!message_center_bubble()) |
| 293 return; | 294 return; |
| 294 SetDrawBackgroundAsActive(false); | 295 SetDrawBackgroundAsActive(false); |
| 295 message_center_bubble_.reset(); | 296 message_center_bubble_.reset(); |
| 296 should_block_shelf_auto_hide_ = false; | 297 should_block_shelf_auto_hide_ = false; |
| 297 show_message_center_on_unlock_ = false; | 298 show_message_center_on_unlock_ = false; |
| 298 status_area_widget()->SetHideSystemNotifications(false); | 299 status_area_widget_->SetHideSystemNotifications(false); |
| 299 GetShelf()->UpdateAutoHideState(); | 300 shelf()->UpdateAutoHideState(); |
| 300 button_->SetBubbleVisible(false); | 301 button_->SetBubbleVisible(false); |
| 301 } | 302 } |
| 302 | 303 |
| 303 void WebNotificationTray::SetSystemTrayHeight(int height) { | 304 void WebNotificationTray::SetSystemTrayHeight(int height) { |
| 304 popup_alignment_delegate_->SetSystemTrayHeight(height); | 305 popup_alignment_delegate_->SetSystemTrayHeight(height); |
| 305 } | 306 } |
| 306 | 307 |
| 307 int WebNotificationTray::system_tray_height_for_test() const { | 308 int WebNotificationTray::system_tray_height_for_test() const { |
| 308 return popup_alignment_delegate_->system_tray_height_for_test(); | 309 return popup_alignment_delegate_->system_tray_height_for_test(); |
| 309 } | 310 } |
| 310 | 311 |
| 311 bool WebNotificationTray::ShowPopups() { | 312 bool WebNotificationTray::ShowPopups() { |
| 312 if (message_center_bubble()) | 313 if (message_center_bubble()) |
| 313 return false; | 314 return false; |
| 314 | 315 |
| 315 popup_collection_->DoUpdateIfPossible(); | 316 popup_collection_->DoUpdateIfPossible(); |
| 316 return true; | 317 return true; |
| 317 } | 318 } |
| 318 | 319 |
| 319 void WebNotificationTray::HidePopups() { | 320 void WebNotificationTray::HidePopups() { |
| 320 DCHECK(popup_collection_.get()); | 321 DCHECK(popup_collection_.get()); |
| 321 popup_collection_->MarkAllPopupsShown(); | 322 popup_collection_->MarkAllPopupsShown(); |
| 322 } | 323 } |
| 323 | 324 |
| 324 // Private methods. | 325 // Private methods. |
| 325 | 326 |
| 326 bool WebNotificationTray::ShouldShowMessageCenter() { | 327 bool WebNotificationTray::ShouldShowMessageCenter() { |
| 327 return !(status_area_widget()->system_tray() && | 328 return !(status_area_widget_->system_tray() && |
| 328 status_area_widget()->system_tray()->HasNotificationBubble()); | 329 status_area_widget_->system_tray()->HasNotificationBubble()); |
| 329 } | 330 } |
| 330 | 331 |
| 331 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { | 332 bool WebNotificationTray::ShouldBlockShelfAutoHide() const { |
| 332 return should_block_shelf_auto_hide_; | 333 return should_block_shelf_auto_hide_; |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { | 336 bool WebNotificationTray::IsMessageCenterBubbleVisible() const { |
| 336 return (message_center_bubble() && | 337 return (message_center_bubble() && |
| 337 message_center_bubble()->bubble()->IsVisible()); | 338 message_center_bubble()->bubble()->IsVisible()); |
| 338 } | 339 } |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 499 button_->SetUnreadCount(message_center->UnreadNotificationCount()); | 500 button_->SetUnreadCount(message_center->UnreadNotificationCount()); |
| 500 if (IsMessageCenterBubbleVisible()) | 501 if (IsMessageCenterBubbleVisible()) |
| 501 button_->SetState(views::CustomButton::STATE_PRESSED); | 502 button_->SetState(views::CustomButton::STATE_PRESSED); |
| 502 else | 503 else |
| 503 button_->SetState(views::CustomButton::STATE_NORMAL); | 504 button_->SetState(views::CustomButton::STATE_NORMAL); |
| 504 | 505 |
| 505 SetVisible(IsLoggedIn()); | 506 SetVisible(IsLoggedIn()); |
| 506 Layout(); | 507 Layout(); |
| 507 SchedulePaint(); | 508 SchedulePaint(); |
| 508 if (IsLoggedIn()) | 509 if (IsLoggedIn()) |
| 509 status_area_widget()->system_tray()->SetNextFocusableView(this); | 510 status_area_widget_->system_tray()->SetNextFocusableView(this); |
| 510 } | 511 } |
| 511 | 512 |
| 512 void WebNotificationTray::ClickedOutsideBubble() { | 513 void WebNotificationTray::ClickedOutsideBubble() { |
| 513 // Only hide the message center | 514 // Only hide the message center |
| 514 if (!message_center_bubble()) | 515 if (!message_center_bubble()) |
| 515 return; | 516 return; |
| 516 | 517 |
| 517 message_center_tray_->HideMessageCenterBubble(); | 518 message_center_tray_->HideMessageCenterBubble(); |
| 518 } | 519 } |
| 519 | 520 |
| 520 message_center::MessageCenter* WebNotificationTray::message_center() const { | 521 message_center::MessageCenter* WebNotificationTray::message_center() const { |
| 521 return message_center_tray_->message_center(); | 522 return message_center_tray_->message_center(); |
| 522 } | 523 } |
| 523 | 524 |
| 524 bool WebNotificationTray::IsLoggedIn() const { | 525 bool WebNotificationTray::IsLoggedIn() const { |
| 525 return status_area_widget()->login_status() != LoginStatus::NOT_LOGGED_IN && | 526 WmShell* shell = WmShell::Get(); |
| 526 !WmShell::Get()->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); | 527 // TODO(jamescook): Should this also check LoginState::LOCKED? |
| 528 return shell->system_tray_delegate()->GetUserLoginStatus() != |
| 529 LoginStatus::NOT_LOGGED_IN && |
| 530 !shell->GetSessionStateDelegate()->IsInSecondaryLoginScreen(); |
| 527 } | 531 } |
| 528 | 532 |
| 529 // Methods for testing | 533 // Methods for testing |
| 530 | 534 |
| 531 bool WebNotificationTray::IsPopupVisible() const { | 535 bool WebNotificationTray::IsPopupVisible() const { |
| 532 return message_center_tray_->popups_visible(); | 536 return message_center_tray_->popups_visible(); |
| 533 } | 537 } |
| 534 | 538 |
| 535 message_center::MessageCenterBubble* | 539 message_center::MessageCenterBubble* |
| 536 WebNotificationTray::GetMessageCenterBubbleForTest() { | 540 WebNotificationTray::GetMessageCenterBubbleForTest() { |
| 537 if (!message_center_bubble()) | 541 if (!message_center_bubble()) |
| 538 return NULL; | 542 return NULL; |
| 539 return static_cast<message_center::MessageCenterBubble*>( | 543 return static_cast<message_center::MessageCenterBubble*>( |
| 540 message_center_bubble()->bubble()); | 544 message_center_bubble()->bubble()); |
| 541 } | 545 } |
| 542 | 546 |
| 543 } // namespace ash | 547 } // namespace ash |
| OLD | NEW |