1 /*
   2  * Copyright (c) 2011, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 #include "config.h"
  27 
  28 #include "FloatRect.h"
  29 #include "Frame.h"
  30 #include "FrameView.h"
  31 #include "HostWindow.h"
  32 #include <wtf/java/JavaEnv.h>
  33 #include "PlatformScreen.h"
  34 #include "ScrollView.h"
  35 #include "Widget.h"
  36 
  37 #include "NotImplemented.h"
  38 
  39 namespace PlatformScreenJavaInternal {
  40 
  41 static JGClass rectangleCls;
  42 static JGClass widgetClass;
  43 
  44 static jfieldID rectxFID;
  45 static jfieldID rectyFID;
  46 static jfieldID rectwFID;
  47 static jfieldID recthFID;
  48 static jmethodID getScreenDepthMID;
  49 static jmethodID getScreenRectMID;
  50 
  51 static void initRefs(JNIEnv* env)
  52 {
  53     if (!widgetClass) {
  54         widgetClass = JLClass(env->FindClass("com/sun/webkit/WCWidget"));
  55         ASSERT(widgetClass);
  56 
  57         getScreenDepthMID = env->GetMethodID(
  58                 widgetClass,
  59                 "fwkGetScreenDepth",
  60                 "()I");
  61         ASSERT(getScreenDepthMID);
  62 
  63         getScreenRectMID = env->GetMethodID(
  64                 widgetClass,
  65                 "fwkGetScreenRect",
  66                 "(Z)Lcom/sun/webkit/graphics/WCRectangle;");
  67         ASSERT(getScreenRectMID);
  68 
  69         rectangleCls = JLClass(env->FindClass("com/sun/webkit/graphics/WCRectangle"));
  70         ASSERT(rectangleCls);
  71 
  72         rectxFID = env->GetFieldID(rectangleCls, "x", "F");
  73         ASSERT(rectxFID);
  74         rectyFID = env->GetFieldID(rectangleCls, "y", "F");
  75         ASSERT(rectyFID);
  76         rectwFID = env->GetFieldID(rectangleCls, "w", "F");
  77         ASSERT(rectwFID);
  78         recthFID = env->GetFieldID(rectangleCls, "h", "F");
  79         ASSERT(recthFID);
  80     }
  81 }
  82 }
  83 
  84 namespace WebCore
  85 {
  86 
  87 int screenHorizontalDPI(Widget*)
  88 {
  89     notImplemented();
  90     return 0;
  91 }
  92 
  93 int screenVerticalDPI(Widget*)
  94 {
  95     notImplemented();
  96     return 0;
  97 }
  98 
  99 int screenDepth(Widget* w)
 100 {
 101     using namespace PlatformScreenJavaInternal;
 102     if (!w)
 103         return 24;
 104 
 105     ASSERT(w->root());
 106     ASSERT(w->root()->hostWindow());
 107     PlatformWidget j(w->root()->hostWindow()->platformPageClient());
 108     if (!j)
 109         return 24;
 110 
 111     JNIEnv* env = WebCore_GetJavaEnv();
 112     initRefs(env);
 113 
 114     jint depth(env->CallIntMethod(
 115             (jobject) j,
 116             getScreenDepthMID));
 117     CheckAndClearException(env);
 118 
 119     return depth;
 120 }
 121 
 122 int screenDepthPerComponent(Widget* w)
 123 {
 124     return screenDepth(w) / 3;
 125 }
 126 
 127 bool screenIsMonochrome(Widget*)
 128 {
 129     notImplemented();
 130     return false;
 131 }
 132 
 133 FloatRect getScreenRect(Widget* w, bool available)
 134 {
 135     using namespace PlatformScreenJavaInternal;
 136     if (!w)
 137         return IntRect(0, 0, 0, 0);
 138 
 139     ASSERT(w->root());
 140     ASSERT(w->root()->hostWindow());
 141     PlatformWidget j(w->root()->hostWindow()->platformPageClient());
 142     if (!j)
 143         return IntRect(0, 0, 0, 0);
 144 
 145     JNIEnv* env = WebCore_GetJavaEnv();
 146     initRefs(env);
 147 
 148     JLObject rect(env->CallObjectMethod(
 149             (jobject) j,
 150             getScreenRectMID,
 151             bool_to_jbool(available)));
 152     CheckAndClearException(env);
 153 
 154     if (!rect) {
 155         return IntRect(0, 0, 0, 0);
 156     }
 157 
 158     float x = env->GetFloatField(rect, rectxFID);
 159     float y = env->GetFloatField(rect, rectyFID);
 160     float width = env->GetFloatField(rect, rectwFID);
 161     float height = env->GetFloatField(rect, recthFID);
 162 
 163     return FloatRect(x, y, width, height);
 164 }
 165 
 166 FloatRect screenRect(Widget* w)
 167 {
 168     return getScreenRect(w, false);
 169 }
 170 
 171 FloatRect screenAvailableRect(Widget* w)
 172 {
 173     return getScreenRect(w, true);
 174 }
 175 
 176 bool screenHasInvertedColors() //XXX: recheck
 177 {
 178     return false;
 179 }
 180 
 181 bool screenSupportsExtendedColor(Widget*)
 182 {
 183     return false;
 184 }
 185 
 186 } // namespace WebCore