Back to index

lightning-sunbird  0.9+nobinonly
Classes | Public Member Functions | Static Public Member Functions | Public Attributes | Private Types | Private Member Functions | Private Attributes | Static Private Attributes
nsCSSExpandedDataBlock Class Reference

#include <nsCSSDataBlock.h>

Collaboration diagram for nsCSSExpandedDataBlock:
Collaboration graph
[legend]

List of all members.

Classes

struct  ComputeSizeResult
 Compute the size that will be occupied by the result of |Compress|. More...
struct  PropertyOffsetInfo

Public Member Functions

 nsCSSExpandedDataBlock ()
 ~nsCSSExpandedDataBlock ()
void Expand (nsCSSCompressedDataBlock **aNormalBlock, nsCSSCompressedDataBlock **aImportantBlock)
 Transfer all of the state from the compressed block to this expanded block.
void Compress (nsCSSCompressedDataBlock **aNormalBlock, nsCSSCompressedDataBlock **aImportantBlock)
 Allocate a new compressed block and transfer all of the state from this expanded block to the new compressed block, clearing the state of this expanded block.
void Clear ()
 Clear (and thus destroy) the state of this expanded block.
void ClearProperty (nsCSSProperty aPropID)
 Clear the data for the given property (including the set and important bits).
void AssertInitialState ()
voidPropertyAt (nsCSSProperty aProperty)
void AssertInSetRange (nsCSSProperty aProperty)
void SetPropertyBit (nsCSSProperty aProperty)
void ClearPropertyBit (nsCSSProperty aProperty)
PRBool HasPropertyBit (nsCSSProperty aProperty)
void SetImportantBit (nsCSSProperty aProperty)
void ClearImportantBit (nsCSSProperty aProperty)
PRBool HasImportantBit (nsCSSProperty aProperty)
void ClearSets ()

Static Public Member Functions

static voidRuleDataPropertyAt (nsRuleData *aRuleData, nsCSSProperty aProperty)

Public Attributes

nsCSSFont mFont
nsCSSDisplay mDisplay
nsCSSMargin mMargin
nsCSSList mList
nsCSSPosition mPosition
nsCSSTable mTable
nsCSSColor mColor
nsCSSContent mContent
nsCSSText mText
nsCSSUserInterface mUserInterface
nsCSSAural mAural
nsCSSPage mPage
nsCSSBreaks mBreaks
nsCSSXUL mXUL
nsCSSColumn mColumn

Private Types

enum  { kPropertiesSetChunkSize = 8 }
enum  { kPropertiesSetChunkCount }
typedef PRUint8 property_set_type

Private Member Functions

ComputeSizeResult ComputeSize ()
void DoExpand (nsCSSCompressedDataBlock *aBlock, PRBool aImportant)

Private Attributes

property_set_type mPropertiesSet [kPropertiesSetChunkCount]
property_set_type mPropertiesImportant [kPropertiesSetChunkCount]

Static Private Attributes

static const PropertyOffsetInfo kOffsetTable []

Detailed Description

Definition at line 115 of file nsCSSDataBlock.h.


Class Documentation

struct nsCSSExpandedDataBlock::ComputeSizeResult

Compute the size that will be occupied by the result of |Compress|.

Definition at line 186 of file nsCSSDataBlock.h.

Class Members
PRUint32 important
PRUint32 normal
struct nsCSSExpandedDataBlock::PropertyOffsetInfo

Definition at line 197 of file nsCSSDataBlock.h.

Class Members
size_t block_offset
size_t ruledata_member_offset
size_t ruledata_struct_offset

Member Typedef Documentation

Definition at line 207 of file nsCSSDataBlock.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
kPropertiesSetChunkSize 

Definition at line 208 of file nsCSSDataBlock.h.

{ kPropertiesSetChunkSize = 8 }; // number of bits in
anonymous enum [private]
Enumerator:
kPropertiesSetChunkCount 

Definition at line 211 of file nsCSSDataBlock.h.

         { kPropertiesSetChunkCount =
             (eCSSProperty_COUNT_no_shorthands + (kPropertiesSetChunkSize-1)) /
             kPropertiesSetChunkSize };

Constructor & Destructor Documentation

