Back to index

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

An |nsCSSCompressedDataBlock| holds an immutable chunk of property-value data for a CSS declaration block (which we misname a |nsCSSDeclaration|). More...

#include <nsCSSDataBlock.h>

List of all members.

Public Member Functions

nsresult MapRuleInfoInto (nsRuleData *aRuleData) const
 Do what |nsIStyleRule::MapRuleInfoInto| needs to do for a style rule using this block for storage.
const voidStorageFor (nsCSSProperty aProperty) const
 Return the location at which the value for the property is stored, or null if the block does not contain a value for the property.
nsCSSCompressedDataBlockClone () const
 Clone this block, or return null on out-of-memory.
void Destroy ()
 Delete all the data stored in this block, and the block itself.

Static Public Member Functions

static nsCSSCompressedDataBlockCreateEmptyBlock ()
 Create a new nsCSSCompressedDataBlock holding no declarations.

Private Types

enum  { block_chars = 4 }

Private Member Functions

voidoperator new (size_t aBaseSize, size_t aDataSize)
 nsCSSCompressedDataBlock ()
 ~nsCSSCompressedDataBlock ()
char * Block ()
char * BlockEnd ()
const char * Block () const
const char * BlockEnd () const
ptrdiff_t DataSize () const

Private Attributes

PRInt32 mStyleBits
char * mBlockEnd
char mBlock_ [block_chars]

Friends

class nsCSSExpandedDataBlock

Detailed Description

An |nsCSSCompressedDataBlock| holds an immutable chunk of property-value data for a CSS declaration block (which we misname a |nsCSSDeclaration|).

Mutation is accomplished through |nsCSSExpandedDataBlock|.

Definition at line 51 of file nsCSSDataBlock.h.


Member Enumeration Documentation

anonymous enum [private]
Enumerator:
block_chars 

Definition at line 90 of file nsCSSDataBlock.h.

{ block_chars = 4 }; // put 4 chars in the definition of the class

Constructor & Destructor Documentation

Definition at line 99 of file nsCSSDataBlock.h.

: mStyleBits(0) {}

Here is the caller graph for this function:

Definition at line 103 of file nsCSSDataBlock.h.

{ }

Member Function Documentation

char* nsCSSCompressedDataBlock::Block ( ) [inline, private]

Definition at line 108 of file nsCSSDataBlock.h.

{ return mBlock_; }

Here is the caller graph for this function:

const char* nsCSSCompressedDataBlock::Block ( ) const [inline, private]

Definition at line 110 of file nsCSSDataBlock.h.

{ return mBlock_; }
char* nsCSSCompressedDataBlock::BlockEnd ( ) [inline, private]

Definition at line 109 of file nsCSSDataBlock.h.

{ return mBlockEnd; }

Here is the caller graph for this function:

const char* nsCSSCompressedDataBlock::BlockEnd ( ) const [inline, private]

Definition at line 111 of file nsCSSDataBlock.h.

{ return mBlockEnd; }

Clone this block, or return null on out-of-memory.

Definition at line 364 of file nsCSSDataBlock.cpp.

