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/DOMWindow.h> 31 #include <WebCore/JSMainThreadExecState.h> 32 #include <WebCore/KeyboardEvent.h> 33 #include <WebCore/ThreadCheck.h> 34 #include <WebCore/UIEvent.h> 35 #include <WebCore/URL.h> 36 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<UIEvent*>(jlong_to_ptr(peer))) 47 48 49 // Attributes 50 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_UIEventImpl_getViewImpl(JNIEnv* env, jclass, jlong peer) 51 { 52 WebCore::JSMainThreadNullState state; 53 return JavaReturn<DOMWindow>(env, WTF::getPtr(IMPL->view())); 54 } 55 56 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getDetailImpl(JNIEnv*, jclass, jlong peer) 57 { 58 WebCore::JSMainThreadNullState state; 59 return IMPL->detail(); 60 } 61 62 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getKeyCodeImpl(JNIEnv*, jclass, jlong peer) 63 { 64 WebCore::JSMainThreadNullState state; 65 if (is<WebCore::KeyboardEvent>(*IMPL)) 66 return downcast<WebCore::KeyboardEvent>(*IMPL).keyCode(); 67 return 0; 68 } 69 70 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getCharCodeImpl(JNIEnv*, jclass, jlong peer) 71 { 72 WebCore::JSMainThreadNullState state; 73 if (is<WebCore::KeyboardEvent>(*IMPL)) 74 return downcast<WebCore::KeyboardEvent>(*IMPL).charCode(); 75 return 0; 76 } 77 78 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getLayerXImpl(JNIEnv*, jclass, jlong peer) 79 { 80 WebCore::JSMainThreadNullState state; 81 return IMPL->layerX(); 82 } 83 84 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getLayerYImpl(JNIEnv*, jclass, jlong peer) 85 { 86 WebCore::JSMainThreadNullState state; 87 return IMPL->layerY(); 88 } 89 90 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getPageXImpl(JNIEnv*, jclass, jlong peer) 91 { 92 WebCore::JSMainThreadNullState state; 93 return IMPL->pageX(); 94 } 95 96 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getPageYImpl(JNIEnv*, jclass, jlong peer) 97 { 98 WebCore::JSMainThreadNullState state; 99 return IMPL->pageY(); 100 } 101 102 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_UIEventImpl_getWhichImpl(JNIEnv*, jclass, jlong peer) 103 { 104 WebCore::JSMainThreadNullState state; 105 return IMPL->which(); 106 } 107 108 109 // Functions 110 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_UIEventImpl_initUIEventImpl(JNIEnv* env, jclass, jlong peer 111 , jstring type 112 , jboolean canBubble 113 , jboolean cancelable 114 , jlong view 115 , jint detail) 116 { 117 WebCore::JSMainThreadNullState state; 118 IMPL->initUIEvent(String(env, type) 119 , canBubble 120 , cancelable 121 , static_cast<DOMWindow*>(jlong_to_ptr(view)) 122 , detail); 123 } 124 125 126 }