summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 11:40:04 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-02-01 11:40:04 +0000
commit1a5c97540834be79830865a401368c75f3138381 (patch)
tree433545cba236b0c628ae8d0002ccf98bce5411ce
parent7d121994978c05073f4d63bf44311465fcdb2251 (diff)
downloadchromium_src-1a5c97540834be79830865a401368c75f3138381.zip
chromium_src-1a5c97540834be79830865a401368c75f3138381.tar.gz
chromium_src-1a5c97540834be79830865a401368c75f3138381.tar.bz2
views: Move the implementation of more examples from header to source file.
BUG=None TEST=run out/Debug/views_examples, everything should works as before. Review URL: http://codereview.chromium.org/6347030 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@73276 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--views/examples/message_box_example.cc67
-rw-r--r--views/examples/message_box_example.h67
-rw-r--r--views/examples/radio_button_example.cc73
-rw-r--r--views/examples/radio_button_example.h71
-rw-r--r--views/examples/scroll_view_example.cc117
-rw-r--r--views/examples/scroll_view_example.h120
-rw-r--r--views/examples/table_example.h19
-rw-r--r--views/examples/textfield_example.cc84
-rw-r--r--views/examples/textfield_example.h96
-rw-r--r--views/views.gyp4
10 files changed, 419 insertions, 299 deletions
diff --git a/views/examples/message_box_example.cc b/views/examples/message_box_example.cc
new file mode 100644
index 0000000..0fa3777
--- /dev/null
+++ b/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 "views/examples/message_box_example.h"
+
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+MessageBoxExample::MessageBoxExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+MessageBoxExample::~MessageBoxExample() {
+}
+
+std::wstring MessageBoxExample::GetExampleTitle() {
+ return L"Message Box View";
+}
+
+void MessageBoxExample::CreateExampleView(views::View* container) {
+ message_box_view_ = new MessageBoxView(
+ 0, L"Message Box Message", L"Default Prompt");
+ status_ = new views::TextButton(this, L"Show Status");
+ toggle_ = new views::TextButton(this, L"Toggle Checkbox");
+
+ views::GridLayout* layout = new views::GridLayout(container);
+ container->SetLayoutManager(layout);
+
+ message_box_view_->SetCheckBoxLabel(L"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(
+ IntToOnOff(message_box_view_->IsCheckBoxSelected()));
+ PrintStatus(message_box_view_->IsCheckBoxSelected() ?
+ L"Check Box Selected" : L"Check Box Not Selected");
+ } else if (sender == toggle_) {
+ message_box_view_->SetCheckBoxSelected(
+ !message_box_view_->IsCheckBoxSelected());
+ }
+}
+
+} // namespace examples
diff --git a/views/examples/message_box_example.h b/views/examples/message_box_example.h
index 51eb646..a8ecbb9 100644
--- a/views/examples/message_box_example.h
+++ b/views/examples/message_box_example.h
@@ -6,13 +6,13 @@
#define VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
#pragma once
+#include <string>
+
+#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/string_util.h"
#include "views/controls/button/text_button.h"
#include "views/controls/message_box_view.h"
-#include "views/controls/tabbed_pane/tabbed_pane.h"
#include "views/examples/example_base.h"
-#include "views/layout/grid_layout.h"
namespace examples {
@@ -20,65 +20,25 @@ namespace examples {
class MessageBoxExample : public ExampleBase,
public views::ButtonListener {
public:
- explicit MessageBoxExample(ExamplesMain* main) : ExampleBase(main) {}
-
- virtual ~MessageBoxExample() {}
-
- virtual std::wstring GetExampleTitle() {
- return L"Message Box View";
- }
-
- virtual void CreateExampleView(views::View* container) {
- message_box_view_ =
- new MessageBoxView(0, L"Message Box Message", L"Default Prompt");
- status_ = new views::TextButton(this, L"Show Status");
- toggle_ = new views::TextButton(this, L"Toggle Checkbox");
-
- views::GridLayout* layout = new views::GridLayout(container);
- container->SetLayoutManager(layout);
+ explicit MessageBoxExample(ExamplesMain* main);
+ virtual ~MessageBoxExample();
- message_box_view_->SetCheckBoxLabel(L"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_);
- }
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
private:
- // ButtonListener overrides.
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- if (sender == status_) {
- message_box_view_->SetCheckBoxLabel(
- IntToOnOff(message_box_view_->IsCheckBoxSelected()));
- PrintStatus(message_box_view_->IsCheckBoxSelected() ?
- L"Check Box Selected" : L"Check Box Not Selected");
- } else if (sender == toggle_) {
- message_box_view_->SetCheckBoxSelected(
- !message_box_view_->IsCheckBoxSelected());
- }
- }
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
// The MessageBoxView to be tested.
MessageBoxView* message_box_view_;
// Control buttons to show the status and toggle checkbox in the
// message box.
- views::Button* status_, *toggle_;
+ views::Button* status_;
+ views::Button* toggle_;
DISALLOW_COPY_AND_ASSIGN(MessageBoxExample);
};
@@ -86,4 +46,3 @@ class MessageBoxExample : public ExampleBase,
} // namespace examples
#endif // VIEWS_EXAMPLES_MESSAGE_BOX_EXAMPLE_H_
-
diff --git a/views/examples/radio_button_example.cc b/views/examples/radio_button_example.cc
new file mode 100644
index 0000000..27d8fa1
--- /dev/null
+++ b/views/examples/radio_button_example.cc
@@ -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.
+
+#include "views/examples/radio_button_example.h"
+
+#include "base/stringprintf.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+RadioButtonExample::RadioButtonExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+RadioButtonExample::~RadioButtonExample() {
+}
+
+std::wstring RadioButtonExample::GetExampleTitle() {
+ return L"Radio Button";
+}
+
+void RadioButtonExample::CreateExampleView(views::View* container) {
+ select_ = new views::TextButton(this, L"Select");
+ status_ = new views::TextButton(this, L"Show Status");
+
+ int all = arraysize(radio_buttons_);
+
+ // divide buttons into 2 groups
+ int group_count = all / 2;
+ for (int i = 0; i < all; i++) {
+ int group = i / group_count;
+ radio_buttons_[i] = new views::RadioButton(
+ base::StringPrintf(
+ L"Radio %d in group %d", (i % group_count + 1), group),
+ group);
+ }
+
+ 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 (int i = 0; i < all; 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_[0]->SetChecked(true);
+ radio_buttons_[5]->SetChecked(true);
+ } else if (sender == status_) {
+ // Show the state of radio buttons.
+ PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls",
+ IntToOnOff(radio_buttons_[0]->checked()),
+ IntToOnOff(radio_buttons_[1]->checked()),
+ IntToOnOff(radio_buttons_[2]->checked()),
+ IntToOnOff(radio_buttons_[3]->checked()),
+ IntToOnOff(radio_buttons_[4]->checked()),
+ IntToOnOff(radio_buttons_[5]->checked()));
+ }
+}
+
+} // namespace examples
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h
index 4bd5ab2a..92cf431 100644
--- a/views/examples/radio_button_example.h
+++ b/views/examples/radio_button_example.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,8 +6,10 @@
#define VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
#pragma once
+#include <string>
+
+#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/string_util.h"
#include "views/controls/button/radio_button.h"
#include "views/controls/button/text_button.h"
#include "views/examples/example_base.h"
@@ -17,69 +19,25 @@ namespace examples {
class RadioButtonExample : public ExampleBase,
public views::ButtonListener {
public:
- explicit RadioButtonExample(ExamplesMain* main): ExampleBase(main) {}
-
- virtual ~RadioButtonExample() {}
-
- virtual std::wstring GetExampleTitle() {
- return L"Radio Button";
- }
-
- virtual void CreateExampleView(views::View* container) {
- select_ = new views::TextButton(this, L"Select");
- status_ = new views::TextButton(this, L"Show Status");
+ explicit RadioButtonExample(ExamplesMain* main);
+ virtual ~RadioButtonExample();
- int all = arraysize(radio_buttons_);
-
- // divide buttons into 2 groups
- int group_count = all / 2;
- for (int i = 0; i < all; i++) {
- int group = i / group_count;
- radio_buttons_[i] = new views::RadioButton(
- StringPrintf(L"Radio %d in group %d", (i % group_count + 1), group),
- group);
- }
-
- 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 (int i = 0; i < all; i++) {
- layout->StartRow(0, 0);
- layout->AddView(radio_buttons_[i]);
- }
- layout->StartRow(0, 0);
- layout->AddView(select_);
- layout->StartRow(0, 0);
- layout->AddView(status_);
- }
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
private:
- // Override from ButtonListener
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- if (sender == select_) {
- radio_buttons_[0]->SetChecked(true);
- radio_buttons_[5]->SetChecked(true);
- } else if (sender == status_) {
- // Show the state of radio buttons.
- PrintStatus(L"Group1: 1:%ls, 2:%ls, 3:%ls Group2: 1:%ls, 2:%ls, 3:%ls",
- IntToOnOff(radio_buttons_[0]->checked()),
- IntToOnOff(radio_buttons_[1]->checked()),
- IntToOnOff(radio_buttons_[2]->checked()),
- IntToOnOff(radio_buttons_[3]->checked()),
- IntToOnOff(radio_buttons_[4]->checked()),
- IntToOnOff(radio_buttons_[5]->checked()));
- }
- }
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
// 6 radio buttons, 0-2 consists 1st group, and 3-5 consists
// 2nd group.
views::RadioButton* radio_buttons_[6];
// Control button to select radio buttons, and show the status of buttons.
- views::TextButton* select_, *status_;
+ views::TextButton* select_;
+ views::TextButton* status_;
DISALLOW_COPY_AND_ASSIGN(RadioButtonExample);
};
@@ -87,4 +45,3 @@ class RadioButtonExample : public ExampleBase,
} // namespace examples
#endif // VIEWS_EXAMPLES_RADIO_BUTTON_EXAMPLE_H_
-
diff --git a/views/examples/scroll_view_example.cc b/views/examples/scroll_view_example.cc
new file mode 100644
index 0000000..29febeb
--- /dev/null
+++ b/views/examples/scroll_view_example.cc
@@ -0,0 +1,117 @@
+// 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 "views/examples/scroll_view_example.h"
+
+#include "base/stringprintf.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, L"Button"));
+ AddChildView(new views::RadioButton(L"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 = GetChildViewAt(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) {
+}
+
+ScrollViewExample::~ScrollViewExample() {
+}
+
+std::wstring ScrollViewExample::GetExampleTitle() {
+ return L"Scroll View";
+}
+
+void ScrollViewExample::CreateExampleView(views::View* container) {
+ wide_ = new views::TextButton(this, L"Wide");
+ tall_ = new views::TextButton(this, L"Tall");
+ big_square_ = new views::TextButton(this, L"Big Square");
+ small_square_ = new views::TextButton(this, L"Small Square");
+ scroll_to_ = new views::TextButton(this, L"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/views/examples/scroll_view_example.h b/views/examples/scroll_view_example.h
index d8eab90..4e26d6e 100644
--- a/views/examples/scroll_view_example.h
+++ b/views/examples/scroll_view_example.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,9 +6,10 @@
#define VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_
#pragma once
+#include <string>
+
+#include "base/basictypes.h"
#include "base/compiler_specific.h"
-#include "base/string_util.h"
-#include "views/controls/button/radio_button.h"
#include "views/controls/button/text_button.h"
#include "views/controls/scroll_view.h"
#include "views/examples/example_base.h"
@@ -18,111 +19,27 @@ namespace examples {
class ScrollViewExample : public ExampleBase,
public views::ButtonListener {
public:
- explicit ScrollViewExample(ExamplesMain* main): ExampleBase(main) {}
-
- virtual ~ScrollViewExample() {}
-
- virtual std::wstring GetExampleTitle() {
- return L"Scroll View";
- }
-
- virtual void CreateExampleView(views::View* container) {
- wide_ = new views::TextButton(this, L"Wide");
- tall_ = new views::TextButton(this, L"Tall");
- big_square_ = new views::TextButton(this, L"Big Square");
- small_square_ = new views::TextButton(this, L"Small Square");
- scroll_to_ = new views::TextButton(this, L"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);
+ explicit ScrollViewExample(ExamplesMain* main);
+ virtual ~ScrollViewExample();
- 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_);
- }
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
private:
- // ScrollView's content, which draws gradient color on background.
- // TODO(oshima): add child views as well.
- class ScrollableView : public views::View {
- public:
- ScrollableView() {
- SetColor(SK_ColorRED, SK_ColorCYAN);
- AddChildView(new views::TextButton(NULL, L"Button"));
- AddChildView(new views::RadioButton(L"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 = GetChildViewAt(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);
- };
-
- // ButtonListner implementation.
- virtual void 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();
- }
+ // 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_, *tall_, *big_square_, *small_square_, *scroll_to_;
+ 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_;
@@ -135,4 +52,3 @@ class ScrollViewExample : public ExampleBase,
} // namespace examples
#endif // VIEWS_EXAMPLES_SCROLL_BAR_EXAMPLE_H_
-
diff --git a/views/examples/table_example.h b/views/examples/table_example.h
index a9e6ebc..081e0de 100644
--- a/views/examples/table_example.h
+++ b/views/examples/table_example.h
@@ -15,17 +15,14 @@
#include "views/controls/table/table_view_observer.h"
#include "views/examples/example_base.h"
#include "views/layout/fill_layout.h"
-
-using ui::TableModel;
-using ui::TableModelObserver; // TODO(beng): remove these
+#include "views/layout/grid_layout.h"
namespace examples {
-class TableExample
- : public ExampleBase,
- public TableModel,
- public views::ButtonListener,
- public views::TableViewObserver {
+class TableExample : public ExampleBase,
+ public ui::TableModel,
+ public views::ButtonListener,
+ public views::TableViewObserver {
public:
explicit TableExample(ExamplesMain* main) : ExampleBase(main) {
}
@@ -95,7 +92,7 @@ class TableExample
layout->AddView(column4_visible_checkbox_);
}
- // TableModel implementation:
+ // Overridden from ui::TableModel:
virtual int RowCount() {
return 10;
}
@@ -115,10 +112,10 @@ class TableExample
return row % 2 ? icon1 : icon2;
}
- virtual void SetObserver(TableModelObserver* observer) {
+ virtual void SetObserver(ui::TableModelObserver* observer) {
}
- // TableViewObserver implementation:
+ // Overridden from views::TableViewObserver:
virtual void OnSelectionChanged() {
PrintStatus(L"Selection changed");
}
diff --git a/views/examples/textfield_example.cc b/views/examples/textfield_example.cc
new file mode 100644
index 0000000..3266e56
--- /dev/null
+++ b/views/examples/textfield_example.cc
@@ -0,0 +1,84 @@
+// 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 "views/examples/textfield_example.h"
+
+#include "base/utf_string_conversions.h"
+#include "views/controls/label.h"
+#include "views/layout/grid_layout.h"
+#include "views/view.h"
+
+namespace examples {
+
+TextfieldExample::TextfieldExample(ExamplesMain* main)
+ : ExampleBase(main) {
+}
+
+TextfieldExample::~TextfieldExample() {
+}
+
+std::wstring TextfieldExample::GetExampleTitle() {
+ return L"Textfield";
+}
+
+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, L"Show password");
+ clear_all_ = new views::TextButton(this, L"Clear All");
+ append_ = new views::TextButton(this, L"Append");
+ 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(L"Name:"));
+ layout->AddView(name_);
+ layout->StartRow(0, 0);
+ layout->AddView(new views::Label(L"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_);
+}
+
+void TextfieldExample::ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) {
+ if (sender == name_) {
+ PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str());
+ } else if (sender == password_) {
+ PrintStatus(L"Password [%ls]", UTF16ToWideHack(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(L"Password [%ls]", UTF16ToWideHack(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]"));
+ }
+}
+
+} // namespace examples
diff --git a/views/examples/textfield_example.h b/views/examples/textfield_example.h
index a448f9f..a94797b 100644
--- a/views/examples/textfield_example.h
+++ b/views/examples/textfield_example.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// 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.
@@ -6,93 +6,39 @@
#define VIEWS_EXAMPLES_TEXTFIELD_EXAMPLE_H_
#pragma once
-#include "base/utf_string_conversions.h"
+#include <string>
+
+#include "base/basictypes.h"
+#include "base/compiler_specific.h"
+#include "base/string16.h"
#include "views/controls/button/text_button.h"
-#include "views/controls/label.h"
-#include "views/controls/tabbed_pane/tabbed_pane.h"
#include "views/controls/textfield/textfield.h"
#include "views/examples/example_base.h"
namespace examples {
-using views::Textfield;
-
// TextfieldExample mimics login screen.
class TextfieldExample : public ExampleBase,
- public Textfield::Controller,
+ public views::Textfield::Controller,
public views::ButtonListener {
public:
- explicit TextfieldExample(ExamplesMain* main) : ExampleBase(main) {}
-
- virtual ~TextfieldExample() {}
-
- virtual std::wstring GetExampleTitle() {
- return L"Textfield";
- }
+ explicit TextfieldExample(ExamplesMain* main);
+ virtual ~TextfieldExample();
- virtual void CreateExampleView(views::View* container) {
- name_ = new Textfield();
- password_ = new Textfield(Textfield::STYLE_PASSWORD);
- password_->set_text_to_display_when_empty(ASCIIToUTF16("password"));
- show_password_ = new views::TextButton(this, L"Show password");
- clear_all_ = new views::TextButton(this, L"Clear All");
- append_ = new views::TextButton(this, L"Append");
- 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(L"Name:"));
- layout->AddView(name_);
- layout->StartRow(0, 0);
- layout->AddView(new views::Label(L"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_);
- }
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ virtual void CreateExampleView(views::View* container) OVERRIDE;
private:
- // Textfield::Controller implementations:
- // This method is called whenever the text in the field changes.
- virtual void ContentsChanged(Textfield* sender,
- const string16& new_contents) {
- if (sender == name_) {
- PrintStatus(L"Name [%ls]", UTF16ToWideHack(new_contents).c_str());
- } else if (sender == password_) {
- PrintStatus(L"Password [%ls]", UTF16ToWideHack(new_contents).c_str());
- }
- }
-
- // Let the control handle keystrokes.
- virtual bool HandleKeyEvent(Textfield* sender,
- const views::KeyEvent& key_event) {
- return false;
- }
-
- // ButtonListner implementation.
- virtual void ButtonPressed(views::Button* sender, const views::Event& event) {
- if (sender == show_password_) {
- PrintStatus(L"Password [%ls]",
- UTF16ToWideHack(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]"));
- }
- }
+ // Overridden from views::Textfield::Controller:
+ virtual void ContentsChanged(views::Textfield* sender,
+ const string16& new_contents) OVERRIDE;
+ virtual bool HandleKeyEvent(views::Textfield* sender,
+ const views::KeyEvent& key_event) OVERRIDE;
+
+ // Overridden from views::ButtonListener:
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
// Textfields for name and password.
views::Textfield* name_;
diff --git a/views/views.gyp b/views/views.gyp
index e38cde8..5a437d9 100644
--- a/views/views.gyp
+++ b/views/views.gyp
@@ -527,9 +527,12 @@
'examples/example_base.h',
'examples/examples_main.cc',
'examples/examples_main.h',
+ 'examples/message_box_example.cc',
'examples/message_box_example.h',
'examples/menu_example.h',
+ 'examples/radio_button_example.cc',
'examples/radio_button_example.h',
+ 'examples/scroll_view_example.cc',
'examples/scroll_view_example.h',
'examples/single_split_view_example.cc',
'examples/single_split_view_example.h',
@@ -539,6 +542,7 @@
'examples/tabbed_pane_example.h',
'examples/table2_example.cc',
'examples/table2_example.h',
+ 'examples/textfield_example.cc',
'examples/textfield_example.h',
'examples/throbber_example.cc',
'examples/throbber_example.h',