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 "DOMException.h"
  31 #include <WebCore/Element.h>
  32 #include <WebCore/HTMLCollection.h>
  33 #include <WebCore/HTMLElement.h>
  34 #include <WebCore/HTMLNames.h>
  35 #include <WebCore/JSMainThreadExecState.h>
  36 
  37 #include <wtf/RefPtr.h>
  38 #include <wtf/GetPtr.h>
  39 
  40 #include "JavaDOMUtils.h"
  41 #include <wtf/java/JavaEnv.h>
  42 
  43 using namespace WebCore;
  44 
  45 extern "C" {
  46 
  47 #define IMPL (static_cast<HTMLElement*>(jlong_to_ptr(peer)))
  48 
  49 // Attributes
  50 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getIdImpl(JNIEnv* env, jclass, jlong peer)
  51 {
  52     WebCore::JSMainThreadNullState state;
  53     return JavaReturn<String>(env, IMPL->getIdAttribute());
  54 }
  55 
  56 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setIdImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  57 {
  58     WebCore::JSMainThreadNullState state;
  59     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::idAttr, String(env, value));
  60 }
  61 
  62 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getTitleImpl(JNIEnv* env, jclass, jlong peer)
  63 {
  64     WebCore::JSMainThreadNullState state;
  65     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::titleAttr));
  66 }
  67 
  68 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setTitleImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  69 {
  70     WebCore::JSMainThreadNullState state;
  71     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::titleAttr, String(env, value));
  72 }
  73 
  74 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getLangImpl(JNIEnv* env, jclass, jlong peer)
  75 {
  76     WebCore::JSMainThreadNullState state;
  77     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::langAttr));
  78 }
  79 
  80 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setLangImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  81 {
  82     WebCore::JSMainThreadNullState state;
  83     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::langAttr, String(env, value));
  84 }
  85 
  86 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getTranslateImpl(JNIEnv*, jclass, jlong peer)
  87 {
  88     WebCore::JSMainThreadNullState state;
  89     return IMPL->translate();
  90 }
  91 
  92 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setTranslateImpl(JNIEnv*, jclass, jlong peer, jboolean value)
  93 {
  94     WebCore::JSMainThreadNullState state;
  95     IMPL->setTranslate(value);
  96 }
  97 
  98 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getDirImpl(JNIEnv* env, jclass, jlong peer)
  99 {
 100     WebCore::JSMainThreadNullState state;
 101     return JavaReturn<String>(env, IMPL->dir());
 102 }
 103 
 104 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setDirImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 105 {
 106     WebCore::JSMainThreadNullState state;
 107     IMPL->setDir(String(env, value));
 108 }
 109 
 110 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getTabIndexImpl(JNIEnv*, jclass, jlong peer)
 111 {
 112     WebCore::JSMainThreadNullState state;
 113     return IMPL->tabIndex();
 114 }
 115 
 116 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setTabIndexImpl(JNIEnv*, jclass, jlong peer, jint value)
 117 {
 118     WebCore::JSMainThreadNullState state;
 119     IMPL->setTabIndex(value);
 120 }
 121 
 122 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getDraggableImpl(JNIEnv*, jclass, jlong peer)
 123 {
 124     WebCore::JSMainThreadNullState state;
 125     return IMPL->draggable();
 126 }
 127 
 128 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setDraggableImpl(JNIEnv*, jclass, jlong peer, jboolean value)
 129 {
 130     WebCore::JSMainThreadNullState state;
 131     IMPL->setDraggable(value);
 132 }
 133 
 134 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getWebkitdropzoneImpl(JNIEnv* env, jclass, jlong peer)
 135 {
 136     WebCore::JSMainThreadNullState state;
 137     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::webkitdropzoneAttr));
 138 }
 139 
 140 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setWebkitdropzoneImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 141 {
 142     WebCore::JSMainThreadNullState state;
 143     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::webkitdropzoneAttr, String(env, value));
 144 }
 145 
 146 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getHiddenImpl(JNIEnv*, jclass, jlong peer)
 147 {
 148     WebCore::JSMainThreadNullState state;
 149     return IMPL->hasAttribute(WebCore::HTMLNames::hiddenAttr);
 150 }
 151 
 152 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setHiddenImpl(JNIEnv*, jclass, jlong peer, jboolean value)
 153 {
 154     WebCore::JSMainThreadNullState state;
 155     IMPL->setBooleanAttribute(WebCore::HTMLNames::hiddenAttr, value);
 156 }
 157 
 158 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getAccessKeyImpl(JNIEnv* env, jclass, jlong peer)
 159 {
 160     WebCore::JSMainThreadNullState state;
 161     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::accesskeyAttr));
 162 }
 163 
 164 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setAccessKeyImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 165 {
 166     WebCore::JSMainThreadNullState state;
 167     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::accesskeyAttr, String(env, value));
 168 }
 169 
 170 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getInnerTextImpl(JNIEnv* env, jclass, jlong peer)
 171 {
 172     WebCore::JSMainThreadNullState state;
 173     return JavaReturn<String>(env, IMPL->innerText());
 174 }
 175 
 176 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setInnerTextImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 177 {
 178     WebCore::JSMainThreadNullState state;
 179     IMPL->setInnerText(String(env, value));
 180 }
 181 
 182 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getOuterTextImpl(JNIEnv* env, jclass, jlong peer)
 183 {
 184     WebCore::JSMainThreadNullState state;
 185     return JavaReturn<String>(env, IMPL->outerText());
 186 }
 187 
 188 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setOuterTextImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 189 {
 190     WebCore::JSMainThreadNullState state;
 191     IMPL->setOuterText(String(env, value));
 192 }
 193 
 194 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getChildrenImpl(JNIEnv* env, jclass, jlong peer)
 195 {
 196     WebCore::JSMainThreadNullState state;
 197     return JavaReturn<HTMLCollection>(env, WTF::getPtr(IMPL->children()));
 198 }
 199 
 200 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getContentEditableImpl(JNIEnv* env, jclass, jlong peer)
 201 {
 202     WebCore::JSMainThreadNullState state;
 203     return JavaReturn<String>(env, IMPL->contentEditable());
 204 }
 205 
 206 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setContentEditableImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 207 {
 208     WebCore::JSMainThreadNullState state;
 209     IMPL->setContentEditable(String(env, value));
 210 }
 211 
 212 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getIsContentEditableImpl(JNIEnv*, jclass, jlong peer)
 213 {
 214     WebCore::JSMainThreadNullState state;
 215     return IMPL->isContentEditable();
 216 }
 217 
 218 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getSpellcheckImpl(JNIEnv*, jclass, jlong peer)
 219 {
 220     WebCore::JSMainThreadNullState state;
 221     return IMPL->spellcheck();
 222 }
 223 
 224 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_setSpellcheckImpl(JNIEnv*, jclass, jlong peer, jboolean value)
 225 {
 226     WebCore::JSMainThreadNullState state;
 227     IMPL->setSpellcheck(value);
 228 }
 229 
 230 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_getTitleDisplayStringImpl(JNIEnv* env, jclass, jlong peer)
 231 {
 232     WebCore::JSMainThreadNullState state;
 233     return JavaReturn<String>(env, IMPL->title());
 234 }
 235 
 236 
 237 // Functions
 238 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_insertAdjacentElementImpl(JNIEnv* env, jclass, jlong peer
 239     , jstring where
 240     , jlong element)
 241 {
 242     WebCore::JSMainThreadNullState state;
 243     if (!element) {
 244         raiseTypeErrorException(env);
 245         return 0;
 246     }
 247     return JavaReturn<Element>(env, WTF::getPtr(raiseOnDOMError(env, IMPL->insertAdjacentElement(String(env, where), *static_cast<Element*>(jlong_to_ptr(element))))));
 248 }
 249 
 250 
 251 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_insertAdjacentHTMLImpl(JNIEnv* env, jclass, jlong peer
 252     , jstring where
 253     , jstring html)
 254 {
 255     WebCore::JSMainThreadNullState state;
 256     raiseOnDOMError(env, IMPL->insertAdjacentHTML(String(env, where)
 257             , String(env, html)));
 258 }
 259 
 260 
 261 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_insertAdjacentTextImpl(JNIEnv* env, jclass, jlong peer
 262     , jstring where
 263     , jstring text)
 264 {
 265     WebCore::JSMainThreadNullState state;
 266     raiseOnDOMError(env, IMPL->insertAdjacentText(String(env, where)
 267             , String(env, text)));
 268 }
 269 
 270 
 271 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLElementImpl_clickImpl(JNIEnv*, jclass, jlong peer)
 272 {
 273     WebCore::JSMainThreadNullState state;
 274     IMPL->click();
 275 }
 276 
 277 
 278 }