Descriptionviews::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 #Depends on Patchset: Messages
Total messages: 8 (1 generated)
|