1 /* 2 * Copyright (c) 2013, 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 #undef IMPL 27 28 #include "config.h" 29 30 #include <WebCore/Event.h> 31 #include <WebCore/EventTarget.h> 32 #include <WebCore/KeyboardEvent.h> 33 #include <WebCore/MouseEvent.h> 34 #include <WebCore/MutationEvent.h> 35 #include <WebCore/UIEvent.h> 36 #include <WebCore/WheelEvent.h> 37 #include <WebCore/JSMainThreadExecState.h> 38 39 #include <wtf/RefPtr.h> 40 #include <wtf/GetPtr.h> 41 42 #include "JavaDOMUtils.h" 43 #include <wtf/java/JavaEnv.h> 44 45 using namespace WebCore; 46 47 extern "C" { 48 49 #define IMPL (static_cast<Event*>(jlong_to_ptr(peer))) 50 51 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_dispose(JNIEnv*, jclass, jlong peer) 52 { 53 IMPL->deref(); 54 } 55 56 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_EventImpl_getCPPTypeImpl(JNIEnv*, jclass, jlong peer) 57 { 58 if (IMPL->isWheelEvent()) 59 return 1; 60 if (IMPL->isMouseEvent()) 61 return 2; 62 if (IMPL->isKeyboardEvent()) 63 return 3; 64 if (IMPL->isUIEvent()) 65 return 4; 66 if (IMPL->isMutationEvent()) 67 return 5; 68 return 0; 69 } 70 71 72 // Attributes 73 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_EventImpl_getTypeImpl(JNIEnv* env, jclass, jlong peer) 74 { 75 WebCore::JSMainThreadNullState state; 76 return JavaReturn<String>(env, IMPL->type()); 77 } 78 79 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_EventImpl_getTargetImpl(JNIEnv* env, jclass, jlong peer) 80 { 81 WebCore::JSMainThreadNullState state; 82 return JavaReturn<EventTarget>(env, WTF::getPtr(IMPL->target())); 83 } 84 85 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_EventImpl_getCurrentTargetImpl(JNIEnv* env, jclass, jlong peer) 86 { 87 WebCore::JSMainThreadNullState state; 88 return JavaReturn<EventTarget>(env, WTF::getPtr(IMPL->currentTarget())); 89 } 90 91 JNIEXPORT jshort JNICALL Java_com_sun_webkit_dom_EventImpl_getEventPhaseImpl(JNIEnv*, jclass, jlong peer) 92 { 93 WebCore::JSMainThreadNullState state; 94 return IMPL->eventPhase(); 95 } 96 97 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getBubblesImpl(JNIEnv*, jclass, jlong peer) 98 { 99 WebCore::JSMainThreadNullState state; 100 return IMPL->bubbles(); 101 } 102 103 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getCancelableImpl(JNIEnv*, jclass, jlong peer) 104 { 105 WebCore::JSMainThreadNullState state; 106 return IMPL->cancelable(); 107 } 108 109 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_EventImpl_getTimeStampImpl(JNIEnv*, jclass, jlong peer) 110 { 111 WebCore::JSMainThreadNullState state; 112 return IMPL->timeStamp().approximateWallTime().secondsSinceEpoch().milliseconds(); 113 } 114 115 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getDefaultPreventedImpl(JNIEnv*, jclass, jlong peer) 116 { 117 WebCore::JSMainThreadNullState state; 118 return IMPL->defaultPrevented(); 119 } 120 121 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getIsTrustedImpl(JNIEnv*, jclass, jlong peer) 122 { 123 WebCore::JSMainThreadNullState state; 124 return IMPL->isTrusted(); 125 } 126 127 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_EventImpl_getSrcElementImpl(JNIEnv* env, jclass, jlong peer) 128 { 129 WebCore::JSMainThreadNullState state; 130 return JavaReturn<EventTarget>(env, WTF::getPtr(IMPL->target())); 131 } 132 133 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getReturnValueImpl(JNIEnv*, jclass, jlong peer) 134 { 135 WebCore::JSMainThreadNullState state; 136 return IMPL->legacyReturnValue(); 137 } 138 139 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_setReturnValueImpl(JNIEnv*, jclass, jlong peer, jboolean value) 140 { 141 WebCore::JSMainThreadNullState state; 142 IMPL->setLegacyReturnValue(value); 143 } 144 145 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_EventImpl_getCancelBubbleImpl(JNIEnv*, jclass, jlong peer) 146 { 147 WebCore::JSMainThreadNullState state; 148 return IMPL->cancelBubble(); 149 } 150 151 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_setCancelBubbleImpl(JNIEnv*, jclass, jlong peer, jboolean value) 152 { 153 WebCore::JSMainThreadNullState state; 154 IMPL->setCancelBubble(value); 155 } 156 157 158 // Functions 159 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_stopPropagationImpl(JNIEnv*, jclass, jlong peer) 160 { 161 WebCore::JSMainThreadNullState state; 162 IMPL->stopPropagation(); 163 } 164 165 166 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_preventDefaultImpl(JNIEnv*, jclass, jlong peer) 167 { 168 WebCore::JSMainThreadNullState state; 169 IMPL->preventDefault(); 170 } 171 172 173 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_initEventImpl(JNIEnv* env, jclass, jlong peer 174 , jstring eventTypeArg 175 , jboolean canBubbleArg 176 , jboolean cancelableArg) 177 { 178 WebCore::JSMainThreadNullState state; 179 IMPL->initEvent(String(env, eventTypeArg) 180 , canBubbleArg 181 , cancelableArg); 182 } 183 184 185 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_EventImpl_stopImmediatePropagationImpl(JNIEnv*, jclass, jlong peer) 186 { 187 WebCore::JSMainThreadNullState state; 188 IMPL->stopImmediatePropagation(); 189 } 190 191 192 }