Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Attributes | Friends
nsXTFService Class Reference
Inheritance diagram for nsXTFService:
Inheritance graph
[legend]
Collaboration diagram for nsXTFService:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS nsresult CreateElement (nsIContent **aResult, nsINodeInfo *aNodeInfo)

Protected Member Functions

 nsXTFService ()

Private Attributes

nsInterfaceHashtable
< nsUint32HashKey,
nsIXTFElementFactory
mFactoryHash

Friends

nsresult NS_NewXTFService (nsIXTFService **aResult)

Detailed Description

Definition at line 63 of file nsXTFService.cpp.


Constructor & Destructor Documentation

nsXTFService::nsXTFService ( ) [protected]

Definition at line 84 of file nsXTFService.cpp.

{
  mFactoryHash.Init(); // XXX this can fail. move to Init()
}

Here is the call graph for this function:


Member Function Documentation

nsresult nsXTFService::CreateElement ( nsIContent **  aResult,
nsINodeInfo aNodeInfo 
) [virtual]

Implements nsIXTFService.

Definition at line 114 of file nsXTFService.cpp.

{
  nsCOMPtr<nsIXTFElementFactory> factory;

  // Check if we have an xtf factory for the given namespaceid in our cache:
  if (!mFactoryHash.Get(aNodeInfo->NamespaceID(), getter_AddRefs(factory))) {
    // No. See if there is one registered with the component manager:
    nsCAutoString xtf_contract_id(NS_XTF_ELEMENT_FACTORY_CONTRACTID_PREFIX);
    nsAutoString uri;
    aNodeInfo->GetNamespaceURI(uri);
    AppendUTF16toUTF8(uri, xtf_contract_id);
#ifdef DEBUG_xtf_verbose
    printf("Testing for XTF factory at %s\n", xtf_contract_id.get());
#endif
    factory = do_GetService(xtf_contract_id.get());
    if (factory) {
#ifdef DEBUG
      printf("We've got an XTF factory.\n");
#endif
      // Put into hash:
      mFactoryHash.Put(aNodeInfo->NamespaceID(), factory);
    }
  }
  if (!factory) return NS_ERROR_FAILURE;

  // We have an xtf factory. Now try to create an element for the given tag name:
  nsCOMPtr<nsIXTFElement> elem;
  nsAutoString tagName;
  aNodeInfo->GetName(tagName);
  factory->CreateElement(tagName, getter_AddRefs(elem));
  if (!elem) return NS_ERROR_FAILURE;
  
  // We've got an xtf element. Create an appropriate wrapper for it:
  PRUint32 elementType;
  elem->GetElementType(&elementType);
  switch (elementType) {
    case nsIXTFElement::ELEMENT_TYPE_GENERIC_ELEMENT:
    {
      nsCOMPtr<nsIXTFGenericElement> elem2 = do_QueryInterface(elem);
      return NS_NewXTFGenericElementWrapper(elem2, aNodeInfo, aResult);
    }
    case nsIXTFElement::ELEMENT_TYPE_BINDABLE:
    {
      nsCOMPtr<nsIXTFBindableElement> elem2 = do_QueryInterface(elem);
      return NS_NewXTFBindableElementWrapper(elem2, aNodeInfo, aResult);
    }
    case nsIXTFElement::ELEMENT_TYPE_SVG_VISUAL:
    {
#ifdef MOZ_SVG
      nsCOMPtr<nsIXTFSVGVisual> elem2 = do_QueryInterface(elem);
      return NS_NewXTFSVGVisualWrapper(elem2, aNodeInfo, aResult);
#else
      NS_ERROR("xtf svg visuals are only supported in mozilla builds with native svg support");
      break;
#endif
    }
    case nsIXTFElement::ELEMENT_TYPE_XML_VISUAL:
    {
      nsCOMPtr<nsIXTFXMLVisual> elem2 = do_QueryInterface(elem);
      return NS_NewXTFXMLVisualWrapper(elem2, aNodeInfo, aResult);
    }
    case nsIXTFElement::ELEMENT_TYPE_XUL_VISUAL:
    {
      nsCOMPtr<nsIXTFXULVisual> elem2 = do_QueryInterface(elem);
      return NS_NewXTFXULVisualWrapper(elem2, aNodeInfo, aResult);
    }
    default:
      NS_ERROR("unknown xtf element type");
      break;
  }
  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:


Friends And Related Function Documentation

nsresult NS_NewXTFService ( nsIXTFService **  aResult) [friend]

Definition at line 90 of file nsXTFService.cpp.

{
  NS_PRECONDITION(aResult != nsnull, "null ptr");
  if (! aResult)
    return NS_ERROR_NULL_POINTER;

  nsXTFService* result = new nsXTFService();
  if (! result)
    return NS_ERROR_OUT_OF_MEMORY;

  NS_ADDREF(result);
  *aResult = result;
  return NS_OK;
}

Member Data Documentation

Definition at line 78 of file nsXTFService.cpp.


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