on e1659ca help sign in
221 lines 6.0 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 const QUrl& screenshot,
49 const QUrl &qmlFilePath = QUrl());
50 virtual ~MirSurface();
52 ////
53 // unity.shell.application.MirSurface
55 Mir::Type type() const override;
57 QString name() const override;
59 QString persistentId() const override;
61 QPoint position() const override { return m_position; }
63 QSize size() const override { return QSize(width(),height()); }
64 void resize(int width, int height) override;
65 void resize(const QSize &size) override { resize(size.width(), size.height()); }
68 Mir::State state() const override;
70 bool live() const override;
72 bool visible() const override;
74 Mir::OrientationAngle orientationAngle() const override;
75 void setOrientationAngle(Mir::OrientationAngle) override;
77 int minimumWidth() const override { return m_minimumWidth; }
78 int minimumHeight() const override { return m_minimumHeight; }
79 int maximumWidth() const override { return m_maximumWidth; }
80 int maximumHeight() const override { return m_maximumHeight; }
81 int widthIncrement() const override { return m_widthIncrement; }
82 int heightIncrement() const override { return m_heightIncrement; }
84 void setKeymap(const QString &) override;
85 QString keymap() const override;
87 Mir::ShellChrome shellChrome() const override;
89 bool focused() const override;
90 QRect inputBounds() const override;
92 bool confinesMousePointer() const override { return false; }
94 QPoint requestedPosition() const override { return m_requestedPosition; }
95 void setRequestedPosition(const QPoint &) override;
97 Q_INVOKABLE void close() override;
98 Q_INVOKABLE void activate() override;
100 ////
101 // API for tests
103 Q_INVOKABLE void requestFocus();
104 Q_INVOKABLE void setLive(bool live);
105 Q_INVOKABLE void setShellChrome(Mir::ShellChrome shellChrome);
107 int width() const;
108 int height() const;
110 bool isSlowToResize() const;
111 void setSlowToResize(bool value);
113 bool exposed() const { return m_exposed; }
115 Q_INVOKABLE void setMinimumWidth(int);
116 Q_INVOKABLE void setMaximumWidth(int);
117 Q_INVOKABLE void setMinimumHeight(int);
118 Q_INVOKABLE void setMaximumHeight(int);
119 Q_INVOKABLE void setWidthIncrement(int);
120 Q_INVOKABLE void setHeightIncrement(int);
122 Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect);
124 /////
125 // internal mock stuff
127 QUrl qmlFilePath() const;
129 QUrl screenshotUrl() const;
130 void setScreenshotUrl(QUrl);
132 bool activeFocus() const;
133 void setActiveFocus(bool);
135 void registerView(qintptr viewId);
136 void unregisterView(qintptr viewId);
137 void setViewExposure(qintptr viewId, bool visible);
138 int viewCount() const { return m_views.count(); }
140 void setFocused(bool value);
142 void setState(Mir::State state);
144 Mir::State previousState() const { return m_previousState; }
145 void setPreviousState(Mir::State state) { m_previousState = state; }
147public Q_SLOTS:
148 ////
149 // unity.shell.application.MirSurface
150 void requestState(Mir::State) override;
152Q_SIGNALS:
153 ////
154 // API for tests
155 void widthChanged();
156 void heightChanged();
157 void slowToResizeChanged();
158 void exposedChanged(bool exposed);
160 ////
161 // internal mock stuff
162 void screenshotUrlChanged(QUrl);
163 void activeFocusChanged(bool);
164 void closeRequested();
165 void stateRequested(Mir::State);
167protected:
168 virtual void updateInputBoundsAfterResize();
170private Q_SLOTS:
171 void applyDelayedResize();
173private:
174 void doResize(int width, int height);
175 void updateExposure();
177 const QString m_name;
178 const Mir::Type m_type;
179 Mir::State m_state;
180 Mir::State m_previousState{Mir::UnknownState};
181 Mir::OrientationAngle m_orientationAngle;
183 QUrl m_screenshotUrl;
184 QUrl m_qmlFilePath;
185 bool m_live;
186 bool m_focused;
187 bool m_activeFocus;
188 int m_width;
189 int m_height;
191 int m_minimumWidth{0};
192 int m_minimumHeight{0};
193 int m_maximumWidth{0};
194 int m_maximumHeight{0};
195 int m_widthIncrement{0};
196 int m_heightIncrement{0};
198 QString m_keymap;
200 bool m_slowToResize;
201 QTimer m_delayedResizeTimer;
202 QSize m_delayedResize;
203 QSize m_pendingResize;
205 Mir::ShellChrome m_shellChrome;
207 struct View {
208 bool visible;
209 };
210 QHash<qintptr, View> m_views;
211 bool m_exposed{false};
213 QTimer m_zombieTimer;
215 QRect m_inputBounds;
217 QPoint m_position;
218 QPoint m_requestedPosition;
219};
221#endif // MOCK_MIR_SURFACE_H