diff options
Diffstat (limited to 'views/controls/button')
-rw-r--r-- | views/controls/button/checkbox.cc | 31 | ||||
-rw-r--r-- | views/controls/button/checkbox.h | 4 | ||||
-rw-r--r-- | views/controls/button/native_button_gtk.cc | 4 | ||||
-rw-r--r-- | views/controls/button/native_button_gtk.h | 1 | ||||
-rw-r--r-- | views/controls/button/native_button_win.cc | 8 | ||||
-rw-r--r-- | views/controls/button/native_button_win.h | 2 | ||||
-rw-r--r-- | views/controls/button/native_button_wrapper.h | 4 |
7 files changed, 42 insertions, 12 deletions
diff --git a/views/controls/button/checkbox.cc b/views/controls/button/checkbox.cc index 0097251..c3ea2ff 100644 --- a/views/controls/button/checkbox.cc +++ b/views/controls/button/checkbox.cc @@ -57,6 +57,9 @@ gfx::Size Checkbox::GetPreferredSize() { return gfx::Size(); gfx::Size prefsize = native_wrapper_->GetView()->GetPreferredSize(); + if (native_wrapper_->UsesNativeLabel()) + return prefsize; + prefsize.set_width( prefsize.width() + kCheckboxLabelSpacing + kLabelFocusPaddingHorizontal * 2); @@ -72,16 +75,24 @@ void Checkbox::Layout() { if (!native_wrapper_) return; - gfx::Size checkmark_prefsize = native_wrapper_->GetView()->GetPreferredSize(); - int label_x = checkmark_prefsize.width() + kCheckboxLabelSpacing + - kLabelFocusPaddingHorizontal; - label_->SetBounds( - label_x, 0, std::max(0, width() - label_x - kLabelFocusPaddingHorizontal), - height()); - int first_line_height = label_->GetFont().height(); - native_wrapper_->GetView()->SetBounds( - 0, ((first_line_height - checkmark_prefsize.height()) / 2), - checkmark_prefsize.width(), checkmark_prefsize.height()); + if (native_wrapper_->UsesNativeLabel()) { + label_->SetBounds(0, 0, 0, 0); + label_->SetVisible(false); + native_wrapper_->GetView()->SetBounds(0, 0, width(), height()); + } else { + gfx::Size checkmark_prefsize = + native_wrapper_->GetView()->GetPreferredSize(); + int label_x = checkmark_prefsize.width() + kCheckboxLabelSpacing + + kLabelFocusPaddingHorizontal; + label_->SetBounds( + label_x, 0, std::max(0, width() - label_x - + kLabelFocusPaddingHorizontal), + height()); + int first_line_height = label_->GetFont().height(); + native_wrapper_->GetView()->SetBounds( + 0, ((first_line_height - checkmark_prefsize.height()) / 2), + checkmark_prefsize.width(), checkmark_prefsize.height()); + } native_wrapper_->GetView()->Layout(); } diff --git a/views/controls/button/checkbox.h b/views/controls/button/checkbox.h index 86111d1..e515b4f 100644 --- a/views/controls/button/checkbox.h +++ b/views/controls/button/checkbox.h @@ -69,8 +69,8 @@ class Checkbox : public NativeButton { // Called from the constructor to create and configure the checkbox label. void Init(const std::wstring& label_text); - // The checkbox's label. We don't use the OS version because of transparency - // and sizing issues. + // The checkbox's label. We may not be able to use the OS version on some + // platforms because of transparency and sizing issues. Label* label_; // True if the checkbox is checked. diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc index 7bd4da6..4ed3138 100644 --- a/views/controls/button/native_button_gtk.cc +++ b/views/controls/button/native_button_gtk.cc @@ -70,6 +70,10 @@ void NativeButtonGtk::SetFocus() { Focus(); } +bool NativeButtonGtk::UsesNativeLabel() const { + return true; +} + gfx::NativeView NativeButtonGtk::GetTestingHandle() const { return native_view(); } diff --git a/views/controls/button/native_button_gtk.h b/views/controls/button/native_button_gtk.h index 1d0dfc1..4b609d9 100644 --- a/views/controls/button/native_button_gtk.h +++ b/views/controls/button/native_button_gtk.h @@ -23,6 +23,7 @@ class NativeButtonGtk : public NativeControlGtk, public NativeButtonWrapper { virtual void UpdateDefault(); virtual View* GetView(); virtual void SetFocus(); + virtual bool UsesNativeLabel() const; virtual gfx::NativeView GetTestingHandle() const; // Overridden from View: diff --git a/views/controls/button/native_button_win.cc b/views/controls/button/native_button_win.cc index 86dd91f..f134b51 100644 --- a/views/controls/button/native_button_win.cc +++ b/views/controls/button/native_button_win.cc @@ -63,6 +63,10 @@ void NativeButtonWin::SetFocus() { Focus(); } +bool NativeButtonWin::UsesNativeLabel() const { + return true; +} + gfx::NativeView NativeButtonWin::GetTestingHandle() const { return native_view(); } @@ -156,6 +160,10 @@ bool NativeCheckboxWin::OnKeyDown(int vkey) { return false; } +bool NativeCheckboxWin::UsesNativeLabel() const { + return false; +} + //////////////////////////////////////////////////////////////////////////////// // NativeCheckboxWin, NativeButtonWin overrides: diff --git a/views/controls/button/native_button_win.h b/views/controls/button/native_button_win.h index ea7e7cb..2ac0817 100644 --- a/views/controls/button/native_button_win.h +++ b/views/controls/button/native_button_win.h @@ -24,6 +24,7 @@ class NativeButtonWin : public NativeControlWin, virtual void UpdateDefault(); virtual View* GetView(); virtual void SetFocus(); + virtual bool UsesNativeLabel() const; virtual gfx::NativeView GetTestingHandle() const; // Overridden from View: @@ -63,6 +64,7 @@ class NativeCheckboxWin : public NativeButtonWin { virtual void UpdateChecked(); virtual void SetPushed(bool pushed); virtual bool OnKeyDown(int vkey); + virtual bool UsesNativeLabel() const; // Overridden from NativeControlWin: virtual bool ProcessMessage(UINT message, diff --git a/views/controls/button/native_button_wrapper.h b/views/controls/button/native_button_wrapper.h index 39aa2c3..bd974bd 100644 --- a/views/controls/button/native_button_wrapper.h +++ b/views/controls/button/native_button_wrapper.h @@ -46,6 +46,10 @@ class NativeButtonWrapper { // Sets the focus to the button. virtual void SetFocus() = 0; + // Returns true if the wrapped NativeButton supplies its own label, false if + // the caller needs to provide one. + virtual bool UsesNativeLabel() const = 0; + // Returns a handle to the underlying native view for testing. virtual gfx::NativeView GetTestingHandle() const = 0; |