on bb09f86 help sign in
232 lines 6.5 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;
62 QPoint position() const override { return m_position; }
64 QSize size() const override { return QSize(width(),height()); }
65 void resize(int width, int height) override;
66 void resize(const QSize &size) override { resize(size.width(), size.height()); }
69 Mir::State state() const override;
71 bool live() const override;
73 bool visible() const override;
75 Mir::OrientationAngle orientationAngle() const override;
76 void setOrientationAngle(Mir::OrientationAngle) override;
78 int minimumWidth() const override { return m_minimumWidth; }
79 int minimumHeight() const override { return m_minimumHeight; }
80 int maximumWidth() const override { return m_maximumWidth; }
81 int maximumHeight() const override { return m_maximumHeight; }
82 int widthIncrement() const override { return m_widthIncrement; }
83 int heightIncrement() const override { return m_heightIncrement; }
85 void setKeymap(const QString &) override;
86 QString keymap() const override;
88 Mir::ShellChrome shellChrome() const override;
90 bool focused() const override;
91 QRect inputBounds() const override;
93 bool confinesMousePointer() const override { return false; }
95 QPoint requestedPosition() const override { return m_requestedPosition; }
96 void setRequestedPosition(const QPoint &) override;
98 unity::shell::application::MirSurfaceInterface* parentSurface() const override;
99 unity::shell::application::MirSurfaceListInterface* childSurfaceList() const override;
101 Q_INVOKABLE void close() override;
102 Q_INVOKABLE void activate() override;
104 ////
105 // API for tests
107 Q_INVOKABLE void requestFocus();
108 Q_INVOKABLE void setLive(bool live);
109 Q_INVOKABLE void setShellChrome(Mir::ShellChrome shellChrome);
111 int width() const;
112 int height() const;
114 bool isSlowToResize() const;
115 void setSlowToResize(bool value);
117 bool exposed() const { return m_exposed; }
119 Q_INVOKABLE void setMinimumWidth(int);
120 Q_INVOKABLE void setMaximumWidth(int);
121 Q_INVOKABLE void setMinimumHeight(int);
122 Q_INVOKABLE void setMaximumHeight(int);
123 Q_INVOKABLE void setWidthIncrement(int);
124 Q_INVOKABLE void setHeightIncrement(int);
126 Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect);
128 Q_INVOKABLE void openMenu(qreal x, qreal y, qreal width, qreal height);
129 Q_INVOKABLE void openDialog(qreal x, qreal y, qreal width, qreal height);
131 /////
132 // internal mock stuff
134 QUrl qmlFilePath() const;
136 QUrl screenshotUrl() const;
137 void setScreenshotUrl(QUrl);
139 bool activeFocus() const;
140 void setActiveFocus(bool);
142 void registerView(qintptr viewId);
143 void unregisterView(qintptr viewId);
144 void setViewExposure(qintptr viewId, bool visible);
145 int viewCount() const { return m_views.count(); }
147 void setFocused(bool value);
149 void setState(Mir::State state);
151 Mir::State previousState() const { return m_previousState; }
152 void setPreviousState(Mir::State state) { m_previousState = state; }
154public Q_SLOTS:
155 ////
156 // unity.shell.application.MirSurface
157 void requestState(Mir::State) override;
159Q_SIGNALS:
160 ////
161 // API for tests
162 void widthChanged();
163 void heightChanged();
164 void slowToResizeChanged();
165 void exposedChanged(bool exposed);
167 ////
168 // internal mock stuff
169 void screenshotUrlChanged(QUrl);
170 void activeFocusChanged(bool);
171 void closeRequested();
172 void stateRequested(Mir::State);
174protected:
175 virtual void updateInputBoundsAfterResize();
177private Q_SLOTS:
178 void applyDelayedResize();
180private:
181 void doResize(int width, int height);
182 void updateExposure();
184 const QString m_name;
185 const Mir::Type m_type;
186 Mir::State m_state;
187 Mir::State m_previousState{Mir::UnknownState};
188 Mir::OrientationAngle m_orientationAngle;
190 QUrl m_screenshotUrl;
191 QUrl m_qmlFilePath;
192 bool m_live;
193 bool m_focused;
194 bool m_activeFocus;
195 int m_width;
196 int m_height;
198 int m_minimumWidth{0};
199 int m_minimumHeight{0};
200 int m_maximumWidth{0};
201 int m_maximumHeight{0};
202 int m_widthIncrement{0};
203 int m_heightIncrement{0};
205 QString m_keymap;
207 bool m_slowToResize;
208 QTimer m_delayedResizeTimer;
209 QSize m_delayedResize;
210 QSize m_pendingResize;
212 Mir::ShellChrome m_shellChrome;
214 struct View {
215 bool visible;
216 };
217 QHash<qintptr, View> m_views;
218 bool m_exposed{false};
220 QTimer m_zombieTimer;
222 QRect m_inputBounds;
224 QPoint m_position;
225 QPoint m_requestedPosition;
227 unity::shell::application::MirSurfaceInterface* m_parentSurface;
229 MirSurfaceListModel *m_childSurfaceList;
230};
232#endif // MOCK_MIR_SURFACE_H