summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorsaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-29 23:31:23 +0000
committersaintlou@chromium.org <saintlou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-03-29 23:31:23 +0000
commit67d8c128bd558f9919f370116f13515f4b84effb (patch)
treee5fbde630acd2e23ca29817586a52d3b258eab68 /views
parent87e165d66a06abe6f4cfeb6b5e575c3215ea2b0e (diff)
downloadchromium_src-67d8c128bd558f9919f370116f13515f4b84effb.zip
chromium_src-67d8c128bd558f9919f370116f13515f4b84effb.tar.gz
chromium_src-67d8c128bd558f9919f370116f13515f4b84effb.tar.bz2
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 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@79762 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, 143 insertions, 57 deletions
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index 0cb01f6..cd598dd 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() : NativeButton(NULL), checked_(false) {
+Checkbox::Checkbox() : NativeButtonBase(NULL), checked_(false) {
Init(std::wstring());
}
Checkbox::Checkbox(const std::wstring& label)
- : NativeButton(NULL, label),
+ : NativeButtonBase(NULL, label),
checked_(false) {
Init(label);
}
@@ -88,7 +88,7 @@ int Checkbox::GetHeightForWidth(int w) {
}
void Checkbox::SetEnabled(bool enabled) {
- NativeButton::SetEnabled(enabled);
+ NativeButtonBase::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) {
- NativeButton::SetLabel(label);
+ NativeButtonBase::SetLabel(label);
if (!native_wrapper_->UsesNativeLabel())
label_->SetText(label);
}
diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h
index 4451217..e251406 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 NativeButton {
+class Checkbox : public NativeButtonBase {
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 9cee97b..e03f91c 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -32,12 +32,12 @@ static const int kButtonBorderHWidth = 0;
#endif
// static
-const char NativeButton::kViewClassName[] = "views/NativeButton";
+const char NativeButtonBase::kViewClassName[] = "views/NativeButtonBase";
////////////////////////////////////////////////////////////////////////////////
-// NativeButton, public:
+// NativeButtonBase, public:
-NativeButton::NativeButton(ButtonListener* listener)
+NativeButtonBase::NativeButtonBase(ButtonListener* listener)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
@@ -47,7 +47,8 @@ NativeButton::NativeButton(ButtonListener* listener)
SetFocusable(true);
}
-NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
+NativeButtonBase::NativeButtonBase(ButtonListener* listener,
+ const std::wstring& label)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
@@ -58,10 +59,10 @@ NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
SetFocusable(true);
}
-NativeButton::~NativeButton() {
+NativeButtonBase::~NativeButtonBase() {
}
-void NativeButton::SetLabel(const std::wstring& label) {
+void NativeButtonBase::SetLabel(const std::wstring& label) {
label_ = WideToUTF16Hack(label);
// Even though we create a flipped HWND for a native button when the locale
@@ -84,7 +85,7 @@ void NativeButton::SetLabel(const std::wstring& label) {
PreferredSizeChanged();
}
-void NativeButton::SetIsDefault(bool is_default) {
+void NativeButtonBase::SetIsDefault(bool is_default) {
if (is_default == is_default_)
return;
is_default_ = is_default;
@@ -97,14 +98,14 @@ void NativeButton::SetIsDefault(bool is_default) {
PreferredSizeChanged();
}
-void NativeButton::SetNeedElevation(bool need_elevation) {
+void NativeButtonBase::SetNeedElevation(bool need_elevation) {
need_elevation_ = need_elevation;
if (native_wrapper_)
native_wrapper_->UpdateLabel();
PreferredSizeChanged();
}
-void NativeButton::ButtonPressed() {
+void NativeButtonBase::ButtonPressed() {
RequestFocus();
// TODO(beng): obtain mouse event flags for native buttons someday.
@@ -123,9 +124,9 @@ void NativeButton::ButtonPressed() {
}
////////////////////////////////////////////////////////////////////////////////
-// NativeButton, View overrides:
+// NativeButtonBase, View overrides:
-gfx::Size NativeButton::GetPreferredSize() {
+gfx::Size NativeButtonBase::GetPreferredSize() {
if (!native_wrapper_)
return gfx::Size();
@@ -156,20 +157,20 @@ gfx::Size NativeButton::GetPreferredSize() {
return sz;
}
-void NativeButton::Layout() {
+void NativeButtonBase::Layout() {
if (native_wrapper_) {
native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
native_wrapper_->GetView()->Layout();
}
}
-void NativeButton::SetEnabled(bool flag) {
+void NativeButtonBase::SetEnabled(bool flag) {
Button::SetEnabled(flag);
if (native_wrapper_)
native_wrapper_->UpdateEnabled();
}
-void NativeButton::ViewHierarchyChanged(bool is_add, View* parent,
+void NativeButtonBase::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
@@ -179,11 +180,11 @@ void NativeButton::ViewHierarchyChanged(bool is_add, View* parent,
}
}
-std::string NativeButton::GetClassName() const {
+std::string NativeButtonBase::GetClassName() const {
return kViewClassName;
}
-bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
+bool NativeButtonBase::AcceleratorPressed(const Accelerator& accelerator) {
if (IsEnabled()) {
#if defined(OS_WIN)
DWORD pos = GetMessagePos();
@@ -201,7 +202,7 @@ bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
return false;
}
-void NativeButton::OnFocus() {
+void NativeButtonBase::OnFocus() {
// Forward the focus to the wrapper.
if (native_wrapper_)
native_wrapper_->SetFocus();
@@ -210,15 +211,15 @@ void NativeButton::OnFocus() {
// keyboard messages).
}
-void NativeButton::OnPaintFocusBorder(gfx::Canvas* canvas) {
+void NativeButtonBase::OnPaintFocusBorder(gfx::Canvas* canvas) {
if (NativeViewHost::kRenderNativeControlFocus)
View::OnPaintFocusBorder(canvas);
}
////////////////////////////////////////////////////////////////////////////////
-// NativeButton, protected:
+// NativeButtonBase, protected:
-NativeButtonWrapper* NativeButton::CreateWrapper() {
+NativeButtonWrapper* NativeButtonBase::CreateWrapper() {
NativeButtonWrapper* native_wrapper =
NativeButtonWrapper::CreateNativeButtonWrapper(this);
native_wrapper->UpdateLabel();
@@ -226,9 +227,54 @@ NativeButtonWrapper* NativeButton::CreateWrapper() {
return native_wrapper;
}
-void NativeButton::InitBorder() {
+void NativeButtonBase::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 2e1337a..4c0e7fa 100644
--- a/views/controls/button/native_button.h
+++ b/views/controls/button/native_button.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -12,20 +12,24 @@
#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 NativeButton : public Button {
+class NativeButtonBase : public Button {
public:
// The button's class name.
static const char kViewClassName[];
- explicit NativeButton(ButtonListener* listener);
- NativeButton(ButtonListener* listener, const std::wstring& label);
- virtual ~NativeButton();
+ explicit NativeButtonBase(ButtonListener* listener);
+ NativeButtonBase(ButtonListener* listener, const std::wstring& label);
+ virtual ~NativeButtonBase();
// Sets/Gets the text to be used as the button's label.
virtual void SetLabel(const std::wstring& label);
@@ -96,8 +100,43 @@ class NativeButton : 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 bcd7a22..cf8b757 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -18,7 +18,7 @@
namespace views {
-NativeButtonGtk::NativeButtonGtk(NativeButton* native_button)
+NativeButtonGtk::NativeButtonGtk(NativeButtonBase* 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(
- NativeButton* native_button) {
+ NativeButtonBase* 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 8e0d5bf..e8c5d5a 100644
--- a/views/controls/button/native_button_gtk.h
+++ b/views/controls/button/native_button_gtk.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -15,7 +15,7 @@ namespace views {
// A View that hosts a native GTK button.
class NativeButtonGtk : public NativeControlGtk, public NativeButtonWrapper {
public:
- explicit NativeButtonGtk(NativeButton* native_button);
+ explicit NativeButtonGtk(NativeButtonBase* 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.
- NativeButton* native_button_;
+ NativeButtonBase* 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 2783c84..60a6c40 100644
--- a/views/controls/button/native_button_win.cc
+++ b/views/controls/button/native_button_win.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -22,7 +22,7 @@ namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeButtonWin, public:
-NativeButtonWin::NativeButtonWin(NativeButton* native_button)
+NativeButtonWin::NativeButtonWin(NativeButtonBase* 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(
- NativeButton* native_button) {
+ NativeButtonBase* 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 ed19836..3061353 100644
--- a/views/controls/button/native_button_win.h
+++ b/views/controls/button/native_button_win.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -15,7 +15,7 @@ namespace views {
class NativeButtonWin : public NativeControlWin,
public NativeButtonWrapper {
public:
- explicit NativeButtonWin(NativeButton* native_button);
+ explicit NativeButtonWin(NativeButtonBase* native_button);
virtual ~NativeButtonWin();
// Overridden from NativeButtonWrapper:
@@ -49,7 +49,7 @@ class NativeButtonWin : public NativeControlWin,
private:
// The NativeButton we are bound to.
- NativeButton* native_button_;
+ NativeButtonBase* 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 37e0265..37968c0 100644
--- a/views/controls/button/native_button_wrapper.h
+++ b/views/controls/button/native_button_wrapper.h
@@ -1,4 +1,4 @@
-// Copyright (c) 2010 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.
@@ -11,7 +11,7 @@
namespace views {
class Checkbox;
-class NativeButton;
+class NativeButtonBase;
class RadioButton;
class View;
@@ -67,7 +67,8 @@ class NativeButtonWrapper {
static int GetFixedWidth();
// Creates an appropriate NativeButtonWrapper for the platform.
- static NativeButtonWrapper* CreateNativeButtonWrapper(NativeButton* button);
+ static NativeButtonWrapper* CreateNativeButtonWrapper(
+ NativeButtonBase* 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 f2791c7..e09524b 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 NativeButton {
+class ButtonTest : public NativeButtonBase {
public:
ButtonTest(ButtonListener* listener, const std::wstring& label)
- : NativeButton(listener, label) {
+ : NativeButtonBase(listener, label) {
}
HWND GetHWND() {
@@ -1268,8 +1268,8 @@ class TestDialog : public DialogDelegate, public ButtonListener {
virtual View* GetContentsView() {
if (!contents_) {
contents_ = new View();
- button1_ = new NativeButton(this, L"Button1");
- button2_ = new NativeButton(this, L"Button2");
+ button1_ = new NativeButtonBase(this, L"Button1");
+ button2_ = new NativeButtonBase(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_;
- NativeButton* button1_;
- NativeButton* button2_;
- NativeButton* checkbox_;
+ NativeButtonBase* button1_;
+ NativeButtonBase* button2_;
+ NativeButtonBase* 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::NativeButton* ok_button_;
- views::NativeButton* cancel_button_;
+ views::NativeButtonBase* ok_button_;
+ views::NativeButtonBase* 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();
- NativeButton* native = new NativeButton(NULL, L"Native");
+ NativeButtonBase* native = new NativeButtonBase(NULL, L"Native");
root_view->SetContentsView(native);
native->SetVisible(true);