summaryrefslogtreecommitdiffstats
path: root/shared
diff options
context:
space:
mode:
authorJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-17 18:58:06 +0200
committerJocelyn Turcotte <jocelyn.turcotte@digia.com>2013-06-19 12:19:11 +0200
commitbbeaf3278de08da00f56aba3511951aaf6a8d233 (patch)
treef59de9808a942a2668f2bb73d0b03a1bebcd4b0f /shared
parent2d2da7d717d6bd354f5febe3deb8615685ca3280 (diff)
Allow the API class to provide the page widget rendering implementation.
- Rename NativeViewQt to RenderWidgetHostViewQtDelegate to keep the context obvious. - Use an interface to handle the parenting instead of the NativeViewContainerQt mechanism that was needed with the Shell.
Diffstat (limited to 'shared')
-rw-r--r--shared/native_view_container_qt.h116
-rw-r--r--shared/native_view_qt.cpp208
-rw-r--r--shared/native_view_qt.h97
-rw-r--r--shared/render_widget_host_view_qt.cpp60
-rw-r--r--shared/render_widget_host_view_qt.h5
-rw-r--r--shared/render_widget_host_view_qt_delegate.h21
-rw-r--r--shared/shared.pro6
7 files changed, 51 insertions, 462 deletions
diff --git a/shared/native_view_container_qt.h b/shared/native_view_container_qt.h
deleted file mode 100644
index 185a5b826..000000000
--- a/shared/native_view_container_qt.h
+++ /dev/null
@@ -1,116 +0,0 @@
-#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(true)
- {
- }
-
- 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_isQQuick = false;
- QVBoxLayout *l = new QVBoxLayout;
- l->setContentsMargins(0, 0, 0, 0);
- m_embeddable = l;
- }
- 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));
- connect(m_currentQQuickNativeView, SIGNAL(destroyed(QObject*)), this, SLOT(destroyedNativeView(QObject*)));
- 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)
- {
- 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);
- }
-
- void destroyedNativeView(QObject* nativeView)
- {
- m_currentQQuickNativeView = 0;
- }
-
-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
deleted file mode 100644
index 1a5716549..000000000
--- a/shared/native_view_qt.cpp
+++ /dev/null
@@ -1,208 +0,0 @@
-#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(const QRect& rect)
-{
- QWidget::update(rect);
-}
-
-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(const QRect& rect)
-{
- QQuickPaintedItem::update(rect);
-}
-
-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
deleted file mode 100644
index 6a15701e8..000000000
--- a/shared/native_view_qt.h
+++ /dev/null
@@ -1,97 +0,0 @@
-#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(const QRect& rect = QRect()) = 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(const QRect& rect = QRect());
-
- 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(const QRect& rect = QRect());
-
- 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/render_widget_host_view_qt.cpp b/shared/render_widget_host_view_qt.cpp
index 46a710591..759667000 100644
--- a/shared/render_widget_host_view_qt.cpp
+++ b/shared/render_widget_host_view_qt.cpp
@@ -42,9 +42,8 @@
#include "render_widget_host_view_qt.h"
#include "backing_store_qt.h"
+#include "render_widget_host_view_qt_delegate.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"
@@ -77,9 +76,9 @@ static void GetScreenInfoFromNativeWindow(QWindow* window, WebKit::WebScreenInfo
namespace content {
-RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
- RenderWidgetHost* widget) {
- return new RenderWidgetHostViewQt(widget);
+RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(RenderWidgetHost*) {
+ // WebContentsViewQt should take care of this directly.
+ Q_ASSERT(false);
}
// static
@@ -90,7 +89,7 @@ void RenderWidgetHostViewPort::GetDefaultScreenInfo(WebKit::WebScreenInfo* resul
RenderWidgetHostViewQt::RenderWidgetHostViewQt(content::RenderWidgetHost* widget)
: m_host(content::RenderWidgetHostImpl::From(widget))
- , m_view(0)
+ , m_delegate(0)
, about_to_validate_and_paint_(false)
{
m_host->SetView(this);
@@ -128,28 +127,19 @@ bool RenderWidgetHostViewQt::handleEvent(QEvent* event) {
content::BackingStore *RenderWidgetHostViewQt::AllocBackingStore(const gfx::Size &size)
{
- if (m_view)
- return new BackingStoreQt(m_host, size, new QWindow);
- return 0;
+ return new BackingStoreQt(m_host, size, new QWindow);
}
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
@@ -164,7 +154,7 @@ void RenderWidgetHostViewQt::SetSize(const gfx::Size& size)
// int width = std::min(size.width(), kMaxWindowWidth);
// int height = std::min(size.height(), kMaxWindowHeight);
// if (IsPopup())
- // m_view->resize(width,height);
+ // m_delegate->resize(width,height);
if (m_requestedSize.width() != width ||
m_requestedSize.height() != height) {
@@ -178,7 +168,7 @@ 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());
+ // m_delegate->setGeometry(rect.x(), rect.y(), rect.width(), rect.height());
SetSize(rect.size());
}
@@ -204,12 +194,12 @@ gfx::NativeViewAccessible RenderWidgetHostViewQt::GetNativeViewAccessible()
// Set focus to the associated View component.
void RenderWidgetHostViewQt::Focus()
{
- // m_view->setFocus(Qt::MouseFocusReason);
+ // m_delegate->setFocus(Qt::MouseFocusReason);
}
bool RenderWidgetHostViewQt::HasFocus() const
{
- // return m_view->hasFocus();
+ // return m_delegate->hasFocus();
return true;
}
@@ -220,23 +210,23 @@ bool RenderWidgetHostViewQt::IsSurfaceAvailableForCopy() const
void RenderWidgetHostViewQt::Show()
{
- m_view->show();
+ m_delegate->show();
}
void RenderWidgetHostViewQt::Hide()
{
- m_view->hide();
+ m_delegate->hide();
}
bool RenderWidgetHostViewQt::IsShowing()
{
- return m_view->isVisible();
+ return m_delegate->isVisible();
}
// Retrieve the bounds of the View, in screen coordinates.
gfx::Rect RenderWidgetHostViewQt::GetViewBounds() const
{
- QRectF p = m_view->screenRect();
+ QRectF p = m_delegate->screenRect();
return gfx::Rect(p.x(), p.y(), p.width(), p.height());
}
@@ -281,7 +271,7 @@ gfx::NativeView RenderWidgetHostViewQt::BuildInputMethodsGtkMenu()
void RenderWidgetHostViewQt::WasShown()
{
- if (m_view->isVisible())
+ if (m_delegate->isVisible())
return;
m_host->WasShown();
@@ -289,7 +279,7 @@ void RenderWidgetHostViewQt::WasShown()
void RenderWidgetHostViewQt::WasHidden()
{
- if (!m_view->isVisible())
+ if (!m_delegate->isVisible())
return;
m_host->WasHidden();
@@ -334,7 +324,7 @@ void RenderWidgetHostViewQt::ImeCompositionRangeChanged(const ui::Range&, const
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())
+ if (!m_delegate->isVisible())
return;
if (about_to_validate_and_paint_)
@@ -361,8 +351,8 @@ void RenderWidgetHostViewQt::RenderViewGone(base::TerminationStatus, int)
void RenderWidgetHostViewQt::Destroy()
{
- delete m_view;
- m_view = 0;
+ delete m_delegate;
+ m_delegate = 0;
}
void RenderWidgetHostViewQt::SetTooltipText(const string16&)
@@ -436,7 +426,7 @@ bool RenderWidgetHostViewQt::HasAcceleratedSurface(const gfx::Size&)
void RenderWidgetHostViewQt::GetScreenInfo(WebKit::WebScreenInfo* results)
{
- QWindow* window = m_view->window();
+ QWindow* window = m_delegate->window();
if (!window)
return;
GetScreenInfoFromNativeWindow(window, results);
@@ -444,10 +434,10 @@ void RenderWidgetHostViewQt::GetScreenInfo(WebKit::WebScreenInfo* results)
gfx::Rect RenderWidgetHostViewQt::GetBoundsInRootWindow()
{
- if (!m_view || !m_view->window())
+ if (!m_delegate->window())
return gfx::Rect();
- QRect r = m_view->window()->frameGeometry();
+ QRect r = m_delegate->window()->frameGeometry();
return gfx::Rect(r.x(), r.y(), r.width(), r.height());
}
@@ -479,10 +469,10 @@ void RenderWidgetHostViewQt::Paint(const gfx::Rect& damage_rect)
// Calling GetBackingStore maybe have changed |invalid_rect_|...
about_to_validate_and_paint_ = false;
- if (backing_store && m_view) {
- m_view->setBackingStore(backing_store);
+ if (backing_store) {
+ m_delegate->setBackingStore(backing_store);
QRect r(invalid_rect_.x(), invalid_rect_.y(), invalid_rect_.width(), invalid_rect_.height());
- m_view->update(r);
+ m_delegate->update(r);
}
}
diff --git a/shared/render_widget_host_view_qt.h b/shared/render_widget_host_view_qt.h
index fce2144df..79b9921ae 100644
--- a/shared/render_widget_host_view_qt.h
+++ b/shared/render_widget_host_view_qt.h
@@ -56,7 +56,7 @@ class QFocusEvent;
class QKeyEvent;
class QMouseEvent;
class QWheelEvent;
-class NativeViewQt;
+class RenderWidgetHostViewQtDelegate;
namespace content {
@@ -67,6 +67,7 @@ public:
RenderWidgetHostViewQt(content::RenderWidgetHost* widget);
~RenderWidgetHostViewQt();
+ void SetDelegate(RenderWidgetHostViewQtDelegate* delegate) { m_delegate = delegate; }
bool handleEvent(QEvent* event);
virtual content::BackingStore *AllocBackingStore(const gfx::Size &size);
@@ -136,7 +137,7 @@ private:
bool IsPopup() const;
content::RenderWidgetHostImpl *m_host;
- NativeViewQt *m_view;
+ RenderWidgetHostViewQtDelegate *m_delegate;
gfx::Size m_requestedSize;
// This is true when we are currently painting and thus should handle extra
diff --git a/shared/render_widget_host_view_qt_delegate.h b/shared/render_widget_host_view_qt_delegate.h
new file mode 100644
index 000000000..c01d7d942
--- /dev/null
+++ b/shared/render_widget_host_view_qt_delegate.h
@@ -0,0 +1,21 @@
+#ifndef RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_H
+#define RENDER_WIDGET_HOST_VIEW_QT_DELEGATE_H
+
+#include <QRect>
+
+class BackingStoreQt;
+class QWindow;
+
+class RenderWidgetHostViewQtDelegate {
+public:
+ virtual ~RenderWidgetHostViewQtDelegate() {}
+ 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(const QRect& rect = QRect()) = 0;
+};
+
+#endif
diff --git a/shared/shared.pro b/shared/shared.pro
index 33c5d4051..053dacc4b 100644
--- a/shared/shared.pro
+++ b/shared/shared.pro
@@ -23,13 +23,11 @@ QT += widgets quick
SOURCES = \
backing_store_qt.cpp \
render_widget_host_view_qt.cpp \
- web_event_factory.cpp \
- native_view_qt.cpp
+ web_event_factory.cpp
HEADERS = \
backing_store_qt.h \
- native_view_container_qt.h \
- native_view_qt.h \
render_widget_host_view_qt.h \
+ render_widget_host_view_qt_delegate.h \
web_event_factory.h