2016-11-23 02:26:20 +03:00
|
|
|
/* -*- 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/. */
|
|
|
|
|
|
|
|
/* representation of CSSRuleList for stylo */
|
|
|
|
|
|
|
|
#ifndef mozilla_ServoCSSRuleList_h
|
|
|
|
#define mozilla_ServoCSSRuleList_h
|
|
|
|
|
|
|
|
#include "mozilla/ServoBindingTypes.h"
|
|
|
|
#include "mozilla/dom/CSSRuleList.h"
|
2017-04-07 18:07:37 +03:00
|
|
|
#include "nsDataHashtable.h"
|
2016-11-23 02:26:20 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
2017-04-07 18:07:37 +03:00
|
|
|
class ServoStyleRule;
|
2016-11-23 02:26:20 +03:00
|
|
|
class ServoStyleSheet;
|
|
|
|
namespace css {
|
2017-03-09 12:53:34 +03:00
|
|
|
class GroupRule;
|
2016-11-23 02:26:20 +03:00
|
|
|
class Rule;
|
|
|
|
} // namespace css
|
|
|
|
|
2016-12-01 21:37:43 +03:00
|
|
|
class ServoCSSRuleList final : public dom::CSSRuleList
|
2016-11-23 02:26:20 +03:00
|
|
|
{
|
|
|
|
public:
|
2017-05-30 04:10:25 +03:00
|
|
|
// @param aDirectOwnerStyleSheet should be set to the owner stylesheet
|
|
|
|
// if this rule list is owned directly by a stylesheet, which means it
|
|
|
|
// is a top level CSSRuleList. If it's owned by a group rule, nullptr.
|
|
|
|
// If this param is set, the caller doesn't need to call SetStyleSheet.
|
|
|
|
ServoCSSRuleList(already_AddRefed<ServoCssRules> aRawRules,
|
|
|
|
ServoStyleSheet* aDirectOwnerStyleSheet);
|
2017-03-08 10:27:53 +03:00
|
|
|
css::GroupRule* GetParentRule() const { return mParentRule; }
|
2017-03-09 12:53:34 +03:00
|
|
|
void SetParentRule(css::GroupRule* aParentRule);
|
|
|
|
void SetStyleSheet(StyleSheet* aSheet);
|
2016-11-23 02:26:20 +03:00
|
|
|
|
2017-01-06 07:14:28 +03:00
|
|
|
NS_DECL_ISUPPORTS_INHERITED
|
|
|
|
NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(ServoCSSRuleList, dom::CSSRuleList)
|
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
ServoStyleSheet* GetParentObject() final { return mStyleSheet; }
|
|
|
|
|
2017-01-13 18:41:03 +03:00
|
|
|
css::Rule* IndexedGetter(uint32_t aIndex, bool& aFound) final;
|
2016-11-23 02:26:20 +03:00
|
|
|
uint32_t Length() final { return mRules.Length(); }
|
|
|
|
|
|
|
|
void DropReference();
|
|
|
|
|
2016-11-29 14:59:55 +03:00
|
|
|
css::Rule* GetRule(uint32_t aIndex);
|
|
|
|
nsresult InsertRule(const nsAString& aRule, uint32_t aIndex);
|
|
|
|
nsresult DeleteRule(uint32_t aIndex);
|
|
|
|
|
2017-04-03 12:55:06 +03:00
|
|
|
uint16_t GetRuleType(uint32_t aIndex) const;
|
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
private:
|
|
|
|
virtual ~ServoCSSRuleList();
|
|
|
|
|
|
|
|
// XXX Is it possible to have an address lower than or equal to 255?
|
|
|
|
// Is it possible to have more than 255 CSS rule types?
|
|
|
|
static const uintptr_t kMaxRuleType = UINT8_MAX;
|
|
|
|
|
|
|
|
static uintptr_t CastToUint(css::Rule* aPtr) {
|
|
|
|
return reinterpret_cast<uintptr_t>(aPtr);
|
|
|
|
}
|
|
|
|
static css::Rule* CastToPtr(uintptr_t aInt) {
|
|
|
|
MOZ_ASSERT(aInt > kMaxRuleType);
|
|
|
|
return reinterpret_cast<css::Rule*>(aInt);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename Func>
|
|
|
|
void EnumerateInstantiatedRules(Func aCallback);
|
|
|
|
|
2017-03-09 12:53:34 +03:00
|
|
|
void DropAllRules();
|
|
|
|
|
2016-11-23 02:26:20 +03:00
|
|
|
// mStyleSheet may be nullptr when it drops the reference to us.
|
2017-03-09 12:53:34 +03:00
|
|
|
ServoStyleSheet* mStyleSheet = nullptr;
|
|
|
|
// mParentRule is nullptr if it isn't a nested rule list.
|
|
|
|
css::GroupRule* mParentRule = nullptr;
|
2016-11-23 02:26:20 +03:00
|
|
|
RefPtr<ServoCssRules> mRawRules;
|
|
|
|
// Array stores either a number indicating rule type, or a pointer to
|
|
|
|
// css::Rule. If the value is less than kMaxRuleType, the given rule
|
|
|
|
// instance has not been constructed, and the value means the type
|
|
|
|
// of the rule. Otherwise, it is a pointer.
|
|
|
|
nsTArray<uintptr_t> mRules;
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ServoCSSRuleList_h
|