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'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
16 * DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
17 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
18 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
19 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
22 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23 */
24
25 #include "HostWindow.h"
26
27 namespace WebKitAPITest {
28
29 static LPCWSTR hostWindowClassName = L"HostWindow";
30
HostWindow()31 HostWindow::HostWindow()
32 : m_window(0)
33 {
34 }
35
initialize()36 bool HostWindow::initialize()
37 {
38 registerWindowClass();
39 m_window = CreateWindowExW(0, hostWindowClassName, L"WebKitAPITest", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, GetModuleHandle(0), 0);
40 return m_window;
41 }
42
~HostWindow()43 HostWindow::~HostWindow()
44 {
45 if (!IsWindow(m_window))
46 return;
47 DestroyWindow(m_window);
48 }
49
clientRect() const50 RECT HostWindow::clientRect() const
51 {
52 RECT rect = {0};
53 if (!GetClientRect(m_window, &rect)) {
54 RECT emptyRect = {0};
55 return emptyRect;
56 }
57 return rect;
58 }
59
registerWindowClass()60 void HostWindow::registerWindowClass()
61 {
62 static bool initialized;
63 if (initialized)
64 return;
65 initialized = true;
66
67 WNDCLASSEXW wndClass = {0};
68 wndClass.cbSize = sizeof(wndClass);
69 wndClass.style = CS_HREDRAW | CS_VREDRAW;
70 wndClass.lpfnWndProc = wndProc;
71 wndClass.hCursor = LoadCursor(0, IDC_ARROW);
72 wndClass.hInstance = GetModuleHandle(0);
73 wndClass.lpszClassName = hostWindowClassName;
74
75 RegisterClassExW(&wndClass);
76 }
77
wndProc(HWND hWnd,UINT uMsg,WPARAM wParam,LPARAM lParam)78 LRESULT HostWindow::wndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
79 {
80 return DefWindowProcW(hWnd, uMsg, wParam, lParam);
81 }
82
83 } // namespace WebKitAPITest
84