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/HTMLFormElement.h>
  32 #include <WebCore/HTMLNames.h>
  33 #include <WebCore/HTMLTextAreaElement.h>
  34 #include <WebCore/NodeList.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<HTMLTextAreaElement*>(jlong_to_ptr(peer)))
  48 
  49 
  50 // Attributes
  51 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getAutofocusImpl(JNIEnv*, jclass, jlong peer)
  52 {
  53     WebCore::JSMainThreadNullState state;
  54     return IMPL->hasAttribute(WebCore::HTMLNames::autofocusAttr);
  55 }
  56 
  57 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setAutofocusImpl(JNIEnv*, jclass, jlong peer, jboolean value)
  58 {
  59     WebCore::JSMainThreadNullState state;
  60     IMPL->setBooleanAttribute(WebCore::HTMLNames::autofocusAttr, value);
  61 }
  62 
  63 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getDirNameImpl(JNIEnv* env, jclass, jlong peer)
  64 {
  65     WebCore::JSMainThreadNullState state;
  66     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::dirnameAttr));
  67 }
  68 
  69 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setDirNameImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  70 {
  71     WebCore::JSMainThreadNullState state;
  72     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::dirnameAttr, String(env, value));
  73 }
  74 
  75 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getDisabledImpl(JNIEnv*, jclass, jlong peer)
  76 {
  77     WebCore::JSMainThreadNullState state;
  78     return IMPL->hasAttribute(WebCore::HTMLNames::disabledAttr);
  79 }
  80 
  81 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setDisabledImpl(JNIEnv*, jclass, jlong peer, jboolean value)
  82 {
  83     WebCore::JSMainThreadNullState state;
  84     IMPL->setBooleanAttribute(WebCore::HTMLNames::disabledAttr, value);
  85 }
  86 
  87 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getFormImpl(JNIEnv* env, jclass, jlong peer)
  88 {
  89     WebCore::JSMainThreadNullState state;
  90     return JavaReturn<HTMLFormElement>(env, WTF::getPtr(IMPL->form()));
  91 }
  92 
  93 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getMaxLengthImpl(JNIEnv*, jclass, jlong peer)
  94 {
  95     WebCore::JSMainThreadNullState state;
  96     return IMPL->maxLength();
  97 }
  98 
  99 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setMaxLengthImpl(JNIEnv*, jclass, jlong peer, jint value)
 100 {
 101     WebCore::JSMainThreadNullState state;
 102     IMPL->setMaxLength(value);
 103 }
 104 
 105 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getNameImpl(JNIEnv* env, jclass, jlong peer)
 106 {
 107     WebCore::JSMainThreadNullState state;
 108     return JavaReturn<String>(env, IMPL->getNameAttribute());
 109 }
 110 
 111 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setNameImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 112 {
 113     WebCore::JSMainThreadNullState state;
 114     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::nameAttr, String(env, value));
 115 }
 116 
 117 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getPlaceholderImpl(JNIEnv* env, jclass, jlong peer)
 118 {
 119     WebCore::JSMainThreadNullState state;
 120     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::placeholderAttr));
 121 }
 122 
 123 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setPlaceholderImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 124 {
 125     WebCore::JSMainThreadNullState state;
 126     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::placeholderAttr, String(env, value));
 127 }
 128 
 129 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getReadOnlyImpl(JNIEnv*, jclass, jlong peer)
 130 {
 131     WebCore::JSMainThreadNullState state;
 132     return IMPL->hasAttribute(WebCore::HTMLNames::readonlyAttr);
 133 }
 134 
 135 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setReadOnlyImpl(JNIEnv*, jclass, jlong peer, jboolean value)
 136 {
 137     WebCore::JSMainThreadNullState state;
 138     IMPL->setBooleanAttribute(WebCore::HTMLNames::readonlyAttr, value);
 139 }
 140 
 141 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getRequiredImpl(JNIEnv*, jclass, jlong peer)
 142 {
 143     WebCore::JSMainThreadNullState state;
 144     return IMPL->hasAttribute(WebCore::HTMLNames::requiredAttr);
 145 }
 146 
 147 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setRequiredImpl(JNIEnv*, jclass, jlong peer, jboolean value)
 148 {
 149     WebCore::JSMainThreadNullState state;
 150     IMPL->setBooleanAttribute(WebCore::HTMLNames::requiredAttr, value);
 151 }
 152 
 153 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getRowsImpl(JNIEnv*, jclass, jlong peer)
 154 {
 155     WebCore::JSMainThreadNullState state;
 156     return IMPL->rows();
 157 }
 158 
 159 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setRowsImpl(JNIEnv*, jclass, jlong peer, jint value)
 160 {
 161     WebCore::JSMainThreadNullState state;
 162     IMPL->setRows(value);
 163 }
 164 
 165 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getColsImpl(JNIEnv*, jclass, jlong peer)
 166 {
 167     WebCore::JSMainThreadNullState state;
 168     return IMPL->cols();
 169 }
 170 
 171 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setColsImpl(JNIEnv*, jclass, jlong peer, jint value)
 172 {
 173     WebCore::JSMainThreadNullState state;
 174     IMPL->setCols(value);
 175 }
 176 
 177 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getWrapImpl(JNIEnv* env, jclass, jlong peer)
 178 {
 179     WebCore::JSMainThreadNullState state;
 180     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::wrapAttr));
 181 }
 182 
 183 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setWrapImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 184 {
 185     WebCore::JSMainThreadNullState state;
 186     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::wrapAttr, String(env, value));
 187 }
 188 
 189 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getTypeImpl(JNIEnv* env, jclass, jlong peer)
 190 {
 191     WebCore::JSMainThreadNullState state;
 192     return JavaReturn<String>(env, IMPL->type());
 193 }
 194 
 195 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getDefaultValueImpl(JNIEnv* env, jclass, jlong peer)
 196 {
 197     WebCore::JSMainThreadNullState state;
 198     return JavaReturn<String>(env, IMPL->defaultValue());
 199 }
 200 
 201 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setDefaultValueImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 202 {
 203     WebCore::JSMainThreadNullState state;
 204     IMPL->setDefaultValue(String(env, value));
 205 }
 206 
 207 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getValueImpl(JNIEnv* env, jclass, jlong peer)
 208 {
 209     WebCore::JSMainThreadNullState state;
 210     return JavaReturn<String>(env, IMPL->value());
 211 }
 212 
 213 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setValueImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 214 {
 215     WebCore::JSMainThreadNullState state;
 216     IMPL->setValue(String(env, value));
 217 }
 218 
 219 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getTextLengthImpl(JNIEnv*, jclass, jlong peer)
 220 {
 221     WebCore::JSMainThreadNullState state;
 222     return IMPL->textLength();
 223 }
 224 
 225 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getWillValidateImpl(JNIEnv*, jclass, jlong peer)
 226 {
 227     WebCore::JSMainThreadNullState state;
 228     return IMPL->willValidate();
 229 }
 230 
 231 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getValidationMessageImpl(JNIEnv* env, jclass, jlong peer)
 232 {
 233     WebCore::JSMainThreadNullState state;
 234     return JavaReturn<String>(env, IMPL->validationMessage());
 235 }
 236 
 237 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getLabelsImpl(JNIEnv* env, jclass, jlong peer)
 238 {
 239     WebCore::JSMainThreadNullState state;
 240     return JavaReturn<NodeList>(env, WTF::getPtr(IMPL->labels()));
 241 }
 242 
 243 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getSelectionStartImpl(JNIEnv*, jclass, jlong peer)
 244 {
 245     WebCore::JSMainThreadNullState state;
 246     return IMPL->selectionStart();
 247 }
 248 
 249 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setSelectionStartImpl(JNIEnv*, jclass, jlong peer, jint value)
 250 {
 251     WebCore::JSMainThreadNullState state;
 252     IMPL->setSelectionStart(value);
 253 }
 254 
 255 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getSelectionEndImpl(JNIEnv*, jclass, jlong peer)
 256 {
 257     WebCore::JSMainThreadNullState state;
 258     return IMPL->selectionEnd();
 259 }
 260 
 261 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setSelectionEndImpl(JNIEnv*, jclass, jlong peer, jint value)
 262 {
 263     WebCore::JSMainThreadNullState state;
 264     IMPL->setSelectionEnd(value);
 265 }
 266 
 267 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getSelectionDirectionImpl(JNIEnv* env, jclass, jlong peer)
 268 {
 269     WebCore::JSMainThreadNullState state;
 270     return JavaReturn<String>(env, IMPL->selectionDirection());
 271 }
 272 
 273 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setSelectionDirectionImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 274 {
 275     WebCore::JSMainThreadNullState state;
 276     IMPL->setSelectionDirection(String(env, value));
 277 }
 278 
 279 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getAccessKeyImpl(JNIEnv* env, jclass, jlong peer)
 280 {
 281     WebCore::JSMainThreadNullState state;
 282     return JavaReturn<String>(env, IMPL->getAttribute(WebCore::HTMLNames::accesskeyAttr));
 283 }
 284 
 285 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setAccessKeyImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 286 {
 287     WebCore::JSMainThreadNullState state;
 288     IMPL->setAttributeWithoutSynchronization(WebCore::HTMLNames::accesskeyAttr, String(env, value));
 289 }
 290 
 291 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_getAutocompleteImpl(JNIEnv* env, jclass, jlong peer)
 292 {
 293     WebCore::JSMainThreadNullState state;
 294     return JavaReturn<String>(env, IMPL->autocomplete());
 295 }
 296 
 297 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setAutocompleteImpl(JNIEnv* env, jclass, jlong peer, jstring value)
 298 {
 299     WebCore::JSMainThreadNullState state;
 300     IMPL->setAutocomplete(String(env, value));
 301 }
 302 
 303 
 304 // Functions
 305 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_checkValidityImpl(JNIEnv*, jclass, jlong peer)
 306 {
 307     WebCore::JSMainThreadNullState state;
 308     return IMPL->checkValidity();
 309 }
 310 
 311 
 312 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setCustomValidityImpl(JNIEnv* env, jclass, jlong peer
 313     , jstring error)
 314 {
 315     WebCore::JSMainThreadNullState state;
 316     IMPL->setCustomValidity(String(env, error));
 317 }
 318 
 319 
 320 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_selectImpl(JNIEnv*, jclass, jlong peer)
 321 {
 322     WebCore::JSMainThreadNullState state;
 323     IMPL->select();
 324 }
 325 
 326 
 327 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setRangeTextImpl(JNIEnv* env, jclass, jlong peer
 328     , jstring replacement)
 329 {
 330     WebCore::JSMainThreadNullState state;
 331     raiseOnDOMError(env, IMPL->setRangeText(String(env, replacement)));
 332 }
 333 
 334 
 335 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setRangeTextExImpl(JNIEnv* env, jclass, jlong peer
 336     , jstring replacement
 337     , jint start
 338     , jint end
 339     , jstring selectionMode)
 340 {
 341     WebCore::JSMainThreadNullState state;
 342     raiseOnDOMError(env, IMPL->setRangeText(String(env, replacement)
 343             , start
 344             , end
 345             , String(env, selectionMode)));
 346 }
 347 
 348 
 349 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLTextAreaElementImpl_setSelectionRangeImpl(JNIEnv* env, jclass, jlong peer
 350     , jint start
 351     , jint end
 352     , jstring direction)
 353 {
 354     WebCore::JSMainThreadNullState state;
 355     IMPL->setSelectionRange(start
 356             , end
 357             , String(env, direction));
 358 }
 359 
 360 
 361 }