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

version 1.1, 2002/03/07 18:35:48 version 1.9, 2002/04/14 08:43:03
Line 37 Line 37
   
 #include "nsCOMPtr.h"  #include "nsCOMPtr.h"
 #include "ContentClickListener.h"  #include "ContentClickListener.h"
   #include "nsIDOMEventTarget.h"
   #include "nsIContent.h"
   #include "nsIAtom.h"
   #include "nsIDOMElement.h"
   #include "nsString.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 54  ContentClickListener::~ContentClickListe Line 66  ContentClickListener::~ContentClickListe
 NS_IMETHODIMP  NS_IMETHODIMP
 ContentClickListener::MouseClick(nsIDOMEvent* aEvent)  ContentClickListener::MouseClick(nsIDOMEvent* aEvent)
 {  {
  printf("You clicked in the content area! Good for you!\n");  nsCOMPtr<nsIDOMEventTarget> target;
   aEvent->GetTarget(getter_AddRefs(target));
   if (!target)
     return NS_OK;
   nsCOMPtr<nsIDOMNode> content(do_QueryInterface(target));
 
   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.1  
changed lines
  Added in v.1.9


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