LCOV - code coverage report
Current view: directory - layout/style - nsHTMLStyleSheet.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 230 37 16.1 %
Date: 2012-06-02 Functions: 55 11 20.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
       2                 :  *
       3                 :  * ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is mozilla.org code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK *****
      38                 :  *
      39                 :  * This Original Code has been modified by IBM Corporation. Modifications made by IBM 
      40                 :  * described herein are Copyright (c) International Business Machines Corporation, 2000.
      41                 :  * Modifications to Mozilla code or documentation identified per MPL Section 3.3
      42                 :  *
      43                 :  * Date             Modified by     Description of modification
      44                 :  * 04/20/2000       IBM Corp.      OS/2 VisualAge build.
      45                 :  */
      46                 : 
      47                 : /*
      48                 :  * style sheet and style rule processor representing data from presentational
      49                 :  * HTML attributes
      50                 :  */
      51                 : 
      52                 : #include "nsHTMLStyleSheet.h"
      53                 : #include "nsINameSpaceManager.h"
      54                 : #include "nsIAtom.h"
      55                 : #include "nsIURL.h"
      56                 : #include "nsMappedAttributes.h"
      57                 : #include "nsILink.h"
      58                 : #include "nsIFrame.h"
      59                 : #include "nsStyleContext.h"
      60                 : #include "nsGkAtoms.h"
      61                 : #include "nsPresContext.h"
      62                 : #include "nsEventStates.h"
      63                 : #include "nsIDocument.h"
      64                 : #include "nsIPresShell.h"
      65                 : #include "nsStyleConsts.h"
      66                 : #include "nsCSSAnonBoxes.h"
      67                 : #include "nsRuleWalker.h"
      68                 : #include "nsRuleData.h"
      69                 : #include "nsContentErrors.h"
      70                 : #include "nsRuleProcessorData.h"
      71                 : #include "nsCSSRuleProcessor.h"
      72                 : #include "mozilla/dom/Element.h"
      73                 : #include "nsCSSFrameConstructor.h"
      74                 : 
      75                 : using namespace mozilla::dom;
      76                 : 
      77               0 : NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::HTMLColorRule, nsIStyleRule)
      78                 : 
      79                 : /* virtual */ void
      80               0 : nsHTMLStyleSheet::HTMLColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
      81                 : {
      82               0 :   if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
      83               0 :     nsCSSValue* color = aRuleData->ValueForColor();
      84               0 :     if (color->GetUnit() == eCSSUnit_Null &&
      85               0 :         aRuleData->mPresContext->UseDocumentColors())
      86               0 :       color->SetColorValue(mColor);
      87                 :   }
      88               0 : }
      89                 : 
      90                 : #ifdef DEBUG
      91                 : /* virtual */ void
      92               0 : nsHTMLStyleSheet::HTMLColorRule::List(FILE* out, PRInt32 aIndent) const
      93                 : {
      94               0 : }
      95                 : #endif
      96                 : 
      97                 :  
      98            2814 : NS_IMPL_ISUPPORTS1(nsHTMLStyleSheet::GenericTableRule, nsIStyleRule)
      99                 : 
     100                 : #ifdef DEBUG
     101                 : /* virtual */ void
     102               0 : nsHTMLStyleSheet::GenericTableRule::List(FILE* out, PRInt32 aIndent) const
     103                 : {
     104               0 : }
     105                 : #endif
     106                 : 
     107                 : /* virtual */ void
     108               0 : nsHTMLStyleSheet::TableTHRule::MapRuleInfoInto(nsRuleData* aRuleData)
     109                 : {
     110               0 :   if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Text)) {
     111               0 :     nsCSSValue* textAlign = aRuleData->ValueForTextAlign();
     112               0 :     if (textAlign->GetUnit() == eCSSUnit_Null) {
     113                 :       textAlign->SetIntValue(NS_STYLE_TEXT_ALIGN_MOZ_CENTER_OR_INHERIT,
     114               0 :                              eCSSUnit_Enumerated);
     115                 :     }
     116                 :   }
     117               0 : }
     118                 : 
     119                 : /* virtual */ void
     120               0 : nsHTMLStyleSheet::TableQuirkColorRule::MapRuleInfoInto(nsRuleData* aRuleData)
     121                 : {
     122               0 :   if (aRuleData->mSIDs & NS_STYLE_INHERIT_BIT(Color)) {
     123               0 :     nsCSSValue* color = aRuleData->ValueForColor();
     124                 :     // We do not check UseDocumentColors() here, because we want to
     125                 :     // use the body color no matter what.
     126               0 :     if (color->GetUnit() == eCSSUnit_Null)
     127                 :       color->SetIntValue(NS_STYLE_COLOR_INHERIT_FROM_BODY,
     128               0 :                          eCSSUnit_Enumerated);
     129                 :   }
     130               0 : }
     131                 : 
     132                 : // -----------------------------------------------------------
     133                 : 
     134                 : struct MappedAttrTableEntry : public PLDHashEntryHdr {
     135                 :   nsMappedAttributes *mAttributes;
     136                 : };
     137                 : 
     138                 : static PLDHashNumber
     139               0 : MappedAttrTable_HashKey(PLDHashTable *table, const void *key)
     140                 : {
     141                 :   nsMappedAttributes *attributes =
     142               0 :     static_cast<nsMappedAttributes*>(const_cast<void*>(key));
     143                 : 
     144               0 :   return attributes->HashValue();
     145                 : }
     146                 : 
     147                 : static void
     148               0 : MappedAttrTable_ClearEntry(PLDHashTable *table, PLDHashEntryHdr *hdr)
     149                 : {
     150               0 :   MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>(hdr);
     151                 : 
     152               0 :   entry->mAttributes->DropStyleSheetReference();
     153               0 :   memset(entry, 0, sizeof(MappedAttrTableEntry));
     154               0 : }
     155                 : 
     156                 : static bool
     157               0 : MappedAttrTable_MatchEntry(PLDHashTable *table, const PLDHashEntryHdr *hdr,
     158                 :                            const void *key)
     159                 : {
     160                 :   nsMappedAttributes *attributes =
     161               0 :     static_cast<nsMappedAttributes*>(const_cast<void*>(key));
     162                 :   const MappedAttrTableEntry *entry =
     163               0 :     static_cast<const MappedAttrTableEntry*>(hdr);
     164                 : 
     165               0 :   return attributes->Equals(entry->mAttributes);
     166                 : }
     167                 : 
     168                 : static PLDHashTableOps MappedAttrTable_Ops = {
     169                 :   PL_DHashAllocTable,
     170                 :   PL_DHashFreeTable,
     171                 :   MappedAttrTable_HashKey,
     172                 :   MappedAttrTable_MatchEntry,
     173                 :   PL_DHashMoveEntryStub,
     174                 :   MappedAttrTable_ClearEntry,
     175                 :   PL_DHashFinalizeStub,
     176                 :   NULL
     177                 : };
     178                 : 
     179                 : // -----------------------------------------------------------
     180                 : 
     181             469 : nsHTMLStyleSheet::nsHTMLStyleSheet(void)
     182             469 :   : mDocument(nsnull)
     183                 : {
     184             469 :   mMappedAttrTable.ops = nsnull;
     185             469 : }
     186                 : 
     187                 : nsresult
     188             469 : nsHTMLStyleSheet::Init()
     189                 : {
     190             469 :   mTableTHRule = new TableTHRule();
     191             469 :   mTableQuirkColorRule = new TableQuirkColorRule();
     192             469 :   return NS_OK;
     193                 : }
     194                 : 
     195             938 : nsHTMLStyleSheet::~nsHTMLStyleSheet()
     196                 : {
     197             469 :   if (mMappedAttrTable.ops)
     198               0 :     PL_DHashTableFinish(&mMappedAttrTable);
     199             469 : }
     200                 : 
     201            1407 : NS_IMPL_ISUPPORTS2(nsHTMLStyleSheet, nsIStyleSheet, nsIStyleRuleProcessor)
     202                 : 
     203                 : /* virtual */ void
     204               0 : nsHTMLStyleSheet::RulesMatching(ElementRuleProcessorData* aData)
     205                 : {
     206               0 :   nsRuleWalker *ruleWalker = aData->mRuleWalker;
     207               0 :   if (aData->mElement->IsHTML()) {
     208               0 :     nsIAtom* tag = aData->mElement->Tag();
     209                 : 
     210                 :     // if we have anchor colors, check if this is an anchor with an href
     211               0 :     if (tag == nsGkAtoms::a) {
     212               0 :       if (mLinkRule || mVisitedRule || mActiveRule) {
     213                 :         nsEventStates state = nsCSSRuleProcessor::GetContentStateForVisitedHandling(
     214                 :                                   aData->mElement,
     215                 :                                   aData->mTreeMatchContext.VisitedHandling(),
     216                 :                                   // If the node being matched is a link,
     217                 :                                   // it's the relevant link.
     218               0 :                                   nsCSSRuleProcessor::IsLink(aData->mElement));
     219               0 :         if (mLinkRule && state.HasState(NS_EVENT_STATE_UNVISITED)) {
     220               0 :           ruleWalker->Forward(mLinkRule);
     221               0 :           aData->mTreeMatchContext.SetHaveRelevantLink();
     222                 :         }
     223               0 :         else if (mVisitedRule && state.HasState(NS_EVENT_STATE_VISITED)) {
     224               0 :           ruleWalker->Forward(mVisitedRule);
     225               0 :           aData->mTreeMatchContext.SetHaveRelevantLink();
     226                 :         }
     227                 : 
     228                 :         // No need to add to the active rule if it's not a link
     229               0 :         if (mActiveRule && nsCSSRuleProcessor::IsLink(aData->mElement) &&
     230               0 :             state.HasState(NS_EVENT_STATE_ACTIVE)) {
     231               0 :           ruleWalker->Forward(mActiveRule);
     232                 :         }
     233                 :       } // end link/visited/active rules
     234                 :     } // end A tag
     235                 :     // add the rule to handle text-align for a <th>
     236               0 :     else if (tag == nsGkAtoms::th) {
     237               0 :       ruleWalker->Forward(mTableTHRule);
     238                 :     }
     239               0 :     else if (tag == nsGkAtoms::table) {
     240               0 :       if (aData->mTreeMatchContext.mCompatMode == eCompatibility_NavQuirks) {
     241               0 :         ruleWalker->Forward(mTableQuirkColorRule);
     242                 :       }
     243                 :     }
     244                 :   } // end html element
     245                 : 
     246                 :     // just get the style rules from the content
     247               0 :   aData->mElement->WalkContentStyleRules(ruleWalker);
     248               0 : }
     249                 : 
     250                 : // Test if style is dependent on content state
     251                 : /* virtual */ nsRestyleHint
     252               0 : nsHTMLStyleSheet::HasStateDependentStyle(StateRuleProcessorData* aData)
     253                 : {
     254               0 :   if (aData->mElement->IsHTML(nsGkAtoms::a) &&
     255               0 :       nsCSSRuleProcessor::IsLink(aData->mElement) &&
     256               0 :       ((mActiveRule && aData->mStateMask.HasState(NS_EVENT_STATE_ACTIVE)) ||
     257               0 :        (mLinkRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)) ||
     258               0 :        (mVisitedRule && aData->mStateMask.HasState(NS_EVENT_STATE_VISITED)))) {
     259               0 :     return eRestyle_Self;
     260                 :   }
     261                 :   
     262               0 :   return nsRestyleHint(0);
     263                 : }
     264                 : 
     265                 : /* virtual */ bool
     266               0 : nsHTMLStyleSheet::HasDocumentStateDependentStyle(StateRuleProcessorData* aData)
     267                 : {
     268               0 :   return false;
     269                 : }
     270                 : 
     271                 : /* virtual */ nsRestyleHint
     272               0 : nsHTMLStyleSheet::HasAttributeDependentStyle(AttributeRuleProcessorData* aData)
     273                 : {
     274                 :   // Do nothing on before-change checks
     275               0 :   if (!aData->mAttrHasChanged) {
     276               0 :     return nsRestyleHint(0);
     277                 :   }
     278                 : 
     279                 :   // Note: no need to worry about whether some states changed with this
     280                 :   // attribute here, because we handle that under HasStateDependentStyle() as
     281                 :   // needed.
     282                 : 
     283                 :   // Result is true for |href| changes on HTML links if we have link rules.
     284               0 :   Element *element = aData->mElement;
     285               0 :   if (aData->mAttribute == nsGkAtoms::href &&
     286               0 :       (mLinkRule || mVisitedRule || mActiveRule) &&
     287               0 :       element->IsHTML(nsGkAtoms::a)) {
     288               0 :     return eRestyle_Self;
     289                 :   }
     290                 : 
     291                 :   // Don't worry about the mDocumentColorRule since it only applies
     292                 :   // to descendants of body, when we're already reresolving.
     293                 : 
     294                 :   // Handle the content style rules.
     295               0 :   if (element->IsAttributeMapped(aData->mAttribute)) {
     296                 :     // cellpadding on tables is special and requires reresolving all
     297                 :     // the cells in the table
     298               0 :     if (aData->mAttribute == nsGkAtoms::cellpadding &&
     299               0 :         element->IsHTML(nsGkAtoms::table)) {
     300               0 :       return eRestyle_Subtree;
     301                 :     }
     302               0 :     return eRestyle_Self;
     303                 :   }
     304                 : 
     305               0 :   return nsRestyleHint(0);
     306                 : }
     307                 : 
     308                 : /* virtual */ bool
     309               0 : nsHTMLStyleSheet::MediumFeaturesChanged(nsPresContext* aPresContext)
     310                 : {
     311               0 :   return false;
     312                 : }
     313                 : 
     314                 : /* virtual */ size_t
     315               0 : nsHTMLStyleSheet::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
     316                 : {
     317               0 :   return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
     318                 : }
     319                 : 
     320                 : /* virtual */ size_t
     321               0 : nsHTMLStyleSheet::SizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
     322                 : {
     323               0 :   return 0; // nsHTMLStyleSheets are charged to the DOM, not layout
     324                 : }
     325                 : 
     326                 : /* virtual */ void
     327               0 : nsHTMLStyleSheet::RulesMatching(PseudoElementRuleProcessorData* aData)
     328                 : {
     329               0 : }
     330                 : 
     331                 : /* virtual */ void
     332               0 : nsHTMLStyleSheet::RulesMatching(AnonBoxRuleProcessorData* aData)
     333                 : {
     334               0 : }
     335                 : 
     336                 : #ifdef MOZ_XUL
     337                 : /* virtual */ void
     338               0 : nsHTMLStyleSheet::RulesMatching(XULTreeRuleProcessorData* aData)
     339                 : {
     340               0 : }
     341                 : #endif
     342                 : 
     343                 :   // nsIStyleSheet api
     344                 : /* virtual */ nsIURI*
     345               0 : nsHTMLStyleSheet::GetSheetURI() const
     346                 : {
     347               0 :   return mURL;
     348                 : }
     349                 : 
     350                 : /* virtual */ nsIURI*
     351               0 : nsHTMLStyleSheet::GetBaseURI() const
     352                 : {
     353               0 :   return mURL;
     354                 : }
     355                 : 
     356                 : /* virtual */ void
     357               0 : nsHTMLStyleSheet::GetTitle(nsString& aTitle) const
     358                 : {
     359               0 :   aTitle.Truncate();
     360               0 : }
     361                 : 
     362                 : /* virtual */ void
     363               0 : nsHTMLStyleSheet::GetType(nsString& aType) const
     364                 : {
     365               0 :   aType.AssignLiteral("text/html");
     366               0 : }
     367                 : 
     368                 : /* virtual */ bool
     369               0 : nsHTMLStyleSheet::HasRules() const
     370                 : {
     371               0 :   return true; // We have rules at all reasonable times
     372                 : }
     373                 : 
     374                 : /* virtual */ bool
     375               0 : nsHTMLStyleSheet::IsApplicable() const
     376                 : {
     377               0 :   return true;
     378                 : }
     379                 : 
     380                 : /* virtual */ void
     381               0 : nsHTMLStyleSheet::SetEnabled(bool aEnabled)
     382                 : { // these can't be disabled
     383               0 : }
     384                 : 
     385                 : /* virtual */ bool
     386               0 : nsHTMLStyleSheet::IsComplete() const
     387                 : {
     388               0 :   return true;
     389                 : }
     390                 : 
     391                 : /* virtual */ void
     392               0 : nsHTMLStyleSheet::SetComplete()
     393                 : {
     394               0 : }
     395                 : 
     396                 : /* virtual */ nsIStyleSheet*
     397               0 : nsHTMLStyleSheet::GetParentSheet() const
     398                 : {
     399               0 :   return nsnull;
     400                 : }
     401                 : 
     402                 : /* virtual */ nsIDocument*
     403               0 : nsHTMLStyleSheet::GetOwningDocument() const
     404                 : {
     405               0 :   return mDocument;
     406                 : }
     407                 : 
     408                 : /* virtual */ void
     409            1407 : nsHTMLStyleSheet::SetOwningDocument(nsIDocument* aDocument)
     410                 : {
     411            1407 :   mDocument = aDocument; // not refcounted
     412            1407 : }
     413                 : 
     414                 : nsresult
     415             469 : nsHTMLStyleSheet::Init(nsIURI* aURL, nsIDocument* aDocument)
     416                 : {
     417             469 :   NS_PRECONDITION(aURL && aDocument, "null ptr");
     418             469 :   if (! aURL || ! aDocument)
     419               0 :     return NS_ERROR_NULL_POINTER;
     420                 : 
     421             469 :   if (mURL || mDocument)
     422               0 :     return NS_ERROR_ALREADY_INITIALIZED;
     423                 : 
     424             469 :   mDocument = aDocument; // not refcounted!
     425             469 :   mURL = aURL;
     426             469 :   return NS_OK;
     427                 : }
     428                 : 
     429                 : void
     430               0 : nsHTMLStyleSheet::Reset(nsIURI* aURL)
     431                 : {
     432               0 :   mURL = aURL;
     433                 : 
     434               0 :   mLinkRule          = nsnull;
     435               0 :   mVisitedRule       = nsnull;
     436               0 :   mActiveRule        = nsnull;
     437                 : 
     438               0 :   if (mMappedAttrTable.ops) {
     439               0 :     PL_DHashTableFinish(&mMappedAttrTable);
     440               0 :     mMappedAttrTable.ops = nsnull;
     441                 :   }
     442               0 : }
     443                 : 
     444                 : nsresult
     445               0 : nsHTMLStyleSheet::ImplLinkColorSetter(nsRefPtr<HTMLColorRule>& aRule, nscolor aColor)
     446                 : {
     447               0 :   if (aRule && aRule->mColor == aColor) {
     448               0 :     return NS_OK;
     449                 :   }
     450                 : 
     451               0 :   aRule = new HTMLColorRule();
     452               0 :   if (!aRule)
     453               0 :     return NS_ERROR_OUT_OF_MEMORY;
     454                 : 
     455               0 :   aRule->mColor = aColor;
     456                 :   // Now make sure we restyle any links that might need it.  This
     457                 :   // shouldn't happen often, so just rebuilding everything is ok.
     458               0 :   if (mDocument && mDocument->GetShell()) {
     459               0 :     Element* root = mDocument->GetRootElement();
     460               0 :     if (root) {
     461                 :       mDocument->GetShell()->FrameConstructor()->
     462               0 :         PostRestyleEvent(root, eRestyle_Subtree, NS_STYLE_HINT_NONE);
     463                 :     }
     464                 :   }
     465               0 :   return NS_OK;
     466                 : }
     467                 : 
     468                 : nsresult
     469               0 : nsHTMLStyleSheet::SetLinkColor(nscolor aColor)
     470                 : {
     471               0 :   return ImplLinkColorSetter(mLinkRule, aColor);
     472                 : }
     473                 : 
     474                 : 
     475                 : nsresult
     476               0 : nsHTMLStyleSheet::SetActiveLinkColor(nscolor aColor)
     477                 : {
     478               0 :   return ImplLinkColorSetter(mActiveRule, aColor);
     479                 : }
     480                 : 
     481                 : nsresult
     482               0 : nsHTMLStyleSheet::SetVisitedLinkColor(nscolor aColor)
     483                 : {
     484               0 :   return ImplLinkColorSetter(mVisitedRule, aColor);
     485                 : }
     486                 : 
     487                 : already_AddRefed<nsMappedAttributes>
     488               0 : nsHTMLStyleSheet::UniqueMappedAttributes(nsMappedAttributes* aMapped)
     489                 : {
     490               0 :   if (!mMappedAttrTable.ops) {
     491                 :     bool res = PL_DHashTableInit(&mMappedAttrTable, &MappedAttrTable_Ops,
     492               0 :                                    nsnull, sizeof(MappedAttrTableEntry), 16);
     493               0 :     if (!res) {
     494               0 :       mMappedAttrTable.ops = nsnull;
     495               0 :       return nsnull;
     496                 :     }
     497                 :   }
     498                 :   MappedAttrTableEntry *entry = static_cast<MappedAttrTableEntry*>
     499               0 :                                            (PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_ADD));
     500               0 :   if (!entry)
     501               0 :     return nsnull;
     502               0 :   if (!entry->mAttributes) {
     503                 :     // We added a new entry to the hashtable, so we have a new unique set.
     504               0 :     entry->mAttributes = aMapped;
     505                 :   }
     506               0 :   NS_ADDREF(entry->mAttributes); // for caller
     507               0 :   return entry->mAttributes;
     508                 : }
     509                 : 
     510                 : void
     511               0 : nsHTMLStyleSheet::DropMappedAttributes(nsMappedAttributes* aMapped)
     512                 : {
     513               0 :   NS_ENSURE_TRUE(aMapped, /**/);
     514                 : 
     515               0 :   NS_ASSERTION(mMappedAttrTable.ops, "table uninitialized");
     516                 : #ifdef DEBUG
     517               0 :   PRUint32 entryCount = mMappedAttrTable.entryCount - 1;
     518                 : #endif
     519                 : 
     520               0 :   PL_DHashTableOperate(&mMappedAttrTable, aMapped, PL_DHASH_REMOVE);
     521                 : 
     522               0 :   NS_ASSERTION(entryCount == mMappedAttrTable.entryCount, "not removed");
     523                 : }
     524                 : 
     525                 : #ifdef DEBUG
     526                 : /* virtual */ void
     527               0 : nsHTMLStyleSheet::List(FILE* out, PRInt32 aIndent) const
     528                 : {
     529                 :   // Indent
     530               0 :   for (PRInt32 index = aIndent; --index >= 0; ) fputs("  ", out);
     531                 : 
     532               0 :   fputs("HTML Style Sheet: ", out);
     533               0 :   nsCAutoString urlSpec;
     534               0 :   mURL->GetSpec(urlSpec);
     535               0 :   if (!urlSpec.IsEmpty()) {
     536               0 :     fputs(urlSpec.get(), out);
     537                 :   }
     538               0 :   fputs("\n", out);
     539               0 : }
     540                 : #endif
     541                 : 
     542                 : static size_t
     543               0 : SizeOfAttributesEntryExcludingThis(PLDHashEntryHdr* aEntry,
     544                 :                                    nsMallocSizeOfFun aMallocSizeOf,
     545                 :                                    void* aArg)
     546                 : {
     547               0 :   NS_PRECONDITION(aEntry, "The entry should not be null!");
     548                 : 
     549               0 :   MappedAttrTableEntry* entry = static_cast<MappedAttrTableEntry*>(aEntry);
     550               0 :   NS_ASSERTION(entry->mAttributes, "entry->mAttributes should not be null!");
     551               0 :   return entry->mAttributes->SizeOfIncludingThis(aMallocSizeOf);
     552                 : }
     553                 : 
     554                 : size_t
     555               0 : nsHTMLStyleSheet::DOMSizeOfIncludingThis(nsMallocSizeOfFun aMallocSizeOf) const
     556                 : {
     557               0 :   size_t n = aMallocSizeOf(this);
     558                 : 
     559               0 :   if (mMappedAttrTable.ops) {
     560                 :     n += PL_DHashTableSizeOfExcludingThis(&mMappedAttrTable,
     561                 :                                           SizeOfAttributesEntryExcludingThis,
     562               0 :                                           aMallocSizeOf);
     563                 :   }
     564                 : 
     565                 :   // Measurement of the following members may be added later if DMD finds it is
     566                 :   // worthwhile:
     567                 :   // - mURL
     568                 :   // - mLinkRule
     569                 :   // - mVisitedRule
     570                 :   // - mActiveRule
     571                 :   // - mTableQuirkColorRule
     572                 :   // - mTableTHRule
     573                 :   //
     574                 :   // The following members are not measured:
     575                 :   // - mDocument, because it's non-owning
     576                 : 
     577               0 :   return n;
     578                 : }
     579                 : 
     580                 : // XXX For convenience and backwards compatibility
     581                 : nsresult
     582             469 : NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult, nsIURI* aURL, 
     583                 :                      nsIDocument* aDocument)
     584                 : {
     585                 :   nsresult rv;
     586                 :   nsHTMLStyleSheet* sheet;
     587             469 :   if (NS_FAILED(rv = NS_NewHTMLStyleSheet(&sheet)))
     588               0 :     return rv;
     589                 : 
     590             469 :   if (NS_FAILED(rv = sheet->Init(aURL, aDocument))) {
     591               0 :     NS_RELEASE(sheet);
     592               0 :     return rv;
     593                 :   }
     594                 : 
     595             469 :   *aInstancePtrResult = sheet;
     596             469 :   return NS_OK;
     597                 : }
     598                 : 
     599                 : 
     600                 : nsresult
     601             469 : NS_NewHTMLStyleSheet(nsHTMLStyleSheet** aInstancePtrResult)
     602                 : {
     603             469 :   NS_ASSERTION(aInstancePtrResult, "null out param");
     604                 : 
     605             469 :   nsHTMLStyleSheet *it = new nsHTMLStyleSheet();
     606             469 :   if (!it) {
     607               0 :     *aInstancePtrResult = nsnull;
     608               0 :     return NS_ERROR_OUT_OF_MEMORY;
     609                 :   }
     610                 : 
     611             469 :   NS_ADDREF(it);
     612             469 :   nsresult rv = it->Init();
     613             469 :   if (NS_FAILED(rv))
     614               0 :     NS_RELEASE(it);
     615                 : 
     616             469 :   *aInstancePtrResult = it; // NS_ADDREF above, or set to null by NS_RELEASE
     617             469 :   return rv;
     618                 : }
     619                 : 

Generated by: LCOV version 1.7