summaryrefslogtreecommitdiffstats
path: root/shared/native_view_qt.h
blob: 6a15701e883c8a04d21269dbfb2fe00f77c17de0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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(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