summaryrefslogtreecommitdiffstats
path: root/ui/views
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:56:30 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-11-15 02:56:30 +0000
commit75b985094ca3603b5d566227a3dc2d0b62fcf51c (patch)
tree23e30d8df3b4527c80a56fc9eb61cd67c43e5677 /ui/views
parente5c49f5cb6e52f3d3f23f6f514421d3247d4c01b (diff)
downloadchromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.zip
chromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.tar.gz
chromium_src-75b985094ca3603b5d566227a3dc2d0b62fcf51c.tar.bz2
views: Move examples/ directory to ui/views/.
BUG=104039 R=ben@chromium.org Review URL: http://codereview.chromium.org/8555013 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@110023 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/views')
-rw-r--r--ui/views/examples/bubble_example.cc100
-rw-r--r--ui/views/examples/bubble_example.h38
-rw-r--r--ui/views/examples/button_example.cc104
-rw-r--r--ui/views/examples/button_example.h50
-rw-r--r--ui/views/examples/combobox_example.cc58
-rw-r--r--ui/views/examples/combobox_example.h40
-rw-r--r--ui/views/examples/double_split_view_example.cc80
-rw-r--r--ui/views/examples/double_split_view_example.h37
-rw-r--r--ui/views/examples/example_base.cc67
-rw-r--r--ui/views/examples/example_base.h59
-rw-r--r--ui/views/examples/example_combobox_model.cc28
-rw-r--r--ui/views/examples/example_combobox_model.h32
-rw-r--r--ui/views/examples/examples_main.cc196
-rw-r--r--ui/views/examples/examples_main.h60
-rw-r--r--ui/views/examples/link_example.cc33
-rw-r--r--ui/views/examples/link_example.h40
-rw-r--r--ui/views/examples/menu_example.cc216
-rw-r--r--ui/views/examples/menu_example.h32
-rw-r--r--ui/views/examples/message_box_example.cc67
-rw-r--r--ui/views/examples/message_box_example.h50
-rw-r--r--ui/views/examples/native_theme_button_example.cc255
-rw-r--r--ui/views/examples/native_theme_button_example.h93
-rw-r--r--ui/views/examples/native_theme_checkbox_example.cc35
-rw-r--r--ui/views/examples/native_theme_checkbox_example.h45
-rw-r--r--ui/views/examples/native_widget_views_example.cc95
-rw-r--r--ui/views/examples/native_widget_views_example.h29
-rw-r--r--ui/views/examples/progress_bar_example.cc69
-rw-r--r--ui/views/examples/progress_bar_example.h44
-rw-r--r--ui/views/examples/radio_button_example.cc66
-rw-r--r--ui/views/examples/radio_button_example.h51
-rw-r--r--ui/views/examples/scroll_view_example.cc114
-rw-r--r--ui/views/examples/scroll_view_example.h53
-rw-r--r--ui/views/examples/single_split_view_example.cc89
-rw-r--r--ui/views/examples/single_split_view_example.h35
-rw-r--r--ui/views/examples/tabbed_pane_example.cc91
-rw-r--r--ui/views/examples/tabbed_pane_example.h59
-rw-r--r--ui/views/examples/table2_example.cc154
-rw-r--r--ui/views/examples/table2_example.h73
-rw-r--r--ui/views/examples/table_example.cc141
-rw-r--r--ui/views/examples/table_example.h74
-rw-r--r--ui/views/examples/text_example.cc328
-rw-r--r--ui/views/examples/text_example.h79
-rw-r--r--ui/views/examples/textfield_example.cc113
-rw-r--r--ui/views/examples/textfield_example.h58
-rw-r--r--ui/views/examples/throbber_example.cc60
-rw-r--r--ui/views/examples/throbber_example.h33
-rw-r--r--ui/views/examples/views_examples.exe.manifest27
-rw-r--r--ui/views/examples/widget_example.cc169
-rw-r--r--ui/views/examples/widget_example.h56
49 files changed, 3975 insertions, 0 deletions
diff --git a/ui/views/examples/bubble_example.cc b/ui/views/examples/bubble_example.cc
new file mode 100644
index 0000000..38a3529
--- /dev/null
+++ b/ui/views/examples/bubble_example.cc
@@ -0,0 +1,100 @@
+// 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/examples/bubble_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/bubble/bubble_delegate.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/label.h"
+#include "views/layout/box_layout.h"
+#include "views/layout/fill_layout.h"
+#include "views/widget/widget.h"
+
+namespace examples {
+
+struct BubbleConfig {
+ string16 label;
+ SkColor color;
+ views::View* anchor_view;
+ views::BubbleBorder::ArrowLocation arrow;
+ bool fade_in;
+ bool fade_out;
+};
+
+// Create four types of bubbles, one without arrow, one with an arrow, one
+// that fades in, and another that fades out and won't close on the escape key.
+BubbleConfig kRoundConfig = { ASCIIToUTF16("Round"), 0xFFC1B1E1, NULL,
+ views::BubbleBorder::NONE, false, false };
+BubbleConfig kArrowConfig = { ASCIIToUTF16("Arrow"), SK_ColorGRAY, NULL,
+ views::BubbleBorder::TOP_LEFT, false, false };
+BubbleConfig kFadeInConfig = { ASCIIToUTF16("FadeIn"), SK_ColorYELLOW, NULL,
+ views::BubbleBorder::BOTTOM_RIGHT, true, false };
+BubbleConfig kFadeOutConfig = { ASCIIToUTF16("FadeOut"), SK_ColorWHITE, NULL,
+ views::BubbleBorder::LEFT_TOP, false, true };
+
+class ExampleBubbleDelegateView : public views::BubbleDelegateView {
+ public:
+ ExampleBubbleDelegateView(const BubbleConfig& config)
+ : BubbleDelegateView(config.anchor_view, config.arrow, config.color),
+ label_(config.label) {}
+
+ protected:
+ virtual void Init() OVERRIDE {
+ SetLayoutManager(new views::FillLayout());
+ views::Label* label = new views::Label(label_);
+ AddChildView(label);
+ }
+
+ private:
+ string16 label_;
+};
+
+BubbleExample::BubbleExample(ExamplesMain* main)
+ : ExampleBase(main, "Bubble") {}
+
+BubbleExample::~BubbleExample() {}
+
+void BubbleExample::CreateExampleView(views::View* container) {
+ container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1));
+ round_ = new views::TextButton(this, kRoundConfig.label);
+ arrow_ = new views::TextButton(this, kArrowConfig.label);
+ fade_in_ = new views::TextButton(this, kFadeInConfig.label);
+ fade_out_ = new views::TextButton(this, kFadeOutConfig.label);
+ container->AddChildView(round_);
+ container->AddChildView(arrow_);
+ container->AddChildView(fade_in_);
+ container->AddChildView(fade_out_);
+}
+
+void BubbleExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ BubbleConfig config;
+ if (sender == round_)
+ config = kRoundConfig;
+ else if (sender == arrow_)
+ config = kArrowConfig;
+ else if (sender == fade_in_)
+ config = kFadeInConfig;
+ else if (sender == fade_out_)
+ config = kFadeOutConfig;
+
+ config.anchor_view = sender;
+ ExampleBubbleDelegateView* bubble_delegate =
+ new ExampleBubbleDelegateView(config);
+ views::BubbleDelegateView::CreateBubble(bubble_delegate);
+
+ if (config.fade_in)
+ bubble_delegate->StartFade(true);
+ else
+ bubble_delegate->Show();
+
+ if (config.fade_out) {
+ bubble_delegate->set_close_on_esc(false);
+ bubble_delegate->StartFade(false);
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/bubble_example.h b/ui/views/examples/bubble_example.h
new file mode 100644
index 0000000..9c7e1c7
--- /dev/null
+++ b/ui/views/examples/bubble_example.h
@@ -0,0 +1,38 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_BUBBLE_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_BUBBLE_EXAMPLE_H_
+#pragma once
+
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+
+namespace examples {
+
+// A Bubble example.
+class BubbleExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit BubbleExample(ExamplesMain* main);
+ virtual ~BubbleExample();
+
+ // Overridden from ExampleBase.
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ views::Button* round_;
+ views::Button* arrow_;
+ views::Button* fade_in_;
+ views::Button* fade_out_;
+
+ DISALLOW_COPY_AND_ASSIGN(BubbleExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_BUBBLE_EXAMPLE_H_
diff --git a/ui/views/examples/button_example.cc b/ui/views/examples/button_example.cc
new file mode 100644
index 0000000..f3f1c1f
--- /dev/null
+++ b/ui/views/examples/button_example.cc
@@ -0,0 +1,104 @@
+// 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/examples/button_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "grit/ui_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "views/controls/button/checkbox.h"
+#include "views/layout/fill_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+ButtonExample::ButtonExample(ExamplesMain* main)
+ : ExampleBase(main, "Text Button"),
+ alignment_(views::TextButton::ALIGN_LEFT),
+ use_native_theme_border_(false),
+ icon_(NULL),
+ count_(0) {
+ ResourceBundle& rb = ResourceBundle::GetSharedInstance();
+ icon_ = rb.GetBitmapNamed(IDR_CLOSE_SA_H);
+}
+
+ButtonExample::~ButtonExample() {
+}
+
+void ButtonExample::CreateExampleView(views::View* container) {
+ views::TextButton* tb = new views::TextButton(this, ASCIIToUTF16("Button"));
+ button_ = tb;
+ container->SetLayoutManager(new views::FillLayout);
+ container->AddChildView(button_);
+}
+
+void ButtonExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ PrintStatus("Pressed! count: %d", ++count_);
+
+ if (event.IsControlDown()) {
+ if (event.IsShiftDown()) {
+ if (event.IsAltDown()) {
+ button_->SetMultiLine(!button_->multi_line());
+ if (button_->multi_line()) {
+ button_->SetText(ASCIIToUTF16("Multi-line text\n") +
+ ASCIIToUTF16("is here to stay all the way!\n") +
+ ASCIIToUTF16("123"));
+ } else {
+ button_->SetText(ASCIIToUTF16("Button"));
+ }
+ } else {
+ switch(button_->icon_placement()) {
+ case views::TextButton::ICON_ON_LEFT:
+ button_->set_icon_placement(views::TextButton::ICON_ON_RIGHT);
+ break;
+ case views::TextButton::ICON_ON_RIGHT:
+ button_->set_icon_placement(views::TextButton::ICON_ON_LEFT);
+ break;
+ }
+ }
+ } else if (event.IsAltDown()) {
+ if (button_->HasIcon())
+ button_->SetIcon(SkBitmap());
+ else
+ button_->SetIcon(*icon_);
+ } else {
+ switch(alignment_) {
+ case views::TextButton::ALIGN_LEFT:
+ alignment_ = views::TextButton::ALIGN_CENTER;
+ break;
+ case views::TextButton::ALIGN_CENTER:
+ alignment_ = views::TextButton::ALIGN_RIGHT;
+ break;
+ case views::TextButton::ALIGN_RIGHT:
+ alignment_ = views::TextButton::ALIGN_LEFT;
+ break;
+ }
+ button_->set_alignment(alignment_);
+ }
+ } else if (event.IsShiftDown()) {
+ if (event.IsAltDown()) {
+ if (button_->text().length() < 10) {
+ button_->SetText(
+ ASCIIToUTF16("Startof") +
+ ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
+ ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
+ ASCIIToUTF16("ReallyReallyReallyReallyReallyReallyReally") +
+ ASCIIToUTF16("LongButtonText"));
+ } else {
+ button_->SetText(ASCIIToUTF16("Button"));
+ }
+ } else {
+ use_native_theme_border_ = !use_native_theme_border_;
+ if (use_native_theme_border_)
+ button_->set_border(new views::TextButtonNativeThemeBorder(button_));
+ else
+ button_->set_border(new views::TextButtonBorder());
+ }
+ } else if (event.IsAltDown()) {
+ button_->SetIsDefault(!button_->is_default());
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/button_example.h b/ui/views/examples/button_example.h
new file mode 100644
index 0000000..b353105
--- /dev/null
+++ b/ui/views/examples/button_example.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_BUTTON_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_BUTTON_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+
+namespace views {
+class View;
+}
+
+namespace examples {
+
+// ButtonExample simply counts the number of clicks.
+class ButtonExample : public ExampleBase, public views::ButtonListener {
+ public:
+ explicit ButtonExample(ExamplesMain* main);
+ virtual ~ButtonExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // The only control in this test.
+ views::TextButton* button_;
+
+ // Values used to modify the look and feel of the button.
+ views::TextButton::TextAlignment alignment_;
+ bool use_native_theme_border_;
+ SkBitmap* icon_;
+
+ // The number of times the button is pressed.
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(ButtonExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_BUTTON_EXAMPLE_H_
diff --git a/ui/views/examples/combobox_example.cc b/ui/views/examples/combobox_example.cc
new file mode 100644
index 0000000..c1053fc
--- /dev/null
+++ b/ui/views/examples/combobox_example.cc
@@ -0,0 +1,58 @@
+// 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/examples/combobox_example.h"
+
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/models/combobox_model.h"
+
+namespace {
+
+// An sample combobox model that generates list of "Item <index>".
+class ComboboxModelExample : public ui::ComboboxModel {
+ public:
+ ComboboxModelExample() {}
+ virtual ~ComboboxModelExample() {}
+
+ // Overridden from ui::ComboboxModel:
+ virtual int GetItemCount() OVERRIDE { return 10; }
+
+ // Overridden from ui::ComboboxModel:
+ virtual string16 GetItemAt(int index) OVERRIDE {
+ return UTF8ToUTF16(base::StringPrintf("Item %d", index));
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ComboboxModelExample);
+};
+
+} // namespace
+
+namespace examples {
+
+ComboboxExample::ComboboxExample(ExamplesMain* main)
+ : ExampleBase(main, "Combo Box") {
+}
+
+ComboboxExample::~ComboboxExample() {
+}
+
+void ComboboxExample::CreateExampleView(views::View* container) {
+ combobox_ = new views::Combobox(new ComboboxModelExample());
+ combobox_->set_listener(this);
+ combobox_->SetSelectedItem(3);
+
+ container->SetLayoutManager(new views::FillLayout);
+ container->AddChildView(combobox_);
+}
+
+void ComboboxExample::ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) {
+ PrintStatus("Selected: index=%d, label=%s",
+ new_index, UTF16ToUTF8(combo_box->model()->GetItemAt(new_index)).c_str());
+}
+
+} // namespace examples
diff --git a/ui/views/examples/combobox_example.h b/ui/views/examples/combobox_example.h
new file mode 100644
index 0000000..757fe3d
--- /dev/null
+++ b/ui/views/examples/combobox_example.h
@@ -0,0 +1,40 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/combobox/combobox.h"
+#include "views/layout/fill_layout.h"
+
+namespace examples {
+
+class ComboboxExample : public ExampleBase,
+ public views::Combobox::Listener {
+ public:
+ explicit ComboboxExample(ExamplesMain* main);
+ virtual ~ComboboxExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::Combobox::Listener:
+ virtual void ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) OVERRIDE;
+
+ // This test only control.
+ views::Combobox* combobox_;
+
+ DISALLOW_COPY_AND_ASSIGN(ComboboxExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_COMBOBOX_EXAMPLE_H_
diff --git a/ui/views/examples/double_split_view_example.cc b/ui/views/examples/double_split_view_example.cc
new file mode 100644
index 0000000..bd7d756
--- /dev/null
+++ b/ui/views/examples/double_split_view_example.cc
@@ -0,0 +1,80 @@
+// 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/examples/double_split_view_example.h"
+
+#include "views/controls/single_split_view.h"
+#include "views/layout/grid_layout.h"
+
+namespace {
+
+// DoubleSplitViews's content, which draws gradient color on background.
+class SplittedView : public views::View {
+ public:
+ SplittedView();
+ virtual ~SplittedView();
+
+ void SetColor(SkColor from, SkColor to);
+
+ // Overridden from views::View.
+ virtual gfx::Size GetMinimumSize() OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(SplittedView);
+};
+
+SplittedView::SplittedView() {
+ SetColor(SK_ColorRED, SK_ColorGREEN);
+}
+
+SplittedView::~SplittedView() {
+}
+
+void SplittedView::SetColor(SkColor from, SkColor to) {
+ set_background(
+ views::Background::CreateVerticalGradientBackground(from, to));
+}
+
+gfx::Size SplittedView::GetMinimumSize() {
+ return gfx::Size(10, 10);
+}
+
+} // namespace
+
+namespace examples {
+
+DoubleSplitViewExample::DoubleSplitViewExample(ExamplesMain* main)
+ : ExampleBase(main, "Double Split View") {
+}
+
+DoubleSplitViewExample::~DoubleSplitViewExample() {
+}
+
+void DoubleSplitViewExample::CreateExampleView(views::View* container) {
+ SplittedView* splitted_view_1 = new SplittedView();
+ SplittedView* splitted_view_2 = new SplittedView();
+ SplittedView* splitted_view_3 = new SplittedView();
+
+ inner_single_split_view_ = new views::SingleSplitView(
+ splitted_view_1, splitted_view_2,
+ views::SingleSplitView::HORIZONTAL_SPLIT,
+ NULL);
+
+ outer_single_split_view_ = new views::SingleSplitView(
+ inner_single_split_view_, splitted_view_3,
+ views::SingleSplitView::HORIZONTAL_SPLIT,
+ NULL);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ // Add scroll view.
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1, 0);
+ layout->AddView(outer_single_split_view_);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/double_split_view_example.h b/ui/views/examples/double_split_view_example.h
new file mode 100644
index 0000000..709cff6
--- /dev/null
+++ b/ui/views/examples/double_split_view_example.h
@@ -0,0 +1,37 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_DOUBLE_SPLIT_VIEW_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_DOUBLE_SPLIT_VIEW_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+
+namespace views {
+class SingleSplitView;
+}
+
+namespace examples {
+
+class DoubleSplitViewExample : public ExampleBase {
+ public:
+ explicit DoubleSplitViewExample(ExamplesMain* main);
+ virtual ~DoubleSplitViewExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // The SingleSplitViews to be embedded.
+ views::SingleSplitView* outer_single_split_view_;
+ views::SingleSplitView* inner_single_split_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(DoubleSplitViewExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_DOUBLE_SPLIT_VIEW_EXAMPLE_H_
diff --git a/ui/views/examples/example_base.cc b/ui/views/examples/example_base.cc
new file mode 100644
index 0000000..f4ced56
--- /dev/null
+++ b/ui/views/examples/example_base.cc
@@ -0,0 +1,67 @@
+// 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/examples/example_base.h"
+
+#include <stdarg.h>
+
+#include "base/compiler_specific.h"
+#include "base/stringprintf.h"
+#include "ui/views/examples/examples_main.h"
+
+namespace {
+
+// Some of GTK based view classes require NativeWidgetGtk in the view
+// parent chain. This class is used to defer the creation of such
+// views until a NativeWidgetGtk is added to the view hierarchy.
+class ContainerView : public views::View {
+ public:
+ explicit ContainerView(examples::ExampleBase* base)
+ : example_view_created_(false),
+ example_base_(base) {
+ }
+
+ private:
+ // Overridden from views::View:
+ virtual void ViewHierarchyChanged(bool is_add,
+ views::View* parent,
+ views::View* child) OVERRIDE {
+ views::View::ViewHierarchyChanged(is_add, parent, child);
+ // We're not using child == this because a Widget may not be
+ // availalbe when this is added to the hierarchy.
+ if (is_add && GetWidget() && !example_view_created_) {
+ example_view_created_ = true;
+ example_base_->CreateExampleView(this);
+ }
+ }
+
+ // True if the example view has already been created, or false otherwise.
+ bool example_view_created_;
+
+ examples::ExampleBase* example_base_;
+
+ DISALLOW_COPY_AND_ASSIGN(ContainerView);
+};
+
+} // namespace
+
+namespace examples {
+
+ExampleBase::~ExampleBase() {}
+
+ExampleBase::ExampleBase(ExamplesMain* main, const char* title)
+ : main_(main), example_title_(title) {
+ container_ = new ContainerView(this);
+}
+
+// Prints a message in the status area, at the bottom of the window.
+void ExampleBase::PrintStatus(const char* format, ...) {
+ va_list ap;
+ va_start(ap, format);
+ std::string msg;
+ base::StringAppendV(&msg, format, ap);
+ main_->SetStatus(msg);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/example_base.h b/ui/views/examples/example_base.h
new file mode 100644
index 0000000..7d49586
--- /dev/null
+++ b/ui/views/examples/example_base.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_
+#define UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+
+namespace views {
+class View;
+}
+
+namespace examples {
+
+class ExamplesMain;
+
+class ExampleBase {
+ public:
+ virtual ~ExampleBase();
+
+ // Sub-classes should creates and add the views to the given parent.
+ virtual void CreateExampleView(views::View* parent) = 0;
+
+ const std::string& example_title() const { return example_title_; }
+
+ // This view is added as a tab to the example application.
+ views::View* example_view() { return container_; }
+
+ protected:
+ ExampleBase(ExamplesMain* main, const char* title);
+
+ // Prints a message in the status area, at the bottom of the window.
+ void PrintStatus(const char* format, ...);
+
+ // Converts an boolean value to "on" or "off".
+ const char* BoolToOnOff(bool value) {
+ return value ? "on" : "off";
+ }
+
+ private:
+ // The runner actually running this example.
+ ExamplesMain* main_;
+
+ // Name of the example - used for the title of the tab.
+ std::string example_title_;
+
+ // The view containing example views.
+ views::View* container_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExampleBase);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_EXAMPLE_BASE_H_
diff --git a/ui/views/examples/example_combobox_model.cc b/ui/views/examples/example_combobox_model.cc
new file mode 100644
index 0000000..f457291
--- /dev/null
+++ b/ui/views/examples/example_combobox_model.cc
@@ -0,0 +1,28 @@
+// 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/examples/example_combobox_model.h"
+
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/models/combobox_model.h"
+
+namespace examples {
+
+ExampleComboboxModel::ExampleComboboxModel(const char** strings, int count)
+ : strings_(strings), count_(count) {
+}
+
+ExampleComboboxModel::~ExampleComboboxModel() {
+}
+
+int ExampleComboboxModel::GetItemCount() {
+ return count_;
+}
+
+string16 ExampleComboboxModel::GetItemAt(int index) {
+ return ASCIIToUTF16(strings_[index]);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/example_combobox_model.h b/ui/views/examples/example_combobox_model.h
new file mode 100644
index 0000000..1a7582a
--- /dev/null
+++ b/ui/views/examples/example_combobox_model.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_EXAMPLE_COMBOBOX_MODEL_H_
+#define UI_VIEWS_EXAMPLES_EXAMPLE_COMBOBOX_MODEL_H_
+#pragma once
+
+#include "base/compiler_specific.h"
+#include "ui/base/models/combobox_model.h"
+
+namespace examples {
+
+class ExampleComboboxModel : public ui::ComboboxModel {
+ public:
+ ExampleComboboxModel(const char** strings, int count);
+ virtual ~ExampleComboboxModel();
+
+ // Overridden from ui::ComboboxModel:
+ virtual int GetItemCount() OVERRIDE;
+ virtual string16 GetItemAt(int index) OVERRIDE;
+
+ private:
+ const char** strings_;
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExampleComboboxModel);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_EXAMPLE_COMBOBOX_MODEL_H_
diff --git a/ui/views/examples/examples_main.cc b/ui/views/examples/examples_main.cc
new file mode 100644
index 0000000..84a0b14
--- /dev/null
+++ b/ui/views/examples/examples_main.cc
@@ -0,0 +1,196 @@
+// 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/examples/examples_main.h"
+
+#include "base/at_exit.h"
+#include "base/command_line.h"
+#include "base/i18n/icu_util.h"
+#include "base/process_util.h"
+#include "base/stl_util.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/base/ui_base_paths.h"
+#include "ui/views/examples/bubble_example.h"
+#include "ui/views/examples/button_example.h"
+#include "ui/views/examples/combobox_example.h"
+#include "ui/views/examples/double_split_view_example.h"
+#include "ui/views/examples/link_example.h"
+#include "ui/views/examples/menu_example.h"
+#include "ui/views/examples/message_box_example.h"
+#include "ui/views/examples/native_theme_button_example.h"
+#include "ui/views/examples/native_theme_checkbox_example.h"
+#include "ui/views/examples/native_widget_views_example.h"
+#include "ui/views/examples/progress_bar_example.h"
+#include "ui/views/examples/radio_button_example.h"
+#include "ui/views/examples/scroll_view_example.h"
+#include "ui/views/examples/single_split_view_example.h"
+#include "ui/views/examples/tabbed_pane_example.h"
+#include "ui/views/examples/table2_example.h"
+#include "ui/views/examples/text_example.h"
+#include "ui/views/examples/textfield_example.h"
+#include "ui/views/examples/throbber_example.h"
+#include "ui/views/examples/widget_example.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/label.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/focus/accelerator_handler.h"
+#include "views/layout/grid_layout.h"
+#include "views/test/test_views_delegate.h"
+#include "views/widget/widget.h"
+
+#if defined(OS_WIN)
+// TableView is not yet ported to Linux.
+#include "ui/views/examples/table_example.h"
+#endif
+
+namespace examples {
+
+ExamplesMain::ExamplesMain()
+ : tabbed_pane_(NULL),
+ contents_(NULL),
+ status_label_(NULL) {
+}
+
+ExamplesMain::~ExamplesMain() {
+ STLDeleteElements(&examples_);
+}
+
+void ExamplesMain::Init() {
+ // Creates a window with the tabbed pane for each example,
+ // and a label to print messages from each example.
+ DCHECK(contents_ == NULL) << "Run called more than once.";
+ contents_ = new views::View();
+ contents_->set_background(views::Background::CreateStandardPanelBackground());
+ views::GridLayout* layout = new views::GridLayout(contents_);
+ contents_->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+
+ tabbed_pane_ = new views::TabbedPane();
+ status_label_ = new views::Label();
+
+ layout->StartRow(1, 0);
+ layout->AddView(tabbed_pane_);
+ layout->StartRow(0 /* no expand */, 0);
+ layout->AddView(status_label_);
+
+ // TODO(satorux): The window is getting wide. Eventually, we would have
+ // the second tabbed pane.
+ views::Widget* window =
+ views::Widget::CreateWindowWithBounds(this, gfx::Rect(0, 0, 850, 300));
+
+ // Keep these in alphabetical order!
+ examples_.push_back(new BubbleExample(this));
+ examples_.push_back(new ButtonExample(this));
+ examples_.push_back(new ComboboxExample(this));
+ examples_.push_back(new DoubleSplitViewExample(this));
+ examples_.push_back(new LinkExample(this));
+ examples_.push_back(new MenuExample(this));
+ examples_.push_back(new MessageBoxExample(this));
+ examples_.push_back(new NativeThemeButtonExample(this));
+ examples_.push_back(new NativeThemeCheckboxExample(this));
+ examples_.push_back(new NativeWidgetViewsExample(this));
+ examples_.push_back(new ProgressBarExample(this));
+ examples_.push_back(new RadioButtonExample(this));
+ examples_.push_back(new ScrollViewExample(this));
+ examples_.push_back(new SingleSplitViewExample(this));
+ examples_.push_back(new TabbedPaneExample(this));
+#if defined(OS_WIN)
+ examples_.push_back(new TableExample(this));
+#endif
+ examples_.push_back(new Table2Example(this));
+ examples_.push_back(new TextExample(this));
+ examples_.push_back(new TextfieldExample(this));
+ examples_.push_back(new ThrobberExample(this));
+ examples_.push_back(new WidgetExample(this));
+
+ for (std::vector<ExampleBase*>::const_iterator i(examples_.begin());
+ i != examples_.end(); ++i)
+ AddExample(*i);
+
+ window->Show();
+}
+
+void ExamplesMain::SetStatus(const std::string& status) {
+ status_label_->SetText(UTF8ToUTF16(status));
+}
+
+void ExamplesMain::AddExample(ExampleBase* example) {
+ tabbed_pane_->AddTab(UTF8ToUTF16(example->example_title()),
+ example->example_view());
+}
+
+bool ExamplesMain::CanResize() const {
+ return true;
+}
+
+bool ExamplesMain::CanMaximize() const {
+ return true;
+}
+
+string16 ExamplesMain::GetWindowTitle() const {
+ return ASCIIToUTF16("Views Examples");
+}
+
+views::View* ExamplesMain::GetContentsView() {
+ return contents_;
+}
+
+void ExamplesMain::WindowClosing() {
+ MessageLoopForUI::current()->Quit();
+}
+
+views::Widget* ExamplesMain::GetWidget() {
+ return contents_->GetWidget();
+}
+
+const views::Widget* ExamplesMain::GetWidget() const {
+ return contents_->GetWidget();
+}
+
+} // namespace examples
+
+int main(int argc, char** argv) {
+#if defined(OS_WIN)
+ OleInitialize(NULL);
+#elif defined(OS_LINUX)
+ // Initializes gtk stuff.
+ g_type_init();
+ gtk_init(&argc, &argv);
+#endif
+ CommandLine::Init(argc, argv);
+
+ base::EnableTerminationOnHeapCorruption();
+
+ // The exit manager is in charge of calling the dtors of singleton objects.
+ base::AtExitManager exit_manager;
+
+ ui::RegisterPathProvider();
+ bool icu_result = icu_util::Initialize();
+ CHECK(icu_result);
+ ui::ResourceBundle::InitSharedInstance("en-US");
+
+ MessageLoop main_message_loop(MessageLoop::TYPE_UI);
+
+ views::TestViewsDelegate delegate;
+
+ // We do not use this header: chrome/common/chrome_switches.h
+ // because that would create a bad dependency back on Chrome.
+ views::Widget::SetPureViews(
+ CommandLine::ForCurrentProcess()->HasSwitch("use-pure-views"));
+
+ examples::ExamplesMain main;
+ main.Init();
+
+ views::AcceleratorHandler accelerator_handler;
+ MessageLoopForUI::current()->RunWithDispatcher(&accelerator_handler);
+
+#if defined(OS_WIN)
+ OleUninitialize();
+#endif
+ return 0;
+}
diff --git a/ui/views/examples/examples_main.h b/ui/views/examples/examples_main.h
new file mode 100644
index 0000000..a4278937
--- /dev/null
+++ b/ui/views/examples/examples_main.h
@@ -0,0 +1,60 @@
+// 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.
+
+#ifndef VIEWS_EXAMPLES_EXAMPLE_MAIN_H_
+#define VIEWS_EXAMPLES_EXAMPLE_MAIN_H_
+#pragma once
+
+#include <string>
+#include <vector>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "views/widget/widget_delegate.h"
+
+namespace views {
+class Label;
+class TabbedPane;
+class View;
+} // namespace views
+
+namespace examples {
+class ExampleBase;
+
+// ExamplesMain creates all view examples.
+class ExamplesMain : public views::WidgetDelegate {
+ public:
+ ExamplesMain();
+ virtual ~ExamplesMain();
+
+ // Creates all the examples and shows the window.
+ void Init();
+
+ // Prints a message in the status area, at the bottom of the window.
+ void SetStatus(const std::string& status);
+
+ private:
+ // Adds a new example to the tabbed window.
+ void AddExample(ExampleBase* example);
+
+ // views::WidgetDelegate implementation:
+ virtual bool CanResize() const OVERRIDE;
+ virtual bool CanMaximize() const OVERRIDE;
+ virtual string16 GetWindowTitle() const OVERRIDE;
+ virtual views::View* GetContentsView() OVERRIDE;
+ virtual void WindowClosing() OVERRIDE;
+ virtual views::Widget* GetWidget() OVERRIDE;
+ virtual const views::Widget* GetWidget() const OVERRIDE;
+
+ views::TabbedPane* tabbed_pane_;
+ views::View* contents_;
+ views::Label* status_label_;
+ std::vector<ExampleBase*> examples_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExamplesMain);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_EXAMPLE_MAIN_H_
diff --git a/ui/views/examples/link_example.cc b/ui/views/examples/link_example.cc
new file mode 100644
index 0000000..7b81d88
--- /dev/null
+++ b/ui/views/examples/link_example.cc
@@ -0,0 +1,33 @@
+// 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/examples/link_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/link.h"
+#include "views/layout/fill_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+LinkExample::LinkExample(ExamplesMain* main)
+ : ExampleBase(main, "Link") {
+}
+
+LinkExample::~LinkExample() {
+}
+
+void LinkExample::CreateExampleView(views::View* container) {
+ link_ = new views::Link(ASCIIToUTF16("Click me!"));
+ link_->set_listener(this);
+
+ container->SetLayoutManager(new views::FillLayout);
+ container->AddChildView(link_);
+}
+
+void LinkExample::LinkClicked(views::Link* source, int event_flags) {
+ PrintStatus("Link clicked");
+}
+
+} // namespace examples
diff --git a/ui/views/examples/link_example.h b/ui/views/examples/link_example.h
new file mode 100644
index 0000000..38513f6
--- /dev/null
+++ b/ui/views/examples/link_example.h
@@ -0,0 +1,40 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_LINK_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_LINK_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/link_listener.h"
+
+namespace views {
+class View;
+}
+
+namespace examples {
+
+class LinkExample : public ExampleBase,
+ public views::LinkListener {
+ public:
+ explicit LinkExample(ExamplesMain* main);
+ virtual ~LinkExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::LinkListener:
+ virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE;
+
+ views::Link* link_;
+
+ DISALLOW_COPY_AND_ASSIGN(LinkExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_LINK_EXAMPLE_H_
diff --git a/ui/views/examples/menu_example.cc b/ui/views/examples/menu_example.cc
new file mode 100644
index 0000000..15bfc0d
--- /dev/null
+++ b/ui/views/examples/menu_example.cc
@@ -0,0 +1,216 @@
+// 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/examples/menu_example.h"
+
+#include <set>
+
+#include "base/utf_string_conversions.h"
+#include "ui/base/models/simple_menu_model.h"
+#include "views/controls/button/menu_button.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/menu/menu_2.h"
+#include "views/controls/menu/view_menu_delegate.h"
+#include "views/layout/fill_layout.h"
+#include "views/view.h"
+
+namespace {
+
+class ExampleMenuModel : public ui::SimpleMenuModel,
+ public ui::SimpleMenuModel::Delegate {
+ public:
+ ExampleMenuModel();
+
+ void RunMenuAt(const gfx::Point& point);
+
+ // Overridden from ui::SimpleMenuModel::Delegate:
+ virtual bool IsCommandIdChecked(int command_id) const OVERRIDE;
+ virtual bool IsCommandIdEnabled(int command_id) const OVERRIDE;
+ virtual bool GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) OVERRIDE;
+ virtual void ExecuteCommand(int command_id) OVERRIDE;
+
+ private:
+ enum {
+ kGroupMakeDecision,
+ };
+
+ enum {
+ kCommandDoSomething,
+ kCommandSelectAscii,
+ kCommandSelectUtf8,
+ kCommandSelectUtf16,
+ kCommandCheckApple,
+ kCommandCheckOrange,
+ kCommandCheckKiwi,
+ kCommandGoHome,
+ };
+
+ scoped_ptr<views::Menu2> menu_;
+ scoped_ptr<ui::SimpleMenuModel> submenu_;
+ std::set<int> checked_fruits_;
+ int current_encoding_command_id_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExampleMenuModel);
+};
+
+class ExampleMenuButton : public views::MenuButton,
+ public views::ViewMenuDelegate {
+ public:
+ ExampleMenuButton(const string16& test, bool show_menu_marker);
+ virtual ~ExampleMenuButton();
+
+ private:
+ // Overridden from views::ViewMenuDelegate:
+ virtual void RunMenu(views::View* source, const gfx::Point& point) OVERRIDE;
+
+ scoped_ptr<ExampleMenuModel> menu_model_;
+ DISALLOW_COPY_AND_ASSIGN(ExampleMenuButton);
+};
+
+// ExampleMenuModel ---------------------------------------------------------
+
+ExampleMenuModel::ExampleMenuModel()
+ : ALLOW_THIS_IN_INITIALIZER_LIST(ui::SimpleMenuModel(this)),
+ current_encoding_command_id_(kCommandSelectAscii) {
+ AddItem(kCommandDoSomething, WideToUTF16(L"Do Something"));
+ AddSeparator();
+ AddRadioItem(kCommandSelectAscii,
+ WideToUTF16(L"ASCII"), kGroupMakeDecision);
+ AddRadioItem(kCommandSelectUtf8,
+ WideToUTF16(L"UTF-8"), kGroupMakeDecision);
+ AddRadioItem(kCommandSelectUtf16,
+ WideToUTF16(L"UTF-16"), kGroupMakeDecision);
+ AddSeparator();
+ AddCheckItem(kCommandCheckApple, WideToUTF16(L"Apple"));
+ AddCheckItem(kCommandCheckOrange, WideToUTF16(L"Orange"));
+ AddCheckItem(kCommandCheckKiwi, WideToUTF16(L"Kiwi"));
+ AddSeparator();
+ AddItem(kCommandGoHome, WideToUTF16(L"Go Home"));
+
+ submenu_.reset(new ui::SimpleMenuModel(this));
+ submenu_->AddItem(kCommandDoSomething, WideToUTF16(L"Do Something 2"));
+ AddSubMenu(0, ASCIIToUTF16("Submenu"), submenu_.get());
+ menu_.reset(new views::Menu2(this));
+}
+
+void ExampleMenuModel::RunMenuAt(const gfx::Point& point) {
+ menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPRIGHT);
+}
+
+bool ExampleMenuModel::IsCommandIdChecked(int command_id) const {
+ // Radio items.
+ if (command_id == current_encoding_command_id_)
+ return true;
+
+ // Check items.
+ if (checked_fruits_.find(command_id) != checked_fruits_.end())
+ return true;
+
+ return false;
+}
+
+bool ExampleMenuModel::IsCommandIdEnabled(int command_id) const {
+ // All commands are enabled except for kCommandGoHome.
+ return command_id != kCommandGoHome;
+}
+
+bool ExampleMenuModel::GetAcceleratorForCommandId(
+ int command_id,
+ ui::Accelerator* accelerator) {
+ // We don't use this in the example.
+ return false;
+}
+
+void ExampleMenuModel::ExecuteCommand(int command_id) {
+ switch (command_id) {
+ case kCommandDoSomething: {
+ LOG(INFO) << "Done something";
+ break;
+ }
+
+ // Radio items.
+ case kCommandSelectAscii: {
+ current_encoding_command_id_ = kCommandSelectAscii;
+ LOG(INFO) << "Selected ASCII";
+ break;
+ }
+ case kCommandSelectUtf8: {
+ current_encoding_command_id_ = kCommandSelectUtf8;
+ LOG(INFO) << "Selected UTF-8";
+ break;
+ }
+ case kCommandSelectUtf16: {
+ current_encoding_command_id_ = kCommandSelectUtf16;
+ LOG(INFO) << "Selected UTF-16";
+ break;
+ }
+
+ // Check items.
+ case kCommandCheckApple:
+ case kCommandCheckOrange:
+ case kCommandCheckKiwi: {
+ // Print what fruit is checked.
+ const char* checked_fruit = "";
+ if (command_id == kCommandCheckApple) {
+ checked_fruit = "Apple";
+ } else if (command_id == kCommandCheckOrange) {
+ checked_fruit = "Orange";
+ } else if (command_id == kCommandCheckKiwi) {
+ checked_fruit = "Kiwi";
+ }
+ LOG(INFO) << "Checked " << checked_fruit;
+
+ // Update the check status.
+ std::set<int>::iterator iter = checked_fruits_.find(command_id);
+ if (iter == checked_fruits_.end())
+ checked_fruits_.insert(command_id);
+ else
+ checked_fruits_.erase(iter);
+ break;
+ }
+ }
+}
+
+// ExampleMenuButton -----------------------------------------------------------
+
+ExampleMenuButton::ExampleMenuButton(const string16& test,
+ bool show_menu_marker)
+ : ALLOW_THIS_IN_INITIALIZER_LIST(
+ views::MenuButton(NULL, test, this, show_menu_marker)) {
+}
+
+ExampleMenuButton::~ExampleMenuButton() {
+}
+
+void ExampleMenuButton::RunMenu(views::View* source, const gfx::Point& point) {
+ if (!menu_model_.get())
+ menu_model_.reset(new ExampleMenuModel);
+
+ menu_model_->RunMenuAt(point);
+}
+
+} // namespace
+
+namespace examples {
+
+MenuExample::MenuExample(ExamplesMain* main)
+ : ExampleBase(main, "Menu") {
+}
+
+MenuExample::~MenuExample() {
+}
+
+void MenuExample::CreateExampleView(views::View* container) {
+ // views::Menu2 is not a sub class of View, hence we cannot directly
+ // add to the container. Instead, we add a button to open a menu.
+ const bool show_menu_marker = true;
+ ExampleMenuButton* menu_button = new ExampleMenuButton(
+ ASCIIToUTF16("Open a menu"), show_menu_marker);
+ container->SetLayoutManager(new views::FillLayout);
+ container->AddChildView(menu_button);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/menu_example.h b/ui/views/examples/menu_example.h
new file mode 100644
index 0000000..9c7a640
--- /dev/null
+++ b/ui/views/examples/menu_example.h
@@ -0,0 +1,32 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_MENU_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_MENU_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+
+namespace examples {
+
+// MenuExample demonstrates how to use the Menu class.
+class MenuExample : public ExampleBase {
+ public:
+ explicit MenuExample(ExamplesMain* main);
+ virtual ~MenuExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MenuExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_MENU_EXAMPLE_H_
diff --git a/ui/views/examples/message_box_example.cc b/ui/views/examples/message_box_example.cc
new file mode 100644
index 0000000..5da917f
--- /dev/null
+++ b/ui/views/examples/message_box_example.cc
@@ -0,0 +1,67 @@
+// 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/examples/message_box_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/message_box_view.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+MessageBoxExample::MessageBoxExample(ExamplesMain* main)
+ : ExampleBase(main, "Message Box View") {
+}
+
+MessageBoxExample::~MessageBoxExample() {
+}
+
+void MessageBoxExample::CreateExampleView(views::View* container) {
+ message_box_view_ = new views::MessageBoxView(
+ 0,
+ ASCIIToUTF16("Message Box Message"),
+ ASCIIToUTF16("Default Prompt"));
+ status_ = new views::TextButton(this, ASCIIToUTF16("Show Status"));
+ toggle_ = new views::TextButton(this, ASCIIToUTF16("Toggle Checkbox"));
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ message_box_view_->SetCheckBoxLabel(ASCIIToUTF16("Check Box"));
+
+ const int message_box_column = 0;
+ views::ColumnSet* column_set = layout->AddColumnSet(message_box_column);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, message_box_column);
+ layout->AddView(message_box_view_);
+
+ const int button_column = 1;
+ column_set = layout->AddColumnSet(button_column);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0 /* no expand */, button_column);
+
+ layout->AddView(status_);
+ layout->AddView(toggle_);
+}
+
+void MessageBoxExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == status_) {
+ message_box_view_->SetCheckBoxLabel(
+ ASCIIToUTF16(BoolToOnOff(message_box_view_->IsCheckBoxSelected())));
+ PrintStatus(message_box_view_->IsCheckBoxSelected() ?
+ "Check Box Selected" : "Check Box Not Selected");
+ } else if (sender == toggle_) {
+ message_box_view_->SetCheckBoxSelected(
+ !message_box_view_->IsCheckBoxSelected());
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/message_box_example.h b/ui/views/examples/message_box_example.h
new file mode 100644
index 0000000..cc45486
--- /dev/null
+++ b/ui/views/examples/message_box_example.h
@@ -0,0 +1,50 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+
+namespace views {
+class MessageBoxView;
+}
+
+namespace examples {
+
+// A MessageBoxView example. This tests some of checkbox features as well.
+class MessageBoxExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit MessageBoxExample(ExamplesMain* main);
+ virtual ~MessageBoxExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // The MessageBoxView to be tested.
+ views::MessageBoxView* message_box_view_;
+
+ // Control buttons to show the status and toggle checkbox in the
+ // message box.
+ views::Button* status_;
+ views::Button* toggle_;
+
+ DISALLOW_COPY_AND_ASSIGN(MessageBoxExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
diff --git a/ui/views/examples/native_theme_button_example.cc b/ui/views/examples/native_theme_button_example.cc
new file mode 100644
index 0000000..e11bfcd
--- /dev/null
+++ b/ui/views/examples/native_theme_button_example.cc
@@ -0,0 +1,255 @@
+// 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/examples/native_theme_button_example.h"
+
+#include <string>
+
+#include "base/logging.h"
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "ui/base/animation/throb_animation.h"
+#include "ui/base/models/combobox_model.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/examples/example_combobox_model.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/native_theme_painter.h"
+
+namespace {
+
+const char* kParts[] = {
+ "PushButton",
+ "RadioButton",
+ "Checkbox",
+};
+
+const char* kStates[] = {
+ "Disabled",
+ "Normal",
+ "Hot",
+ "Pressed",
+ "<Dynamic>",
+};
+
+} // namespace
+
+namespace examples {
+
+ExampleNativeThemeButton::ExampleNativeThemeButton(
+ views::ButtonListener* listener,
+ views::Combobox* cb_part,
+ views::Combobox* cb_state)
+ : CustomButton(listener),
+ cb_part_(cb_part),
+ cb_state_(cb_state),
+ count_(0),
+ is_checked_(false),
+ is_indeterminate_(false) {
+ cb_part_->set_listener(this);
+ cb_state_->set_listener(this);
+
+ painter_.reset(new views::NativeThemePainter(this));
+ set_background(views::Background::CreateBackgroundPainter(
+ false, painter_.get()));
+}
+
+ExampleNativeThemeButton::~ExampleNativeThemeButton() {
+}
+
+std::string ExampleNativeThemeButton::MessWithState() {
+ const char* message = NULL;
+ switch (GetThemePart()) {
+ case gfx::NativeTheme::kPushButton:
+ message = "Pressed! count:%d";
+ break;
+ case gfx::NativeTheme::kRadio:
+ is_checked_ = !is_checked_;
+ message = is_checked_ ? "Checked! count:%d" : "Unchecked! count:%d";
+ break;
+ case gfx::NativeTheme::kCheckbox:
+ if (is_indeterminate_) {
+ is_checked_ = false;
+ is_indeterminate_ = false;
+ } else if (!is_checked_) {
+ is_checked_ = true;
+ } else {
+ is_checked_ = false;
+ is_indeterminate_ = true;
+ }
+
+ message = is_checked_ ? "Checked! count:%d" :
+ is_indeterminate_ ? "Indeterminate! count:%d" : "Unchecked! count:%d";
+ break;
+ default:
+ DCHECK(false);
+ }
+
+ return base::StringPrintf(message, ++count_);
+}
+
+void ExampleNativeThemeButton::ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) {
+ SchedulePaint();
+}
+
+gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
+ int selected = cb_part_->selected_item();
+ switch (selected) {
+ case 0:
+ return gfx::NativeTheme::kPushButton;
+ case 1:
+ return gfx::NativeTheme::kRadio;
+ case 2:
+ return gfx::NativeTheme::kCheckbox;
+ default:
+ DCHECK(false);
+ }
+ return gfx::NativeTheme::kPushButton;
+}
+
+gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
+ gfx::NativeTheme::ExtraParams extra;
+ gfx::NativeTheme::State state = GetThemeState(&extra);
+ gfx::Size size(gfx::NativeTheme::instance()->GetPartSize(GetThemePart(),
+ state,
+ extra));
+ gfx::Rect rect(size);
+ rect.set_x(GetMirroredXForRect(rect));
+ return rect;
+}
+
+gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState(
+ gfx::NativeTheme::ExtraParams* params) const {
+ GetExtraParams(params);
+
+ int selected = cb_state_->selected_item();
+ if (selected > 3) {
+ switch (state()) {
+ case BS_DISABLED:
+ return gfx::NativeTheme::kDisabled;
+ case BS_NORMAL:
+ return gfx::NativeTheme::kNormal;
+ case BS_HOT:
+ return gfx::NativeTheme::kHovered;
+ case BS_PUSHED:
+ return gfx::NativeTheme::kPressed;
+ default:
+ DCHECK(false);
+ }
+ }
+
+ switch (selected) {
+ case 0:
+ return gfx::NativeTheme::kDisabled;
+ case 1:
+ return gfx::NativeTheme::kNormal;
+ case 2:
+ return gfx::NativeTheme::kHovered;
+ case 3:
+ return gfx::NativeTheme::kPressed;
+ default:
+ DCHECK(false);
+ }
+ return gfx::NativeTheme::kNormal;
+}
+
+void ExampleNativeThemeButton::GetExtraParams(
+ gfx::NativeTheme::ExtraParams* params) const {
+
+ params->button.checked = is_checked_;
+ params->button.indeterminate = is_indeterminate_;
+ params->button.is_default = false;
+ params->button.has_border = false;
+ params->button.classic_state = 0;
+ params->button.background_color = SkColorSetARGB(0, 0, 0, 0);
+}
+
+const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
+ int selected = cb_state_->selected_item();
+ return selected <= 3 ? NULL : hover_animation_.get();
+}
+
+gfx::NativeTheme::State ExampleNativeThemeButton::GetBackgroundThemeState(
+ gfx::NativeTheme::ExtraParams* params) const {
+ GetExtraParams(params);
+ return gfx::NativeTheme::kNormal;
+}
+
+gfx::NativeTheme::State ExampleNativeThemeButton::GetForegroundThemeState(
+ gfx::NativeTheme::ExtraParams* params) const {
+ GetExtraParams(params);
+ return gfx::NativeTheme::kHovered;
+}
+
+gfx::Size ExampleNativeThemeButton::GetPreferredSize() {
+ return painter_.get() == NULL ? gfx::Size() : painter_->GetPreferredSize();
+}
+
+void ExampleNativeThemeButton::OnPaintBackground(gfx::Canvas* canvas) {
+ // Fill the background with a known colour so that we know where the bounds
+ // of the View are.
+ canvas->FillRect(SkColorSetRGB(255, 128, 128), GetLocalBounds());
+ CustomButton::OnPaintBackground(canvas);
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
+NativeThemeButtonExample::NativeThemeButtonExample(ExamplesMain* main)
+ : ExampleBase(main, "Native Theme Button") {
+}
+
+NativeThemeButtonExample::~NativeThemeButtonExample() {
+}
+
+void NativeThemeButtonExample::CreateExampleView(views::View* container) {
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ layout->AddPaddingRow(0, 8);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0.1f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.9f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(ASCIIToUTF16("Part:")));
+ views::Combobox* cb_part = new views::Combobox(
+ new ExampleComboboxModel(kParts, arraysize(kParts)));
+ cb_part->SetSelectedItem(0);
+ layout->AddView(cb_part);
+
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(ASCIIToUTF16("State:")));
+ views::Combobox* cb_state = new views::Combobox(
+ new ExampleComboboxModel(kStates, arraysize(kStates)));
+ cb_state->SetSelectedItem(0);
+ layout->AddView(cb_state);
+
+ layout->AddPaddingRow(0, 32);
+
+ button_ = new ExampleNativeThemeButton(this, cb_part, cb_state);
+
+ column_set = layout->AddColumnSet(1);
+ column_set->AddPaddingColumn(0, 16);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 16);
+ layout->StartRow(1, 1);
+ layout->AddView(button_);
+
+ layout->AddPaddingRow(0, 8);
+}
+
+void NativeThemeButtonExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ PrintStatus(button_->MessWithState().c_str());
+}
+
+} // namespace examples
diff --git a/ui/views/examples/native_theme_button_example.h b/ui/views/examples/native_theme_button_example.h
new file mode 100644
index 0000000..59f5e97
--- /dev/null
+++ b/ui/views/examples/native_theme_button_example.h
@@ -0,0 +1,93 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_NATIVE_THEME_BUTTON_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_NATIVE_THEME_BUTTON_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "ui/gfx/native_theme.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/custom_button.h"
+#include "views/controls/combobox/combobox.h"
+#include "views/native_theme_delegate.h"
+#include "views/native_theme_painter.h"
+
+namespace views {
+class Combobox;
+class NativeThemePainter;
+}
+
+namespace examples {
+
+// A subclass of button to test native theme rendering.
+class ExampleNativeThemeButton : public views::CustomButton,
+ public views::NativeThemeDelegate,
+ public views::Combobox::Listener {
+ public:
+ ExampleNativeThemeButton(views::ButtonListener* listener,
+ views::Combobox* cb_part,
+ views::Combobox* cb_state);
+ virtual ~ExampleNativeThemeButton();
+
+ std::string MessWithState();
+
+ private:
+ // Overridden from View:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual void OnPaintBackground(gfx::Canvas* canvas) OVERRIDE;
+
+ // Overridden from views::Combobox::Listener:
+ virtual void ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) OVERRIDE;
+
+ // Overridden from views::NativeThemePainter::Delegate:
+ virtual gfx::NativeTheme::Part GetThemePart() const OVERRIDE;
+ virtual gfx::Rect GetThemePaintRect() const OVERRIDE;
+ virtual gfx::NativeTheme::State GetThemeState(
+ gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
+ virtual const ui::Animation* GetThemeAnimation() const OVERRIDE;
+ virtual gfx::NativeTheme::State GetBackgroundThemeState(
+ gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
+ virtual gfx::NativeTheme::State GetForegroundThemeState(
+ gfx::NativeTheme::ExtraParams* params) const OVERRIDE;
+
+ void GetExtraParams(gfx::NativeTheme::ExtraParams* params) const;
+
+ scoped_ptr<views::NativeThemePainter> painter_;
+ views::Combobox* cb_part_;
+ views::Combobox* cb_state_;
+ int count_;
+ bool is_checked_;
+ bool is_indeterminate_;
+
+ DISALLOW_COPY_AND_ASSIGN(ExampleNativeThemeButton);
+};
+
+// NativeThemeButtonExample shows how a View can use the NativeThemePainter
+// to paints its background and get a native look.
+class NativeThemeButtonExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit NativeThemeButtonExample(ExamplesMain* main);
+ virtual ~NativeThemeButtonExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // The only control in this test.
+ ExampleNativeThemeButton* button_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeThemeButtonExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_NATIVE_THEME_BUTTON_EXAMPLE_H_
diff --git a/ui/views/examples/native_theme_checkbox_example.cc b/ui/views/examples/native_theme_checkbox_example.cc
new file mode 100644
index 0000000..8c2bb55
--- /dev/null
+++ b/ui/views/examples/native_theme_checkbox_example.cc
@@ -0,0 +1,35 @@
+// 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/examples/native_theme_checkbox_example.h"
+
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/button/radio_button.h"
+#include "views/layout/fill_layout.h"
+
+namespace examples {
+
+NativeThemeCheckboxExample::NativeThemeCheckboxExample(ExamplesMain* main)
+ : ExampleBase(main, "Native Theme Checkbox"),
+ count_(0) {
+}
+
+NativeThemeCheckboxExample::~NativeThemeCheckboxExample() {
+}
+
+void NativeThemeCheckboxExample::CreateExampleView(views::View* container) {
+ button_ = new views::Checkbox(ASCIIToUTF16("Checkbox"));
+ button_->set_listener(this);
+ container->SetLayoutManager(new views::FillLayout);
+ container->AddChildView(button_);
+}
+
+void NativeThemeCheckboxExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ PrintStatus(base::StringPrintf("Pressed! count: %d", ++count_).c_str());
+}
+
+} // namespace examples
diff --git a/ui/views/examples/native_theme_checkbox_example.h b/ui/views/examples/native_theme_checkbox_example.h
new file mode 100644
index 0000000..4ab6957
--- /dev/null
+++ b/ui/views/examples/native_theme_checkbox_example.h
@@ -0,0 +1,45 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "ui/gfx/native_theme.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+
+namespace views {
+class Checkbox;
+}
+
+namespace examples {
+
+// NativeThemeCheckboxExample exercises a Checkbox control.
+class NativeThemeCheckboxExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit NativeThemeCheckboxExample(ExamplesMain* main);
+ virtual ~NativeThemeCheckboxExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // The only control in this test.
+ views::Checkbox* button_;
+
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeThemeCheckboxExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
diff --git a/ui/views/examples/native_widget_views_example.cc b/ui/views/examples/native_widget_views_example.cc
new file mode 100644
index 0000000..0e00035
--- /dev/null
+++ b/ui/views/examples/native_widget_views_example.cc
@@ -0,0 +1,95 @@
+// 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/examples/native_widget_views_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "ui/gfx/canvas.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/test/test_views_delegate.h"
+#include "views/view.h"
+#include "views/widget/native_widget_views.h"
+#include "views/widget/widget.h"
+
+namespace examples {
+
+// A ContentView for our example widget. Contains a variety of controls for
+// testing NativeWidgetViews event handling. If any part of the Widget's bounds
+// are rendered red, something went wrong.
+class TestContentView : public views::View,
+ public views::ButtonListener {
+ public:
+ TestContentView()
+ : click_count_(0),
+ ALLOW_THIS_IN_INITIALIZER_LIST(
+ button_(new views::TextButton(this, ASCIIToUTF16("Click me!")))) {
+ AddChildView(button_);
+ }
+ virtual ~TestContentView() {
+ }
+
+ // Overridden from views::View:
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+ SkColor color = click_count_ % 2 == 0 ? SK_ColorGREEN : SK_ColorBLUE;
+ canvas->FillRect(color, GetLocalBounds());
+ }
+ virtual void Layout() OVERRIDE {
+ button_->SetBounds(10, 10, width() - 20, height() - 20);
+ }
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE {
+ if (sender == button_) {
+ ++click_count_;
+ SchedulePaint();
+ }
+ }
+
+ private:
+ int click_count_;
+ views::TextButton* button_;
+
+ DISALLOW_COPY_AND_ASSIGN(TestContentView);
+};
+
+NativeWidgetViewsExample::NativeWidgetViewsExample(ExamplesMain* main)
+ : ExampleBase(main, "Native Widget Views") {
+}
+
+NativeWidgetViewsExample::~NativeWidgetViewsExample() {
+}
+
+void NativeWidgetViewsExample::CreateExampleView(views::View* container) {
+ views::Widget* widget = new views::Widget;
+ views::NativeWidgetViews* nwv = new views::NativeWidgetViews(widget);
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
+
+ // Set parent View for widget. Real code should use params.parent_widget
+ // but since tabs are implemented with Views instead of Widgets on Windows
+ // we have to hack the parenting.
+#if defined(OS_WIN)
+ views::TestViewsDelegate* test_views_delegate =
+ static_cast<views::TestViewsDelegate*>(
+ views::ViewsDelegate::views_delegate);
+ views::View* old_default_parent_view =
+ test_views_delegate->GetDefaultParentView();
+ test_views_delegate->set_default_parent_view(container);
+#else
+ params.parent_widget = container->GetWidget();
+#endif
+
+ params.native_widget = nwv;
+ widget->Init(params);
+
+#if defined(OS_WIN)
+ test_views_delegate->set_default_parent_view(old_default_parent_view);
+#endif
+
+ widget->SetContentsView(new TestContentView);
+ widget->SetBounds(gfx::Rect(10, 10, 300, 150));
+}
+
+} // namespace examples
diff --git a/ui/views/examples/native_widget_views_example.h b/ui/views/examples/native_widget_views_example.h
new file mode 100644
index 0000000..339016c
--- /dev/null
+++ b/ui/views/examples/native_widget_views_example.h
@@ -0,0 +1,29 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+
+namespace examples {
+
+class NativeWidgetViewsExample : public ExampleBase {
+ public:
+ explicit NativeWidgetViewsExample(ExamplesMain* main);
+ virtual ~NativeWidgetViewsExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NativeWidgetViewsExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_NATIVE_WIDGET_VIEWS_EXAMPLE_H_
diff --git a/ui/views/examples/progress_bar_example.cc b/ui/views/examples/progress_bar_example.cc
new file mode 100644
index 0000000..5fabe7a
--- /dev/null
+++ b/ui/views/examples/progress_bar_example.cc
@@ -0,0 +1,69 @@
+// 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/examples/progress_bar_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/progress_bar.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace {
+
+const double kStepSize = 0.1;
+
+double ClampToMin(double percent) {
+ return std::min(std::max(percent, 0.0), 1.0);
+}
+
+} // namespace
+
+namespace examples {
+
+ProgressBarExample::ProgressBarExample(ExamplesMain* main)
+ : ExampleBase(main, "Progress Bar"),
+ minus_button_(NULL),
+ plus_button_(NULL),
+ progress_bar_(NULL),
+ current_percent_(0.0) {
+}
+
+ProgressBarExample::~ProgressBarExample() {
+}
+
+void ProgressBarExample::CreateExampleView(views::View* container) {
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL,
+ 0, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0, 0);
+ minus_button_ = new views::TextButton(this, ASCIIToUTF16("-"));
+ layout->AddView(minus_button_);
+ progress_bar_ = new views::ProgressBar();
+ layout->AddView(progress_bar_);
+ plus_button_ = new views::TextButton(this, ASCIIToUTF16("+"));
+ layout->AddView(plus_button_);
+}
+
+void ProgressBarExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == minus_button_)
+ current_percent_ = ClampToMin(current_percent_ - kStepSize);
+ else if (sender == plus_button_)
+ current_percent_ = ClampToMin(current_percent_ + kStepSize);
+
+ progress_bar_->SetValue(current_percent_);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/progress_bar_example.h b/ui/views/examples/progress_bar_example.h
new file mode 100644
index 0000000..08724b2
--- /dev/null
+++ b/ui/views/examples/progress_bar_example.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+
+namespace views {
+class ProgressBar;
+}
+
+namespace examples {
+
+class ProgressBarExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit ProgressBarExample(ExamplesMain* main);
+ virtual ~ProgressBarExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* button,
+ const views::Event& event) OVERRIDE;
+
+ views::Button* minus_button_;
+ views::Button* plus_button_;
+ views::ProgressBar* progress_bar_;
+ double current_percent_;
+
+ DISALLOW_COPY_AND_ASSIGN(ProgressBarExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_PROGRESS_BAR_EXAMPLE_H_
diff --git a/ui/views/examples/radio_button_example.cc b/ui/views/examples/radio_button_example.cc
new file mode 100644
index 0000000..6450248
--- /dev/null
+++ b/ui/views/examples/radio_button_example.cc
@@ -0,0 +1,66 @@
+// 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/examples/radio_button_example.h"
+
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/text_button.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+RadioButtonExample::RadioButtonExample(ExamplesMain* main)
+ : ExampleBase(main, "Radio Button"), count_(0) {
+}
+
+RadioButtonExample::~RadioButtonExample() {
+}
+
+void RadioButtonExample::CreateExampleView(views::View* container) {
+ select_ = new views::TextButton(this, ASCIIToUTF16("Select"));
+ status_ = new views::TextButton(this, ASCIIToUTF16("Show Status"));
+
+ int group = 1;
+ for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
+ radio_buttons_[i] = new views::RadioButton(
+ UTF8ToUTF16(base::StringPrintf(
+ "Radio %d in group %d", static_cast<int>(i) + 1, group)),
+ group);
+ radio_buttons_[i]->set_listener(this);
+ }
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1.0f, views::GridLayout::USE_PREF, 0, 0);
+ for (size_t i = 0; i < arraysize(radio_buttons_); ++i) {
+ layout->StartRow(0, 0);
+ layout->AddView(radio_buttons_[i]);
+ }
+ layout->StartRow(0, 0);
+ layout->AddView(select_);
+ layout->StartRow(0, 0);
+ layout->AddView(status_);
+}
+
+void RadioButtonExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == select_) {
+ radio_buttons_[2]->SetChecked(true);
+ } else if (sender == status_) {
+ // Show the state of radio buttons.
+ PrintStatus("Group: 1:%s, 2:%s, 3:%s",
+ BoolToOnOff(radio_buttons_[0]->checked()),
+ BoolToOnOff(radio_buttons_[1]->checked()),
+ BoolToOnOff(radio_buttons_[2]->checked()));
+ } else {
+ PrintStatus("Pressed! count:%d", ++count_);
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/radio_button_example.h b/ui/views/examples/radio_button_example.h
new file mode 100644
index 0000000..44e59b1
--- /dev/null
+++ b/ui/views/examples/radio_button_example.h
@@ -0,0 +1,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.
+
+#ifndef UI_VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/radio_button.h"
+
+namespace events {
+class TextButton;
+}
+
+namespace examples {
+
+class RadioButtonExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit RadioButtonExample(ExamplesMain* main);
+ virtual ~RadioButtonExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // Group of 3 radio buttons.
+ views::RadioButton* radio_buttons_[3];
+
+ // Control button to select radio buttons, and show the status of buttons.
+ views::TextButton* select_;
+ views::TextButton* status_;
+
+ // The number of times the button is pressed.
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(RadioButtonExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
diff --git a/ui/views/examples/scroll_view_example.cc b/ui/views/examples/scroll_view_example.cc
new file mode 100644
index 0000000..ddd9af9
--- /dev/null
+++ b/ui/views/examples/scroll_view_example.cc
@@ -0,0 +1,114 @@
+// 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/examples/scroll_view_example.h"
+
+#include "base/stringprintf.h"
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/radio_button.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+// ScrollView's content, which draws gradient color on background.
+// TODO(oshima): add child views as well.
+class ScrollViewExample::ScrollableView : public views::View {
+ public:
+ ScrollableView() {
+ SetColor(SK_ColorRED, SK_ColorCYAN);
+ AddChildView(new views::TextButton(NULL, ASCIIToUTF16("Button")));
+ AddChildView(new views::RadioButton(ASCIIToUTF16("Radio Button"), 0));
+ }
+
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(width(), height());
+ }
+
+ void SetColor(SkColor from, SkColor to) {
+ set_background(
+ views::Background::CreateVerticalGradientBackground(from, to));
+ }
+
+ void PlaceChildY(int index, int y) {
+ views::View* view = child_at(index);
+ gfx::Size size = view->GetPreferredSize();
+ view->SetBounds(0, y, size.width(), size.height());
+ }
+
+ virtual void Layout() {
+ PlaceChildY(0, 0);
+ PlaceChildY(1, height() / 2);
+ SizeToPreferredSize();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ScrollableView);
+};
+
+ScrollViewExample::ScrollViewExample(ExamplesMain* main)
+ : ExampleBase(main, "Scroll View") {
+}
+
+ScrollViewExample::~ScrollViewExample() {
+}
+
+void ScrollViewExample::CreateExampleView(views::View* container) {
+ wide_ = new views::TextButton(this, ASCIIToUTF16("Wide"));
+ tall_ = new views::TextButton(this, ASCIIToUTF16("Tall"));
+ big_square_ = new views::TextButton(this, ASCIIToUTF16("Big Square"));
+ small_square_ = new views::TextButton(this, ASCIIToUTF16("Small Square"));
+ scroll_to_ = new views::TextButton(this, ASCIIToUTF16("Scroll to"));
+ scrollable_ = new ScrollableView();
+ scroll_view_ = new views::ScrollView();
+ scroll_view_->SetContents(scrollable_);
+ scrollable_->SetBounds(0, 0, 1000, 100);
+ scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ // Add scroll view.
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1, 0);
+ layout->AddView(scroll_view_);
+
+ // Add control buttons.
+ column_set = layout->AddColumnSet(1);
+ for (int i = 0; i < 5; i++) {
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ }
+ layout->StartRow(0, 1);
+ layout->AddView(wide_);
+ layout->AddView(tall_);
+ layout->AddView(big_square_);
+ layout->AddView(small_square_);
+ layout->AddView(scroll_to_);
+}
+
+void ScrollViewExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == wide_) {
+ scrollable_->SetBounds(0, 0, 1000, 100);
+ scrollable_->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
+ } else if (sender == tall_) {
+ scrollable_->SetBounds(0, 0, 100, 1000);
+ scrollable_->SetColor(SK_ColorRED, SK_ColorCYAN);
+ } else if (sender == big_square_) {
+ scrollable_->SetBounds(0, 0, 1000, 1000);
+ scrollable_->SetColor(SK_ColorRED, SK_ColorGREEN);
+ } else if (sender == small_square_) {
+ scrollable_->SetBounds(0, 0, 100, 100);
+ scrollable_->SetColor(SK_ColorYELLOW, SK_ColorGREEN);
+ } else if (sender == scroll_to_) {
+ scroll_view_->ScrollContentsRegionToBeVisible(
+ gfx::Rect(20, 500, 1000, 500));
+ }
+ scroll_view_->Layout();
+}
+
+} // namespace examples
diff --git a/ui/views/examples/scroll_view_example.h b/ui/views/examples/scroll_view_example.h
new file mode 100644
index 0000000..77d618a
--- /dev/null
+++ b/ui/views/examples/scroll_view_example.h
@@ -0,0 +1,53 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_SCROLL_VIEW_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_SCROLL_VIEW_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/scroll_view.h"
+
+namespace examples {
+
+class ScrollViewExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit ScrollViewExample(ExamplesMain* main);
+ virtual ~ScrollViewExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // Control buttons to change the size of scrollable and jump to
+ // predefined position.
+ views::TextButton* wide_;
+ views::TextButton* tall_;
+ views::TextButton* big_square_;
+ views::TextButton* small_square_;
+ views::TextButton* scroll_to_;
+
+ class ScrollableView;
+ // The content of the scroll view.
+ ScrollableView* scrollable_;
+
+ // The scroll view to test.
+ views::ScrollView* scroll_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(ScrollViewExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_SCROLL_VIEW_EXAMPLE_H_
diff --git a/ui/views/examples/single_split_view_example.cc b/ui/views/examples/single_split_view_example.cc
new file mode 100644
index 0000000..df57373
--- /dev/null
+++ b/ui/views/examples/single_split_view_example.cc
@@ -0,0 +1,89 @@
+// 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/examples/single_split_view_example.h"
+
+#include "views/controls/single_split_view.h"
+#include "views/layout/grid_layout.h"
+
+namespace {
+
+// SingleSplitView's content, which draws gradient color on background.
+class SplittedView : public views::View {
+ public:
+ SplittedView();
+ virtual ~SplittedView();
+
+ void SetColor(SkColor from, SkColor to);
+
+ private:
+ // Overridden from views::View:
+ virtual gfx::Size GetPreferredSize() OVERRIDE;
+ virtual gfx::Size GetMinimumSize() OVERRIDE;
+ virtual void Layout() OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(SplittedView);
+};
+
+SplittedView::SplittedView() {
+ SetColor(SK_ColorRED, SK_ColorGREEN);
+}
+
+SplittedView::~SplittedView() {
+}
+
+void SplittedView::SetColor(SkColor from, SkColor to) {
+ set_background(views::Background::CreateVerticalGradientBackground(from, to));
+}
+
+gfx::Size SplittedView::GetPreferredSize() {
+ return gfx::Size(width(), height());
+}
+
+gfx::Size SplittedView::GetMinimumSize() {
+ return gfx::Size(10, 10);
+}
+
+void SplittedView::Layout() {
+ SizeToPreferredSize();
+}
+
+} // namespace
+
+namespace examples {
+
+SingleSplitViewExample::SingleSplitViewExample(ExamplesMain* main)
+ : ExampleBase(main, "Single Split View") {
+}
+
+SingleSplitViewExample::~SingleSplitViewExample() {
+}
+
+void SingleSplitViewExample::CreateExampleView(views::View* container) {
+ SplittedView* splitted_view_1 = new SplittedView;
+ SplittedView* splitted_view_2 = new SplittedView;
+
+ splitted_view_1->SetColor(SK_ColorYELLOW, SK_ColorCYAN);
+
+ single_split_view_ = new views::SingleSplitView(
+ splitted_view_1, splitted_view_2,
+ views::SingleSplitView::HORIZONTAL_SPLIT,
+ this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1, 0);
+ layout->AddView(single_split_view_);
+}
+
+bool SingleSplitViewExample::SplitHandleMoved(views::SingleSplitView* sender) {
+ PrintStatus("Splitter moved");
+ return true;
+}
+
+} // namespace examples
diff --git a/ui/views/examples/single_split_view_example.h b/ui/views/examples/single_split_view_example.h
new file mode 100644
index 0000000..6f70184
--- /dev/null
+++ b/ui/views/examples/single_split_view_example.h
@@ -0,0 +1,35 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/single_split_view_listener.h"
+
+namespace examples {
+
+class SingleSplitViewExample : public ExampleBase,
+ public views::SingleSplitViewListener {
+ public:
+ explicit SingleSplitViewExample(ExamplesMain* main);
+ virtual ~SingleSplitViewExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ virtual bool SplitHandleMoved(views::SingleSplitView* sender) OVERRIDE;
+
+ views::SingleSplitView* single_split_view_;
+
+ DISALLOW_COPY_AND_ASSIGN(SingleSplitViewExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_SINGLE_SPLIT_VIEW_EXAMPLE_H_
diff --git a/ui/views/examples/tabbed_pane_example.cc b/ui/views/examples/tabbed_pane_example.cc
new file mode 100644
index 0000000..5016e53b
--- /dev/null
+++ b/ui/views/examples/tabbed_pane_example.cc
@@ -0,0 +1,91 @@
+// 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/examples/tabbed_pane_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/tabbed_pane/tabbed_pane.h"
+#include "views/layout/grid_layout.h"
+
+namespace examples {
+
+TabbedPaneExample::TabbedPaneExample(ExamplesMain* main)
+ : ExampleBase(main, "Tabbed Pane") {
+}
+
+TabbedPaneExample::~TabbedPaneExample() {
+}
+
+void TabbedPaneExample::CreateExampleView(views::View* container) {
+ tabbed_pane_ = new views::TabbedPane();
+ tabbed_pane_->set_listener(this);
+ add_ = new views::TextButton(this, ASCIIToUTF16("Add"));
+ add_at_ = new views::TextButton(this, ASCIIToUTF16("Add At 1"));
+ remove_at_ = new views::TextButton(this, ASCIIToUTF16("Remove At 1"));
+ select_at_ = new views::TextButton(this, ASCIIToUTF16("Select At 1"));
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ const int tabbed_pane_column = 0;
+ views::ColumnSet* column_set = layout->AddColumnSet(tabbed_pane_column);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1.0f, views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, tabbed_pane_column);
+ layout->AddView(tabbed_pane_);
+
+ // Create a few tabs with a button first.
+ AddButton("Tab 1");
+ AddButton("Tab 2");
+
+ // Add control buttons horizontally.
+ const int button_column = 1;
+ column_set = layout->AddColumnSet(button_column);
+ for (int i = 0; i < 4; i++) {
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1.0f, views::GridLayout::USE_PREF, 0, 0);
+ }
+
+ layout->StartRow(0 /* no expand */, button_column);
+ layout->AddView(add_);
+ layout->AddView(add_at_);
+ layout->AddView(remove_at_);
+ layout->AddView(select_at_);
+}
+
+void TabbedPaneExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == add_) {
+ AddButton("Added");
+ } else if (sender == add_at_) {
+ const string16 label = ASCIIToUTF16("Added at 1");
+ tabbed_pane_->AddTabAtIndex(1, label,
+ new views::TextButton(NULL, label), true);
+ } else if (sender == remove_at_) {
+ if (tabbed_pane_->GetTabCount() > 1)
+ delete tabbed_pane_->RemoveTabAtIndex(1);
+ } else if (sender == select_at_) {
+ if (tabbed_pane_->GetTabCount() > 1)
+ tabbed_pane_->SelectTabAt(1);
+ }
+ PrintStatus();
+}
+
+void TabbedPaneExample::TabSelectedAt(int index) {
+ // Just print the status when selection changes.
+ PrintStatus();
+}
+
+void TabbedPaneExample::PrintStatus() {
+ ExampleBase::PrintStatus("Tab Count:%d, Selected Tab:%d",
+ tabbed_pane_->GetTabCount(),
+ tabbed_pane_->GetSelectedTabIndex());
+}
+
+void TabbedPaneExample::AddButton(const std::string& label) {
+ views::TextButton* button = new views::TextButton(NULL, ASCIIToUTF16(label));
+ tabbed_pane_->AddTab(ASCIIToUTF16(label), button);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/tabbed_pane_example.h b/ui/views/examples/tabbed_pane_example.h
new file mode 100644
index 0000000..1564ac6
--- /dev/null
+++ b/ui/views/examples/tabbed_pane_example.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/tabbed_pane/tabbed_pane_listener.h"
+
+namespace views {
+class TabbedPane;
+}
+
+namespace examples {
+
+// A TabbedPane example tests adding/removing/selecting tabs.
+class TabbedPaneExample : public ExampleBase,
+ public views::ButtonListener,
+ public views::TabbedPaneListener {
+ public:
+ explicit TabbedPaneExample(ExamplesMain* main);
+ virtual ~TabbedPaneExample();
+
+ // ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // views::TabbedPaneListener:
+ virtual void TabSelectedAt(int index) OVERRIDE;
+
+ // Print the status of the tab in the status area.
+ void PrintStatus();
+
+ void AddButton(const std::string& label);
+
+ // The tabbed pane to be tested.
+ views::TabbedPane* tabbed_pane_;
+
+ // Control buttons to add, remove or select tabs.
+ views::Button* add_;
+ views::Button* add_at_;
+ views::Button* remove_at_;
+ views::Button* select_at_;
+
+ DISALLOW_COPY_AND_ASSIGN(TabbedPaneExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_TABBED_PANE_EXAMPLE_H_
diff --git a/ui/views/examples/table2_example.cc b/ui/views/examples/table2_example.cc
new file mode 100644
index 0000000..4ee46b8
--- /dev/null
+++ b/ui/views/examples/table2_example.cc
@@ -0,0 +1,154 @@
+// 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/examples/table2_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/table/table_view2.h"
+#include "views/layout/grid_layout.h"
+
+namespace examples {
+
+Table2Example::Table2Example(ExamplesMain* main)
+ : ExampleBase(main, "Table2") {
+}
+
+Table2Example::~Table2Example() {
+}
+
+void Table2Example::CreateExampleView(views::View* container) {
+ column1_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Fruit column visible"));
+ column1_visible_checkbox_->SetChecked(true);
+ column1_visible_checkbox_->set_listener(this);
+ column2_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Color column visible"));
+ column2_visible_checkbox_->SetChecked(true);
+ column2_visible_checkbox_->set_listener(this);
+ column3_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Origin column visible"));
+ column3_visible_checkbox_->SetChecked(true);
+ column3_visible_checkbox_->set_listener(this);
+ column4_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Price column visible"));
+ column4_visible_checkbox_->SetChecked(true);
+ column4_visible_checkbox_->set_listener(this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ std::vector<ui::TableColumn> columns;
+ columns.push_back(
+ ui::TableColumn(0, ASCIIToUTF16("Fruit"), ui::TableColumn::LEFT, 100));
+ columns.push_back(
+ ui::TableColumn(1, ASCIIToUTF16("Color"), ui::TableColumn::LEFT, 100));
+ columns.push_back(
+ ui::TableColumn(2, ASCIIToUTF16("Origin"), ui::TableColumn::LEFT, 100));
+ columns.push_back(
+ ui::TableColumn(3, ASCIIToUTF16("Price"), ui::TableColumn::LEFT, 100));
+ const int options = (views::TableView2::SINGLE_SELECTION |
+ views::TableView2::RESIZABLE_COLUMNS |
+ views::TableView2::AUTOSIZE_COLUMNS |
+ views::TableView2::HORIZONTAL_LINES |
+ views::TableView2::VERTICAL_LINES);
+ table_ = new views::TableView2(this, columns, views::ICON_AND_TEXT, options);
+ table_->SetObserver(this);
+ icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon1_.allocPixels();
+ SkCanvas canvas1(icon1_);
+ canvas1.drawColor(SK_ColorRED);
+
+ icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon2_.allocPixels();
+ SkCanvas canvas2(icon2_);
+ canvas2.drawColor(SK_ColorBLUE);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, 0);
+ layout->AddView(table_);
+
+ column_set = layout->AddColumnSet(1);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0 /* no expand */, 1);
+
+ layout->AddView(column1_visible_checkbox_);
+ layout->AddView(column2_visible_checkbox_);
+ layout->AddView(column3_visible_checkbox_);
+ layout->AddView(column4_visible_checkbox_);
+}
+
+int Table2Example::RowCount() {
+ return 10;
+}
+
+string16 Table2Example::GetText(int row, int column_id) {
+ const char* const cells[5][4] = {
+ { "Orange", "Orange", "South america", "$5" },
+ { "Apple", "Green", "Canada", "$3" },
+ { "Blue berries", "Blue", "Mexico", "$10.3" },
+ { "Strawberries", "Red", "California", "$7" },
+ { "Cantaloupe", "Orange", "South america", "$5" }
+ };
+ return ASCIIToUTF16(cells[row % 5][column_id]);
+}
+
+SkBitmap Table2Example::GetIcon(int row) {
+ return row % 2 ? icon1_ : icon2_;
+}
+
+void Table2Example::SetObserver(ui::TableModelObserver* observer) {
+}
+
+void Table2Example::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ int index = 0;
+ bool show = true;
+ if (sender == column1_visible_checkbox_) {
+ index = 0;
+ show = column1_visible_checkbox_->checked();
+ } else if (sender == column2_visible_checkbox_) {
+ index = 1;
+ show = column2_visible_checkbox_->checked();
+ } else if (sender == column3_visible_checkbox_) {
+ index = 2;
+ show = column3_visible_checkbox_->checked();
+ } else if (sender == column4_visible_checkbox_) {
+ index = 3;
+ show = column4_visible_checkbox_->checked();
+ }
+ table_->SetColumnVisibility(index, show);
+}
+
+void Table2Example::OnSelectionChanged() {
+ PrintStatus("Selection changed: %d", table_->GetFirstSelectedRow());
+}
+
+void Table2Example::OnDoubleClick() {
+}
+
+void Table2Example::OnMiddleClick() {
+}
+
+void Table2Example::OnKeyDown(ui::KeyboardCode virtual_keycode) {
+}
+
+void Table2Example::OnTableViewDelete(views::TableView* table_view) {
+}
+
+void Table2Example::OnTableView2Delete(views::TableView2* table_view) {
+}
+
+} // namespace examples
diff --git a/ui/views/examples/table2_example.h b/ui/views/examples/table2_example.h
new file mode 100644
index 0000000..45ce2d4
--- /dev/null
+++ b/ui/views/examples/table2_example.h
@@ -0,0 +1,73 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/models/table_model.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+#include "views/controls/table/table_view_observer.h"
+
+namespace views {
+class Checkbox;
+class Event;
+class TableView2;
+}
+
+namespace examples {
+
+class Table2Example : public ExampleBase,
+ public ui::TableModel,
+ public views::ButtonListener,
+ public views::TableViewObserver {
+ public:
+ explicit Table2Example(ExamplesMain* main);
+ virtual ~Table2Example();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ // Overridden from TableModel:
+ virtual int RowCount() OVERRIDE;
+ virtual string16 GetText(int row, int column_id) OVERRIDE;
+ virtual SkBitmap GetIcon(int row) OVERRIDE;
+ virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // Overridden from views::TableViewObserver:
+ virtual void OnSelectionChanged() OVERRIDE;
+ virtual void OnDoubleClick() OVERRIDE;
+ virtual void OnMiddleClick() OVERRIDE;
+ virtual void OnKeyDown(ui::KeyboardCode virtual_keycode) OVERRIDE;
+ virtual void OnTableViewDelete(views::TableView* table_view) OVERRIDE;
+ virtual void OnTableView2Delete(views::TableView2* table_view) OVERRIDE;
+
+ private:
+ // The table to be tested.
+ views::TableView2* table_;
+
+ views::Checkbox* column1_visible_checkbox_;
+ views::Checkbox* column2_visible_checkbox_;
+ views::Checkbox* column3_visible_checkbox_;
+ views::Checkbox* column4_visible_checkbox_;
+
+ SkBitmap icon1_;
+ SkBitmap icon2_;
+
+ DISALLOW_COPY_AND_ASSIGN(Table2Example);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_TABLE2_EXAMPLE_H_
diff --git a/ui/views/examples/table_example.cc b/ui/views/examples/table_example.cc
new file mode 100644
index 0000000..06671d4
--- /dev/null
+++ b/ui/views/examples/table_example.cc
@@ -0,0 +1,141 @@
+// 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/examples/table_example.h"
+
+#include <vector>
+
+#include "base/utf_string_conversions.h"
+#include "third_party/skia/include/core/SkCanvas.h"
+#include "views/controls/button/checkbox.h"
+#include "views/layout/grid_layout.h"
+
+namespace examples {
+
+TableExample::TableExample(ExamplesMain* main)
+ : ExampleBase(main, "Table") {
+}
+
+TableExample::~TableExample() {
+}
+
+void TableExample::CreateExampleView(views::View* container) {
+ column1_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Fruit column visible"));
+ column1_visible_checkbox_->SetChecked(true);
+ column1_visible_checkbox_->set_listener(this);
+ column2_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Color column visible"));
+ column2_visible_checkbox_->SetChecked(true);
+ column2_visible_checkbox_->set_listener(this);
+ column3_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Origin column visible"));
+ column3_visible_checkbox_->SetChecked(true);
+ column3_visible_checkbox_->set_listener(this);
+ column4_visible_checkbox_ = new views::Checkbox(
+ ASCIIToUTF16("Price column visible"));
+ column4_visible_checkbox_->SetChecked(true);
+ column4_visible_checkbox_->set_listener(this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ std::vector<ui::TableColumn> columns;
+ columns.push_back(ui::TableColumn(0, L"Fruit", ui::TableColumn::LEFT, 100));
+ columns.push_back(ui::TableColumn(1, L"Color", ui::TableColumn::LEFT, 100));
+ columns.push_back(ui::TableColumn(2, L"Origin", ui::TableColumn::LEFT, 100));
+ columns.push_back(ui::TableColumn(3, L"Price", ui::TableColumn::LEFT, 100));
+ table_ = new views::TableView(this, columns, views::ICON_AND_TEXT,
+ true, true, true);
+ table_->SetObserver(this);
+ icon1_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon1_.allocPixels();
+ SkCanvas canvas1(icon1_);
+ canvas1.drawColor(SK_ColorRED);
+
+ icon2_.setConfig(SkBitmap::kARGB_8888_Config, 16, 16);
+ icon2_.allocPixels();
+ SkCanvas canvas2(icon2_);
+ canvas2.drawColor(SK_ColorBLUE);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(1 /* expand */, 0);
+ layout->AddView(table_);
+
+ column_set = layout->AddColumnSet(1);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.5f, views::GridLayout::USE_PREF, 0, 0);
+
+ layout->StartRow(0 /* no expand */, 1);
+
+ layout->AddView(column1_visible_checkbox_);
+ layout->AddView(column2_visible_checkbox_);
+ layout->AddView(column3_visible_checkbox_);
+ layout->AddView(column4_visible_checkbox_);
+}
+
+int TableExample::RowCount() {
+ return 10;
+}
+
+string16 TableExample::GetText(int row, int column_id) {
+ const char* const cells[5][4] = {
+ { "Orange", "Orange", "South america", "$5" },
+ { "Apple", "Green", "Canada", "$3" },
+ { "Blue berries", "Blue", "Mexico", "$10.3" },
+ { "Strawberries", "Red", "California", "$7" },
+ { "Cantaloupe", "Orange", "South america", "$5" },
+ };
+ return ASCIIToUTF16(cells[row % 5][column_id]);
+}
+
+SkBitmap TableExample::GetIcon(int row) {
+ return row % 2 ? icon1_ : icon2_;
+}
+
+void TableExample::SetObserver(ui::TableModelObserver* observer) {}
+
+void TableExample::OnSelectionChanged() {
+ PrintStatus("Selection changed");
+}
+
+void TableExample::OnDoubleClick() {}
+
+void TableExample::OnMiddleClick() {}
+
+void TableExample::OnKeyDown(ui::KeyboardCode virtual_keycode) {}
+
+void TableExample::OnTableViewDelete(views::TableView* table_view) {}
+
+void TableExample::OnTableView2Delete(views::TableView2* table_view) {}
+
+void TableExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ int index = 0;
+ bool show = true;
+ if (sender == column1_visible_checkbox_) {
+ index = 0;
+ show = column1_visible_checkbox_->checked();
+ } else if (sender == column2_visible_checkbox_) {
+ index = 1;
+ show = column2_visible_checkbox_->checked();
+ } else if (sender == column3_visible_checkbox_) {
+ index = 2;
+ show = column3_visible_checkbox_->checked();
+ } else if (sender == column4_visible_checkbox_) {
+ index = 3;
+ show = column4_visible_checkbox_->checked();
+ }
+ table_->SetColumnVisibility(index, show);
+}
+
+} // namespace examples
diff --git a/ui/views/examples/table_example.h b/ui/views/examples/table_example.h
new file mode 100644
index 0000000..c5b535a
--- /dev/null
+++ b/ui/views/examples/table_example.h
@@ -0,0 +1,74 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_TABLE_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_TABLE_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "third_party/skia/include/core/SkBitmap.h"
+#include "ui/base/models/table_model.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+#include "views/controls/table/table_view.h"
+#include "views/controls/table/table_view_observer.h"
+
+namespace views {
+class Checkbox;
+class Event;
+class TableView;
+}
+
+namespace examples {
+
+class TableExample : public ExampleBase,
+ public ui::TableModel,
+ public views::TableViewObserver,
+ public views::ButtonListener {
+ public:
+ explicit TableExample(ExamplesMain* main);
+ virtual ~TableExample();
+
+ // ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ // ui::TableModel:
+ virtual int RowCount() OVERRIDE;
+ virtual string16 GetText(int row, int column_id) OVERRIDE;
+ virtual SkBitmap GetIcon(int row) OVERRIDE;
+ virtual void SetObserver(ui::TableModelObserver* observer) OVERRIDE;
+
+ // views::TableViewObserver:
+ virtual void OnSelectionChanged() OVERRIDE;
+ virtual void OnDoubleClick() OVERRIDE;
+ virtual void OnMiddleClick() OVERRIDE;
+ virtual void OnKeyDown(ui::KeyboardCode virtual_keycode) OVERRIDE;
+ virtual void OnTableViewDelete(views::TableView* table_view) OVERRIDE;
+ virtual void OnTableView2Delete(views::TableView2* table_view) OVERRIDE;
+
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ private:
+ // The table to be tested.
+ views::TableView* table_;
+
+ views::Checkbox* column1_visible_checkbox_;
+ views::Checkbox* column2_visible_checkbox_;
+ views::Checkbox* column3_visible_checkbox_;
+ views::Checkbox* column4_visible_checkbox_;
+
+ SkBitmap icon1_;
+ SkBitmap icon2_;
+
+ DISALLOW_COPY_AND_ASSIGN(TableExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_TABLE_EXAMPLE_H_
diff --git a/ui/views/examples/text_example.cc b/ui/views/examples/text_example.cc
new file mode 100644
index 0000000..3b7c82d
--- /dev/null
+++ b/ui/views/examples/text_example.cc
@@ -0,0 +1,328 @@
+// 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/examples/text_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/canvas_skia.h"
+#include "ui/views/examples/example_combobox_model.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace {
+
+const char kShortText[] = "Batman";
+const char kMediumText[] = "The quick brown fox jumps over the lazy dog.";
+const char kLongText[] =
+ "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod "
+ "tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim "
+ "veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea "
+ "commodo consequat. Duis aute irure dolor in reprehenderit in voluptate "
+ "velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint "
+ "occaecat cupidatat non proident, sunt in culpa qui officia deserunt "
+ "mollit anim id est laborum.";
+const char kAmpersandText[] =
+ "The quick && &brown fo&x jumps over the lazy dog.";
+
+const char* kTextExamples[] = {
+ "Short",
+ "Medium",
+ "Long",
+ "Ampersands",
+};
+
+const char* kElidingBehaviors[] = {
+ "Ellipsis",
+ "None",
+#if defined(OS_WIN)
+ "Fade Tail",
+ "Fade Head",
+ "Fade Head and Tail",
+#endif
+};
+
+const char* kPrefixOptions[] = {
+ "Default",
+ "Show",
+ "Hide",
+};
+
+const char* kHorizontalAligments[] = {
+ "Default",
+ "Left",
+ "Center",
+ "Right",
+};
+
+const char* kVerticalAlignments[] = {
+ "Default",
+ "Top",
+ "Middle",
+ "Bottom",
+};
+
+} // namespace
+
+namespace examples {
+
+// TextExample's content view, which is responsible for drawing a string with
+// the specified style.
+class TextExample::TextExampleView : public views::View {
+ public:
+ TextExampleView()
+ : font_(ResourceBundle::GetSharedInstance().GetFont(
+ ResourceBundle::BaseFont)),
+ text_(ASCIIToUTF16(kShortText)),
+ text_flags_(0),
+ fade_(false),
+ fade_mode_(gfx::CanvasSkia::TruncateFadeTail) {
+ }
+
+ virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
+#if defined(OS_WIN)
+ if (fade_) {
+ gfx::Rect rect(0, 0, width(), height());
+ size_t characters_to_truncate_from_head =
+ gfx::CanvasSkia::TruncateFadeHeadAndTail ? 10 : 0;
+ canvas->AsCanvasSkia()->DrawFadeTruncatingString(text_, fade_mode_,
+ characters_to_truncate_from_head, font_, SK_ColorDKGRAY, rect);
+ return;
+ }
+#endif
+
+ canvas->DrawStringInt(text_, font_, SK_ColorDKGRAY,
+ 0, 0, width(), height(), text_flags_);
+ }
+
+ int text_flags() const { return text_flags_; }
+ void set_text_flags(int text_flags) { text_flags_ = text_flags; }
+
+ const string16& text() const { return text_; }
+ void set_text(const string16& text) { text_ = text; }
+
+ bool fade() const { return fade_; }
+ void set_fade(bool fade) { fade_ = fade; }
+
+ gfx::CanvasSkia::TruncateFadeMode fade_mode() const { return fade_mode_; }
+ void set_fade_mode(gfx::CanvasSkia::TruncateFadeMode fade_mode) {
+ fade_mode_ = fade_mode;
+ }
+
+ private:
+ // The font used for drawing the text.
+ gfx::Font font_;
+
+ // The text to draw.
+ string16 text_;
+
+ // Text flags for passing to |DrawStringInt()|.
+ int text_flags_;
+
+ // If |true|, specifies to call |DrawFadeTruncatingString()| instead of
+ // |DrawStringInt()|.
+ bool fade_;
+
+ // If |fade_| is |true|, fade mode parameter to |DrawFadeTruncatingString()|.
+ gfx::CanvasSkia::TruncateFadeMode fade_mode_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextExampleView);
+};
+
+TextExample::TextExample(ExamplesMain* main)
+ : ExampleBase(main, "Text Styles") {
+}
+
+TextExample::~TextExample() {
+}
+
+views::Combobox* TextExample::AddCombobox(views::GridLayout* layout,
+ const char* name,
+ const char** strings,
+ int count) {
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(ASCIIToUTF16(name)));
+ views::Combobox* combo_box =
+ new views::Combobox(new ExampleComboboxModel(strings, count));
+ combo_box->SetSelectedItem(0);
+ combo_box->set_listener(this);
+ layout->AddView(combo_box);
+ return combo_box;
+}
+
+void TextExample::CreateExampleView(views::View* container) {
+ text_view_ = new TextExampleView;
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ layout->AddPaddingRow(0, 8);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddPaddingColumn(0, 8);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0.1f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.9f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 8);
+
+ h_align_cb_ = AddCombobox(layout,
+ "H-Align",
+ kHorizontalAligments,
+ arraysize(kHorizontalAligments));
+ v_align_cb_ = AddCombobox(layout,
+ "V-Align",
+ kVerticalAlignments,
+ arraysize(kVerticalAlignments));
+ eliding_cb_ = AddCombobox(layout,
+ "Eliding",
+ kElidingBehaviors,
+ arraysize(kElidingBehaviors));
+ prefix_cb_ = AddCombobox(layout,
+ "Prefix",
+ kPrefixOptions,
+ arraysize(kPrefixOptions));
+ text_cb_ = AddCombobox(layout,
+ "Example Text",
+ kTextExamples,
+ arraysize(kTextExamples));
+
+ layout->StartRow(0, 0);
+ multiline_checkbox_ = new views::Checkbox(ASCIIToUTF16("Multiline"));
+ multiline_checkbox_->set_listener(this);
+ layout->AddView(multiline_checkbox_);
+ break_checkbox_ = new views::Checkbox(ASCIIToUTF16("Character Break"));
+ break_checkbox_->set_listener(this);
+ layout->AddView(break_checkbox_);
+
+ layout->AddPaddingRow(0, 32);
+
+ column_set = layout->AddColumnSet(1);
+ column_set->AddPaddingColumn(0, 16);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 1, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddPaddingColumn(0, 16);
+ layout->StartRow(1, 1);
+ layout->AddView(text_view_);
+
+ layout->AddPaddingRow(0, 8);
+}
+
+void TextExample::ButtonPressed(views::Button* button,
+ const views::Event& event) {
+ int text_flags = text_view_->text_flags();
+ if (button == multiline_checkbox_) {
+ if (multiline_checkbox_->checked())
+ text_flags |= gfx::Canvas::MULTI_LINE;
+ else
+ text_flags &= ~gfx::Canvas::MULTI_LINE;
+ } else if (button == break_checkbox_) {
+ if (break_checkbox_->checked())
+ text_flags |= gfx::Canvas::CHARACTER_BREAK;
+ else
+ text_flags &= ~gfx::Canvas::CHARACTER_BREAK;
+ }
+ text_view_->set_text_flags(text_flags);
+ text_view_->SchedulePaint();
+}
+
+void TextExample::ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) {
+ int text_flags = text_view_->text_flags();
+ if (combo_box == h_align_cb_) {
+ text_flags &= ~(gfx::Canvas::TEXT_ALIGN_LEFT |
+ gfx::Canvas::TEXT_ALIGN_CENTER |
+ gfx::Canvas::TEXT_ALIGN_RIGHT);
+ switch (new_index) {
+ case 0:
+ break;
+ case 1:
+ text_flags |= gfx::Canvas::TEXT_ALIGN_LEFT;
+ break;
+ case 2:
+ text_flags |= gfx::Canvas::TEXT_ALIGN_CENTER;
+ break;
+ case 3:
+ text_flags |= gfx::Canvas::TEXT_ALIGN_RIGHT;
+ break;
+ }
+ } else if (combo_box == v_align_cb_) {
+ text_flags &= ~(gfx::Canvas::TEXT_VALIGN_TOP |
+ gfx::Canvas::TEXT_VALIGN_MIDDLE |
+ gfx::Canvas::TEXT_VALIGN_BOTTOM);
+ switch (new_index) {
+ case 0:
+ break;
+ case 1:
+ text_flags |= gfx::Canvas::TEXT_VALIGN_TOP;
+ break;
+ case 2:
+ text_flags |= gfx::Canvas::TEXT_VALIGN_MIDDLE;
+ break;
+ case 3:
+ text_flags |= gfx::Canvas::TEXT_VALIGN_BOTTOM;
+ break;
+ }
+ } else if (combo_box == text_cb_) {
+ switch (new_index) {
+ case 0:
+ text_view_->set_text(ASCIIToUTF16(kShortText));
+ break;
+ case 1:
+ text_view_->set_text(ASCIIToUTF16(kMediumText));
+ break;
+ case 2:
+ text_view_->set_text(ASCIIToUTF16(kLongText));
+ break;
+ case 3:
+ text_view_->set_text(ASCIIToUTF16(kAmpersandText));
+ break;
+ }
+ } else if (combo_box == eliding_cb_) {
+ switch (new_index) {
+ case 0:
+ text_flags &= ~gfx::Canvas::NO_ELLIPSIS;
+ text_view_->set_fade(false);
+ break;
+ case 1:
+ text_flags |= gfx::Canvas::NO_ELLIPSIS;
+ text_view_->set_fade(false);
+ break;
+#if defined(OS_WIN)
+ case 2:
+ text_view_->set_fade_mode(gfx::CanvasSkia::TruncateFadeTail);
+ text_view_->set_fade(true);
+ break;
+ case 3:
+ text_view_->set_fade_mode(gfx::CanvasSkia::TruncateFadeHead);
+ text_view_->set_fade(true);
+ break;
+ case 4:
+ text_view_->set_fade_mode(gfx::CanvasSkia::TruncateFadeHeadAndTail);
+ text_view_->set_fade(true);
+ break;
+#endif
+ }
+ } else if (combo_box == prefix_cb_) {
+ text_flags &= ~(gfx::Canvas::SHOW_PREFIX | gfx::Canvas::HIDE_PREFIX);
+ switch (new_index) {
+ case 0:
+ break;
+ case 1:
+ text_flags |= gfx::Canvas::SHOW_PREFIX;
+ break;
+ case 2:
+ text_flags |= gfx::Canvas::HIDE_PREFIX;
+ break;
+ }
+ }
+ text_view_->set_text_flags(text_flags);
+ text_view_->SchedulePaint();
+}
+
+} // namespace examples
diff --git a/ui/views/examples/text_example.h b/ui/views/examples/text_example.h
new file mode 100644
index 0000000..fb8c4f0
--- /dev/null
+++ b/ui/views/examples/text_example.h
@@ -0,0 +1,79 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_TEXT_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_TEXT_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/button.h"
+#include "views/controls/combobox/combobox.h"
+
+namespace views {
+class Checkbox;
+class GridLayout;
+}
+
+namespace examples {
+
+class TextExample : public ExampleBase,
+ public views::ButtonListener,
+ public views::Combobox::Listener {
+ public:
+ explicit TextExample(ExamplesMain* main);
+ virtual ~TextExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // Create and add a combo box to the layout.
+ views::Combobox* AddCombobox(views::GridLayout* layout,
+ const char* name,
+ const char** strings,
+ int count);
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* button,
+ const views::Event& event) OVERRIDE;
+
+ // Overridden from views::Combobox::Listener:
+ virtual void ItemChanged(views::Combobox* combo_box,
+ int prev_index,
+ int new_index) OVERRIDE;
+
+
+ class TextExampleView;
+ // The content of the scroll view.
+ TextExampleView* text_view_;
+
+ // Combo box for horizontal text alignment.
+ views::Combobox* h_align_cb_;
+
+ // Combo box for vertical text alignment.
+ views::Combobox* v_align_cb_;
+
+ // Combo box for text eliding style.
+ views::Combobox* eliding_cb_;
+
+ // Combo box for ampersand prefix show / hide behavior.
+ views::Combobox* prefix_cb_;
+
+ // Combo box to choose one of the sample texts.
+ views::Combobox* text_cb_;
+
+ // Check box to enable/disable multiline text drawing.
+ views::Checkbox* multiline_checkbox_;
+
+ // Check box to enable/disable character break behavior.
+ views::Checkbox* break_checkbox_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_TEXT_EXAMPLE_H_
diff --git a/ui/views/examples/textfield_example.cc b/ui/views/examples/textfield_example.cc
new file mode 100644
index 0000000..f9536e5
--- /dev/null
+++ b/ui/views/examples/textfield_example.cc
@@ -0,0 +1,113 @@
+// 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/examples/textfield_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "ui/base/range/range.h"
+#include "ui/gfx/render_text.h"
+#include "views/controls/label.h"
+#include "views/controls/textfield/textfield.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+TextfieldExample::TextfieldExample(ExamplesMain* main)
+ : ExampleBase(main, "Textfield") {
+}
+
+TextfieldExample::~TextfieldExample() {
+}
+
+void TextfieldExample::CreateExampleView(views::View* container) {
+ name_ = new views::Textfield();
+ password_ = new views::Textfield(views::Textfield::STYLE_PASSWORD);
+ password_->set_text_to_display_when_empty(ASCIIToUTF16("password"));
+ show_password_ = new views::TextButton(this, ASCIIToUTF16("Show password"));
+ clear_all_ = new views::TextButton(this, ASCIIToUTF16("Clear All"));
+ append_ = new views::TextButton(this, ASCIIToUTF16("Append"));
+ set_ = new views::TextButton(this, ASCIIToUTF16("Set"));
+ set_style_ = new views::TextButton(this, ASCIIToUTF16("Set Styles"));
+ name_->SetController(this);
+ password_->SetController(this);
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ views::ColumnSet* column_set = layout->AddColumnSet(0);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL,
+ 0.2f, views::GridLayout::USE_PREF, 0, 0);
+ column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL,
+ 0.8f, views::GridLayout::USE_PREF, 0, 0);
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(ASCIIToUTF16("Name:")));
+ layout->AddView(name_);
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(ASCIIToUTF16("Password:")));
+ layout->AddView(password_);
+ layout->StartRow(0, 0);
+ layout->AddView(show_password_);
+ layout->StartRow(0, 0);
+ layout->AddView(clear_all_);
+ layout->StartRow(0, 0);
+ layout->AddView(append_);
+ layout->StartRow(0, 0);
+ layout->AddView(set_);
+ layout->StartRow(0, 0);
+ layout->AddView(set_style_);
+}
+
+void TextfieldExample::ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {
+ if (sender == name_) {
+ PrintStatus("Name [%s]", UTF16ToUTF8(new_contents).c_str());
+ } else if (sender == password_) {
+ PrintStatus("Password [%s]", UTF16ToUTF8(new_contents).c_str());
+ }
+}
+
+bool TextfieldExample::HandleKeyEvent(views::Textfield* sender,
+ const views::KeyEvent& key_event) {
+ return false;
+}
+
+void TextfieldExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ if (sender == show_password_) {
+ PrintStatus("Password [%s]", UTF16ToUTF8(password_->text()).c_str());
+ } else if (sender == clear_all_) {
+ string16 empty;
+ name_->SetText(empty);
+ password_->SetText(empty);
+ } else if (sender == append_) {
+ name_->AppendText(WideToUTF16(L"[append]"));
+ } else if (sender == set_) {
+ name_->SetText(WideToUTF16(L"[set]"));
+ } else if (sender == set_style_) {
+ if (!name_->text().empty()) {
+ gfx::StyleRange color;
+ color.foreground = SK_ColorYELLOW;
+ color.range = ui::Range(0, name_->text().length());
+ name_->ApplyStyleRange(color);
+
+ if (name_->text().length() >= 5) {
+ size_t fifth = name_->text().length() / 5;
+ gfx::StyleRange underline;
+ underline.underline = true;
+ underline.foreground = SK_ColorBLUE;
+ underline.range = ui::Range(1 * fifth, 4 * fifth);
+ name_->ApplyStyleRange(underline);
+
+ gfx::StyleRange strike;
+ strike.strike = true;
+ strike.foreground = SK_ColorRED;
+ strike.range = ui::Range(2 * fifth, 3 * fifth);
+ name_->ApplyStyleRange(strike);
+ }
+ }
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/textfield_example.h b/ui/views/examples/textfield_example.h
new file mode 100644
index 0000000..f3e1d74
--- /dev/null
+++ b/ui/views/examples/textfield_example.h
@@ -0,0 +1,58 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/string16.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/controls/textfield/textfield_controller.h"
+
+namespace examples {
+
+// TextfieldExample mimics login screen.
+class TextfieldExample : public ExampleBase,
+ public views::TextfieldController,
+ public views::ButtonListener {
+ public:
+ explicit TextfieldExample(ExamplesMain* main);
+ virtual ~TextfieldExample();
+
+ // ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ // views::TextfieldController:
+ virtual void ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) OVERRIDE;
+ virtual bool HandleKeyEvent(views::Textfield* sender,
+ const views::KeyEvent& key_event) OVERRIDE;
+
+ // views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ // Textfields for name and password.
+ views::Textfield* name_;
+ views::Textfield* password_;
+
+ // Various buttons to control textfield.
+ views::TextButton* show_password_;
+ views::TextButton* clear_all_;
+ views::TextButton* append_;
+ views::TextButton* set_;
+ views::TextButton* set_style_;
+
+ DISALLOW_COPY_AND_ASSIGN(TextfieldExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_
diff --git a/ui/views/examples/throbber_example.cc b/ui/views/examples/throbber_example.cc
new file mode 100644
index 0000000..dbba597
--- /dev/null
+++ b/ui/views/examples/throbber_example.cc
@@ -0,0 +1,60 @@
+// 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/examples/throbber_example.h"
+
+#include "views/controls/throbber.h"
+#include "views/layout/fill_layout.h"
+#include "views/view.h"
+
+namespace {
+
+// Time in ms per throbber frame.
+const int kThrobberFrameMs = 60;
+
+class ThrobberView : public views::View {
+ public:
+ ThrobberView() {
+ throbber_ = new views::Throbber(kThrobberFrameMs, false);
+ AddChildView(throbber_);
+ throbber_->SetVisible(true);
+ throbber_->Start();
+ }
+
+ virtual gfx::Size GetPreferredSize() {
+ return gfx::Size(width(), height());
+ }
+
+ virtual void Layout() {
+ views::View* child = child_at(0);
+ gfx::Size ps = child->GetPreferredSize();
+ child->SetBounds((width() - ps.width()) / 2,
+ (height() - ps.height()) / 2,
+ ps.width(), ps.height());
+ SizeToPreferredSize();
+ }
+
+ private:
+ views::Throbber* throbber_;
+
+ DISALLOW_COPY_AND_ASSIGN(ThrobberView);
+};
+
+} // namespace
+
+namespace examples {
+
+ThrobberExample::ThrobberExample(ExamplesMain* main)
+ : ExampleBase(main, "Throbber") {
+}
+
+ThrobberExample::~ThrobberExample() {
+}
+
+void ThrobberExample::CreateExampleView(views::View* container) {
+ container->SetLayoutManager(new views::FillLayout());
+ container->AddChildView(new ThrobberView());
+}
+
+} // namespace examples
diff --git a/ui/views/examples/throbber_example.h b/ui/views/examples/throbber_example.h
new file mode 100644
index 0000000..82efd41
--- /dev/null
+++ b/ui/views/examples/throbber_example.h
@@ -0,0 +1,33 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+
+namespace views {
+class View;
+}
+
+namespace examples {
+
+class ThrobberExample : public ExampleBase {
+ public:
+ explicit ThrobberExample(ExamplesMain* main);
+ virtual ~ThrobberExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ThrobberExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_THROBBER_EXAMPLE_H_
diff --git a/ui/views/examples/views_examples.exe.manifest b/ui/views/examples/views_examples.exe.manifest
new file mode 100644
index 0000000..92f2e44
--- /dev/null
+++ b/ui/views/examples/views_examples.exe.manifest
@@ -0,0 +1,27 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
+
+ <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
+ <application>
+ <!--This Id value indicates the application supports Windows Vista functionality -->
+ <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/>
+ <!--This Id value indicates the application supports Windows 7 functionality-->
+ <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
+ </application>
+ </compatibility>
+
+ <dependency>
+ <dependentAssembly>
+ <assemblyIdentity type="Win32" name="Microsoft.Windows.Common-Controls" version="6.0.0.0" processorArchitecture="X86" publicKeyToken="6595b64144ccf1df" language="*"></assemblyIdentity>
+ </dependentAssembly>
+ </dependency>
+
+ <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
+ <security>
+ <requestedPrivileges>
+ <requestedExecutionLevel level="asInvoker" />
+ </requestedPrivileges>
+ </security>
+ </trustInfo>
+
+</assembly> \ No newline at end of file
diff --git a/ui/views/examples/widget_example.cc b/ui/views/examples/widget_example.cc
new file mode 100644
index 0000000..07844a0
--- /dev/null
+++ b/ui/views/examples/widget_example.cc
@@ -0,0 +1,169 @@
+// 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/examples/widget_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/button/text_button.h"
+#include "views/layout/box_layout.h"
+#include "views/layout/layout_manager.h"
+#include "views/view.h"
+#include "views/widget/widget.h"
+
+namespace {
+
+// A layout manager that layouts a single child at
+// the center of the host view.
+class CenterLayout : public views::LayoutManager {
+ public:
+ CenterLayout() {}
+ virtual ~CenterLayout() {}
+
+ // Overridden from LayoutManager:
+ virtual void Layout(views::View* host) {
+ views::View* child = host->child_at(0);
+ gfx::Size size = child->GetPreferredSize();
+ child->SetBounds((host->width() - size.width()) / 2,
+ (host->height() - size.height()) / 2,
+ size.width(), size.height());
+ }
+
+ virtual gfx::Size GetPreferredSize(views::View* host) {
+ return gfx::Size();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(CenterLayout);
+};
+
+} // namespace
+
+namespace examples {
+
+WidgetExample::WidgetExample(ExamplesMain* main)
+ : ExampleBase(main, "Widget") {
+}
+
+WidgetExample::~WidgetExample() {
+}
+
+void WidgetExample::CreateExampleView(views::View* container) {
+ container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 2));
+ BuildButton(container, "Create a popup widget", POPUP);
+ BuildButton(container, "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 views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 20));
+ BuildButton(vert_container, "Create a child widget", CHILD);
+ BuildButton(vert_container, "Create a transparent child widget",
+ TRANSPARENT_CHILD);
+#endif
+}
+
+void WidgetExample::BuildButton(views::View* container,
+ const std::string& label,
+ int tag) {
+ views::TextButton* button = new views::TextButton(this, ASCIIToUTF16(label));
+ button->set_tag(tag);
+ container->AddChildView(button);
+}
+
+void WidgetExample::InitWidget(views::Widget* widget, bool transparent) {
+ // Add view/native buttons to close the popup widget.
+ views::TextButton* close_button = new views::TextButton(
+ this, ASCIIToUTF16("Close"));
+ close_button->set_tag(CLOSE_WIDGET);
+ // TODO(oshima): support transparent native view.
+ views::NativeTextButton* native_button = new views::NativeTextButton(
+ this, ASCIIToUTF16("Native Close"));
+ native_button->set_tag(CLOSE_WIDGET);
+
+ views::View* button_container = new views::View();
+ button_container->SetLayoutManager(
+ new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 1));
+ button_container->AddChildView(close_button);
+ button_container->AddChildView(native_button);
+
+ views::View* widget_container = new views::View();
+ widget_container->SetLayoutManager(new CenterLayout);
+ widget_container->AddChildView(button_container);
+
+ widget->SetContentsView(widget_container);
+
+ if (!transparent) {
+ widget_container->set_background(
+ views::Background::CreateStandardPanelBackground());
+ }
+
+ // Show the widget.
+ widget->Show();
+}
+
+#if defined(OS_LINUX)
+void WidgetExample::CreateChild(views::View* parent, bool transparent) {
+ views::Widget* widget = new views::Widget;
+ // Compute where to place the child widget.
+ // We'll place it at the center of the root widget.
+ views::Widget* parent_widget = parent->GetWidget();
+ gfx::Rect bounds = parent_widget->GetClientAreaScreenBounds();
+ // Child widget is 200x200 square.
+ bounds.SetRect((bounds.width() - 200) / 2, (bounds.height() - 200) / 2,
+ 200, 200);
+ // Initialize the child widget with the computed bounds.
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL);
+ params.transparent = transparent;
+ params.parent_widget = parent_widget;
+ widget->Init(params);
+ InitWidget(widget, transparent);
+}
+#endif
+
+void WidgetExample::CreatePopup(views::View* parent, bool transparent) {
+ views::Widget* widget = new views::Widget;
+
+ // Compute where to place the popup widget.
+ // We'll place it right below the create button.
+ gfx::Point point = parent->GetMirroredPosition();
+ // The position in point is relative to the parent. Make it absolute.
+ views::View::ConvertPointToScreen(parent, &point);
+ // Add the height of create_button_.
+ point.Offset(0, parent->size().height());
+
+ // Initialize the popup widget with the computed bounds.
+ views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP);
+ params.transparent = transparent;
+ params.parent_widget = parent->GetWidget();
+ params.bounds = gfx::Rect(point.x(), point.y(), 200, 300);
+ widget->Init(params);
+ InitWidget(widget, transparent);
+}
+
+void WidgetExample::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ switch (sender->tag()) {
+ case POPUP:
+ CreatePopup(sender, false);
+ break;
+ case TRANSPARENT_POPUP:
+ CreatePopup(sender, true);
+ break;
+#if defined(OS_LINUX)
+ case CHILD:
+ CreateChild(sender, false);
+ break;
+ case TRANSPARENT_CHILD:
+ CreateChild(sender, true);
+ break;
+#endif
+ case CLOSE_WIDGET:
+ sender->GetWidget()->Close();
+ break;
+ }
+}
+
+} // namespace examples
diff --git a/ui/views/examples/widget_example.h b/ui/views/examples/widget_example.h
new file mode 100644
index 0000000..ab802e3
--- /dev/null
+++ b/ui/views/examples/widget_example.h
@@ -0,0 +1,56 @@
+// 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.
+
+#ifndef UI_VIEWS_EXAMPLES_WIDGET_EXAMPLE_H_
+#define UI_VIEWS_EXAMPLES_WIDGET_EXAMPLE_H_
+#pragma once
+
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "ui/views/examples/example_base.h"
+#include "views/controls/button/text_button.h"
+#include "views/widget/widget.h"
+
+namespace examples {
+
+// WidgetExample demonstrates how to create a popup widget.
+class WidgetExample : public ExampleBase, public views::ButtonListener {
+ public:
+ explicit WidgetExample(ExamplesMain* main);
+ virtual ~WidgetExample();
+
+ // Overridden from ExampleBase:
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
+
+ private:
+ enum Command {
+ POPUP,
+ CHILD,
+ TRANSPARENT_POPUP,
+ TRANSPARENT_CHILD,
+ CLOSE_WIDGET,
+ };
+
+ void BuildButton(views::View* container, const std::string& label, int tag);
+
+ void InitWidget(views::Widget* widget, bool transparent);
+
+#if defined(OS_LINUX)
+ void CreateChild(views::View* parent, bool transparent);
+#endif
+
+ void CreatePopup(views::View* parent, bool transparent);
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ DISALLOW_COPY_AND_ASSIGN(WidgetExample);
+};
+
+} // namespace examples
+
+#endif // UI_VIEWS_EXAMPLES_WIDGET_EXAMPLE_H_