diff options
author | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-28 19:36:00 +0000 |
---|---|---|
committer | rogerta@chromium.org <rogerta@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-04-28 19:36:00 +0000 |
commit | 1d9b33d9640fb304cc8680d4f2546e2c8b68fe69 (patch) | |
tree | 69310971313838845be36cbdac029ad88e3e09c2 /views/examples | |
parent | 165fde8bf1c4872c8bfaada18c64e2b16b93c36d (diff) | |
download | chromium_src-1d9b33d9640fb304cc8680d4f2546e2c8b68fe69.zip chromium_src-1d9b33d9640fb304cc8680d4f2546e2c8b68fe69.tar.gz chromium_src-1d9b33d9640fb304cc8680d4f2546e2c8b68fe69.tar.bz2 |
Revert 83373 - Resubmitting change to fix a build break in the arm builder. The only changefrom the original code is in text_button.cc, line 402, where text_x isinitialized to 0.Add classes for native themed push buttons, radio buttons, and checkboxes.These controls expose the same public interface and the existing controlsof the same type to make it easier to change between the implementations.BUG=NoneTEST=The new controls should look and feel like native platform controlsR=ben@chromium.orgReview URL: http://codereview.chromium.org/6853015
TBR=rogerta@chromium.org
Review URL: http://codereview.chromium.org/6902119
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@83378 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/examples')
-rw-r--r-- | views/examples/button_example.cc | 62 | ||||
-rw-r--r-- | views/examples/button_example.h | 5 | ||||
-rw-r--r-- | views/examples/examples_main.cc | 5 | ||||
-rw-r--r-- | views/examples/native_theme_button_example.cc | 6 | ||||
-rw-r--r-- | views/examples/native_theme_button_example.h | 6 | ||||
-rw-r--r-- | views/examples/native_theme_checkbox_example.cc | 39 | ||||
-rw-r--r-- | views/examples/native_theme_checkbox_example.h | 46 | ||||
-rw-r--r-- | views/examples/radio_button_example.cc | 33 | ||||
-rw-r--r-- | views/examples/radio_button_example.h | 6 |
9 files changed, 21 insertions, 187 deletions
diff --git a/views/examples/button_example.cc b/views/examples/button_example.cc index 4ab7f80..d27a5d2 100644 --- a/views/examples/button_example.cc +++ b/views/examples/button_example.cc @@ -4,9 +4,6 @@ #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" @@ -14,12 +11,7 @@ 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() { @@ -30,8 +22,7 @@ std::wstring ButtonExample::GetExampleTitle() { } void ButtonExample::CreateExampleView(views::View* container) { - views::TextButton* tb = new views::TextButton(this, L"Button"); - button_ = tb; + button_ = new views::TextButton(this, L"Button"); container->SetLayoutManager(new views::FillLayout); container->AddChildView(button_); } @@ -39,57 +30,6 @@ 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 aad1ff9..fe8567b 100644 --- a/views/examples/button_example.h +++ b/views/examples/button_example.h @@ -35,11 +35,6 @@ 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 8b2b647..7f12733 100644 --- a/views/examples/examples_main.cc +++ b/views/examples/examples_main.cc @@ -20,7 +20,6 @@ #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" @@ -100,10 +99,6 @@ 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 e7630e3..7398a270 100644 --- a/views/examples/native_theme_button_example.cc +++ b/views/examples/native_theme_button_example.cc @@ -136,10 +136,6 @@ 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); @@ -186,7 +182,7 @@ void ExampleNativeThemeButton::GetExtraParams( params->button.background_color = SkColorSetARGB(0, 0, 0, 0); } -const ui::Animation* ExampleNativeThemeButton::GetThemeAnimation() 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 91f02a6..9ca7c33 100644 --- a/views/examples/native_theme_button_example.h +++ b/views/examples/native_theme_button_example.h @@ -11,7 +11,6 @@ #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 { @@ -23,7 +22,7 @@ namespace examples { // A subclass of button to test native theme rendering. class ExampleNativeThemeButton : public views::CustomButton, - public views::NativeThemeDelegate, + public views::NativeThemePainter::Delegate, public views::Combobox::Listener { public: ExampleNativeThemeButton(views::ButtonListener* listener, @@ -45,10 +44,9 @@ 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 const ui::Animation* GetThemeAnimation() const OVERRIDE; + virtual 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 deleted file mode 100644 index f7c6626..0000000 --- a/views/examples/native_theme_checkbox_example.cc +++ /dev/null @@ -1,39 +0,0 @@ -// 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 deleted file mode 100644 index 4bd83c7..0000000 --- a/views/examples/native_theme_checkbox_example.h +++ /dev/null @@ -1,46 +0,0 @@ -// 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 546a0ee..27d8fa1 100644 --- a/views/examples/radio_button_example.cc +++ b/views/examples/radio_button_example.cc @@ -25,17 +25,16 @@ void RadioButtonExample::CreateExampleView(views::View* container) { select_ = new views::TextButton(this, L"Select"); status_ = new views::TextButton(this, L"Show Status"); - 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 + 1, group), group); - } + int all = arraysize(radio_buttons_); - ++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); + // 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); @@ -44,14 +43,10 @@ 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 < arraysize(radio_buttons_); i++) { + for (int i = 0; i < all; 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); @@ -62,16 +57,16 @@ void RadioButtonExample::ButtonPressed(views::Button* sender, const views::Event& event) { if (sender == select_) { radio_buttons_[0]->SetChecked(true); - radio_buttons_nt_[2]->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_nt_[0]->checked()), - IntToOnOff(radio_buttons_nt_[1]->checked()), - IntToOnOff(radio_buttons_nt_[2]->checked())); + IntToOnOff(radio_buttons_[3]->checked()), + IntToOnOff(radio_buttons_[4]->checked()), + IntToOnOff(radio_buttons_[5]->checked())); } } diff --git a/views/examples/radio_button_example.h b/views/examples/radio_button_example.h index 72217e2..92cf431 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; - // Two groups of 3 radio buttons. - views::RadioButton* radio_buttons_[3]; - views::RadioButtonNt* radio_buttons_nt_[3]; + // 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_; |