Definition at line 532 of file nsCSSDataBlock.cpp.

Here is the call graph for this function:

Definition at line 538 of file nsCSSDataBlock.cpp.

Here is the call graph for this function:


Member Function Documentation

Definition at line 175 of file nsCSSDataBlock.h.

                              {
#ifdef DEBUG
        DoAssertInitialState();
#endif
    }

Here is the caller graph for this function:

Definition at line 257 of file nsCSSDataBlock.h.

                                                   {
        NS_ASSERTION(0 <= aProperty &&
                     aProperty < eCSSProperty_COUNT_no_shorthands,
                     "out of bounds");
    }

Here is the caller graph for this function:

Clear (and thus destroy) the state of this expanded block.

Definition at line 826 of file nsCSSDataBlock.cpp.

{
    for (PRUint32 iHigh = 0; iHigh < NS_ARRAY_LENGTH(mPropertiesSet); ++iHigh) {
        if (mPropertiesSet[iHigh] == 0)
            continue;
        for (PRInt32 iLow = 0; iLow < kPropertiesSetChunkSize; ++iLow) {
            if ((mPropertiesSet[iHigh] & (1 << iLow)) == 0)
                continue;
            nsCSSProperty iProp =
                nsCSSProperty(iHigh * kPropertiesSetChunkSize + iLow);
            ClearProperty(iProp);
        }
    }

    AssertInitialState();
}

Here is the call graph for this function:

Definition at line 287 of file nsCSSDataBlock.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Clear the data for the given property (including the set and important bits).

Definition at line 844 of file nsCSSDataBlock.cpp.

