Forum > Third party

TWebBrowser control for LCL Cocoa

(1/6) > >>

Phil:
Here's an initial proof-of-concept Web browser control:

https://macpgmr.github.io/MacXPlatform/lclwebbrowser-src.zip

Currently implemented only for LCL Cocoa widgetset by wrapping the WebView class that's part of every Mac's WebKit framework.

You can install this control in Lazarus with any widgetset to use as a placeholder when designing, but when run nothing will appear in the web control's area on the form since it's not implemented for other widgetsets (yet).

Note that by default macOS blocks calls to insecure HTTP sites. You can relax this restriction by setting the NSAllowsArbitraryLoads key in your app's Info.plist file, but for testing you might stick with HTTPS sites.

Note also that only a single method is implemented: LoadPage, which you pass a URL into.

This control does not add any bulk to your app and does not require installation of any additional libraries. Everything it needs is already on your Mac and is accessible via FPC CocoaAll unit.

Tested with 64-bit Cocoa on trunk, but will also work with 32-bit Cocoa and probably works with Laz 1.8, maybe even 1.6.4 - depends on whether anything critical to custom controls has been added to the Cocoa widgetset since those releases.

Phil:

--- Quote from: Phil on July 05, 2017, 10:15:42 pm ---Tested with 64-bit Cocoa on trunk, but will also work with 32-bit Cocoa and probably works with Laz 1.8, maybe even 1.6.4 - depends on whether anything critical to custom controls has been added to the Cocoa widgetset since those releases.

--- End quote ---

Sounds like one of the obstacles is just compiling the Cocoa widgetset in trunk such that the existing Lazarus installation doesn't get messed up. Here are some brief steps that might make the it a little easier and explain a bit about it in the process:

https://macpgmr.github.io/MacXPlatform/UsingCocoaFromTrunk.html

Phil:

Added OnPageLoaded and OnPageLoadError event properties to TWebBrowser so you can know when the page is done loading or whether there was an error.

I was going to look at what might be involved in adding support for Qt to TWebBrowser, but the Qt 5 QWebEngineView class and related classes are missing from qt56.pas in Laz 1.8 and trunk. Does anybody know anything about that? Can't proceed without them.

Also, has anyone ever compiled an LCL app on Mac with the Qt5 widgetset?

carl_caulkett:
Hi Phil, I've tried it in Lazarus 1.8.0 RC3 on the Apple Mac on 10.12.5 Sierra. I've simply got a form with:


--- 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";}};} ---procedure TForm1.FormShow(Sender: TObject);begin  WebBrowser1.LoadPage('https://www.google.com');end; 
But I'm not seeing any web page.

I also added an OnPageLoadError event handler but that's not getting fired.

Cheers,
Carl

Phil:

--- Quote from: carl_caulkett on July 08, 2017, 01:01:24 am ---
But I'm not seeing any web page.

I also added an OnPageLoadError event handler but that's not getting fired.


--- End quote ---

You're probably using the Carbon widgetset, which is the Lazarus default. It won't work with Carbon, so you're seeing the right result. You need to use the Cocoa widgetset.

Read this and see if it makes sense to you:

https://macpgmr.github.io/MacXPlatform/UsingCocoaFromTrunk.html

Navigation

[0] Message Index

[#] Next page

Go to full version