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