Created
October 12, 2013 04:56
-
-
Save tokibito/6945988 to your computer and use it in GitHub Desktop.
WebView使いたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
unit Unit1; | |
interface | |
uses | |
System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes, | |
System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, | |
FMX.StdCtrls, Macapi.CocoaTypes, Macapi.Foundation, Macapi.AppKit, | |
Macapi.ObjectiveC, FMX.Platform.Mac; | |
type | |
WebFrameClass = interface(NSObjectClass) | |
['{7BE750C8-DFEC-4870-851A-12DBCB0B78F6}'] | |
end; | |
WebFrame = interface(NSObject) | |
['{BCFA04BE-41AB-4B78-89C0-3330F12C7695}'] | |
procedure loadRequest(request: NSURLRequest); cdecl; | |
end; | |
TWebFrame = class(TOCGenericImport<WebFrameClass, WebFrame>) end; | |
WebViewClass = interface(NSViewClass) | |
['{0D9F44B7-09FD-4E35-B96E-8DB71B9A2537}'] | |
{class} function canShowMIMEType(MIMEType: NSString): Boolean; cdecl; | |
end; | |
WebView = interface(NSView) | |
['{C36D8016-2FCB-49F0-BA1C-C9913A37F9AC}'] | |
procedure clos; cdecl; | |
procedure setHostWindow(hostWindow: NSWindow); cdecl; | |
function initWithFrame(frame: NSRect; frameName: NSString; groupName: NSString): Pointer; cdecl; | |
function mainFrame: WebFrame; cdecl; | |
end; | |
TWebView = class(TOCGenericImport<WebViewClass, WebView>) end; | |
TOCLocalAccess = class(TOCLocal); | |
TForm1 = class(TForm) | |
Button1: TButton; | |
procedure FormCreate(Sender: TObject); | |
private | |
MyWebView: WebView; | |
end; | |
var | |
Form1: TForm1; | |
implementation | |
{$R *.fmx} | |
procedure TForm1.FormCreate(Sender: TObject); | |
var | |
PWebView: Pointer; | |
FwkMod: HMODULE; | |
urlStr: NSURL; | |
urlreq: NSURLRequest; | |
ObjTOC: TOCLocal; | |
MyNSWindow : NSWindow; | |
const | |
WebKitFWK: string = '/System/Library/Frameworks/WebKit.framework/WebKit'; | |
begin | |
FwkMod := System.SysUtils.LoadLibrary(PWideChar(WebKitFWK)); | |
ObjTOC := (WindowHandleToPlatform(Form1.Handle).Handle as TOCLocal); | |
MyNSWindow := NSWindow(TOCLocalAccess(ObjTOC).Super); | |
PWebView := TWebView.Alloc.initWithFrame(MakeNSRect(0, 0, 0, 0), nil, nil); | |
MyWebView := TWebView.Wrap(PWebView); | |
MyWebView.setHostWindow(MyNSWindow); | |
urlStr := TNSURL.Create; | |
urlstr.initWithString(NSSTR('http://www.google.co.jp/')); | |
urlreq := TNSURLRequest.Create; | |
urlreq.initWithURL(urlstr); | |
MyWebView.mainFrame.loadRequest(urlreq); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment