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

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

Issue 1998933002: Update shelf spacing in Chrome OS according to the MD specs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments & Refactor border around item implementation 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/shelf/shelf_view.h" 5 #include "ash/shelf/shelf_view.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <memory> 8 #include <memory>
9 9
10 #include "ash/ash_constants.h" 10 #include "ash/ash_constants.h"
(...skipping 798 matching lines...) Expand 10 before | Expand all | Expand 10 after
809 int available_size = shelf_->PrimaryAxisValue(width(), height()); 809 int available_size = shelf_->PrimaryAxisValue(width(), height());
810 DCHECK(model_->item_count() == view_model_->view_size()); 810 DCHECK(model_->item_count() == view_model_->view_size());
811 if (!available_size) 811 if (!available_size)
812 return; 812 return;
813 813
814 int first_panel_index = model_->FirstPanelIndex(); 814 int first_panel_index = model_->FirstPanelIndex();
815 int last_button_index = first_panel_index - 1; 815 int last_button_index = first_panel_index - 1;
816 816
817 int x = 0; 817 int x = 0;
818 int y = 0; 818 int y = 0;
819 int button_size = kShelfButtonSize; 819 int button_size = GetShelfLayoutConstant(SHELF_BUTTON_SIZE);
820 int button_spacing = kShelfButtonSpacing; 820 int button_spacing = GetShelfLayoutConstant(SHELF_BUTTON_SPACING);
821 821
822 int w = shelf_->PrimaryAxisValue(button_size, width()); 822 int w = shelf_->PrimaryAxisValue(button_size, width());
823 int h = shelf_->PrimaryAxisValue(height(), button_size); 823 int h = shelf_->PrimaryAxisValue(height(), button_size);
824 for (int i = 0; i < view_model_->view_size(); ++i) { 824 for (int i = 0; i < view_model_->view_size(); ++i) {
825 if (i < first_visible_index_) { 825 if (i < first_visible_index_) {
826 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 826 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
827 continue; 827 continue;
828 } 828 }
829 829
830 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 830 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 view_model_->view_at(last_button_index)->bounds(); 1409 view_model_->view_at(last_button_index)->bounds();
1410 if (overflow_button_->visible() && 1410 if (overflow_button_->visible() &&
1411 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) { 1411 model_->GetItemIndexForType(TYPE_APP_PANEL) == -1) {
1412 // When overflow button is visible and shelf has no panel items, 1412 // When overflow button is visible and shelf has no panel items,
1413 // last_button_bounds should be overflow button's bounds. 1413 // last_button_bounds should be overflow button's bounds.
1414 last_button_bounds = overflow_button_->bounds(); 1414 last_button_bounds = overflow_button_->bounds();
1415 } 1415 }
1416 1416
1417 if (shelf_->IsHorizontalAlignment()) { 1417 if (shelf_->IsHorizontalAlignment()) {
1418 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_, 1418 preferred_size = gfx::Size(last_button_bounds.right() + leading_inset_,
1419 kShelfSize); 1419 GetShelfLayoutConstant(SHELF_SIZE));
1420 } else { 1420 } else {
1421 preferred_size = gfx::Size(kShelfSize, 1421 preferred_size = gfx::Size(GetShelfLayoutConstant(SHELF_SIZE),
1422 last_button_bounds.bottom() + leading_inset_); 1422 last_button_bounds.bottom() + leading_inset_);
1423 } 1423 }
1424 } 1424 }
1425 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0); 1425 gfx::Point origin(GetMirroredXWithWidthInView(0, preferred_size.width()), 0);
1426 1426
1427 // In overflow mode, we should use OverflowBubbleView as a source for 1427 // In overflow mode, we should use OverflowBubbleView as a source for
1428 // converting |origin| to screen coordinates. When a scroll operation is 1428 // converting |origin| to screen coordinates. When a scroll operation is
1429 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can 1429 // occurred in OverflowBubble, the bounds of ShelfView in OverflowBubble can
1430 // be changed. 1430 // be changed.
1431 if (is_overflow_mode()) 1431 if (is_overflow_mode())
(...skipping 29 matching lines...) Expand all
1461 // If the modified view will be at the end of the list, return the new end of 1461 // If the modified view will be at the end of the list, return the new end of
1462 // the list. 1462 // the list.
1463 if (at_end) 1463 if (at_end)
1464 return view_model_->view_size(); 1464 return view_model_->view_size();
1465 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; 1465 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1;
1466 } 1466 }
1467 1467
1468 gfx::Size ShelfView::GetPreferredSize() const { 1468 gfx::Size ShelfView::GetPreferredSize() const {
1469 IdealBounds ideal_bounds; 1469 IdealBounds ideal_bounds;
1470 CalculateIdealBounds(&ideal_bounds); 1470 CalculateIdealBounds(&ideal_bounds);
1471 1471
tdanderson 2016/06/03 19:25:23 nit: declare a const int shelf_size = GetShelfLayo
yiyix 2016/06/10 19:26:04 Done.
1472 int last_button_index = is_overflow_mode() ? 1472 int last_button_index = is_overflow_mode() ?
1473 last_visible_index_ : view_model_->view_size() - 1; 1473 last_visible_index_ : view_model_->view_size() - 1;
1474 1474
1475 // When an item is dragged off from the overflow bubble, it is moved to last 1475 // When an item is dragged off from the overflow bubble, it is moved to last
1476 // position and and changed to invisible. Overflow bubble size should be 1476 // position and and changed to invisible. Overflow bubble size should be
1477 // shrunk to fit only for visible items. 1477 // shrunk to fit only for visible items.
1478 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible 1478 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible
1479 // items in the shelf. 1479 // items in the shelf.
1480 if (is_overflow_mode() && 1480 if (is_overflow_mode() &&
1481 dragged_off_shelf_ && 1481 dragged_off_shelf_ &&
1482 !dragged_off_from_overflow_to_shelf_ && 1482 !dragged_off_from_overflow_to_shelf_ &&
1483 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE) 1483 RemovableByRipOff(view_model_->GetIndexOfView(drag_view_)) == REMOVABLE)
1484 last_button_index--; 1484 last_button_index--;
1485 1485
1486 const gfx::Rect last_button_bounds = 1486 const gfx::Rect last_button_bounds =
1487 last_button_index >= first_visible_index_ ? 1487 last_button_index >= first_visible_index_
1488 view_model_->ideal_bounds(last_button_index) : 1488 ? view_model_->ideal_bounds(last_button_index)
1489 gfx::Rect(gfx::Size(kShelfSize, kShelfSize)); 1489 : gfx::Rect(gfx::Size(GetShelfLayoutConstant(SHELF_SIZE),
1490 GetShelfLayoutConstant(SHELF_SIZE)));
1490 1491
1491 if (shelf_->IsHorizontalAlignment()) 1492 if (shelf_->IsHorizontalAlignment())
1492 return gfx::Size(last_button_bounds.right() + leading_inset_, kShelfSize); 1493 return gfx::Size(last_button_bounds.right() + leading_inset_,
1494 GetShelfLayoutConstant(SHELF_SIZE));
tdanderson 2016/06/03 19:25:23 nit: enclose in {} since it is more than one line.
yiyix 2016/06/10 19:26:04 Done.
1493 1495
1494 return gfx::Size(kShelfSize, last_button_bounds.bottom() + leading_inset_); 1496 return gfx::Size(GetShelfLayoutConstant(SHELF_SIZE),
1497 last_button_bounds.bottom() + leading_inset_);
1495 } 1498 }
1496 1499
1497 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) { 1500 void ShelfView::OnBoundsChanged(const gfx::Rect& previous_bounds) {
1498 // This bounds change is produced by the shelf movement and all content has 1501 // This bounds change is produced by the shelf movement and all content has
1499 // to follow. Using an animation at that time would produce a time lag since 1502 // to follow. Using an animation at that time would produce a time lag since
1500 // the animation of the BoundsAnimator has itself a delay before it arrives 1503 // the animation of the BoundsAnimator has itself a delay before it arrives
1501 // at the required location. As such we tell the animator to go there 1504 // at the required location. As such we tell the animator to go there
1502 // immediately. 1505 // immediately.
1503 BoundsAnimatorDisabler disabler(bounds_animator_.get()); 1506 BoundsAnimatorDisabler disabler(bounds_animator_.get());
1504 LayoutToIdealBounds(); 1507 LayoutToIdealBounds();
(...skipping 386 matching lines...) Expand 10 before | Expand all | Expand 10 after
1891 1894
1892 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const { 1895 int ShelfView::CalculateShelfDistance(const gfx::Point& coordinate) const {
1893 const gfx::Rect bounds = GetBoundsInScreen(); 1896 const gfx::Rect bounds = GetBoundsInScreen();
1894 int distance = shelf_->SelectValueForShelfAlignment( 1897 int distance = shelf_->SelectValueForShelfAlignment(
1895 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(), 1898 bounds.y() - coordinate.y(), coordinate.x() - bounds.right(),
1896 bounds.x() - coordinate.x()); 1899 bounds.x() - coordinate.x());
1897 return distance > 0 ? distance : 0; 1900 return distance > 0 ? distance : 0;
1898 } 1901 }
1899 1902
1900 } // namespace ash 1903 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698