{
    NS_ASSERTION(0 <= aPropID && aPropID < eCSSProperty_COUNT_no_shorthands,
                 "out of range");

    ClearPropertyBit(aPropID);
    ClearImportantBit(aPropID);

    void *prop = PropertyAt(aPropID);
    switch (nsCSSProps::kTypeTable[aPropID]) {
        case eCSSType_Value: {
            nsCSSValue* val = NS_STATIC_CAST(nsCSSValue*, prop);
            val->Reset();
        } break;

        case eCSSType_Rect: {
            nsCSSRect* val = NS_STATIC_CAST(nsCSSRect*, prop);
            val->Reset();
        } break;

        case eCSSType_ValuePair: {
            nsCSSValuePair* val = NS_STATIC_CAST(nsCSSValuePair*, prop);
            val->mXValue.Reset();
            val->mYValue.Reset();
        } break;

        case eCSSType_ValueList: {
            nsCSSValueList*& val = *NS_STATIC_CAST(nsCSSValueList**, prop);
            if (val) {
                delete val;
                val = nsnull;
            }
        } break;

        case eCSSType_CounterData: {
            nsCSSCounterData*& val =
                *NS_STATIC_CAST(nsCSSCounterData**, prop);
            if (val) {
                delete val;
                val = nsnull;
            }
        } break;

        case eCSSType_Quotes: {
            nsCSSQuotes*& val = *NS_STATIC_CAST(nsCSSQuotes**, prop);
            if (val) {
                delete val;
                val = nsnull;
            }
        } break;

        case eCSSType_Shadow: {
            nsCSSShadow*& val = *NS_STATIC_CAST(nsCSSShadow**, prop);
            if (val) {
                delete val;
                val = nsnull;
            }
        } break;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 269 of file nsCSSDataBlock.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 299 of file nsCSSDataBlock.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Allocate a new compressed block and transfer all of the state from this expanded block to the new compressed block, clearing the state of this expanded block.

Definition at line 703 of file nsCSSDataBlock.cpp.

{
    nsCSSCompressedDataBlock *result_normal, *result_important;
    char *cursor_normal, *cursor_important;

    ComputeSizeResult size = ComputeSize();
    
    result_normal = new(size.normal) nsCSSCompressedDataBlock();
    if (!result_normal) {
        *aNormalBlock = nsnull;
        *aImportantBlock = nsnull;
        return;
    }
    cursor_normal = result_normal->Block();

    if (size.important != 0) {
        result_important = new(size.important) nsCSSCompressedDataBlock();
        if (!result_important) {
            delete result_normal;
            *aNormalBlock = nsnull;
            *aImportantBlock = nsnull;
            return;
        }
        cursor_important = result_important->Block();
    } else {
        result_important = nsnull;
    }

    /*
     * Save needless copying and allocation by copying the memory
     * corresponding to the stored data in the expanded block, and then
     * clearing the data in the expanded block.
     */
    for (PRUint32 iHigh = 0; iHigh < NS_ARRAY_LENGTH(mPropertiesSet); ++iHigh) {
        if (mPropertiesSet[iHigh] == 0)
            continue;
        for (PRInt32 iLow = 0; iLow < kPropertiesSetChunkSize; ++iLow) {
            if ((mPropertiesSet[iHigh] & (1 << iLow)) == 0)
                continue;
            nsCSSProperty iProp =
                nsCSSProperty(iHigh * kPropertiesSetChunkSize + iLow);
            NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                         "out of range");
            void *prop = PropertyAt(iProp);
            PRBool important =
                (mPropertiesImportant[iHigh] & (1 << iLow)) != 0;
            char *&cursor = important ? cursor_important : cursor_normal;
            nsCSSCompressedDataBlock *result =
                important ? result_important : result_normal;
            switch (nsCSSProps::kTypeTable[iProp]) {
                case eCSSType_Value: {
                    nsCSSValue* val = NS_STATIC_CAST(nsCSSValue*, prop);
                    NS_ASSERTION(val->GetUnit() != eCSSUnit_Null,
                                 "Null value while compressing");
                    CDBValueStorage *storage =
                        NS_REINTERPRET_CAST(CDBValueStorage*, cursor);
                    storage->property = iProp;
                    memcpy(&storage->value, val, sizeof(nsCSSValue));
                    new (val) nsCSSValue();
                    cursor += CDBValueStorage_advance;
                } break;

                case eCSSType_Rect: {
                    nsCSSRect* val = NS_STATIC_CAST(nsCSSRect*, prop);
                    NS_ASSERTION(val->HasValue(),
                                 "Valueless rect while compressing");
                    CDBRectStorage *storage =
                        NS_REINTERPRET_CAST(CDBRectStorage*, cursor);
                    storage->property = iProp;
                    memcpy(&storage->value, val, sizeof(nsCSSRect));
                    new (val) nsCSSRect();
                    cursor += CDBRectStorage_advance;
                } break;

                case eCSSType_ValuePair: {
                    nsCSSValuePair* val = NS_STATIC_CAST(nsCSSValuePair*, prop);
                    NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
                                 val->mYValue.GetUnit() != eCSSUnit_Null,
                                 "Valueless pair while compressing");
                    CDBValuePairStorage *storage =
                        NS_REINTERPRET_CAST(CDBValuePairStorage*, cursor);
                    storage->property = iProp;
                    memcpy(&storage->value, val, sizeof(nsCSSValuePair));
                    new (val) nsCSSValuePair();
                    cursor += CDBValuePairStorage_advance;
                } break;

                case eCSSType_ValueList:
                case eCSSType_CounterData:
                case eCSSType_Quotes:
                case eCSSType_Shadow: {
                    void*& val = *NS_STATIC_CAST(void**, prop);
                    NS_ASSERTION(val, "Null pointer while compressing");
                    CDBPointerStorage *storage =
                        NS_REINTERPRET_CAST(CDBPointerStorage*, cursor);
                    storage->property = iProp;
                    storage->value = val;
                    val = nsnull;
                    cursor += CDBPointerStorage_advance;
                } break;
            }
            result->mStyleBits |=
                nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[iProp]);
        }
    }

    result_normal->mBlockEnd = cursor_normal;
    NS_ASSERTION(result_normal->DataSize() == ptrdiff_t(size.normal),
                 "size miscalculation");
    if (result_important) {
        result_important->mBlockEnd = cursor_important;
        NS_ASSERTION(result_important->DataSize() == ptrdiff_t(size.important),
                     "size miscalculation");
    }

    ClearSets();
    AssertInitialState();
    *aNormalBlock = result_normal;
    *aImportantBlock = result_important;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 638 of file nsCSSDataBlock.cpp.

