| 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 "ui/views/layout/grid_layout.h" | 5 #include "ui/views/layout/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 "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 813 | 813 |
| 814 int GridLayout::GetPreferredHeightForWidth(const View* host, int width) const { | 814 int GridLayout::GetPreferredHeightForWidth(const View* host, int width) const { |
| 815 DCHECK(host_ == host); | 815 DCHECK(host_ == host); |
| 816 gfx::Size pref; | 816 gfx::Size pref; |
| 817 SizeRowsAndColumns(false, width, 0, &pref); | 817 SizeRowsAndColumns(false, width, 0, &pref); |
| 818 return pref.height(); | 818 return pref.height(); |
| 819 } | 819 } |
| 820 | 820 |
| 821 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, | 821 void GridLayout::SizeRowsAndColumns(bool layout, int width, int height, |
| 822 gfx::Size* pref) const { | 822 gfx::Size* pref) const { |
| 823 // Protect against clients asking for metrics during the addition of a View. |
| 824 // The View is in the hierarchy, but it will not be accounted for in the |
| 825 // layout calculations at this point, so the result will be incorrect. |
| 826 DCHECK(!adding_view_) << "GridLayout queried while adding a view."; |
| 827 |
| 823 // Make sure the master columns have been calculated. | 828 // Make sure the master columns have been calculated. |
| 824 CalculateMasterColumnsIfNecessary(); | 829 CalculateMasterColumnsIfNecessary(); |
| 825 pref->SetSize(0, 0); | 830 pref->SetSize(0, 0); |
| 826 if (rows_.empty()) | 831 if (rows_.empty()) |
| 827 return; | 832 return; |
| 828 | 833 |
| 829 // Calculate the preferred width of each of the columns. Some views' | 834 // Calculate the preferred width of each of the columns. Some views' |
| 830 // preferred heights are derived from their width, as such we need to | 835 // preferred heights are derived from their width, as such we need to |
| 831 // calculate the size of the columns first. | 836 // calculate the size of the columns first. |
| 832 for (const auto& column_set : column_sets_) { | 837 for (const auto& column_set : column_sets_) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1021 | 1026 |
| 1022 ColumnSet* GridLayout::GetLastValidColumnSet() { | 1027 ColumnSet* GridLayout::GetLastValidColumnSet() { |
| 1023 for (int i = current_row_ - 1; i >= 0; --i) { | 1028 for (int i = current_row_ - 1; i >= 0; --i) { |
| 1024 if (rows_[i]->column_set()) | 1029 if (rows_[i]->column_set()) |
| 1025 return rows_[i]->column_set(); | 1030 return rows_[i]->column_set(); |
| 1026 } | 1031 } |
| 1027 return nullptr; | 1032 return nullptr; |
| 1028 } | 1033 } |
| 1029 | 1034 |
| 1030 } // namespace views | 1035 } // namespace views |
| OLD | NEW |