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

version 1.2, 2002/03/08 00:27:48 version 1.9, 2002/04/14 08:43:03
Line 43 Line 43
 #include "nsIDOMElement.h"  #include "nsIDOMElement.h"
 #include "nsString.h"  #include "nsString.h"
 #include "nsUnicharUtils.h"  #include "nsUnicharUtils.h"
   #include "nsIPrefBranch.h"
   #include "nsIDOMMouseEvent.h"
   #include "nsEmbedAPI.h"
   
   // Common helper routines (also used by the context menu code)
   #include "GeckoUtils.h"
   
 NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener);  NS_IMPL_ISUPPORTS2(ContentClickListener, nsIDOMMouseListener, nsIDOMEventListener);
   
Line 64  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); 
   
  ToLowerCase(localName); 
   
   nsCOMPtr<nsIDOMElement> linkContent;    nsCOMPtr<nsIDOMElement> linkContent;
     nsAutoString href;
     GeckoUtils::GetEnclosingLinkElementAndHref(content, getter_AddRefs(linkContent), href);
       
     // XXXdwh Handle simple XLINKs if we want to be compatible with Mozilla, but who
     // really uses these anyway? :)
     if (!linkContent || href.IsEmpty())
       return NS_OK;
   
     nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
     if (!pref)
       return NS_OK; // Something bad happened if we can't get prefs.
       
     PRUint16 button;
     nsCOMPtr<nsIDOMMouseEvent> mouseEvent(do_QueryInterface(aEvent));
     mouseEvent->GetButton(&button);
   
     PRBool metaKey, shiftKey, altKey;
     mouseEvent->GetMetaKey(&metaKey);
     mouseEvent->GetShiftKey(&shiftKey);
     mouseEvent->GetAltKey(&altKey);
   
     NSString* hrefStr = [NSString stringWithCharacters: href.get() length:nsCRT::strlen(href.get())];
     NSURL* linkURL = [NSURL URLWithString: hrefStr];
   
     if ((metaKey && button == 0) || button == 1) {
       // The command key is down or we got a middle click.  Open the link in a new window or tab.
       PRBool useTab;
       pref->GetBoolPref("browser.tabs.opentabfor.middleclick", &useTab);
       PRBool loadInBackground;
       pref->GetBoolPref("browser.tabs.loadInBackground", &loadInBackground);
       if (shiftKey)
         loadInBackground = !loadInBackground;
       if (useTab)
         [mBrowserController openNewTabWithURL: linkURL loadInBackground: loadInBackground];
       else
         [mBrowserController openNewWindowWithURL: linkURL loadInBackground: loadInBackground];
     }
     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.2  
changed lines
  Added in v.1.9


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