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

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: ButtonSize and ButtonSpacing moved to shelf_constants 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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1; 66 const int SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT = 1;
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.
78 const int kButtonSpacing = 4;
79 const int kAlternateButtonSpacing = 10;
80
81 // Size allocated to for each button.
82 const int kButtonSize = 44;
83
84 // Additional spacing for the left and right side of icons. 76 // Additional spacing for the left and right side of icons.
85 const int kHorizontalIconSpacing = 2; 77 const int kHorizontalIconSpacing = 2;
86 78
87 // Inset for items which do not have an icon. 79 // Inset for items which do not have an icon.
88 const int kHorizontalNoIconInsetSpacing = 80 const int kHorizontalNoIconInsetSpacing =
89 kHorizontalIconSpacing + kDefaultLeadingInset; 81 kHorizontalIconSpacing + kDefaultLeadingInset;
90 82
91 // The proportion of the shelf space reserved for non-panel icons. Panels 83 // The proportion of the shelf space reserved for non-panel icons. Panels
92 // may flow into this space but will be put into the overflow bubble if there 84 // may flow into this space but will be put into the overflow bubble if there
93 // is contention for the space. 85 // is contention for the space.
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 void ShelfView::Init() { 395 void ShelfView::Init() {
404 model_->AddObserver(this); 396 model_->AddObserver(this);
405 397
406 const LauncherItems& items(model_->items()); 398 const LauncherItems& items(model_->items());
407 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) { 399 for (LauncherItems::const_iterator i = items.begin(); i != items.end(); ++i) {
408 views::View* child = CreateViewForItem(*i); 400 views::View* child = CreateViewForItem(*i);
409 child->SetPaintToLayer(true); 401 child->SetPaintToLayer(true);
410 view_model_->Add(child, static_cast<int>(i - items.begin())); 402 view_model_->Add(child, static_cast<int>(i - items.begin()));
411 AddChildView(child); 403 AddChildView(child);
412 } 404 }
413 ShelfStatusChanged();
414 overflow_button_ = new OverflowButton(this); 405 overflow_button_ = new OverflowButton(this);
415 overflow_button_->set_context_menu_controller(this); 406 overflow_button_->set_context_menu_controller(this);
416 ConfigureChildView(overflow_button_); 407 ConfigureChildView(overflow_button_);
417 AddChildView(overflow_button_); 408 AddChildView(overflow_button_);
418 UpdateFirstButtonPadding();
419 409
420 // We'll layout when our bounds change. 410 // We'll layout when our bounds change.
421 } 411 }
422 412
423 void ShelfView::OnShelfAlignmentChanged() { 413 void ShelfView::OnShelfAlignmentChanged() {
424 UpdateFirstButtonPadding();
425 overflow_button_->OnShelfAlignmentChanged(); 414 overflow_button_->OnShelfAlignmentChanged();
426 LayoutToIdealBounds(); 415 LayoutToIdealBounds();
427 for (int i=0; i < view_model_->view_size(); ++i) { 416 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_) 417 if (i >= first_visible_index_ && i <= last_visible_index_)
444 view_model_->view_at(i)->Layout(); 418 view_model_->view_at(i)->Layout();
445 } 419 }
446 tooltip_->Close(); 420 tooltip_->Close();
447 if (overflow_bubble_) 421 if (overflow_bubble_)
448 overflow_bubble_->Hide(); 422 overflow_bubble_->Hide();
449 } 423 }
450 424
451 void ShelfView::SchedulePaintForAllButtons() { 425 void ShelfView::SchedulePaintForAllButtons() {
452 for (int i = 0; i < view_model_->view_size(); ++i) { 426 for (int i = 0; i < view_model_->view_size(); ++i) {
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 656
683 IdealBounds ideal_bounds; 657 IdealBounds ideal_bounds;
684 CalculateIdealBounds(&ideal_bounds); 658 CalculateIdealBounds(&ideal_bounds);
685 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 659 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
686 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 660 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
687 } 661 }
688 662
689 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { 663 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() {
690 // The overflow button is not shown in overflow mode. 664 // The overflow button is not shown in overflow mode.
691 overflow_button_->SetVisible(false); 665 overflow_button_->SetVisible(false);
692 int last_button_index = model_->FirstPanelIndex() - 1;
693 DCHECK_LT(last_visible_index_, view_model_->view_size()); 666 DCHECK_LT(last_visible_index_, view_model_->view_size());
694 for (int i = 0; i < view_model_->view_size(); ++i) { 667 for (int i = 0; i < view_model_->view_size(); ++i) {
695 bool visible = i >= first_visible_index_ && 668 bool visible = i >= first_visible_index_ &&
696 i <= last_visible_index_; 669 i <= last_visible_index_;
697 if (!ash::switches::UseAlternateShelfLayout())
698 visible &= i != last_button_index;
699 670
700 // To track the dragging of |drag_view_| continuously, its visibility 671 // To track the dragging of |drag_view_| continuously, its visibility
701 // should be always true regardless of its position. 672 // should be always true regardless of its position.
702 if (dragged_off_from_overflow_to_shelf_ && 673 if (dragged_off_from_overflow_to_shelf_ &&
703 view_model_->view_at(i) == drag_view_) 674 view_model_->view_at(i) == drag_view_)
704 view_model_->view_at(i)->SetVisible(true); 675 view_model_->view_at(i)->SetVisible(true);
705 else 676 else
706 view_model_->view_at(i)->SetVisible(visible); 677 view_model_->view_at(i)->SetVisible(visible);
707 } 678 }
708 } 679 }
709 680
710 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { 681 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) {
711 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); 682 int available_size = layout_manager_->PrimaryAxisValue(width(), height());
712 DCHECK(model_->item_count() == view_model_->view_size()); 683 DCHECK(model_->item_count() == view_model_->view_size());
713 if (!available_size) 684 if (!available_size)
714 return; 685 return;
715 686
716 int first_panel_index = model_->FirstPanelIndex(); 687 int first_panel_index = model_->FirstPanelIndex();
717 int last_button_index = first_panel_index - 1; 688 int last_button_index = first_panel_index - 1;
718 689
719 // Initial x,y values account both leading_inset in primary 690 int x = 0;
720 // coordinate and secondary coordinate based on the dynamic edge of the 691 int y = 0;
721 // shelf (eg top edge on bottom-aligned shelf).
722 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset_;
723 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset);
724 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0);
725 692
726 int button_size = GetButtonSize(); 693 int button_size = kShelfButtonSize;
727 int button_spacing = GetButtonSpacing(); 694 int button_spacing = kShelfButtonSpacing;
728 695
729 int w = layout_manager_->PrimaryAxisValue(button_size, width()); 696 int w = layout_manager_->PrimaryAxisValue(button_size, width());
730 int h = layout_manager_->PrimaryAxisValue(height(), button_size); 697 int h = layout_manager_->PrimaryAxisValue(height(), button_size);
731 for (int i = 0; i < view_model_->view_size(); ++i) { 698 for (int i = 0; i < view_model_->view_size(); ++i) {
732 if (i < first_visible_index_) { 699 if (i < first_visible_index_) {
733 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 700 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
734 continue; 701 continue;
735 } 702 }
736 703
737 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 704 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
738 if (i != last_button_index) { 705 if (i != last_button_index) {
739 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); 706 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x);
740 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); 707 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing);
741 } 708 }
742 } 709 }
743 710
744 if (is_overflow_mode()) { 711 if (is_overflow_mode()) {
745 UpdateAllButtonsVisibilityInOverflowMode(); 712 UpdateAllButtonsVisibilityInOverflowMode();
746 return; 713 return;
747 } 714 }
748 715
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. 716 // Right aligned icons.
760 int end_position = available_size - button_spacing; 717 int end_position = available_size - button_spacing;
761 x = layout_manager_->PrimaryAxisValue(end_position, 0); 718 x = layout_manager_->PrimaryAxisValue(end_position, 0);
762 y = layout_manager_->PrimaryAxisValue(0, end_position); 719 y = layout_manager_->PrimaryAxisValue(0, end_position);
763 for (int i = view_model_->view_size() - 1; 720 for (int i = view_model_->view_size() - 1;
764 i >= first_panel_index; --i) { 721 i >= first_panel_index; --i) {
765 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); 722 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x);
766 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing); 723 y = layout_manager_->PrimaryAxisValue(y, y - h - button_spacing);
767 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 724 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
768 end_position = layout_manager_->PrimaryAxisValue(x, y); 725 end_position = layout_manager_->PrimaryAxisValue(x, y);
769 } 726 }
770 727
771 // Icons on the left / top are guaranteed up to kLeftIconProportion of 728 // Icons on the left / top are guaranteed up to kLeftIconProportion of
772 // the available space. 729 // the available space.
773 int last_icon_position = layout_manager_->PrimaryAxisValue( 730 int last_icon_position = layout_manager_->PrimaryAxisValue(
774 view_model_->ideal_bounds(last_button_index).right(), 731 view_model_->ideal_bounds(last_button_index).right(),
775 view_model_->ideal_bounds(last_button_index).bottom()) 732 view_model_->ideal_bounds(last_button_index).bottom())
776 + button_size + inset; 733 + button_size;
777 if (!ash::switches::UseAlternateShelfLayout())
778 last_icon_position += button_size;
779 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; 734 int reserved_icon_space = available_size * kReservedNonPanelIconProportion;
780 if (last_icon_position < reserved_icon_space) 735 if (last_icon_position < reserved_icon_space)
781 end_position = last_icon_position; 736 end_position = last_icon_position;
782 else 737 else
783 end_position = std::max(end_position, reserved_icon_space); 738 end_position = std::max(end_position, reserved_icon_space);
784 739
785 bounds->overflow_bounds.set_size( 740 bounds->overflow_bounds.set_size(
786 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()), 741 gfx::Size(layout_manager_->PrimaryAxisValue(w, width()),
787 layout_manager_->PrimaryAxisValue(height(), h))); 742 layout_manager_->PrimaryAxisValue(height(), h)));
788 743
789 if (ash::switches::UseAlternateShelfLayout()) { 744 last_visible_index_ = DetermineLastVisibleIndex(
790 last_visible_index_ = DetermineLastVisibleIndex( 745 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; 746 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1;
797 bool show_overflow = 747 bool show_overflow = (last_visible_index_ < last_button_index ||
798 ((ash::switches::UseAlternateShelfLayout() ? 0 : 1) + 748 last_hidden_index_ >= first_panel_index);
Mr4D (OOO till 08-26) 2014/01/25 01:37:39 isn't here a space missing?
799 last_visible_index_ < last_button_index ||
800 last_hidden_index_ >= first_panel_index);
801 749
802 // Create Space for the overflow button 750 // Create Space for the overflow button
803 if (show_overflow && ash::switches::UseAlternateShelfLayout() && 751 if (show_overflow && last_visible_index_ > 0 &&
804 last_visible_index_ > 0 && last_visible_index_ < last_button_index) 752 last_visible_index_ < last_button_index)
805 --last_visible_index_; 753 --last_visible_index_;
806 for (int i = 0; i < view_model_->view_size(); ++i) { 754 for (int i = 0; i < view_model_->view_size(); ++i) {
807 bool visible = i <= last_visible_index_ || i > last_hidden_index_; 755 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 756 // 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 757 // off from the shelf, don't make |drag_view_| invisible. It will be
813 // eventually invisible and removed from the |view_model_| by 758 // eventually invisible and removed from the |view_model_| by
814 // FinalizeRipOffDrag(). 759 // FinalizeRipOffDrag().
815 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_) 760 if (dragged_off_shelf_ && view_model_->view_at(i) == drag_view_)
816 continue; 761 continue;
817 view_model_->view_at(i)->SetVisible(visible); 762 view_model_->view_at(i)->SetVisible(visible);
818 } 763 }
819 764
820 overflow_button_->SetVisible(show_overflow); 765 overflow_button_->SetVisible(show_overflow);
821 if (show_overflow) { 766 if (show_overflow) {
822 DCHECK_NE(0, view_model_->view_size()); 767 DCHECK_NE(0, view_model_->view_size());
823 if (last_visible_index_ == -1) { 768 if (last_visible_index_ == -1) {
824 x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); 769 x = 0;
825 y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); 770 y = 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 { 771 } else {
831 x = layout_manager_->PrimaryAxisValue( 772 x = layout_manager_->PrimaryAxisValue(
832 view_model_->ideal_bounds(last_visible_index_).right(), 773 view_model_->ideal_bounds(last_visible_index_).right(),
833 view_model_->ideal_bounds(last_visible_index_).x()); 774 view_model_->ideal_bounds(last_visible_index_).x());
834 y = layout_manager_->PrimaryAxisValue( 775 y = layout_manager_->PrimaryAxisValue(
835 view_model_->ideal_bounds(last_visible_index_).y(), 776 view_model_->ideal_bounds(last_visible_index_).y(),
836 view_model_->ideal_bounds(last_visible_index_).bottom()); 777 view_model_->ideal_bounds(last_visible_index_).bottom());
837 } 778 }
838 // Set all hidden panel icon positions to be on the overflow button. 779 // Set all hidden panel icon positions to be on the overflow button.
839 for (int i = first_panel_index; i <= last_hidden_index_; ++i) 780 for (int i = first_panel_index; i <= last_hidden_index_; ++i)
840 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 781 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
841 782
842 // Add more space between last visible item and overflow button. 783 // Add more space between last visible item and overflow button.
843 // Without this, two buttons look too close compared with other items. 784 // Without this, two buttons look too close compared with other items.
844 if (ash::switches::UseAlternateShelfLayout()) { 785 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x);
845 x = layout_manager_->PrimaryAxisValue(x + button_spacing, x); 786 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing);
846 y = layout_manager_->PrimaryAxisValue(y, y + button_spacing);
847 }
848 787
849 bounds->overflow_bounds.set_x(x); 788 bounds->overflow_bounds.set_x(x);
850 bounds->overflow_bounds.set_y(y); 789 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()) 790 if (overflow_bubble_.get() && overflow_bubble_->IsShowing())
862 UpdateOverflowRange(overflow_bubble_->shelf_view()); 791 UpdateOverflowRange(overflow_bubble_->shelf_view());
863 } else { 792 } else {
864 if (overflow_bubble_) 793 if (overflow_bubble_)
865 overflow_bubble_->Hide(); 794 overflow_bubble_->Hide();
866 } 795 }
867 } 796 }
868 797
869 int ShelfView::DetermineLastVisibleIndex(int max_value) const { 798 int ShelfView::DetermineLastVisibleIndex(int max_value) const {
870 int index = model_->FirstPanelIndex() - 1; 799 int index = model_->FirstPanelIndex() - 1;
(...skipping 28 matching lines...) Expand all
899 void ShelfView::AnimateToIdealBounds() { 828 void ShelfView::AnimateToIdealBounds() {
900 IdealBounds ideal_bounds; 829 IdealBounds ideal_bounds;
901 CalculateIdealBounds(&ideal_bounds); 830 CalculateIdealBounds(&ideal_bounds);
902 for (int i = 0; i < view_model_->view_size(); ++i) { 831 for (int i = 0; i < view_model_->view_size(); ++i) {
903 View* view = view_model_->view_at(i); 832 View* view = view_model_->view_at(i);
904 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i)); 833 bounds_animator_->AnimateViewTo(view, view_model_->ideal_bounds(i));
905 // Now that the item animation starts, we have to make sure that the 834 // 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. 835 // padding of the first gets properly transferred to the new first item.
907 if (i && view->border()) 836 if (i && view->border())
908 view->set_border(NULL); 837 view->set_border(NULL);
909 else if (!i && !view->border())
910 UpdateFirstButtonPadding();
911 } 838 }
912 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 839 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
913 } 840 }
914 841
915 views::View* ShelfView::CreateViewForItem(const LauncherItem& item) { 842 views::View* ShelfView::CreateViewForItem(const LauncherItem& item) {
916 views::View* view = NULL; 843 views::View* view = NULL;
917 switch (item.type) { 844 switch (item.type) {
918 case TYPE_BROWSER_SHORTCUT: 845 case TYPE_BROWSER_SHORTCUT:
919 case TYPE_APP_SHORTCUT: 846 case TYPE_APP_SHORTCUT:
920 case TYPE_WINDOWED_APP: 847 case TYPE_WINDOWED_APP:
921 case TYPE_PLATFORM_APP: 848 case TYPE_PLATFORM_APP:
922 case TYPE_DIALOG: 849 case TYPE_DIALOG:
923 case TYPE_APP_PANEL: { 850 case TYPE_APP_PANEL: {
924 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_); 851 ShelfButton* button = ShelfButton::Create(this, this, layout_manager_);
925 button->SetImage(item.image); 852 button->SetImage(item.image);
926 ReflectItemStatus(item, button); 853 ReflectItemStatus(item, button);
927 view = button; 854 view = button;
928 break; 855 break;
929 } 856 }
930 857
931 case TYPE_APP_LIST: { 858 case TYPE_APP_LIST: {
932 if (ash::switches::UseAlternateShelfLayout()) { 859 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; 860 break;
953 } 861 }
954 862
955 default: 863 default:
956 break; 864 break;
957 } 865 }
958 view->set_context_menu_controller(this); 866 view->set_context_menu_controller(this);
959 867
960 DCHECK(view); 868 DCHECK(view);
961 ConfigureChildView(view); 869 ConfigureChildView(view);
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1299 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); 1207 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
1300 overflow_view->OnShelfAlignmentChanged(); 1208 overflow_view->OnShelfAlignmentChanged();
1301 overflow_view->main_shelf_ = this; 1209 overflow_view->main_shelf_ = this;
1302 UpdateOverflowRange(overflow_view); 1210 UpdateOverflowRange(overflow_view);
1303 1211
1304 overflow_bubble_->Show(overflow_button_, overflow_view); 1212 overflow_bubble_->Show(overflow_button_, overflow_view);
1305 1213
1306 Shell::GetInstance()->UpdateShelfVisibility(); 1214 Shell::GetInstance()->UpdateShelfVisibility();
1307 } 1215 }
1308 1216
1309 void ShelfView::UpdateFirstButtonPadding() {
1310 if (ash::switches::UseAlternateShelfLayout())
1311 return;
1312
1313 // Creates an empty border for first shelf button to make included leading
1314 // inset act as the button's padding. This is only needed on button creation
1315 // and when shelf alignment changes.
1316 if (view_model_->view_size() > 0) {
1317 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder(
1318 layout_manager_->PrimaryAxisValue(0, leading_inset_),
1319 layout_manager_->PrimaryAxisValue(leading_inset_, 0),
1320 0,
1321 0));
1322 }
1323 }
1324
1325 void ShelfView::OnFadeOutAnimationEnded() { 1217 void ShelfView::OnFadeOutAnimationEnded() {
1326 AnimateToIdealBounds(); 1218 AnimateToIdealBounds();
1327 StartFadeInLastVisibleItem(); 1219 StartFadeInLastVisibleItem();
1328 } 1220 }
1329 1221
1330 void ShelfView::StartFadeInLastVisibleItem() { 1222 void ShelfView::StartFadeInLastVisibleItem() {
1331 // If overflow button is visible and there is a valid new last item, fading 1223 // If overflow button is visible and there is a valid new last item, fading
1332 // the new last item in after sliding animation is finished. 1224 // the new last item in after sliding animation is finished.
1333 if (overflow_button_->visible() && last_visible_index_ >= 0) { 1225 if (overflow_button_->visible() && last_visible_index_ >= 0) {
1334 views::View* last_visible_view = view_model_->view_at(last_visible_index_); 1226 views::View* last_visible_view = view_model_->view_at(last_visible_index_);
1335 last_visible_view->layer()->SetOpacity(0); 1227 last_visible_view->layer()->SetOpacity(0);
1336 bounds_animator_->SetAnimationDelegate( 1228 bounds_animator_->SetAnimationDelegate(
1337 last_visible_view, 1229 last_visible_view,
1338 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), 1230 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view),
1339 true); 1231 true);
1340 } 1232 }
1341 } 1233 }
1342 1234
1343 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { 1235 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) {
1344 const int first_overflow_index = last_visible_index_ + 1; 1236 const int first_overflow_index = last_visible_index_ + 1;
1345 const int last_overflow_index = last_hidden_index_; 1237 const int last_overflow_index = last_hidden_index_;
1346 DCHECK_LE(first_overflow_index, last_overflow_index); 1238 DCHECK_LE(first_overflow_index, last_overflow_index);
1347 DCHECK_LT(last_overflow_index, view_model_->view_size()); 1239 DCHECK_LT(last_overflow_index, view_model_->view_size());
1348 1240
1349 overflow_view->first_visible_index_ = first_overflow_index; 1241 overflow_view->first_visible_index_ = first_overflow_index;
1350 overflow_view->last_visible_index_ = last_overflow_index; 1242 overflow_view->last_visible_index_ = last_overflow_index;
1351 } 1243 }
1352 1244
1353 int ShelfView::GetButtonSize() const {
1354 return ash::switches::UseAlternateShelfLayout() ?
1355 kButtonSize : kShelfPreferredSize;
1356 }
1357
1358 int ShelfView::GetButtonSpacing() const {
1359 return ash::switches::UseAlternateShelfLayout() ?
1360 kAlternateButtonSpacing : kButtonSpacing;
1361 }
1362
1363 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { 1245 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) {
1364 gfx::Rect active_bounds; 1246 gfx::Rect active_bounds;
1365 1247
1366 for (int i = 0; i < child_count(); ++i) { 1248 for (int i = 0; i < child_count(); ++i) {
1367 views::View* child = child_at(i); 1249 views::View* child = child_at(i);
1368 if (child == overflow_button_) 1250 if (child == overflow_button_)
1369 continue; 1251 continue;
1370 if (!ShouldShowTooltipForView(child)) 1252 if (!ShouldShowTooltipForView(child))
1371 continue; 1253 continue;
1372 1254
(...skipping 12 matching lines...) Expand all
1385 } 1267 }
1386 1268
1387 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() { 1269 gfx::Rect ShelfView::GetBoundsForDragInsertInScreen() {
1388 gfx::Size preferred_size; 1270 gfx::Size preferred_size;
1389 if (is_overflow_mode()) { 1271 if (is_overflow_mode()) {
1390 DCHECK(owner_overflow_bubble_); 1272 DCHECK(owner_overflow_bubble_);
1391 gfx::Rect bubble_bounds = 1273 gfx::Rect bubble_bounds =
1392 owner_overflow_bubble_->bubble_view()->GetBubbleBounds(); 1274 owner_overflow_bubble_->bubble_view()->GetBubbleBounds();
1393 preferred_size = bubble_bounds.size(); 1275 preferred_size = bubble_bounds.size();
1394 } else { 1276 } else {
1395 const int preferred_shelf_size = layout_manager_->GetPreferredShelfSize();
1396
1397 const int last_button_index = view_model_->view_size() - 1; 1277 const int last_button_index = view_model_->view_size() - 1;
1398 gfx::Rect last_button_bounds = 1278 gfx::Rect last_button_bounds =
1399 view_model_->view_at(last_button_index)->bounds(); 1279 view_model_->view_at(last_button_index)->bounds();
1400 if (overflow_button_->visible() && 1280 if (overflow_button_->visible() &&
1401 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { 1281 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) {
1402 // When overflow button is visible and shelf has no panel items, 1282 // When overflow button is visible and shelf has no panel items,
1403 // last_button_bounds should be overflow button's bounds. 1283 // last_button_bounds should be overflow button's bounds.
1404 last_button_bounds = overflow_button_->bounds(); 1284 last_button_bounds = overflow_button_->bounds();
1405 } 1285 }
1406 1286
1407 if (layout_manager_->IsHorizontalAlignment()) { 1287 if (layout_manager_->IsHorizontalAlignment()) {
1408 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_, 1288 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_,
1409 preferred_shelf_size); 1289 kShelfSize);
1410 } else { 1290 } else {
1411 preferred_size = gfx::Size(preferred_shelf_size, 1291 preferred_size = gfx::Size(kShelfSize,
1412 last_button_bounds.bottom() + leading_inset_); 1292 last_button_bounds.bottom() + leading_inset_);
1413 } 1293 }
1414 } 1294 }
1415 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); 1295 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0);
1416 1296
1417 // In overflow mode, we should use OverflowBubbleView as a source for 1297 // In overflow mode, we should use OverflowBubbleView as a source for
1418 // converting |origin| to screen coordinates. When a scroll operation is 1298 // converting |origin| to screen coordinates. When a scroll operation is
1419 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can 1299 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can
1420 // be changed. 1300 // be changed.
1421 if (is_overflow_mode()) 1301 if (is_overflow_mode())
(...skipping 30 matching lines...) Expand all
1452 // the list. 1332 // the list.
1453 if (at_end) 1333 if (at_end)
1454 return view_model_->view_size(); 1334 return view_model_->view_size();
1455 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; 1335 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1;
1456 } 1336 }
1457 1337
1458 gfx::Size ShelfView::GetPreferredSize() { 1338 gfx::Size ShelfView::GetPreferredSize() {
1459 IdealBounds ideal_bounds; 1339 IdealBounds ideal_bounds;
1460 CalculateIdealBounds(&ideal_bounds); 1340 CalculateIdealBounds(&ideal_bounds);
1461 1341
1462 const int preferred_size = layout_manager_->GetPreferredShelfSize();
1463
1464 int last_button_index = is_overflow_mode() ? 1342 int last_button_index = is_overflow_mode() ?
1465 last_visible_index_ : view_model_->view_size() - 1; 1343 last_visible_index_ : view_model_->view_size() - 1;
1466 1344
1467 // When an item is dragged off from the overflow bubble, it is moved to last 1345 // When an item is dragged off from the overflow bubble, it is moved to last
1468 // position and and changed to invisible. Overflow bubble size should be 1346 // position and and changed to invisible. Overflow bubble size should be
1469 // shrunk to fit only for visible items. 1347 // shrunk to fit only for visible items.
1470 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible 1348 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible
1471 // items in the shelf. 1349 // items in the shelf.
1472 if (is_overflow_mode() && 1350 if (is_overflow_mode() &&
1473 dragged_off_shelf_ && 1351 dragged_off_shelf_ &&
1474 !dragged_off_from_overflow_to_shelf_ && 1352 !dragged_off_from_overflow_to_shelf_ &&
1475 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) 1353 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
1476 last_button_index--; 1354 last_button_index--;
1477 1355
1478 const gfx::Rect last_button_bounds = 1356 const gfx::Rect last_button_bounds =
1479 last_button_index >= first_visible_index_ ? 1357 last_button_index >= first_visible_index_ ?
1480 view_model_->ideal_bounds(last_button_index) : 1358 view_model_->ideal_bounds(last_button_index) :
1481 gfx::Rect(gfx::Size(preferred_size, preferred_size)); 1359 gfx::Rect(gfx::Size(kShelfSize, kShelfSize));
1482 1360
1483 if (layout_manager_->IsHorizontalAlignment()) { 1361 if (layout_manager_->IsHorizontalAlignment()) {
1484 return gfx::Size(last_button_bounds.right() + leading_inset_, 1362 return gfx::Size(last_button_bounds.right() + leading_inset_, kShelfSize);
1485 preferred_size);
1486 } 1363 }
1487 1364
1488 return gfx::Size(preferred_size, 1365 return gfx::Size(kShelfSize,
Mr4D (OOO till 08-26) 2014/01/25 01:37:39 This might fit into one line.
1489 last_button_bounds.bottom() + leading_inset_); 1366 last_button_bounds.bottom() + leading_inset_);
1490 } 1367 }
1491 1368
1492 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 1369 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
1493 LayoutToIdealBounds(); 1370 LayoutToIdealBounds();
1494 FOR_EACH_OBSERVER(ShelfIconObserver, observers_, 1371 FOR_EACH_OBSERVER(ShelfIconObserver, observers_,
1495 OnShelfIconPositionsChanged()); 1372 OnShelfIconPositionsChanged());
1496 1373
1497 if (IsShowingOverflowBubble()) 1374 if (IsShowingOverflowBubble())
1498 overflow_bubble_->Hide(); 1375 overflow_bubble_->Hide();
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 view_model_->Move(start_index, target_index); 1515 view_model_->Move(start_index, target_index);
1639 // When cancelling a drag due to a shelf item being added, the currently 1516 // When cancelling a drag due to a shelf item being added, the currently
1640 // dragged item is moved back to its initial position. AnimateToIdealBounds 1517 // dragged item is moved back to its initial position. AnimateToIdealBounds
1641 // will be called again when the new item is added to the |view_model_| but 1518 // will be called again when the new item is added to the |view_model_| but
1642 // at this time the |view_model_| is inconsistent with the |model_|. 1519 // at this time the |view_model_| is inconsistent with the |model_|.
1643 if (!cancelling_drag_model_changed_) 1520 if (!cancelling_drag_model_changed_)
1644 AnimateToIdealBounds(); 1521 AnimateToIdealBounds();
1645 } 1522 }
1646 1523
1647 void ShelfView::ShelfStatusChanged() { 1524 void ShelfView::ShelfStatusChanged() {
1648 if (ash::switches::UseAlternateShelfLayout()) 1525 // Nothing to do here.
1649 return;
1650 AppListButton* app_list_button =
1651 static_cast<AppListButton*>(GetAppListButtonView());
1652 if (model_->status() == ShelfModel::STATUS_LOADING)
1653 app_list_button->StartLoadingAnimation();
1654 else
1655 app_list_button->StopLoadingAnimation();
1656 } 1526 }
1657 1527
1658 void ShelfView::PointerPressedOnButton(views::View* view, 1528 void ShelfView::PointerPressedOnButton(views::View* view,
1659 Pointer pointer, 1529 Pointer pointer,
1660 const ui::LocatedEvent& event) { 1530 const ui::LocatedEvent& event) {
1661 if (drag_view_) 1531 if (drag_view_)
1662 return; 1532 return;
1663 1533
1664 int index = view_model_->GetIndexOfView(view); 1534 int index = view_model_->GetIndexOfView(view);
1665 if (index == -1) 1535 if (index == -1)
(...skipping 357 matching lines...) Expand 10 before | Expand all | Expand 10 after
2023 break; 1893 break;
2024 case SHELF_ALIGNMENT_TOP: 1894 case SHELF_ALIGNMENT_TOP:
2025 distance = coordinate.y() - bounds.bottom(); 1895 distance = coordinate.y() - bounds.bottom();
2026 break; 1896 break;
2027 } 1897 }
2028 return distance > 0 ? distance : 0; 1898 return distance > 0 ? distance : 0;
2029 } 1899 }
2030 1900
2031 } // namespace internal 1901 } // namespace internal
2032 } // namespace ash 1902 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698