summaryrefslogtreecommitdiffstats
path: root/views/controls/button
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 23:35:22 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-25 23:35:22 +0000
commitb5ac72f9cc7c836a923ab81be80a6e3913498a9d (patch)
tree224231c6ea079c27b4bd8214366860b0d3c83b45 /views/controls/button
parent59326aacf6020c3cfa8978a334c36b2dcc1a99bb (diff)
downloadchromium_src-b5ac72f9cc7c836a923ab81be80a6e3913498a9d.zip
chromium_src-b5ac72f9cc7c836a923ab81be80a6e3913498a9d.tar.gz
chromium_src-b5ac72f9cc7c836a923ab81be80a6e3913498a9d.tar.bz2
Native button cleanup:
. I nuked NativeButton's minimum_size_ field as it's only used to enforce a minimum size on windows. The code to adjust for minimum size is now ifdef'd on windows. . Changes GTK's button to set the font as appropriate. BUG=none TEST=none Review URL: http://codereview.chromium.org/246007 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27288 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views/controls/button')
-rw-r--r--views/controls/button/checkbox.cc3
-rw-r--r--views/controls/button/native_button.cc38
-rw-r--r--views/controls/button/native_button.h9
-rw-r--r--views/controls/button/native_button_gtk.cc7
4 files changed, 22 insertions, 35 deletions
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc
index 9120ace..cba0aaf 100644
--- a/views/controls/button/checkbox.cc
+++ b/views/controls/button/checkbox.cc
@@ -184,7 +184,8 @@ bool Checkbox::HitTestLabel(const MouseEvent& e) {
// Checkbox, private:
void Checkbox::Init(const std::wstring& label_text) {
- set_minimum_size(gfx::Size(0, 0));
+ // Checkboxs don't need to enforce a minimum size.
+ set_ignore_minimum_size(true);
label_ = new Label(label_text);
label_->set_has_focus_border(true);
label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
diff --git a/views/controls/button/native_button.cc b/views/controls/button/native_button.cc
index ea97e54..e36719c 100644
--- a/views/controls/button/native_button.cc
+++ b/views/controls/button/native_button.cc
@@ -14,7 +14,14 @@
namespace views {
-static int kButtonBorderHWidth = 8;
+static const int kButtonBorderHWidth = 8;
+
+#if defined(OS_WIN)
+// The min size in DLUs comes from
+// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
+static const int kMinWidthDLUs = 50;
+static const int kMinHeightDLUs = 14;
+#endif
// static
const char NativeButton::kViewClassName[] = "views/NativeButton";
@@ -26,10 +33,7 @@ NativeButton::NativeButton(ButtonListener* listener)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
- ignore_minimum_size_(false),
- minimum_size_(50, 14) {
- // The min size in DLUs comes from
- // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
+ ignore_minimum_size_(false) {
InitBorder();
SetFocusable(true);
}
@@ -38,11 +42,8 @@ NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
: Button(listener),
native_wrapper_(NULL),
is_default_(false),
- ignore_minimum_size_(false),
- minimum_size_(50, 14) {
+ ignore_minimum_size_(false) {
SetLabel(label); // SetLabel takes care of label layout in RTL UI.
- // The min size in DLUs comes from
- // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
InitBorder();
SetFocusable(true);
}
@@ -125,21 +126,16 @@ gfx::Size NativeButton::GetPreferredSize() {
sz.set_width(sz.width() + border.left() + border.right());
sz.set_height(sz.height() + border.top() + border.bottom());
- // Clamp the size returned to at least the minimum size.
#if defined(OS_WIN)
+ // Clamp the size returned to at least the minimum size.
if (!ignore_minimum_size_) {
- if (minimum_size_.width()) {
- int min_width = font_.horizontal_dlus_to_pixels(minimum_size_.width());
- sz.set_width(std::max(static_cast<int>(sz.width()), min_width));
- }
- if (minimum_size_.height()) {
- int min_height = font_.vertical_dlus_to_pixels(minimum_size_.height());
- sz.set_height(std::max(static_cast<int>(sz.height()), min_height));
- }
+ sz.set_width(std::max(sz.width(),
+ font_.horizontal_dlus_to_pixels(kMinWidthDLUs)));
+ sz.set_height(std::max(sz.height(),
+ font_.vertical_dlus_to_pixels(kMinHeightDLUs)));
}
-#else
- if (minimum_size_.width() || minimum_size_.height())
- NOTIMPLEMENTED();
+ // GTK returns a meaningful preferred size so that we don't need to adjust
+ // the preferred size as we do on windows.
#endif
return sz;
diff --git a/views/controls/button/native_button.h b/views/controls/button/native_button.h
index 428d0ad..c1ecfb8 100644
--- a/views/controls/button/native_button.h
+++ b/views/controls/button/native_button.h
@@ -42,9 +42,6 @@ class NativeButton : public Button {
// registered, use SetIsDefault for that).
void SetAppearsAsDefault(bool default_button);
- void set_minimum_size(const gfx::Size& minimum_size) {
- minimum_size_ = minimum_size;
- }
void set_ignore_minimum_size(bool ignore_minimum_size) {
ignore_minimum_size_ = ignore_minimum_size;
}
@@ -91,12 +88,6 @@ class NativeButton : public Button {
// is false. Set to true to create narrower buttons.
bool ignore_minimum_size_;
- // The minimum size of the button from the specified size in native dialog
- // units. The definition of this unit may vary from platform to platform. If
- // the width/height is non-zero, the preferred size of the button will not be
- // less than this value when the dialog units are converted to pixels.
- gfx::Size minimum_size_;
-
DISALLOW_COPY_AND_ASSIGN(NativeButton);
};
diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc
index ce7ab64..fd58c42 100644
--- a/views/controls/button/native_button_gtk.cc
+++ b/views/controls/button/native_button_gtk.cc
@@ -40,11 +40,10 @@ void NativeButtonGtk::UpdateFont() {
if (!native_view())
return;
- NOTIMPLEMENTED();
+ gtk_widget_modify_font(
+ native_view(),
+ gfx::Font::PangoFontFromGfxFont(native_button_->font()));
preferred_size_ = gfx::Size();
- // SendMessage(GetHWND(), WM_SETFONT,
- // reinterpret_cast<WPARAM>(native_button_->font().hfont()),
- // FALSE);
}
void NativeButtonGtk::UpdateEnabled() {