OLD | NEW |
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 745 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
756 } | 756 } |
757 | 757 |
758 void GridLayout::ViewRemoved(View* host, View* view) { | 758 void GridLayout::ViewRemoved(View* host, View* view) { |
759 DCHECK(host_ == host); | 759 DCHECK(host_ == host); |
760 } | 760 } |
761 | 761 |
762 void GridLayout::Layout(View* host) { | 762 void GridLayout::Layout(View* host) { |
763 DCHECK(host_ == host); | 763 DCHECK(host_ == host); |
764 // SizeRowsAndColumns sets the size and location of each row/column, but | 764 // SizeRowsAndColumns sets the size and location of each row/column, but |
765 // not of the views. | 765 // not of the views. |
766 CSize pref; | 766 gfx::Size pref; |
767 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref); | 767 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref); |
768 | 768 |
769 // Size each view. | 769 // Size each view. |
770 for (std::vector<ViewState*>::iterator i = view_states_.begin(); | 770 for (std::vector<ViewState*>::iterator i = view_states_.begin(); |
771 i != view_states_.end(); ++i) { | 771 i != view_states_.end(); ++i) { |
772 ViewState* view_state = *i; | 772 ViewState* view_state = *i; |
773 ColumnSet* column_set = view_state->column_set; | 773 ColumnSet* column_set = view_state->column_set; |
774 View* view = (*i)->view; | 774 View* view = (*i)->view; |
775 DCHECK(view); | 775 DCHECK(view); |
776 int x = column_set->columns_[view_state->start_col]->Location() + | 776 int x = column_set->columns_[view_state->start_col]->Location() + |
777 left_inset_; | 777 left_inset_; |
778 int width = column_set->GetColumnWidth(view_state->start_col, | 778 int width = column_set->GetColumnWidth(view_state->start_col, |
779 view_state->col_span); | 779 view_state->col_span); |
780 CalculateSize(view_state->pref_width, view_state->h_align, | 780 CalculateSize(view_state->pref_width, view_state->h_align, |
781 &x, &width); | 781 &x, &width); |
782 int y = rows_[view_state->start_row]->Location() + top_inset_; | 782 int y = rows_[view_state->start_row]->Location() + top_inset_; |
783 int height = LayoutElement::TotalSize(view_state->start_row, | 783 int height = LayoutElement::TotalSize(view_state->start_row, |
784 view_state->row_span, &rows_); | 784 view_state->row_span, &rows_); |
785 CalculateSize(view_state->pref_height, view_state->v_align, | 785 CalculateSize(view_state->pref_height, view_state->v_align, |
786 &y, &height); | 786 &y, &height); |
787 view->SetBounds(x, y, width, height); | 787 view->SetBounds(x, y, width, height); |
788 } | 788 } |
789 } | 789 } |
790 | 790 |
791 gfx::Size GridLayout::GetPreferredSize(View* host) { | 791 gfx::Size GridLayout::GetPreferredSize(View* host) { |
792 DCHECK(host_ == host); | 792 DCHECK(host_ == host); |
793 CSize out; | 793 gfx::Size out; |
794 SizeRowsAndColumns(false, 0, 0, &out); | 794 SizeRowsAndColumns(false, 0, 0, &out); |
795 return gfx::Size(out.cx, out.cy); | 795 return out; |
796 } | 796 } |
797 | 797 |
798 int GridLayout::GetPreferredHeightForWidth(View* host, int width) { | 798 int GridLayout::GetPreferredHeightForWidth(View* host, int width) { |
799 DCHECK(host_ == host); | 799 DCHECK(host_ == host); |
800 CSize pref; | 800 gfx::Size pref; |
801 SizeRowsAndColumns(false, width, 0, &pref); | 801 SizeRowsAndColumns(false, width, 0, &pref); |
802 return pref.cy; | 802 return pref.height(); |
803 } | 803 } |
804 | 804 |
805 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, | 805 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, |
806 CSize* pref) { | 806 gfx::Size* pref) { |
807 // Make sure the master columns have been calculated. | 807 // Make sure the master columns have been calculated. |
808 CalculateMasterColumnsIfNecessary(); | 808 CalculateMasterColumnsIfNecessary(); |
809 pref->cx = pref->cy = 0; | 809 pref->SetSize(0, 0); |
810 if (rows_.empty()) | 810 if (rows_.empty()) |
811 return; | 811 return; |
812 | 812 |
813 // Calculate the size of each of the columns. Some views preferred heights are | 813 // Calculate the size of each of the columns. Some views preferred heights are |
814 // derived from their width, as such we need to calculate the size of the | 814 // derived from their width, as such we need to calculate the size of the |
815 // columns first. | 815 // columns first. |
816 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); | 816 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); |
817 i != column_sets_.end(); ++i) { | 817 i != column_sets_.end(); ++i) { |
818 (*i)->CalculateSize(); | 818 (*i)->CalculateSize(); |
819 if (layout || width > 0) { | 819 if (layout || width > 0) { |
820 // We're doing a layout, divy up any extra space. | 820 // We're doing a layout, divy up any extra space. |
821 (*i)->Resize(width - (*i)->LayoutWidth() - left_inset_ - right_inset_); | 821 (*i)->Resize(width - (*i)->LayoutWidth() - left_inset_ - right_inset_); |
822 // And reset the x coordinates. | 822 // And reset the x coordinates. |
823 (*i)->ResetColumnXCoordinates(); | 823 (*i)->ResetColumnXCoordinates(); |
824 } | 824 } |
825 pref->cx = std::max(static_cast<int>(pref->cx), (*i)->LayoutWidth()); | 825 pref->set_width(std::max(pref->width(), (*i)->LayoutWidth())); |
826 } | 826 } |
827 pref->cx += left_inset_ + right_inset_; | 827 pref->set_width(pref->width() + left_inset_ + right_inset_); |
828 | 828 |
829 // Reset the height of each row. | 829 // Reset the height of each row. |
830 LayoutElement::ResetSizes(&rows_); | 830 LayoutElement::ResetSizes(&rows_); |
831 | 831 |
832 // Do two things: | 832 // Do two things: |
833 // . Reset the remaining_height of each view state. | 833 // . Reset the remaining_height of each view state. |
834 // . If the width the view will be given is different than it's pref, ask | 834 // . If the width the view will be given is different than it's pref, ask |
835 // for the height given a particularly width. | 835 // for the height given a particularly width. |
836 for (std::vector<ViewState*>::iterator i= view_states_.begin(); | 836 for (std::vector<ViewState*>::iterator i= view_states_.begin(); |
837 i != view_states_.end() ; ++i) { | 837 i != view_states_.end() ; ++i) { |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 UpdateRemainingHeightFromRows(view_state); | 872 UpdateRemainingHeightFromRows(view_state); |
873 | 873 |
874 // Distribute the remaining height. | 874 // Distribute the remaining height. |
875 DistributeRemainingHeight(view_state); | 875 DistributeRemainingHeight(view_state); |
876 } | 876 } |
877 | 877 |
878 // Update the location of each of the rows. | 878 // Update the location of each of the rows. |
879 LayoutElement::CalculateLocationsFromSize(&rows_); | 879 LayoutElement::CalculateLocationsFromSize(&rows_); |
880 | 880 |
881 // We now know the preferred height, set it here. | 881 // We now know the preferred height, set it here. |
882 pref->cy = rows_[rows_.size() - 1]->Location() + | 882 pref->set_height(rows_[rows_.size() - 1]->Location() + |
883 rows_[rows_.size() - 1]->Size() + top_inset_ + bottom_inset_; | 883 rows_[rows_.size() - 1]->Size() + top_inset_ + bottom_inset_); |
884 | 884 |
885 if (layout && height != pref->cy) { | 885 if (layout && height != pref->height()) { |
886 // We're doing a layout, and the height differs from the preferred height, | 886 // We're doing a layout, and the height differs from the preferred height, |
887 // divy up the extra space. | 887 // divy up the extra space. |
888 LayoutElement::DistributeDelta(height - pref->cy, &rows_); | 888 LayoutElement::DistributeDelta(height - pref->height(), &rows_); |
889 | 889 |
890 // Reset y locations. | 890 // Reset y locations. |
891 LayoutElement::CalculateLocationsFromSize(&rows_); | 891 LayoutElement::CalculateLocationsFromSize(&rows_); |
892 } | 892 } |
893 } | 893 } |
894 | 894 |
895 void GridLayout::CalculateMasterColumnsIfNecessary() { | 895 void GridLayout::CalculateMasterColumnsIfNecessary() { |
896 if (!calculated_master_columns_) { | 896 if (!calculated_master_columns_) { |
897 calculated_master_columns_ = true; | 897 calculated_master_columns_ = true; |
898 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); | 898 for (std::vector<ColumnSet*>::iterator i = column_sets_.begin(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1005 ColumnSet* GridLayout::GetLastValidColumnSet() { | 1005 ColumnSet* GridLayout::GetLastValidColumnSet() { |
1006 for (int i = current_row_ - 1; i >= 0; --i) { | 1006 for (int i = current_row_ - 1; i >= 0; --i) { |
1007 if (rows_[i]->column_set()) | 1007 if (rows_[i]->column_set()) |
1008 return rows_[i]->column_set(); | 1008 return rows_[i]->column_set(); |
1009 } | 1009 } |
1010 return NULL; | 1010 return NULL; |
1011 } | 1011 } |
1012 | 1012 |
1013 } // namespace views | 1013 } // namespace views |
1014 | 1014 |
OLD | NEW |