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 
  31 #include "DOMException.h"
  32 
  33 #include <WebCore/HTMLOptGroupElement.h>
  34 #include <WebCore/HTMLOptionElement.h>
  35 #include <WebCore/HTMLOptionsCollection.h>
  36 #include <WebCore/JSMainThreadExecState.h>
  37 #include <WebCore/Node.h>
  38 #include <WebCore/ThreadCheck.h>
  39 #include <WebCore/URL.h>
  40 #include <wtf/RefPtr.h>
  41 #include <wtf/GetPtr.h>
  42 #include <wtf/Variant.h>
  43 
  44 #include "JavaDOMUtils.h"
  45 #include <wtf/java/JavaEnv.h>
  46 
  47 using namespace WebCore;
  48 
  49 extern "C" {
  50 
  51 #define IMPL (static_cast<HTMLOptionsCollection*>(jlong_to_ptr(peer)))
  52 
  53 // Attributes
  54 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_getSelectedIndexImpl(JNIEnv*, jclass, jlong peer)
  55 {
  56     WebCore::JSMainThreadNullState state;
  57     return IMPL->selectedIndex();
  58 }
  59 
  60 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_setSelectedIndexImpl(JNIEnv*, jclass, jlong peer, jint value)
  61 {
  62     WebCore::JSMainThreadNullState state;
  63     IMPL->setSelectedIndex(value);
  64 }
  65 
  66 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_getLengthImpl(JNIEnv*, jclass, jlong peer)
  67 {
  68     WebCore::JSMainThreadNullState state;
  69     return IMPL->length();
  70 }
  71 
  72 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_setLengthImpl(JNIEnv*, jclass, jlong peer, jint value)
  73 {
  74     WebCore::JSMainThreadNullState state;
  75     IMPL->setLength(value);
  76 }
  77 
  78 
  79 // Functions
  80 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_namedItemImpl(JNIEnv* env, jclass, jlong peer
  81     , jstring name)
  82 {
  83     WebCore::JSMainThreadNullState state;
  84     return JavaReturn<Node>(env, WTF::getPtr(IMPL->namedItem(String(env, name))));
  85 }
  86 
  87 
  88 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_addImpl(JNIEnv* env, jclass, jlong peer
  89     , jlong option
  90     , jint index)
  91 {
  92     WebCore::JSMainThreadNullState state;
  93     if (!option) {
  94         raiseTypeErrorException(env);
  95         return;
  96     }
  97     raiseOnDOMError(env, IMPL->add(static_cast<HTMLOptionElement*>(jlong_to_ptr(option)), std::optional<WebCore::HTMLOptionsCollection::HTMLElementOrInt> { static_cast<int>(index) }));
  98 }
  99 
 100 
 101 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_HTMLOptionsCollectionImpl_itemImpl(JNIEnv* env, jclass, jlong peer
 102     , jint index)
 103 {
 104     WebCore::JSMainThreadNullState state;
 105     return JavaReturn<Node>(env, WTF::getPtr(IMPL->item(index)));
 106 }
 107 
 108 
 109 }