summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authordhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 00:33:29 +0000
committerdhollowa@chromium.org <dhollowa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-30 00:33:29 +0000
commit9ad913a5cca7fa2c434ea0134be9a3f5c005e2d1 (patch)
treeee2bc12521a0ba485351ea9644329c476380e715 /views
parent1b9f7ab1f8abf238acf180a029b25cf41cc7ec07 (diff)
downloadchromium_src-9ad913a5cca7fa2c434ea0134be9a3f5c005e2d1.zip
chromium_src-9ad913a5cca7fa2c434ea0134be9a3f5c005e2d1.tar.gz
chromium_src-9ad913a5cca7fa2c434ea0134be9a3f5c005e2d1.tar.bz2
Revert 79762 - This CL wraps TextButton inside NativeButton for the touch case.
The reason for the added intermediate class is that RadioButton is derived from CheckBox which is derived from NativeButton. This is just transitional code this approach is simpler and more importantly contained to the views/controls/button/, the rest of the code can continue to use NativeButton transparently as before. Note: the Windows trybot seems to fail on flaky test BUG=none TEST=none Review URL: http://codereview.chromium.org/6770014 TBR=saintlou@chromium.org Review URL: http://codereview.chromium.org/6731075 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79770 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/controls/button/checkbox.cc8
-rw-r--r--views/controls/button/checkbox.h2
-rw-r--r--views/controls/button/native_button.cc90
-rw-r--r--views/controls/button/native_button.h49
-rw-r--r--views/controls/button/native_button_gtk.cc6
-rw-r--r--views/controls/button/native_button_gtk.h6
-rw-r--r--views/controls/button/native_button_win.cc6
-rw-r--r--views/controls/button/native_button_win.h6
-rw-r--r--views/controls/button/native_button_wrapper.h7
-rw-r--r--views/view_unittest.cc20
10 files changed, 57 insertions, 143 deletions
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index cd598dd..0cb01f6 100644
--- a/views/controls/button/checkbox.cc
+++ b/views/controls/button/checkbox.cc
@@ -21,12 +21,12 @@ static const int kLabelFocusPaddingVertical = 1;
////////////////////////////////////////////////////////////////////////////////
// Checkbox, public:
-Checkbox::Checkbox() : NativeButtonBase(NULL), checked_(false) {
+Checkbox::Checkbox() : NativeButton(NULL), checked_(false) {
Init(std::wstring());
}
Checkbox::Checkbox(const std::wstring& label)
- : NativeButtonBase(NULL, label),
+ : NativeButton(NULL, label),
checked_(false) {
Init(label);
}
@@ -88,7 +88,7 @@ int Checkbox::GetHeightForWidth(int w) {
}
void Checkbox::SetEnabled(bool enabled) {
- NativeButtonBase::SetEnabled(enabled);
+ NativeButton::SetEnabled(enabled);
if (label_)
label_->SetEnabled(enabled);
}
@@ -165,7 +165,7 @@ void Checkbox::GetAccessibleState(ui::AccessibleViewState* state) {
// Checkbox, NativeButton overrides:
void Checkbox::SetLabel(const std::wstring& label) {
- NativeButtonBase::SetLabel(label);
+ NativeButton::SetLabel(label);
if (!native_wrapper_->UsesNativeLabel())
label_->SetText(label);
}
diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h
index e251406..4451217 100644
--- a/views/controls/button/checkbox.h
+++ b/views/controls/button/checkbox.h
@@ -15,7 +15,7 @@ namespace views {
class Label;
// A NativeButton subclass representing a checkbox.
-class Checkbox : public NativeButtonBase {
+class Checkbox : public NativeButton {
public:
// The button's class name.
static const char kViewClassName[];
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc
index e03f91c..9cee97b 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -32,12 +32,12 @@ static const int kButtonBorderHWidth = 0;
#endif
// static
-const char NativeButtonBase::kViewClassName[] = "views/NativeButtonBase";
+const char NativeButton::kViewClassName[] = "views/NativeButton";
////////////////////////////////////////////////////////////////////////////////
-// NativeButtonBase, public:
+// NativeButton, public:
-NativeButtonBase::NativeButtonBase(ButtonListener* listener)
+NativeButton::NativeButton(ButtonListener* listener)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
@@ -47,8 +47,7 @@ NativeButtonBase::NativeButtonBase(ButtonListener* listener)
SetFocusable(true);
}
-NativeButtonBase::NativeButtonBase(ButtonListener* listener,
- const std::wstring& label)
+NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
@@ -59,10 +58,10 @@ NativeButtonBase::NativeButtonBase(ButtonListener* listener,
SetFocusable(true);
}
-NativeButtonBase::~NativeButtonBase() {
+NativeButton::~NativeButton() {
}
-void NativeButtonBase::SetLabel(const std::wstring& label) {
+void NativeButton::SetLabel(const std::wstring& label) {
label_ = WideToUTF16Hack(label);
// Even though we create a flipped HWND for a native button when the locale
@@ -85,7 +84,7 @@ void NativeButtonBase::SetLabel(const std::wstring& label) {
PreferredSizeChanged();
}
-void NativeButtonBase::SetIsDefault(bool is_default) {
+void NativeButton::SetIsDefault(bool is_default) {
if (is_default == is_default_)
return;
is_default_ = is_default;
@@ -98,14 +97,14 @@ void NativeButtonBase::SetIsDefault(bool is_default) {
PreferredSizeChanged();
}
-void NativeButtonBase::SetNeedElevation(bool need_elevation) {
+void NativeButton::SetNeedElevation(bool need_elevation) {
need_elevation_ = need_elevation;
if (native_wrapper_)
native_wrapper_->UpdateLabel();
PreferredSizeChanged();
}
-void NativeButtonBase::ButtonPressed() {
+void NativeButton::ButtonPressed() {
RequestFocus();
// TODO(beng): obtain mouse event flags for native buttons someday.
@@ -124,9 +123,9 @@ void NativeButtonBase::ButtonPressed() {
}
////////////////////////////////////////////////////////////////////////////////
-// NativeButtonBase, View overrides:
+// NativeButton, View overrides:
-gfx::Size NativeButtonBase::GetPreferredSize() {
+gfx::Size NativeButton::GetPreferredSize() {
if (!native_wrapper_)
return gfx::Size();
@@ -157,20 +156,20 @@ gfx::Size NativeButtonBase::GetPreferredSize() {
return sz;
}
-void NativeButtonBase::Layout() {
+void NativeButton::Layout() {
if (native_wrapper_) {
native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
native_wrapper_->GetView()->Layout();
}
}
-void NativeButtonBase::SetEnabled(bool flag) {
+void NativeButton::SetEnabled(bool flag) {
Button::SetEnabled(flag);
if (native_wrapper_)
native_wrapper_->UpdateEnabled();
}
-void NativeButtonBase::ViewHierarchyChanged(bool is_add, View* parent,
+void NativeButton::ViewHierarchyChanged(bool is_add, View* parent,
View* child) {
if (is_add && !native_wrapper_ && GetWidget()) {
// The native wrapper's lifetime will be managed by the view hierarchy after
@@ -180,11 +179,11 @@ void NativeButtonBase::ViewHierarchyChanged(bool is_add, View* parent,
}
}
-std::string NativeButtonBase::GetClassName() const {
+std::string NativeButton::GetClassName() const {
return kViewClassName;
}
-bool NativeButtonBase::AcceleratorPressed(const Accelerator& accelerator) {
+bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
if (IsEnabled()) {
#if defined(OS_WIN)
DWORD pos = GetMessagePos();
@@ -202,7 +201,7 @@ bool NativeButtonBase::AcceleratorPressed(const Accelerator& accelerator) {
return false;
}
-void NativeButtonBase::OnFocus() {
+void NativeButton::OnFocus() {
// Forward the focus to the wrapper.
if (native_wrapper_)
native_wrapper_->SetFocus();
@@ -211,15 +210,15 @@ void NativeButtonBase::OnFocus() {
// keyboard messages).
}
-void NativeButtonBase::OnPaintFocusBorder(gfx::Canvas* canvas) {
+void NativeButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
if (NativeViewHost::kRenderNativeControlFocus)
View::OnPaintFocusBorder(canvas);
}
////////////////////////////////////////////////////////////////////////////////
-// NativeButtonBase, protected:
+// NativeButton, protected:
-NativeButtonWrapper* NativeButtonBase::CreateWrapper() {
+NativeButtonWrapper* NativeButton::CreateWrapper() {
NativeButtonWrapper* native_wrapper =
NativeButtonWrapper::CreateNativeButtonWrapper(this);
native_wrapper->UpdateLabel();
@@ -227,54 +226,9 @@ NativeButtonWrapper* NativeButtonBase::CreateWrapper() {
return native_wrapper;
}
-void NativeButtonBase::InitBorder() {
+void NativeButton::InitBorder() {
set_border(Border::CreateEmptyBorder(0, kButtonBorderHWidth, 0,
kButtonBorderHWidth));
}
-#if defined(TOUCH_UI)
-////////////////////////////////////////////////////////////////////////////////
-// NativeButton, public:
-
-NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
- : TextButton(listener, label), is_default_(false) {
- set_alignment(TextButton::ALIGN_CENTER);
- SetNormalHasBorder(true);
-}
-
-void NativeButton::SetLabel(const std::wstring& label) {
- SetText(label);
-}
-
-void NativeButton::set_font(const gfx::Font& font) {
- SetFont(font);
-}
-
-void NativeButton::SetIsDefault(bool default_button) {
- is_default_ = default_button;
-}
-
-bool NativeButton::is_default() const {
- return is_default_;
-}
-
-void NativeButton::set_ignore_minimum_size(bool) {
- // TODO(saintlou): ignoring for now
-}
-#elif defined(OS_WIN)
-////////////////////////////////////////////////////////////////////////////////
-// NativeButton, public:
-
-NativeButton::NativeButton(ButtonListener* listener)
- : NativeButtonBase(listener) {
-}
-
-NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
- : NativeButtonBase(listener, label) {
-}
-
-NativeButton::~NativeButton() {
-}
-#endif
-
} // namespace views
diff --git a/views/controls/button/native_button.h b/views/controls/button/native_button.h
index 4c0e7fa..2e1337a 100644
--- a/views/controls/button/native_button.h
+++ b/views/controls/button/native_button.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -12,24 +12,20 @@
#include "views/controls/button/button.h"
#include "views/controls/button/native_button_wrapper.h"
-#if defined(TOUCH_UI)
-#include "views/controls/button/text_button.h"
-#endif
-
namespace gfx {
class Font;
}
namespace views {
-class NativeButtonBase : public Button {
+class NativeButton : public Button {
public:
// The button's class name.
static const char kViewClassName[];
- explicit NativeButtonBase(ButtonListener* listener);
- NativeButtonBase(ButtonListener* listener, const std::wstring& label);
- virtual ~NativeButtonBase();
+ explicit NativeButton(ButtonListener* listener);
+ NativeButton(ButtonListener* listener, const std::wstring& label);
+ virtual ~NativeButton();
// Sets/Gets the text to be used as the button's label.
virtual void SetLabel(const std::wstring& label);
@@ -100,43 +96,8 @@ class NativeButtonBase : public Button {
// is false. Set to true to create narrower buttons.
bool ignore_minimum_size_;
- DISALLOW_COPY_AND_ASSIGN(NativeButtonBase);
-};
-
-#if defined(TOUCH_UI)
-// TODO(saintlou): this maps NativeButton to TextButton in the touch case
-class NativeButton : public TextButton {
- public:
- NativeButton(ButtonListener* listener, const std::wstring& label);
- void SetLabel(const std::wstring& label);
- void set_font(const gfx::Font& font);
- void SetIsDefault(bool default_button);
- bool is_default() const;
- void set_ignore_minimum_size(bool);
-
- private:
- // True if the button is the default button in its context.
- bool is_default_;
-
- DISALLOW_COPY_AND_ASSIGN(NativeButton);
-};
-#elif defined(OS_WIN)
-// TODO(saintlou): Windows does not like typedef, in particluar it
-// chokes in other modules that have a forward declaration for
-// NativeButton
-class NativeButton : public NativeButtonBase {
- public:
- explicit NativeButton(ButtonListener* listener);
- NativeButton(ButtonListener* listener, const std::wstring& label);
- virtual ~NativeButton();
-
- private:
DISALLOW_COPY_AND_ASSIGN(NativeButton);
};
-#else
-// Keep the same implementation as before for non-touch case
-typedef NativeButtonBase NativeButton;
-#endif
} // namespace views
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index cf8b757..bcd7a22 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -18,7 +18,7 @@
namespace views {
-NativeButtonGtk::NativeButtonGtk(NativeButtonBase* native_button)
+NativeButtonGtk::NativeButtonGtk(NativeButton* native_button)
: native_button_(native_button) {
// Associates the actual GtkWidget with the native_button so the native_button
// is the one considered as having the focus (not the wrapper) when the
@@ -285,7 +285,7 @@ int NativeButtonWrapper::GetFixedWidth() {
// static
NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper(
- NativeButtonBase* native_button) {
+ NativeButton* native_button) {
return new NativeButtonGtk(native_button);
}
diff --git a/views/controls/button/native_button_gtk.h b/views/controls/button/native_button_gtk.h
index e8c5d5a..8e0d5bf 100644
--- a/views/controls/button/native_button_gtk.h
+++ b/views/controls/button/native_button_gtk.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,7 +15,7 @@ namespace views {
// A View that hosts a native GTK button.
class NativeButtonGtk : public NativeControlGtk, public NativeButtonWrapper {
public:
- explicit NativeButtonGtk(NativeButtonBase* native_button);
+ explicit NativeButtonGtk(NativeButton* native_button);
virtual ~NativeButtonGtk();
// Overridden from NativeButtonWrapper:
@@ -42,7 +42,7 @@ class NativeButtonGtk : public NativeControlGtk, public NativeButtonWrapper {
virtual void OnClicked();
// The NativeButton we are bound to.
- NativeButtonBase* native_button_;
+ NativeButton* native_button_;
private:
// The preferred size from the last size_request. We save this until we are
diff --git a/views/controls/button/native_button_win.cc b/views/controls/button/native_button_win.cc
index 60a6c40..2783c84 100644
--- a/views/controls/button/native_button_win.cc
+++ b/views/controls/button/native_button_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -22,7 +22,7 @@ namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeButtonWin, public:
-NativeButtonWin::NativeButtonWin(NativeButtonBase* native_button)
+NativeButtonWin::NativeButtonWin(NativeButton* native_button)
: native_button_(native_button),
button_size_valid_(false) {
// Associates the actual HWND with the native_button so the native_button is
@@ -267,7 +267,7 @@ int NativeButtonWrapper::GetFixedWidth() {
// static
NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper(
- NativeButtonBase* native_button) {
+ NativeButton* native_button) {
return new NativeButtonWin(native_button);
}
diff --git a/views/controls/button/native_button_win.h b/views/controls/button/native_button_win.h
index 3061353..ed19836 100644
--- a/views/controls/button/native_button_win.h
+++ b/views/controls/button/native_button_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -15,7 +15,7 @@ namespace views {
class NativeButtonWin : public NativeControlWin,
public NativeButtonWrapper {
public:
- explicit NativeButtonWin(NativeButtonBase* native_button);
+ explicit NativeButtonWin(NativeButton* native_button);
virtual ~NativeButtonWin();
// Overridden from NativeButtonWrapper:
@@ -49,7 +49,7 @@ class NativeButtonWin : public NativeControlWin,
private:
// The NativeButton we are bound to.
- NativeButtonBase* native_button_;
+ NativeButton* native_button_;
// It's expensive to find the size of a button on windows, so we cache it.
mutable gfx::Size button_size_;
diff --git a/views/controls/button/native_button_wrapper.h b/views/controls/button/native_button_wrapper.h
index 37968c0..37e0265 100644
--- a/views/controls/button/native_button_wrapper.h
+++ b/views/controls/button/native_button_wrapper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -11,7 +11,7 @@
namespace views {
class Checkbox;
-class NativeButtonBase;
+class NativeButton;
class RadioButton;
class View;
@@ -67,8 +67,7 @@ class NativeButtonWrapper {
static int GetFixedWidth();
// Creates an appropriate NativeButtonWrapper for the platform.
- static NativeButtonWrapper* CreateNativeButtonWrapper(
- NativeButtonBase* button);
+ static NativeButtonWrapper* CreateNativeButtonWrapper(NativeButton* button);
static NativeButtonWrapper* CreateCheckboxWrapper(Checkbox* checkbox);
static NativeButtonWrapper* CreateRadioButtonWrapper(
RadioButton* radio_button);
diff --git a/views/view_unittest.cc b/views/view_unittest.cc
index e09524b..f2791c7 100644
--- a/views/view_unittest.cc
+++ b/views/view_unittest.cc
@@ -1090,10 +1090,10 @@ TEST_F(ViewTest, HiddenViewWithAccelerator) {
////////////////////////////////////////////////////////////////////////////////
// Mouse-wheel message rerouting
////////////////////////////////////////////////////////////////////////////////
-class ButtonTest : public NativeButtonBase {
+class ButtonTest : public NativeButton {
public:
ButtonTest(ButtonListener* listener, const std::wstring& label)
- : NativeButtonBase(listener, label) {
+ : NativeButton(listener, label) {
}
HWND GetHWND() {
@@ -1268,8 +1268,8 @@ class TestDialog : public DialogDelegate, public ButtonListener {
virtual View* GetContentsView() {
if (!contents_) {
contents_ = new View();
- button1_ = new NativeButtonBase(this, L"Button1");
- button2_ = new NativeButtonBase(this, L"Button2");
+ button1_ = new NativeButton(this, L"Button1");
+ button2_ = new NativeButton(this, L"Button2");
checkbox_ = new Checkbox(L"My checkbox");
button_drop_ = new ButtonDropDown(this, mock_menu_model_);
contents_->AddChildView(button1_);
@@ -1314,9 +1314,9 @@ class TestDialog : public DialogDelegate, public ButtonListener {
}
View* contents_;
- NativeButtonBase* button1_;
- NativeButtonBase* button2_;
- NativeButtonBase* checkbox_;
+ NativeButton* button1_;
+ NativeButton* button2_;
+ NativeButton* checkbox_;
ButtonDropDown* button_drop_;
Button* last_pressed_button_;
ui::MockMenuModel* mock_menu_model_;
@@ -1389,8 +1389,8 @@ class DefaultButtonTest : public ViewTest {
views::FocusManager* focus_manager_;
TestDialog* test_dialog_;
DialogClientView* client_view_;
- views::NativeButtonBase* ok_button_;
- views::NativeButtonBase* cancel_button_;
+ views::NativeButton* ok_button_;
+ views::NativeButton* cancel_button_;
};
TEST_F(DefaultButtonTest, DialogDefaultButtonTest) {
@@ -1508,7 +1508,7 @@ TEST_F(ViewTest, ChangeVisibility) {
scoped_ptr<views::Widget> window(CreateWidget());
window->Init(NULL, gfx::Rect(0, 0, 500, 300));
views::RootView* root_view = window->GetRootView();
- NativeButtonBase* native = new NativeButtonBase(NULL, L"Native");
+ NativeButton* native = new NativeButton(NULL, L"Native");
root_view->SetContentsView(native);
native->SetVisible(true);