PageRenderTime 40ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/src/qt/qtbase/src/gui/kernel/qplatformintegration.cpp

https://gitlab.com/x33n/phantomjs
C++ | 505 lines | 184 code | 43 blank | 278 comment | 13 complexity | 5a0a5993bbda6ca93a5eaed49a7bfde2 MD5 | raw file
  1. /****************************************************************************
  2. **
  3. ** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
  4. ** Contact: http://www.qt-project.org/legal
  5. **
  6. ** This file is part of the QtGui module of the Qt Toolkit.
  7. **
  8. ** $QT_BEGIN_LICENSE:LGPL$
  9. ** Commercial License Usage
  10. ** Licensees holding valid commercial Qt licenses may use this file in
  11. ** accordance with the commercial license agreement provided with the
  12. ** Software or, alternatively, in accordance with the terms contained in
  13. ** a written agreement between you and Digia. For licensing terms and
  14. ** conditions see http://qt.digia.com/licensing. For further information
  15. ** use the contact form at http://qt.digia.com/contact-us.
  16. **
  17. ** GNU Lesser General Public License Usage
  18. ** Alternatively, this file may be used under the terms of the GNU Lesser
  19. ** General Public License version 2.1 as published by the Free Software
  20. ** Foundation and appearing in the file LICENSE.LGPL included in the
  21. ** packaging of this file. Please review the following information to
  22. ** ensure the GNU Lesser General Public License version 2.1 requirements
  23. ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
  24. **
  25. ** In addition, as a special exception, Digia gives you certain additional
  26. ** rights. These rights are described in the Digia Qt LGPL Exception
  27. ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
  28. **
  29. ** GNU General Public License Usage
  30. ** Alternatively, this file may be used under the terms of the GNU
  31. ** General Public License version 3.0 as published by the Free Software
  32. ** Foundation and appearing in the file LICENSE.GPL included in the
  33. ** packaging of this file. Please review the following information to
  34. ** ensure the GNU General Public License version 3.0 requirements will be
  35. ** met: http://www.gnu.org/copyleft/gpl.html.
  36. **
  37. **
  38. ** $QT_END_LICENSE$
  39. **
  40. ****************************************************************************/
  41. #include "qplatformintegration.h"
  42. #include <qpa/qplatformfontdatabase.h>
  43. #include <qpa/qplatformclipboard.h>
  44. #include <qpa/qplatformaccessibility.h>
  45. #include <qpa/qplatformtheme.h>
  46. #include <QtGui/private/qguiapplication_p.h>
  47. #include <QtGui/private/qpixmap_raster_p.h>
  48. #include <qpa/qplatformscreen_p.h>
  49. #include <private/qdnd_p.h>
  50. #include <private/qsimpledrag_p.h>
  51. #ifndef QT_NO_SESSIONMANAGER
  52. # include <qpa/qplatformsessionmanager.h>
  53. #endif
  54. QT_BEGIN_NAMESPACE
  55. /*!
  56. Accessor for the platform integration's fontdatabase.
  57. Default implementation returns a default QPlatformFontDatabase.
  58. \sa QPlatformFontDatabase
  59. */
  60. QPlatformFontDatabase *QPlatformIntegration::fontDatabase() const
  61. {
  62. static QPlatformFontDatabase *db = 0;
  63. if (!db) {
  64. db = new QPlatformFontDatabase;
  65. }
  66. return db;
  67. }
  68. /*!
  69. Accessor for the platform integration's clipboard.
  70. Default implementation returns a default QPlatformClipboard.
  71. \sa QPlatformClipboard
  72. */
  73. #ifndef QT_NO_CLIPBOARD
  74. QPlatformClipboard *QPlatformIntegration::clipboard() const
  75. {
  76. static QPlatformClipboard *clipboard = 0;
  77. if (!clipboard) {
  78. clipboard = new QPlatformClipboard;
  79. }
  80. return clipboard;
  81. }
  82. #endif
  83. #ifndef QT_NO_DRAGANDDROP
  84. /*!
  85. Accessor for the platform integration's drag object.
  86. Default implementation returns 0, implying no drag and drop support.
  87. */
  88. QPlatformDrag *QPlatformIntegration::drag() const
  89. {
  90. static QSimpleDrag *drag = 0;
  91. if (!drag) {
  92. drag = new QSimpleDrag;
  93. }
  94. return drag;
  95. }
  96. #endif
  97. QPlatformNativeInterface * QPlatformIntegration::nativeInterface() const
  98. {
  99. return 0;
  100. }
  101. QPlatformServices *QPlatformIntegration::services() const
  102. {
  103. return 0;
  104. }
  105. /*!
  106. \class QPlatformIntegration
  107. \since 4.8
  108. \internal
  109. \preliminary
  110. \ingroup qpa
  111. \brief The QPlatformIntegration class is the entry for WindowSystem specific functionality.
  112. QPlatformIntegration is the single entry point for windowsystem specific functionality when
  113. using the QPA platform. It has factory functions for creating platform specific pixmaps and
  114. windows. The class also controls the font subsystem.
  115. QPlatformIntegration is a singleton class which gets instantiated in the QGuiApplication
  116. constructor. The QPlatformIntegration instance do not have ownership of objects it creates in
  117. functions where the name starts with create. However, functions which don't have a name
  118. starting with create acts as accessors to member variables.
  119. It is not trivial to create or build a platform plugin outside of the Qt source tree. Therefore
  120. the recommended approach for making new platform plugin is to copy an existing plugin inside
  121. the QTSRCTREE/src/plugins/platform and develop the plugin inside the source tree.
  122. The minimal platform integration is the smallest platform integration it is possible to make,
  123. which makes it an ideal starting point for new plugins. For a slightly more advanced plugin,
  124. consider reviewing the directfb plugin, or the testlite plugin.
  125. */
  126. /*!
  127. \fn QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
  128. Factory function for QPlatformPixmap. PixelType can be either PixmapType or BitmapType.
  129. \sa QPlatformPixmap
  130. */
  131. /*!
  132. \fn QPlatformWindow *QPlatformIntegration::createPlatformWindow(QWindow *window) const
  133. Factory function for QPlatformWindow. The \a window parameter is a pointer to the top level
  134. window which the QPlatformWindow is supposed to be created for.
  135. All top level windows have to have a QPlatformWindow, and it will be created when the
  136. QPlatformWindow is set to be visible for the first time. If the top level window's flags are
  137. changed, or if the top level window's QPlatformWindowFormat is changed, then the top level
  138. window's QPlatformWindow is deleted and a new one is created.
  139. In the constructor, of the QPlatformWindow, the window flags, state, title and geometry
  140. of the \a window should be applied to the underlying window. If the resulting flags or state
  141. differs, the resulting values should be set on the \a window using QWindow::setWindowFlags()
  142. or QWindow::setWindowState(), respectively.
  143. \sa QPlatformWindow, QPlatformWindowFormat
  144. \sa createPlatformBackingStore()
  145. */
  146. /*!
  147. \fn QPlatformBackingStore *QPlatformIntegration::createPlatformBackingStore(QWindow *window) const
  148. Factory function for QPlatformBackingStore. The QWindow parameter is a pointer to the
  149. top level widget(tlw) the window surface is created for. A QPlatformWindow is always created
  150. before the QPlatformBackingStore for tlw where the widget also requires a backing store.
  151. \sa QBackingStore
  152. \sa createPlatformWindow()
  153. */
  154. /*!
  155. \enum QPlatformIntegration::Capability
  156. Capabilities are used to determing specific features of a platform integration
  157. \value ThreadedPixmaps The platform uses a pixmap implementation that is reentrant
  158. and can be used from multiple threads, like the raster paint engine and QImage based
  159. pixmaps.
  160. \value OpenGL The platform supports OpenGL
  161. \value ThreadedOpenGL The platform supports using OpenGL outside the GUI thread.
  162. \value SharedGraphicsCache The platform supports a shared graphics cache
  163. \value BufferQueueingOpenGL The OpenGL implementation on the platform will queue
  164. up buffers when swapBuffers() is called and block only when its buffer pipeline
  165. is full, rather than block immediately.
  166. \value MultipleWindows The platform supports multiple QWindows, i.e. does some kind
  167. of compositing either client or server side. Some platforms might only support a
  168. single fullscreen window.
  169. \value ApplicationState The platform handles the application state explicitly.
  170. This means that QEvent::ApplicationActivate and QEvent::ApplicationDeativate
  171. will not be posted automatically. Instead, the platform must handle application
  172. state explicitly by using QWindowSystemInterface::handleApplicationStateChanged().
  173. If not set, application state will follow window activation, which is the normal
  174. behavior for desktop platforms.
  175. \value ForeignWindows The platform allows creating QWindows which represent
  176. native windows created by other processes or anyway created by using native
  177. libraries.
  178. \value NonFullScreenWindows The platform supports top-level windows which do not
  179. fill the screen. The default implementation returns \c true. Returning false for
  180. this will cause all windows, including dialogs and popups, to be resized to fill the
  181. screen.
  182. \value WindowManagement The platform is based on a system that performs window
  183. management. This includes the typical desktop platforms. Can be set to false on
  184. platforms where no window management is available, meaning for example that windows
  185. are never repositioned by the window manager. The default implementation returns \c true.
  186. \value AllGLFunctionsQueryable The QOpenGLContext backend provided by the platform is
  187. able to return function pointers from getProcAddress() even for standard OpenGL
  188. functions, for example OpenGL 1 functions like glClear() or glDrawArrays(). This is
  189. important because the OpenGL specifications do not require this ability from the
  190. getProcAddress implementations of the windowing system interfaces (EGL, WGL, GLX). The
  191. platform plugins may however choose to enhance the behavior in the backend
  192. implementation for QOpenGLContext::getProcAddress() and support returning a function
  193. pointer also for the standard, non-extension functions. This capability is a
  194. prerequisite for dynamic OpenGL loading.
  195. */
  196. /*!
  197. \fn QAbstractEventDispatcher *QPlatformIntegration::createEventDispatcher() const = 0
  198. Factory function for the GUI event dispatcher. The platform plugin should create
  199. and return a QAbstractEventDispatcher subclass when this function is called.
  200. If the platform plugin for some reason creates the event dispatcher outside of
  201. this function (for example in the constructor), it needs to handle the case
  202. where this function is never called, ensuring that the event dispatcher is
  203. still deleted at some point (typically in the destructor).
  204. Note that the platform plugin should never explicitly set the event dispatcher
  205. itself, using QCoreApplication::setEventDispatcher(), but let QCoreApplication
  206. decide when and which event dispatcher to create.
  207. \since 5.2
  208. */
  209. bool QPlatformIntegration::hasCapability(Capability cap) const
  210. {
  211. return cap == NonFullScreenWindows || cap == NativeWidgets || cap == WindowManagement;
  212. }
  213. QPlatformPixmap *QPlatformIntegration::createPlatformPixmap(QPlatformPixmap::PixelType type) const
  214. {
  215. return new QRasterPlatformPixmap(type);
  216. }
  217. #ifndef QT_NO_OPENGL
  218. QPlatformOpenGLContext *QPlatformIntegration::createPlatformOpenGLContext(QOpenGLContext *context) const
  219. {
  220. Q_UNUSED(context);
  221. qWarning("This plugin does not support createPlatformOpenGLContext!");
  222. return 0;
  223. }
  224. #endif
  225. /*!
  226. Factory function for QPlatformSharedGraphicsCache. This function will return 0 if the platform
  227. integration does not support any shared graphics cache mechanism for the given \a cacheId.
  228. */
  229. QPlatformSharedGraphicsCache *QPlatformIntegration::createPlatformSharedGraphicsCache(const char *cacheId) const
  230. {
  231. qWarning("This plugin does not support createPlatformSharedGraphicsBuffer for cacheId: %s!",
  232. cacheId);
  233. return 0;
  234. }
  235. /*!
  236. Factory function for QPaintEngine. This function will return 0 if the platform
  237. integration does not support creating any paint engine the given \a paintDevice.
  238. */
  239. QPaintEngine *QPlatformIntegration::createImagePaintEngine(QPaintDevice *paintDevice) const
  240. {
  241. Q_UNUSED(paintDevice)
  242. return 0;
  243. }
  244. /*!
  245. Performs initialization steps that depend on having an event dispatcher
  246. available. Called after the event dispatcher has been created.
  247. Tasks that require an event dispatcher, for example creating socket notifiers, cannot be
  248. performed in the constructor. Instead, they should be performed here. The default
  249. implementation does nothing.
  250. */
  251. void QPlatformIntegration::initialize()
  252. {
  253. }
  254. /*!
  255. Returns the platforms input context.
  256. The default implementation returns 0, implying no input method support.
  257. */
  258. QPlatformInputContext *QPlatformIntegration::inputContext() const
  259. {
  260. return 0;
  261. }
  262. #ifndef QT_NO_ACCESSIBILITY
  263. /*!
  264. Returns the platforms accessibility.
  265. The default implementation returns 0, implying no accessibility support.
  266. */
  267. QPlatformAccessibility *QPlatformIntegration::accessibility() const
  268. {
  269. return 0;
  270. }
  271. #endif
  272. QVariant QPlatformIntegration::styleHint(StyleHint hint) const
  273. {
  274. switch (hint) {
  275. case CursorFlashTime:
  276. return QPlatformTheme::defaultThemeHint(QPlatformTheme::CursorFlashTime);
  277. case KeyboardInputInterval:
  278. return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardInputInterval);
  279. case KeyboardAutoRepeatRate:
  280. return QPlatformTheme::defaultThemeHint(QPlatformTheme::KeyboardAutoRepeatRate);
  281. case MouseDoubleClickInterval:
  282. return QPlatformTheme::defaultThemeHint(QPlatformTheme::MouseDoubleClickInterval);
  283. case StartDragDistance:
  284. return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragDistance);
  285. case StartDragTime:
  286. return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragTime);
  287. case ShowIsFullScreen:
  288. return false;
  289. case ShowIsMaximized:
  290. return false;
  291. case PasswordMaskDelay:
  292. return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskDelay);
  293. case PasswordMaskCharacter:
  294. return QPlatformTheme::defaultThemeHint(QPlatformTheme::PasswordMaskCharacter);
  295. case FontSmoothingGamma:
  296. return qreal(1.7);
  297. case StartDragVelocity:
  298. return QPlatformTheme::defaultThemeHint(QPlatformTheme::StartDragVelocity);
  299. case UseRtlExtensions:
  300. return QVariant(false);
  301. case SynthesizeMouseFromTouchEvents:
  302. return true;
  303. case SetFocusOnTouchRelease:
  304. return QVariant(false);
  305. case MousePressAndHoldInterval:
  306. return QPlatformTheme::defaultThemeHint(QPlatformTheme::MousePressAndHoldInterval);
  307. }
  308. return 0;
  309. }
  310. Qt::WindowState QPlatformIntegration::defaultWindowState(Qt::WindowFlags flags) const
  311. {
  312. // Leave popup-windows as is
  313. if (flags & Qt::Popup & ~Qt::Window)
  314. return Qt::WindowNoState;
  315. if (styleHint(QPlatformIntegration::ShowIsFullScreen).toBool())
  316. return Qt::WindowFullScreen;
  317. else if (styleHint(QPlatformIntegration::ShowIsMaximized).toBool())
  318. return Qt::WindowMaximized;
  319. return Qt::WindowNoState;
  320. }
  321. Qt::KeyboardModifiers QPlatformIntegration::queryKeyboardModifiers() const
  322. {
  323. return QGuiApplication::keyboardModifiers();
  324. }
  325. /*!
  326. Should be used to obtain a list of possible shortcuts for the given key
  327. event. As that needs system functionality it cannot be done in qkeymapper.
  328. One example for more than 1 possibility is the key combination of Shift+5.
  329. That one might trigger a shortcut which is set as "Shift+5" as well as one
  330. using %. These combinations depend on the currently set keyboard layout
  331. which cannot be obtained by Qt functionality.
  332. */
  333. QList<int> QPlatformIntegration::possibleKeys(const QKeyEvent *) const
  334. {
  335. return QList<int>();
  336. }
  337. /*!
  338. Should be called by the implementation whenever a new screen is added.
  339. The first screen added will be the primary screen, used for default-created
  340. windows, GL contexts, and other resources unless otherwise specified.
  341. This adds the screen to QGuiApplication::screens(), and emits the
  342. QGuiApplication::screenAdded() signal.
  343. The screen is automatically removed when the QPlatformScreen is destroyed.
  344. */
  345. void QPlatformIntegration::screenAdded(QPlatformScreen *ps)
  346. {
  347. QScreen *screen = new QScreen(ps);
  348. ps->d_func()->screen = screen;
  349. QGuiApplicationPrivate::screen_list << screen;
  350. emit qGuiApp->screenAdded(screen);
  351. }
  352. QStringList QPlatformIntegration::themeNames() const
  353. {
  354. return QStringList();
  355. }
  356. class QPlatformTheme *QPlatformIntegration::createPlatformTheme(const QString &name) const
  357. {
  358. Q_UNUSED(name)
  359. return new QPlatformTheme;
  360. }
  361. /*!
  362. Factory function for QOffscreenSurface. An offscreen surface will typically be implemented with a
  363. pixel buffer (pbuffer). If the platform doesn't support offscreen surfaces, an invisible window
  364. will be used by QOffscreenSurface instead.
  365. */
  366. QPlatformOffscreenSurface *QPlatformIntegration::createPlatformOffscreenSurface(QOffscreenSurface *surface) const
  367. {
  368. Q_UNUSED(surface)
  369. return 0;
  370. }
  371. #ifndef QT_NO_SESSIONMANAGER
  372. /*!
  373. \since 5.2
  374. Factory function for QPlatformSessionManager. The default QPlatformSessionManager provides the same
  375. functionality as the QSessionManager.
  376. */
  377. QPlatformSessionManager *QPlatformIntegration::createPlatformSessionManager(const QString &id, const QString &key) const
  378. {
  379. return new QPlatformSessionManager(id, key);
  380. }
  381. #endif
  382. /*!
  383. \since 5.2
  384. Function to sync the platform integrations state with the window system.
  385. This is often implemented as a roundtrip from the platformintegration to the window system.
  386. This function should not call QWindowSystemInterface::flushWindowSystemEvents() or
  387. QCoreApplication::processEvents()
  388. */
  389. void QPlatformIntegration::sync()
  390. {
  391. }
  392. #ifndef QT_NO_OPENGL
  393. /*!
  394. Platform integration function for querying the OpenGL implementation type.
  395. Used only when dynamic OpenGL implementation loading is enabled.
  396. Subclasses should reimplement this function and return a value based on
  397. the OpenGL implementation they have chosen to load.
  398. \note The return value does not indicate or limit the types of
  399. contexts that can be created by a given implementation. For example
  400. a desktop OpenGL implementation may be capable of creating OpenGL
  401. ES-compatible contexts too.
  402. \sa QOpenGLContext::openGLModuleType(), QOpenGLContext::isOpenGLES()
  403. \since 5.3
  404. */
  405. QOpenGLContext::OpenGLModuleType QPlatformIntegration::openGLModuleType()
  406. {
  407. qWarning("This plugin does not support dynamic OpenGL loading!");
  408. return QOpenGLContext::LibGL;
  409. }
  410. #endif
  411. QT_END_NAMESPACE