| 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/tray/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "ash/shelf/shelf_layout_manager.h" | 8 #include "ash/shelf/shelf_layout_manager.h" |
| 9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
| 10 #include "ash/shell/panel_window.h" | 10 #include "ash/shell/panel_window.h" |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 206 TrayBubbleView::InitParams::kArrowDefaultOffset); | 206 TrayBubbleView::InitParams::kArrowDefaultOffset); |
| 207 } | 207 } |
| 208 | 208 |
| 209 void SystemTray::ShowDetailedView(SystemTrayItem* item, | 209 void SystemTray::ShowDetailedView(SystemTrayItem* item, |
| 210 int close_delay, | 210 int close_delay, |
| 211 bool activate, | 211 bool activate, |
| 212 BubbleCreationType creation_type) { | 212 BubbleCreationType creation_type) { |
| 213 std::vector<SystemTrayItem*> items; | 213 std::vector<SystemTrayItem*> items; |
| 214 items.push_back(item); | 214 items.push_back(item); |
| 215 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item)); | 215 ShowItems(items, true, activate, creation_type, GetTrayXOffset(item)); |
| 216 if (system_bubble_.get()) | 216 if (system_bubble_) |
| 217 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); | 217 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); |
| 218 } | 218 } |
| 219 | 219 |
| 220 void SystemTray::SetDetailedViewCloseDelay(int close_delay) { | 220 void SystemTray::SetDetailedViewCloseDelay(int close_delay) { |
| 221 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED)) | 221 if (HasSystemBubbleType(SystemTrayBubble::BUBBLE_TYPE_DETAILED)) |
| 222 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); | 222 system_bubble_->bubble()->StartAutoCloseTimer(close_delay); |
| 223 } | 223 } |
| 224 | 224 |
| 225 void SystemTray::HideDetailedView(SystemTrayItem* item) { | 225 void SystemTray::HideDetailedView(SystemTrayItem* item) { |
| 226 if (item != detailed_item_) | 226 if (item != detailed_item_) |
| (...skipping 10 matching lines...) Expand all Loading... |
| 237 UpdateNotificationBubble(); | 237 UpdateNotificationBubble(); |
| 238 } | 238 } |
| 239 | 239 |
| 240 void SystemTray::HideNotificationView(SystemTrayItem* item) { | 240 void SystemTray::HideNotificationView(SystemTrayItem* item) { |
| 241 std::vector<SystemTrayItem*>::iterator found_iter = | 241 std::vector<SystemTrayItem*>::iterator found_iter = |
| 242 std::find(notification_items_.begin(), notification_items_.end(), item); | 242 std::find(notification_items_.begin(), notification_items_.end(), item); |
| 243 if (found_iter == notification_items_.end()) | 243 if (found_iter == notification_items_.end()) |
| 244 return; | 244 return; |
| 245 notification_items_.erase(found_iter); | 245 notification_items_.erase(found_iter); |
| 246 // Only update the notification bubble if visible (i.e. don't create one). | 246 // Only update the notification bubble if visible (i.e. don't create one). |
| 247 if (notification_bubble_.get()) | 247 if (notification_bubble_) |
| 248 UpdateNotificationBubble(); | 248 UpdateNotificationBubble(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { | 251 void SystemTray::UpdateAfterLoginStatusChange(user::LoginStatus login_status) { |
| 252 DestroySystemBubble(); | 252 DestroySystemBubble(); |
| 253 UpdateNotificationBubble(); | 253 UpdateNotificationBubble(); |
| 254 | 254 |
| 255 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 255 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 256 it != items_.end(); | 256 it != items_.end(); |
| 257 ++it) { | 257 ++it) { |
| 258 (*it)->UpdateAfterLoginStatusChange(login_status); | 258 (*it)->UpdateAfterLoginStatusChange(login_status); |
| 259 } | 259 } |
| 260 | 260 |
| 261 SetVisible(true); | 261 SetVisible(true); |
| 262 PreferredSizeChanged(); | 262 PreferredSizeChanged(); |
| 263 } | 263 } |
| 264 | 264 |
| 265 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 265 void SystemTray::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 266 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 266 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 267 it != items_.end(); | 267 it != items_.end(); |
| 268 ++it) { | 268 ++it) { |
| 269 (*it)->UpdateAfterShelfAlignmentChange(alignment); | 269 (*it)->UpdateAfterShelfAlignmentChange(alignment); |
| 270 } | 270 } |
| 271 } | 271 } |
| 272 | 272 |
| 273 void SystemTray::SetHideNotifications(bool hide_notifications) { | 273 void SystemTray::SetHideNotifications(bool hide_notifications) { |
| 274 if (notification_bubble_.get()) | 274 if (notification_bubble_) |
| 275 notification_bubble_->bubble()->SetVisible(!hide_notifications); | 275 notification_bubble_->bubble()->SetVisible(!hide_notifications); |
| 276 hide_notifications_ = hide_notifications; | 276 hide_notifications_ = hide_notifications; |
| 277 } | 277 } |
| 278 | 278 |
| 279 bool SystemTray::ShouldShowLauncher() const { | 279 bool SystemTray::ShouldShowLauncher() const { |
| 280 return system_bubble_.get() && system_bubble_->bubble()->ShouldShowLauncher(); | 280 return system_bubble_.get() && system_bubble_->bubble()->ShouldShowLauncher(); |
| 281 } | 281 } |
| 282 | 282 |
| 283 bool SystemTray::HasSystemBubble() const { | 283 bool SystemTray::HasSystemBubble() const { |
| 284 return system_bubble_.get() != NULL; | 284 return system_bubble_.get() != NULL; |
| 285 } | 285 } |
| 286 | 286 |
| 287 bool SystemTray::HasNotificationBubble() const { | 287 bool SystemTray::HasNotificationBubble() const { |
| 288 return notification_bubble_.get() != NULL; | 288 return notification_bubble_.get() != NULL; |
| 289 } | 289 } |
| 290 | 290 |
| 291 internal::SystemTrayBubble* SystemTray::GetSystemBubble() { | 291 internal::SystemTrayBubble* SystemTray::GetSystemBubble() { |
| 292 if (!system_bubble_.get()) | 292 if (!system_bubble_) |
| 293 return NULL; | 293 return NULL; |
| 294 return system_bubble_->bubble(); | 294 return system_bubble_->bubble(); |
| 295 } | 295 } |
| 296 | 296 |
| 297 bool SystemTray::IsAnyBubbleVisible() const { | 297 bool SystemTray::IsAnyBubbleVisible() const { |
| 298 return ((system_bubble_.get() && | 298 return ((system_bubble_.get() && |
| 299 system_bubble_->bubble()->IsVisible()) || | 299 system_bubble_->bubble()->IsVisible()) || |
| 300 (notification_bubble_.get() && | 300 (notification_bubble_.get() && |
| 301 notification_bubble_->bubble()->IsVisible())); | 301 notification_bubble_->bubble()->IsVisible())); |
| 302 } | 302 } |
| 303 | 303 |
| 304 bool SystemTray::IsMouseInNotificationBubble() const { | 304 bool SystemTray::IsMouseInNotificationBubble() const { |
| 305 if (!notification_bubble_.get()) | 305 if (!notification_bubble_) |
| 306 return false; | 306 return false; |
| 307 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( | 307 return notification_bubble_->bubble_view()->GetBoundsInScreen().Contains( |
| 308 Shell::GetScreen()->GetCursorScreenPoint()); | 308 Shell::GetScreen()->GetCursorScreenPoint()); |
| 309 } | 309 } |
| 310 | 310 |
| 311 bool SystemTray::CloseSystemBubbleForTest() const { | 311 bool SystemTray::CloseSystemBubbleForTest() const { |
| 312 if (!system_bubble_.get()) | 312 if (!system_bubble_) |
| 313 return false; | 313 return false; |
| 314 system_bubble_->bubble()->Close(); | 314 system_bubble_->bubble()->Close(); |
| 315 return true; | 315 return true; |
| 316 } | 316 } |
| 317 | 317 |
| 318 bool SystemTray::CloseNotificationBubbleForTest() const { | 318 bool SystemTray::CloseNotificationBubbleForTest() const { |
| 319 if (!notification_bubble_.get()) | 319 if (!notification_bubble_) |
| 320 return false; | 320 return false; |
| 321 notification_bubble_->bubble()->Close(); | 321 notification_bubble_->bubble()->Close(); |
| 322 return true; | 322 return true; |
| 323 } | 323 } |
| 324 | 324 |
| 325 // Private methods. | 325 // Private methods. |
| 326 | 326 |
| 327 bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { | 327 bool SystemTray::HasSystemBubbleType(SystemTrayBubble::BubbleType type) { |
| 328 DCHECK(type != SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); | 328 DCHECK(type != SystemTrayBubble::BUBBLE_TYPE_NOTIFICATION); |
| 329 return system_bubble_.get() && system_bubble_->bubble_type() == type; | 329 return system_bubble_.get() && system_bubble_->bubble_type() == type; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 } | 467 } |
| 468 | 468 |
| 469 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | 469 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 470 if (alignment == shelf_alignment()) | 470 if (alignment == shelf_alignment()) |
| 471 return; | 471 return; |
| 472 internal::TrayBackgroundView::SetShelfAlignment(alignment); | 472 internal::TrayBackgroundView::SetShelfAlignment(alignment); |
| 473 UpdateAfterShelfAlignmentChange(alignment); | 473 UpdateAfterShelfAlignmentChange(alignment); |
| 474 // Destroy any existing bubble so that it is rebuilt correctly. | 474 // Destroy any existing bubble so that it is rebuilt correctly. |
| 475 system_bubble_.reset(); | 475 system_bubble_.reset(); |
| 476 // Rebuild any notification bubble. | 476 // Rebuild any notification bubble. |
| 477 if (notification_bubble_.get()) { | 477 if (notification_bubble_) { |
| 478 notification_bubble_.reset(); | 478 notification_bubble_.reset(); |
| 479 UpdateNotificationBubble(); | 479 UpdateNotificationBubble(); |
| 480 } | 480 } |
| 481 } | 481 } |
| 482 | 482 |
| 483 void SystemTray::AnchorUpdated() { | 483 void SystemTray::AnchorUpdated() { |
| 484 if (notification_bubble_.get()) { | 484 if (notification_bubble_) { |
| 485 notification_bubble_->bubble_view()->UpdateBubble(); | 485 notification_bubble_->bubble_view()->UpdateBubble(); |
| 486 // Ensure that the notification buble is above the launcher/status area. | 486 // Ensure that the notification buble is above the launcher/status area. |
| 487 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 487 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 488 UpdateBubbleViewArrow(notification_bubble_->bubble_view()); | 488 UpdateBubbleViewArrow(notification_bubble_->bubble_view()); |
| 489 } | 489 } |
| 490 if (system_bubble_.get()) { | 490 if (system_bubble_) { |
| 491 system_bubble_->bubble_view()->UpdateBubble(); | 491 system_bubble_->bubble_view()->UpdateBubble(); |
| 492 UpdateBubbleViewArrow(system_bubble_->bubble_view()); | 492 UpdateBubbleViewArrow(system_bubble_->bubble_view()); |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 | 495 |
| 496 base::string16 SystemTray::GetAccessibleNameForTray() { | 496 base::string16 SystemTray::GetAccessibleNameForTray() { |
| 497 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 497 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
| 498 } | 498 } |
| 499 | 499 |
| 500 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { | 500 void SystemTray::HideBubbleWithView(const TrayBubbleView* bubble_view) { |
| 501 if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { | 501 if (system_bubble_.get() && bubble_view == system_bubble_->bubble_view()) { |
| 502 DestroySystemBubble(); | 502 DestroySystemBubble(); |
| 503 UpdateNotificationBubble(); // State changed, re-create notifications. | 503 UpdateNotificationBubble(); // State changed, re-create notifications. |
| 504 GetShelfLayoutManager()->UpdateAutoHideState(); | 504 GetShelfLayoutManager()->UpdateAutoHideState(); |
| 505 } else if (notification_bubble_.get() && | 505 } else if (notification_bubble_.get() && |
| 506 bubble_view == notification_bubble_->bubble_view()) { | 506 bubble_view == notification_bubble_->bubble_view()) { |
| 507 DestroyNotificationBubble(); | 507 DestroyNotificationBubble(); |
| 508 } | 508 } |
| 509 } | 509 } |
| 510 | 510 |
| 511 bool SystemTray::ClickedOutsideBubble() { | 511 bool SystemTray::ClickedOutsideBubble() { |
| 512 if (!system_bubble_.get()) | 512 if (!system_bubble_) |
| 513 return false; | 513 return false; |
| 514 HideBubbleWithView(system_bubble_->bubble_view()); | 514 HideBubbleWithView(system_bubble_->bubble_view()); |
| 515 return true; | 515 return true; |
| 516 } | 516 } |
| 517 | 517 |
| 518 void SystemTray::BubbleViewDestroyed() { | 518 void SystemTray::BubbleViewDestroyed() { |
| 519 if (system_bubble_.get()) { | 519 if (system_bubble_) { |
| 520 system_bubble_->bubble()->DestroyItemViews(); | 520 system_bubble_->bubble()->DestroyItemViews(); |
| 521 system_bubble_->bubble()->BubbleViewDestroyed(); | 521 system_bubble_->bubble()->BubbleViewDestroyed(); |
| 522 } | 522 } |
| 523 } | 523 } |
| 524 | 524 |
| 525 void SystemTray::OnMouseEnteredView() { | 525 void SystemTray::OnMouseEnteredView() { |
| 526 if (system_bubble_.get()) | 526 if (system_bubble_) |
| 527 system_bubble_->bubble()->StopAutoCloseTimer(); | 527 system_bubble_->bubble()->StopAutoCloseTimer(); |
| 528 } | 528 } |
| 529 | 529 |
| 530 void SystemTray::OnMouseExitedView() { | 530 void SystemTray::OnMouseExitedView() { |
| 531 if (system_bubble_.get()) | 531 if (system_bubble_) |
| 532 system_bubble_->bubble()->RestartAutoCloseTimer(); | 532 system_bubble_->bubble()->RestartAutoCloseTimer(); |
| 533 } | 533 } |
| 534 | 534 |
| 535 base::string16 SystemTray::GetAccessibleNameForBubble() { | 535 base::string16 SystemTray::GetAccessibleNameForBubble() { |
| 536 return GetAccessibleNameForTray(); | 536 return GetAccessibleNameForTray(); |
| 537 } | 537 } |
| 538 | 538 |
| 539 gfx::Rect SystemTray::GetAnchorRect( | 539 gfx::Rect SystemTray::GetAnchorRect( |
| 540 views::Widget* anchor_widget, | 540 views::Widget* anchor_widget, |
| 541 TrayBubbleView::AnchorType anchor_type, | 541 TrayBubbleView::AnchorType anchor_type, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 563 ConvertPointToWidget(this, &point); | 563 ConvertPointToWidget(this, &point); |
| 564 arrow_offset = point.x(); | 564 arrow_offset = point.x(); |
| 565 } | 565 } |
| 566 } | 566 } |
| 567 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 567 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
| 568 } | 568 } |
| 569 return true; | 569 return true; |
| 570 } | 570 } |
| 571 | 571 |
| 572 } // namespace ash | 572 } // namespace ash |
| OLD | NEW |