layout/style/GroupRule.cpp
author Xianzhu Wang <wangxianzhu@chromium.org>
Tue, 05 Mar 2019 12:18:01 +0000
changeset 464575 4325ba7b38576495a78289c2a8f4dff391922e66
parent 461895 e0fb4657355d4d8052bff3f1e8baac265b5efef7
child 471711 ee37c856a47e46f3f548cef19d64b581119188fb
permissions -rw-r--r--
Bug 1529059 [wpt PR 15420] - [BlinkGenPropertyTrees] Initiailize double_sided of synthetic effect, a=testonly Automatic update from web-platform-tests [BlinkGenPropertyTrees] Initiailize double_sided of synthetic effect Previously synthetic effects always had double_sided==false, causing the layer disappear when the backface was facing forward. Bug: 928190 Change-Id: I35534b40346d5c5918bc99c00a4ca6b4e3b68796 Reviewed-on: https://chromium-review.googlesource.com/c/1475815 Reviewed-by: Philip Rogers <pdr@chromium.org> Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org> Cr-Commit-Position: refs/heads/master@{#632764} -- wpt-commits: a89467050deaf1dcbd9140a2f0670b1b85e518ee wpt-pr: 15420

/* -*- 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/. */

/*
 * internal interface representing CSS style rules that contain other
 * rules, such as @media rules
 */

#include "mozilla/css/GroupRule.h"

#include "mozilla/dom/CSSRuleList.h"

using namespace mozilla::dom;

namespace mozilla {
namespace css {

GroupRule::GroupRule(already_AddRefed<ServoCssRules> aRules, StyleSheet* aSheet,
                     Rule* aParentRule, uint32_t aLineNumber,
                     uint32_t aColumnNumber)
    : Rule(aSheet, aParentRule, aLineNumber, aColumnNumber),
      mRuleList(new ServoCSSRuleList(std::move(aRules), aSheet, this)) {}

GroupRule::~GroupRule() {
  MOZ_ASSERT(!mSheet, "SetStyleSheet should have been called");
  if (mRuleList) {
    mRuleList->DropReferences();
  }
}

NS_IMPL_ADDREF_INHERITED(GroupRule, Rule)
NS_IMPL_RELEASE_INHERITED(GroupRule, Rule)

NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule)
NS_INTERFACE_MAP_END_INHERITING(Rule)

bool GroupRule::IsCCLeaf() const {
  // Let's not worry for now about sorting out whether we're a leaf or not.
  return false;
}

NS_IMPL_CYCLE_COLLECTION_CLASS(GroupRule)

NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(GroupRule, Rule)
  if (tmp->mRuleList) {
    // If tmp has a style sheet (which can happen if it gets unlinked
    // earlier than its owning style sheet), then we need to null out the
    // style sheet pointer on descendants now, before we clear mRuleList.
    tmp->mRuleList->DropReferences();
    tmp->mRuleList = nullptr;
  }
NS_IMPL_CYCLE_COLLECTION_UNLINK_END

NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(GroupRule, Rule)
  ImplCycleCollectionTraverse(cb, tmp->mRuleList, "mRuleList");
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END

#ifdef DEBUG
void GroupRule::List(FILE* out, int32_t aIndent) const {
  // TODO list something reasonable?
}
#endif

/* virtual */
void GroupRule::DropSheetReference() {
  if (mRuleList) {
    mRuleList->DropSheetReference();
  }
  Rule::DropSheetReference();
}

uint32_t GroupRule::InsertRule(const nsAString& aRule, uint32_t aIndex,
                               ErrorResult& aRv) {
  StyleSheet* sheet = GetStyleSheet();
  if (NS_WARN_IF(!sheet)) {
    aRv.Throw(NS_ERROR_FAILURE);
    return 0;
  }

  uint32_t count = StyleRuleCount();
  if (aIndex > count) {
    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return 0;
  }

  NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");

  nsresult rv = sheet->InsertRuleIntoGroup(aRule, this, aIndex);
  if (NS_FAILED(rv)) {
    aRv.Throw(rv);
    return 0;
  }
  return aIndex;
}

void GroupRule::DeleteRule(uint32_t aIndex, ErrorResult& aRv) {
  StyleSheet* sheet = GetStyleSheet();
  if (NS_WARN_IF(!sheet)) {
    aRv.Throw(NS_ERROR_FAILURE);
    return;
  }

  uint32_t count = StyleRuleCount();
  if (aIndex >= count) {
    aRv.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
    return;
  }

  NS_ASSERTION(count <= INT32_MAX, "Too many style rules!");

  nsresult rv = sheet->DeleteRuleFromGroup(this, aIndex);
  if (NS_FAILED(rv)) {
    aRv.Throw(rv);
  }
}

size_t GroupRule::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const {
  // TODO how to implement?
  return 0;
}

}  // namespace css
}  // namespace mozilla