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/CSSImportRule.h>
  31 #include <WebCore/CSSRule.h>
  32 #include <WebCore/CSSRuleList.h>
  33 #include <WebCore/CSSStyleSheet.h>
  34 #include "DOMException.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<CSSStyleSheet*>(jlong_to_ptr(peer)))
  48 
  49 
  50 // Attributes
  51 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_getOwnerRuleImpl(JNIEnv* env, jclass, jlong peer)
  52 {
  53     WebCore::JSMainThreadNullState state;
  54     return JavaReturn<CSSRule>(env, WTF::getPtr(IMPL->ownerRule()));
  55 }
  56 
  57 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_getCssRulesImpl(JNIEnv* env, jclass, jlong peer)
  58 {
  59     WebCore::JSMainThreadNullState state;
  60     return JavaReturn<CSSRuleList>(env, WTF::getPtr(IMPL->cssRules()));
  61 }
  62 
  63 JNIEXPORT jlong JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_getRulesImpl(JNIEnv* env, jclass, jlong peer)
  64 {
  65     WebCore::JSMainThreadNullState state;
  66     return JavaReturn<CSSRuleList>(env, WTF::getPtr(IMPL->rules()));
  67 }
  68 
  69 
  70 // Functions
  71 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_insertRuleImpl(JNIEnv* env, jclass, jlong peer
  72     , jstring rule
  73     , jint index)
  74 {
  75     WebCore::JSMainThreadNullState state;
  76     return raiseOnDOMError(env, IMPL->insertRule(String(env, rule)
  77             , index));
  78 }
  79 
  80 
  81 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_deleteRuleImpl(JNIEnv* env, jclass, jlong peer
  82     , jint index)
  83 {
  84     WebCore::JSMainThreadNullState state;
  85     raiseOnDOMError(env, IMPL->deleteRule(index));
  86 }
  87 
  88 
  89 JNIEXPORT jint JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_addRuleImpl(JNIEnv* env, jclass, jlong peer
  90     , jstring selector
  91     , jstring style
  92     , jint index)
  93 {
  94     WebCore::JSMainThreadNullState state;
  95     return raiseOnDOMError(env, IMPL->addRule(String(env, selector)
  96             , String(env, style)
  97             , index));
  98 }
  99 
 100 
 101 JNIEXPORT void JNICALL Java_com_sun_webkit_dom_CSSStyleSheetImpl_removeRuleImpl(JNIEnv* env, jclass, jlong peer
 102     , jint index)
 103 {
 104     WebCore::JSMainThreadNullState state;
 105     raiseOnDOMError(env, IMPL->removeRule(index));
 106 }
 107 
 108 
 109 }