Skip to content
This repository has been archived by the owner on Jan 2, 2023. It is now read-only.

Commit

Permalink
Remove some graphics dependencies
Browse files Browse the repository at this point in the history
Check for graphics mode in various webkit and qt classes, and
give sane fallback defaults in the case of tty mode.
  • Loading branch information
antialize authored and ashkulz committed Jan 17, 2014
1 parent d123a48 commit e673ec1
Show file tree
Hide file tree
Showing 9 changed files with 50 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,17 @@ static int screenNumber(Widget* w)

int screenDepth(Widget* w)
{
if (QApplication::type() == QApplication::Tty)
return 32;

return QApplication::desktop()->screen(screenNumber(w))->depth();
}

int screenDepthPerComponent(Widget* w)
{
if (QApplication::type() == QApplication::Tty)
return 8;

int depth = QApplication::desktop()->screen(0)->depth();
if (w) {
QWebPageClient* client = w->root()->hostWindow()->platformPageClient();
Expand Down Expand Up @@ -86,17 +92,26 @@ int screenDepthPerComponent(Widget* w)

bool screenIsMonochrome(Widget* w)
{
if (QApplication::type() == QApplication::Tty)
return false;

return QApplication::desktop()->screen(screenNumber(w))->colorCount() == 2;
}

FloatRect screenRect(Widget* w)
{
if (QApplication::type() == QApplication::Tty)
return FloatRect(0,0,800,600);

QRect r = QApplication::desktop()->screenGeometry(screenNumber(w));
return FloatRect(r.x(), r.y(), r.width(), r.height());
}

FloatRect screenAvailableRect(Widget* w)
{
if (QApplication::type() == QApplication::Tty)
return FloatRect(0,0,800,600);

QRect r = QApplication::desktop()->availableGeometry(screenNumber(w));
return FloatRect(r.x(), r.y(), r.width(), r.height());
}
Expand Down
12 changes: 12 additions & 0 deletions src/3rdparty/webkit/Source/WebCore/platform/qt/RenderThemeQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ RenderThemeQt::RenderThemeQt(Page* page)
: RenderTheme()
, m_page(page)
, m_lineEdit(0)
, m_fallbackStyle(0)
{
if (QApplication::type() == QApplication::Tty) {
m_buttonFontFamily = "sans-serif";
return;
}

QPushButton button;
button.setAttribute(Qt::WA_MacSmallSize);
QFont defaultButtonFont = QApplication::font(&button);
Expand Down Expand Up @@ -339,6 +345,9 @@ bool RenderThemeQt::supportsControlTints() const

int RenderThemeQt::findFrameLineWidth(QStyle* style) const
{
if (QApplication::type()==QApplication::Tty)
return 1;

#ifndef QT_NO_LINEEDIT
if (!m_lineEdit)
m_lineEdit = new QLineEdit();
Expand Down Expand Up @@ -445,6 +454,9 @@ Color RenderThemeQt::systemColor(int cssValueId) const

int RenderThemeQt::minimumMenuListSize(RenderStyle*) const
{
if (QApplication::type() == QApplication::Tty)
return 1;

const QFontMetrics &fm = QApplication::fontMetrics();
return fm.width(QLatin1Char('x'));
}
Expand Down
9 changes: 9 additions & 0 deletions src/3rdparty/webkit/Source/WebCore/platform/qt/ScreenQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ static QWidget* qwidgetForPage(const Page* page)

FloatRect screenRect(const Page* page)
{
if (QApplication::type() == QApplication::Tty)
return FloatRect(0,0,800,600);

QWidget* qw = qwidgetForPage(page);
if (!qw)
return FloatRect();
Expand All @@ -68,6 +71,9 @@ FloatRect screenRect(const Page* page)

int screenDepth(const Page* page)
{
if (QApplication::type() == QApplication::Tty)
return 32;

QWidget* qw = qwidgetForPage(page);
if (!qw)
return 32;
Expand All @@ -77,6 +83,9 @@ int screenDepth(const Page* page)

FloatRect usableScreenRect(const Page* page)
{
if (QApplication::type() == QApplication::Tty)
return FloatRect();

QWidget* qw = qwidgetForPage(page);
if (!qw)
return FloatRect();
Expand Down
4 changes: 4 additions & 0 deletions src/3rdparty/webkit/Source/WebCore/platform/qt/WidgetQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#include "QWebPageClient.h"
#include "ScrollView.h"

#include <QApplication>
#include <QCoreApplication>
#include <QDebug>
#include <QPaintEngine>
Expand Down Expand Up @@ -78,6 +79,9 @@ void Widget::setFocus(bool focused)
void Widget::setCursor(const Cursor& cursor)
{
#ifndef QT_NO_CURSOR
if (QApplication::type() == QApplication::Tty)
return;

ScrollView* view = root();
if (!view)
return;
Expand Down
6 changes: 0 additions & 6 deletions src/gui/image/qpixmap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,6 @@ extern QApplication::Type qt_appType;

void QPixmap::init(int w, int h, int type)
{
if (qt_appType == QApplication::Tty) {
qWarning("QPixmap: Cannot create a QPixmap when no GUI is being used");
data = 0;
return;
}

if ((w > 0 && h > 0) || type == QPixmapData::BitmapType)
data = QPixmapData::create(w, h, (QPixmapData::PixelType) type);
else
Expand Down
7 changes: 5 additions & 2 deletions src/gui/image/qpixmap_raster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "qnativeimage_p.h"
#include "qimage_p.h"
#include "qpaintengine.h"
#include "kernel/qapplication_p.h"

#include "qbitmap.h"
#include "qimage.h"
Expand Down Expand Up @@ -115,8 +116,10 @@ void QRasterPixmapData::resize(int width, int height)
#else
if (pixelType() == BitmapType)
format = QImage::Format_MonoLSB;
else
else if (qt_is_gui_used)
format = QNativeImage::systemFormat();
else
format = QImage::Format_RGB32;
#endif

image = QImage(width, height, format);
Expand Down Expand Up @@ -432,7 +435,7 @@ void QRasterPixmapData::createPixmapForImage(QImage &sourceImage, Qt::ImageConve
? QImage::Format_ARGB32_Premultiplied
: QImage::Format_RGB32;
} else {
QImage::Format opaqueFormat = QNativeImage::systemFormat();
QImage::Format opaqueFormat = qt_is_gui_used ? QNativeImage::systemFormat() : QImage::Format_RGB32;
QImage::Format alphaFormat = QImage::Format_ARGB32_Premultiplied;

#if !defined(QT_HAVE_NEON) && !defined(QT_ALWAYS_HAVE_SSE2)
Expand Down
2 changes: 2 additions & 0 deletions src/gui/kernel/qapplication_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,8 @@ void qt_init(QApplicationPrivate *priv, int,
QSegfaultHandler::initialize(priv->argv, priv->argc);
#endif
QCursorData::initialize();
} else if (!QApplicationPrivate::graphics_system_name.isNull()) {
QApplicationPrivate::graphics_system = QGraphicsSystemFactory::create(QApplicationPrivate::graphics_system_name);
}
QFont::initialize();

Expand Down
2 changes: 1 addition & 1 deletion src/gui/kernel/qguiplatformplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ QGuiPlatformPlugin *qt_guiPlatformPlugin()

QString key = QString::fromLocal8Bit(qgetenv("QT_PLATFORM_PLUGIN"));
#ifdef Q_WS_X11
if (key.isEmpty()) {
if (QApplication::type() != QApplication::Tty && key.isEmpty()) {
switch(X11->desktopEnvironment) {
case DE_KDE:
key = QString::fromLatin1("kde");
Expand Down
3 changes: 2 additions & 1 deletion src/gui/styles/qstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "qpixmapcache.h"
#include "qstyleoption.h"
#include "private/qstyle_p.h"
#include "private/qapplication_p.h"
#ifndef QT_NO_DEBUG
#include "qdebug.h"
#endif
Expand Down Expand Up @@ -2229,7 +2230,7 @@ QPalette QStyle::standardPalette() const
{
#ifdef Q_WS_X11
QColor background;
if (QX11Info::appDepth() > 8)
if (!qt_is_gui_used || QX11Info::appDepth() > 8)
background = QColor(0xd4, 0xd0, 0xc8); // win 2000 grey
else
background = QColor(192, 192, 192);
Expand Down

0 comments on commit e673ec1

Please sign in to comment.