on d07cfbe help sign in
237 lines 6.7 kB history raw
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 */
17#ifndef MOCK_MIR_SURFACE_H
18#define MOCK_MIR_SURFACE_H
20#include <QObject>
21#include <QTimer>
22#include <QUrl>
23#include <QHash>
25// unity-api
26#include <unity/shell/application/MirSurfaceInterface.h>
28#include "MirSurfaceListModel.h"
30class MirSurface;
32class MirSurface : public unity::shell::application::MirSurfaceInterface
34 Q_OBJECT
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)
44public:
45 MirSurface(const QString& name,
46 Mir::Type type,
47 Mir::State state,
48 MirSurface *parentSurface,
49 const QUrl& screenshot,
50 const QUrl &qmlFilePath = QUrl());
51 virtual ~MirSurface();
53 ////
54 // unity.shell.application.MirSurface
56 Mir::Type type() const override;
58 QString name() const override;
60 QString persistentId() const override;
61 QString appId() const override;
63 QPoint position() const override { return m_position; }
65 QSize size() const override { return QSize(width(),height()); }
66 void resize(int width, int height) override;
67 void resize(const QSize &size) override { resize(size.width(), size.height()); }
70 Mir::State state() const override;
72 bool live() const override;
74 bool visible() const override;
76 Mir::OrientationAngle orientationAngle() const override;
77 void setOrientationAngle(Mir::OrientationAngle) override;
79 int minimumWidth() const override { return m_minimumWidth; }
80 int minimumHeight() const override { return m_minimumHeight; }
81 int maximumWidth() const override { return m_maximumWidth; }
82 int maximumHeight() const override { return m_maximumHeight; }
83 int widthIncrement() const override { return m_widthIncrement; }
84 int heightIncrement() const override { return m_heightIncrement; }
86 void setKeymap(const QString &) override;
87 QString keymap() const override;
89 Mir::ShellChrome shellChrome() const override;
91 bool focused() const override;
92 QRect inputBounds() const override;
94 bool confinesMousePointer() const override { return false; }
96 bool allowClientResize() const override { return true; }
97 void setAllowClientResize(bool) override {}
99 QPoint requestedPosition() const override { return m_requestedPosition; }
100 void setRequestedPosition(const QPoint &) override;
102 unity::shell::application::MirSurfaceInterface* parentSurface() const override;
103 unity::shell::application::MirSurfaceListInterface* childSurfaceList() const override;
105 Q_INVOKABLE void close() override;
106 Q_INVOKABLE void forceClose() override { }
107 Q_INVOKABLE void activate() override;
109 ////
110 // API for tests
112 Q_INVOKABLE void requestFocus();
113 Q_INVOKABLE void setLive(bool live);
114 Q_INVOKABLE void setShellChrome(Mir::ShellChrome shellChrome);
116 int width() const;
117 int height() const;
119 bool isSlowToResize() const;
120 void setSlowToResize(bool value);
122 bool exposed() const { return m_exposed; }
124 Q_INVOKABLE void setMinimumWidth(int);
125 Q_INVOKABLE void setMaximumWidth(int);
126 Q_INVOKABLE void setMinimumHeight(int);
127 Q_INVOKABLE void setMaximumHeight(int);
128 Q_INVOKABLE void setWidthIncrement(int);
129 Q_INVOKABLE void setHeightIncrement(int);
131 Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect);
133 Q_INVOKABLE void openMenu(qreal x, qreal y, qreal width, qreal height);
134 Q_INVOKABLE void openDialog(qreal x, qreal y, qreal width, qreal height);
136 /////
137 // internal mock stuff
139 QUrl qmlFilePath() const;
141 QUrl screenshotUrl() const;
142 void setScreenshotUrl(QUrl);
144 bool activeFocus() const;
145 void setActiveFocus(bool);
147 void registerView(qintptr viewId);
148 void unregisterView(qintptr viewId);
149 void setViewExposure(qintptr viewId, bool visible);
150 int viewCount() const { return m_views.count(); }
152 void setFocused(bool value);
154 void setState(Mir::State state);
156 Mir::State previousState() const { return m_previousState; }
157 void setPreviousState(Mir::State state) { m_previousState = state; }
159public Q_SLOTS:
160 ////
161 // unity.shell.application.MirSurface
162 void requestState(Mir::State) override;
164Q_SIGNALS:
165 ////
166 // API for tests
167 void widthChanged();
168 void heightChanged();
169 void slowToResizeChanged();
170 void exposedChanged(bool exposed);
172 ////
173 // internal mock stuff
174 void screenshotUrlChanged(QUrl);
175 void activeFocusChanged(bool);
176 void closeRequested();
177 void stateRequested(Mir::State);
179protected:
180 virtual void updateInputBoundsAfterResize();
182private Q_SLOTS:
183 void applyDelayedResize();
185private:
186 void doResize(int width, int height);
187 void updateExposure();
189 const QString m_name;
190 const Mir::Type m_type;
191 Mir::State m_state;
192 Mir::State m_previousState{Mir::UnknownState};
193 Mir::OrientationAngle m_orientationAngle;
195 QUrl m_screenshotUrl;
196 QUrl m_qmlFilePath;
197 bool m_live;
198 bool m_focused;
199 bool m_activeFocus;
200 int m_width;
201 int m_height;
203 int m_minimumWidth{0};
204 int m_minimumHeight{0};
205 int m_maximumWidth{0};
206 int m_maximumHeight{0};
207 int m_widthIncrement{0};
208 int m_heightIncrement{0};
210 QString m_keymap;
212 bool m_slowToResize;
213 QTimer m_delayedResizeTimer;
214 QSize m_delayedResize;
215 QSize m_pendingResize;
217 Mir::ShellChrome m_shellChrome;
219 struct View {
220 bool visible;
221 };
222 QHash<qintptr, View> m_views;
223 bool m_exposed{false};
225 QTimer m_zombieTimer;
227 QRect m_inputBounds;
229 QPoint m_position;
230 QPoint m_requestedPosition;
232 unity::shell::application::MirSurfaceInterface* m_parentSurface;
234 MirSurfaceListModel *m_childSurfaceList;
235};
237#endif // MOCK_MIR_SURFACE_H