2010-10-03 23:04:50 +02:00
|
|
|
// Copyright (c) 2006-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.
|
|
|
|
|
|
|
|
#include "webview_host.h"
|
|
|
|
#include "browser_webview_delegate.h"
|
2011-02-28 01:33:11 +01:00
|
|
|
#include "cef_context.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-11-04 19:19:14 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
|
2011-11-04 19:19:14 +01:00
|
|
|
#include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFactory.h"
|
2011-02-15 19:07:24 +01:00
|
|
|
#include "ui/base/win/hwnd_util.h"
|
|
|
|
#include "ui/gfx/rect.h"
|
|
|
|
#include "ui/gfx/size.h"
|
2010-10-03 23:04:50 +02:00
|
|
|
#include "webkit/glue/webpreferences.h"
|
|
|
|
|
2011-11-04 19:19:14 +01:00
|
|
|
using WebKit::WebDevToolsAgentClient;
|
|
|
|
using WebKit::WebKeyboardEvent;
|
|
|
|
using WebKit::WebInputEvent;
|
|
|
|
using WebKit::WebInputEventFactory;
|
|
|
|
using WebKit::WebView;
|
2010-10-03 23:04:50 +02:00
|
|
|
|
|
|
|
static const wchar_t kWindowClassName[] = L"WebViewHost";
|
|
|
|
|
|
|
|
/*static*/
|
|
|
|
WebViewHost* WebViewHost::Create(HWND parent_view,
|
2010-11-15 16:39:56 +01:00
|
|
|
const gfx::Rect&,
|
2010-10-03 23:04:50 +02:00
|
|
|
BrowserWebViewDelegate* delegate,
|
2011-03-24 21:36:47 +01:00
|
|
|
PaintDelegate* paint_delegate,
|
2010-10-03 23:04:50 +02:00
|
|
|
WebDevToolsAgentClient* dev_tools_client,
|
|
|
|
const WebPreferences& prefs) {
|
2011-11-04 19:19:14 +01:00
|
|
|
WebViewHost* host = new WebViewHost(delegate);
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
if (!paint_delegate) {
|
|
|
|
static bool registered_class = false;
|
|
|
|
if (!registered_class) {
|
|
|
|
WNDCLASSEX wcex = {0};
|
|
|
|
wcex.cbSize = sizeof(wcex);
|
|
|
|
wcex.style = CS_DBLCLKS;
|
|
|
|
wcex.lpfnWndProc = WebWidgetHost::WndProc;
|
|
|
|
wcex.hInstance = GetModuleHandle(NULL);
|
|
|
|
wcex.hCursor = LoadCursor(NULL, IDC_ARROW);
|
|
|
|
wcex.lpszClassName = kWindowClassName;
|
|
|
|
RegisterClassEx(&wcex);
|
|
|
|
registered_class = true;
|
|
|
|
}
|
2010-10-03 23:04:50 +02:00
|
|
|
|
2011-03-24 21:36:47 +01:00
|
|
|
host->view_ = CreateWindow(kWindowClassName, NULL,
|
|
|
|
WS_CHILD|WS_CLIPCHILDREN|WS_CLIPSIBLINGS, 0, 0,
|
|
|
|
0, 0, parent_view, NULL,
|
|
|
|
GetModuleHandle(NULL), NULL);
|
|
|
|
ui::SetWindowUserData(host->view_, host);
|
|
|
|
} else {
|
|
|
|
host->paint_delegate_ = paint_delegate;
|
|
|
|
}
|
2010-10-03 23:04:50 +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-02-24 16:37:39 +01:00
|
|
|
host->webview()->setPermissionClient(delegate);
|
2010-10-03 23:04:50 +02:00
|
|
|
prefs.Apply(host->webview());
|
|
|
|
host->webview()->initializeMainFrame(delegate);
|
|
|
|
|
|
|
|
return host;
|
|
|
|
}
|
|
|
|
|
|
|
|
WebView* WebViewHost::webview() const {
|
|
|
|
return static_cast<WebView*>(webwidget_);
|
|
|
|
}
|
|
|
|
|
2011-06-14 17:45:00 +02:00
|
|
|
bool WebViewHost::WndProc(UINT message, WPARAM wparam, LPARAM lparam) {
|
|
|
|
switch (message) {
|
|
|
|
case WM_SETFOCUS:
|
|
|
|
// Set the current WebViewHost in case a drag action is started before mouse
|
|
|
|
// events are detected for the window.
|
|
|
|
_Context->set_current_webviewhost(this);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-28 01:33:11 +01:00
|
|
|
void WebViewHost::MouseEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
|
|
|
_Context->set_current_webviewhost(this);
|
|
|
|
WebWidgetHost::MouseEvent(message, wparam, lparam);
|
|
|
|
}
|
2011-11-04 19:19:14 +01:00
|
|
|
|
|
|
|
void WebViewHost::KeyEvent(UINT message, WPARAM wparam, LPARAM lparam) {
|
|
|
|
// Give the client a chance to handle keyboard events before they're passed
|
|
|
|
// to WebKit.
|
|
|
|
const WebKeyboardEvent& event = WebInputEventFactory::keyboardEvent(
|
|
|
|
view_, message, wparam, lparam);
|
|
|
|
if (delegate_->OnKeyboardEvent(event, false))
|
|
|
|
return;
|
|
|
|
|
|
|
|
WebWidgetHost::KeyEvent(message, wparam, lparam);
|
|
|
|
}
|