2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07: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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
|
|
|
|
|
2011-12-19 10:48:15 -08:00
|
|
|
#include "mozilla/Attributes.h"
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsCSSRules.h"
|
2008-08-07 16:15:40 -07:00
|
|
|
#include "nsCSSValue.h"
|
2011-03-17 10:41:52 -07:00
|
|
|
#include "mozilla/css/ImportRule.h"
|
2011-03-17 10:41:52 -07:00
|
|
|
#include "mozilla/css/NameSpaceRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
#include "nsCSSProps.h"
|
2010-05-11 13:41:47 -07:00
|
|
|
#include "nsCSSStyleSheet.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
|
|
|
#include "nsIMediaList.h"
|
2008-10-22 07:31:14 -07:00
|
|
|
#include "nsICSSRuleList.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIDocument.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2012-07-27 07:03:27 -07:00
|
|
|
#include "nsError.h"
|
2008-08-07 16:15:40 -07:00
|
|
|
#include "nsStyleUtil.h"
|
2010-06-28 15:49:35 -07:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2011-04-11 23:18:43 -07:00
|
|
|
#include "nsCSSParser.h"
|
2009-08-20 14:52:47 -07:00
|
|
|
#include "nsPrintfCString.h"
|
2012-07-20 09:42:08 -07:00
|
|
|
#include "nsDOMClassInfoID.h"
|
2012-08-23 21:08:09 -07:00
|
|
|
#include "mozilla/dom/CSSStyleDeclarationBinding.h"
|
2012-08-31 14:21:28 -07:00
|
|
|
#include "StyleRule.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-10-01 09:49:41 -07:00
|
|
|
using namespace mozilla;
|
2011-03-17 10:41:52 -07:00
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
#define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \
|
2012-10-07 19:39:08 -07:00
|
|
|
/* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \
|
|
|
|
{ return this; } \
|
|
|
|
/* virtual */ nsIDOMCSSRule* class_::GetExistingDOMRule() \
|
2011-04-07 23:36:09 -07:00
|
|
|
{ return this; }
|
2011-04-11 23:18:43 -07:00
|
|
|
#define IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(class_, super_) \
|
|
|
|
/* virtual */ void class_::MapRuleInfoInto(nsRuleData* aRuleData) \
|
2011-10-17 07:59:28 -07:00
|
|
|
{ NS_ABORT_IF_FALSE(false, "should not be called"); }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
#define IMPL_STYLE_RULE_INHERIT(class_, super_) \
|
|
|
|
IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \
|
|
|
|
IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(class_, super_)
|
2011-03-28 20:21:20 -07:00
|
|
|
|
|
|
|
// base class for all rule types in a CSS style sheet
|
|
|
|
|
2011-03-06 19:59:03 -08:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet*
|
|
|
|
Rule::GetStyleSheet() const
|
|
|
|
{
|
|
|
|
if (!(mSheet & 0x1)) {
|
|
|
|
return reinterpret_cast<nsCSSStyleSheet*>(mSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsHTMLCSSStyleSheet*
|
|
|
|
Rule::GetHTMLCSSStyleSheet() const
|
|
|
|
{
|
|
|
|
if (mSheet & 0x1) {
|
|
|
|
return reinterpret_cast<nsHTMLCSSStyleSheet*>(mSheet & ~uintptr_t(0x1));
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2011-03-28 20:21:20 -07:00
|
|
|
/* virtual */ void
|
2011-03-06 19:59:03 -08:00
|
|
|
Rule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2011-03-28 20:21:20 -07:00
|
|
|
{
|
|
|
|
// We don't reference count this up reference. The style sheet
|
|
|
|
// will tell us when it's going away or when we're detached from
|
|
|
|
// it.
|
2012-09-30 09:40:24 -07:00
|
|
|
mSheet = reinterpret_cast<uintptr_t>(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
Rule::SetHTMLCSSStyleSheet(nsHTMLCSSStyleSheet* aSheet)
|
|
|
|
{
|
|
|
|
// We don't reference count this up reference. The style sheet
|
|
|
|
// will tell us when it's going away or when we're detached from
|
|
|
|
// it.
|
|
|
|
mSheet = reinterpret_cast<uintptr_t>(aSheet);
|
|
|
|
mSheet |= 0x1;
|
2011-03-28 20:21:20 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 19:46:35 -07:00
|
|
|
nsresult
|
|
|
|
Rule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
if (mParentRule) {
|
2011-04-07 23:36:09 -07:00
|
|
|
NS_IF_ADDREF(*aParentRule = mParentRule->GetDOMRule());
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aParentRule = nullptr;
|
2011-04-11 19:46:35 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSheet);
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
NS_IF_ADDREF(*aSheet = GetStyleSheet());
|
2011-04-11 19:46:35 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
size_t
|
|
|
|
Rule::SizeOfCOMArrayElementIncludingThis(css::Rule* aElement,
|
|
|
|
nsMallocSizeOfFun aMallocSizeOf,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
return aElement->SizeOfIncludingThis(aMallocSizeOf);
|
|
|
|
}
|
2011-03-28 20:21:20 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------
|
|
|
|
// Style Rule List for group rules
|
|
|
|
//
|
2010-08-07 22:23:17 -07:00
|
|
|
|
2011-12-19 10:48:15 -08:00
|
|
|
class GroupRuleRuleList MOZ_FINAL : public nsICSSRuleList
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRuleRuleList(GroupRule *aGroupRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSIDOMCSSRULELIST
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
virtual nsIDOMCSSRule* GetItemAt(uint32_t aIndex, nsresult* aResult);
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
void DropReference() { mGroupRule = nullptr; }
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
private:
|
|
|
|
~GroupRuleRuleList();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
private:
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule* mGroupRule;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRuleRuleList::GroupRuleRuleList(GroupRule *aGroupRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The rule will tell us when its going away.
|
|
|
|
mGroupRule = aGroupRule;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
GroupRuleRuleList::~GroupRuleRuleList()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSGroupRuleRuleList
|
2010-08-07 22:23:17 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN(GroupRuleRuleList)
|
2008-10-22 07:31:14 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSGroupRuleRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
NS_IMPL_ADDREF(GroupRuleRuleList)
|
|
|
|
NS_IMPL_RELEASE(GroupRuleRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRuleRuleList::GetLength(uint32_t* aLength)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mGroupRule) {
|
2012-08-22 08:56:38 -07:00
|
|
|
*aLength = (uint32_t)mGroupRule->StyleRuleCount();
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
nsIDOMCSSRule*
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRuleRuleList::GetItemAt(uint32_t aIndex, nsresult* aResult)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:29:28 -07:00
|
|
|
*aResult = NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
if (mGroupRule) {
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> rule = mGroupRule->GetStyleRuleAt(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rule) {
|
2011-04-07 23:36:09 -07:00
|
|
|
return rule->GetDOMRule();
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-10-22 07:31:14 -07:00
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2008-10-22 07:31:14 -07:00
|
|
|
}
|
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRuleRuleList::Item(uint32_t aIndex, nsIDOMCSSRule** aReturn)
|
2008-10-22 07:31:14 -07:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
|
|
|
|
if (!rule) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aReturn = nullptr;
|
2008-10-22 07:31:14 -07:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-07-18 13:23:12 -07:00
|
|
|
NS_ADDREF(*aReturn = rule);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-07 22:23:17 -07:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside the namespace
|
|
|
|
DOMCI_DATA(CSSGroupRuleRuleList, css::GroupRuleRuleList)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// CharsetRule
|
|
|
|
//
|
|
|
|
|
2010-08-07 22:34:19 -07:00
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSCharsetRule, css::CharsetRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-07 22:34:19 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::CharsetRule(const nsAString& aEncoding)
|
2011-04-11 19:46:35 -07:00
|
|
|
: Rule(),
|
2007-03-22 10:30:00 -07:00
|
|
|
mEncoding(aEncoding)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::CharsetRule(const CharsetRule& aCopy)
|
2011-04-11 19:46:35 -07:00
|
|
|
: Rule(aCopy),
|
2007-03-22 10:30:00 -07:00
|
|
|
mEncoding(aCopy.mEncoding)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_ADDREF(CharsetRule)
|
|
|
|
NS_IMPL_RELEASE(CharsetRule)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2010-08-07 22:34:19 -07:00
|
|
|
// QueryInterface implementation for CharsetRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CharsetRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCharsetRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCharsetRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-04-11 19:46:35 -07:00
|
|
|
IMPL_STYLE_RULE_INHERIT(CharsetRule, Rule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
CharsetRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fputs("@charset \"", out);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mEncoding).get(), out);
|
|
|
|
fputs("\"\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
return Rule::CHARSET_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::Clone() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> clone = new CharsetRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::GetEncoding(nsAString& aEncoding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aEncoding = mEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::SetEncoding(const nsAString& aEncoding)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mEncoding = aEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
CharsetRule::GetType(uint16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::CHARSET_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::GetCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@charset \"");
|
|
|
|
aCssText.Append(mEncoding);
|
|
|
|
aCssText.AppendLiteral("\";");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::SetCssText(const nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-07 22:34:19 -07:00
|
|
|
CharsetRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
CharsetRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mEncoding
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// -------------------------------------------
|
2011-03-17 10:41:52 -07:00
|
|
|
// ImportRule
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2011-03-17 10:41:52 -07:00
|
|
|
|
2011-03-22 22:22:59 -07:00
|
|
|
ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec)
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule()
|
2011-03-22 22:22:59 -07:00
|
|
|
, mURLSpec(aURLSpec)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mMedia(aMedia)
|
|
|
|
{
|
|
|
|
// XXXbz This is really silly.... the mMedia here will be replaced
|
|
|
|
// with itself if we manage to load a sheet. Which should really
|
|
|
|
// never fail nowadays, in sane cases.
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::ImportRule(const ImportRule& aCopy)
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule(aCopy),
|
2007-03-22 10:30:00 -07:00
|
|
|
mURLSpec(aCopy.mURLSpec)
|
|
|
|
{
|
2011-03-29 20:46:12 -07:00
|
|
|
// Whether or not an @import rule has a null sheet is a permanent
|
|
|
|
// property of that @import rule, since it is null only if the target
|
|
|
|
// sheet failed security checks.
|
2007-03-22 10:30:00 -07:00
|
|
|
if (aCopy.mChildSheet) {
|
2011-03-29 20:46:12 -07:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet =
|
2012-07-30 07:20:58 -07:00
|
|
|
aCopy.mChildSheet->Clone(nullptr, this, nullptr, nullptr);
|
2011-03-29 20:46:12 -07:00
|
|
|
SetSheet(sheet);
|
|
|
|
// SetSheet sets mMedia appropriately
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::~ImportRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mChildSheet) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mChildSheet->SetOwnerRule(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_ADDREF(ImportRule)
|
|
|
|
NS_IMPL_RELEASE(ImportRule)
|
2010-01-12 05:08:43 -08:00
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
// QueryInterface implementation for ImportRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(ImportRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 19:59:03 -08:00
|
|
|
IMPL_STYLE_RULE_INHERIT(ImportRule, Rule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
ImportRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// Indent
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
fputs("@import \"", out);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
|
|
|
fputs("\" ", out);
|
|
|
|
|
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
|
|
|
fputs("\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
return Rule::IMPORT_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::Clone() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> clone = new ImportRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
void
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::SetSheet(nsCSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-03-17 10:41:52 -07:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// set the new sheet
|
|
|
|
mChildSheet = aSheet;
|
|
|
|
aSheet->SetOwnerRule(this);
|
|
|
|
|
|
|
|
// set our medialist to be the same as the sheet's medialist
|
|
|
|
nsCOMPtr<nsIDOMMediaList> mediaList;
|
2011-03-17 10:41:52 -07:00
|
|
|
mChildSheet->GetMedia(getter_AddRefs(mediaList));
|
|
|
|
NS_ABORT_IF_FALSE(mediaList, "GetMedia returned null");
|
2007-07-08 00:08:04 -07:00
|
|
|
mMedia = static_cast<nsMediaList*>(mediaList.get());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
ImportRule::GetType(uint16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
|
|
|
*aType = nsIDOMCSSRule::IMPORT_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@import url(");
|
2009-03-05 20:05:01 -08:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
|
2007-03-22 10:30:00 -07:00
|
|
|
aCssText.Append(NS_LITERAL_STRING(")"));
|
|
|
|
if (mMedia) {
|
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
if (!mediaText.IsEmpty()) {
|
|
|
|
aCssText.AppendLiteral(" ");
|
|
|
|
aCssText.Append(mediaText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aCssText.AppendLiteral(";");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::SetCssText(const nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetHref(nsAString & aHref)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aHref = mURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetMedia(nsIDOMMediaList * *aMedia)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
|
2010-07-18 13:23:12 -07:00
|
|
|
NS_IF_ADDREF(*aMedia = mMedia);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStyleSheet);
|
|
|
|
|
2010-05-31 16:51:40 -07:00
|
|
|
NS_IF_ADDREF(*aStyleSheet = mChildSheet);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
ImportRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mURLSpec
|
|
|
|
//
|
|
|
|
// The following members are not measured:
|
|
|
|
// - mMedia, because it is measured via nsCSSStyleSheet::mMedia
|
|
|
|
// - mChildSheet, because it is measured via nsCSSStyleSheetInner::mSheets
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// must be outside the namespace
|
|
|
|
DOMCI_DATA(CSSImportRule, css::ImportRule)
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-07 18:23:46 -07:00
|
|
|
CloneRuleInto(css::Rule* aRule, void* aArray)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<css::Rule> clone = aRule->Clone();
|
|
|
|
static_cast<nsCOMArray<css::Rule>*>(aArray)->AppendObject(clone);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
GroupRule::GroupRule()
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule()
|
2010-08-07 22:28:33 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-07 18:23:46 -07:00
|
|
|
SetParentRuleReference(Rule* aRule, void* aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule* parentRule = static_cast<GroupRule*>(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
aRule->SetParentRule(parentRule);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::GroupRule(const GroupRule& aCopy)
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule(aCopy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
const_cast<GroupRule&>(aCopy).mRules.EnumerateForwards(CloneRuleInto, &mRules);
|
2007-03-22 10:30:00 -07:00
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, this);
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::~GroupRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-05-02 18:43:44 -07:00
|
|
|
NS_ABORT_IF_FALSE(!mSheet, "SetStyleSheet should have been called");
|
2012-07-30 07:20:58 -07:00
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(GroupRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(GroupRule)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(GroupRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(GroupRule, Rule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
static bool
|
2011-04-07 18:23:46 -07:00
|
|
|
SetStyleSheetReference(Rule* aRule, void* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-05-11 13:41:47 -07:00
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
2007-03-22 10:30:00 -07:00
|
|
|
aRule->SetStyleSheet(sheet);
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(GroupRule)
|
|
|
|
tmp->mRules.EnumerateForwards(SetParentRuleReference, nullptr);
|
|
|
|
// If tmp does not have a stylesheet, neither do its descendants. In that
|
|
|
|
// case, don't try to null out their stylesheet, to avoid O(N^2) behavior in
|
|
|
|
// depth of group rule nesting. But if tmp _does_ have a stylesheet (which
|
|
|
|
// can happen if it gets unlinked earlier than its owning stylesheet), then we
|
|
|
|
// need to null out the stylesheet pointer on descendants now, before we clear
|
|
|
|
// tmp->mRules.
|
|
|
|
if (tmp->GetStyleSheet()) {
|
|
|
|
tmp->mRules.EnumerateForwards(SetStyleSheetReference, nullptr);
|
|
|
|
}
|
|
|
|
tmp->mRules.Clear();
|
|
|
|
if (tmp->mRuleCollection) {
|
|
|
|
tmp->mRuleCollection->DropReference();
|
|
|
|
tmp->mRuleCollection = nullptr;
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(GroupRule)
|
|
|
|
const nsCOMArray<Rule>& rules = tmp->mRules;
|
|
|
|
for (int32_t i = 0, count = rules.Count(); i < count; ++i) {
|
|
|
|
NS_CYCLE_COLLECTION_NOTE_EDGE_NAME(cb, "mRules[i]");
|
|
|
|
cb.NoteXPCOMChild(rules[i]->GetExistingDOMRule());
|
|
|
|
}
|
2012-11-14 23:32:40 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRuleCollection)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2010-07-18 07:39:20 -07:00
|
|
|
/* virtual */ void
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-10-07 19:39:09 -07:00
|
|
|
// Don't set the sheet on the kids if it's already the same as the sheet we
|
|
|
|
// already have. This is needed to avoid O(N^2) behavior in group nesting
|
|
|
|
// depth when seting the sheet to null during unlink, if we happen to unlin in
|
|
|
|
// order from most nested rule up to least nested rule.
|
|
|
|
if (aSheet != GetStyleSheet()) {
|
|
|
|
mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
|
|
|
|
Rule::SetStyleSheet(aSheet);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
fputs(" {\n", out);
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = 0, count = mRules.Count(); index < count; ++index) {
|
2007-03-22 10:30:00 -07:00
|
|
|
mRules.ObjectAt(index)->List(out, aIndent + 1);
|
|
|
|
}
|
2012-08-04 00:07:03 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
fputs("}\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-08-07 22:29:28 -07:00
|
|
|
void
|
2011-04-07 18:23:46 -07:00
|
|
|
GroupRule::AppendStyleRule(Rule* aRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mRules.AppendObject(aRule);
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
aRule->SetStyleSheet(sheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
aRule->SetParentRule(this);
|
2012-09-30 09:40:24 -07:00
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
Rule*
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRule::GetStyleRuleAt(int32_t aIndex) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:29:28 -07:00
|
|
|
return mRules.SafeObjectAt(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-12-14 14:59:20 -08:00
|
|
|
return
|
2010-08-07 22:28:33 -07:00
|
|
|
const_cast<GroupRule*>(this)->mRules.EnumerateForwards(aFunc, aData);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2013-02-09 22:56:49 -08:00
|
|
|
* The next two methods (DeleteStyleRuleAt and InsertStyleRuleAt)
|
2007-03-22 10:30:00 -07:00
|
|
|
* should never be called unless you have first called WillDirty() on
|
2012-11-26 21:30:31 -08:00
|
|
|
* the parents stylesheet. After they are called, DidDirty() needs to
|
2007-03-22 10:30:00 -07:00
|
|
|
* be called on the sheet
|
|
|
|
*/
|
2010-08-07 22:29:28 -07:00
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRule::DeleteStyleRuleAt(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
Rule* rule = mRules.SafeObjectAt(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
if (rule) {
|
2012-07-30 07:20:58 -07:00
|
|
|
rule->SetStyleSheet(nullptr);
|
|
|
|
rule->SetParentRule(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:29:28 -07:00
|
|
|
nsresult
|
2013-02-09 22:56:49 -08:00
|
|
|
GroupRule::InsertStyleRuleAt(uint32_t aIndex, Rule* aRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-02-09 22:56:49 -08:00
|
|
|
aRule->SetStyleSheet(GetStyleSheet());
|
|
|
|
aRule->SetParentRule(this);
|
|
|
|
if (! mRules.InsertObjectAt(aRule, aIndex)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:29:28 -07:00
|
|
|
nsresult
|
2011-04-07 18:23:46 -07:00
|
|
|
GroupRule::ReplaceStyleRule(Rule* aOld, Rule* aNew)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t index = mRules.IndexOf(aOld);
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
|
|
|
|
mRules.ReplaceObjectAt(aNew, index);
|
2012-09-30 09:40:24 -07:00
|
|
|
aNew->SetStyleSheet(GetStyleSheet());
|
2007-03-22 10:30:00 -07:00
|
|
|
aNew->SetParentRule(this);
|
2012-07-30 07:20:58 -07:00
|
|
|
aOld->SetStyleSheet(nullptr);
|
|
|
|
aOld->SetParentRule(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::AppendRulesToCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AppendLiteral(" {\n");
|
|
|
|
|
|
|
|
// get all the rules
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t index = 0, count = mRules.Count(); index < count; ++index) {
|
2011-04-07 18:23:46 -07:00
|
|
|
Rule* rule = mRules.ObjectAt(index);
|
2011-04-07 23:36:09 -07:00
|
|
|
nsIDOMCSSRule* domRule = rule->GetDOMRule();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (domRule) {
|
|
|
|
nsAutoString cssText;
|
|
|
|
domRule->GetCssText(cssText);
|
|
|
|
aCssText.Append(NS_LITERAL_STRING(" ") +
|
|
|
|
cssText +
|
|
|
|
NS_LITERAL_STRING("\n"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
aCssText.AppendLiteral("}");
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods
|
2011-04-11 19:46:35 -07:00
|
|
|
nsresult
|
|
|
|
GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (!mRuleCollection) {
|
2010-08-07 22:23:17 -07:00
|
|
|
mRuleCollection = new css::GroupRuleRuleList(this);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-11 19:46:35 -07:00
|
|
|
NS_ADDREF(*aRuleList = mRuleCollection);
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
if (aIndex > uint32_t(mRules.Count()))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX,
|
2007-03-22 10:30:00 -07:00
|
|
|
"Too many style rules!");
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
return sheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 08:56:38 -07:00
|
|
|
GroupRule::DeleteRule(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
NS_ENSURE_TRUE(sheet, NS_ERROR_FAILURE);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
if (aIndex >= uint32_t(mRules.Count()))
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2012-09-27 23:57:33 -07:00
|
|
|
NS_ASSERTION(uint32_t(mRules.Count()) <= INT32_MAX,
|
2007-03-22 10:30:00 -07:00
|
|
|
"Too many style rules!");
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
return sheet->DeleteRuleFromGroup(this, aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
GroupRule::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return mRules.SizeOfExcludingThis(Rule::SizeOfCOMArrayElementIncludingThis,
|
|
|
|
aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mRuleCollection
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsICSSMediaRule
|
|
|
|
//
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::MediaRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::MediaRule(const MediaRule& aCopy)
|
2010-08-07 22:28:33 -07:00
|
|
|
: GroupRule(aCopy)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (aCopy.mMedia) {
|
|
|
|
aCopy.mMedia->Clone(getter_AddRefs(mMedia));
|
|
|
|
if (mMedia) {
|
|
|
|
// XXXldb This doesn't really make sense.
|
2012-09-30 09:40:24 -07:00
|
|
|
mMedia->SetStyleSheet(aCopy.GetStyleSheet());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::~MediaRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2012-07-30 07:20:58 -07:00
|
|
|
mMedia->SetStyleSheet(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 00:33:57 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
// QueryInterface implementation for MediaRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(MediaRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2012-11-26 21:30:30 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(GroupRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-07-18 07:39:20 -07:00
|
|
|
/* virtual */ void
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
// Set to null so it knows it's leaving one sheet and joining another.
|
2012-07-30 07:20:58 -07:00
|
|
|
mMedia->SetStyleSheet(nullptr);
|
2007-03-22 10:30:00 -07:00
|
|
|
mMedia->SetStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::SetStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@media ", out);
|
|
|
|
|
|
|
|
if (mMedia) {
|
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::List(out, aIndent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
return Rule::MEDIA_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::Clone() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> clone = new MediaRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::SetMedia(nsMediaList* aMedia)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
mMedia = aMedia;
|
|
|
|
if (aMedia)
|
2012-09-30 09:40:24 -07:00
|
|
|
mMedia->SetStyleSheet(GetStyleSheet());
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaRule::GetType(uint16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::MEDIA_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::GetCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@media ");
|
2012-11-26 21:30:30 -08:00
|
|
|
AppendConditionText(aCssText);
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::AppendRulesToCssText(aCssText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::SetCssText(const nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSGroupingRule methods
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::InsertRule(aRule, aIndex, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
MediaRule::DeleteRule(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::DeleteRule(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSConditionRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaRule::GetConditionText(nsAString& aConditionText)
|
|
|
|
{
|
|
|
|
aConditionText.Truncate(0);
|
|
|
|
AppendConditionText(aConditionText);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaRule::SetConditionText(const nsAString& aConditionText)
|
|
|
|
{
|
2012-11-26 21:30:31 -08:00
|
|
|
if (!mMedia) {
|
|
|
|
nsRefPtr<nsMediaList> media = new nsMediaList();
|
|
|
|
media->SetStyleSheet(GetStyleSheet());
|
|
|
|
nsresult rv = media->SetMediaText(aConditionText);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
mMedia = media;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
return mMedia->SetMediaText(aConditionText);
|
2012-11-26 21:30:30 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSMediaRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
MediaRule::GetMedia(nsIDOMMediaList* *aMedia)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
NS_IF_ADDREF(*aMedia = mMedia);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
// GroupRule interface
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2011-03-17 22:18:08 -07:00
|
|
|
MediaRule::UseForPresentation(nsPresContext* aPresContext,
|
2008-07-26 09:14:48 -07:00
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2011-04-21 20:17:31 -07:00
|
|
|
return mMedia->Matches(aPresContext, &aKey);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
MediaRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mMedia
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
void
|
|
|
|
MediaRule::AppendConditionText(nsAString& aOutput)
|
|
|
|
{
|
|
|
|
if (mMedia) {
|
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
aOutput.Append(mediaText);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSMediaRule, css::MediaRule)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::DocumentRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::DocumentRule(const DocumentRule& aCopy)
|
2010-08-07 22:28:33 -07:00
|
|
|
: GroupRule(aCopy)
|
2007-03-22 10:30:00 -07:00
|
|
|
, mURLs(new URL(*aCopy.mURLs))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::~DocumentRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-06 00:33:57 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DocumentRule, GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
// QueryInterface implementation for DocumentRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DocumentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2012-11-26 21:30:30 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(GroupRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
DocumentRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString str;
|
2007-03-22 10:30:00 -07:00
|
|
|
str.AssignLiteral("@-moz-document ");
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL:
|
|
|
|
str.AppendLiteral("url(\"");
|
|
|
|
break;
|
|
|
|
case eURLPrefix:
|
|
|
|
str.AppendLiteral("url-prefix(\"");
|
|
|
|
break;
|
|
|
|
case eDomain:
|
|
|
|
str.AppendLiteral("domain(\"");
|
2011-06-12 18:52:32 -07:00
|
|
|
break;
|
2011-04-28 10:21:37 -07:00
|
|
|
case eRegExp:
|
|
|
|
str.AppendLiteral("regexp(\"");
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString escapedURL(url->url);
|
2007-03-22 10:30:00 -07:00
|
|
|
escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
|
|
|
|
str.Append(escapedURL);
|
|
|
|
str.AppendLiteral("\"), ");
|
|
|
|
}
|
|
|
|
str.Cut(str.Length() - 2, 1); // remove last ,
|
|
|
|
fputs(str.get(), out);
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
GroupRule::List(out, aIndent);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
return Rule::DOCUMENT_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::Clone() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> clone = new DocumentRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
DocumentRule::GetType(uint16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// XXX What should really happen here?
|
|
|
|
*aType = nsIDOMCSSRule::UNKNOWN_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::GetCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@-moz-document ");
|
2012-11-26 21:30:30 -08:00
|
|
|
AppendConditionText(aCssText);
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::AppendRulesToCssText(aCssText);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::SetCssText(const nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSGroupingRule methods
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_IMETHODIMP
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
DocumentRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::InsertRule(aRule, aIndex, _retval);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
DocumentRule::DeleteRule(uint32_t aIndex)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2010-08-07 22:28:33 -07:00
|
|
|
return GroupRule::DeleteRule(aIndex);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSConditionRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentRule::GetConditionText(nsAString& aConditionText)
|
|
|
|
{
|
|
|
|
aConditionText.Truncate(0);
|
|
|
|
AppendConditionText(aConditionText);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
DocumentRule::SetConditionText(const nsAString& aConditionText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2010-08-07 22:28:33 -07:00
|
|
|
// GroupRule interface
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::UseForPresentation(nsPresContext* aPresContext,
|
2011-04-28 10:21:37 -07:00
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-28 10:21:37 -07:00
|
|
|
nsIDocument *doc = aPresContext->Document();
|
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString docURISpec;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (docURI)
|
|
|
|
docURI->GetSpec(docURISpec);
|
|
|
|
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL: {
|
|
|
|
if (docURISpec == url->url)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} break;
|
|
|
|
case eURLPrefix: {
|
|
|
|
if (StringBeginsWith(docURISpec, url->url))
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} break;
|
|
|
|
case eDomain: {
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString host;
|
2007-03-22 10:30:00 -07:00
|
|
|
if (docURI)
|
|
|
|
docURI->GetHost(host);
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t lenDiff = host.Length() - url->url.Length();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (lenDiff == 0) {
|
|
|
|
if (host == url->url)
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
|
|
|
if (StringEndsWith(host, url->url) &&
|
|
|
|
host.CharAt(lenDiff - 1) == '.')
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
} break;
|
2011-04-28 10:21:37 -07:00
|
|
|
case eRegExp: {
|
|
|
|
NS_ConvertUTF8toUTF16 spec(docURISpec);
|
|
|
|
NS_ConvertUTF8toUTF16 regex(url->url);
|
|
|
|
if (nsContentUtils::IsPatternMatching(spec, regex, doc)) {
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2011-04-28 10:21:37 -07:00
|
|
|
}
|
|
|
|
} break;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
DocumentRule::URL::~URL()
|
2009-01-16 15:33:57 -08:00
|
|
|
{
|
2011-03-17 22:18:08 -07:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(DocumentRule::URL, this, next);
|
2009-01-16 15:33:57 -08:00
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
DocumentRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mURLs
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
void
|
|
|
|
DocumentRule::AppendConditionText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL:
|
|
|
|
aCssText.AppendLiteral("url(");
|
|
|
|
break;
|
|
|
|
case eURLPrefix:
|
|
|
|
aCssText.AppendLiteral("url-prefix(");
|
|
|
|
break;
|
|
|
|
case eDomain:
|
|
|
|
aCssText.AppendLiteral("domain(");
|
|
|
|
break;
|
|
|
|
case eRegExp:
|
|
|
|
aCssText.AppendLiteral("regexp(");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(url->url),
|
|
|
|
aCssText);
|
|
|
|
aCssText.AppendLiteral("), ");
|
|
|
|
}
|
|
|
|
aCssText.Truncate(aCssText.Length() - 2); // remove last ", "
|
|
|
|
}
|
|
|
|
|
2011-03-17 22:18:08 -07:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSMozDocumentRule, css::DocumentRule)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// -------------------------------------------
|
2011-03-17 10:41:52 -07:00
|
|
|
// NameSpaceRule
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
2011-03-17 10:41:52 -07:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2011-03-22 22:23:04 -07:00
|
|
|
NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec)
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule(),
|
2011-03-22 22:23:04 -07:00
|
|
|
mPrefix(aPrefix),
|
|
|
|
mURLSpec(aURLSpec)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy)
|
2011-03-06 19:59:03 -08:00
|
|
|
: Rule(aCopy),
|
2007-03-22 10:30:00 -07:00
|
|
|
mPrefix(aCopy.mPrefix),
|
|
|
|
mURLSpec(aCopy.mURLSpec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::~NameSpaceRule()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_IMPL_ADDREF(NameSpaceRule)
|
|
|
|
NS_IMPL_RELEASE(NameSpaceRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
// QueryInterface implementation for NameSpaceRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(NameSpaceRule)
|
2011-03-17 10:41:52 -07:00
|
|
|
if (aIID.Equals(NS_GET_IID(css::NameSpaceRule))) {
|
|
|
|
*aInstancePtr = this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 19:59:03 -08:00
|
|
|
IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
NameSpaceRule::List(FILE* out, int32_t aIndent) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@namespace ", out);
|
|
|
|
|
|
|
|
if (mPrefix) {
|
|
|
|
mPrefix->ToString(buffer);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
|
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("url(", out);
|
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
|
|
|
fputs(")\n", out);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::GetType() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
return Rule::NAMESPACE_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::Clone() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<Rule> clone = new NameSpaceRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
NameSpaceRule::GetType(uint16_t* aType)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2012-06-21 12:58:19 -07:00
|
|
|
*aType = nsIDOMCSSRule::NAMESPACE_RULE;
|
2007-03-22 10:30:00 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::GetCssText(nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@namespace ");
|
|
|
|
if (mPrefix) {
|
2010-03-08 07:45:00 -08:00
|
|
|
aCssText.Append(nsDependentAtomString(mPrefix) + NS_LITERAL_STRING(" "));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
aCssText.AppendLiteral("url(");
|
2009-03-05 20:05:01 -08:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
|
2007-03-22 10:30:00 -07:00
|
|
|
aCssText.Append(NS_LITERAL_STRING(");"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::SetCssText(const nsAString& aCssText)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 10:41:52 -07:00
|
|
|
NameSpaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2008-08-07 16:15:40 -07:00
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
NameSpaceRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mPrefix
|
|
|
|
// - mURLSpec
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-17 10:41:52 -07:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSNameSpaceRule, css::NameSpaceRule)
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSFontFaceStyleDecl and related routines
|
|
|
|
//
|
|
|
|
|
|
|
|
// A src: descriptor is represented as an array value; each entry in
|
|
|
|
// the array can be eCSSUnit_URL, eCSSUnit_Local_Font, or
|
|
|
|
// eCSSUnit_Font_Format. Blocks of eCSSUnit_Font_Format may appear
|
|
|
|
// only after one of the first two. (css3-fonts only contemplates
|
|
|
|
// annotating URLs with formats, but we handle the general case.)
|
|
|
|
static void
|
2012-07-06 13:14:07 -07:00
|
|
|
AppendSerializedFontSrc(const nsCSSValue& src, nsAString & aResult)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
2009-03-09 16:14:34 -07:00
|
|
|
NS_PRECONDITION(src.GetUnit() == eCSSUnit_Array,
|
2008-08-07 16:15:40 -07:00
|
|
|
"improper value unit for src:");
|
|
|
|
|
|
|
|
const nsCSSValue::Array& sources = *src.GetArrayValue();
|
2010-06-25 12:38:57 -07:00
|
|
|
size_t i = 0;
|
2008-08-07 16:15:40 -07:00
|
|
|
|
|
|
|
while (i < sources.Count()) {
|
|
|
|
nsAutoString formats;
|
|
|
|
|
|
|
|
if (sources[i].GetUnit() == eCSSUnit_URL) {
|
2009-03-05 20:05:00 -08:00
|
|
|
aResult.AppendLiteral("url(");
|
2008-08-07 16:15:40 -07:00
|
|
|
nsDependentString url(sources[i].GetOriginalURLValue());
|
2009-03-05 20:05:00 -08:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(url, aResult);
|
|
|
|
aResult.AppendLiteral(")");
|
2008-08-07 16:15:40 -07:00
|
|
|
} else if (sources[i].GetUnit() == eCSSUnit_Local_Font) {
|
2009-03-05 20:05:00 -08:00
|
|
|
aResult.AppendLiteral("local(");
|
2008-08-07 16:15:40 -07:00
|
|
|
nsDependentString local(sources[i].GetStringBufferValue());
|
2009-03-05 20:05:00 -08:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(local, aResult);
|
|
|
|
aResult.AppendLiteral(")");
|
2008-08-07 16:15:40 -07:00
|
|
|
} else {
|
|
|
|
NS_NOTREACHED("entry in src: descriptor with improper unit");
|
|
|
|
i++;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
i++;
|
|
|
|
formats.Truncate();
|
|
|
|
while (i < sources.Count() &&
|
|
|
|
sources[i].GetUnit() == eCSSUnit_Font_Format) {
|
|
|
|
formats.Append('"');
|
|
|
|
formats.Append(sources[i].GetStringBufferValue());
|
|
|
|
formats.AppendLiteral("\", ");
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
if (formats.Length() > 0) {
|
|
|
|
formats.Truncate(formats.Length() - 2); // remove the last comma
|
|
|
|
aResult.AppendLiteral(" format(");
|
|
|
|
aResult.Append(formats);
|
|
|
|
aResult.Append(')');
|
|
|
|
}
|
|
|
|
aResult.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
aResult.Truncate(aResult.Length() - 2); // remove the last comma-space
|
|
|
|
}
|
|
|
|
|
2009-08-20 14:52:47 -07:00
|
|
|
// print all characters with at least four hex digits
|
|
|
|
static void
|
2012-08-22 08:56:38 -07:00
|
|
|
AppendSerializedUnicodePoint(uint32_t aCode, nsACString &aBuf)
|
2009-08-20 14:52:47 -07:00
|
|
|
{
|
|
|
|
aBuf.Append(nsPrintfCString("%04X", aCode));
|
|
|
|
}
|
|
|
|
|
|
|
|
// A unicode-range: descriptor is represented as an array of integers,
|
|
|
|
// to be interpreted as a sequence of pairs: min max min max ...
|
|
|
|
// It is in source order. (Possibly it should be sorted and overlaps
|
|
|
|
// consolidated, but right now we don't do that.)
|
|
|
|
static void
|
|
|
|
AppendSerializedUnicodeRange(nsCSSValue const & aValue,
|
2012-07-06 13:14:07 -07:00
|
|
|
nsAString & aResult)
|
2009-08-20 14:52:47 -07:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aValue.GetUnit() == eCSSUnit_Null ||
|
|
|
|
aValue.GetUnit() == eCSSUnit_Array,
|
|
|
|
"improper value unit for unicode-range:");
|
|
|
|
aResult.Truncate();
|
|
|
|
if (aValue.GetUnit() != eCSSUnit_Array)
|
|
|
|
return;
|
|
|
|
|
|
|
|
nsCSSValue::Array const & sources = *aValue.GetArrayValue();
|
2012-09-01 19:35:17 -07:00
|
|
|
nsAutoCString buf;
|
2009-08-20 14:52:47 -07:00
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(sources.Count() % 2 == 0,
|
|
|
|
"odd number of entries in a unicode-range: array");
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0; i < sources.Count(); i += 2) {
|
|
|
|
uint32_t min = sources[i].GetIntValue();
|
|
|
|
uint32_t max = sources[i+1].GetIntValue();
|
2009-08-20 14:52:47 -07:00
|
|
|
|
|
|
|
// We don't try to replicate the U+XX?? notation.
|
|
|
|
buf.AppendLiteral("U+");
|
|
|
|
AppendSerializedUnicodePoint(min, buf);
|
|
|
|
|
|
|
|
if (min != max) {
|
|
|
|
buf.Append('-');
|
|
|
|
AppendSerializedUnicodePoint(max, buf);
|
|
|
|
}
|
|
|
|
buf.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
buf.Truncate(buf.Length() - 2); // remove the last comma-space
|
|
|
|
CopyASCIItoUTF16(buf, aResult);
|
|
|
|
}
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
// Mapping from nsCSSFontDesc codes to nsCSSFontFaceStyleDecl fields.
|
|
|
|
nsCSSValue nsCSSFontFaceStyleDecl::* const
|
|
|
|
nsCSSFontFaceStyleDecl::Fields[] = {
|
2011-12-20 08:49:16 -08:00
|
|
|
#define CSS_FONT_DESC(name_, method_) &nsCSSFontFaceStyleDecl::m##method_,
|
|
|
|
#include "nsCSSFontDescList.h"
|
|
|
|
#undef CSS_FONT_DESC
|
2008-08-07 16:15:40 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSFontFaceStyleDecl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSFontFaceStyleDecl)
|
2012-08-05 19:16:30 -07:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration)
|
2012-08-05 19:14:47 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSDeclaration)
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2012-08-05 19:16:30 -07:00
|
|
|
// We forward the cycle collection interfaces to ContainingRule(), which is
|
|
|
|
// never null (in fact, we're part of that object!)
|
|
|
|
if (aIID.Equals(NS_GET_IID(nsCycleCollectionISupports)) ||
|
|
|
|
aIID.Equals(NS_GET_IID(nsXPCOMCycleCollectionParticipant))) {
|
|
|
|
return ContainingRule()->QueryInterface(aIID, aInstancePtr);
|
|
|
|
}
|
2012-08-05 22:24:43 -07:00
|
|
|
else
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_USING_AGGREGATOR(nsCSSFontFaceStyleDecl, ContainingRule())
|
|
|
|
NS_IMPL_RELEASE_USING_AGGREGATOR(nsCSSFontFaceStyleDecl, ContainingRule())
|
|
|
|
|
|
|
|
// helper for string GetPropertyValue and RemovePropertyValue
|
|
|
|
nsresult
|
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyValue(nsCSSFontDesc aFontDescID,
|
2012-07-06 13:14:07 -07:00
|
|
|
nsAString & aResult) const
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_RANGE(aFontDescID, eCSSFontDesc_UNKNOWN,
|
|
|
|
eCSSFontDesc_COUNT - 1);
|
|
|
|
|
|
|
|
aResult.Truncate();
|
|
|
|
if (aFontDescID == eCSSFontDesc_UNKNOWN)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
const nsCSSValue& val = this->*nsCSSFontFaceStyleDecl::Fields[aFontDescID];
|
|
|
|
|
2009-03-09 16:14:34 -07:00
|
|
|
if (val.GetUnit() == eCSSUnit_Null) {
|
|
|
|
// Avoid having to check no-value in the Family and Src cases below.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
switch (aFontDescID) {
|
|
|
|
case eCSSFontDesc_Family: {
|
2010-07-23 11:00:27 -07:00
|
|
|
// we don't use nsCSSValue::AppendToString here because it doesn't
|
2008-08-07 16:15:40 -07:00
|
|
|
// canonicalize the way we want, and anyway it's overkill when
|
|
|
|
// we know we have eCSSUnit_String
|
2009-03-05 20:05:01 -08:00
|
|
|
NS_ASSERTION(val.GetUnit() == eCSSUnit_String, "unexpected unit");
|
2008-08-07 16:15:40 -07:00
|
|
|
nsDependentString family(val.GetStringBufferValue());
|
2009-03-05 20:05:00 -08:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(family, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eCSSFontDesc_Style:
|
2010-07-23 11:00:27 -07:00
|
|
|
val.AppendToString(eCSSProperty_font_style, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_Weight:
|
2010-07-23 11:00:27 -07:00
|
|
|
val.AppendToString(eCSSProperty_font_weight, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
2010-07-23 11:00:27 -07:00
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
case eCSSFontDesc_Stretch:
|
2010-07-23 11:00:27 -07:00
|
|
|
val.AppendToString(eCSSProperty_font_stretch, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-23 03:32:03 -07:00
|
|
|
case eCSSFontDesc_FontFeatureSettings:
|
2012-04-25 23:24:26 -07:00
|
|
|
nsStyleUtil::AppendFontFeatureSettings(val, aResult);
|
2010-08-23 03:32:03 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_FontLanguageOverride:
|
|
|
|
val.AppendToString(eCSSProperty_font_language_override, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
case eCSSFontDesc_Src:
|
2009-03-09 16:14:34 -07:00
|
|
|
AppendSerializedFontSrc(val, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_UnicodeRange:
|
2009-08-20 14:52:47 -07:00
|
|
|
AppendSerializedUnicodeRange(val, aResult);
|
2008-08-07 16:15:40 -07:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_UNKNOWN:
|
|
|
|
case eCSSFontDesc_COUNT:
|
|
|
|
;
|
|
|
|
}
|
|
|
|
NS_NOTREACHED("nsCSSFontFaceStyleDecl::GetPropertyValue: "
|
|
|
|
"out-of-range value got to the switch");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// attribute DOMString cssText;
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetCssText(nsAString & aCssText)
|
|
|
|
{
|
|
|
|
nsAutoString descStr;
|
|
|
|
|
|
|
|
aCssText.Truncate();
|
|
|
|
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
|
|
|
|
id < eCSSFontDesc_COUNT;
|
|
|
|
id = nsCSSFontDesc(id + 1)) {
|
|
|
|
if ((this->*nsCSSFontFaceStyleDecl::Fields[id]).GetUnit()
|
|
|
|
!= eCSSUnit_Null &&
|
|
|
|
NS_SUCCEEDED(GetPropertyValue(id, descStr))) {
|
|
|
|
NS_ASSERTION(descStr.Length() > 0,
|
|
|
|
"GetCssText: non-null unit, empty property value");
|
|
|
|
aCssText.AppendLiteral(" ");
|
|
|
|
aCssText.AppendASCII(nsCSSProps::GetStringValue(id).get());
|
|
|
|
aCssText.AppendLiteral(": ");
|
|
|
|
aCssText.Append(descStr);
|
|
|
|
aCssText.AppendLiteral(";\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::SetCssText(const nsAString & aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
|
|
|
|
}
|
|
|
|
|
|
|
|
// DOMString getPropertyValue (in DOMString propertyName);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyValue(const nsAString & propertyName,
|
2012-07-06 13:14:07 -07:00
|
|
|
nsAString & aResult)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
return GetPropertyValue(nsCSSProps::LookupFontDesc(propertyName), aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSValue getPropertyCSSValue (in DOMString propertyName);
|
2012-10-01 09:49:41 -07:00
|
|
|
already_AddRefed<dom::CSSValue>
|
2008-08-07 16:15:40 -07:00
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyCSSValue(const nsAString & propertyName,
|
2012-10-01 09:49:41 -07:00
|
|
|
ErrorResult& aRv)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
// ??? nsDOMCSSDeclaration returns null/NS_OK, but that seems wrong.
|
2012-10-01 09:49:41 -07:00
|
|
|
aRv.Throw(NS_ERROR_NOT_IMPLEMENTED);
|
|
|
|
return nullptr;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// DOMString removeProperty (in DOMString propertyName) raises (DOMException);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::RemoveProperty(const nsAString & propertyName,
|
2012-07-06 13:14:07 -07:00
|
|
|
nsAString & aResult)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
nsCSSFontDesc descID = nsCSSProps::LookupFontDesc(propertyName);
|
|
|
|
NS_ASSERTION(descID >= eCSSFontDesc_UNKNOWN &&
|
|
|
|
descID < eCSSFontDesc_COUNT,
|
|
|
|
"LookupFontDesc returned value out of range");
|
|
|
|
|
|
|
|
if (descID == eCSSFontDesc_UNKNOWN) {
|
|
|
|
aResult.Truncate();
|
|
|
|
} else {
|
|
|
|
nsresult rv = GetPropertyValue(descID, aResult);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
(this->*nsCSSFontFaceStyleDecl::Fields[descID]).Reset();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DOMString getPropertyPriority (in DOMString propertyName);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyPriority(const nsAString & propertyName,
|
2012-07-06 13:14:07 -07:00
|
|
|
nsAString & aResult)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
// font descriptors do not have priorities at present
|
|
|
|
aResult.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// void setProperty (in DOMString propertyName, in DOMString value,
|
|
|
|
// in DOMString priority) raises (DOMException);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::SetProperty(const nsAString & propertyName,
|
|
|
|
const nsAString & value,
|
|
|
|
const nsAString & priority)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
|
|
|
|
}
|
|
|
|
|
|
|
|
// readonly attribute unsigned long length;
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSFontFaceStyleDecl::GetLength(uint32_t *aLength)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t len = 0;
|
2008-08-07 16:15:40 -07:00
|
|
|
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
|
|
|
|
id < eCSSFontDesc_COUNT;
|
|
|
|
id = nsCSSFontDesc(id + 1))
|
|
|
|
if ((this->*nsCSSFontFaceStyleDecl::Fields[id]).GetUnit() != eCSSUnit_Null)
|
|
|
|
len++;
|
|
|
|
|
|
|
|
*aLength = len;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DOMString item (in unsigned long index);
|
|
|
|
NS_IMETHODIMP
|
2012-08-23 21:08:08 -07:00
|
|
|
nsCSSFontFaceStyleDecl::Item(uint32_t aIndex, nsAString& aReturn)
|
|
|
|
{
|
|
|
|
bool found;
|
|
|
|
IndexedGetter(aIndex, found, aReturn);
|
|
|
|
if (!found) {
|
|
|
|
aReturn.Truncate();
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSFontFaceStyleDecl::IndexedGetter(uint32_t index, bool& aFound, nsAString & aResult)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
int32_t nset = -1;
|
2008-08-07 16:15:40 -07:00
|
|
|
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
|
|
|
|
id < eCSSFontDesc_COUNT;
|
|
|
|
id = nsCSSFontDesc(id + 1)) {
|
|
|
|
if ((this->*nsCSSFontFaceStyleDecl::Fields[id]).GetUnit()
|
|
|
|
!= eCSSUnit_Null) {
|
|
|
|
nset++;
|
2012-08-22 08:56:38 -07:00
|
|
|
if (nset == int32_t(index)) {
|
2012-08-23 21:08:08 -07:00
|
|
|
aFound = true;
|
2008-08-07 16:15:40 -07:00
|
|
|
aResult.AssignASCII(nsCSSProps::GetStringValue(id).get());
|
2012-08-23 21:08:08 -07:00
|
|
|
return;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-08-23 21:08:08 -07:00
|
|
|
aFound = false;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// readonly attribute nsIDOMCSSRule parentRule;
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-07 23:36:09 -07:00
|
|
|
NS_IF_ADDREF(*aParentRule = ContainingRule()->GetDOMRule());
|
|
|
|
return NS_OK;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
2012-08-05 19:14:47 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyValue(const nsCSSProperty aPropID,
|
|
|
|
nsAString& aValue)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
GetPropertyValue(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID)),
|
|
|
|
aValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::SetPropertyValue(const nsCSSProperty aPropID,
|
|
|
|
const nsAString& aValue)
|
|
|
|
{
|
|
|
|
return SetProperty(NS_ConvertUTF8toUTF16(nsCSSProps::GetStringValue(aPropID)),
|
|
|
|
aValue, EmptyString());
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode*
|
|
|
|
nsCSSFontFaceStyleDecl::GetParentObject()
|
|
|
|
{
|
2012-08-05 19:14:52 -07:00
|
|
|
return ContainingRule()->GetDocument();
|
2012-08-05 19:14:47 -07:00
|
|
|
}
|
2008-08-07 16:15:40 -07:00
|
|
|
|
2012-08-23 21:08:09 -07:00
|
|
|
JSObject*
|
|
|
|
nsCSSFontFaceStyleDecl::WrapObject(JSContext *cx, JSObject *scope,
|
|
|
|
bool *triedToWrap)
|
|
|
|
{
|
|
|
|
return mozilla::dom::CSSStyleDeclarationBinding::Wrap(cx, scope, this,
|
|
|
|
triedToWrap);
|
|
|
|
}
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSFontFaceRule
|
|
|
|
//
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2010-08-15 08:19:34 -07:00
|
|
|
nsCSSFontFaceRule::Clone() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSFontFaceRule(*this);
|
2010-08-15 08:19:34 -07:00
|
|
|
return clone.forget();
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
2012-08-05 19:16:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSFontFaceRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSFontFaceRule)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_BEGIN(nsCSSFontFaceRule)
|
|
|
|
// Trace the wrapper for our declaration. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_TRACE_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
|
|
|
nsContentUtils::TraceWrapper(&tmp->mDecl, aCallback, aClosure);
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRACE_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSFontFaceRule)
|
|
|
|
// Unlink the wrapper for our declaraton. This just expands out
|
|
|
|
// NS_IMPL_CYCLE_COLLECTION_UNLINK_PRESERVED_WRAPPER which we can't use
|
|
|
|
// directly because the wrapper is on the declaration, not on us.
|
2012-11-14 23:32:39 -08:00
|
|
|
nsContentUtils::ReleaseWrapper(static_cast<nsISupports*>(p), &tmp->mDecl);
|
2012-08-05 19:16:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSFontFaceRule)
|
|
|
|
// Just NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS here: that will call
|
|
|
|
// into our Trace hook, where we do the right thing with declarations
|
|
|
|
// already.
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_SCRIPT_OBJECTS
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2008-08-07 16:15:40 -07:00
|
|
|
|
2010-01-12 05:08:43 -08:00
|
|
|
DOMCI_DATA(CSSFontFaceRule, nsCSSFontFaceRule)
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
// QueryInterface implementation for nsCSSFontFaceRule
|
2012-08-05 19:16:30 -07:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSFontFaceRule)
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 08:09:05 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule)
|
2008-08-07 16:15:40 -07:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-06 19:59:03 -08:00
|
|
|
IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule)
|
2008-08-07 16:15:40 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-19 19:28:00 -07:00
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSFontFaceRule::List(FILE* out, int32_t aIndent) const
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
nsCString baseInd, descInd;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) {
|
2008-08-07 16:15:40 -07:00
|
|
|
baseInd.AppendLiteral(" ");
|
|
|
|
descInd.AppendLiteral(" ");
|
|
|
|
}
|
|
|
|
descInd.AppendLiteral(" ");
|
|
|
|
|
|
|
|
nsString descStr;
|
|
|
|
|
|
|
|
fprintf(out, "%s@font-face {\n", baseInd.get());
|
|
|
|
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
|
|
|
|
id < eCSSFontDesc_COUNT;
|
|
|
|
id = nsCSSFontDesc(id + 1))
|
|
|
|
if ((mDecl.*nsCSSFontFaceStyleDecl::Fields[id]).GetUnit()
|
|
|
|
!= eCSSUnit_Null) {
|
|
|
|
if (NS_FAILED(mDecl.GetPropertyValue(id, descStr)))
|
|
|
|
descStr.AssignLiteral("#<serialization error>");
|
|
|
|
else if (descStr.Length() == 0)
|
|
|
|
descStr.AssignLiteral("#<serialization missing>");
|
|
|
|
fprintf(out, "%s%s: %s\n",
|
|
|
|
descInd.get(), nsCSSProps::GetStringValue(id).get(),
|
|
|
|
NS_ConvertUTF16toUTF8(descStr).get());
|
|
|
|
}
|
|
|
|
fprintf(out, "%s}\n", baseInd.get());
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2010-07-18 07:39:20 -07:00
|
|
|
nsCSSFontFaceRule::GetType() const
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::FONT_FACE_RULE;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSFontFaceRule::GetType(uint16_t* aType)
|
2008-08-07 16:15:40 -07:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::FONT_FACE_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
nsAutoString propText;
|
|
|
|
mDecl.GetCssText(propText);
|
|
|
|
|
|
|
|
aCssText.AssignLiteral("@font-face {\n");
|
|
|
|
aCssText.Append(propText);
|
|
|
|
aCssText.Append('}');
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED; // bug 443978
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
2010-07-18 13:23:12 -07:00
|
|
|
NS_IF_ADDREF(*aStyle = &mDecl);
|
|
|
|
return NS_OK;
|
2008-08-07 16:15:40 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Arguably these should forward to nsCSSFontFaceStyleDecl methods.
|
|
|
|
void
|
|
|
|
nsCSSFontFaceRule::SetDesc(nsCSSFontDesc aDescID, nsCSSValue const & aValue)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDescID > eCSSFontDesc_UNKNOWN &&
|
|
|
|
aDescID < eCSSFontDesc_COUNT,
|
|
|
|
"aDescID out of range in nsCSSFontFaceRule::SetDesc");
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
// FIXME: handle dynamic changes
|
|
|
|
|
2008-08-07 16:15:40 -07:00
|
|
|
mDecl.*nsCSSFontFaceStyleDecl::Fields[aDescID] = aValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSFontFaceRule::GetDesc(nsCSSFontDesc aDescID, nsCSSValue & aValue)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aDescID > eCSSFontDesc_UNKNOWN &&
|
|
|
|
aDescID < eCSSFontDesc_COUNT,
|
|
|
|
"aDescID out of range in nsCSSFontFaceRule::GetDesc");
|
|
|
|
|
|
|
|
aValue = mDecl.*nsCSSFontFaceStyleDecl::Fields[aDescID];
|
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSFontFaceRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mDecl
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSKeyframeStyleDeclaration
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSKeyframeStyleDeclaration::nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule)
|
|
|
|
: mRule(aRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeyframeStyleDeclaration::~nsCSSKeyframeStyleDeclaration()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRule, "DropReference not called.");
|
|
|
|
}
|
|
|
|
|
2012-08-05 19:16:30 -07:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeStyleDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeStyleDeclaration)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsCSSKeyframeStyleDeclaration)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeStyleDeclaration)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
css::Declaration*
|
2011-09-28 23:19:26 -07:00
|
|
|
nsCSSKeyframeStyleDeclaration::GetCSSDeclaration(bool aAllocate)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
|
|
|
if (mRule) {
|
|
|
|
return mRule->Declaration();
|
|
|
|
} else {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-27 13:53:49 -07:00
|
|
|
void
|
|
|
|
nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2011-04-27 13:53:49 -07:00
|
|
|
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeStyleDeclaration::GetParentRule(nsIDOMCSSRule **aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aParent = mRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSKeyframeStyleDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aDecl, "must be non-null");
|
|
|
|
mRule->ChangeDeclaration(aDecl);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
nsCSSKeyframeStyleDeclaration::DocToUpdate()
|
|
|
|
{
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2012-08-05 19:14:52 -07:00
|
|
|
nsINode*
|
|
|
|
nsCSSKeyframeStyleDeclaration::GetParentObject()
|
|
|
|
{
|
|
|
|
return mRule ? mRule->GetDocument() : nullptr;
|
|
|
|
}
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSKeyframeRule
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy)
|
|
|
|
// copy everything except our reference count and mDOMDeclaration
|
|
|
|
: Rule(aCopy)
|
|
|
|
, mKeys(aCopy.mKeys)
|
2011-04-11 19:46:35 -07:00
|
|
|
, mDeclaration(new css::Declaration(*aCopy.mDeclaration))
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeyframeRule::~nsCSSKeyframeRule()
|
|
|
|
{
|
|
|
|
if (mDOMDeclaration) {
|
|
|
|
mDOMDeclaration->DropReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframeRule::Clone() const
|
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSKeyframeRule(*this);
|
2011-04-11 23:18:43 -07:00
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
2013-01-18 20:32:12 -08:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSKeyframeRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSKeyframeRule)
|
|
|
|
|
2013-02-06 06:24:04 -08:00
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN(nsCSSKeyframeRule)
|
|
|
|
if (tmp->mDOMDeclaration) {
|
|
|
|
tmp->mDOMDeclaration->DropReference();
|
|
|
|
ImplCycleCollectionUnlink(tmp->mDOMDeclaration);
|
|
|
|
}
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN(nsCSSKeyframeRule)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mDOMDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
DOMCI_DATA(MozCSSKeyframeRule, nsCSSKeyframeRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSKeyframeRule
|
2013-01-18 20:32:12 -08:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSKeyframeRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframeRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSKeyframeRule, Rule)
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsCSSKeyframeRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
// We need to implement MapRuleInfoInto because the animation manager
|
|
|
|
// constructs a rule node pointing to us in order to compute the
|
|
|
|
// styles it needs to animate.
|
|
|
|
|
2012-10-16 09:21:35 -07:00
|
|
|
// The spec says that !important declarations should just be ignored
|
|
|
|
NS_ASSERTION(!mDeclaration->HasImportantData(),
|
|
|
|
"Keyframe rules has !important data");
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
mDeclaration->MapNormalRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSKeyframeRule::List(FILE* out, int32_t aIndent) const
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString tmp;
|
|
|
|
DoGetKeyText(tmp);
|
|
|
|
fputs(NS_ConvertUTF16toUTF8(tmp).get(), out);
|
|
|
|
fputs(" ", out);
|
|
|
|
mDeclaration->List(out, aIndent);
|
|
|
|
fputs("\n", out);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframeRule::GetType() const
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::KEYFRAME_RULE;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSKeyframeRule::GetType(uint16_t* aType)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-11-28 23:57:32 -08:00
|
|
|
*aType = nsIDOMCSSRule::KEYFRAME_RULE;
|
2011-04-11 23:18:43 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
DoGetKeyText(aCssText);
|
2011-04-11 23:18:43 -07:00
|
|
|
aCssText.AppendLiteral(" { ");
|
|
|
|
nsAutoString tmp;
|
|
|
|
mDeclaration->ToString(tmp);
|
|
|
|
aCssText.Append(tmp);
|
|
|
|
aCssText.AppendLiteral(" }");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
// FIXME: implement???
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetKeyText(nsAString& aKeyText)
|
2012-11-20 11:55:14 -08:00
|
|
|
{
|
|
|
|
DoGetKeyText(aKeyText);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSKeyframeRule::DoGetKeyText(nsAString& aKeyText) const
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
|
|
|
aKeyText.Truncate();
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t i = 0, i_end = mKeys.Length();
|
2011-04-11 23:18:43 -07:00
|
|
|
NS_ABORT_IF_FALSE(i_end != 0, "must have some keys");
|
|
|
|
for (;;) {
|
|
|
|
aKeyText.AppendFloat(mKeys[i] * 100.0f);
|
|
|
|
aKeyText.Append(PRUnichar('%'));
|
|
|
|
if (++i == i_end) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
aKeyText.AppendLiteral(", ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText)
|
|
|
|
{
|
|
|
|
nsCSSParser parser;
|
|
|
|
|
2011-05-28 15:38:48 -07:00
|
|
|
InfallibleTArray<float> newSelectors;
|
2011-04-11 23:18:43 -07:00
|
|
|
// FIXME: pass filename and line number
|
2012-07-30 07:20:58 -07:00
|
|
|
if (parser.ParseKeyframeSelectorString(aKeyText, nullptr, 0, newSelectors)) {
|
2011-04-11 23:18:43 -07:00
|
|
|
newSelectors.SwapElements(mKeys);
|
|
|
|
} else {
|
|
|
|
// for now, we don't do anything if the parse fails
|
|
|
|
}
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
2011-05-02 18:43:44 -07:00
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
|
|
|
if (!mDOMDeclaration) {
|
|
|
|
mDOMDeclaration = new nsCSSKeyframeStyleDeclaration(this);
|
|
|
|
}
|
|
|
|
NS_ADDREF(*aStyle = mDOMDeclaration);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-04-11 19:46:35 -07:00
|
|
|
nsCSSKeyframeRule::ChangeDeclaration(css::Declaration* aDeclaration)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-02-02 08:59:39 -08:00
|
|
|
// Be careful to not assign to an nsAutoPtr if we would be assigning
|
|
|
|
// the thing it already holds.
|
|
|
|
if (aDeclaration != mDeclaration) {
|
|
|
|
mDeclaration = aDeclaration;
|
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
2011-05-02 18:43:44 -07:00
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSKeyframeRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mKeys
|
|
|
|
// - mDeclaration
|
|
|
|
// - mDOMDeclaration
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-11 23:18:43 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSKeyframesRule
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSKeyframesRule::nsCSSKeyframesRule(const nsCSSKeyframesRule& aCopy)
|
|
|
|
// copy everything except our reference count. GroupRule's copy
|
|
|
|
// constructor also doesn't copy the lazily-constructed
|
|
|
|
// mRuleCollection.
|
|
|
|
: GroupRule(aCopy),
|
|
|
|
mName(aCopy.mName)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeyframesRule::~nsCSSKeyframesRule()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-07 18:23:46 -07:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframesRule::Clone() const
|
|
|
|
{
|
2011-04-07 18:23:46 -07:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSKeyframesRule(*this);
|
2011-04-11 23:18:43 -07:00
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
2011-04-11 19:46:35 -07:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSKeyframesRule, css::GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
DOMCI_DATA(MozCSSKeyframesRule, nsCSSKeyframesRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSKeyframesRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSKeyframesRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframesRule)
|
2011-04-07 18:23:46 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframesRule)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(GroupRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSKeyframesRule::List(FILE* out, int32_t aIndent) const
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fprintf(out, "@keyframes %s", NS_ConvertUTF16toUTF8(mName).get());
|
|
|
|
GroupRule::List(out, aIndent);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframesRule::GetType() const
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return Rule::KEYFRAMES_RULE;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
nsCSSKeyframesRule::GetType(uint16_t* aType)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
2012-11-28 23:57:32 -08:00
|
|
|
*aType = nsIDOMCSSRule::KEYFRAMES_RULE;
|
2011-04-11 23:18:43 -07:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
2012-07-08 18:25:10 -07:00
|
|
|
aCssText.AssignLiteral("@keyframes ");
|
2011-04-11 23:18:43 -07:00
|
|
|
aCssText.Append(mName);
|
|
|
|
aCssText.AppendLiteral(" {\n");
|
|
|
|
nsAutoString tmp;
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = 0, i_end = mRules.Count(); i != i_end; ++i) {
|
2011-04-11 23:18:43 -07:00
|
|
|
static_cast<nsCSSKeyframeRule*>(mRules[i])->GetCssText(tmp);
|
|
|
|
aCssText.Append(tmp);
|
|
|
|
aCssText.AppendLiteral("\n");
|
|
|
|
}
|
|
|
|
aCssText.AppendLiteral("}");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
// FIXME: implement???
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName = mName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::SetName(const nsAString& aName)
|
|
|
|
{
|
|
|
|
mName = aName;
|
|
|
|
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
2011-05-02 18:43:44 -07:00
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
|
|
|
{
|
2011-04-11 19:46:35 -07:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2013-02-15 21:38:34 -08:00
|
|
|
nsCSSKeyframesRule::AppendRule(const nsAString& aRule)
|
2011-04-11 23:18:43 -07:00
|
|
|
{
|
|
|
|
// The spec is confusing, and I think we should just append the rule,
|
|
|
|
// which also turns out to match WebKit:
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2011Apr/0034.html
|
|
|
|
nsCSSParser parser;
|
|
|
|
|
|
|
|
// FIXME: pass filename and line number
|
|
|
|
nsRefPtr<nsCSSKeyframeRule> rule =
|
2012-07-30 07:20:58 -07:00
|
|
|
parser.ParseKeyframeRule(aRule, nullptr, 0);
|
2011-04-11 23:18:43 -07:00
|
|
|
if (rule) {
|
2012-01-11 11:36:43 -08:00
|
|
|
AppendStyleRule(rule);
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
static const uint32_t RULE_NOT_FOUND = uint32_t(-1);
|
2011-04-11 23:18:43 -07:00
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString& aKey)
|
|
|
|
{
|
|
|
|
nsCSSParser parser;
|
|
|
|
|
2011-05-28 15:38:48 -07:00
|
|
|
InfallibleTArray<float> keys;
|
2011-04-11 23:18:43 -07:00
|
|
|
// FIXME: pass filename and line number
|
2012-07-30 07:20:58 -07:00
|
|
|
if (parser.ParseKeyframeSelectorString(aKey, nullptr, 0, keys)) {
|
2011-04-11 23:18:43 -07:00
|
|
|
// The spec isn't clear, but we'll match on the key list, which
|
|
|
|
// mostly matches what WebKit does, except we'll do last-match
|
|
|
|
// instead of first-match, and handling parsing differences better.
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2011Apr/0036.html
|
|
|
|
// http://lists.w3.org/Archives/Public/www-style/2011Apr/0037.html
|
2012-08-22 08:56:38 -07:00
|
|
|
for (uint32_t i = mRules.Count(); i-- != 0; ) {
|
2011-04-11 23:18:43 -07:00
|
|
|
if (static_cast<nsCSSKeyframeRule*>(mRules[i])->GetKeys() == keys) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RULE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::DeleteRule(const nsAString& aKey)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index = FindRuleIndexForKey(aKey);
|
2011-04-11 23:18:43 -07:00
|
|
|
if (index != RULE_NOT_FOUND) {
|
|
|
|
mRules.RemoveObjectAt(index);
|
2012-09-30 09:40:24 -07:00
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
2011-05-02 18:43:44 -07:00
|
|
|
}
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::FindRule(const nsAString& aKey,
|
|
|
|
nsIDOMMozCSSKeyframeRule** aResult)
|
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
uint32_t index = FindRuleIndexForKey(aKey);
|
2011-04-11 23:18:43 -07:00
|
|
|
if (index == RULE_NOT_FOUND) {
|
2012-07-30 07:20:58 -07:00
|
|
|
*aResult = nullptr;
|
2011-04-11 23:18:43 -07:00
|
|
|
} else {
|
|
|
|
NS_ADDREF(*aResult = static_cast<nsCSSKeyframeRule*>(mRules[index]));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupRule interface
|
2011-09-28 23:19:26 -07:00
|
|
|
/* virtual */ bool
|
2011-04-11 23:18:43 -07:00
|
|
|
nsCSSKeyframesRule::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
NS_ABORT_IF_FALSE(false, "should not be called");
|
|
|
|
return false;
|
2011-04-11 23:18:43 -07:00
|
|
|
}
|
|
|
|
|
2012-01-02 18:19:14 -08:00
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSKeyframesRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += GroupRule::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mName
|
|
|
|
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-08-31 14:21:28 -07:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSPageStyleDeclaration
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSPageStyleDeclaration::nsCSSPageStyleDeclaration(nsCSSPageRule* aRule)
|
|
|
|
: mRule(aRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSPageStyleDeclaration::~nsCSSPageStyleDeclaration()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRule, "DropReference not called.");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(nsCSSPageStyleDeclaration)
|
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE(nsCSSPageStyleDeclaration)
|
|
|
|
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE_0(nsCSSPageStyleDeclaration)
|
|
|
|
|
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION(nsCSSPageStyleDeclaration)
|
|
|
|
NS_WRAPPERCACHE_INTERFACE_MAP_ENTRY
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsDOMCSSDeclaration)
|
|
|
|
|
|
|
|
css::Declaration*
|
|
|
|
nsCSSPageStyleDeclaration::GetCSSDeclaration(bool aAllocate)
|
|
|
|
{
|
|
|
|
if (mRule) {
|
|
|
|
return mRule->Declaration();
|
|
|
|
} else {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSPageStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
|
|
|
|
{
|
|
|
|
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageStyleDeclaration::GetParentRule(nsIDOMCSSRule** aParent)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aParent);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aParent = mRule);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsCSSPageStyleDeclaration::SetCSSDeclaration(css::Declaration* aDecl)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(aDecl, "must be non-null");
|
|
|
|
mRule->ChangeDeclaration(aDecl);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIDocument*
|
|
|
|
nsCSSPageStyleDeclaration::DocToUpdate()
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsINode*
|
|
|
|
nsCSSPageStyleDeclaration::GetParentObject()
|
|
|
|
{
|
|
|
|
return mRule ? mRule->GetDocument() : nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSPageRule
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSPageRule::nsCSSPageRule(const nsCSSPageRule& aCopy)
|
|
|
|
// copy everything except our reference count and mDOMDeclaration
|
|
|
|
: Rule(aCopy)
|
|
|
|
, mDeclaration(new css::Declaration(*aCopy.mDeclaration))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSPageRule::~nsCSSPageRule()
|
|
|
|
{
|
|
|
|
if (mDOMDeclaration) {
|
|
|
|
mDOMDeclaration->DropReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
|
|
|
nsCSSPageRule::Clone() const
|
|
|
|
{
|
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSPageRule(*this);
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsCSSPageRule)
|
|
|
|
NS_IMPL_RELEASE(nsCSSPageRule)
|
|
|
|
|
|
|
|
DOMCI_DATA(CSSPageRule, nsCSSPageRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSPageRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSPageRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSPageRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSPageRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(nsCSSPageRule, Rule)
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSPageRule::List(FILE* out, int32_t aIndent) const
|
|
|
|
{
|
2012-11-20 11:55:14 -08:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("@page ", out);
|
|
|
|
mDeclaration->List(out, aIndent);
|
|
|
|
fputs("\n", out);
|
2012-08-31 14:21:28 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ int32_t
|
|
|
|
nsCSSPageRule::GetType() const
|
|
|
|
{
|
|
|
|
return Rule::PAGE_RULE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::GetType(uint16_t* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::PAGE_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.AppendLiteral("@page { ");
|
|
|
|
nsAutoString tmp;
|
|
|
|
mDeclaration->ToString(tmp);
|
|
|
|
aCssText.Append(tmp);
|
|
|
|
aCssText.AppendLiteral(" }");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
// FIXME: implement???
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
return Rule::GetParentRule(aParentRule);
|
|
|
|
}
|
|
|
|
|
|
|
|
css::ImportantRule*
|
|
|
|
nsCSSPageRule::GetImportantRule()
|
|
|
|
{
|
|
|
|
if (!mDeclaration->HasImportantData()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
if (!mImportantRule) {
|
|
|
|
mImportantRule = new css::ImportantRule(mDeclaration);
|
|
|
|
}
|
|
|
|
return mImportantRule;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
nsCSSPageRule::MapRuleInfoInto(nsRuleData* aRuleData)
|
|
|
|
{
|
|
|
|
mDeclaration->MapNormalRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSPageRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
|
|
|
if (!mDOMDeclaration) {
|
|
|
|
mDOMDeclaration = new nsCSSPageStyleDeclaration(this);
|
|
|
|
}
|
|
|
|
NS_ADDREF(*aStyle = mDOMDeclaration);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsCSSPageRule::ChangeDeclaration(css::Declaration* aDeclaration)
|
|
|
|
{
|
|
|
|
mImportantRule = nullptr;
|
2013-01-09 10:33:09 -08:00
|
|
|
// Be careful to not assign to an nsAutoPtr if we would be assigning
|
|
|
|
// the thing it already holds.
|
|
|
|
if (aDeclaration != mDeclaration) {
|
|
|
|
mDeclaration = aDeclaration;
|
|
|
|
}
|
2012-08-31 14:21:28 -07:00
|
|
|
|
|
|
|
nsCSSStyleSheet* sheet = GetStyleSheet();
|
|
|
|
if (sheet) {
|
|
|
|
sheet->SetModifiedByChildRule();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
nsCSSPageRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
return aMallocSizeOf(this);
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:32:12 -07:00
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
CSSSupportsRule::CSSSupportsRule(bool aConditionMet,
|
|
|
|
const nsString& aCondition)
|
|
|
|
: mUseGroup(aConditionMet),
|
|
|
|
mCondition(aCondition)
|
|
|
|
{
|
|
|
|
}
|
2012-01-02 18:19:14 -08:00
|
|
|
|
2012-08-01 17:32:12 -07:00
|
|
|
CSSSupportsRule::CSSSupportsRule(const CSSSupportsRule& aCopy)
|
|
|
|
: css::GroupRule(aCopy),
|
|
|
|
mUseGroup(aCopy.mUseGroup),
|
|
|
|
mCondition(aCopy.mCondition)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
/* virtual */ void
|
2012-08-22 08:56:38 -07:00
|
|
|
CSSSupportsRule::List(FILE* out, int32_t aIndent) const
|
2012-08-01 17:32:12 -07:00
|
|
|
{
|
2012-08-22 08:56:38 -07:00
|
|
|
for (int32_t indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
2012-08-01 17:32:12 -07:00
|
|
|
|
|
|
|
fputs("@supports ", out);
|
2012-11-20 11:55:14 -08:00
|
|
|
fputs(NS_ConvertUTF16toUTF8(mCondition).get(), out);
|
2012-08-01 17:32:12 -07:00
|
|
|
css::GroupRule::List(out, aIndent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
/* virtual */ int32_t
|
2012-08-01 17:32:12 -07:00
|
|
|
CSSSupportsRule::GetType() const
|
|
|
|
{
|
|
|
|
return Rule::SUPPORTS_RULE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ already_AddRefed<mozilla::css::Rule>
|
|
|
|
CSSSupportsRule::Clone() const
|
|
|
|
{
|
|
|
|
nsRefPtr<css::Rule> clone = new CSSSupportsRule(*this);
|
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ bool
|
|
|
|
CSSSupportsRule::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
|
|
|
{
|
|
|
|
return mUseGroup;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF_INHERITED(CSSSupportsRule, css::GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CSSSupportsRule, css::GroupRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSSupportsRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CSSSupportsRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2012-11-26 21:30:30 -08:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSGroupingRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSConditionRule)
|
2012-08-01 17:32:12 -07:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSSupportsRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSSupportsRule)
|
2012-10-07 19:39:09 -07:00
|
|
|
NS_INTERFACE_MAP_END_INHERITING(GroupRule)
|
2012-08-01 17:32:12 -07:00
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
CSSSupportsRule::GetType(uint16_t* aType)
|
2012-08-01 17:32:12 -07:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::SUPPORTS_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@supports ");
|
|
|
|
aCssText.Append(mCondition);
|
|
|
|
return css::GroupRule::AppendRulesToCssText(aCssText);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::SetCssText(const nsAString& aCssText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
return css::GroupRule::GetParentStyleSheet(aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
return css::GroupRule::GetParentRule(aParentRule);
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSGroupingRule methods
|
2012-08-01 17:32:12 -07:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
|
|
|
{
|
|
|
|
return css::GroupRule::GetCssRules(aRuleList);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
CSSSupportsRule::InsertRule(const nsAString & aRule, uint32_t aIndex, uint32_t* _retval)
|
2012-08-01 17:32:12 -07:00
|
|
|
{
|
|
|
|
return css::GroupRule::InsertRule(aRule, aIndex, _retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 08:56:38 -07:00
|
|
|
CSSSupportsRule::DeleteRule(uint32_t aIndex)
|
2012-08-01 17:32:12 -07:00
|
|
|
{
|
|
|
|
return css::GroupRule::DeleteRule(aIndex);
|
|
|
|
}
|
|
|
|
|
2012-11-26 21:30:30 -08:00
|
|
|
// nsIDOMCSSConditionRule methods
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::GetConditionText(nsAString& aConditionText)
|
|
|
|
{
|
|
|
|
aConditionText.Assign(mCondition);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSSupportsRule::SetConditionText(const nsAString& aConditionText)
|
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ size_t
|
|
|
|
CSSSupportsRule::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
|
|
|
|
{
|
|
|
|
size_t n = aMallocSizeOf(this);
|
|
|
|
n += css::GroupRule::SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
n += mCondition.SizeOfExcludingThisIfUnshared(aMallocSizeOf);
|
|
|
|
return n;
|
|
|
|
}
|
|
|
|
|
2012-08-01 17:32:12 -07:00
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSSupportsRule, mozilla::CSSSupportsRule)
|