| 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_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell_window_ids.h" | 8 #include "ash/shell_window_ids.h" |
| 9 #include "ash/system/tray/system_tray.h" | 9 #include "ash/system/tray/system_tray.h" |
| 10 #include "ash/system/tray/system_tray_delegate.h" | 10 #include "ash/system/tray/system_tray_delegate.h" |
| (...skipping 30 matching lines...) Expand all Loading... |
| 41 const int kSystemTrayBubbleVerticalInset = 1; | 41 const int kSystemTrayBubbleVerticalInset = 1; |
| 42 | 42 |
| 43 const int kArrowHeight = 10; | 43 const int kArrowHeight = 10; |
| 44 const int kArrowWidth = 20; | 44 const int kArrowWidth = 20; |
| 45 const int kArrowPaddingFromRight = 20; | 45 const int kArrowPaddingFromRight = 20; |
| 46 const int kArrowPaddingFromBottom = 17; | 46 const int kArrowPaddingFromBottom = 17; |
| 47 const int kMinArrowOffset = 12; | 47 const int kMinArrowOffset = 12; |
| 48 | 48 |
| 49 const int kAnimationDurationForPopupMS = 200; | 49 const int kAnimationDurationForPopupMS = 200; |
| 50 | 50 |
| 51 // Normally a detailed view is the same size as the default view. However, |
| 52 // when showing a detailed view directly (e.g. clicking on a notification), |
| 53 // we may not know the height of the default view, or the default view may |
| 54 // be too short, so we use this as a default and minimum height for any |
| 55 // detailed view. |
| 56 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
| 57 |
| 51 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); | 58 const SkColor kShadowColor = SkColorSetARGB(0xff, 0, 0, 0); |
| 52 | 59 |
| 53 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, | 60 void DrawBlurredShadowAroundView(gfx::Canvas* canvas, |
| 54 int top, | 61 int top, |
| 55 int bottom, | 62 int bottom, |
| 56 int width, | 63 int width, |
| 57 const gfx::Insets& inset) { | 64 const gfx::Insets& inset) { |
| 58 SkPath path; | 65 SkPath path; |
| 59 path.incReserve(4); | 66 path.incReserve(4); |
| 60 path.moveTo(SkIntToScalar(inset.left() + kShadowThickness), | 67 path.moveTo(SkIntToScalar(inset.left() + kShadowThickness), |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 | 263 |
| 257 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); | 264 DISALLOW_COPY_AND_ASSIGN(SystemTrayBubbleBorder); |
| 258 }; | 265 }; |
| 259 | 266 |
| 260 } // namespace | 267 } // namespace |
| 261 | 268 |
| 262 namespace internal { | 269 namespace internal { |
| 263 | 270 |
| 264 // SystemTrayBubbleView | 271 // SystemTrayBubbleView |
| 265 | 272 |
| 266 SystemTrayBubbleView::SystemTrayBubbleView(views::View* anchor, | 273 SystemTrayBubbleView::SystemTrayBubbleView( |
| 274 views::View* anchor, |
| 267 views::BubbleBorder::ArrowLocation arrow_location, | 275 views::BubbleBorder::ArrowLocation arrow_location, |
| 268 SystemTrayBubble* host, | 276 SystemTrayBubble* host, |
| 269 bool can_activate) | 277 bool can_activate) |
| 270 : views::BubbleDelegateView(anchor, arrow_location), | 278 : views::BubbleDelegateView(anchor, arrow_location), |
| 271 host_(host), | 279 host_(host), |
| 272 can_activate_(can_activate) { | 280 can_activate_(can_activate), |
| 281 max_height_(0) { |
| 273 set_margin(0); | 282 set_margin(0); |
| 274 set_parent_window(ash::Shell::GetInstance()->GetContainer( | 283 set_parent_window(ash::Shell::GetInstance()->GetContainer( |
| 275 ash::internal::kShellWindowId_SettingBubbleContainer)); | 284 ash::internal::kShellWindowId_SettingBubbleContainer)); |
| 276 set_notify_enter_exit_on_child(true); | 285 set_notify_enter_exit_on_child(true); |
| 277 } | 286 } |
| 278 | 287 |
| 279 SystemTrayBubbleView::~SystemTrayBubbleView() { | 288 SystemTrayBubbleView::~SystemTrayBubbleView() { |
| 280 // Inform host items (models) that their views are being destroyed. | 289 // Inform host items (models) that their views are being destroyed. |
| 281 if (host_) | 290 if (host_) |
| 282 host_->DestroyItemViews(); | 291 host_->DestroyItemViews(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); | 338 IDS_ASH_STATUS_TRAY_ACCESSIBLE_NAME); |
| 330 } | 339 } |
| 331 } | 340 } |
| 332 | 341 |
| 333 bool SystemTrayBubbleView::CanActivate() const { | 342 bool SystemTrayBubbleView::CanActivate() const { |
| 334 return can_activate_; | 343 return can_activate_; |
| 335 } | 344 } |
| 336 | 345 |
| 337 gfx::Size SystemTrayBubbleView::GetPreferredSize() { | 346 gfx::Size SystemTrayBubbleView::GetPreferredSize() { |
| 338 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); | 347 gfx::Size size = views::BubbleDelegateView::GetPreferredSize(); |
| 339 return gfx::Size(kTrayPopupWidth, size.height()); | 348 int height = size.height(); |
| 349 if (max_height_ != 0 && height > max_height_) |
| 350 height = max_height_; |
| 351 return gfx::Size(kTrayPopupWidth, height); |
| 340 } | 352 } |
| 341 | 353 |
| 342 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { | 354 void SystemTrayBubbleView::OnMouseEntered(const views::MouseEvent& event) { |
| 343 if (host_) | 355 if (host_) |
| 344 host_->StopAutoCloseTimer(); | 356 host_->StopAutoCloseTimer(); |
| 345 } | 357 } |
| 346 | 358 |
| 347 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { | 359 void SystemTrayBubbleView::OnMouseExited(const views::MouseEvent& event) { |
| 348 if (host_) | 360 if (host_) |
| 349 host_->RestartAutoCloseTimer(); | 361 host_->RestartAutoCloseTimer(); |
| 350 } | 362 } |
| 351 | 363 |
| 352 // SystemTrayBubble::InitParams | 364 // SystemTrayBubble::InitParams |
| 353 SystemTrayBubble::InitParams::InitParams( | 365 SystemTrayBubble::InitParams::InitParams( |
| 354 SystemTrayBubble::AnchorType anchor_type, | 366 SystemTrayBubble::AnchorType anchor_type, |
| 355 ShelfAlignment shelf_alignment) | 367 ShelfAlignment shelf_alignment) |
| 356 : anchor(NULL), | 368 : anchor(NULL), |
| 357 anchor_type(anchor_type), | 369 anchor_type(anchor_type), |
| 358 can_activate(false), | 370 can_activate(false), |
| 359 login_status(ash::user::LOGGED_IN_NONE), | 371 login_status(ash::user::LOGGED_IN_NONE), |
| 360 arrow_offset( | 372 arrow_offset( |
| 361 (shelf_alignment == SHELF_ALIGNMENT_BOTTOM ? | 373 (shelf_alignment == SHELF_ALIGNMENT_BOTTOM ? |
| 362 kArrowPaddingFromRight : kArrowPaddingFromBottom) | 374 kArrowPaddingFromRight : kArrowPaddingFromBottom) |
| 363 + kArrowWidth / 2) { | 375 + kArrowWidth / 2), |
| 376 max_height(0) { |
| 364 } | 377 } |
| 365 | 378 |
| 366 // SystemTrayBubble | 379 // SystemTrayBubble |
| 367 | 380 |
| 368 SystemTrayBubble::SystemTrayBubble( | 381 SystemTrayBubble::SystemTrayBubble( |
| 369 ash::SystemTray* tray, | 382 ash::SystemTray* tray, |
| 370 const std::vector<ash::SystemTrayItem*>& items, | 383 const std::vector<ash::SystemTrayItem*>& items, |
| 371 BubbleType bubble_type) | 384 BubbleType bubble_type) |
| 372 : tray_(tray), | 385 : tray_(tray), |
| 373 bubble_view_(NULL), | 386 bubble_view_(NULL), |
| (...skipping 24 matching lines...) Expand all Loading... |
| 398 const std::vector<ash::SystemTrayItem*>& items, | 411 const std::vector<ash::SystemTrayItem*>& items, |
| 399 BubbleType bubble_type) { | 412 BubbleType bubble_type) { |
| 400 DestroyItemViews(); | 413 DestroyItemViews(); |
| 401 bubble_view_->RemoveAllChildViews(true); | 414 bubble_view_->RemoveAllChildViews(true); |
| 402 | 415 |
| 403 items_ = items; | 416 items_ = items; |
| 404 bubble_type_ = bubble_type; | 417 bubble_type_ = bubble_type; |
| 405 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); | 418 CreateItemViews(Shell::GetInstance()->tray_delegate()->GetUserLoginStatus()); |
| 406 bubble_widget_->GetContentsView()->Layout(); | 419 bubble_widget_->GetContentsView()->Layout(); |
| 407 // Make sure that the bubble is large enough for the default view. | 420 // Make sure that the bubble is large enough for the default view. |
| 408 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) | 421 if (bubble_type_ == BUBBLE_TYPE_DEFAULT) { |
| 422 bubble_view_->set_max_height(0); // Clear max height limit. |
| 409 bubble_view_->SizeToContents(); | 423 bubble_view_->SizeToContents(); |
| 424 } |
| 410 } | 425 } |
| 411 | 426 |
| 412 void SystemTrayBubble::InitView(const InitParams& init_params) { | 427 void SystemTrayBubble::InitView(const InitParams& init_params) { |
| 413 DCHECK(bubble_view_ == NULL); | 428 DCHECK(bubble_view_ == NULL); |
| 414 anchor_type_ = init_params.anchor_type; | 429 anchor_type_ = init_params.anchor_type; |
| 415 views::BubbleBorder::ArrowLocation arrow_location; | 430 views::BubbleBorder::ArrowLocation arrow_location; |
| 416 if (anchor_type_ == ANCHOR_TYPE_TRAY) { | 431 if (anchor_type_ == ANCHOR_TYPE_TRAY) { |
| 417 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 432 if (tray_->shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
| 418 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; | 433 arrow_location = views::BubbleBorder::BOTTOM_RIGHT; |
| 419 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 434 } else if (tray_->shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
| 420 arrow_location = views::BubbleBorder::LEFT_BOTTOM; | 435 arrow_location = views::BubbleBorder::LEFT_BOTTOM; |
| 421 } else { | 436 } else { |
| 422 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; | 437 arrow_location = views::BubbleBorder::RIGHT_BOTTOM; |
| 423 } | 438 } |
| 424 } else { | 439 } else { |
| 425 arrow_location = views::BubbleBorder::NONE; | 440 arrow_location = views::BubbleBorder::NONE; |
| 426 } | 441 } |
| 427 bubble_view_ = new SystemTrayBubbleView( | 442 bubble_view_ = new SystemTrayBubbleView( |
| 428 init_params.anchor, arrow_location, this, init_params.can_activate); | 443 init_params.anchor, arrow_location, this, init_params.can_activate); |
| 429 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) | 444 if (bubble_type_ == BUBBLE_TYPE_NOTIFICATION) |
| 430 bubble_view_->set_close_on_deactivate(false); | 445 bubble_view_->set_close_on_deactivate(false); |
| 446 int max_height = init_params.max_height; |
| 447 if (bubble_type_ == BUBBLE_TYPE_DETAILED && |
| 448 max_height < kDetailedBubbleMaxHeight) |
| 449 max_height = kDetailedBubbleMaxHeight; |
| 450 bubble_view_->set_max_height(max_height); |
| 431 | 451 |
| 432 CreateItemViews(init_params.login_status); | 452 CreateItemViews(init_params.login_status); |
| 433 | 453 |
| 434 DCHECK(bubble_widget_ == NULL); | 454 DCHECK(bubble_widget_ == NULL); |
| 435 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); | 455 bubble_widget_ = views::BubbleDelegateView::CreateBubble(bubble_view_); |
| 436 | 456 |
| 437 // Must occur after call to CreateBubble() | 457 // Must occur after call to CreateBubble() |
| 438 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); | 458 bubble_view_->SetAlignment(views::BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE); |
| 439 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); | 459 bubble_widget_->non_client_view()->frame_view()->set_background(NULL); |
| 440 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( | 460 SystemTrayBubbleBorder* bubble_border = new SystemTrayBubbleBorder( |
| (...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 580 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, | 600 void SystemTrayBubble::OnWidgetVisibilityChanged(views::Widget* widget, |
| 581 bool visible) { | 601 bool visible) { |
| 582 if (!visible) | 602 if (!visible) |
| 583 MessageLoopForUI::current()->RemoveObserver(this); | 603 MessageLoopForUI::current()->RemoveObserver(this); |
| 584 else | 604 else |
| 585 MessageLoopForUI::current()->AddObserver(this); | 605 MessageLoopForUI::current()->AddObserver(this); |
| 586 } | 606 } |
| 587 | 607 |
| 588 } // namespace internal | 608 } // namespace internal |
| 589 } // namespace ash | 609 } // namespace ash |
| OLD | NEW |