summaryrefslogtreecommitdiffstats
path: root/views/box_layout.cc
diff options
context:
space:
mode:
authormnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-06 07:48:58 +0000
committermnissler@chromium.org <mnissler@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-06 07:48:58 +0000
commit0af29d8cedd97d4604619dd4ab2b5e0a0805ecb1 (patch)
tree3c9f00670a268464b963443a7de96728fb32e0be /views/box_layout.cc
parent6e094094ed8b96e68b30e8628e8a169719edda27 (diff)
downloadchromium_src-0af29d8cedd97d4604619dd4ab2b5e0a0805ecb1.zip
chromium_src-0af29d8cedd97d4604619dd4ab2b5e0a0805ecb1.tar.gz
chromium_src-0af29d8cedd97d4604619dd4ab2b5e0a0805ecb1.tar.bz2
Display warning banner in Win preferences dialog for managed options.
BUG=43423 TEST=box_layout_unittest.cc, manual UI tests. Review URL: http://codereview.chromium.org/2738002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@51655 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/box_layout.cc')
-rw-r--r--views/box_layout.cc66
1 files changed, 66 insertions, 0 deletions
diff --git a/views/box_layout.cc b/views/box_layout.cc
new file mode 100644
index 0000000..84fb096
--- /dev/null
+++ b/views/box_layout.cc
@@ -0,0 +1,66 @@
+// Copyright (c) 2010 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 "views/box_layout.h"
+
+namespace views {
+
+BoxLayout::BoxLayout(BoxLayout::Orientation orientation,
+ int inside_border_spacing,
+ int between_child_spacing)
+ : orientation_(orientation),
+ inside_border_spacing_(inside_border_spacing),
+ between_child_spacing_(between_child_spacing) {
+}
+
+void BoxLayout::Layout(View* host) {
+ gfx::Rect childArea(gfx::Rect(host->size()));
+ childArea.Inset(host->GetInsets());
+ childArea.Inset(inside_border_spacing_, inside_border_spacing_);
+ int x = childArea.x();
+ int y = childArea.y();
+ for (int i = 0; i < host->GetChildViewCount(); ++i) {
+ View* child = host->GetChildViewAt(i);
+ if (child->IsVisible()) {
+ gfx::Rect bounds(x, y, childArea.width(), childArea.height());
+ gfx::Size size(child->GetPreferredSize());
+ if (orientation_ == kHorizontal) {
+ bounds.set_width(size.width());
+ x += size.width() + between_child_spacing_;
+ } else {
+ bounds.set_height(size.height());
+ y += size.height() + between_child_spacing_;
+ }
+ // Clamp child view bounds to |childArea|.
+ child->SetBounds(bounds.Intersect(childArea));
+ }
+ }
+}
+
+gfx::Size BoxLayout::GetPreferredSize(View* host) {
+ gfx::Rect bounds;
+ int position = 0;
+ for (int i = 0; i < host->GetChildViewCount(); ++i) {
+ View* child = host->GetChildViewAt(i);
+ if (child->IsVisible()) {
+ gfx::Size size(child->GetPreferredSize());
+ if (orientation_ == kHorizontal) {
+ gfx::Rect child_bounds(position, 0, size.width(), size.height());
+ bounds = bounds.Union(child_bounds);
+ position += size.width();
+ } else {
+ gfx::Rect child_bounds(0, position, size.width(), size.height());
+ bounds = bounds.Union(child_bounds);
+ position += size.height();
+ }
+ position += between_child_spacing_;
+ }
+ }
+ gfx::Insets insets(host->GetInsets());
+ return
+ gfx::Size(bounds.width() + insets.width() + 2 * inside_border_spacing_,
+ bounds.height() + insets.height() + 2 * inside_border_spacing_);
+}
+
+} // namespace views