{
    const char *cursor = Block(), *cursor_end = BlockEnd();
    char *result_cursor;

    nsCSSCompressedDataBlock *result =
        new(cursor_end - cursor) nsCSSCompressedDataBlock();
    if (!result)
        return nsnull;
    result_cursor = result->Block();

    while (cursor < cursor_end) {
        nsCSSProperty iProp = PropertyAtCursor(cursor);
        NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                     "out of range");
        PropertyAtCursor(result_cursor) = iProp;

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

            case eCSSType_Rect: {
                const nsCSSRect* val = RectAtCursor(cursor);
                NS_ASSERTION(val->HasValue(), "oops");
                nsCSSRect* result_val = RectAtCursor(result_cursor);
                new (result_val) nsCSSRect(*val);
                cursor += CDBRectStorage_advance;
                result_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");
                nsCSSValuePair* result_val = ValuePairAtCursor(result_cursor);
                new (result_val) nsCSSValuePair(*val);
                cursor += CDBValuePairStorage_advance;
                result_cursor += CDBValuePairStorage_advance;
            } break;

            case eCSSType_ValueList:
            case eCSSType_CounterData:
            case eCSSType_Quotes:
            case eCSSType_Shadow: {
                void *copy;
                NS_ASSERTION(PointerAtCursor(cursor), "oops");
                switch (nsCSSProps::kTypeTable[iProp]) {
                    default:
                        NS_NOTREACHED("unreachable");
                        // fall through to keep gcc's uninitialized
                        // variable warning quiet
                    case eCSSType_ValueList:
                        copy = new nsCSSValueList(*ValueListAtCursor(cursor));
                        break;
                    case eCSSType_CounterData:
                        copy =
                            new nsCSSCounterData(*CounterDataAtCursor(cursor));
                        break;
                    case eCSSType_Quotes:
                        copy = new nsCSSQuotes(*QuotesAtCursor(cursor));
                        break;
                    case eCSSType_Shadow:
                        copy = new nsCSSShadow(*ShadowAtCursor(cursor));
                        break;
                }
                if (!copy) {
                    result->mBlockEnd = result_cursor;
                    result->Destroy();
                    return nsnull;
                }
                PointerAtCursor(result_cursor) = copy;
                cursor += CDBPointerStorage_advance;
                result_cursor += CDBPointerStorage_advance;
            } break;
        }
    }
    NS_ASSERTION(cursor == cursor_end, "inconsistent data");

    result->mBlockEnd = result_cursor;
    result->mStyleBits = mStyleBits;
    NS_ASSERTION(result->DataSize() == DataSize(), "wrong size");
    return result;
}

Here is the call graph for this function:

Create a new nsCSSCompressedDataBlock holding no declarations.

Definition at line 521 of file nsCSSDataBlock.cpp.

{
    nsCSSCompressedDataBlock *result = new(0) nsCSSCompressedDataBlock();
    if (!result)
        return nsnull;
    result->mBlockEnd = result->Block();
    return result;
}

Here is the call graph for this function:

Here is the caller graph for this function:

ptrdiff_t nsCSSCompressedDataBlock::DataSize ( ) const [inline, private]

Definition at line 112 of file nsCSSDataBlock.h.

{ return BlockEnd() - Block(); }

Here is the call graph for this function:

Here is the caller graph for this function:

Delete all the data stored in this block, and the block itself.

Definition at line 455 of file nsCSSDataBlock.cpp.

{
    const char* cursor = Block();
    const char* cursor_end = BlockEnd();
    while (cursor < cursor_end) {
        nsCSSProperty iProp = PropertyAtCursor(cursor);
        NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                     "out of range");

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

            case eCSSType_Rect: {
                const nsCSSRect* val = RectAtCursor(cursor);
                NS_ASSERTION(val->HasValue(), "oops");
                val->~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");
                val->~nsCSSValuePair();
                cursor += CDBValuePairStorage_advance;
            } break;

            case eCSSType_ValueList: {
                nsCSSValueList* val = ValueListAtCursor(cursor);
                NS_ASSERTION(val, "oops");
                delete val;
                cursor += CDBPointerStorage_advance;
            } break;

            case eCSSType_CounterData: {
                nsCSSCounterData* val = CounterDataAtCursor(cursor);
                NS_ASSERTION(val, "oops");
                delete val;
                cursor += CDBPointerStorage_advance;
            } break;

            case eCSSType_Quotes: {
                nsCSSQuotes* val = QuotesAtCursor(cursor);
                NS_ASSERTION(val, "oops");
                delete val;
                cursor += CDBPointerStorage_advance;
            } break;

            case eCSSType_Shadow: {
                nsCSSShadow* val = ShadowAtCursor(cursor);
                NS_ASSERTION(val, "oops");
                delete val;
                cursor += CDBPointerStorage_advance;
            } break;
        }
    }
    NS_ASSERTION(cursor == cursor_end, "inconsistent data");
    delete this;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Do what |nsIStyleRule::MapRuleInfoInto| needs to do for a style rule using this block for storage.

