Diff for /chimera/ContentClickListener.mm between versions 1.6 and 1.9

version 1.6, 2002/03/09 03:34:51 version 1.9, 2002/04/14 08:43:03
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 150  ContentClickListener::MouseClick(nsIDOME Line 88  ContentClickListener::MouseClick(nsIDOME
   PRUint16 button;    PRUint16 button;
   nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));    nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
   mouseEvent->GetButton(&button);    mouseEvent->GetButton(&button);
  switch (button) {
    case 0: {  PRBool metaKey, shiftKey, altKey;
      PRBool metaKey, shiftKey, altKey;  mouseEvent->GetMetaKey(&metaKey);
      mouseEvent->GetMetaKey(&metaKey);  mouseEvent->GetShiftKey(&shiftKey);
      mouseEvent->GetShiftKey(&shiftKey);  mouseEvent->GetAltKey(&altKey);
      mouseEvent->GetAltKey(&altKey);
      if (metaKey) {  NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
        // The command key is down.  Open the link in a new window or tab.  NSURL* linkURL = [NSURL URLWithString: hrefStr];
        PRBool useTab;
        pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab);  if ((metaKey && button == 0) || button == 1) {
        PRBool loadInBackground;    // The command key is down or we got a middle click.  Open the link in a new window or tab.
        pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);    PRBool useTab;
        if (shiftKey)    pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab);
          loadInBackground = !loadInBackground;    PRBool loadInBackground;
        if (useTab)    pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
          [mBrowserController openNewTabWithURL: urlToLoad loadInBackground: loadInBackground];    if (shiftKey)
        else      loadInBackground = !loadInBackground;
          [mBrowserController openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];    if (useTab)
      }      [mBrowserController openNewTabWithURL: linkURL loadInBackground: loadInBackground];
      else if (altKey) {    else
        // The user wants to save this link.      [mBrowserController openNewWindowWithURL: linkURL loadInBackground: loadInBackground];
        nsAutoString text; 
        GeckoUtils::GatherTextUnder(content, text); 
         
      } 
    } 
   }    }
      else if (altKey) {
     // The user wants to save this link.
     nsAutoString text;
     GeckoUtils::GatherTextUnder(content, text);
 
     [mBrowserController saveURL: nil filterList: nil
               url: linkURL suggestedFilename: [NSString stringWithCharacters: text.get()
                                                                       length: nsCRT::strlen(text.get())]];
   }
 
   return NS_OK;    return NS_OK;
 }  }

Removed from v.1.6  
changed lines
  Added in v.1.9


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