1 /*
   2  * Copyright (c) 2013, 2017, 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 #undef IMPL
  27 
  28 #include "config.h"
  29 
  30 #include <WebCore/DOMWindow.h>
  31 #include <WebCore/EventTarget.h>
  32 #include <WebCore/MouseEvent.h>
  33 #include <WebCore/Node.h>
  34 #include <WebCore/JSMainThreadExecState.h>
  35 
  36 #include <wtf/RefPtr.h>
  37 #include <wtf/GetPtr.h>
  38 
  39 #include "JavaDOMUtils.h"
  40 #include <wtf/java/JavaEnv.h>
  41 
  42 using namespace WebCore;
  43 
  44 extern "C" {
  45 
  46 #define IMPL (static_cast<MouseEvent*>(jlong_to_ptr(peer)))
  47 
  48 
  49 // Attributes
  50 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getScreenXImpl(JNIEnv*, jclass, jlong peer)
  51 {
  52     WebCore::JSMainThreadNullState state;
  53     return IMPL->screenX();
  54 }
  55 
  56 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getScreenYImpl(JNIEnv*, jclass, jlong peer)
  57 {
  58     WebCore::JSMainThreadNullState state;
  59     return IMPL->screenY();
  60 }
  61 
  62 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getClientXImpl(JNIEnv*, jclass, jlong peer)
  63 {
  64     WebCore::JSMainThreadNullState state;
  65     return IMPL->clientX();
  66 }
  67 
  68 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getClientYImpl(JNIEnv*, jclass, jlong peer)
  69 {
  70     WebCore::JSMainThreadNullState state;
  71     return IMPL->clientY();
  72 }
  73 
  74 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getCtrlKeyImpl(JNIEnv*, jclass, jlong peer)
  75 {
  76     WebCore::JSMainThreadNullState state;
  77     return IMPL->ctrlKey();
  78 }
  79 
  80 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getShiftKeyImpl(JNIEnv*, jclass, jlong peer)
  81 {
  82     WebCore::JSMainThreadNullState state;
  83     return IMPL->shiftKey();
  84 }
  85 
  86 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getAltKeyImpl(JNIEnv*, jclass, jlong peer)
  87 {
  88     WebCore::JSMainThreadNullState state;
  89     return IMPL->altKey();
  90 }
  91 
  92 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getMetaKeyImpl(JNIEnv*, jclass, jlong peer)
  93 {
  94     WebCore::JSMainThreadNullState state;
  95     return IMPL->metaKey();
  96 }
  97 
  98 JNIEXPORT jshort JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getButtonImpl(JNIEnv*, jclass, jlong peer)
  99 {
 100     WebCore::JSMainThreadNullState state;
 101     return IMPL->button();
 102 }
 103 
 104 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getRelatedTargetImpl(JNIEnv* env, jclass, jlong peer)
 105 {
 106     WebCore::JSMainThreadNullState state;
 107     return JavaReturn<EventTarget>(env, WTF::getPtr(IMPL->relatedTarget()));
 108 }
 109 
 110 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getOffsetXImpl(JNIEnv*, jclass, jlong peer)
 111 {
 112     WebCore::JSMainThreadNullState state;
 113     return IMPL->offsetX();
 114 }
 115 
 116 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getOffsetYImpl(JNIEnv*, jclass, jlong peer)
 117 {
 118     WebCore::JSMainThreadNullState state;
 119     return IMPL->offsetY();
 120 }
 121 
 122 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getXImpl(JNIEnv*, jclass, jlong peer)
 123 {
 124     WebCore::JSMainThreadNullState state;
 125     return IMPL->x();
 126 }
 127 
 128 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getYImpl(JNIEnv*, jclass, jlong peer)
 129 {
 130     WebCore::JSMainThreadNullState state;
 131     return IMPL->y();
 132 }
 133 
 134 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getFromElementImpl(JNIEnv* env, jclass, jlong peer)
 135 {
 136     WebCore::JSMainThreadNullState state;
 137     return JavaReturn<Node>(env, WTF::getPtr(IMPL->fromElement()));
 138 }
 139 
 140 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_MouseEventImpl_getToElementImpl(JNIEnv* env, jclass, jlong peer)
 141 {
 142     WebCore::JSMainThreadNullState state;
 143     return JavaReturn<Node>(env, WTF::getPtr(IMPL->toElement()));
 144 }
 145 
 146 
 147 // Functions
 148 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_MouseEventImpl_initMouseEventImpl(JNIEnv* env, jclass, jlong peer
 149     , jstring type
 150     , jboolean canBubble
 151     , jboolean cancelable
 152     , jlong view
 153     , jint detail
 154     , jint screenX
 155     , jint screenY
 156     , jint clientX
 157     , jint clientY
 158     , jboolean ctrlKey
 159     , jboolean altKey
 160     , jboolean shiftKey
 161     , jboolean metaKey
 162     , jshort button
 163     , jlong relatedTarget)
 164 {
 165     WebCore::JSMainThreadNullState state;
 166     IMPL->initMouseEvent(String(env, type)
 167             , canBubble
 168             , cancelable
 169             , static_cast<DOMWindow*>(jlong_to_ptr(view))
 170             , detail
 171             , screenX
 172             , screenY
 173             , clientX
 174             , clientY
 175             , ctrlKey
 176             , altKey
 177             , shiftKey
 178             , metaKey
 179             , button
 180             , static_cast<EventTarget*>(jlong_to_ptr(relatedTarget)));
 181 }
 182 
 183 
 184 }