diff options
Diffstat (limited to 'lib/widgets')
-rw-r--r-- | lib/widgets/Api/qwebcontentsview.cpp | 144 | ||||
-rw-r--r-- | lib/widgets/Api/qwebcontentsview.h | 79 | ||||
-rw-r--r-- | lib/widgets/Api/qwebcontentsview_p.h | 70 | ||||
-rw-r--r-- | lib/widgets/render_widget_host_view_qt_delegate_widget.cpp | 114 | ||||
-rw-r--r-- | lib/widgets/render_widget_host_view_qt_delegate_widget.h | 73 | ||||
-rw-r--r-- | lib/widgets/widgets.pro | 33 |
6 files changed, 513 insertions, 0 deletions
diff --git a/lib/widgets/Api/qwebcontentsview.cpp b/lib/widgets/Api/qwebcontentsview.cpp new file mode 100644 index 000000000..612f7699b --- /dev/null +++ b/lib/widgets/Api/qwebcontentsview.cpp @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qwebcontentsview.h" +#include "qwebcontentsview_p.h" + +#include "render_widget_host_view_qt_delegate_widget.h" +#include "web_contents_adapter.h" + +#include <QStackedLayout> +#include <QUrl> + +QWebContentsViewPrivate::QWebContentsViewPrivate() + : m_isLoading(false) + , adapter(new WebContentsAdapter(this)) +{ +} + +void QWebContentsViewPrivate::titleChanged(const QString &title) +{ + Q_EMIT q_ptr->titleChanged(title); +} + +void QWebContentsViewPrivate::urlChanged(const QUrl &url) +{ + Q_EMIT q_ptr->urlChanged(url); +} + +void QWebContentsViewPrivate::loadingStateChanged() +{ + Q_Q(QWebContentsView); + const bool wasLoading = m_isLoading; + m_isLoading = adapter->isLoading(); + if (m_isLoading != wasLoading) { + if (m_isLoading) + Q_EMIT q->loadStarted(); + else + Q_EMIT q->loadFinished(true); + } +} + +RenderWidgetHostViewQtDelegate *QWebContentsViewPrivate::CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQt* rwhv) +{ + Q_Q(QWebContentsView); + RenderWidgetHostViewQtDelegateWidget *viewDelegate = new RenderWidgetHostViewQtDelegateWidget(q); + viewDelegate->resetView(rwhv); + // Parent the RWHVQtDelegate directly, this might have to be changed to handle popups and fullscreen. + q->layout()->addWidget(viewDelegate); + return viewDelegate; +} + +QWebContentsView::QWebContentsView() + : d_ptr(new QWebContentsViewPrivate) +{ + d_ptr->q_ptr=this; + // This causes the child RenderWidgetHostViewQtDelegateWidgets to fill this widget. + setLayout(new QStackedLayout); +} + +QWebContentsView::~QWebContentsView() +{ +} + +void QWebContentsView::load(const QUrl& url) +{ + Q_D(QWebContentsView); + d->adapter->load(url); +} + +bool QWebContentsView::canGoBack() const +{ + Q_D(const QWebContentsView); + return d->adapter->canGoBack(); +} + +bool QWebContentsView::canGoForward() const +{ + Q_D(const QWebContentsView); + return d->adapter->canGoForward(); +} + +void QWebContentsView::back() +{ + Q_D(QWebContentsView); + d->adapter->navigateHistory(-1); +} + +void QWebContentsView::forward() +{ + Q_D(QWebContentsView); + d->adapter->navigateHistory(1); +} + +void QWebContentsView::reload() +{ + Q_D(QWebContentsView); + d->adapter->reload(); +} + +void QWebContentsView::stop() +{ + Q_D(QWebContentsView); + d->adapter->stop(); +} + +#include "moc_qwebcontentsview.cpp" diff --git a/lib/widgets/Api/qwebcontentsview.h b/lib/widgets/Api/qwebcontentsview.h new file mode 100644 index 000000000..92f41c6a6 --- /dev/null +++ b/lib/widgets/Api/qwebcontentsview.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBCONTESTSVIEW_H +#define QWEBCONTESTSVIEW_H + +#include <qtwebengineglobal.h> + +#include <QWidget> +#include <QScopedPointer> + +class QWebContentsViewPrivate; + +class QWEBENGINEWIDGETS_EXPORT QWebContentsView : public QWidget { + Q_OBJECT +public: + QWebContentsView(); + ~QWebContentsView(); + + void load(const QUrl& url); + bool canGoBack() const; + bool canGoForward() const; + +public Q_SLOTS: + void back(); + void forward(); + void reload(); + void stop(); + +Q_SIGNALS: + void loadFinished(bool ok); + void loadStarted(); + void titleChanged(const QString& title); + void urlChanged(const QUrl& url); + +private: + Q_DECLARE_PRIVATE(QWebContentsView); + QScopedPointer<QWebContentsViewPrivate> d_ptr; +}; + +#endif // QWEBCONTESTSVIEW_H diff --git a/lib/widgets/Api/qwebcontentsview_p.h b/lib/widgets/Api/qwebcontentsview_p.h new file mode 100644 index 000000000..ba3739c4b --- /dev/null +++ b/lib/widgets/Api/qwebcontentsview_p.h @@ -0,0 +1,70 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QWEBCONTESTSVIEWPRIVATE_H +#define QWEBCONTESTSVIEWPRIVATE_H + +#include "web_contents_adapter_client.h" + +#include <QScopedPointer> + +class QWebContentsView; +class RenderWidgetHostViewQtDelegate; +class WebContentsAdapter; + +class QWebContentsViewPrivate : public WebContentsAdapterClient +{ + Q_DECLARE_PUBLIC(QWebContentsView) + QWebContentsView *q_ptr; + +public: + QWebContentsViewPrivate(); + + virtual RenderWidgetHostViewQtDelegate* CreateRenderWidgetHostViewQtDelegate(RenderWidgetHostViewQt *) Q_DECL_OVERRIDE; + virtual void titleChanged(const QString&) Q_DECL_OVERRIDE; + virtual void urlChanged(const QUrl&) Q_DECL_OVERRIDE; + virtual void loadingStateChanged() Q_DECL_OVERRIDE; + + bool m_isLoading; + QScopedPointer<WebContentsAdapter> adapter; +}; + +#endif diff --git a/lib/widgets/render_widget_host_view_qt_delegate_widget.cpp b/lib/widgets/render_widget_host_view_qt_delegate_widget.cpp new file mode 100644 index 000000000..d90190edb --- /dev/null +++ b/lib/widgets/render_widget_host_view_qt_delegate_widget.cpp @@ -0,0 +1,114 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "render_widget_host_view_qt_delegate_widget.h" + +#include <QResizeEvent> +#include <QPainter> +#include <QPaintEvent> + +RenderWidgetHostViewQtDelegateWidget::RenderWidgetHostViewQtDelegateWidget(QWidget *parent) + : QWidget(parent) +{ + setFocusPolicy(Qt::ClickFocus); + setAttribute(Qt::WA_AcceptTouchEvents); + setAttribute(Qt::WA_OpaquePaintEvent); +} + +QRectF RenderWidgetHostViewQtDelegateWidget::screenRect() const +{ + return QRectF(x(), y(), width(), height()); +} + +void RenderWidgetHostViewQtDelegateWidget::setKeyboardFocus() +{ + setFocus(); +} + +bool RenderWidgetHostViewQtDelegateWidget::hasKeyboardFocus() +{ + return hasFocus(); +} + +void RenderWidgetHostViewQtDelegateWidget::show() +{ + QWidget::show(); +} + +void RenderWidgetHostViewQtDelegateWidget::hide() +{ + QWidget::hide(); +} + +bool RenderWidgetHostViewQtDelegateWidget::isVisible() const +{ + return QWidget::isVisible(); +} + +QWindow* RenderWidgetHostViewQtDelegateWidget::window() const +{ + return QWidget::windowHandle(); +} + +void RenderWidgetHostViewQtDelegateWidget::update(const QRect& rect) +{ + QWidget::update(rect); +} + +void RenderWidgetHostViewQtDelegateWidget::paintEvent(QPaintEvent * event) +{ + QPainter painter(this); + fetchBackingStore(); + paint(&painter, event->rect()); +} + +void RenderWidgetHostViewQtDelegateWidget::resizeEvent(QResizeEvent *resizeEvent) +{ + Q_UNUSED(resizeEvent); + notifyResize(); +} + +bool RenderWidgetHostViewQtDelegateWidget::event(QEvent *event) +{ + if (!forwardEvent(event)) + return QWidget::event(event); + return true; +} diff --git a/lib/widgets/render_widget_host_view_qt_delegate_widget.h b/lib/widgets/render_widget_host_view_qt_delegate_widget.h new file mode 100644 index 000000000..fbde05ce4 --- /dev/null +++ b/lib/widgets/render_widget_host_view_qt_delegate_widget.h @@ -0,0 +1,73 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the QtWebEngine module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H +#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_WIDGET_H + +#include "render_widget_host_view_qt_delegate.h" + +#include <QWidget> + +class BackingStoreQt; +class QWindow; + +class RenderWidgetHostViewQtDelegateWidget : public QWidget, public RenderWidgetHostViewQtDelegate +{ +public: + RenderWidgetHostViewQtDelegateWidget(QWidget *parent = 0); + + virtual QRectF screenRect() const; + virtual void setKeyboardFocus(); + virtual bool hasKeyboardFocus(); + virtual void show(); + virtual void hide(); + virtual bool isVisible() const; + virtual QWindow* window() const; + virtual void update(const QRect& rect = QRect()); + +protected: + void paintEvent(QPaintEvent * event); + bool event(QEvent *event); + void resizeEvent(QResizeEvent *resizeEvent); + +}; + +#endif diff --git a/lib/widgets/widgets.pro b/lib/widgets/widgets.pro new file mode 100644 index 000000000..351264d57 --- /dev/null +++ b/lib/widgets/widgets.pro @@ -0,0 +1,33 @@ +# Use Qt5 module system +load(qt_build_config) + +TEMPLATE = lib +TARGET = QtWebEngineWidgets + +MODULE = webenginewidgets + +# For our export macros +DEFINES += QT_BUILD_WEBENGINEWIDGETS_LIB + +QT += widgets + +# FIXME: all this should eventually be turned into QT += webenginecore +macx:LIBPATH = $$getOutDir()/$$getConfigDir() +else:LIBPATH = $$getOutDir()/$$getConfigDir()/lib +LIBS += -L$$LIBPATH -lQt5WebEngineCore +QMAKE_RPATHDIR += $$LIBPATH + +DESTDIR = $$LIBPATH + +INCLUDEPATH += ../ + +SOURCES = \ + Api/qwebcontentsview.cpp\ + render_widget_host_view_qt_delegate_widget.cpp + +HEADERS = \ + Api/qwebcontentsview.h \ + Api/qwebcontentsview_p.h \ + render_widget_host_view_qt_delegate_widget.h + +load(qt_module) |