summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--chrome/browser/gtk/options/general_page_gtk.cc10
-rw-r--r--chrome/browser/views/options/general_page_view.cc15
-rw-r--r--chrome/browser/views/options/managed_prefs_banner_view.cc71
-rw-r--r--chrome/browser/views/options/managed_prefs_banner_view.h54
-rw-r--r--chrome/chrome_browser.gypi2
-rw-r--r--chrome/chrome_tests.gypi1
-rw-r--r--gfx/gfx.gyp1
-rw-r--r--gfx/rect.cc5
-rw-r--r--gfx/rect.h5
-rw-r--r--views/box_layout.cc66
-rw-r--r--views/box_layout.h50
-rw-r--r--views/box_layout_unittest.cc108
-rw-r--r--views/examples/box_layout.cc37
-rw-r--r--views/examples/box_layout.h40
-rw-r--r--views/examples/widget_example.h10
-rw-r--r--views/views.gyp4
16 files changed, 392 insertions, 87 deletions
diff --git a/chrome/browser/gtk/options/general_page_gtk.cc b/chrome/browser/gtk/options/general_page_gtk.cc
index b522561..80327cc 100644
--- a/chrome/browser/gtk/options/general_page_gtk.cc
+++ b/chrome/browser/gtk/options/general_page_gtk.cc
@@ -56,8 +56,9 @@ enum {
SEARCH_ENGINES_COL_COUNT,
};
-// Set of preferences which might be unavailable for editing when managed.
-const wchar_t* kGeneralManagablePrefs[] = {
+// All general preferences that are potentially managed by policy. We'll
+// display the warning banner if one of these have the managed bit set.
+static const wchar_t* kGeneralPolicyConstrainedPrefs[] = {
prefs::kHomePage,
prefs::kHomePageIsNewTabPage
};
@@ -74,8 +75,9 @@ GeneralPageGtk::GeneralPageGtk(Profile* profile)
initializing_(true),
default_browser_worker_(
new ShellIntegration::DefaultBrowserWorker(this)),
- managed_prefs_banner_(profile->GetPrefs(), kGeneralManagablePrefs,
- arraysize(kGeneralManagablePrefs)) {
+ managed_prefs_banner_(profile->GetPrefs(),
+ kGeneralPolicyConstrainedPrefs,
+ arraysize(kGeneralPolicyConstrainedPrefs)) {
scoped_ptr<OptionsLayoutBuilderGtk>
options_builder(OptionsLayoutBuilderGtk::CreateOptionallyCompactLayout());
page_ = options_builder->get_page_widget();
diff --git a/chrome/browser/views/options/general_page_view.cc b/chrome/browser/views/options/general_page_view.cc
index f836ea4..d7c36a7 100644
--- a/chrome/browser/views/options/general_page_view.cc
+++ b/chrome/browser/views/options/general_page_view.cc
@@ -19,6 +19,7 @@
#include "chrome/browser/search_engines/template_url.h"
#include "chrome/browser/search_engines/template_url_model.h"
#include "chrome/browser/views/keyword_editor_view.h"
+#include "chrome/browser/views/options/managed_prefs_banner_view.h"
#include "chrome/browser/views/options/options_group_view.h"
#include "chrome/common/chrome_constants.h"
#include "chrome/common/pref_names.h"
@@ -43,6 +44,13 @@ const SkColor kDefaultBrowserLabelColor = SkColorSetRGB(0, 135, 0);
const SkColor kNotDefaultBrowserLabelColor = SkColorSetRGB(135, 0, 0);
const int kHomePageTextfieldWidthChars = 40;
+// All general preferences that are potentially managed by policy. We'll
+// display the warning banner if one of these have the managed bit set.
+const wchar_t* kGeneralPolicyConstrainedPrefs[] = {
+ prefs::kHomePage,
+ prefs::kHomePageIsNewTabPage
+};
+
} // namespace
///////////////////////////////////////////////////////////////////////////////
@@ -307,6 +315,13 @@ void GeneralPageView::InitControlLayout() {
ColumnSet* column_set = layout->AddColumnSet(single_column_view_set_id);
column_set->AddColumn(GridLayout::FILL, GridLayout::FILL, 1,
GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, single_column_view_set_id);
+ layout->AddView(
+ new ManagedPrefsBannerView(profile()->GetPrefs(),
+ kGeneralPolicyConstrainedPrefs,
+ arraysize(kGeneralPolicyConstrainedPrefs)));
+
layout->StartRow(0, single_column_view_set_id);
InitStartupGroup();
layout->AddView(startup_group_);
diff --git a/chrome/browser/views/options/managed_prefs_banner_view.cc b/chrome/browser/views/options/managed_prefs_banner_view.cc
new file mode 100644
index 0000000..020617c
--- /dev/null
+++ b/chrome/browser/views/options/managed_prefs_banner_view.cc
@@ -0,0 +1,71 @@
+// 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 "chrome/browser/views/options/managed_prefs_banner_view.h"
+
+#include "app/resource_bundle.h"
+#include "gfx/color_utils.h"
+#include "grit/generated_resources.h"
+#include "grit/theme_resources.h"
+#include "views/box_layout.h"
+#include "views/controls/image_view.h"
+#include "views/controls/label.h"
+#include "views/standard_layout.h"
+
+// Spacing between the banner frame and its contents.
+static const int kPrefsBannerPadding = 3;
+// Width of the banner frame.
+static const int kPrefsBannerBorderSize = 1;
+
+ManagedPrefsBannerView::ManagedPrefsBannerView(PrefService* prefs,
+ const wchar_t** relevant_prefs,
+ size_t count)
+ : ManagedPrefsBannerBase(prefs, relevant_prefs, count) {
+ content_ = new views::View;
+ SkColor border_color = color_utils::GetSysSkColor(COLOR_3DSHADOW);
+ views::Border* border = views::Border::CreateSolidBorder(
+ kPrefsBannerBorderSize, border_color);
+ content_->set_border(border);
+
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ warning_image_ = new views::ImageView();
+ warning_image_->SetImage(rb.GetBitmapNamed(IDR_WARNING));
+ label_ = new views::Label(rb.GetLocalizedString(IDS_OPTIONS_MANAGED_PREFS));
+}
+
+void ManagedPrefsBannerView::Init() {
+ AddChildView(content_);
+ content_->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal,
+ kPrefsBannerPadding,
+ kRelatedControlSmallHorizontalSpacing));
+ content_->AddChildView(warning_image_);
+ content_->AddChildView(label_);
+ OnUpdateVisibility();
+}
+
+gfx::Size ManagedPrefsBannerView::GetPreferredSize() {
+ if (!IsVisible())
+ return gfx::Size();
+
+ // Add space below the banner.
+ gfx::Size size(content_->GetPreferredSize());
+ size.Enlarge(0, kRelatedControlVerticalSpacing);
+ return size;
+}
+
+void ManagedPrefsBannerView::Layout() {
+ content_->SetBounds(0, 0, width(), height() - kRelatedControlVerticalSpacing);
+}
+
+void ManagedPrefsBannerView::ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) {
+ if (is_add && child == this)
+ Init();
+}
+
+void ManagedPrefsBannerView::OnUpdateVisibility() {
+ SetVisible(DetermineVisibility());
+}
diff --git a/chrome/browser/views/options/managed_prefs_banner_view.h b/chrome/browser/views/options/managed_prefs_banner_view.h
new file mode 100644
index 0000000..60c9953
--- /dev/null
+++ b/chrome/browser/views/options/managed_prefs_banner_view.h
@@ -0,0 +1,54 @@
+// 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.
+
+#ifndef CHROME_BROWSER_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_
+#define CHROME_BROWSER_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_
+
+#include "chrome/browser/managed_prefs_banner_base.h"
+#include "views/view.h"
+
+namespace views {
+class ImageView;
+class Label;
+}
+
+// Displays a banner showing a warning message that tells the user some options
+// cannot be changed because the relevant preferences are managed by their
+// system administrator.
+class ManagedPrefsBannerView : public ManagedPrefsBannerBase,
+ public views::View {
+ public:
+ // Initialize the banner. |relevant_prefs| is an array of |count| prefs
+ // holding names of the preferences that control the banner visibility
+ // through their managed flag.
+ ManagedPrefsBannerView(PrefService* pref_service,
+ const wchar_t** relevant_prefs,
+ size_t count);
+ virtual ~ManagedPrefsBannerView() {}
+
+ private:
+ // Initialize contents and layout.
+ void Init();
+
+ // views::View overrides.
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child);
+
+ // ManagedPrefsBannerBase override.
+ virtual void OnUpdateVisibility();
+
+ // Holds the warning icon image and text label and renders the border.
+ views::View* content_;
+ // Warning icon image.
+ views::ImageView* warning_image_;
+ // The label responsible for rendering the warning text.
+ views::Label* label_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(ManagedPrefsBannerView);
+};
+
+#endif // CHROME_BROWSER_VIEWS_OPTIONS_MANAGED_PREFS_BANNER_VIEW_H_
diff --git a/chrome/chrome_browser.gypi b/chrome/chrome_browser.gypi
index 6aa8a5cd..4e07e6d 100644
--- a/chrome/chrome_browser.gypi
+++ b/chrome/chrome_browser.gypi
@@ -2582,6 +2582,8 @@
'browser/views/options/general_page_view.h',
'browser/views/options/languages_page_view.cc',
'browser/views/options/languages_page_view.h',
+ 'browser/views/options/managed_prefs_banner_view.cc',
+ 'browser/views/options/managed_prefs_banner_view.h',
'browser/views/options/options_group_view.cc',
'browser/views/options/options_group_view.h',
'browser/views/options/options_page_view.cc',
diff --git a/chrome/chrome_tests.gypi b/chrome/chrome_tests.gypi
index e1d2434..16a1037 100644
--- a/chrome/chrome_tests.gypi
+++ b/chrome/chrome_tests.gypi
@@ -19,6 +19,7 @@
# TODO(jcampan): move these vars to views.gyp.
'views_unit_tests_sources': [
'../views/animation/bounds_animator_unittest.cc',
+ '../views/box_layout_unittest.cc',
'../views/view_unittest.cc',
'../views/focus/focus_manager_unittest.cc',
'../views/controls/label_unittest.cc',
diff --git a/gfx/gfx.gyp b/gfx/gfx.gyp
index 668ac00..898b981 100644
--- a/gfx/gfx.gyp
+++ b/gfx/gfx.gyp
@@ -126,6 +126,7 @@
# font_gtk.cc uses fontconfig.
# TODO(evanm): I think this is wrong; it should just use GTK.
'../build/linux/system.gyp:fontconfig',
+ '../build/linux/system.gyp:gtk',
],
'sources': [
'font_skia.cc',
diff --git a/gfx/rect.cc b/gfx/rect.cc
index dd8f392..ea328beb 100644
--- a/gfx/rect.cc
+++ b/gfx/rect.cc
@@ -15,6 +15,7 @@
#include <iostream>
#include "base/logging.h"
+#include "gfx/insets.h"
namespace {
@@ -105,6 +106,10 @@ void Rect::SetRect(int x, int y, int width, int height) {
set_height(height);
}
+void Rect::Inset(const gfx::Insets& insets) {
+ Inset(insets.left(), insets.top(), insets.right(), insets.bottom());
+}
+
void Rect::Inset(int left, int top, int right, int bottom) {
Offset(left, top);
set_width(std::max(width() - left - right, 0));
diff --git a/gfx/rect.h b/gfx/rect.h
index 1c83f48..f1e43a7 100644
--- a/gfx/rect.h
+++ b/gfx/rect.h
@@ -25,6 +25,8 @@ typedef struct _GdkRectangle GdkRectangle;
namespace gfx {
+class Insets;
+
class Rect {
public:
Rect();
@@ -78,6 +80,9 @@ class Rect {
Inset(horizontal, vertical, horizontal, vertical);
}
+ // Shrink the rectangle by the given insets.
+ void Inset(const gfx::Insets& insets);
+
// Shrink the rectangle by the specified amount on each side.
void Inset(int left, int top, int right, int bottom);
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
diff --git a/views/box_layout.h b/views/box_layout.h
new file mode 100644
index 0000000..332be47
--- /dev/null
+++ b/views/box_layout.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef VIEWS_BOX_LAYOUT_H_
+#define VIEWS_BOX_LAYOUT_H_
+
+#include "base/basictypes.h"
+#include "views/layout_manager.h"
+
+namespace views {
+
+// A Layout manager that arranges child views vertically or horizontally in a
+// side-by-side fashion with spacing around and between the child views. The
+// child views are always sized according to their preferred size. If the
+// host's bounds provide insufficient space, child views will be clamped.
+// Excess space will not be distributed.
+class BoxLayout : public LayoutManager {
+ public:
+ enum Orientation {
+ kHorizontal,
+ kVertical,
+ };
+
+ // Use |inside_border_spacing| to add additional space between the child view
+ // area and the host view border. |between_child_spacing| controls the space
+ // in between child views.
+ BoxLayout(Orientation orientation,
+ int inside_border_spacing,
+ int between_child_spacing);
+ virtual ~BoxLayout() {}
+
+ // Overridden from views::LayoutManager:
+ virtual void Layout(View* host);
+ virtual gfx::Size GetPreferredSize(View* host);
+
+ private:
+ const Orientation orientation_;
+
+ // Spacing between child views and host view border.
+ const int inside_border_spacing_;
+ // Spacing to put in between child views.
+ const int between_child_spacing_;
+
+ DISALLOW_IMPLICIT_CONSTRUCTORS(BoxLayout);
+};
+
+} // namespace views
+
+#endif // VIEWS_BOX_LAYOUT_H_
diff --git a/views/box_layout_unittest.cc b/views/box_layout_unittest.cc
new file mode 100644
index 0000000..712b2ef
--- /dev/null
+++ b/views/box_layout_unittest.cc
@@ -0,0 +1,108 @@
+// 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 "testing/gtest/include/gtest/gtest.h"
+#include "views/box_layout.h"
+#include "views/view.h"
+
+class StaticSizedView : public views::View {
+ public:
+ explicit StaticSizedView(const gfx::Size& size)
+ : size_(size) { }
+
+ virtual gfx::Size GetPreferredSize() {
+ return size_;
+ }
+
+ private:
+ gfx::Size size_;
+};
+
+class BoxLayoutTest : public testing::Test {
+ public:
+ virtual void SetUp() {
+ host_.reset(new views::View);
+ }
+
+ scoped_ptr<views::View> host_;
+ scoped_ptr<views::BoxLayout> layout_;
+};
+
+TEST_F(BoxLayoutTest, Empty) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 20));
+ EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get()));
+}
+
+TEST_F(BoxLayoutTest, AlignmentHorizontal) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0));
+ views::View* v1 = new StaticSizedView(gfx::Size(10, 20));
+ host_->AddChildView(v1);
+ views::View* v2 = new StaticSizedView(gfx::Size(10, 10));
+ host_->AddChildView(v2);
+ EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get()));
+ host_->SetBounds(0, 0, 20, 20);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 20), v1->bounds());
+ EXPECT_EQ(gfx::Rect(10, 0, 10, 20), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, AlignmentVertical) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0));
+ views::View* v1 = new StaticSizedView(gfx::Size(20, 10));
+ host_->AddChildView(v1);
+ views::View* v2 = new StaticSizedView(gfx::Size(10, 10));
+ host_->AddChildView(v2);
+ EXPECT_EQ(gfx::Size(20, 20), layout_->GetPreferredSize(host_.get()));
+ host_->SetBounds(0, 0, 20, 20);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(0, 0, 20, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 10, 20, 10), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, Spacing) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 7, 8));
+ views::View* v1 = new StaticSizedView(gfx::Size(10, 20));
+ host_->AddChildView(v1);
+ views::View* v2 = new StaticSizedView(gfx::Size(10, 20));
+ host_->AddChildView(v2);
+ EXPECT_EQ(gfx::Size(42, 34), layout_->GetPreferredSize(host_.get()));
+ host_->SetBounds(0, 0, 100, 100);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(7, 7, 10, 86), v1->bounds());
+ EXPECT_EQ(gfx::Rect(25, 7, 10, 86), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, Overflow) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0));
+ views::View* v1 = new StaticSizedView(gfx::Size(20, 20));
+ host_->AddChildView(v1);
+ views::View* v2 = new StaticSizedView(gfx::Size(10, 20));
+ host_->AddChildView(v2);
+ host_->SetBounds(0, 0, 10, 10);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(0, 0, 10, 10), v1->bounds());
+ EXPECT_EQ(gfx::Rect(0, 0, 0, 0), v2->bounds());
+}
+
+TEST_F(BoxLayoutTest, NoSpace) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10));
+ views::View* childView = new StaticSizedView(gfx::Size(20, 20));
+ host_->AddChildView(childView);
+ host_->SetBounds(0, 0, 10, 10);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(0, 0, 0, 0), childView->bounds());
+}
+
+TEST_F(BoxLayoutTest, InvisibleChild) {
+ layout_.reset(new views::BoxLayout(views::BoxLayout::kHorizontal, 10, 10));
+ views::View* v1 = new StaticSizedView(gfx::Size(20, 20));
+ v1->SetVisible(false);
+ host_->AddChildView(v1);
+ views::View* v2 = new StaticSizedView(gfx::Size(10, 10));
+ host_->AddChildView(v2);
+ EXPECT_EQ(gfx::Size(30, 30), layout_->GetPreferredSize(host_.get()));
+ host_->SetBounds(0, 0, 30, 30);
+ layout_->Layout(host_.get());
+ EXPECT_EQ(gfx::Rect(10, 10, 10, 10), v2->bounds());
+}
diff --git a/views/examples/box_layout.cc b/views/examples/box_layout.cc
deleted file mode 100644
index 957d0d6..0000000
--- a/views/examples/box_layout.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// 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/examples/box_layout.h"
-
-namespace examples {
-
-BoxLayout::BoxLayout(Orientation orientation, int margin)
- : orientation_(orientation),
- margin_(margin) {
-}
-
-void BoxLayout::Layout(views::View* host) {
- int height = host->height();
- int width = host->width();
- int count = host->GetChildViewCount();
-
- int z = 0;
- for (int i = 0; i < count; ++i) {
- views::View* child = host->GetChildViewAt(i);
-
- if (orientation_ == kVertical) {
- child->SetBounds(0, z, width, height / count);
- z = (height + margin_) * (i + 1) / count;
- } else if (orientation_ == kHorizontal) {
- child->SetBounds(z, 0, width / count, height);
- z = (width + margin_) * (i + 1) / count;
- }
- }
-}
-
-gfx::Size BoxLayout::GetPreferredSize(views::View* host) {
- return gfx::Size();
-}
-
-} // namespace examples
diff --git a/views/examples/box_layout.h b/views/examples/box_layout.h
deleted file mode 100644
index 2e802aa..0000000
--- a/views/examples/box_layout.h
+++ /dev/null
@@ -1,40 +0,0 @@
-// 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.
-
-#ifndef VIEWS_EXAMPLES_BOX_LAYOUT_H_
-#define VIEWS_EXAMPLES_BOX_LAYOUT_H_
-
-#include "views/layout_manager.h"
-
-namespace examples {
-
-// A layout manager that layouts child views vertically or horizontally.
-class BoxLayout : public views::LayoutManager {
- public:
- enum Orientation {
- kHorizontal,
- kVertical,
- };
-
- BoxLayout(Orientation orientation, int margin);
-
- virtual ~BoxLayout() {}
-
- // Overridden from views::LayoutManager:
- virtual void Layout(views::View* host);
-
- virtual gfx::Size GetPreferredSize(views::View* host);
-
- private:
- const Orientation orientation_;
-
- // The pixel distance between children.
- const int margin_;
-
- DISALLOW_COPY_AND_ASSIGN(BoxLayout);
-};
-
-} // namespace examples
-
-#endif // VIEWS_EXAMPLES_BOX_LAYOUT_H_
diff --git a/views/examples/widget_example.h b/views/examples/widget_example.h
index 4fff3e2..9208a1b 100644
--- a/views/examples/widget_example.h
+++ b/views/examples/widget_example.h
@@ -6,8 +6,8 @@
#define VIEWS_EXAMPLES_WIDGET_EXAMPLE_H_
#include "views/background.h"
+#include "views/box_layout.h"
#include "views/controls/button/text_button.h"
-#include "views/examples/box_layout.h"
#include "views/examples/example_base.h"
#include "views/view.h"
#include "views/widget/root_view.h"
@@ -59,14 +59,16 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
virtual std::wstring GetExampleTitle() { return L"Widget"; }
virtual void CreateExampleView(views::View* container) {
- container->SetLayoutManager(new BoxLayout(BoxLayout::kHorizontal, 2));
+ container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 2));
BuildButton(container, L"Create a popup widget", POPUP);
BuildButton(container, L"Create a transparent popup widget",
TRANSPARENT_POPUP);
#if defined(OS_LINUX)
views::View* vert_container = new views::View();
container->AddChildView(vert_container);
- vert_container->SetLayoutManager(new BoxLayout(BoxLayout::kVertical, 20));
+ vert_container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kVertical, 0, 20));
BuildButton(vert_container, L"Create a child widget", CHILD);
BuildButton(vert_container, L"Create a transparent child widget",
TRANSPARENT_CHILD);
@@ -100,7 +102,7 @@ class WidgetExample : public ExampleBase, public views::ButtonListener {
views::View* button_container = new views::View();
button_container->SetLayoutManager(
- new BoxLayout(BoxLayout::kHorizontal, 1));
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 1));
button_container->AddChildView(close_button);
button_container->AddChildView(native_button);
diff --git a/views/views.gyp b/views/views.gyp
index 0193383..3ee4096 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -61,6 +61,8 @@
'background.h',
'border.cc',
'border.h',
+ 'box_layout.h',
+ 'box_layout.cc',
'controls/button/button.cc',
'controls/button/button.h',
'controls/button/button_dropdown.cc',
@@ -383,8 +385,6 @@
'..',
],
'sources': [
- 'examples/box_layout.cc',
- 'examples/box_layout.h',
'examples/button_example.h',
'examples/combobox_example.h',
'examples/example_base.cc',