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 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // Map all items from overflow area to the overflow button. Note that the | 455 // Map all items from overflow area to the overflow button. Note that the |
456 // section between last_index_hidden_ and model_->FirstPanelIndex() is the | 456 // section between last_index_hidden_ and model_->FirstPanelIndex() is the |
457 // list of invisible panel items. However, these items are currently nowhere | 457 // list of invisible panel items. However, these items are currently nowhere |
458 // represented and get dropped instead - see (crbug.com/378907). As such there | 458 // represented and get dropped instead - see (crbug.com/378907). As such there |
459 // is no way to address them or place them. We therefore move them over the | 459 // is no way to address them or place them. We therefore move them over the |
460 // overflow button. | 460 // overflow button. |
461 if (index > last_visible_index_ && index < model_->FirstPanelIndex()) | 461 if (index > last_visible_index_ && index < model_->FirstPanelIndex()) |
462 index = last_visible_index_ + 1; | 462 index = last_visible_index_ + 1; |
463 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); | 463 const gfx::Rect& ideal_bounds(view_model_->ideal_bounds(index)); |
464 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); | 464 DCHECK_NE(TYPE_APP_LIST, model_->items()[index].type); |
465 ShelfButton* button = static_cast<ShelfButton*>(view_model_->view_at(index)); | 465 views::View* view = view_model_->view_at(index); |
| 466 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
| 467 ShelfButton* button = static_cast<ShelfButton*>(view); |
466 gfx::Rect icon_bounds = button->GetIconBounds(); | 468 gfx::Rect icon_bounds = button->GetIconBounds(); |
467 return gfx::Rect(GetMirroredXWithWidthInView( | 469 return gfx::Rect(GetMirroredXWithWidthInView( |
468 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()), | 470 ideal_bounds.x() + icon_bounds.x(), icon_bounds.width()), |
469 ideal_bounds.y() + icon_bounds.y(), | 471 ideal_bounds.y() + icon_bounds.y(), |
470 icon_bounds.width(), | 472 icon_bounds.width(), |
471 icon_bounds.height()); | 473 icon_bounds.height()); |
472 } | 474 } |
473 | 475 |
474 void ShelfView::UpdatePanelIconPosition(ShelfID id, | 476 void ShelfView::UpdatePanelIconPosition(ShelfID id, |
475 const gfx::Point& midpoint) { | 477 const gfx::Point& midpoint) { |
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1061 } | 1063 } |
1062 // Move our proxy view item. | 1064 // Move our proxy view item. |
1063 UpdateDragIconProxy(screen_location); | 1065 UpdateDragIconProxy(screen_location); |
1064 return true; | 1066 return true; |
1065 } | 1067 } |
1066 // Check if we are too far away from the shelf to enter the ripped off state. | 1068 // Check if we are too far away from the shelf to enter the ripped off state. |
1067 // Determine the distance to the shelf. | 1069 // Determine the distance to the shelf. |
1068 int delta = CalculateShelfDistance(screen_location); | 1070 int delta = CalculateShelfDistance(screen_location); |
1069 if (delta > kRipOffDistance) { | 1071 if (delta > kRipOffDistance) { |
1070 // Create a proxy view item which can be moved anywhere. | 1072 // Create a proxy view item which can be moved anywhere. |
1071 ShelfButton* button = static_cast<ShelfButton*>(drag_view_); | |
1072 CreateDragIconProxy(event.root_location(), | 1073 CreateDragIconProxy(event.root_location(), |
1073 button->GetImage(), | 1074 drag_view_->GetImage(), |
1074 drag_view_, | 1075 drag_view_, |
1075 gfx::Vector2d(0, 0), | 1076 gfx::Vector2d(0, 0), |
1076 kDragAndDropProxyScale); | 1077 kDragAndDropProxyScale); |
1077 drag_view_->layer()->SetOpacity(0.0f); | 1078 drag_view_->layer()->SetOpacity(0.0f); |
1078 dragged_off_shelf_ = true; | 1079 dragged_off_shelf_ = true; |
1079 if (RemovableByRipOff(current_index) == REMOVABLE) { | 1080 if (RemovableByRipOff(current_index) == REMOVABLE) { |
1080 // Move the item to the front of the first panel item and hide it. | 1081 // Move the item to the front of the first panel item and hide it. |
1081 // ShelfItemMoved() callback will handle the |view_model_| update and | 1082 // ShelfItemMoved() callback will handle the |view_model_| update and |
1082 // call AnimateToIdealBounds(). | 1083 // call AnimateToIdealBounds(). |
1083 if (current_index != model_->FirstPanelIndex() - 1) { | 1084 if (current_index != model_->FirstPanelIndex() - 1) { |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1145 gfx::Rect drag_bounds = drag_image_->GetBoundsInScreen(); | 1146 gfx::Rect drag_bounds = drag_image_->GetBoundsInScreen(); |
1146 gfx::Point relative_to = GetBoundsInScreen().origin(); | 1147 gfx::Point relative_to = GetBoundsInScreen().origin(); |
1147 gfx::Rect target( | 1148 gfx::Rect target( |
1148 gfx::PointAtOffsetFromOrigin(drag_bounds.origin()- relative_to), | 1149 gfx::PointAtOffsetFromOrigin(drag_bounds.origin()- relative_to), |
1149 drag_bounds.size()); | 1150 drag_bounds.size()); |
1150 drag_view_->SetBoundsRect(target); | 1151 drag_view_->SetBoundsRect(target); |
1151 // Hide the status from the active item since we snap it back now. Upon | 1152 // Hide the status from the active item since we snap it back now. Upon |
1152 // animation end the flag gets cleared if |snap_back_from_rip_off_view_| | 1153 // animation end the flag gets cleared if |snap_back_from_rip_off_view_| |
1153 // is set. | 1154 // is set. |
1154 snap_back_from_rip_off_view_ = drag_view_; | 1155 snap_back_from_rip_off_view_ = drag_view_; |
1155 ShelfButton* button = static_cast<ShelfButton*>(drag_view_); | 1156 drag_view_->AddState(ShelfButton::STATE_HIDDEN); |
1156 button->AddState(ShelfButton::STATE_HIDDEN); | |
1157 // When a canceling drag model is happening, the view model is diverged | 1157 // When a canceling drag model is happening, the view model is diverged |
1158 // from the menu model and movements / animations should not be done. | 1158 // from the menu model and movements / animations should not be done. |
1159 model_->Move(current_index, start_drag_index_); | 1159 model_->Move(current_index, start_drag_index_); |
1160 AnimateToIdealBounds(); | 1160 AnimateToIdealBounds(); |
1161 } | 1161 } |
1162 drag_view_->layer()->SetOpacity(1.0f); | 1162 drag_view_->layer()->SetOpacity(1.0f); |
1163 } | 1163 } |
1164 DestroyDragIconProxy(); | 1164 DestroyDragIconProxy(); |
1165 } | 1165 } |
1166 | 1166 |
(...skipping 354 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1521 views::View* view = view_model_->view_at(model_index); | 1521 views::View* view = view_model_->view_at(model_index); |
1522 switch (item.type) { | 1522 switch (item.type) { |
1523 case TYPE_BROWSER_SHORTCUT: | 1523 case TYPE_BROWSER_SHORTCUT: |
1524 // Fallthrough for the new Shelf since it needs to show the activation | 1524 // Fallthrough for the new Shelf since it needs to show the activation |
1525 // change as well. | 1525 // change as well. |
1526 case TYPE_APP_SHORTCUT: | 1526 case TYPE_APP_SHORTCUT: |
1527 case TYPE_WINDOWED_APP: | 1527 case TYPE_WINDOWED_APP: |
1528 case TYPE_PLATFORM_APP: | 1528 case TYPE_PLATFORM_APP: |
1529 case TYPE_DIALOG: | 1529 case TYPE_DIALOG: |
1530 case TYPE_APP_PANEL: { | 1530 case TYPE_APP_PANEL: { |
| 1531 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
1531 ShelfButton* button = static_cast<ShelfButton*>(view); | 1532 ShelfButton* button = static_cast<ShelfButton*>(view); |
1532 ReflectItemStatus(item, button); | 1533 ReflectItemStatus(item, button); |
1533 // The browser shortcut is currently not a "real" item and as such the | 1534 // The browser shortcut is currently not a "real" item and as such the |
1534 // the image is bogous as well. We therefore keep the image as is for it. | 1535 // the image is bogous as well. We therefore keep the image as is for it. |
1535 if (item.type != TYPE_BROWSER_SHORTCUT) | 1536 if (item.type != TYPE_BROWSER_SHORTCUT) |
1536 button->SetImage(item.image); | 1537 button->SetImage(item.image); |
1537 button->SchedulePaint(); | 1538 button->SchedulePaint(); |
1538 break; | 1539 break; |
1539 } | 1540 } |
1540 | 1541 |
(...skipping 24 matching lines...) Expand all Loading... |
1565 | 1566 |
1566 int index = view_model_->GetIndexOfView(view); | 1567 int index = view_model_->GetIndexOfView(view); |
1567 if (index == -1) | 1568 if (index == -1) |
1568 return; | 1569 return; |
1569 | 1570 |
1570 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( | 1571 ShelfItemDelegate* item_delegate = item_manager_->GetShelfItemDelegate( |
1571 model_->items()[index].id); | 1572 model_->items()[index].id); |
1572 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) | 1573 if (view_model_->view_size() <= 1 || !item_delegate->IsDraggable()) |
1573 return; // View is being deleted or not draggable, ignore request. | 1574 return; // View is being deleted or not draggable, ignore request. |
1574 | 1575 |
1575 drag_view_ = view; | 1576 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
| 1577 drag_view_ = static_cast<ShelfButton*>(view); |
1576 drag_origin_ = gfx::Point(event.x(), event.y()); | 1578 drag_origin_ = gfx::Point(event.x(), event.y()); |
1577 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", | 1579 UMA_HISTOGRAM_ENUMERATION("Ash.ShelfAlignmentUsage", |
1578 layout_manager_->SelectValueForShelfAlignment( | 1580 layout_manager_->SelectValueForShelfAlignment( |
1579 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, | 1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_BOTTOM, |
1580 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, | 1582 SHELF_ALIGNMENT_UMA_ENUM_VALUE_LEFT, |
1581 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, | 1583 SHELF_ALIGNMENT_UMA_ENUM_VALUE_RIGHT, |
1582 -1), | 1584 -1), |
1583 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); | 1585 SHELF_ALIGNMENT_UMA_ENUM_VALUE_COUNT); |
1584 } | 1586 } |
1585 | 1587 |
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1859 void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { | 1861 void ShelfView::OnBoundsAnimatorDone(views::BoundsAnimator* animator) { |
1860 if (snap_back_from_rip_off_view_ && animator == bounds_animator_) { | 1862 if (snap_back_from_rip_off_view_ && animator == bounds_animator_) { |
1861 if (!animator->IsAnimating(snap_back_from_rip_off_view_)) { | 1863 if (!animator->IsAnimating(snap_back_from_rip_off_view_)) { |
1862 // Coming here the animation of the ShelfButton is finished and the | 1864 // Coming here the animation of the ShelfButton is finished and the |
1863 // previously hidden status can be shown again. Since the button itself | 1865 // previously hidden status can be shown again. Since the button itself |
1864 // might have gone away or changed locations we check that the button | 1866 // might have gone away or changed locations we check that the button |
1865 // is still in the shelf and show its status again. | 1867 // is still in the shelf and show its status again. |
1866 for (int index = 0; index < view_model_->view_size(); index++) { | 1868 for (int index = 0; index < view_model_->view_size(); index++) { |
1867 views::View* view = view_model_->view_at(index); | 1869 views::View* view = view_model_->view_at(index); |
1868 if (view == snap_back_from_rip_off_view_) { | 1870 if (view == snap_back_from_rip_off_view_) { |
| 1871 CHECK_EQ(ShelfButton::kViewClassName, view->GetClassName()); |
1869 ShelfButton* button = static_cast<ShelfButton*>(view); | 1872 ShelfButton* button = static_cast<ShelfButton*>(view); |
1870 button->ClearState(ShelfButton::STATE_HIDDEN); | 1873 button->ClearState(ShelfButton::STATE_HIDDEN); |
1871 break; | 1874 break; |
1872 } | 1875 } |
1873 } | 1876 } |
1874 snap_back_from_rip_off_view_ = NULL; | 1877 snap_back_from_rip_off_view_ = NULL; |
1875 } | 1878 } |
1876 } | 1879 } |
1877 } | 1880 } |
1878 | 1881 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1924 distance = bounds.x() - coordinate.x(); | 1927 distance = bounds.x() - coordinate.x(); |
1925 break; | 1928 break; |
1926 case SHELF_ALIGNMENT_TOP: | 1929 case SHELF_ALIGNMENT_TOP: |
1927 distance = coordinate.y() - bounds.bottom(); | 1930 distance = coordinate.y() - bounds.bottom(); |
1928 break; | 1931 break; |
1929 } | 1932 } |
1930 return distance > 0 ? distance : 0; | 1933 return distance > 0 ? distance : 0; |
1931 } | 1934 } |
1932 | 1935 |
1933 } // namespace ash | 1936 } // namespace ash |
OLD | NEW |