summaryrefslogtreecommitdiffstats
path: root/views/examples
diff options
context:
space:
mode:
authorrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 01:07:09 +0000
committerrogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-04-27 01:07:09 +0000
commitc4f06dff5def187a1e2e276d5c83ea0aaeef3299 (patch)
treea328905746e9d54e48b0a983aa2d4d2e8d37461e /views/examples
parent24af8c96481b398ef33bf1e36c57d4ab0b00c1d9 (diff)
downloadchromium_src-c4f06dff5def187a1e2e276d5c83ea0aaeef3299.zip
chromium_src-c4f06dff5def187a1e2e276d5c83ea0aaeef3299.tar.gz
chromium_src-c4f06dff5def187a1e2e276d5c83ea0aaeef3299.tar.bz2
Add classes for native themed push buttons, radio buttons, and checkboxes.
These controls expose the same public interface and the existing controls of the same type to make it easier to change between the implementations. BUG=None TEST=The new controls should look and feel like native platform controls R=ben@chromium.org Review URL: http://codereview.chromium.org/6853015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83110 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples')
-rw-r--r--views/examples/button_example.cc62
-rw-r--r--views/examples/button_example.h5
-rw-r--r--views/examples/examples_main.cc5
-rw-r--r--views/examples/native_theme_button_example.cc6
-rw-r--r--views/examples/native_theme_button_example.h6
-rw-r--r--views/examples/native_theme_checkbox_example.cc39
-rw-r--r--views/examples/native_theme_checkbox_example.h46
-rw-r--r--views/examples/radio_button_example.cc33
-rw-r--r--views/examples/radio_button_example.h6
9 files changed, 187 insertions, 21 deletions
diff --git a/views/examples/button_example.cc b/views/examples/button_example.cc
index d27a5d2..4ab7f80 100644
--- a/views/examples/button_example.cc
+++ b/views/examples/button_example.cc
@@ -4,6 +4,9 @@
#include "views/examples/button_example.h"
+#include "grit/app_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"
@@ -11,7 +14,12 @@ namespace examples {
ButtonExample::ButtonExample(ExamplesMain* main)
: ExampleBase(main),
+ 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() {
@@ -22,7 +30,8 @@ std::wstring ButtonExample::GetExampleTitle() {
}
void ButtonExample::CreateExampleView(views::View* container) {
- button_ = new views::TextButton(this, L"Button");
+ views::TextButton* tb = new views::TextButton(this, L"Button");
+ button_ = tb;
container->SetLayoutManager(new views::FillLayout);
container->AddChildView(button_);
}
@@ -30,6 +39,57 @@ void ButtonExample::CreateExampleView(views::View* container) {
void ButtonExample::ButtonPressed(views::Button* sender,
const views::Event& event) {
PrintStatus(L"Pressed! count:%d", ++count_);
+
+ if (event.IsControlDown()) {
+ if (event.IsShiftDown()) {
+ 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(L"Startof"
+ L"ReallyReallyReallyReallyReallyReallyReally"
+ L"ReallyReallyReallyReallyReallyReallyReally"
+ L"ReallyReallyReallyReallyReallyReallyReally"
+ L"LongButtonText");
+ } else {
+ button_->SetText(L"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/views/examples/button_example.h b/views/examples/button_example.h
index fe8567b..aad1ff9 100644
--- a/views/examples/button_example.h
+++ b/views/examples/button_example.h
@@ -35,6 +35,11 @@ class ButtonExample : public ExampleBase, public views::ButtonListener {
// 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_;
diff --git a/views/examples/examples_main.cc b/views/examples/examples_main.cc
index 7f12733..8b2b647 100644
--- a/views/examples/examples_main.cc
+++ b/views/examples/examples_main.cc
@@ -20,6 +20,7 @@
#include "views/examples/menu_example.h"
#include "views/examples/message_box_example.h"
#include "views/examples/native_theme_button_example.h"
+#include "views/examples/native_theme_checkbox_example.h"
#include "views/examples/radio_button_example.h"
#include "views/examples/scroll_view_example.h"
#include "views/examples/single_split_view_example.h"
@@ -99,6 +100,10 @@ void ExamplesMain::Run() {
views::Window* window =
views::Window::CreateChromeWindow(NULL, gfx::Rect(0, 0, 850, 300), this);
+ examples::NativeThemeCheckboxExample native_theme_checkbox_example(this);
+ tabbed_pane->AddTab(native_theme_checkbox_example.GetExampleTitle(),
+ native_theme_checkbox_example.GetExampleView());
+
examples::NativeThemeButtonExample native_theme_button_example(this);
tabbed_pane->AddTab(native_theme_button_example.GetExampleTitle(),
native_theme_button_example.GetExampleView());
diff --git a/views/examples/native_theme_button_example.cc b/views/examples/native_theme_button_example.cc
index 7398a270..e7630e3 100644
--- a/views/examples/native_theme_button_example.cc
+++ b/views/examples/native_theme_button_example.cc
@@ -136,6 +136,10 @@ gfx::NativeTheme::Part ExampleNativeThemeButton::GetThemePart() const {
return gfx::NativeTheme::kPushButton;
}
+gfx::Rect ExampleNativeThemeButton::GetThemePaintRect() const {
+ return bounds();
+}
+
gfx::NativeTheme::State ExampleNativeThemeButton::GetThemeState(
gfx::NativeTheme::ExtraParams* params) const {
GetExtraParams(params);
@@ -182,7 +186,7 @@ void ExampleNativeThemeButton::GetExtraParams(
params->button.background_color = SkColorSetARGB(0, 0, 0, 0);
}
-ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
+const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() const {
int selected = cb_state_->selected_item();
return selected <= 3 ? NULL : hover_animation_.get();
}
diff --git a/views/examples/native_theme_button_example.h b/views/examples/native_theme_button_example.h
index 9ca7c33..91f02a6 100644
--- a/views/examples/native_theme_button_example.h
+++ b/views/examples/native_theme_button_example.h
@@ -11,6 +11,7 @@
#include "views/controls/button/custom_button.h"
#include "views/controls/combobox/combobox.h"
#include "views/examples/example_base.h"
+#include "views/native_theme_delegate.h"
#include "views/native_theme_painter.h"
namespace views {
@@ -22,7 +23,7 @@ namespace examples {
// A subclass of button to test native theme rendering.
class ExampleNativeThemeButton : public views::CustomButton,
- public views::NativeThemePainter::Delegate,
+ public views::NativeThemeDelegate,
public views::Combobox::Listener {
public:
ExampleNativeThemeButton(views::ButtonListener* listener,
@@ -44,9 +45,10 @@ class ExampleNativeThemeButton : public views::CustomButton,
// 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 ui::Animation* GetThemeAnimation() 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(
diff --git a/views/examples/native_theme_checkbox_example.cc b/views/examples/native_theme_checkbox_example.cc
new file mode 100644
index 0000000..f7c6626
--- /dev/null
+++ b/views/examples/native_theme_checkbox_example.cc
@@ -0,0 +1,39 @@
+// 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/native_theme_checkbox_example.h"
+
+#include "base/stringprintf.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),
+ count_(0) {
+}
+
+NativeThemeCheckboxExample::~NativeThemeCheckboxExample() {
+}
+
+std::wstring NativeThemeCheckboxExample::GetExampleTitle() {
+ return L"CheckboxNt";
+}
+
+void NativeThemeCheckboxExample::CreateExampleView(views::View* container) {
+ //button_ = new views::RadioButtonNt(L"RadioButtonNt", 3);
+ button_ = new views::CheckboxNt(L"CheckboxNt");
+ 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(L"Pressed! count:%d", ++count_).c_str());
+}
+
+} // namespace examples
diff --git a/views/examples/native_theme_checkbox_example.h b/views/examples/native_theme_checkbox_example.h
new file mode 100644
index 0000000..4bd83c7
--- /dev/null
+++ b/views/examples/native_theme_checkbox_example.h
@@ -0,0 +1,46 @@
+// 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_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
+#define VIEWS_EXAMPLES_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "ui/gfx/native_theme.h"
+#include "views/controls/button/button.h"
+#include "views/examples/example_base.h"
+
+namespace views {
+class CheckboxNt;
+}
+
+namespace examples {
+
+// NativeThemeCheckboxExample exercises a CheckboxNt control.
+class NativeThemeCheckboxExample : public ExampleBase,
+ public views::ButtonListener {
+ public:
+ explicit NativeThemeCheckboxExample(ExamplesMain* main);
+ virtual ~NativeThemeCheckboxExample();
+
+ // Overridden from ExampleBase:
+ virtual std::wstring GetExampleTitle() OVERRIDE;
+ 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::CheckboxNt* button_;
+
+ int count_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeThemeCheckboxExample);
+};
+
+} // namespace examples
+
+#endif // VIEWS_EXAMPLES_NATIVE_THEME_CHECKBOX_EXAMPLE_H_
diff --git a/views/examples/radio_button_example.cc b/views/examples/radio_button_example.cc
index 27d8fa1..546a0ee 100644
--- a/views/examples/radio_button_example.cc
+++ b/views/examples/radio_button_example.cc
@@ -25,16 +25,17 @@ 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;
+ int group = 1;
+ for (int i = 0; i < arraysize(radio_buttons_); ++i) {
radio_buttons_[i] = new views::RadioButton(
- base::StringPrintf(
- L"Radio %d in group %d", (i % group_count + 1), group),
- group);
+ base::StringPrintf( L"Radio %d in group %d", i + 1, group), group);
+ }
+
+ ++group;
+ for (int i = 0; i < arraysize(radio_buttons_nt_); ++i) {
+ radio_buttons_nt_[i] = new views::RadioButtonNt(
+ base::StringPrintf( L"Radio %d in group %d", i + 1, group), group);
+ radio_buttons_nt_[i]->SetFocusable(true);
}
views::GridLayout* layout = new views::GridLayout(container);
@@ -43,10 +44,14 @@ void RadioButtonExample::CreateExampleView(views::View* container) {
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++) {
+ for (int i = 0; i < arraysize(radio_buttons_); i++) {
layout->StartRow(0, 0);
layout->AddView(radio_buttons_[i]);
}
+ for (int i = 0; i < arraysize(radio_buttons_nt_); i++) {
+ layout->StartRow(0, 0);
+ layout->AddView(radio_buttons_nt_[i]);
+ }
layout->StartRow(0, 0);
layout->AddView(select_);
layout->StartRow(0, 0);
@@ -57,16 +62,16 @@ void RadioButtonExample::ButtonPressed(views::Button* sender,
const views::Event& event) {
if (sender == select_) {
radio_buttons_[0]->SetChecked(true);
- radio_buttons_[5]->SetChecked(true);
+ radio_buttons_nt_[2]->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()));
+ IntToOnOff(radio_buttons_nt_[0]->checked()),
+ IntToOnOff(radio_buttons_nt_[1]->checked()),
+ IntToOnOff(radio_buttons_nt_[2]->checked()));
}
}
diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h
index 92cf431..72217e2 100644
--- a/views/examples/radio_button_example.h
+++ b/views/examples/radio_button_example.h
@@ -31,9 +31,9 @@ class RadioButtonExample : public ExampleBase,
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];
+ // Two groups of 3 radio buttons.
+ views::RadioButton* radio_buttons_[3];
+ views::RadioButtonNt* radio_buttons_nt_[3];
// Control button to select radio buttons, and show the status of buttons.
views::TextButton* select_;