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/CSSRule.h>
  31 #include <WebCore/CSSStyleDeclaration.h>
  32 #include <WebCore/DeprecatedCSSOMValue.h>
  33 #include "DOMException.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<CSSStyleDeclaration*>(jlong_to_ptr(peer)))
  47 
  48 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_dispose(JNIEnv*, jclass, jlong peer)
  49 {
  50     IMPL->deref();
  51 }
  52 
  53 
  54 // Attributes
  55 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getCssTextImpl(JNIEnv* env, jclass, jlong peer)
  56 {
  57     WebCore::JSMainThreadNullState state;
  58     return JavaReturn<String>(env, IMPL->cssText());
  59 }
  60 
  61 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_setCssTextImpl(JNIEnv* env, jclass, jlong peer, jstring value)
  62 {
  63     WebCore::JSMainThreadNullState state;
  64     IMPL->setCssText(String(env, value));
  65 }
  66 
  67 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getLengthImpl(JNIEnv*, jclass, jlong peer)
  68 {
  69     WebCore::JSMainThreadNullState state;
  70     return IMPL->length();
  71 }
  72 
  73 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getParentRuleImpl(JNIEnv* env, jclass, jlong peer)
  74 {
  75     WebCore::JSMainThreadNullState state;
  76     return JavaReturn<CSSRule>(env, WTF::getPtr(IMPL->parentRule()));
  77 }
  78 
  79 
  80 // Functions
  81 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getPropertyValueImpl(JNIEnv* env, jclass, jlong peer
  82     , jstring propertyName)
  83 {
  84     WebCore::JSMainThreadNullState state;
  85     return JavaReturn<String>(env, IMPL->getPropertyValue(String(env, propertyName)));
  86 }
  87 
  88 
  89 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getPropertyCSSValueImpl(JNIEnv* env, jclass, jlong peer
  90     , jstring propertyName)
  91 {
  92     WebCore::JSMainThreadNullState state;
  93     return JavaReturn<DeprecatedCSSOMValue>(env, WTF::getPtr(IMPL->getPropertyCSSValue(String(env, propertyName))));
  94 }
  95 
  96 
  97 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_removePropertyImpl(JNIEnv* env, jclass, jlong peer
  98     , jstring propertyName)
  99 {
 100     WebCore::JSMainThreadNullState state;
 101     return JavaReturn<String>(env, raiseOnDOMError(env, IMPL->removeProperty(String(env, propertyName))));
 102 }
 103 
 104 
 105 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getPropertyPriorityImpl(JNIEnv* env, jclass, jlong peer
 106     , jstring propertyName)
 107 {
 108     WebCore::JSMainThreadNullState state;
 109     return JavaReturn<String>(env, IMPL->getPropertyPriority(String(env, propertyName)));
 110 }
 111 
 112 
 113 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_setPropertyImpl(JNIEnv* env, jclass, jlong peer
 114     , jstring propertyName
 115     , jstring value
 116     , jstring priority)
 117 {
 118     WebCore::JSMainThreadNullState state;
 119     raiseOnDOMError(env, IMPL->setProperty(String(env, propertyName)
 120             , String(env, value)
 121             , String(env, priority)));
 122 }
 123 
 124 
 125 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_itemImpl(JNIEnv* env, jclass, jlong peer
 126     , jint index)
 127 {
 128     WebCore::JSMainThreadNullState state;
 129     return JavaReturn<String>(env, IMPL->item(index));
 130 }
 131 
 132 
 133 JNIEXPORT jstring JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_getPropertyShorthandImpl(JNIEnv* env, jclass, jlong peer
 134     , jstring propertyName)
 135 {
 136     WebCore::JSMainThreadNullState state;
 137     return JavaReturn<String>(env, IMPL->getPropertyShorthand(String(env, propertyName)));
 138 }
 139 
 140 
 141 JNIEXPORT jboolean JNICALL Java_com_sun_webkit_dom_CSSStyleDeclarationImpl_isPropertyImplicitImpl(JNIEnv* env, jclass, jlong peer
 142     , jstring propertyName)
 143 {
 144     WebCore::JSMainThreadNullState state;
 145     return IMPL->isPropertyImplicit(String(env, propertyName));
 146 }
 147 
 148 
 149 }