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

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

Issue 2095193002: clang-format all of //ash (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 6 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
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/aura/wm_window_aura.h" 10 #include "ash/aura/wm_window_aura.h"
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
78 78
79 // The proportion of the shelf space reserved for non-panel icons. Panels 79 // The proportion of the shelf space reserved for non-panel icons. Panels
80 // may flow into this space but will be put into the overflow bubble if there 80 // may flow into this space but will be put into the overflow bubble if there
81 // is contention for the space. 81 // is contention for the space.
82 const float kReservedNonPanelIconProportion = 0.67f; 82 const float kReservedNonPanelIconProportion = 0.67f;
83 83
84 // This is the command id of the menu item which contains the name of the menu. 84 // This is the command id of the menu item which contains the name of the menu.
85 const int kCommandIdOfMenuName = 0; 85 const int kCommandIdOfMenuName = 0;
86 86
87 // The background color of the active item in the list. 87 // The background color of the active item in the list.
88 const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203 , 219, 241); 88 const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203, 219, 241);
89 89
90 // The background color of the active & hovered item in the list. 90 // The background color of the active & hovered item in the list.
91 const SkColor kFocusedActiveListItemBackgroundColor = 91 const SkColor kFocusedActiveListItemBackgroundColor =
92 SkColorSetRGB(193, 211, 236); 92 SkColorSetRGB(193, 211, 236);
93 93
94 // The text color of the caption item in a list. 94 // The text color of the caption item in a list.
95 const SkColor kCaptionItemForegroundColor = SK_ColorBLACK; 95 const SkColor kCaptionItemForegroundColor = SK_ColorBLACK;
96 96
97 // The maximum allowable length of a menu line of an application menu in pixels. 97 // The maximum allowable length of a menu line of an application menu in pixels.
98 const int kMaximumAppMenuItemLength = 350; 98 const int kMaximumAppMenuItemLength = 350;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 int GetMaxWidthForMenu(views::MenuItemView* menu) override; 154 int GetMaxWidthForMenu(views::MenuItemView* menu) override;
155 bool ShouldReserveSpaceForSubmenuIndicator() const override; 155 bool ShouldReserveSpaceForSubmenuIndicator() const override;
156 156
157 private: 157 private:
158 ShelfMenuModel* menu_model_; 158 ShelfMenuModel* menu_model_;
159 159
160 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelAdapter); 160 DISALLOW_COPY_AND_ASSIGN(ShelfMenuModelAdapter);
161 }; 161 };
162 162
163 ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model) 163 ShelfMenuModelAdapter::ShelfMenuModelAdapter(ShelfMenuModel* menu_model)
164 : MenuModelAdapter(menu_model), 164 : MenuModelAdapter(menu_model), menu_model_(menu_model) {}
165 menu_model_(menu_model) {
166 }
167 165
168 const gfx::FontList* ShelfMenuModelAdapter::GetLabelFontList( 166 const gfx::FontList* ShelfMenuModelAdapter::GetLabelFontList(
169 int command_id) const { 167 int command_id) const {
170 if (command_id != kCommandIdOfMenuName) 168 if (command_id != kCommandIdOfMenuName)
171 return MenuModelAdapter::GetLabelFontList(command_id); 169 return MenuModelAdapter::GetLabelFontList(command_id);
172 170
173 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance(); 171 ui::ResourceBundle* rb = &ui::ResourceBundle::GetSharedInstance();
174 return &rb->GetFontList(ui::ResourceBundle::BoldFont); 172 return &rb->GetFontList(ui::ResourceBundle::BoldFont);
175 } 173 }
176 174
(...skipping 10 matching lines...) Expand all
187 *override_color = kCaptionItemForegroundColor; 185 *override_color = kCaptionItemForegroundColor;
188 return true; 186 return true;
189 } 187 }
190 188
191 bool ShelfMenuModelAdapter::GetBackgroundColor(int command_id, 189 bool ShelfMenuModelAdapter::GetBackgroundColor(int command_id,
192 bool is_hovered, 190 bool is_hovered,
193 SkColor* override_color) const { 191 SkColor* override_color) const {
194 if (!menu_model_->IsCommandActive(command_id)) 192 if (!menu_model_->IsCommandActive(command_id))
195 return false; 193 return false;
196 194
197 *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor : 195 *override_color = is_hovered ? kFocusedActiveListItemBackgroundColor
198 kActiveListItemBackgroundColor; 196 : kActiveListItemBackgroundColor;
199 return true; 197 return true;
200 } 198 }
201 199
202 void ShelfMenuModelAdapter::GetHorizontalIconMargins(int command_id, 200 void ShelfMenuModelAdapter::GetHorizontalIconMargins(int command_id,
203 int icon_size, 201 int icon_size,
204 int* left_margin, 202 int* left_margin,
205 int* right_margin) const { 203 int* right_margin) const {
206 *left_margin = kHorizontalIconSpacing; 204 *left_margin = kHorizontalIconSpacing;
207 *right_margin = (command_id != kCommandIdOfMenuName) ? 205 *right_margin = (command_id != kCommandIdOfMenuName)
208 kHorizontalIconSpacing : -(icon_size + kHorizontalNoIconInsetSpacing); 206 ? kHorizontalIconSpacing
207 : -(icon_size + kHorizontalNoIconInsetSpacing);
209 } 208 }
210 209
211 int ShelfMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) { 210 int ShelfMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) {
212 return kMaximumAppMenuItemLength; 211 return kMaximumAppMenuItemLength;
213 } 212 }
214 213
215 bool ShelfMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const { 214 bool ShelfMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const {
216 return false; 215 return false;
217 } 216 }
218 217
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
305 } 304 }
306 } 305 }
307 306
308 } // namespace 307 } // namespace
309 308
310 // AnimationDelegate used when deleting an item. This steadily decreased the 309 // AnimationDelegate used when deleting an item. This steadily decreased the
311 // opacity of the layer as the animation progress. 310 // opacity of the layer as the animation progress.
312 class ShelfView::FadeOutAnimationDelegate : public gfx::AnimationDelegate { 311 class ShelfView::FadeOutAnimationDelegate : public gfx::AnimationDelegate {
313 public: 312 public:
314 FadeOutAnimationDelegate(ShelfView* host, views::View* view) 313 FadeOutAnimationDelegate(ShelfView* host, views::View* view)
315 : shelf_view_(host), 314 : shelf_view_(host), view_(view) {}
316 view_(view) {}
317 ~FadeOutAnimationDelegate() override {} 315 ~FadeOutAnimationDelegate() override {}
318 316
319 // AnimationDelegate overrides: 317 // AnimationDelegate overrides:
320 void AnimationProgressed(const Animation* animation) override { 318 void AnimationProgressed(const Animation* animation) override {
321 view_->layer()->SetOpacity(1 - animation->GetCurrentValue()); 319 view_->layer()->SetOpacity(1 - animation->GetCurrentValue());
322 view_->layer()->ScheduleDraw(); 320 view_->layer()->ScheduleDraw();
323 } 321 }
324 void AnimationEnded(const Animation* animation) override { 322 void AnimationEnded(const Animation* animation) override {
325 shelf_view_->OnFadeOutAnimationEnded(); 323 shelf_view_->OnFadeOutAnimationEnded();
326 } 324 }
327 void AnimationCanceled(const Animation* animation) override {} 325 void AnimationCanceled(const Animation* animation) override {}
328 326
329 private: 327 private:
330 ShelfView* shelf_view_; 328 ShelfView* shelf_view_;
331 std::unique_ptr<views::View> view_; 329 std::unique_ptr<views::View> view_;
332 330
333 DISALLOW_COPY_AND_ASSIGN(FadeOutAnimationDelegate); 331 DISALLOW_COPY_AND_ASSIGN(FadeOutAnimationDelegate);
334 }; 332 };
335 333
336 // AnimationDelegate used to trigger fading an element in. When an item is 334 // AnimationDelegate used to trigger fading an element in. When an item is
337 // inserted this delegate is attached to the animation that expands the size of 335 // inserted this delegate is attached to the animation that expands the size of
338 // the item. When done it kicks off another animation to fade the item in. 336 // the item. When done it kicks off another animation to fade the item in.
339 class ShelfView::StartFadeAnimationDelegate : public gfx::AnimationDelegate { 337 class ShelfView::StartFadeAnimationDelegate : public gfx::AnimationDelegate {
340 public: 338 public:
341 StartFadeAnimationDelegate(ShelfView* host, 339 StartFadeAnimationDelegate(ShelfView* host, views::View* view)
342 views::View* view) 340 : shelf_view_(host), view_(view) {}
343 : shelf_view_(host),
344 view_(view) {}
345 ~StartFadeAnimationDelegate() override {} 341 ~StartFadeAnimationDelegate() override {}
346 342
347 // AnimationDelegate overrides: 343 // AnimationDelegate overrides:
348 void AnimationEnded(const Animation* animation) override { 344 void AnimationEnded(const Animation* animation) override {
349 shelf_view_->FadeIn(view_); 345 shelf_view_->FadeIn(view_);
350 } 346 }
351 void AnimationCanceled(const Animation* animation) override { 347 void AnimationCanceled(const Animation* animation) override {
352 view_->layer()->SetOpacity(1.0f); 348 view_->layer()->SetOpacity(1.0f);
353 } 349 }
354 350
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
469 if (index > last_visible_index_ && index < model_->FirstPanelIndex()) 465 if (index > last_visible_index_ && index < model_->FirstPanelIndex())
470 index = last_visible_index_ + 1; 466 index = last_visible_index_ + 1;
471 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); 467 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index));
472 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); 468 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type);
473 views::View* view = view_model_->view_at(index); 469 views::View* view = view_model_->view_at(index);
474 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 470 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
475 ShelfButton* button = static_cast<ShelfButton*>(view); 471 ShelfButton* button = static_cast<ShelfButton*>(view);
476 gfx::Rect icon_bounds = button->GetIconBounds(); 472 gfx::Rect icon_bounds = button->GetIconBounds();
477 return gfx::Rect(GetMirroredXWithWidthInView( 473 return gfx::Rect(GetMirroredXWithWidthInView(
478 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()), 474 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()),
479 ideal_bounds.y() + icon_bounds.y(), 475 ideal_bounds.y() + icon_bounds.y(), icon_bounds.width(),
480 icon_bounds.width(),
481 icon_bounds.height()); 476 icon_bounds.height());
482 } 477 }
483 478
484 void ShelfView::UpdatePanelIconPosition(ShelfID id, 479 void ShelfView::UpdatePanelIconPosition(ShelfID id,
485 const gfx::Point& midpoint) { 480 const gfx::Point& midpoint) {
486 int current_index = model_->ItemIndexByID(id); 481 int current_index = model_->ItemIndexByID(id);
487 int first_panel_index = model_->FirstPanelIndex(); 482 int first_panel_index = model_->FirstPanelIndex();
488 if (current_index < first_panel_index) 483 if (current_index < first_panel_index)
489 return; 484 return;
490 485
491 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), 486 gfx::Point midpoint_in_view(GetMirroredXInView(midpoint.x()), midpoint.y());
492 midpoint.y());
493 int target_index = current_index; 487 int target_index = current_index;
494 while (target_index > first_panel_index && 488 while (target_index > first_panel_index &&
495 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(), 489 shelf_->PrimaryAxisValue(view_model_->ideal_bounds(target_index).x(),
496 view_model_->ideal_bounds(target_index).y()) > 490 view_model_->ideal_bounds(target_index).y()) >
497 shelf_->PrimaryAxisValue(midpoint_in_view.x(), 491 shelf_->PrimaryAxisValue(midpoint_in_view.x(),
498 midpoint_in_view.y())) { 492 midpoint_in_view.y())) {
499 --target_index; 493 --target_index;
500 } 494 }
501 while (target_index < view_model_->view_size() - 1 && 495 while (target_index < view_model_->view_size() - 1 &&
502 shelf_->PrimaryAxisValue( 496 shelf_->PrimaryAxisValue(
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
588 drag_image_.reset(new DragImageView( 582 drag_image_.reset(new DragImageView(
589 drag_replaced_view_->GetWidget()->GetNativeWindow()->GetRootWindow(), 583 drag_replaced_view_->GetWidget()->GetNativeWindow()->GetRootWindow(),
590 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE)); 584 ui::DragDropTypes::DRAG_EVENT_SOURCE_MOUSE));
591 drag_image_->SetImage(icon); 585 drag_image_->SetImage(icon);
592 gfx::Size size = drag_image_->GetPreferredSize(); 586 gfx::Size size = drag_image_->GetPreferredSize();
593 size.set_width(size.width() * scale_factor); 587 size.set_width(size.width() * scale_factor);
594 size.set_height(size.height() * scale_factor); 588 size.set_height(size.height() * scale_factor);
595 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) + 589 drag_image_offset_ = gfx::Vector2d(size.width() / 2, size.height() / 2) +
596 cursor_offset_from_center; 590 cursor_offset_from_center;
597 gfx::Rect drag_image_bounds( 591 gfx::Rect drag_image_bounds(
598 location_in_screen_coordinates - drag_image_offset_, 592 location_in_screen_coordinates - drag_image_offset_, size);
599 size);
600 drag_image_->SetBoundsInScreen(drag_image_bounds); 593 drag_image_->SetBoundsInScreen(drag_image_bounds);
601 drag_image_->SetWidgetVisible(true); 594 drag_image_->SetWidgetVisible(true);
602 } 595 }
603 596
604 void ShelfView::UpdateDragIconProxy( 597 void ShelfView::UpdateDragIconProxy(
605 const gfx::Point& location_in_screen_coordinates) { 598 const gfx::Point& location_in_screen_coordinates) {
606 // TODO(jennyz): Investigate why drag_image_ becomes null at this point per 599 // TODO(jennyz): Investigate why drag_image_ becomes null at this point per
607 // crbug.com/34722, while the app list item is still being dragged around. 600 // crbug.com/34722, while the app list item is still being dragged around.
608 if (drag_image_) { 601 if (drag_image_) {
609 drag_image_->SetScreenPosition( 602 drag_image_->SetScreenPosition(location_in_screen_coordinates -
610 location_in_screen_coordinates - drag_image_offset_); 603 drag_image_offset_);
611 } 604 }
612 } 605 }
613 606
614 void ShelfView::DestroyDragIconProxy() { 607 void ShelfView::DestroyDragIconProxy() {
615 drag_image_.reset(); 608 drag_image_.reset();
616 drag_image_offset_ = gfx::Vector2d(0, 0); 609 drag_image_offset_ = gfx::Vector2d(0, 0);
617 } 610 }
618 611
619 bool ShelfView::StartDrag(const std::string& app_id, 612 bool ShelfView::StartDrag(const std::string& app_id,
620 const gfx::Point& location_in_screen_coordinates) { 613 const gfx::Point& location_in_screen_coordinates) {
621 // Bail if an operation is already going on - or the cursor is not inside. 614 // Bail if an operation is already going on - or the cursor is not inside.
622 // This could happen if mouse / touch operations overlap. 615 // This could happen if mouse / touch operations overlap.
623 if (drag_and_drop_shelf_id_ || 616 if (drag_and_drop_shelf_id_ ||
624 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 617 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
625 return false; 618 return false;
626 619
627 // If the AppsGridView (which was dispatching this event) was opened by our 620 // If the AppsGridView (which was dispatching this event) was opened by our
628 // button, ShelfView dragging operations are locked and we have to unlock. 621 // button, ShelfView dragging operations are locked and we have to unlock.
629 CancelDrag(-1); 622 CancelDrag(-1);
630 drag_and_drop_item_pinned_ = false; 623 drag_and_drop_item_pinned_ = false;
631 drag_and_drop_app_id_ = app_id; 624 drag_and_drop_app_id_ = app_id;
632 drag_and_drop_shelf_id_ = 625 drag_and_drop_shelf_id_ =
633 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_); 626 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_);
634 // Check if the application is known and pinned - if not, we have to pin it so 627 // Check if the application is known and pinned - if not, we have to pin it so
635 // that we can re-arrange the shelf order accordingly. Note that items have 628 // that we can re-arrange the shelf order accordingly. Note that items have
636 // to be pinned to give them the same (order) possibilities as a shortcut. 629 // to be pinned to give them the same (order) possibilities as a shortcut.
637 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble() 630 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble()
638 // returns true. At this time, we don't need to pin the item. 631 // returns true. At this time, we don't need to pin the item.
639 if (!IsShowingOverflowBubble() && 632 if (!IsShowingOverflowBubble() &&
640 (!drag_and_drop_shelf_id_ || 633 (!drag_and_drop_shelf_id_ || !delegate_->IsAppPinned(app_id))) {
641 !delegate_->IsAppPinned(app_id))) {
642 delegate_->PinAppWithID(app_id); 634 delegate_->PinAppWithID(app_id);
643 drag_and_drop_shelf_id_ = 635 drag_and_drop_shelf_id_ =
644 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_); 636 delegate_->GetShelfIDForAppID(drag_and_drop_app_id_);
645 if (!drag_and_drop_shelf_id_) 637 if (!drag_and_drop_shelf_id_)
646 return false; 638 return false;
647 drag_and_drop_item_pinned_ = true; 639 drag_and_drop_item_pinned_ = true;
648 } 640 }
649 views::View* drag_and_drop_view = view_model_->view_at( 641 views::View* drag_and_drop_view =
650 model_->ItemIndexByID(drag_and_drop_shelf_id_)); 642 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
651 DCHECK(drag_and_drop_view); 643 DCHECK(drag_and_drop_view);
652 644
653 // Since there is already an icon presented by the caller, we hide this item 645 // Since there is already an icon presented by the caller, we hide this item
654 // for now. That has to be done by reducing the size since the visibility will 646 // for now. That has to be done by reducing the size since the visibility will
655 // change once a regrouping animation is performed. 647 // change once a regrouping animation is performed.
656 pre_drag_and_drop_size_ = drag_and_drop_view->size(); 648 pre_drag_and_drop_size_ = drag_and_drop_view->size();
657 drag_and_drop_view->SetSize(gfx::Size()); 649 drag_and_drop_view->SetSize(gfx::Size());
658 650
659 // First we have to center the mouse cursor over the item. 651 // First we have to center the mouse cursor over the item.
660 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint(); 652 gfx::Point pt = drag_and_drop_view->GetBoundsInScreen().CenterPoint();
(...skipping 11 matching lines...) Expand all
672 Drag(location_in_screen_coordinates); 664 Drag(location_in_screen_coordinates);
673 return true; 665 return true;
674 } 666 }
675 667
676 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) { 668 bool ShelfView::Drag(const gfx::Point& location_in_screen_coordinates) {
677 if (!drag_and_drop_shelf_id_ || 669 if (!drag_and_drop_shelf_id_ ||
678 !GetBoundsInScreen().Contains(location_in_screen_coordinates)) 670 !GetBoundsInScreen().Contains(location_in_screen_coordinates))
679 return false; 671 return false;
680 672
681 gfx::Point pt = location_in_screen_coordinates; 673 gfx::Point pt = location_in_screen_coordinates;
682 views::View* drag_and_drop_view = view_model_->view_at( 674 views::View* drag_and_drop_view =
683 model_->ItemIndexByID(drag_and_drop_shelf_id_)); 675 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
684 ConvertPointFromScreen(drag_and_drop_view, &pt); 676 ConvertPointFromScreen(drag_and_drop_view, &pt);
685 gfx::Point point_in_root = location_in_screen_coordinates; 677 gfx::Point point_in_root = location_in_screen_coordinates;
686 ::wm::ConvertPointFromScreen( 678 ::wm::ConvertPointFromScreen(
687 WmWindowAura::GetAuraWindow( 679 WmWindowAura::GetAuraWindow(
688 ash::wm::GetRootWindowAt(location_in_screen_coordinates)), 680 ash::wm::GetRootWindowAt(location_in_screen_coordinates)),
689 &point_in_root); 681 &point_in_root);
690 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root, 682 ui::MouseEvent event(ui::ET_MOUSE_DRAGGED, pt, point_in_root,
691 ui::EventTimeForNow(), 0, 0); 683 ui::EventTimeForNow(), 0, 0);
692 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event); 684 PointerDraggedOnButton(drag_and_drop_view, DRAG_AND_DROP, event);
693 return true; 685 return true;
694 } 686 }
695 687
696 void ShelfView::EndDrag(bool cancel) { 688 void ShelfView::EndDrag(bool cancel) {
697 if (!drag_and_drop_shelf_id_) 689 if (!drag_and_drop_shelf_id_)
698 return; 690 return;
699 691
700 views::View* drag_and_drop_view = view_model_->view_at( 692 views::View* drag_and_drop_view =
701 model_->ItemIndexByID(drag_and_drop_shelf_id_)); 693 view_model_->view_at(model_->ItemIndexByID(drag_and_drop_shelf_id_));
702 PointerReleasedOnButton(drag_and_drop_view, DRAG_AND_DROP, cancel); 694 PointerReleasedOnButton(drag_and_drop_view, DRAG_AND_DROP, cancel);
703 695
704 // Either destroy the temporarily created item - or - make the item visible. 696 // Either destroy the temporarily created item - or - make the item visible.
705 if (drag_and_drop_item_pinned_ && cancel) { 697 if (drag_and_drop_item_pinned_ && cancel) {
706 delegate_->UnpinAppWithID(drag_and_drop_app_id_); 698 delegate_->UnpinAppWithID(drag_and_drop_app_id_);
707 } else if (drag_and_drop_view) { 699 } else if (drag_and_drop_view) {
708 if (cancel) { 700 if (cancel) {
709 // When a hosted drag gets canceled, the item can remain in the same slot 701 // When a hosted drag gets canceled, the item can remain in the same slot
710 // and it might have moved within the bounds. In that case the item need 702 // and it might have moved within the bounds. In that case the item need
711 // to animate back to its correct location. 703 // to animate back to its correct location.
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
814 CalculateIdealBounds(&ideal_bounds); 806 CalculateIdealBounds(&ideal_bounds);
815 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_); 807 views::ViewModelUtils::SetViewBoundsToIdealBounds(*view_model_);
816 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds); 808 overflow_button_->SetBoundsRect(ideal_bounds.overflow_bounds);
817 } 809 }
818 810
819 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() { 811 void ShelfView::UpdateAllButtonsVisibilityInOverflowMode() {
820 // The overflow button is not shown in overflow mode. 812 // The overflow button is not shown in overflow mode.
821 overflow_button_->SetVisible(false); 813 overflow_button_->SetVisible(false);
822 DCHECK_LT(last_visible_index_, view_model_->view_size()); 814 DCHECK_LT(last_visible_index_, view_model_->view_size());
823 for (int i = 0; i < view_model_->view_size(); ++i) { 815 for (int i = 0; i < view_model_->view_size(); ++i) {
824 bool visible = i >= first_visible_index_ && 816 bool visible = i >= first_visible_index_ && i <= last_visible_index_;
825 i <= last_visible_index_;
826 // To track the dragging of |drag_view_| continuously, its visibility 817 // To track the dragging of |drag_view_| continuously, its visibility
827 // should be always true regardless of its position. 818 // should be always true regardless of its position.
828 if (dragged_off_from_overflow_to_shelf_ && 819 if (dragged_off_from_overflow_to_shelf_ &&
829 view_model_->view_at(i) == drag_view_) 820 view_model_->view_at(i) == drag_view_)
830 view_model_->view_at(i)->SetVisible(true); 821 view_model_->view_at(i)->SetVisible(true);
831 else 822 else
832 view_model_->view_at(i)->SetVisible(visible); 823 view_model_->view_at(i)->SetVisible(visible);
833 } 824 }
834 } 825 }
835 826
(...skipping 26 matching lines...) Expand all
862 853
863 if (is_overflow_mode()) { 854 if (is_overflow_mode()) {
864 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode(); 855 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode();
865 return; 856 return;
866 } 857 }
867 858
868 // Right aligned icons. 859 // Right aligned icons.
869 int end_position = available_size - button_spacing; 860 int end_position = available_size - button_spacing;
870 x = shelf_->PrimaryAxisValue(end_position, 0); 861 x = shelf_->PrimaryAxisValue(end_position, 0);
871 y = shelf_->PrimaryAxisValue(0, end_position); 862 y = shelf_->PrimaryAxisValue(0, end_position);
872 for (int i = view_model_->view_size() - 1; 863 for (int i = view_model_->view_size() - 1; i >= first_panel_index; --i) {
873 i >= first_panel_index; --i) {
874 x = shelf_->PrimaryAxisValue(x - w - button_spacing, x); 864 x = shelf_->PrimaryAxisValue(x - w - button_spacing, x);
875 y = shelf_->PrimaryAxisValue(y, y - h - button_spacing); 865 y = shelf_->PrimaryAxisValue(y, y - h - button_spacing);
876 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 866 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
877 end_position = shelf_->PrimaryAxisValue(x, y); 867 end_position = shelf_->PrimaryAxisValue(x, y);
878 } 868 }
879 869
880 // Icons on the left / top are guaranteed up to kLeftIconProportion of 870 // Icons on the left / top are guaranteed up to kLeftIconProportion of
881 // the available space. 871 // the available space.
882 int last_icon_position = 872 int last_icon_position =
883 shelf_->PrimaryAxisValue( 873 shelf_->PrimaryAxisValue(
884 view_model_->ideal_bounds(last_button_index).right(), 874 view_model_->ideal_bounds(last_button_index).right(),
885 view_model_->ideal_bounds(last_button_index).bottom()) + 875 view_model_->ideal_bounds(last_button_index).bottom()) +
886 button_size; 876 button_size;
887 int reserved_icon_space = available_size * kReservedNonPanelIconProportion; 877 int reserved_icon_space = available_size * kReservedNonPanelIconProportion;
888 if (last_icon_position < reserved_icon_space) 878 if (last_icon_position < reserved_icon_space)
889 end_position = last_icon_position; 879 end_position = last_icon_position;
890 else 880 else
891 end_position = std::max(end_position, reserved_icon_space); 881 end_position = std::max(end_position, reserved_icon_space);
892 882
893 bounds->overflow_bounds.set_size( 883 bounds->overflow_bounds.set_size(
894 gfx::Size(shelf_->PrimaryAxisValue(w, width()), 884 gfx::Size(shelf_->PrimaryAxisValue(w, width()),
895 shelf_->PrimaryAxisValue(height(), h))); 885 shelf_->PrimaryAxisValue(height(), h)));
896 886
897 last_visible_index_ = DetermineLastVisibleIndex( 887 last_visible_index_ = DetermineLastVisibleIndex(end_position - button_size);
898 end_position - button_size);
899 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1; 888 last_hidden_index_ = DetermineFirstVisiblePanelIndex(end_position) - 1;
900 bool show_overflow = last_visible_index_ < last_button_index || 889 bool show_overflow = last_visible_index_ < last_button_index ||
901 last_hidden_index_ >= first_panel_index; 890 last_hidden_index_ >= first_panel_index;
902 891
903 // Create Space for the overflow button 892 // Create Space for the overflow button
904 if (show_overflow) { 893 if (show_overflow) {
905 // The following code makes sure that platform apps icons (aligned to left / 894 // The following code makes sure that platform apps icons (aligned to left /
906 // top) are favored over panel apps icons (aligned to right / bottom). 895 // top) are favored over panel apps icons (aligned to right / bottom).
907 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) { 896 if (last_visible_index_ > 0 && last_visible_index_ < last_button_index) {
908 // This condition means that we will take one platform app and replace it 897 // This condition means that we will take one platform app and replace it
909 // with the overflow button and put the app in the overflow bubble. 898 // with the overflow button and put the app in the overflow bubble.
910 // This happens when the space needed for platform apps exceeds the 899 // This happens when the space needed for platform apps exceeds the
911 // reserved area for non-panel icons, 900 // reserved area for non-panel icons,
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
1049 view, std::unique_ptr<gfx::AnimationDelegate>( 1038 view, std::unique_ptr<gfx::AnimationDelegate>(
1050 new FadeInAnimationDelegate(view))); 1039 new FadeInAnimationDelegate(view)));
1051 } 1040 }
1052 1041
1053 void ShelfView::PrepareForDrag(Pointer pointer, const ui::LocatedEvent& event) { 1042 void ShelfView::PrepareForDrag(Pointer pointer, const ui::LocatedEvent& event) {
1054 DCHECK(!dragging()); 1043 DCHECK(!dragging());
1055 DCHECK(drag_view_); 1044 DCHECK(drag_view_);
1056 drag_pointer_ = pointer; 1045 drag_pointer_ = pointer;
1057 start_drag_index_ = view_model_->GetIndexOfView(drag_view_); 1046 start_drag_index_ = view_model_->GetIndexOfView(drag_view_);
1058 1047
1059 if (start_drag_index_== -1) { 1048 if (start_drag_index_ == -1) {
1060 CancelDrag(-1); 1049 CancelDrag(-1);
1061 return; 1050 return;
1062 } 1051 }
1063 1052
1064 // If the item is no longer draggable, bail out. 1053 // If the item is no longer draggable, bail out.
1065 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( 1054 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate(
1066 model_->items()[start_drag_index_].id); 1055 model_->items()[start_drag_index_].id);
1067 if (!item_delegate->IsDraggable()) { 1056 if (!item_delegate->IsDraggable()) {
1068 CancelDrag(-1); 1057 CancelDrag(-1);
1069 return; 1058 return;
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 int first_drag_index = indices.first; 1097 int first_drag_index = indices.first;
1109 int last_drag_index = indices.second; 1098 int last_drag_index = indices.second;
1110 // If the last index isn't valid, we're overflowing. Constrain to the app list 1099 // If the last index isn't valid, we're overflowing. Constrain to the app list
1111 // (which is the last visible item). 1100 // (which is the last visible item).
1112 if (first_drag_index < model_->FirstPanelIndex() && 1101 if (first_drag_index < model_->FirstPanelIndex() &&
1113 last_drag_index > last_visible_index_) 1102 last_drag_index > last_visible_index_)
1114 last_drag_index = last_visible_index_; 1103 last_drag_index = last_visible_index_;
1115 int x = 0, y = 0; 1104 int x = 0, y = 0;
1116 if (shelf_->IsHorizontalAlignment()) { 1105 if (shelf_->IsHorizontalAlignment()) {
1117 x = std::max(view_model_->ideal_bounds(indices.first).x(), 1106 x = std::max(view_model_->ideal_bounds(indices.first).x(),
1118 drag_point.x() - drag_origin_.x()); 1107 drag_point.x() - drag_origin_.x());
1119 x = std::min(view_model_->ideal_bounds(last_drag_index).right() - 1108 x = std::min(view_model_->ideal_bounds(last_drag_index).right() -
1120 view_model_->ideal_bounds(current_index).width(), 1109 view_model_->ideal_bounds(current_index).width(),
1121 x); 1110 x);
1122 if (drag_view_->x() == x) 1111 if (drag_view_->x() == x)
1123 return; 1112 return;
1124 drag_view_->SetX(x); 1113 drag_view_->SetX(x);
1125 } else { 1114 } else {
1126 y = std::max(view_model_->ideal_bounds(indices.first).y(), 1115 y = std::max(view_model_->ideal_bounds(indices.first).y(),
1127 drag_point.y() - drag_origin_.y()); 1116 drag_point.y() - drag_origin_.y());
1128 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() - 1117 y = std::min(view_model_->ideal_bounds(last_drag_index).bottom() -
1129 view_model_->ideal_bounds(current_index).height(), 1118 view_model_->ideal_bounds(current_index).height(),
1130 y); 1119 y);
1131 if (drag_view_->y() == y) 1120 if (drag_view_->y() == y)
1132 return; 1121 return;
1133 drag_view_->SetY(y); 1122 drag_view_->SetY(y);
1134 } 1123 }
1135 1124
1136 int target_index = views::ViewModelUtils::DetermineMoveIndex( 1125 int target_index = views::ViewModelUtils::DetermineMoveIndex(
1137 *view_model_, drag_view_, 1126 *view_model_, drag_view_,
1138 shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL 1127 shelf_->IsHorizontalAlignment() ? views::ViewModelUtils::HORIZONTAL
1139 : views::ViewModelUtils::VERTICAL, 1128 : views::ViewModelUtils::VERTICAL,
1140 x, y); 1129 x, y);
1141 target_index = 1130 target_index =
1142 std::min(indices.second, std::max(target_index, indices.first)); 1131 std::min(indices.second, std::max(target_index, indices.first));
1143 1132
1144 int first_draggable_item = 0; 1133 int first_draggable_item = 0;
1145 while (first_draggable_item < static_cast<int>(model_->items().size()) && 1134 while (first_draggable_item < static_cast<int>(model_->items().size()) &&
1146 !item_manager_->GetShelfItemDelegate( 1135 !item_manager_
1147 model_->items()[first_draggable_item].id) 1136 ->GetShelfItemDelegate(model_->items()[first_draggable_item].id)
1148 ->IsDraggable()) { 1137 ->IsDraggable()) {
1149 first_draggable_item++; 1138 first_draggable_item++;
1150 } 1139 }
1151 1140
1152 target_index = std::max(target_index, first_draggable_item); 1141 target_index = std::max(target_index, first_draggable_item);
1153 1142
1154 if (target_index == current_index) 1143 if (target_index == current_index)
1155 return; 1144 return;
1156 1145
1157 // Change the model, the ShelfItemMoved() callback will handle the 1146 // Change the model, the ShelfItemMoved() callback will handle the
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1220 } 1209 }
1221 // Move our proxy view item. 1210 // Move our proxy view item.
1222 UpdateDragIconProxy(screen_location); 1211 UpdateDragIconProxy(screen_location);
1223 return true; 1212 return true;
1224 } 1213 }
1225 // Check if we are too far away from the shelf to enter the ripped off state. 1214 // Check if we are too far away from the shelf to enter the ripped off state.
1226 // Determine the distance to the shelf. 1215 // Determine the distance to the shelf.
1227 int delta = CalculateShelfDistance(screen_location); 1216 int delta = CalculateShelfDistance(screen_location);
1228 if (delta > kRipOffDistance) { 1217 if (delta > kRipOffDistance) {
1229 // Create a proxy view item which can be moved anywhere. 1218 // Create a proxy view item which can be moved anywhere.
1230 CreateDragIconProxy(event.root_location(), 1219 CreateDragIconProxy(event.root_location(), drag_view_->GetImage(),
1231 drag_view_->GetImage(), 1220 drag_view_, gfx::Vector2d(0, 0),
1232 drag_view_,
1233 gfx::Vector2d(0, 0),
1234 kDragAndDropProxyScale); 1221 kDragAndDropProxyScale);
1235 drag_view_->layer()->SetOpacity(0.0f); 1222 drag_view_->layer()->SetOpacity(0.0f);
1236 dragged_off_shelf_ = true; 1223 dragged_off_shelf_ = true;
1237 if (RemovableByRipOff(current_index) == REMOVABLE) { 1224 if (RemovableByRipOff(current_index) == REMOVABLE) {
1238 // Move the item to the front of the first panel item and hide it. 1225 // Move the item to the front of the first panel item and hide it.
1239 // ShelfItemMoved() callback will handle the |view_model_| update and 1226 // ShelfItemMoved() callback will handle the |view_model_| update and
1240 // call AnimateToIdealBounds(). 1227 // call AnimateToIdealBounds().
1241 if (current_index != model_->FirstPanelIndex() - 1) { 1228 if (current_index != model_->FirstPanelIndex() - 1) {
1242 model_->Move(current_index, model_->FirstPanelIndex() - 1); 1229 model_->Move(current_index, model_->FirstPanelIndex() - 1);
1243 StartFadeInLastVisibleItem(); 1230 StartFadeInLastVisibleItem();
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1296 if (dragged_off_from_overflow_to_shelf_) { 1283 if (dragged_off_from_overflow_to_shelf_) {
1297 dragged_off_from_overflow_to_shelf_ = false; 1284 dragged_off_from_overflow_to_shelf_ = false;
1298 // Main shelf handles revert of dragged item. 1285 // Main shelf handles revert of dragged item.
1299 main_shelf_->EndDrag(true); 1286 main_shelf_->EndDrag(true);
1300 drag_view_->layer()->SetOpacity(1.0f); 1287 drag_view_->layer()->SetOpacity(1.0f);
1301 } else if (!cancelling_drag_model_changed_) { 1288 } else if (!cancelling_drag_model_changed_) {
1302 // Only do something if the change did not come through a model change. 1289 // Only do something if the change did not come through a model change.
1303 gfx::Rect drag_bounds = drag_image_->GetBoundsInScreen(); 1290 gfx::Rect drag_bounds = drag_image_->GetBoundsInScreen();
1304 gfx::Point relative_to = GetBoundsInScreen().origin(); 1291 gfx::Point relative_to = GetBoundsInScreen().origin();
1305 gfx::Rect target( 1292 gfx::Rect target(
1306 gfx::PointAtOffsetFromOrigin(drag_bounds.origin()- relative_to), 1293 gfx::PointAtOffsetFromOrigin(drag_bounds.origin() - relative_to),
1307 drag_bounds.size()); 1294 drag_bounds.size());
1308 drag_view_->SetBoundsRect(target); 1295 drag_view_->SetBoundsRect(target);
1309 // Hide the status from the active item since we snap it back now. Upon 1296 // Hide the status from the active item since we snap it back now. Upon
1310 // animation end the flag gets cleared if |snap_back_from_rip_off_view_| 1297 // animation end the flag gets cleared if |snap_back_from_rip_off_view_|
1311 // is set. 1298 // is set.
1312 snap_back_from_rip_off_view_ = drag_view_; 1299 snap_back_from_rip_off_view_ = drag_view_;
1313 drag_view_->AddState(ShelfButton::STATE_HIDDEN); 1300 drag_view_->AddState(ShelfButton::STATE_HIDDEN);
1314 // When a canceling drag model is happening, the view model is diverged 1301 // When a canceling drag model is happening, the view model is diverged
1315 // from the menu model and movements / animations should not be done. 1302 // from the menu model and movements / animations should not be done.
1316 model_->Move(current_index, start_drag_index_); 1303 model_->Move(current_index, start_drag_index_);
1317 AnimateToIdealBounds(); 1304 AnimateToIdealBounds();
1318 } 1305 }
1319 drag_view_->layer()->SetOpacity(1.0f); 1306 drag_view_->layer()->SetOpacity(1.0f);
1320 } 1307 }
1321 DestroyDragIconProxy(); 1308 DestroyDragIconProxy();
1322 } 1309 }
1323 1310
1324 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) const { 1311 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) const {
1325 DCHECK(index >= 0 && index < model_->item_count()); 1312 DCHECK(index >= 0 && index < model_->item_count());
1326 ShelfItemType type = model_->items()[index].type; 1313 ShelfItemType type = model_->items()[index].type;
1327 if (type == TYPE_APP_LIST || type == TYPE_DIALOG) 1314 if (type == TYPE_APP_LIST || type == TYPE_DIALOG)
1328 return NOT_REMOVABLE; 1315 return NOT_REMOVABLE;
1329 1316
1330 std::string app_id = delegate_->GetAppIDForShelfID(model_->items()[index].id); 1317 std::string app_id = delegate_->GetAppIDForShelfID(model_->items()[index].id);
1331 ShelfItemDelegate* item_delegate = 1318 ShelfItemDelegate* item_delegate =
1332 item_manager_->GetShelfItemDelegate(model_->items()[index].id); 1319 item_manager_->GetShelfItemDelegate(model_->items()[index].id);
1333 if (!item_delegate->CanPin()) 1320 if (!item_delegate->CanPin())
1334 return NOT_REMOVABLE; 1321 return NOT_REMOVABLE;
1335 // Note: Only pinned app shortcuts can be removed! 1322 // Note: Only pinned app shortcuts can be removed!
1336 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id)) ? 1323 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id))
1337 REMOVABLE : DRAGGABLE; 1324 ? REMOVABLE
1325 : DRAGGABLE;
1338 } 1326 }
1339 1327
1340 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const { 1328 bool ShelfView::SameDragType(ShelfItemType typea, ShelfItemType typeb) const {
1341 switch (typea) { 1329 switch (typea) {
1342 case TYPE_APP_SHORTCUT: 1330 case TYPE_APP_SHORTCUT:
1343 case TYPE_BROWSER_SHORTCUT: 1331 case TYPE_BROWSER_SHORTCUT:
1344 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT); 1332 return (typeb == TYPE_APP_SHORTCUT || typeb == TYPE_BROWSER_SHORTCUT);
1345 case TYPE_APP_LIST: 1333 case TYPE_APP_LIST:
1346 case TYPE_PLATFORM_APP: 1334 case TYPE_PLATFORM_APP:
1347 case TYPE_WINDOWED_APP: 1335 case TYPE_WINDOWED_APP:
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
1494 if (at_end) 1482 if (at_end)
1495 return view_model_->view_size(); 1483 return view_model_->view_size();
1496 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; 1484 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1;
1497 } 1485 }
1498 1486
1499 gfx::Size ShelfView::GetPreferredSize() const { 1487 gfx::Size ShelfView::GetPreferredSize() const {
1500 IdealBounds ideal_bounds; 1488 IdealBounds ideal_bounds;
1501 CalculateIdealBounds(&ideal_bounds); 1489 CalculateIdealBounds(&ideal_bounds);
1502 const int shelf_size = GetShelfConstant(SHELF_SIZE); 1490 const int shelf_size = GetShelfConstant(SHELF_SIZE);
1503 1491
1504 int last_button_index = is_overflow_mode() ? 1492 int last_button_index =
1505 last_visible_index_ : view_model_->view_size() - 1; 1493 is_overflow_mode() ? last_visible_index_ : view_model_->view_size() - 1;
1506 1494
1507 // When an item is dragged off from the overflow bubble, it is moved to last 1495 // When an item is dragged off from the overflow bubble, it is moved to last
1508 // position and and changed to invisible. Overflow bubble size should be 1496 // position and and changed to invisible. Overflow bubble size should be
1509 // shrunk to fit only for visible items. 1497 // shrunk to fit only for visible items.
1510 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible 1498 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible
1511 // items in the shelf. 1499 // items in the shelf.
1512 if (is_overflow_mode() && 1500 if (is_overflow_mode() && dragged_off_shelf_ &&
1513 dragged_off_shelf_ &&
1514 !dragged_off_from_overflow_to_shelf_ && 1501 !dragged_off_from_overflow_to_shelf_ &&
1515 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) 1502 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
1516 last_button_index--; 1503 last_button_index--;
1517 1504
1518 const gfx::Rect last_button_bounds = 1505 const gfx::Rect last_button_bounds =
1519 last_button_index >= first_visible_index_ 1506 last_button_index >= first_visible_index_
1520 ? view_model_->ideal_bounds(last_button_index) 1507 ? view_model_->ideal_bounds(last_button_index)
1521 : gfx::Rect(gfx::Size(shelf_size, shelf_size)); 1508 : gfx::Rect(gfx::Size(shelf_size, shelf_size));
1522 1509
1523 if (shelf_->IsHorizontalAlignment()) 1510 if (shelf_->IsHorizontalAlignment())
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1559 void ShelfView::OnGestureEvent(ui::GestureEvent* event) { 1546 void ShelfView::OnGestureEvent(ui::GestureEvent* event) {
1560 aura::Window* target_window = static_cast<views::View*>(event->target()) 1547 aura::Window* target_window = static_cast<views::View*>(event->target())
1561 ->GetWidget() 1548 ->GetWidget()
1562 ->GetNativeWindow(); 1549 ->GetNativeWindow();
1563 if (gesture_handler_.ProcessGestureEvent(*event, target_window)) 1550 if (gesture_handler_.ProcessGestureEvent(*event, target_window))
1564 event->StopPropagation(); 1551 event->StopPropagation();
1565 } 1552 }
1566 1553
1567 void ShelfView::ShelfItemAdded(int model_index) { 1554 void ShelfView::ShelfItemAdded(int model_index) {
1568 { 1555 {
1569 base::AutoReset<bool> cancelling_drag( 1556 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_,
1570 &cancelling_drag_model_changed_, true); 1557 true);
1571 model_index = CancelDrag(model_index); 1558 model_index = CancelDrag(model_index);
1572 } 1559 }
1573 views::View* view = CreateViewForItem(model_->items()[model_index]); 1560 views::View* view = CreateViewForItem(model_->items()[model_index]);
1574 AddChildView(view); 1561 AddChildView(view);
1575 // Hide the view, it'll be made visible when the animation is done. Using 1562 // Hide the view, it'll be made visible when the animation is done. Using
1576 // opacity 0 here to avoid messing with CalculateIdealBounds which touches 1563 // opacity 0 here to avoid messing with CalculateIdealBounds which touches
1577 // the view's visibility. 1564 // the view's visibility.
1578 view->layer()->SetOpacity(0); 1565 view->layer()->SetOpacity(0);
1579 view_model_->Add(view, model_index); 1566 view_model_->Add(view, model_index);
1580 1567
(...skipping 17 matching lines...) Expand all
1598 } else { 1585 } else {
1599 // Undo the hiding if animation does not run. 1586 // Undo the hiding if animation does not run.
1600 view->layer()->SetOpacity(1.0f); 1587 view->layer()->SetOpacity(1.0f);
1601 } 1588 }
1602 } 1589 }
1603 1590
1604 void ShelfView::ShelfItemRemoved(int model_index, ShelfID id) { 1591 void ShelfView::ShelfItemRemoved(int model_index, ShelfID id) {
1605 if (id == context_menu_id_) 1592 if (id == context_menu_id_)
1606 launcher_menu_runner_.reset(); 1593 launcher_menu_runner_.reset();
1607 { 1594 {
1608 base::AutoReset<bool> cancelling_drag( 1595 base::AutoReset<bool> cancelling_drag(&cancelling_drag_model_changed_,
1609 &cancelling_drag_model_changed_, true); 1596 true);
1610 model_index = CancelDrag(model_index); 1597 model_index = CancelDrag(model_index);
1611 } 1598 }
1612 views::View* view = view_model_->view_at(model_index); 1599 views::View* view = view_model_->view_at(model_index);
1613 view_model_->Remove(model_index); 1600 view_model_->Remove(model_index);
1614 1601
1615 // When the overflow bubble is visible, the overflow range needs to be set 1602 // When the overflow bubble is visible, the overflow range needs to be set
1616 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds() 1603 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds()
1617 // could trigger a ShelfItemChanged() by hiding the overflow bubble and 1604 // could trigger a ShelfItemChanged() by hiding the overflow bubble and
1618 // since the overflow bubble is not yet synced with the ShelfModel this 1605 // since the overflow bubble is not yet synced with the ShelfModel this
1619 // could cause a crash. 1606 // could cause a crash.
1620 if (overflow_bubble_ && overflow_bubble_->IsShowing()) { 1607 if (overflow_bubble_ && overflow_bubble_->IsShowing()) {
1621 last_hidden_index_ = std::min(last_hidden_index_, 1608 last_hidden_index_ =
1622 view_model_->view_size() - 1); 1609 std::min(last_hidden_index_, view_model_->view_size() - 1);
1623 UpdateOverflowRange(overflow_bubble_->shelf_view()); 1610 UpdateOverflowRange(overflow_bubble_->shelf_view());
1624 } 1611 }
1625 1612
1626 if (view->visible()) { 1613 if (view->visible()) {
1627 // The first animation fades out the view. When done we'll animate the rest 1614 // The first animation fades out the view. When done we'll animate the rest
1628 // of the views to their target location. 1615 // of the views to their target location.
1629 bounds_animator_->AnimateViewTo(view, view->bounds()); 1616 bounds_animator_->AnimateViewTo(view, view->bounds());
1630 bounds_animator_->SetAnimationDelegate( 1617 bounds_animator_->SetAnimationDelegate(
1631 view, std::unique_ptr<gfx::AnimationDelegate>( 1618 view, std::unique_ptr<gfx::AnimationDelegate>(
1632 new FadeOutAnimationDelegate(this, view))); 1619 new FadeOutAnimationDelegate(this, view)));
(...skipping 25 matching lines...) Expand all
1658 view_model_->set_ideal_bounds(model_index, old_ideal_bounds); 1645 view_model_->set_ideal_bounds(model_index, old_ideal_bounds);
1659 new_view->SetBoundsRect(old_view->bounds()); 1646 new_view->SetBoundsRect(old_view->bounds());
1660 if (overflow_button_ && overflow_button_->visible()) 1647 if (overflow_button_ && overflow_button_->visible())
1661 AnimateToIdealBounds(); 1648 AnimateToIdealBounds();
1662 return; 1649 return;
1663 } 1650 }
1664 1651
1665 views::View* view = view_model_->view_at(model_index); 1652 views::View* view = view_model_->view_at(model_index);
1666 switch (item.type) { 1653 switch (item.type) {
1667 case TYPE_BROWSER_SHORTCUT: 1654 case TYPE_BROWSER_SHORTCUT:
1668 // Fallthrough for the new Shelf since it needs to show the activation 1655 // Fallthrough for the new Shelf since it needs to show the activation
1669 // change as well. 1656 // change as well.
1670 case TYPE_APP_SHORTCUT: 1657 case TYPE_APP_SHORTCUT:
1671 case TYPE_WINDOWED_APP: 1658 case TYPE_WINDOWED_APP:
1672 case TYPE_PLATFORM_APP: 1659 case TYPE_PLATFORM_APP:
1673 case TYPE_DIALOG: 1660 case TYPE_DIALOG:
1674 case TYPE_APP_PANEL: 1661 case TYPE_APP_PANEL:
1675 case TYPE_IME_MENU: { 1662 case TYPE_IME_MENU: {
1676 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); 1663 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName());
1677 ShelfButton* button = static_cast<ShelfButton*>(view); 1664 ShelfButton* button = static_cast<ShelfButton*>(view);
1678 ReflectItemStatus(item, button); 1665 ReflectItemStatus(item, button);
1679 button->SetImage(item.image); 1666 button->SetImage(item.image);
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
1724 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode( 1711 slowing_animations.reset(new ui::ScopedAnimationDurationScaleMode(
1725 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION)); 1712 ui::ScopedAnimationDurationScaleMode::SLOW_DURATION));
1726 } 1713 }
1727 1714
1728 // Collect usage statistics before we decide what to do with the click. 1715 // Collect usage statistics before we decide what to do with the click.
1729 switch (model_->items()[last_pressed_index_].type) { 1716 switch (model_->items()[last_pressed_index_].type) {
1730 case TYPE_APP_SHORTCUT: 1717 case TYPE_APP_SHORTCUT:
1731 case TYPE_WINDOWED_APP: 1718 case TYPE_WINDOWED_APP:
1732 case TYPE_PLATFORM_APP: 1719 case TYPE_PLATFORM_APP:
1733 case TYPE_BROWSER_SHORTCUT: 1720 case TYPE_BROWSER_SHORTCUT:
1734 WmShell::Get()->RecordUserMetricsAction( 1721 WmShell::Get()->RecordUserMetricsAction(UMA_LAUNCHER_CLICK_ON_APP);
1735 UMA_LAUNCHER_CLICK_ON_APP);
1736 break; 1722 break;
1737 1723
1738 case TYPE_APP_LIST: 1724 case TYPE_APP_LIST:
1739 WmShell::Get()->RecordUserMetricsAction( 1725 WmShell::Get()->RecordUserMetricsAction(
1740 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON); 1726 UMA_LAUNCHER_CLICK_ON_APPLIST_BUTTON);
1741 break; 1727 break;
1742 1728
1743 case TYPE_APP_PANEL: 1729 case TYPE_APP_PANEL:
1744 case TYPE_DIALOG: 1730 case TYPE_DIALOG:
1745 case TYPE_IME_MENU: 1731 case TYPE_IME_MENU:
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 1902
1917 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1903 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1918 const gfx::Rect bounds = GetBoundsInScreen(); 1904 const gfx::Rect bounds = GetBoundsInScreen();
1919 int distance = shelf_->SelectValueForShelfAlignment( 1905 int distance = shelf_->SelectValueForShelfAlignment(
1920 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1906 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1921 bounds.x() - coordinate.x()); 1907 bounds.x() - coordinate.x());
1922 return distance > 0 ? distance : 0; 1908 return distance > 0 ? distance : 0;
1923 } 1909 }
1924 1910
1925 } // namespace ash 1911 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shelf/shelf_view_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698