summaryrefslogtreecommitdiffstats
path: root/src/core/render_widget_host_view_qt.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/render_widget_host_view_qt.cpp')
-rw-r--r--src/core/render_widget_host_view_qt.cpp446
1 files changed, 179 insertions, 267 deletions
diff --git a/src/core/render_widget_host_view_qt.cpp b/src/core/render_widget_host_view_qt.cpp
index 3641398f6..0bb28bd37 100644
--- a/src/core/render_widget_host_view_qt.cpp
+++ b/src/core/render_widget_host_view_qt.cpp
@@ -39,47 +39,38 @@
#include "render_widget_host_view_qt.h"
-#include "common/qt_messages.h"
#include "browser_accessibility_manager_qt.h"
-#include "browser_accessibility_qt.h"
#include "chromium_overrides.h"
-#include "delegated_frame_node.h"
+#include "compositor.h"
#include "qtwebenginecoreglobal_p.h"
#include "render_widget_host_view_qt_delegate.h"
#include "type_conversion.h"
-#include "web_contents_adapter.h"
#include "web_contents_adapter_client.h"
#include "web_event_factory.h"
-#include "base/command_line.h"
-#include "components/viz/service/display/direct_renderer.h"
-#include "components/viz/service/frame_sinks/frame_sink_manager_impl.h"
+#include "components/viz/common/surfaces/frame_sink_id_allocator.h"
#include "content/browser/accessibility/browser_accessibility_state_impl.h"
-#include "content/browser/browser_main_loop.h"
#include "content/browser/frame_host/render_frame_host_impl.h"
#include "content/browser/frame_host/frame_tree.h"
#include "content/browser/renderer_host/render_view_host_impl.h"
#include "content/common/cursors/webcursor.h"
#include "content/common/input_messages.h"
-#include "content/public/browser/browser_accessibility_state.h"
-#include "content/public/browser/browser_thread.h"
-#include "content/public/common/content_switches.h"
#include "third_party/skia/include/core/SkColor.h"
-#include "third_party/WebKit/public/platform/WebColor.h"
-#include "third_party/WebKit/public/platform/WebCursorInfo.h"
-#include "ui/base/clipboard/scoped_clipboard_writer.h"
-#include "ui/base/resource/resource_bundle.h"
+#include "third_party/blink/public/platform/web_cursor_info.h"
#include "ui/events/blink/blink_event_util.h"
#include "ui/events/event.h"
#include "ui/events/gesture_detection/gesture_provider_config_helper.h"
#include "ui/events/gesture_detection/motion_event.h"
-#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/gfx/image/image_skia.h"
+
+#if defined(USE_OZONE)
+#include "ui/base/clipboard/scoped_clipboard_writer.h"
+#endif
#if defined(USE_AURA)
#include "ui/base/cursor/cursor.h"
#include "ui/base/cursor/cursors_aura.h"
+#include "ui/base/resource/resource_bundle.h"
#endif
#include <private/qguiapplication_p.h>
@@ -99,9 +90,7 @@
#include <QVariant>
#include <QWheelEvent>
#include <QWindow>
-#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
#include <QtGui/private/qinputcontrol_p.h>
-#endif
#include <QtGui/qaccessible.h>
namespace QtWebEngineCore {
@@ -117,14 +106,10 @@ enum ImStateFlags {
static inline ui::LatencyInfo CreateLatencyInfo(const blink::WebInputEvent& event) {
ui::LatencyInfo latency_info;
// The latency number should only be added if the timestamp is valid.
- if (event.TimeStampSeconds()) {
- const int64_t time_micros = static_cast<int64_t>(
- event.TimeStampSeconds() * base::Time::kMicrosecondsPerSecond);
+ if (!event.TimeStamp().is_null()) {
latency_info.AddLatencyNumberWithTimestamp(
ui::INPUT_EVENT_LATENCY_ORIGINAL_COMPONENT,
- 0,
- 0,
- base::TimeTicks() + base::TimeDelta::FromMicroseconds(time_micros),
+ event.TimeStamp(),
1);
}
return latency_info;
@@ -191,55 +176,7 @@ static inline bool compareTouchPoints(const QTouchEvent::TouchPoint &lhs, const
static inline bool isCommonTextEditShortcut(const QKeyEvent *ke)
{
-#if QT_VERSION >= QT_VERSION_CHECK(5, 9, 0)
return QInputControl::isCommonTextEditShortcut(ke);
-#else
- if (ke->modifiers() == Qt::NoModifier
- || ke->modifiers() == Qt::ShiftModifier
- || ke->modifiers() == Qt::KeypadModifier) {
- if (ke->key() < Qt::Key_Escape) {
- return true;
- } else {
- switch (ke->key()) {
- case Qt::Key_Return:
- case Qt::Key_Enter:
- case Qt::Key_Delete:
- case Qt::Key_Home:
- case Qt::Key_End:
- case Qt::Key_Backspace:
- case Qt::Key_Left:
- case Qt::Key_Right:
- case Qt::Key_Up:
- case Qt::Key_Down:
- case Qt::Key_Tab:
- return true;
- default:
- break;
- }
- }
- } else if (ke->matches(QKeySequence::Copy)
- || ke->matches(QKeySequence::Paste)
- || ke->matches(QKeySequence::Cut)
- || ke->matches(QKeySequence::Redo)
- || ke->matches(QKeySequence::Undo)
- || ke->matches(QKeySequence::MoveToNextWord)
- || ke->matches(QKeySequence::MoveToPreviousWord)
- || ke->matches(QKeySequence::MoveToStartOfDocument)
- || ke->matches(QKeySequence::MoveToEndOfDocument)
- || ke->matches(QKeySequence::SelectNextWord)
- || ke->matches(QKeySequence::SelectPreviousWord)
- || ke->matches(QKeySequence::SelectStartOfLine)
- || ke->matches(QKeySequence::SelectEndOfLine)
- || ke->matches(QKeySequence::SelectStartOfBlock)
- || ke->matches(QKeySequence::SelectEndOfBlock)
- || ke->matches(QKeySequence::SelectStartOfDocument)
- || ke->matches(QKeySequence::SelectEndOfDocument)
- || ke->matches(QKeySequence::SelectAll)
- ) {
- return true;
- }
- return false;
-#endif
}
static uint32_t s_eventId = 0;
@@ -255,7 +192,7 @@ public:
, dpiScale(dpiScale)
{
// ACTION_DOWN and ACTION_UP must be accesssed through pointer_index 0
- Q_ASSERT((action != ACTION_DOWN && action != ACTION_UP) || index == 0);
+ Q_ASSERT((action != Action::DOWN && action != Action::UP) || index == 0);
}
uint32_t GetUniqueEventId() const override { return eventId; }
@@ -292,7 +229,7 @@ public:
float GetHistoricalTouchMajor(size_t pointer_index, size_t historical_index) const override { return 0; }
float GetHistoricalX(size_t pointer_index, size_t historical_index) const override { return 0; }
float GetHistoricalY(size_t pointer_index, size_t historical_index) const override { return 0; }
- ToolType GetToolType(size_t pointer_index) const override { return ui::MotionEvent::TOOL_TYPE_FINGER; }
+ ToolType GetToolType(size_t pointer_index) const override { return ui::MotionEvent::ToolType::FINGER; }
int GetButtonState() const override { return 0; }
private:
@@ -319,34 +256,25 @@ bool isAccessibilityEnabled() {
}
RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget)
- : m_host(content::RenderWidgetHostImpl::From(widget))
+ : content::RenderWidgetHostViewBase::RenderWidgetHostViewBase(widget)
, m_gestureProvider(QtGestureProviderConfig(), this)
, m_sendMotionActionDown(false)
, m_touchMotionStarted(false)
- , m_chromiumCompositorData(new ChromiumCompositorData)
- , m_needsDelegatedFrameAck(false)
+ , m_compositor(new Compositor)
, m_loadVisuallyCommittedState(NotCommitted)
, m_adapterClient(0)
- , m_rendererCompositorFrameSink(0)
, m_imeInProgress(false)
, m_receivedEmptyImeEvent(false)
- , m_initPending(false)
- , m_beginFrameSource(nullptr)
- , m_needsBeginFrames(false)
- , m_addedFrameObserver(false)
- , m_backgroundColor(SK_ColorWHITE)
, m_imState(0)
, m_anchorPositionWithinSelection(-1)
, m_cursorPositionWithinSelection(-1)
, m_cursorPosition(0)
, m_emptyPreviousSelection(true)
, m_wheelAckPending(false)
+ , m_pendingResize(false)
+ , m_mouseWheelPhaseHandler(this)
{
- auto* task_runner = base::ThreadTaskRunnerHandle::Get().get();
- m_beginFrameSource.reset(new viz::DelayBasedBeginFrameSource(
- base::MakeUnique<viz::DelayBasedTimeSource>(task_runner), 0));
-
- m_host->SetView(this);
+ host()->SetView(this);
#ifndef QT_NO_ACCESSIBILITY
if (isAccessibilityEnabled()) {
QAccessible::installActivationObserver(this);
@@ -360,6 +288,8 @@ RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost *widget
const QPlatformInputContext *context = QGuiApplicationPrivate::platformIntegration()->inputContext();
m_imeHasHiddenTextCapability = context && context->hasCapability(QPlatformInputContext::HiddenTextCapability);
+
+ m_localSurfaceId = m_localSurfaceIdAllocator.GenerateId();
}
RenderWidgetHostViewQt::~RenderWidgetHostViewQt()
@@ -376,6 +306,7 @@ RenderWidgetHostViewQt::~RenderWidgetHostViewQt()
void RenderWidgetHostViewQt::setDelegate(RenderWidgetHostViewQtDelegate* delegate)
{
m_delegate.reset(delegate);
+ m_compositor->setViewDelegate(delegate);
}
void RenderWidgetHostViewQt::setAdapterClient(WebContentsAdapterClient *adapterClient)
@@ -387,18 +318,10 @@ void RenderWidgetHostViewQt::setAdapterClient(WebContentsAdapterClient *adapterC
m_adapterClientDestroyedConnection = QObject::connect(adapterClient->holdingQObject(),
&QObject::destroyed, [this] {
m_adapterClient = nullptr; });
- if (m_initPending)
- InitAsChild(0);
}
void RenderWidgetHostViewQt::InitAsChild(gfx::NativeView)
{
- if (!m_adapterClient) {
- m_initPending = true;
- return;
- }
- m_initPending = false;
- m_delegate->initAsChild(m_adapterClient);
}
void RenderWidgetHostViewQt::InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect& rect)
@@ -410,11 +333,6 @@ void RenderWidgetHostViewQt::InitAsFullscreen(content::RenderWidgetHostView*)
{
}
-content::RenderWidgetHostImpl* RenderWidgetHostViewQt::GetRenderWidgetHostImpl() const
-{
- return m_host;
-}
-
void RenderWidgetHostViewQt::SetSize(const gfx::Size& size)
{
int width = size.width();
@@ -431,11 +349,7 @@ void RenderWidgetHostViewQt::SetBounds(const gfx::Rect& screenRect)
SetSize(screenRect.size());
}
-gfx::Vector2dF RenderWidgetHostViewQt::GetLastScrollOffset() const {
- return m_lastScrollOffset;
-}
-
-gfx::Size RenderWidgetHostViewQt::GetPhysicalBackingSize() const
+gfx::Size RenderWidgetHostViewQt::GetCompositorViewportPixelSize() const
{
if (!m_delegate || !m_delegate->window() || !m_delegate->window()->screen())
return gfx::Size();
@@ -479,7 +393,7 @@ void RenderWidgetHostViewQt::Focus()
{
if (!IsPopup())
m_delegate->setKeyboardFocus();
- m_host->Focus();
+ host()->Focus();
}
bool RenderWidgetHostViewQt::HasFocus() const
@@ -517,27 +431,17 @@ gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const
return gfx::BoundingRect(p1, p2);
}
-SkColor RenderWidgetHostViewQt::background_color() const
-{
- return m_backgroundColor;
-}
-
-void RenderWidgetHostViewQt::SetBackgroundColor(SkColor color)
+void RenderWidgetHostViewQt::UpdateBackgroundColor()
{
- if (m_backgroundColor == color)
- return;
- m_backgroundColor = color;
- // Set the background of the compositor if necessary
- m_delegate->setClearColor(toQt(color));
- // Set the background of the blink::FrameView
- m_host->SetBackgroundOpaque(SkColorGetA(color) == SK_AlphaOPAQUE);
- m_host->Send(new RenderViewObserverQt_SetBackgroundColor(m_host->GetRoutingID(), color));
+ auto color = GetBackgroundColor();
+ if (color) {
+ m_delegate->setClearColor(toQt(*color));
+ }
}
// Return value indicates whether the mouse is locked successfully or not.
bool RenderWidgetHostViewQt::LockMouse()
{
- mouse_locked_ = true;
m_previousMousePosition = QCursor::pos();
m_delegate->lockMouse();
qApp->setOverrideCursor(Qt::BlankCursor);
@@ -546,14 +450,18 @@ bool RenderWidgetHostViewQt::LockMouse()
void RenderWidgetHostViewQt::UnlockMouse()
{
- mouse_locked_ = false;
m_delegate->unlockMouse();
qApp->restoreOverrideCursor();
- m_host->LostMouseLock();
+ host()->LostMouseLock();
}
void RenderWidgetHostViewQt::UpdateCursor(const content::WebCursor &webCursor)
{
+ DisplayCursor(webCursor);
+}
+
+void RenderWidgetHostViewQt::DisplayCursor(const content::WebCursor &webCursor)
+{
content::CursorInfo cursorInfo;
webCursor.GetCursorInfo(&cursorInfo);
Qt::CursorShape shape = Qt::ArrowCursor;
@@ -620,6 +528,12 @@ void RenderWidgetHostViewQt::UpdateCursor(const content::WebCursor &webCursor)
case blink::WebCursorInfo::kTypeProgress:
shape = Qt::BusyCursor;
break;
+ case blink::WebCursorInfo::kTypeCopy:
+ shape = Qt::DragCopyCursor;
+ break;
+ case blink::WebCursorInfo::kTypeAlias:
+ shape = Qt::DragLinkCursor;
+ break;
#if defined(USE_AURA)
case blink::WebCursorInfo::kTypeVerticalText:
auraType = ui::CursorType::kVerticalText;
@@ -630,12 +544,6 @@ void RenderWidgetHostViewQt::UpdateCursor(const content::WebCursor &webCursor)
case blink::WebCursorInfo::kTypeContextMenu:
auraType = ui::CursorType::kContextMenu;
break;
- case blink::WebCursorInfo::kTypeAlias:
- auraType = ui::CursorType::kAlias;
- break;
- case blink::WebCursorInfo::kTypeCopy:
- auraType = ui::CursorType::kCopy;
- break;
case blink::WebCursorInfo::kTypeZoomIn:
auraType = ui::CursorType::kZoomIn;
break;
@@ -646,8 +554,6 @@ void RenderWidgetHostViewQt::UpdateCursor(const content::WebCursor &webCursor)
case blink::WebCursorInfo::kTypeVerticalText:
case blink::WebCursorInfo::kTypeCell:
case blink::WebCursorInfo::kTypeContextMenu:
- case blink::WebCursorInfo::kTypeAlias:
- case blink::WebCursorInfo::kTypeCopy:
case blink::WebCursorInfo::kTypeZoomIn:
case blink::WebCursorInfo::kTypeZoomOut:
// FIXME: Support on OS X
@@ -740,40 +646,26 @@ void RenderWidgetHostViewQt::Destroy()
void RenderWidgetHostViewQt::SetTooltipText(const base::string16 &tooltip_text)
{
- if (m_adapterClient)
- m_adapterClient->setToolTip(toQt(tooltip_text));
+ DisplayTooltipText(tooltip_text);
}
-bool RenderWidgetHostViewQt::HasAcceleratedSurface(const gfx::Size&)
+void RenderWidgetHostViewQt::DisplayTooltipText(const base::string16 &tooltip_text)
{
- return false;
+ if (m_adapterClient)
+ m_adapterClient->setToolTip(toQt(tooltip_text));
}
void RenderWidgetHostViewQt::DidCreateNewRendererCompositorFrameSink(viz::mojom::CompositorFrameSinkClient *frameSink)
{
- // Accumulated resources belong to the old RendererCompositorFrameSink and
- // should not be returned.
- m_resourcesToRelease.clear();
- m_rendererCompositorFrameSink = frameSink;
+ m_compositor->setFrameSinkClient(frameSink);
}
-void RenderWidgetHostViewQt::SubmitCompositorFrame(const viz::LocalSurfaceId &local_surface_id, viz::CompositorFrame frame, viz::mojom::HitTestRegionListPtr)
+void RenderWidgetHostViewQt::SubmitCompositorFrame(const viz::LocalSurfaceId &local_surface_id, viz::CompositorFrame frame, base::Optional<viz::HitTestRegionList>)
{
bool scrollOffsetChanged = (m_lastScrollOffset != frame.metadata.root_scroll_offset);
bool contentsSizeChanged = (m_lastContentsSize != frame.metadata.root_layer_size);
m_lastScrollOffset = frame.metadata.root_scroll_offset;
m_lastContentsSize = frame.metadata.root_layer_size;
- m_backgroundColor = frame.metadata.root_background_color;
- if (m_localSurfaceId != local_surface_id) {
- m_localSurfaceId = local_surface_id;
- // FIXME: update frame_size and device_scale_factor?
- // FIXME: showPrimarySurface()?
- }
- Q_ASSERT(!m_needsDelegatedFrameAck);
- m_needsDelegatedFrameAck = true;
- m_chromiumCompositorData->previousFrameData = std::move(m_chromiumCompositorData->frameData);
- m_chromiumCompositorData->frameDevicePixelRatio = frame.metadata.device_scale_factor;
- m_chromiumCompositorData->frameData = std::move(frame);
// Force to process swap messages
uint32_t frame_token = frame.metadata.frame_token;
@@ -783,9 +675,9 @@ void RenderWidgetHostViewQt::SubmitCompositorFrame(const viz::LocalSurfaceId &lo
// Support experimental.viewport.devicePixelRatio, see GetScreenInfo implementation below.
float dpiScale = this->dpiScale();
if (dpiScale != 0 && dpiScale != 1)
- m_chromiumCompositorData->frameDevicePixelRatio /= dpiScale;
+ frame.metadata.device_scale_factor /= dpiScale;
- m_delegate->update();
+ m_compositor->submitFrame(std::move(frame));
if (m_loadVisuallyCommittedState == NotCommitted) {
m_loadVisuallyCommittedState = DidFirstCompositorFrameSwap;
@@ -800,9 +692,9 @@ void RenderWidgetHostViewQt::SubmitCompositorFrame(const viz::LocalSurfaceId &lo
m_adapterClient->updateContentsSize(toQt(m_lastContentsSize));
}
-void RenderWidgetHostViewQt::GetScreenInfo(content::ScreenInfo* results)
+void RenderWidgetHostViewQt::GetScreenInfo(content::ScreenInfo *results) const
{
- QWindow* window = m_delegate->window();
+ QWindow *window = m_delegate->window();
if (!window)
return;
GetScreenInfoFromNativeWindow(window, results);
@@ -886,13 +778,13 @@ void RenderWidgetHostViewQt::OnTextSelectionChanged(content::TextInputManager *t
if (!selection)
return;
-#if defined(USE_X11)
+#if defined(USE_OZONE)
if (!selection->selected_text().empty() && selection->user_initiated()) {
// Set the CLIPBOARD_TYPE_SELECTION to the ui::Clipboard.
ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_SELECTION);
clipboard_writer.WriteText(selection->selected_text());
}
-#endif // defined(USE_X11)
+#endif // defined(USE_OZONE)
m_imState |= ImStateFlags::TextSelectionUpdated;
if (m_imState == ImStateFlags::AllFlags
@@ -972,60 +864,72 @@ void RenderWidgetHostViewQt::selectionChanged()
void RenderWidgetHostViewQt::OnGestureEvent(const ui::GestureEventData& gesture)
{
- m_host->ForwardGestureEvent(ui::CreateWebGestureEventFromGestureEventData(gesture));
+ host()->ForwardGestureEvent(ui::CreateWebGestureEventFromGestureEventData(gesture));
}
-QSGNode *RenderWidgetHostViewQt::updatePaintNode(QSGNode *oldNode)
+viz::ScopedSurfaceIdAllocator RenderWidgetHostViewQt::DidUpdateVisualProperties(const cc::RenderFrameMetadata &metadata)
{
- DelegatedFrameNode *frameNode = static_cast<DelegatedFrameNode *>(oldNode);
- if (!frameNode)
- frameNode = new DelegatedFrameNode;
+ base::OnceCallback<void()> allocation_task =
+ base::BindOnce(&RenderWidgetHostViewQt::OnDidUpdateVisualPropertiesComplete,
+ base::Unretained(this), metadata);
+ return viz::ScopedSurfaceIdAllocator(std::move(allocation_task));
+}
- frameNode->commit(m_chromiumCompositorData.data(), &m_resourcesToRelease, m_delegate.get());
+void RenderWidgetHostViewQt::OnDidUpdateVisualPropertiesComplete(const cc::RenderFrameMetadata &metadata)
+{
+ if (metadata.local_surface_id)
+ m_localSurfaceIdAllocator.UpdateFromChild(*metadata.local_surface_id);
- // This is possibly called from the Qt render thread, post the ack back to the UI
- // to tell the child compositors to release resources and trigger a new frame.
- if (m_needsDelegatedFrameAck) {
- m_needsDelegatedFrameAck = false;
- content::BrowserThread::PostTask(content::BrowserThread::UI, FROM_HERE,
- base::Bind(&RenderWidgetHostViewQt::sendDelegatedFrameAck, AsWeakPtr()));
+ m_localSurfaceId = m_localSurfaceIdAllocator.GenerateId();
+ host()->SendScreenRects();
+ if (m_pendingResize) {
+ if (host()->SynchronizeVisualProperties())
+ m_pendingResize = false;
}
+}
- return frameNode;
+QSGNode *RenderWidgetHostViewQt::updatePaintNode(QSGNode *oldNode)
+{
+ if (m_pendingResize && host()) {
+ if (host()->SynchronizeVisualProperties())
+ m_pendingResize = false;
+ }
+ return m_compositor->updatePaintNode(oldNode);
}
void RenderWidgetHostViewQt::notifyResize()
{
- m_host->WasResized();
- m_host->SendScreenRects();
+ m_pendingResize = true;
+ if (host()->SynchronizeVisualProperties())
+ m_pendingResize = false;
}
void RenderWidgetHostViewQt::notifyShown()
{
- m_host->WasShown(ui::LatencyInfo());
+ host()->WasShown(false);
}
void RenderWidgetHostViewQt::notifyHidden()
{
- m_host->WasHidden();
+ host()->WasHidden();
}
void RenderWidgetHostViewQt::windowBoundsChanged()
{
- m_host->SendScreenRects();
- if (m_delegate->window())
- m_host->NotifyScreenInfoChanged();
+ host()->SendScreenRects();
+ if (m_delegate && m_delegate->window())
+ host()->NotifyScreenInfoChanged();
}
void RenderWidgetHostViewQt::windowChanged()
{
- if (m_delegate->window())
- m_host->NotifyScreenInfoChanged();
+ if (m_delegate && m_delegate->window())
+ host()->NotifyScreenInfoChanged();
}
bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
{
- Q_ASSERT(m_host->GetView());
+ Q_ASSERT(host()->GetView());
switch (event->type()) {
case QEvent::ShortcutOverride: {
@@ -1067,7 +971,8 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
return false;
}
case QEvent::MouseButtonPress:
- Focus(); // Fall through.
+ Focus();
+ Q_FALLTHROUGH();
case QEvent::MouseButtonRelease:
case QEvent::MouseMove:
// Skip second MouseMove event when a window is being adopted, so that Chromium
@@ -1088,7 +993,8 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
handleWheelEvent(static_cast<QWheelEvent*>(event));
break;
case QEvent::TouchBegin:
- Focus(); // Fall through.
+ Focus();
+ Q_FALLTHROUGH();
case QEvent::TouchUpdate:
case QEvent::TouchEnd:
case QEvent::TouchCancel:
@@ -1096,7 +1002,8 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
break;
#if QT_CONFIG(tabletevent)
case QEvent::TabletPress:
- Focus(); // Fall through.
+ Focus();
+ Q_FALLTHROUGH();
case QEvent::TabletRelease:
case QEvent::TabletMove:
handleTabletEvent(static_cast<QTabletEvent*>(event));
@@ -1122,7 +1029,7 @@ bool RenderWidgetHostViewQt::forwardEvent(QEvent *event)
break;
case QEvent::HoverLeave:
case QEvent::Leave:
- m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(event));
+ host()->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(event));
break;
default:
return false;
@@ -1149,10 +1056,12 @@ QVariant RenderWidgetHostViewQt::inputMethodQuery(Qt::InputMethodQuery query)
case Qt::ImCursorRectangle: {
if (text_input_manager_) {
if (auto *region = text_input_manager_->GetSelectionRegion()) {
- gfx::Rect caretRect = gfx::RectBetweenSelectionBounds(region->anchor, region->focus);
- if (caretRect.width() == 0)
- caretRect.set_width(1); // IME API on Windows expects a width > 0
- return toQt(caretRect);
+ if (region->focus.GetHeight() > 0) {
+ gfx::Rect caretRect = gfx::RectBetweenSelectionBounds(region->anchor, region->focus);
+ if (caretRect.width() == 0)
+ caretRect.set_width(1); // IME API on Windows expects a width > 0
+ return toQt(caretRect);
+ }
}
}
return QVariant();
@@ -1180,8 +1089,8 @@ void RenderWidgetHostViewQt::closePopup()
// We notify the popup to be closed by telling it that it lost focus. WebKit does the rest
// (hiding the widget and automatic memory cleanup via
// RenderWidget::CloseWidgetSoon() -> RenderWidgetHostImpl::ShutdownAndDestroyWidget(true).
- m_host->SetActive(false);
- m_host->Blur();
+ host()->SetActive(false);
+ host()->Blur();
}
void RenderWidgetHostViewQt::ProcessAckedTouchEvent(const content::TouchEventWithLatencyInfo &touch, content::InputEventAckState ack_result) {
@@ -1190,15 +1099,6 @@ void RenderWidgetHostViewQt::ProcessAckedTouchEvent(const content::TouchEventWit
m_gestureProvider.OnTouchEventAck(touch.event.unique_touch_event_id, eventConsumed, /*fixme: ?? */false);
}
-void RenderWidgetHostViewQt::sendDelegatedFrameAck()
-{
- m_beginFrameSource->DidFinishFrame(this);
- std::vector<viz::ReturnedResource> resources;
- m_resourcesToRelease.swap(resources);
- if (m_rendererCompositorFrameSink)
- m_rendererCompositorFrameSink->DidReceiveCompositorFrameAck(resources);
-}
-
void RenderWidgetHostViewQt::processMotionEvent(const ui::MotionEvent &motionEvent)
{
auto result = m_gestureProvider.OnTouchEvent(motionEvent);
@@ -1206,8 +1106,9 @@ void RenderWidgetHostViewQt::processMotionEvent(const ui::MotionEvent &motionEve
return;
blink::WebTouchEvent touchEvent = ui::CreateWebTouchEventFromMotionEvent(motionEvent,
- result.moved_beyond_slop_region);
- m_host->ForwardTouchEventWithLatencyInfo(touchEvent, CreateLatencyInfo(touchEvent));
+ result.moved_beyond_slop_region,
+ false /*hovering, FIXME ?*/);
+ host()->ForwardTouchEventWithLatencyInfo(touchEvent, CreateLatencyInfo(touchEvent));
}
QList<QTouchEvent::TouchPoint> RenderWidgetHostViewQt::mapTouchPointIds(const QList<QTouchEvent::TouchPoint> &inputPoints)
@@ -1260,11 +1161,11 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
// We're getting the composition result in a key event.
if (ev->key() != 0) {
// The key event is not a result of an IME composition. Cancel IME.
- m_host->ImeCancelComposition();
+ host()->ImeCancelComposition();
m_receivedEmptyImeEvent = false;
} else {
if (ev->type() == QEvent::KeyRelease) {
- m_host->ImeCommitText(toString16(ev->text()),
+ host()->ImeCommitText(toString16(ev->text()),
std::vector<ui::ImeTextSpan>(),
gfx::Range::InvalidRange(),
0);
@@ -1282,13 +1183,13 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
content::EditCommands commands;
commands.emplace_back(m_editCommand, "");
m_editCommand.clear();
- m_host->ForwardKeyboardEventWithCommands(webEvent, latency, &commands, nullptr);
+ host()->ForwardKeyboardEventWithCommands(webEvent, latency, &commands, nullptr);
return;
}
bool keyDownTextInsertion = webEvent.GetType() == blink::WebInputEvent::kRawKeyDown && webEvent.text[0];
webEvent.skip_in_browser = keyDownTextInsertion;
- m_host->ForwardKeyboardEvent(webEvent);
+ host()->ForwardKeyboardEvent(webEvent);
if (keyDownTextInsertion) {
// Blink won't consume the RawKeyDown, but rather the Char event in this case.
@@ -1296,7 +1197,7 @@ void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
// The same os_event will be set on both NativeWebKeyboardEvents.
webEvent.skip_in_browser = false;
webEvent.SetType(blink::WebInputEvent::kChar);
- m_host->ForwardKeyboardEvent(webEvent);
+ host()->ForwardKeyboardEvent(webEvent);
}
}
@@ -1305,7 +1206,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
// Reset input manager state
m_imState = 0;
- if (!m_host)
+ if (!host())
return;
QString commitString = ev->commitString();
@@ -1340,7 +1241,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
if (format.underlineStyle() != QTextCharFormat::NoUnderline)
underlineColor = format.underlineColor();
- underlines.push_back(ui::ImeTextSpan(ui::ImeTextSpan::Type::kComposition, start, end, toSk(underlineColor), /*thick*/ false, SK_ColorTRANSPARENT));
+ underlines.push_back(ui::ImeTextSpan(ui::ImeTextSpan::Type::kComposition, start, end, ui::ImeTextSpan::Thickness::kThin, toSk(underlineColor), SK_ColorTRANSPARENT));
break;
}
case QInputMethodEvent::Cursor:
@@ -1419,7 +1320,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
m_receivedEmptyImeEvent = false;
if (m_imeInProgress) {
m_imeInProgress = false;
- m_host->ImeCancelComposition();
+ host()->ImeCancelComposition();
}
}
@@ -1430,7 +1331,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
// Finish compostion: insert or erase text.
if (!commitString.isEmpty() || replacementLength > 0) {
- m_host->ImeCommitText(toString16(commitString),
+ host()->ImeCommitText(toString16(commitString),
underlines,
replacementRange,
0);
@@ -1441,7 +1342,7 @@ void RenderWidgetHostViewQt::handleInputMethodEvent(QInputMethodEvent *ev)
// Be aware of that, we might get a commit string and a pre-edit string in a single event and
// this means a new composition.
if (!preeditString.isEmpty()) {
- m_host->ImeSetComposition(toString16(preeditString),
+ host()->ImeSetComposition(toString16(preeditString),
underlines,
replacementRange,
selectionRange.start(),
@@ -1477,8 +1378,10 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev)
{
if (!m_wheelAckPending) {
Q_ASSERT(m_pendingWheelEvents.isEmpty());
- m_wheelAckPending = true;
- m_host->ForwardWheelEvent(WebEventFactory::toWebWheelEvent(ev, dpiScale()));
+ blink::WebMouseWheelEvent webEvent = WebEventFactory::toWebWheelEvent(ev, dpiScale());
+ m_wheelAckPending = (webEvent.phase != blink::WebMouseWheelEvent::kPhaseEnded);
+ m_mouseWheelPhaseHandler.AddPhaseIfNeededAndScheduleEndEvent(webEvent, false);
+ host()->ForwardWheelEvent(webEvent);
return;
}
if (!m_pendingWheelEvents.isEmpty()) {
@@ -1489,16 +1392,26 @@ void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev)
m_pendingWheelEvents.append(WebEventFactory::toWebWheelEvent(ev, dpiScale()));
}
-void RenderWidgetHostViewQt::WheelEventAck(const blink::WebMouseWheelEvent &/*event*/, content::InputEventAckState /*ack_result*/)
+void RenderWidgetHostViewQt::WheelEventAck(const blink::WebMouseWheelEvent &event, content::InputEventAckState /*ack_result*/)
{
+ if (event.phase == blink::WebMouseWheelEvent::kPhaseEnded)
+ return;
+ Q_ASSERT(m_wheelAckPending);
m_wheelAckPending = false;
- if (!m_pendingWheelEvents.isEmpty()) {
- m_wheelAckPending = true;
- m_host->ForwardWheelEvent(m_pendingWheelEvents.takeFirst());
+ while (!m_pendingWheelEvents.isEmpty() && !m_wheelAckPending) {
+ blink::WebMouseWheelEvent webEvent = m_pendingWheelEvents.takeFirst();
+ m_wheelAckPending = (webEvent.phase != blink::WebMouseWheelEvent::kPhaseEnded);
+ m_mouseWheelPhaseHandler.AddPhaseIfNeededAndScheduleEndEvent(webEvent, false);
+ host()->ForwardWheelEvent(webEvent);
}
// TODO: We could forward unhandled wheelevents to our parent.
}
+content::MouseWheelPhaseHandler *RenderWidgetHostViewQt::GetMouseWheelPhaseHandler()
+{
+ return &m_mouseWheelPhaseHandler;
+}
+
void RenderWidgetHostViewQt::clearPreviousTouchMotionState()
{
m_previousTouchPoints.clear();
@@ -1511,7 +1424,7 @@ void RenderWidgetHostViewQt::handleGestureEvent(QNativeGestureEvent *ev)
const Qt::NativeGestureType type = ev->gestureType();
// These are the only supported gestures by Chromium so far.
if (type == Qt::ZoomNativeGesture || type == Qt::SmartZoomNativeGesture) {
- m_host->ForwardGestureEvent(WebEventFactory::toWebGestureEvent(
+ host()->ForwardGestureEvent(WebEventFactory::toWebGestureEvent(
ev,
static_cast<double>(dpiScale())));
}
@@ -1569,7 +1482,7 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
if (touchPoints.isEmpty())
touchPoints = m_previousTouchPoints;
clearPreviousTouchMotionState();
- MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::ACTION_CANCEL,
+ MotionEventQt cancelEvent(touchPoints, eventTimestamp, ui::MotionEvent::Action::CANCEL,
ev->modifiers(), dpiScale());
processMotionEvent(cancelEvent);
return;
@@ -1604,18 +1517,18 @@ void RenderWidgetHostViewQt::handleTouchEvent(QTouchEvent *ev)
switch (touchPoints[i].state()) {
case Qt::TouchPointPressed:
if (m_sendMotionActionDown) {
- action = ui::MotionEvent::ACTION_DOWN;
+ action = ui::MotionEvent::Action::DOWN;
m_sendMotionActionDown = false;
} else {
- action = ui::MotionEvent::ACTION_POINTER_DOWN;
+ action = ui::MotionEvent::Action::POINTER_DOWN;
}
break;
case Qt::TouchPointMoved:
- action = ui::MotionEvent::ACTION_MOVE;
+ action = ui::MotionEvent::Action::MOVE;
break;
case Qt::TouchPointReleased:
- action = touchPoints.size() > 1 ? ui::MotionEvent::ACTION_POINTER_UP :
- ui::MotionEvent::ACTION_UP;
+ action = touchPoints.size() > 1 ? ui::MotionEvent::Action::POINTER_UP :
+ ui::MotionEvent::Action::UP;
break;
default:
// Ignore Qt::TouchPointStationary
@@ -1681,20 +1594,20 @@ void RenderWidgetHostViewQt::handlePointerEvent(T *event)
#endif
}
- m_host->ForwardMouseEvent(webEvent);
+ host()->ForwardMouseEvent(webEvent);
}
void RenderWidgetHostViewQt::handleHoverEvent(QHoverEvent *ev)
{
- m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev, dpiScale()));
+ host()->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev, dpiScale()));
}
void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev)
{
if (ev->gotFocus()) {
- m_host->GotFocus();
- m_host->SetActive(true);
- content::RenderViewHostImpl *viewHost = content::RenderViewHostImpl::From(m_host);
+ host()->GotFocus();
+ host()->SetActive(true);
+ content::RenderViewHostImpl *viewHost = content::RenderViewHostImpl::From(host());
Q_ASSERT(viewHost);
if (ev->reason() == Qt::TabFocusReason)
viewHost->SetInitialFocus(false);
@@ -1702,52 +1615,20 @@ void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev)
viewHost->SetInitialFocus(true);
ev->accept();
} else if (ev->lostFocus()) {
- m_host->SetActive(false);
- m_host->Blur();
+ host()->SetActive(false);
+ host()->Blur();
ev->accept();
}
}
void RenderWidgetHostViewQt::SetNeedsBeginFrames(bool needs_begin_frames)
{
- m_needsBeginFrames = needs_begin_frames;
- updateNeedsBeginFramesInternal();
-}
-
-void RenderWidgetHostViewQt::updateNeedsBeginFramesInternal()
-{
- Q_ASSERT(m_beginFrameSource);
-
- if (m_addedFrameObserver == m_needsBeginFrames)
- return;
-
- if (m_needsBeginFrames)
- m_beginFrameSource->AddObserver(this);
- else
- m_beginFrameSource->RemoveObserver(this);
- m_addedFrameObserver = m_needsBeginFrames;
-}
-
-bool RenderWidgetHostViewQt::OnBeginFrameDerivedImpl(const viz::BeginFrameArgs& args)
-{
- m_beginFrameSource->OnUpdateVSyncParameters(args.frame_time, args.interval);
- if (m_rendererCompositorFrameSink)
- m_rendererCompositorFrameSink->OnBeginFrame(args);
- else // FIXME: is this else part ever needed?
- m_host->Send(new ViewMsg_BeginFrame(m_host->GetRoutingID(), args));
- return true;
-}
-
-void RenderWidgetHostViewQt::OnBeginFrameSourcePausedChanged(bool paused)
-{
- // Ignored for now. If the begin frame source is paused, the renderer
- // doesn't need to be informed about it and will just not receive more
- // begin frames.
+ m_compositor->setNeedsBeginFrames(needs_begin_frames);
}
content::RenderFrameHost *RenderWidgetHostViewQt::getFocusedFrameHost()
{
- content::RenderViewHostImpl *viewHost = content::RenderViewHostImpl::From(m_host);
+ content::RenderViewHostImpl *viewHost = content::RenderViewHostImpl::From(host());
if (!viewHost)
return nullptr;
@@ -1775,4 +1656,35 @@ viz::SurfaceId RenderWidgetHostViewQt::GetCurrentSurfaceId() const
return viz::SurfaceId();
}
+const viz::FrameSinkId &RenderWidgetHostViewQt::GetFrameSinkId() const
+{
+ return viz::FrameSinkIdAllocator::InvalidFrameSinkId();
+}
+
+const viz::LocalSurfaceId &RenderWidgetHostViewQt::GetLocalSurfaceId() const
+{
+ return m_localSurfaceId;
+}
+
+void RenderWidgetHostViewQt::TakeFallbackContentFrom(content::RenderWidgetHostView *view)
+{
+ DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)->IsRenderWidgetHostViewChildFrame());
+ DCHECK(!static_cast<RenderWidgetHostViewBase*>(view)->IsRenderWidgetHostViewGuest());
+ base::Optional<SkColor> color = view->GetBackgroundColor();
+ if (color)
+ SetBackgroundColor(*color);
+}
+
+void RenderWidgetHostViewQt::EnsureSurfaceSynchronizedForLayoutTest()
+{
+ ++m_latestCaptureSequenceNumber;
+ if (host())
+ host()->SynchronizeVisualProperties();
+}
+
+uint32_t RenderWidgetHostViewQt::GetCaptureSequenceNumber() const
+{
+ return m_latestCaptureSequenceNumber;
+}
+
} // namespace QtWebEngineCore