summaryrefslogtreecommitdiff
path: root/chromium/ui/views/layout/fill_layout.cc
blob: 731504e23d2b11f849df3c8f25dd5d344d019e2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/views/layout/fill_layout.h"

#include <algorithm>

namespace views {

FillLayout::FillLayout() {}

FillLayout::~FillLayout() {}

void FillLayout::Layout(View* host) {
  if (!host->has_children())
    return;

  for (int i = 0; i < host->child_count(); ++i)
    host->child_at(i)->SetBoundsRect(host->GetContentsBounds());
}

gfx::Size FillLayout::GetPreferredSize(const View* host) const {
  if (!host->has_children())
    return gfx::Size();

  gfx::Size preferred_size;
  for (int i = 0; i < host->child_count(); ++i)
    preferred_size.SetToMax(host->child_at(i)->GetPreferredSize());
  gfx::Rect rect(preferred_size);
  rect.Inset(-host->GetInsets());
  return rect.size();
}

int FillLayout::GetPreferredHeightForWidth(const View* host, int width) const {
  if (!host->has_children())
    return 0;

  const gfx::Insets insets = host->GetInsets();
  int preferred_height = 0;
  for (int i = 0; i < host->child_count(); ++i) {
    int cur_preferred_height = 0;
    cur_preferred_height =
        host->child_at(i)->GetHeightForWidth(width - insets.width()) +
        insets.height();
    preferred_height = std::max(preferred_height, cur_preferred_height);
  }
  return preferred_height;
}

}  // namespace views