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/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
436 } | 436 } |
437 | 437 |
438 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 438 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
439 shelf_alignment_ = alignment; | 439 shelf_alignment_ = alignment; |
440 SetBorder(); | 440 SetBorder(); |
441 tray_container_->SetAlignment(alignment); | 441 tray_container_->SetAlignment(alignment); |
442 } | 442 } |
443 | 443 |
444 void TrayBackgroundView::SetBorder() { | 444 void TrayBackgroundView::SetBorder() { |
445 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 445 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
446 | 446 // Tray views are laid out right-to-left or bottom-to-top |
| 447 bool on_edge = (this == parent->child_at(0)); |
| 448 int left_edge, top_edge, right_edge, bottom_edge; |
447 if (ash::switches::UseAlternateShelfLayout()) { | 449 if (ash::switches::UseAlternateShelfLayout()) { |
448 set_border(views::Border::CreateEmptyBorder( | 450 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
449 0, | 451 top_edge = ShelfLayoutManager::kShelfItemInset; |
450 0, | 452 left_edge = 0; |
451 ShelfLayoutManager::kAutoHideSize, | 453 bottom_edge = ShelfLayoutManager::GetPreferredShelfSize() - |
452 0)); | 454 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); |
| 455 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
| 456 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
| 457 top_edge = 0; |
| 458 left_edge = ShelfLayoutManager::GetPreferredShelfSize() - |
| 459 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); |
| 460 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
| 461 right_edge = ShelfLayoutManager::kShelfItemInset; |
| 462 } else { // SHELF_ALIGNMENT_RIGHT |
| 463 top_edge = 0; |
| 464 left_edge = ShelfLayoutManager::kShelfItemInset; |
| 465 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0; |
| 466 right_edge = ShelfLayoutManager::GetPreferredShelfSize() - |
| 467 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight(); |
| 468 } |
453 } else { | 469 } else { |
454 // Tray views are laid out right-to-left or bottom-to-top | |
455 int on_edge = (this == parent->child_at(0)); | |
456 // Change the border padding for different shelf alignment. | 470 // Change the border padding for different shelf alignment. |
457 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 471 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
458 set_border(views::Border::CreateEmptyBorder( | 472 top_edge = 0; |
459 0, 0, | 473 left_edge = 0; |
460 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : | 474 bottom_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment : |
461 kPaddingFromBottomOfScreenBottomAlignment - 1, | 475 kPaddingFromBottomOfScreenBottomAlignment - 1; |
462 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); | 476 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0; |
463 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) { | 477 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) { |
464 set_border(views::Border::CreateEmptyBorder( | 478 top_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment : |
465 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : | 479 kPaddingFromBottomOfScreenBottomAlignment - 1; |
466 kPaddingFromBottomOfScreenBottomAlignment - 1, | 480 left_edge = 0; |
467 0, 0, | 481 bottom_edge = 0; |
468 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); | 482 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0; |
469 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 483 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
470 set_border(views::Border::CreateEmptyBorder( | 484 top_edge = 0; |
471 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, | 485 left_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment; |
472 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 486 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0; |
473 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); | 487 right_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment; |
474 } else { | 488 } else { |
475 set_border(views::Border::CreateEmptyBorder( | 489 top_edge = 0; |
476 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | 490 left_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment; |
477 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 491 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0; |
478 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | 492 right_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment; |
479 } | 493 } |
480 } | 494 } |
| 495 set_border(views::Border::CreateEmptyBorder( |
| 496 top_edge, left_edge, bottom_edge, right_edge)); |
481 } | 497 } |
482 | 498 |
483 void TrayBackgroundView::InitializeBubbleAnimations( | 499 void TrayBackgroundView::InitializeBubbleAnimations( |
484 views::Widget* bubble_widget) { | 500 views::Widget* bubble_widget) { |
485 views::corewm::SetWindowVisibilityAnimationType( | 501 views::corewm::SetWindowVisibilityAnimationType( |
486 bubble_widget->GetNativeWindow(), | 502 bubble_widget->GetNativeWindow(), |
487 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 503 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
488 views::corewm::SetWindowVisibilityAnimationTransition( | 504 views::corewm::SetWindowVisibilityAnimationTransition( |
489 bubble_widget->GetNativeWindow(), | 505 bubble_widget->GetNativeWindow(), |
490 views::corewm::ANIMATE_HIDE); | 506 views::corewm::ANIMATE_HIDE); |
(...skipping 11 matching lines...) Expand all Loading... |
502 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( | 518 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( |
503 views::Widget* anchor_widget, | 519 views::Widget* anchor_widget, |
504 TrayBubbleView::AnchorType anchor_type, | 520 TrayBubbleView::AnchorType anchor_type, |
505 TrayBubbleView::AnchorAlignment anchor_alignment) const { | 521 TrayBubbleView::AnchorAlignment anchor_alignment) const { |
506 gfx::Rect rect; | 522 gfx::Rect rect; |
507 if (anchor_widget && anchor_widget->IsVisible()) { | 523 if (anchor_widget && anchor_widget->IsVisible()) { |
508 rect = anchor_widget->GetWindowBoundsInScreen(); | 524 rect = anchor_widget->GetWindowBoundsInScreen(); |
509 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | 525 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { |
510 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 526 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
511 bool rtl = base::i18n::IsRTL(); | 527 bool rtl = base::i18n::IsRTL(); |
512 rect.Inset( | 528 if (!ash::switches::UseAlternateShelfLayout()) { |
513 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, | 529 rect.Inset( |
514 kTrayBubbleAnchorTopInsetBottomAnchor, | 530 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, |
515 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, | 531 kTrayBubbleAnchorTopInsetBottomAnchor, |
516 kPaddingFromBottomOfScreenBottomAlignment); | 532 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, |
| 533 kPaddingFromBottomOfScreenBottomAlignment); |
| 534 } else { |
| 535 rect.Inset( |
| 536 rtl ? kAlternateLayoutBubblePaddingHorizontalSide : 0, |
| 537 kAlternateLayoutBubblePaddingHorizontalBottom, |
| 538 rtl ? 0 : kAlternateLayoutBubblePaddingHorizontalSide, |
| 539 0); |
| 540 } |
517 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | 541 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { |
518 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5, | 542 if (!ash::switches::UseAlternateShelfLayout()) { |
519 kPaddingFromBottomOfScreenVerticalAlignment); | 543 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5, |
| 544 kPaddingFromBottomOfScreenVerticalAlignment); |
| 545 } else { |
| 546 rect.Inset(0, 0, kAlternateLayoutBubblePaddingVerticalSide + 4, |
| 547 kAlternateLayoutBubblePaddingVerticalBottom); |
| 548 } |
520 } else { | 549 } else { |
521 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1, | 550 if (!ash::switches::UseAlternateShelfLayout()) { |
522 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | 551 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1, |
| 552 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); |
| 553 } else { |
| 554 rect.Inset(kAlternateLayoutBubblePaddingVerticalSide, 0, 0, |
| 555 kAlternateLayoutBubblePaddingVerticalBottom); |
| 556 } |
523 } | 557 } |
524 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { | 558 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { |
525 // Invert the offsets to align with the bubble below. | 559 // Invert the offsets to align with the bubble below. |
526 // Note that with the alternate shelf layout the tips are not shown and | 560 // Note that with the alternate shelf layout the tips are not shown and |
527 // the offsets for left and right alignment do not need to be applied. | 561 // the offsets for left and right alignment do not need to be applied. |
528 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ? | 562 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ? |
529 0 : kPaddingFromInnerEdgeOfLauncherVerticalAlignment; | 563 0 : |
530 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | 564 kPaddingFromInnerEdgeOfLauncherVerticalAlignment; |
531 rect.Inset(vertical_alignment, | 565 int horizontal_alignment = ash::switches::UseAlternateShelfLayout() ? |
532 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | 566 kAlternateLayoutBubblePaddingVerticalBottom : |
533 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | 567 kPaddingFromBottomOfScreenVerticalAlignment; |
534 rect.Inset(0, 0, vertical_alignment, | 568 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) |
535 kPaddingFromBottomOfScreenVerticalAlignment); | 569 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); |
536 } | 570 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) |
| 571 rect.Inset(0, 0, vertical_alignment, horizontal_alignment); |
537 } | 572 } |
538 } | 573 } |
539 | 574 |
540 // TODO(jennyz): May need to add left/right alignment in the following code. | 575 // TODO(jennyz): May need to add left/right alignment in the following code. |
541 if (rect.IsEmpty()) { | 576 if (rect.IsEmpty()) { |
542 aura::RootWindow* target_root = anchor_widget ? | 577 aura::RootWindow* target_root = anchor_widget ? |
543 anchor_widget->GetNativeView()->GetRootWindow() : | 578 anchor_widget->GetNativeView()->GetRootWindow() : |
544 Shell::GetPrimaryRootWindow(); | 579 Shell::GetPrimaryRootWindow(); |
545 rect = target_root->bounds(); | 580 rect = target_root->bounds(); |
546 rect = gfx::Rect( | 581 rect = gfx::Rect( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
593 ash::internal::ShelfLayoutManager* shelf = | 628 ash::internal::ShelfLayoutManager* shelf = |
594 ShelfLayoutManager::ForLauncher(root_window); | 629 ShelfLayoutManager::ForLauncher(root_window); |
595 bubble_view->SetArrowPaintType( | 630 bubble_view->SetArrowPaintType( |
596 (shelf && shelf->IsVisible()) ? | 631 (shelf && shelf->IsVisible()) ? |
597 views::BubbleBorder::PAINT_NORMAL : | 632 views::BubbleBorder::PAINT_NORMAL : |
598 views::BubbleBorder::PAINT_TRANSPARENT); | 633 views::BubbleBorder::PAINT_TRANSPARENT); |
599 } | 634 } |
600 | 635 |
601 } // namespace internal | 636 } // namespace internal |
602 } // namespace ash | 637 } // namespace ash |
OLD | NEW |