2001-09-25 05:32:19 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 01:52:36 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-06-10 09:32:38 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 01:52:36 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-25 05:32:19 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1999
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2004-04-18 01:52:36 +04:00
|
|
|
* Boris Zbarsky <bzbarsky@mit.edu>
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 01:52:36 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-25 05:32:19 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 01:52:36 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-25 05:32:19 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 01:52:36 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-25 05:32:19 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-25 08:47:31 +03:00
|
|
|
|
|
|
|
/* rules in a CSS stylesheet other than style rules (e.g., @import rules) */
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsCSSRules.h"
|
2008-08-08 03:15:40 +04:00
|
|
|
#include "nsCSSValue.h"
|
2011-03-17 20:41:52 +03:00
|
|
|
#include "mozilla/css/ImportRule.h"
|
2011-03-17 20:41:52 +03:00
|
|
|
#include "mozilla/css/NameSpaceRule.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
#include "nsCSSProps.h"
|
2010-05-12 00:41:47 +04:00
|
|
|
#include "nsCSSStyleSheet.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-05-15 12:26:13 +04:00
|
|
|
#include "nsIDOMCSSStyleSheet.h"
|
2001-08-05 01:19:53 +04:00
|
|
|
#include "nsIMediaList.h"
|
2008-10-22 18:31:14 +04:00
|
|
|
#include "nsICSSRuleList.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsIDocument.h"
|
2004-08-05 22:26:14 +04:00
|
|
|
#include "nsPresContext.h"
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
#include "nsContentUtils.h"
|
2001-09-05 04:00:18 +04:00
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsDOMError.h"
|
2008-08-08 03:15:40 +04:00
|
|
|
#include "nsStyleUtil.h"
|
2010-06-29 02:49:35 +04:00
|
|
|
#include "mozilla/css/Declaration.h"
|
2011-04-12 10:18:43 +04:00
|
|
|
#include "nsCSSParser.h"
|
2009-08-21 01:52:47 +04:00
|
|
|
#include "nsPrintfCString.h"
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
namespace css = mozilla::css;
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
#define IMPL_STYLE_RULE_INHERIT_GET_DOM_RULE_WEAK(class_, super_) \
|
2011-04-08 10:36:09 +04:00
|
|
|
/* virtual */ nsIDOMCSSRule* class_::GetDOMRule() \
|
|
|
|
{ return this; }
|
2011-04-12 10:18:43 +04:00
|
|
|
#define IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(class_, super_) \
|
|
|
|
/* virtual */ void class_::MapRuleInfoInto(nsRuleData* aRuleData) \
|
|
|
|
{ NS_ABORT_IF_FALSE(PR_FALSE, "should not be called"); }
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-04-12 10:18:43 +04: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-29 07:21:20 +04:00
|
|
|
|
|
|
|
// base class for all rule types in a CSS style sheet
|
|
|
|
|
2011-03-07 06:59:03 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
NS_IMPL_ADDREF(Rule)
|
|
|
|
NS_IMPL_RELEASE(Rule)
|
|
|
|
|
2011-03-29 07:21:20 +04:00
|
|
|
/* virtual */ void
|
2011-03-07 06:59:03 +03:00
|
|
|
Rule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2011-03-29 07:21:20 +04: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.
|
|
|
|
mSheet = aSheet;
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
nsresult
|
|
|
|
Rule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
|
|
|
if (mParentRule) {
|
2011-04-08 10:36:09 +04:00
|
|
|
NS_IF_ADDREF(*aParentRule = mParentRule->GetDOMRule());
|
|
|
|
} else {
|
|
|
|
*aParentRule = nsnull;
|
2011-04-12 06:46:35 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
Rule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aSheet);
|
|
|
|
|
|
|
|
NS_IF_ADDREF(*aSheet = mSheet);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-03-29 07:21:20 +04:00
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
// -------------------------------
|
|
|
|
// Style Rule List for group rules
|
|
|
|
//
|
2010-08-08 09:23:17 +04:00
|
|
|
|
|
|
|
class NS_FINAL_CLASS GroupRuleRuleList : public nsICSSRuleList
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
public:
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRuleRuleList(GroupRule *aGroupRule);
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
NS_DECL_NSIDOMCSSRULELIST
|
|
|
|
|
2008-10-22 18:31:14 +04:00
|
|
|
virtual nsIDOMCSSRule* GetItemAt(PRUint32 aIndex, nsresult* aResult);
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
void DropReference() { mGroupRule = nsnull; }
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
private:
|
|
|
|
~GroupRuleRuleList();
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
private:
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule* mGroupRule;
|
2001-09-05 04:00:18 +04:00
|
|
|
};
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRuleRuleList::GroupRuleRuleList(GroupRule *aGroupRule)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
// Not reference counted to avoid circular references.
|
|
|
|
// The rule will tell us when its going away.
|
|
|
|
mGroupRule = aGroupRule;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
GroupRuleRuleList::~GroupRuleRuleList()
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
// QueryInterface implementation for CSSGroupRuleRuleList
|
2010-08-08 09:23:17 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(GroupRuleRuleList)
|
2008-10-22 18:31:14 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsICSSRuleList)
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRuleList)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSGroupRuleRuleList)
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
NS_IMPL_ADDREF(GroupRuleRuleList)
|
|
|
|
NS_IMPL_RELEASE(GroupRuleRuleList)
|
2001-09-05 04:00:18 +04:00
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GroupRuleRuleList::GetLength(PRUint32* aLength)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
if (mGroupRule) {
|
2010-08-08 09:29:28 +04:00
|
|
|
*aLength = (PRUint32)mGroupRule->StyleRuleCount();
|
2001-09-05 04:00:18 +04:00
|
|
|
} else {
|
|
|
|
*aLength = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
nsIDOMCSSRule*
|
|
|
|
GroupRuleRuleList::GetItemAt(PRUint32 aIndex, nsresult* aResult)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2010-08-08 09:29:28 +04:00
|
|
|
*aResult = NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
|
|
|
|
if (mGroupRule) {
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> rule = mGroupRule->GetStyleRuleAt(aIndex);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (rule) {
|
2011-04-08 10:36:09 +04:00
|
|
|
return rule->GetDOMRule();
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
GroupRuleRuleList::Item(PRUint32 aIndex, nsIDOMCSSRule** aReturn)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIDOMCSSRule* rule = GetItemAt(aIndex, &rv);
|
|
|
|
if (!rule) {
|
|
|
|
*aReturn = nsnull;
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2010-07-19 00:23:12 +04:00
|
|
|
NS_ADDREF(*aReturn = rule);
|
|
|
|
return NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:23:17 +04:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside the namespace
|
|
|
|
DOMCI_DATA(CSSGroupRuleRuleList, css::GroupRuleRuleList)
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// -------------------------------------------
|
2002-08-06 09:26:41 +04:00
|
|
|
// CharsetRule
|
1999-06-10 09:32:38 +04:00
|
|
|
//
|
|
|
|
|
2010-08-08 09:34:19 +04:00
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSCharsetRule, css::CharsetRule)
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-08-08 09:34:19 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::CharsetRule(const nsAString& aEncoding)
|
2011-04-12 06:46:35 +04:00
|
|
|
: Rule(),
|
2002-08-06 09:26:41 +04:00
|
|
|
mEncoding(aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::CharsetRule(const CharsetRule& aCopy)
|
2011-04-12 06:46:35 +04:00
|
|
|
: Rule(aCopy),
|
1999-06-10 09:32:38 +04:00
|
|
|
mEncoding(aCopy.mEncoding)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(CharsetRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(CharsetRule, Rule)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2010-08-08 09:34:19 +04:00
|
|
|
// QueryInterface implementation for CharsetRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(CharsetRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2002-08-06 09:26:41 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSCharsetRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSCharsetRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT(CharsetRule, Rule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::List(FILE* out, PRInt32 aIndent) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("@charset \"", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mEncoding).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\"\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetType() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::CHARSET_RULE;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::Clone() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new CharsetRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetEncoding(nsAString& aEncoding)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
aEncoding = mEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-08-06 09:26:41 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::SetEncoding(const nsAString& aEncoding)
|
2002-08-06 09:26:41 +04:00
|
|
|
{
|
|
|
|
mEncoding = aEncoding;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetType(PRUint16* aType)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::CHARSET_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@charset \"");
|
2001-05-15 12:26:13 +04:00
|
|
|
aCssText.Append(mEncoding);
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("\";");
|
2001-05-15 12:26:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-08 09:34:19 +04:00
|
|
|
CharsetRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
// -------------------------------------------
|
2011-03-17 20:41:52 +03:00
|
|
|
// ImportRule
|
1999-06-10 09:32:38 +04:00
|
|
|
//
|
2011-03-17 20:41:52 +03:00
|
|
|
|
2011-03-23 08:22:59 +03:00
|
|
|
ImportRule::ImportRule(nsMediaList* aMedia, const nsString& aURLSpec)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule()
|
2011-03-23 08:22:59 +03:00
|
|
|
, mURLSpec(aURLSpec)
|
2005-03-30 04:36:57 +04:00
|
|
|
, mMedia(aMedia)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
// XXXbz This is really silly.... the mMedia here will be replaced
|
|
|
|
// with itself if we manage to load a sheet. Which should really
|
2004-01-10 05:27:41 +03:00
|
|
|
// never fail nowadays, in sane cases.
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::ImportRule(const ImportRule& aCopy)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(aCopy),
|
2001-08-05 01:19:53 +04:00
|
|
|
mURLSpec(aCopy.mURLSpec)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-03-30 07:46:12 +04: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.
|
2001-08-05 01:19:53 +04:00
|
|
|
if (aCopy.mChildSheet) {
|
2011-03-30 07:46:12 +04:00
|
|
|
nsRefPtr<nsCSSStyleSheet> sheet =
|
|
|
|
aCopy.mChildSheet->Clone(nsnull, this, nsnull, nsnull);
|
|
|
|
SetSheet(sheet);
|
|
|
|
// SetSheet sets mMedia appropriately
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::~ImportRule()
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2002-08-06 09:08:47 +04:00
|
|
|
if (mChildSheet) {
|
|
|
|
mChildSheet->SetOwnerRule(nsnull);
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(ImportRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(ImportRule, Rule)
|
2010-01-12 16:08:43 +03:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
// QueryInterface implementation for ImportRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(ImportRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSImportRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSImportRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-03-07 06:59:03 +03:00
|
|
|
IMPL_STYLE_RULE_INHERIT(ImportRule, Rule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::List(FILE* out, PRInt32 aIndent) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("@import \"", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\" ", out);
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
nsAutoString mediaText;
|
2001-09-05 04:00:18 +04:00
|
|
|
mMedia->GetText(mediaText);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs("\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetType() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::IMPORT_RULE;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::Clone() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new ImportRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
void
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::SetSheet(nsCSSStyleSheet* aSheet)
|
2001-08-05 01:19:53 +04:00
|
|
|
{
|
2011-03-17 20:41:52 +03:00
|
|
|
NS_PRECONDITION(aSheet, "null arg");
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
// set the new sheet
|
|
|
|
mChildSheet = aSheet;
|
2002-08-06 09:08:47 +04:00
|
|
|
aSheet->SetOwnerRule(this);
|
2001-08-05 01:19:53 +04:00
|
|
|
|
|
|
|
// set our medialist to be the same as the sheet's medialist
|
|
|
|
nsCOMPtr<nsIDOMMediaList> mediaList;
|
2011-03-17 20:41:52 +03:00
|
|
|
mChildSheet->GetMedia(getter_AddRefs(mediaList));
|
|
|
|
NS_ABORT_IF_FALSE(mediaList, "GetMedia returned null");
|
2007-07-08 11:08:04 +04:00
|
|
|
mMedia = static_cast<nsMediaList*>(mediaList.get());
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetType(PRUint16* aType)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(aType);
|
2001-05-15 12:26:13 +04:00
|
|
|
*aType = nsIDOMCSSRule::IMPORT_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@import url(");
|
2009-03-06 07:05:01 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
|
2001-08-05 01:19:53 +04:00
|
|
|
aCssText.Append(NS_LITERAL_STRING(")"));
|
|
|
|
if (mMedia) {
|
|
|
|
nsAutoString mediaText;
|
2001-09-05 04:00:18 +04:00
|
|
|
mMedia->GetText(mediaText);
|
2001-08-05 01:19:53 +04:00
|
|
|
if (!mediaText.IsEmpty()) {
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(" ");
|
2001-08-05 01:19:53 +04:00
|
|
|
aCssText.Append(mediaText);
|
|
|
|
}
|
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(";");
|
2001-05-15 12:26:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
2001-08-05 01:19:53 +04:00
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetHref(nsAString & aHref)
|
2001-08-05 01:19:53 +04:00
|
|
|
{
|
|
|
|
aHref = mURLSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetMedia(nsIDOMMediaList * *aMedia)
|
2001-08-05 01:19:53 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
|
|
|
|
2010-07-19 00:23:12 +04:00
|
|
|
NS_IF_ADDREF(*aMedia = mMedia);
|
|
|
|
return NS_OK;
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
ImportRule::GetStyleSheet(nsIDOMCSSStyleSheet * *aStyleSheet)
|
2001-08-05 01:19:53 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aStyleSheet);
|
|
|
|
|
2010-06-01 03:51:40 +04:00
|
|
|
NS_IF_ADDREF(*aStyleSheet = mChildSheet);
|
|
|
|
return NS_OK;
|
2001-08-05 01:19:53 +04:00
|
|
|
}
|
2001-05-15 12:26:13 +04:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// must be outside the namespace
|
|
|
|
DOMCI_DATA(CSSImportRule, css::ImportRule)
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
static PRBool
|
2011-04-08 05:23:46 +04:00
|
|
|
CloneRuleInto(css::Rule* aRule, void* aArray)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> clone = aRule->Clone();
|
|
|
|
static_cast<nsCOMArray<css::Rule>*>(aArray)->AppendObject(clone);
|
1999-06-10 09:32:38 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
|
|
|
GroupRule::GroupRule()
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule()
|
2010-08-08 09:28:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-09-20 06:38:56 +04:00
|
|
|
static PRBool
|
2011-04-08 05:23:46 +04:00
|
|
|
SetParentRuleReference(Rule* aRule, void* aParentRule)
|
2001-09-19 18:16:34 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule* parentRule = static_cast<GroupRule*>(aParentRule);
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->SetParentRule(parentRule);
|
2001-09-19 18:16:34 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::GroupRule(const GroupRule& aCopy)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(aCopy)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
const_cast<GroupRule&>(aCopy).mRules.EnumerateForwards(CloneRuleInto, &mRules);
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, this);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::~GroupRule()
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-05-03 05:43:44 +04:00
|
|
|
NS_ABORT_IF_FALSE(!mSheet, "SetStyleSheet should have been called");
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.EnumerateForwards(SetParentRuleReference, nsnull);
|
2001-09-05 04:00:18 +04:00
|
|
|
if (mRuleCollection) {
|
|
|
|
mRuleCollection->DropReference();
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 10:18:43 +04:00
|
|
|
IMPL_STYLE_RULE_INHERIT_MAP_RULE_INFO_INTO(GroupRule, Rule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
static PRBool
|
2011-04-08 05:23:46 +04:00
|
|
|
SetStyleSheetReference(Rule* aRule, void* aSheet)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2010-05-12 00:41:47 +04:00
|
|
|
nsCSSStyleSheet* sheet = (nsCSSStyleSheet*)aSheet;
|
2005-10-16 00:21:20 +04:00
|
|
|
aRule->SetStyleSheet(sheet);
|
1999-06-10 09:32:38 +04:00
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ void
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.EnumerateForwards(SetStyleSheetReference, aSheet);
|
2011-03-07 06:59:03 +03:00
|
|
|
Rule::SetStyleSheet(aSheet);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::List(FILE* out, PRInt32 aIndent) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
fputs(" {\n", out);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
|
|
|
|
mRules.ObjectAt(index)->List(out, aIndent + 1);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
fputs("}\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-08-08 09:29:28 +04:00
|
|
|
void
|
2011-04-08 05:23:46 +04:00
|
|
|
GroupRule::AppendStyleRule(Rule* aRule)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.AppendObject(aRule);
|
|
|
|
aRule->SetStyleSheet(mSheet);
|
|
|
|
aRule->SetParentRule(this);
|
|
|
|
if (mSheet) {
|
2011-04-12 10:18:43 +04:00
|
|
|
mSheet->SetModifiedByChildRule();
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
Rule*
|
2010-08-08 09:29:28 +04:00
|
|
|
GroupRule::GetStyleRuleAt(PRInt32 aIndex) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2010-08-08 09:29:28 +04:00
|
|
|
return mRules.SafeObjectAt(aIndex);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:29:28 +04:00
|
|
|
PRBool
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::EnumerateRulesForwards(RuleEnumFunc aFunc, void * aData) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2007-12-15 01:59:20 +03:00
|
|
|
return
|
2010-08-08 09:28:33 +04:00
|
|
|
const_cast<GroupRule*>(this)->mRules.EnumerateForwards(aFunc, aData);
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
/*
|
2001-09-06 17:14:35 +04:00
|
|
|
* The next two methods (DeleteStyleRuleAt and InsertStyleRulesAt)
|
2001-09-05 04:00:18 +04:00
|
|
|
* should never be called unless you have first called WillDirty() on
|
|
|
|
* the parents tylesheet. After they are called, DidDirty() needs to
|
|
|
|
* be called on the sheet
|
|
|
|
*/
|
2010-08-08 09:29:28 +04:00
|
|
|
nsresult
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::DeleteStyleRuleAt(PRUint32 aIndex)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
Rule* rule = mRules.SafeObjectAt(aIndex);
|
2001-09-06 17:14:35 +04:00
|
|
|
if (rule) {
|
|
|
|
rule->SetStyleSheet(nsnull);
|
2001-09-19 18:16:34 +04:00
|
|
|
rule->SetParentRule(nsnull);
|
2001-09-06 17:14:35 +04:00
|
|
|
}
|
2005-10-16 00:21:20 +04:00
|
|
|
return mRules.RemoveObjectAt(aIndex) ? NS_OK : NS_ERROR_ILLEGAL_VALUE;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:29:28 +04:00
|
|
|
nsresult
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::InsertStyleRulesAt(PRUint32 aIndex,
|
2011-04-08 05:23:46 +04:00
|
|
|
nsCOMArray<Rule>& aRules)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
aRules.EnumerateForwards(SetStyleSheetReference, mSheet);
|
|
|
|
aRules.EnumerateForwards(SetParentRuleReference, this);
|
|
|
|
if (! mRules.InsertObjectsAt(aRules, aIndex)) {
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-08-08 09:29:28 +04:00
|
|
|
nsresult
|
2011-04-08 05:23:46 +04:00
|
|
|
GroupRule::ReplaceStyleRule(Rule* aOld, Rule* aNew)
|
2003-06-18 05:59:57 +04:00
|
|
|
{
|
2005-10-16 00:21:20 +04:00
|
|
|
PRInt32 index = mRules.IndexOf(aOld);
|
2003-06-18 05:59:57 +04:00
|
|
|
NS_ENSURE_TRUE(index != -1, NS_ERROR_UNEXPECTED);
|
2005-10-16 00:21:20 +04:00
|
|
|
mRules.ReplaceObjectAt(aNew, index);
|
2003-06-18 05:59:57 +04:00
|
|
|
aNew->SetStyleSheet(mSheet);
|
|
|
|
aNew->SetParentRule(this);
|
|
|
|
aOld->SetStyleSheet(nsnull);
|
|
|
|
aOld->SetParentRule(nsnull);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
|
|
|
|
nsresult
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::AppendRulesToCssText(nsAString& aCssText)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral(" {\n");
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
// get all the rules
|
2005-10-16 00:21:20 +04:00
|
|
|
for (PRInt32 index = 0, count = mRules.Count(); index < count; ++index) {
|
2011-04-08 05:23:46 +04:00
|
|
|
Rule* rule = mRules.ObjectAt(index);
|
2011-04-08 10:36:09 +04:00
|
|
|
nsIDOMCSSRule* domRule = rule->GetDOMRule();
|
2005-10-16 00:21:20 +04:00
|
|
|
if (domRule) {
|
|
|
|
nsAutoString cssText;
|
|
|
|
domRule->GetCssText(cssText);
|
|
|
|
aCssText.Append(NS_LITERAL_STRING(" ") +
|
|
|
|
cssText +
|
|
|
|
NS_LITERAL_STRING("\n"));
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("}");
|
2001-05-15 12:26:13 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// nsIDOMCSSMediaRule or nsIDOMCSSMozDocumentRule methods
|
2011-04-12 06:46:35 +04:00
|
|
|
nsresult
|
|
|
|
GroupRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
if (!mRuleCollection) {
|
2010-08-08 09:23:17 +04:00
|
|
|
mRuleCollection = new css::GroupRuleRuleList(this);
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
NS_ADDREF(*aRuleList = mRuleCollection);
|
|
|
|
return NS_OK;
|
2001-09-05 04:00:18 +04:00
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
if (aIndex > PRUint32(mRules.Count()))
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
2005-10-16 00:21:20 +04:00
|
|
|
|
|
|
|
NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return mSheet->InsertRuleIntoGroup(aRule, this, aIndex, _retval);
|
|
|
|
}
|
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
nsresult
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::DeleteRule(PRUint32 aIndex)
|
2001-09-05 04:00:18 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_TRUE(mSheet, NS_ERROR_FAILURE);
|
2005-10-16 00:21:20 +04:00
|
|
|
|
|
|
|
if (aIndex >= PRUint32(mRules.Count()))
|
2001-09-05 04:00:18 +04:00
|
|
|
return NS_ERROR_DOM_INDEX_SIZE_ERR;
|
|
|
|
|
2005-10-16 00:21:20 +04:00
|
|
|
NS_ASSERTION(PRUint32(mRules.Count()) <= PR_INT32_MAX,
|
|
|
|
"Too many style rules!");
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
return mSheet->DeleteRuleFromGroup(this, aIndex);
|
|
|
|
}
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
// -------------------------------------------
|
|
|
|
// nsICSSMediaRule
|
|
|
|
//
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::MediaRule()
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::MediaRule(const MediaRule& aCopy)
|
2010-08-08 09:28:33 +04:00
|
|
|
: GroupRule(aCopy)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
if (aCopy.mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
aCopy.mMedia->Clone(getter_AddRefs(mMedia));
|
|
|
|
if (mMedia) {
|
|
|
|
// XXXldb This doesn't really make sense.
|
|
|
|
mMedia->SetStyleSheet(aCopy.mSheet);
|
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::~MediaRule()
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia->SetStyleSheet(nsnull);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-05-06 11:33:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(MediaRule, GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(MediaRule, GroupRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
// QueryInterface implementation for MediaRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(MediaRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMediaRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMediaRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ void
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::SetStyleSheet(nsCSSStyleSheet* aSheet)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
// Set to null so it knows it's leaving one sheet and joining another.
|
|
|
|
mMedia->SetStyleSheet(nsnull);
|
|
|
|
mMedia->SetStyleSheet(aSheet);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::SetStyleSheet(aSheet);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::List(FILE* out, PRInt32 aIndent) const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@media ", out);
|
|
|
|
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mediaText).get(), out);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::List(out, aIndent);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetType() const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::MEDIA_RULE;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::Clone() const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new MediaRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::SetMedia(nsMediaList* aMedia)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2005-03-30 04:36:57 +04:00
|
|
|
mMedia = aMedia;
|
|
|
|
if (aMedia)
|
|
|
|
mMedia->SetStyleSheet(mSheet);
|
|
|
|
return NS_OK;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetType(PRUint16* aType)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::MEDIA_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetCssText(nsAString& aCssText)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@media ");
|
|
|
|
// get all the media
|
|
|
|
if (mMedia) {
|
2005-03-30 04:36:57 +04:00
|
|
|
nsAutoString mediaText;
|
|
|
|
mMedia->GetText(mediaText);
|
|
|
|
aCssText.Append(mediaText);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::AppendRulesToCssText(aCssText);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::SetCssText(const nsAString& aCssText)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSMediaRule methods
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetMedia(nsIDOMMediaList* *aMedia)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aMedia);
|
2010-07-19 00:23:12 +04:00
|
|
|
NS_IF_ADDREF(*aMedia = mMedia);
|
|
|
|
return NS_OK;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::InsertRule(aRule, aIndex, _retval);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::DeleteRule(PRUint32 aIndex)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::DeleteRule(aIndex);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
// GroupRule interface
|
2010-08-08 09:29:28 +04:00
|
|
|
/* virtual */ PRBool
|
2011-03-18 08:18:08 +03:00
|
|
|
MediaRule::UseForPresentation(nsPresContext* aPresContext,
|
2008-07-26 20:14:48 +04:00
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
if (mMedia) {
|
2011-04-22 07:17:31 +04:00
|
|
|
return mMedia->Matches(aPresContext, &aKey);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSMediaRule, css::MediaRule)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::DocumentRule()
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::DocumentRule(const DocumentRule& aCopy)
|
2010-08-08 09:28:33 +04:00
|
|
|
: GroupRule(aCopy)
|
2004-08-05 22:26:14 +04:00
|
|
|
, mURLs(new URL(*aCopy.mURLs))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::~DocumentRule()
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-05-06 11:33:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(DocumentRule, GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(DocumentRule, GroupRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
// QueryInterface implementation for DocumentRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(DocumentRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSMozDocumentRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSMozDocumentRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::List(FILE* out, PRInt32 aIndent) const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsCAutoString str;
|
|
|
|
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-13 05:52:32 +04:00
|
|
|
break;
|
2011-04-28 21:21:37 +04:00
|
|
|
case eRegExp:
|
|
|
|
str.AppendLiteral("regexp(\"");
|
2004-08-05 22:26:14 +04:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
nsCAutoString escapedURL(url->url);
|
|
|
|
escapedURL.ReplaceSubstring("\"", "\\\""); // escape quotes
|
|
|
|
str.Append(escapedURL);
|
|
|
|
str.AppendLiteral("\"), ");
|
|
|
|
}
|
|
|
|
str.Cut(str.Length() - 2, 1); // remove last ,
|
|
|
|
fputs(str.get(), out);
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
GroupRule::List(out, aIndent);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetType() const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::DOCUMENT_RULE;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::Clone() const
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new DocumentRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSRule methods
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetType(PRUint16* aType)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
// XXX What should really happen here?
|
|
|
|
*aType = nsIDOMCSSRule::UNKNOWN_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetCssText(nsAString& aCssText)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@-moz-document ");
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL:
|
2009-03-06 07:05:01 +03:00
|
|
|
aCssText.AppendLiteral("url(");
|
2004-08-05 22:26:14 +04:00
|
|
|
break;
|
|
|
|
case eURLPrefix:
|
2009-03-06 07:05:01 +03:00
|
|
|
aCssText.AppendLiteral("url-prefix(");
|
2004-08-05 22:26:14 +04:00
|
|
|
break;
|
|
|
|
case eDomain:
|
2009-03-06 07:05:01 +03:00
|
|
|
aCssText.AppendLiteral("domain(");
|
2004-08-05 22:26:14 +04:00
|
|
|
break;
|
2011-04-28 21:21:37 +04:00
|
|
|
case eRegExp:
|
|
|
|
aCssText.AppendLiteral("regexp(");
|
|
|
|
break;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
2009-03-06 07:05:01 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(NS_ConvertUTF8toUTF16(url->url),
|
|
|
|
aCssText);
|
|
|
|
aCssText.AppendLiteral("), ");
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
aCssText.Cut(aCssText.Length() - 2, 1); // remove last ,
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::AppendRulesToCssText(aCssText);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::SetCssText(const nsAString& aCssText)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::InsertRule(const nsAString & aRule, PRUint32 aIndex, PRUint32* _retval)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::InsertRule(aRule, aIndex, _retval);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::DeleteRule(PRUint32 aIndex)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2010-08-08 09:28:33 +04:00
|
|
|
return GroupRule::DeleteRule(aIndex);
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
|
2010-08-08 09:28:33 +04:00
|
|
|
// GroupRule interface
|
2010-08-08 09:29:28 +04:00
|
|
|
/* virtual */ PRBool
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::UseForPresentation(nsPresContext* aPresContext,
|
2011-04-28 21:21:37 +04:00
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
2004-08-05 22:26:14 +04:00
|
|
|
{
|
2011-04-28 21:21:37 +04:00
|
|
|
nsIDocument *doc = aPresContext->Document();
|
|
|
|
nsIURI *docURI = doc->GetDocumentURI();
|
2004-08-05 22:26:14 +04:00
|
|
|
nsCAutoString docURISpec;
|
|
|
|
if (docURI)
|
|
|
|
docURI->GetSpec(docURISpec);
|
|
|
|
|
|
|
|
for (URL *url = mURLs; url; url = url->next) {
|
|
|
|
switch (url->func) {
|
|
|
|
case eURL: {
|
|
|
|
if (docURISpec == url->url)
|
|
|
|
return PR_TRUE;
|
|
|
|
} break;
|
|
|
|
case eURLPrefix: {
|
|
|
|
if (StringBeginsWith(docURISpec, url->url))
|
|
|
|
return PR_TRUE;
|
|
|
|
} break;
|
|
|
|
case eDomain: {
|
|
|
|
nsCAutoString host;
|
|
|
|
if (docURI)
|
|
|
|
docURI->GetHost(host);
|
|
|
|
PRInt32 lenDiff = host.Length() - url->url.Length();
|
|
|
|
if (lenDiff == 0) {
|
|
|
|
if (host == url->url)
|
|
|
|
return PR_TRUE;
|
|
|
|
} else {
|
|
|
|
if (StringEndsWith(host, url->url) &&
|
|
|
|
host.CharAt(lenDiff - 1) == '.')
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} break;
|
2011-04-28 21:21:37 +04:00
|
|
|
case eRegExp: {
|
|
|
|
NS_ConvertUTF8toUTF16 spec(docURISpec);
|
|
|
|
NS_ConvertUTF8toUTF16 regex(url->url);
|
|
|
|
if (nsContentUtils::IsPatternMatching(spec, regex, doc)) {
|
|
|
|
return PR_TRUE;
|
|
|
|
}
|
|
|
|
} break;
|
2004-08-05 22:26:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
DocumentRule::URL::~URL()
|
2009-01-17 02:33:57 +03:00
|
|
|
{
|
2011-03-18 08:18:08 +03:00
|
|
|
NS_CSS_DELETE_LIST_MEMBER(DocumentRule::URL, this, next);
|
2009-01-17 02:33:57 +03:00
|
|
|
}
|
2004-08-05 22:26:14 +04:00
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSMozDocumentRule, css::DocumentRule)
|
|
|
|
|
1999-06-10 09:32:38 +04:00
|
|
|
// -------------------------------------------
|
2011-03-17 20:41:52 +03:00
|
|
|
// NameSpaceRule
|
1999-06-10 09:32:38 +04:00
|
|
|
//
|
2011-03-17 20:41:52 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace css {
|
|
|
|
|
2011-03-23 08:23:04 +03:00
|
|
|
NameSpaceRule::NameSpaceRule(nsIAtom* aPrefix, const nsString& aURLSpec)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(),
|
2011-03-23 08:23:04 +03:00
|
|
|
mPrefix(aPrefix),
|
|
|
|
mURLSpec(aURLSpec)
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::NameSpaceRule(const NameSpaceRule& aCopy)
|
2011-03-07 06:59:03 +03:00
|
|
|
: Rule(aCopy),
|
1999-06-10 09:32:38 +04:00
|
|
|
mPrefix(aCopy.mPrefix),
|
|
|
|
mURLSpec(aCopy.mURLSpec)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::~NameSpaceRule()
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-03-18 08:18:08 +03:00
|
|
|
NS_IMPL_ADDREF_INHERITED(NameSpaceRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(NameSpaceRule, Rule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
// QueryInterface implementation for NameSpaceRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(NameSpaceRule)
|
2011-03-17 20:41:52 +03:00
|
|
|
if (aIID.Equals(NS_GET_IID(css::NameSpaceRule))) {
|
|
|
|
*aInstancePtr = this;
|
|
|
|
NS_ADDREF_THIS();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSNameSpaceRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2011-03-07 06:59:03 +03:00
|
|
|
IMPL_STYLE_RULE_INHERIT(NameSpaceRule, Rule)
|
1999-06-10 09:32:38 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
/* virtual */ void
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::List(FILE* out, PRInt32 aIndent) const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
nsAutoString buffer;
|
|
|
|
|
|
|
|
fputs("@namespace ", out);
|
|
|
|
|
|
|
|
if (mPrefix) {
|
|
|
|
mPrefix->ToString(buffer);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(buffer).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs(" ", out);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputs("url(", out);
|
2006-02-03 17:18:39 +03:00
|
|
|
fputs(NS_LossyConvertUTF16toASCII(mURLSpec).get(), out);
|
1999-06-10 09:32:38 +04:00
|
|
|
fputs(")\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::GetType() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
return Rule::NAMESPACE_RULE;
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<Rule>
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::Clone() const
|
1999-06-10 09:32:38 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<Rule> clone = new NameSpaceRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
1999-06-10 09:32:38 +04:00
|
|
|
}
|
|
|
|
|
2001-05-15 12:26:13 +04:00
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::GetType(PRUint16* aType)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-08-05 22:26:14 +04:00
|
|
|
// XXX What should really happen here?
|
2001-05-15 12:26:13 +04:00
|
|
|
*aType = nsIDOMCSSRule::UNKNOWN_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::GetCssText(nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AssignLiteral("@namespace ");
|
2001-05-15 12:26:13 +04:00
|
|
|
if (mPrefix) {
|
2010-03-08 18:45:00 +03:00
|
|
|
aCssText.Append(nsDependentAtomString(mPrefix) + NS_LITERAL_STRING(" "));
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
2004-06-17 04:13:25 +04:00
|
|
|
aCssText.AppendLiteral("url(");
|
2009-03-06 07:05:01 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(mURLSpec, aCssText);
|
2001-05-15 12:26:13 +04:00
|
|
|
aCssText.Append(NS_LITERAL_STRING(");"));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::SetCssText(const nsAString& aCssText)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::GetParentStyleSheet(nsIDOMCSSStyleSheet** aSheet)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-03-17 20:41:52 +03:00
|
|
|
NameSpaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
2001-05-15 12:26:13 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2001-05-15 12:26:13 +04:00
|
|
|
}
|
2008-08-08 03:15:40 +04:00
|
|
|
|
2011-03-17 20:41:52 +03:00
|
|
|
} // namespace css
|
|
|
|
} // namespace mozilla
|
|
|
|
|
|
|
|
// Must be outside namespace
|
|
|
|
DOMCI_DATA(CSSNameSpaceRule, css::NameSpaceRule)
|
|
|
|
|
2008-08-08 03:15:40 +04: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
|
2009-03-10 02:14:34 +03:00
|
|
|
AppendSerializedFontSrc(const nsCSSValue& src, nsAString & aResult NS_OUTPARAM)
|
2008-08-08 03:15:40 +04:00
|
|
|
{
|
2009-03-10 02:14:34 +03:00
|
|
|
NS_PRECONDITION(src.GetUnit() == eCSSUnit_Array,
|
2008-08-08 03:15:40 +04:00
|
|
|
"improper value unit for src:");
|
|
|
|
|
|
|
|
const nsCSSValue::Array& sources = *src.GetArrayValue();
|
2010-06-25 23:38:57 +04:00
|
|
|
size_t i = 0;
|
2008-08-08 03:15:40 +04:00
|
|
|
|
|
|
|
while (i < sources.Count()) {
|
|
|
|
nsAutoString formats;
|
|
|
|
|
|
|
|
if (sources[i].GetUnit() == eCSSUnit_URL) {
|
2009-03-06 07:05:00 +03:00
|
|
|
aResult.AppendLiteral("url(");
|
2008-08-08 03:15:40 +04:00
|
|
|
nsDependentString url(sources[i].GetOriginalURLValue());
|
2009-03-06 07:05:00 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(url, aResult);
|
|
|
|
aResult.AppendLiteral(")");
|
2008-08-08 03:15:40 +04:00
|
|
|
} else if (sources[i].GetUnit() == eCSSUnit_Local_Font) {
|
2009-03-06 07:05:00 +03:00
|
|
|
aResult.AppendLiteral("local(");
|
2008-08-08 03:15:40 +04:00
|
|
|
nsDependentString local(sources[i].GetStringBufferValue());
|
2009-03-06 07:05:00 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(local, aResult);
|
|
|
|
aResult.AppendLiteral(")");
|
2008-08-08 03:15:40 +04: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-21 01:52:47 +04:00
|
|
|
// print all characters with at least four hex digits
|
|
|
|
static void
|
|
|
|
AppendSerializedUnicodePoint(PRUint32 aCode, nsACString &aBuf NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
nsAString & aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
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();
|
|
|
|
nsCAutoString buf;
|
|
|
|
|
|
|
|
NS_ABORT_IF_FALSE(sources.Count() % 2 == 0,
|
|
|
|
"odd number of entries in a unicode-range: array");
|
|
|
|
|
|
|
|
for (PRUint32 i = 0; i < sources.Count(); i += 2) {
|
|
|
|
PRUint32 min = sources[i].GetIntValue();
|
|
|
|
PRUint32 max = sources[i+1].GetIntValue();
|
|
|
|
|
|
|
|
// 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-08 03:15:40 +04:00
|
|
|
// Mapping from nsCSSFontDesc codes to nsCSSFontFaceStyleDecl fields.
|
|
|
|
// Keep this in sync with enum nsCSSFontDesc in nsCSSProperty.h.
|
|
|
|
nsCSSValue nsCSSFontFaceStyleDecl::* const
|
|
|
|
nsCSSFontFaceStyleDecl::Fields[] = {
|
|
|
|
&nsCSSFontFaceStyleDecl::mFamily,
|
|
|
|
&nsCSSFontFaceStyleDecl::mStyle,
|
|
|
|
&nsCSSFontFaceStyleDecl::mWeight,
|
|
|
|
&nsCSSFontFaceStyleDecl::mStretch,
|
|
|
|
&nsCSSFontFaceStyleDecl::mSrc,
|
2010-07-14 00:30:42 +04:00
|
|
|
&nsCSSFontFaceStyleDecl::mUnicodeRange,
|
|
|
|
&nsCSSFontFaceStyleDecl::mFontFeatureSettings,
|
|
|
|
&nsCSSFontFaceStyleDecl::mFontLanguageOverride
|
2008-08-08 03:15:40 +04:00
|
|
|
};
|
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
DOMCI_DATA(CSSFontFaceStyleDecl, nsCSSFontFaceStyleDecl)
|
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
// QueryInterface implementation for nsCSSFontFaceStyleDecl
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSFontFaceStyleDecl)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSStyleDeclaration)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISupports)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceStyleDecl)
|
2008-08-08 03:15:40 +04: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,
|
|
|
|
nsAString & aResult NS_OUTPARAM) const
|
|
|
|
{
|
|
|
|
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-10 02:14:34 +03:00
|
|
|
if (val.GetUnit() == eCSSUnit_Null) {
|
|
|
|
// Avoid having to check no-value in the Family and Src cases below.
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
switch (aFontDescID) {
|
|
|
|
case eCSSFontDesc_Family: {
|
2010-07-23 22:00:27 +04:00
|
|
|
// we don't use nsCSSValue::AppendToString here because it doesn't
|
2008-08-08 03:15:40 +04:00
|
|
|
// canonicalize the way we want, and anyway it's overkill when
|
|
|
|
// we know we have eCSSUnit_String
|
2009-03-06 07:05:01 +03:00
|
|
|
NS_ASSERTION(val.GetUnit() == eCSSUnit_String, "unexpected unit");
|
2008-08-08 03:15:40 +04:00
|
|
|
nsDependentString family(val.GetStringBufferValue());
|
2009-03-06 07:05:00 +03:00
|
|
|
nsStyleUtil::AppendEscapedCSSString(family, aResult);
|
2008-08-08 03:15:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
case eCSSFontDesc_Style:
|
2010-07-23 22:00:27 +04:00
|
|
|
val.AppendToString(eCSSProperty_font_style, aResult);
|
2008-08-08 03:15:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_Weight:
|
2010-07-23 22:00:27 +04:00
|
|
|
val.AppendToString(eCSSProperty_font_weight, aResult);
|
2008-08-08 03:15:40 +04:00
|
|
|
return NS_OK;
|
2010-07-23 22:00:27 +04:00
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
case eCSSFontDesc_Stretch:
|
2010-07-23 22:00:27 +04:00
|
|
|
val.AppendToString(eCSSProperty_font_stretch, aResult);
|
2008-08-08 03:15:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
2010-08-23 14:32:03 +04:00
|
|
|
case eCSSFontDesc_FontFeatureSettings:
|
|
|
|
val.AppendToString(eCSSProperty_font_feature_settings, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_FontLanguageOverride:
|
|
|
|
val.AppendToString(eCSSProperty_font_language_override, aResult);
|
|
|
|
return NS_OK;
|
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
case eCSSFontDesc_Src:
|
2009-03-10 02:14:34 +03:00
|
|
|
AppendSerializedFontSrc(val, aResult);
|
2008-08-08 03:15:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
case eCSSFontDesc_UnicodeRange:
|
2009-08-21 01:52:47 +04:00
|
|
|
AppendSerializedUnicodeRange(val, aResult);
|
2008-08-08 03:15:40 +04: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,
|
|
|
|
nsAString & aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
return GetPropertyValue(nsCSSProps::LookupFontDesc(propertyName), aResult);
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIDOMCSSValue getPropertyCSSValue (in DOMString propertyName);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetPropertyCSSValue(const nsAString & propertyName,
|
|
|
|
nsIDOMCSSValue **aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
// ??? nsDOMCSSDeclaration returns null/NS_OK, but that seems wrong.
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
// DOMString removeProperty (in DOMString propertyName) raises (DOMException);
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::RemoveProperty(const nsAString & propertyName,
|
|
|
|
nsAString & aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
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,
|
|
|
|
nsAString & aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
nsCSSFontFaceStyleDecl::GetLength(PRUint32 *aLength)
|
|
|
|
{
|
|
|
|
PRUint32 len = 0;
|
|
|
|
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
|
|
|
|
nsCSSFontFaceStyleDecl::Item(PRUint32 index, nsAString & aResult NS_OUTPARAM)
|
|
|
|
{
|
|
|
|
PRInt32 nset = -1;
|
|
|
|
for (nsCSSFontDesc id = nsCSSFontDesc(eCSSFontDesc_UNKNOWN + 1);
|
|
|
|
id < eCSSFontDesc_COUNT;
|
|
|
|
id = nsCSSFontDesc(id + 1)) {
|
|
|
|
if ((this->*nsCSSFontFaceStyleDecl::Fields[id]).GetUnit()
|
|
|
|
!= eCSSUnit_Null) {
|
|
|
|
nset++;
|
|
|
|
if (nset == PRInt32(index)) {
|
|
|
|
aResult.AssignASCII(nsCSSProps::GetStringValue(id).get());
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
aResult.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// readonly attribute nsIDOMCSSRule parentRule;
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceStyleDecl::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-08 10:36:09 +04:00
|
|
|
NS_IF_ADDREF(*aParentRule = ContainingRule()->GetDOMRule());
|
|
|
|
return NS_OK;
|
2008-08-08 03:15:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSFontFaceRule
|
|
|
|
//
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2010-08-15 19:19:34 +04:00
|
|
|
nsCSSFontFaceRule::Clone() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSFontFaceRule(*this);
|
2010-08-15 19:19:34 +04:00
|
|
|
return clone.forget();
|
2008-08-08 03:15:40 +04:00
|
|
|
}
|
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSFontFaceRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSFontFaceRule, Rule)
|
2008-08-08 03:15:40 +04:00
|
|
|
|
2010-01-12 16:08:43 +03:00
|
|
|
DOMCI_DATA(CSSFontFaceRule, nsCSSFontFaceRule)
|
|
|
|
|
2008-08-08 03:15:40 +04:00
|
|
|
// QueryInterface implementation for nsCSSFontFaceRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSFontFaceRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSFontFaceRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2010-03-17 18:09:05 +03:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(CSSFontFaceRule)
|
2008-08-08 03:15:40 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2011-03-07 06:59:03 +03:00
|
|
|
IMPL_STYLE_RULE_INHERIT(nsCSSFontFaceRule, Rule)
|
2008-08-08 03:15:40 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG
|
2010-05-20 06:28:00 +04:00
|
|
|
void
|
2008-08-08 03:15:40 +04:00
|
|
|
nsCSSFontFaceRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
nsCString baseInd, descInd;
|
|
|
|
for (PRInt32 indent = aIndent; --indent >= 0; ) {
|
|
|
|
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
|
|
|
|
|
2010-07-18 18:39:20 +04:00
|
|
|
/* virtual */ PRInt32
|
|
|
|
nsCSSFontFaceRule::GetType() const
|
2008-08-08 03:15:40 +04:00
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::FONT_FACE_RULE;
|
2008-08-08 03:15:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*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-12 06:46:35 +04:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2008-08-08 03:15:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2008-08-08 03:15:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSFontFaceRule::GetStyle(nsIDOMCSSStyleDeclaration** aStyle)
|
|
|
|
{
|
2010-07-19 00:23:12 +04:00
|
|
|
NS_IF_ADDREF(*aStyle = &mDecl);
|
|
|
|
return NS_OK;
|
2008-08-08 03:15:40 +04: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-12 10:18:43 +04:00
|
|
|
// FIXME: handle dynamic changes
|
|
|
|
|
2008-08-08 03:15:40 +04: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-12 10:18:43 +04:00
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSKeyframeStyleDeclaration
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSKeyframeStyleDeclaration::nsCSSKeyframeStyleDeclaration(nsCSSKeyframeRule *aRule)
|
|
|
|
: mRule(aRule)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeyframeStyleDeclaration::~nsCSSKeyframeStyleDeclaration()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mRule, "DropReference not called.");
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsCSSKeyframeStyleDeclaration)
|
|
|
|
NS_IMPL_RELEASE(nsCSSKeyframeStyleDeclaration)
|
|
|
|
|
|
|
|
css::Declaration*
|
|
|
|
nsCSSKeyframeStyleDeclaration::GetCSSDeclaration(PRBool aAllocate)
|
|
|
|
{
|
|
|
|
if (mRule) {
|
|
|
|
return mRule->Declaration();
|
|
|
|
} else {
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-28 00:53:49 +04:00
|
|
|
void
|
|
|
|
nsCSSKeyframeStyleDeclaration::GetCSSParsingEnvironment(CSSParsingEnvironment& aCSSParseEnv)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
2011-04-28 00:53:49 +04:00
|
|
|
GetCSSParsingEnvironmentForRule(mRule, aCSSParseEnv);
|
2011-04-12 10:18:43 +04: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()
|
|
|
|
{
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
// -------------------------------------------
|
|
|
|
// nsCSSKeyframeRule
|
|
|
|
//
|
|
|
|
|
|
|
|
nsCSSKeyframeRule::nsCSSKeyframeRule(const nsCSSKeyframeRule& aCopy)
|
|
|
|
// copy everything except our reference count and mDOMDeclaration
|
|
|
|
: Rule(aCopy)
|
|
|
|
, mKeys(aCopy.mKeys)
|
2011-04-12 06:46:35 +04:00
|
|
|
, mDeclaration(new css::Declaration(*aCopy.mDeclaration))
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCSSKeyframeRule::~nsCSSKeyframeRule()
|
|
|
|
{
|
|
|
|
if (mDOMDeclaration) {
|
|
|
|
mDOMDeclaration->DropReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSKeyframeRule::Clone() const
|
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSKeyframeRule(*this);
|
2011-04-12 10:18:43 +04:00
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
2011-05-06 11:33:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSKeyframeRule, Rule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSKeyframeRule, Rule)
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
DOMCI_DATA(MozCSSKeyframeRule, nsCSSKeyframeRule)
|
|
|
|
|
|
|
|
// QueryInterface implementation for nsCSSKeyframeRule
|
|
|
|
NS_INTERFACE_MAP_BEGIN(nsCSSKeyframeRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStyleRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMMozCSSKeyframeRule)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMCSSRule)
|
2011-04-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2011-04-12 10:18:43 +04: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.
|
|
|
|
|
|
|
|
// FIXME (spec): The spec doesn't say what to do with !important.
|
|
|
|
// We'll just map them.
|
|
|
|
if (mDeclaration->HasImportantData()) {
|
|
|
|
mDeclaration->MapImportantRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
mDeclaration->MapNormalRuleInfoInto(aRuleData);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSKeyframeRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// FIXME: WRITE ME
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ PRInt32
|
|
|
|
nsCSSKeyframeRule::GetType() const
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::KEYFRAME_RULE;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::MOZ_KEYFRAME_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
nsCSSKeyframeRule::GetKeyText(aCssText);
|
|
|
|
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-12 06:46:35 +04:00
|
|
|
return Rule::GetParentStyleSheet(aSheet);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::GetParentRule(aParentRule);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::GetKeyText(nsAString& aKeyText)
|
|
|
|
{
|
|
|
|
aKeyText.Truncate();
|
|
|
|
PRUint32 i = 0, i_end = mKeys.Length();
|
|
|
|
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(", ");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframeRule::SetKeyText(const nsAString& aKeyText)
|
|
|
|
{
|
|
|
|
nsCSSParser parser;
|
|
|
|
|
|
|
|
nsTArray<float> newSelectors;
|
|
|
|
// FIXME: pass filename and line number
|
|
|
|
if (parser.ParseKeyframeSelectorString(aKeyText, nsnull, 0, newSelectors)) {
|
|
|
|
newSelectors.SwapElements(mKeys);
|
|
|
|
} else {
|
|
|
|
// for now, we don't do anything if the parse fails
|
|
|
|
}
|
|
|
|
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->SetModifiedByChildRule();
|
|
|
|
}
|
2011-04-12 10:18:43 +04: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-12 06:46:35 +04:00
|
|
|
nsCSSKeyframeRule::ChangeDeclaration(css::Declaration* aDeclaration)
|
2011-04-12 10:18:43 +04:00
|
|
|
{
|
|
|
|
mDeclaration = aDeclaration;
|
|
|
|
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->SetModifiedByChildRule();
|
|
|
|
}
|
2011-04-12 10:18:43 +04: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-08 05:23:46 +04:00
|
|
|
/* virtual */ already_AddRefed<css::Rule>
|
2011-04-12 10:18:43 +04:00
|
|
|
nsCSSKeyframesRule::Clone() const
|
|
|
|
{
|
2011-04-08 05:23:46 +04:00
|
|
|
nsRefPtr<css::Rule> clone = new nsCSSKeyframesRule(*this);
|
2011-04-12 10:18:43 +04:00
|
|
|
return clone.forget();
|
|
|
|
}
|
|
|
|
|
2011-04-12 06:46:35 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsCSSKeyframesRule, css::GroupRule)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsCSSKeyframesRule, css::GroupRule)
|
2011-04-12 10:18:43 +04: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-08 05:23:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStyleRule)
|
2011-04-12 10:18:43 +04:00
|
|
|
NS_DOM_INTERFACE_MAP_ENTRY_CLASSINFO(MozCSSKeyframesRule)
|
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
void
|
|
|
|
nsCSSKeyframesRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// FIXME: WRITE ME
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/* virtual */ PRInt32
|
|
|
|
nsCSSKeyframesRule::GetType() const
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return Rule::KEYFRAMES_RULE;
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetType(PRUint16* aType)
|
|
|
|
{
|
|
|
|
*aType = nsIDOMCSSRule::MOZ_KEYFRAMES_RULE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetCssText(nsAString& aCssText)
|
|
|
|
{
|
|
|
|
aCssText.AssignLiteral("@-moz-keyframes ");
|
|
|
|
aCssText.Append(mName);
|
|
|
|
aCssText.AppendLiteral(" {\n");
|
|
|
|
nsAutoString tmp;
|
|
|
|
for (PRUint32 i = 0, i_end = mRules.Count(); i != i_end; ++i) {
|
|
|
|
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-12 06:46:35 +04:00
|
|
|
return GroupRule::GetParentStyleSheet(aSheet);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetParentRule(nsIDOMCSSRule** aParentRule)
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetParentRule(aParentRule);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetName(nsAString& aName)
|
|
|
|
{
|
|
|
|
aName = mName;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::SetName(const nsAString& aName)
|
|
|
|
{
|
|
|
|
mName = aName;
|
|
|
|
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->SetModifiedByChildRule();
|
|
|
|
}
|
2011-04-12 10:18:43 +04:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::GetCssRules(nsIDOMCSSRuleList* *aRuleList)
|
|
|
|
{
|
2011-04-12 06:46:35 +04:00
|
|
|
return GroupRule::GetCssRules(aRuleList);
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::InsertRule(const nsAString& aRule)
|
|
|
|
{
|
|
|
|
// 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 =
|
|
|
|
parser.ParseKeyframeRule(aRule, nsnull, 0);
|
|
|
|
if (rule) {
|
|
|
|
mRules.AppendObject(rule);
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->SetModifiedByChildRule();
|
|
|
|
}
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const PRUint32 RULE_NOT_FOUND = PRUint32(-1);
|
|
|
|
|
|
|
|
PRUint32
|
|
|
|
nsCSSKeyframesRule::FindRuleIndexForKey(const nsAString& aKey)
|
|
|
|
{
|
|
|
|
nsCSSParser parser;
|
|
|
|
|
|
|
|
nsTArray<float> keys;
|
|
|
|
// FIXME: pass filename and line number
|
|
|
|
if (parser.ParseKeyframeSelectorString(aKey, nsnull, 0, keys)) {
|
|
|
|
// 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
|
|
|
|
for (PRUint32 i = mRules.Count(); i-- != 0; ) {
|
|
|
|
if (static_cast<nsCSSKeyframeRule*>(mRules[i])->GetKeys() == keys) {
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return RULE_NOT_FOUND;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::DeleteRule(const nsAString& aKey)
|
|
|
|
{
|
|
|
|
PRUint32 index = FindRuleIndexForKey(aKey);
|
|
|
|
if (index != RULE_NOT_FOUND) {
|
|
|
|
mRules.RemoveObjectAt(index);
|
2011-05-03 05:43:44 +04:00
|
|
|
if (mSheet) {
|
|
|
|
mSheet->SetModifiedByChildRule();
|
|
|
|
}
|
2011-04-12 10:18:43 +04:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsCSSKeyframesRule::FindRule(const nsAString& aKey,
|
|
|
|
nsIDOMMozCSSKeyframeRule** aResult)
|
|
|
|
{
|
|
|
|
PRUint32 index = FindRuleIndexForKey(aKey);
|
|
|
|
if (index == RULE_NOT_FOUND) {
|
|
|
|
*aResult = nsnull;
|
|
|
|
} else {
|
|
|
|
NS_ADDREF(*aResult = static_cast<nsCSSKeyframeRule*>(mRules[index]));
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// GroupRule interface
|
|
|
|
/* virtual */ PRBool
|
|
|
|
nsCSSKeyframesRule::UseForPresentation(nsPresContext* aPresContext,
|
|
|
|
nsMediaQueryResultCacheKey& aKey)
|
|
|
|
{
|
|
|
|
NS_ABORT_IF_FALSE(PR_FALSE, "should not be called");
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
|
|
|
|