Definition at line 179 of file nsCSSDataBlock.cpp.

{
    // If we have no data for this struct, then return immediately.
    // This optimization should make us return most of the time, so we
    // have to worry much less (although still some) about the speed of
    // the rest of the function.
    if (!(nsCachedStyleData::GetBitForSID(aRuleData->mSID) & mStyleBits))
        return NS_OK;

    const char* cursor = Block();
    const char* cursor_end = BlockEnd();
    while (cursor < cursor_end) {
        nsCSSProperty iProp = PropertyAtCursor(cursor);
        NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                     "out of range");
        if (nsCSSProps::kSIDTable[iProp] == aRuleData->mSID) {
            void *prop =
                nsCSSExpandedDataBlock::RuleDataPropertyAt(aRuleData, iProp);
            switch (nsCSSProps::kTypeTable[iProp]) {
                case eCSSType_Value: {
                    nsCSSValue* target = NS_STATIC_CAST(nsCSSValue*, prop);
                    if (target->GetUnit() == eCSSUnit_Null) {
                        const nsCSSValue *val = ValueAtCursor(cursor);
                        NS_ASSERTION(val->GetUnit() != eCSSUnit_Null, "oops");
                        if ((iProp == eCSSProperty_background_image ||
                             iProp == eCSSProperty_list_style_image) &&
                            val->GetUnit() == eCSSUnit_URL) {
                            val->StartImageLoad(aRuleData->mPresContext->GetDocument(),
                                                iProp == eCSSProperty_background_image);
                        }
                        *target = *val;
                        if (iProp == eCSSProperty_font_family) {
                            // XXX Are there other things like this?
                            aRuleData->mFontData->mFamilyFromHTML = PR_FALSE;
                        }
                    }
                    cursor += CDBValueStorage_advance;
                } break;

                case eCSSType_Rect: {
                    const nsCSSRect* val = RectAtCursor(cursor);
                    NS_ASSERTION(val->HasValue(), "oops");
                    nsCSSRect* target = NS_STATIC_CAST(nsCSSRect*, prop);
                    if (target->mTop.GetUnit() == eCSSUnit_Null)
                        target->mTop = val->mTop;
                    if (target->mRight.GetUnit() == eCSSUnit_Null)
                        target->mRight = val->mRight;
                    if (target->mBottom.GetUnit() == eCSSUnit_Null)
                        target->mBottom = val->mBottom;
                    if (target->mLeft.GetUnit() == eCSSUnit_Null)
                        target->mLeft = val->mLeft;
                    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");
                    nsCSSValuePair* target = NS_STATIC_CAST(nsCSSValuePair*, prop);
                    if (target->mXValue.GetUnit() == eCSSUnit_Null)
                        target->mXValue = val->mXValue;
                    if (target->mYValue.GetUnit() == eCSSUnit_Null)
                        target->mYValue = val->mYValue;
                    cursor += CDBValuePairStorage_advance;
                } break;

                case eCSSType_ValueList:
                    if (iProp == eCSSProperty_content) {
                        for (nsCSSValueList* l = ValueListAtCursor(cursor);
                             l; l = l->mNext)
                            if (l->mValue.GetUnit() == eCSSUnit_URL)
                                l->mValue.StartImageLoad(
                                    aRuleData->mPresContext->GetDocument());
                    } else if (iProp == eCSSProperty_cursor) {
                        for (nsCSSValueList* l = ValueListAtCursor(cursor);
                             l; l = l->mNext)
                            if (l->mValue.GetUnit() == eCSSUnit_Array)
                                l->mValue.GetArrayValue()->Item(0).
                                    StartImageLoad(
                                    aRuleData->mPresContext->GetDocument());
                    }
                // fall through
                case eCSSType_CounterData:
                case eCSSType_Quotes:
                case eCSSType_Shadow: {
                    void** target = NS_STATIC_CAST(void**, prop);
                    if (!*target) {
                        void* val = PointerAtCursor(cursor);
                        NS_ASSERTION(val, "oops");
                        *target = val;
                    }
                    cursor += CDBPointerStorage_advance;
                } break;
            }
        } else {
            switch (nsCSSProps::kTypeTable[iProp]) {
                case eCSSType_Value: {
                    cursor += CDBValueStorage_advance;
                } break;

                case eCSSType_Rect: {
                    cursor += CDBRectStorage_advance;
                } break;

                case eCSSType_ValuePair: {
                    cursor += CDBValuePairStorage_advance;
                } break;

                case eCSSType_ValueList:
                case eCSSType_CounterData:
                case eCSSType_Quotes:
                case eCSSType_Shadow: {
                    cursor += CDBPointerStorage_advance;
                } break;
            }
        }
    }
    NS_ASSERTION(cursor == cursor_end, "inconsistent data");

    return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void* nsCSSCompressedDataBlock::operator new ( size_t  aBaseSize,
size_t  aDataSize 
) [inline, private]

