Browse Source

Merge remote-tracking branch 'gh/master' into develop

tags/2021-05-28
jules 11 years ago
parent
commit
0ed61cb1ad
6 changed files with 43 additions and 7 deletions
  1. +10
    -4
      extras/Demo/Source/Demos/WebBrowserDemo.cpp
  2. +1
    -0
      modules/juce_gui_basics/drawables/juce_DrawableImage.cpp
  3. +1
    -0
      modules/juce_gui_extra/juce_gui_extra.cpp
  4. +6
    -0
      modules/juce_gui_extra/misc/juce_WebBrowserComponent.h
  5. +18
    -3
      modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm
  6. +7
    -0
      modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp

+ 10
- 4
extras/Demo/Source/Demos/WebBrowserDemo.cpp View File

@@ -37,13 +37,12 @@ class DemoBrowserComponent : public WebBrowserComponent
{
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..
bool pageAboutToLoad (const String& newURL)
bool pageAboutToLoad (const String& newURL) override
{
// We'll just update our address box to reflect the new location..
addressTextBox.setText (newURL, false);
@@ -53,6 +52,13 @@ public:
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:
TextEditor& addressTextBox;
@@ -93,7 +99,7 @@ public:
webView->goToURL ("http://www.juce.com");
}
void paint (Graphics& g)
void paint (Graphics& g) override
{
g.fillAll (Colours::grey);
}


+ 1
- 0
modules/juce_gui_basics/drawables/juce_DrawableImage.cpp View File

@@ -37,6 +37,7 @@ DrawableImage::DrawableImage (const DrawableImage& other)
overlayColour (other.overlayColour),
bounds (other.bounds)
{
setBounds (other.getBounds());
}
DrawableImage::~DrawableImage()


+ 1
- 0
modules/juce_gui_extra/juce_gui_extra.cpp View File

@@ -147,5 +147,6 @@ namespace juce
bool WebBrowserComponent::pageAboutToLoad (const String&) { return true; }
void WebBrowserComponent::pageFinishedLoading (const String&) {}
void WebBrowserComponent::windowCloseRequest() {}
void WebBrowserComponent::newWindowAttemptingToLoad (const String&) {}
#endif
}

+ 6
- 0
modules/juce_gui_extra/misc/juce_WebBrowserComponent.h View File

@@ -98,6 +98,12 @@ public:
*/
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 */
void paint (Graphics&) override;


+ 18
- 3
modules/juce_gui_extra/native/juce_mac_WebBrowserComponent.mm View File

@@ -32,6 +32,8 @@ struct DownloadClickDetectorClass : public ObjCClass <NSObject>
addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:),
decidePolicyForNavigationAction, "v@:@@@@@");
addMethod (@selector (webView:decidePolicyForNewWindowAction:request:newFrameName:decisionListener:),
decidePolicyForNewWindowAction, "v@:@@@@@");
addMethod (@selector (webView:didFinishLoadForFrame:), didFinishLoadForFrame, "v@:@@");
addMethod (@selector (webView:willCloseFrame:), willCloseFrame, "v@:@@");
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"); }
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,
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];
else
[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)
{
if ([frame isEqual: [sender mainFrame]])


+ 7
- 0
modules/juce_gui_extra/native/juce_win32_WebBrowserComponent.cpp View File

@@ -153,6 +153,13 @@ private:
: VARIANT_TRUE;
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)
{
owner.pageFinishedLoading (getStringFromVariant (pDispParams->rgvarg[0].pvarVal));


Loading…
Cancel
Save