/**************************************************************************** ** ** 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_quick.h" #include "qquickwebengineview_p.h" #include "qquickwebengineview_p_p.h" #include #include #include #include #include RenderWidgetHostViewQtDelegateQuick::RenderWidgetHostViewQtDelegateQuick(RenderWidgetHostViewQtDelegateClient *client, bool isPopup) : m_client(client) , m_isPopup(isPopup) , m_initialized(false) { setFlag(ItemHasContents); setAcceptedMouseButtons(Qt::AllButtons); setAcceptHoverEvents(true); if (isPopup) return; setFocus(true); setActiveFocusOnTab(true); setFlag(QQuickItem::ItemIsFocusScope); } void RenderWidgetHostViewQtDelegateQuick::initAsChild(WebContentsAdapterClient* container) { QQuickWebEngineViewPrivate *viewPrivate = static_cast(container); setParentItem(viewPrivate->q_func()); setSize(viewPrivate->q_func()->boundingRect().size()); m_initialized = true; } void RenderWidgetHostViewQtDelegateQuick::initAsPopup(const QRect &r) { Q_ASSERT(m_isPopup && parentItem()); QRectF rect(parentItem()->mapRectFromScene(r)); setX(rect.x()); setY(rect.y()); setWidth(rect.width()); setHeight(rect.height()); setVisible(true); m_initialized = true; } QRectF RenderWidgetHostViewQtDelegateQuick::screenRect() const { QPointF pos = mapToScene(QPointF(0,0)); return QRectF(pos.x(), pos.y(), width(), height()); } void RenderWidgetHostViewQtDelegateQuick::setKeyboardFocus() { setFocus(true); } bool RenderWidgetHostViewQtDelegateQuick::hasKeyboardFocus() { return hasFocus(); } void RenderWidgetHostViewQtDelegateQuick::show() { setVisible(true); } void RenderWidgetHostViewQtDelegateQuick::hide() { setVisible(false); } bool RenderWidgetHostViewQtDelegateQuick::isVisible() const { return QQuickItem::isVisible(); } QWindow* RenderWidgetHostViewQtDelegateQuick::window() const { return QQuickItem::window(); } void RenderWidgetHostViewQtDelegateQuick::update() { QQuickItem::update(); } void RenderWidgetHostViewQtDelegateQuick::updateCursor(const QCursor &cursor) { setCursor(cursor); } void RenderWidgetHostViewQtDelegateQuick::resize(int width, int height) { setSize(QSizeF(width, height)); } void RenderWidgetHostViewQtDelegateQuick::inputMethodStateChanged(bool editorVisible) { if (qApp->inputMethod()->isVisible() == editorVisible) return; setFlag(QQuickItem::ItemAcceptsInputMethod, editorVisible); qApp->inputMethod()->update(Qt::ImQueryInput | Qt::ImEnabled | Qt::ImHints); qApp->inputMethod()->setVisible(editorVisible); } void RenderWidgetHostViewQtDelegateQuick::focusInEvent(QFocusEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::focusOutEvent(QFocusEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::mousePressEvent(QMouseEvent *event) { if (!m_isPopup) forceActiveFocus(); m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::mouseMoveEvent(QMouseEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::mouseReleaseEvent(QMouseEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::keyPressEvent(QKeyEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::keyReleaseEvent(QKeyEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::wheelEvent(QWheelEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::touchEvent(QTouchEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::hoverMoveEvent(QHoverEvent *event) { m_client->forwardEvent(event); } QVariant RenderWidgetHostViewQtDelegateQuick::inputMethodQuery(Qt::InputMethodQuery query) const { return m_client->inputMethodQuery(query); } void RenderWidgetHostViewQtDelegateQuick::inputMethodEvent(QInputMethodEvent *event) { m_client->forwardEvent(event); } void RenderWidgetHostViewQtDelegateQuick::geometryChanged(const QRectF &newGeometry, const QRectF &oldGeometry) { QQuickItem::geometryChanged(newGeometry, oldGeometry); m_client->notifyResize(); } void RenderWidgetHostViewQtDelegateQuick::itemChange(ItemChange change, const ItemChangeData &value) { QQuickItem::itemChange(change, value); if (m_initialized && change == QQuickItem::ItemSceneChange) m_client->windowChanged(); } QSGNode *RenderWidgetHostViewQtDelegateQuick::updatePaintNode(QSGNode *oldNode, UpdatePaintNodeData *) { return m_client->updatePaintNode(oldNode, QQuickWindowPrivate::get(QQuickItem::window())->context); }