| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "ash/shelf/shelf_view.h" | 5 #include "ash/shelf/shelf_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "ash/ash_constants.h" | 9 #include "ash/ash_constants.h" |
| 10 #include "ash/ash_switches.h" | 10 #include "ash/ash_switches.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 // Size allocated to for each button. | 80 // Size allocated to for each button. |
| 81 const int kButtonSize = 44; | 81 const int kButtonSize = 44; |
| 82 | 82 |
| 83 // Additional spacing for the left and right side of icons. | 83 // Additional spacing for the left and right side of icons. |
| 84 const int kHorizontalIconSpacing = 2; | 84 const int kHorizontalIconSpacing = 2; |
| 85 | 85 |
| 86 // Inset for items which do not have an icon. | 86 // Inset for items which do not have an icon. |
| 87 const int kHorizontalNoIconInsetSpacing = | 87 const int kHorizontalNoIconInsetSpacing = |
| 88 kHorizontalIconSpacing + kDefaultLeadingInset; | 88 kHorizontalIconSpacing + kDefaultLeadingInset; |
| 89 | 89 |
| 90 // The proportion of the launcher space reserved for non-panel icons. Panels | 90 // The proportion of the shelf space reserved for non-panel icons. Panels |
| 91 // may flow into this space but will be put into the overflow bubble if there | 91 // may flow into this space but will be put into the overflow bubble if there |
| 92 // is contention for the space. | 92 // is contention for the space. |
| 93 const float kReservedNonPanelIconProportion = 0.67f; | 93 const float kReservedNonPanelIconProportion = 0.67f; |
| 94 | 94 |
| 95 // This is the command id of the menu item which contains the name of the menu. | 95 // This is the command id of the menu item which contains the name of the menu. |
| 96 const int kCommandIdOfMenuName = 0; | 96 const int kCommandIdOfMenuName = 0; |
| 97 | 97 |
| 98 // The background color of the active item in the list. | 98 // The background color of the active item in the list. |
| 99 const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203 , 219, 241); | 99 const SkColor kActiveListItemBackgroundColor = SkColorSetRGB(203 , 219, 241); |
| 100 | 100 |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 } | 196 } |
| 197 | 197 |
| 198 int ShelfMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) { | 198 int ShelfMenuModelAdapter::GetMaxWidthForMenu(views::MenuItemView* menu) { |
| 199 return kMaximumAppMenuItemLength; | 199 return kMaximumAppMenuItemLength; |
| 200 } | 200 } |
| 201 | 201 |
| 202 bool ShelfMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const { | 202 bool ShelfMenuModelAdapter::ShouldReserveSpaceForSubmenuIndicator() const { |
| 203 return false; | 203 return false; |
| 204 } | 204 } |
| 205 | 205 |
| 206 // Custom FocusSearch used to navigate the launcher in the order items are in | 206 // Custom FocusSearch used to navigate the shelf in the order items are in |
| 207 // the ViewModel. | 207 // the ViewModel. |
| 208 class LauncherFocusSearch : public views::FocusSearch { | 208 class ShelfFocusSearch : public views::FocusSearch { |
| 209 public: | 209 public: |
| 210 explicit LauncherFocusSearch(views::ViewModel* view_model) | 210 explicit ShelfFocusSearch(views::ViewModel* view_model) |
| 211 : FocusSearch(NULL, true, true), | 211 : FocusSearch(NULL, true, true), |
| 212 view_model_(view_model) {} | 212 view_model_(view_model) {} |
| 213 virtual ~LauncherFocusSearch() {} | 213 virtual ~ShelfFocusSearch() {} |
| 214 | 214 |
| 215 // views::FocusSearch overrides: | 215 // views::FocusSearch overrides: |
| 216 virtual View* FindNextFocusableView( | 216 virtual View* FindNextFocusableView( |
| 217 View* starting_view, | 217 View* starting_view, |
| 218 bool reverse, | 218 bool reverse, |
| 219 Direction direction, | 219 Direction direction, |
| 220 bool check_starting_view, | 220 bool check_starting_view, |
| 221 views::FocusTraversable** focus_traversable, | 221 views::FocusTraversable** focus_traversable, |
| 222 View** focus_traversable_view) OVERRIDE { | 222 View** focus_traversable_view) OVERRIDE { |
| 223 int index = view_model_->GetIndexOfView(starting_view); | 223 int index = view_model_->GetIndexOfView(starting_view); |
| 224 if (index == -1) | 224 if (index == -1) |
| 225 return view_model_->view_at(0); | 225 return view_model_->view_at(0); |
| 226 | 226 |
| 227 if (reverse) { | 227 if (reverse) { |
| 228 --index; | 228 --index; |
| 229 if (index < 0) | 229 if (index < 0) |
| 230 index = view_model_->view_size() - 1; | 230 index = view_model_->view_size() - 1; |
| 231 } else { | 231 } else { |
| 232 ++index; | 232 ++index; |
| 233 if (index >= view_model_->view_size()) | 233 if (index >= view_model_->view_size()) |
| 234 index = 0; | 234 index = 0; |
| 235 } | 235 } |
| 236 return view_model_->view_at(index); | 236 return view_model_->view_at(index); |
| 237 } | 237 } |
| 238 | 238 |
| 239 private: | 239 private: |
| 240 views::ViewModel* view_model_; | 240 views::ViewModel* view_model_; |
| 241 | 241 |
| 242 DISALLOW_COPY_AND_ASSIGN(LauncherFocusSearch); | 242 DISALLOW_COPY_AND_ASSIGN(ShelfFocusSearch); |
| 243 }; | 243 }; |
| 244 | 244 |
| 245 // AnimationDelegate used when inserting a new item. This steadily increases the | 245 // AnimationDelegate used when inserting a new item. This steadily increases the |
| 246 // opacity of the layer as the animation progress. | 246 // opacity of the layer as the animation progress. |
| 247 class FadeInAnimationDelegate | 247 class FadeInAnimationDelegate |
| 248 : public views::BoundsAnimator::OwnedAnimationDelegate { | 248 : public views::BoundsAnimator::OwnedAnimationDelegate { |
| 249 public: | 249 public: |
| 250 explicit FadeInAnimationDelegate(views::View* view) : view_(view) {} | 250 explicit FadeInAnimationDelegate(views::View* view) : view_(view) {} |
| 251 virtual ~FadeInAnimationDelegate() {} | 251 virtual ~FadeInAnimationDelegate() {} |
| 252 | 252 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 378 snap_back_from_rip_off_view_(NULL), | 378 snap_back_from_rip_off_view_(NULL), |
| 379 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), | 379 item_manager_(Shell::GetInstance()->shelf_item_delegate_manager()), |
| 380 layout_manager_(manager), | 380 layout_manager_(manager), |
| 381 overflow_mode_(false), | 381 overflow_mode_(false), |
| 382 main_shelf_(NULL), | 382 main_shelf_(NULL), |
| 383 dragged_off_from_overflow_to_shelf_(false) { | 383 dragged_off_from_overflow_to_shelf_(false) { |
| 384 DCHECK(model_); | 384 DCHECK(model_); |
| 385 bounds_animator_.reset(new views::BoundsAnimator(this)); | 385 bounds_animator_.reset(new views::BoundsAnimator(this)); |
| 386 bounds_animator_->AddObserver(this); | 386 bounds_animator_->AddObserver(this); |
| 387 set_context_menu_controller(this); | 387 set_context_menu_controller(this); |
| 388 focus_search_.reset(new LauncherFocusSearch(view_model_.get())); | 388 focus_search_.reset(new ShelfFocusSearch(view_model_.get())); |
| 389 tooltip_.reset(new ShelfTooltipManager(manager, this)); | 389 tooltip_.reset(new ShelfTooltipManager(manager, this)); |
| 390 } | 390 } |
| 391 | 391 |
| 392 ShelfView::~ShelfView() { | 392 ShelfView::~ShelfView() { |
| 393 bounds_animator_->RemoveObserver(this); | 393 bounds_animator_->RemoveObserver(this); |
| 394 model_->RemoveObserver(this); | 394 model_->RemoveObserver(this); |
| 395 // If we are inside the MenuRunner, we need to know if we were getting | 395 // If we are inside the MenuRunner, we need to know if we were getting |
| 396 // deleted while it was running. | 396 // deleted while it was running. |
| 397 if (got_deleted_) | 397 if (got_deleted_) |
| 398 *got_deleted_ = true; | 398 *got_deleted_ = true; |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 578 return false; | 578 return false; |
| 579 | 579 |
| 580 // If the AppsGridView (which was dispatching this event) was opened by our | 580 // If the AppsGridView (which was dispatching this event) was opened by our |
| 581 // button, ShelfView dragging operations are locked and we have to unlock. | 581 // button, ShelfView dragging operations are locked and we have to unlock. |
| 582 CancelDrag(-1); | 582 CancelDrag(-1); |
| 583 drag_and_drop_item_pinned_ = false; | 583 drag_and_drop_item_pinned_ = false; |
| 584 drag_and_drop_app_id_ = app_id; | 584 drag_and_drop_app_id_ = app_id; |
| 585 drag_and_drop_launcher_id_ = | 585 drag_and_drop_launcher_id_ = |
| 586 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); | 586 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); |
| 587 // Check if the application is known and pinned - if not, we have to pin it so | 587 // Check if the application is known and pinned - if not, we have to pin it so |
| 588 // that we can re-arrange the launcher order accordingly. Note that items have | 588 // that we can re-arrange the shelf order accordingly. Note that items have |
| 589 // to be pinned to give them the same (order) possibilities as a shortcut. | 589 // to be pinned to give them the same (order) possibilities as a shortcut. |
| 590 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble() | 590 // When an item is dragged from overflow to shelf, IsShowingOverflowBubble() |
| 591 // returns true. At this time, we don't need to pin the item. | 591 // returns true. At this time, we don't need to pin the item. |
| 592 if (!IsShowingOverflowBubble() && | 592 if (!IsShowingOverflowBubble() && |
| 593 (!drag_and_drop_launcher_id_ || | 593 (!drag_and_drop_launcher_id_ || |
| 594 !delegate_->IsAppPinned(app_id))) { | 594 !delegate_->IsAppPinned(app_id))) { |
| 595 delegate_->PinAppWithID(app_id); | 595 delegate_->PinAppWithID(app_id); |
| 596 drag_and_drop_launcher_id_ = | 596 drag_and_drop_launcher_id_ = |
| 597 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); | 597 delegate_->GetLauncherIDForAppID(drag_and_drop_app_id_); |
| 598 if (!drag_and_drop_launcher_id_) | 598 if (!drag_and_drop_launcher_id_) |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 709 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); | 709 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); |
| 710 DCHECK(model_->item_count() == view_model_->view_size()); | 710 DCHECK(model_->item_count() == view_model_->view_size()); |
| 711 if (!available_size) | 711 if (!available_size) |
| 712 return; | 712 return; |
| 713 | 713 |
| 714 int first_panel_index = model_->FirstPanelIndex(); | 714 int first_panel_index = model_->FirstPanelIndex(); |
| 715 int last_button_index = first_panel_index - 1; | 715 int last_button_index = first_panel_index - 1; |
| 716 | 716 |
| 717 // Initial x,y values account both leading_inset in primary | 717 // Initial x,y values account both leading_inset in primary |
| 718 // coordinate and secondary coordinate based on the dynamic edge of the | 718 // coordinate and secondary coordinate based on the dynamic edge of the |
| 719 // launcher (eg top edge on bottom-aligned launcher). | 719 // shelf (eg top edge on bottom-aligned shelf). |
| 720 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset_; | 720 int inset = ash::switches::UseAlternateShelfLayout() ? 0 : leading_inset_; |
| 721 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); | 721 int x = layout_manager_->SelectValueForShelfAlignment(inset, 0, 0, inset); |
| 722 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); | 722 int y = layout_manager_->SelectValueForShelfAlignment(0, inset, inset, 0); |
| 723 | 723 |
| 724 int button_size = GetButtonSize(); | 724 int button_size = GetButtonSize(); |
| 725 int button_spacing = GetButtonSpacing(); | 725 int button_spacing = GetButtonSpacing(); |
| 726 | 726 |
| 727 int w = layout_manager_->PrimaryAxisValue(button_size, width()); | 727 int w = layout_manager_->PrimaryAxisValue(button_size, width()); |
| 728 int h = layout_manager_->PrimaryAxisValue(height(), button_size); | 728 int h = layout_manager_->PrimaryAxisValue(height(), button_size); |
| 729 for (int i = 0; i < view_model_->view_size(); ++i) { | 729 for (int i = 0; i < view_model_->view_size(); ++i) { |
| 730 if (i < first_visible_index_) { | 730 if (i < first_visible_index_) { |
| 731 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); | 731 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); |
| 732 continue; | 732 continue; |
| 733 } | 733 } |
| 734 | 734 |
| 735 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); | 735 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); |
| 736 if (i != last_button_index) { | 736 if (i != last_button_index) { |
| 737 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); | 737 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); |
| 738 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); | 738 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); |
| 739 } | 739 } |
| 740 } | 740 } |
| 741 | 741 |
| 742 if (is_overflow_mode()) { | 742 if (is_overflow_mode()) { |
| 743 UpdateAllButtonsVisibilityInOverflowMode(); | 743 UpdateAllButtonsVisibilityInOverflowMode(); |
| 744 return; | 744 return; |
| 745 } | 745 } |
| 746 | 746 |
| 747 // To address Fitt's law, we make the first launcher button include the | 747 // To address Fitt's law, we make the first shelf button include the |
| 748 // leading inset (if there is one). | 748 // leading inset (if there is one). |
| 749 if (!ash::switches::UseAlternateShelfLayout()) { | 749 if (!ash::switches::UseAlternateShelfLayout()) { |
| 750 if (view_model_->view_size() > 0) { | 750 if (view_model_->view_size() > 0) { |
| 751 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( | 751 view_model_->set_ideal_bounds(0, gfx::Rect(gfx::Size( |
| 752 layout_manager_->PrimaryAxisValue(inset + w, w), | 752 layout_manager_->PrimaryAxisValue(inset + w, w), |
| 753 layout_manager_->PrimaryAxisValue(h, inset + h)))); | 753 layout_manager_->PrimaryAxisValue(h, inset + h)))); |
| 754 } | 754 } |
| 755 } | 755 } |
| 756 | 756 |
| 757 // Right aligned icons. | 757 // Right aligned icons. |
| (...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1053 *view_model_, drag_view_, | 1053 *view_model_, drag_view_, |
| 1054 layout_manager_->IsHorizontalAlignment() ? | 1054 layout_manager_->IsHorizontalAlignment() ? |
| 1055 views::ViewModelUtils::HORIZONTAL : | 1055 views::ViewModelUtils::HORIZONTAL : |
| 1056 views::ViewModelUtils::VERTICAL, | 1056 views::ViewModelUtils::VERTICAL, |
| 1057 x, y); | 1057 x, y); |
| 1058 target_index = | 1058 target_index = |
| 1059 std::min(indices.second, std::max(target_index, indices.first)); | 1059 std::min(indices.second, std::max(target_index, indices.first)); |
| 1060 if (target_index == current_index) | 1060 if (target_index == current_index) |
| 1061 return; | 1061 return; |
| 1062 | 1062 |
| 1063 // Change the model, the LauncherItemMoved() callback will handle the | 1063 // Change the model, the ShelfItemMoved() callback will handle the |
| 1064 // |view_model_| update. | 1064 // |view_model_| update. |
| 1065 model_->Move(current_index, target_index); | 1065 model_->Move(current_index, target_index); |
| 1066 bounds_animator_->StopAnimatingView(drag_view_); | 1066 bounds_animator_->StopAnimatingView(drag_view_); |
| 1067 } | 1067 } |
| 1068 | 1068 |
| 1069 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { | 1069 bool ShelfView::HandleRipOffDrag(const ui::LocatedEvent& event) { |
| 1070 int current_index = view_model_->GetIndexOfView(drag_view_); | 1070 int current_index = view_model_->GetIndexOfView(drag_view_); |
| 1071 DCHECK_NE(-1, current_index); | 1071 DCHECK_NE(-1, current_index); |
| 1072 std::string dragged_app_id = | 1072 std::string dragged_app_id = |
| 1073 delegate_->GetAppIDForLauncherID(model_->items()[current_index].id); | 1073 delegate_->GetAppIDForLauncherID(model_->items()[current_index].id); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1136 ShelfButton* button = static_cast<ShelfButton*>(drag_view_); | 1136 ShelfButton* button = static_cast<ShelfButton*>(drag_view_); |
| 1137 CreateDragIconProxy(event.root_location(), | 1137 CreateDragIconProxy(event.root_location(), |
| 1138 button->GetImage(), | 1138 button->GetImage(), |
| 1139 drag_view_, | 1139 drag_view_, |
| 1140 gfx::Vector2d(0, 0), | 1140 gfx::Vector2d(0, 0), |
| 1141 kDragAndDropProxyScale); | 1141 kDragAndDropProxyScale); |
| 1142 drag_view_->layer()->SetOpacity(0.0f); | 1142 drag_view_->layer()->SetOpacity(0.0f); |
| 1143 dragged_off_shelf_ = true; | 1143 dragged_off_shelf_ = true; |
| 1144 if (RemovableByRipOff(current_index) == REMOVABLE) { | 1144 if (RemovableByRipOff(current_index) == REMOVABLE) { |
| 1145 // Move the item to the front of the first panel item and hide it. | 1145 // Move the item to the front of the first panel item and hide it. |
| 1146 // LauncherItemMoved() callback will handle the |view_model_| update and | 1146 // ShelfItemMoved() callback will handle the |view_model_| update and |
| 1147 // call AnimateToIdealBounds(). | 1147 // call AnimateToIdealBounds(). |
| 1148 if (current_index != model_->FirstPanelIndex() - 1) { | 1148 if (current_index != model_->FirstPanelIndex() - 1) { |
| 1149 model_->Move(current_index, model_->FirstPanelIndex() - 1); | 1149 model_->Move(current_index, model_->FirstPanelIndex() - 1); |
| 1150 StartFadeInLastVisibleItem(); | 1150 StartFadeInLastVisibleItem(); |
| 1151 } else if (is_overflow_mode()) { | 1151 } else if (is_overflow_mode()) { |
| 1152 // Overflow bubble should be shrunk when an item is ripped off. | 1152 // Overflow bubble should be shrunk when an item is ripped off. |
| 1153 PreferredSizeChanged(); | 1153 PreferredSizeChanged(); |
| 1154 } | 1154 } |
| 1155 // Make the item partially disappear to show that it will get removed if | 1155 // Make the item partially disappear to show that it will get removed if |
| 1156 // dropped. | 1156 // dropped. |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1299 | 1299 |
| 1300 overflow_bubble_->Show(overflow_button_, overflow_view); | 1300 overflow_bubble_->Show(overflow_button_, overflow_view); |
| 1301 | 1301 |
| 1302 Shell::GetInstance()->UpdateShelfVisibility(); | 1302 Shell::GetInstance()->UpdateShelfVisibility(); |
| 1303 } | 1303 } |
| 1304 | 1304 |
| 1305 void ShelfView::UpdateFirstButtonPadding() { | 1305 void ShelfView::UpdateFirstButtonPadding() { |
| 1306 if (ash::switches::UseAlternateShelfLayout()) | 1306 if (ash::switches::UseAlternateShelfLayout()) |
| 1307 return; | 1307 return; |
| 1308 | 1308 |
| 1309 // Creates an empty border for first launcher button to make included leading | 1309 // Creates an empty border for first shelf button to make included leading |
| 1310 // inset act as the button's padding. This is only needed on button creation | 1310 // inset act as the button's padding. This is only needed on button creation |
| 1311 // and when shelf alignment changes. | 1311 // and when shelf alignment changes. |
| 1312 if (view_model_->view_size() > 0) { | 1312 if (view_model_->view_size() > 0) { |
| 1313 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( | 1313 view_model_->view_at(0)->set_border(views::Border::CreateEmptyBorder( |
| 1314 layout_manager_->PrimaryAxisValue(0, leading_inset_), | 1314 layout_manager_->PrimaryAxisValue(0, leading_inset_), |
| 1315 layout_manager_->PrimaryAxisValue(leading_inset_, 0), | 1315 layout_manager_->PrimaryAxisValue(leading_inset_, 0), |
| 1316 0, | 1316 0, |
| 1317 0)); | 1317 0)); |
| 1318 } | 1318 } |
| 1319 } | 1319 } |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1550 { | 1550 { |
| 1551 base::AutoReset<bool> cancelling_drag( | 1551 base::AutoReset<bool> cancelling_drag( |
| 1552 &cancelling_drag_model_changed_, true); | 1552 &cancelling_drag_model_changed_, true); |
| 1553 model_index = CancelDrag(model_index); | 1553 model_index = CancelDrag(model_index); |
| 1554 } | 1554 } |
| 1555 views::View* view = view_model_->view_at(model_index); | 1555 views::View* view = view_model_->view_at(model_index); |
| 1556 view_model_->Remove(model_index); | 1556 view_model_->Remove(model_index); |
| 1557 | 1557 |
| 1558 // When the overflow bubble is visible, the overflow range needs to be set | 1558 // When the overflow bubble is visible, the overflow range needs to be set |
| 1559 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds() | 1559 // before CalculateIdealBounds() gets called. Otherwise CalculateIdealBounds() |
| 1560 // could trigger a LauncherItemChanged() by hiding the overflow bubble and | 1560 // could trigger a ShelfItemChanged() by hiding the overflow bubble and |
| 1561 // since the overflow bubble is not yet synced with the ShelfModel this | 1561 // since the overflow bubble is not yet synced with the ShelfModel this |
| 1562 // could cause a crash. | 1562 // could cause a crash. |
| 1563 if (overflow_bubble_ && overflow_bubble_->IsShowing()) { | 1563 if (overflow_bubble_ && overflow_bubble_->IsShowing()) { |
| 1564 last_hidden_index_ = std::min(last_hidden_index_, | 1564 last_hidden_index_ = std::min(last_hidden_index_, |
| 1565 view_model_->view_size() - 1); | 1565 view_model_->view_size() - 1); |
| 1566 UpdateOverflowRange(overflow_bubble_->shelf_view()); | 1566 UpdateOverflowRange(overflow_bubble_->shelf_view()); |
| 1567 } | 1567 } |
| 1568 | 1568 |
| 1569 if (view->visible()) { | 1569 if (view->visible()) { |
| 1570 // The first animation fades out the view. When done we'll animate the rest | 1570 // The first animation fades out the view. When done we'll animate the rest |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1624 break; | 1624 break; |
| 1625 } | 1625 } |
| 1626 | 1626 |
| 1627 default: | 1627 default: |
| 1628 break; | 1628 break; |
| 1629 } | 1629 } |
| 1630 } | 1630 } |
| 1631 | 1631 |
| 1632 void ShelfView::ShelfItemMoved(int start_index, int target_index) { | 1632 void ShelfView::ShelfItemMoved(int start_index, int target_index) { |
| 1633 view_model_->Move(start_index, target_index); | 1633 view_model_->Move(start_index, target_index); |
| 1634 // When cancelling a drag due to a launcher item being added, the currently | 1634 // When cancelling a drag due to a shelf item being added, the currently |
| 1635 // dragged item is moved back to its initial position. AnimateToIdealBounds | 1635 // dragged item is moved back to its initial position. AnimateToIdealBounds |
| 1636 // will be called again when the new item is added to the |view_model_| but | 1636 // will be called again when the new item is added to the |view_model_| but |
| 1637 // at this time the |view_model_| is inconsistent with the |model_|. | 1637 // at this time the |view_model_| is inconsistent with the |model_|. |
| 1638 if (!cancelling_drag_model_changed_) | 1638 if (!cancelling_drag_model_changed_) |
| 1639 AnimateToIdealBounds(); | 1639 AnimateToIdealBounds(); |
| 1640 } | 1640 } |
| 1641 | 1641 |
| 1642 void ShelfView::ShelfStatusChanged() { | 1642 void ShelfView::ShelfStatusChanged() { |
| 1643 if (ash::switches::UseAlternateShelfLayout()) | 1643 if (ash::switches::UseAlternateShelfLayout()) |
| 1644 return; | 1644 return; |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1867 new views::MenuRunner(menu_model_adapter->CreateMenu())); | 1867 new views::MenuRunner(menu_model_adapter->CreateMenu())); |
| 1868 | 1868 |
| 1869 ScopedTargetRootWindow scoped_target( | 1869 ScopedTargetRootWindow scoped_target( |
| 1870 source->GetWidget()->GetNativeView()->GetRootWindow()); | 1870 source->GetWidget()->GetNativeView()->GetRootWindow()); |
| 1871 | 1871 |
| 1872 // Determine the menu alignment dependent on the shelf. | 1872 // Determine the menu alignment dependent on the shelf. |
| 1873 views::MenuItemView::AnchorPosition menu_alignment = | 1873 views::MenuItemView::AnchorPosition menu_alignment = |
| 1874 views::MenuItemView::TOPLEFT; | 1874 views::MenuItemView::TOPLEFT; |
| 1875 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); | 1875 gfx::Rect anchor_point = gfx::Rect(click_point, gfx::Size()); |
| 1876 | 1876 |
| 1877 ShelfWidget* shelf = RootWindowController::ForLauncher( | 1877 ShelfWidget* shelf = RootWindowController::ForShelf( |
| 1878 GetWidget()->GetNativeView())->shelf(); | 1878 GetWidget()->GetNativeView())->shelf(); |
| 1879 if (!context_menu) { | 1879 if (!context_menu) { |
| 1880 // Application lists use a bubble. | 1880 // Application lists use a bubble. |
| 1881 ash::ShelfAlignment align = shelf->GetAlignment(); | 1881 ash::ShelfAlignment align = shelf->GetAlignment(); |
| 1882 anchor_point = source->GetBoundsInScreen(); | 1882 anchor_point = source->GetBoundsInScreen(); |
| 1883 | 1883 |
| 1884 // It is possible to invoke the menu while it is sliding into view. To cover | 1884 // It is possible to invoke the menu while it is sliding into view. To cover |
| 1885 // that case, the screen coordinates are offsetted by the animation delta. | 1885 // that case, the screen coordinates are offsetted by the animation delta. |
| 1886 gfx::Vector2d offset = | 1886 gfx::Vector2d offset = |
| 1887 source->GetWidget()->GetNativeWindow()->bounds().origin() - | 1887 source->GetWidget()->GetNativeWindow()->bounds().origin() - |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1902 menu_alignment = views::MenuItemView::BUBBLE_RIGHT; | 1902 menu_alignment = views::MenuItemView::BUBBLE_RIGHT; |
| 1903 break; | 1903 break; |
| 1904 case ash::SHELF_ALIGNMENT_RIGHT: | 1904 case ash::SHELF_ALIGNMENT_RIGHT: |
| 1905 menu_alignment = views::MenuItemView::BUBBLE_LEFT; | 1905 menu_alignment = views::MenuItemView::BUBBLE_LEFT; |
| 1906 break; | 1906 break; |
| 1907 case ash::SHELF_ALIGNMENT_TOP: | 1907 case ash::SHELF_ALIGNMENT_TOP: |
| 1908 menu_alignment = views::MenuItemView::BUBBLE_BELOW; | 1908 menu_alignment = views::MenuItemView::BUBBLE_BELOW; |
| 1909 break; | 1909 break; |
| 1910 } | 1910 } |
| 1911 } | 1911 } |
| 1912 // If this gets deleted while we are in the menu, the launcher will be gone | 1912 // If this gets deleted while we are in the menu, the shelf will be gone |
| 1913 // as well. | 1913 // as well. |
| 1914 bool got_deleted = false; | 1914 bool got_deleted = false; |
| 1915 got_deleted_ = &got_deleted; | 1915 got_deleted_ = &got_deleted; |
| 1916 | 1916 |
| 1917 shelf->ForceUndimming(true); | 1917 shelf->ForceUndimming(true); |
| 1918 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building | 1918 // NOTE: if you convert to HAS_MNEMONICS be sure and update menu building |
| 1919 // code. | 1919 // code. |
| 1920 if (launcher_menu_runner_->RunMenuAt( | 1920 if (launcher_menu_runner_->RunMenuAt( |
| 1921 source->GetWidget(), | 1921 source->GetWidget(), |
| 1922 NULL, | 1922 NULL, |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1998 return false; | 1998 return false; |
| 1999 const LauncherItem* item = LauncherItemForView(view); | 1999 const LauncherItem* item = LauncherItemForView(view); |
| 2000 if (!item) | 2000 if (!item) |
| 2001 return true; | 2001 return true; |
| 2002 ShelfItemDelegate* item_delegate = | 2002 ShelfItemDelegate* item_delegate = |
| 2003 item_manager_->GetShelfItemDelegate(item->id); | 2003 item_manager_->GetShelfItemDelegate(item->id); |
| 2004 return item_delegate->ShouldShowTooltip(); | 2004 return item_delegate->ShouldShowTooltip(); |
| 2005 } | 2005 } |
| 2006 | 2006 |
| 2007 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 2007 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
| 2008 ShelfWidget* shelf = RootWindowController::ForLauncher( | 2008 ShelfWidget* shelf = RootWindowController::ForShelf( |
| 2009 GetWidget()->GetNativeView())->shelf(); | 2009 GetWidget()->GetNativeView())->shelf(); |
| 2010 ash::ShelfAlignment align = shelf->GetAlignment(); | 2010 ash::ShelfAlignment align = shelf->GetAlignment(); |
| 2011 const gfx::Rect bounds = GetBoundsInScreen(); | 2011 const gfx::Rect bounds = GetBoundsInScreen(); |
| 2012 int distance = 0; | 2012 int distance = 0; |
| 2013 switch (align) { | 2013 switch (align) { |
| 2014 case ash::SHELF_ALIGNMENT_BOTTOM: | 2014 case ash::SHELF_ALIGNMENT_BOTTOM: |
| 2015 distance = bounds.y() - coordinate.y(); | 2015 distance = bounds.y() - coordinate.y(); |
| 2016 break; | 2016 break; |
| 2017 case ash::SHELF_ALIGNMENT_LEFT: | 2017 case ash::SHELF_ALIGNMENT_LEFT: |
| 2018 distance = coordinate.x() - bounds.right(); | 2018 distance = coordinate.x() - bounds.right(); |
| 2019 break; | 2019 break; |
| 2020 case ash::SHELF_ALIGNMENT_RIGHT: | 2020 case ash::SHELF_ALIGNMENT_RIGHT: |
| 2021 distance = bounds.x() - coordinate.x(); | 2021 distance = bounds.x() - coordinate.x(); |
| 2022 break; | 2022 break; |
| 2023 case ash::SHELF_ALIGNMENT_TOP: | 2023 case ash::SHELF_ALIGNMENT_TOP: |
| 2024 distance = coordinate.y() - bounds.bottom(); | 2024 distance = coordinate.y() - bounds.bottom(); |
| 2025 break; | 2025 break; |
| 2026 } | 2026 } |
| 2027 return distance > 0 ? distance : 0; | 2027 return distance > 0 ? distance : 0; |
| 2028 } | 2028 } |
| 2029 | 2029 |
| 2030 } // namespace internal | 2030 } // namespace internal |
| 2031 } // namespace ash | 2031 } // namespace ash |
| OLD | NEW |