Commit 2d0a0721 authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1723921 - Cleanup nsComputedDOMStyle and related APIs. r=layout-reviewers,jfkthame

This will make implementing the new behavior behind a pref
really straight-forward, and is generally nicer.

Depends on D121858

Differential Revision: https://phabricator.services.mozilla.com/D121705
parent 96a00ac8
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -15,8 +15,7 @@ using namespace mozilla;
using namespace mozilla::a11y;

StyleInfo::StyleInfo(dom::Element* aElement) : mElement(aElement) {
  mComputedStyle =
      nsComputedDOMStyle::GetComputedStyleNoFlush(aElement, nullptr);
  mComputedStyle = nsComputedDOMStyle::GetComputedStyleNoFlush(aElement);
}

already_AddRefed<nsAtom> StyleInfo::Display() {
+14 −21
Original line number Diff line number Diff line
@@ -782,9 +782,9 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
    return result;
  }

  RefPtr<nsAtom> pseudoAtom =
      nsCSSPseudoElements::GetPseudoAtom(options.mPseudoElement);
  if (!pseudoAtom) {
  Maybe<PseudoStyleType> pseudoType =
      nsCSSPseudoElements::GetPseudoType(options.mPseudoElement);
  if (!pseudoType) {
    // Per the spec, we throw SyntaxError for syntactically invalid pseudos.
    aRv.ThrowSyntaxError(
        nsPrintfCString("'%s' is a syntactically invalid pseudo-element.",
@@ -792,8 +792,7 @@ static KeyframeEffectParams KeyframeEffectParamsFromUnion(
    return result;
  }

  result.mPseudoType = nsCSSPseudoElements::GetPseudoType(
      pseudoAtom, CSSEnabledState::ForAllContent);
  result.mPseudoType = *pseudoType;
  if (!IsSupportedPseudoForWebAnimation(result.mPseudoType)) {
    // Per the spec, we throw SyntaxError for unsupported pseudos.
    aRv.ThrowSyntaxError(
@@ -1015,16 +1014,13 @@ already_AddRefed<ComputedStyle> KeyframeEffect::GetTargetComputedStyle(
  MOZ_ASSERT(mTarget,
             "Should only have a document when we have a target element");

  nsAtom* pseudo = PseudoStyle::IsPseudoElement(mTarget.mPseudoType)
                       ? nsCSSPseudoElements::GetPseudoAtom(mTarget.mPseudoType)
                       : nullptr;

  OwningAnimationTarget kungfuDeathGrip(mTarget.mElement, mTarget.mPseudoType);

  return aFlushType == Flush::Style
             ? nsComputedDOMStyle::GetComputedStyle(mTarget.mElement, pseudo)
             ? nsComputedDOMStyle::GetComputedStyle(mTarget.mElement,
                                                    mTarget.mPseudoType)
             : nsComputedDOMStyle::GetComputedStyleNoFlush(mTarget.mElement,
                                                           pseudo);
                                                           mTarget.mPseudoType);
}

#ifdef DEBUG
@@ -1088,17 +1084,16 @@ already_AddRefed<KeyframeEffect> KeyframeEffect::Constructor(

void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
                                      ErrorResult& aRv) {
  PseudoStyleType pseudoType = PseudoStyleType::NotPseudo;
  if (DOMStringIsNull(aPseudoElement)) {
    UpdateTarget(mTarget.mElement, pseudoType);
    UpdateTarget(mTarget.mElement, PseudoStyleType::NotPseudo);
    return;
  }

  // Note: GetPseudoAtom() also returns nullptr for the null string,
  // Note: GetPseudoType() returns Some(NotPseudo) for the null string,
  // so we handle null case before this.
  RefPtr<nsAtom> pseudoAtom =
      nsCSSPseudoElements::GetPseudoAtom(aPseudoElement);
  if (!pseudoAtom) {
  Maybe<PseudoStyleType> pseudoType =
      nsCSSPseudoElements::GetPseudoType(aPseudoElement);
  if (!pseudoType || *pseudoType == PseudoStyleType::NotPseudo) {
    // Per the spec, we throw SyntaxError for syntactically invalid pseudos.
    aRv.ThrowSyntaxError(
        nsPrintfCString("'%s' is a syntactically invalid pseudo-element.",
@@ -1106,9 +1101,7 @@ void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
    return;
  }

  pseudoType = nsCSSPseudoElements::GetPseudoType(
      pseudoAtom, CSSEnabledState::ForAllContent);
  if (!IsSupportedPseudoForWebAnimation(pseudoType)) {
  if (!IsSupportedPseudoForWebAnimation(*pseudoType)) {
    // Per the spec, we throw SyntaxError for unsupported pseudos.
    aRv.ThrowSyntaxError(
        nsPrintfCString("'%s' is an unsupported pseudo-element.",
@@ -1116,7 +1109,7 @@ void KeyframeEffect::SetPseudoElement(const nsAString& aPseudoElement,
    return;
  }

  UpdateTarget(mTarget.mElement, pseudoType);
  UpdateTarget(mTarget.mElement, *pseudoType);
}

static void CreatePropertyValue(
+2 −1
Original line number Diff line number Diff line
@@ -192,7 +192,8 @@ void AnonymousContent::GetComputedStylePropertyValue(
  }

  RefPtr<nsComputedDOMStyle> cs = new nsComputedDOMStyle(
      element, u""_ns, element->OwnerDoc(), nsComputedDOMStyle::eAll);
      element, PseudoStyleType::NotPseudo, element->OwnerDoc(),
      nsComputedDOMStyle::StyleType::All);
  aRv = cs->GetPropertyValue(aPropertyName, aResult);
}

+6 −18
Original line number Diff line number Diff line
@@ -8227,20 +8227,6 @@ bool IsLowercaseASCII(const nsAString& aValue) {
  return true;
}
// We only support pseudo-elements with two colons in this function.
static PseudoStyleType GetPseudoElementType(const nsString& aString,
                                            ErrorResult& aRv) {
  MOZ_ASSERT(!aString.IsEmpty(),
             "GetPseudoElementType aString should be non-null");
  if (aString.Length() <= 2 || aString[0] != ':' || aString[1] != ':') {
    aRv.Throw(NS_ERROR_DOM_SYNTAX_ERR);
    return PseudoStyleType::NotPseudo;
  }
  RefPtr<nsAtom> pseudo = NS_Atomize(Substring(aString, 1));
  return nsCSSPseudoElements::GetPseudoType(pseudo,
                                            CSSEnabledState::InUASheets);
}
already_AddRefed<Element> Document::CreateElement(
    const nsAString& aTagName, const ElementCreationOptionsOrString& aOptions,
    ErrorResult& rv) {
@@ -8268,12 +8254,14 @@ already_AddRefed<Element> Document::CreateElement(
    // Check 'pseudo' and throw an exception if it's not one allowed
    // with CSS_PSEUDO_ELEMENT_IS_JS_CREATED_NAC.
    if (options.mPseudo.WasPassed()) {
      pseudoType = GetPseudoElementType(options.mPseudo.Value(), rv);
      if (rv.Failed() || pseudoType == PseudoStyleType::NotPseudo ||
          !nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(pseudoType)) {
        rv.Throw(NS_ERROR_DOM_NOT_SUPPORTED_ERR);
      Maybe<PseudoStyleType> type =
          nsCSSPseudoElements::GetPseudoType(options.mPseudo.Value());
      if (!type || *type == PseudoStyleType::NotPseudo ||
          !nsCSSPseudoElements::PseudoElementIsJSCreatedNAC(*type)) {
        rv.ThrowNotSupportedError("Invalid pseudo-element");
        return nullptr;
      }
      pseudoType = *type;
    }
  }
+6 −2
Original line number Diff line number Diff line
@@ -3153,9 +3153,13 @@ nsDOMWindowUtils::GetUnanimatedComputedStyle(Element* aElement,
    return NS_ERROR_FAILURE;
  }

  RefPtr<nsAtom> pseudo = nsCSSPseudoElements::GetPseudoAtom(aPseudoElement);
  Maybe<PseudoStyleType> pseudo =
      nsCSSPseudoElements::GetPseudoType(aPseudoElement);
  if (!pseudo) {
    return NS_ERROR_FAILURE;
  }
  RefPtr<ComputedStyle> computedStyle =
      nsComputedDOMStyle::GetUnanimatedComputedStyleNoFlush(aElement, pseudo);
      nsComputedDOMStyle::GetUnanimatedComputedStyleNoFlush(aElement, *pseudo);
  if (!computedStyle) {
    return NS_ERROR_FAILURE;
  }
Loading