Commit 37716ddb authored by Emilio Cobos Álvarez's avatar Emilio Cobos Álvarez
Browse files

Bug 1763644 - Add basic @container rule parsing and boilerplate....

Bug 1763644 - Add basic @container rule parsing and boilerplate. r=firefox-style-system-reviewers,layout-reviewers,boris

For now parse a MediaFeatureCondition. That needs being made more
specific, but that is probably worth its own patch.

Differential Revision: https://phabricator.services.mozilla.com/D143192
parent 3e31b63b
Loading
Loading
Loading
Loading
+14 −0
Original line number Diff line number Diff line
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/.
 *
 * The origin of this IDL file is
 * https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface
 */

// https://drafts.csswg.org/css-contain-3/#the-csscontainerrule-interface
[Exposed=Window, Pref="layout.css.container-queries.enabled"]
interface CSSContainerRule : CSSConditionRule {
};
+1 −0
Original line number Diff line number Diff line
@@ -475,6 +475,7 @@ WEBIDL_FILES = [
    "CSS.webidl",
    "CSSAnimation.webidl",
    "CSSConditionRule.webidl",
    "CSSContainerRule.webidl",
    "CSSCounterStyleRule.webidl",
    "CSSFontFaceRule.webidl",
    "CSSFontFeatureValuesRule.webidl",
+2 −0
Original line number Diff line number Diff line
@@ -86,6 +86,7 @@ void ServoStyleRuleMap::RuleRemoved(StyleSheet& aStyleSheet,
    case StyleCssRuleType::Media:
    case StyleCssRuleType::Supports:
    case StyleCssRuleType::LayerBlock:
    case StyleCssRuleType::Container:
    case StyleCssRuleType::Document: {
      // See the comment in StyleSheetRemoved.
      mTable.Clear();
@@ -122,6 +123,7 @@ void ServoStyleRuleMap::FillTableFromRule(css::Rule& aRule) {
    case StyleCssRuleType::LayerBlock:
    case StyleCssRuleType::Media:
    case StyleCssRuleType::Supports:
    case StyleCssRuleType::Container:
    case StyleCssRuleType::Document: {
      auto& rule = static_cast<css::GroupRule&>(aRule);
      if (ServoCSSRuleList* ruleList = rule.GetCssRules()) {
+83 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/CSSContainerRule.h"

#include "mozilla/css/GroupRule.h"
#include "mozilla/dom/CSSContainerRuleBinding.h"
#include "mozilla/ServoBindings.h"

using namespace mozilla::css;

namespace mozilla::dom {

CSSContainerRule::CSSContainerRule(RefPtr<RawServoContainerRule> aRawRule,
                                   StyleSheet* aSheet, css::Rule* aParentRule,
                                   uint32_t aLine, uint32_t aColumn)
    : css::ConditionRule(Servo_ContainerRule_GetRules(aRawRule).Consume(),
                         aSheet, aParentRule, aLine, aColumn),
      mRawRule(std::move(aRawRule)) {}

CSSContainerRule::~CSSContainerRule() = default;

NS_IMPL_ADDREF_INHERITED(CSSContainerRule, ConditionRule)
NS_IMPL_RELEASE_INHERITED(CSSContainerRule, ConditionRule)

// QueryInterface implementation for ContainerRule
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(CSSContainerRule)
NS_INTERFACE_MAP_END_INHERITING(ConditionRule)

#ifdef DEBUG
/* virtual */
void CSSContainerRule::List(FILE* out, int32_t aIndent) const {
  nsAutoCString str;
  for (int32_t i = 0; i < aIndent; i++) {
    str.AppendLiteral("  ");
  }
  Servo_ContainerRule_Debug(mRawRule, &str);
  fprintf_stderr(out, "%s\n", str.get());
}
#endif

StyleCssRuleType CSSContainerRule::Type() const {
  return StyleCssRuleType::Container;
}

void CSSContainerRule::GetConditionText(nsACString& aConditionText) {
  Servo_ContainerRule_GetConditionText(mRawRule, &aConditionText);
}

void CSSContainerRule::SetConditionText(const nsACString& aConditionText, ErrorResult&) {
  // FIXME: This shouldn't be here, CSSConditionRule.conditionText should be
  // readonly as per:
  // https://github.com/w3c/csswg-drafts/issues/6819#issuecomment-1016695585
}

/* virtual */
void CSSContainerRule::GetCssText(nsACString& aCssText) const {
  Servo_ContainerRule_GetCssText(mRawRule, &aCssText);
}

void CSSContainerRule::SetRawAfterClone(RefPtr<RawServoContainerRule> aRaw) {
  mRawRule = std::move(aRaw);

  css::ConditionRule::SetRawAfterClone(
      Servo_ContainerRule_GetRules(mRawRule).Consume());
}

/* virtual */
size_t CSSContainerRule::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
  // TODO Implement this!
  return aMallocSizeOf(this);
}

/* virtual */
JSObject* CSSContainerRule::WrapObject(JSContext* aCx,
                                       JS::Handle<JSObject*> aGivenProto) {
  return CSSContainerRule_Binding::Wrap(aCx, this, aGivenProto);
}

}  // namespace mozilla::dom
+49 −0
Original line number Diff line number Diff line
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */

#ifndef mozilla_dom_CSSContainerRule_h
#define mozilla_dom_CSSContainerRule_h

#include "mozilla/css/GroupRule.h"
#include "mozilla/ServoBindingTypes.h"

namespace mozilla::dom {

class CSSContainerRule final : public css::ConditionRule {
 public:
  CSSContainerRule(RefPtr<RawServoContainerRule> aRawRule, StyleSheet* aSheet,
                   css::Rule* aParentRule, uint32_t aLine, uint32_t aColumn);

  NS_DECL_ISUPPORTS_INHERITED

#ifdef DEBUG
  void List(FILE* out = stdout, int32_t aIndent = 0) const final;
#endif

  RawServoContainerRule* Raw() const { return mRawRule; }
  void SetRawAfterClone(RefPtr<RawServoContainerRule>);

  // WebIDL interface
  StyleCssRuleType Type() const override;
  // WebIDL interface
  void GetCssText(nsACString& aCssText) const final;
  void GetConditionText(nsACString& aConditionText) final;
  void SetConditionText(const nsACString& aConditionText, ErrorResult&) final;

  size_t SizeOfIncludingThis(MallocSizeOf) const override;

  JSObject* WrapObject(JSContext* aCx,
                       JS::Handle<JSObject*> aGivenProto) override;

 private:
  virtual ~CSSContainerRule();

  RefPtr<RawServoContainerRule> mRawRule;
};

}  // namespace mozilla::dom

#endif  // mozilla_dom_CSSContainerRule_h
Loading