Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(633)

Issue 1216673005: views::LabelButton should not call virtual methods from its constructor (Closed)

Created:
5 years, 5 months ago by tapted
Modified:
5 years, 5 months ago
Reviewers:
sadrul
CC:
chromium-reviews, tfarina, alicet1, msw+watch_chromium.org, dcheng, chrome-apps-syd-reviews_chromium.org
Base URL:
https://chromium.googlesource.com/chromium/src.git@20150703-Views-ButtonBorderRefactor
Target Ref:
refs/pending/heads/master
Project:
chromium
Visibility:
Public.

Description

views::LabelButton should not call virtual methods from its constructor LabelButton::SetText() and LabelButton::CreateDefaultBorder() are both virtual, and both called from the LabelButton constructor (the latter via SetStyle()). This is typically frowned upon. It also means Button types that override CreateDefaultBorder do not get their override called when the LabelButton constructor calls SetStyle(): These overrides currently only "work" because when the view hierarchy is first added to the Widget, PropagateNativeThemeChanged() is triggered which re-initializes the border (typically for a third time). This setup also results in some sub-optimal initialization paths: - SetStyle(..), when used, is called just after construction, or from a subclass constructor. It overrides the SetStyle call done in the LabelButton constructor which is now wasted work. The wasted work includes creating a LabelButtonBorder with 18 ImageSkias in it, fetched from the ResourceBundle. - For buttons with custom borders (or a null border), the SetStyle(..) call first creates a themed border which is then destroyed with a SetBorder call. In these cases, there's no way for a subclass to prevent the behavior because an overide of CreateDefaultBorder can't be called via the LabelButton constructor. To fix, add InitAs...() methods, which replace LabelButton::SetStyle(). The style was always part of the initialization (i.e. client code that changes the default style all calls SetStyle() just after construction). However, currently the only way to alter the style is to first initialize with the default style, then replace it. Client code that currently calls SetStyle(STYLE_BUTTON) now just calls InitAsButton(label). Client code that used the default style (STYLE_TEXTBUTTON) now needs to calls InitAsTextbutton(label). By calling SetBorder() before Init(), a LabelButton can now skip generating themed borders altogether. This CL is Part 1 of N, which migrates code compiled along with `views_unittests`. Adds overloads so that `chrome` and other targets can be addressed in follow-ups (and the overloads removed). BUG=506729

Patch Set 1 #

Patch Set 2 : Progress... #

Patch Set 3 : Leave checkbox, radiobutton busted - maybe do the same to MenuButton #

Patch Set 4 : Chrome builds \o/. But. This is too huge. #

Patch Set 5 : Fixes the `chrome` target after rolling back some checkbox stuff #

Patch Set 6 : Pare back just to views_unittests deps #

Patch Set 7 : Add overloads, public, TODO #

Patch Set 8 : selfnits #

Total comments: 8

Patch Set 9 : InitAsTextbutton #

Patch Set 10 : self review #

