mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Focus fix for win32 web browser component. Ability to use javascript in goToURL on OSX.
This commit is contained in:
parent
951b15e6e3
commit
7f901e452f
5 changed files with 84 additions and 41 deletions
|
|
@ -113,6 +113,8 @@ public:
|
||||||
void parentHierarchyChanged() override;
|
void parentHierarchyChanged() override;
|
||||||
/** @internal */
|
/** @internal */
|
||||||
void visibilityChanged() override;
|
void visibilityChanged() override;
|
||||||
|
/** @internal */
|
||||||
|
void focusGained (FocusChangeType) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
|
|
|
||||||
|
|
@ -107,3 +107,7 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
{
|
{
|
||||||
checkWindowAssociation();
|
checkWindowAssociation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -112,3 +112,7 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
{
|
{
|
||||||
checkWindowAssociation();
|
checkWindowAssociation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -24,11 +24,11 @@
|
||||||
|
|
||||||
#if JUCE_MAC
|
#if JUCE_MAC
|
||||||
|
|
||||||
struct DownloadClickDetectorClass : public ObjCClass <NSObject>
|
struct DownloadClickDetectorClass : public ObjCClass<NSObject>
|
||||||
{
|
{
|
||||||
DownloadClickDetectorClass() : ObjCClass <NSObject> ("JUCEWebClickDetector_")
|
DownloadClickDetectorClass() : ObjCClass<NSObject> ("JUCEWebClickDetector_")
|
||||||
{
|
{
|
||||||
addIvar <WebBrowserComponent*> ("owner");
|
addIvar<WebBrowserComponent*> ("owner");
|
||||||
|
|
||||||
addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:),
|
addMethod (@selector (webView:decidePolicyForNavigationAction:request:frame:decisionListener:),
|
||||||
decidePolicyForNavigationAction, "v@:@@@@@");
|
decidePolicyForNavigationAction, "v@:@@@@@");
|
||||||
|
|
@ -54,7 +54,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
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)
|
||||||
{
|
{
|
||||||
if (getOwner (self)->pageAboutToLoad (getOriginalURL (actionInformation)))
|
if (getOwner (self)->pageAboutToLoad (getOriginalURL (actionInformation)))
|
||||||
[listener use];
|
[listener use];
|
||||||
|
|
@ -63,7 +63,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
static void decidePolicyForNewWindowAction (id self, SEL, WebView*, NSDictionary* actionInformation,
|
static void decidePolicyForNewWindowAction (id self, SEL, WebView*, NSDictionary* actionInformation,
|
||||||
NSURLRequest*, NSString*, id <WebPolicyDecisionListener> listener)
|
NSURLRequest*, NSString*, id<WebPolicyDecisionListener> listener)
|
||||||
{
|
{
|
||||||
getOwner (self)->newWindowAttemptingToLoad (getOriginalURL (actionInformation));
|
getOwner (self)->newWindowAttemptingToLoad (getOriginalURL (actionInformation));
|
||||||
[listener ignore];
|
[listener ignore];
|
||||||
|
|
@ -109,7 +109,7 @@ private:
|
||||||
} // (juce namespace)
|
} // (juce namespace)
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@interface WebViewTapDetector : NSObject <UIGestureRecognizerDelegate>
|
@interface WebViewTapDetector : NSObject<UIGestureRecognizerDelegate>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -130,7 +130,7 @@ private:
|
||||||
@end
|
@end
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
@interface WebViewURLChangeDetector : NSObject <UIWebViewDelegate>
|
@interface WebViewURLChangeDetector : NSObject<UIWebViewDelegate>
|
||||||
{
|
{
|
||||||
juce::WebBrowserComponent* ownerComponent;
|
juce::WebBrowserComponent* ownerComponent;
|
||||||
}
|
}
|
||||||
|
|
@ -216,37 +216,45 @@ public:
|
||||||
const StringArray* headers,
|
const StringArray* headers,
|
||||||
const MemoryBlock* postData)
|
const MemoryBlock* postData)
|
||||||
{
|
{
|
||||||
NSMutableURLRequest* r
|
|
||||||
= [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
|
|
||||||
cachePolicy: NSURLRequestUseProtocolCachePolicy
|
|
||||||
timeoutInterval: 30.0];
|
|
||||||
|
|
||||||
if (postData != nullptr && postData->getSize() > 0)
|
|
||||||
{
|
|
||||||
[r setHTTPMethod: nsStringLiteral ("POST")];
|
|
||||||
[r setHTTPBody: [NSData dataWithBytes: postData->getData()
|
|
||||||
length: postData->getSize()]];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (headers != nullptr)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < headers->size(); ++i)
|
|
||||||
{
|
|
||||||
const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
|
|
||||||
const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
|
|
||||||
|
|
||||||
[r setValue: juceStringToNS (headerValue)
|
|
||||||
forHTTPHeaderField: juceStringToNS (headerName)];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
stop();
|
stop();
|
||||||
|
|
||||||
#if JUCE_MAC
|
if (url.trimStart().startsWithIgnoreCase ("javascript:"))
|
||||||
[[webView mainFrame] loadRequest: r];
|
{
|
||||||
#else
|
[webView stringByEvaluatingJavaScriptFromString:
|
||||||
[webView loadRequest: r];
|
juceStringToNS (url.fromFirstOccurrenceOf (":", false, false))];
|
||||||
#endif
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSMutableURLRequest* r
|
||||||
|
= [NSMutableURLRequest requestWithURL: [NSURL URLWithString: juceStringToNS (url)]
|
||||||
|
cachePolicy: NSURLRequestUseProtocolCachePolicy
|
||||||
|
timeoutInterval: 30.0];
|
||||||
|
|
||||||
|
if (postData != nullptr && postData->getSize() > 0)
|
||||||
|
{
|
||||||
|
[r setHTTPMethod: nsStringLiteral ("POST")];
|
||||||
|
[r setHTTPBody: [NSData dataWithBytes: postData->getData()
|
||||||
|
length: postData->getSize()]];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (headers != nullptr)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < headers->size(); ++i)
|
||||||
|
{
|
||||||
|
const String headerName ((*headers)[i].upToFirstOccurrenceOf (":", false, false).trim());
|
||||||
|
const String headerValue ((*headers)[i].fromFirstOccurrenceOf (":", false, false).trim());
|
||||||
|
|
||||||
|
[r setValue: juceStringToNS (headerValue)
|
||||||
|
forHTTPHeaderField: juceStringToNS (headerName)];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#if JUCE_MAC
|
||||||
|
[[webView mainFrame] loadRequest: r];
|
||||||
|
#else
|
||||||
|
[webView loadRequest: r];
|
||||||
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void goBack() { [webView goBack]; }
|
void goBack() { [webView goBack]; }
|
||||||
|
|
@ -392,3 +400,7 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
{
|
{
|
||||||
checkWindowAssociation();
|
checkWindowAssociation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public:
|
||||||
|
|
||||||
if (connectionPoint != nullptr)
|
if (connectionPoint != nullptr)
|
||||||
{
|
{
|
||||||
WebBrowserComponent* const owner = dynamic_cast <WebBrowserComponent*> (getParentComponent());
|
WebBrowserComponent* const owner = dynamic_cast<WebBrowserComponent*> (getParentComponent());
|
||||||
jassert (owner != nullptr);
|
jassert (owner != nullptr);
|
||||||
|
|
||||||
EventHandler* handler = new EventHandler (*owner);
|
EventHandler* handler = new EventHandler (*owner);
|
||||||
|
|
@ -129,13 +129,11 @@ private:
|
||||||
DWORD adviseCookie;
|
DWORD adviseCookie;
|
||||||
|
|
||||||
//==============================================================================
|
//==============================================================================
|
||||||
class EventHandler : public ComBaseClassHelper <IDispatch>,
|
class EventHandler : public ComBaseClassHelper<IDispatch>,
|
||||||
public ComponentMovementWatcher
|
public ComponentMovementWatcher
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EventHandler (WebBrowserComponent& owner_)
|
EventHandler (WebBrowserComponent& w) : ComponentMovementWatcher (&w), owner (w)
|
||||||
: ComponentMovementWatcher (&owner_),
|
|
||||||
owner (owner_)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -330,3 +328,26 @@ void WebBrowserComponent::visibilityChanged()
|
||||||
{
|
{
|
||||||
checkWindowAssociation();
|
checkWindowAssociation();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebBrowserComponent::focusGained (FocusChangeType)
|
||||||
|
{
|
||||||
|
if (IOleObject* oleObject = (IOleObject*) browser->queryInterface (&IID_IOleObject))
|
||||||
|
{
|
||||||
|
if (IOleWindow* oleWindow = (IOleWindow*) browser->queryInterface (&IID_IOleWindow))
|
||||||
|
{
|
||||||
|
IOleClientSite* oleClientSite = nullptr;
|
||||||
|
|
||||||
|
if (SUCCEEDED (oleObject->GetClientSite (&oleClientSite)))
|
||||||
|
{
|
||||||
|
HWND hwnd;
|
||||||
|
oleWindow->GetWindow (&hwnd);
|
||||||
|
oleObject->DoVerb (OLEIVERB_UIACTIVATE, nullptr, oleClientSite, 0, hwnd, nullptr);
|
||||||
|
oleClientSite->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
oleWindow->Release();
|
||||||
|
}
|
||||||
|
|
||||||
|
oleObject->Release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue