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

Side by Side Diff: chrome/views/grid_layout.cc

Issue 7344: Convert GetPreferredSize from:... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 2 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
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "chrome/views/grid_layout.h" 5 #include "chrome/views/grid_layout.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "chrome/views/view.h" 10 #include "chrome/views/view.h"
(...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after
564 564
565 int ColumnSet::GetColumnWidth(int start_col, int col_span) { 565 int ColumnSet::GetColumnWidth(int start_col, int col_span) {
566 return LayoutElement::TotalSize(start_col, col_span, &columns_); 566 return LayoutElement::TotalSize(start_col, col_span, &columns_);
567 } 567 }
568 568
569 void ColumnSet::ResetColumnXCoordinates() { 569 void ColumnSet::ResetColumnXCoordinates() {
570 LayoutElement::CalculateLocationsFromSize(&columns_); 570 LayoutElement::CalculateLocationsFromSize(&columns_);
571 } 571 }
572 572
573 void ColumnSet::CalculateSize() { 573 void ColumnSet::CalculateSize() {
574 CSize pref; 574 gfx::Size pref;
575 // Reset the preferred and remaining sizes. 575 // Reset the preferred and remaining sizes.
576 for (std::vector<ViewState*>::iterator i = view_states_.begin(); 576 for (std::vector<ViewState*>::iterator i = view_states_.begin();
577 i != view_states_.end(); ++i) { 577 i != view_states_.end(); ++i) {
578 ViewState* view_state = *i; 578 ViewState* view_state = *i;
579 pref.cx = pref.cy = 0;
580 if (!view_state->pref_width_fixed || !view_state->pref_height_fixed) { 579 if (!view_state->pref_width_fixed || !view_state->pref_height_fixed) {
581 view_state->view->GetPreferredSize(&pref); 580 pref = view_state->view->GetPreferredSize();
582 if (!view_state->pref_width_fixed) 581 if (!view_state->pref_width_fixed)
583 view_state->pref_width = pref.cx; 582 view_state->pref_width = pref.width();
584 if (!view_state->pref_height_fixed) 583 if (!view_state->pref_height_fixed)
585 view_state->pref_height = pref.cy; 584 view_state->pref_height = pref.height();
586 } 585 }
587 view_state->remaining_width = pref.cx; 586 view_state->remaining_width = pref.width();
588 view_state->remaining_height = pref.cy; 587 view_state->remaining_height = pref.height();
589 } 588 }
590 589
591 // Let layout element reset the sizes for us. 590 // Let layout element reset the sizes for us.
592 LayoutElement::ResetSizes(&columns_); 591 LayoutElement::ResetSizes(&columns_);
593 592
594 // Distribute the size of each view with a col span == 1. 593 // Distribute the size of each view with a col span == 1.
595 std::vector<ViewState*>::iterator view_state_iterator = 594 std::vector<ViewState*>::iterator view_state_iterator =
596 view_states_.begin(); 595 view_states_.begin();
597 for (; view_state_iterator != view_states_.end() && 596 for (; view_state_iterator != view_states_.end() &&
598 (*view_state_iterator)->col_span == 1; ++view_state_iterator) { 597 (*view_state_iterator)->col_span == 1; ++view_state_iterator) {
(...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after
782 &x, &width); 781 &x, &width);
783 int y = rows_[view_state->start_row]->Location() + top_inset_; 782 int y = rows_[view_state->start_row]->Location() + top_inset_;
784 int height = LayoutElement::TotalSize(view_state->start_row, 783 int height = LayoutElement::TotalSize(view_state->start_row,
785 view_state->row_span, &rows_); 784 view_state->row_span, &rows_);
786 CalculateSize(view_state->pref_height, view_state->v_align, 785 CalculateSize(view_state->pref_height, view_state->v_align,
787 &y, &height); 786 &y, &height);
788 view->SetBounds(x, y, width, height); 787 view->SetBounds(x, y, width, height);
789 } 788 }
790 } 789 }
791 790
792 void GridLayout::GetPreferredSize(View* host, CSize* out) { 791 gfx::Size GridLayout::GetPreferredSize(View* host) {
793 DCHECK(host_ == host); 792 DCHECK(host_ == host);
794 SizeRowsAndColumns(false, 0, 0, out); 793 CSize out;
794 SizeRowsAndColumns(false, 0, 0, &out);
795 return gfx::Size(out.cx, out.cy);
795 } 796 }
796 797
797 int GridLayout::GetPreferredHeightForWidth(View* host, int width) { 798 int GridLayout::GetPreferredHeightForWidth(View* host, int width) {
798 DCHECK(host_ == host); 799 DCHECK(host_ == host);
799 CSize pref; 800 CSize pref;
800 SizeRowsAndColumns(false, width, 0, &pref); 801 SizeRowsAndColumns(false, width, 0, &pref);
801 return pref.cy; 802 return pref.cy;
802 } 803 }
803 804
804 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, 805 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height,
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
1004 ColumnSet* GridLayout::GetLastValidColumnSet() { 1005 ColumnSet* GridLayout::GetLastValidColumnSet() {
1005 for (int i = current_row_ - 1; i >= 0; --i) { 1006 for (int i = current_row_ - 1; i >= 0; --i) {
1006 if (rows_[i]->column_set()) 1007 if (rows_[i]->column_set())
1007 return rows_[i]->column_set(); 1008 return rows_[i]->column_set();
1008 } 1009 }
1009 return NULL; 1010 return NULL;
1010 } 1011 }
1011 1012
1012 } // namespace 1013 } // namespace
1013 1014
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698