WebBrowserComponent does not work in resizable window


#1

Hi all,
I’m trying to create a simple demo app which embeds HTML page and have encountered a weird issue.
I’ve created the app skeleton with Projucer 5.2.0, my custom code is minimal:

MainWindow (String name)  : DocumentWindow (name, Desktop::getInstance().getDefaultLookAndFeel().findColour(ResizableWindow::backgrounColourId), DocumentWindow::allButtons)
{
    setUsingNativeTitleBar (true);
    setContentOwned (new MainContentComponent(), true);
    centreWithSize (getWidth(), getHeight());
    setVisible (true);
    // setResizable(true, true);
}

void MainContentComponent::resized()
{
    auto bounds = getLocalBounds();
    bounds.reduce(10, 20);
    m_browser.setBounds(bounds);
}

MainContentComponent::MainContentComponent()
{
    setSize(800, 600);
    addAndMakeVisible(m_browser);
    m_browser.goToURL("https://google.com");
}

So far everything works, but after I enable window resize (by uncommenting the last line in MainWindow’s constructor) web page is no longer shown.
This reproduces on macOS (I have High Sierra 10.13.2), though I don’t have any other desktop OSes at hand to check there


#2

Try making the window resizable first, before you do anything else to it like adding its content.

When you swap a window between being resizable/non-resizable, the underlying code actually has to tear-down and recreate the whole thing, so if you’ve got complex stuff inside it like embedded web-browsers, there’s a lot of scope for things to not be recreated correctly.


#3

That worked out, thanks!