Unified diffs Side-by-side diffs Delta from patch set Stats (+126 lines, -81 lines) Patch
M ui/views/accessible_pane_view_unittest.cc View 1 2 3 4 5 6 7 8 2 chunks +13 lines, -8 lines 0 comments Download
M ui/views/bubble/bubble_frame_view.cc View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -2 lines 0 comments Download
M ui/views/button_drag_utils.cc View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -3 lines 0 comments Download
M ui/views/controls/button/blue_button.h View 1 2 3 4 5 6 7 8 9 1 chunk +5 lines, -2 lines 0 comments Download
M ui/views/controls/button/blue_button.cc View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -4 lines 0 comments Download
M ui/views/controls/button/blue_button_unittest.cc View 1 2 3 4 5 6 7 8 1 chunk +3 lines, -17 lines 0 comments Download
M ui/views/controls/button/checkbox.cc View 1 2 3 4 5 6 7 8 1 chunk +8 lines, -3 lines 0 comments Download
M ui/views/controls/button/custom_button_unittest.cc View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -1 line 0 comments Download
M ui/views/controls/button/label_button.h View 1 2 3 4 5 6 7 8 9 3 chunks +21 lines, -1 line 0 comments Download
M ui/views/controls/button/label_button.cc View 1 2 3 4 5 6 7 8 4 chunks +18 lines, -7 lines 0 comments Download
M ui/views/controls/button/label_button_unittest.cc View 1 2 3 4 5 6 7 8 7 chunks +15 lines, -7 lines 0 comments Download
M ui/views/controls/button/menu_button.cc View 1 2 3 4 5 6 7 8 1 chunk +8 lines, -3 lines 0 comments Download
M ui/views/focus/focus_manager_unittest.cc View 1 2 3 4 1 chunk +2 lines, -3 lines 0 comments Download
M ui/views/focus/focus_traversal_unittest.cc View 1 2 3 4 4 chunks +15 lines, -15 lines 0 comments Download
M ui/views/touchui/touch_selection_menu_runner_views.cc View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -1 line 0 comments Download
M ui/views/window/dialog_client_view.cc View 1 2 3 4 5 6 7 8 1 chunk +2 lines, -2 lines 0 comments Download
M ui/views/window/dialog_delegate_unittest.cc View 1 2 3 4 5 6 7 8 2 chunks +4 lines, -2 lines 0 comments Download

Depends on Patchset:

Messages

Total messages: 8 (1 generated)
tapted
Hi sadrul, please take a look. (I'm working on themed buttons for Mac. While tracing, ...
5 years, 5 months ago (2015-07-07 00:10:09 UTC) #2
tapted
(oh, and patchset 5 has a preview of how the `chrome` target would be fixed, ...
5 years, 5 months ago (2015-07-07 00:12:29 UTC) #3
sadrul
https://codereview.chromium.org/1216673005/diff/140001/ui/views/bubble/bubble_frame_view.cc File ui/views/bubble/bubble_frame_view.cc (left): https://codereview.chromium.org/1216673005/diff/140001/ui/views/bubble/bubble_frame_view.cc#oldcode107 ui/views/bubble/bubble_frame_view.cc:107: close->SetBorder(nullptr); What happens if this call to SetBorder() happens ...
5 years, 5 months ago (2015-07-08 05:59:11 UTC) #4
tapted
(no new code yet - just a question wrt InitAsTextButton) https://codereview.chromium.org/1216673005/diff/140001/ui/views/bubble/bubble_frame_view.cc File ui/views/bubble/bubble_frame_view.cc (left): https://codereview.chromium.org/1216673005/diff/140001/ui/views/bubble/bubble_frame_view.cc#oldcode107 ...
5 years, 5 months ago (2015-07-08 06:31:33 UTC) #5
tapted
actually I tried out InitAsTextbutton() (and discarded the notion of a "default" style). I think ...
5 years, 5 months ago (2015-07-09 00:53:48 UTC) #6
tapted
After burying myself in callgraphs all day (context: http://crbug.com/508410 ), I think I've got a ...
5 years, 5 months ago (2015-07-09 11:30:24 UTC) #7
tapted
5 years, 5 months ago (2015-07-10 03:29:22 UTC) #8
On 2015/07/09 11:30:24, tapted wrote:
> After burying myself in callgraphs all day (context: http://crbug.com/508410
),
> I think I've got a simpler solution cooking in my head. (Basically, don't call
> virtual methods from SetStyle() - pretty sure there's a way to make it all
work,
> so long as we guarantee SetStyle is never called while the LabelButton is
> already in a Widget, and that's easy to DCHECK). SetText() is also virtual,
but
> in my adventures I'm pretty sure I found only one override, and there should
be
> a way to support what it needs in a different way.
> 
> I think I can resolve both the wasted SetBorder() (i.e. when it's done after
> Init()), and the repeated/redundant UpdateThemedBorder() calls. Let me put
that
> together tomorrow.

created https://codereview.chromium.org/1228213003/ . I'll close this.

Powered by Google App Engine
This is Rietveld 408576698