diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 04:19:35 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-05 04:19:35 +0000 |
commit | 1966d6d1568191bb984efd30f20d884553e35450 (patch) | |
tree | cac5a77663b4c5a976970be83ad9dff926ed4599 /ui/message_center/views/notifier_settings_view.cc | |
parent | fc18b9eacd5657f6ebc3b5f9e6a72ddcf751896e (diff) | |
download | chromium_src-1966d6d1568191bb984efd30f20d884553e35450.zip chromium_src-1966d6d1568191bb984efd30f20d884553e35450.tar.gz chromium_src-1966d6d1568191bb984efd30f20d884553e35450.tar.bz2 |
Removes FocusBorder from views
This patch removes FocusBorder from View along with
View::OnPaintFocusBorder. Views that want to render focus and that
need to allow overriding get a Painter that is responsible for
rendering the focus. Views that render focus differently must override
OnFocus/OnBlur to SchedulePaint the necessary region.
This patch simplifies View and cleans things up for views that don't
ever want to paint focus, or paint focus differently (say TableView,
or Textfield). On the down side it does mean any view that is
focusable needs to override a few more additional methods. It was easy
to get this wrong previously though as a common pattern is to
override OnPaint and not invoke View::OnPaint.
BUG=none
TEST=none
R=ben@chromium.org
Review URL: https://codereview.chromium.org/105013002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@238888 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/message_center/views/notifier_settings_view.cc')
-rw-r--r-- | ui/message_center/views/notifier_settings_view.cc | 35 |
1 files changed, 26 insertions, 9 deletions
diff --git a/ui/message_center/views/notifier_settings_view.cc b/ui/message_center/views/notifier_settings_view.cc index 7446b0d..399283b 100644 --- a/ui/message_center/views/notifier_settings_view.cc +++ b/ui/message_center/views/notifier_settings_view.cc @@ -38,6 +38,7 @@ #include "ui/views/layout/box_layout.h" #include "ui/views/layout/fill_layout.h" #include "ui/views/layout/grid_layout.h" +#include "ui/views/painter.h" #include "ui/views/widget/widget.h" #if defined(USE_AURA) @@ -124,9 +125,9 @@ const int kComputedTitleElementSpacing = settings::kDescriptionToSwitcherSpace - kButtonPainterInsets - 1; // A function to create a focus border. -views::FocusBorder* CreateFocusBorder() { - return views::FocusBorder::CreateSolidFocusBorder(kFocusBorderColor, - gfx::Insets(1, 2, 3, 2)); +scoped_ptr<views::Painter> CreateFocusPainter() { + return views::Painter::CreateSolidFocusPainter(kFocusBorderColor, + gfx::Insets(1, 2, 3, 2)); } // EntryView ------------------------------------------------------------------ @@ -135,7 +136,7 @@ views::FocusBorder* CreateFocusBorder() { // middle. It also guarantee the left margin. class EntryView : public views::View { public: - EntryView(views::View* contents); + explicit EntryView(views::View* contents); virtual ~EntryView(); // views::View: @@ -145,13 +146,17 @@ class EntryView : public views::View { virtual void OnFocus() OVERRIDE; virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE; virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE; + virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; + virtual void OnBlur() OVERRIDE; private: + scoped_ptr<views::Painter> focus_painter_; + DISALLOW_COPY_AND_ASSIGN(EntryView); }; -EntryView::EntryView(views::View* contents) { - set_focus_border(CreateFocusBorder()); +EntryView::EntryView(views::View* contents) + : focus_painter_(CreateFocusPainter()) { AddChildView(contents); } @@ -181,6 +186,8 @@ void EntryView::GetAccessibleState(ui::AccessibleViewState* state) { void EntryView::OnFocus() { views::View::OnFocus(); ScrollRectToVisible(GetLocalBounds()); + // We render differently when focused. + SchedulePaint(); } bool EntryView::OnKeyPressed(const ui::KeyEvent& event) { @@ -191,6 +198,17 @@ bool EntryView::OnKeyReleased(const ui::KeyEvent& event) { return child_at(0)->OnKeyReleased(event); } +void EntryView::OnPaint(gfx::Canvas* canvas) { + View::OnPaint(canvas); + views::Painter::PaintFocusPainter(this, canvas, focus_painter_.get()); +} + +void EntryView::OnBlur() { + View::OnBlur(); + // We render differently when focused. + SchedulePaint(); +} + } // namespace @@ -294,7 +312,7 @@ NotifierSettingsView::NotifierButton::NotifierButton( if (ShouldHaveLearnMoreButton()) { // Create a more-info button that will be right-aligned. learn_more_ = new views::ImageButton(this); - learn_more_->set_focus_border(CreateFocusBorder()); + learn_more_->SetFocusPainter(CreateFocusPainter()); learn_more_->set_request_focus_on_press(false); learn_more_->set_focusable(true); @@ -466,7 +484,6 @@ NotifierSettingsView::NotifierSettingsView(NotifierSettingsProvider* provider) provider_->AddObserver(this); set_focusable(true); - set_focus_border(NULL); set_background( views::Background::CreateSolidBackground(kMessageCenterBackgroundColor)); if (get_use_acceleration_when_possible()) @@ -582,7 +599,7 @@ void NotifierSettingsView::UpdateContentsView( kMenuButtonVerticalPadding, kMenuButtonLeftPadding, kMenuButtonVerticalPadding, kMenuButtonRightPadding)); notifier_group_selector_->set_border(selector_border.release()); - notifier_group_selector_->set_focus_border(NULL); + notifier_group_selector_->SetFocusPainter(scoped_ptr<views::Painter>()); notifier_group_selector_->set_animate_on_state_change(false); notifier_group_selector_->set_focusable(true); contents_title_view->AddChildView(notifier_group_selector_); |