Definition at line 93 of file nsCSSDataBlock.h.

                                                           {
        // subtract off the extra size to store |mBlock_|
        return ::operator new(aBaseSize + aDataSize -
                              sizeof(char) * block_chars);
    }

Return the location at which the value for the property is stored, or null if the block does not contain a value for the property.

This is either an |nsCSSValue*|, |nsCSSRect*|, or an |nsCSSValueList**|, etc.

Inefficient (by design).

Definition at line 302 of file nsCSSDataBlock.cpp.

{
    // If we have no data for this struct, then return immediately.
    // This optimization should make us return most of the time, so we
    // have to worry much less (although still some) about the speed of
    // the rest of the function.
    if (!(nsCachedStyleData::GetBitForSID(nsCSSProps::kSIDTable[aProperty]) &
          mStyleBits))
        return nsnull;

    const char* cursor = Block();
    const char* cursor_end = BlockEnd();
    while (cursor < cursor_end) {
        nsCSSProperty iProp = PropertyAtCursor(cursor);
        NS_ASSERTION(0 <= iProp && iProp < eCSSProperty_COUNT_no_shorthands,
                     "out of range");
        if (iProp == aProperty) {
            switch (nsCSSProps::kTypeTable[iProp]) {
                case eCSSType_Value: {
                    return ValueAtCursor(cursor);
                }
                case eCSSType_Rect: {
                    return RectAtCursor(cursor);
                }
                case eCSSType_ValuePair: {
                    return ValuePairAtCursor(cursor);
                }
                case eCSSType_ValueList:
                case eCSSType_CounterData:
                case eCSSType_Quotes:
                case eCSSType_Shadow: {
                    return &PointerAtCursor(NS_CONST_CAST(char*, cursor));
                }
            }
        }
        switch (nsCSSProps::kTypeTable[iProp]) {
            case eCSSType_Value: {
                cursor += CDBValueStorage_advance;
            } break;

            case eCSSType_Rect: {
                cursor += CDBRectStorage_advance;
            } break;

            case eCSSType_ValuePair: {
                cursor += CDBValuePairStorage_advance;
            } break;

            case eCSSType_ValueList:
            case eCSSType_CounterData:
            case eCSSType_Quotes:
            case eCSSType_Shadow: {
                cursor += CDBPointerStorage_advance;
            } break;
        }
    }
    NS_ASSERTION(cursor == cursor_end, "inconsistent data");

    return nsnull;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nsCSSExpandedDataBlock [friend]

Definition at line 53 of file nsCSSDataBlock.h.


Member Data Documentation

Definition at line 106 of file nsCSSDataBlock.h.

Definition at line 105 of file nsCSSDataBlock.h.

Definition at line 87 of file nsCSSDataBlock.h.


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