Only perform dialog Layout() once during Widget::Init().

For Widgets that require a non-client view Layout is currently performed
twice during Widget::Init():
 - once before the initial bounds of the Widget are determined
    (when setting the RootView's ContentsView), and
 - once after (when setting the initial bounds).

The first Layout() is unnecessary and can lead to bugs when the RootView
attempts a layout at an invalid size. Layout of text in particular can
be affected since giving it a size influences text wrapping, and
subsequent answers for Label::GetPreferredSize() will change.

In particular, on Mac and Linux, zero-sized windows are not valid, so a
NativeWidget may take on a size of 1x1 until its initial bounds is
determined. If RootView performs a layout at this size, it can "lock" a
Label to an non-preferred, but non-zero, size. This causes Label (and
gfx::RenderText) to report a new preferred size of 0x0 (since no text
will fit). So when Widget initialization later tries to determine what
the initial bounds of the Widget should be, the Label is not accounted
for. Keeping the Label with a 0x0 size instead causes
Label::GetPreferredSize() to report a meaningful preferred size in more
cases.

But also layout is expensive and shouldn't be done multiple times
whenever a Widget is created if we can avoid it.

BUG=671820

Review-Url: https://codereview.chromium.org/2712383002
Cr-Commit-Position: refs/heads/master@{#453365}
3 files changed