Diff for /chimera/ContentClickListener.mm between versions 1.7 and 1.8

version 1.7, 2002/03/09 23:14:00 version 1.8, 2002/04/14 00:08:17
Line 46 Line 46
 #include "nsIPrefBranch.h"  #include "nsIPrefBranch.h"
 #include "nsIDOMMouseEvent.h"  #include "nsIDOMMouseEvent.h"
 #include "nsEmbedAPI.h"  #include "nsEmbedAPI.h"
 #include "nsIDOMHTMLAnchorElement.h"  
 #include "nsIDOMHTMLAreaElement.h"  
 #include "nsIDOMHTMLLinkElement.h"  
 #include "nsIDOMHTMLImageElement.h"  
 #include "nsIDOMCharacterData.h"  
   
 // Common helper routines (also used by the context menu code)  // Common helper routines (also used by the context menu code)
 #include "GeckoUtils.h"  #include "GeckoUtils.h"
Line 75  ContentClickListener::MouseClick(nsIDOME Line 70  ContentClickListener::MouseClick(nsIDOME
   aEvent->GetTarget(getter_AddRefs(target));    aEvent->GetTarget(getter_AddRefs(target));
   if (!target)    if (!target)
     return NS_OK;      return NS_OK;
  nsCOMPtr<nsIDOMElement> content(do_QueryInterface(target));  nsCOMPtr<nsIDOMNode> content(do_QueryInterface(target));
  nsAutoString localName;
  if (content) 
    content->GetLocalName(localName); 
   
   nsCOMPtr<nsIDOMElement> linkContent;    nsCOMPtr<nsIDOMElement> linkContent;
   ToLowerCase(localName);  
   nsAutoString href;    nsAutoString href;
  if (localName.Equals(NS_LITERAL_STRING("a")) ||  GeckoUtils::GetEnclosingLinkElementAndHref(content, getter_AddRefs(linkContent), href);
      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<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent)); 
      if (anchor) 
        anchor->GetHref(href); 
      else { 
        nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(linkContent)); 
        if (area) 
          area->GetHref(href); 
        else { 
          nsCOMPtr<nsIDOMHTMLLinkElement> link(do_QueryInterface(linkContent)); 
          if (link) 
            link->GetHref(href); 
        } 
      } 
    } 
  } 
  else { 
    // XXXdwh Handle prefilling of forms (input fields) on a click. 
    nsCOMPtr<nsIDOMNode> curr(do_QueryInterface(target)); 
    nsCOMPtr<nsIDOMNode> 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<nsIDOMHTMLAnchorElement> 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)); 
    } 
  } 
       
   // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who    // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
   // really uses these anyway? :)    // really uses these anyway? :)
   if (!linkContent || href.IsEmpty())    if (!linkContent || href.IsEmpty())
     return NS_OK;      return NS_OK;
   
   NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];  
   NSURL* urlToLoad = [NSURL URLWithString: hrefStr];  
     
   nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));    nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
   if (!pref)    if (!pref)
     return NS_OK; // Something bad happened if we can't get prefs.      return NS_OK; // Something bad happened if we can't get prefs.
Line 159  ContentClickListener::MouseClick(nsIDOME Line 97  ContentClickListener::MouseClick(nsIDOME
     // The command key is down or we got a middle click.  Open the link in a new window or tab.      // The command key is down or we got a middle click.  Open the link in a new window or tab.
     PRBool useTab;      PRBool useTab;
     pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab);      pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab);
   
       NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
       NSURL* urlToLoad = [NSURL URLWithString: hrefStr];
   
     PRBool loadInBackground;      PRBool loadInBackground;
     pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);      pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
     if (shiftKey)      if (shiftKey)

Removed from v.1.7  
changed lines
  Added in v.1.8


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>