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
|
1998-05-14 03:42:18 +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/
|
1998-05-14 03:42:18 +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.
|
1998-05-14 03:42:18 +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) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-25 05:32:19 +04:00
|
|
|
* Contributor(s):
|
2000-02-03 01:24:56 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
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 ***** */
|
1999-02-27 04:35:25 +03:00
|
|
|
|
1998-05-14 03:42:18 +04:00
|
|
|
#include "nsIHTMLCSSStyleSheet.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsIAtom.h"
|
|
|
|
#include "nsIURL.h"
|
|
|
|
#include "nsISupportsArray.h"
|
2002-11-17 18:37:56 +03:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2005-01-12 22:45:38 +03:00
|
|
|
#include "nsIStyledContent.h"
|
1998-05-14 03:42:18 +04:00
|
|
|
#include "nsIStyleRule.h"
|
1998-05-19 01:11:08 +04:00
|
|
|
#include "nsIFrame.h"
|
1998-09-12 06:46:59 +04:00
|
|
|
#include "nsICSSStyleRule.h"
|
1999-10-08 07:09:31 +04:00
|
|
|
#include "nsIStyleRuleProcessor.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-11-26 04:34:53 +03:00
|
|
|
#include "nsIDocument.h"
|
2000-03-31 11:08:36 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-10-24 04:01:09 +04:00
|
|
|
#include "nsRuleWalker.h"
|
2004-07-20 10:11:27 +04:00
|
|
|
#include "nsRuleData.h"
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
/*
|
|
|
|
* The CSSFirstLetterRule and CSSFirstLineRule exist so that we can fix
|
|
|
|
* up the style data so that we don't have non-default values for the
|
|
|
|
* properties that don't apply to :first-letter and :first-line.
|
|
|
|
*
|
|
|
|
* CSSDisablePropsRule is a common base class for both the
|
|
|
|
* CSSFirstLetterRule and CSSFirstLineRule.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class CSSDisablePropsRule : public nsIStyleRule {
|
1999-04-20 04:28:40 +04:00
|
|
|
public:
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSDisablePropsRule();
|
2003-02-22 22:20:16 +03:00
|
|
|
virtual ~CSSDisablePropsRule();
|
1999-04-20 04:28:40 +04:00
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
// Call this something else so that this class still has pure virtual
|
|
|
|
// functions.
|
|
|
|
void CommonMapRuleInfoInto(nsRuleData* aRuleData);
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1999-04-20 04:28:40 +04:00
|
|
|
NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1999-04-20 04:28:40 +04:00
|
|
|
};
|
|
|
|
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSDisablePropsRule::CSSDisablePropsRule()
|
1999-04-20 04:28:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
class CSSFirstLineRule : public CSSDisablePropsRule {
|
|
|
|
public:
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSFirstLineRule() {}
|
2003-02-22 22:20:16 +03:00
|
|
|
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
|
|
|
};
|
|
|
|
|
|
|
|
class CSSFirstLetterRule : public CSSDisablePropsRule {
|
|
|
|
public:
|
2004-10-31 20:33:50 +03:00
|
|
|
CSSFirstLetterRule() {}
|
2003-02-22 22:20:16 +03:00
|
|
|
|
|
|
|
NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
|
|
|
|
};
|
|
|
|
|
|
|
|
CSSDisablePropsRule::~CSSDisablePropsRule()
|
1999-04-20 04:28:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(CSSDisablePropsRule, nsIStyleRule)
|
1999-04-20 04:28:40 +04:00
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
#ifdef DEBUG
|
1999-04-20 04:28:40 +04:00
|
|
|
NS_IMETHODIMP
|
2003-02-22 22:20:16 +03:00
|
|
|
CSSDisablePropsRule::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note: These rule mapping functions, unlike practically all others,
|
|
|
|
* will overwrite the properties even if they're not |eCSSUnit_Null|.
|
|
|
|
* This is only a partial fix for the fact that they should be higher in
|
|
|
|
* the cascade (at the very top).
|
|
|
|
*
|
|
|
|
* XXX This should be cleaned up once we implement eCSSUnit_Initial
|
|
|
|
* throughout.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void
|
|
|
|
CSSDisablePropsRule::CommonMapRuleInfoInto(nsRuleData* aData)
|
1999-04-20 04:28:40 +04:00
|
|
|
{
|
2003-02-22 22:20:16 +03:00
|
|
|
/*
|
|
|
|
* Common code for disabling the properties that apply neither to
|
|
|
|
* :first-letter nor to :first-line.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// Disable 'unicode-bidi'.
|
|
|
|
if (aData->mSID == eStyleStruct_TextReset) {
|
|
|
|
nsCSSValue normal(eCSSUnit_Normal);
|
|
|
|
aData->mTextData->mUnicodeBidi = normal;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: 'text-align', 'text-indent', and 'white-space' should not be
|
|
|
|
// handled by the frames so we don't need to bother.
|
|
|
|
|
|
|
|
// Disable everything in the nsRuleDataDisplay struct except 'float'
|
|
|
|
// and 'clear'.
|
|
|
|
if (aData->mSID == eStyleStruct_Visibility) {
|
|
|
|
nsCSSValue inherit(eCSSUnit_Inherit);
|
|
|
|
aData->mDisplayData->mVisibility = inherit;
|
|
|
|
aData->mDisplayData->mDirection = inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->mSID == eStyleStruct_Display) {
|
|
|
|
nsCSSValue none(eCSSUnit_None);
|
|
|
|
aData->mDisplayData->mAppearance = none;
|
|
|
|
|
|
|
|
nsCSSValue autovalue(eCSSUnit_Auto);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mDisplayData->mClip.mTop = autovalue;
|
|
|
|
aData->mDisplayData->mClip.mRight = autovalue;
|
|
|
|
aData->mDisplayData->mClip.mBottom = autovalue;
|
|
|
|
aData->mDisplayData->mClip.mLeft = autovalue;
|
2003-02-22 22:20:16 +03:00
|
|
|
|
2003-11-02 01:34:59 +03:00
|
|
|
nsCSSValue one(1.0f, eCSSUnit_Number);
|
|
|
|
aData->mDisplayData->mOpacity = one;
|
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
nsCSSValue inlinevalue(NS_STYLE_DISPLAY_INLINE, eCSSUnit_Enumerated);
|
|
|
|
aData->mDisplayData->mDisplay = inlinevalue;
|
|
|
|
|
|
|
|
aData->mDisplayData->mBinding = none;
|
|
|
|
|
|
|
|
nsCSSValue staticposition(NS_STYLE_POSITION_STATIC, eCSSUnit_Enumerated);
|
|
|
|
aData->mDisplayData->mPosition = staticposition;
|
|
|
|
|
|
|
|
nsCSSValue visible(NS_STYLE_OVERFLOW_VISIBLE, eCSSUnit_Enumerated);
|
2004-09-05 04:04:04 +04:00
|
|
|
aData->mDisplayData->mOverflowX = visible;
|
|
|
|
aData->mDisplayData->mOverflowY = visible;
|
2003-02-22 22:20:16 +03:00
|
|
|
|
|
|
|
// Nobody will care about 'break-before' or 'break-after', since
|
|
|
|
// they only apply to blocks (assuming we implement them correctly).
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: We'll never do anything with what's in nsCSSList,
|
|
|
|
// nsCSSTable, nsCSSBreaks, nsCSSPage, nsCSSAural, nsCSSXUL, or
|
|
|
|
// nsCSSSVG, so don't bother.
|
|
|
|
|
|
|
|
// Disable everything in the position struct.
|
|
|
|
if (aData->mSID == eStyleStruct_Position) {
|
|
|
|
nsCSSValue autovalue(eCSSUnit_Auto);
|
|
|
|
nsCSSValue none(eCSSUnit_None);
|
|
|
|
nsCSSValue zero(0.0f, eCSSUnit_Point);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mPositionData->mOffset.mTop = autovalue;
|
|
|
|
aData->mPositionData->mOffset.mRight = autovalue;
|
|
|
|
aData->mPositionData->mOffset.mBottom = autovalue;
|
|
|
|
aData->mPositionData->mOffset.mLeft = autovalue;
|
2003-02-22 22:20:16 +03:00
|
|
|
aData->mPositionData->mWidth = autovalue;
|
|
|
|
aData->mPositionData->mMinWidth = zero;
|
|
|
|
aData->mPositionData->mMaxWidth = none;
|
|
|
|
aData->mPositionData->mHeight = autovalue;
|
|
|
|
aData->mPositionData->mMinHeight = zero;
|
|
|
|
aData->mPositionData->mMaxHeight = none;
|
|
|
|
nsCSSValue content(NS_STYLE_BOX_SIZING_CONTENT, eCSSUnit_Enumerated);
|
|
|
|
aData->mPositionData->mBoxSizing = content;
|
|
|
|
aData->mPositionData->mZIndex = autovalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable everything in the Content struct.
|
|
|
|
if (aData->mSID == eStyleStruct_Content) {
|
|
|
|
// Don't bother resetting 'content'.
|
|
|
|
|
|
|
|
// Don't bother with '-moz-counter-increment' and
|
|
|
|
// '-moz-counter-reset' since they're '-moz-'ed and should be
|
|
|
|
// removed soon.
|
|
|
|
|
|
|
|
nsCSSValue autovalue(eCSSUnit_Auto);
|
|
|
|
aData->mContentData->mMarkerOffset = autovalue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->mSID == eStyleStruct_Quotes) {
|
|
|
|
// XXX |mQuotes| is a pain, because we have to have our own cursor
|
|
|
|
// structure allocated.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable everything in the UserInterface struct.
|
|
|
|
if (aData->mSID == eStyleStruct_UserInterface) {
|
|
|
|
nsCSSValue inherit(eCSSUnit_Inherit);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mUserInterfaceData->mUserInput = inherit;
|
|
|
|
aData->mUserInterfaceData->mUserModify = inherit;
|
|
|
|
aData->mUserInterfaceData->mUserFocus = inherit;
|
2003-02-22 22:20:16 +03:00
|
|
|
// XXX |mCursor| is a pain, because we have to have our own cursor
|
|
|
|
// structure allocated.
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->mSID == eStyleStruct_UIReset) {
|
|
|
|
nsCSSValue autovalue(eCSSUnit_Auto);
|
|
|
|
nsCSSValue none(eCSSUnit_None);
|
|
|
|
// Don't bother with '-moz-force-broken-image-icon' since it's only
|
|
|
|
// half a property.
|
|
|
|
// Don't bother with '-moz-user-select' because there's no way to
|
|
|
|
// specify the initial value.
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable all outline properties.
|
|
|
|
if (aData->mSID == eStyleStruct_Outline) {
|
|
|
|
nsCSSValue none(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
|
|
|
aData->mMarginData->mOutlineStyle = none;
|
1999-04-20 04:28:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-02-22 22:20:16 +03:00
|
|
|
CSSFirstLineRule::MapRuleInfoInto(nsRuleData* aData)
|
1999-04-20 04:28:40 +04:00
|
|
|
{
|
2003-02-22 22:20:16 +03:00
|
|
|
/*
|
|
|
|
* See CSS2 section 5.12.1, which says that the properties that apply
|
|
|
|
* to :first-line are: font properties, color properties, background
|
|
|
|
* properties, 'word-spacing', 'letter-spacing', 'text-decoration',
|
|
|
|
* 'vertical-align', 'text-transform', 'line-height', 'text-shadow',
|
|
|
|
* and 'clear'.
|
|
|
|
*/
|
|
|
|
|
|
|
|
CommonMapRuleInfoInto(aData);
|
|
|
|
|
|
|
|
// Disable 'float'.
|
|
|
|
if (aData->mSID == eStyleStruct_Display) {
|
|
|
|
nsCSSValue none(eCSSUnit_None);
|
|
|
|
aData->mDisplayData->mFloat = none;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Disable border properties, margin properties, and padding
|
|
|
|
// properties.
|
|
|
|
if (aData->mSID == eStyleStruct_Border) {
|
|
|
|
nsCSSValue none(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mMarginData->mBorderStyle.mTop = none;
|
|
|
|
aData->mMarginData->mBorderStyle.mRight = none;
|
|
|
|
aData->mMarginData->mBorderStyle.mBottom = none;
|
|
|
|
aData->mMarginData->mBorderStyle.mLeft = none;
|
2003-02-22 22:20:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->mSID == eStyleStruct_Margin) {
|
|
|
|
nsCSSValue zero(0.0f, eCSSUnit_Point);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mMarginData->mMargin.mTop = zero;
|
|
|
|
aData->mMarginData->mMargin.mRight = zero;
|
|
|
|
aData->mMarginData->mMargin.mBottom = zero;
|
|
|
|
aData->mMarginData->mMargin.mLeft = zero;
|
2003-02-22 22:20:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aData->mSID == eStyleStruct_Padding) {
|
|
|
|
nsCSSValue zero(0.0f, eCSSUnit_Point);
|
2003-06-08 02:14:42 +04:00
|
|
|
aData->mMarginData->mPadding.mTop = zero;
|
|
|
|
aData->mMarginData->mPadding.mRight = zero;
|
|
|
|
aData->mMarginData->mPadding.mBottom = zero;
|
|
|
|
aData->mMarginData->mPadding.mLeft = zero;
|
2003-02-22 22:20:16 +03:00
|
|
|
}
|
|
|
|
|
1999-04-20 04:28:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-03-31 11:08:36 +04:00
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
CSSFirstLetterRule::MapRuleInfoInto(nsRuleData* aData)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* See CSS2 5.12.2, which says that the properties that apply to
|
|
|
|
* :first-letter are: font properties, color properties, background
|
|
|
|
* properties, 'text-decoration', 'vertical-align' (only if 'float' is
|
|
|
|
* 'none'), 'text-transform', 'line-height', margin properties,
|
|
|
|
* padding properties, border properties, 'float', 'text-shadow', and
|
|
|
|
* 'clear'.
|
|
|
|
*/
|
1999-04-20 04:28:40 +04:00
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
CommonMapRuleInfoInto(aData);
|
1999-04-20 04:28:40 +04:00
|
|
|
|
2003-02-22 22:20:16 +03:00
|
|
|
if (aData->mSID == eStyleStruct_Text) {
|
|
|
|
nsCSSValue inherit(eCSSUnit_Inherit);
|
|
|
|
aData->mTextData->mWordSpacing = inherit;
|
|
|
|
aData->mTextData->mLetterSpacing = inherit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: 'vertical-align' is only supposed to be relevant if 'float'
|
|
|
|
// is 'none', but we don't do anything with it if 'float' is not none,
|
|
|
|
// so we don't need to disable it.
|
|
|
|
|
|
|
|
return NS_OK;
|
1999-04-20 04:28:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// -----------------------------------------------------------
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet,
|
|
|
|
public nsIStyleRuleProcessor {
|
1998-05-14 03:42:18 +04:00
|
|
|
public:
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl();
|
1998-05-14 03:42:18 +04:00
|
|
|
|
2002-10-15 03:57:17 +04:00
|
|
|
NS_DECL_ISUPPORTS
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// basic style sheet data
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
|
|
|
|
NS_IMETHOD Reset(nsIURI* aURL);
|
2004-09-10 10:45:59 +04:00
|
|
|
NS_IMETHOD GetSheetURI(nsIURI** aSheetURL) const;
|
|
|
|
NS_IMETHOD GetBaseURI(nsIURI** aBaseURL) const;
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHOD GetTitle(nsString& aTitle) const;
|
|
|
|
NS_IMETHOD GetType(nsString& aType) const;
|
|
|
|
NS_IMETHOD GetMediumCount(PRInt32& aCount) const;
|
1998-12-02 03:38:33 +03:00
|
|
|
NS_IMETHOD GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const;
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHOD_(PRBool) UseForMedium(nsIAtom* aMedium) const;
|
2003-07-04 05:44:24 +04:00
|
|
|
NS_IMETHOD_(PRBool) HasRules() const;
|
1998-11-26 04:34:53 +03:00
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHOD SetEnabled(PRBool aEnabled);
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IMETHOD GetComplete(PRBool& aComplete) const;
|
|
|
|
NS_IMETHOD SetComplete();
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const; // will be null
|
|
|
|
NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
|
|
|
|
NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
// nsIStyleRuleProcessor api
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData);
|
2001-11-11 02:51:45 +03:00
|
|
|
|
2004-08-05 22:26:14 +04:00
|
|
|
NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData);
|
2001-11-11 02:51:45 +03:00
|
|
|
|
|
|
|
NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsReStyleHint* aResult);
|
1999-04-20 04:05:54 +04:00
|
|
|
|
2003-02-22 19:10:53 +03:00
|
|
|
NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsReStyleHint* aResult);
|
1998-05-14 03:42:18 +04:00
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-05-14 03:42:18 +04:00
|
|
|
virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
2000-03-31 11:08:36 +04:00
|
|
|
|
1998-05-14 03:42:18 +04:00
|
|
|
private:
|
|
|
|
// These are not supported and are not implemented!
|
|
|
|
HTMLCSSStyleSheetImpl(const HTMLCSSStyleSheetImpl& aCopy);
|
|
|
|
HTMLCSSStyleSheetImpl& operator=(const HTMLCSSStyleSheetImpl& aCopy);
|
|
|
|
|
|
|
|
protected:
|
|
|
|
virtual ~HTMLCSSStyleSheetImpl();
|
|
|
|
|
|
|
|
protected:
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI* mURL;
|
1998-11-26 04:34:53 +03:00
|
|
|
nsIDocument* mDocument;
|
1999-04-20 04:28:40 +04:00
|
|
|
|
|
|
|
CSSFirstLineRule* mFirstLineRule;
|
1999-04-28 05:16:45 +04:00
|
|
|
CSSFirstLetterRule* mFirstLetterRule;
|
1998-05-14 03:42:18 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
|
1998-05-14 03:42:18 +04:00
|
|
|
: nsIHTMLCSSStyleSheet(),
|
2002-09-17 08:49:28 +04:00
|
|
|
mRefCnt(0),
|
1998-12-03 23:20:35 +03:00
|
|
|
mURL(nsnull),
|
1999-04-20 04:28:40 +04:00
|
|
|
mDocument(nsnull),
|
1999-04-28 05:16:45 +04:00
|
|
|
mFirstLineRule(nsnull),
|
|
|
|
mFirstLetterRule(nsnull)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
|
|
|
|
{
|
|
|
|
NS_RELEASE(mURL);
|
2004-10-31 20:33:50 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mFirstLineRule);
|
|
|
|
NS_IF_RELEASE(mFirstLetterRule);
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
2001-11-11 02:51:45 +03:00
|
|
|
NS_IMPL_ISUPPORTS3(HTMLCSSStyleSheetImpl,
|
|
|
|
nsIHTMLCSSStyleSheet,
|
|
|
|
nsIStyleSheet,
|
|
|
|
nsIStyleRuleProcessor)
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
HTMLCSSStyleSheetImpl::RulesMatching(ElementRuleProcessorData* aData)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
2004-10-24 21:10:32 +04:00
|
|
|
nsIStyledContent* styledContent = aData->mStyledContent;
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2002-08-16 15:29:20 +04:00
|
|
|
if (styledContent) {
|
2001-06-01 02:19:43 +04:00
|
|
|
// just get the one and only style rule from the content's STYLE attribute
|
2004-10-24 21:10:32 +04:00
|
|
|
nsICSSStyleRule* rule = styledContent->GetInlineStyleRule();
|
2002-08-16 15:29:20 +04:00
|
|
|
if (rule)
|
2003-03-06 22:07:22 +03:00
|
|
|
aData->mRuleWalker->Forward(rule);
|
2002-08-16 15:29:20 +04:00
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
1999-10-08 07:09:31 +04:00
|
|
|
NS_IMETHODIMP
|
2004-08-05 22:26:14 +04:00
|
|
|
HTMLCSSStyleSheetImpl::RulesMatching(PseudoRuleProcessorData* aData)
|
1998-05-19 01:11:08 +04:00
|
|
|
{
|
2001-11-11 02:51:45 +03:00
|
|
|
// We only want to add these rules if there are real :first-letter or
|
|
|
|
// :first-line rules that cause a pseudo-element frame to be created.
|
|
|
|
// Otherwise the use of ProbePseudoStyleContextFor will prevent frame
|
|
|
|
// creation, and adding rules here would cause it.
|
|
|
|
if (aData->mRuleWalker->AtRoot())
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsIAtom* pseudoTag = aData->mPseudoTag;
|
2002-11-17 18:37:56 +03:00
|
|
|
if (pseudoTag == nsCSSPseudoElements::firstLine) {
|
2001-11-11 02:51:45 +03:00
|
|
|
if (!mFirstLineRule) {
|
2004-10-31 20:33:50 +03:00
|
|
|
mFirstLineRule = new CSSFirstLineRule();
|
2001-11-11 02:51:45 +03:00
|
|
|
if (!mFirstLineRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mFirstLineRule);
|
|
|
|
}
|
|
|
|
aData->mRuleWalker->Forward(mFirstLineRule);
|
1999-04-28 05:16:45 +04:00
|
|
|
}
|
2002-11-17 18:37:56 +03:00
|
|
|
else if (pseudoTag == nsCSSPseudoElements::firstLetter) {
|
2001-11-11 02:51:45 +03:00
|
|
|
if (!mFirstLetterRule) {
|
2004-10-31 20:33:50 +03:00
|
|
|
mFirstLetterRule = new CSSFirstLetterRule();
|
2001-11-11 02:51:45 +03:00
|
|
|
if (!mFirstLetterRule)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(mFirstLetterRule);
|
|
|
|
}
|
|
|
|
aData->mRuleWalker->Forward(mFirstLetterRule);
|
|
|
|
}
|
1999-10-08 07:09:31 +04:00
|
|
|
return NS_OK;
|
1998-05-19 01:11:08 +04:00
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
HTMLCSSStyleSheetImpl::Init(nsIURI* aURL, nsIDocument* aDocument)
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURL && aDocument, "null ptr");
|
|
|
|
if (! aURL || ! aDocument)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
if (mURL || mDocument)
|
|
|
|
return NS_ERROR_ALREADY_INITIALIZED;
|
|
|
|
|
|
|
|
mDocument = aDocument; // not refcounted!
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
// Test if style is dependent on content state
|
|
|
|
NS_IMETHODIMP
|
2001-11-11 02:51:45 +03:00
|
|
|
HTMLCSSStyleSheetImpl::HasStateDependentStyle(StateRuleProcessorData* aData,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsReStyleHint* aResult)
|
1999-04-20 04:05:54 +04:00
|
|
|
{
|
2004-01-14 04:36:35 +03:00
|
|
|
*aResult = nsReStyleHint(0);
|
2002-04-11 07:49:30 +04:00
|
|
|
return NS_OK;
|
1999-04-20 04:05:54 +04:00
|
|
|
}
|
|
|
|
|
2003-02-22 19:10:53 +03:00
|
|
|
// Test if style is dependent on attribute
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
|
2004-01-14 04:36:35 +03:00
|
|
|
nsReStyleHint* aResult)
|
2003-02-22 19:10:53 +03:00
|
|
|
{
|
2004-01-14 04:36:35 +03:00
|
|
|
*aResult = nsReStyleHint(0);
|
2003-02-22 19:10:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-20 04:05:54 +04:00
|
|
|
|
|
|
|
|
1999-02-03 22:38:16 +03:00
|
|
|
NS_IMETHODIMP
|
1999-06-23 07:29:44 +04:00
|
|
|
HTMLCSSStyleSheetImpl::Reset(nsIURI* aURL)
|
1999-02-03 22:38:16 +03:00
|
|
|
{
|
|
|
|
NS_IF_RELEASE(mURL);
|
|
|
|
mURL = aURL;
|
|
|
|
NS_ADDREF(mURL);
|
2004-10-31 20:33:50 +03:00
|
|
|
|
|
|
|
NS_IF_RELEASE(mFirstLineRule);
|
|
|
|
NS_IF_RELEASE(mFirstLetterRule);
|
1999-02-03 22:38:16 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
2004-09-10 10:45:59 +04:00
|
|
|
HTMLCSSStyleSheetImpl::GetSheetURI(nsIURI** aSheetURL) const
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IF_ADDREF(mURL);
|
2004-09-10 10:45:59 +04:00
|
|
|
*aSheetURL = mURL;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetBaseURI(nsIURI** aBaseURL) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mURL);
|
|
|
|
*aBaseURL = mURL;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
|
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
|
|
|
|
{
|
2004-06-17 04:13:25 +04:00
|
|
|
aType.AssignLiteral("text/html");
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetMediumCount(PRInt32& aCount) const
|
|
|
|
{
|
|
|
|
aCount = 0;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-12-02 03:38:33 +03:00
|
|
|
HTMLCSSStyleSheetImpl::GetMediumAt(PRInt32 aIndex, nsIAtom*& aMedium) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
1998-12-02 03:38:33 +03:00
|
|
|
aMedium = nsnull;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2001-09-05 04:00:18 +04:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
1999-06-15 10:21:47 +04:00
|
|
|
HTMLCSSStyleSheetImpl::UseForMedium(nsIAtom* aMedium) const
|
|
|
|
{
|
2001-09-05 04:00:18 +04:00
|
|
|
return PR_TRUE; // works for all media
|
1999-06-15 10:21:47 +04:00
|
|
|
}
|
|
|
|
|
2003-07-04 05:44:24 +04:00
|
|
|
NS_IMETHODIMP_(PRBool)
|
|
|
|
HTMLCSSStyleSheetImpl::HasRules() const
|
|
|
|
{
|
|
|
|
return PR_TRUE; // We always have rules, since mFirstLineRule and
|
|
|
|
// mFirstLetterRule are created on request.
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
NS_IMETHODIMP
|
2002-12-03 08:48:14 +03:00
|
|
|
HTMLCSSStyleSheetImpl::GetApplicable(PRBool& aApplicable) const
|
1998-11-26 04:34:53 +03:00
|
|
|
{
|
2002-12-03 08:48:14 +03:00
|
|
|
aApplicable = PR_TRUE;
|
1998-11-26 04:34:53 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
|
|
|
|
{ // these can't be disabled
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-12-03 08:48:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetComplete(PRBool& aComplete) const
|
|
|
|
{
|
|
|
|
aComplete = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::SetComplete()
|
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1998-11-26 04:34:53 +03:00
|
|
|
// style sheet owner info
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
|
|
|
|
{
|
|
|
|
aParent = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
|
|
|
|
{
|
|
|
|
NS_IF_ADDREF(mDocument);
|
|
|
|
aDocument = mDocument;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
|
|
|
|
{
|
|
|
|
mDocument = aDocument;
|
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|
|
|
|
|
2001-10-16 09:31:36 +04:00
|
|
|
#ifdef DEBUG
|
1998-05-14 03:42:18 +04:00
|
|
|
void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
|
|
|
|
{
|
|
|
|
// Indent
|
|
|
|
for (PRInt32 index = aIndent; --index >= 0; ) fputs(" ", out);
|
|
|
|
|
|
|
|
fputs("HTML CSS Style Sheet: ", out);
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString urlSpec;
|
|
|
|
mURL->GetSpec(urlSpec);
|
|
|
|
if (!urlSpec.IsEmpty()) {
|
|
|
|
fputs(urlSpec.get(), out);
|
1999-06-28 01:17:39 +04:00
|
|
|
}
|
1998-05-14 03:42:18 +04:00
|
|
|
fputs("\n", out);
|
|
|
|
}
|
2001-10-16 09:31:36 +04:00
|
|
|
#endif
|
1998-12-03 23:20:35 +03:00
|
|
|
|
|
|
|
// XXX For backwards compatibility and convenience
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult,
|
|
|
|
nsIURI* aURL, nsIDocument* aDocument)
|
1998-12-03 23:20:35 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIHTMLCSSStyleSheet* sheet;
|
|
|
|
if (NS_FAILED(rv = NS_NewHTMLCSSStyleSheet(&sheet)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (NS_FAILED(rv = sheet->Init(aURL, aDocument))) {
|
|
|
|
NS_RELEASE(sheet);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*aInstancePtrResult = sheet;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-03-05 18:08:41 +03:00
|
|
|
nsresult
|
|
|
|
NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult)
|
1998-05-14 03:42:18 +04:00
|
|
|
{
|
|
|
|
if (aInstancePtrResult == nsnull) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
HTMLCSSStyleSheetImpl* it = new HTMLCSSStyleSheetImpl();
|
1998-05-14 03:42:18 +04:00
|
|
|
|
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
|
1998-12-03 23:20:35 +03:00
|
|
|
NS_ADDREF(it);
|
|
|
|
*aInstancePtrResult = it;
|
|
|
|
return NS_OK;
|
1998-05-14 03:42:18 +04:00
|
|
|
}
|