PlatformScreenQt.cpp [plain text]
#include "config.h"
#include "PlatformScreen.h"
#include "FloatRect.h"
#include "Frame.h"
#include "FrameView.h"
#include "HostWindow.h"
#include "NotImplemented.h"
#include "Widget.h"
#include "QWebPageClient.h"
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
#include <QGuiApplication>
#include <QScreen>
#else
#include <QApplication>
#include <QDesktopWidget>
#endif
namespace WebCore {
int screenHorizontalDPI(Widget* widget)
{
notImplemented();
return 0;
}
int screenVerticalDPI(Widget* widget)
{
notImplemented();
return 0;
}
static int screenNumber(Widget* w)
{
if (!w)
return 0;
QWebPageClient* client = w->root()->hostWindow()->platformPageClient();
return client ? client->screenNumber() : 0;
}
int screenDepth(Widget* w)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
return QGuiApplication::screens().value(screenNumber(w))->depth();
#else
return QApplication::desktop()->screen(screenNumber(w))->depth();
#endif
}
int screenDepthPerComponent(Widget* w)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
int depth = QGuiApplication::primaryScreen()->depth();
Q_UNUSED(w);
#else
int depth = QApplication::desktop()->screen(0)->depth();
if (w) {
QWebPageClient* client = w->root()->hostWindow()->platformPageClient();
if (client) {
QWidget* view = client->ownerWidget();
if (view)
depth = view->depth();
}
}
#endif
switch (depth) {
case 8:
return 2;
case 32:
return 8;
default:
return depth / 3;
}
}
bool screenIsMonochrome(Widget* w)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
Q_UNUSED(w);
return false;
#else
return QApplication::desktop()->screen(screenNumber(w))->colorCount() == 2;
#endif
}
FloatRect screenRect(Widget* widget)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRect r = QGuiApplication::screens().value(screenNumber(widget))->geometry();
#else
QRect r = QApplication::desktop()->screenGeometry(screenNumber(widget));
#endif
return FloatRect(r.x(), r.y(), r.width(), r.height());
}
FloatRect screenAvailableRect(Widget* widget)
{
#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
QRect r = QGuiApplication::screens().value(screenNumber(widget))->availableGeometry();
#else
QRect r = QApplication::desktop()->availableGeometry(screenNumber(widget));
#endif
return FloatRect(r.x(), r.y(), r.width(), r.height());
}
}