bool SVGAElement::IsLink(nsIURI** aURI) const { // To be a clickable XLink for styling and interaction purposes, we require: // // xlink:href - must be set // xlink:type - must be unset or set to "" or set to "simple" // xlink:show - must be unset or set to "", "new" or "replace" // xlink:actuate - must be unset or set to "" or "onRequest" // // For any other values, we're either not a *clickable* XLink, or the end // result is poorly specified. Either way, we return false. static nsIContent::AttrValuesArray sTypeVals[] = { &nsGkAtoms::_empty, &nsGkAtoms::simple, nullptr }; static nsIContent::AttrValuesArray sShowVals[] = { &nsGkAtoms::_empty, &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr }; static nsIContent::AttrValuesArray sActuateVals[] = { &nsGkAtoms::_empty, &nsGkAtoms::onRequest, nullptr }; // Optimization: check for href first for early return bool useXLink = !HasAttr(kNameSpaceID_None, nsGkAtoms::href); const nsAttrValue* href = useXLink ? mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink) : mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_None); if (href && FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::type, sTypeVals, eCaseMatters) != nsIContent::ATTR_VALUE_NO_MATCH && FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show, sShowVals, eCaseMatters) != nsIContent::ATTR_VALUE_NO_MATCH && FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate, sActuateVals, eCaseMatters) != nsIContent::ATTR_VALUE_NO_MATCH) { nsCOMPtr<nsIURI> baseURI = GetBaseURI(); // Get absolute URI nsAutoString str; const uint8_t idx = useXLink ? XLINK_HREF : HREF; mStringAttributes[idx].GetAnimValue(str, this); nsContentUtils::NewURIWithDocumentCharset(aURI, str, OwnerDoc(), baseURI); // must promise out param is non-null if we return true return !!*aURI; } *aURI = nullptr; return false; }
void HTMLLinkElement::CreateAndDispatchEvent(nsIDocument* aDoc, const nsAString& aEventName) { if (!aDoc) return; // In the unlikely case that both rev is specified *and* rel=stylesheet, // this code will cause the event to fire, on the principle that maybe the // page really does want to specify that its author is a stylesheet. Since // this should never actually happen and the performance hit is minimal, // doing the "right" thing costs virtually nothing here, even if it doesn't // make much sense. static nsIContent::AttrValuesArray strings[] = {&nsGkAtoms::_empty, &nsGkAtoms::stylesheet, nullptr}; if (!nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None, nsGkAtoms::rev) && FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::rel, strings, eIgnoreCase) != ATTR_VALUE_NO_MATCH) return; nsRefPtr<AsyncEventDispatcher> asyncDispatcher = new AsyncEventDispatcher(this, aEventName, true, true); // Always run async in order to avoid running script when the content // sink isn't expecting it. asyncDispatcher->PostDOMEvent(); }
PRBool nsXMLElement::IsLink(nsIURI** aURI) const { NS_PRECONDITION(aURI, "Must provide aURI out param"); // To be an XLink for styling and interaction purposes, we require: // // xlink:href - must be set // xlink:type - must be set to "simple" // xlink:_moz_target - must be set, OR // xlink:show - must be unset or set to "", "new" or "replace" // xlink:actuate - must be unset or set to "" or "onRequest" // // For any other values, we're either not a *clickable* XLink, or the end // result is poorly specified. Either way, we return PR_FALSE. static nsIContent::AttrValuesArray sShowVals[] = { &nsGkAtoms::_empty, &nsGkAtoms::_new, &nsGkAtoms::replace, nsnull }; static nsIContent::AttrValuesArray sActuateVals[] = { &nsGkAtoms::_empty, &nsGkAtoms::onRequest, nsnull }; // Optimization: check for href first for early return const nsAttrValue* href = mAttrsAndChildren.GetAttr(nsGkAtoms::href, kNameSpaceID_XLink); if (href && AttrValueIs(kNameSpaceID_XLink, nsGkAtoms::type, nsGkAtoms::simple, eCaseMatters) && (HasAttr(kNameSpaceID_XLink, nsGkAtoms::_moz_target) || FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show, sShowVals, eCaseMatters) != nsIContent::ATTR_VALUE_NO_MATCH) && FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::actuate, sActuateVals, eCaseMatters) != nsIContent::ATTR_VALUE_NO_MATCH) { // Get absolute URI nsCOMPtr<nsIURI> baseURI = GetBaseURI(); nsContentUtils::NewURIWithDocumentCharset(aURI, href->GetStringValue(), GetOwnerDoc(), baseURI); return !!*aURI; // must promise out param is non-null if we return true } *aURI = nsnull; return PR_FALSE; }
void SVGAElement::GetLinkTarget(nsAString& aTarget) { mStringAttributes[TARGET].GetAnimValue(aTarget, this); if (aTarget.IsEmpty()) { static Element::AttrValuesArray sShowVals[] = { &nsGkAtoms::_new, &nsGkAtoms::replace, nullptr }; switch (FindAttrValueIn(kNameSpaceID_XLink, nsGkAtoms::show, sShowVals, eCaseMatters)) { case 0: aTarget.AssignLiteral("_blank"); return; case 1: return; } nsIDocument* ownerDoc = OwnerDoc(); if (ownerDoc) { ownerDoc->GetBaseTarget(aTarget); } } }