1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "PlatformWebView.h"
28
29 namespace WTR {
30
31 static LPCWSTR hostWindowClassName = L"WTRWebViewHostWindow";
32
registerWindowClass()33 static void registerWindowClass()
34 {
35 static bool initialized;
36 if (initialized)
37 return;
38 initialized = true;
39
40 WNDCLASSEXW wndClass = {0};
41 wndClass.cbSize = sizeof(wndClass);
42 wndClass.style = CS_HREDRAW | CS_VREDRAW;
43 wndClass.lpfnWndProc = DefWindowProcW;
44 wndClass.hCursor = LoadCursor(0, IDC_ARROW);
45 wndClass.hInstance = GetModuleHandle(0);
46 wndClass.lpszClassName = hostWindowClassName;
47
48 RegisterClassExW(&wndClass);
49 }
50
PlatformWebView(WKContextRef contextRef,WKPageGroupRef pageGroupRef)51 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
52 {
53 registerWindowClass();
54
55 RECT viewRect = {0, 0, 800, 600};
56 m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitTestRunner", WS_OVERLAPPEDWINDOW, 0 /*XOFFSET*/, 0 /*YOFFSET*/, viewRect.right, viewRect.bottom, 0, 0, GetModuleHandle(0), 0);
57 m_view = WKViewCreate(viewRect, contextRef, pageGroupRef, m_window);
58 WKViewSetIsInWindow(m_view, true);
59 }
60
~PlatformWebView()61 PlatformWebView::~PlatformWebView()
62 {
63 if (::IsWindow(m_window))
64 ::DestroyWindow(m_window);
65 WKRelease(m_view);
66 }
67
resizeTo(unsigned width,unsigned height)68 void PlatformWebView::resizeTo(unsigned width, unsigned height)
69 {
70 ::SetWindowPos(WKViewGetWindow(m_view), 0, 0, 0, width, height, SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOCOPYBITS);
71 }
72
page()73 WKPageRef PlatformWebView::page()
74 {
75 return WKViewGetPage(m_view);
76 }
77
focus()78 void PlatformWebView::focus()
79 {
80 ::SetFocus(::WKViewGetWindow(m_view));
81 }
82
windowFrame()83 WKRect PlatformWebView::windowFrame()
84 {
85 // Implement.
86
87 WKRect wkFrame;
88 wkFrame.origin.x = 0;
89 wkFrame.origin.y = 0;
90 wkFrame.size.width = 0;
91 wkFrame.size.height = 0;
92 return wkFrame;
93 }
94
setWindowFrame(WKRect)95 void PlatformWebView::setWindowFrame(WKRect)
96 {
97 // Implement.
98 }
99
100 } // namespace WTR
101