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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
66 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1; | 65 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1; |
67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2; | 66 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT = 2; |
68 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3; | 67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT = 3; |
69 | 68 |
70 // Default amount content is inset on the left edge. | 69 // Default amount content is inset on the left edge. |
71 const int kDefaultLeadingInset = 8; | 70 const int kDefaultLeadingInset = 8; |
72 | 71 |
73 // Minimum distance before drag starts. | 72 // Minimum distance before drag starts. |
74 const int kMinimumDragDistance = 8; | 73 const int kMinimumDragDistance = 8; |
75 | 74 |
76 // Size between the buttons. | |
77 const int kButtonSpacing = 4; | |
78 const int kAlternateButtonSpacing = 10; | |
79 | |
80 // Size allocated to for each button. | |
81 const int kButtonSize = 44; | |
82 | |
83 // Additional spacing for the left and right side of icons. | 75 // Additional spacing for the left and right side of icons. |
84 const int kHorizontalIconSpacing = 2; | 76 const int kHorizontalIconSpacing = 2; |
85 | 77 |
86 // Inset for items which do not have an icon. | 78 // Inset for items which do not have an icon. |
87 const int kHorizontalNoIconInsetSpacing = | 79 const int kHorizontalNoIconInsetSpacing = |
88 kHorizontalIconSpacing + kDefaultLeadingInset; | 80 kHorizontalIconSpacing + kDefaultLeadingInset; |
89 | 81 |
90 // The proportion of the shelf space reserved for non-panel icons. Panels | 82 // The proportion of the shelf space reserved for non-panel icons. Panels |
91 // may flow into this space but will be put into the overflow bubble if there | 83 // may flow into this space but will be put into the overflow bubble if there |
92 // is contention for the space. | 84 // is contention for the space. |
(...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
424 void ShelfView::Init() { | 416 void ShelfView::Init() { |
425 model_->AddObserver(this); | 417 model_->AddObserver(this); |
426 | 418 |
427 const ShelfItems& items(model_->items()); | 419 const ShelfItems& items(model_->items()); |
428 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { | 420 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { |
429 views::View* child = CreateViewForItem(*i); | 421 views::View* child = CreateViewForItem(*i); |
430 child->SetPaintToLayer(true); | 422 child->SetPaintToLayer(true); |
431 view_model_->Add(child, static_cast<int>(i - items.begin())); | 423 view_model_->Add(child, static_cast<int>(i - items.begin())); |
432 AddChildView(child); | 424 AddChildView(child); |
433 } | 425 } |
434 ShelfStatusChanged(); | |
435 overflow_button_ = new OverflowButton(this); | 426 overflow_button_ = new OverflowButton(this); |
436 overflow_button_->set_context_menu_controller(this); | 427 overflow_button_->set_context_menu_controller(this); |
437 ConfigureChildView(overflow_button_); | 428 ConfigureChildView(overflow_button_); |
438 AddChildView(overflow_button_); | 429 AddChildView(overflow_button_); |
439 UpdateFirstButtonPadding(); | |
440 | 430 |
441 // We'll layout when our bounds change. | 431 // We'll layout when our bounds change. |
442 } | 432 } |
443 | 433 |
444 void ShelfView::OnShelfAlignmentChanged() { | 434 void ShelfView::OnShelfAlignmentChanged() { |
445 UpdateFirstButtonPadding(); | |
446 overflow_button_->OnShelfAlignmentChanged(); | 435 overflow_button_->OnShelfAlignmentChanged(); |
447 LayoutToIdealBounds(); | 436 LayoutToIdealBounds(); |
448 for (int i=0; i < view_model_->view_size(); ++i) { | 437 for (int i=0; i < view_model_->view_size(); ++i) { |
449 // TODO: remove when AppIcon is a Shelf Button. | |
450 if (TYPE_APP_LIST == model_->items()[i].type && | |
451 !ash::switches::UseAlternateShelfLayout()) { | |
452 static_cast<AppListButton*>(view_model_->view_at(i))->SetImageAlignment( | |
453 layout_manager_->SelectValueForShelfAlignment( | |
454 views::ImageButton::ALIGN_CENTER, | |
455 views::ImageButton::ALIGN_LEFT, | |
456 views::ImageButton::ALIGN_RIGHT, | |
457 views::ImageButton::ALIGN_CENTER), | |
458 layout_manager_->SelectValueForShelfAlignment( | |
459 views::ImageButton::ALIGN_TOP, | |
460 views::ImageButton::ALIGN_MIDDLE, | |
461 views::ImageButton::ALIGN_MIDDLE, | |
462 views::ImageButton::ALIGN_BOTTOM)); | |
463 } | |
464 if (i >= first_visible_index_ && i <= last_visible_index_) | 438 if (i >= first_visible_index_ && i <= last_visible_index_) |
465 view_model_->view_at(i)->Layout(); | 439 view_model_->view_at(i)->Layout(); |
466 } | 440 } |
467 tooltip_->Close(); | 441 tooltip_->Close(); |
468 if (overflow_bubble_) | 442 if (overflow_bubble_) |
469 overflow_bubble_->Hide(); | 443 overflow_bubble_->Hide(); |
470 } | 444 } |
471 | 445 |
472 void ShelfView::SchedulePaintForAllButtons() { | 446 void ShelfView::SchedulePaintForAllButtons() { |
473 for (int i = 0; i < view_model_->view_size(); ++i) { | 447 for (int i = 0; i < view_model_->view_size(); ++i) { |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
707 | 681 |
708 IdealBounds ideal_bounds; | 682 IdealBounds ideal_bounds; |
709 CalculateIdealBounds(&ideal_bounds); | 683 CalculateIdealBounds(&ideal_bounds); |
710 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); | 684 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); |
711 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 685 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
712 } | 686 } |
713 | 687 |
714 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { | 688 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { |
715 // The overflow button is not shown in overflow mode. | 689 // The overflow button is not shown in overflow mode. |
716 overflow_button_->SetVisible(false); | 690 overflow_button_->SetVisible(false); |
717 int last_button_index = model_->FirstPanelIndex() - 1; | |
718 DCHECK_LT(last_visible_index_, view_model_->view_size()); | 691 DCHECK_LT(last_visible_index_, view_model_->view_size()); |
719 for (int i = 0; i < view_model_->view_size(); ++i) { | 692 for (int i = 0; i < view_model_->view_size(); ++i) { |
720 bool visible = i >= first_visible_index_ && | 693 bool visible = i >= first_visible_index_ && |
721 i <= last_visible_index_; | 694 i <= last_visible_index_; |
722 if (!ash::switches::UseAlternateShelfLayout()) | |
723 visible &= i != last_button_index; | |
724 | |
725 // To track the dragging of |drag_view_| continuously, its visibility | 695 // To track the dragging of |drag_view_| continuously, its visibility |
726 // should be always true regardless of its position. | 696 // should be always true regardless of its position. |
727 if (dragged_off_from_overflow_to_shelf_ && | 697 if (dragged_off_from_overflow_to_shelf_ && |
728 view_model_->view_at(i) == drag_view_) | 698 view_model_->view_at(i) == drag_view_) |
729 view_model_->view_at(i)->SetVisible(true); | 699 view_model_->view_at(i)->SetVisible(true); |
730 else | 700 else |
731 view_model_->view_at(i)->SetVisible(visible); | 701 view_model_->view_at(i)->SetVisible(visible); |
732 } | 702 } |
733 } | 703 } |
734 | 704 |
735 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { | 705 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { |
736 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); | 706 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); |
737 DCHECK(model_->item_count() == view_model_->view_size()); | 707 DCHECK(model_->item_count() == view_model_->view_size()); |
738 if (!available_size) | 708 if (!available_size) |
739 return; | 709 return; |
740 | 710 |
741 int first_panel_index = model_->FirstPanelIndex(); | 711 int first_panel_index = model_->FirstPanelIndex(); |
742 int last_button_index = first_panel_index - 1; | 712 int last_button_index = first_panel_index - 1; |
743 | 713 |
744 // Initial x,y values account both leading_inset in primary | 714 int x = 0; |
745 // coordinate and secondary coordinate based on the dynamic edge of the | 715 int y = 0; |
746 // shelf (eg top edge on bottom-aligned shelf). | 716 int button_size = kShelfButtonSize; |
747 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset_; | 717 int button_spacing = kShelfButtonSpacing; |
748 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); | |
749 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); | |
750 | |
751 int button_size = GetButtonSize(); | |
752 int button_spacing = GetButtonSpacing(); | |
753 | 718 |
754 int w = layout_manager_->PrimaryAxisValue(button_size, width()); | 719 int w = layout_manager_->PrimaryAxisValue(button_size, width()); |
755 int h = layout_manager_->PrimaryAxisValue(height(), button_size); | 720 int h = layout_manager_->PrimaryAxisValue(height(), button_size); |
756 for (int i = 0; i < view_model_->view_size(); ++i) { | 721 for (int i = 0; i < view_model_->view_size(); ++i) { |
757 if (i < first_visible_index_) { | 722 if (i < first_visible_index_) { |
758 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 723 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
759 continue; | 724 continue; |
760 } | 725 } |
761 | 726 |
762 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 727 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
763 if (i != last_button_index) { | 728 if (i != last_button_index) { |
764 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); | 729 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); |
765 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); | 730 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); |
766 } | 731 } |
767 } | 732 } |
768 | 733 |
769 if (is_overflow_mode()) { | 734 if (is_overflow_mode()) { |
770 UpdateAllButtonsVisibilityInOverflowMode(); | 735 UpdateAllButtonsVisibilityInOverflowMode(); |
771 return; | 736 return; |
772 } | 737 } |
773 | 738 |
774 // To address Fitt's law, we make the first shelf button include the | |
775 // leading inset (if there is one). | |
776 if (!ash::switches::UseAlternateShelfLayout()) { | |
777 if (view_model_->view_size() > 0) { | |
778 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( | |
779 layout_manager_->PrimaryAxisValue(inset + w, w), | |
780 layout_manager_->PrimaryAxisValue(h, inset + h)))); | |
781 } | |
782 } | |
783 | |
784 // Right aligned icons. | 739 // Right aligned icons. |
785 int end_position = available_size - button_spacing; | 740 int end_position = available_size - button_spacing; |
786 x = layout_manager_->PrimaryAxisValue(end_position, 0); | 741 x = layout_manager_->PrimaryAxisValue(end_position, 0); |
787 y = layout_manager_->PrimaryAxisValue(0, end_position); | 742 y = layout_manager_->PrimaryAxisValue(0, end_position); |
788 for (int i = view_model_->view_size() - 1; | 743 for (int i = view_model_->view_size() - 1; |
789 i >= first_panel_index; --i) { | 744 i >= first_panel_index; --i) { |
790 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); | 745 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); |
791 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing); | 746 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing); |
792 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 747 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
793 end_position = layout_manager_->PrimaryAxisValue(x, y); | 748 end_position = layout_manager_->PrimaryAxisValue(x, y); |
794 } | 749 } |
795 | 750 |
796 // Icons on the left / top are guaranteed up to kLeftIconProportion of | 751 // Icons on the left / top are guaranteed up to kLeftIconProportion of |
797 // the available space. | 752 // the available space. |
798 int last_icon_position = layout_manager_->PrimaryAxisValue( | 753 int last_icon_position = layout_manager_->PrimaryAxisValue( |
799 view_model_->ideal_bounds(last_button_index).right(), | 754 view_model_->ideal_bounds(last_button_index).right(), |
800 view_model_->ideal_bounds(last_button_index).bottom()) | 755 view_model_->ideal_bounds(last_button_index).bottom()) + button_size; |
801 + button_size + inset; | |
802 if (!ash::switches::UseAlternateShelfLayout()) | |
803 last_icon_position += button_size; | |
804 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; | 756 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; |
805 if (last_icon_position < reserved_icon_space) | 757 if (last_icon_position < reserved_icon_space) |
806 end_position = last_icon_position; | 758 end_position = last_icon_position; |
807 else | 759 else |
808 end_position = std::max(end_position, reserved_icon_space); | 760 end_position = std::max(end_position, reserved_icon_space); |
809 | 761 |
810 bounds->overflow_bounds.set_size( | 762 bounds->overflow_bounds.set_size( |
811 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()), | 763 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()), |
812 layout_manager_->PrimaryAxisValue(height(), h))); | 764 layout_manager_->PrimaryAxisValue(height(), h))); |
813 | 765 |
814 if (ash::switches::UseAlternateShelfLayout()) { | 766 last_visible_index_ = DetermineLastVisibleIndex( |
815 last_visible_index_ = DetermineLastVisibleIndex( | 767 end_position - button_size); |
816 end_position - button_size); | |
817 } else { | |
818 last_visible_index_ = DetermineLastVisibleIndex( | |
819 end_position - inset - 2 * button_size); | |
820 } | |
821 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; | 768 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; |
822 bool show_overflow = | 769 bool show_overflow = last_visible_index_ < last_button_index || |
823 ((ash::switches::UseAlternateShelfLayout() ? 0 : 1) + | 770 last_hidden_index_ >= first_panel_index; |
824 last_visible_index_ < last_button_index || | |
825 last_hidden_index_ >= first_panel_index); | |
826 | 771 |
827 // Create Space for the overflow button | 772 // Create Space for the overflow button |
828 if (show_overflow && ash::switches::UseAlternateShelfLayout() && | 773 if (show_overflow && |
829 last_visible_index_ > 0 && last_visible_index_ < last_button_index) | 774 last_visible_index_ > 0 && last_visible_index_ < last_button_index) |
830 --last_visible_index_; | 775 --last_visible_index_; |
831 for (int i = 0; i < view_model_->view_size(); ++i) { | 776 for (int i = 0; i < view_model_->view_size(); ++i) { |
832 bool visible = i <= last_visible_index_ || i > last_hidden_index_; | 777 bool visible = i <= last_visible_index_ || i > last_hidden_index_; |
833 // Always show the app list. | |
834 if (!ash::switches::UseAlternateShelfLayout()) | |
835 visible |= (i == last_button_index); | |
836 // To receive drag event continously from |drag_view_| during the dragging | 778 // To receive drag event continously from |drag_view_| during the dragging |
837 // off from the shelf, don't make |drag_view_| invisible. It will be | 779 // off from the shelf, don't make |drag_view_| invisible. It will be |
838 // eventually invisible and removed from the |view_model_| by | 780 // eventually invisible and removed from the |view_model_| by |
839 // FinalizeRipOffDrag(). | 781 // FinalizeRipOffDrag(). |
840 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) | 782 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) |
841 continue; | 783 continue; |
842 view_model_->view_at(i)->SetVisible(visible); | 784 view_model_->view_at(i)->SetVisible(visible); |
843 } | 785 } |
844 | 786 |
845 overflow_button_->SetVisible(show_overflow); | 787 overflow_button_->SetVisible(show_overflow); |
846 if (show_overflow) { | 788 if (show_overflow) { |
847 DCHECK_NE(0, view_model_->view_size()); | 789 DCHECK_NE(0, view_model_->view_size()); |
848 if (last_visible_index_ == -1) { | 790 if (last_visible_index_ == -1) { |
849 x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); | 791 x = 0; |
850 y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); | 792 y = 0; |
851 } else if (last_visible_index_ == last_button_index | |
852 && !ash::switches::UseAlternateShelfLayout()) { | |
853 x = view_model_->ideal_bounds(last_visible_index_).x(); | |
854 y = view_model_->ideal_bounds(last_visible_index_).y(); | |
855 } else { | 793 } else { |
856 x = layout_manager_->PrimaryAxisValue( | 794 x = layout_manager_->PrimaryAxisValue( |
857 view_model_->ideal_bounds(last_visible_index_).right(), | 795 view_model_->ideal_bounds(last_visible_index_).right(), |
858 view_model_->ideal_bounds(last_visible_index_).x()); | 796 view_model_->ideal_bounds(last_visible_index_).x()); |
859 y = layout_manager_->PrimaryAxisValue( | 797 y = layout_manager_->PrimaryAxisValue( |
860 view_model_->ideal_bounds(last_visible_index_).y(), | 798 view_model_->ideal_bounds(last_visible_index_).y(), |
861 view_model_->ideal_bounds(last_visible_index_).bottom()); | 799 view_model_->ideal_bounds(last_visible_index_).bottom()); |
862 } | 800 } |
863 // Set all hidden panel icon positions to be on the overflow button. | 801 // Set all hidden panel icon positions to be on the overflow button. |
864 for (int i = first_panel_index; i <= last_hidden_index_; ++i) | 802 for (int i = first_panel_index; i <= last_hidden_index_; ++i) |
865 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 803 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
866 | 804 |
867 // Add more space between last visible item and overflow button. | 805 // Add more space between last visible item and overflow button. |
868 // Without this, two buttons look too close compared with other items. | 806 // Without this, two buttons look too close compared with other items. |
869 if (ash::switches::UseAlternateShelfLayout()) { | 807 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x); |
870 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x); | 808 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing); |
871 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing); | |
872 } | |
873 | 809 |
874 bounds->overflow_bounds.set_x(x); | 810 bounds->overflow_bounds.set_x(x); |
875 bounds->overflow_bounds.set_y(y); | 811 bounds->overflow_bounds.set_y(y); |
876 if (!ash::switches::UseAlternateShelfLayout()) { | |
877 // Position app list after overflow button. | |
878 gfx::Rect app_list_bounds = view_model_->ideal_bounds(last_button_index); | |
879 | |
880 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); | |
881 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); | |
882 app_list_bounds.set_x(x); | |
883 app_list_bounds.set_y(y); | |
884 view_model_->set_ideal_bounds(last_button_index, app_list_bounds); | |
885 } | |
886 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) | 812 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) |
887 UpdateOverflowRange(overflow_bubble_->shelf_view()); | 813 UpdateOverflowRange(overflow_bubble_->shelf_view()); |
888 } else { | 814 } else { |
889 if (overflow_bubble_) | 815 if (overflow_bubble_) |
890 overflow_bubble_->Hide(); | 816 overflow_bubble_->Hide(); |
891 } | 817 } |
892 } | 818 } |
893 | 819 |
894 int ShelfView::DetermineLastVisibleIndex(int max_value) const { | 820 int ShelfView::DetermineLastVisibleIndex(int max_value) const { |
895 int index = model_->FirstPanelIndex() - 1; | 821 int index = model_->FirstPanelIndex() - 1; |
(...skipping 28 matching lines...) Expand all Loading... |
924 void ShelfView::AnimateToIdealBounds() { | 850 void ShelfView::AnimateToIdealBounds() { |
925 IdealBounds ideal_bounds; | 851 IdealBounds ideal_bounds; |
926 CalculateIdealBounds(&ideal_bounds); | 852 CalculateIdealBounds(&ideal_bounds); |
927 for (int i = 0; i < view_model_->view_size(); ++i) { | 853 for (int i = 0; i < view_model_->view_size(); ++i) { |
928 View* view = view_model_->view_at(i); | 854 View* view = view_model_->view_at(i); |
929 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i)); | 855 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i)); |
930 // Now that the item animation starts, we have to make sure that the | 856 // Now that the item animation starts, we have to make sure that the |
931 // padding of the first gets properly transferred to the new first item. | 857 // padding of the first gets properly transferred to the new first item. |
932 if (i && view->border()) | 858 if (i && view->border()) |
933 view->SetBorder(views::Border::NullBorder()); | 859 view->SetBorder(views::Border::NullBorder()); |
934 else if (!i && !view->border()) | |
935 UpdateFirstButtonPadding(); | |
936 } | 860 } |
937 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); | 861 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); |
938 } | 862 } |
939 | 863 |
940 views::View* ShelfView::CreateViewForItem(const ShelfItem& item) { | 864 views::View* ShelfView::CreateViewForItem(const ShelfItem& item) { |
941 views::View* view = NULL; | 865 views::View* view = NULL; |
942 switch (item.type) { | 866 switch (item.type) { |
943 case TYPE_BROWSER_SHORTCUT: | 867 case TYPE_BROWSER_SHORTCUT: |
944 case TYPE_APP_SHORTCUT: | 868 case TYPE_APP_SHORTCUT: |
945 case TYPE_WINDOWED_APP: | 869 case TYPE_WINDOWED_APP: |
946 case TYPE_PLATFORM_APP: | 870 case TYPE_PLATFORM_APP: |
947 case TYPE_DIALOG: | 871 case TYPE_DIALOG: |
948 case TYPE_APP_PANEL: { | 872 case TYPE_APP_PANEL: { |
949 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); | 873 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); |
950 button->SetImage(item.image); | 874 button->SetImage(item.image); |
951 ReflectItemStatus(item, button); | 875 ReflectItemStatus(item, button); |
952 view = button; | 876 view = button; |
953 break; | 877 break; |
954 } | 878 } |
955 | 879 |
956 case TYPE_APP_LIST: { | 880 case TYPE_APP_LIST: { |
957 if (ash::switches::UseAlternateShelfLayout()) { | 881 view = new AppListButton(this, this, layout_manager_->shelf_widget()); |
958 view = new AlternateAppListButton(this, | |
959 this, | |
960 layout_manager_->shelf_widget()); | |
961 } else { | |
962 // TODO(dave): turn this into a ShelfButton too. | |
963 AppListButton* button = new AppListButton(this, this); | |
964 button->SetImageAlignment( | |
965 layout_manager_->SelectValueForShelfAlignment( | |
966 views::ImageButton::ALIGN_CENTER, | |
967 views::ImageButton::ALIGN_LEFT, | |
968 views::ImageButton::ALIGN_RIGHT, | |
969 views::ImageButton::ALIGN_CENTER), | |
970 layout_manager_->SelectValueForShelfAlignment( | |
971 views::ImageButton::ALIGN_TOP, | |
972 views::ImageButton::ALIGN_MIDDLE, | |
973 views::ImageButton::ALIGN_MIDDLE, | |
974 views::ImageButton::ALIGN_BOTTOM)); | |
975 view = button; | |
976 } | |
977 break; | 882 break; |
978 } | 883 } |
979 | 884 |
980 default: | 885 default: |
981 break; | 886 break; |
982 } | 887 } |
983 view->set_context_menu_controller(this); | 888 view->set_context_menu_controller(this); |
984 | 889 |
985 DCHECK(view); | 890 DCHECK(view); |
986 ConfigureChildView(view); | 891 ConfigureChildView(view); |
(...skipping 336 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); | 1228 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); |
1324 overflow_view->OnShelfAlignmentChanged(); | 1229 overflow_view->OnShelfAlignmentChanged(); |
1325 overflow_view->main_shelf_ = this; | 1230 overflow_view->main_shelf_ = this; |
1326 UpdateOverflowRange(overflow_view); | 1231 UpdateOverflowRange(overflow_view); |
1327 | 1232 |
1328 overflow_bubble_->Show(overflow_button_, overflow_view); | 1233 overflow_bubble_->Show(overflow_button_, overflow_view); |
1329 | 1234 |
1330 Shell::GetInstance()->UpdateShelfVisibility(); | 1235 Shell::GetInstance()->UpdateShelfVisibility(); |
1331 } | 1236 } |
1332 | 1237 |
1333 void ShelfView::UpdateFirstButtonPadding() { | |
1334 if (ash::switches::UseAlternateShelfLayout()) | |
1335 return; | |
1336 | |
1337 // Creates an empty border for first shelf button to make included leading | |
1338 // inset act as the button's padding. This is only needed on button creation | |
1339 // and when shelf alignment changes. | |
1340 if (view_model_->view_size() > 0) { | |
1341 view_model_->view_at(0)->SetBorder(views::Border::CreateEmptyBorder( | |
1342 layout_manager_->PrimaryAxisValue(0, leading_inset_), | |
1343 layout_manager_->PrimaryAxisValue(leading_inset_, 0), | |
1344 0, | |
1345 0)); | |
1346 } | |
1347 } | |
1348 | |
1349 void ShelfView::OnFadeOutAnimationEnded() { | 1238 void ShelfView::OnFadeOutAnimationEnded() { |
1350 AnimateToIdealBounds(); | 1239 AnimateToIdealBounds(); |
1351 StartFadeInLastVisibleItem(); | 1240 StartFadeInLastVisibleItem(); |
1352 } | 1241 } |
1353 | 1242 |
1354 void ShelfView::StartFadeInLastVisibleItem() { | 1243 void ShelfView::StartFadeInLastVisibleItem() { |
1355 // If overflow button is visible and there is a valid new last item, fading | 1244 // If overflow button is visible and there is a valid new last item, fading |
1356 // the new last item in after sliding animation is finished. | 1245 // the new last item in after sliding animation is finished. |
1357 if (overflow_button_->visible() && last_visible_index_ >= 0) { | 1246 if (overflow_button_->visible() && last_visible_index_ >= 0) { |
1358 views::View* last_visible_view = view_model_->view_at(last_visible_index_); | 1247 views::View* last_visible_view = view_model_->view_at(last_visible_index_); |
1359 last_visible_view->layer()->SetOpacity(0); | 1248 last_visible_view->layer()->SetOpacity(0); |
1360 bounds_animator_->SetAnimationDelegate( | 1249 bounds_animator_->SetAnimationDelegate( |
1361 last_visible_view, | 1250 last_visible_view, |
1362 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), | 1251 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), |
1363 true); | 1252 true); |
1364 } | 1253 } |
1365 } | 1254 } |
1366 | 1255 |
1367 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { | 1256 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { |
1368 const int first_overflow_index = last_visible_index_ + 1; | 1257 const int first_overflow_index = last_visible_index_ + 1; |
1369 const int last_overflow_index = last_hidden_index_; | 1258 const int last_overflow_index = last_hidden_index_; |
1370 DCHECK_LE(first_overflow_index, last_overflow_index); | 1259 DCHECK_LE(first_overflow_index, last_overflow_index); |
1371 DCHECK_LT(last_overflow_index, view_model_->view_size()); | 1260 DCHECK_LT(last_overflow_index, view_model_->view_size()); |
1372 | 1261 |
1373 overflow_view->first_visible_index_ = first_overflow_index; | 1262 overflow_view->first_visible_index_ = first_overflow_index; |
1374 overflow_view->last_visible_index_ = last_overflow_index; | 1263 overflow_view->last_visible_index_ = last_overflow_index; |
1375 } | 1264 } |
1376 | 1265 |
1377 int ShelfView::GetButtonSize() const { | |
1378 return ash::switches::UseAlternateShelfLayout() ? | |
1379 kButtonSize : kShelfPreferredSize; | |
1380 } | |
1381 | |
1382 int ShelfView::GetButtonSpacing() const { | |
1383 return ash::switches::UseAlternateShelfLayout() ? | |
1384 kAlternateButtonSpacing : kButtonSpacing; | |
1385 } | |
1386 | |
1387 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { | 1266 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { |
1388 gfx::Rect active_bounds; | 1267 gfx::Rect active_bounds; |
1389 | 1268 |
1390 for (int i = 0; i < child_count(); ++i) { | 1269 for (int i = 0; i < child_count(); ++i) { |
1391 views::View* child = child_at(i); | 1270 views::View* child = child_at(i); |
1392 if (child == overflow_button_) | 1271 if (child == overflow_button_) |
1393 continue; | 1272 continue; |
1394 if (!ShouldShowTooltipForView(child)) | 1273 if (!ShouldShowTooltipForView(child)) |
1395 continue; | 1274 continue; |
1396 | 1275 |
(...skipping 12 matching lines...) Expand all Loading... |
1409 } | 1288 } |
1410 | 1289 |
1411 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() { | 1290 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() { |
1412 gfx::Size preferred_size; | 1291 gfx::Size preferred_size; |
1413 if (is_overflow_mode()) { | 1292 if (is_overflow_mode()) { |
1414 DCHECK(owner_overflow_bubble_); | 1293 DCHECK(owner_overflow_bubble_); |
1415 gfx::Rect bubble_bounds = | 1294 gfx::Rect bubble_bounds = |
1416 owner_overflow_bubble_->bubble_view()->GetBubbleBounds(); | 1295 owner_overflow_bubble_->bubble_view()->GetBubbleBounds(); |
1417 preferred_size = bubble_bounds.size(); | 1296 preferred_size = bubble_bounds.size(); |
1418 } else { | 1297 } else { |
1419 const int preferred_shelf_size = layout_manager_->GetPreferredShelfSize(); | |
1420 | |
1421 const int last_button_index = view_model_->view_size() - 1; | 1298 const int last_button_index = view_model_->view_size() - 1; |
1422 gfx::Rect last_button_bounds = | 1299 gfx::Rect last_button_bounds = |
1423 view_model_->view_at(last_button_index)->bounds(); | 1300 view_model_->view_at(last_button_index)->bounds(); |
1424 if (overflow_button_->visible() && | 1301 if (overflow_button_->visible() && |
1425 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { | 1302 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { |
1426 // When overflow button is visible and shelf has no panel items, | 1303 // When overflow button is visible and shelf has no panel items, |
1427 // last_button_bounds should be overflow button's bounds. | 1304 // last_button_bounds should be overflow button's bounds. |
1428 last_button_bounds = overflow_button_->bounds(); | 1305 last_button_bounds = overflow_button_->bounds(); |
1429 } | 1306 } |
1430 | 1307 |
1431 if (layout_manager_->IsHorizontalAlignment()) { | 1308 if (layout_manager_->IsHorizontalAlignment()) { |
1432 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_, | 1309 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_, |
1433 preferred_shelf_size); | 1310 kShelfSize); |
1434 } else { | 1311 } else { |
1435 preferred_size = gfx::Size(preferred_shelf_size, | 1312 preferred_size = gfx::Size(kShelfSize, |
1436 last_button_bounds.bottom() + leading_inset_); | 1313 last_button_bounds.bottom() + leading_inset_); |
1437 } | 1314 } |
1438 } | 1315 } |
1439 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); | 1316 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); |
1440 | 1317 |
1441 // In overflow mode, we should use OverflowBubbleView as a source for | 1318 // In overflow mode, we should use OverflowBubbleView as a source for |
1442 // converting |origin| to screen coordinates. When a scroll operation is | 1319 // converting |origin| to screen coordinates. When a scroll operation is |
1443 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can | 1320 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can |
1444 // be changed. | 1321 // be changed. |
1445 if (is_overflow_mode()) | 1322 if (is_overflow_mode()) |
(...skipping 30 matching lines...) Expand all Loading... |
1476 // the list. | 1353 // the list. |
1477 if (at_end) | 1354 if (at_end) |
1478 return view_model_->view_size(); | 1355 return view_model_->view_size(); |
1479 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; | 1356 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; |
1480 } | 1357 } |
1481 | 1358 |
1482 gfx::Size ShelfView::GetPreferredSize() { | 1359 gfx::Size ShelfView::GetPreferredSize() { |
1483 IdealBounds ideal_bounds; | 1360 IdealBounds ideal_bounds; |
1484 CalculateIdealBounds(&ideal_bounds); | 1361 CalculateIdealBounds(&ideal_bounds); |
1485 | 1362 |
1486 const int preferred_size = layout_manager_->GetPreferredShelfSize(); | |
1487 | |
1488 int last_button_index = is_overflow_mode() ? | 1363 int last_button_index = is_overflow_mode() ? |
1489 last_visible_index_ : view_model_->view_size() - 1; | 1364 last_visible_index_ : view_model_->view_size() - 1; |
1490 | 1365 |
1491 // When an item is dragged off from the overflow bubble, it is moved to last | 1366 // When an item is dragged off from the overflow bubble, it is moved to last |
1492 // position and and changed to invisible. Overflow bubble size should be | 1367 // position and and changed to invisible. Overflow bubble size should be |
1493 // shrunk to fit only for visible items. | 1368 // shrunk to fit only for visible items. |
1494 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible | 1369 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible |
1495 // items in the shelf. | 1370 // items in the shelf. |
1496 if (is_overflow_mode() && | 1371 if (is_overflow_mode() && |
1497 dragged_off_shelf_ && | 1372 dragged_off_shelf_ && |
1498 !dragged_off_from_overflow_to_shelf_ && | 1373 !dragged_off_from_overflow_to_shelf_ && |
1499 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) | 1374 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) |
1500 last_button_index--; | 1375 last_button_index--; |
1501 | 1376 |
1502 const gfx::Rect last_button_bounds = | 1377 const gfx::Rect last_button_bounds = |
1503 last_button_index >= first_visible_index_ ? | 1378 last_button_index >= first_visible_index_ ? |
1504 view_model_->ideal_bounds(last_button_index) : | 1379 view_model_->ideal_bounds(last_button_index) : |
1505 gfx::Rect(gfx::Size(preferred_size, preferred_size)); | 1380 gfx::Rect(gfx::Size(kShelfSize, kShelfSize)); |
1506 | 1381 |
1507 if (layout_manager_->IsHorizontalAlignment()) { | 1382 if (layout_manager_->IsHorizontalAlignment()) { |
1508 return gfx::Size(last_button_bounds.right() + leading_inset_, | 1383 return gfx::Size(last_button_bounds.right() + leading_inset_, kShelfSize); |
1509 preferred_size); | |
1510 } | 1384 } |
1511 | 1385 |
1512 return gfx::Size(preferred_size, | 1386 return gfx::Size(kShelfSize, |
1513 last_button_bounds.bottom() + leading_inset_); | 1387 last_button_bounds.bottom() + leading_inset_); |
1514 } | 1388 } |
1515 | 1389 |
1516 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1390 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
1517 // This bounds change is produced by the shelf movement and all content has | 1391 // This bounds change is produced by the shelf movement and all content has |
1518 // to follow. Using an animation at that time would produce a time lag since | 1392 // to follow. Using an animation at that time would produce a time lag since |
1519 // the animation of the BoundsAnimator has itself a delay before it arrives | 1393 // the animation of the BoundsAnimator has itself a delay before it arrives |
1520 // at the required location. As such we tell the animator to go there | 1394 // at the required location. As such we tell the animator to go there |
1521 // immediately. | 1395 // immediately. |
1522 BoundsAnimatorDisabler disabler(bounds_animator_.get()); | 1396 BoundsAnimatorDisabler disabler(bounds_animator_.get()); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1667 view_model_->Move(start_index, target_index); | 1541 view_model_->Move(start_index, target_index); |
1668 // When cancelling a drag due to a shelf item being added, the currently | 1542 // When cancelling a drag due to a shelf item being added, the currently |
1669 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1543 // dragged item is moved back to its initial position. AnimateToIdealBounds |
1670 // will be called again when the new item is added to the |view_model_| but | 1544 // will be called again when the new item is added to the |view_model_| but |
1671 // at this time the |view_model_| is inconsistent with the |model_|. | 1545 // at this time the |view_model_| is inconsistent with the |model_|. |
1672 if (!cancelling_drag_model_changed_) | 1546 if (!cancelling_drag_model_changed_) |
1673 AnimateToIdealBounds(); | 1547 AnimateToIdealBounds(); |
1674 } | 1548 } |
1675 | 1549 |
1676 void ShelfView::ShelfStatusChanged() { | 1550 void ShelfView::ShelfStatusChanged() { |
1677 if (ash::switches::UseAlternateShelfLayout()) | 1551 // Nothing to do here. |
1678 return; | |
1679 AppListButton* app_list_button = | |
1680 static_cast<AppListButton*>(GetAppListButtonView()); | |
1681 if (model_->status() == ShelfModel::STATUS_LOADING) | |
1682 app_list_button->StartLoadingAnimation(); | |
1683 else | |
1684 app_list_button->StopLoadingAnimation(); | |
1685 } | 1552 } |
1686 | 1553 |
1687 void ShelfView::PointerPressedOnButton(views::View* view, | 1554 void ShelfView::PointerPressedOnButton(views::View* view, |
1688 Pointer pointer, | 1555 Pointer pointer, |
1689 const ui::LocatedEvent& event) { | 1556 const ui::LocatedEvent& event) { |
1690 if (drag_view_) | 1557 if (drag_view_) |
1691 return; | 1558 return; |
1692 | 1559 |
1693 int index = view_model_->GetIndexOfView(view); | 1560 int index = view_model_->GetIndexOfView(view); |
1694 if (index == -1) | 1561 if (index == -1) |
(...skipping 355 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2050 distance = bounds.x() - coordinate.x(); | 1917 distance = bounds.x() - coordinate.x(); |
2051 break; | 1918 break; |
2052 case SHELF_ALIGNMENT_TOP: | 1919 case SHELF_ALIGNMENT_TOP: |
2053 distance = coordinate.y() - bounds.bottom(); | 1920 distance = coordinate.y() - bounds.bottom(); |
2054 break; | 1921 break; |
2055 } | 1922 } |
2056 return distance > 0 ? distance : 0; | 1923 return distance > 0 ? distance : 0; |
2057 } | 1924 } |
2058 | 1925 |
2059 } // namespace ash | 1926 } // namespace ash |
OLD | NEW |