Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(63)

Side by Side Diff: ash/launcher/launcher_view.cc

Issue 22291003: ash:Shelf Update Alternate Layout (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/launcher/launcher_view.h" 5 #include "ash/launcher/launcher_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"
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 namespace internal { 59 namespace internal {
60 60
61 // Default amount content is inset on the left edge. 61 // Default amount content is inset on the left edge.
62 const int kDefaultLeadingInset = 8; 62 const int kDefaultLeadingInset = 8;
63 63
64 // Minimum distance before drag starts. 64 // Minimum distance before drag starts.
65 const int kMinimumDragDistance = 8; 65 const int kMinimumDragDistance = 8;
66 66
67 // Size between the buttons. 67 // Size between the buttons.
68 const int kButtonSpacing = 4; 68 const int kButtonSpacing = 4;
69 const int kAlternateButtonSpacing = 10;
70
71 // Size allocated to for each button.
72 const int kButtonSize = 44;
69 73
70 // Additional spacing for the left and right side of icons. 74 // Additional spacing for the left and right side of icons.
71 const int kHorizontalIconSpacing = 2; 75 const int kHorizontalIconSpacing = 2;
72 76
73 // Inset for items which do not have an icon. 77 // Inset for items which do not have an icon.
74 const int kHorizontalNoIconInsetSpacing = 78 const int kHorizontalNoIconInsetSpacing =
75 kHorizontalIconSpacing + kDefaultLeadingInset; 79 kHorizontalIconSpacing + kDefaultLeadingInset;
76 80
77 // The proportion of the launcher space reserved for non-panel icons. Panels 81 // The proportion of the launcher space reserved for non-panel icons. Panels
78 // may flow into this space but will be put into the overflow bubble if there 82 // may flow into this space but will be put into the overflow bubble if there
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
679 683
680 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) { 684 void LauncherView::CalculateIdealBounds(IdealBounds* bounds) {
681 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); 685 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
682 686
683 int available_size = shelf->PrimaryAxisValue(width(), height()); 687 int available_size = shelf->PrimaryAxisValue(width(), height());
684 DCHECK(model_->item_count() == view_model_->view_size()); 688 DCHECK(model_->item_count() == view_model_->view_size());
685 if (!available_size) 689 if (!available_size)
686 return; 690 return;
687 691
688 int first_panel_index = model_->FirstPanelIndex(); 692 int first_panel_index = model_->FirstPanelIndex();
689 // TODO(harrym): if alternate shelf layout stays, rename app_list_index. 693 int last_button_index = first_panel_index - 1;
690 int app_list_index = first_panel_index - 1;
691 694
692 // Initial x,y values account both leading_inset in primary 695 // Initial x,y values account both leading_inset in primary
693 // coordinate and secondary coordinate based on the dynamic edge of the 696 // coordinate and secondary coordinate based on the dynamic edge of the
694 // launcher (eg top edge on bottom-aligned launcher). 697 // launcher (eg top edge on bottom-aligned launcher).
695 int x = shelf->SelectValueForShelfAlignment( 698 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset();
696 leading_inset(), 699 int x = shelf->SelectValueForShelfAlignment(inset, 0, 0, inset);
697 0, 700 int y = shelf->SelectValueForShelfAlignment(0, inset, inset, 0);
698 0,
699 leading_inset());
700 int y = shelf->SelectValueForShelfAlignment(
701 0,
702 leading_inset(),
703 leading_inset(),
704 0);
705 701
706 int shelf_size = ash::switches::UseAlternateShelfLayout() ? 702 int button_size = ash::switches::UseAlternateShelfLayout() ?
707 ShelfLayoutManager::kShelfSize : kLauncherPreferredSize; 703 kButtonSize : kLauncherPreferredSize;
704 int button_spacing = ash::switches::UseAlternateShelfLayout() ?
705 kAlternateButtonSpacing : kButtonSpacing;
708 706
709 int w = shelf->PrimaryAxisValue(shelf_size, width()); 707 int w = shelf->PrimaryAxisValue(button_size, width());
710 int h = shelf->PrimaryAxisValue(height(), shelf_size); 708 int h = shelf->PrimaryAxisValue(height(), button_size);
711 for (int i = 0; i < view_model_->view_size(); ++i) { 709 for (int i = 0; i < view_model_->view_size(); ++i) {
712 if (i < first_visible_index_) { 710 if (i < first_visible_index_) {
713 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 711 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
714 continue; 712 continue;
715 } 713 }
716 714
717 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 715 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
718 if (i != app_list_index) { 716 if (i != last_button_index) {
719 x = shelf->PrimaryAxisValue(x + w + kButtonSpacing, x); 717 x = shelf->PrimaryAxisValue(x + w + button_spacing, x);
720 y = shelf->PrimaryAxisValue(y, y + h + kButtonSpacing); 718 y = shelf->PrimaryAxisValue(y, y + h + button_spacing);
721 } 719 }
722 } 720 }
723 721
724 if (is_overflow_mode()) { 722 if (is_overflow_mode()) {
725 DCHECK_LT(last_visible_index_, view_model_->view_size()); 723 DCHECK_LT(last_visible_index_, view_model_->view_size());
726 for (int i = 0; i < view_model_->view_size(); ++i) { 724 for (int i = 0; i < view_model_->view_size(); ++i) {
727 view_model_->view_at(i)->SetVisible( 725 bool visible = i >= first_visible_index_ &&
728 i >= first_visible_index_ && 726 i <= last_visible_index_;
729 i != app_list_index && 727 if (!ash::switches::UseAlternateShelfLayout())
730 i <= last_visible_index_); 728 visible &= i != last_button_index;
729 view_model_->view_at(i)->SetVisible(visible);
731 } 730 }
732 return; 731 return;
733 } 732 }
734 733
735 // To address Fitt's law, we make the first launcher button include the 734 // To address Fitt's law, we make the first launcher button include the
736 // leading inset (if there is one). 735 // leading inset (if there is one).
737 if (view_model_->view_size() > 0) { 736 if (!ash::switches::UseAlternateShelfLayout()) {
738 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( 737 if (view_model_->view_size() > 0) {
739 shelf->PrimaryAxisValue(leading_inset() + w, w), 738 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size(
740 shelf->PrimaryAxisValue(h, leading_inset() + h)))); 739 shelf->PrimaryAxisValue(inset + w, w),
740 shelf->PrimaryAxisValue(h, inset + h))));
741 }
741 } 742 }
742 743
743 // Right aligned icons. 744 // Right aligned icons.
744 int end_position = available_size - kButtonSpacing; 745 int end_position = available_size - button_spacing;
745 x = shelf->PrimaryAxisValue(end_position, 0); 746 x = shelf->PrimaryAxisValue(end_position, 0);
746 y = shelf->PrimaryAxisValue(0, end_position); 747 y = shelf->PrimaryAxisValue(0, end_position);
747 for (int i = view_model_->view_size() - 1; 748 for (int i = view_model_->view_size() - 1;
748 i >= first_panel_index; --i) { 749 i >= first_panel_index; --i) {
749 x = shelf->PrimaryAxisValue(x - w - kButtonSpacing, x); 750 x = shelf->PrimaryAxisValue(x - w - button_spacing, x);
750 y = shelf->PrimaryAxisValue(y, y - h - kButtonSpacing); 751 y = shelf->PrimaryAxisValue(y, y - h - button_spacing);
751 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 752 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
752 end_position = shelf->PrimaryAxisValue(x, y); 753 end_position = shelf->PrimaryAxisValue(x, y);
753 } 754 }
754 755
755 // Icons on the left / top are guaranteed up to kLeftIconProportion of 756 // Icons on the left / top are guaranteed up to kLeftIconProportion of
756 // the available space. 757 // the available space.
757 int last_icon_position = shelf->PrimaryAxisValue( 758 int last_icon_position = shelf->PrimaryAxisValue(
758 view_model_->ideal_bounds(first_panel_index - 1).right(), 759 view_model_->ideal_bounds(last_button_index).right(),
759 view_model_->ideal_bounds(first_panel_index - 1).bottom()) + 760 view_model_->ideal_bounds(last_button_index).bottom())
760 2 * kLauncherPreferredSize + leading_inset(); 761 + button_size + inset;
762 if (!ash::switches::UseAlternateShelfLayout())
763 last_icon_position += button_size;
761 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; 764 int reserved_icon_space = available_size * kReservedNonPanelIconProportion;
762 if (last_icon_position < reserved_icon_space) 765 if (last_icon_position < reserved_icon_space)
763 end_position = last_icon_position; 766 end_position = last_icon_position;
764 else 767 else
765 end_position = std::max(end_position, reserved_icon_space); 768 end_position = std::max(end_position, reserved_icon_space);
766 769
767 bounds->overflow_bounds.set_size(gfx::Size( 770 bounds->overflow_bounds.set_size(gfx::Size(
768 shelf->PrimaryAxisValue(w, width()), 771 shelf->PrimaryAxisValue(w, width()),
769 shelf->PrimaryAxisValue(height(), h))); 772 shelf->PrimaryAxisValue(height(), h)));
770 last_visible_index_ = DetermineLastVisibleIndex( 773 if (ash::switches::UseAlternateShelfLayout())
771 end_position - leading_inset() - 2 * kLauncherPreferredSize); 774 last_visible_index_ = DetermineLastVisibleIndex(
775 end_position - button_size);
776 else
777 last_visible_index_ = DetermineLastVisibleIndex(
778 end_position - inset - 2 * button_size);
772 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; 779 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1;
773 bool show_overflow = (last_visible_index_ + 1 < app_list_index || 780 bool show_overflow =
774 last_hidden_index_ >= first_panel_index); 781 ((ash::switches::UseAlternateShelfLayout() ? 0 : 1) +
782 last_visible_index_ < last_button_index ||
783 last_hidden_index_ >= first_panel_index);
775 784
785 // Create Space for the overflow button
786 if (show_overflow && ash::switches::UseAlternateShelfLayout() &&
787 last_visible_index_ > 0)
Mr4D (OOO till 08-26) 2013/08/06 21:10:34 Shouldn't "last_visible_index_" always be > 0?
Harry McCleave 2013/08/06 22:41:06 This was to maintain the code stability in all pat
Mr4D (OOO till 08-26) 2013/08/06 23:32:19 If the *overflow* gets shown - there should be a w
788 --last_visible_index_;
776 for (int i = 0; i < view_model_->view_size(); ++i) { 789 for (int i = 0; i < view_model_->view_size(); ++i) {
777 view_model_->view_at(i)->SetVisible( 790 bool visible = i <= last_visible_index_ || i > last_hidden_index_;
778 i <= last_visible_index_ || 791 // Always show the app list.
779 i == app_list_index || 792 if (!ash::switches::UseAlternateShelfLayout())
780 i > last_hidden_index_); 793 visible |= (i == last_button_index);
794 view_model_->view_at(i)->SetVisible(visible);
781 } 795 }
782 796
783 overflow_button_->SetVisible(show_overflow); 797 overflow_button_->SetVisible(show_overflow);
784 if (show_overflow) { 798 if (show_overflow) {
785 DCHECK_NE(0, view_model_->view_size()); 799 DCHECK_NE(0, view_model_->view_size());
786 if (last_visible_index_ == -1) { 800 if (last_visible_index_ == -1) {
787 x = shelf->SelectValueForShelfAlignment( 801 x = shelf->SelectValueForShelfAlignment(inset, 0, 0, inset);
788 leading_inset(), 802 y = shelf->SelectValueForShelfAlignment(0, inset, inset, 0);
789 0, 803 } else if (last_visible_index_ == last_button_index) {
790 0,
791 leading_inset());
792 y = shelf->SelectValueForShelfAlignment(
793 0,
794 leading_inset(),
795 leading_inset(),
796 0);
797 } else if (last_visible_index_ == app_list_index) {
798 x = view_model_->ideal_bounds(last_visible_index_).x(); 804 x = view_model_->ideal_bounds(last_visible_index_).x();
799 y = view_model_->ideal_bounds(last_visible_index_).y(); 805 y = view_model_->ideal_bounds(last_visible_index_).y();
800 } else { 806 } else {
801 x = shelf->PrimaryAxisValue( 807 x = shelf->PrimaryAxisValue(
802 view_model_->ideal_bounds(last_visible_index_).right(), 808 view_model_->ideal_bounds(last_visible_index_).right(),
803 view_model_->ideal_bounds(last_visible_index_).x()); 809 view_model_->ideal_bounds(last_visible_index_).x());
804 y = shelf->PrimaryAxisValue( 810 y = shelf->PrimaryAxisValue(
805 view_model_->ideal_bounds(last_visible_index_).y(), 811 view_model_->ideal_bounds(last_visible_index_).y(),
806 view_model_->ideal_bounds(last_visible_index_).bottom()); 812 view_model_->ideal_bounds(last_visible_index_).bottom());
807 } 813 }
808 gfx::Rect app_list_bounds = view_model_->ideal_bounds(app_list_index);
809 bounds->overflow_bounds.set_x(x);
810 bounds->overflow_bounds.set_y(y);
811
812 // Set all hidden panel icon positions to be on the overflow button. 814 // Set all hidden panel icon positions to be on the overflow button.
813 for (int i = first_panel_index; i <= last_hidden_index_; ++i) 815 for (int i = first_panel_index; i <= last_hidden_index_; ++i)
814 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 816 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
815 817
816 x = shelf->PrimaryAxisValue(x + w + kButtonSpacing, x); 818 bounds->overflow_bounds.set_x(x);
817 y = shelf->PrimaryAxisValue(y, y + h + kButtonSpacing); 819 bounds->overflow_bounds.set_y(y);
818 app_list_bounds.set_x(x); 820 if (!ash::switches::UseAlternateShelfLayout()) {
819 app_list_bounds.set_y(y); 821 // Position app list after overflow button.
820 view_model_->set_ideal_bounds(app_list_index, app_list_bounds); 822 gfx::Rect app_list_bounds = view_model_->ideal_bounds(last_button_index);
821 823
824 x = shelf->PrimaryAxisValue(x + w + button_spacing, x);
825 y = shelf->PrimaryAxisValue(y, y + h + button_spacing);
826 app_list_bounds.set_x(x);
827 app_list_bounds.set_y(y);
828 view_model_->set_ideal_bounds(last_button_index, app_list_bounds);
829 }
822 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) 830 if (overflow_bubble_.get() && overflow_bubble_->IsShowing())
823 UpdateOverflowRange(overflow_bubble_->launcher_view()); 831 UpdateOverflowRange(overflow_bubble_->launcher_view());
824 } else { 832 } else {
825 if (overflow_bubble_) 833 if (overflow_bubble_)
826 overflow_bubble_->Hide(); 834 overflow_bubble_->Hide();
827 } 835 }
828 } 836 }
829 837
830 int LauncherView::DetermineLastVisibleIndex(int max_value) const { 838 int LauncherView::DetermineLastVisibleIndex(int max_value) const {
831 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); 839 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
1029 return; 1037 return;
1030 1038
1031 // Change the model, the LauncherItemMoved() callback will handle the 1039 // Change the model, the LauncherItemMoved() callback will handle the
1032 // |view_model_| update. 1040 // |view_model_| update.
1033 model_->Move(current_index, target_index); 1041 model_->Move(current_index, target_index);
1034 bounds_animator_->StopAnimatingView(drag_view_); 1042 bounds_animator_->StopAnimatingView(drag_view_);
1035 } 1043 }
1036 1044
1037 bool LauncherView::SameDragType(LauncherItemType typea, 1045 bool LauncherView::SameDragType(LauncherItemType typea,
1038 LauncherItemType typeb) const { 1046 LauncherItemType typeb) const {
1039 if (ash::switches::UseAlternateShelfLayout()) { 1047 switch (typea) {
1040 // TODO(harrym): Allow app list to be repositionable, if this goes live 1048 case TYPE_TABBED:
1041 // (no flag) the pref file has to be updated so the changes persist. 1049 case TYPE_PLATFORM_APP:
1042 switch (typea) {
1043 case TYPE_TABBED:
1044 case TYPE_PLATFORM_APP:
1045 return (typeb == TYPE_TABBED || typeb == TYPE_PLATFORM_APP); 1050 return (typeb == TYPE_TABBED || typeb == TYPE_PLATFORM_APP);
1046 case TYPE_APP_SHORTCUT: 1051 case TYPE_APP_SHORTCUT:
1047 case TYPE_APP_LIST: 1052 case TYPE_BROWSER_SHORTCUT:
1048 case TYPE_BROWSER_SHORTCUT: 1053 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT);
1049 return (typeb == TYPE_APP_SHORTCUT || 1054 case TYPE_WINDOWED_APP:
1050 typeb == TYPE_APP_LIST || 1055 case TYPE_APP_LIST:
1051 typeb == TYPE_BROWSER_SHORTCUT); 1056 case TYPE_APP_PANEL:
1052 case TYPE_WINDOWED_APP: 1057 return typeb == typea;
1053 case TYPE_APP_PANEL:
1054 return typeb == typea;
1055 }
1056 } else {
1057 switch (typea) {
1058 case TYPE_TABBED:
1059 case TYPE_PLATFORM_APP:
1060 return (typeb == TYPE_TABBED || typeb == TYPE_PLATFORM_APP);
1061 case TYPE_APP_SHORTCUT:
1062 case TYPE_BROWSER_SHORTCUT:
1063 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT);
1064 case TYPE_WINDOWED_APP:
1065 case TYPE_APP_LIST:
1066 case TYPE_APP_PANEL:
1067 return typeb == typea;
1068 }
1069 } 1058 }
1070 NOTREACHED(); 1059 NOTREACHED();
1071 return false; 1060 return false;
1072 } 1061 }
1073 1062
1074 std::pair<int, int> LauncherView::GetDragRange(int index) { 1063 std::pair<int, int> LauncherView::GetDragRange(int index) {
1075 int min_index = -1; 1064 int min_index = -1;
1076 int max_index = -1; 1065 int max_index = -1;
1077 LauncherItemType type = model_->items()[index].type; 1066 LauncherItemType type = model_->items()[index].type;
1078 for (int i = 0; i < model_->item_count(); ++i) { 1067 for (int i = 0; i < model_->item_count(); ++i) {
(...skipping 25 matching lines...) Expand all
1104 overflow_view->Init(); 1093 overflow_view->Init();
1105 overflow_view->OnShelfAlignmentChanged(); 1094 overflow_view->OnShelfAlignmentChanged();
1106 UpdateOverflowRange(overflow_view); 1095 UpdateOverflowRange(overflow_view);
1107 1096
1108 overflow_bubble_->Show(overflow_button_, overflow_view); 1097 overflow_bubble_->Show(overflow_button_, overflow_view);
1109 1098
1110 Shell::GetInstance()->UpdateShelfVisibility(); 1099 Shell::GetInstance()->UpdateShelfVisibility();
1111 } 1100 }
1112 1101
1113 void LauncherView::UpdateFirstButtonPadding() { 1102 void LauncherView::UpdateFirstButtonPadding() {
1103 if (ash::switches::UseAlternateShelfLayout())
1104 return;
Mr4D (OOO till 08-26) 2013/08/06 21:10:34 Yeah! code which will go away soon!
Harry McCleave 2013/08/06 22:41:06 Indeed
1105
1114 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager(); 1106 ShelfLayoutManager* shelf = tooltip_->shelf_layout_manager();
1115 1107
1116 // Creates an empty border for first launcher button to make included leading 1108 // Creates an empty border for first launcher button to make included leading
1117 // inset act as the button's padding. This is only needed on button creation 1109 // inset act as the button's padding. This is only needed on button creation
1118 // and when shelf alignment changes. 1110 // and when shelf alignment changes.
1119 if (view_model_->view_size() > 0) { 1111 if (view_model_->view_size() > 0) {
1120 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( 1112 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder(
1121 shelf->PrimaryAxisValue(0, leading_inset()), 1113 shelf->PrimaryAxisValue(0, leading_inset()),
1122 shelf->PrimaryAxisValue(leading_inset(), 0), 1114 shelf->PrimaryAxisValue(leading_inset(), 0),
1123 0, 1115 0,
(...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
1706 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const { 1698 bool LauncherView::ShouldShowTooltipForView(const views::View* view) const {
1707 if (view == GetAppListButtonView() && 1699 if (view == GetAppListButtonView() &&
1708 Shell::GetInstance()->GetAppListWindow()) 1700 Shell::GetInstance()->GetAppListWindow())
1709 return false; 1701 return false;
1710 const LauncherItem* item = LauncherItemForView(view); 1702 const LauncherItem* item = LauncherItemForView(view);
1711 return (!item || delegate_->ShouldShowTooltip(*item)); 1703 return (!item || delegate_->ShouldShowTooltip(*item));
1712 } 1704 }
1713 1705
1714 } // namespace internal 1706 } // namespace internal
1715 } // namespace ash 1707 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698