[Release] Webkit2-efl-123997_0.11.78
[framework/web/webkit-efl.git] / Tools / MiniBrowser / qt / MiniBrowserApplication.h
1 /*
2  * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
3  * Copyright (C) 2010 University of Szeged
4  *
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  */
28
29 #ifndef MiniBrowserApplication_h
30 #define MiniBrowserApplication_h
31
32 #include <QHash>
33 #include <QObject>
34 #include <QStringList>
35 #include <QtQml>
36 #include <QGuiApplication>
37 #include <QTouchEvent>
38 #include <QUrl>
39 #include <qpa/qwindowsysteminterface.h>
40
41 class BrowserWindow;
42
43 class WindowOptions : public QObject {
44     Q_OBJECT
45     Q_PROPERTY(bool printLoadedUrls READ printLoadedUrls)
46     Q_PROPERTY(bool startMaximized READ startMaximized)
47     Q_PROPERTY(bool touchMockingEnabled READ touchMockingEnabled WRITE setTouchMockingEnabled NOTIFY touchMockingEnabledChanged)
48
49 public:
50     WindowOptions(QObject* parent = 0)
51         : QObject(parent)
52         , m_printLoadedUrls(false)
53         , m_startMaximized(false)
54         , m_touchMockingEnabled(true)
55         , m_windowSize(QSize(980, 735))
56     {
57     }
58
59     void setPrintLoadedUrls(bool enabled) { m_printLoadedUrls = enabled; }
60     bool printLoadedUrls() const { return m_printLoadedUrls; }
61     void setStartMaximized(bool enabled) { m_startMaximized = enabled; }
62     bool startMaximized() const { return m_startMaximized; }
63     void setStartFullScreen(bool enabled) { m_startFullScreen = enabled; }
64     bool startFullScreen() const { return m_startFullScreen; }
65     void setRequestedWindowSize(const QSize& size) { m_windowSize = size; }
66     QSize requestedWindowSize() const { return m_windowSize; }
67     void setUserAgent(const QString& userAgent) { m_userAgent = userAgent; }
68     QString userAgent() const { return m_userAgent; }
69     bool touchMockingEnabled() const { return m_touchMockingEnabled; }
70     void setTouchMockingEnabled(bool enabled)
71     {
72         if (enabled != m_touchMockingEnabled) {
73             m_touchMockingEnabled = enabled;
74             emit touchMockingEnabledChanged();
75         }
76     }
77
78 signals:
79     void touchMockingEnabledChanged();
80
81 private:
82     bool m_printLoadedUrls;
83     bool m_startMaximized;
84     bool m_startFullScreen;
85     bool m_touchMockingEnabled;
86     QSize m_windowSize;
87     QString m_userAgent;
88 };
89
90 class MiniBrowserApplication : public QGuiApplication {
91     Q_OBJECT
92
93 public:
94     MiniBrowserApplication(int& argc, char** argv);
95     QStringList urls() const { return m_urls; }
96     bool isRobotized() const { return m_isRobotized; }
97     int robotTimeout() const { return m_robotTimeoutSeconds; }
98     int robotExtraTime() const { return m_robotExtraTimeSeconds; }
99     WindowOptions* windowOptions() { return &m_windowOptions; }
100
101     virtual bool notify(QObject*, QEvent*);
102
103 private:
104     void updateTouchPoint(const QMouseEvent*, QTouchEvent::TouchPoint, Qt::MouseButton);
105     bool sendTouchEvent(BrowserWindow*, QEvent::Type, ulong timestamp);
106     void handleUserOptions();
107
108 private:
109     bool m_realTouchEventReceived;
110     int m_pendingFakeTouchEventCount;
111     bool m_isRobotized;
112     int m_robotTimeoutSeconds;
113     int m_robotExtraTimeSeconds;
114     QStringList m_urls;
115
116     QHash<int, QTouchEvent::TouchPoint> m_touchPoints;
117     QSet<int> m_heldTouchPoints;
118
119     WindowOptions m_windowOptions;
120     bool m_holdingControl;
121 };
122
123 QML_DECLARE_TYPE(WindowOptions);
124
125 #endif