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/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
11 #include "ash/drag_drop/drag_image_view.h" | 11 #include "ash/drag_drop/drag_image_view.h" |
12 #include "ash/metrics/user_metrics_recorder.h" | 12 #include "ash/metrics/user_metrics_recorder.h" |
13 #include "ash/root_window_controller.h" | 13 #include "ash/root_window_controller.h" |
14 #include "ash/scoped_target_root_window.h" | 14 #include "ash/scoped_target_root_window.h" |
15 #include "ash/shelf/alternate_app_list_button.h" | |
16 #include "ash/shelf/app_list_button.h" | 15 #include "ash/shelf/app_list_button.h" |
17 #include "ash/shelf/overflow_bubble.h" | 16 #include "ash/shelf/overflow_bubble.h" |
18 #include "ash/shelf/overflow_bubble_view.h" | 17 #include "ash/shelf/overflow_bubble_view.h" |
19 #include "ash/shelf/overflow_button.h" | 18 #include "ash/shelf/overflow_button.h" |
20 #include "ash/shelf/shelf_button.h" | 19 #include "ash/shelf/shelf_button.h" |
21 #include "ash/shelf/shelf_constants.h" | 20 #include "ash/shelf/shelf_constants.h" |
22 #include "ash/shelf/shelf_delegate.h" | 21 #include "ash/shelf/shelf_delegate.h" |
23 #include "ash/shelf/shelf_icon_observer.h" | 22 #include "ash/shelf/shelf_icon_observer.h" |
24 #include "ash/shelf/shelf_item_delegate.h" | 23 #include "ash/shelf/shelf_item_delegate.h" |
25 #include "ash/shelf/shelf_item_delegate_manager.h" | 24 #include "ash/shelf/shelf_item_delegate_manager.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
68 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2; | 67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2; |
69 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3; | 68 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3; |
70 | 69 |
71 // Default amount content is inset on the left edge. | 70 // Default amount content is inset on the left edge. |
72 const int kDefaultLeadingInset = 8; | 71 const int kDefaultLeadingInset = 8; |
73 | 72 |
74 // Minimum distance before drag starts. | 73 // Minimum distance before drag starts. |
75 const int kMinimumDragDistance = 8; | 74 const int kMinimumDragDistance = 8; |
76 | 75 |
77 // Size between the buttons. | 76 // Size between the buttons. |
78 const int kButtonSpacing = 4; | 77 const int kButtonSpacing = 10; |
79 const int kAlternateButtonSpacing = 10; | |
80 | 78 |
81 // Size allocated to for each button. | 79 // Size allocated to for each button. |
82 const int kButtonSize = 44; | 80 const int kButtonSize = 44; |
83 | 81 |
84 // Additional spacing for the left and right side of icons. | 82 // Additional spacing for the left and right side of icons. |
85 const int kHorizontalIconSpacing = 2; | 83 const int kHorizontalIconSpacing = 2; |
86 | 84 |
87 // Inset for items which do not have an icon. | 85 // Inset for items which do not have an icon. |
88 const int kHorizontalNoIconInsetSpacing = | 86 const int kHorizontalNoIconInsetSpacing = |
89 kHorizontalIconSpacing + kDefaultLeadingInset; | 87 kHorizontalIconSpacing + kDefaultLeadingInset; |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 void ShelfView::Init() { | 401 void ShelfView::Init() { |
404 model_->AddObserver(this); | 402 model_->AddObserver(this); |
405 | 403 |
406 const LauncherItems& items(model_->items()); | 404 const LauncherItems& items(model_->items()); |
407 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 405 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
408 views::View* child = CreateViewForItem(*i); | 406 views::View* child = CreateViewForItem(*i); |
409 child->SetPaintToLayer(true); | 407 child->SetPaintToLayer(true); |
410 view_model_->Add(child, static_cast<int>(i - items.begin())); | 408 view_model_->Add(child, static_cast<int>(i - items.begin())); |
411 AddChildView(child); | 409 AddChildView(child); |
412 } | 410 } |
413 ShelfStatusChanged(); | |
414 overflow_button_ = new OverflowButton(this); | 411 overflow_button_ = new OverflowButton(this); |
415 overflow_button_->set_context_menu_controller(this); | 412 overflow_button_->set_context_menu_controller(this); |
416 ConfigureChildView(overflow_button_); | 413 ConfigureChildView(overflow_button_); |
417 AddChildView(overflow_button_); | 414 AddChildView(overflow_button_); |
418 UpdateFirstButtonPadding(); | |
419 | 415 |
420 // We'll layout when our bounds change. | 416 // We'll layout when our bounds change. |
421 } | 417 } |
422 | 418 |
423 void ShelfView::OnShelfAlignmentChanged() { | 419 void ShelfView::OnShelfAlignmentChanged() { |
424 UpdateFirstButtonPadding(); | |
425 overflow_button_->OnShelfAlignmentChanged(); | 420 overflow_button_->OnShelfAlignmentChanged(); |
426 LayoutToIdealBounds(); | 421 LayoutToIdealBounds(); |
427 for (int i=0; i < view_model_->view_size(); ++i) { | 422 for (int i=0; i < view_model_->view_size(); ++i) { |
428 // TODO: remove when AppIcon is a Shelf Button. | |
429 if (TYPE_APP_LIST == model_->items()[i].type && | |
430 !ash::switches::UseAlternateShelfLayout()) { | |
431 static_cast<AppListButton*>(view_model_->view_at(i))->SetImageAlignment( | |
432 layout_manager_->SelectValueForShelfAlignment( | |
433 views::ImageButton::ALIGN_CENTER, | |
434 views::ImageButton::ALIGN_LEFT, | |
435 views::ImageButton::ALIGN_RIGHT, | |
436 views::ImageButton::ALIGN_CENTER), | |
437 layout_manager_->SelectValueForShelfAlignment( | |
438 views::ImageButton::ALIGN_TOP, | |
439 views::ImageButton::ALIGN_MIDDLE, | |
440 views::ImageButton::ALIGN_MIDDLE, | |
441 views::ImageButton::ALIGN_BOTTOM)); | |
442 } | |
443 if (i >= first_visible_index_ && i <= last_visible_index_) | 423 if (i >= first_visible_index_ && i <= last_visible_index_) |
444 view_model_->view_at(i)->Layout(); | 424 view_model_->view_at(i)->Layout(); |
445 } | 425 } |
446 tooltip_->Close(); | 426 tooltip_->Close(); |
447 if (overflow_bubble_) | 427 if (overflow_bubble_) |
448 overflow_bubble_->Hide(); | 428 overflow_bubble_->Hide(); |
449 } | 429 } |
450 | 430 |
451 void ShelfView::SchedulePaintForAllButtons() { | 431 void ShelfView::SchedulePaintForAllButtons() { |
452 for (int i = 0; i < view_model_->view_size(); ++i) { | 432 for (int i = 0; i < view_model_->view_size(); ++i) { |
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
682 | 662 |
683 IdealBounds ideal_bounds; | 663 IdealBounds ideal_bounds; |
684 CalculateIdealBounds(&ideal_bounds); | 664 CalculateIdealBounds(&ideal_bounds); |
685 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 665 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
686 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 666 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
687 } | 667 } |
688 | 668 |
689 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { | 669 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { |
690 // The overflow button is not shown in overflow mode. | 670 // The overflow button is not shown in overflow mode. |
691 overflow_button_->SetVisible(false); | 671 overflow_button_->SetVisible(false); |
692 int last_button_index = model_->FirstPanelIndex() - 1; | |
693 DCHECK_LT(last_visible_index_, view_model_->view_size()); | 672 DCHECK_LT(last_visible_index_, view_model_->view_size()); |
694 for (int i = 0; i < view_model_->view_size(); ++i) { | 673 for (int i = 0; i < view_model_->view_size(); ++i) { |
695 bool visible = i >= first_visible_index_ && | 674 bool visible = i >= first_visible_index_ && |
696 i <= last_visible_index_; | 675 i <= last_visible_index_; |
697 if (!ash::switches::UseAlternateShelfLayout()) | |
698 visible &= i != last_button_index; | |
699 | 676 |
700 // To track the dragging of |drag_view_| continuously, its visibility | 677 // To track the dragging of |drag_view_| continuously, its visibility |
701 // should be always true regardless of its position. | 678 // should be always true regardless of its position. |
702 if (dragged_off_from_overflow_to_shelf_ && | 679 if (dragged_off_from_overflow_to_shelf_ && |
703 view_model_->view_at(i) == drag_view_) | 680 view_model_->view_at(i) == drag_view_) |
704 view_model_->view_at(i)->SetVisible(true); | 681 view_model_->view_at(i)->SetVisible(true); |
705 else | 682 else |
706 view_model_->view_at(i)->SetVisible(visible); | 683 view_model_->view_at(i)->SetVisible(visible); |
707 } | 684 } |
708 } | 685 } |
709 | 686 |
710 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { | 687 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { |
711 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); | 688 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); |
712 DCHECK(model_->item_count() == view_model_->view_size()); | 689 DCHECK(model_->item_count() == view_model_->view_size()); |
713 if (!available_size) | 690 if (!available_size) |
714 return; | 691 return; |
715 | 692 |
716 int first_panel_index = model_->FirstPanelIndex(); | 693 int first_panel_index = model_->FirstPanelIndex(); |
717 int last_button_index = first_panel_index - 1; | 694 int last_button_index = first_panel_index - 1; |
718 | 695 |
719 // Initial x,y values account both leading_inset in primary | 696 // Initial x,y values account both leading_inset in primary |
720 // coordinate and secondary coordinate based on the dynamic edge of the | 697 // coordinate and secondary coordinate based on the dynamic edge of the |
721 // shelf (eg top edge on bottom-aligned shelf). | 698 // shelf (eg top edge on bottom-aligned shelf). |
722 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset_; | 699 int inset = 0; |
723 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); | 700 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); |
James Cook
2014/01/23 18:02:35
Doesn't this always select 0?
Harry McCleave
2014/01/24 22:48:47
Done.
| |
724 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); | 701 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); |
Mr4D (OOO till 08-26)
2014/01/23 19:25:08
as here.
Harry McCleave
2014/01/24 22:48:47
Done.
| |
725 | 702 |
726 int button_size = GetButtonSize(); | 703 int button_size = GetButtonSize(); |
727 int button_spacing = GetButtonSpacing(); | 704 int button_spacing = GetButtonSpacing(); |
728 | 705 |
729 int w = layout_manager_->PrimaryAxisValue(button_size, width()); | 706 int w = layout_manager_->PrimaryAxisValue(button_size, width()); |
730 int h = layout_manager_->PrimaryAxisValue(height(), button_size); | 707 int h = layout_manager_->PrimaryAxisValue(height(), button_size); |
731 for (int i = 0; i < view_model_->view_size(); ++i) { | 708 for (int i = 0; i < view_model_->view_size(); ++i) { |
732 if (i < first_visible_index_) { | 709 if (i < first_visible_index_) { |
733 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 710 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
734 continue; | 711 continue; |
735 } | 712 } |
736 | 713 |
737 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 714 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
738 if (i != last_button_index) { | 715 if (i != last_button_index) { |
739 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); | 716 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); |
740 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); | 717 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); |
741 } | 718 } |
742 } | 719 } |
743 | 720 |
744 if (is_overflow_mode()) { | 721 if (is_overflow_mode()) { |
745 UpdateAllButtonsVisibilityInOverflowMode(); | 722 UpdateAllButtonsVisibilityInOverflowMode(); |
746 return; | 723 return; |
747 } | 724 } |
748 | 725 |
749 // To address Fitt's law, we make the first shelf button include the | |
750 // leading inset (if there is one). | |
751 if (!ash::switches::UseAlternateShelfLayout()) { | |
752 if (view_model_->view_size() > 0) { | |
753 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( | |
754 layout_manager_->PrimaryAxisValue(inset + w, w), | |
755 layout_manager_->PrimaryAxisValue(h, inset + h)))); | |
756 } | |
757 } | |
758 | |
759 // Right aligned icons. | 726 // Right aligned icons. |
760 int end_position = available_size - button_spacing; | 727 int end_position = available_size - button_spacing; |
761 x = layout_manager_->PrimaryAxisValue(end_position, 0); | 728 x = layout_manager_->PrimaryAxisValue(end_position, 0); |
762 y = layout_manager_->PrimaryAxisValue(0, end_position); | 729 y = layout_manager_->PrimaryAxisValue(0, end_position); |
763 for (int i = view_model_->view_size() - 1; | 730 for (int i = view_model_->view_size() - 1; |
764 i >= first_panel_index; --i) { | 731 i >= first_panel_index; --i) { |
765 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); | 732 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); |
766 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing); | 733 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing); |
767 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 734 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
768 end_position = layout_manager_->PrimaryAxisValue(x, y); | 735 end_position = layout_manager_->PrimaryAxisValue(x, y); |
769 } | 736 } |
770 | 737 |
771 // Icons on the left / top are guaranteed up to kLeftIconProportion of | 738 // Icons on the left / top are guaranteed up to kLeftIconProportion of |
772 // the available space. | 739 // the available space. |
773 int last_icon_position = layout_manager_->PrimaryAxisValue( | 740 int last_icon_position = layout_manager_->PrimaryAxisValue( |
774 view_model_->ideal_bounds(last_button_index).right(), | 741 view_model_->ideal_bounds(last_button_index).right(), |
775 view_model_->ideal_bounds(last_button_index).bottom()) | 742 view_model_->ideal_bounds(last_button_index).bottom()) |
776 + button_size + inset; | 743 + button_size + inset; |
777 if (!ash::switches::UseAlternateShelfLayout()) | |
778 last_icon_position += button_size; | |
779 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; | 744 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; |
780 if (last_icon_position < reserved_icon_space) | 745 if (last_icon_position < reserved_icon_space) |
781 end_position = last_icon_position; | 746 end_position = last_icon_position; |
782 else | 747 else |
783 end_position = std::max(end_position, reserved_icon_space); | 748 end_position = std::max(end_position, reserved_icon_space); |
784 | 749 |
785 bounds->overflow_bounds.set_size( | 750 bounds->overflow_bounds.set_size( |
786 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()), | 751 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()), |
787 layout_manager_->PrimaryAxisValue(height(), h))); | 752 layout_manager_->PrimaryAxisValue(height(), h))); |
788 | 753 |
789 if (ash::switches::UseAlternateShelfLayout()) { | 754 last_visible_index_ = DetermineLastVisibleIndex( |
790 last_visible_index_ = DetermineLastVisibleIndex( | 755 end_position - button_size); |
791 end_position - button_size); | |
792 } else { | |
793 last_visible_index_ = DetermineLastVisibleIndex( | |
794 end_position - inset - 2 * button_size); | |
795 } | |
796 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; | 756 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; |
797 bool show_overflow = | 757 bool show_overflow = |
798 ((ash::switches::UseAlternateShelfLayout() ? 0 : 1) + | 758 (last_visible_index_ < last_button_index || |
799 last_visible_index_ < last_button_index || | |
800 last_hidden_index_ >= first_panel_index); | 759 last_hidden_index_ >= first_panel_index); |
801 | 760 |
802 // Create Space for the overflow button | 761 // Create Space for the overflow button |
803 if (show_overflow && ash::switches::UseAlternateShelfLayout() && | 762 if (show_overflow && last_visible_index_ > 0 && |
804 last_visible_index_ > 0 && last_visible_index_ < last_button_index) | 763 last_visible_index_ < last_button_index) |
805 --last_visible_index_; | 764 --last_visible_index_; |
806 for (int i = 0; i < view_model_->view_size(); ++i) { | 765 for (int i = 0; i < view_model_->view_size(); ++i) { |
807 bool visible = i <= last_visible_index_ || i > last_hidden_index_; | 766 bool visible = i <= last_visible_index_ || i > last_hidden_index_; |
808 // Always show the app list. | |
809 if (!ash::switches::UseAlternateShelfLayout()) | |
810 visible |= (i == last_button_index); | |
811 // To receive drag event continously from |drag_view_| during the dragging | 767 // To receive drag event continously from |drag_view_| during the dragging |
812 // off from the shelf, don't make |drag_view_| invisible. It will be | 768 // off from the shelf, don't make |drag_view_| invisible. It will be |
813 // eventually invisible and removed from the |view_model_| by | 769 // eventually invisible and removed from the |view_model_| by |
814 // FinalizeRipOffDrag(). | 770 // FinalizeRipOffDrag(). |
815 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) | 771 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) |
816 continue; | 772 continue; |
817 view_model_->view_at(i)->SetVisible(visible); | 773 view_model_->view_at(i)->SetVisible(visible); |
818 } | 774 } |
819 | 775 |
820 overflow_button_->SetVisible(show_overflow); | 776 overflow_button_->SetVisible(show_overflow); |
821 if (show_overflow) { | 777 if (show_overflow) { |
822 DCHECK_NE(0, view_model_->view_size()); | 778 DCHECK_NE(0, view_model_->view_size()); |
823 if (last_visible_index_ == -1) { | 779 if (last_visible_index_ == -1) { |
824 x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); | 780 x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); |
James Cook
2014/01/23 18:02:35
Isn't inset always 0 here?
Harry McCleave
2014/01/24 22:48:47
Done.
| |
825 y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); | 781 y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); |
826 } else if (last_visible_index_ == last_button_index | |
827 && !ash::switches::UseAlternateShelfLayout()) { | |
828 x = view_model_->ideal_bounds(last_visible_index_).x(); | |
829 y = view_model_->ideal_bounds(last_visible_index_).y(); | |
830 } else { | 782 } else { |
831 x = layout_manager_->PrimaryAxisValue( | 783 x = layout_manager_->PrimaryAxisValue( |
832 view_model_->ideal_bounds(last_visible_index_).right(), | 784 view_model_->ideal_bounds(last_visible_index_).right(), |
833 view_model_->ideal_bounds(last_visible_index_).x()); | 785 view_model_->ideal_bounds(last_visible_index_).x()); |
834 y = layout_manager_->PrimaryAxisValue( | 786 y = layout_manager_->PrimaryAxisValue( |
835 view_model_->ideal_bounds(last_visible_index_).y(), | 787 view_model_->ideal_bounds(last_visible_index_).y(), |
836 view_model_->ideal_bounds(last_visible_index_).bottom()); | 788 view_model_->ideal_bounds(last_visible_index_).bottom()); |
837 } | 789 } |
838 // Set all hidden panel icon positions to be on the overflow button. | 790 // Set all hidden panel icon positions to be on the overflow button. |
839 for (int i = first_panel_index; i <= last_hidden_index_; ++i) | 791 for (int i = first_panel_index; i <= last_hidden_index_; ++i) |
840 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 792 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
841 | 793 |
842 // Add more space between last visible item and overflow button. | 794 // Add more space between last visible item and overflow button. |
843 // Without this, two buttons look too close compared with other items. | 795 // Without this, two buttons look too close compared with other items. |
844 if (ash::switches::UseAlternateShelfLayout()) { | 796 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x); |
845 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x); | 797 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing); |
846 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing); | |
847 } | |
848 | 798 |
849 bounds->overflow_bounds.set_x(x); | 799 bounds->overflow_bounds.set_x(x); |
850 bounds->overflow_bounds.set_y(y); | 800 bounds->overflow_bounds.set_y(y); |
851 if (!ash::switches::UseAlternateShelfLayout()) { | |
852 // Position app list after overflow button. | |
853 gfx::Rect app_list_bounds = view_model_->ideal_bounds(last_button_index); | |
854 | |
855 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); | |
856 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); | |
857 app_list_bounds.set_x(x); | |
858 app_list_bounds.set_y(y); | |
859 view_model_->set_ideal_bounds(last_button_index, app_list_bounds); | |
860 } | |
861 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) | 801 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) |
862 UpdateOverflowRange(overflow_bubble_->shelf_view()); | 802 UpdateOverflowRange(overflow_bubble_->shelf_view()); |
863 } else { | 803 } else { |
864 if (overflow_bubble_) | 804 if (overflow_bubble_) |
865 overflow_bubble_->Hide(); | 805 overflow_bubble_->Hide(); |
866 } | 806 } |
867 } | 807 } |
James Cook
2014/01/23 18:02:35
Not for this CL, but man it would be awesome to br
Harry McCleave
2014/01/24 22:48:47
Part 2's intention is to do just this, the layout
| |
868 | 808 |
869 int ShelfView::DetermineLastVisibleIndex(int max_value) const { | 809 int ShelfView::DetermineLastVisibleIndex(int max_value) const { |
870 int index = model_->FirstPanelIndex() - 1; | 810 int index = model_->FirstPanelIndex() - 1; |
871 while (index >= 0 && | 811 while (index >= 0 && |
872 layout_manager_->PrimaryAxisValue( | 812 layout_manager_->PrimaryAxisValue( |
873 view_model_->ideal_bounds(index).right(), | 813 view_model_->ideal_bounds(index).right(), |
874 view_model_->ideal_bounds(index).bottom()) > max_value) { | 814 view_model_->ideal_bounds(index).bottom()) > max_value) { |
875 index--; | 815 index--; |
876 } | 816 } |
877 return index; | 817 return index; |
(...skipping 21 matching lines...) Expand all Loading... | |
899 void ShelfView::AnimateToIdealBounds() { | 839 void ShelfView::AnimateToIdealBounds() { |
900 IdealBounds ideal_bounds; | 840 IdealBounds ideal_bounds; |
901 CalculateIdealBounds(&ideal_bounds); | 841 CalculateIdealBounds(&ideal_bounds); |
902 for (int i = 0; i < view_model_->view_size(); ++i) { | 842 for (int i = 0; i < view_model_->view_size(); ++i) { |
903 View* view = view_model_->view_at(i); | 843 View* view = view_model_->view_at(i); |
904 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i)); | 844 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i)); |
905 // Now that the item animation starts, we have to make sure that the | 845 // Now that the item animation starts, we have to make sure that the |
906 // padding of the first gets properly transferred to the new first item. | 846 // padding of the first gets properly transferred to the new first item. |
907 if (i && view->border()) | 847 if (i && view->border()) |
908 view->set_border(NULL); | 848 view->set_border(NULL); |
909 else if (!i && !view->border()) | |
910 UpdateFirstButtonPadding(); | |
911 } | 849 } |
912 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 850 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
913 } | 851 } |
914 | 852 |
915 views::View* ShelfView::CreateViewForItem(const LauncherItem& item) { | 853 views::View* ShelfView::CreateViewForItem(const LauncherItem& item) { |
916 views::View* view = NULL; | 854 views::View* view = NULL; |
917 switch (item.type) { | 855 switch (item.type) { |
918 case TYPE_BROWSER_SHORTCUT: | 856 case TYPE_BROWSER_SHORTCUT: |
919 case TYPE_APP_SHORTCUT: | 857 case TYPE_APP_SHORTCUT: |
920 case TYPE_WINDOWED_APP: | 858 case TYPE_WINDOWED_APP: |
921 case TYPE_PLATFORM_APP: | 859 case TYPE_PLATFORM_APP: |
922 case TYPE_DIALOG: | 860 case TYPE_DIALOG: |
923 case TYPE_APP_PANEL: { | 861 case TYPE_APP_PANEL: { |
924 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); | 862 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); |
925 button->SetImage(item.image); | 863 button->SetImage(item.image); |
926 ReflectItemStatus(item, button); | 864 ReflectItemStatus(item, button); |
927 view = button; | 865 view = button; |
928 break; | 866 break; |
929 } | 867 } |
930 | 868 |
931 case TYPE_APP_LIST: { | 869 case TYPE_APP_LIST: { |
932 if (ash::switches::UseAlternateShelfLayout()) { | 870 view = new AppListButton(this, this, layout_manager_->shelf_widget()); |
933 view = new AlternateAppListButton(this, | |
934 this, | |
935 layout_manager_->shelf_widget()); | |
936 } else { | |
937 // TODO(dave): turn this into a ShelfButton too. | |
938 AppListButton* button = new AppListButton(this, this); | |
939 button->SetImageAlignment( | |
940 layout_manager_->SelectValueForShelfAlignment( | |
941 views::ImageButton::ALIGN_CENTER, | |
942 views::ImageButton::ALIGN_LEFT, | |
943 views::ImageButton::ALIGN_RIGHT, | |
944 views::ImageButton::ALIGN_CENTER), | |
945 layout_manager_->SelectValueForShelfAlignment( | |
946 views::ImageButton::ALIGN_TOP, | |
947 views::ImageButton::ALIGN_MIDDLE, | |
948 views::ImageButton::ALIGN_MIDDLE, | |
949 views::ImageButton::ALIGN_BOTTOM)); | |
950 view = button; | |
951 } | |
952 break; | 871 break; |
953 } | 872 } |
954 | 873 |
955 default: | 874 default: |
956 break; | 875 break; |
957 } | 876 } |
958 view->set_context_menu_controller(this); | 877 view->set_context_menu_controller(this); |
959 | 878 |
960 DCHECK(view); | 879 DCHECK(view); |
961 ConfigureChildView(view); | 880 ConfigureChildView(view); |
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1299 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); | 1218 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); |
1300 overflow_view->OnShelfAlignmentChanged(); | 1219 overflow_view->OnShelfAlignmentChanged(); |
1301 overflow_view->main_shelf_ = this; | 1220 overflow_view->main_shelf_ = this; |
1302 UpdateOverflowRange(overflow_view); | 1221 UpdateOverflowRange(overflow_view); |
1303 | 1222 |
1304 overflow_bubble_->Show(overflow_button_, overflow_view); | 1223 overflow_bubble_->Show(overflow_button_, overflow_view); |
1305 | 1224 |
1306 Shell::GetInstance()->UpdateShelfVisibility(); | 1225 Shell::GetInstance()->UpdateShelfVisibility(); |
1307 } | 1226 } |
1308 | 1227 |
1309 void ShelfView::UpdateFirstButtonPadding() { | |
1310 if (ash::switches::UseAlternateShelfLayout()) | |
1311 return; | |
1312 | |
1313 // Creates an empty border for first shelf button to make included leading | |
1314 // inset act as the button's padding. This is only needed on button creation | |
1315 // and when shelf alignment changes. | |
1316 if (view_model_->view_size() > 0) { | |
1317 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( | |
1318 layout_manager_->PrimaryAxisValue(0, leading_inset_), | |
1319 layout_manager_->PrimaryAxisValue(leading_inset_, 0), | |
1320 0, | |
1321 0)); | |
1322 } | |
1323 } | |
1324 | |
1325 void ShelfView::OnFadeOutAnimationEnded() { | 1228 void ShelfView::OnFadeOutAnimationEnded() { |
1326 AnimateToIdealBounds(); | 1229 AnimateToIdealBounds(); |
1327 StartFadeInLastVisibleItem(); | 1230 StartFadeInLastVisibleItem(); |
1328 } | 1231 } |
1329 | 1232 |
1330 void ShelfView::StartFadeInLastVisibleItem() { | 1233 void ShelfView::StartFadeInLastVisibleItem() { |
1331 // If overflow button is visible and there is a valid new last item, fading | 1234 // If overflow button is visible and there is a valid new last item, fading |
1332 // the new last item in after sliding animation is finished. | 1235 // the new last item in after sliding animation is finished. |
1333 if (overflow_button_->visible() && last_visible_index_ >= 0) { | 1236 if (overflow_button_->visible() && last_visible_index_ >= 0) { |
1334 views::View* last_visible_view = view_model_->view_at(last_visible_index_); | 1237 views::View* last_visible_view = view_model_->view_at(last_visible_index_); |
1335 last_visible_view->layer()->SetOpacity(0); | 1238 last_visible_view->layer()->SetOpacity(0); |
1336 bounds_animator_->SetAnimationDelegate( | 1239 bounds_animator_->SetAnimationDelegate( |
1337 last_visible_view, | 1240 last_visible_view, |
1338 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), | 1241 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), |
1339 true); | 1242 true); |
1340 } | 1243 } |
1341 } | 1244 } |
1342 | 1245 |
1343 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { | 1246 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { |
1344 const int first_overflow_index = last_visible_index_ + 1; | 1247 const int first_overflow_index = last_visible_index_ + 1; |
1345 const int last_overflow_index = last_hidden_index_; | 1248 const int last_overflow_index = last_hidden_index_; |
1346 DCHECK_LE(first_overflow_index, last_overflow_index); | 1249 DCHECK_LE(first_overflow_index, last_overflow_index); |
1347 DCHECK_LT(last_overflow_index, view_model_->view_size()); | 1250 DCHECK_LT(last_overflow_index, view_model_->view_size()); |
1348 | 1251 |
1349 overflow_view->first_visible_index_ = first_overflow_index; | 1252 overflow_view->first_visible_index_ = first_overflow_index; |
1350 overflow_view->last_visible_index_ = last_overflow_index; | 1253 overflow_view->last_visible_index_ = last_overflow_index; |
1351 } | 1254 } |
1352 | 1255 |
1353 int ShelfView::GetButtonSize() const { | 1256 int ShelfView::GetButtonSize() const { |
1354 return ash::switches::UseAlternateShelfLayout() ? | 1257 return kShelfPreferredSize; |
1355 kButtonSize : kShelfPreferredSize; | |
1356 } | 1258 } |
1357 | 1259 |
1358 int ShelfView::GetButtonSpacing() const { | 1260 int ShelfView::GetButtonSpacing() const { |
1359 return ash::switches::UseAlternateShelfLayout() ? | 1261 return kButtonSpacing; |
1360 kAlternateButtonSpacing : kButtonSpacing; | |
1361 } | 1262 } |
1362 | 1263 |
1363 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { | 1264 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { |
1364 gfx::Rect active_bounds; | 1265 gfx::Rect active_bounds; |
1365 | 1266 |
1366 for (int i = 0; i < child_count(); ++i) { | 1267 for (int i = 0; i < child_count(); ++i) { |
1367 views::View* child = child_at(i); | 1268 views::View* child = child_at(i); |
1368 if (child == overflow_button_) | 1269 if (child == overflow_button_) |
1369 continue; | 1270 continue; |
1370 if (!ShouldShowTooltipForView(child)) | 1271 if (!ShouldShowTooltipForView(child)) |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1638 view_model_->Move(start_index, target_index); | 1539 view_model_->Move(start_index, target_index); |
1639 // When cancelling a drag due to a shelf item being added, the currently | 1540 // When cancelling a drag due to a shelf item being added, the currently |
1640 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1541 // dragged item is moved back to its initial position. AnimateToIdealBounds |
1641 // will be called again when the new item is added to the |view_model_| but | 1542 // will be called again when the new item is added to the |view_model_| but |
1642 // at this time the |view_model_| is inconsistent with the |model_|. | 1543 // at this time the |view_model_| is inconsistent with the |model_|. |
1643 if (!cancelling_drag_model_changed_) | 1544 if (!cancelling_drag_model_changed_) |
1644 AnimateToIdealBounds(); | 1545 AnimateToIdealBounds(); |
1645 } | 1546 } |
1646 | 1547 |
1647 void ShelfView::ShelfStatusChanged() { | 1548 void ShelfView::ShelfStatusChanged() { |
1648 if (ash::switches::UseAlternateShelfLayout()) | |
1649 return; | |
1650 AppListButton* app_list_button = | |
1651 static_cast<AppListButton*>(GetAppListButtonView()); | |
1652 if (model_->status() == ShelfModel::STATUS_LOADING) | |
1653 app_list_button->StartLoadingAnimation(); | |
1654 else | |
1655 app_list_button->StopLoadingAnimation(); | |
1656 } | 1549 } |
James Cook
2014/01/23 18:02:35
optional nit: Maybe comment "// Nothing to do." A
Harry McCleave
2014/01/24 22:48:47
Done. I thought it could be removed as well, the c
| |
1657 | 1550 |
1658 void ShelfView::PointerPressedOnButton(views::View* view, | 1551 void ShelfView::PointerPressedOnButton(views::View* view, |
1659 Pointer pointer, | 1552 Pointer pointer, |
1660 const ui::LocatedEvent& event) { | 1553 const ui::LocatedEvent& event) { |
1661 if (drag_view_) | 1554 if (drag_view_) |
1662 return; | 1555 return; |
1663 | 1556 |
1664 int index = view_model_->GetIndexOfView(view); | 1557 int index = view_model_->GetIndexOfView(view); |
1665 if (index == -1) | 1558 if (index == -1) |
1666 return; | 1559 return; |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2023 break; | 1916 break; |
2024 case SHELF_ALIGNMENT_TOP: | 1917 case SHELF_ALIGNMENT_TOP: |
2025 distance = coordinate.y() - bounds.bottom(); | 1918 distance = coordinate.y() - bounds.bottom(); |
2026 break; | 1919 break; |
2027 } | 1920 } |
2028 return distance > 0 ? distance : 0; | 1921 return distance > 0 ? distance : 0; |
2029 } | 1922 } |
2030 | 1923 |
2031 } // namespace internal | 1924 } // namespace internal |
2032 } // namespace ash | 1925 } // namespace ash |
OLD | NEW |