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

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

Issue 273223002: views: Make view::Views::GetPreferredSize() const. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More compile fix for ToT Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shell/lock_view.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 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 684 matching lines...) Expand 10 before | Expand all | Expand 10 after
695 // To track the dragging of |drag_view_| continuously, its visibility 695 // To track the dragging of |drag_view_| continuously, its visibility
696 // should be always true regardless of its position. 696 // should be always true regardless of its position.
697 if (dragged_off_from_overflow_to_shelf_ && 697 if (dragged_off_from_overflow_to_shelf_ &&
698 view_model_->view_at(i) == drag_view_) 698 view_model_->view_at(i) == drag_view_)
699 view_model_->view_at(i)->SetVisible(true); 699 view_model_->view_at(i)->SetVisible(true);
700 else 700 else
701 view_model_->view_at(i)->SetVisible(visible); 701 view_model_->view_at(i)->SetVisible(visible);
702 } 702 }
703 } 703 }
704 704
705 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) { 705 void ShelfView::CalculateIdealBounds(IdealBounds* bounds) const {
706 int available_size = layout_manager_->PrimaryAxisValue(width(), height()); 706 int available_size = layout_manager_->PrimaryAxisValue(width(), height());
707 DCHECK(model_->item_count() == view_model_->view_size()); 707 DCHECK(model_->item_count() == view_model_->view_size());
708 if (!available_size) 708 if (!available_size)
709 return; 709 return;
710 710
711 int first_panel_index = model_->FirstPanelIndex(); 711 int first_panel_index = model_->FirstPanelIndex();
712 int last_button_index = first_panel_index - 1; 712 int last_button_index = first_panel_index - 1;
713 713
714 int x = 0; 714 int x = 0;
715 int y = 0; 715 int y = 0;
716 int button_size = kShelfButtonSize; 716 int button_size = kShelfButtonSize;
717 int button_spacing = kShelfButtonSpacing; 717 int button_spacing = kShelfButtonSpacing;
718 718
719 int w = layout_manager_->PrimaryAxisValue(button_size, width()); 719 int w = layout_manager_->PrimaryAxisValue(button_size, width());
720 int h = layout_manager_->PrimaryAxisValue(height(), button_size); 720 int h = layout_manager_->PrimaryAxisValue(height(), button_size);
721 for (int i = 0; i < view_model_->view_size(); ++i) { 721 for (int i = 0; i < view_model_->view_size(); ++i) {
722 if (i < first_visible_index_) { 722 if (i < first_visible_index_) {
723 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0)); 723 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, 0, 0));
724 continue; 724 continue;
725 } 725 }
726 726
727 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h)); 727 view_model_->set_ideal_bounds(i, gfx::Rect(x, y, w, h));
728 if (i != last_button_index) { 728 if (i != last_button_index) {
729 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x); 729 x = layout_manager_->PrimaryAxisValue(x + w + button_spacing, x);
730 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing); 730 y = layout_manager_->PrimaryAxisValue(y, y + h + button_spacing);
731 } 731 }
732 } 732 }
733 733
734 if (is_overflow_mode()) { 734 if (is_overflow_mode()) {
735 UpdateAllButtonsVisibilityInOverflowMode(); 735 const_cast<ShelfView*>(this)->UpdateAllButtonsVisibilityInOverflowMode();
736 return; 736 return;
737 } 737 }
738 738
739 // Right aligned icons. 739 // Right aligned icons.
740 int end_position = available_size - button_spacing; 740 int end_position = available_size - button_spacing;
741 x = layout_manager_->PrimaryAxisValue(end_position, 0); 741 x = layout_manager_->PrimaryAxisValue(end_position, 0);
742 y = layout_manager_->PrimaryAxisValue(0, end_position); 742 y = layout_manager_->PrimaryAxisValue(0, end_position);
743 for (int i = view_model_->view_size() - 1; 743 for (int i = view_model_->view_size() - 1;
744 i >= first_panel_index; --i) { 744 i >= first_panel_index; --i) {
745 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x); 745 x = layout_manager_->PrimaryAxisValue(x - w - button_spacing, x);
(...skipping 409 matching lines...) Expand 10 before | Expand all | Expand 10 after
1155 // When a canceling drag model is happening, the view model is diverged 1155 // When a canceling drag model is happening, the view model is diverged
1156 // from the menu model and movements / animations should not be done. 1156 // from the menu model and movements / animations should not be done.
1157 model_->Move(current_index, start_drag_index_); 1157 model_->Move(current_index, start_drag_index_);
1158 AnimateToIdealBounds(); 1158 AnimateToIdealBounds();
1159 } 1159 }
1160 drag_view_->layer()->SetOpacity(1.0f); 1160 drag_view_->layer()->SetOpacity(1.0f);
1161 } 1161 }
1162 DestroyDragIconProxy(); 1162 DestroyDragIconProxy();
1163 } 1163 }
1164 1164
1165 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) { 1165 ShelfView::RemovableState ShelfView::RemovableByRipOff(int index) const {
1166 DCHECK(index >= 0 && index < model_->item_count()); 1166 DCHECK(index >= 0 && index < model_->item_count());
1167 ShelfItemType type = model_->items()[index].type; 1167 ShelfItemType type = model_->items()[index].type;
1168 if (type == TYPE_APP_LIST || type == TYPE_DIALOG || !delegate_->CanPin()) 1168 if (type == TYPE_APP_LIST || type == TYPE_DIALOG || !delegate_->CanPin())
1169 return NOT_REMOVABLE; 1169 return NOT_REMOVABLE;
1170 1170
1171 std::string app_id = delegate_->GetAppIDForShelfID(model_->items()[index].id); 1171 std::string app_id = delegate_->GetAppIDForShelfID(model_->items()[index].id);
1172 // Note: Only pinned app shortcuts can be removed! 1172 // Note: Only pinned app shortcuts can be removed!
1173 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id)) ? 1173 return (type == TYPE_APP_SHORTCUT && delegate_->IsAppPinned(app_id)) ?
1174 REMOVABLE : DRAGGABLE; 1174 REMOVABLE : DRAGGABLE;
1175 } 1175 }
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1246 if (overflow_button_->visible() && last_visible_index_ >= 0) { 1246 if (overflow_button_->visible() && last_visible_index_ >= 0) {
1247 views::View* last_visible_view = view_model_->view_at(last_visible_index_); 1247 views::View* last_visible_view = view_model_->view_at(last_visible_index_);
1248 last_visible_view->layer()->SetOpacity(0); 1248 last_visible_view->layer()->SetOpacity(0);
1249 bounds_animator_->SetAnimationDelegate( 1249 bounds_animator_->SetAnimationDelegate(
1250 last_visible_view, 1250 last_visible_view,
1251 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view), 1251 new ShelfView::StartFadeAnimationDelegate(this, last_visible_view),
1252 true); 1252 true);
1253 } 1253 }
1254 } 1254 }
1255 1255
1256 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) { 1256 void ShelfView::UpdateOverflowRange(ShelfView* overflow_view) const {
1257 const int first_overflow_index = last_visible_index_ + 1; 1257 const int first_overflow_index = last_visible_index_ + 1;
1258 const int last_overflow_index = last_hidden_index_; 1258 const int last_overflow_index = last_hidden_index_;
1259 DCHECK_LE(first_overflow_index, last_overflow_index); 1259 DCHECK_LE(first_overflow_index, last_overflow_index);
1260 DCHECK_LT(last_overflow_index, view_model_->view_size()); 1260 DCHECK_LT(last_overflow_index, view_model_->view_size());
1261 1261
1262 overflow_view->first_visible_index_ = first_overflow_index; 1262 overflow_view->first_visible_index_ = first_overflow_index;
1263 overflow_view->last_visible_index_ = last_overflow_index; 1263 overflow_view->last_visible_index_ = last_overflow_index;
1264 } 1264 }
1265 1265
1266 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) { 1266 bool ShelfView::ShouldHideTooltip(const gfx::Point& cursor_location) {
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
1349 view_model_->view_at(modified_index) : NULL; 1349 view_model_->view_at(modified_index) : NULL;
1350 model_->Move(drag_view_index, start_drag_index_); 1350 model_->Move(drag_view_index, start_drag_index_);
1351 1351
1352 // If the modified view will be at the end of the list, return the new end of 1352 // If the modified view will be at the end of the list, return the new end of
1353 // the list. 1353 // the list.
1354 if (at_end) 1354 if (at_end)
1355 return view_model_->view_size(); 1355 return view_model_->view_size();
1356 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1; 1356 return modified_view ? view_model_->GetIndexOfView(modified_view) : -1;
1357 } 1357 }
1358 1358
1359 gfx::Size ShelfView::GetPreferredSize() { 1359 gfx::Size ShelfView::GetPreferredSize() const {
1360 IdealBounds ideal_bounds; 1360 IdealBounds ideal_bounds;
1361 CalculateIdealBounds(&ideal_bounds); 1361 CalculateIdealBounds(&ideal_bounds);
1362 1362
1363 int last_button_index = is_overflow_mode() ? 1363 int last_button_index = is_overflow_mode() ?
1364 last_visible_index_ : view_model_->view_size() - 1; 1364 last_visible_index_ : view_model_->view_size() - 1;
1365 1365
1366 // When an item is dragged off from the overflow bubble, it is moved to last 1366 // When an item is dragged off from the overflow bubble, it is moved to last
1367 // position and and changed to invisible. Overflow bubble size should be 1367 // position and and changed to invisible. Overflow bubble size should be
1368 // shrunk to fit only for visible items. 1368 // shrunk to fit only for visible items.
1369 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible 1369 // If |dragged_off_from_overflow_to_shelf_| is set, there will be no invisible
(...skipping 546 matching lines...) Expand 10 before | Expand all | Expand 10 after
1916 distance = bounds.x() - coordinate.x(); 1916 distance = bounds.x() - coordinate.x();
1917 break; 1917 break;
1918 case SHELF_ALIGNMENT_TOP: 1918 case SHELF_ALIGNMENT_TOP:
1919 distance = coordinate.y() - bounds.bottom(); 1919 distance = coordinate.y() - bounds.bottom();
1920 break; 1920 break;
1921 } 1921 }
1922 return distance > 0 ? distance : 0; 1922 return distance > 0 ? distance : 0;
1923 } 1923 }
1924 1924
1925 } // namespace ash 1925 } // namespace ash
OLDNEW
« no previous file with comments | « ash/shelf/shelf_view.h ('k') | ash/shell/lock_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698