use of com.gargoylesoftware.css.dom.CSSRuleListImpl in project htmlunit by HtmlUnit.
the class CSSStyleSheet method refreshCssRules.
private void refreshCssRules() {
if (cssRules_ == null) {
return;
}
cssRules_.clearRules();
cssRulesIndexFix_.clear();
final CSSRuleListImpl ruleList = getWrappedSheet().getCssRules();
final List<AbstractCSSRuleImpl> rules = ruleList.getRules();
int pos = 0;
for (final AbstractCSSRuleImpl rule : rules) {
if (rule instanceof CSSCharsetRuleImpl) {
cssRulesIndexFix_.add(pos);
continue;
}
final com.gargoylesoftware.htmlunit.javascript.host.css.CSSRule cssRule = com.gargoylesoftware.htmlunit.javascript.host.css.CSSRule.create(this, rule);
if (null == cssRule) {
cssRulesIndexFix_.add(pos);
} else {
cssRules_.addRule(cssRule);
}
pos++;
}
// reset our index also
getWrappedSheet().resetRuleIndex();
}
use of com.gargoylesoftware.css.dom.CSSRuleListImpl in project htmlunit by HtmlUnit.
the class CSSStyleSheet method index.
private void index(final CSSStyleSheetImpl.CSSStyleSheetRuleIndex index, final CSSRuleListImpl ruleList, final Set<String> alreadyProcessing) {
for (final AbstractCSSRuleImpl rule : ruleList.getRules()) {
if (rule instanceof CSSStyleRuleImpl) {
final CSSStyleRuleImpl styleRule = (CSSStyleRuleImpl) rule;
final SelectorList selectors = styleRule.getSelectors();
for (final Selector selector : selectors) {
final SimpleSelector simpleSel = selector.getSimpleSelector();
if (SelectorType.ELEMENT_NODE_SELECTOR == simpleSel.getSelectorType()) {
final ElementSelector es = (ElementSelector) simpleSel;
boolean wasClass = false;
final List<Condition> conds = es.getConditions();
if (conds != null && conds.size() == 1) {
final Condition c = conds.get(0);
if (ConditionType.CLASS_CONDITION == c.getConditionType()) {
index.addClassSelector(es, c.getValue(), selector, styleRule);
wasClass = true;
}
}
if (!wasClass) {
index.addElementSelector(es, selector, styleRule);
}
} else {
index.addOtherSelector(selector, styleRule);
}
}
} else if (rule instanceof CSSImportRuleImpl) {
final CSSImportRuleImpl importRule = (CSSImportRuleImpl) rule;
final CSSStyleSheet sheet = getImportedStyleSheet(importRule);
if (!alreadyProcessing.contains(sheet.getUri())) {
final CSSRuleListImpl sheetRuleList = sheet.getWrappedSheet().getCssRules();
alreadyProcessing.add(sheet.getUri());
final MediaListImpl mediaList = importRule.getMedia();
if (mediaList.getLength() == 0 && index.getMediaList().getLength() == 0) {
index(index, sheetRuleList, alreadyProcessing);
} else {
index(index.addMedia(mediaList), sheetRuleList, alreadyProcessing);
}
}
} else if (rule instanceof CSSMediaRuleImpl) {
final CSSMediaRuleImpl mediaRule = (CSSMediaRuleImpl) rule;
final MediaListImpl mediaList = mediaRule.getMediaList();
if (mediaList.getLength() == 0 && index.getMediaList().getLength() == 0) {
index(index, mediaRule.getCssRules(), alreadyProcessing);
} else {
index(index.addMedia(mediaList), mediaRule.getCssRules(), alreadyProcessing);
}
}
}
}
use of com.gargoylesoftware.css.dom.CSSRuleListImpl in project htmlunit by HtmlUnit.
the class CSSGroupingRule method refreshCssRules.
private void refreshCssRules() {
if (cssRules_ == null) {
return;
}
cssRules_.clearRules();
cssRulesIndexFix_.clear();
final CSSRuleListImpl ruleList = getGroupingRule().getCssRules();
final List<AbstractCSSRuleImpl> rules = ruleList.getRules();
int pos = 0;
for (final AbstractCSSRuleImpl rule : rules) {
if (rule instanceof CSSCharsetRuleImpl) {
cssRulesIndexFix_.add(pos);
continue;
}
final CSSRule cssRule = CSSRule.create(getParentStyleSheet(), rule);
if (null == cssRule) {
cssRulesIndexFix_.add(pos);
} else {
cssRules_.addRule(cssRule);
}
pos++;
}
}
use of com.gargoylesoftware.css.dom.CSSRuleListImpl in project htmlunit by HtmlUnit.
the class CSSStyleSheet method getRuleIndex.
private CSSStyleSheetImpl.CSSStyleSheetRuleIndex getRuleIndex() {
final CSSStyleSheetImpl styleSheet = getWrappedSheet();
CSSStyleSheetImpl.CSSStyleSheetRuleIndex index = styleSheet.getRuleIndex();
if (index == null) {
index = new CSSStyleSheetImpl.CSSStyleSheetRuleIndex();
final CSSRuleListImpl ruleList = styleSheet.getCssRules();
index(index, ruleList, new HashSet<>());
styleSheet.setRuleIndex(index);
}
return index;
}
Aggregations