gecko-dev/dom/svg/SVGAElement.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

270 строки
8.9 KiB
C++
Исходник Обычный вид История

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
2012-05-21 15:12:37 +04:00
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "mozilla/dom/SVGAElement.h"
#include "mozilla/EventDispatcher.h"
#include "mozilla/dom/DocumentInlines.h"
#include "mozilla/dom/SVGAElementBinding.h"
#include "mozilla/FocusModel.h"
#include "nsCOMPtr.h"
#include "nsContentUtils.h"
#include "nsGkAtoms.h"
#include "nsIContentInlines.h"
#include "nsIURI.h"
NS_IMPL_NS_NEW_SVG_ELEMENT(A)
namespace mozilla::dom {
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv The only manual changes here are to BindingUtils.h, BindingUtils.cpp, Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp, dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp, Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp, Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The rest of this diff was generated by running the following commands: find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g' find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
JSObject* SVGAElement::WrapNode(JSContext* aCx,
JS::Handle<JSObject*> aGivenProto) {
return SVGAElement_Binding::Wrap(aCx, this, aGivenProto);
}
SVGElement::StringInfo SVGAElement::sStringInfo[3] = {
{nsGkAtoms::href, kNameSpaceID_None, true},
{nsGkAtoms::href, kNameSpaceID_XLink, true},
{nsGkAtoms::target, kNameSpaceID_None, true}};
//----------------------------------------------------------------------
// nsISupports methods
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(SVGAElement)
NS_INTERFACE_MAP_ENTRY(Link)
NS_INTERFACE_MAP_END_INHERITING(SVGAElementBase)
NS_IMPL_CYCLE_COLLECTION_INHERITED(SVGAElement, SVGAElementBase, mRelList)
NS_IMPL_ADDREF_INHERITED(SVGAElement, SVGAElementBase)
NS_IMPL_RELEASE_INHERITED(SVGAElement, SVGAElementBase)
//----------------------------------------------------------------------
// Implementation
SVGAElement::SVGAElement(already_AddRefed<mozilla::dom::NodeInfo>&& aNodeInfo)
: SVGAElementBase(std::move(aNodeInfo)), Link(this) {}
already_AddRefed<DOMSVGAnimatedString> SVGAElement::Href() {
return mStringAttributes[HREF].IsExplicitlySet()
? mStringAttributes[HREF].ToDOMAnimatedString(this)
: mStringAttributes[XLINK_HREF].ToDOMAnimatedString(this);
}
//----------------------------------------------------------------------
// nsINode methods
void SVGAElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
Element::GetEventTargetParent(aVisitor);
GetEventTargetParentForLinks(aVisitor);
}
nsresult SVGAElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
return PostHandleEventForLinks(aVisitor);
}
NS_IMPL_ELEMENT_CLONE_WITH_INIT(SVGAElement)
//----------------------------------------------------------------------
already_AddRefed<DOMSVGAnimatedString> SVGAElement::Target() {
return mStringAttributes[TARGET].ToDOMAnimatedString(this);
}
void SVGAElement::GetDownload(nsAString& aDownload) {
GetAttr(nsGkAtoms::download, aDownload);
}
void SVGAElement::SetDownload(const nsAString& aDownload, ErrorResult& rv) {
SetAttr(nsGkAtoms::download, aDownload, rv);
}
void SVGAElement::GetPing(nsAString& aPing) { GetAttr(nsGkAtoms::ping, aPing); }
void SVGAElement::SetPing(const nsAString& aPing, ErrorResult& rv) {
SetAttr(nsGkAtoms::ping, aPing, rv);
}
void SVGAElement::GetRel(nsAString& aRel) { GetAttr(nsGkAtoms::rel, aRel); }
void SVGAElement::SetRel(const nsAString& aRel, ErrorResult& rv) {
SetAttr(nsGkAtoms::rel, aRel, rv);
}
void SVGAElement::GetReferrerPolicy(nsAString& aPolicy) {
GetEnumAttr(nsGkAtoms::referrerpolicy, "", aPolicy);
}
void SVGAElement::SetReferrerPolicy(const nsAString& aPolicy,
mozilla::ErrorResult& rv) {
SetAttr(nsGkAtoms::referrerpolicy, aPolicy, rv);
}
nsDOMTokenList* SVGAElement::RelList() {
if (!mRelList) {
mRelList =
new nsDOMTokenList(this, nsGkAtoms::rel, sAnchorAndFormRelValues);
}
return mRelList;
}
void SVGAElement::GetHreflang(nsAString& aHreflang) {
GetAttr(nsGkAtoms::hreflang, aHreflang);
}
void SVGAElement::SetHreflang(const nsAString& aHreflang,
mozilla::ErrorResult& rv) {
SetAttr(nsGkAtoms::hreflang, aHreflang, rv);
}
void SVGAElement::GetType(nsAString& aType) { GetAttr(nsGkAtoms::type, aType); }
void SVGAElement::SetType(const nsAString& aType, mozilla::ErrorResult& rv) {
SetAttr(nsGkAtoms::type, aType, rv);
}
void SVGAElement::GetText(nsAString& aText, mozilla::ErrorResult& rv) const {
if (NS_WARN_IF(
!nsContentUtils::GetNodeTextContent(this, true, aText, fallible))) {
rv.Throw(NS_ERROR_OUT_OF_MEMORY);
}
}
void SVGAElement::SetText(const nsAString& aText, mozilla::ErrorResult& rv) {
rv = nsContentUtils::SetNodeTextContent(this, aText, false);
}
//----------------------------------------------------------------------
// nsIContent methods
Bug 1555216 - Change the signature of BindToTree to be (BindContext&, nsINode& aParentNode). r=bzbarsky BindContext was going to have way more information at first, but then I realized that most of the things I wanted to know were basically a flag away using the parent node. Still I think it's worth it, now experimenting with BindToTree will only mean adding a field to a struct that's included from a couple cpp files, instead of a massive pain. I also think this is clearer, and doing this highlights quite a few inconsistencies in our code which I've left untouched, but commented with FIXMEs. Steps are: $ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsresult BindToTree(Document\* aDocument, nsIContent\* aParent,#nsresult BindToTree(BindContext\&, nsINode\& aParent)#g' $file; done $ for file in $(rg 'nsresult BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's# nsIContent\* aBindingParent) override#override#g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(Document\* aDocument, nsIContent\* aParent,#::BindToTree(BindContext\& aContext, nsINode\& aParent)#g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#nsIContent\* aBindingParent)##g' $file; done $ for file in $(rg '::BindToTree\(' | cut -d : -f 1 | sort | uniq); do sed -i 's#::BindToTree(aDocument, aParent, aBindingParent)#::BindToTree(aContext, aParent)#g' $file; done $ ./mach clang-format Then manual fixups. Depends on D32948 Differential Revision: https://phabricator.services.mozilla.com/D32949
2019-05-29 07:27:04 +03:00
nsresult SVGAElement::BindToTree(BindContext& aContext, nsINode& aParent) {
nsresult rv = SVGAElementBase::BindToTree(aContext, aParent);
NS_ENSURE_SUCCESS(rv, rv);
Link::BindToTree(aContext);
return NS_OK;
}
void SVGAElement::UnbindFromTree(UnbindContext& aContext) {
SVGAElementBase::UnbindFromTree(aContext);
// Without removing the link state we risk a dangling pointer
// in the mStyledLinks hashtable
Link::UnbindFromTree();
}
int32_t SVGAElement::TabIndexDefault() { return 0; }
Focusable SVGAElement::IsFocusableWithoutStyle(IsFocusableFlags) {
Focusable result;
if (IsSVGFocusable(&result.mFocusable, &result.mTabIndex)) {
return result;
}
if (!OwnerDoc()->LinkHandlingEnabled()) {
return {};
}
// Links that are in an editable region should never be focusable, even if
// they are in a contenteditable="false" region.
if (nsContentUtils::IsNodeInEditableRegion(this)) {
return {};
}
if (GetTabIndexAttrValue().isNothing()) {
// check whether we're actually a link
if (!IsLink()) {
// Not tabbable or focusable without href (bug 17605), unless
// forced to be via presence of nonnegative tabindex attribute
return {};
}
}
if (!FocusModel::IsTabFocusable(TabFocusableType::Links)) {
result.mTabIndex = -1;
}
return result;
}
bool SVGAElement::HasHref() const {
// Currently our SMIL implementation does not modify the DOM attributes. Once
// we implement the SVG 2 SMIL behaviour this can be removed.
return mStringAttributes[HREF].IsExplicitlySet() ||
mStringAttributes[XLINK_HREF].IsExplicitlySet();
}
already_AddRefed<nsIURI> SVGAElement::GetHrefURI() const {
// Optimization: check for href first for early return
bool useBareHref = mStringAttributes[HREF].IsExplicitlySet();
if (useBareHref || mStringAttributes[XLINK_HREF].IsExplicitlySet()) {
// Get absolute URI
nsAutoString str;
const uint8_t idx = useBareHref ? HREF : XLINK_HREF;
mStringAttributes[idx].GetAnimValue(str, this);
nsCOMPtr<nsIURI> uri;
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(uri), str,
OwnerDoc(), GetBaseURI());
return uri.forget();
}
return nullptr;
}
void SVGAElement::GetLinkTargetImpl(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;
}
Document* ownerDoc = OwnerDoc();
if (ownerDoc) {
ownerDoc->GetBaseTarget(aTarget);
}
}
}
void SVGAElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
const nsAttrValue* aValue,
const nsAttrValue* aOldValue,
nsIPrincipal* aMaybeScriptedPrincipal,
bool aNotify) {
if (aName == nsGkAtoms::href && (aNameSpaceID == kNameSpaceID_XLink ||
aNameSpaceID == kNameSpaceID_None)) {
// We can't assume that null aValue means we no longer have an href, because
// we could be unsetting xlink:href but still have a null-namespace href, or
// vice versa. But we can fast-path the case when we _do_ have a new value.
Link::ResetLinkState(aNotify, aValue || Link::ElementHasHref());
}
return SVGAElementBase::AfterSetAttr(aNameSpaceID, aName, aValue, aOldValue,
aMaybeScriptedPrincipal, aNotify);
}
//----------------------------------------------------------------------
// SVGElement methods
SVGElement::StringAttributesInfo SVGAElement::GetStringInfo() {
return StringAttributesInfo(mStringAttributes, sStringInfo,
ArrayLength(sStringInfo));
}
void SVGAElement::DidAnimateAttribute(int32_t aNameSpaceID,
nsAtom* aAttribute) {
if ((aNameSpaceID == kNameSpaceID_None ||
aNameSpaceID == kNameSpaceID_XLink) &&
aAttribute == nsGkAtoms::href) {
Link::ResetLinkState(true, Link::ElementHasHref());
}
SVGAElementBase::DidAnimateAttribute(aNameSpaceID, aAttribute);
}
} // namespace mozilla::dom