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

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

Issue 2899253002: chromeos: Rename ash::WmShelf to Shelf (Closed)
Patch Set: cleanup Created 3 years, 7 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
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 #include <memory> 8 #include <memory>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
11 #include "ash/drag_drop/drag_image_view.h" 11 #include "ash/drag_drop/drag_image_view.h"
12 #include "ash/public/cpp/shelf_item_delegate.h" 12 #include "ash/public/cpp/shelf_item_delegate.h"
13 #include "ash/scoped_root_window_for_new_windows.h" 13 #include "ash/scoped_root_window_for_new_windows.h"
14 #include "ash/screen_util.h" 14 #include "ash/screen_util.h"
15 #include "ash/shelf/app_list_button.h" 15 #include "ash/shelf/app_list_button.h"
16 #include "ash/shelf/overflow_bubble.h" 16 #include "ash/shelf/overflow_bubble.h"
17 #include "ash/shelf/overflow_bubble_view.h" 17 #include "ash/shelf/overflow_bubble_view.h"
18 #include "ash/shelf/overflow_button.h" 18 #include "ash/shelf/overflow_button.h"
19 #include "ash/shelf/shelf.h"
19 #include "ash/shelf/shelf_application_menu_model.h" 20 #include "ash/shelf/shelf_application_menu_model.h"
20 #include "ash/shelf/shelf_button.h" 21 #include "ash/shelf/shelf_button.h"
21 #include "ash/shelf/shelf_constants.h" 22 #include "ash/shelf/shelf_constants.h"
22 #include "ash/shelf/shelf_model.h" 23 #include "ash/shelf/shelf_model.h"
23 #include "ash/shelf/shelf_widget.h" 24 #include "ash/shelf/shelf_widget.h"
24 #include "ash/shelf/wm_shelf.h"
25 #include "ash/shell.h" 25 #include "ash/shell.h"
26 #include "ash/shell_delegate.h" 26 #include "ash/shell_delegate.h"
27 #include "ash/shell_port.h" 27 #include "ash/shell_port.h"
28 #include "ash/strings/grit/ash_strings.h" 28 #include "ash/strings/grit/ash_strings.h"
29 #include "ash/wm/root_window_finder.h" 29 #include "ash/wm/root_window_finder.h"
30 #include "ash/wm_window.h" 30 #include "ash/wm_window.h"
31 #include "base/auto_reset.h" 31 #include "base/auto_reset.h"
32 #include "base/memory/ptr_util.h" 32 #include "base/memory/ptr_util.h"
33 #include "base/metrics/histogram_macros.h" 33 #include "base/metrics/histogram_macros.h"
34 #include "ui/accessibility/ax_node_data.h" 34 #include "ui/accessibility/ax_node_data.h"
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
234 private: 234 private:
235 ShelfView* shelf_view_; 235 ShelfView* shelf_view_;
236 views::View* view_; 236 views::View* view_;
237 237
238 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate); 238 DISALLOW_COPY_AND_ASSIGN(StartFadeAnimationDelegate);
239 }; 239 };
240 240
241 // static 241 // static
242 const int ShelfView::kMinimumDragDistance = 8; 242 const int ShelfView::kMinimumDragDistance = 8;
243 243
244 ShelfView::ShelfView(ShelfModel* model, 244 ShelfView::ShelfView(ShelfModel* model, Shelf* shelf, ShelfWidget* shelf_widget)
245 WmShelf* wm_shelf,
246 ShelfWidget* shelf_widget)
247 : model_(model), 245 : model_(model),
248 wm_shelf_(wm_shelf), 246 shelf_(shelf),
249 shelf_widget_(shelf_widget), 247 shelf_widget_(shelf_widget),
250 view_model_(new views::ViewModel), 248 view_model_(new views::ViewModel),
251 tooltip_(this), 249 tooltip_(this),
252 weak_factory_(this) { 250 weak_factory_(this) {
253 DCHECK(model_); 251 DCHECK(model_);
254 DCHECK(wm_shelf_); 252 DCHECK(shelf_);
255 DCHECK(shelf_widget_); 253 DCHECK(shelf_widget_);
256 bounds_animator_.reset(new views::BoundsAnimator(this)); 254 bounds_animator_.reset(new views::BoundsAnimator(this));
257 bounds_animator_->AddObserver(this); 255 bounds_animator_->AddObserver(this);
258 set_context_menu_controller(this); 256 set_context_menu_controller(this);
259 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); 257 focus_search_.reset(new ShelfFocusSearch(view_model_.get()));
260 } 258 }
261 259
262 ShelfView::~ShelfView() { 260 ShelfView::~ShelfView() {
263 bounds_animator_->RemoveObserver(this); 261 bounds_animator_->RemoveObserver(this);
264 model_->RemoveObserver(this); 262 model_->RemoveObserver(this);
265 } 263 }
266 264
267 void ShelfView::Init() { 265 void ShelfView::Init() {
268 model_->AddObserver(this); 266 model_->AddObserver(this);
269 267
270 const ShelfItems& items(model_->items()); 268 const ShelfItems& items(model_->items());
271 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) { 269 for (ShelfItems::const_iterator i = items.begin(); i != items.end(); ++i) {
272 views::View* child = CreateViewForItem(*i); 270 views::View* child = CreateViewForItem(*i);
273 child->SetPaintToLayer(); 271 child->SetPaintToLayer();
274 view_model_->Add(child, static_cast<int>(i - items.begin())); 272 view_model_->Add(child, static_cast<int>(i - items.begin()));
275 AddChildView(child); 273 AddChildView(child);
276 } 274 }
277 overflow_button_ = new OverflowButton(this, wm_shelf_); 275 overflow_button_ = new OverflowButton(this, shelf_);
278 overflow_button_->set_context_menu_controller(this); 276 overflow_button_->set_context_menu_controller(this);
279 ConfigureChildView(overflow_button_); 277 ConfigureChildView(overflow_button_);
280 AddChildView(overflow_button_); 278 AddChildView(overflow_button_);
281 279
282 // We'll layout when our bounds change. 280 // We'll layout when our bounds change.
283 } 281 }
284 282
285 void ShelfView::OnShelfAlignmentChanged() { 283 void ShelfView::OnShelfAlignmentChanged() {
286 overflow_button_->OnShelfAlignmentChanged(); 284 overflow_button_->OnShelfAlignmentChanged();
287 LayoutToIdealBounds(); 285 LayoutToIdealBounds();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 322
325 void ShelfView::UpdatePanelIconPosition(const ShelfID& id, 323 void ShelfView::UpdatePanelIconPosition(const ShelfID& id,
326 const gfx::Point& midpoint) { 324 const gfx::Point& midpoint) {
327 int current_index = model_->ItemIndexByID(id); 325 int current_index = model_->ItemIndexByID(id);
328 int first_panel_index = model_->FirstPanelIndex(); 326 int first_panel_index = model_->FirstPanelIndex();
329 if (current_index < first_panel_index) 327 if (current_index < first_panel_index)
330 return; 328 return;
331 329
332 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), midpoint.y()); 330 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), midpoint.y());
333 int target_index = current_index; 331 int target_index = current_index;
334 while ( 332 while (target_index > first_panel_index &&
335 target_index > first_panel_index && 333 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(),
336 wm_shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(),
337 view_model_->ideal_bounds(target_index).y()) > 334 view_model_->ideal_bounds(target_index).y()) >
338 wm_shelf_->PrimaryAxisValue(midpoint_in_view.x(), 335 shelf_->PrimaryAxisValue(midpoint_in_view.x(),
339 midpoint_in_view.y())) { 336 midpoint_in_view.y())) {
340 --target_index; 337 --target_index;
341 } 338 }
342 while (target_index < view_model_->view_size() - 1 && 339 while (target_index < view_model_->view_size() - 1 &&
343 wm_shelf_->PrimaryAxisValue( 340 shelf_->PrimaryAxisValue(
344 view_model_->ideal_bounds(target_index).right(), 341 view_model_->ideal_bounds(target_index).right(),
345 view_model_->ideal_bounds(target_index).bottom()) < 342 view_model_->ideal_bounds(target_index).bottom()) <
346 wm_shelf_->PrimaryAxisValue(midpoint_in_view.x(), 343 shelf_->PrimaryAxisValue(midpoint_in_view.x(),
347 midpoint_in_view.y())) { 344 midpoint_in_view.y())) {
348 ++target_index; 345 ++target_index;
349 } 346 }
350 if (current_index != target_index) 347 if (current_index != target_index)
351 model_->Move(current_index, target_index); 348 model_->Move(current_index, target_index);
352 } 349 }
353 350
354 bool ShelfView::IsShowingMenu() const { 351 bool ShelfView::IsShowingMenu() const {
355 return launcher_menu_runner_.get() && launcher_menu_runner_->IsRunning(); 352 return launcher_menu_runner_.get() && launcher_menu_runner_->IsRunning();
356 } 353 }
357 354
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 is_repost_event_on_same_item_ = 655 is_repost_event_on_same_item_ =
659 IsRepostEvent(event) && (last_pressed_index_ == index); 656 IsRepostEvent(event) && (last_pressed_index_ == index);
660 657
661 if (pointer == TOUCH) 658 if (pointer == TOUCH)
662 touch_press_time_ = base::TimeTicks::Now(); 659 touch_press_time_ = base::TimeTicks::Now();
663 660
664 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 661 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
665 drag_view_ = static_cast<ShelfButton*>(view); 662 drag_view_ = static_cast<ShelfButton*>(view);
666 drag_origin_ = gfx::Point(event.x(), event.y()); 663 drag_origin_ = gfx::Point(event.x(), event.y());
667 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", 664 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage",
668 wm_shelf_->SelectValueForShelfAlignment( 665 shelf_->SelectValueForShelfAlignment(
669 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, 666 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM,
670 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, 667 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT,
671 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT), 668 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT),
672 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); 669 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT);
673 } 670 }
674 671
675 void ShelfView::PointerDraggedOnButton(views::View* view, 672 void ShelfView::PointerDraggedOnButton(views::View* view,
676 Pointer pointer, 673 Pointer pointer,
677 const ui::LocatedEvent& event) { 674 const ui::LocatedEvent& event) {
678 if (CanPrepareForDrag(pointer, event)) 675 if (CanPrepareForDrag(pointer, event))
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
728 if (dragged_to_another_shelf_ && view_model_->view_at(i) == drag_view_) 725 if (dragged_to_another_shelf_ && view_model_->view_at(i) == drag_view_)
729 view_model_->view_at(i)->SetVisible(true); 726 view_model_->view_at(i)->SetVisible(true);
730 else 727 else
731 view_model_->view_at(i)->SetVisible(visible); 728 view_model_->view_at(i)->SetVisible(visible);
732 } 729 }
733 } 730 }
734 731
735 void ShelfView::CalculateIdealBounds(gfx::Rect* overflow_bounds) const { 732 void ShelfView::CalculateIdealBounds(gfx::Rect* overflow_bounds) const {
736 DCHECK(model_->item_count() == view_model_->view_size()); 733 DCHECK(model_->item_count() == view_model_->view_size());
737 734
738 int available_size = wm_shelf_->PrimaryAxisValue(width(), height()); 735 int available_size = shelf_->PrimaryAxisValue(width(), height());
739 int first_panel_index = model_->FirstPanelIndex(); 736 int first_panel_index = model_->FirstPanelIndex();
740 int last_button_index = first_panel_index - 1; 737 int last_button_index = first_panel_index - 1;
741 738
742 int x = 0; 739 int x = 0;
743 int y = 0; 740 int y = 0;
744 741
745 int w = wm_shelf_->PrimaryAxisValue(kShelfButtonSize, width()); 742 int w = shelf_->PrimaryAxisValue(kShelfButtonSize, width());
746 int h = wm_shelf_->PrimaryAxisValue(height(), kShelfButtonSize); 743 int h = shelf_->PrimaryAxisValue(height(), kShelfButtonSize);
747 for (int i = 0; i < view_model_->view_size(); ++i) { 744 for (int i = 0; i < view_model_->view_size(); ++i) {
748 if (i < first_visible_index_) { 745 if (i < first_visible_index_) {
749 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 746 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
750 continue; 747 continue;
751 } 748 }
752 749
753 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 750 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
754 x = wm_shelf_->PrimaryAxisValue(x + w + kShelfButtonSpacing, x); 751 x = shelf_->PrimaryAxisValue(x + w + kShelfButtonSpacing, x);
755 y = wm_shelf_->PrimaryAxisValue(y, y + h + kShelfButtonSpacing); 752 y = shelf_->PrimaryAxisValue(y, y + h + kShelfButtonSpacing);
756 } 753 }
757 754
758 if (is_overflow_mode()) { 755 if (is_overflow_mode()) {
759 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); 756 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode();
760 return; 757 return;
761 } 758 }
762 759
763 // Right aligned icons. 760 // Right aligned icons.
764 int end_position = available_size; 761 int end_position = available_size;
765 x = wm_shelf_->PrimaryAxisValue(end_position, 0); 762 x = shelf_->PrimaryAxisValue(end_position, 0);
766 y = wm_shelf_->PrimaryAxisValue(0, end_position); 763 y = shelf_->PrimaryAxisValue(0, end_position);
767 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) { 764 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) {
768 x = wm_shelf_->PrimaryAxisValue(x - w - kShelfButtonSpacing, x); 765 x = shelf_->PrimaryAxisValue(x - w - kShelfButtonSpacing, x);
769 y = wm_shelf_->PrimaryAxisValue(y, y - h - kShelfButtonSpacing); 766 y = shelf_->PrimaryAxisValue(y, y - h - kShelfButtonSpacing);
770 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 767 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
771 end_position = wm_shelf_->PrimaryAxisValue(x, y); 768 end_position = shelf_->PrimaryAxisValue(x, y);
772 } 769 }
773 770
774 // Icons on the left / top are guaranteed up to kLeftIconProportion of 771 // Icons on the left / top are guaranteed up to kLeftIconProportion of
775 // the available space. 772 // the available space.
776 int last_icon_position = 773 int last_icon_position =
777 wm_shelf_->PrimaryAxisValue( 774 shelf_->PrimaryAxisValue(
778 view_model_->ideal_bounds(last_button_index).right(), 775 view_model_->ideal_bounds(last_button_index).right(),
779 view_model_->ideal_bounds(last_button_index).bottom()) + 776 view_model_->ideal_bounds(last_button_index).bottom()) +
780 kShelfButtonSpacing; 777 kShelfButtonSpacing;
781 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; 778 int reserved_icon_space = available_size * kReservedNonPanelIconProportion;
782 if (last_icon_position < reserved_icon_space) 779 if (last_icon_position < reserved_icon_space)
783 end_position = last_icon_position; 780 end_position = last_icon_position;
784 else 781 else
785 end_position = std::max(end_position, reserved_icon_space); 782 end_position = std::max(end_position, reserved_icon_space);
786 783
787 overflow_bounds->set_size( 784 overflow_bounds->set_size(gfx::Size(shelf_->PrimaryAxisValue(w, width()),
788 gfx::Size(wm_shelf_->PrimaryAxisValue(w, width()), 785 shelf_->PrimaryAxisValue(height(), h)));
789 wm_shelf_->PrimaryAxisValue(height(), h)));
790 786
791 last_visible_index_ = 787 last_visible_index_ =
792 DetermineLastVisibleIndex(end_position - kShelfButtonSpacing); 788 DetermineLastVisibleIndex(end_position - kShelfButtonSpacing);
793 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; 789 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1;
794 bool show_overflow = last_visible_index_ < last_button_index || 790 bool show_overflow = last_visible_index_ < last_button_index ||
795 last_hidden_index_ >= first_panel_index; 791 last_hidden_index_ >= first_panel_index;
796 792
797 // Create Space for the overflow button 793 // Create Space for the overflow button
798 if (show_overflow) { 794 if (show_overflow) {
799 // The following code makes sure that platform apps icons (aligned to left / 795 // The following code makes sure that platform apps icons (aligned to left /
(...skipping 27 matching lines...) Expand all
827 view_model_->view_at(i)->SetVisible(visible); 823 view_model_->view_at(i)->SetVisible(visible);
828 } 824 }
829 825
830 overflow_button_->SetVisible(show_overflow); 826 overflow_button_->SetVisible(show_overflow);
831 if (show_overflow) { 827 if (show_overflow) {
832 DCHECK_NE(0, view_model_->view_size()); 828 DCHECK_NE(0, view_model_->view_size());
833 if (last_visible_index_ == -1) { 829 if (last_visible_index_ == -1) {
834 x = 0; 830 x = 0;
835 y = 0; 831 y = 0;
836 } else { 832 } else {
837 x = wm_shelf_->PrimaryAxisValue( 833 x = shelf_->PrimaryAxisValue(
838 view_model_->ideal_bounds(last_visible_index_).right(), 834 view_model_->ideal_bounds(last_visible_index_).right(),
839 view_model_->ideal_bounds(last_visible_index_).x()); 835 view_model_->ideal_bounds(last_visible_index_).x());
840 y = wm_shelf_->PrimaryAxisValue( 836 y = shelf_->PrimaryAxisValue(
841 view_model_->ideal_bounds(last_visible_index_).y(), 837 view_model_->ideal_bounds(last_visible_index_).y(),
842 view_model_->ideal_bounds(last_visible_index_).bottom()); 838 view_model_->ideal_bounds(last_visible_index_).bottom());
843 } 839 }
844 840
845 if (last_visible_index_ >= 0) { 841 if (last_visible_index_ >= 0) {
846 // Add more space between last visible item and overflow button. 842 // Add more space between last visible item and overflow button.
847 // Without this, two buttons look too close compared with other items. 843 // Without this, two buttons look too close compared with other items.
848 x = wm_shelf_->PrimaryAxisValue(x + kShelfButtonSpacing, x); 844 x = shelf_->PrimaryAxisValue(x + kShelfButtonSpacing, x);
849 y = wm_shelf_->PrimaryAxisValue(y, y + kShelfButtonSpacing); 845 y = shelf_->PrimaryAxisValue(y, y + kShelfButtonSpacing);
850 } 846 }
851 847
852 // Set all hidden panel icon positions to be on the overflow button. 848 // Set all hidden panel icon positions to be on the overflow button.
853 for (int i = first_panel_index; i <= last_hidden_index_; ++i) 849 for (int i = first_panel_index; i <= last_hidden_index_; ++i)
854 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 850 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
855 851
856 overflow_bounds->set_x(x); 852 overflow_bounds->set_x(x);
857 overflow_bounds->set_y(y); 853 overflow_bounds->set_y(y);
858 if (overflow_bubble_.get() && overflow_bubble_->IsShowing()) 854 if (overflow_bubble_.get() && overflow_bubble_->IsShowing())
859 UpdateOverflowRange(overflow_bubble_->shelf_view()); 855 UpdateOverflowRange(overflow_bubble_->shelf_view());
860 } else { 856 } else {
861 if (overflow_bubble_) 857 if (overflow_bubble_)
862 overflow_bubble_->Hide(); 858 overflow_bubble_->Hide();
863 } 859 }
864 } 860 }
865 861
866 int ShelfView::DetermineLastVisibleIndex(int max_value) const { 862 int ShelfView::DetermineLastVisibleIndex(int max_value) const {
867 int index = model_->FirstPanelIndex() - 1; 863 int index = model_->FirstPanelIndex() - 1;
868 while (index >= 0 && 864 while (index >= 0 &&
869 wm_shelf_->PrimaryAxisValue( 865 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).right(),
870 view_model_->ideal_bounds(index).right(), 866 view_model_->ideal_bounds(index).bottom()) >
871 view_model_->ideal_bounds(index).bottom()) > max_value) { 867 max_value) {
872 index--; 868 index--;
873 } 869 }
874 return index; 870 return index;
875 } 871 }
876 872
877 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const { 873 int ShelfView::DetermineFirstVisiblePanelIndex(int min_value) const {
878 int index = model_->FirstPanelIndex(); 874 int index = model_->FirstPanelIndex();
879 while (index < view_model_->view_size() && 875 while (index < view_model_->view_size() &&
880 wm_shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).x(), 876 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(index).x(),
881 view_model_->ideal_bounds(index).y()) < 877 view_model_->ideal_bounds(index).y()) <
882 min_value) { 878 min_value) {
883 ++index; 879 ++index;
884 } 880 }
885 return index; 881 return index;
886 } 882 }
887 883
888 void ShelfView::AnimateToIdealBounds() { 884 void ShelfView::AnimateToIdealBounds() {
889 gfx::Rect overflow_bounds; 885 gfx::Rect overflow_bounds;
890 CalculateIdealBounds(&overflow_bounds); 886 CalculateIdealBounds(&overflow_bounds);
891 for (int i = 0; i < view_model_->view_size(); ++i) { 887 for (int i = 0; i < view_model_->view_size(); ++i) {
(...skipping 16 matching lines...) Expand all
908 case TYPE_APP: 904 case TYPE_APP:
909 case TYPE_DIALOG: { 905 case TYPE_DIALOG: {
910 ShelfButton* button = new ShelfButton(this, this); 906 ShelfButton* button = new ShelfButton(this, this);
911 button->SetImage(item.image); 907 button->SetImage(item.image);
912 ReflectItemStatus(item, button); 908 ReflectItemStatus(item, button);
913 view = button; 909 view = button;
914 break; 910 break;
915 } 911 }
916 912
917 case TYPE_APP_LIST: { 913 case TYPE_APP_LIST: {
918 view = new AppListButton(this, this, wm_shelf_); 914 view = new AppListButton(this, this, shelf_);
919 break; 915 break;
920 } 916 }
921 917
922 case TYPE_UNDEFINED: 918 case TYPE_UNDEFINED:
923 return nullptr; 919 return nullptr;
924 } 920 }
925 921
926 view->set_context_menu_controller(this); 922 view->set_context_menu_controller(this);
927 ConfigureChildView(view); 923 ConfigureChildView(view);
928 return view; 924 return view;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
980 // Constrain the location to the range of valid indices for the type. 976 // Constrain the location to the range of valid indices for the type.
981 std::pair<int, int> indices(GetDragRange(current_index)); 977 std::pair<int, int> indices(GetDragRange(current_index));
982 int first_drag_index = indices.first; 978 int first_drag_index = indices.first;
983 int last_drag_index = indices.second; 979 int last_drag_index = indices.second;
984 // If the last index isn't valid, we're overflowing. Constrain to the app list 980 // If the last index isn't valid, we're overflowing. Constrain to the app list
985 // (which is the last visible item). 981 // (which is the last visible item).
986 if (first_drag_index < model_->FirstPanelIndex() && 982 if (first_drag_index < model_->FirstPanelIndex() &&
987 last_drag_index > last_visible_index_) 983 last_drag_index > last_visible_index_)
988 last_drag_index = last_visible_index_; 984 last_drag_index = last_visible_index_;
989 int x = 0, y = 0; 985 int x = 0, y = 0;
990 if (wm_shelf_->IsHorizontalAlignment()) { 986 if (shelf_->IsHorizontalAlignment()) {
991 x = std::max(view_model_->ideal_bounds(indices.first).x(), 987 x = std::max(view_model_->ideal_bounds(indices.first).x(),
992 drag_point.x() - drag_origin_.x()); 988 drag_point.x() - drag_origin_.x());
993 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - 989 x = std::min(view_model_->ideal_bounds(last_drag_index).right() -
994 view_model_->ideal_bounds(current_index).width(), 990 view_model_->ideal_bounds(current_index).width(),
995 x); 991 x);
996 if (drag_view_->x() == x) 992 if (drag_view_->x() == x)
997 return; 993 return;
998 drag_view_->SetX(x); 994 drag_view_->SetX(x);
999 } else { 995 } else {
1000 y = std::max(view_model_->ideal_bounds(indices.first).y(), 996 y = std::max(view_model_->ideal_bounds(indices.first).y(),
1001 drag_point.y() - drag_origin_.y()); 997 drag_point.y() - drag_origin_.y());
1002 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() - 998 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() -
1003 view_model_->ideal_bounds(current_index).height(), 999 view_model_->ideal_bounds(current_index).height(),
1004 y); 1000 y);
1005 if (drag_view_->y() == y) 1001 if (drag_view_->y() == y)
1006 return; 1002 return;
1007 drag_view_->SetY(y); 1003 drag_view_->SetY(y);
1008 } 1004 }
1009 1005
1010 int target_index = views::ViewModelUtils::DetermineMoveIndex( 1006 int target_index = views::ViewModelUtils::DetermineMoveIndex(
1011 *view_model_, drag_view_, 1007 *view_model_, drag_view_,
1012 wm_shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL 1008 shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL
1013 : views::ViewModelUtils::VERTICAL, 1009 : views::ViewModelUtils::VERTICAL,
1014 x, y); 1010 x, y);
1015 target_index = 1011 target_index =
1016 std::min(indices.second, std::max(target_index, indices.first)); 1012 std::min(indices.second, std::max(target_index, indices.first));
1017 1013
1018 // The app list button is always first, and it is the only non-draggable item. 1014 // The app list button is always first, and it is the only non-draggable item.
1019 int first_draggable_item = model_->GetItemIndexForType(TYPE_APP_LIST) + 1; 1015 int first_draggable_item = model_->GetItemIndexForType(TYPE_APP_LIST) + 1;
1020 DCHECK_EQ(1, first_draggable_item); 1016 DCHECK_EQ(1, first_draggable_item);
1021 target_index = std::max(target_index, first_draggable_item); 1017 target_index = std::max(target_index, first_draggable_item);
1022 DCHECK_LT(target_index, model_->item_count()); 1018 DCHECK_LT(target_index, model_->item_count());
1023 1019
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 view->layer()->SetFillsBoundsOpaquely(false); 1276 view->layer()->SetFillsBoundsOpaquely(false);
1281 } 1277 }
1282 1278
1283 void ShelfView::ToggleOverflowBubble() { 1279 void ShelfView::ToggleOverflowBubble() {
1284 if (IsShowingOverflowBubble()) { 1280 if (IsShowingOverflowBubble()) {
1285 overflow_bubble_->Hide(); 1281 overflow_bubble_->Hide();
1286 return; 1282 return;
1287 } 1283 }
1288 1284
1289 if (!overflow_bubble_) 1285 if (!overflow_bubble_)
1290 overflow_bubble_.reset(new OverflowBubble(wm_shelf_)); 1286 overflow_bubble_.reset(new OverflowBubble(shelf_));
1291 1287
1292 ShelfView* overflow_view = new ShelfView(model_, wm_shelf_, shelf_widget_); 1288 ShelfView* overflow_view = new ShelfView(model_, shelf_, shelf_widget_);
1293 overflow_view->overflow_mode_ = true; 1289 overflow_view->overflow_mode_ = true;
1294 overflow_view->Init(); 1290 overflow_view->Init();
1295 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get()); 1291 overflow_view->set_owner_overflow_bubble(overflow_bubble_.get());
1296 overflow_view->OnShelfAlignmentChanged(); 1292 overflow_view->OnShelfAlignmentChanged();
1297 overflow_view->main_shelf_ = this; 1293 overflow_view->main_shelf_ = this;
1298 UpdateOverflowRange(overflow_view); 1294 UpdateOverflowRange(overflow_view);
1299 1295
1300 overflow_bubble_->Show(overflow_button_, overflow_view); 1296 overflow_bubble_->Show(overflow_button_, overflow_view);
1301 1297
1302 wm_shelf_->UpdateVisibilityState(); 1298 shelf_->UpdateVisibilityState();
1303 } 1299 }
1304 1300
1305 void ShelfView::OnFadeOutAnimationEnded() { 1301 void ShelfView::OnFadeOutAnimationEnded() {
1306 AnimateToIdealBounds(); 1302 AnimateToIdealBounds();
1307 StartFadeInLastVisibleItem(); 1303 StartFadeInLastVisibleItem();
1308 } 1304 }
1309 1305
1310 void ShelfView::StartFadeInLastVisibleItem() { 1306 void ShelfView::StartFadeInLastVisibleItem() {
1311 // If overflow button is visible and there is a valid new last item, fading 1307 // If overflow button is visible and there is a valid new last item, fading
1312 // the new last item in after sliding animation is finished. 1308 // the new last item in after sliding animation is finished.
(...skipping 28 matching lines...) Expand all
1341 const int last_button_index = view_model_->view_size() - 1; 1337 const int last_button_index = view_model_->view_size() - 1;
1342 gfx::Rect last_button_bounds = 1338 gfx::Rect last_button_bounds =
1343 view_model_->view_at(last_button_index)->bounds(); 1339 view_model_->view_at(last_button_index)->bounds();
1344 if (overflow_button_->visible() && 1340 if (overflow_button_->visible() &&
1345 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { 1341 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) {
1346 // When overflow button is visible and shelf has no panel items, 1342 // When overflow button is visible and shelf has no panel items,
1347 // last_button_bounds should be overflow button's bounds. 1343 // last_button_bounds should be overflow button's bounds.
1348 last_button_bounds = overflow_button_->bounds(); 1344 last_button_bounds = overflow_button_->bounds();
1349 } 1345 }
1350 1346
1351 if (wm_shelf_->IsHorizontalAlignment()) { 1347 if (shelf_->IsHorizontalAlignment()) {
1352 preferred_size = gfx::Size(last_button_bounds.right(), kShelfSize); 1348 preferred_size = gfx::Size(last_button_bounds.right(), kShelfSize);
1353 } else { 1349 } else {
1354 preferred_size = gfx::Size(kShelfSize, last_button_bounds.bottom()); 1350 preferred_size = gfx::Size(kShelfSize, last_button_bounds.bottom());
1355 } 1351 }
1356 } 1352 }
1357 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); 1353 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0);
1358 1354
1359 // In overflow mode, we should use OverflowBubbleView as a source for 1355 // In overflow mode, we should use OverflowBubbleView as a source for
1360 // converting |origin| to screen coordinates. When a scroll operation is 1356 // converting |origin| to screen coordinates. When a scroll operation is
1361 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can 1357 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1416 // invisible items in the shelf. 1412 // invisible items in the shelf.
1417 if (is_overflow_mode() && dragged_off_shelf_ && !dragged_to_another_shelf_ && 1413 if (is_overflow_mode() && dragged_off_shelf_ && !dragged_to_another_shelf_ &&
1418 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) 1414 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
1419 last_button_index--; 1415 last_button_index--;
1420 1416
1421 const gfx::Rect last_button_bounds = 1417 const gfx::Rect last_button_bounds =
1422 last_button_index >= first_visible_index_ 1418 last_button_index >= first_visible_index_
1423 ? view_model_->ideal_bounds(last_button_index) 1419 ? view_model_->ideal_bounds(last_button_index)
1424 : gfx::Rect(gfx::Size(kShelfSize, kShelfSize)); 1420 : gfx::Rect(gfx::Size(kShelfSize, kShelfSize));
1425 1421
1426 if (wm_shelf_->IsHorizontalAlignment()) 1422 if (shelf_->IsHorizontalAlignment())
1427 return gfx::Size(last_button_bounds.right(), kShelfSize); 1423 return gfx::Size(last_button_bounds.right(), kShelfSize);
1428 1424
1429 return gfx::Size(kShelfSize, last_button_bounds.bottom()); 1425 return gfx::Size(kShelfSize, last_button_bounds.bottom());
1430 } 1426 }
1431 1427
1432 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 1428 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
1433 // This bounds change is produced by the shelf movement and all content has 1429 // This bounds change is produced by the shelf movement and all content has
1434 // to follow. Using an animation at that time would produce a time lag since 1430 // to follow. Using an animation at that time would produce a time lag since
1435 // the animation of the BoundsAnimator has itself a delay before it arrives 1431 // the animation of the BoundsAnimator has itself a delay before it arrives
1436 // at the required location. As such we tell the animator to go there 1432 // at the required location. As such we tell the animator to go there
1437 // immediately. 1433 // immediately.
1438 BoundsAnimatorDisabler disabler(bounds_animator_.get()); 1434 BoundsAnimatorDisabler disabler(bounds_animator_.get());
1439 LayoutToIdealBounds(); 1435 LayoutToIdealBounds();
1440 wm_shelf_->NotifyShelfIconPositionsChanged(); 1436 shelf_->NotifyShelfIconPositionsChanged();
1441 1437
1442 if (IsShowingOverflowBubble()) 1438 if (IsShowingOverflowBubble())
1443 overflow_bubble_->Hide(); 1439 overflow_bubble_->Hide();
1444 } 1440 }
1445 1441
1446 views::FocusTraversable* ShelfView::GetPaneFocusTraversable() { 1442 views::FocusTraversable* ShelfView::GetPaneFocusTraversable() {
1447 return this; 1443 return this;
1448 } 1444 }
1449 1445
1450 void ShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) { 1446 void ShelfView::GetAccessibleNodeData(ui::AXNodeData* node_data) {
1451 node_data->role = ui::AX_ROLE_TOOLBAR; 1447 node_data->role = ui::AX_ROLE_TOOLBAR;
1452 node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME)); 1448 node_data->SetName(l10n_util::GetStringUTF8(IDS_ASH_SHELF_ACCESSIBLE_NAME));
1453 } 1449 }
1454 1450
1455 void ShelfView::ViewHierarchyChanged( 1451 void ShelfView::ViewHierarchyChanged(
1456 const ViewHierarchyChangedDetails& details) { 1452 const ViewHierarchyChangedDetails& details) {
1457 if (details.is_add && details.child == this) 1453 if (details.is_add && details.child == this)
1458 tooltip_.Init(); 1454 tooltip_.Init();
1459 } 1455 }
1460 1456
1461 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { 1457 void ShelfView::OnGestureEvent(ui::GestureEvent* event) {
1462 if (wm_shelf_->ProcessGestureEvent(*event)) 1458 if (shelf_->ProcessGestureEvent(*event))
1463 event->StopPropagation(); 1459 event->StopPropagation();
1464 } 1460 }
1465 1461
1466 void ShelfView::ShelfItemAdded(int model_index) { 1462 void ShelfView::ShelfItemAdded(int model_index) {
1467 { 1463 {
1468 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_, 1464 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_,
1469 true); 1465 true);
1470 model_index = CancelDrag(model_index); 1466 model_index = CancelDrag(model_index);
1471 } 1467 }
1472 views::View* view = CreateViewForItem(model_->items()[model_index]); 1468 views::View* view = CreateViewForItem(model_->items()[model_index]);
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
1635 ui::MenuSourceType source_type) { 1631 ui::MenuSourceType source_type) {
1636 gfx::Point context_menu_point = point; 1632 gfx::Point context_menu_point = point;
1637 // Align the context menu to the edge of the shelf for touch events. 1633 // Align the context menu to the edge of the shelf for touch events.
1638 if (source_type == ui::MenuSourceType::MENU_SOURCE_TOUCH) { 1634 if (source_type == ui::MenuSourceType::MENU_SOURCE_TOUCH) {
1639 aura::Window* shelf_window = shelf_widget_->GetNativeWindow(); 1635 aura::Window* shelf_window = shelf_widget_->GetNativeWindow();
1640 gfx::Rect shelf_bounds = 1636 gfx::Rect shelf_bounds =
1641 is_overflow_mode() 1637 is_overflow_mode()
1642 ? owner_overflow_bubble_->bubble_view()->GetBubbleBounds() 1638 ? owner_overflow_bubble_->bubble_view()->GetBubbleBounds()
1643 : ScreenUtil::GetDisplayBoundsWithShelf(shelf_window); 1639 : ScreenUtil::GetDisplayBoundsWithShelf(shelf_window);
1644 1640
1645 switch (wm_shelf_->GetAlignment()) { 1641 switch (shelf_->alignment()) {
1646 case SHELF_ALIGNMENT_BOTTOM: 1642 case SHELF_ALIGNMENT_BOTTOM:
1647 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 1643 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1648 context_menu_point.SetPoint(point.x(), 1644 context_menu_point.SetPoint(point.x(),
1649 shelf_bounds.bottom() - kShelfSize); 1645 shelf_bounds.bottom() - kShelfSize);
1650 break; 1646 break;
1651 case SHELF_ALIGNMENT_LEFT: 1647 case SHELF_ALIGNMENT_LEFT:
1652 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y()); 1648 context_menu_point.SetPoint(shelf_bounds.x() + kShelfSize, point.y());
1653 break; 1649 break;
1654 case SHELF_ALIGNMENT_RIGHT: 1650 case SHELF_ALIGNMENT_RIGHT:
1655 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize, 1651 context_menu_point.SetPoint(shelf_bounds.right() - kShelfSize,
1656 point.y()); 1652 point.y());
1657 break; 1653 break;
1658 } 1654 }
1659 } 1655 }
1660 last_pressed_index_ = -1; 1656 last_pressed_index_ = -1;
1661 1657
1662 const ShelfItem* item = ShelfItemForView(source); 1658 const ShelfItem* item = ShelfItemForView(source);
1663 if (!item) { 1659 if (!item) {
1664 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type); 1660 ShellPort::Get()->ShowContextMenu(context_menu_point, source_type);
1665 return; 1661 return;
1666 } 1662 }
1667 1663
1668 std::unique_ptr<ui::MenuModel> context_menu_model( 1664 std::unique_ptr<ui::MenuModel> context_menu_model(
1669 Shell::Get()->shell_delegate()->CreateContextMenu(wm_shelf_, item)); 1665 Shell::Get()->shell_delegate()->CreateContextMenu(shelf_, item));
1670 if (!context_menu_model) 1666 if (!context_menu_model)
1671 return; 1667 return;
1672 1668
1673 context_menu_id_ = item ? item->id : ShelfID(); 1669 context_menu_id_ = item ? item->id : ShelfID();
1674 ShowMenu(std::move(context_menu_model), source, context_menu_point, true, 1670 ShowMenu(std::move(context_menu_model), source, context_menu_point, true,
1675 source_type, nullptr); 1671 source_type, nullptr);
1676 } 1672 }
1677 1673
1678 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model, 1674 void ShelfView::ShowMenu(std::unique_ptr<ui::MenuModel> menu_model,
1679 views::View* source, 1675 views::View* source,
(...skipping 27 matching lines...) Expand all
1707 // It is possible to invoke the menu while it is sliding into view. To cover 1703 // It is possible to invoke the menu while it is sliding into view. To cover
1708 // that case, the screen coordinates are offsetted by the animation delta. 1704 // that case, the screen coordinates are offsetted by the animation delta.
1709 anchor = source->GetBoundsInScreen() + 1705 anchor = source->GetBoundsInScreen() +
1710 (window->GetTargetBounds().origin() - window->bounds().origin()); 1706 (window->GetTargetBounds().origin() - window->bounds().origin());
1711 1707
1712 // Adjust the anchor location for shelf items with asymmetrical borders. 1708 // Adjust the anchor location for shelf items with asymmetrical borders.
1713 if (source->border()) 1709 if (source->border())
1714 anchor.Inset(source->border()->GetInsets()); 1710 anchor.Inset(source->border()->GetInsets());
1715 1711
1716 // Determine the menu alignment dependent on the shelf. 1712 // Determine the menu alignment dependent on the shelf.
1717 switch (wm_shelf_->GetAlignment()) { 1713 switch (shelf_->alignment()) {
1718 case SHELF_ALIGNMENT_BOTTOM: 1714 case SHELF_ALIGNMENT_BOTTOM:
1719 case SHELF_ALIGNMENT_BOTTOM_LOCKED: 1715 case SHELF_ALIGNMENT_BOTTOM_LOCKED:
1720 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE; 1716 menu_alignment = views::MENU_ANCHOR_BUBBLE_ABOVE;
1721 break; 1717 break;
1722 case SHELF_ALIGNMENT_LEFT: 1718 case SHELF_ALIGNMENT_LEFT:
1723 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT; 1719 menu_alignment = views::MENU_ANCHOR_BUBBLE_RIGHT;
1724 break; 1720 break;
1725 case SHELF_ALIGNMENT_RIGHT: 1721 case SHELF_ALIGNMENT_RIGHT:
1726 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT; 1722 menu_alignment = views::MENU_ANCHOR_BUBBLE_LEFT;
1727 break; 1723 break;
1728 } 1724 }
1729 } else { 1725 } else {
1730 // Distinguish the touch events that triggered on the bottom or left / right 1726 // Distinguish the touch events that triggered on the bottom or left / right
1731 // shelf. Since they should have different |MenuAnchorPosition|. 1727 // shelf. Since they should have different |MenuAnchorPosition|.
1732 if (wm_shelf_->IsHorizontalAlignment()) 1728 if (shelf_->IsHorizontalAlignment())
1733 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER; 1729 menu_alignment = views::MENU_ANCHOR_FIXED_BOTTOMCENTER;
1734 else 1730 else
1735 menu_alignment = views::MENU_ANCHOR_FIXED_SIDECENTER; 1731 menu_alignment = views::MENU_ANCHOR_FIXED_SIDECENTER;
1736 } 1732 }
1737 1733
1738 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code. 1734 // NOTE: if you convert to HAS_MNEMONICS be sure to update menu building code.
1739 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor, 1735 launcher_menu_runner_->RunMenuAt(source->GetWidget(), nullptr, anchor,
1740 menu_alignment, source_type); 1736 menu_alignment, source_type);
1741 } 1737 }
1742 1738
1743 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) { 1739 void ShelfView::OnMenuClosed(views::InkDrop* ink_drop) {
1744 context_menu_id_ = ShelfID(); 1740 context_menu_id_ = ShelfID();
1745 1741
1746 // Hide the hide overflow bubble after showing a context menu for its items. 1742 // Hide the hide overflow bubble after showing a context menu for its items.
1747 if (owner_overflow_bubble_) 1743 if (owner_overflow_bubble_)
1748 owner_overflow_bubble_->Hide(); 1744 owner_overflow_bubble_->Hide();
1749 1745
1750 closing_event_time_ = launcher_menu_runner_->closing_event_time(); 1746 closing_event_time_ = launcher_menu_runner_->closing_event_time();
1751 1747
1752 if (ink_drop) 1748 if (ink_drop)
1753 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED); 1749 ink_drop->AnimateToState(views::InkDropState::DEACTIVATED);
1754 1750
1755 launcher_menu_runner_.reset(); 1751 launcher_menu_runner_.reset();
1756 menu_model_adapter_.reset(); 1752 menu_model_adapter_.reset();
1757 menu_model_.reset(); 1753 menu_model_.reset();
1758 scoped_root_window_for_new_windows_.reset(); 1754 scoped_root_window_for_new_windows_.reset();
1759 1755
1760 // Auto-hide or alignment might have changed, but only for this shelf. 1756 // Auto-hide or alignment might have changed, but only for this shelf.
1761 wm_shelf_->UpdateVisibilityState(); 1757 shelf_->UpdateVisibilityState();
1762 } 1758 }
1763 1759
1764 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) { 1760 void ShelfView::OnBoundsAnimatorProgressed(views::BoundsAnimator* animator) {
1765 wm_shelf_->NotifyShelfIconPositionsChanged(); 1761 shelf_->NotifyShelfIconPositionsChanged();
1766 PreferredSizeChanged(); 1762 PreferredSizeChanged();
1767 } 1763 }
1768 1764
1769 void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { 1765 void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) {
1770 if (snap_back_from_rip_off_view_ && animator == bounds_animator_.get()) { 1766 if (snap_back_from_rip_off_view_ && animator == bounds_animator_.get()) {
1771 if (!animator->IsAnimating(snap_back_from_rip_off_view_)) { 1767 if (!animator->IsAnimating(snap_back_from_rip_off_view_)) {
1772 // Coming here the animation of the ShelfButton is finished and the 1768 // Coming here the animation of the ShelfButton is finished and the
1773 // previously hidden status can be shown again. Since the button itself 1769 // previously hidden status can be shown again. Since the button itself
1774 // might have gone away or changed locations we check that the button 1770 // might have gone away or changed locations we check that the button
1775 // is still in the shelf and show its status again. 1771 // is still in the shelf and show its status again.
(...skipping 20 matching lines...) Expand all
1796 return closing_event_time_ == event.time_stamp(); 1792 return closing_event_time_ == event.time_stamp();
1797 } 1793 }
1798 1794
1799 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const { 1795 const ShelfItem* ShelfView::ShelfItemForView(const views::View* view) const {
1800 const int view_index = view_model_->GetIndexOfView(view); 1796 const int view_index = view_model_->GetIndexOfView(view);
1801 return (view_index < 0) ? nullptr : &(model_->items()[view_index]); 1797 return (view_index < 0) ? nullptr : &(model_->items()[view_index]);
1802 } 1798 }
1803 1799
1804 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1800 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1805 const gfx::Rect bounds = GetBoundsInScreen(); 1801 const gfx::Rect bounds = GetBoundsInScreen();
1806 int distance = wm_shelf_->SelectValueForShelfAlignment( 1802 int distance = shelf_->SelectValueForShelfAlignment(
1807 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1803 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1808 bounds.x() - coordinate.x()); 1804 bounds.x() - coordinate.x());
1809 return distance > 0 ? distance : 0; 1805 return distance > 0 ? distance : 0;
1810 } 1806 }
1811 1807
1812 bool ShelfView::CanPrepareForDrag(Pointer pointer, 1808 bool ShelfView::CanPrepareForDrag(Pointer pointer,
1813 const ui::LocatedEvent& event) { 1809 const ui::LocatedEvent& event) {
1814 // Bail if dragging has already begun, or if no item has been pressed. 1810 // Bail if dragging has already begun, or if no item has been pressed.
1815 if (dragging() || !drag_view_) 1811 if (dragging() || !drag_view_)
1816 return false; 1812 return false;
1817 1813
1818 // Dragging only begins once the pointer has travelled a minimum distance. 1814 // Dragging only begins once the pointer has travelled a minimum distance.
1819 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) && 1815 if ((std::abs(event.x() - drag_origin_.x()) < kMinimumDragDistance) &&
1820 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) { 1816 (std::abs(event.y() - drag_origin_.y()) < kMinimumDragDistance)) {
1821 return false; 1817 return false;
1822 } 1818 }
1823 1819
1824 // Touch dragging only begins after a delay from the press event. This 1820 // Touch dragging only begins after a delay from the press event. This
1825 // prevents accidental dragging on swipe or scroll gestures. 1821 // prevents accidental dragging on swipe or scroll gestures.
1826 if (pointer == TOUCH && 1822 if (pointer == TOUCH &&
1827 (base::TimeTicks::Now() - touch_press_time_) < 1823 (base::TimeTicks::Now() - touch_press_time_) <
1828 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) { 1824 base::TimeDelta::FromMilliseconds(kTouchDragTimeThresholdMs)) {
1829 return false; 1825 return false;
1830 } 1826 }
1831 1827
1832 return true; 1828 return true;
1833 } 1829 }
1834 1830
1835 } // namespace ash 1831 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698