1 /*
2 * Copyright (C) 2006 Dirk Mueller <mueller@kde.org>
3 * (C) 2006 Nikolas Zimmermann <zimmermann@kde.org>
4 *
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
17 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
20 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
21 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
22 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
24 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include "config.h"
30 #include "Screen.h"
31
32 #include "FloatRect.h"
33 #include "Frame.h"
34 #include "FrameView.h"
35 #include "IntRect.h"
36 #include "Page.h"
37 #include "Widget.h"
38
39 #include <QApplication>
40 #include <QDesktopWidget>
41 #include <QByteArray>
42
43 namespace WebCore {
44
wkhtmltox_screen_width()45 static int wkhtmltox_screen_width()
46 {
47 QByteArray override = qgetenv("WKHTMLTOX_SCREEN_WIDTH");
48
49 bool ok;
50 int width = override.toInt(&ok);
51 if (ok)
52 return qMax(320, qMin(7680, width));
53
54 return 1366; // default screen width
55 }
56
wkhtmltox_screen_height()57 static int wkhtmltox_screen_height()
58 {
59 QByteArray override = qgetenv("WKHTMLTOX_SCREEN_HEIGHT");
60
61 bool ok;
62 int height = override.toInt(&ok);
63 if (ok)
64 return qMax(240, qMin(4320, height));
65
66 return 768; // default screen width
67 }
68
69
70
qwidgetForPage(const Page * page)71 static QWidget* qwidgetForPage(const Page* page)
72 {
73 Frame* frame = (page ? page->mainFrame() : 0);
74 FrameView* frameView = (frame ? frame->view() : 0);
75
76 if (!frameView)
77 return 0;
78
79 return frameView->qwidget();
80 }
81
screenRect(const Page * page)82 FloatRect screenRect(const Page* page)
83 {
84 if (QApplication::type() == QApplication::Tty)
85 return FloatRect(0,0,wkhtmltox_screen_width(),wkhtmltox_screen_height());
86
87 QWidget* qw = qwidgetForPage(page);
88 if (!qw)
89 return FloatRect();
90
91 // Taken from KGlobalSettings::desktopGeometry
92 QDesktopWidget* dw = QApplication::desktop();
93 if (!dw)
94 return FloatRect();
95
96 return IntRect(dw->screenGeometry(qw));
97 }
98
screenDepth(const Page * page)99 int screenDepth(const Page* page)
100 {
101 if (QApplication::type() == QApplication::Tty)
102 return 32;
103
104 QWidget* qw = qwidgetForPage(page);
105 if (!qw)
106 return 32;
107
108 return qw->depth();
109 }
110
usableScreenRect(const Page * page)111 FloatRect usableScreenRect(const Page* page)
112 {
113 if (QApplication::type() == QApplication::Tty)
114 return FloatRect();
115
116 QWidget* qw = qwidgetForPage(page);
117 if (!qw)
118 return FloatRect();
119
120 // Taken from KGlobalSettings::desktopGeometry
121 QDesktopWidget* dw = QApplication::desktop();
122 if (!dw)
123 return FloatRect();
124
125 return IntRect(dw->availableGeometry(qw));
126 }
127
scaleFactor(const Page *)128 float scaleFactor(const Page*)
129 {
130 return 1.0f;
131 }
132
133 }
134
135 // vim: ts=4 sw=4 et
136