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

Side by Side Diff: ash/shelf/shelf_view.cc

Issue 140323010: Ash:Shelf - Cleanup of Alternate Shelf (part 1) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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/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
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
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
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);
724 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); 701 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0);
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);
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 }
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;
(...skipping 28 matching lines...) Expand all
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 338 matching lines...) Expand 10 before | Expand all | Expand 10 after
1300 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); 1219 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
1301 overflow_view->OnShelfAlignmentChanged(); 1220 overflow_view->OnShelfAlignmentChanged();
1302 overflow_view->main_shelf_ = this; 1221 overflow_view->main_shelf_ = this;
1303 UpdateOverflowRange(overflow_view); 1222 UpdateOverflowRange(overflow_view);
1304 1223
1305 overflow_bubble_->Show(overflow_button_, overflow_view); 1224 overflow_bubble_->Show(overflow_button_, overflow_view);
1306 1225
1307 Shell::GetInstance()->UpdateShelfVisibility(); 1226 Shell::GetInstance()->UpdateShelfVisibility();
1308 } 1227 }
1309 1228
1310 void ShelfView::UpdateFirstButtonPadding() {
1311 if (ash::switches::UseAlternateShelfLayout())
1312 return;
1313
1314 // Creates an empty border for first shelf button to make included leading
1315 // inset act as the button's padding. This is only needed on button creation
1316 // and when shelf alignment changes.
1317 if (view_model_->view_size() > 0) {
1318 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder(
1319 layout_manager_->PrimaryAxisValue(0, leading_inset_),
1320 layout_manager_->PrimaryAxisValue(leading_inset_, 0),
1321 0,
1322 0));
1323 }
1324 }
1325
1326 void ShelfView::OnFadeOutAnimationEnded() { 1229 void ShelfView::OnFadeOutAnimationEnded() {
1327 AnimateToIdealBounds(); 1230 AnimateToIdealBounds();
1328 StartFadeInLastVisibleItem(); 1231 StartFadeInLastVisibleItem();
1329 } 1232 }
1330 1233
1331 void ShelfView::StartFadeInLastVisibleItem() { 1234 void ShelfView::StartFadeInLastVisibleItem() {
1332 // If overflow button is visible and there is a valid new last item, fading 1235 // If overflow button is visible and there is a valid new last item, fading
1333 // the new last item in after sliding animation is finished. 1236 // the new last item in after sliding animation is finished.
1334 if (overflow_button_->visible() && last_visible_index_ >= 0) { 1237 if (overflow_button_->visible() && last_visible_index_ >= 0) {
1335 views::View* last_visible_view = view_model_->view_at(last_visible_index_); 1238 views::View* last_visible_view = view_model_->view_at(last_visible_index_);
1336 last_visible_view->layer()->SetOpacity(0); 1239 last_visible_view->layer()->SetOpacity(0);
1337 bounds_animator_->SetAnimationDelegate( 1240 bounds_animator_->SetAnimationDelegate(
1338 last_visible_view, 1241 last_visible_view,
1339 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), 1242 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view),
1340 true); 1243 true);
1341 } 1244 }
1342 } 1245 }
1343 1246
1344 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { 1247 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) {
1345 const int first_overflow_index = last_visible_index_ + 1; 1248 const int first_overflow_index = last_visible_index_ + 1;
1346 const int last_overflow_index = last_hidden_index_; 1249 const int last_overflow_index = last_hidden_index_;
1347 DCHECK_LE(first_overflow_index, last_overflow_index); 1250 DCHECK_LE(first_overflow_index, last_overflow_index);
1348 DCHECK_LT(last_overflow_index, view_model_->view_size()); 1251 DCHECK_LT(last_overflow_index, view_model_->view_size());
1349 1252
1350 overflow_view->first_visible_index_ = first_overflow_index; 1253 overflow_view->first_visible_index_ = first_overflow_index;
1351 overflow_view->last_visible_index_ = last_overflow_index; 1254 overflow_view->last_visible_index_ = last_overflow_index;
1352 } 1255 }
1353 1256
1354 int ShelfView::GetButtonSize() const { 1257 int ShelfView::GetButtonSize() const {
1355 return ash::switches::UseAlternateShelfLayout() ? 1258 return kShelfPreferredSize;
1356 kButtonSize : kShelfPreferredSize;
1357 } 1259 }
1358 1260
1359 int ShelfView::GetButtonSpacing() const { 1261 int ShelfView::GetButtonSpacing() const {
1360 return ash::switches::UseAlternateShelfLayout() ? 1262 return kButtonSpacing;
1361 kAlternateButtonSpacing : kButtonSpacing;
1362 } 1263 }
1363 1264
1364 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { 1265 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) {
1365 gfx::Rect active_bounds; 1266 gfx::Rect active_bounds;
1366 1267
1367 for (int i = 0; i < child_count(); ++i) { 1268 for (int i = 0; i < child_count(); ++i) {
1368 views::View* child = child_at(i); 1269 views::View* child = child_at(i);
1369 if (child == overflow_button_) 1270 if (child == overflow_button_)
1370 continue; 1271 continue;
1371 if (!ShouldShowTooltipForView(child)) 1272 if (!ShouldShowTooltipForView(child))
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
1639 view_model_->Move(start_index, target_index); 1540 view_model_->Move(start_index, target_index);
1640 // When cancelling a drag due to a shelf item being added, the currently 1541 // When cancelling a drag due to a shelf item being added, the currently
1641 // dragged item is moved back to its initial position. AnimateToIdealBounds 1542 // dragged item is moved back to its initial position. AnimateToIdealBounds
1642 // will be called again when the new item is added to the |view_model_| but 1543 // will be called again when the new item is added to the |view_model_| but
1643 // at this time the |view_model_| is inconsistent with the |model_|. 1544 // at this time the |view_model_| is inconsistent with the |model_|.
1644 if (!cancelling_drag_model_changed_) 1545 if (!cancelling_drag_model_changed_)
1645 AnimateToIdealBounds(); 1546 AnimateToIdealBounds();
1646 } 1547 }
1647 1548
1648 void ShelfView::ShelfStatusChanged() { 1549 void ShelfView::ShelfStatusChanged() {
1649 if (ash::switches::UseAlternateShelfLayout())
1650 return;
1651 AppListButton* app_list_button =
1652 static_cast<AppListButton*>(GetAppListButtonView());
1653 if (model_->status() == ShelfModel::STATUS_LOADING)
1654 app_list_button->StartLoadingAnimation();
1655 else
1656 app_list_button->StopLoadingAnimation();
1657 } 1550 }
1658 1551
1659 void ShelfView::PointerPressedOnButton(views::View* view, 1552 void ShelfView::PointerPressedOnButton(views::View* view,
1660 Pointer pointer, 1553 Pointer pointer,
1661 const ui::LocatedEvent& event) { 1554 const ui::LocatedEvent& event) {
1662 if (drag_view_) 1555 if (drag_view_)
1663 return; 1556 return;
1664 1557
1665 int index = view_model_->GetIndexOfView(view); 1558 int index = view_model_->GetIndexOfView(view);
1666 if (index == -1) 1559 if (index == -1)
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2024 break; 1917 break;
2025 case ash::SHELF_ALIGNMENT_TOP: 1918 case ash::SHELF_ALIGNMENT_TOP:
2026 distance = coordinate.y() - bounds.bottom(); 1919 distance = coordinate.y() - bounds.bottom();
2027 break; 1920 break;
2028 } 1921 }
2029 return distance > 0 ? distance : 0; 1922 return distance > 0 ? distance : 0;
2030 } 1923 }
2031 1924
2032 } // namespace internal 1925 } // namespace internal
2033 } // namespace ash 1926 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698