2010-10-23 19:00:47 +02:00
|
|
|
// Copyright (c) 2008 The Chromium Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2012-01-10 00:46:23 +01:00
|
|
|
#include "libcef/webview_host.h"
|
|
|
|
#include "libcef/browser_webview_delegate.h"
|
|
|
|
#include "libcef/browser_webview_mac.h"
|
|
|
|
#include "libcef/cef_context.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
|
|
|
|
#include "skia/ext/platform_canvas.h"
|
2011-11-04 19:19:14 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/mac/WebInputEventFactory.h"
|
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
|
2011-12-21 21:02:39 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
|
|
|
#include "ui/gfx/rect.h"
|
|
|
|
#include "ui/gfx/size.h"
|
2010-10-23 19:00:47 +02:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
|
|
|
|
|
|
|
using WebKit::WebDevToolsAgentClient;
|
2011-11-04 19:19:14 +01:00
|
|
|
using WebKit::WebKeyboardEvent;
|
|
|
|
using WebKit::WebInputEvent;
|
|
|
|
using WebKit::WebInputEventFactory;
|
2010-10-23 19:00:47 +02:00
|
|
|
using WebKit::WebSize;
|
|
|
|
using WebKit::WebView;
|
|
|
|
|
|
|
|
// static
|
|
|
|
WebViewHost* WebViewHost::Create(NSView* parent_view,
|
2010-11-15 16:39:56 +01:00
|
|
|
const gfx::Rect& rect,
|
2010-10-23 19:00:47 +02:00
|
|
|
BrowserWebViewDelegate* delegate,
|
2011-03-24 21:36:47 +01:00
|
|
|
PaintDelegate* paint_delegate,
|
2010-10-23 19:00:47 +02:00
|
|
|
WebDevToolsAgentClient* dev_tools_client,
|
|
|
|
const WebPreferences& prefs) {
|
2011-11-04 19:19:14 +01:00
|
|
|
WebViewHost* host = new WebViewHost(delegate);
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2010-11-15 16:39:56 +01:00
|
|
|
NSRect content_rect = {{rect.x(), rect.y()}, {rect.width(), rect.height()}};
|
2012-05-16 18:56:38 +02:00
|
|
|
if (!paint_delegate) {
|
|
|
|
host->view_ = [[BrowserWebView alloc] initWithFrame:content_rect];
|
|
|
|
[host->view_ setAutoresizingMask:(NSViewWidthSizable |
|
|
|
|
NSViewHeightSizable)];
|
|
|
|
[parent_view addSubview:host->view_];
|
|
|
|
[host->view_ release];
|
|
|
|
} else {
|
|
|
|
host->paint_delegate_ = paint_delegate;
|
|
|
|
}
|
2010-10-23 19:00:47 +02:00
|
|
|
|
2011-01-12 00:46:14 +01:00
|
|
|
#if defined(WEBKIT_HAS_WEB_AUTO_FILL_CLIENT)
|
2011-04-05 18:17:33 +02:00
|
|
|
host->webwidget_ = WebView::create(delegate, NULL);
|
2011-01-12 00:46:14 +01:00
|
|
|
#else
|
2011-04-05 18:17:33 +02:00
|
|
|
host->webwidget_ = WebView::create(delegate);
|
2011-01-12 00:46:14 +01:00
|
|
|
#endif
|
2011-04-05 18:17:33 +02:00
|
|
|
host->webview()->setDevToolsAgentClient(dev_tools_client);
|
2012-01-05 20:34:20 +01:00
|
|
|
host->webview()->setPermissionClient(delegate);
|
2010-10-23 19:00:47 +02:00
|
|
|
prefs.Apply(host->webview());
|
|
|
|
host->webview()->initializeMainFrame(delegate);
|
|
|
|
host->webwidget_->resize(WebSize(content_rect.size.width,
|
|
|
|
content_rect.size.height));
|
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
2011-08-14 23:54:18 +02:00
|
|
|
WebViewHost::~WebViewHost() {
|
|
|
|
BrowserWebView* webView = static_cast<BrowserWebView*>(view_);
|
|
|
|
webView.browser = NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-23 19:00:47 +02:00
|
|
|
WebView* WebViewHost::webview() const {
|
|
|
|
return static_cast<WebView*>(webwidget_);
|
|
|
|
}
|
|
|
|
|
|
|
|
void WebViewHost::SetIsActive(bool active) {
|
|
|
|
webview()->setIsActive(active);
|
|
|
|
}
|
2011-08-02 18:50:06 +02:00
|
|
|
|
|
|
|
void WebViewHost::MouseEvent(NSEvent* event) {
|
|
|
|
_Context->set_current_webviewhost(this);
|
|
|
|
WebWidgetHost::MouseEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-11-04 19:19:14 +01:00
|
|
|
void WebViewHost::KeyEvent(NSEvent *event) {
|
|
|
|
WebKeyboardEvent keyboard_event(WebInputEventFactory::keyboardEvent(event));
|
|
|
|
if (delegate_->OnKeyboardEvent(keyboard_event, false))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebWidgetHost::KeyEvent(event);
|
|
|
|
}
|
|
|
|
|
2011-08-02 18:50:06 +02:00
|
|
|
void WebViewHost::SetFocus(bool enable) {
|
|
|
|
if (enable) {
|
|
|
|
// Set the current WebViewHost in case a drag action is started before mouse
|
|
|
|
// events are detected for the window.
|
|
|
|
_Context->set_current_webviewhost(this);
|
|
|
|
}
|
|
|
|
WebWidgetHost::SetFocus(enable);
|
|
|
|
}
|