Esempio n. 1
0
void nsDomAttUtil::GetComLayoutInfo(nsIDOMElement* node,std::map<std::string,std::string> &lmap)
{
     nsCOMPtr<nsIDOMDocument> oDoc(nsnull);
     if(node!=nsnull)
	  node->GetOwnerDocument(getter_AddRefs(oDoc));
     if(oDoc!=nsnull)
     {
	  nsCOMPtr<nsIDOMViewCSS> viewCSS(nsnull);
	  nsCOMPtr<nsIDOMDocumentView> domView = do_QueryInterface(oDoc);
	  if(domView!=nsnull)
	  {
	       nsCOMPtr<nsIDOMAbstractView> abstractView;
	       domView->GetDefaultView(getter_AddRefs(abstractView));
	       if(abstractView!=nsnull)
	       {
		    viewCSS=do_QueryInterface(abstractView);
	       }
	  }
	  if(viewCSS!=nsnull)
	  {
	       nsCOMPtr<nsIDOMCSSStyleDeclaration> style;
	       viewCSS->GetComputedStyle(node, EmptyString(),getter_AddRefs(style));
	       if(style!=nsnull)
	       {
		    PRUint32 slen;
		    style->GetLength(&slen);
		    nsString csstext;
		    style->GetCssText(csstext);
		    for(int j=0;j<slen;j++)
		    {
			 nsString name;
			 nsString value;
			 nsString prio;
			 style->Item(j,name);
			 style->GetPropertyValue(name,value);

			 std::string strName(NS_ConvertUTF16toUTF8(name).get());

			 std::map<std::string,std::string>::iterator fit=lmap.find(strName);
			 if(fit==lmap.end())
			 {
			      lmap.insert(make_pair(strName,std::string(NS_ConvertUTF16toUTF8(value).get())));
			 }
		    }
	       }
	  }
     }
}
already_AddRefed<nsIDOMCSSStyleDeclaration>
nsCoreUtils::GetComputedStyleDeclaration(const nsAString& aPseudoElt,
                                         nsIContent *aContent)
{
  nsIContent* content = GetDOMElementFor(aContent);
  if (!content)
    return nsnull;

  // Returns number of items in style declaration
  nsIDocument* document = content->GetOwnerDoc();
  if (!document)
    return nsnull;

  nsCOMPtr<nsIDOMViewCSS> viewCSS(do_QueryInterface(document->GetWindow()));
  if (!viewCSS)
    return nsnull;

  nsIDOMCSSStyleDeclaration* cssDecl = nsnull;
  nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(content));
  viewCSS->GetComputedStyle(domElement, aPseudoElt, &cssDecl);
  return cssDecl;
}