| 1 |
/* |
| 2 |
* Copyright (C) 2015-2016 Canonical Ltd. |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or modify |
| 5 |
* it under the terms of the GNU General Public License as published by |
| 6 |
* the Free Software Foundation; version 3. |
| 7 |
* |
| 8 |
* This program is distributed in the hope that it will be useful, |
| 9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 |
* GNU General Public License for more details. |
| 12 |
* |
| 13 |
* You should have received a copy of the GNU General Public License |
| 14 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 15 |
*/ |
| 16 |
|
| 17 |
#ifndef MOCK_MIR_SURFACE_H |
| 18 |
#define MOCK_MIR_SURFACE_H |
| 19 |
|
| 20 |
#include <QObject> |
| 21 |
#include <QTimer> |
| 22 |
#include <QUrl> |
| 23 |
#include <QHash> |
| 24 |
|
| 25 |
// lomiri-api |
| 26 |
#include <lomiri/shell/application/MirSurfaceInterface.h> |
| 27 |
|
| 28 |
#include "MirSurfaceListModel.h" |
| 29 |
|
| 30 |
class MirSurface; |
| 31 |
|
| 32 |
class MirSurface : public lomiri::shell::application::MirSurfaceInterface |
| 33 |
{ |
| 34 |
Q_OBJECT |
| 35 |
|
| 36 |
//// |
| 37 |
// for use in qml tests |
| 38 |
Q_PROPERTY(int width READ width NOTIFY widthChanged) |
| 39 |
Q_PROPERTY(int height READ height NOTIFY heightChanged) |
| 40 |
Q_PROPERTY(bool activeFocus READ activeFocus NOTIFY activeFocusChanged) |
| 41 |
Q_PROPERTY(bool slowToResize READ isSlowToResize WRITE setSlowToResize NOTIFY slowToResizeChanged) |
| 42 |
Q_PROPERTY(bool exposed READ exposed NOTIFY exposedChanged) |
| 43 |
Q_PROPERTY(bool isReady READ isReady NOTIFY ready) |
| 44 |
|
| 45 |
public: |
| 46 |
MirSurface(const QString& name, |
| 47 |
Mir::Type type, |
| 48 |
Mir::State state, |
| 49 |
MirSurface *parentSurface, |
| 50 |
const QUrl& screenshot, |
| 51 |
const QUrl &qmlFilePath = QUrl()); |
| 52 |
virtual ~MirSurface(); |
| 53 |
|
| 54 |
//// |
| 55 |
// lomiri.shell.application.MirSurface |
| 56 |
|
| 57 |
Mir::Type type() const override; |
| 58 |
|
| 59 |
QString name() const override; |
| 60 |
|
| 61 |
QString persistentId() const override; |
| 62 |
QString appId() const override; |
| 63 |
|
| 64 |
QPoint position() const override { return m_position; } |
| 65 |
|
| 66 |
QSize size() const override { return QSize(width(),height()); } |
| 67 |
void resize(int width, int height) override; |
| 68 |
void resize(const QSize &size) override { resize(size.width(), size.height()); } |
| 69 |
|
| 70 |
|
| 71 |
Mir::State state() const override; |
| 72 |
|
| 73 |
bool live() const override; |
| 74 |
bool isReady() const override; |
| 75 |
|
| 76 |
bool visible() const override; |
| 77 |
|
| 78 |
Mir::OrientationAngle orientationAngle() const override; |
| 79 |
void setOrientationAngle(Mir::OrientationAngle) override; |
| 80 |
|
| 81 |
int minimumWidth() const override { return m_minimumWidth; } |
| 82 |
int minimumHeight() const override { return m_minimumHeight; } |
| 83 |
int maximumWidth() const override { return m_maximumWidth; } |
| 84 |
int maximumHeight() const override { return m_maximumHeight; } |
| 85 |
int widthIncrement() const override { return m_widthIncrement; } |
| 86 |
int heightIncrement() const override { return m_heightIncrement; } |
| 87 |
|
| 88 |
void setKeymap(const QString &) override; |
| 89 |
QString keymap() const override; |
| 90 |
|
| 91 |
Mir::ShellChrome shellChrome() const override; |
| 92 |
|
| 93 |
bool focused() const override; |
| 94 |
QRect inputBounds() const override; |
| 95 |
|
| 96 |
bool confinesMousePointer() const override { return false; } |
| 97 |
|
| 98 |
bool allowClientResize() const override { return true; } |
| 99 |
void setAllowClientResize(bool) override {} |
| 100 |
|
| 101 |
QPoint requestedPosition() const override { return m_requestedPosition; } |
| 102 |
void setRequestedPosition(const QPoint &) override; |
| 103 |
|
| 104 |
lomiri::shell::application::MirSurfaceInterface* parentSurface() const override; |
| 105 |
lomiri::shell::application::MirSurfaceListInterface* childSurfaceList() const override; |
| 106 |
|
| 107 |
Q_INVOKABLE void close() override; |
| 108 |
Q_INVOKABLE void forceClose() override { } |
| 109 |
Q_INVOKABLE void activate() override; |
| 110 |
|
| 111 |
//// |
| 112 |
// API for tests |
| 113 |
|
| 114 |
Q_INVOKABLE void requestFocus(); |
| 115 |
Q_INVOKABLE void setLive(bool live); |
| 116 |
Q_INVOKABLE void setShellChrome(Mir::ShellChrome shellChrome); |
| 117 |
|
| 118 |
int width() const; |
| 119 |
int height() const; |
| 120 |
void setReady(); |
| 121 |
|
| 122 |
bool isSlowToResize() const; |
| 123 |
void setSlowToResize(bool value); |
| 124 |
|
| 125 |
bool exposed() const { return m_exposed; } |
| 126 |
|
| 127 |
Q_INVOKABLE void setMinimumWidth(int); |
| 128 |
Q_INVOKABLE void setMaximumWidth(int); |
| 129 |
Q_INVOKABLE void setMinimumHeight(int); |
| 130 |
Q_INVOKABLE void setMaximumHeight(int); |
| 131 |
Q_INVOKABLE void setWidthIncrement(int); |
| 132 |
Q_INVOKABLE void setHeightIncrement(int); |
| 133 |
|
| 134 |
Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect); |
| 135 |
|
| 136 |
Q_INVOKABLE void openMenu(qreal x, qreal y, qreal width, qreal height); |
| 137 |
Q_INVOKABLE void openDialog(qreal x, qreal y, qreal width, qreal height); |
| 138 |
|
| 139 |
///// |
| 140 |
// internal mock stuff |
| 141 |
|
| 142 |
QUrl qmlFilePath() const; |
| 143 |
|
| 144 |
QUrl screenshotUrl() const; |
| 145 |
void setScreenshotUrl(QUrl); |
| 146 |
|
| 147 |
bool activeFocus() const; |
| 148 |
void setActiveFocus(bool); |
| 149 |
|
| 150 |
void registerView(qintptr viewId); |
| 151 |
void unregisterView(qintptr viewId); |
| 152 |
void setViewExposure(qintptr viewId, bool visible); |
| 153 |
int viewCount() const { return m_views.count(); } |
| 154 |
|
| 155 |
void setFocused(bool value); |
| 156 |
|
| 157 |
void setState(Mir::State state); |
| 158 |
|
| 159 |
Mir::State previousState() const { return m_previousState; } |
| 160 |
void setPreviousState(Mir::State state) { m_previousState = state; } |
| 161 |
|
| 162 |
public Q_SLOTS: |
| 163 |
//// |
| 164 |
// lomiri.shell.application.MirSurface |
| 165 |
void requestState(Mir::State) override; |
| 166 |
|
| 167 |
Q_SIGNALS: |
| 168 |
//// |
| 169 |
// API for tests |
| 170 |
void widthChanged(); |
| 171 |
void heightChanged(); |
| 172 |
void slowToResizeChanged(); |
| 173 |
void exposedChanged(bool exposed); |
| 174 |
void ready(); |
| 175 |
|
| 176 |
//// |
| 177 |
// internal mock stuff |
| 178 |
void screenshotUrlChanged(QUrl); |
| 179 |
void activeFocusChanged(bool); |
| 180 |
void closeRequested(); |
| 181 |
void stateRequested(Mir::State); |
| 182 |
|
| 183 |
protected: |
| 184 |
virtual void updateInputBoundsAfterResize(); |
| 185 |
|
| 186 |
private Q_SLOTS: |
| 187 |
void applyDelayedResize(); |
| 188 |
|
| 189 |
private: |
| 190 |
void doResize(int width, int height); |
| 191 |
void updateExposure(); |
| 192 |
|
| 193 |
const QString m_name; |
| 194 |
const Mir::Type m_type; |
| 195 |
Mir::State m_state; |
| 196 |
Mir::State m_previousState{Mir::UnknownState}; |
| 197 |
Mir::OrientationAngle m_orientationAngle; |
| 198 |
|
| 199 |
QUrl m_screenshotUrl; |
| 200 |
QUrl m_qmlFilePath; |
| 201 |
bool m_live; |
| 202 |
bool m_ready; |
| 203 |
bool m_focused; |
| 204 |
bool m_activeFocus; |
| 205 |
int m_width; |
| 206 |
int m_height; |
| 207 |
|
| 208 |
int m_minimumWidth{0}; |
| 209 |
int m_minimumHeight{0}; |
| 210 |
int m_maximumWidth{0}; |
| 211 |
int m_maximumHeight{0}; |
| 212 |
int m_widthIncrement{0}; |
| 213 |
int m_heightIncrement{0}; |
| 214 |
|
| 215 |
QString m_keymap; |
| 216 |
|
| 217 |
bool m_slowToResize; |
| 218 |
QTimer m_delayedResizeTimer; |
| 219 |
QSize m_delayedResize; |
| 220 |
QSize m_pendingResize; |
| 221 |
|
| 222 |
Mir::ShellChrome m_shellChrome; |
| 223 |
|
| 224 |
struct View { |
| 225 |
bool visible; |
| 226 |
}; |
| 227 |
QHash<qintptr, View> m_views; |
| 228 |
bool m_exposed{false}; |
| 229 |
|
| 230 |
QTimer m_zombieTimer; |
| 231 |
|
| 232 |
QTimer m_readyTimer; |
| 233 |
|
| 234 |
QRect m_inputBounds; |
| 235 |
|
| 236 |
QPoint m_position; |
| 237 |
QPoint m_requestedPosition; |
| 238 |
|
| 239 |
lomiri::shell::application::MirSurfaceInterface* m_parentSurface; |
| 240 |
|
| 241 |
MirSurfaceListModel *m_childSurfaceList; |
| 242 |
}; |
| 243 |
|
| 244 |
#endif // MOCK_MIR_SURFACE_H |