{
    ComputeSizeResult result = {0, 0};
    for (PRUint32 iHigh = 0; iHigh < NS_ARRAY_LENGTH(mPropertiesSet); ++iHigh) {
        if (mPropertiesSet[iHigh] == 0)
            continue;
        for (PRInt32 iLow = 0; iLow < kPropertiesSetChunkSize; ++iLow) {
            if ((mPropertiesSet[iHigh] & (1 << iLow)) == 0)
                continue;
            nsCSSProperty iProp =
                nsCSSProperty(iHigh * kPropertiesSetChunkSize + iLow);
            NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                         "out of range");
            void *prop = PropertyAt(iProp);
            PRUint32 increment = 0;
            switch (nsCSSProps::kTypeTable[iProp]) {
                case eCSSType_Value: {
#ifdef DEBUG
                    nsCSSValue* val = NS_STATIC_CAST(nsCSSValue*, prop);
                    NS_ASSERTION(val->GetUnit() != eCSSUnit_Null,
                                 "null value while computing size");
#endif
                    increment = CDBValueStorage_advance;
                } break;

                case eCSSType_Rect: {
#ifdef DEBUG
                    nsCSSRect* val = NS_STATIC_CAST(nsCSSRect*, prop);
                    NS_ASSERTION(val->HasValue(),
                                 "Valueless rect while computing size");
#endif
                    increment = CDBRectStorage_advance;
                } break;

                case eCSSType_ValuePair: {
#ifdef DEBUG
                    nsCSSValuePair* val = NS_STATIC_CAST(nsCSSValuePair*, prop);
                    NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
                                 val->mYValue.GetUnit() != eCSSUnit_Null,
                                 "Valueless pair while computing size");
#endif
                    increment = CDBValuePairStorage_advance;
                } break;

                case eCSSType_ValueList:
                case eCSSType_CounterData:
                case eCSSType_Quotes:
                case eCSSType_Shadow: {
#ifdef DEBUG
                    void* val = *NS_STATIC_CAST(void**, prop);
                    NS_ASSERTION(val, "Null pointer while computing size");
#endif
                    increment = CDBPointerStorage_advance;
                } break;
            }
            if ((mPropertiesImportant[iHigh] & (1 << iLow)) == 0)
                result.normal += increment;
            else
                result.important += increment;
        }
    }
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsCSSExpandedDataBlock::DoExpand ( nsCSSCompressedDataBlock aBlock,
PRBool  aImportant 
) [private]

Definition at line 559 of file nsCSSDataBlock.cpp.

{
    NS_PRECONDITION(aBlock, "unexpected null block");

    /*
     * Save needless copying and allocation by copying the memory
     * corresponding to the stored data in the compressed block, and
     * then, to avoid destructors, deleting the compressed block by
     * calling |delete| instead of using its |Destroy| method.
     */
    const char* cursor = aBlock->Block();
    const char* cursor_end = aBlock->BlockEnd();
    while (cursor < cursor_end) {
        nsCSSProperty iProp = PropertyAtCursor(cursor);
        NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                     "out of range");
        NS_ASSERTION(!HasPropertyBit(iProp),
                     "compressed block has property multiple times");
        SetPropertyBit(iProp);
        if (aImportant)
            SetImportantBit(iProp);
        void *prop = PropertyAt(iProp);

        switch (nsCSSProps::kTypeTable[iProp]) {
            case eCSSType_Value: {
                const nsCSSValue* val = ValueAtCursor(cursor);
                NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
                memcpy(prop, val, sizeof(nsCSSValue));
                cursor += CDBValueStorage_advance;
            } break;

            case eCSSType_Rect: {
                const nsCSSRect* val = RectAtCursor(cursor);
                NS_ASSERTION(val->HasValue(), "oops");
                memcpy(prop, val, sizeof(nsCSSRect));
                cursor += CDBRectStorage_advance;
            } break;

            case eCSSType_ValuePair: {
                const nsCSSValuePair* val = ValuePairAtCursor(cursor);
                NS_ASSERTION(val->mXValue.GetUnit() != eCSSUnit_Null ||
                             val->mYValue.GetUnit() != eCSSUnit_Null, "oops");
                memcpy(prop, val, sizeof(nsCSSValuePair));
                cursor += CDBValuePairStorage_advance;
            } break;

            case eCSSType_ValueList:
            case eCSSType_CounterData:
            case eCSSType_Quotes:
            case eCSSType_Shadow: {
                void* val = PointerAtCursor(cursor);
                NS_ASSERTION(val, "oops");
                *NS_STATIC_CAST(void**, prop) = val;
                cursor += CDBPointerStorage_advance;
            } break;
        }
    }
    NS_ASSERTION(cursor == cursor_end, "inconsistent data");

    delete aBlock;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Transfer all of the state from the compressed block to this expanded block.

