Forum > Cocoa
Minimum code for implementing WebView (deprecated) or WKWebView
MISV:
I am manually copying in parts. Do you suggest I download the files and put them in a shared code library and try get Lazarus to use them? (Could not recompile FPC source)
trev:
In the past I've simply copied Cocoa headers into my applications when I've needed to change/omit/add to the existing Cocoa headers (and removed the framework link directives).
MISV:
Maybe that had been better. But well, seems like no matter the solution one uses something trippy happens. But seems like a good idea, but not sure I want to to change now unless strictly necessary. It works OK copying in all headers. And then some day FPC team wants to integrate new headers I can comment it out.
But still... the problem is confusing:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---//--// WKUserContentController.inc//--type WKUserContentController = objcclass external (NSObject, NSSecureCodingProtocol) public function userScripts: NSArray; message 'userScripts'; procedure addUserScript (userScript: WKUserScript); message 'addUserScript:'; procedure removeAllUserScripts; message 'removeAllUserScripts'; procedure addScriptMessageHandler_contentWorld_name (scriptMessageHandler: WKScriptMessageHandlerProtocol; world: WKContentWorld; name: NSString); message 'addScriptMessageHandler:contentWorld:name:'; { available in macos 11.0, ios 14.0 } procedure addScriptMessageHandlerWithReply_contentWorld_name (scriptMessageHandlerWithReply: WKScriptMessageHandlerWithReplyProtocol; contentWorld: WKContentWorld; name: NSString); message 'addScriptMessageHandlerWithReply:contentWorld:name:'; { available in macos 11.0, ios 14.0 } procedure addScriptMessageHandler_name (scriptMessageHandler: WKScriptMessageHandlerProtocol; name: NSString); message 'addScriptMessageHandler:name:'; procedure removeScriptMessageHandlerForName_contentWorld (name: NSString; contentWorld: WKContentWorld); message 'removeScriptMessageHandlerForName:contentWorld:'; { available in macos 11.0, ios 14.0 } procedure removeScriptMessageHandlerForName (name: NSString); message 'removeScriptMessageHandlerForName:'; procedure removeAllScriptMessageHandlersFromContentWorld (contentWorld: WKContentWorld); message 'removeAllScriptMessageHandlersFromContentWorld:'; { available in macos 11.0, ios 14.0 } procedure removeAllScriptMessageHandlers; message 'removeAllScriptMessageHandlers'; { available in macos 11.0, ios 14.0 } procedure addContentRuleList (contentRuleList: WKContentRuleList); message 'addContentRuleList:'; { available in macos 10.13, ios 11.0 } procedure removeContentRuleList (contentRuleList: WKContentRuleList); message 'removeContentRuleList:'; { available in macos 10.13, ios 11.0 } procedure removeAllContentRuleLists; message 'removeAllContentRuleLists'; { available in macos 10.13, ios 11.0 } { Adopted protocols } procedure encodeWithCoder (coder: NSCoder); message 'encodeWithCoder:'; function initWithCoder (coder: NSCoder): id; message 'initWithCoder:'; class function supportsSecureCoding: objcbool; message 'supportsSecureCoding'; end;type WKUserContentControllerPtr = ^WKUserContentController;//--// WKScriptMessageHandler.inc//--type WKScriptMessageHandlerProtocol = objcprotocol external name 'WKScriptMessageHandler' (NSObjectProtocol) required procedure userContentController_didReceiveScriptMessage (userContentController: WKUserContentController; message_: WKScriptMessage); message 'userContentController:didReceiveScriptMessage:'; end;
Can't solve the circular reference between WKUserContentController and and WKScriptMessageHandlerProtocol
One additional oddness I have found is that copy from the updated headers I see code like this
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type WKScriptMessageHandlerProtocolPtr = ^WKScriptMessageHandlerProtocol; WKScriptMessageHandlerProtocol = objcprotocol external name 'WKScriptMessageHandler' (NSObjectProtocol) ...
But when I compile Lazarus/FPC will not accept that and forces me to reverse order
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type WKScriptMessageHandlerProtocol = objcprotocol external name 'WKScriptMessageHandler' (NSObjectProtocol) ... WKScriptMessageHandlerProtocolPtr = ^WKScriptMessageHandlerProtocol;
Not sure if the problem is related with some kind of forwards
MISV:
Found what I THOUGHT was solution in
https://github.com/genericptr/MacOS_11_0/blob/557d8f835b5591b8c43b820a8554185c0e402f2e/DefinedClassesWebKit.pas
DefinedClasses.inc
So examples
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- WKScriptMessageHandlerProtocol = objcprotocol external name 'WKScriptMessageHandler'; // above forward for: WKScriptMessageHandlerProtocol = objcprotocol external name 'WKScriptMessageHandler' (NSObjectProtocol) WKUserContentController = objcclass external; // above forward for: WKUserContentController = objcclass external (NSObject, NSSecureCodingProtocol)
I am flipping inside right now. Why the **** does this work for the headers, but if predefine/forward declarations like above I get
--- Quote ---Error: Duplicate identifier "xxxx"
Hint: Identifier already defined in UmsXXX.pas at line xxx
--- End quote ---
I actually think getting WKWebView fully working with all features would take like 1/50 of the time without all these problems :o
MISV:
I am going to solve this "broken forwards of all kinds not working in my Lazarus" + "circular referencing" problems by...
Simply leaving out those declarations. I think that will work as long as I do not need to call them. At least I can compile then. Will need to see if causes problems runtime.
Do you agree this most likely will work? (i.e. I can only test on my own Mac, so if you have experience with it then do please let me know)
It will do as a temporary solution, so I can continue work and possibly also release.
Navigation
[0] Message Index
[#] Next page
[*] Previous page