Back to index

lightning-sunbird  0.9+nobinonly
Classes | Functions | Variables
nsXBLPrototypeBinding.cpp File Reference
#include "nsCOMPtr.h"
#include "nsIAtom.h"
#include "nsIXBLDocumentInfo.h"
#include "nsIInputStream.h"
#include "nsINameSpaceManager.h"
#include "nsIURI.h"
#include "nsIURL.h"
#include "nsIDOMEventReceiver.h"
#include "nsIChannel.h"
#include "nsXPIDLString.h"
#include "nsReadableUtils.h"
#include "nsIParser.h"
#include "nsParserCIID.h"
#include "nsNetUtil.h"
#include "plstr.h"
#include "nsITextContent.h"
#include "nsIDocument.h"
#include "nsIXMLContentSink.h"
#include "nsContentCID.h"
#include "nsXMLDocument.h"
#include "nsIDOMElement.h"
#include "nsIDOMText.h"
#include "nsSupportsArray.h"
#include "nsXBLService.h"
#include "nsXBLBinding.h"
#include "nsXBLInsertionPoint.h"
#include "nsXBLPrototypeBinding.h"
#include "nsFixedSizeAllocator.h"
#include "xptinfo.h"
#include "nsIInterfaceInfoManager.h"
#include "nsIPresShell.h"
#include "nsIDocumentObserver.h"
#include "nsHTMLAtoms.h"
#include "nsXULAtoms.h"
#include "nsXBLAtoms.h"
#include "nsXBLProtoImpl.h"
#include "nsCRT.h"
#include "nsContentUtils.h"
#include "nsIScriptContext.h"
#include "nsICSSLoader.h"
#include "nsIStyleRuleProcessor.h"

Go to the source code of this file.

Classes

class  nsXBLAttributeEntry
class  nsXBLInsertionPointEntry
struct  InsertionData
struct  nsXBLAttrChangeData

Functions

PRBool PR_CALLBACK InstantiateInsertionPoint (nsHashKey *aKey, void *aData, void *aClosure)
PRBool PR_CALLBACK SetAttrs (nsHashKey *aKey, void *aData, void *aClosure)
PRBool PR_CALLBACK SetAttrsNS (nsHashKey *aKey, void *aData, void *aClosure)
static PRBool PR_CALLBACK DeleteAttributeEntry (nsHashKey *aKey, void *aData, void *aClosure)
static PRBool PR_CALLBACK DeleteAttributeTable (nsHashKey *aKey, void *aData, void *aClosure)
static PRBool PR_CALLBACK DeleteInsertionPointEntry (nsHashKey *aKey, void *aData, void *aClosure)

Variables

static const PRInt32 kNumElements = 128
static const size_t kAttrBucketSizes []
static const PRInt32 kAttrNumBuckets = sizeof(kAttrBucketSizes)/sizeof(size_t)
static const PRInt32 kAttrInitialSize = (NS_SIZE_IN_HEAP(sizeof(nsXBLAttributeEntry))) * kNumElements
static const size_t kInsBucketSizes []
static const PRInt32 kInsNumBuckets = sizeof(kInsBucketSizes)/sizeof(size_t)
static const PRInt32 kInsInitialSize = (NS_SIZE_IN_HEAP(sizeof(nsXBLInsertionPointEntry))) * kNumElements

Function Documentation

static PRBool PR_CALLBACK DeleteAttributeEntry ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 982 of file nsXBLPrototypeBinding.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool PR_CALLBACK DeleteAttributeTable ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 989 of file nsXBLPrototypeBinding.cpp.

{
  delete NS_STATIC_CAST(nsObjectHashtable*, aData);
  return PR_TRUE;
}

Here is the caller graph for this function:

static PRBool PR_CALLBACK DeleteInsertionPointEntry ( nsHashKey *  aKey,
void aData,
void aClosure 
) [static]

Definition at line 1115 of file nsXBLPrototypeBinding.cpp.

Here is the caller graph for this function:

PRBool PR_CALLBACK InstantiateInsertionPoint ( nsHashKey *  aKey,
void aData,
void aClosure 
)

Definition at line 554 of file nsXBLPrototypeBinding.cpp.

