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

version 1.1, 2002/03/07 18:35:48 version 1.3, 2002/03/08 01:43:01
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"
   #include "nsIDOMHTMLAnchorElement.h"
   #include "nsIDOMHTMLAreaElement.h"
   #include "nsIDOMHTMLLinkElement.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<nsIDOMElement> content(do_QueryInterface(target));
   nsAutoString localName;
   if (content)
     content->GetLocalName(localName);
   
   nsCOMPtr<nsIDOMElement> 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<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
   // really uses these anyway? :)
   if (!linkContent || href.IsEmpty())
     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"));
   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);
   switch (button) {
     case 0: {
       PRBool metaKey, shiftKey;
       mouseEvent->GetMetaKey(&metaKey);
       mouseEvent->GetShiftKey(&shiftKey);
       if (metaKey) {
         // The command key is down.  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) {
           
         }
         else
           [mBrowserController openNewWindowWithURL: urlToLoad loadInBackground: loadInBackground];
       }
     }
   }
     
   return NS_OK;    return NS_OK;
 }  }

Removed from v.1.1  
changed lines
  Added in v.1.3


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