diff options
author | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 23:02:15 +0000 |
---|---|---|
committer | ben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-22 23:02:15 +0000 |
commit | a37bea8f194682046c02a681ccc743e5c6bd2098 (patch) | |
tree | ebf8b10609d3abe48e5876d4e9afc1d2c17d5bc7 /chrome/views/controls/button/checkbox.cc | |
parent | 528ad8be61f87ef874a3da9be49c2d73575b7e33 (diff) | |
download | chromium_src-a37bea8f194682046c02a681ccc743e5c6bd2098.zip chromium_src-a37bea8f194682046c02a681ccc743e5c6bd2098.tar.gz chromium_src-a37bea8f194682046c02a681ccc743e5c6bd2098.tar.bz2 |
Fix focus rects for checkboxes and radio buttons:
- add concept of default insets to view which get added to any other insets provided by the user. used by label to provide room for a focus border.
- provide the ability for the label to paint its focus border even if it isn't focused. needed because the outer container (the checkbox) gets focus but the inner label does not, however the label knows best the location of its text around which the focus border must be drawn.
please note:
- also make it easier to click checkboxes by not resetting mouse_pressed_handler_ in RootView when a view decides it doesn't want to handle a drag. this is so we can still receive mousereleased notifications when the mouse is released... it's "difficult" to click checkboxes and radio buttons when you accidentally drag a little on their label. (this is the root view change).
- fix slight alignment issue on the general page of options.
Also fix a slight error in my last radio checkbox - clicking on a checked radio button should still focus it.
http://crbug.com/10834
TEST=visit options, Minor Tweaks. click the "always ask before downloading" checkbox and observe that the focus rect tightly surrounds the text label instead of stretching to the right side of the dialog.
Visit options, click an already-checked radio button. observe that it takes focus.
Visit options, click on any checkbox or radio button, drag slightly then release (still within the bounds of the item). note the item is now toggled or selected. click down then drag out and release, note that it is not toggled or selected.
Review URL: http://codereview.chromium.org/92004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@14265 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views/controls/button/checkbox.cc')
-rw-r--r-- | chrome/views/controls/button/checkbox.cc | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/chrome/views/controls/button/checkbox.cc b/chrome/views/controls/button/checkbox.cc index ae523ed..ae023ce 100644 --- a/chrome/views/controls/button/checkbox.cc +++ b/chrome/views/controls/button/checkbox.cc @@ -82,17 +82,8 @@ void Checkbox::Layout() { 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::PaintFocusBorder(ChromeCanvas* canvas) { + // Our focus border is rendered by the label, so we don't do anything here. } View* Checkbox::GetViewForPoint(const gfx::Point& point) { @@ -129,6 +120,18 @@ void Checkbox::OnMouseReleased(const MouseEvent& e, bool canceled) { } } +bool Checkbox::OnMouseDragged(const MouseEvent& e) { + return false; +} + +void Checkbox::WillGainFocus() { + label_->set_paint_as_focused(true); +} + +void Checkbox::WillLoseFocus() { + label_->set_paint_as_focused(false); +} + std::string Checkbox::GetClassName() const { return kViewClassName; } @@ -147,6 +150,15 @@ void Checkbox::InitBorder() { } //////////////////////////////////////////////////////////////////////////////// +// Checkbox, protected: + +bool Checkbox::HitTestLabel(const MouseEvent& e) { + gfx::Point tmp(e.location()); + ConvertPointToView(this, label_, &tmp); + return label_->HitTest(tmp); +} + +//////////////////////////////////////////////////////////////////////////////// // Checkbox, private: void Checkbox::Init(const std::wstring& label_text) { @@ -156,10 +168,4 @@ void Checkbox::Init(const std::wstring& label_text) { AddChildView(label_); } -bool Checkbox::HitTestLabel(const MouseEvent& e) { - gfx::Point tmp(e.location()); - ConvertPointToView(this, label_, &tmp); - return label_->HitTest(tmp); -} - } // namespace views |