Back to index

lightning-sunbird  0.9+nobinonly
nsHTMLCSSStyleSheet.cpp
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *   Pierre Phaneuf <pp@ludusdesign.com>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 #include "nsIHTMLCSSStyleSheet.h"
00040 #include "nsCRT.h"
00041 #include "nsIAtom.h"
00042 #include "nsIURL.h"
00043 #include "nsISupportsArray.h"
00044 #include "nsCSSPseudoElements.h"
00045 #include "nsIStyledContent.h"
00046 #include "nsIStyleRule.h"
00047 #include "nsIFrame.h"
00048 #include "nsICSSStyleRule.h"
00049 #include "nsIStyleRuleProcessor.h"
00050 #include "nsPresContext.h"
00051 #include "nsIDocument.h"
00052 #include "nsCOMPtr.h"
00053 #include "nsRuleWalker.h"
00054 #include "nsRuleData.h"
00055 
00056 /*
00057  * The CSSFirstLetterRule and CSSFirstLineRule exist so that we can fix
00058  * up the style data so that we don't have non-default values for the
00059  * properties that don't apply to :first-letter and :first-line.
00060  *
00061  * CSSDisablePropsRule is a common base class for both the
00062  * CSSFirstLetterRule and CSSFirstLineRule.
00063  */
00064 
00065 class CSSDisablePropsRule : public nsIStyleRule {
00066 public:
00067   CSSDisablePropsRule();
00068   virtual ~CSSDisablePropsRule();
00069 
00070   NS_DECL_ISUPPORTS
00071 
00072   // Call this something else so that this class still has pure virtual
00073   // functions.
00074   void CommonMapRuleInfoInto(nsRuleData* aRuleData);
00075 
00076 #ifdef DEBUG
00077   NS_IMETHOD List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00078 #endif
00079 protected:
00080   nsCSSValueList mInheritList;
00081   nsCSSQuotes mInheritQuotes;
00082   nsCSSCounterData mNoneCounter;
00083 };
00084 
00085 CSSDisablePropsRule::CSSDisablePropsRule()
00086 {
00087   nsCSSValue none(eCSSUnit_None);
00088   mNoneCounter.mCounter = none;
00089   nsCSSValue inherit(eCSSUnit_Inherit);
00090   mInheritList.mValue = inherit;
00091   mInheritQuotes.mOpen = inherit;
00092 }
00093 
00094 class CSSFirstLineRule : public CSSDisablePropsRule {
00095 public:
00096   CSSFirstLineRule() {}
00097 
00098   NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00099 };
00100 
00101 class CSSFirstLetterRule : public CSSDisablePropsRule {
00102 public:
00103   CSSFirstLetterRule() {}
00104 
00105   NS_IMETHOD MapRuleInfoInto(nsRuleData* aRuleData);
00106 };
00107 
00108 CSSDisablePropsRule::~CSSDisablePropsRule()
00109 {
00110 }
00111 
00112 NS_IMPL_ISUPPORTS1(CSSDisablePropsRule, nsIStyleRule)
00113 
00114 #ifdef DEBUG
00115 NS_IMETHODIMP
00116 CSSDisablePropsRule::List(FILE* out, PRInt32 aIndent) const
00117 {
00118   return NS_OK;
00119 }
00120 #endif
00121 
00122 // -----------------------------------------------------------
00123 
00124 /*
00125  * Note:  These rule mapping functions, unlike practically all others,
00126  * will overwrite the properties even if they're not |eCSSUnit_Null|.
00127  * XXX This is only a partial fix for the fact that they should be
00128  * higher in the cascade (at the very top).  It doesn't work in the case
00129  * where something higher in the cascade fully specifies the struct.
00130  *
00131  * XXX This should be cleaned up once we implement eCSSUnit_Initial
00132  * throughout.
00133  */
00134 
00135 void
00136 CSSDisablePropsRule::CommonMapRuleInfoInto(nsRuleData* aData)
00137 {
00138   /*
00139    * Common code for disabling the properties that apply neither to
00140    * :first-letter nor to :first-line.
00141    */
00142 
00143   // Disable 'unicode-bidi'.
00144   if (aData->mSID == eStyleStruct_TextReset) {
00145     nsCSSValue normal(eCSSUnit_Normal);
00146     aData->mTextData->mUnicodeBidi = normal;
00147   }
00148 
00149   // NOTE: 'text-align', 'text-indent', and 'white-space' should not be
00150   // handled by the frames so we don't need to bother.
00151 
00152   // Disable everything in the nsRuleDataDisplay struct except 'float'
00153   // and 'clear'.
00154   if (aData->mSID == eStyleStruct_Visibility) {
00155     nsCSSValue inherit(eCSSUnit_Inherit);
00156     aData->mDisplayData->mVisibility = inherit;
00157     aData->mDisplayData->mDirection = inherit;
00158   }
00159 
00160   if (aData->mSID == eStyleStruct_Display) {
00161     nsCSSValue none(eCSSUnit_None);
00162     aData->mDisplayData->mAppearance = none;
00163 
00164     nsCSSValue autovalue(eCSSUnit_Auto);
00165     aData->mDisplayData->mClip.mTop = autovalue;
00166     aData->mDisplayData->mClip.mRight = autovalue;
00167     aData->mDisplayData->mClip.mBottom = autovalue;
00168     aData->mDisplayData->mClip.mLeft = autovalue;
00169 
00170     nsCSSValue one(1.0f, eCSSUnit_Number);
00171     aData->mDisplayData->mOpacity = one;
00172 
00173     nsCSSValue inlinevalue(NS_STYLE_DISPLAY_INLINE, eCSSUnit_Enumerated);
00174     aData->mDisplayData->mDisplay = inlinevalue;
00175 
00176     aData->mDisplayData->mBinding = none;
00177 
00178     nsCSSValue staticposition(NS_STYLE_POSITION_STATIC, eCSSUnit_Enumerated);
00179     aData->mDisplayData->mPosition = staticposition;
00180 
00181     nsCSSValue visible(NS_STYLE_OVERFLOW_VISIBLE, eCSSUnit_Enumerated);
00182     aData->mDisplayData->mOverflowX = visible;
00183     aData->mDisplayData->mOverflowY = visible;
00184 
00185     // Nobody will care about 'break-before' or 'break-after', since
00186     // they only apply to blocks (assuming we implement them correctly).
00187   }
00188 
00189   // NOTE:  We'll never do anything with what's in nsCSSList,
00190   // nsCSSTable, nsCSSBreaks, nsCSSPage, nsCSSAural, nsCSSXUL, or
00191   // nsCSSSVG, so don't bother.
00192 
00193   // Disable everything in the position struct.
00194   if (aData->mSID == eStyleStruct_Position) {
00195     nsCSSValue autovalue(eCSSUnit_Auto);
00196     nsCSSValue none(eCSSUnit_None);
00197     nsCSSValue zero(0.0f, eCSSUnit_Point);
00198     aData->mPositionData->mOffset.mTop = autovalue;
00199     aData->mPositionData->mOffset.mRight = autovalue;
00200     aData->mPositionData->mOffset.mBottom = autovalue;
00201     aData->mPositionData->mOffset.mLeft = autovalue;
00202     aData->mPositionData->mWidth = autovalue;
00203     aData->mPositionData->mMinWidth = zero;
00204     aData->mPositionData->mMaxWidth = none;
00205     aData->mPositionData->mHeight = autovalue;
00206     aData->mPositionData->mMinHeight = zero;
00207     aData->mPositionData->mMaxHeight = none;
00208     nsCSSValue content(NS_STYLE_BOX_SIZING_CONTENT, eCSSUnit_Enumerated);
00209     aData->mPositionData->mBoxSizing = content;
00210     aData->mPositionData->mZIndex = autovalue;
00211   }
00212 
00213   // Disable everything in the Content struct.
00214   if (aData->mSID == eStyleStruct_Content) {
00215     // Don't bother resetting 'content'.
00216 
00217     aData->mContentData->mCounterIncrement = &mNoneCounter;
00218     aData->mContentData->mCounterReset = &mNoneCounter;
00219 
00220     nsCSSValue autovalue(eCSSUnit_Auto);
00221     aData->mContentData->mMarkerOffset = autovalue;
00222   }
00223 
00224   if (aData->mSID == eStyleStruct_Quotes) {
00225     aData->mContentData->mQuotes = &mInheritQuotes;
00226   }
00227 
00228   // Disable everything in the UserInterface struct.
00229   if (aData->mSID == eStyleStruct_UserInterface) {
00230     nsCSSValue inherit(eCSSUnit_Inherit);
00231     aData->mUserInterfaceData->mUserInput = inherit;
00232     aData->mUserInterfaceData->mUserModify = inherit;
00233     aData->mUserInterfaceData->mUserFocus = inherit;
00234     aData->mUserInterfaceData->mCursor = &mInheritList;
00235   }
00236 
00237   if (aData->mSID == eStyleStruct_UIReset) {
00238     nsCSSValue autovalue(eCSSUnit_Auto);
00239     nsCSSValue none(eCSSUnit_None);
00240     // Don't bother with '-moz-force-broken-image-icon' since it's only
00241     // half a property.
00242     // Don't bother with '-moz-user-select' because there's no way to
00243     // specify the initial value.
00244   }
00245 
00246   // Disable all outline properties.
00247   if (aData->mSID == eStyleStruct_Outline) {
00248     nsCSSValue none(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
00249     aData->mMarginData->mOutlineStyle = none;
00250   }
00251 
00252 }
00253 
00254 NS_IMETHODIMP
00255 CSSFirstLineRule::MapRuleInfoInto(nsRuleData* aData)
00256 {
00257   /*
00258    * See CSS2 section 5.12.1, which says that the properties that apply
00259    * to :first-line are: font properties, color properties, background
00260    * properties, 'word-spacing', 'letter-spacing', 'text-decoration',
00261    * 'vertical-align', 'text-transform', 'line-height', 'text-shadow',
00262    * and 'clear'.
00263    */
00264 
00265   CommonMapRuleInfoInto(aData);
00266 
00267   // Disable 'float'.
00268   if (aData->mSID == eStyleStruct_Display) {
00269     nsCSSValue none(eCSSUnit_None);
00270     aData->mDisplayData->mFloat = none;
00271   }
00272 
00273   // Disable border properties, margin properties, and padding
00274   // properties.
00275   if (aData->mSID == eStyleStruct_Border) {
00276     nsCSSValue none(NS_STYLE_BORDER_STYLE_NONE, eCSSUnit_Enumerated);
00277     aData->mMarginData->mBorderStyle.mTop = none;
00278     aData->mMarginData->mBorderStyle.mRight = none;
00279     aData->mMarginData->mBorderStyle.mBottom = none;
00280     aData->mMarginData->mBorderStyle.mLeft = none;
00281   }
00282 
00283   if (aData->mSID == eStyleStruct_Margin) {
00284     nsCSSValue zero(0.0f, eCSSUnit_Point);
00285     aData->mMarginData->mMargin.mTop = zero;
00286     aData->mMarginData->mMargin.mRight = zero;
00287     aData->mMarginData->mMargin.mBottom = zero;
00288     aData->mMarginData->mMargin.mLeft = zero;
00289   }
00290 
00291   if (aData->mSID == eStyleStruct_Padding) {
00292     nsCSSValue zero(0.0f, eCSSUnit_Point);
00293     aData->mMarginData->mPadding.mTop = zero;
00294     aData->mMarginData->mPadding.mRight = zero;
00295     aData->mMarginData->mPadding.mBottom = zero;
00296     aData->mMarginData->mPadding.mLeft = zero;
00297   }
00298 
00299   return NS_OK;
00300 }
00301 
00302 NS_IMETHODIMP
00303 CSSFirstLetterRule::MapRuleInfoInto(nsRuleData* aData)
00304 {
00305   /*
00306    * See CSS2 5.12.2, which says that the properties that apply to
00307    * :first-letter are: font properties, color properties, background
00308    * properties, 'text-decoration', 'vertical-align' (only if 'float' is
00309    * 'none'), 'text-transform', 'line-height', margin properties,
00310    * padding properties, border properties, 'float', 'text-shadow', and
00311    * 'clear'.
00312    */
00313 
00314   CommonMapRuleInfoInto(aData);
00315 
00316   if (aData->mSID == eStyleStruct_Text) {
00317     nsCSSValue inherit(eCSSUnit_Inherit);
00318     aData->mTextData->mWordSpacing = inherit;
00319     aData->mTextData->mLetterSpacing = inherit;
00320   }
00321 
00322   // NOTE:  'vertical-align' is only supposed to be relevant if 'float'
00323   // is 'none', but we don't do anything with it if 'float' is not none,
00324   // so we don't need to disable it.
00325 
00326   return NS_OK;
00327 }
00328 
00329 // -----------------------------------------------------------
00330 
00331 class HTMLCSSStyleSheetImpl : public nsIHTMLCSSStyleSheet,
00332                               public nsIStyleRuleProcessor {
00333 public:
00334   HTMLCSSStyleSheetImpl();
00335 
00336   NS_DECL_ISUPPORTS
00337 
00338   // basic style sheet data
00339   NS_IMETHOD Init(nsIURI* aURL, nsIDocument* aDocument);
00340   NS_IMETHOD Reset(nsIURI* aURL);
00341   NS_IMETHOD GetSheetURI(nsIURI** aSheetURL) const;
00342   NS_IMETHOD GetBaseURI(nsIURI** aBaseURL) const;
00343   NS_IMETHOD GetTitle(nsString& aTitle) const;
00344   NS_IMETHOD GetType(nsString& aType) const;
00345   NS_IMETHOD_(PRBool) UseForMedium(nsPresContext* aPresContext) const;
00346   NS_IMETHOD_(PRBool) HasRules() const;
00347 
00348   NS_IMETHOD GetApplicable(PRBool& aApplicable) const;
00349   
00350   NS_IMETHOD SetEnabled(PRBool aEnabled);
00351 
00352   NS_IMETHOD GetComplete(PRBool& aComplete) const;
00353   NS_IMETHOD SetComplete();
00354 
00355   // style sheet owner info
00356   NS_IMETHOD GetParentSheet(nsIStyleSheet*& aParent) const;  // will be null
00357   NS_IMETHOD GetOwningDocument(nsIDocument*& aDocument) const;
00358   NS_IMETHOD SetOwningDocument(nsIDocument* aDocument);
00359 
00360   // nsIStyleRuleProcessor api
00361   NS_IMETHOD RulesMatching(ElementRuleProcessorData* aData);
00362 
00363   NS_IMETHOD RulesMatching(PseudoRuleProcessorData* aData);
00364 
00365   NS_IMETHOD HasStateDependentStyle(StateRuleProcessorData* aData,
00366                                     nsReStyleHint* aResult);
00367 
00368   NS_IMETHOD HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
00369                                         nsReStyleHint* aResult);
00370 
00371 #ifdef DEBUG
00372   virtual void List(FILE* out = stdout, PRInt32 aIndent = 0) const;
00373 #endif
00374 
00375 private: 
00376   // These are not supported and are not implemented! 
00377   HTMLCSSStyleSheetImpl(const HTMLCSSStyleSheetImpl& aCopy); 
00378   HTMLCSSStyleSheetImpl& operator=(const HTMLCSSStyleSheetImpl& aCopy); 
00379 
00380 protected:
00381   virtual ~HTMLCSSStyleSheetImpl();
00382 
00383 protected:
00384   nsIURI*         mURL;
00385   nsIDocument*    mDocument;
00386 
00387   CSSFirstLineRule* mFirstLineRule;
00388   CSSFirstLetterRule* mFirstLetterRule;
00389 };
00390 
00391 
00392 HTMLCSSStyleSheetImpl::HTMLCSSStyleSheetImpl()
00393   : nsIHTMLCSSStyleSheet(),
00394     mRefCnt(0),
00395     mURL(nsnull),
00396     mDocument(nsnull),
00397     mFirstLineRule(nsnull),
00398     mFirstLetterRule(nsnull)
00399 {
00400 }
00401 
00402 HTMLCSSStyleSheetImpl::~HTMLCSSStyleSheetImpl()
00403 {
00404   NS_RELEASE(mURL);
00405 
00406   NS_IF_RELEASE(mFirstLineRule);
00407   NS_IF_RELEASE(mFirstLetterRule);
00408 }
00409 
00410 NS_IMPL_ISUPPORTS3(HTMLCSSStyleSheetImpl,
00411                    nsIHTMLCSSStyleSheet,
00412                    nsIStyleSheet,
00413                    nsIStyleRuleProcessor)
00414 
00415 NS_IMETHODIMP
00416 HTMLCSSStyleSheetImpl::RulesMatching(ElementRuleProcessorData* aData)
00417 {
00418   nsIStyledContent* styledContent = aData->mStyledContent;
00419   
00420   if (styledContent) {
00421     // just get the one and only style rule from the content's STYLE attribute
00422     nsICSSStyleRule* rule = styledContent->GetInlineStyleRule();
00423     if (rule)
00424       aData->mRuleWalker->Forward(rule);
00425   }
00426 
00427   return NS_OK;
00428 }
00429 
00430 NS_IMETHODIMP
00431 HTMLCSSStyleSheetImpl::RulesMatching(PseudoRuleProcessorData* aData)
00432 {
00433   // We only want to add these rules if there are real :first-letter or
00434   // :first-line rules that cause a pseudo-element frame to be created.
00435   // Otherwise the use of ProbePseudoStyleContextFor will prevent frame
00436   // creation, and adding rules here would cause it.
00437   if (aData->mRuleWalker->AtRoot())
00438     return NS_OK;
00439 
00440   nsIAtom* pseudoTag = aData->mPseudoTag;
00441   if (pseudoTag == nsCSSPseudoElements::firstLine) {
00442     if (!mFirstLineRule) {
00443       mFirstLineRule = new CSSFirstLineRule();
00444       if (!mFirstLineRule)
00445         return NS_ERROR_OUT_OF_MEMORY;
00446       NS_ADDREF(mFirstLineRule);
00447     }
00448     aData->mRuleWalker->Forward(mFirstLineRule);
00449   }
00450   else if (pseudoTag == nsCSSPseudoElements::firstLetter) {
00451     if (!mFirstLetterRule) {
00452       mFirstLetterRule = new CSSFirstLetterRule();
00453       if (!mFirstLetterRule)
00454         return NS_ERROR_OUT_OF_MEMORY;
00455       NS_ADDREF(mFirstLetterRule);
00456     }
00457     aData->mRuleWalker->Forward(mFirstLetterRule);
00458   } 
00459   return NS_OK;
00460 }
00461 
00462 NS_IMETHODIMP
00463 HTMLCSSStyleSheetImpl::Init(nsIURI* aURL, nsIDocument* aDocument)
00464 {
00465   NS_PRECONDITION(aURL && aDocument, "null ptr");
00466   if (! aURL || ! aDocument)
00467     return NS_ERROR_NULL_POINTER;
00468 
00469   if (mURL || mDocument)
00470     return NS_ERROR_ALREADY_INITIALIZED;
00471 
00472   mDocument = aDocument; // not refcounted!
00473   mURL = aURL;
00474   NS_ADDREF(mURL);
00475   return NS_OK;
00476 }
00477 
00478 // Test if style is dependent on content state
00479 NS_IMETHODIMP
00480 HTMLCSSStyleSheetImpl::HasStateDependentStyle(StateRuleProcessorData* aData,
00481                                               nsReStyleHint* aResult)
00482 {
00483   *aResult = nsReStyleHint(0);
00484   return NS_OK;
00485 }
00486 
00487 // Test if style is dependent on attribute
00488 NS_IMETHODIMP
00489 HTMLCSSStyleSheetImpl::HasAttributeDependentStyle(AttributeRuleProcessorData* aData,
00490                                                   nsReStyleHint* aResult)
00491 {
00492   *aResult = nsReStyleHint(0);
00493   return NS_OK;
00494 }
00495 
00496 
00497 
00498 NS_IMETHODIMP 
00499 HTMLCSSStyleSheetImpl::Reset(nsIURI* aURL)
00500 {
00501   NS_IF_RELEASE(mURL);
00502   mURL = aURL;
00503   NS_ADDREF(mURL);
00504 
00505   NS_IF_RELEASE(mFirstLineRule);
00506   NS_IF_RELEASE(mFirstLetterRule);
00507   return NS_OK;
00508 }
00509 
00510 NS_IMETHODIMP
00511 HTMLCSSStyleSheetImpl::GetSheetURI(nsIURI** aSheetURL) const
00512 {
00513   NS_IF_ADDREF(mURL);
00514   *aSheetURL = mURL;
00515   return NS_OK;
00516 }
00517 
00518 NS_IMETHODIMP
00519 HTMLCSSStyleSheetImpl::GetBaseURI(nsIURI** aBaseURL) const
00520 {
00521   NS_IF_ADDREF(mURL);
00522   *aBaseURL = mURL;
00523   return NS_OK;
00524 }
00525 
00526 NS_IMETHODIMP
00527 HTMLCSSStyleSheetImpl::GetTitle(nsString& aTitle) const
00528 {
00529   aTitle.AssignLiteral("Internal HTML/CSS Style Sheet");
00530   return NS_OK;
00531 }
00532 
00533 NS_IMETHODIMP
00534 HTMLCSSStyleSheetImpl::GetType(nsString& aType) const
00535 {
00536   aType.AssignLiteral("text/html");
00537   return NS_OK;
00538 }
00539 
00540 NS_IMETHODIMP_(PRBool)
00541 HTMLCSSStyleSheetImpl::UseForMedium(nsPresContext* aPresContext) const
00542 {
00543   return PR_TRUE; // works for all media
00544 }
00545 
00546 NS_IMETHODIMP_(PRBool)
00547 HTMLCSSStyleSheetImpl::HasRules() const
00548 {
00549   return PR_TRUE;  // We always have rules, since mFirstLineRule and
00550                    // mFirstLetterRule are created on request.
00551 }
00552 
00553 NS_IMETHODIMP
00554 HTMLCSSStyleSheetImpl::GetApplicable(PRBool& aApplicable) const
00555 {
00556   aApplicable = PR_TRUE;
00557   return NS_OK;
00558 }
00559 
00560 NS_IMETHODIMP
00561 HTMLCSSStyleSheetImpl::SetEnabled(PRBool aEnabled)
00562 { // these can't be disabled
00563   return NS_OK;
00564 }
00565 
00566 NS_IMETHODIMP
00567 HTMLCSSStyleSheetImpl::GetComplete(PRBool& aComplete) const
00568 {
00569   aComplete = PR_TRUE;
00570   return NS_OK;
00571 }
00572 
00573 NS_IMETHODIMP
00574 HTMLCSSStyleSheetImpl::SetComplete()
00575 {
00576   return NS_OK;
00577 }
00578 
00579 // style sheet owner info
00580 NS_IMETHODIMP
00581 HTMLCSSStyleSheetImpl::GetParentSheet(nsIStyleSheet*& aParent) const
00582 {
00583   aParent = nsnull;
00584   return NS_OK;
00585 }
00586 
00587 NS_IMETHODIMP
00588 HTMLCSSStyleSheetImpl::GetOwningDocument(nsIDocument*& aDocument) const
00589 {
00590   NS_IF_ADDREF(mDocument);
00591   aDocument = mDocument;
00592   return NS_OK;
00593 }
00594 
00595 NS_IMETHODIMP
00596 HTMLCSSStyleSheetImpl::SetOwningDocument(nsIDocument* aDocument)
00597 {
00598   mDocument = aDocument;
00599   return NS_OK;
00600 }
00601 
00602 #ifdef DEBUG
00603 void HTMLCSSStyleSheetImpl::List(FILE* out, PRInt32 aIndent) const
00604 {
00605   // Indent
00606   for (PRInt32 index = aIndent; --index >= 0; ) fputs("  ", out);
00607 
00608   fputs("HTML CSS Style Sheet: ", out);
00609   nsCAutoString urlSpec;
00610   mURL->GetSpec(urlSpec);
00611   if (!urlSpec.IsEmpty()) {
00612     fputs(urlSpec.get(), out);
00613   }
00614   fputs("\n", out);
00615 }
00616 #endif
00617 
00618 // XXX For backwards compatibility and convenience
00619 nsresult
00620 NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult,
00621                         nsIURI* aURL, nsIDocument* aDocument)
00622 {
00623   nsresult rv;
00624   nsIHTMLCSSStyleSheet* sheet;
00625   if (NS_FAILED(rv = NS_NewHTMLCSSStyleSheet(&sheet)))
00626     return rv;
00627 
00628   if (NS_FAILED(rv = sheet->Init(aURL, aDocument))) {
00629     NS_RELEASE(sheet);
00630     return rv;
00631   }
00632 
00633   *aInstancePtrResult = sheet;
00634   return NS_OK;
00635 }
00636 
00637 nsresult
00638 NS_NewHTMLCSSStyleSheet(nsIHTMLCSSStyleSheet** aInstancePtrResult)
00639 {
00640   if (aInstancePtrResult == nsnull) {
00641     return NS_ERROR_NULL_POINTER;
00642   }
00643 
00644   HTMLCSSStyleSheetImpl*  it = new HTMLCSSStyleSheetImpl();
00645 
00646   if (nsnull == it) {
00647     return NS_ERROR_OUT_OF_MEMORY;
00648   }
00649 
00650   NS_ADDREF(it);
00651   *aInstancePtrResult = it;
00652   return NS_OK;
00653 }