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 int on_edge = (this == parent->child_at(0)); | |
James Cook
2013/09/18 01:36:07
int -> bool?
| |
447 if (ash::switches::UseAlternateShelfLayout()) { | 448 if (ash::switches::UseAlternateShelfLayout()) { |
448 set_border(views::Border::CreateEmptyBorder( | 449 int inner_edge = ShelfLayoutManager::kShelfItemInset; |
449 0, | 450 int outer_edge = |
450 0, | 451 ShelfLayoutManager::GetPreferredShelfSize() - inner_edge - |
451 ShelfLayoutManager::kAutoHideSize, | 452 GetShelfItemHeight(); |
452 0)); | 453 int leading_edge = 0; |
454 int trailing_edge = on_edge ? kPaddingFromShelf : 0; | |
455 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | |
456 set_border(views::Border::CreateEmptyBorder( | |
457 inner_edge, leading_edge, outer_edge, trailing_edge); | |
458 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | |
459 set_border(views::Border::CreateEmptyBorder( | |
460 leading_edge, outer_edge, trailing_edge, inner_edge)); | |
461 } else { // SHELF_ALIGNMENT_RIGHT | |
462 set_border(views::Border::CreateEmptyBorder( | |
463 leading_edge, | |
464 inner_edge, | |
465 trailing_edge, | |
466 outer_edge)); | |
467 } | |
453 } else { | 468 } 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. | 469 // Change the border padding for different shelf alignment. |
457 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 470 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
458 set_border(views::Border::CreateEmptyBorder( | 471 set_border(views::Border::CreateEmptyBorder( |
459 0, 0, | 472 0, 0, |
460 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : | 473 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : |
461 kPaddingFromBottomOfScreenBottomAlignment - 1, | 474 kPaddingFromBottomOfScreenBottomAlignment - 1, |
462 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); | 475 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); |
463 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) { | 476 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) { |
464 set_border(views::Border::CreateEmptyBorder( | 477 set_border(views::Border::CreateEmptyBorder( |
465 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : | 478 on_edge ? kPaddingFromBottomOfScreenBottomAlignment : |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
502 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( | 515 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( |
503 views::Widget* anchor_widget, | 516 views::Widget* anchor_widget, |
504 TrayBubbleView::AnchorType anchor_type, | 517 TrayBubbleView::AnchorType anchor_type, |
505 TrayBubbleView::AnchorAlignment anchor_alignment) const { | 518 TrayBubbleView::AnchorAlignment anchor_alignment) const { |
506 gfx::Rect rect; | 519 gfx::Rect rect; |
507 if (anchor_widget && anchor_widget->IsVisible()) { | 520 if (anchor_widget && anchor_widget->IsVisible()) { |
508 rect = anchor_widget->GetWindowBoundsInScreen(); | 521 rect = anchor_widget->GetWindowBoundsInScreen(); |
509 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | 522 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { |
510 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 523 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
511 bool rtl = base::i18n::IsRTL(); | 524 bool rtl = base::i18n::IsRTL(); |
512 rect.Inset( | 525 if (!ash::switches::UseAlternateShelfLayout()) { |
513 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, | 526 rect.Inset( |
514 kTrayBubbleAnchorTopInsetBottomAnchor, | 527 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, |
515 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, | 528 kTrayBubbleAnchorTopInsetBottomAnchor, |
516 kPaddingFromBottomOfScreenBottomAlignment); | 529 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, |
530 kPaddingFromBottomOfScreenBottomAlignment); | |
531 } else { | |
532 rect.Inset( | |
533 rtl ? kAlternateLayoutBubblePaddingHorizontalSide : 0, | |
534 kAlternateLayoutBubblePaddingHorizontalBottom, | |
535 rtl ? 0 : kAlternateLayoutBubblePaddingHorizontalSide, | |
536 0); | |
537 } | |
517 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | 538 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { |
518 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5, | 539 if (!ash::switches::UseAlternateShelfLayout()) { |
519 kPaddingFromBottomOfScreenVerticalAlignment); | 540 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5, |
541 kPaddingFromBottomOfScreenVerticalAlignment); | |
542 } else { | |
543 rect.Inset(0, 0, kAlternateLayoutBubblePaddingVerticalSide + 4, | |
544 kAlternateLayoutBubblePaddingVerticalBottom); | |
545 } | |
520 } else { | 546 } else { |
521 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1, | 547 if (!ash::switches::UseAlternateShelfLayout()) { |
522 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | 548 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1, |
549 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
550 } else { | |
551 rect.Inset(kAlternateLayoutBubblePaddingVerticalSide, 0, 0, | |
552 kAlternateLayoutBubblePaddingVerticalBottom); | |
553 } | |
523 } | 554 } |
524 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { | 555 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { |
525 // Invert the offsets to align with the bubble below. | 556 // Invert the offsets to align with the bubble below. |
526 // Note that with the alternate shelf layout the tips are not shown and | 557 // 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. | 558 // the offsets for left and right alignment do not need to be applied. |
528 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ? | 559 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ? |
529 0 : kPaddingFromInnerEdgeOfLauncherVerticalAlignment; | 560 0 : |
530 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | 561 kPaddingFromInnerEdgeOfLauncherVerticalAlignment; |
531 rect.Inset(vertical_alignment, | 562 int horizontal_alignment = ash::switches::UseAlternateShelfLayout() ? |
532 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | 563 kAlternateLayoutBubblePaddingVerticalBottom : |
533 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | 564 kPaddingFromBottomOfScreenVerticalAlignment; |
534 rect.Inset(0, 0, vertical_alignment, | 565 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) |
535 kPaddingFromBottomOfScreenVerticalAlignment); | 566 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment); |
536 } | 567 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) |
568 rect.Inset(0, 0, vertical_alignment, horizontal_alignment); | |
537 } | 569 } |
538 } | 570 } |
539 | 571 |
540 // TODO(jennyz): May need to add left/right alignment in the following code. | 572 // TODO(jennyz): May need to add left/right alignment in the following code. |
541 if (rect.IsEmpty()) { | 573 if (rect.IsEmpty()) { |
542 aura::RootWindow* target_root = anchor_widget ? | 574 aura::RootWindow* target_root = anchor_widget ? |
543 anchor_widget->GetNativeView()->GetRootWindow() : | 575 anchor_widget->GetNativeView()->GetRootWindow() : |
544 Shell::GetPrimaryRootWindow(); | 576 Shell::GetPrimaryRootWindow(); |
545 rect = target_root->bounds(); | 577 rect = target_root->bounds(); |
546 rect = gfx::Rect( | 578 rect = gfx::Rect( |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
593 ash::internal::ShelfLayoutManager* shelf = | 625 ash::internal::ShelfLayoutManager* shelf = |
594 ShelfLayoutManager::ForLauncher(root_window); | 626 ShelfLayoutManager::ForLauncher(root_window); |
595 bubble_view->SetArrowPaintType( | 627 bubble_view->SetArrowPaintType( |
596 (shelf && shelf->IsVisible()) ? | 628 (shelf && shelf->IsVisible()) ? |
597 views::BubbleBorder::PAINT_NORMAL : | 629 views::BubbleBorder::PAINT_NORMAL : |
598 views::BubbleBorder::PAINT_TRANSPARENT); | 630 views::BubbleBorder::PAINT_TRANSPARENT); |
599 } | 631 } |
600 | 632 |
601 } // namespace internal | 633 } // namespace internal |
602 } // namespace ash | 634 } // namespace ash |
OLD | NEW |