diff options
Diffstat (limited to 'src/core/render_widget_host_view_qt_delegate_client.cpp')
-rw-r--r-- | src/core/render_widget_host_view_qt_delegate_client.cpp | 113 |
1 files changed, 32 insertions, 81 deletions
diff --git a/src/core/render_widget_host_view_qt_delegate_client.cpp b/src/core/render_widget_host_view_qt_delegate_client.cpp index 0f218ab6c..3e8cad669 100644 --- a/src/core/render_widget_host_view_qt_delegate_client.cpp +++ b/src/core/render_widget_host_view_qt_delegate_client.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2020 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/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 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2020 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "render_widget_host_view_qt_delegate_client.h" @@ -52,15 +16,12 @@ #include <QEvent> #include <QInputMethodEvent> -#include <QScopeGuard> -#include <QSGNode> +#include <QSet> #include <QStyleHints> #include <QTextFormat> #include <QVariant> -#include <private/qguiapplication_p.h> -#include <qpa/qplatforminputcontext.h> -#include <qpa/qplatformintegration.h> +#include <QtGui/private/qguiapplication_p.h> #include <QtGui/private/qinputcontrol_p.h> namespace QtWebEngineCore { @@ -94,7 +55,7 @@ QList<TouchPoint> RenderWidgetHostViewQtDelegateClient::mapTouchPointIds(const Q Q_ASSERT(output.size() == std::accumulate(output.cbegin(), output.cend(), QSet<int>(), [] (QSet<int> s, const TouchPoint &p) { s.insert(p.second.id()); return s; }).size()); - for (auto &&point : qAsConst(input)) + for (auto &&point : std::as_const(input)) if (point.state() == QEventPoint::Released) m_touchIdMapping.remove(point.id()); @@ -202,11 +163,6 @@ RenderWidgetHostViewQtDelegateClient::RenderWidgetHostViewQtDelegateClient( : m_rwhv(rwhv) { Q_ASSERT(rwhv); - - const QPlatformInputContext *context = - QGuiApplicationPrivate::platformIntegration()->inputContext(); - m_imeHasHiddenTextCapability = - context && context->hasCapability(QPlatformInputContext::HiddenTextCapability); } Compositor::Id RenderWidgetHostViewQtDelegateClient::compositorId() @@ -242,7 +198,7 @@ void RenderWidgetHostViewQtDelegateClient::visualPropertiesChanged() m_rwhv->host()->SendScreenRects(); if (m_viewRectInDips.size() != oldViewRect.size() || screenInfoChanged) - m_rwhv->synchronizeVisualProperties(base::nullopt); + m_rwhv->synchronizeVisualProperties(absl::nullopt); } bool RenderWidgetHostViewQtDelegateClient::forwardEvent(QEvent *event) @@ -252,7 +208,7 @@ bool RenderWidgetHostViewQtDelegateClient::forwardEvent(QEvent *event) switch (event->type()) { case QEvent::ShortcutOverride: { QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event); - + event->ignore(); auto acceptKeyOutOfInputField = [](QKeyEvent *keyEvent) -> bool { #ifdef Q_OS_MACOS // Check if a shortcut is registered for this key sequence. @@ -336,9 +292,13 @@ bool RenderWidgetHostViewQtDelegateClient::forwardEvent(QEvent *event) handleHoverEvent(static_cast<QHoverEvent *>(event)); break; case QEvent::FocusIn: - case QEvent::FocusOut: - handleFocusEvent(static_cast<QFocusEvent *>(event)); - break; + case QEvent::FocusOut: { + // Focus in/out events for popup event do not mean 'parent' focus change + // and should not be handled by Chromium + QFocusEvent *e = static_cast<QFocusEvent *>(event); + if (e->reason() != Qt::PopupFocusReason) + handleFocusEvent(e); + } break; case QEvent::InputMethod: handleInputMethodEvent(static_cast<QInputMethodEvent *>(event)); break; @@ -365,17 +325,8 @@ bool RenderWidgetHostViewQtDelegateClient::forwardEvent(QEvent *event) QVariant RenderWidgetHostViewQtDelegateClient::inputMethodQuery(Qt::InputMethodQuery query) { switch (query) { - case Qt::ImEnabled: { - ui::TextInputType type = m_rwhv->getTextInputType(); - bool editorVisible = type != ui::TEXT_INPUT_TYPE_NONE; - // IME manager should disable composition on input fields with ImhHiddenText hint if - // supported - if (m_imeHasHiddenTextCapability) - return QVariant(editorVisible); - - bool passwordInput = type == ui::TEXT_INPUT_TYPE_PASSWORD; - return QVariant(editorVisible && !passwordInput); - } + case Qt::ImEnabled: + return QVariant(m_rwhv->getTextInputType() != ui::TEXT_INPUT_TYPE_NONE); case Qt::ImFont: // TODO: Implement this return QVariant(); @@ -393,6 +344,7 @@ QVariant RenderWidgetHostViewQtDelegateClient::inputMethodQuery(Qt::InputMethodQ } return QVariant(); } + case Qt::ImAbsolutePosition: case Qt::ImCursorPosition: return m_cursorPosition; case Qt::ImAnchorPosition: @@ -457,6 +409,7 @@ void RenderWidgetHostViewQtDelegateClient::handlePointerEvent(T *event) webEvent.movement_x = event->globalPosition().x() - m_previousMousePosition.x(); webEvent.movement_y = event->globalPosition().y() - m_previousMousePosition.y(); + webEvent.is_raw_movement_event = true; if (m_rwhv->IsMouseLocked()) QCursor::setPos(m_previousMousePosition); @@ -487,12 +440,6 @@ void RenderWidgetHostViewQtDelegateClient::handleMouseEvent(QMouseEvent *event) if (event->type() == QEvent::MouseButtonRelease) m_mouseButtonPressed--; - // Don't forward mouse events synthesized by the system, which are caused by genuine touch - // events. Chromium would then process for e.g. a mouse click handler twice, once due to the - // system synthesized mouse event, and another time due to a touch-to-gesture-to-mouse - // transformation done by Chromium. - if (event->source() == Qt::MouseEventSynthesizedBySystem) - return; handlePointerEvent<QMouseEvent>(event); } @@ -529,6 +476,9 @@ void RenderWidgetHostViewQtDelegateClient::handleKeyEvent(QKeyEvent *event) if (event->type() == QEvent::KeyRelease && event->isAutoRepeat()) return; + if (!m_rwhv->GetFocusedWidget()) + return; + content::NativeWebKeyboardEvent webEvent = WebEventFactory::toWebKeyboardEvent(event); if (webEvent.GetType() == blink::WebInputEvent::Type::kRawKeyDown && !m_editCommand.empty()) { ui::LatencyInfo latency; @@ -542,14 +492,14 @@ void RenderWidgetHostViewQtDelegateClient::handleKeyEvent(QKeyEvent *event) bool keyDownTextInsertion = webEvent.GetType() == blink::WebInputEvent::Type::kRawKeyDown && webEvent.text[0]; - webEvent.skip_in_browser = keyDownTextInsertion; + webEvent.skip_if_unhandled = keyDownTextInsertion; m_rwhv->GetFocusedWidget()->ForwardKeyboardEvent(webEvent); if (keyDownTextInsertion) { // Blink won't consume the RawKeyDown, but rather the Char event in this case. // The RawKeyDown is skipped on the way back (see above). // The same os_event will be set on both NativeWebKeyboardEvents. - webEvent.skip_in_browser = false; + webEvent.skip_if_unhandled = false; webEvent.SetType(blink::WebInputEvent::Type::kChar); m_rwhv->GetFocusedWidget()->ForwardKeyboardEvent(webEvent); } @@ -572,12 +522,12 @@ void RenderWidgetHostViewQtDelegateClient::handleTouchEvent(QTouchEvent *event) // Calculate a delta between event timestamps and Now() on the first received event, and // apply this delta to all successive events. This delta is most likely smaller than it // should by calculating it here but this will hopefully cause less than one frame of delay. - base::TimeTicks eventTimestamp = base::TimeTicks() + base::TimeDelta::FromMilliseconds(event->timestamp()); + base::TimeTicks eventTimestamp = base::TimeTicks() + base::Milliseconds(event->timestamp()); if (m_eventsToNowDelta == 0) m_eventsToNowDelta = (base::TimeTicks::Now() - eventTimestamp).InMicroseconds(); - eventTimestamp += base::TimeDelta::FromMicroseconds(m_eventsToNowDelta); + eventTimestamp += base::Microseconds(m_eventsToNowDelta); - auto touchPoints = mapTouchPointIds(event->touchPoints()); + auto touchPoints = mapTouchPointIds(event->points()); // Make sure that POINTER_DOWN action is delivered before MOVE, and MOVE before POINTER_UP std::sort(touchPoints.begin(), touchPoints.end(), [] (const TouchPoint &l, const TouchPoint &r) { return l.second.state() < r.second.state(); @@ -586,7 +536,7 @@ void RenderWidgetHostViewQtDelegateClient::handleTouchEvent(QTouchEvent *event) auto sc = qScopeGuard([&] () { switch (event->type()) { case QEvent::TouchCancel: - for (auto &&it : qAsConst(touchPoints)) + for (auto &&it : std::as_const(touchPoints)) m_touchIdMapping.remove(it.second.id()); Q_FALLTHROUGH(); @@ -605,13 +555,13 @@ void RenderWidgetHostViewQtDelegateClient::handleTouchEvent(QTouchEvent *event) // Check first if the touch event should be routed to the selectionController if (!touchPoints.isEmpty()) { switch (touchPoints[0].second.state()) { - case Qt::TouchPointPressed: + case QEventPoint::Pressed: action = ui::MotionEvent::Action::DOWN; break; - case Qt::TouchPointMoved: + case QEventPoint::Updated: action = ui::MotionEvent::Action::MOVE; break; - case Qt::TouchPointReleased: + case QEventPoint::Released: action = ui::MotionEvent::Action::UP; break; default: @@ -733,7 +683,8 @@ void RenderWidgetHostViewQtDelegateClient::handleGestureEvent(QNativeGestureEven { const Qt::NativeGestureType type = event->gestureType(); // These are the only supported gestures by Chromium so far. - if (type == Qt::ZoomNativeGesture || type == Qt::SmartZoomNativeGesture) { + if (type == Qt::ZoomNativeGesture || type == Qt::SmartZoomNativeGesture + || type == Qt::BeginNativeGesture || type == Qt::EndNativeGesture) { auto *hostDelegate = m_rwhv->host()->delegate(); if (hostDelegate && hostDelegate->GetInputEventRouter()) { auto webEvent = WebEventFactory::toWebGestureEvent(event); |