Commit 1156877e authored by Wojciech Dzierżanowski's avatar Wojciech Dzierżanowski Committed by Commit Bot

Call Widget::Init() after OverlayWindowViews constructor

Calling Widget::Init() from OverlayWindowViews constructor seems too
early. Widget::Init() triggers calls to virtual functions such as
OnNativeWidgetMove() while OverlayWindowViews hasn't been constructed
fully. To cope with this, the |is_initialized_| flag was used as a
trigger for early returns. This turned out error-prone as some crucial
parts of the virtual functions were skipped, resulting in the PiP window
becoming blank and unusable on some systems. It seems safer in general
to call Widget::Init() on a constructed OverlayWindowViews object
anyway.

With this CL, we still call SetUpViews() in the constructor to set up
all the views::View pointers that are dereferenced as a result of
Widget::Init(). Since the root view is not available at this stage (it
gets created by Widget::Init()), we keep the child views in a temporary
container. We defer the initialization steps that require the root View
to a new helper function OverlayWindowViews::OnRootViewReady().

Bug: 1058852
Change-Id: I7434fc6067fae0b5fcc0135d6c3b7b8ff62d79d0
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2107991
Commit-Queue: Wojciech Dzierżanowski <wdzierzanowski@opera.com>
Reviewed-by: default avatarAllen Bauer <kylixrd@chromium.org>
Cr-Commit-Position: refs/heads/master@{#751824}
parent 64bed061
...@@ -31,8 +31,9 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -31,8 +31,9 @@ class OverlayWindowViews : public content::OverlayWindow,
public views::ButtonListener, public views::ButtonListener,
public views::Widget { public views::Widget {
public: public:
explicit OverlayWindowViews( static std::unique_ptr<content::OverlayWindow> Create(
content::PictureInPictureWindowController* controller); content::PictureInPictureWindowController* controller);
~OverlayWindowViews() override; ~OverlayWindowViews() override;
enum class WindowQuadrant { kBottomLeft, kBottomRight, kTopLeft, kTopRight }; enum class WindowQuadrant { kBottomLeft, kBottomRight, kTopLeft, kTopRight };
...@@ -105,6 +106,9 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -105,6 +106,9 @@ class OverlayWindowViews : public content::OverlayWindow,
const gfx::Size& window_size); const gfx::Size& window_size);
private: private:
explicit OverlayWindowViews(
content::PictureInPictureWindowController* controller);
// Return the work area for the nearest display the widget is on. // Return the work area for the nearest display the widget is on.
gfx::Rect GetWorkAreaForWindow() const; gfx::Rect GetWorkAreaForWindow() const;
...@@ -117,6 +121,9 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -117,6 +121,9 @@ class OverlayWindowViews : public content::OverlayWindow,
// Set up the views::Views that will be shown on the window. // Set up the views::Views that will be shown on the window.
void SetUpViews(); void SetUpViews();
// Finish initialization by performing the steps that require the root View.
void OnRootViewReady();
// Update the bounds of the layers on the window. This may introduce // Update the bounds of the layers on the window. This may introduce
// letterboxing. // letterboxing.
void UpdateLayerBoundsWithLetterboxing(gfx::Size window_size); void UpdateLayerBoundsWithLetterboxing(gfx::Size window_size);
...@@ -171,11 +178,6 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -171,11 +178,6 @@ class OverlayWindowViews : public content::OverlayWindow,
// Not owned; |controller_| owns |this|. // Not owned; |controller_| owns |this|.
content::PictureInPictureWindowController* controller_; content::PictureInPictureWindowController* controller_;
// Whether or not the components of the window has been set up. This is used
// as a check as some event handlers (e.g. focus) is propogated to the window
// before its contents is initialized. This is only set once.
bool is_initialized_ = false;
// Whether or not the window has been shown before. This is used to determine // Whether or not the window has been shown before. This is used to determine
// sizing and placement. This is different from checking whether the window // sizing and placement. This is different from checking whether the window
// components has been initialized. // components has been initialized.
...@@ -202,6 +204,11 @@ class OverlayWindowViews : public content::OverlayWindow, ...@@ -202,6 +204,11 @@ class OverlayWindowViews : public content::OverlayWindow,
// ensuring factors such as aspect ratio is maintained. // ensuring factors such as aspect ratio is maintained.
gfx::Size natural_size_; gfx::Size natural_size_;
// Temporary storage for child Views. Used during the time between
// construction and initialization, when the views::View pointer members must
// already be initialized, but there is no root view to add them to yet.
std::vector<std::unique_ptr<views::View>> view_holder_;
// Views to be shown. // Views to be shown.
views::View* window_background_view_ = nullptr; views::View* window_background_view_ = nullptr;
views::View* video_view_ = nullptr; views::View* video_view_ = nullptr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment