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 "DOMException.h" 31 #include <WebCore/DOMSelection.h> 32 #include <WebCore/Node.h> 33 #include <WebCore/Range.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<DOMSelection*>(jlong_to_ptr(peer))) 47 48 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_dispose(JNIEnv* env, jclass, jlong peer) 49 { 50 IMPL->deref(); 51 } 52 53 54 // Attributes 55 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getAnchorNodeImpl(JNIEnv* env, jclass, jlong peer) 56 { 57 WebCore::JSMainThreadNullState state; 58 return JavaReturn<Node>(env, WTF::getPtr(IMPL->anchorNode())); 59 } 60 61 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getAnchorOffsetImpl(JNIEnv* env, jclass, jlong peer) 62 { 63 WebCore::JSMainThreadNullState state; 64 return IMPL->anchorOffset(); 65 } 66 67 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getFocusNodeImpl(JNIEnv* env, jclass, jlong peer) 68 { 69 WebCore::JSMainThreadNullState state; 70 return JavaReturn<Node>(env, WTF::getPtr(IMPL->focusNode())); 71 } 72 73 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getFocusOffsetImpl(JNIEnv* env, jclass, jlong peer) 74 { 75 WebCore::JSMainThreadNullState state; 76 return IMPL->focusOffset(); 77 } 78 79 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getIsCollapsedImpl(JNIEnv* env, jclass, jlong peer) 80 { 81 WebCore::JSMainThreadNullState state; 82 return IMPL->isCollapsed(); 83 } 84 85 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getRangeCountImpl(JNIEnv* env, jclass, jlong peer) 86 { 87 WebCore::JSMainThreadNullState state; 88 return IMPL->rangeCount(); 89 } 90 91 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getBaseNodeImpl(JNIEnv* env, jclass, jlong peer) 92 { 93 WebCore::JSMainThreadNullState state; 94 return JavaReturn<Node>(env, WTF::getPtr(IMPL->baseNode())); 95 } 96 97 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getBaseOffsetImpl(JNIEnv* env, jclass, jlong peer) 98 { 99 WebCore::JSMainThreadNullState state; 100 return IMPL->baseOffset(); 101 } 102 103 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getExtentNodeImpl(JNIEnv* env, jclass, jlong peer) 104 { 105 WebCore::JSMainThreadNullState state; 106 return JavaReturn<Node>(env, WTF::getPtr(IMPL->extentNode())); 107 } 108 109 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getExtentOffsetImpl(JNIEnv* env, jclass, jlong peer) 110 { 111 WebCore::JSMainThreadNullState state; 112 return IMPL->extentOffset(); 113 } 114 115 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getTypeImpl(JNIEnv* env, jclass, jlong peer) 116 { 117 WebCore::JSMainThreadNullState state; 118 return JavaReturn<String>(env, IMPL->type()); 119 } 120 121 122 // Functions 123 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_collapseImpl(JNIEnv* env, jclass, jlong peer 124 , jlong node 125 , jint index) 126 { 127 WebCore::JSMainThreadNullState state; 128 raiseOnDOMError(env, IMPL->collapse(static_cast<Node*>(jlong_to_ptr(node)) 129 , index)); 130 } 131 132 133 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_collapseToEndImpl(JNIEnv* env, jclass, jlong peer) 134 { 135 WebCore::JSMainThreadNullState state; 136 raiseOnDOMError(env, IMPL->collapseToEnd()); 137 } 138 139 140 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_collapseToStartImpl(JNIEnv* env, jclass, jlong peer) 141 { 142 WebCore::JSMainThreadNullState state; 143 raiseOnDOMError(env, IMPL->collapseToStart()); 144 } 145 146 147 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_deleteFromDocumentImpl(JNIEnv* env, jclass, jlong peer) 148 { 149 WebCore::JSMainThreadNullState state; 150 IMPL->deleteFromDocument(); 151 } 152 153 154 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_containsNodeImpl(JNIEnv* env, jclass, jlong peer 155 , jlong node 156 , jboolean allowPartial) 157 { 158 WebCore::JSMainThreadNullState state; 159 return IMPL->containsNode(static_cast<Node*>(jlong_to_ptr(node)) 160 , allowPartial); 161 } 162 163 164 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_selectAllChildrenImpl(JNIEnv* env, jclass, jlong peer 165 , jlong node) 166 { 167 WebCore::JSMainThreadNullState state; 168 raiseOnDOMError(env, IMPL->selectAllChildren(static_cast<Node*>(jlong_to_ptr(node)))); 169 } 170 171 172 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_extendImpl(JNIEnv* env, jclass, jlong peer 173 , jlong node 174 , jint offset) 175 { 176 WebCore::JSMainThreadNullState state; 177 raiseOnDOMError(env, IMPL->extend(static_cast<Node*>(jlong_to_ptr(node)) 178 , offset)); 179 } 180 181 182 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_getRangeAtImpl(JNIEnv* env, jclass, jlong peer 183 , jint index) 184 { 185 WebCore::JSMainThreadNullState state; 186 return JavaReturn<Range>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->getRangeAt(index)))); 187 } 188 189 190 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_removeAllRangesImpl(JNIEnv* env, jclass, jlong peer) 191 { 192 WebCore::JSMainThreadNullState state; 193 IMPL->removeAllRanges(); 194 } 195 196 197 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_addRangeImpl(JNIEnv* env, jclass, jlong peer 198 , jlong range) 199 { 200 WebCore::JSMainThreadNullState state; 201 IMPL->addRange(static_cast<Range*>(jlong_to_ptr(range))); 202 } 203 204 205 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_modifyImpl(JNIEnv* env, jclass, jlong peer 206 , jstring alter 207 , jstring direction 208 , jstring granularity) 209 { 210 WebCore::JSMainThreadNullState state; 211 IMPL->modify(String(env, alter) 212 , String(env, direction) 213 , String(env, granularity)); 214 } 215 216 217 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_setBaseAndExtentImpl(JNIEnv* env, jclass, jlong peer 218 , jlong baseNode 219 , jint baseOffset 220 , jlong extentNode 221 , jint extentOffset) 222 { 223 WebCore::JSMainThreadNullState state; 224 raiseOnDOMError(env, IMPL->setBaseAndExtent(static_cast<Node*>(jlong_to_ptr(baseNode)) 225 , baseOffset 226 , static_cast<Node*>(jlong_to_ptr(extentNode)) 227 , extentOffset)); 228 } 229 230 231 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_setPositionImpl(JNIEnv* env, jclass, jlong peer 232 , jlong node 233 , jint offset) 234 { 235 WebCore::JSMainThreadNullState state; 236 raiseOnDOMError(env, IMPL->setPosition(static_cast<Node*>(jlong_to_ptr(node)) 237 , offset)); 238 } 239 240 241 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_DOMSelectionImpl_emptyImpl(JNIEnv* env, jclass, jlong peer) 242 { 243 WebCore::JSMainThreadNullState state; 244 IMPL->empty(); 245 } 246 247 248 }