summaryrefslogtreecommitdiff
path: root/modules/web/src/main/native/Source/WebCore/platform/java/PlatformScreenJava.cpp
blob: 3d5ac6dc14df3d18efc1f3cdee6d627abb8d8700 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
 */
#include "config.h"

#include "FloatRect.h"
#include "Frame.h"
#include "FrameView.h"
#include "HostWindow.h"
#include <wtf/java/JavaEnv.h>
#include "PlatformScreen.h"
#include "ScrollView.h"
#include "WebPage.h"
#include "Widget.h"

#include "NotImplemented.h"

static JGClass rectangleCls;
static JGClass widgetClass;

static jfieldID rectxFID;
static jfieldID rectyFID;
static jfieldID rectwFID;
static jfieldID recthFID;
static jmethodID getScreenDepthMID;
static jmethodID getScreenRectMID;

static void initRefs(JNIEnv* env)
{
    if (!widgetClass) {
        widgetClass = JLClass(env->FindClass("com/sun/webkit/WCWidget"));
        ASSERT(widgetClass);

        getScreenDepthMID = env->GetMethodID(
                widgetClass,
                "fwkGetScreenDepth",
                "()I");
        ASSERT(getScreenDepthMID);

        getScreenRectMID = env->GetMethodID(
                widgetClass,
                "fwkGetScreenRect",
                "(Z)Lcom/sun/webkit/graphics/WCRectangle;");
        ASSERT(getScreenRectMID);

        rectangleCls = JLClass(env->FindClass("com/sun/webkit/graphics/WCRectangle"));
        ASSERT(rectangleCls);

        rectxFID = env->GetFieldID(rectangleCls, "x", "F");
        ASSERT(rectxFID);
        rectyFID = env->GetFieldID(rectangleCls, "y", "F");
        ASSERT(rectyFID);
        rectwFID = env->GetFieldID(rectangleCls, "w", "F");
        ASSERT(rectwFID);
        recthFID = env->GetFieldID(rectangleCls, "h", "F");
        ASSERT(recthFID);
    }
}

namespace WebCore
{

int screenHorizontalDPI(Widget*)
{
    notImplemented();
    return 0;
}

int screenVerticalDPI(Widget*)
{
    notImplemented();
    return 0;
}

int screenDepth(Widget* w)
{
    if (!w)
        return 24;

    ASSERT(w->root());
    ASSERT(w->root()->hostWindow());
    PlatformWidget j(w->root()->hostWindow()->platformPageClient());
    if (!j)
        return 24;

    JNIEnv* env = WebCore_GetJavaEnv();
    initRefs(env);

    jint depth(env->CallIntMethod(
            (jobject) j,
            getScreenDepthMID));
    CheckAndClearException(env);

    return depth;
}

int screenDepthPerComponent(Widget* w)
{
    return screenDepth(w) / 3;
}

bool screenIsMonochrome(Widget*)
{
    notImplemented();
    return false;
}

FloatRect getScreenRect(Widget* w, bool available)
{
    if (!w)
        return IntRect(0, 0, 0, 0);

    ASSERT(w->root());
    ASSERT(w->root()->hostWindow());
    PlatformWidget j(w->root()->hostWindow()->platformPageClient());
    if (!j)
        return IntRect(0, 0, 0, 0);

    JNIEnv* env = WebCore_GetJavaEnv();
    initRefs(env);

    JLObject rect(env->CallObjectMethod(
            (jobject) j,
            getScreenRectMID,
            bool_to_jbool(available)));
    CheckAndClearException(env);

    if (!rect) {
        return IntRect(0, 0, 0, 0);
    }

    float x = env->GetFloatField(rect, rectxFID);
    float y = env->GetFloatField(rect, rectyFID);
    float width = env->GetFloatField(rect, rectwFID);
    float height = env->GetFloatField(rect, recthFID);

    return FloatRect(x, y, width, height);
}

FloatRect screenRect(Widget* w)
{
    return getScreenRect(w, false);
}

FloatRect screenAvailableRect(Widget* w)
{
    return getScreenRect(w, true);
}

bool screenHasInvertedColors() //XXX: recheck
{
    return false;
}

bool screenSupportsExtendedColor(Widget*)
{
    return false;
}

} // namespace WebCore