nsresult nsXTFService::CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) { 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: %s \n", xtf_contract_id.get()); #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 a wrapper for it: return NS_NewXTFElementWrapper(elem, aNodeInfo, aResult); }
nsresult nsXTFService::CreateElement(nsIContent** aResult, nsINodeInfo* aNodeInfo) { 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; }