on eae958a help sign in
219 lines 6.1 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/MirFocusControllerInterface.h>
27#include <unity/shell/application/MirSurfaceInterface.h>
29#include "MirSurfaceListModel.h"
31class MirSurface;
33class MirFocusController : public unity::shell::application::MirFocusControllerInterface
35 Q_OBJECT
36public:
37 MirFocusController();
38 virtual ~MirFocusController();
39 static MirFocusController* instance();
41 void setFocusedSurface(unity::shell::application::MirSurfaceInterface *surface) override;
42 unity::shell::application::MirSurfaceInterface* focusedSurface() const override { return m_focusedSurface; }
43 unity::shell::application::MirSurfaceInterface* previouslyFocusedSurface() { return m_previouslyFocusedSurface; }
44 void clear();
45private:
46 static MirFocusController *m_instance;
47 unity::shell::application::MirSurfaceInterface* m_previouslyFocusedSurface{nullptr};
48 unity::shell::application::MirSurfaceInterface* m_focusedSurface{nullptr};
49};
51class MirSurface : public unity::shell::application::MirSurfaceInterface
53 Q_OBJECT
55 ////
56 // for use in qml tests
57 Q_PROPERTY(int width READ width NOTIFY widthChanged)
58 Q_PROPERTY(int height READ height NOTIFY heightChanged)
59 Q_PROPERTY(bool activeFocus READ activeFocus NOTIFY activeFocusChanged)
60 Q_PROPERTY(bool slowToResize READ isSlowToResize WRITE setSlowToResize NOTIFY slowToResizeChanged)
62public:
63 MirSurface(const QString& name,
64 Mir::Type type,
65 Mir::State state,
66 const QUrl& screenshot,
67 const QUrl &qmlFilePath = QUrl());
68 virtual ~MirSurface();
70 ////
71 // unity.shell.application.MirSurface
73 Mir::Type type() const override;
75 QString name() const override;
77 QString persistentId() const override;
79 QSize size() const override { return QSize(width(),height()); }
80 void resize(int width, int height) override;
81 void resize(const QSize &size) override { resize(size.width(), size.height()); }
84 Mir::State state() const override;
85 Q_INVOKABLE void setState(Mir::State) override;
87 bool live() const override;
89 bool visible() const override;
91 Mir::OrientationAngle orientationAngle() const override;
92 void setOrientationAngle(Mir::OrientationAngle) override;
94 int minimumWidth() const override { return m_minimumWidth; }
95 int minimumHeight() const override { return m_minimumHeight; }
96 int maximumWidth() const override { return m_maximumWidth; }
97 int maximumHeight() const override { return m_maximumHeight; }
98 int widthIncrement() const override { return m_widthIncrement; }
99 int heightIncrement() const override { return m_heightIncrement; }
101 void setKeymap(const QString &) override;
102 QString keymap() const override;
104 Mir::ShellChrome shellChrome() const override;
106 bool focused() const override;
107 QRect inputBounds() const override;
109 bool confinesMousePointer() const override { return false; }
111 Q_INVOKABLE void requestFocus() override;
113 Q_INVOKABLE void close() override;
115 Q_INVOKABLE void raise() override;
117 ////
118 // API for tests
120 Q_INVOKABLE void setLive(bool live);
121 Q_INVOKABLE void setShellChrome(Mir::ShellChrome shellChrome);
123 int width() const;
124 int height() const;
126 bool isSlowToResize() const;
127 void setSlowToResize(bool value);
129 Q_INVOKABLE void setMinimumWidth(int);
130 Q_INVOKABLE void setMaximumWidth(int);
131 Q_INVOKABLE void setMinimumHeight(int);
132 Q_INVOKABLE void setMaximumHeight(int);
133 Q_INVOKABLE void setWidthIncrement(int);
134 Q_INVOKABLE void setHeightIncrement(int);
136 Q_INVOKABLE virtual void setInputBounds(const QRect &boundsRect);
138 /////
139 // internal mock stuff
141 QUrl qmlFilePath() const;
143 QUrl screenshotUrl() const;
144 void setScreenshotUrl(QUrl);
146 bool activeFocus() const;
147 void setActiveFocus(bool);
149 void registerView(qintptr viewId);
150 void unregisterView(qintptr viewId);
151 void setViewVisibility(qintptr viewId, bool visible);
152 int viewCount() const { return m_views.count(); }
154 void setFocused(bool value);
156Q_SIGNALS:
157 ////
158 // API for tests
159 void widthChanged();
160 void heightChanged();
161 void slowToResizeChanged();
163 ////
164 // internal mock stuff
165 void screenshotUrlChanged(QUrl);
166 void activeFocusChanged(bool);
167 void raiseRequested();
168 void closeRequested();
170protected:
171 virtual void updateInputBoundsAfterResize();
173private Q_SLOTS:
174 void applyDelayedResize();
176private:
177 void doResize(int width, int height);
178 void updateVisibility();
180 const QString m_name;
181 const Mir::Type m_type;
182 Mir::State m_state;
183 Mir::OrientationAngle m_orientationAngle;
185 QUrl m_screenshotUrl;
186 QUrl m_qmlFilePath;
187 bool m_live;
188 bool m_visible;
189 bool m_activeFocus;
190 int m_width;
191 int m_height;
193 int m_minimumWidth{0};
194 int m_minimumHeight{0};
195 int m_maximumWidth{0};
196 int m_maximumHeight{0};
197 int m_widthIncrement{0};
198 int m_heightIncrement{0};
200 QString m_keymap;
202 bool m_slowToResize;
203 QTimer m_delayedResizeTimer;
204 QSize m_delayedResize;
205 QSize m_pendingResize;
207 Mir::ShellChrome m_shellChrome;
209 struct View {
210 bool visible;
211 };
212 QHash<qintptr, View> m_views;
214 QTimer m_zombieTimer;
216 QRect m_inputBounds;
217};
219#endif // MOCK_MIR_SURFACE_H