*/
private boolean vetLinkToHistorySensitiveSimpleSelector(
CssTree.SimpleSelector selector) {
if (selector.children().isEmpty()) { return false; }
if (!containsLinkPseudoClass(selector)) { return false; }
CssTree firstChild = selector.children().get(0);
if (firstChild instanceof CssTree.WildcardElement) {
// "*#foo:visited" --> "a#foo:visited"
selector.replaceChild(
new CssTree.IdentLiteral(
firstChild.getFilePosition(), HTML_ANCHOR.toString()),
firstChild);
return true;
} else if (firstChild instanceof CssTree.IdentLiteral) {
// "a#foo:visited" is legal; "p#foo:visited" is not
String value = ((CssTree.IdentLiteral) firstChild).getValue();
if (!HTML_ANCHOR.equals(
ElKey.forElement(Namespaces.HTML_DEFAULT, value))) {
mq.addMessage(
PluginMessageType.CSS_LINK_PSEUDO_SELECTOR_NOT_ALLOWED_ON_NONANCHOR,
firstChild.getFilePosition());
}
return false;
} else {
// "#foo:visited" --> "a#foo:visited"
selector.insertBefore(
new CssTree.IdentLiteral(
firstChild.getFilePosition(), HTML_ANCHOR.toString()),
firstChild);
return true;
}
}