| @@ -37,13 +37,12 @@ class DemoBrowserComponent : public WebBrowserComponent | |||||
| { | { | ||||
| public: | public: | ||||
| //============================================================================== | //============================================================================== | ||||
| DemoBrowserComponent (TextEditor& addressTextBox_) | |||||
| : addressTextBox (addressTextBox_) | |||||
| DemoBrowserComponent (TextEditor& addressBox) : addressTextBox (addressBox) | |||||
| { | { | ||||
| } | } | ||||
| // This method gets called when the browser is about to go to a new URL.. | // This method gets called when the browser is about to go to a new URL.. | ||||
| bool pageAboutToLoad (const String& newURL) | |||||
| bool pageAboutToLoad (const String& newURL) override | |||||
| { | { | ||||
| // We'll just update our address box to reflect the new location.. | // We'll just update our address box to reflect the new location.. | ||||
| addressTextBox.setText (newURL, false); | addressTextBox.setText (newURL, false); | ||||
| @@ -53,6 +52,13 @@ public: | |||||
| return true; | return true; | ||||
| } | } | ||||
| // This method gets called when the browser is requested to launch a new window | |||||
| void newWindowAttemptingToLoad (const String& newURL) override | |||||
| { | |||||
| // We'll just load the URL into the main window | |||||
| goToURL (newURL); | |||||
| } | |||||
| private: | private: | ||||
| TextEditor& addressTextBox; | TextEditor& addressTextBox; | ||||
| @@ -93,7 +99,7 @@ public: | |||||
| webView->goToURL ("http://www.juce.com"); | webView->goToURL ("http://www.juce.com"); | ||||
| } | } | ||||
| void paint (Graphics& g) | |||||
| void paint (Graphics& g) override | |||||
| { | { | ||||
| g.fillAll (Colours::grey); | g.fillAll (Colours::grey); | ||||
| } | } | ||||
| @@ -37,6 +37,7 @@ DrawableImage::DrawableImage (const DrawableImage& other) | |||||
| overlayColour (other.overlayColour), | overlayColour (other.overlayColour), | ||||
| bounds (other.bounds) | bounds (other.bounds) | ||||
| { | { | ||||
| setBounds (other.getBounds()); | |||||
| } | } | ||||
| DrawableImage::~DrawableImage() | DrawableImage::~DrawableImage() | ||||
| @@ -147,5 +147,6 @@ namespace juce | |||||
| bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } | bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; } | ||||
| void WebBrowserComponent::pageFinishedLoading (const String&) {} | void WebBrowserComponent::pageFinishedLoading (const String&) {} | ||||
| void WebBrowserComponent::windowCloseRequest() {} | void WebBrowserComponent::windowCloseRequest() {} | ||||
| void WebBrowserComponent::newWindowAttemptingToLoad (const String&) {} | |||||
| #endif | #endif | ||||
| } | } | ||||
| @@ -98,6 +98,12 @@ public: | |||||
| */ | */ | ||||
| virtual void windowCloseRequest(); | virtual void windowCloseRequest(); | ||||
| /** This callback occurs when the browser attempts to load a URL in a new window. | |||||
| This won't actually load the window but gives you a chance to either launch a | |||||
| new window yourself or just load the URL into the current window with goToURL(). | |||||
| */ | |||||
| virtual void newWindowAttemptingToLoad (const String& newURL); | |||||
| //============================================================================== | //============================================================================== | ||||
| /** @internal */ | /** @internal */ | ||||
| void paint (Graphics&) override; | void paint (Graphics&) override; | ||||
| @@ -32,6 +32,8 @@ struct DownloadClickDetectorClass : public ObjCClass <NSObject> | |||||
| addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:), | addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:), | ||||
| decidePolicyForNavigationAction, "v@:@@@@@"); | decidePolicyForNavigationAction, "v@:@@@@@"); | ||||
| addMethod (@selector (webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:), | |||||
| decidePolicyForNewWindowAction, "v@:@@@@@"); | |||||
| addMethod (@selector (webView:didFinishLoadForFrame:), didFinishLoadForFrame, "v@:@@"); | addMethod (@selector (webView:didFinishLoadForFrame:), didFinishLoadForFrame, "v@:@@"); | ||||
| addMethod (@selector (webView:willCloseFrame:), willCloseFrame, "v@:@@"); | addMethod (@selector (webView:willCloseFrame:), willCloseFrame, "v@:@@"); | ||||
| addMethod (@selector (webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), runOpenPanel, "v@:@@", @encode (BOOL)); | addMethod (@selector (webView:runOpenPanelForFileButtonWithResultListener:allowMultipleFiles:), runOpenPanel, "v@:@@", @encode (BOOL)); | ||||
| @@ -43,17 +45,30 @@ struct DownloadClickDetectorClass : public ObjCClass <NSObject> | |||||
| static WebBrowserComponent* getOwner (id self) { return getIvar<WebBrowserComponent*> (self, "owner"); } | static WebBrowserComponent* getOwner (id self) { return getIvar<WebBrowserComponent*> (self, "owner"); } | ||||
| private: | private: | ||||
| static String getOriginalURL (NSDictionary* actionInformation) | |||||
| { | |||||
| if (NSURL* url = [actionInformation valueForKey: nsStringLiteral ("WebActionOriginalURLKey")]) | |||||
| return nsStringToJuce ([url absoluteString]); | |||||
| return String(); | |||||
| } | |||||
| static void decidePolicyForNavigationAction (id self, SEL, WebView*, NSDictionary* actionInformation, | static void decidePolicyForNavigationAction (id self, SEL, WebView*, NSDictionary* actionInformation, | ||||
| NSURLRequest*, WebFrame*, id <WebPolicyDecisionListener> listener) | NSURLRequest*, WebFrame*, id <WebPolicyDecisionListener> listener) | ||||
| { | { | ||||
| NSURL* url = [actionInformation valueForKey: nsStringLiteral ("WebActionOriginalURLKey")]; | |||||
| if (getOwner (self)->pageAboutToLoad (nsStringToJuce ([url absoluteString]))) | |||||
| if (getOwner (self)->pageAboutToLoad (getOriginalURL (actionInformation))) | |||||
| [listener use]; | [listener use]; | ||||
| else | else | ||||
| [listener ignore]; | [listener ignore]; | ||||
| } | } | ||||
| static void decidePolicyForNewWindowAction (id self, SEL, WebView*, NSDictionary* actionInformation, | |||||
| NSURLRequest*, NSString*, id <WebPolicyDecisionListener> listener) | |||||
| { | |||||
| getOwner (self)->newWindowAttemptingToLoad (getOriginalURL (actionInformation)); | |||||
| [listener ignore]; | |||||
| } | |||||
| static void didFinishLoadForFrame (id self, SEL, WebView* sender, WebFrame* frame) | static void didFinishLoadForFrame (id self, SEL, WebView* sender, WebFrame* frame) | ||||
| { | { | ||||
| if ([frame isEqual: [sender mainFrame]]) | if ([frame isEqual: [sender mainFrame]]) | ||||
| @@ -153,6 +153,13 @@ private: | |||||
| : VARIANT_TRUE; | : VARIANT_TRUE; | ||||
| return S_OK; | return S_OK; | ||||
| } | } | ||||
| else if (dispIdMember == DISPID_NEWWINDOW3) | |||||
| { | |||||
| owner.newWindowAttemptingToLoad (pDispParams->rgvarg[0].bstrVal); | |||||
| *pDispParams->rgvarg[3].pboolVal = VARIANT_TRUE; | |||||
| return S_OK; | |||||
| } | |||||
| else if (dispIdMember == DISPID_DOCUMENTCOMPLETE) | else if (dispIdMember == DISPID_DOCUMENTCOMPLETE) | ||||
| { | { | ||||
| owner.pageFinishedLoading (getStringFromVariant (pDispParams->rgvarg[0].pvarVal)); | owner.pageFinishedLoading (getStringFromVariant (pDispParams->rgvarg[0].pvarVal)); | ||||