The state of this expanded block must be clear beforehand.

The compressed block passed in IS DESTROYED by this method and set to null, and thus cannot be used again. (This is necessary because ownership of sub-objects is transferred to the expanded block.)

Definition at line 623 of file nsCSSDataBlock.cpp.

{
    NS_PRECONDITION(*aNormalBlock, "unexpected null block");
    AssertInitialState();

    DoExpand(*aNormalBlock, PR_FALSE);
    *aNormalBlock = nsnull;
    if (*aImportantBlock) {
        DoExpand(*aImportantBlock, PR_TRUE);
        *aImportantBlock = nsnull;
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 293 of file nsCSSDataBlock.h.

                                                    {
        AssertInSetRange(aProperty);
        return (mPropertiesImportant[aProperty / kPropertiesSetChunkSize] &
                (1 << (aProperty % kPropertiesSetChunkSize))) != 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 275 of file nsCSSDataBlock.h.

                                                   {
        AssertInSetRange(aProperty);
        return (mPropertiesSet[aProperty / kPropertiesSetChunkSize] &
                (1 << (aProperty % kPropertiesSetChunkSize))) != 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 232 of file nsCSSDataBlock.h.

                                              {
        const PropertyOffsetInfo& offsets =
            nsCSSExpandedDataBlock::kOffsetTable[aProperty];
        return NS_REINTERPRET_CAST(void*, NS_REINTERPRET_CAST(char*, this) +
                                          offsets.block_offset);
    }

Here is the caller graph for this function:

static void* nsCSSExpandedDataBlock::RuleDataPropertyAt ( nsRuleData aRuleData,
nsCSSProperty  aProperty 
) [inline, static]

Definition at line 244 of file nsCSSDataBlock.h.

                                                             {
        const PropertyOffsetInfo& offsets =
            nsCSSExpandedDataBlock::kOffsetTable[aProperty];
        NS_ASSERTION(offsets.ruledata_struct_offset != size_t(-1),
                     "property should not use CSS_PROP_BACKENDONLY");
        char* cssstruct = *NS_REINTERPRET_CAST(char**,
                              NS_REINTERPRET_CAST(char*, aRuleData) +
                              offsets.ruledata_struct_offset);
        return NS_REINTERPRET_CAST(void*,
                                   cssstruct + offsets.ruledata_member_offset);
    }

Here is the caller graph for this function:

Definition at line 281 of file nsCSSDataBlock.h.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 263 of file nsCSSDataBlock.h.

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 205 of file nsCSSDataBlock.h.

Definition at line 134 of file nsCSSDataBlock.h.

Definition at line 136 of file nsCSSDataBlock.h.

Definition at line 130 of file nsCSSDataBlock.h.

Definition at line 141 of file nsCSSDataBlock.h.

Definition at line 131 of file nsCSSDataBlock.h.

Definition at line 125 of file nsCSSDataBlock.h.

Definition at line 124 of file nsCSSDataBlock.h.

Definition at line 127 of file nsCSSDataBlock.h.

Definition at line 126 of file nsCSSDataBlock.h.

Definition at line 135 of file nsCSSDataBlock.h.

Definition at line 128 of file nsCSSDataBlock.h.

Definition at line 224 of file nsCSSDataBlock.h.

Definition at line 220 of file nsCSSDataBlock.h.

Definition at line 129 of file nsCSSDataBlock.h.

Definition at line 132 of file nsCSSDataBlock.h.

Definition at line 133 of file nsCSSDataBlock.h.

Definition at line 137 of file nsCSSDataBlock.h.


The documentation for this class was generated from the following files: