MiniBrowserApplication.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef MiniBrowserApplication_h
  29. #define MiniBrowserApplication_h
  30. #include <QHash>
  31. #include <QObject>
  32. #include <QStringList>
  33. #include <QtQml>
  34. #include <QGuiApplication>
  35. #include <QTouchEvent>
  36. #include <QUrl>
  37. #include <qpa/qwindowsysteminterface.h>
  38. class BrowserWindow;
  39. class WindowOptions : public QObject {
  40. Q_OBJECT
  41. Q_PROPERTY(bool printLoadedUrls READ printLoadedUrls)
  42. Q_PROPERTY(bool startMaximized READ startMaximized)
  43. Q_PROPERTY(bool touchMockingEnabled READ touchMockingEnabled WRITE setTouchMockingEnabled NOTIFY touchMockingEnabledChanged)
  44. public:
  45. WindowOptions(QObject* parent = 0)
  46. : QObject(parent)
  47. , m_printLoadedUrls(false)
  48. , m_startMaximized(false)
  49. , m_touchMockingEnabled(true)
  50. , m_windowSize(QSize(980, 735))
  51. {
  52. }
  53. void setPrintLoadedUrls(bool enabled) { m_printLoadedUrls = enabled; }
  54. bool printLoadedUrls() const { return m_printLoadedUrls; }
  55. void setStartMaximized(bool enabled) { m_startMaximized = enabled; }
  56. bool startMaximized() const { return m_startMaximized; }
  57. void setStartFullScreen(bool enabled) { m_startFullScreen = enabled; }
  58. bool startFullScreen() const { return m_startFullScreen; }
  59. void setRequestedWindowSize(const QSize& size) { m_windowSize = size; }
  60. QSize requestedWindowSize() const { return m_windowSize; }
  61. void setUserAgent(const QString& userAgent) { m_userAgent = userAgent; }
  62. QString userAgent() const { return m_userAgent; }
  63. bool touchMockingEnabled() const { return m_touchMockingEnabled; }
  64. void setTouchMockingEnabled(bool enabled)
  65. {
  66. if (enabled != m_touchMockingEnabled) {
  67. m_touchMockingEnabled = enabled;
  68. emit touchMockingEnabledChanged();
  69. }
  70. }
  71. Q_SIGNALS:
  72. void touchMockingEnabledChanged();
  73. private:
  74. bool m_printLoadedUrls;
  75. bool m_startMaximized;
  76. bool m_startFullScreen;
  77. bool m_touchMockingEnabled;
  78. QSize m_windowSize;
  79. QString m_userAgent;
  80. };
  81. class MiniBrowserApplication : public QGuiApplication {
  82. Q_OBJECT
  83. public:
  84. MiniBrowserApplication(int& argc, char** argv);
  85. QStringList urls() const { return m_urls; }
  86. bool isRobotized() const { return m_isRobotized; }
  87. int robotTimeout() const { return m_robotTimeoutSeconds; }
  88. int robotExtraTime() const { return m_robotExtraTimeSeconds; }
  89. WindowOptions* windowOptions() { return &m_windowOptions; }
  90. virtual bool notify(QObject*, QEvent*);
  91. private:
  92. void updateTouchPoint(const QMouseEvent*, QTouchEvent::TouchPoint, Qt::MouseButton);
  93. bool sendTouchEvent(BrowserWindow*, QEvent::Type, ulong timestamp);
  94. void handleUserOptions();
  95. private:
  96. bool m_realTouchEventReceived;
  97. int m_pendingFakeTouchEventCount;
  98. bool m_isRobotized;
  99. int m_robotTimeoutSeconds;
  100. int m_robotExtraTimeSeconds;
  101. QStringList m_urls;
  102. QHash<int, QTouchEvent::TouchPoint> m_touchPoints;
  103. QSet<int> m_heldTouchPoints;
  104. WindowOptions m_windowOptions;
  105. bool m_holdingControl;
  106. };
  107. QML_DECLARE_TYPE(WindowOptions);
  108. #endif