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 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "ash/ash_constants.h" | 10 #include "ash/ash_constants.h" |
(...skipping 1324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1335 gfx::Rect last_button_bounds = | 1335 gfx::Rect last_button_bounds = |
1336 view_model_->view_at(last_button_index)->bounds(); | 1336 view_model_->view_at(last_button_index)->bounds(); |
1337 if (overflow_button_->visible() && | 1337 if (overflow_button_->visible() && |
1338 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { | 1338 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { |
1339 // When overflow button is visible and shelf has no panel items, | 1339 // When overflow button is visible and shelf has no panel items, |
1340 // last_button_bounds should be overflow button's bounds. | 1340 // last_button_bounds should be overflow button's bounds. |
1341 last_button_bounds = overflow_button_->bounds(); | 1341 last_button_bounds = overflow_button_->bounds(); |
1342 } | 1342 } |
1343 | 1343 |
1344 if (wm_shelf_->IsHorizontalAlignment()) { | 1344 if (wm_shelf_->IsHorizontalAlignment()) { |
1345 preferred_size = | 1345 preferred_size = gfx::Size(last_button_bounds.right(), kShelfSize); |
1346 gfx::Size(last_button_bounds.right(), GetShelfConstant(SHELF_SIZE)); | |
1347 } else { | 1346 } else { |
1348 preferred_size = | 1347 preferred_size = gfx::Size(kShelfSize, last_button_bounds.bottom()); |
1349 gfx::Size(GetShelfConstant(SHELF_SIZE), last_button_bounds.bottom()); | |
1350 } | 1348 } |
1351 } | 1349 } |
1352 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); | 1350 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); |
1353 | 1351 |
1354 // In overflow mode, we should use OverflowBubbleView as a source for | 1352 // In overflow mode, we should use OverflowBubbleView as a source for |
1355 // converting |origin| to screen coordinates. When a scroll operation is | 1353 // converting |origin| to screen coordinates. When a scroll operation is |
1356 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can | 1354 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can |
1357 // be changed. | 1355 // be changed. |
1358 if (is_overflow_mode()) | 1356 if (is_overflow_mode()) |
1359 ConvertPointToScreen(owner_overflow_bubble_->bubble_view(), &origin); | 1357 ConvertPointToScreen(owner_overflow_bubble_->bubble_view(), &origin); |
(...skipping 28 matching lines...) Expand all Loading... |
1388 // If the modified view will be at the end of the list, return the new end of | 1386 // If the modified view will be at the end of the list, return the new end of |
1389 // the list. | 1387 // the list. |
1390 if (at_end) | 1388 if (at_end) |
1391 return view_model_->view_size(); | 1389 return view_model_->view_size(); |
1392 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; | 1390 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; |
1393 } | 1391 } |
1394 | 1392 |
1395 gfx::Size ShelfView::GetPreferredSize() const { | 1393 gfx::Size ShelfView::GetPreferredSize() const { |
1396 gfx::Rect overflow_bounds; | 1394 gfx::Rect overflow_bounds; |
1397 CalculateIdealBounds(&overflow_bounds); | 1395 CalculateIdealBounds(&overflow_bounds); |
1398 const int shelf_size = GetShelfConstant(SHELF_SIZE); | |
1399 | 1396 |
1400 int last_button_index = last_visible_index_; | 1397 int last_button_index = last_visible_index_; |
1401 if (!is_overflow_mode()) { | 1398 if (!is_overflow_mode()) { |
1402 if (last_hidden_index_ < view_model_->view_size() - 1) | 1399 if (last_hidden_index_ < view_model_->view_size() - 1) |
1403 last_button_index = view_model_->view_size() - 1; | 1400 last_button_index = view_model_->view_size() - 1; |
1404 else if (overflow_button_ && overflow_button_->visible()) | 1401 else if (overflow_button_ && overflow_button_->visible()) |
1405 last_button_index++; | 1402 last_button_index++; |
1406 } | 1403 } |
1407 | 1404 |
1408 // When an item is dragged off from the overflow bubble, it is moved to last | 1405 // When an item is dragged off from the overflow bubble, it is moved to last |
1409 // position and and changed to invisible. Overflow bubble size should be | 1406 // position and and changed to invisible. Overflow bubble size should be |
1410 // shrunk to fit only for visible items. | 1407 // shrunk to fit only for visible items. |
1411 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible | 1408 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible |
1412 // items in the shelf. | 1409 // items in the shelf. |
1413 if (is_overflow_mode() && dragged_off_shelf_ && | 1410 if (is_overflow_mode() && dragged_off_shelf_ && |
1414 !dragged_off_from_overflow_to_shelf_ && | 1411 !dragged_off_from_overflow_to_shelf_ && |
1415 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) | 1412 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) |
1416 last_button_index--; | 1413 last_button_index--; |
1417 | 1414 |
1418 const gfx::Rect last_button_bounds = | 1415 const gfx::Rect last_button_bounds = |
1419 last_button_index >= first_visible_index_ | 1416 last_button_index >= first_visible_index_ |
1420 ? view_model_->ideal_bounds(last_button_index) | 1417 ? view_model_->ideal_bounds(last_button_index) |
1421 : gfx::Rect(gfx::Size(shelf_size, shelf_size)); | 1418 : gfx::Rect(gfx::Size(kShelfSize, kShelfSize)); |
1422 | 1419 |
1423 if (wm_shelf_->IsHorizontalAlignment()) | 1420 if (wm_shelf_->IsHorizontalAlignment()) |
1424 return gfx::Size(last_button_bounds.right(), shelf_size); | 1421 return gfx::Size(last_button_bounds.right(), kShelfSize); |
1425 | 1422 |
1426 return gfx::Size(shelf_size, last_button_bounds.bottom()); | 1423 return gfx::Size(kShelfSize, last_button_bounds.bottom()); |
1427 } | 1424 } |
1428 | 1425 |
1429 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { | 1426 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { |
1430 // This bounds change is produced by the shelf movement and all content has | 1427 // This bounds change is produced by the shelf movement and all content has |
1431 // to follow. Using an animation at that time would produce a time lag since | 1428 // to follow. Using an animation at that time would produce a time lag since |
1432 // the animation of the BoundsAnimator has itself a delay before it arrives | 1429 // the animation of the BoundsAnimator has itself a delay before it arrives |
1433 // at the required location. As such we tell the animator to go there | 1430 // at the required location. As such we tell the animator to go there |
1434 // immediately. | 1431 // immediately. |
1435 BoundsAnimatorDisabler disabler(bounds_animator_.get()); | 1432 BoundsAnimatorDisabler disabler(bounds_animator_.get()); |
1436 LayoutToIdealBounds(); | 1433 LayoutToIdealBounds(); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1761 | 1758 |
1762 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { | 1759 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { |
1763 const gfx::Rect bounds = GetBoundsInScreen(); | 1760 const gfx::Rect bounds = GetBoundsInScreen(); |
1764 int distance = wm_shelf_->SelectValueForShelfAlignment( | 1761 int distance = wm_shelf_->SelectValueForShelfAlignment( |
1765 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), | 1762 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), |
1766 bounds.x() - coordinate.x()); | 1763 bounds.x() - coordinate.x()); |
1767 return distance > 0 ? distance : 0; | 1764 return distance > 0 ? distance : 0; |
1768 } | 1765 } |
1769 | 1766 |
1770 } // namespace ash | 1767 } // namespace ash |
OLD | NEW |