{
  nsXBLInsertionPointEntry* entry = NS_STATIC_CAST(nsXBLInsertionPointEntry*, aData);
  InsertionData* data = NS_STATIC_CAST(InsertionData*, aClosure);
  nsXBLBinding* binding = data->mBinding;
  nsXBLPrototypeBinding* proto = data->mPrototype;

  // Get the insertion parent.
  nsIContent* content = entry->GetInsertionParent();
  PRUint32 index = entry->GetInsertionIndex();
  nsIContent* defContent = entry->GetDefaultContent();

  // Locate the real content.
  nsIContent *instanceRoot = binding->GetAnonymousContent();
  nsIContent *templRoot = proto->GetImmediateChild(nsXBLAtoms::content);
  nsIContent *realContent = proto->LocateInstance(nsnull, templRoot,
                                                  instanceRoot, content);
  if (!realContent)
    realContent = binding->GetBoundElement();

  // Now that we have the real content, look it up in our table.
  nsVoidArray* points;
  binding->GetInsertionPointsFor(realContent, &points);
  nsXBLInsertionPoint* insertionPoint = nsnull;
  PRInt32 count = points->Count();
  PRInt32 i = 0;
  PRInt32 currIndex = 0;  
  
  for ( ; i < count; i++) {
    nsXBLInsertionPoint* currPoint = NS_STATIC_CAST(nsXBLInsertionPoint*, points->ElementAt(i));
    currIndex = currPoint->GetInsertionIndex();
    if (currIndex == (PRInt32)index) {
      // This is a match. Break out of the loop and set our variable.
      insertionPoint = currPoint;
      break;
    }
    
    if (currIndex > (PRInt32)index)
      // There was no match. Break.
      break;
  }

  if (!insertionPoint) {
    // We need to make a new insertion point.
    insertionPoint = new nsXBLInsertionPoint(realContent, index, defContent);
    if (insertionPoint) {
      NS_ADDREF(insertionPoint);
      points->InsertElementAt(insertionPoint, i);
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK SetAttrs ( nsHashKey *  aKey,
void aData,
void aClosure 
)

Definition at line 854 of file nsXBLPrototypeBinding.cpp.

{
  nsXBLAttributeEntry* entry = NS_STATIC_CAST(nsXBLAttributeEntry*, aData);
  nsXBLAttrChangeData* changeData = NS_STATIC_CAST(nsXBLAttrChangeData*, aClosure);

  nsIAtom* src = entry->GetSrcAttribute();
  PRInt32 srcNs = changeData->mSrcNamespace;
  nsAutoString value;
  PRBool attrPresent = PR_TRUE;

  if (src == nsHTMLAtoms::text && srcNs == kNameSpaceID_XBL) {
    nsXBLBinding::GetTextData(changeData->mBoundElement, value);
    value.StripChar(PRUnichar('\n'));
    value.StripChar(PRUnichar('\r'));
    nsAutoString stripVal(value);
    stripVal.StripWhitespace();

    if (stripVal.IsEmpty()) 
      attrPresent = PR_FALSE;
  }
  else {
    nsresult result = changeData->mBoundElement->GetAttr(srcNs, src, value);
    attrPresent = (result == NS_CONTENT_ATTR_NO_VALUE ||
                   result == NS_CONTENT_ATTR_HAS_VALUE);
  }

  if (attrPresent) {
    nsIContent* content =
      changeData->mProto->GetImmediateChild(nsXBLAtoms::content);

    nsXBLAttributeEntry* curr = entry;
    while (curr) {
      nsIAtom* dst = curr->GetDstAttribute();
      PRInt32 dstNs = curr->GetDstNameSpace();
      nsIContent* element = curr->GetElement();

      nsIContent *realElement =
        changeData->mProto->LocateInstance(changeData->mBoundElement, content,
                                           changeData->mContent, element);

      if (realElement) {
        realElement->SetAttr(dstNs, dst, value, PR_FALSE);

        if ((dst == nsHTMLAtoms::text && dstNs == kNameSpaceID_XBL) ||
            (realElement->GetNodeInfo()->Equals(nsHTMLAtoms::html,
                                                kNameSpaceID_XUL) &&
             dst == nsHTMLAtoms::value && !value.IsEmpty())) {

          nsCOMPtr<nsITextContent> textContent;
          NS_NewTextNode(getter_AddRefs(textContent),
                         realElement->GetNodeInfo()->NodeInfoManager());
          if (!textContent) {
            continue;
          }

          textContent->SetText(value, PR_TRUE);
          realElement->AppendChildTo(textContent, PR_TRUE);
        }
      }

      curr = curr->GetNext();
    }
  }

  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

PRBool PR_CALLBACK SetAttrsNS ( nsHashKey *  aKey,
void aData,
void aClosure 
)

Definition at line 921 of file nsXBLPrototypeBinding.cpp.

{
  if (aData && aClosure) {
    nsPRUint32Key * key = NS_STATIC_CAST(nsPRUint32Key*, aKey);
    nsObjectHashtable* xblAttributes =
      NS_STATIC_CAST(nsObjectHashtable*, aData);
    nsXBLAttrChangeData * changeData = NS_STATIC_CAST(nsXBLAttrChangeData *,
                                                      aClosure);
    changeData->mSrcNamespace = key->GetValue();
    xblAttributes->Enumerate(SetAttrs, (void*)changeData);
  }
  return PR_TRUE;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

const size_t kAttrBucketSizes[] [static]
Initial value:
 {
  sizeof(nsXBLAttributeEntry)
}

Definition at line 217 of file nsXBLPrototypeBinding.cpp.

Definition at line 222 of file nsXBLPrototypeBinding.cpp.

const PRInt32 kAttrNumBuckets = sizeof(kAttrBucketSizes)/sizeof(size_t) [static]

Definition at line 221 of file nsXBLPrototypeBinding.cpp.

const size_t kInsBucketSizes[] [static]
Initial value:

Definition at line 224 of file nsXBLPrototypeBinding.cpp.

Definition at line 229 of file nsXBLPrototypeBinding.cpp.

const PRInt32 kInsNumBuckets = sizeof(kInsBucketSizes)/sizeof(size_t) [static]

Definition at line 228 of file nsXBLPrototypeBinding.cpp.

const PRInt32 kNumElements = 128 [static]

Definition at line 215 of file nsXBLPrototypeBinding.cpp.