2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 * Copyright (C) 2010 University of Szeged. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
18 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
19 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
20 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include "PlatformWebView.h"
30 #include "qdesktopwebview.h"
31 #include <QtDeclarative/qsgcanvas.h>
36 class WebView : public QSGCanvas {
38 WebView(WKContextRef, WKPageGroupRef);
40 QDesktopWebView* wkView() const { return m_item; }
41 WKPageRef pageRef() const { return m_item->pageRef(); }
43 virtual ~WebView() { delete m_item; }
46 QDesktopWebView* m_item;
49 WebView::WebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
50 : m_item(new QDesktopWebView(contextRef, pageGroupRef, rootItem()))
52 m_item->setWidth(800);
53 m_item->setHeight(600);
56 PlatformWebView::PlatformWebView(WKContextRef contextRef, WKPageGroupRef pageGroupRef)
57 : m_view(new WebView(contextRef, pageGroupRef))
58 , m_window(new QMainWindow())
60 m_view->setParent(m_window);
61 m_window->setCentralWidget(m_view);
62 m_window->setGeometry(0, 0, 800, 600);
64 QFocusEvent ev(QEvent::WindowActivate);
65 QApplication::sendEvent(m_view, &ev);
66 m_view->wkView()->setFocus(Qt::OtherFocusReason);
69 PlatformWebView::~PlatformWebView()
74 void PlatformWebView::resizeTo(unsigned width, unsigned height)
76 m_window->resize(width, height);
79 WKPageRef PlatformWebView::page()
81 return m_view->pageRef();
84 void PlatformWebView::focus()
86 m_view->setFocus(Qt::OtherFocusReason);
89 WKRect PlatformWebView::windowFrame()
91 QRect windowRect = m_window->geometry();
93 wkFrame.origin.x = windowRect.x();
94 wkFrame.origin.y = windowRect.y();
95 wkFrame.size.width = windowRect.size().width();
96 wkFrame.size.height = windowRect.size().height();
100 void PlatformWebView::setWindowFrame(WKRect wkRect)
102 m_window->setGeometry(wkRect.origin.x, wkRect.origin.y, wkRect.size.width, wkRect.size.height);