From fcaa9be00369105192da9760ae63a5f7a87bf7f9 Mon Sep 17 00:00:00 2001 From: "hwaara%gmail.com" Date: Sat, 27 May 2006 09:29:55 +0000 Subject: [PATCH] bug 331194, part 1: implement new methods to Find a docshell for a given URI, and to find a URI for a given docshell. Move around code in GeckoUtils. r=smfr git-svn-id: svn://10.0.0.236/branches/MOZILLA_1_8_BRANCH@198503 18797224-902f-48f8-a5cc-f745e15eee43 --- .../src/browser/BrowserWindowController.mm | 3 +- mozilla/camino/src/extensions/GeckoUtils.h | 150 +++--------------- 2 files changed, 20 insertions(+), 133 deletions(-) diff --git a/mozilla/camino/src/browser/BrowserWindowController.mm b/mozilla/camino/src/browser/BrowserWindowController.mm index ab398b1d9ea..1d1c074e8cc 100644 --- a/mozilla/camino/src/browser/BrowserWindowController.mm +++ b/mozilla/camino/src/browser/BrowserWindowController.mm @@ -108,6 +108,7 @@ #include "nsIDOMHTMLEmbedElement.h" #include "nsIDOMHTMLObjectElement.h" #include "nsIDOMHTMLAppletElement.h" +#include "nsIDOMHTMLImageElement.h" #include "nsIFocusController.h" #include "nsIX509Cert.h" @@ -155,7 +156,7 @@ static NSArray* sToolbarDefaults = nil; #pragma mark - -// small class that owns C++ objects in behalf of BrowserWindowController. +// small class that owns C++ objects on behalf of BrowserWindowController. // this just allows us to use nsCOMPtr rather than doing manual refcounting. class BWCDataOwner { diff --git a/mozilla/camino/src/extensions/GeckoUtils.h b/mozilla/camino/src/extensions/GeckoUtils.h index cd7365fac1b..1d8f68648bc 100644 --- a/mozilla/camino/src/extensions/GeckoUtils.h +++ b/mozilla/camino/src/extensions/GeckoUtils.h @@ -38,142 +38,28 @@ #ifndef __GeckoUtils_h__ #define __GeckoUtils_h__ -#include "nsIDOMHTMLAnchorElement.h" -#include "nsIDOMHTMLAreaElement.h" -#include "nsIDOMHTMLLinkElement.h" -#include "nsIDOMHTMLImageElement.h" -#include "nsIDOMCharacterData.h" -#include "nsUnicharUtils.h" +#include "nsString.h" + +class nsIDOMNode; +class nsIDOMElement; +class nsIDocShell; +class nsIURI; class GeckoUtils { -public: - static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult) { - nsAutoString text; - nsCOMPtr node; - aNode->GetFirstChild(getter_AddRefs(node)); - PRUint32 depth = 1; - while (node && depth) { - nsCOMPtr charData(do_QueryInterface(node)); - PRUint16 nodeType; - node->GetNodeType(&nodeType); - if (charData && nodeType == nsIDOMNode::TEXT_NODE) { - // Add this text to our collection. - text += NS_LITERAL_STRING(" "); - nsAutoString data; - charData->GetData(data); - text += data; - } - else { - nsCOMPtr img(do_QueryInterface(node)); - if (img) { - nsAutoString altText; - img->GetAlt(altText); - if (!altText.IsEmpty()) { - text = altText; - break; - } - } - } + public: - // Find the next node to test. - PRBool hasChildNodes; - node->HasChildNodes(&hasChildNodes); - if (hasChildNodes) { - nsCOMPtr temp = node; - temp->GetFirstChild(getter_AddRefs(node)); - depth++; - } - else { - nsCOMPtr nextSibling; - node->GetNextSibling(getter_AddRefs(nextSibling)); - if (nextSibling) - node = nextSibling; - else { - nsCOMPtr parentNode; - node->GetParentNode(getter_AddRefs(parentNode)); - if (!parentNode) - node = nsnull; - else { - nsCOMPtr nextSibling2; - parentNode->GetNextSibling(getter_AddRefs(nextSibling2)); - node = nextSibling2; - depth--; - } - } - } - } - - text.CompressWhitespace(); - aResult = text; - }; - - static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref) - { - nsCOMPtr content(do_QueryInterface(aNode)); - nsAutoString localName; - if (content) - content->GetLocalName(localName); - - nsCOMPtr linkContent; - ToLowerCase(localName); - nsAutoString href; - if (localName.Equals(NS_LITERAL_STRING("a")) || - localName.Equals(NS_LITERAL_STRING("area")) || - localName.Equals(NS_LITERAL_STRING("link"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - else { - nsCOMPtr area(do_QueryInterface(linkContent)); - if (area) - area->GetHref(href); - else { - nsCOMPtr link(do_QueryInterface(linkContent)); - if (link) - link->GetHref(href); - } - } - } - } - else { - nsCOMPtr curr = aNode; - nsCOMPtr temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - while (curr) { - content = do_QueryInterface(curr); - if (!content) - break; - content->GetLocalName(localName); - ToLowerCase(localName); - if (localName.Equals(NS_LITERAL_STRING("a"))) { - PRBool hasAttr; - content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr); - if (hasAttr) { - linkContent = content; - nsCOMPtr anchor(do_QueryInterface(linkContent)); - if (anchor) - anchor->GetHref(href); - } - else - linkContent = nsnull; // Links can't be nested. - break; - } - - temp = curr; - temp->GetParentNode(getter_AddRefs(curr)); - } - } - - *aLinkContent = linkContent; - NS_IF_ADDREF(*aLinkContent); - - aHref = href; - } + static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult); + static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref); + + /* Ouputs the docshell |aDocShell|'s URI as a nsACString. */ + static void GetURIForDocShell(nsIDocShell* aDocShell, nsACString& aURI); + + /* Given a URI, and a docshell node, will traverse the tree looking for the docshell with the + given URI. This is used for example when unblocking popups, because the popup "windows" are docshells + found somewhere in a document's docshell tree. NOTE: Addrefs the found docshell! + */ + static void FindDocShellForURI(nsIURI *aURI, nsIDocShell *aRoot, nsIDocShell **outMatch); };