summaryrefslogtreecommitdiffstats
path: root/chrome/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-23 21:55:52 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-03-23 21:55:52 +0000
commita8111ce7343d3d6458eff4a5f370cf611f6753b4 (patch)
tree30dfb0171c2e450f0271d3c787ac0cfbc06e663b /chrome/views
parente48211e18675bec9056fb0762ec1c6644b0ff32e (diff)
downloadchromium_src-a8111ce7343d3d6458eff4a5f370cf611f6753b4.zip
chromium_src-a8111ce7343d3d6458eff4a5f370cf611f6753b4.tar.gz
chromium_src-a8111ce7343d3d6458eff4a5f370cf611f6753b4.tar.bz2
The death knell for the old native buttons, checkboxes and radio buttons.
Replace with renamed NativeButton2, Checkbox2, RadioButton2. Review URL: http://codereview.chromium.org/50083 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12317 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r--chrome/views/controls/button/button.h13
-rw-r--r--chrome/views/controls/button/checkbox.cc243
-rw-r--r--chrome/views/controls/button/checkbox.h98
-rw-r--r--chrome/views/controls/button/checkbox2.cc166
-rw-r--r--chrome/views/controls/button/checkbox2.h75
-rw-r--r--chrome/views/controls/button/native_button.cc245
-rw-r--r--chrome/views/controls/button/native_button.h169
-rw-r--r--chrome/views/controls/button/native_button2.cc150
-rw-r--r--chrome/views/controls/button/native_button2.h93
-rw-r--r--chrome/views/controls/button/native_button_win.cc23
-rw-r--r--chrome/views/controls/button/native_button_win.h10
-rw-r--r--chrome/views/controls/button/native_button_wrapper.h16
-rw-r--r--chrome/views/controls/button/radio_button.cc142
-rw-r--r--chrome/views/controls/button/radio_button.h54
-rw-r--r--chrome/views/controls/button/radio_button2.cc103
-rw-r--r--chrome/views/controls/button/radio_button2.h45
-rw-r--r--chrome/views/controls/message_box_view.cc24
-rw-r--r--chrome/views/controls/message_box_view.h7
-rw-r--r--chrome/views/controls/native_control_win.cc3
-rw-r--r--chrome/views/focus/focus_manager_unittest.cc27
-rw-r--r--chrome/views/view_unittest.cc36
-rw-r--r--chrome/views/views.vcproj24
-rw-r--r--chrome/views/window/dialog_client_view.cc26
-rw-r--r--chrome/views/window/dialog_client_view.h11
-rw-r--r--chrome/views/window/dialog_delegate.cc1
25 files changed, 493 insertions, 1311 deletions
diff --git a/chrome/views/controls/button/button.h b/chrome/views/controls/button/button.h
index 1f6514b..f00f8a1 100644
--- a/chrome/views/controls/button/button.h
+++ b/chrome/views/controls/button/button.h
@@ -39,15 +39,17 @@ class Button : public View {
virtual void SetAccessibleName(const std::wstring& name);
protected:
- // Construct the Button with a Listener. The listener can be NULL, as long as
- // the specific button implementation makes sure to not call NotifyClick. This
- // can be true of buttons that don't have a listener - e.g. menubuttons where
- // there's no default action.
+ // Construct the Button with a Listener. The listener can be NULL. This can be
+ // true of buttons that don't have a listener - e.g. menubuttons where there's
+ // no default action and checkboxes.
explicit Button(ButtonListener* listener);
// Cause the button to notify the listener that a click occurred.
virtual void NotifyClick(int mouse_event_flags);
+ // The button's listener. Notified when clicked.
+ ButtonListener* listener_;
+
private:
// The text shown in a tooltip.
std::wstring tooltip_text_;
@@ -56,9 +58,6 @@ class Button : public View {
std::wstring accessible_shortcut_;
std::wstring accessible_name_;
- // The button's listener. Notified when clicked.
- ButtonListener* listener_;
-
// The id tag associated with this button. Used to disambiguate buttons in
// the ButtonListener implementation.
int tag_;
diff --git a/chrome/views/controls/button/checkbox.cc b/chrome/views/controls/button/checkbox.cc
index b768037..032a1aa 100644
--- a/chrome/views/controls/button/checkbox.cc
+++ b/chrome/views/controls/button/checkbox.cc
@@ -1,181 +1,164 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 "chrome/views/controls/button/checkbox.h"
#include "chrome/common/gfx/chrome_canvas.h"
-#include "chrome/views/controls/button/checkbox.h"
-#include "chrome/views/controls/hwnd_view.h"
#include "chrome/views/controls/label.h"
-// FIXME(ACW) there got be a better way to find out the check box sizes
-static int kCheckBoxWidth = 13;
-static int kCheckBoxHeight = 13;
-static int kCheckBoxToLabel = 4;
-
namespace views {
-// Horizontal focus padding.
-const int CheckBox::kFocusPaddingHorizontal = 2;
-const int CheckBox::kFocusPaddingVertical = 1;
+// static
+const char Checkbox::kViewClassName[] = "chrome/views/Checkbox";
-const char CheckBox::kViewClassName[] = "chrome/views/CheckBox";
+static const int kCheckboxLabelSpacing = 4;
+static const int kLabelFocusPaddingHorizontal = 2;
+static const int kLabelFocusPaddingVertical = 1;
-CheckBox::CheckBox(const std::wstring& label)
- : NativeButton(label),
- is_selected_(false) {
- // Note: we paint the label as a floating view
- SetMinSizeFromDLUs(gfx::Size(0, 0));
- label_ = new Label(label);
- label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
-}
+////////////////////////////////////////////////////////////////////////////////
+// Checkbox, public:
-CheckBox::~CheckBox() {
- delete label_;
+Checkbox::Checkbox() : NativeButton(NULL), checked_(false) {
+ Init(std::wstring());
}
-void CheckBox::SetMultiLine(bool multi_line) {
- label_->SetMultiLine(multi_line);
+Checkbox::Checkbox(const std::wstring& label)
+ : NativeButton(NULL, label),
+ checked_(false) {
+ Init(label);
}
-// static
-int CheckBox::GetTextIndent() {
- return kCheckBoxWidth + kCheckBoxToLabel + kFocusPaddingHorizontal;
+Checkbox::~Checkbox() {
}
-void CheckBox::SetIsSelected(bool f) {
- if (f != is_selected_) {
- is_selected_ = f;
- UpdateNativeButton();
- }
+void Checkbox::SetMultiLine(bool multiline) {
+ label_->SetMultiLine(multiline);
}
-bool CheckBox::IsSelected() const {
- return is_selected_;
+void Checkbox::SetChecked(bool checked) {
+ if (checked_ == checked)
+ return;
+ checked_ = checked;
+ native_wrapper_->UpdateChecked();
}
-std::string CheckBox::GetClassName() const {
- return kViewClassName;
+// static
+int Checkbox::GetTextIndent() {
+ return NativeButtonWrapper::GetFixedWidth() + kCheckboxLabelSpacing;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// Checkbox, View overrides:
+
+gfx::Size Checkbox::GetPreferredSize() {
+ gfx::Size prefsize = native_wrapper_->GetView()->GetPreferredSize();
+ prefsize.set_width(
+ prefsize.width() + kCheckboxLabelSpacing +
+ kLabelFocusPaddingHorizontal * 2);
+ gfx::Size label_prefsize = label_->GetPreferredSize();
+ prefsize.set_width(prefsize.width() + label_prefsize.width());
+ prefsize.set_height(
+ std::max(prefsize.height(),
+ label_prefsize.height() + kLabelFocusPaddingVertical * 2));
+ return prefsize;
}
-void CheckBox::Layout() {
- int label_x = GetTextIndent();
- label_->SetBounds(label_x, 0, std::max(0, width() - label_x), height());
- if (hwnd_view_) {
- int first_line_height = label_->GetFont().height();
- hwnd_view_->SetBounds(0, ((first_line_height - kCheckBoxHeight) / 2) + 1,
- kCheckBoxWidth, kCheckBoxHeight);
- hwnd_view_->Layout();
+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());
+ native_wrapper_->GetView()->Layout();
+}
+
+void Checkbox::Paint(ChromeCanvas* canvas) {
+ // Paint the focus border manually since we don't want to send actual focus
+ // in to the inner view.
+ if (HasFocus()) {
+ gfx::Rect label_bounds = label_->bounds();
+ canvas->DrawFocusRect(
+ MirroredLeftPointForRect(label_bounds) - kLabelFocusPaddingHorizontal,
+ 0,
+ label_bounds.width() + kLabelFocusPaddingHorizontal * 2,
+ label_bounds.height() - kLabelFocusPaddingVertical * 2);
}
}
-void CheckBox::ComputeTextRect(gfx::Rect* out) {
- gfx::Size s = label_->GetPreferredSize();
- out->set_x(GetTextIndent());
- out->set_y(kFocusPaddingVertical);
- int new_width = std::min(width() - (kCheckBoxWidth + kCheckBoxToLabel),
- s.width());
- out->set_width(std::max(0, new_width));
- out->set_height(s.height());
+View* Checkbox::GetViewForPoint(const gfx::Point& point) {
+ return GetViewForPoint(point, false);
}
-void CheckBox::Paint(ChromeCanvas* canvas) {
- gfx::Rect r;
- ComputeTextRect(&r);
- // Paint the focus border if any.
- if (HasFocus()) {
- // Mirror left point for rectangle to draw focus for RTL text.
- canvas->DrawFocusRect(MirroredLeftPointForRect(r) - kFocusPaddingHorizontal,
- r.y() - kFocusPaddingVertical,
- r.width() + kFocusPaddingHorizontal * 2,
- r.height() + kFocusPaddingVertical * 2);
- }
- PaintFloatingView(canvas, label_, r.x(), r.y(), r.width(), r.height());
+View* Checkbox::GetViewForPoint(const gfx::Point& point,
+ bool can_create_floating) {
+ return GetLocalBounds(true).Contains(point) ? this : NULL;
}
-void CheckBox::SetEnabled(bool enabled) {
- if (enabled_ == enabled)
- return;
- NativeButton::SetEnabled(enabled);
- label_->SetEnabled(enabled);
-}
-
-HWND CheckBox::CreateNativeControl(HWND parent_container) {
- HWND r = ::CreateWindowEx(WS_EX_TRANSPARENT | GetAdditionalExStyle(),
- L"BUTTON",
- L"",
- WS_CHILD | BS_CHECKBOX | WS_VISIBLE,
- 0, 0, width(), height(),
- parent_container, NULL, NULL, NULL);
- ConfigureNativeButton(r);
- return r;
-}
-
-void CheckBox::ConfigureNativeButton(HWND hwnd) {
- ::SendMessage(hwnd,
- static_cast<UINT>(BM_SETCHECK),
- static_cast<WPARAM>(is_selected_ ? BST_CHECKED : BST_UNCHECKED),
- 0);
- label_->SetText(GetLabel());
-}
-
-gfx::Size CheckBox::GetPreferredSize() {
- gfx::Size prefsize = label_->GetPreferredSize();
- prefsize.set_height(std::max(prefsize.height() + kFocusPaddingVertical * 2,
- kCheckBoxHeight));
- prefsize.Enlarge(GetTextIndent() * 2, 0);
- return prefsize;
+void Checkbox::OnMouseEntered(const MouseEvent& e) {
+ native_wrapper_->SetPushed(HitTestLabel(e));
}
-LRESULT CheckBox::OnCommand(UINT code, int id, HWND source) {
- if (code == BN_CLICKED)
- SetIsSelected(!is_selected_);
-
- return NativeButton::OnCommand(code, id, source);
+void Checkbox::OnMouseMoved(const MouseEvent& e) {
+ native_wrapper_->SetPushed(HitTestLabel(e));
}
-void CheckBox::HighlightButton(bool f) {
- ::SendMessage(GetNativeControlHWND(),
- static_cast<UINT>(BM_SETSTATE),
- static_cast<WPARAM>(f),
- 0);
+void Checkbox::OnMouseExited(const MouseEvent& e) {
+ native_wrapper_->SetPushed(false);
}
-bool CheckBox::LabelHitTest(const MouseEvent& event) {
- CPoint p(event.x(), event.y());
- gfx::Rect r;
- ComputeTextRect(&r);
- return r.Contains(event.x(), event.y());
+bool Checkbox::OnMousePressed(const MouseEvent& e) {
+ native_wrapper_->SetPushed(HitTestLabel(e));
+ return true;
}
-void CheckBox::OnMouseEntered(const MouseEvent& event) {
- HighlightButton(LabelHitTest(event));
+void Checkbox::OnMouseReleased(const MouseEvent& e, bool canceled) {
+ native_wrapper_->SetPushed(false);
+ if (!canceled & HitTestLabel(e)) {
+ SetChecked(!checked());
+ ButtonPressed();
+ }
}
-void CheckBox::OnMouseMoved(const MouseEvent& event) {
- HighlightButton(LabelHitTest(event));
+std::string Checkbox::GetClassName() const {
+ return kViewClassName;
}
-void CheckBox::OnMouseExited(const MouseEvent& event) {
- HighlightButton(false);
+////////////////////////////////////////////////////////////////////////////////
+// Checkbox, NativeButton overrides:
+
+void Checkbox::CreateWrapper() {
+ native_wrapper_ = NativeButtonWrapper::CreateCheckboxWrapper(this);
+ native_wrapper_->UpdateLabel();
+ native_wrapper_->UpdateChecked();
}
-bool CheckBox::OnMousePressed(const MouseEvent& event) {
- HighlightButton(LabelHitTest(event));
- return true;
+void Checkbox::InitBorder() {
+ // No border, so we do nothing.
}
-bool CheckBox::OnMouseDragged(const MouseEvent& event) {
- HighlightButton(LabelHitTest(event));
- return true;
+////////////////////////////////////////////////////////////////////////////////
+// Checkbox, private:
+
+void Checkbox::Init(const std::wstring& label_text) {
+ set_minimum_size(gfx::Size(0, 0));
+ label_ = new Label(label_text);
+ label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
+ AddChildView(label_);
}
-void CheckBox::OnMouseReleased(const MouseEvent& event,
- bool canceled) {
- HighlightButton(false);
- if (!canceled && LabelHitTest(event))
- OnCommand(BN_CLICKED, 0, GetNativeControlHWND());
+bool Checkbox::HitTestLabel(const MouseEvent& e) {
+ gfx::Point tmp(e.location());
+ ConvertPointToView(this, label_, &tmp);
+ return label_->HitTest(tmp);
}
} // namespace views
diff --git a/chrome/views/controls/button/checkbox.h b/chrome/views/controls/button/checkbox.h
index 78c006b..b9def2c 100644
--- a/chrome/views/controls/button/checkbox.h
+++ b/chrome/views/controls/button/checkbox.h
@@ -1,85 +1,81 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
#define CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
-#include "base/gfx/rect.h"
#include "chrome/views/controls/button/native_button.h"
namespace views {
class Label;
-////////////////////////////////////////////////////////////////////////////////
-//
-// CheckBox implements a check box button. It uses the standard windows control
-// for the check item but not for the label. We have to do this because windows
-// always wants to draw a background under the label. I tried to intercept
-// WM_CTLCOLORSTATIC and return a NULL_BRUSH and setting the BkMode to
-// transparent as well as other things. The background was always drawn as solid
-// black.
-//
-// The label is implemented with a views::Label
-//
-////////////////////////////////////////////////////////////////////////////////
-class CheckBox : public NativeButton {
+// A NativeButton subclass representing a checkbox.
+class Checkbox : public NativeButton {
public:
+ // The button's class name.
static const char kViewClassName[];
- static const int kFocusPaddingHorizontal;
- static const int kFocusPaddingVertical;
- explicit CheckBox(const std::wstring& label);
- virtual ~CheckBox();
+ Checkbox();
+ Checkbox(const std::wstring& label);
+ virtual ~Checkbox();
- // Allows the label to wrap across multiple lines if |multi_line| is true.
- // If false, the text is cropped.
- void SetMultiLine(bool multi_line);
+ // Sets a listener for this checkbox. Checkboxes aren't required to have them
+ // since their state can be read independently of them being toggled.
+ void set_listener(ButtonListener* listener) { listener_ = listener; }
- // Returns the x position of the text. This can also be used to indent
- // subsequent dependent controls.
- static int GetTextIndent();
+ // Sets whether or not the checkbox label should wrap multiple lines of text.
+ // If true, long lines are wrapped, and this is reflected in the preferred
+ // size returned by GetPreferredSize. If false, text that will not fit within
+ // the available bounds for the label will be cropped.
+ void SetMultiLine(bool multiline);
- virtual void SetIsSelected(bool f);
- bool IsSelected() const;
+ // Sets/Gets whether or not the checkbox is checked.
+ virtual void SetChecked(bool checked);
+ bool checked() const { return checked_; }
- virtual std::string GetClassName() const;
+ // Returns the indentation of the text from the left edge of the view.
+ static int GetTextIndent();
+ // Overridden from View:
virtual gfx::Size GetPreferredSize();
virtual void Layout();
-
- virtual bool OnMousePressed(const MouseEvent& event);
- virtual bool OnMouseDragged(const MouseEvent& event);
- virtual void OnMouseReleased(const MouseEvent& event, bool canceled);
- virtual void OnMouseEntered(const MouseEvent& event);
- virtual void OnMouseMoved(const MouseEvent& event);
- virtual void OnMouseExited(const MouseEvent& event);
-
virtual void Paint(ChromeCanvas* canvas);
-
- // Overriden to forward to the label too.
- virtual void SetEnabled(bool enabled);
+ virtual View* GetViewForPoint(const gfx::Point& point);
+ virtual View* GetViewForPoint(const gfx::Point& point,
+ bool can_create_floating);
+ virtual void OnMouseEntered(const MouseEvent& e);
+ virtual void OnMouseMoved(const MouseEvent& e);
+ virtual void OnMouseExited(const MouseEvent& e);
+ virtual bool OnMousePressed(const MouseEvent& e);
+ virtual void OnMouseReleased(const MouseEvent& e, bool canceled);
protected:
+ virtual std::string GetClassName() const;
- virtual HWND CreateNativeControl(HWND parent_container);
- virtual void ConfigureNativeButton(HWND hwnd);
- virtual LRESULT OnCommand(UINT code, int id, HWND source);
+ // Overridden from NativeButton2:
+ virtual void CreateWrapper();
+ virtual void InitBorder();
- Label* label_;
private:
+ // Called from the constructor to create and configure the checkbox label.
+ void Init(const std::wstring& label_text);
- void HighlightButton(bool f);
- bool LabelHitTest(const MouseEvent& event);
- void ComputeTextRect(gfx::Rect* out);
+ // Returns true if the event (in Checkbox coordinates) is within the bounds of
+ // the label.
+ bool HitTestLabel(const MouseEvent& e);
- bool is_selected_;
+ // The checkbox's label. We don't use the OS version because of transparency
+ // and sizing issues.
+ Label* label_;
+ // True if the checkbox is checked.
+ bool checked_;
- DISALLOW_EVIL_CONSTRUCTORS(CheckBox);
+ DISALLOW_COPY_AND_ASSIGN(Checkbox);
};
} // namespace views
-#endif // CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
+#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX_H_
diff --git a/chrome/views/controls/button/checkbox2.cc b/chrome/views/controls/button/checkbox2.cc
deleted file mode 100644
index 426d0d8..0000000
--- a/chrome/views/controls/button/checkbox2.cc
+++ /dev/null
@@ -1,166 +0,0 @@
-// Copyright (c) 2009 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 "chrome/views/controls/button/checkbox2.h"
-
-#include "chrome/common/gfx/chrome_canvas.h"
-#include "chrome/views/controls/label.h"
-
-namespace views {
-
-// static
-const char Checkbox2::kViewClassName[] = "chrome/views/Checkbox";
-
-static const int kCheckboxLabelSpacing = 4;
-static const int kLabelFocusPaddingHorizontal = 2;
-static const int kLabelFocusPaddingVertical = 1;
-
-////////////////////////////////////////////////////////////////////////////////
-// Checkbox2, public:
-
-Checkbox2::Checkbox2() : NativeButton2(NULL), checked_(false) {
- Init(std::wstring());
-}
-
-Checkbox2::Checkbox2(ButtonListener* listener)
- : NativeButton2(listener),
- checked_(false) {
- Init(std::wstring());
-}
-
-Checkbox2::Checkbox2(ButtonListener* listener, const std::wstring& label)
- : NativeButton2(listener, label),
- checked_(false) {
- Init(label);
-}
-
-Checkbox2::~Checkbox2() {
-}
-
-void Checkbox2::SetMultiLine(bool multiline) {
- label_->SetMultiLine(multiline);
-}
-
-void Checkbox2::SetChecked(bool checked) {
- if (checked_ == checked)
- return;
- checked_ = checked;
- native_wrapper_->UpdateChecked();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Checkbox2, View overrides:
-
-gfx::Size Checkbox2::GetPreferredSize() {
- gfx::Size prefsize = native_wrapper_->GetView()->GetPreferredSize();
- prefsize.set_width(
- prefsize.width() + kCheckboxLabelSpacing +
- kLabelFocusPaddingHorizontal * 2);
- gfx::Size label_prefsize = label_->GetPreferredSize();
- prefsize.set_width(prefsize.width() + label_prefsize.width());
- prefsize.set_height(
- std::max(prefsize.height(),
- label_prefsize.height() + kLabelFocusPaddingVertical * 2));
- return prefsize;
-}
-
-void Checkbox2::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());
- native_wrapper_->GetView()->Layout();
-}
-
-void Checkbox2::Paint(ChromeCanvas* canvas) {
- // Paint the focus border manually since we don't want to send actual focus
- // in to the inner view.
- if (HasFocus()) {
- gfx::Rect label_bounds = label_->bounds();
- canvas->DrawFocusRect(
- MirroredLeftPointForRect(label_bounds) - kLabelFocusPaddingHorizontal,
- 0,
- label_bounds.width() + kLabelFocusPaddingHorizontal * 2,
- label_bounds.height() - kLabelFocusPaddingVertical * 2);
- }
-}
-
-View* Checkbox2::GetViewForPoint(const gfx::Point& point) {
- return GetViewForPoint(point, false);
-}
-
-View* Checkbox2::GetViewForPoint(const gfx::Point& point,
- bool can_create_floating) {
- return GetLocalBounds(true).Contains(point) ? this : NULL;
-}
-
-void Checkbox2::OnMouseEntered(const MouseEvent& e) {
- native_wrapper_->SetPushed(HitTestLabel(e));
-}
-
-void Checkbox2::OnMouseMoved(const MouseEvent& e) {
- native_wrapper_->SetPushed(HitTestLabel(e));
-}
-
-void Checkbox2::OnMouseExited(const MouseEvent& e) {
- native_wrapper_->SetPushed(false);
-}
-
-bool Checkbox2::OnMousePressed(const MouseEvent& e) {
- native_wrapper_->SetPushed(HitTestLabel(e));
- return true;
-}
-
-void Checkbox2::OnMouseReleased(const MouseEvent& e, bool canceled) {
- native_wrapper_->SetPushed(false);
- if (!canceled & HitTestLabel(e)) {
- SetChecked(!checked());
- ButtonPressed();
- }
-}
-
-std::string Checkbox2::GetClassName() const {
- return kViewClassName;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Checkbox2, NativeButton2 overrides:
-
-void Checkbox2::CreateWrapper() {
- native_wrapper_ = NativeButtonWrapper::CreateCheckboxWrapper(this);
- native_wrapper_->UpdateLabel();
- native_wrapper_->UpdateChecked();
-}
-
-void Checkbox2::InitBorder() {
- // No border, so we do nothing.
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// Checkbox2, private:
-
-void Checkbox2::Init(const std::wstring& label_text) {
- SetFocusable(true);
- set_minimum_size(gfx::Size(0, 0));
- label_ = new Label(label_text);
- label_->SetHorizontalAlignment(Label::ALIGN_LEFT);
- AddChildView(label_);
-}
-
-bool Checkbox2::HitTestLabel(const MouseEvent& e) {
- gfx::Point tmp(e.location());
- ConvertPointToView(this, label_, &tmp);
- return label_->HitTest(tmp);
-}
-
-} // namespace views
diff --git a/chrome/views/controls/button/checkbox2.h b/chrome/views/controls/button/checkbox2.h
deleted file mode 100644
index d2c1e0f..0000000
--- a/chrome/views/controls/button/checkbox2.h
+++ /dev/null
@@ -1,75 +0,0 @@
-// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX2_H_
-#define CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX2_H_
-
-#include "chrome/views/controls/button/native_button2.h"
-
-namespace views {
-
-class Label;
-
-// A NativeButton subclass representing a checkbox.
-class Checkbox2 : public NativeButton2 {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- Checkbox2();
- explicit Checkbox2(ButtonListener* listener);
- Checkbox2(ButtonListener* listener, const std::wstring& label);
- virtual ~Checkbox2();
-
- // Sets whether or not the checkbox label should wrap multiple lines of text.
- // If true, long lines are wrapped, and this is reflected in the preferred
- // size returned by GetPreferredSize. If false, text that will not fit within
- // the available bounds for the label will be cropped.
- void SetMultiLine(bool multiline);
-
- // Sets/Gets whether or not the checkbox is checked.
- virtual void SetChecked(bool checked);
- bool checked() const { return checked_; }
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
- virtual void Paint(ChromeCanvas* canvas);
- virtual View* GetViewForPoint(const gfx::Point& point);
- virtual View* GetViewForPoint(const gfx::Point& point,
- bool can_create_floating);
- virtual void OnMouseEntered(const MouseEvent& e);
- virtual void OnMouseMoved(const MouseEvent& e);
- virtual void OnMouseExited(const MouseEvent& e);
- virtual bool OnMousePressed(const MouseEvent& e);
- virtual void OnMouseReleased(const MouseEvent& e, bool canceled);
-
- protected:
- virtual std::string GetClassName() const;
-
- // Overridden from NativeButton2:
- virtual void CreateWrapper();
- virtual void InitBorder();
-
- private:
- // Called from the constructor to create and configure the checkbox label.
- void Init(const std::wstring& label_text);
-
- // Returns true if the event (in Checkbox coordinates) is within the bounds of
- // the label.
- bool HitTestLabel(const MouseEvent& e);
-
- // The checkbox's label. We don't use the OS version because of transparency
- // and sizing issues.
- Label* label_;
-
- // True if the checkbox is checked.
- bool checked_;
-
- DISALLOW_COPY_AND_ASSIGN(Checkbox2);
-};
-
-} // namespace views
-
-#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX2_H_
diff --git a/chrome/views/controls/button/native_button.cc b/chrome/views/controls/button/native_button.cc
index 4da39407..9d681b7 100644
--- a/chrome/views/controls/button/native_button.cc
+++ b/chrome/views/controls/button/native_button.cc
@@ -1,71 +1,53 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 "chrome/views/controls/button/native_button.h"
#include "base/logging.h"
-#include "chrome/common/gfx/chrome_canvas.h"
#include "chrome/common/l10n_util.h"
-#include "chrome/common/resource_bundle.h"
-#include "chrome/views/background.h"
namespace views {
-const char NativeButton::kViewClassName[] = "chrome/views/NativeButton";
-
-NativeButton::NativeButton(const std::wstring& label)
- : enforce_dlu_min_size_(true) {
- Init(label, false);
-}
+static int kButtonBorderHWidth = 8;
-NativeButton::NativeButton(const std::wstring& label, bool is_default)
- : enforce_dlu_min_size_(true) {
- Init(label, is_default);
-}
+// static
+const char NativeButton::kViewClassName[] = "chrome/views/NativeButton";
-NativeButton::~NativeButton() {
-}
+////////////////////////////////////////////////////////////////////////////////
+// NativeButton, public:
-std::string NativeButton::GetClassName() const {
- return kViewClassName;
+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
+ InitBorder();
+ SetFocusable(true);
}
-void NativeButton::SetListener(Listener *l) {
- listener_ = l;
+NativeButton::NativeButton(ButtonListener* listener, const std::wstring& label)
+ : Button(listener),
+ native_wrapper_(NULL),
+ label_(label),
+ 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
+ InitBorder();
+ SetFocusable(true);
}
-void NativeButton::SetPadding(CSize size) {
- padding_ = size;
+NativeButton::~NativeButton() {
}
-gfx::Size NativeButton::GetPreferredSize() {
- HWND hwnd = GetNativeControlHWND();
- if (hwnd) {
- SIZE sz = {0, 0};
- ::SendMessage(hwnd,
- BCM_GETIDEALSIZE,
- 0,
- reinterpret_cast<LPARAM>(&sz));
- sz.cx += 2 * padding_.cx;
- sz.cy += 2 * padding_.cy;
-
- if (enforce_dlu_min_size_) {
- if (min_dlu_size_.width()) {
- sz.cx =
- std::max(static_cast<int>(sz.cx),
- font_.horizontal_dlus_to_pixels(min_dlu_size_.width()));
- }
- if (min_dlu_size_.height())
- sz.cy = std::max(static_cast<int>(sz.cy),
- font_.vertical_dlus_to_pixels(min_dlu_size_.height()));
- }
- return gfx::Size(sz.cx, sz.cy);
- }
- return gfx::Size();
-}
+void NativeButton::SetLabel(const std::wstring& label) {
+ label_ = label;
-void NativeButton::SetLabel(const std::wstring& l) {
// Even though we create a flipped HWND for a native button when the locale
// is right-to-left, Windows does not render text for the button using a
// right-to-left context (perhaps because the parent HWND is not flipped).
@@ -77,136 +59,93 @@ void NativeButton::SetLabel(const std::wstring& l) {
// RTL strings explicitly (using the appropriate Unicode formatting) so that
// Windows displays the text correctly regardless of the HWND hierarchy.
std::wstring localized_label;
- if (l10n_util::AdjustStringForLocaleDirection(l, &localized_label))
- label_.assign(localized_label);
- else
- label_.assign(l);
+ if (l10n_util::AdjustStringForLocaleDirection(label_, &localized_label))
+ label_ = localized_label;
- SetAccessibleName(l);
- UpdateNativeButton();
+ if (native_wrapper_)
+ native_wrapper_->UpdateLabel();
}
-const std::wstring NativeButton::GetLabel() const {
- return label_;
+void NativeButton::SetIsDefault(bool is_default) {
+ if (is_default == is_default_)
+ return;
+ is_default_ = is_default;
+ if (native_wrapper_)
+ native_wrapper_->UpdateDefault();
}
-HWND NativeButton::CreateNativeControl(HWND parent_container) {
- DWORD flags = WS_CHILD | BS_PUSHBUTTON;
- if (is_default_)
- flags |= BS_DEFPUSHBUTTON;
- HWND r = ::CreateWindowEx(GetAdditionalExStyle(), L"BUTTON", L"", flags, 0, 0,
- width(), height(), parent_container, NULL,
- NULL, NULL);
- SendMessage(r, WM_SETFONT, reinterpret_cast<WPARAM>(font_.hfont()), FALSE);
- ConfigureNativeButton(r);
- return r;
-}
+void NativeButton::ButtonPressed() {
+ RequestFocus();
-LRESULT NativeButton::OnNotify(int w_param, LPNMHDR l_param) {
- return 0;
+ // TODO(beng): obtain mouse event flags for native buttons someday.
+ NotifyClick(mouse_event_flags());
}
-LRESULT NativeButton::OnCommand(UINT code, int id, HWND source) {
- if (code == BN_CLICKED)
- Clicked();
- return 0;
-}
+////////////////////////////////////////////////////////////////////////////////
+// NativeButton, View overrides:
-void NativeButton::UpdateNativeButton() {
- HWND hwnd = GetNativeControlHWND();
- if (hwnd)
- ConfigureNativeButton(hwnd);
-}
+gfx::Size NativeButton::GetPreferredSize() {
+ gfx::Size sz = native_wrapper_->GetView()->GetPreferredSize();
+
+ // Add in the border size. (Do this before clamping the minimum size in case
+ // that clamping causes an increase in size that would include the borders.
+ gfx::Insets border = GetInsets();
+ 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 (!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));
+ }
+ }
-void NativeButton::ConfigureNativeButton(HWND hwnd) {
- ::SetWindowText(hwnd, label_.c_str());
+ return sz;
}
-void NativeButton::SetDefaultButton(bool is_default_button) {
- if (is_default_button == is_default_)
- return;
- is_default_ = is_default_button;
- if (is_default_button)
- AddAccelerator(Accelerator(VK_RETURN, false, false, false));
- else
- RemoveAccelerator(Accelerator(VK_RETURN, false, false, false));
- SendMessage(GetNativeControlHWND(), BM_SETSTYLE,
- is_default_button ? BS_DEFPUSHBUTTON : BS_PUSHBUTTON, true);
+void NativeButton::Layout() {
+ if (native_wrapper_) {
+ native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
+ native_wrapper_->GetView()->Layout();
+ }
}
-bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
- if (enabled_) {
- Clicked();
- return true;
+void NativeButton::ViewHierarchyChanged(bool is_add, View* parent,
+ View* child) {
+ if (is_add && !native_wrapper_ && GetWidget()) {
+ CreateWrapper();
+ AddChildView(native_wrapper_->GetView());
}
- return false;
}
-bool NativeButton::GetAccessibleRole(VARIANT* role) {
- DCHECK(role);
-
- role->vt = VT_I4;
- role->lVal = ROLE_SYSTEM_PUSHBUTTON;
- return true;
+std::string NativeButton::GetClassName() const {
+ return kViewClassName;
}
-bool NativeButton::GetAccessibleName(std::wstring* name) {
- if (!accessible_name_.empty()) {
- *name = accessible_name_;
+bool NativeButton::AcceleratorPressed(const Accelerator& accelerator) {
+ if (IsEnabled()) {
+ NotifyClick(mouse_event_flags());
return true;
}
return false;
}
-void NativeButton::SetAccessibleName(const std::wstring& name) {
- accessible_name_.assign(name);
-}
+////////////////////////////////////////////////////////////////////////////////
+// NativeButton, protected:
-void NativeButton::Init(const std::wstring& label, bool is_default) {
- // Marking the string as an RTL string if the locale is RTL. Refer to
- // the comments in NativeButton::SetLabel for more details.
- std::wstring localized_label;
- if (l10n_util::AdjustStringForLocaleDirection(label, &localized_label))
- label_.assign(localized_label);
- else
- label_.assign(label);
-
- l10n_util::AdjustStringForLocaleDirection(label, &label_);
- listener_ = NULL;
- SetAccessibleName(label);
- // The padding of 8 is a bit arbitrary, there appears to be no way to
- // get a recommended padding, and this value varies greatly among windows
- // dialogs.
- //
- // The min size in DLUs comes from
- // http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnwue/html/ch14e.asp
- padding_ = CSize(8, 0);
- is_default_ = is_default;
- min_dlu_size_.SetSize(50, 14);
- SetFocusable(true);
- if (is_default)
- AddAccelerator(Accelerator(VK_RETURN, false, false, false));
+void NativeButton::CreateWrapper() {
+ native_wrapper_ = NativeButtonWrapper::CreateNativeButtonWrapper(this);
+ native_wrapper_->UpdateLabel();
}
-void NativeButton::Clicked() {
- DCHECK(enabled_);
- // Give the focus to the button.
- RequestFocus();
-
- if (listener_)
- listener_->ButtonPressed(this);
-}
-
-bool NativeButton::NotifyOnKeyDown() const {
- return true;
-}
-
-bool NativeButton::OnKeyDown(int virtual_key_code) {
- if (virtual_key_code == VK_RETURN) {
- Clicked();
- return true;
- }
- return false;
+void NativeButton::InitBorder() {
+ set_border(Border::CreateEmptyBorder(0, kButtonBorderHWidth, 0,
+ kButtonBorderHWidth));
}
} // namespace views
diff --git a/chrome/views/controls/button/native_button.h b/chrome/views/controls/button/native_button.h
index 07d7340..566038b 100644
--- a/chrome/views/controls/button/native_button.h
+++ b/chrome/views/controls/button/native_button.h
@@ -1,146 +1,93 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
#define CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
-#include <string>
-
-#include "base/gfx/size.h"
#include "chrome/common/gfx/chrome_font.h"
-#include "chrome/views/controls/native_control.h"
+#include "chrome/views/controls/button/button.h"
+#include "chrome/views/controls/button/native_button_wrapper.h"
+
+class ChromeFont;
namespace views {
-////////////////////////////////////////////////////////////////////////////////
-//
-// NativeButton is a wrapper for a windows native button
-// TODO(beng): (Cleanup) this should derive also from some button-like base to
-// get all the listenery-stuff for free and to work with
-// AddManagedButton.
-//
-////////////////////////////////////////////////////////////////////////////////
-class NativeButton : public NativeControl {
+class NativeButton : public Button {
public:
- explicit NativeButton(const std::wstring& label);
- NativeButton(const std::wstring& label, bool is_default);
- virtual ~NativeButton();
-
- virtual gfx::Size GetPreferredSize();
-
- void SetLabel(const std::wstring& l);
- const std::wstring GetLabel() const;
-
- std::string GetClassName() const;
-
- class Listener {
- public:
- //
- // This is invoked once the button is released.
- virtual void ButtonPressed(NativeButton* sender) = 0;
- };
-
- //
- // The the listener, the object that receives a notification when this
- // button is pressed.
- void SetListener(Listener* listener);
+ // The button's class name.
+ static const char kViewClassName[];
- // Set the font used by this button.
- void SetFont(const ChromeFont& font) { font_ = font; }
+ explicit NativeButton(ButtonListener* listener);
+ NativeButton(ButtonListener* listener, const std::wstring& label);
+ virtual ~NativeButton();
- // Adds some internal padding to the button. The |size| specified is applied
- // on both sides of the button for each directions
- void SetPadding(CSize size);
+ // Sets/Gets the text to be used as the button's label.
+ void SetLabel(const std::wstring& label);
+ std::wstring label() const { return label_; }
- // Sets/unsets this button as the default button. The default button is the
- // one triggered when enter is pressed. It is displayed with a blue border.
- void SetDefaultButton(bool is_default_button);
- bool IsDefaultButton() const { return is_default_; }
+ // Sets the font to be used when displaying the button's label.
+ void set_font(const ChromeFont& font) { font_ = font; }
+ const ChromeFont& font() const { return font_; }
- virtual LRESULT OnNotify(int w_param, LPNMHDR l_param);
- virtual LRESULT OnCommand(UINT code, int id, HWND source);
+ // Sets/Gets whether or not the button appears as the default button in its
+ // current context.
+ void SetIsDefault(bool default_button);
+ bool is_default() const { return is_default_; }
- // Invoked when the accelerator associated with the button is pressed.
- virtual bool AcceleratorPressed(const Accelerator& accelerator);
-
- // Sets the minimum size of the button from the specified size (in dialog
- // units). If the width/height is non-zero, the preferred size of the button
- // is max(preferred size of the content + padding, dlus converted to pixels).
- //
- // The default is 50, 14.
- void SetMinSizeFromDLUs(const gfx::Size& dlu_size) {
- min_dlu_size_ = dlu_size;
+ 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;
}
- // Returns the MSAA role of the current view. The role is what assistive
- // technologies (ATs) use to determine what behavior to expect from a given
- // control.
- bool GetAccessibleRole(VARIANT* role);
-
- // Returns a brief, identifying string, containing a unique, readable name.
- bool GetAccessibleName(std::wstring* name);
-
- // Assigns an accessible string name.
- void SetAccessibleName(const std::wstring& name);
-
- // Sets whether the min size of this button should follow the Windows
- // guidelines. Default is true. Set this to false if you want slim buttons.
- void set_enforce_dlu_min_size(bool value) { enforce_dlu_min_size_ = value; }
+ // Called by the wrapper when the actual wrapped native button was pressed.
+ void ButtonPressed();
- // The view class name.
- static const char kViewClassName[];
+ // Overridden from View:
+ virtual gfx::Size GetPreferredSize();
+ virtual void Layout();
protected:
+ virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
+ virtual std::string GetClassName() const;
+ virtual bool AcceleratorPressed(const Accelerator& accelerator);
- virtual HWND CreateNativeControl(HWND parent_container);
-
- // Sub-classes can call this method to cause the native button to reflect
- // the current state
- virtual void UpdateNativeButton();
+ // Create the button wrapper. Can be overridden by subclass to create a
+ // wrapper of a particular type. See NativeButtonWrapper interface for types.
+ virtual void CreateWrapper();
- // Sub-classes must override this method to properly configure the native
- // button given the current state
- virtual void ConfigureNativeButton(HWND hwnd);
+ // Sets a border to the button. Override to set a different border or to not
+ // set one (the default is 0,8,0,8 for push buttons).
+ virtual void InitBorder();
- // Overridden from NativeControl so we can activate the button when Enter is
- // pressed.
- virtual bool NotifyOnKeyDown() const;
- virtual bool OnKeyDown(int virtual_key_code);
+ // The object that actually implements the native button.
+ NativeButtonWrapper* native_wrapper_;
private:
- NativeButton() {}
-
- // Initializes the button. If |is_default| is true, this appears like the
- // "default" button, and will register Enter as its keyboard accelerator.
- void Init(const std::wstring& label, bool is_default);
-
- void Clicked();
-
- // Whether the button preferred size should follow the Microsoft layout
- // guidelines. Default is true.
- bool enforce_dlu_min_size_;
-
+ // The button label.
std::wstring label_;
- ChromeFont font_;
- Listener* listener_;
- CSize padding_;
-
- // True if the button should be rendered to appear like the "default" button
- // in the containing dialog box. Default buttons register Enter as their
- // accelerator.
+ // True if the button is the default button in its context.
bool is_default_;
- // Minimum size, in dlus (see SetMinSizeFromDLUs).
- gfx::Size min_dlu_size_;
+ // The font used to render the button label.
+ ChromeFont font_;
+
+ // True if the button should ignore the minimum size for the platform. Default
+ // is false. Set to true to create narrower buttons.
+ bool ignore_minimum_size_;
- // Storage of strings needed for accessibility.
- std::wstring accessible_name_;
+ // 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);
};
} // namespace views
-#endif // CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
+#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON_H_
diff --git a/chrome/views/controls/button/native_button2.cc b/chrome/views/controls/button/native_button2.cc
deleted file mode 100644
index 0a12e59..0000000
--- a/chrome/views/controls/button/native_button2.cc
+++ /dev/null
@@ -1,150 +0,0 @@
-// Copyright (c) 2009 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 "chrome/views/controls/button/native_button2.h"
-
-#include "base/logging.h"
-#include "chrome/common/l10n_util.h"
-
-namespace views {
-
-static int kButtonBorderHWidth = 8;
-
-// static
-const char NativeButton2::kViewClassName[] = "chrome/views/NativeButton";
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeButton, public:
-
-NativeButton2::NativeButton2(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
- InitBorder();
-}
-
-NativeButton2::NativeButton2(ButtonListener* listener,
- const std::wstring& label)
- : Button(listener),
- native_wrapper_(NULL),
- label_(label),
- 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
- InitBorder();
-}
-
-NativeButton2::~NativeButton2() {
-}
-
-void NativeButton2::SetLabel(const std::wstring& label) {
- label_ = label;
-
- // Even though we create a flipped HWND for a native button when the locale
- // is right-to-left, Windows does not render text for the button using a
- // right-to-left context (perhaps because the parent HWND is not flipped).
- // The result is that RTL strings containing punctuation marks are not
- // displayed properly. For example, the string "...ABC" (where A, B and C are
- // Hebrew characters) is displayed as "ABC..." which is incorrect.
- //
- // In order to overcome this problem, we mark the localized Hebrew strings as
- // RTL strings explicitly (using the appropriate Unicode formatting) so that
- // Windows displays the text correctly regardless of the HWND hierarchy.
- std::wstring localized_label;
- if (l10n_util::AdjustStringForLocaleDirection(label_, &localized_label))
- label_ = localized_label;
-
- if (native_wrapper_)
- native_wrapper_->UpdateLabel();
-}
-
-void NativeButton2::SetIsDefault(bool is_default) {
- if (is_default == is_default_)
- return;
- is_default_ = is_default;
- if (native_wrapper_)
- native_wrapper_->UpdateDefault();
-}
-
-void NativeButton2::ButtonPressed() {
- RequestFocus();
-
- // TODO(beng): obtain mouse event flags for native buttons someday.
- NotifyClick(mouse_event_flags());
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeButton, View overrides:
-
-gfx::Size NativeButton2::GetPreferredSize() {
- gfx::Size sz = native_wrapper_->GetView()->GetPreferredSize();
-
- // Add in the border size. (Do this before clamping the minimum size in case
- // that clamping causes an increase in size that would include the borders.
- gfx::Insets border = GetInsets();
- 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 (!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));
- }
- }
-
- return sz;
-}
-
-void NativeButton2::Layout() {
- if (native_wrapper_) {
- native_wrapper_->GetView()->SetBounds(0, 0, width(), height());
- native_wrapper_->GetView()->Layout();
- }
-}
-
-void NativeButton2::ViewHierarchyChanged(bool is_add, View* parent,
- View* child) {
- if (is_add && !native_wrapper_ && GetWidget()) {
- CreateWrapper();
- AddChildView(native_wrapper_->GetView());
- }
-}
-
-std::string NativeButton2::GetClassName() const {
- return kViewClassName;
-}
-
-bool NativeButton2::AcceleratorPressed(const Accelerator& accelerator) {
- if (IsEnabled()) {
- NotifyClick(mouse_event_flags());
- return true;
- }
- return false;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// NativeButton, protected:
-
-void NativeButton2::CreateWrapper() {
- native_wrapper_ = NativeButtonWrapper::CreateNativeButtonWrapper(this);
- native_wrapper_->UpdateLabel();
-}
-
-void NativeButton2::InitBorder() {
- set_border(Border::CreateEmptyBorder(0, kButtonBorderHWidth, 0,
- kButtonBorderHWidth));
-}
-
-} // namespace views
diff --git a/chrome/views/controls/button/native_button2.h b/chrome/views/controls/button/native_button2.h
deleted file mode 100644
index 691a76c..0000000
--- a/chrome/views/controls/button/native_button2.h
+++ /dev/null
@@ -1,93 +0,0 @@
-// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON2_H_
-#define CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON2_H_
-
-#include "chrome/common/gfx/chrome_font.h"
-#include "chrome/views/controls/button/button.h"
-#include "chrome/views/controls/button/native_button_wrapper.h"
-
-class ChromeFont;
-
-namespace views {
-
-class NativeButton2 : public Button {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- explicit NativeButton2(ButtonListener* listener);
- NativeButton2(ButtonListener* listener, const std::wstring& label);
- virtual ~NativeButton2();
-
- // Sets/Gets the text to be used as the button's label.
- void SetLabel(const std::wstring& label);
- std::wstring label() const { return label_; }
-
- // Sets the font to be used when displaying the button's label.
- void set_font(const ChromeFont& font) { font_ = font; }
- const ChromeFont& font() const { return font_; }
-
- // Sets/Gets whether or not the button appears as the default button in its
- // current context.
- void SetIsDefault(bool default_button);
- bool is_default() const { return is_default_; }
-
- 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;
- }
-
- // Called by the wrapper when the actual wrapped native button was pressed.
- void ButtonPressed();
-
- // Overridden from View:
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
-
- protected:
- virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child);
- virtual std::string GetClassName() const;
- virtual bool AcceleratorPressed(const Accelerator& accelerator);
-
- // Create the button wrapper. Can be overridden by subclass to create a
- // wrapper of a particular type. See NativeButtonWrapper interface for types.
- virtual void CreateWrapper();
-
- // Sets a border to the button. Override to set a different border or to not
- // set one (the default is 0,8,0,8 for push buttons).
- virtual void InitBorder();
-
- // The object that actually implements the native button.
- NativeButtonWrapper* native_wrapper_;
-
- private:
- // The button label.
- std::wstring label_;
-
- // True if the button is the default button in its context.
- bool is_default_;
-
- // The font used to render the button label.
- ChromeFont font_;
-
- // True if the button should ignore the minimum size for the platform. Default
- // 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(NativeButton2);
-};
-
-} // namespace views
-
-#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_NATIVE_BUTTON2_H_
diff --git a/chrome/views/controls/button/native_button_win.cc b/chrome/views/controls/button/native_button_win.cc
index 8bffd96..aa664ba 100644
--- a/chrome/views/controls/button/native_button_win.cc
+++ b/chrome/views/controls/button/native_button_win.cc
@@ -5,9 +5,9 @@
#include "chrome/views/controls/button/native_button_win.h"
#include "base/logging.h"
-#include "chrome/views/controls/button/checkbox2.h"
-#include "chrome/views/controls/button/native_button2.h"
-#include "chrome/views/controls/button/radio_button2.h"
+#include "chrome/views/controls/button/checkbox.h"
+#include "chrome/views/controls/button/native_button.h"
+#include "chrome/views/controls/button/radio_button.h"
#include "chrome/views/widget/widget.h"
namespace views {
@@ -15,7 +15,7 @@ namespace views {
////////////////////////////////////////////////////////////////////////////////
// NativeButtonWin, public:
-NativeButtonWin::NativeButtonWin(NativeButton2* native_button)
+NativeButtonWin::NativeButtonWin(NativeButton* native_button)
: NativeControlWin(),
native_button_(native_button) {
}
@@ -108,7 +108,7 @@ static const int kCheckboxSize = 13; // pixels
////////////////////////////////////////////////////////////////////////////////
// NativeCheckboxWin, public:
-NativeCheckboxWin::NativeCheckboxWin(Checkbox2* checkbox)
+NativeCheckboxWin::NativeCheckboxWin(Checkbox* checkbox)
: NativeButtonWin(checkbox),
checkbox_(checkbox) {
}
@@ -170,7 +170,7 @@ void NativeCheckboxWin::NativeControlCreated(HWND control_hwnd) {
////////////////////////////////////////////////////////////////////////////////
// NativeRadioButtonWin, public:
-NativeRadioButtonWin::NativeRadioButtonWin(RadioButton2* radio_button)
+NativeRadioButtonWin::NativeRadioButtonWin(RadioButton* radio_button)
: NativeCheckboxWin(radio_button) {
}
@@ -193,20 +193,25 @@ void NativeRadioButtonWin::CreateNativeControl() {
// NativeButtonWrapper, public:
// static
+int NativeButtonWrapper::GetFixedWidth() {
+ return kCheckboxSize;
+}
+
+// static
NativeButtonWrapper* NativeButtonWrapper::CreateNativeButtonWrapper(
- NativeButton2* native_button) {
+ NativeButton* native_button) {
return new NativeButtonWin(native_button);
}
// static
NativeButtonWrapper* NativeButtonWrapper::CreateCheckboxWrapper(
- Checkbox2* checkbox) {
+ Checkbox* checkbox) {
return new NativeCheckboxWin(checkbox);
}
// static
NativeButtonWrapper* NativeButtonWrapper::CreateRadioButtonWrapper(
- RadioButton2* radio_button) {
+ RadioButton* radio_button) {
return new NativeRadioButtonWin(radio_button);
}
diff --git a/chrome/views/controls/button/native_button_win.h b/chrome/views/controls/button/native_button_win.h
index 4b34a20..501ae0d 100644
--- a/chrome/views/controls/button/native_button_win.h
+++ b/chrome/views/controls/button/native_button_win.h
@@ -14,7 +14,7 @@ namespace views {
class NativeButtonWin : public NativeControlWin,
public NativeButtonWrapper {
public:
- explicit NativeButtonWin(NativeButton2* native_button);
+ explicit NativeButtonWin(NativeButton* native_button);
virtual ~NativeButtonWin();
// Overridden from NativeButtonWrapper:
@@ -42,7 +42,7 @@ class NativeButtonWin : public NativeControlWin,
private:
// The NativeButton we are bound to.
- NativeButton2* native_button_;
+ NativeButton* native_button_;
DISALLOW_COPY_AND_ASSIGN(NativeButtonWin);
};
@@ -50,7 +50,7 @@ class NativeButtonWin : public NativeControlWin,
// A View that hosts a native Windows checkbox.
class NativeCheckboxWin : public NativeButtonWin {
public:
- explicit NativeCheckboxWin(Checkbox2* native_button);
+ explicit NativeCheckboxWin(Checkbox* native_button);
virtual ~NativeCheckboxWin();
// Overridden from View:
@@ -72,7 +72,7 @@ class NativeCheckboxWin : public NativeButtonWin {
private:
// The Checkbox we are bound to.
- Checkbox2* checkbox_;
+ Checkbox* checkbox_;
DISALLOW_COPY_AND_ASSIGN(NativeCheckboxWin);
};
@@ -80,7 +80,7 @@ class NativeCheckboxWin : public NativeButtonWin {
// A View that hosts a native Windows radio button.
class NativeRadioButtonWin : public NativeCheckboxWin {
public:
- explicit NativeRadioButtonWin(RadioButton2* radio_button);
+ explicit NativeRadioButtonWin(RadioButton* radio_button);
virtual ~NativeRadioButtonWin();
protected:
diff --git a/chrome/views/controls/button/native_button_wrapper.h b/chrome/views/controls/button/native_button_wrapper.h
index 3d1c932..79cca23 100644
--- a/chrome/views/controls/button/native_button_wrapper.h
+++ b/chrome/views/controls/button/native_button_wrapper.h
@@ -9,9 +9,9 @@ class ChromeFont;
namespace views {
-class Checkbox2;
-class NativeButton2;
-class RadioButton2;
+class Checkbox;
+class NativeButton;
+class RadioButton;
// A specialization of NativeControlWrapper that hosts a platform-native button.
class NativeButtonWrapper {
@@ -38,11 +38,15 @@ class NativeButtonWrapper {
// Retrieves the views::View that hosts the native control.
virtual View* GetView() = 0;
+ // Return the width of the button. Used for fixed size buttons (checkboxes and
+ // radio buttons) only.
+ static int GetFixedWidth();
+
// Creates an appropriate NativeButtonWrapper for the platform.
- static NativeButtonWrapper* CreateNativeButtonWrapper(NativeButton2* button);
- static NativeButtonWrapper* CreateCheckboxWrapper(Checkbox2* checkbox);
+ static NativeButtonWrapper* CreateNativeButtonWrapper(NativeButton* button);
+ static NativeButtonWrapper* CreateCheckboxWrapper(Checkbox* checkbox);
static NativeButtonWrapper* CreateRadioButtonWrapper(
- RadioButton2* radio_button);
+ RadioButton* radio_button);
};
diff --git a/chrome/views/controls/button/radio_button.cc b/chrome/views/controls/button/radio_button.cc
index 0736189..fb09549 100644
--- a/chrome/views/controls/button/radio_button.cc
+++ b/chrome/views/controls/button/radio_button.cc
@@ -1,110 +1,65 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 "chrome/views/controls/button/radio_button.h"
-#include "chrome/views/controls/label.h"
-#include "chrome/views/controls/hwnd_view.h"
#include "chrome/views/widget/root_view.h"
namespace views {
-// FIXME(ACW) there got be a better way to find out the check box sizes
-static int kRadioWidth = 13;
-static int kRadioHeight = 13;
-static int kRadioToLabel = 4;
-
+// static
const char RadioButton::kViewClassName[] = "chrome/views/RadioButton";
-RadioButton::RadioButton(const std::wstring& label, int group_id)
- : CheckBox(label) {
- SetGroup(group_id);
-}
+////////////////////////////////////////////////////////////////////////////////
+// RadioButton, public:
-RadioButton::~RadioButton() {
+RadioButton::RadioButton() : Checkbox() {
}
-HWND RadioButton::CreateNativeControl(HWND parent_container) {
- HWND r = ::CreateWindowEx(GetAdditionalExStyle(),
- L"BUTTON",
- L"",
- WS_CHILD | BS_RADIOBUTTON ,
- 0, 0, width(), height(),
- parent_container, NULL, NULL, NULL);
- ConfigureNativeButton(r);
- return r;
+RadioButton::RadioButton(const std::wstring& label) : Checkbox(label) {
}
-LRESULT RadioButton::OnCommand(UINT code, int id, HWND source) {
- // Radio buttons can't be toggled off once selected except by clicking on
- // another radio button within the same group, so we override this from
- // CheckBox to prevent this from happening.
- if (code == BN_CLICKED) {
- RequestFocus();
- if (!IsSelected()) {
- SetIsSelected(true);
- return NativeButton::OnCommand(code, id, source);
- }
- }
- return 0;
-}
-
-// static
-int RadioButton::GetTextIndent() {
- return kRadioWidth + kRadioToLabel + kFocusPaddingHorizontal;
-}
-
-
-std::string RadioButton::GetClassName() const {
- return kViewClassName;
-}
-
-gfx::Size RadioButton::GetPreferredSize() {
- gfx::Size prefsize = label_->GetPreferredSize();
- prefsize.set_height(std::max(prefsize.height() + kFocusPaddingVertical * 2,
- kRadioHeight));
- prefsize.Enlarge(kRadioToLabel + kRadioWidth + kFocusPaddingHorizontal * 2,
- 0);
- return prefsize;
+RadioButton::RadioButton(const std::wstring& label, int group_id)
+ : Checkbox(label) {
+ SetGroup(group_id);
}
-void RadioButton::Layout() {
- int label_x = GetTextIndent();
- label_->SetBounds(label_x, 0, width() - label_x, height());
- if (hwnd_view_) {
- int first_line_height = label_->GetFont().height();
- hwnd_view_->SetBounds(0, ((first_line_height - kRadioHeight) / 2) + 1,
- kRadioWidth, kRadioHeight);
- hwnd_view_->Layout();
- }
+RadioButton::~RadioButton() {
}
-void RadioButton::SetIsSelected(bool f) {
- if (f != IsSelected()) {
- if (f) {
- // We can't just get the root view here because sometimes the radio
- // button isn't attached to a root view (e.g., if it's part of a tab page
- // that is currently not active).
- View* container = GetParent();
- while (container && container->GetParent())
- container = container->GetParent();
- if (container) {
- std::vector<View*> other;
- container->GetViewsWithGroup(GetGroup(), &other);
- std::vector<View*>::iterator i;
- for (i = other.begin(); i != other.end(); ++i) {
- if (*i != this) {
- RadioButton* peer = static_cast<RadioButton*>(*i);
- peer->SetIsSelected(false);
- }
+////////////////////////////////////////////////////////////////////////////////
+// RadioButton, Checkbox overrides:
+
+void RadioButton::SetChecked(bool checked) {
+ if (checked == RadioButton::checked())
+ return;
+ if (checked) {
+ // We can't just get the root view here because sometimes the radio
+ // button isn't attached to a root view (e.g., if it's part of a tab page
+ // that is currently not active).
+ View* container = GetParent();
+ while (container && container->GetParent())
+ container = container->GetParent();
+ if (container) {
+ std::vector<View*> other;
+ container->GetViewsWithGroup(GetGroup(), &other);
+ std::vector<View*>::iterator i;
+ for (i = other.begin(); i != other.end(); ++i) {
+ if (*i != this) {
+ RadioButton* peer = static_cast<RadioButton*>(*i);
+ peer->SetChecked(false);
}
}
}
- CheckBox::SetIsSelected(f);
}
+ Checkbox::SetChecked(checked);
+
}
+////////////////////////////////////////////////////////////////////////////////
+// RadioButton, View overrides:
+
View* RadioButton::GetSelectedViewForGroup(int group_id) {
std::vector<View*> views;
GetRootView()->GetViewsWithGroup(group_id, &views);
@@ -114,10 +69,29 @@ View* RadioButton::GetSelectedViewForGroup(int group_id) {
for (std::vector<View*>::const_iterator iter = views.begin();
iter != views.end(); ++iter) {
RadioButton* radio_button = static_cast<RadioButton*>(*iter);
- if (radio_button->IsSelected())
+ if (radio_button->checked())
return radio_button;
}
return NULL;
}
+bool RadioButton::IsGroupFocusTraversable() const {
+ // When focusing a radio button with tab/shift+tab, only the selected button
+ // from the group should be focused.
+ return false;
+}
+
+std::string RadioButton::GetClassName() const {
+ return kViewClassName;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+// RadioButton, NativeButton overrides:
+
+void RadioButton::CreateWrapper() {
+ native_wrapper_ = NativeButtonWrapper::CreateRadioButtonWrapper(this);
+ native_wrapper_->UpdateLabel();
+ native_wrapper_->UpdateChecked();
+}
+
} // namespace views
diff --git a/chrome/views/controls/button/radio_button.h b/chrome/views/controls/button/radio_button.h
index dbae232..f1db45b 100644
--- a/chrome/views/controls/button/radio_button.h
+++ b/chrome/views/controls/button/radio_button.h
@@ -1,6 +1,6 @@
-// Copyright (c) 2006-2008 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.
+// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
#define CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
@@ -9,52 +9,34 @@
namespace views {
-////////////////////////////////////////////////////////////////////////////////
-//
-// A wrapper for windows's native radio button. Radio buttons can be mutually
-// exclusive with other radio buttons.
-//
-////////////////////////////////////////////////////////////////////////////////
-class RadioButton : public CheckBox {
+// A Checkbox subclass representing a radio button.
+class RadioButton : public Checkbox {
public:
- // The view class name.
+ // The button's class name.
static const char kViewClassName[];
- // Create a radio button with the provided label and group id.
- // The group id is used to identify all the other radio buttons which are in
- // mutual exclusion with this radio button. Note: RadioButton assumes that
- // all views with that group id are RadioButton. It is an error to give
- // that group id to another view subclass which is not a radio button or
- // a radio button subclass.
+ RadioButton();
+ RadioButton(const std::wstring& label);
RadioButton(const std::wstring& label, int group_id);
virtual ~RadioButton();
- virtual gfx::Size GetPreferredSize();
- virtual void Layout();
-
- virtual std::string GetClassName() const;
-
- // Overridden to properly perform mutual exclusion.
- virtual void SetIsSelected(bool f);
+ // Overridden from Checkbox:
+ virtual void SetChecked(bool checked);
+ // Overridden from View:
virtual View* GetSelectedViewForGroup(int group_id);
-
- // When focusing a RadioButton with Tab/Shift-Tab, only the selected button
- // from the group should be accessible.
- virtual bool IsGroupFocusTraversable() const { return false; }
+ virtual bool IsGroupFocusTraversable() const;
protected:
- virtual HWND CreateNativeControl(HWND parent_container);
- virtual LRESULT OnCommand(UINT code, int id, HWND source);
+ virtual std::string GetClassName() const;
- private:
- // Get the horizontal distance of the start of the text from the left of the
- // control.
- static int GetTextIndent();
+ // Overridden from NativeButton:
+ virtual void CreateWrapper();
- DISALLOW_EVIL_CONSTRUCTORS(RadioButton);
+ private:
+ DISALLOW_COPY_AND_ASSIGN(RadioButton);
};
} // namespace views
-#endif // CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
+#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON_H_
diff --git a/chrome/views/controls/button/radio_button2.cc b/chrome/views/controls/button/radio_button2.cc
deleted file mode 100644
index 72bd927..0000000
--- a/chrome/views/controls/button/radio_button2.cc
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright (c) 2009 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 "chrome/views/controls/button/radio_button2.h"
-
-#include "chrome/views/widget/root_view.h"
-
-namespace views {
-
-// static
-const char RadioButton2::kViewClassName[] = "chrome/views/RadioButton";
-
-////////////////////////////////////////////////////////////////////////////////
-// RadioButton, public:
-
-RadioButton2::RadioButton2() {
-}
-
-RadioButton2::RadioButton2(ButtonListener* listener) : Checkbox2(listener) {
-}
-
-RadioButton2::RadioButton2(ButtonListener* listener, const std::wstring& label)
- : Checkbox2(listener, label) {
-}
-
-RadioButton2::RadioButton2(ButtonListener* listener,
- const std::wstring& label,
- int group_id)
- : Checkbox2(listener, label) {
- SetGroup(group_id);
-}
-
-RadioButton2::~RadioButton2() {
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// RadioButton, Checkbox overrides:
-
-void RadioButton2::SetChecked(bool checked) {
- if (checked == RadioButton2::checked())
- return;
- if (checked) {
- // We can't just get the root view here because sometimes the radio
- // button isn't attached to a root view (e.g., if it's part of a tab page
- // that is currently not active).
- View* container = GetParent();
- while (container && container->GetParent())
- container = container->GetParent();
- if (container) {
- std::vector<View*> other;
- container->GetViewsWithGroup(GetGroup(), &other);
- std::vector<View*>::iterator i;
- for (i = other.begin(); i != other.end(); ++i) {
- if (*i != this) {
- RadioButton2* peer = static_cast<RadioButton2*>(*i);
- peer->SetChecked(false);
- }
- }
- }
- }
- Checkbox2::SetChecked(checked);
-
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// RadioButton, View overrides:
-
-View* RadioButton2::GetSelectedViewForGroup(int group_id) {
- std::vector<View*> views;
- GetRootView()->GetViewsWithGroup(group_id, &views);
- if (views.empty())
- return NULL;
-
- for (std::vector<View*>::const_iterator iter = views.begin();
- iter != views.end(); ++iter) {
- RadioButton2* radio_button = static_cast<RadioButton2*>(*iter);
- if (radio_button->checked())
- return radio_button;
- }
- return NULL;
-}
-
-bool RadioButton2::IsGroupFocusTraversable() const {
- // When focusing a radio button with tab/shift+tab, only the selected button
- // from the group should be focused.
- return false;
-}
-
-std::string RadioButton2::GetClassName() const {
- return kViewClassName;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// RadioButton, NativeButton overrides:
-
-void RadioButton2::CreateWrapper() {
- native_wrapper_ = NativeButtonWrapper::CreateRadioButtonWrapper(this);
- native_wrapper_->UpdateLabel();
- native_wrapper_->UpdateChecked();
-}
-
-} // namespace views
diff --git a/chrome/views/controls/button/radio_button2.h b/chrome/views/controls/button/radio_button2.h
deleted file mode 100644
index ce198d1..0000000
--- a/chrome/views/controls/button/radio_button2.h
+++ /dev/null
@@ -1,45 +0,0 @@
-// Copyright (c) 2009 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 CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON2_H_
-#define CHROME_VIEWS_CONTROLS_BUTTON_RADIO_BUTTON2_H_
-
-#include "chrome/views/controls/button/checkbox2.h"
-
-namespace views {
-
-// A Checkbox subclass representing a radio button.
-class RadioButton2 : public Checkbox2 {
- public:
- // The button's class name.
- static const char kViewClassName[];
-
- RadioButton2();
- explicit RadioButton2(ButtonListener* listener);
- RadioButton2(ButtonListener* listener, const std::wstring& label);
- RadioButton2(ButtonListener* listener,
- const std::wstring& label,
- int group_id);
- virtual ~RadioButton2();
-
- // Overridden from Checkbox:
- virtual void SetChecked(bool checked);
-
- // Overridden from View:
- virtual View* GetSelectedViewForGroup(int group_id);
- virtual bool IsGroupFocusTraversable() const;
-
- protected:
- virtual std::string GetClassName() const;
-
- // Overridden from NativeButton2:
- virtual void CreateWrapper();
-
- private:
- DISALLOW_COPY_AND_ASSIGN(RadioButton2);
-};
-
-} // namespace views
-
-#endif // #ifndef CHROME_VIEWS_CONTROLS_BUTTON_CHECKBOX2_H_
diff --git a/chrome/views/controls/message_box_view.cc b/chrome/views/controls/message_box_view.cc
index b1219f6..6a57480 100644
--- a/chrome/views/controls/message_box_view.cc
+++ b/chrome/views/controls/message_box_view.cc
@@ -24,7 +24,7 @@ MessageBoxView::MessageBoxView(int dialog_flags,
: message_label_(new views::Label(message)),
prompt_field_(NULL),
icon_(NULL),
- check_box_(NULL),
+ checkbox_(NULL),
message_width_(message_width),
focus_grabber_factory_(this) {
Init(dialog_flags, default_prompt);
@@ -36,7 +36,7 @@ MessageBoxView::MessageBoxView(int dialog_flags,
: message_label_(new views::Label(message)),
prompt_field_(NULL),
icon_(NULL),
- check_box_(NULL),
+ checkbox_(NULL),
message_width_(kDefaultMessageWidth),
focus_grabber_factory_(this) {
Init(dialog_flags, default_prompt);
@@ -49,9 +49,7 @@ std::wstring MessageBoxView::GetInputText() {
}
bool MessageBoxView::IsCheckBoxSelected() {
- if (check_box_ == NULL)
- return false;
- return check_box_->IsSelected();
+ return checkbox_ ? checkbox_->checked() : false;
}
void MessageBoxView::SetIcon(const SkBitmap& icon) {
@@ -63,17 +61,17 @@ void MessageBoxView::SetIcon(const SkBitmap& icon) {
}
void MessageBoxView::SetCheckBoxLabel(const std::wstring& label) {
- if (!check_box_)
- check_box_ = new views::CheckBox(label);
+ if (!checkbox_)
+ checkbox_ = new views::Checkbox(label);
else
- check_box_->SetLabel(label);
+ checkbox_->SetLabel(label);
ResetLayoutManager();
}
void MessageBoxView::SetCheckBoxSelected(bool selected) {
- if (!check_box_)
+ if (!checkbox_)
return;
- check_box_->SetIsSelected(selected);
+ checkbox_->SetChecked(selected);
}
///////////////////////////////////////////////////////////////////////////////
@@ -160,7 +158,7 @@ void MessageBoxView::ResetLayoutManager() {
// Column set for checkbox, if one has been set.
const int checkbox_column_view_set_id = 2;
- if (check_box_) {
+ if (checkbox_) {
column_set = layout->AddColumnSet(checkbox_column_view_set_id);
if (icon_) {
column_set->AddPaddingColumn(0,
@@ -182,10 +180,10 @@ void MessageBoxView::ResetLayoutManager() {
layout->AddView(prompt_field_);
}
- if (check_box_) {
+ if (checkbox_) {
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
layout->StartRow(0, checkbox_column_view_set_id);
- layout->AddView(check_box_);
+ layout->AddView(checkbox_);
}
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
diff --git a/chrome/views/controls/message_box_view.h b/chrome/views/controls/message_box_view.h
index 2a8e18f..43589a9 100644
--- a/chrome/views/controls/message_box_view.h
+++ b/chrome/views/controls/message_box_view.h
@@ -8,12 +8,15 @@
#include <string>
#include "base/task.h"
-#include "chrome/views/controls/button/checkbox.h"
#include "chrome/views/controls/image_view.h"
#include "chrome/views/controls/label.h"
#include "chrome/views/controls/text_field.h"
#include "chrome/views/view.h"
+namespace views {
+class Checkbox;
+}
+
// This class displays the contents of a message box. It is intended for use
// within a constrained window, and has options for a message, prompt, OK
// and Cancel buttons.
@@ -106,7 +109,7 @@ class MessageBoxView : public views::View {
views::ImageView* icon_;
// Checkbox for the message box.
- views::CheckBox* check_box_;
+ views::Checkbox* checkbox_;
// Maximum width of the message label.
int message_width_;
diff --git a/chrome/views/controls/native_control_win.cc b/chrome/views/controls/native_control_win.cc
index 4e4f2f7..e8574f0 100644
--- a/chrome/views/controls/native_control_win.cc
+++ b/chrome/views/controls/native_control_win.cc
@@ -60,6 +60,9 @@ void NativeControlWin::ViewHierarchyChanged(bool is_add, View* parent,
// parent HWND to function properly.
if (is_add && GetWidget() && !GetHWND())
CreateNativeControl();
+
+ // Call the base class to hide the view if we're being removed.
+ HWNDView::ViewHierarchyChanged(is_add, parent, child);
}
void NativeControlWin::VisibilityChanged(View* starting_from, bool is_visible) {
diff --git a/chrome/views/focus/focus_manager_unittest.cc b/chrome/views/focus/focus_manager_unittest.cc
index 5a78f32..1246de7 100644
--- a/chrome/views/focus/focus_manager_unittest.cc
+++ b/chrome/views/focus/focus_manager_unittest.cc
@@ -242,8 +242,8 @@ void TestViewWindow::Init() {
WidgetWin::Init(NULL, bounds, true);
SetContentsView(contents_);
- views::CheckBox* cb =
- new views::CheckBox(L"This is a checkbox");
+ views::Checkbox* cb =
+ new views::Checkbox(L"This is a checkbox");
contents_->AddChildView(cb);
// In this fast paced world, who really has time for non hard-coded layout?
cb->SetBounds(10, 10, 200, 20);
@@ -317,14 +317,13 @@ void TestViewWindow::Init() {
y += label_height + gap_between_labels;
- views::NativeButton* button =
- new views::NativeButton(L"Click me");
+ views::NativeButton* button = new views::NativeButton(NULL, L"Click me");
button->SetBounds(label_x, y + 10, 50, 20);
button->SetID(kFruitButtonID);
left_container->AddChildView(button);
y += 40;
- cb = new views::CheckBox(L"This is another check box");
+ cb = new views::Checkbox(L"This is another check box");
cb->SetBounds(label_x + label_width + 5, y, 100, 20);
cb->SetID(kFruitCheckBoxID);
left_container->AddChildView(cb);
@@ -409,18 +408,18 @@ void TestViewWindow::Init() {
y = 250;
int width = 50;
- button = new views::NativeButton(L"OK");
+ button = new views::NativeButton(NULL, L"OK");
button->SetID(kOKButtonID);
contents_->AddChildView(button);
button->SetBounds(150, y, width, 20);
- button = new views::NativeButton(L"Cancel");
+ button = new views::NativeButton(NULL, L"Cancel");
button->SetID(kCancelButtonID);
contents_->AddChildView(button);
button->SetBounds(250, y, width, 20);
- button = new views::NativeButton(L"Help");
+ button = new views::NativeButton(NULL, L"Help");
button->SetID(kHelpButtonID);
contents_->AddChildView(button);
button->SetBounds(350, y, width, 20);
@@ -431,17 +430,17 @@ void TestViewWindow::Init() {
views::View* contents = new views::View();
contents->set_background(
views::Background::CreateSolidBackground(SK_ColorWHITE));
- cb = new views::CheckBox(L"Bold");
+ cb = new views::Checkbox(L"Bold");
contents->AddChildView(cb);
cb->SetBounds(10, 10, 50, 20);
cb->SetID(kBoldCheckBoxID);
- cb = new views::CheckBox(L"Italic");
+ cb = new views::Checkbox(L"Italic");
contents->AddChildView(cb);
cb->SetBounds(70, 10, 50, 20);
cb->SetID(kItalicCheckBoxID);
- cb = new views::CheckBox(L"Underlined");
+ cb = new views::Checkbox(L"Underlined");
contents->AddChildView(cb);
cb->SetBounds(130, 10, 70, 20);
cb->SetID(kUnderlinedCheckBoxID);
@@ -462,7 +461,7 @@ void TestViewWindow::Init() {
text_field->SetBounds(10, 10, 100, 20);
text_field->SetID(kSearchTextFieldID);
- button = new views::NativeButton(L"Search");
+ button = new views::NativeButton(NULL, L"Search");
contents->AddChildView(button);
button->SetBounds(115, 10, 50, 20);
button->SetID(kSearchButtonID);
@@ -486,11 +485,11 @@ void TestViewWindow::Init() {
contents->set_background(
views::Background::CreateSolidBackground(SK_ColorBLUE));
contents->SetID(kThumbnailContainerID);
- button = new views::NativeButton(L"Star");
+ button = new views::NativeButton(NULL, L"Star");
contents->AddChildView(button);
button->SetBounds(5, 5, 50, 20);
button->SetID(kThumbnailStarID);
- button = new views::NativeButton(L"SuperStar");
+ button = new views::NativeButton(NULL, L"SuperStar");
contents->AddChildView(button);
button->SetBounds(60, 5, 100, 20);
button->SetID(kThumbnailSuperStarID);
diff --git a/chrome/views/view_unittest.cc b/chrome/views/view_unittest.cc
index 36895fc..eee1f24 100644
--- a/chrome/views/view_unittest.cc
+++ b/chrome/views/view_unittest.cc
@@ -606,9 +606,9 @@ class TestDialogView : public views::View,
virtual View* GetContentsView() {
views::View* container = new views::View();
- button1_ = new views::NativeButton(L"Button1");
- button2_ = new views::NativeButton(L"Button2");
- checkbox_ = new views::CheckBox(L"My checkbox");
+ button1_ = new views::NativeButton(NULL, L"Button1");
+ button2_ = new views::NativeButton(NULL, L"Button2");
+ checkbox_ = new views::Checkbox(L"My checkbox");
container->AddChildView(button1_);
container->AddChildView(button2_);
container->AddChildView(checkbox_);
@@ -629,35 +629,35 @@ TEST_F(ViewTest, DialogDefaultButtonTest) {
views::NativeButton* ok_button = client_view->ok_button();
views::NativeButton* cancel_button = client_view->cancel_button();
- EXPECT_TRUE(ok_button->IsDefaultButton());
+ EXPECT_TRUE(ok_button->is_default());
// Simualte focusing another button, it should become the default button.
client_view->FocusWillChange(ok_button, dialog_view_->button1_);
- EXPECT_FALSE(ok_button->IsDefaultButton());
- EXPECT_TRUE(dialog_view_->button1_->IsDefaultButton());
+ EXPECT_FALSE(ok_button->is_default());
+ EXPECT_TRUE(dialog_view_->button1_->is_default());
// Now select something that is not a button, the OK should become the default
// button again.
client_view->FocusWillChange(dialog_view_->button1_, dialog_view_->checkbox_);
- EXPECT_TRUE(ok_button->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton());
+ EXPECT_TRUE(ok_button->is_default());
+ EXPECT_FALSE(dialog_view_->button1_->is_default());
// Select yet another button.
client_view->FocusWillChange(dialog_view_->checkbox_, dialog_view_->button2_);
- EXPECT_FALSE(ok_button->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton());
- EXPECT_TRUE(dialog_view_->button2_->IsDefaultButton());
+ EXPECT_FALSE(ok_button->is_default());
+ EXPECT_FALSE(dialog_view_->button1_->is_default());
+ EXPECT_TRUE(dialog_view_->button2_->is_default());
// Focus nothing.
client_view->FocusWillChange(dialog_view_->button2_, NULL);
- EXPECT_TRUE(ok_button->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button2_->IsDefaultButton());
+ EXPECT_TRUE(ok_button->is_default());
+ EXPECT_FALSE(dialog_view_->button1_->is_default());
+ EXPECT_FALSE(dialog_view_->button2_->is_default());
// Focus the cancel button.
client_view->FocusWillChange(NULL, cancel_button);
- EXPECT_FALSE(ok_button->IsDefaultButton());
- EXPECT_TRUE(cancel_button->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button1_->IsDefaultButton());
- EXPECT_FALSE(dialog_view_->button2_->IsDefaultButton());
+ EXPECT_FALSE(ok_button->is_default());
+ EXPECT_TRUE(cancel_button->is_default());
+ EXPECT_FALSE(dialog_view_->button1_->is_default());
+ EXPECT_FALSE(dialog_view_->button2_->is_default());
}
diff --git a/chrome/views/views.vcproj b/chrome/views/views.vcproj
index 01e5770..29cf7bd 100644
--- a/chrome/views/views.vcproj
+++ b/chrome/views/views.vcproj
@@ -582,14 +582,6 @@
>
</File>
<File
- RelativePath=".\controls\button\checkbox2.cc"
- >
- </File>
- <File
- RelativePath=".\controls\button\checkbox2.h"
- >
- </File>
- <File
RelativePath=".\controls\button\custom_button.cc"
>
</File>
@@ -622,14 +614,6 @@
>
</File>
<File
- RelativePath=".\controls\button\native_button2.cc"
- >
- </File>
- <File
- RelativePath=".\controls\button\native_button2.h"
- >
- </File>
- <File
RelativePath=".\controls\button\native_button_win.cc"
>
</File>
@@ -650,14 +634,6 @@
>
</File>
<File
- RelativePath=".\controls\button\radio_button2.cc"
- >
- </File>
- <File
- RelativePath=".\controls\button\radio_button2.h"
- >
- </File>
- <File
RelativePath=".\controls\button\text_button.cc"
>
</File>
diff --git a/chrome/views/window/dialog_client_view.cc b/chrome/views/window/dialog_client_view.cc
index dbc3b179..100a409 100644
--- a/chrome/views/window/dialog_client_view.cc
+++ b/chrome/views/window/dialog_client_view.cc
@@ -15,6 +15,7 @@
#include "chrome/common/l10n_util.h"
#include "chrome/common/resource_bundle.h"
#include "chrome/common/win_util.h"
+#include "chrome/views/controls/button/native_button.h"
#include "chrome/views/window/dialog_delegate.h"
#include "chrome/views/window/window.h"
#include "grit/generated_resources.h"
@@ -47,11 +48,15 @@ void FillViewWithSysColor(ChromeCanvas* canvas, View* view, COLORREF color) {
class DialogButton : public NativeButton {
public:
- DialogButton(Window* owner,
+ DialogButton(ButtonListener* listener,
+ Window* owner,
DialogDelegate::DialogButton type,
const std::wstring& title,
bool is_default)
- : NativeButton(title, is_default), owner_(owner), type_(type) {
+ : NativeButton(listener, title),
+ owner_(owner),
+ type_(type) {
+ SetIsDefault(is_default);
}
// Overridden to forward to the delegate.
@@ -108,9 +113,9 @@ void DialogClientView::ShowDialogButtons() {
label = l10n_util::GetString(IDS_OK);
bool is_default_button =
(dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_OK) != 0;
- ok_button_ = new DialogButton(window(), DialogDelegate::DIALOGBUTTON_OK,
- label, is_default_button);
- ok_button_->SetListener(this);
+ ok_button_ = new DialogButton(this, window(),
+ DialogDelegate::DIALOGBUTTON_OK, label,
+ is_default_button);
ok_button_->SetGroup(kButtonGroup);
if (is_default_button)
default_button_ = ok_button_;
@@ -131,10 +136,9 @@ void DialogClientView::ShowDialogButtons() {
bool is_default_button =
(dd->GetDefaultDialogButton() & DialogDelegate::DIALOGBUTTON_CANCEL)
!= 0;
- cancel_button_ = new DialogButton(window(),
+ cancel_button_ = new DialogButton(this, window(),
DialogDelegate::DIALOGBUTTON_CANCEL,
label, is_default_button);
- cancel_button_->SetListener(this);
cancel_button_->SetGroup(kButtonGroup);
cancel_button_->AddAccelerator(Accelerator(VK_ESCAPE, false, false, false));
if (is_default_button)
@@ -150,13 +154,13 @@ void DialogClientView::ShowDialogButtons() {
void DialogClientView::SetDefaultButton(NativeButton* new_default_button) {
if (default_button_ && default_button_ != new_default_button) {
- default_button_->SetDefaultButton(false);
+ default_button_->SetIsDefault(false);
default_button_ = NULL;
}
if (new_default_button) {
default_button_ = new_default_button;
- default_button_->SetDefaultButton(true);
+ default_button_->SetIsDefault(true);
}
}
@@ -306,9 +310,9 @@ bool DialogClientView::AcceleratorPressed(const Accelerator& accelerator) {
}
////////////////////////////////////////////////////////////////////////////////
-// DialogClientView, NativeButton::Listener implementation:
+// DialogClientView, ButtonListener implementation:
-void DialogClientView::ButtonPressed(NativeButton* sender) {
+void DialogClientView::ButtonPressed(Button* sender) {
if (sender == ok_button_) {
AcceptWindow();
} else if (sender == cancel_button_) {
diff --git a/chrome/views/window/dialog_client_view.h b/chrome/views/window/dialog_client_view.h
index 5f1417c..bfea8e0 100644
--- a/chrome/views/window/dialog_client_view.h
+++ b/chrome/views/window/dialog_client_view.h
@@ -7,12 +7,13 @@
#include "chrome/common/gfx/chrome_font.h"
#include "chrome/views/focus/focus_manager.h"
-#include "chrome/views/controls/button/native_button.h"
+#include "chrome/views/controls/button/button.h"
#include "chrome/views/window/client_view.h"
namespace views {
class DialogDelegate;
+class NativeButton;
class Window;
///////////////////////////////////////////////////////////////////////////////
@@ -25,7 +26,7 @@ class Window;
// buttons.
//
class DialogClientView : public ClientView,
- public NativeButton::Listener,
+ public ButtonListener,
public FocusChangeListener {
public:
DialogClientView(Window* window, View* contents_view);
@@ -67,8 +68,8 @@ class DialogClientView : public ClientView,
virtual gfx::Size GetPreferredSize();
virtual bool AcceleratorPressed(const Accelerator& accelerator);
- // NativeButton::Listener implementation:
- virtual void ButtonPressed(NativeButton* sender);
+ // ButtonListener implementation:
+ virtual void ButtonPressed(Button* sender);
private:
// Paint the size box in the bottom right corner of the window if it is
@@ -114,7 +115,7 @@ class DialogClientView : public ClientView,
static void InitClass();
static ChromeFont dialog_button_font_;
- DISALLOW_EVIL_CONSTRUCTORS(DialogClientView);
+ DISALLOW_COPY_AND_ASSIGN(DialogClientView);
};
} // namespace views
diff --git a/chrome/views/window/dialog_delegate.cc b/chrome/views/window/dialog_delegate.cc
index 8a1c671..9778066 100644
--- a/chrome/views/window/dialog_delegate.cc
+++ b/chrome/views/window/dialog_delegate.cc
@@ -5,6 +5,7 @@
#include "chrome/views/window/dialog_delegate.h"
#include "base/logging.h"
+#include "chrome/views/controls/button/native_button.h"
#include "chrome/views/window/window.h"
namespace views {