summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-10 16:51:06 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-10 18:11:18 +0200
commitc373b6ca6c3bc2597a54cecffd409ea84798905f (patch)
tree09f6067d368eeb8223553b3ac4a5254f4ace6547 /shared
parent83a2bc6d446387d25fd10164e87627c9d49878eb (diff)
Fix undefined symbols in debug builds.
process uses the same code as lib and decides at runtime which code to run. Fix the debug build by making sure that all infrastructure code is available in both process and lib by building common code not shared directly through chromium sources in a separate static lib.
Diffstat (limited to 'shared')
-rw-r--r--shared/backing_store_qt.cpp164
-rw-r--r--shared/backing_store_qt.h73
-rw-r--r--shared/native_view_container_qt.h107
-rw-r--r--shared/native_view_qt.cpp208
-rw-r--r--shared/native_view_qt.h97
-rw-r--r--shared/raster_window.cpp95
-rw-r--r--shared/raster_window.h99
-rw-r--r--shared/render_widget_host_view_qt.cpp518
-rw-r--r--shared/render_widget_host_view_qt.h142
-rw-r--r--shared/shared.pro35
-rw-r--r--shared/web_event_factory.cpp600
-rw-r--r--shared/web_event_factory.h61
12 files changed, 2199 insertions, 0 deletions
diff --git a/shared/backing_store_qt.cpp b/shared/backing_store_qt.cpp
new file mode 100644
index 000000000..8920b72c3
--- /dev/null
+++ b/shared/backing_store_qt.cpp
@@ -0,0 +1,164 @@
+/****************************************************************************
+**
+** 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 "backing_store_qt.h"
+
+#include "content/browser/renderer_host/render_widget_host_impl.h"
+#include "content/public/browser/render_process_host.h"
+#include "ui/gfx/rect.h"
+#include "ui/gfx/rect_conversions.h"
+
+#include <QPainter>
+
+BackingStoreQt::BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent)
+ : m_host(content::RenderWidgetHostImpl::From(host))
+ , m_pixelBuffer(size.width(), size.height())
+ , content::BackingStore(host, size)
+ , m_isValid(false)
+{
+ int width = size.width();
+ int height = size.height();
+ resize(QSize(width, height));
+}
+
+BackingStoreQt::~BackingStoreQt()
+{
+}
+
+void BackingStoreQt::resize(const QSize& size)
+{
+ m_isValid = false;
+ if (size != m_pixelBuffer.size()) {
+ QPixmap oldBackingStore = m_pixelBuffer;
+ m_pixelBuffer = QPixmap(size);
+
+ QPainter painter(&m_pixelBuffer);
+ painter.drawPixmap(oldBackingStore.rect(), oldBackingStore);
+
+ m_host->WasResized();
+ }
+}
+
+void BackingStoreQt::paintToTarget(QPainter* painter, const QRectF& rect)
+{
+ if (m_pixelBuffer.isNull())
+ return;
+ painter->drawPixmap(rect, m_pixelBuffer, rect);
+}
+
+void BackingStoreQt::PaintToBackingStore(content::RenderProcessHost *process,
+ TransportDIB::Id bitmap,
+ const gfx::Rect &bitmap_rect,
+ const std::vector<gfx::Rect> &copy_rects,
+ float scale_factor,
+ const base::Closure &completion_callback,
+ bool *scheduled_completion_callback)
+{
+ if (bitmap_rect.IsEmpty())
+ return;
+
+ *scheduled_completion_callback = false;
+ TransportDIB* dib = process->GetTransportDIB(bitmap);
+ if (!dib)
+ return;
+
+ gfx::Rect pixel_bitmap_rect = bitmap_rect;
+
+ uint8_t* bitmapData = static_cast<uint8_t*>(dib->memory());
+ int width = m_pixelBuffer.size().width();
+ int height = m_pixelBuffer.size().height();
+ QImage img(bitmapData, pixel_bitmap_rect.width(), pixel_bitmap_rect.height(), QImage::Format_ARGB32);
+
+ m_painter.begin(&m_pixelBuffer);
+
+ for (size_t i = 0; i < copy_rects.size(); ++i) {
+ gfx::Rect copy_rect = gfx::ToEnclosedRect(gfx::ScaleRect(copy_rects[i], scale_factor));
+
+ QRect source = QRect( copy_rect.x() - pixel_bitmap_rect.x()
+ , copy_rect.y() - pixel_bitmap_rect.y()
+ , copy_rect.width()
+ , copy_rect.height());
+
+ QRect destination = QRect( copy_rect.x()
+ , copy_rect.y()
+ , copy_rect.width()
+ , copy_rect.height());
+
+ m_painter.drawPixmap(destination, QPixmap::fromImage(img), source);
+ }
+
+ m_painter.end();
+}
+
+void BackingStoreQt::ScrollBackingStore(const gfx::Vector2d &delta, const gfx::Rect &clip_rect, const gfx::Size &view_size)
+{
+ DCHECK(delta.x() == 0 || delta.y() == 0);
+
+ m_pixelBuffer.scroll(delta.x(), delta.y(), clip_rect.x(), clip_rect.y(), clip_rect.width(), clip_rect.height());
+}
+
+bool BackingStoreQt::CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output)
+{
+ // const int width = std::min(m_pixelBuffer.width(), rect.width());
+ // const int height = std::min(m_pixelBuffer.height(), rect.height());
+
+ // if (!output->Allocate(width, height, true))
+ // return false;
+
+ // // This code assumes a visual mode where a pixel is
+ // // represented using a 32-bit unsigned int, with a byte per component.
+ // const SkBitmap& bitmap = output->GetBitmap();
+ // SkAutoLockPixels alp(bitmap);
+
+ // QPixmap cpy = m_pixelBuffer.copy(rect.x(), rect.y(), rect.width(), rect.height());
+ // QImage img = cpy.toImage();
+
+ // // Convert the format and remove transparency.
+ // if (img.format() != QImage::Format_RGB32)
+ // img = img.convertToFormat(QImage::Format_RGB32);
+
+ // const uint8_t* src = img.bits();
+ // uint8_t* dst = reinterpret_cast<uint8_t*>(bitmap.getAddr32(0,0));
+ // memcpy(dst, src, width*height*32);
+
+ // return true;
+}
+
diff --git a/shared/backing_store_qt.h b/shared/backing_store_qt.h
new file mode 100644
index 000000000..9f7e807d3
--- /dev/null
+++ b/shared/backing_store_qt.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 CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_QT_H_
+#define CONTENT_BROWSER_RENDERER_HOST_BACKING_STORE_QT_H_
+
+#include "content/browser/renderer_host/backing_store.h"
+
+#include <QPainter>
+#include <QPixmap>
+
+class BackingStoreQt : public content::BackingStore
+{
+public:
+ BackingStoreQt(content::RenderWidgetHost *host, const gfx::Size &size, QWindow* parent);
+ ~BackingStoreQt();
+
+ void resize(const QSize& size);
+ void paintToTarget(QPainter*, const QRectF& rect);
+
+ virtual void PaintToBackingStore(content::RenderProcessHost *process, TransportDIB::Id bitmap, const gfx::Rect &bitmap_rect,
+ const std::vector<gfx::Rect> &copy_rects, float scale_factor, const base::Closure &completion_callback,
+ bool *scheduled_completion_callback);
+
+ virtual void ScrollBackingStore(const gfx::Vector2d &delta, const gfx::Rect &clip_rect, const gfx::Size &view_size);
+ virtual bool CopyFromBackingStore(const gfx::Rect &rect, skia::PlatformBitmap *output);
+
+private:
+ QPainter m_painter;
+ content::RenderWidgetHost* m_host;
+ QPixmap m_pixelBuffer;
+ bool m_isValid;
+};
+
+#endif
diff --git a/shared/native_view_container_qt.h b/shared/native_view_container_qt.h
new file mode 100644
index 000000000..6937d146d
--- /dev/null
+++ b/shared/native_view_container_qt.h
@@ -0,0 +1,107 @@
+#ifndef NATIVE_VIEW_CONTAINER_QT_H
+#define NATIVE_VIEW_CONTAINER_QT_H
+
+#include "native_view_qt.h"
+
+#include <QWindow>
+#include <QVBoxLayout>
+#include <QQuickItem>
+
+class NativeViewContainerQt : public QObject
+{
+ Q_OBJECT
+public:
+ NativeViewContainerQt()
+ : m_embeddable(0)
+ , m_currentQQuickNativeView(0)
+ , m_currentQWidgetNativeView(0)
+ , m_isQQuick(false)
+ {
+ }
+
+ QQuickItem* qQuickItem()
+ {
+ if (!m_embeddable) {
+ QQuickItem* embeddable = new QQuickItem;
+ m_isQQuick = true;
+ connect(embeddable, SIGNAL(widthChanged()), this, SLOT(resized()));
+ connect(embeddable, SIGNAL(heightChanged()), this, SLOT(resized()));
+ m_embeddable = embeddable;
+ }
+
+ return static_cast<QQuickItem*>(m_embeddable);
+ }
+
+ QVBoxLayout* widget()
+ {
+ if (!m_embeddable)
+ m_embeddable = new QVBoxLayout;
+ return static_cast<QVBoxLayout*>(m_embeddable);
+ }
+
+ void setWidth(qreal width)
+ {
+ if (m_isQQuick && m_currentQQuickNativeView) {
+ m_currentQQuickNativeView->setWidth(width);
+ m_currentQQuickNativeView->setContentsSize(QSize(width, m_currentQQuickNativeView->height()));
+ qQuickItem()->setWidth(width);
+ }
+ }
+
+ void setHeight(qreal height)
+ {
+ if (m_isQQuick && m_currentQQuickNativeView) {
+ m_currentQQuickNativeView->setHeight(height);
+ m_currentQQuickNativeView->setContentsSize(QSize(m_currentQQuickNativeView->width(), height));
+ qQuickItem()->setHeight(height);
+ }
+ }
+
+ NativeViewQt* createNativeView(content::RenderWidgetHostViewQt* renderWidgetHostView)
+ {
+ if (m_isQQuick) {
+ insert(new QQuickNativeView(renderWidgetHostView));
+ return m_currentQQuickNativeView;
+ }
+
+ insert(new QWidgetNativeView(renderWidgetHostView));
+ return m_currentQWidgetNativeView;
+ }
+
+protected:
+ void insert(QWidgetNativeView* nativeView)
+ {
+ widget()->removeWidget(m_currentQWidgetNativeView);
+ widget()->addWidget(nativeView);
+ m_currentQWidgetNativeView = nativeView;
+ }
+
+ void insert(QQuickNativeView* nativeView)
+ {
+ fprintf(stderr, "replace: %p with %p\n", m_currentQQuickNativeView, nativeView);
+ if (m_currentQQuickNativeView)
+ m_currentQQuickNativeView->setParentItem(0);
+
+ nativeView->setParentItem(qQuickItem());
+ m_currentQQuickNativeView = nativeView;
+ setWidth(qQuickItem()->width());
+ setHeight(qQuickItem()->height());
+ }
+
+public Q_SLOTS:
+ void resized()
+ {
+ int w = static_cast<unsigned int>(qQuickItem()->width());
+ int h = static_cast<unsigned int>(qQuickItem()->height());
+ if (m_currentQQuickNativeView)
+ m_currentQQuickNativeView->resize(w, h);
+ }
+
+private:
+ QObject* m_embeddable;
+ QWidgetNativeView* m_currentQWidgetNativeView;
+ QQuickNativeView* m_currentQQuickNativeView;
+ bool m_isQQuick;
+};
+
+#endif
diff --git a/shared/native_view_qt.cpp b/shared/native_view_qt.cpp
new file mode 100644
index 000000000..d95cb6957
--- /dev/null
+++ b/shared/native_view_qt.cpp
@@ -0,0 +1,208 @@
+#include "native_view_qt.h"
+
+#include "backing_store_qt.h"
+#include "render_widget_host_view_qt.h"
+#include <QResizeEvent>
+#include <QShowEvent>
+#include <QPaintEvent>
+#include <QQuickWindow>
+#include <QWindow>
+
+QWidgetNativeView::QWidgetNativeView(content::RenderWidgetHostViewQt* view, QWidget *parent)
+ : QWidget(parent)
+ , m_painter(0)
+ , m_backingStore(0)
+ , m_view(view)
+{
+ setFocusPolicy(Qt::ClickFocus);
+ setAttribute(Qt::WA_OpaquePaintEvent);
+}
+
+QRectF QWidgetNativeView::screenRect() const
+{
+ return QRectF(x(), y(), width(), height());
+}
+
+void QWidgetNativeView::show()
+{
+ QWidget::show();
+}
+
+void QWidgetNativeView::hide()
+{
+ QWidget::hide();
+}
+
+
+bool QWidgetNativeView::isVisible() const
+{
+ return QWidget::isVisible();
+}
+
+QWindow* QWidgetNativeView::window() const
+{
+ return QWidget::windowHandle();
+}
+
+void QWidgetNativeView::update()
+{
+ QWidget::update();
+}
+
+void QWidgetNativeView::setBackingStore(BackingStoreQt* backingStore)
+{
+ m_backingStore = backingStore;
+ if (m_backingStore)
+ m_backingStore->resize(size());
+}
+
+void QWidgetNativeView::paintEvent(QPaintEvent * event)
+{
+ if (!m_backingStore)
+ return;
+ QPainter painter(this);
+ m_backingStore->paintToTarget(&painter, event->rect());
+}
+
+QPainter* QWidgetNativeView::painter()
+{
+ if (!m_painter)
+ m_painter = new QPainter(this);
+ return m_painter;
+}
+
+void QWidgetNativeView::resizeEvent(QResizeEvent *resizeEvent)
+{
+ if (m_backingStore)
+ m_backingStore->resize(resizeEvent->size());
+ QWidget::update();
+}
+
+bool QWidgetNativeView::event(QEvent *event)
+{
+ if (!m_view || !m_view->handleEvent(event))
+ return QWidget::event(event);
+ return true;
+}
+
+QQuickNativeView::QQuickNativeView(content::RenderWidgetHostViewQt* view, QQuickItem *parent)
+ : QQuickPaintedItem(parent)
+ , m_backingStore(0)
+ , m_view(view)
+{
+ setFocus(true);
+ setAcceptedMouseButtons(Qt::AllButtons);
+}
+
+QRectF QQuickNativeView::screenRect() const
+{
+ QPointF pos = mapToScene(QPointF(0,0));
+ return QRectF(pos.x(), pos.y(), width(), height());
+}
+
+void QQuickNativeView::show()
+{
+ setVisible(true);
+}
+
+void QQuickNativeView::hide()
+{
+ setVisible(true);
+}
+
+bool QQuickNativeView::isVisible() const
+{
+ return QQuickPaintedItem::isVisible();
+}
+
+QWindow* QQuickNativeView::window() const
+{
+ return QQuickPaintedItem::window();
+}
+
+void QQuickNativeView::update()
+{
+ QQuickPaintedItem::update();
+}
+
+void QQuickNativeView::paint(QPainter *painter)
+{
+ if (!m_backingStore)
+ return;
+
+ m_backingStore->paintToTarget(painter, boundingRect());
+}
+
+void QQuickNativeView::setBackingStore(BackingStoreQt* backingStore)
+{
+ m_backingStore = backingStore;
+ if (m_backingStore)
+ m_backingStore->resize(QSize(width(), height()));
+}
+
+QSGNode * QQuickNativeView::updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data)
+{
+ return QQuickPaintedItem::updatePaintNode(oldNode, data);
+}
+
+void QQuickNativeView::resizeBackingStore()
+{
+ if (m_backingStore)
+ m_backingStore->resize(QSize(width(), height()));
+}
+
+void QQuickNativeView::resize(int width, int height)
+{
+ resetWidth();
+ resetHeight();
+ setWidth(width);
+ setHeight(height);
+ resizeBackingStore();
+ update();
+}
+
+void QQuickNativeView::focusInEvent(QFocusEvent *event)
+{
+ m_view->handleFocusEvent(event);
+}
+
+void QQuickNativeView::focusOutEvent(QFocusEvent *event)
+{
+ m_view->handleFocusEvent(event);
+}
+
+void QQuickNativeView::mousePressEvent(QMouseEvent *event)
+{
+ setFocus(true);
+ m_view->handleMouseEvent(event);
+}
+
+void QQuickNativeView::mouseMoveEvent(QMouseEvent *event)
+{
+ m_view->handleMouseEvent(event);
+}
+
+void QQuickNativeView::mouseReleaseEvent(QMouseEvent *event)
+{
+ m_view->handleMouseEvent(event);
+}
+
+void QQuickNativeView::mouseDoubleClickEvent(QMouseEvent *event)
+{
+ m_view->handleMouseEvent(event);
+}
+
+void QQuickNativeView::keyPressEvent(QKeyEvent *event)
+{
+ m_view->handleKeyEvent(event);
+}
+
+void QQuickNativeView::keyReleaseEvent(QKeyEvent *event)
+{
+ m_view->handleKeyEvent(event);
+}
+
+void QQuickNativeView::wheelEvent(QWheelEvent *event)
+{
+ m_view->handleWheelEvent(event);
+}
diff --git a/shared/native_view_qt.h b/shared/native_view_qt.h
new file mode 100644
index 000000000..80bb24e87
--- /dev/null
+++ b/shared/native_view_qt.h
@@ -0,0 +1,97 @@
+#ifndef NATIVE_VIEW_QT_H
+#define NATIVE_VIEW_QT_H
+
+
+#include <QWidget>
+#include <QQuickPaintedItem>
+
+class BackingStoreQt;
+class QWindow;
+class QQuickItem;
+class QFocusEvent;
+class QMouseEvent;
+class QKeyEvent;
+class QWheelEvent;
+
+namespace content {
+ class RenderWidgetHostViewQt;
+}
+
+class NativeViewQt {
+public:
+ virtual ~NativeViewQt() {}
+ virtual void setBackingStore(BackingStoreQt* backingStore) = 0;
+ virtual QRectF screenRect() const = 0;
+ virtual void show() = 0;
+ virtual void hide() = 0;
+ virtual bool isVisible() const = 0;
+ virtual QWindow* window() const = 0;
+ virtual void update() = 0;
+};
+
+class QWidgetNativeView : public QWidget, public NativeViewQt
+{
+public:
+ QWidgetNativeView(content::RenderWidgetHostViewQt* view, QWidget *parent = 0);
+
+ virtual void setBackingStore(BackingStoreQt* backingStore);
+ virtual QRectF screenRect() const;
+ virtual void show();
+ virtual void hide();
+ virtual bool isVisible() const;
+ virtual QWindow* window() const;
+ virtual void update();
+
+ QPainter* painter();
+
+protected:
+ void paintEvent(QPaintEvent * event);
+ bool event(QEvent *event);
+ void resizeEvent(QResizeEvent *resizeEvent);
+
+private:
+ BackingStoreQt* m_backingStore;
+ QPainter* m_painter;
+ content::RenderWidgetHostViewQt *m_view;
+};
+
+class QQuickNativeView : public QQuickPaintedItem, public NativeViewQt
+{
+ Q_OBJECT
+public:
+ QQuickNativeView(content::RenderWidgetHostViewQt* view, QQuickItem *parent = 0);
+
+ virtual void setBackingStore(BackingStoreQt* backingStore);
+ virtual QRectF screenRect() const;
+ virtual void show();
+ virtual void hide();
+ virtual bool isVisible() const;
+ virtual QWindow* window() const;
+ virtual void update();
+
+ void paint(QPainter *painter);
+ void resize(int width, int height);
+
+ void focusInEvent(QFocusEvent*);
+ void focusOutEvent(QFocusEvent*);
+ void mousePressEvent(QMouseEvent*);
+ void mouseMoveEvent(QMouseEvent*);
+ void mouseReleaseEvent(QMouseEvent*);
+ void mouseDoubleClickEvent(QMouseEvent*);
+ void keyPressEvent(QKeyEvent*);
+ void keyReleaseEvent(QKeyEvent*);
+ void wheelEvent(QWheelEvent*);
+
+protected Q_SLOTS:
+ void resizeBackingStore();
+
+protected:
+ QSGNode* updatePaintNode(QSGNode * oldNode, UpdatePaintNodeData * data);
+
+private:
+ BackingStoreQt* m_backingStore;
+ content::RenderWidgetHostViewQt *m_view;
+
+};
+
+#endif
diff --git a/shared/raster_window.cpp b/shared/raster_window.cpp
new file mode 100644
index 000000000..778a6b290
--- /dev/null
+++ b/shared/raster_window.cpp
@@ -0,0 +1,95 @@
+/****************************************************************************
+**
+** 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 "raster_window.h"
+
+#include "backing_store_qt.h"
+#include "render_widget_host_view_qt.h"
+#include <QResizeEvent>
+#include <QShowEvent>
+#include <QPaintEvent>
+
+RasterWindow::RasterWindow(content::RenderWidgetHostViewQt* view, QWidget *parent)
+ : QWidget(parent)
+ , m_painter(0)
+ , m_backingStore(0)
+ , m_view(view)
+{
+ setFocusPolicy(Qt::ClickFocus);
+ setAttribute(Qt::WA_OpaquePaintEvent);
+}
+
+void RasterWindow::setBackingStore(BackingStoreQt* backingStore)
+{
+ m_backingStore = backingStore;
+ if (m_backingStore)
+ m_backingStore->resize(size());
+}
+
+void RasterWindow::paintEvent(QPaintEvent * event)
+{
+ if (!m_backingStore)
+ return;
+ QPainter painter(this);
+ m_backingStore->paintToTarget(&painter, event->rect());
+}
+
+QPainter* RasterWindow::painter()
+{
+ if (!m_painter)
+ m_painter = new QPainter(this);
+ return m_painter;
+}
+
+void RasterWindow::resizeEvent(QResizeEvent *resizeEvent)
+{
+ if (m_backingStore)
+ m_backingStore->resize(resizeEvent->size());
+ update();
+}
+
+
+bool RasterWindow::event(QEvent *event)
+{
+ if (!m_view || !m_view->handleEvent(event))
+ return QWidget::event(event);
+ return true;
+}
diff --git a/shared/raster_window.h b/shared/raster_window.h
new file mode 100644
index 000000000..8619b278c
--- /dev/null
+++ b/shared/raster_window.h
@@ -0,0 +1,99 @@
+/****************************************************************************
+**
+** 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 QT_RASTER_WINDOW_H
+#define QT_RASTER_WINDOW_H
+
+#include <QWindow>
+#include <QVBoxLayout>
+#include <QWidget>
+
+class BackingStoreQt;
+
+namespace content {
+ class RenderWidgetHostViewQt;
+}
+
+class RasterWindow : public QWidget
+{
+public:
+ RasterWindow(content::RenderWidgetHostViewQt* view, QWidget *parent = 0);
+
+ void setBackingStore(BackingStoreQt* backingStore);
+
+ QPainter* painter();
+
+protected:
+ void paintEvent(QPaintEvent * event);
+ bool event(QEvent *event);
+ void resizeEvent(QResizeEvent *resizeEvent);
+
+private:
+ BackingStoreQt* m_backingStore;
+ QPainter* m_painter;
+ content::RenderWidgetHostViewQt *m_view;
+
+};
+
+class RasterWindowContainer : public QVBoxLayout
+{
+public:
+ RasterWindowContainer()
+ : m_currentRasterWindow(0)
+ { }
+
+ ~RasterWindowContainer()
+ {
+ }
+
+public:
+ void insert(RasterWindow* rasterWindow)
+ {
+ removeWidget(m_currentRasterWindow);
+ addWidget(rasterWindow);
+ m_currentRasterWindow = rasterWindow;
+ }
+
+private:
+ RasterWindow* m_currentRasterWindow;
+};
+
+#endif
diff --git a/shared/render_widget_host_view_qt.cpp b/shared/render_widget_host_view_qt.cpp
new file mode 100644
index 000000000..351030c7a
--- /dev/null
+++ b/shared/render_widget_host_view_qt.cpp
@@ -0,0 +1,518 @@
+/****************************************************************************
+**
+** 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.h"
+
+#include "backing_store_qt.h"
+#include "web_event_factory.h"
+#include "native_view_container_qt.h"
+#include "native_view_qt.h"
+
+#include "content/browser/renderer_host/render_view_host_impl.h"
+#include "content/common/gpu/gpu_messages.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebScreenInfo.h"
+
+#include <QEvent>
+#include <QFocusEvent>
+#include <QKeyEvent>
+#include <QMouseEvent>
+#include <QWheelEvent>
+#include <QScreen>
+#include <QQuickWindow>
+
+static void GetScreenInfoFromNativeWindow(QWindow* window, WebKit::WebScreenInfo* results)
+{
+ QScreen* screen = window->screen();
+
+ WebKit::WebScreenInfo r;
+ r.deviceScaleFactor = screen->devicePixelRatio();
+ r.depthPerComponent = 8;
+ r.depth = screen->depth();
+ r.isMonochrome = (r.depth == 1);
+
+ QRect virtualGeometry = screen->virtualGeometry();
+ r.rect = WebKit::WebRect(virtualGeometry.x(), virtualGeometry.y(), virtualGeometry.width(), virtualGeometry.height());
+ QRect available = screen->availableGeometry();
+ r.availableRect = WebKit::WebRect(available.x(), available.y(), available.width(), available.height());
+ *results = r;
+}
+
+namespace content {
+
+RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
+ RenderWidgetHost* widget) {
+ return new RenderWidgetHostViewQt(widget);
+}
+
+// static
+void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebKit::WebScreenInfo* results) {
+ QWindow dummy;
+ GetScreenInfoFromNativeWindow(&dummy, results);
+}
+
+RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget)
+ : m_host(content::RenderWidgetHostImpl::From(widget))
+ , m_view(0)
+{
+ m_host->SetView(this);
+}
+
+RenderWidgetHostViewQt::~RenderWidgetHostViewQt()
+{
+}
+
+bool RenderWidgetHostViewQt::handleEvent(QEvent* event) {
+
+ switch(event->type()) {
+ case QEvent::MouseButtonDblClick:
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseMove:
+ handleMouseEvent(static_cast<QMouseEvent*>(event));
+ break;
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ handleKeyEvent(static_cast<QKeyEvent*>(event));
+ break;
+ case QEvent::Wheel:
+ handleWheelEvent(static_cast<QWheelEvent*>(event));
+ break;
+ case QEvent::FocusIn:
+ case QEvent::FocusOut:
+ handleFocusEvent(static_cast<QFocusEvent*>(event));
+ break;
+ default:
+ return false;
+ }
+ return true;
+}
+
+content::BackingStore *RenderWidgetHostViewQt::AllocBackingStore(const gfx::Size &size)
+{
+ if (m_view)
+ return new BackingStoreQt(m_host, size, new QWindow);
+ return 0;
+}
+
+RenderWidgetHostView* RenderWidgetHostViewQt::CreateViewForWidget(content::RenderWidgetHost* widget)
+{
+ return new RenderWidgetHostViewQt(widget);
+}
+
+void RenderWidgetHostViewQt::InitAsChild(gfx::NativeView parent_view)
+{
+ NativeViewContainerQt* container = reinterpret_cast<NativeViewContainerQt*>(parent_view);
+ m_view = container->createNativeView(this);
+ bool force_create = !m_host->empty();
+ BackingStoreQt* backing_store = static_cast<BackingStoreQt*>(m_host->GetBackingStore(force_create));
+ m_view->setBackingStore(backing_store);
+}
+
+void RenderWidgetHostViewQt::InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&)
+{
+ // m_view = new RasterWindow(this);
+}
+
+void RenderWidgetHostViewQt::InitAsFullscreen(content::RenderWidgetHostView*)
+{
+ // m_view = new RasterWindow(this);
+}
+
+content::RenderWidgetHost* RenderWidgetHostViewQt::GetRenderWidgetHost() const
+{
+ return m_host;
+}
+
+void RenderWidgetHostViewQt::SetSize(const gfx::Size& size)
+{
+ int width = size.width();
+ int height = size.height();
+ // int width = std::min(size.width(), kMaxWindowWidth);
+ // int height = std::min(size.height(), kMaxWindowHeight);
+ // if (IsPopup())
+ // m_view->resize(width,height);
+
+ if (m_requestedSize.width() != width ||
+ m_requestedSize.height() != height) {
+ m_requestedSize = gfx::Size(width, height);
+ // m_host->SendScreenRects();
+ m_host->WasResized();
+ }
+}
+
+void RenderWidgetHostViewQt::SetBounds(const gfx::Rect& rect)
+{
+ // This is called when webkit has sent us a Move message.
+ // if (IsPopup())
+ // m_view->setGeometry(rect.x(), rect.y(), rect.width(), rect.height());
+ SetSize(rect.size());
+}
+
+// FIXME: Should this really return a QWindow pointer?
+gfx::NativeView RenderWidgetHostViewQt::GetNativeView() const
+{
+ QT_NOT_YET_IMPLEMENTED
+ return gfx::NativeView();
+}
+
+NativeViewQt* RenderWidgetHostViewQt::GetNativeViewQt() const
+{
+ return m_view;
+}
+
+gfx::NativeViewId RenderWidgetHostViewQt::GetNativeViewId() const
+{
+ QT_NOT_YET_IMPLEMENTED
+ return gfx::NativeViewId();
+}
+
+gfx::NativeViewAccessible RenderWidgetHostViewQt::GetNativeViewAccessible()
+{
+ NOTIMPLEMENTED();
+ return NULL;
+}
+
+// Set focus to the associated View component.
+void RenderWidgetHostViewQt::Focus()
+{
+ // m_view->setFocus(Qt::MouseFocusReason);
+}
+
+bool RenderWidgetHostViewQt::HasFocus() const
+{
+ // return m_view->hasFocus();
+ return true;
+}
+
+bool RenderWidgetHostViewQt::IsSurfaceAvailableForCopy() const
+{
+ return true;
+}
+
+void RenderWidgetHostViewQt::Show()
+{
+ m_view->show();
+}
+
+void RenderWidgetHostViewQt::Hide()
+{
+ m_view->hide();
+}
+
+bool RenderWidgetHostViewQt::IsShowing()
+{
+ return m_view->isVisible();
+}
+
+// Retrieve the bounds of the View, in screen coordinates.
+gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const
+{
+ QRectF p = m_view->screenRect();
+ return gfx::Rect(p.x(), p.y(), p.width(), p.height());
+}
+
+// Subclasses should override this method to do what is appropriate to set
+// the custom background for their platform.
+void RenderWidgetHostViewQt::SetBackground(const SkBitmap& background)
+{
+ RenderWidgetHostViewBase::SetBackground(background);
+ // Send(new ViewMsg_SetBackground(m_host->GetRoutingID(), background));
+}
+
+// Return value indicates whether the mouse is locked successfully or not.
+bool RenderWidgetHostViewQt::LockMouse()
+{
+ QT_NOT_YET_IMPLEMENTED
+ return false;
+}
+void RenderWidgetHostViewQt::UnlockMouse()
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+// Returns true if the mouse pointer is currently locked.
+bool RenderWidgetHostViewQt::IsMouseLocked()
+{
+ QT_NOT_YET_IMPLEMENTED
+ return false;
+}
+
+// FIXME: remove TOOLKIT_GTK related things.
+#if defined(TOOLKIT_GTK)
+// Gets the event for the last mouse down.
+GdkEventButton* RenderWidgetHostViewQt::GetLastMouseDown()
+{
+ return 0;
+}
+
+gfx::NativeView RenderWidgetHostViewQt::BuildInputMethodsGtkMenu()
+{
+}
+#endif // defined(TOOLKIT_GTK)
+
+void RenderWidgetHostViewQt::WasShown()
+{
+ if (m_view->isVisible())
+ return;
+
+ m_host->WasShown();
+}
+
+void RenderWidgetHostViewQt::WasHidden()
+{
+ if (!m_view->isVisible())
+ return;
+
+ m_host->WasHidden();
+}
+
+void RenderWidgetHostViewQt::MovePluginWindows(const gfx::Vector2d&, const std::vector<webkit::npapi::WebPluginGeometry>&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::Blur()
+{
+ m_host->Blur();
+}
+
+void RenderWidgetHostViewQt::UpdateCursor(const WebCursor&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::SetIsLoading(bool)
+{
+ QT_NOT_YET_IMPLEMENTED
+ // Give visual feedback for loading process.
+}
+
+void RenderWidgetHostViewQt::TextInputStateChanged(const ViewHostMsg_TextInputState_Params&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::ImeCancelComposition()
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::ImeCompositionRangeChanged(const ui::Range&, const std::vector<gfx::Rect>&)
+{
+ // FIXME: not implemented?
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::DidUpdateBackingStore(const gfx::Rect& scroll_rect, const gfx::Vector2d& scroll_delta, const std::vector<gfx::Rect>& copy_rects)
+{
+ if (!m_view || !m_view->isVisible())
+ return;
+
+ Paint(scroll_rect);
+
+ for (size_t i = 0; i < copy_rects.size(); ++i) {
+ gfx::Rect rect = gfx::SubtractRects(copy_rects[i], scroll_rect);
+ if (rect.IsEmpty())
+ continue;
+
+ Paint(rect);
+ }
+}
+
+void RenderWidgetHostViewQt::RenderViewGone(base::TerminationStatus, int)
+{
+ Destroy();
+}
+
+void RenderWidgetHostViewQt::Destroy()
+{
+ delete m_view;
+ m_view = 0;
+}
+
+void RenderWidgetHostViewQt::SetTooltipText(const string16&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::ScrollOffsetChanged()
+{
+ // FIXME: not implemented?
+}
+
+void RenderWidgetHostViewQt::CopyFromCompositingSurface(const gfx::Rect& src_subrect, const gfx::Size& /* dst_size */, const base::Callback<void(bool, const SkBitmap&)>& callback)
+{
+ // Grab the snapshot from the renderer as that's the only reliable way to
+ // readback from the GPU for this platform right now.
+ // FIXME: is this true?
+ GetRenderWidgetHost()->GetSnapshotFromRenderer(src_subrect, callback);
+}
+
+void RenderWidgetHostViewQt::CopyFromCompositingSurfaceToVideoFrame(const gfx::Rect& src_subrect, const scoped_refptr<media::VideoFrame>& target, const base::Callback<void(bool)>& callback)
+{
+ NOTIMPLEMENTED();
+ callback.Run(false);
+}
+
+bool RenderWidgetHostViewQt::CanCopyToVideoFrame() const
+{
+ return false;
+}
+
+void RenderWidgetHostViewQt::OnAcceleratedCompositingStateChange()
+{
+ // bool activated = m_host->is_accelerated_compositing_active();
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::AcceleratedSurfaceBuffersSwapped(const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, int gpu_host_id)
+{
+ AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
+ ack_params.sync_point = 0;
+ content::RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, gpu_host_id, ack_params);
+}
+
+void RenderWidgetHostViewQt::AcceleratedSurfacePostSubBuffer(const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, int gpu_host_id)
+{
+ AcceleratedSurfaceMsg_BufferPresented_Params ack_params;
+ ack_params.sync_point = 0;
+ content::RenderWidgetHostImpl::AcknowledgeBufferPresent(params.route_id, gpu_host_id, ack_params);
+}
+
+void RenderWidgetHostViewQt::AcceleratedSurfaceSuspend()
+{
+ //FIXME: not implemented?
+}
+
+void RenderWidgetHostViewQt::AcceleratedSurfaceRelease()
+{
+ //FIXME: not implemented?
+}
+
+bool RenderWidgetHostViewQt::HasAcceleratedSurface(const gfx::Size&)
+{
+ return false;
+}
+
+void RenderWidgetHostViewQt::GetScreenInfo(WebKit::WebScreenInfo* results)
+{
+ QWindow* window = m_view->window();
+ if (!window)
+ return;
+ GetScreenInfoFromNativeWindow(window, results);
+}
+
+gfx::Rect RenderWidgetHostViewQt::GetBoundsInRootWindow()
+{
+ if (!m_view || !m_view->window())
+ return gfx::Rect();
+
+ QRect r = m_view->window()->frameGeometry();
+ return gfx::Rect(r.x(), r.y(), r.width(), r.height());
+}
+
+gfx::GLSurfaceHandle RenderWidgetHostViewQt::GetCompositingSurface()
+{
+ QT_NOT_YET_IMPLEMENTED
+ return gfx::GLSurfaceHandle();
+}
+
+void RenderWidgetHostViewQt::SetHasHorizontalScrollbar(bool) { }
+
+void RenderWidgetHostViewQt::SetScrollOffsetPinning(bool, bool) { }
+
+void RenderWidgetHostViewQt::OnAccessibilityNotifications(const std::vector<AccessibilityHostMsg_NotificationParams>&)
+{
+ QT_NOT_YET_IMPLEMENTED
+}
+
+void RenderWidgetHostViewQt::Paint(const gfx::Rect& scroll_rect)
+{
+ bool force_create = !m_host->empty();
+ BackingStoreQt* backing_store = static_cast<BackingStoreQt*>(m_host->GetBackingStore(force_create));
+ if (backing_store && m_view) {
+ QRectF r = m_view->screenRect();
+ QRect rect(0, 0, r.width(), r.height());
+ m_view->setBackingStore(backing_store);
+ m_view->update();
+ }
+}
+
+bool RenderWidgetHostViewQt::IsPopup() const
+{
+ return popup_type_ != WebKit::WebPopupTypeNone;
+}
+
+void RenderWidgetHostViewQt::handleMouseEvent(QMouseEvent* ev)
+{
+ m_host->ForwardMouseEvent(WebEventFactory::toWebMouseEvent(ev));
+}
+
+void RenderWidgetHostViewQt::handleKeyEvent(QKeyEvent *ev)
+{
+ m_host->ForwardKeyboardEvent(WebEventFactory::toWebKeyboardEvent(ev));
+}
+
+void RenderWidgetHostViewQt::handleWheelEvent(QWheelEvent *ev)
+{
+ m_host->ForwardWheelEvent(WebEventFactory::toWebWheelEvent(ev));
+}
+
+void RenderWidgetHostViewQt::handleFocusEvent(QFocusEvent *ev)
+{
+ if (ev->gotFocus()) {
+ m_host->GotFocus();
+ m_host->SetActive(true);
+ ev->accept();
+ } else if (ev->lostFocus()) {
+ m_host->SetActive(false);
+ m_host->Blur();
+ ev->accept();
+ }
+}
+
+}
+
diff --git a/shared/render_widget_host_view_qt.h b/shared/render_widget_host_view_qt.h
new file mode 100644
index 000000000..94faf8205
--- /dev/null
+++ b/shared/render_widget_host_view_qt.h
@@ -0,0 +1,142 @@
+/****************************************************************************
+**
+** 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 CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_QT_H_
+#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_QT_H_
+
+#include "content/browser/renderer_host/render_widget_host_view_base.h"
+
+#define QT_NOT_YET_IMPLEMENTED fprintf(stderr, "function %s not implemented! - %s:%d\n", __func__, __FILE__, __LINE__);
+
+class QEvent;
+class QFocusEvent;
+class QKeyEvent;
+class QMouseEvent;
+class QWheelEvent;
+class NativeViewQt;
+
+namespace content {
+
+class RenderWidgetHostViewQt
+ : public content::RenderWidgetHostViewBase
+{
+public:
+ RenderWidgetHostViewQt(content::RenderWidgetHost* widget);
+ ~RenderWidgetHostViewQt();
+
+ bool handleEvent(QEvent* event);
+
+ virtual content::BackingStore *AllocBackingStore(const gfx::Size &size);
+ static RenderWidgetHostView* CreateViewForWidget(content::RenderWidgetHost* widget);
+
+ virtual void InitAsChild(gfx::NativeView parent_view);
+ virtual void InitAsPopup(content::RenderWidgetHostView*, const gfx::Rect&);
+ virtual void InitAsFullscreen(content::RenderWidgetHostView*);
+ virtual content::RenderWidgetHost* GetRenderWidgetHost() const;
+ virtual void SetSize(const gfx::Size& size);
+ virtual void SetBounds(const gfx::Rect& rect);
+ virtual gfx::NativeView GetNativeView() const;
+ virtual NativeViewQt* GetNativeViewQt() const OVERRIDE;
+ virtual gfx::NativeViewId GetNativeViewId() const;
+ virtual gfx::NativeViewAccessible GetNativeViewAccessible();
+ virtual void Focus();
+ virtual bool HasFocus() const;
+ virtual bool IsSurfaceAvailableForCopy() const;
+ virtual void Show();
+ virtual void Hide();
+ virtual bool IsShowing();
+ virtual gfx::Rect GetViewBounds() const;
+ virtual void SetBackground(const SkBitmap& background);
+ virtual bool LockMouse();
+ virtual void UnlockMouse();
+ virtual bool IsMouseLocked();
+#if defined(TOOLKIT_GTK)
+ virtual GdkEventButton* GetLastMouseDown();
+ virtual gfx::NativeView BuildInputMethodsGtkMenu();
+#endif // defined(TOOLKIT_GTK)
+ virtual void WasShown();
+ virtual void WasHidden();
+ virtual void MovePluginWindows(const gfx::Vector2d&, const std::vector<webkit::npapi::WebPluginGeometry>&);
+ virtual void Blur();
+ virtual void UpdateCursor(const WebCursor&);
+ virtual void SetIsLoading(bool);
+ virtual void TextInputStateChanged(const ViewHostMsg_TextInputState_Params&);
+ virtual void ImeCancelComposition();
+ virtual void ImeCompositionRangeChanged(const ui::Range&, const std::vector<gfx::Rect>&);
+ virtual void DidUpdateBackingStore(const gfx::Rect& scroll_rect, const gfx::Vector2d& scroll_delta, const std::vector<gfx::Rect>& copy_rects);
+ virtual void RenderViewGone(base::TerminationStatus, int);
+ virtual void Destroy();
+ virtual void SetTooltipText(const string16&);
+ virtual void SelectionBoundsChanged(const ViewHostMsg_SelectionBounds_Params&);
+ virtual void ScrollOffsetChanged();
+ virtual void CopyFromCompositingSurface(const gfx::Rect& src_subrect, const gfx::Size& /* dst_size */, const base::Callback<void(bool, const SkBitmap&)>& callback);
+ virtual void CopyFromCompositingSurfaceToVideoFrame(const gfx::Rect& src_subrect, const scoped_refptr<media::VideoFrame>& target, const base::Callback<void(bool)>& callback);
+ virtual bool CanCopyToVideoFrame() const;
+ virtual void OnAcceleratedCompositingStateChange();
+ virtual void AcceleratedSurfaceBuffersSwapped(const GpuHostMsg_AcceleratedSurfaceBuffersSwapped_Params& params, int gpu_host_id);
+ virtual void AcceleratedSurfacePostSubBuffer(const GpuHostMsg_AcceleratedSurfacePostSubBuffer_Params& params, int gpu_host_id);
+ virtual void AcceleratedSurfaceSuspend();
+ virtual void AcceleratedSurfaceRelease();
+ virtual bool HasAcceleratedSurface(const gfx::Size&);
+ virtual void GetScreenInfo(WebKit::WebScreenInfo* results);
+ virtual gfx::Rect GetBoundsInRootWindow();
+ virtual gfx::GLSurfaceHandle GetCompositingSurface();
+ virtual void SetHasHorizontalScrollbar(bool);
+ virtual void SetScrollOffsetPinning(bool, bool);
+ virtual void OnAccessibilityNotifications(const std::vector<AccessibilityHostMsg_NotificationParams>&);
+
+ void handleMouseEvent(QMouseEvent*);
+ void handleKeyEvent(QKeyEvent*);
+ void handleWheelEvent(QWheelEvent*);
+ void handleFocusEvent(QFocusEvent*);
+private:
+ void Paint(const gfx::Rect& scroll_rect);
+
+ bool IsPopup() const;
+
+ content::RenderWidgetHostImpl *m_host;
+ NativeViewQt *m_view;
+ gfx::Size m_requestedSize;
+};
+
+}
+
+#endif
diff --git a/shared/shared.pro b/shared/shared.pro
new file mode 100644
index 000000000..0fb50e94c
--- /dev/null
+++ b/shared/shared.pro
@@ -0,0 +1,35 @@
+# This is a dummy .pro file used to extract some aspects of the used configuration and feed them to gyp
+# We want the gyp generation step to happen after all the other config steps. For that we need to prepend
+# our gyp_generator.prf feature to the CONFIG variable since it is processed backwards
+CONFIG = gyp_generator $$CONFIG
+GYPINCLUDES += ../blinq.gypi
+
+TEMPLATE = lib
+CONFIG += static
+
+TARGET = blinq_shared
+
+# Defining keywords such as 'signal' clashes with the chromium code base.
+DEFINES += QT_NO_KEYWORDS
+
+# We need a way to tap into gyp´s Debug vs. Release configuration
+PER_CONFIG_DEFINES = BLINQ_PROCESS_PATH=\\\"$$getOutDir()/%config/$$BLINQ_PROCESS_NAME\\\"
+
+# Keep Skia happy
+CONFIG(release, debug|release): DEFINES += NDEBUG
+
+QT += widgets quick
+
+SOURCES = \
+ backing_store_qt.cpp \
+ render_widget_host_view_qt.cpp \
+ web_event_factory.cpp \
+ native_view_qt.cpp
+
+HEADERS = \
+ backing_store_qt.h \
+ native_view_container_qt.h \
+ native_view_qt.h \
+ render_widget_host_view_qt.h \
+ web_event_factory.h
+
diff --git a/shared/web_event_factory.cpp b/shared/web_event_factory.cpp
new file mode 100644
index 000000000..ed24c5b6d
--- /dev/null
+++ b/shared/web_event_factory.cpp
@@ -0,0 +1,600 @@
+/****************************************************************************
+**
+** Copyright (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
+** 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 "web_event_factory.h"
+#include "third_party/WebKit/Source/core/platform/WindowsKeyboardCodes.h"
+
+#include <QMouseEvent>
+#include <QKeyEvent>
+#include <QElapsedTimer>
+#include <QWheelEvent>
+#include <QApplication>
+
+using namespace WebKit;
+
+static int windowsKeyCodeForKeyEvent(unsigned int keycode, bool isKeypad)
+{
+ // Determine wheter the event comes from the keypad
+ if (isKeypad) {
+ switch (keycode) {
+ case Qt::Key_0:
+ return VK_NUMPAD0; // (60) Numeric keypad 0 key
+ case Qt::Key_1:
+ return VK_NUMPAD1; // (61) Numeric keypad 1 key
+ case Qt::Key_2:
+ return VK_NUMPAD2; // (62) Numeric keypad 2 key
+ case Qt::Key_3:
+ return VK_NUMPAD3; // (63) Numeric keypad 3 key
+ case Qt::Key_4:
+ return VK_NUMPAD4; // (64) Numeric keypad 4 key
+ case Qt::Key_5:
+ return VK_NUMPAD5; // (65) Numeric keypad 5 key
+ case Qt::Key_6:
+ return VK_NUMPAD6; // (66) Numeric keypad 6 key
+ case Qt::Key_7:
+ return VK_NUMPAD7; // (67) Numeric keypad 7 key
+ case Qt::Key_8:
+ return VK_NUMPAD8; // (68) Numeric keypad 8 key
+ case Qt::Key_9:
+ return VK_NUMPAD9; // (69) Numeric keypad 9 key
+ case Qt::Key_Asterisk:
+ return VK_MULTIPLY; // (6A) Multiply key
+ case Qt::Key_Plus:
+ return VK_ADD; // (6B) Add key
+ case Qt::Key_Minus:
+ return VK_SUBTRACT; // (6D) Subtract key
+ case Qt::Key_Period:
+ return VK_DECIMAL; // (6E) Decimal key
+ case Qt::Key_Slash:
+ return VK_DIVIDE; // (6F) Divide key
+ case Qt::Key_PageUp:
+ return VK_PRIOR; // (21) PAGE UP key
+ case Qt::Key_PageDown:
+ return VK_NEXT; // (22) PAGE DOWN key
+ case Qt::Key_End:
+ return VK_END; // (23) END key
+ case Qt::Key_Home:
+ return VK_HOME; // (24) HOME key
+ case Qt::Key_Left:
+ return VK_LEFT; // (25) LEFT ARROW key
+ case Qt::Key_Up:
+ return VK_UP; // (26) UP ARROW key
+ case Qt::Key_Right:
+ return VK_RIGHT; // (27) RIGHT ARROW key
+ case Qt::Key_Down:
+ return VK_DOWN; // (28) DOWN ARROW key
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ return VK_RETURN; // (0D) Return key
+ case Qt::Key_Insert:
+ return VK_INSERT; // (2D) INS key
+ case Qt::Key_Delete:
+ return VK_DELETE; // (2E) DEL key
+ default:
+ return 0;
+ }
+
+ } else
+
+ switch (keycode) {
+ case Qt::Key_Backspace:
+ return VK_BACK; // (08) BACKSPACE key
+ case Qt::Key_Backtab:
+ case Qt::Key_Tab:
+ return VK_TAB; // (09) TAB key
+ case Qt::Key_Clear:
+ return VK_CLEAR; // (0C) CLEAR key
+ case Qt::Key_Enter:
+ case Qt::Key_Return:
+ return VK_RETURN; // (0D) Return key
+ case Qt::Key_Shift:
+ return VK_SHIFT; // (10) SHIFT key
+ case Qt::Key_Control:
+ return VK_CONTROL; // (11) CTRL key
+ case Qt::Key_Menu:
+ case Qt::Key_Alt:
+ return VK_MENU; // (12) ALT key
+
+ case Qt::Key_F1:
+ return VK_F1;
+ case Qt::Key_F2:
+ return VK_F2;
+ case Qt::Key_F3:
+ return VK_F3;
+ case Qt::Key_F4:
+ return VK_F4;
+ case Qt::Key_F5:
+ return VK_F5;
+ case Qt::Key_F6:
+ return VK_F6;
+ case Qt::Key_F7:
+ return VK_F7;
+ case Qt::Key_F8:
+ return VK_F8;
+ case Qt::Key_F9:
+ return VK_F9;
+ case Qt::Key_F10:
+ return VK_F10;
+ case Qt::Key_F11:
+ return VK_F11;
+ case Qt::Key_F12:
+ return VK_F12;
+ case Qt::Key_F13:
+ return VK_F13;
+ case Qt::Key_F14:
+ return VK_F14;
+ case Qt::Key_F15:
+ return VK_F15;
+ case Qt::Key_F16:
+ return VK_F16;
+ case Qt::Key_F17:
+ return VK_F17;
+ case Qt::Key_F18:
+ return VK_F18;
+ case Qt::Key_F19:
+ return VK_F19;
+ case Qt::Key_F20:
+ return VK_F20;
+ case Qt::Key_F21:
+ return VK_F21;
+ case Qt::Key_F22:
+ return VK_F22;
+ case Qt::Key_F23:
+ return VK_F23;
+ case Qt::Key_F24:
+ return VK_F24;
+
+ case Qt::Key_Pause:
+ return VK_PAUSE; // (13) PAUSE key
+ case Qt::Key_CapsLock:
+ return VK_CAPITAL; // (14) CAPS LOCK key
+ case Qt::Key_Kana_Lock:
+ case Qt::Key_Kana_Shift:
+ return VK_KANA; // (15) Input Method Editor (IME) Kana mode
+ case Qt::Key_Hangul:
+ return VK_HANGUL; // VK_HANGUL (15) IME Hangul mode
+ // VK_JUNJA (17) IME Junja mode
+ // VK_FINAL (18) IME final mode
+ case Qt::Key_Hangul_Hanja:
+ return VK_HANJA; // (19) IME Hanja mode
+ case Qt::Key_Kanji:
+ return VK_KANJI; // (19) IME Kanji mode
+ case Qt::Key_Escape:
+ return VK_ESCAPE; // (1B) ESC key
+ // VK_CONVERT (1C) IME convert
+ // VK_NONCONVERT (1D) IME nonconvert
+ // VK_ACCEPT (1E) IME accept
+ // VK_MODECHANGE (1F) IME mode change request
+ case Qt::Key_Space:
+ return VK_SPACE; // (20) SPACEBAR
+ case Qt::Key_PageUp:
+ return VK_PRIOR; // (21) PAGE UP key
+ case Qt::Key_PageDown:
+ return VK_NEXT; // (22) PAGE DOWN key
+ case Qt::Key_End:
+ return VK_END; // (23) END key
+ case Qt::Key_Home:
+ return VK_HOME; // (24) HOME key
+ case Qt::Key_Left:
+ return VK_LEFT; // (25) LEFT ARROW key
+ case Qt::Key_Up:
+ return VK_UP; // (26) UP ARROW key
+ case Qt::Key_Right:
+ return VK_RIGHT; // (27) RIGHT ARROW key
+ case Qt::Key_Down:
+ return VK_DOWN; // (28) DOWN ARROW key
+ case Qt::Key_Select:
+ return VK_SELECT; // (29) SELECT key
+ case Qt::Key_Print:
+ return VK_SNAPSHOT; // (2A) PRINT key
+ case Qt::Key_Execute:
+ return VK_EXECUTE; // (2B) EXECUTE key
+ case Qt::Key_Insert:
+ return VK_INSERT; // (2D) INS key
+ case Qt::Key_Delete:
+ return VK_DELETE; // (2E) DEL key
+ case Qt::Key_Help:
+ return VK_HELP; // (2F) HELP key
+ case Qt::Key_0:
+ case Qt::Key_ParenLeft:
+ return VK_0; // (30) 0) key
+ case Qt::Key_1:
+ return VK_1; // (31) 1 ! key
+ case Qt::Key_2:
+ case Qt::Key_At:
+ return VK_2; // (32) 2 & key
+ case Qt::Key_3:
+ case Qt::Key_NumberSign:
+ return VK_3; // case '3': case '#';
+ case Qt::Key_4:
+ case Qt::Key_Dollar: // (34) 4 key '$';
+ return VK_4;
+ case Qt::Key_5:
+ case Qt::Key_Percent:
+ return VK_5; // (35) 5 key '%'
+ case Qt::Key_6:
+ case Qt::Key_AsciiCircum:
+ return VK_6; // (36) 6 key '^'
+ case Qt::Key_7:
+ case Qt::Key_Ampersand:
+ return VK_7; // (37) 7 key case '&'
+ case Qt::Key_8:
+ case Qt::Key_Asterisk:
+ return VK_8; // (38) 8 key '*'
+ case Qt::Key_9:
+ case Qt::Key_ParenRight:
+ return VK_9; // (39) 9 key '('
+ case Qt::Key_A:
+ return VK_A; // (41) A key case 'a': case 'A': return 0x41;
+ case Qt::Key_B:
+ return VK_B; // (42) B key case 'b': case 'B': return 0x42;
+ case Qt::Key_C:
+ return VK_C; // (43) C key case 'c': case 'C': return 0x43;
+ case Qt::Key_D:
+ return VK_D; // (44) D key case 'd': case 'D': return 0x44;
+ case Qt::Key_E:
+ return VK_E; // (45) E key case 'e': case 'E': return 0x45;
+ case Qt::Key_F:
+ return VK_F; // (46) F key case 'f': case 'F': return 0x46;
+ case Qt::Key_G:
+ return VK_G; // (47) G key case 'g': case 'G': return 0x47;
+ case Qt::Key_H:
+ return VK_H; // (48) H key case 'h': case 'H': return 0x48;
+ case Qt::Key_I:
+ return VK_I; // (49) I key case 'i': case 'I': return 0x49;
+ case Qt::Key_J:
+ return VK_J; // (4A) J key case 'j': case 'J': return 0x4A;
+ case Qt::Key_K:
+ return VK_K; // (4B) K key case 'k': case 'K': return 0x4B;
+ case Qt::Key_L:
+ return VK_L; // (4C) L key case 'l': case 'L': return 0x4C;
+ case Qt::Key_M:
+ return VK_M; // (4D) M key case 'm': case 'M': return 0x4D;
+ case Qt::Key_N:
+ return VK_N; // (4E) N key case 'n': case 'N': return 0x4E;
+ case Qt::Key_O:
+ return VK_O; // (4F) O key case 'o': case 'O': return 0x4F;
+ case Qt::Key_P:
+ return VK_P; // (50) P key case 'p': case 'P': return 0x50;
+ case Qt::Key_Q:
+ return VK_Q; // (51) Q key case 'q': case 'Q': return 0x51;
+ case Qt::Key_R:
+ return VK_R; // (52) R key case 'r': case 'R': return 0x52;
+ case Qt::Key_S:
+ return VK_S; // (53) S key case 's': case 'S': return 0x53;
+ case Qt::Key_T:
+ return VK_T; // (54) T key case 't': case 'T': return 0x54;
+ case Qt::Key_U:
+ return VK_U; // (55) U key case 'u': case 'U': return 0x55;
+ case Qt::Key_V:
+ return VK_V; // (56) V key case 'v': case 'V': return 0x56;
+ case Qt::Key_W:
+ return VK_W; // (57) W key case 'w': case 'W': return 0x57;
+ case Qt::Key_X:
+ return VK_X; // (58) X key case 'x': case 'X': return 0x58;
+ case Qt::Key_Y:
+ return VK_Y; // (59) Y key case 'y': case 'Y': return 0x59;
+ case Qt::Key_Z:
+ return VK_Z; // (5A) Z key case 'z': case 'Z': return 0x5A;
+ case Qt::Key_Meta:
+ return VK_LWIN; // (5B) Left Windows key (Microsoft Natural keyboard)
+ // case Qt::Key_Meta_R: FIXME: What to do here?
+ // return VK_RWIN; // (5C) Right Windows key (Natural keyboard)
+ // VK_APPS (5D) Applications key (Natural keyboard)
+ // VK_SLEEP (5F) Computer Sleep key
+ // VK_SEPARATOR (6C) Separator key
+ // VK_SUBTRACT (6D) Subtract key
+ // VK_DECIMAL (6E) Decimal key
+ // VK_DIVIDE (6F) Divide key
+ // handled by key code above
+
+ case Qt::Key_NumLock:
+ return VK_NUMLOCK; // (90) NUM LOCK key
+
+ case Qt::Key_ScrollLock:
+ return VK_SCROLL; // (91) SCROLL LOCK key
+
+ // VK_LSHIFT (A0) Left SHIFT key
+ // VK_RSHIFT (A1) Right SHIFT key
+ // VK_LCONTROL (A2) Left CONTROL key
+ // VK_RCONTROL (A3) Right CONTROL key
+ // VK_LMENU (A4) Left MENU key
+ // VK_RMENU (A5) Right MENU key
+ // VK_BROWSER_BACK (A6) Windows 2000/XP: Browser Back key
+ // VK_BROWSER_FORWARD (A7) Windows 2000/XP: Browser Forward key
+ // VK_BROWSER_REFRESH (A8) Windows 2000/XP: Browser Refresh key
+ // VK_BROWSER_STOP (A9) Windows 2000/XP: Browser Stop key
+ // VK_BROWSER_SEARCH (AA) Windows 2000/XP: Browser Search key
+ // VK_BROWSER_FAVORITES (AB) Windows 2000/XP: Browser Favorites key
+ // VK_BROWSER_HOME (AC) Windows 2000/XP: Browser Start and Home key
+ // VK_VOLUME_MUTE (AD) Windows 2000/XP: Volume Mute key
+ // VK_VOLUME_DOWN (AE) Windows 2000/XP: Volume Down key
+ // VK_VOLUME_UP (AF) Windows 2000/XP: Volume Up key
+ // VK_MEDIA_NEXT_TRACK (B0) Windows 2000/XP: Next Track key
+ // VK_MEDIA_PREV_TRACK (B1) Windows 2000/XP: Previous Track key
+ // VK_MEDIA_STOP (B2) Windows 2000/XP: Stop Media key
+ // VK_MEDIA_PLAY_PAUSE (B3) Windows 2000/XP: Play/Pause Media key
+ // VK_LAUNCH_MAIL (B4) Windows 2000/XP: Start Mail key
+ // VK_LAUNCH_MEDIA_SELECT (B5) Windows 2000/XP: Select Media key
+ // VK_LAUNCH_APP1 (B6) Windows 2000/XP: Start Application 1 key
+ // VK_LAUNCH_APP2 (B7) Windows 2000/XP: Start Application 2 key
+
+ // VK_OEM_1 (BA) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ';:' key
+ case Qt::Key_Semicolon:
+ case Qt::Key_Colon:
+ return VK_OEM_1; // case ';': case ':': return 0xBA;
+ // VK_OEM_PLUS (BB) Windows 2000/XP: For any country/region, the '+' key
+ case Qt::Key_Plus:
+ case Qt::Key_Equal:
+ return VK_OEM_PLUS; // case '=': case '+': return 0xBB;
+ // VK_OEM_COMMA (BC) Windows 2000/XP: For any country/region, the ',' key
+ case Qt::Key_Comma:
+ case Qt::Key_Less:
+ return VK_OEM_COMMA; // case ',': case '<': return 0xBC;
+ // VK_OEM_MINUS (BD) Windows 2000/XP: For any country/region, the '-' key
+ case Qt::Key_Minus:
+ case Qt::Key_Underscore:
+ return VK_OEM_MINUS; // case '-': case '_': return 0xBD;
+ // VK_OEM_PERIOD (BE) Windows 2000/XP: For any country/region, the '.' key
+ case Qt::Key_Period:
+ case Qt::Key_Greater:
+ return VK_OEM_PERIOD; // case '.': case '>': return 0xBE;
+ // VK_OEM_2 (BF) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '/?' key
+ case Qt::Key_Slash:
+ case Qt::Key_Question:
+ return VK_OEM_2; // case '/': case '?': return 0xBF;
+ // VK_OEM_3 (C0) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '`~' key
+ case Qt::Key_AsciiTilde:
+ case Qt::Key_QuoteLeft:
+ return VK_OEM_3; // case '`': case '~': return 0xC0;
+ // VK_OEM_4 (DB) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '[{' key
+ case Qt::Key_BracketLeft:
+ case Qt::Key_BraceLeft:
+ return VK_OEM_4; // case '[': case '{': return 0xDB;
+ // VK_OEM_5 (DC) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the '\|' key
+ case Qt::Key_Backslash:
+ case Qt::Key_Bar:
+ return VK_OEM_5; // case '\\': case '|': return 0xDC;
+ // VK_OEM_6 (DD) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the ']}' key
+ case Qt::Key_BracketRight:
+ case Qt::Key_BraceRight:
+ return VK_OEM_6; // case ']': case '}': return 0xDD;
+ // VK_OEM_7 (DE) Used for miscellaneous characters; it can vary by keyboard. Windows 2000/XP: For the US standard keyboard, the 'single-quote/double-quote' key
+ case Qt::Key_QuoteDbl:
+ return VK_OEM_7; // case '\'': case '"': return 0xDE;
+ // VK_OEM_8 (DF) Used for miscellaneous characters; it can vary by keyboard.
+ // VK_OEM_102 (E2) Windows 2000/XP: Either the angle bracket key or the backslash key on the RT 102-key keyboard
+ // VK_PROCESSKEY (E5) Windows 95/98/Me, Windows NT 4.0, Windows 2000/XP: IME PROCESS key
+ // VK_PACKET (E7) Windows 2000/XP: Used to pass Unicode characters as if they were keystrokes. The VK_PACKET key is the low word of a 32-bit Virtual Key value used for non-keyboard input methods. For more information, see Remark in KEYBDINPUT,SendInput, WM_KEYDOWN, and WM_KEYUP
+ // VK_ATTN (F6) Attn key
+ // VK_CRSEL (F7) CrSel key
+ // VK_EXSEL (F8) ExSel key
+ // VK_EREOF (F9) Erase EOF key
+ // VK_PLAY (FA) Play key
+ // VK_ZOOM (FB) Zoom key
+ // VK_NONAME (FC) Reserved for future use
+ // VK_PA1 (FD) PA1 key
+ // VK_OEM_CLEAR (FE) Clear key
+ default:
+ return 0;
+ }
+}
+
+static inline double currentTimeForEvent(const QInputEvent* event)
+{
+ Q_ASSERT(event);
+
+ if (event->timestamp())
+ return static_cast<double>(event->timestamp()) / 1000;
+
+ static QElapsedTimer timer;
+ if (!timer.isValid())
+ timer.start();
+ return static_cast<double>(timer.elapsed()) / 1000;
+}
+
+static WebMouseEvent::Button mouseButtonForEvent(QMouseEvent *event)
+{
+ if (event->button() == Qt::LeftButton || (event->buttons() & Qt::LeftButton))
+ return WebMouseEvent::ButtonLeft;
+ else if (event->button() == Qt::RightButton || (event->buttons() & Qt::RightButton))
+ return WebMouseEvent::ButtonRight;
+ else if (event->button() == Qt::MidButton || (event->buttons() & Qt::MidButton))
+ return WebMouseEvent::ButtonMiddle;
+ return WebMouseEvent::ButtonNone;
+}
+
+template <typename T>
+static unsigned mouseButtonsModifiersForEvent(const T* event)
+{
+ unsigned ret = 0;
+ if (event->buttons() & Qt::LeftButton)
+ ret |= WebInputEvent::LeftButtonDown;
+ if (event->buttons() & Qt::RightButton)
+ ret |= WebInputEvent::RightButtonDown;
+ if (event->buttons() & Qt::MidButton)
+ ret |= WebInputEvent::MiddleButtonDown;
+ return ret;
+}
+
+static inline WebInputEvent::Modifiers modifiersForEvent(const QInputEvent* event)
+{
+ unsigned result = 0;
+ Qt::KeyboardModifiers modifiers = event->modifiers();
+ if (modifiers & Qt::ShiftModifier)
+ result |= WebInputEvent::ShiftKey;
+ if (modifiers & Qt::ControlModifier)
+ result |= WebInputEvent::ControlKey;
+ if (modifiers & Qt::AltModifier)
+ result |= WebInputEvent::AltKey;
+ if (modifiers & Qt::MetaModifier)
+ result |= WebInputEvent::MetaKey;
+ if (modifiers & Qt::KeypadModifier)
+ result |= WebInputEvent::IsKeyPad;
+
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ case QEvent::MouseButtonRelease:
+ case QEvent::MouseMove:
+ result |= mouseButtonsModifiersForEvent(static_cast<const QMouseEvent*>(event));
+ break;
+ case QEvent::Wheel:
+ result |= mouseButtonsModifiersForEvent(static_cast<const QWheelEvent*>(event));
+ break;
+ case QEvent::KeyPress:
+ case QEvent::KeyRelease:
+ if (static_cast<const QKeyEvent*>(event)->isAutoRepeat())
+ result |= WebInputEvent::IsAutoRepeat;
+ default:
+ break;
+ }
+
+ return (WebInputEvent::Modifiers)result;
+}
+
+static WebInputEvent::Type webEventTypeForEvent(const QEvent* event)
+{
+ switch (event->type()) {
+ case QEvent::MouseButtonPress:
+ return WebInputEvent::MouseDown;
+ case QEvent::MouseButtonRelease:
+ return WebInputEvent::MouseUp;
+ case QEvent::MouseMove:
+ return WebInputEvent::MouseMove;
+ case QEvent::Wheel:
+ return WebInputEvent::MouseWheel;
+ case QEvent::KeyPress:
+ return WebInputEvent::KeyDown;
+ case QEvent::KeyRelease:
+ return WebInputEvent::KeyUp;
+ case QEvent::TouchBegin:
+ return WebInputEvent::TouchStart;
+ case QEvent::TouchUpdate:
+ return WebInputEvent::TouchMove;
+ case QEvent::TouchEnd:
+ return WebInputEvent::TouchEnd;
+ case QEvent::TouchCancel:
+ return WebInputEvent::TouchCancel;
+ case QEvent::MouseButtonDblClick:
+ return WebInputEvent::Undefined;
+ default:
+ Q_ASSERT(false);
+ return WebInputEvent::MouseMove;
+ }
+}
+
+
+WebMouseEvent WebEventFactory::toWebMouseEvent(QMouseEvent *ev)
+{
+ WebMouseEvent webKitEvent;
+ webKitEvent.timeStampSeconds = currentTimeForEvent(ev);
+ webKitEvent.button = mouseButtonForEvent(ev);
+ webKitEvent.modifiers = modifiersForEvent(ev);
+
+ webKitEvent.x = webKitEvent.windowX = ev->x();
+ webKitEvent.y = webKitEvent.windowY = ev->y();
+ webKitEvent.globalX = ev->globalX();
+ webKitEvent.globalY = ev->globalY();
+
+ webKitEvent.type = webEventTypeForEvent(ev);
+
+ switch (ev->type()) {
+ case QEvent::MouseButtonPress:
+ webKitEvent.clickCount = 1;
+ break;
+ case QEvent::MouseButtonDblClick:
+ webKitEvent.clickCount = 2;
+ break;
+ default:
+ webKitEvent.clickCount = 0;
+ break;
+ };
+
+ return webKitEvent;
+}
+
+WebKit::WebMouseWheelEvent WebEventFactory::toWebWheelEvent(QWheelEvent *ev)
+{
+ WebMouseWheelEvent webEvent;
+ webEvent.type = webEventTypeForEvent(ev);
+ webEvent.deltaX = 0;
+ webEvent.deltaY = 0;
+ webEvent.wheelTicksX = 0;
+ webEvent.wheelTicksY = 0;
+ webEvent.modifiers = modifiersForEvent(ev);
+ webEvent.timeStampSeconds = currentTimeForEvent(ev);
+
+ if (ev->orientation() == Qt::Horizontal)
+ webEvent.wheelTicksX = ev->delta() / 120.0f;
+ else
+ webEvent.wheelTicksY = ev->delta() / 120.0f;
+
+
+ // Since we report the scroll by the pixel, convert the delta to pixel distance using standard scroll step.
+ // Use the same single scroll step as QTextEdit (in QTextEditPrivate::init [h,v]bar->setSingleStep)
+ static const float cDefaultQtScrollStep = 20.f;
+
+ const int wheelScrollLines = qApp->wheelScrollLines(); // can be hardcoded to 3 if we don't want to depend on QtWidgets
+
+ webEvent.deltaX = webEvent.wheelTicksX * wheelScrollLines * cDefaultQtScrollStep;
+ webEvent.deltaY = webEvent.wheelTicksY * wheelScrollLines * cDefaultQtScrollStep;
+
+ webEvent.x = webEvent.windowX = ev->x();
+ webEvent.y = webEvent.windowY = ev->y();
+ webEvent.globalX = ev->globalX();
+ webEvent.globalY = ev->globalY();
+ return webEvent;
+}
+
+content::NativeWebKeyboardEvent WebEventFactory::toWebKeyboardEvent(QKeyEvent *ev)
+{
+ content::NativeWebKeyboardEvent webKitEvent;
+ webKitEvent.timeStampSeconds = currentTimeForEvent(ev);
+ webKitEvent.modifiers = modifiersForEvent(ev);
+ webKitEvent.type = webEventTypeForEvent(ev);
+
+ webKitEvent.nativeKeyCode = ev->nativeVirtualKey();
+ webKitEvent.windowsKeyCode = windowsKeyCodeForKeyEvent(ev->key(), ev->modifiers() & Qt::KeypadModifier);
+
+ memcpy(&webKitEvent.text, ev->text().utf16(), qMin(sizeof(webKitEvent.text), sizeof(ev->text().utf16())));
+ return webKitEvent;
+}
diff --git a/shared/web_event_factory.h b/shared/web_event_factory.h
new file mode 100644
index 000000000..061200ccc
--- /dev/null
+++ b/shared/web_event_factory.h
@@ -0,0 +1,61 @@
+/****************************************************************************
+**
+** 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 WEB_EVENT_FACTORY_H
+#define WEB_EVENT_FACTORY_H
+
+#include "content/public/browser/native_web_keyboard_event.h"
+#include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
+
+class QMouseEvent;
+class QKeyEvent;
+class QWheelEvent;
+
+class WebEventFactory {
+
+public:
+ static WebKit::WebMouseEvent toWebMouseEvent(QMouseEvent*);
+ static WebKit::WebMouseWheelEvent toWebWheelEvent(QWheelEvent*);
+ static content::NativeWebKeyboardEvent toWebKeyboardEvent(QKeyEvent*);
+};
+
+
+#endif