NSViewComponent only works when NativeTitleBar is true


#1

We have been creating our own decendant of NSViewComponent to get some custom cocoa classes going. At first it did not seem to work as all what was shown was a black frame. We of course thought that was our own fault but when trying to embed the WebbrowserComponent we had the same result, as someone already found out.
http://www.rawmaterialsoftware.com/juceforum/viewtopic.php?t=2900&highlight=webbrowsercomponent

For some reason i had the idea that it might had to-do with the main window not having a native title bar and voila after setting this to true it all worked. So were happy now, but this needs a fix of course.


#2

That’s puzzling - I can’t think how this could be a fault of the framework. Having a title bar just sets the window style, and isn’t used anywhere else… I’ll have a think, but it feels like it’s probably the webview itself making assumptions about the window it’s being put into.


#3

It’s not the title bar in my opinion… I have done some testing and found out that the WebBrowserComponent works perfectly well if it’s set directly as the content component of a window, while it paints only a black window if I add it to a Component which serves as the content component.

Jules, can you help?


#4

[quote=“yfede”]It’s not the title bar in my opinion… I have done some testing and found out that the WebBrowserComponent works perfectly well if it’s set directly as the content component of a window, while it paints only a black window if I add it to a Component which serves as the content component.

Jules, can you help?[/quote]

If that was true, then the browser page in the juce demo wouldn’t work either.

Maybe you could send me some code that reproduces the problem?


#5

This is the body of the constructor of a MainWindow that shows the problem on Mac:

MainWindow::MainWindow(const String& componentName, Application* const application, const String& lookAndFeelToUse) : 
    DocumentWindow (componentName,
                      Colours::azure,
                      DocumentWindow::allButtons,
                      true),
    m_application (application),
    m_settings (0)
{

    setResizable (false, false); // resizability is a property of ResizableWindow

    // ---------- debug code for some tests on mac
    Component* debug_content = new Component (T("component"));
    
    WebBrowserComponent* debug_browser = new WebBrowserComponent ();
    debug_browser->setBounds (10, 10, 500, 400);
    debug_content->addAndMakeVisible (debug_browser);
    setContentComponent (debug_content, false, true);
    
    centreWithSize (800, 600);
    debug_browser->goToURL (T("http://www.yfede.it/"));
}

#6

Maybe something’s going wrong because you’re initially adding it to a zero-sized component - try setting up the window’s size before you add the browser comp?


#7

Yeah wonderful! it works now, well spotted!

Why not putting some jasserts in the WebBrowserComponent in order to warn other developers that may encounter this?


#8

It should probably just work without needing special treatment - I’ll have a look and see if I can tweak it…