WebBrowserComponent under TabbedComponent


#1

I'm new to the JUCE library and the forums here.  I just created a few of my own simple JUCE applications so I could learn how it works and I may have uncovered a bug.

I'm not too sure on how this behaves on other platforms but the behaviour on Windows doesn't seem correct.  When my application contains a WebBrowserComponent based class in an inactive tab of a TabbedComponent the browser is never shown when the tab is activated, even if reloaded or sent to a new address.  I made some changes to juce_win32_WebBrowserComponent.cpp that will automatically load the last URL requested once the tab becomes active and the WebBrowserComponent is asked to draw.

I'm not sure if these changes break anything or not, so your milage may vary, but it works for me.  Here is the diff of the changes... It's very simple, less than ~10 lines.  The line setVisible(true); probably isn't necessary but I threw it in early on when debugging and kept it there.  Hope this is helpful to others...

​
diff --git "a/X:\\TEMP\\TortoiseGit\\juc770B.tmp\\juce_win32_WebBrowserComponent-eed0a41-left.cpp" "b/X:\\Projects\\JUCE\\modules\\juce_gui_extra\\native\\juce_win32_WebBrowserComponent.cpp"
index 46f5083..937459b 100644
--- "a/X:\\TEMP\\TortoiseGit\\juc770B.tmp\\juce_win32_WebBrowserComponent-eed0a41-left.cpp"
+++ "b/X:\\Projects\\JUCE\\modules\\juce_gui_extra\\native\\juce_win32_WebBrowserComponent.cpp"
@@ -67,6 +67,9 @@ public:
                   const StringArray* headers,
                   const MemoryBlock* postData)
     {
+        if ((browser == nullptr) && (getPeer() != nullptr))
+            createBrowser();
+
         if (browser != nullptr)
         {
             LPSAFEARRAY sa = nullptr;
@@ -261,8 +264,13 @@ void WebBrowserComponent::refresh()
 //==============================================================================
 void WebBrowserComponent::paint (Graphics& g)
 {
-    if (browser->browser == nullptr)
-        g.fillAll (Colours::white);
+    if (browser->browser == nullptr)
+    {
+        setVisible(true);
+        g.fillAll(Colours::white);
+        if (lastURL.isNotEmpty())
+            browser->goToURL(lastURL, &lastHeaders, &lastPostData);
+    }
 }
 
 void WebBrowserComponent::checkWindowAssociation()


#2

Thanks for the heads-up but your changes don't seem quite right to me. I don't have a test-case for the problem you're seeing, but can't you just use calls to checkWindowAssociation() like this:


--- a/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp
+++ b/modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp
@@ -67,6 +67,9 @@ public:
                   const StringArray* headers,
                   const MemoryBlock* postData)
     {
+        if (browser == nullptr)
+            checkWindowAssociation();
+
         if (browser != nullptr)
         {
             LPSAFEARRAY sa = nullptr;
@@ -262,7 +265,10 @@ void WebBrowserComponent::refresh()
 void WebBrowserComponent::paint (Graphics& g)
 {
     if (browser->browser == nullptr)
+    {
         g.fillAll (Colours::white);
+        checkWindowAssociation();
+    }
 }
 

?