1/*
2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3 *
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12 * Library General Public License for more details.
13 *
14 * You should have received a copy of the GNU Library General Public License
15 * along with this program; see the file COPYING.LIB.  If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
18 *
19 */
20
21#ifndef qwkpage_p_h
22#define qwkpage_p_h
23
24#include "DrawingAreaProxy.h"
25#include "LayerTreeContext.h"
26#include "PageClient.h"
27#include "qwkpage.h"
28#include "qgraphicswkview.h"
29#include "WebPageProxy.h"
30#include <wtf/PassOwnPtr.h>
31#include <wtf/RefPtr.h>
32#include <QBasicTimer>
33#include <QGraphicsView>
34#include <QKeyEvent>
35
36class QGraphicsWKView;
37class QWKPreferences;
38
39using namespace WebKit;
40
41class QWKPagePrivate : WebKit::PageClient {
42public:
43    QWKPagePrivate(QWKPage*, QWKContext*);
44    ~QWKPagePrivate();
45
46    static QWKPagePrivate* get(QWKPage* page) { return page->d; }
47
48    void init(QGraphicsItem*, QGraphicsWKView::BackingStoreType);
49
50    // PageClient
51    virtual PassOwnPtr<WebKit::DrawingAreaProxy> createDrawingAreaProxy();
52    virtual void setViewNeedsDisplay(const WebCore::IntRect&);
53    virtual void displayView();
54    virtual void scrollView(const WebCore::IntRect& scrollRect, const WebCore::IntSize& scrollOffset);
55
56    virtual WebCore::IntSize viewSize();
57    virtual bool isViewWindowActive();
58    virtual bool isViewFocused();
59    virtual bool isViewVisible();
60    virtual bool isViewInWindow();
61
62#if USE(ACCELERATED_COMPOSITING)
63    virtual void enterAcceleratedCompositingMode(const LayerTreeContext&);
64    virtual void exitAcceleratedCompositingMode();
65#endif // USE(ACCELERATED_COMPOSITING)
66    virtual void pageDidRequestScroll(const WebCore::IntPoint&);
67    virtual void processDidCrash();
68    virtual void pageClosed() { }
69    virtual void didRelaunchProcess();
70    virtual void didChangeContentsSize(const WebCore::IntSize&);
71    virtual void didFindZoomableArea(const WebCore::IntRect&);
72    virtual void setCursor(const WebCore::Cursor&);
73    virtual void setViewportArguments(const WebCore::ViewportArguments&);
74    virtual void toolTipChanged(const WTF::String&, const WTF::String&);
75    virtual void registerEditCommand(PassRefPtr<WebKit::WebEditCommandProxy>, WebKit::WebPageProxy::UndoOrRedo);
76    virtual void clearAllEditCommands();
77    virtual bool canUndoRedo(WebPageProxy::UndoOrRedo);
78    virtual void executeUndoRedo(WebPageProxy::UndoOrRedo);
79    virtual WebCore::FloatRect convertToDeviceSpace(const WebCore::FloatRect&);
80    virtual WebCore::FloatRect convertToUserSpace(const WebCore::FloatRect&);
81    virtual WebCore::IntRect windowToScreen(const WebCore::IntRect&);
82
83    virtual void doneWithKeyEvent(const WebKit::NativeWebKeyboardEvent&, bool wasEventHandled);
84    virtual void selectionChanged(bool, bool, bool, bool);
85    virtual PassRefPtr<WebKit::WebPopupMenuProxy> createPopupMenuProxy(WebKit::WebPageProxy*);
86    virtual PassRefPtr<WebKit::WebContextMenuProxy> createContextMenuProxy(WebKit::WebPageProxy*);
87
88    virtual void setFindIndicator(PassRefPtr<WebKit::FindIndicator>, bool fadeOut);
89
90    virtual void didCommitLoadForMainFrame(bool useCustomRepresentation);
91    virtual void didFinishLoadingDataForCustomRepresentation(const String& suggestedFilename, const CoreIPC::DataReference&);
92    virtual double customRepresentationZoomFactor() { return 1; }
93    virtual void setCustomRepresentationZoomFactor(double) { }
94    virtual void didChangeScrollbarsForMainFrame() const { }
95
96    virtual void flashBackingStoreUpdates(const Vector<WebCore::IntRect>& updateRects);
97    virtual void findStringInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount) { }
98    virtual void countStringMatchesInCustomRepresentation(const String&, FindOptions, unsigned maxMatchCount) { }
99    virtual float userSpaceScaleFactor() const { return 1; }
100
101    void paint(QPainter* painter, QRect);
102
103    void keyPressEvent(QKeyEvent*);
104    void keyReleaseEvent(QKeyEvent*);
105    void mouseMoveEvent(QGraphicsSceneMouseEvent*);
106    void mousePressEvent(QGraphicsSceneMouseEvent*);
107    void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
108    void mouseDoubleClickEvent(QGraphicsSceneMouseEvent*);
109    void wheelEvent(QGraphicsSceneWheelEvent*);
110
111    void updateAction(QWKPage::WebAction action);
112    void updateNavigationActions();
113    void updateEditorActions();
114
115    void _q_webActionTriggered(bool checked);
116
117    void touchEvent(QTouchEvent*);
118
119    QWKPage* q;
120
121    QGraphicsItem* view;
122    QWKContext* context;
123    QWKHistory* history;
124
125    QAction* actions[QWKPage::WebActionCount];
126    QWKPreferences* preferences;
127
128    RefPtr<WebKit::WebPageProxy> page;
129
130    WebCore::ViewportArguments viewportArguments;
131
132    QWKPage::CreateNewPageFn createNewPageFn;
133
134    QPoint tripleClick;
135    QBasicTimer tripleClickTimer;
136    QGraphicsWKView::BackingStoreType backingStoreType;
137
138    bool isConnectedToEngine;
139};
140
141class QtViewportAttributesPrivate : public QSharedData {
142public:
143    QtViewportAttributesPrivate(QWKPage::ViewportAttributes* qq)
144        : q(qq)
145    { }
146
147    QWKPage::ViewportAttributes* q;
148};
149
150
151#endif /* qkpage_p_h */
152