#define NO_USING_WEBVIEW
#include "WebView.h"
#import <Foundation/Foundation.h>
#import <Cocoa/Cocoa.h>
#import <WebKit/WebKit.h>
#import <PDFKit/PDFKit.h>

//#define WKWEBVIEW_TYPE
#define WEBVIEW_TYPE
//#define PDFVIEW_TYPE

#if 1
MacWebView::MacWebView(QWidget *parent)
  : QMacCocoaViewContainer(0, parent)
{
  NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

#if defined(WKWEBVIEW_TYPE)
  WKWebViewConfiguration *theConfiguration = [[WKWebViewConfiguration alloc] init];
  NSRect r = { 0, 0, 500, 500 };
  WKWebView *webView = [[WKWebView alloc] initWithFrame:r configuration:theConfiguration];
#elif defined(WEBVIEW_TYPE)
  WebView *webView = [[WebView alloc] init];
#elif defined(PDFVIEW_TYPE)
  PDFView *webView = [[PDFView alloc] init];
#endif

  setCocoaView(webView);

  [webView release];
  [pool release];
}

void MacWebView::setUrl(const QUrl& url)
{
#if defined(WKWEBVIEW_TYPE)
  [cocoaView() loadRequest:[NSURLRequest requestWithURL:url.toNSURL()]];
#elif defined(WEBVIEW_TYPE)
  [[cocoaView() mainFrame] loadRequest:[NSURLRequest requestWithURL:url.toNSURL()]];
#elif defined(PDFVIEW_TYPE)
  [cocoaView() setDocument:[[PDFDocument alloc] initWithURL:url.toNSURL()]];
#endif
}

void MacWebView::setFile(const QString& url)
{
#if defined(PDFVIEW_TYPE)
  [cocoaView() setDocument:url.toNSString()];
#endif
}

void MacWebView::runJavaScript(const QString& script)
{
  //[cocoaView() stringByEvaluatingJavaScriptFromString:script.toNSString()];
}
#endif

