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

Side by Side Diff: ui/views/layout/grid_layout.cc

Issue 2859193004: Remove GridLayout::SetInsets in favor of an empty border on the host. (Closed)
Patch Set: missed a merge problem Created 3 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
« no previous file with comments | « ui/views/layout/grid_layout.h ('k') | ui/views/layout/grid_layout_unittest.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 "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"
11 #include "base/memory/ptr_util.h" 11 #include "base/memory/ptr_util.h"
12 #include "ui/views/border.h"
12 #include "ui/views/layout/layout_constants.h" 13 #include "ui/views/layout/layout_constants.h"
13 #include "ui/views/layout/layout_provider.h" 14 #include "ui/views/layout/layout_provider.h"
14 #include "ui/views/view.h" 15 #include "ui/views/view.h"
15 #include "ui/views/window/dialog_delegate.h" 16 #include "ui/views/window/dialog_delegate.h"
16 17
17 namespace views { 18 namespace views {
18 19
19 // LayoutElement ------------------------------------------------------ 20 // LayoutElement ------------------------------------------------------
20 21
21 // A LayoutElement has a size and location along one axis. It contains 22 // A LayoutElement has a size and location along one axis. It contains
(...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after
645 adding_view_(false) { 646 adding_view_(false) {
646 DCHECK(host); 647 DCHECK(host);
647 } 648 }
648 649
649 GridLayout::~GridLayout() { 650 GridLayout::~GridLayout() {
650 } 651 }
651 652
652 // static 653 // static
653 GridLayout* GridLayout::CreatePanel(View* host) { 654 GridLayout* GridLayout::CreatePanel(View* host) {
654 GridLayout* layout = new GridLayout(host); 655 GridLayout* layout = new GridLayout(host);
655 layout->SetInsets(LayoutProvider::Get()->GetInsetsMetric(INSETS_PANEL)); 656 host->SetBorder(
657 CreateEmptyBorder(LayoutProvider::Get()->GetInsetsMetric(INSETS_PANEL)));
656 host->SetLayoutManager(layout); 658 host->SetLayoutManager(layout);
657 return layout; 659 return layout;
658 } 660 }
659 661
660 void GridLayout::SetInsets(int top, int left, int bottom, int right) {
661 insets_.Set(top, left, bottom, right);
662 }
663
664 void GridLayout::SetInsets(const gfx::Insets& insets) {
665 insets_ = insets;
666 }
667
668 ColumnSet* GridLayout::AddColumnSet(int id) { 662 ColumnSet* GridLayout::AddColumnSet(int id) {
669 DCHECK(GetColumnSet(id) == nullptr); 663 DCHECK(GetColumnSet(id) == nullptr);
670 column_sets_.push_back(base::WrapUnique(new ColumnSet(id))); 664 column_sets_.push_back(base::WrapUnique(new ColumnSet(id)));
671 return column_sets_.back().get(); 665 return column_sets_.back().get();
672 } 666 }
673 667
674 ColumnSet* GridLayout::GetColumnSet(int id) { 668 ColumnSet* GridLayout::GetColumnSet(int id) {
675 for (const auto& column_set : column_sets_) { 669 for (const auto& column_set : column_sets_) {
676 if (column_set->id_ == id) { 670 if (column_set->id_ == id) {
677 return column_set.get(); 671 return column_set.get();
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 // SizeRowsAndColumns sets the size and location of each row/column, but 771 // SizeRowsAndColumns sets the size and location of each row/column, but
778 // not of the views. 772 // not of the views.
779 gfx::Size pref; 773 gfx::Size pref;
780 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref); 774 SizeRowsAndColumns(true, host_->width(), host_->height(), &pref);
781 775
782 // Size each view. 776 // Size each view.
783 for (const auto& view_state : view_states_) { 777 for (const auto& view_state : view_states_) {
784 ColumnSet* column_set = view_state->column_set; 778 ColumnSet* column_set = view_state->column_set;
785 View* view = view_state->view; 779 View* view = view_state->view;
786 DCHECK(view); 780 DCHECK(view);
787 int x = column_set->columns_[view_state->start_col]->Location() + 781 const gfx::Insets& insets = host_->GetInsets();
788 insets_.left(); 782 int x =
783 column_set->columns_[view_state->start_col]->Location() + insets.left();
789 int width = column_set->GetColumnWidth(view_state->start_col, 784 int width = column_set->GetColumnWidth(view_state->start_col,
790 view_state->col_span); 785 view_state->col_span);
791 CalculateSize(view_state->pref_width, view_state->h_align, 786 CalculateSize(view_state->pref_width, view_state->h_align,
792 &x, &width); 787 &x, &width);
793 int y = rows_[view_state->start_row]->Location() + insets_.top(); 788 int y = rows_[view_state->start_row]->Location() + insets.top();
794 int height = LayoutElement::TotalSize(view_state->start_row, 789 int height = LayoutElement::TotalSize(view_state->start_row,
795 view_state->row_span, &rows_); 790 view_state->row_span, &rows_);
796 if (view_state->v_align == BASELINE && view_state->baseline != -1) { 791 if (view_state->v_align == BASELINE && view_state->baseline != -1) {
797 y += rows_[view_state->start_row]->max_ascent() - view_state->baseline; 792 y += rows_[view_state->start_row]->max_ascent() - view_state->baseline;
798 height = view_state->pref_height; 793 height = view_state->pref_height;
799 } else { 794 } else {
800 CalculateSize(view_state->pref_height, view_state->v_align, &y, &height); 795 CalculateSize(view_state->pref_height, view_state->v_align, &y, &height);
801 } 796 }
802 view->SetBounds(x, y, width, height); 797 view->SetBounds(x, y, width, height);
803 } 798 }
(...skipping 28 matching lines...) Expand all
832 if (rows_.empty()) 827 if (rows_.empty())
833 return; 828 return;
834 829
835 // Calculate the preferred width of each of the columns. Some views' 830 // Calculate the preferred width of each of the columns. Some views'
836 // preferred heights are derived from their width, as such we need to 831 // preferred heights are derived from their width, as such we need to
837 // calculate the size of the columns first. 832 // calculate the size of the columns first.
838 for (const auto& column_set : column_sets_) { 833 for (const auto& column_set : column_sets_) {
839 column_set->CalculateSize(); 834 column_set->CalculateSize();
840 pref->set_width(std::max(pref->width(), column_set->LayoutWidth())); 835 pref->set_width(std::max(pref->width(), column_set->LayoutWidth()));
841 } 836 }
842 pref->set_width(pref->width() + insets_.width()); 837 const gfx::Insets& insets = host_->GetInsets();
838 pref->set_width(pref->width() + insets.width());
843 839
844 // Go over the columns again and set them all to the size we settled for. 840 // Go over the columns again and set them all to the size we settled for.
845 width = width ? width : pref->width(); 841 width = width ? width : pref->width();
846 for (const auto& column_set : column_sets_) { 842 for (const auto& column_set : column_sets_) {
847 // We're doing a layout, divvy up any extra space. 843 // We're doing a layout, divvy up any extra space.
848 column_set->Resize(width - column_set->LayoutWidth() - insets_.left() - 844 column_set->Resize(width - column_set->LayoutWidth() - insets.left() -
849 insets_.right()); 845 insets.right());
850 // And reset the x coordinates. 846 // And reset the x coordinates.
851 column_set->ResetColumnXCoordinates(); 847 column_set->ResetColumnXCoordinates();
852 } 848 }
853 849
854 // Reset the height of each row. 850 // Reset the height of each row.
855 LayoutElement::ResetSizes(&rows_); 851 LayoutElement::ResetSizes(&rows_);
856 852
857 // Do the following: 853 // Do the following:
858 // . If the view is aligned along it's baseline, obtain the baseline from the 854 // . If the view is aligned along it's baseline, obtain the baseline from the
859 // view and update the rows ascent/descent. 855 // view and update the rows ascent/descent.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 903
908 // Distribute the remaining height. 904 // Distribute the remaining height.
909 DistributeRemainingHeight(view_state); 905 DistributeRemainingHeight(view_state);
910 } 906 }
911 907
912 // Update the location of each of the rows. 908 // Update the location of each of the rows.
913 LayoutElement::CalculateLocationsFromSize(&rows_); 909 LayoutElement::CalculateLocationsFromSize(&rows_);
914 910
915 // We now know the preferred height, set it here. 911 // We now know the preferred height, set it here.
916 pref->set_height(rows_.back()->Location() + rows_.back()->Size() + 912 pref->set_height(rows_.back()->Location() + rows_.back()->Size() +
917 insets_.height()); 913 insets.height());
918 914
919 if (layout && height != pref->height()) { 915 if (layout && height != pref->height()) {
920 // We're doing a layout, and the height differs from the preferred height, 916 // We're doing a layout, and the height differs from the preferred height,
921 // divvy up the extra space. 917 // divvy up the extra space.
922 LayoutElement::DistributeDelta(height - pref->height(), &rows_); 918 LayoutElement::DistributeDelta(height - pref->height(), &rows_);
923 919
924 // Reset y locations. 920 // Reset y locations.
925 LayoutElement::CalculateLocationsFromSize(&rows_); 921 LayoutElement::CalculateLocationsFromSize(&rows_);
926 } 922 }
927 } 923 }
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
1027 1023
1028 ColumnSet* GridLayout::GetLastValidColumnSet() { 1024 ColumnSet* GridLayout::GetLastValidColumnSet() {
1029 for (int i = current_row_ - 1; i >= 0; --i) { 1025 for (int i = current_row_ - 1; i >= 0; --i) {
1030 if (rows_[i]->column_set()) 1026 if (rows_[i]->column_set())
1031 return rows_[i]->column_set(); 1027 return rows_[i]->column_set();
1032 } 1028 }
1033 return nullptr; 1029 return nullptr;
1034 } 1030 }
1035 1031
1036 } // namespace views 1032 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/layout/grid_layout.h ('k') | ui/views/layout/grid_layout_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698