LCOV - code coverage report
Current view: directory - content/html/content/src - nsHTMLAreaElement.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 98 0 0.0 %
Date: 2012-06-02 Functions: 150 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* vim:set tw=80 expandtab softtabstop=2 ts=2 sw=2: */
       3                 : /* ***** BEGIN LICENSE BLOCK *****
       4                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       5                 :  *
       6                 :  * The contents of this file are subject to the Mozilla Public License Version
       7                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       8                 :  * the License. You may obtain a copy of the License at
       9                 :  * http://www.mozilla.org/MPL/
      10                 :  *
      11                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      12                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      13                 :  * for the specific language governing rights and limitations under the
      14                 :  * License.
      15                 :  *
      16                 :  * The Original Code is Mozilla Communicator client code.
      17                 :  *
      18                 :  * The Initial Developer of the Original Code is
      19                 :  * Netscape Communications Corporation.
      20                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      21                 :  * the Initial Developer. All Rights Reserved.
      22                 :  *
      23                 :  * Contributor(s):
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : #include "nsIDOMHTMLAreaElement.h"
      39                 : #include "nsIDOMEventTarget.h"
      40                 : #include "nsGenericHTMLElement.h"
      41                 : #include "nsILink.h"
      42                 : #include "nsGkAtoms.h"
      43                 : #include "nsStyleConsts.h"
      44                 : #include "nsIURL.h"
      45                 : #include "nsNetUtil.h"
      46                 : #include "nsReadableUtils.h"
      47                 : #include "nsIDocument.h"
      48                 : 
      49                 : #include "Link.h"
      50                 : using namespace mozilla::dom;
      51                 : 
      52                 : class nsHTMLAreaElement : public nsGenericHTMLElement,
      53                 :                           public nsIDOMHTMLAreaElement,
      54                 :                           public nsILink,
      55                 :                           public Link
      56                 : {
      57                 : public:
      58                 :   nsHTMLAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      59                 :   virtual ~nsHTMLAreaElement();
      60                 : 
      61                 :   // nsISupports
      62                 :   NS_DECL_ISUPPORTS_INHERITED
      63                 : 
      64                 :   // DOM memory reporter participant
      65                 :   NS_DECL_SIZEOF_EXCLUDING_THIS
      66                 : 
      67                 :   // nsIDOMNode
      68               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
      69                 : 
      70                 :   // nsIDOMElement
      71               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
      72                 : 
      73                 :   // nsIDOMHTMLElement
      74               0 :   NS_FORWARD_NSIDOMHTMLELEMENT_BASIC(nsGenericHTMLElement::)
      75               0 :   NS_SCRIPTABLE NS_IMETHOD Click() {
      76               0 :     return nsGenericHTMLElement::Click();
      77                 :   }
      78                 :   NS_SCRIPTABLE NS_IMETHOD GetTabIndex(PRInt32* aTabIndex);
      79                 :   NS_SCRIPTABLE NS_IMETHOD SetTabIndex(PRInt32 aTabIndex);
      80               0 :   NS_SCRIPTABLE NS_IMETHOD Focus() {
      81               0 :     return nsGenericHTMLElement::Focus();
      82                 :   }
      83               0 :   NS_SCRIPTABLE NS_IMETHOD GetDraggable(bool* aDraggable) {
      84               0 :     return nsGenericHTMLElement::GetDraggable(aDraggable);
      85                 :   }
      86               0 :   NS_SCRIPTABLE NS_IMETHOD GetInnerHTML(nsAString& aInnerHTML) {
      87               0 :     return nsGenericHTMLElement::GetInnerHTML(aInnerHTML);
      88                 :   }
      89               0 :   NS_SCRIPTABLE NS_IMETHOD SetInnerHTML(const nsAString& aInnerHTML) {
      90               0 :     return nsGenericHTMLElement::SetInnerHTML(aInnerHTML);
      91                 :   }
      92                 : 
      93                 :   // nsIDOMHTMLAreaElement
      94                 :   NS_DECL_NSIDOMHTMLAREAELEMENT
      95                 : 
      96                 :   // nsILink
      97               0 :   NS_IMETHOD LinkAdded() { return NS_OK; }
      98               0 :   NS_IMETHOD LinkRemoved() { return NS_OK; }
      99                 : 
     100                 :   virtual nsresult PreHandleEvent(nsEventChainPreVisitor& aVisitor);
     101                 :   virtual nsresult PostHandleEvent(nsEventChainPostVisitor& aVisitor);
     102                 :   virtual bool IsLink(nsIURI** aURI) const;
     103                 :   virtual void GetLinkTarget(nsAString& aTarget);
     104                 :   virtual nsLinkState GetLinkState() const;
     105                 :   virtual already_AddRefed<nsIURI> GetHrefURI() const;
     106                 : 
     107                 :   virtual nsresult BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     108                 :                               nsIContent* aBindingParent,
     109                 :                               bool aCompileEventHandlers);
     110                 :   virtual void UnbindFromTree(bool aDeep = true,
     111                 :                               bool aNullParent = true);
     112               0 :   nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     113                 :                    const nsAString& aValue, bool aNotify)
     114                 :   {
     115               0 :     return SetAttr(aNameSpaceID, aName, nsnull, aValue, aNotify);
     116                 :   }
     117                 :   virtual nsresult SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     118                 :                            nsIAtom* aPrefix, const nsAString& aValue,
     119                 :                            bool aNotify);
     120                 :   virtual nsresult UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
     121                 :                              bool aNotify);
     122                 : 
     123                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
     124                 : 
     125                 :   virtual nsEventStates IntrinsicState() const;
     126                 : 
     127                 :   virtual nsXPCClassInfo* GetClassInfo();
     128                 : };
     129                 : 
     130                 : 
     131               0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Area)
     132                 : 
     133                 : 
     134               0 : nsHTMLAreaElement::nsHTMLAreaElement(already_AddRefed<nsINodeInfo> aNodeInfo)
     135                 :   : nsGenericHTMLElement(aNodeInfo),
     136               0 :     Link(this)
     137                 : {
     138               0 : }
     139                 : 
     140               0 : nsHTMLAreaElement::~nsHTMLAreaElement()
     141                 : {
     142               0 : }
     143                 : 
     144               0 : NS_IMPL_ADDREF_INHERITED(nsHTMLAreaElement, nsGenericElement) 
     145               0 : NS_IMPL_RELEASE_INHERITED(nsHTMLAreaElement, nsGenericElement) 
     146                 : 
     147               0 : DOMCI_NODE_DATA(HTMLAreaElement, nsHTMLAreaElement)
     148                 : 
     149                 : // QueryInterface implementation for nsHTMLAreaElement
     150               0 : NS_INTERFACE_TABLE_HEAD(nsHTMLAreaElement)
     151               0 :   NS_HTML_CONTENT_INTERFACE_TABLE3(nsHTMLAreaElement,
     152                 :                                    nsIDOMHTMLAreaElement,
     153                 :                                    nsILink,
     154                 :                                    Link)
     155               0 :   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLAreaElement,
     156                 :                                                nsGenericHTMLElement)
     157               0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLAreaElement)
     158                 : 
     159                 : 
     160               0 : NS_IMPL_ELEMENT_CLONE(nsHTMLAreaElement)
     161                 : 
     162                 : 
     163               0 : NS_IMPL_STRING_ATTR(nsHTMLAreaElement, Alt, alt)
     164               0 : NS_IMPL_STRING_ATTR(nsHTMLAreaElement, Coords, coords)
     165               0 : NS_IMPL_URI_ATTR(nsHTMLAreaElement, Href, href)
     166               0 : NS_IMPL_BOOL_ATTR(nsHTMLAreaElement, NoHref, nohref)
     167               0 : NS_IMPL_STRING_ATTR(nsHTMLAreaElement, Shape, shape)
     168               0 : NS_IMPL_INT_ATTR(nsHTMLAreaElement, TabIndex, tabindex)
     169                 : 
     170                 : NS_IMETHODIMP
     171               0 : nsHTMLAreaElement::GetTarget(nsAString& aValue)
     172                 : {
     173               0 :   if (!GetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue)) {
     174               0 :     GetBaseTarget(aValue);
     175                 :   }
     176               0 :   return NS_OK;
     177                 : }
     178                 : 
     179                 : NS_IMETHODIMP
     180               0 : nsHTMLAreaElement::SetTarget(const nsAString& aValue)
     181                 : {
     182               0 :   return SetAttr(kNameSpaceID_None, nsGkAtoms::target, aValue, true);
     183                 : }
     184                 : 
     185                 : nsresult
     186               0 : nsHTMLAreaElement::PreHandleEvent(nsEventChainPreVisitor& aVisitor)
     187                 : {
     188               0 :   return PreHandleEventForAnchors(aVisitor);
     189                 : }
     190                 : 
     191                 : nsresult
     192               0 : nsHTMLAreaElement::PostHandleEvent(nsEventChainPostVisitor& aVisitor)
     193                 : {
     194               0 :   return PostHandleEventForAnchors(aVisitor);
     195                 : }
     196                 : 
     197                 : bool
     198               0 : nsHTMLAreaElement::IsLink(nsIURI** aURI) const
     199                 : {
     200               0 :   return IsHTMLLink(aURI);
     201                 : }
     202                 : 
     203                 : void
     204               0 : nsHTMLAreaElement::GetLinkTarget(nsAString& aTarget)
     205                 : {
     206               0 :   GetAttr(kNameSpaceID_None, nsGkAtoms::target, aTarget);
     207               0 :   if (aTarget.IsEmpty()) {
     208               0 :     GetBaseTarget(aTarget);
     209                 :   }
     210               0 : }
     211                 : 
     212                 : nsresult
     213               0 : nsHTMLAreaElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
     214                 :                               nsIContent* aBindingParent,
     215                 :                               bool aCompileEventHandlers)
     216                 : {
     217               0 :   Link::ResetLinkState(false);
     218               0 :   if (aDocument) {
     219               0 :     aDocument->RegisterPendingLinkUpdate(this);
     220                 :   }
     221                 :   
     222                 :   return nsGenericHTMLElement::BindToTree(aDocument, aParent,
     223                 :                                                  aBindingParent,
     224               0 :                                                  aCompileEventHandlers);
     225                 : }
     226                 : 
     227                 : void
     228               0 : nsHTMLAreaElement::UnbindFromTree(bool aDeep, bool aNullParent)
     229                 : {
     230                 :   // If this link is ever reinserted into a document, it might
     231                 :   // be under a different xml:base, so forget the cached state now.
     232               0 :   Link::ResetLinkState(false);
     233                 :   
     234               0 :   nsIDocument* doc = GetCurrentDoc();
     235               0 :   if (doc) {
     236               0 :     doc->UnregisterPendingLinkUpdate(this);
     237                 :   }
     238                 : 
     239               0 :   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
     240               0 : }
     241                 : 
     242                 : nsresult
     243               0 : nsHTMLAreaElement::SetAttr(PRInt32 aNameSpaceID, nsIAtom* aName,
     244                 :                            nsIAtom* aPrefix, const nsAString& aValue,
     245                 :                            bool aNotify)
     246                 : {
     247                 :   nsresult rv =
     248               0 :     nsGenericHTMLElement::SetAttr(aNameSpaceID, aName, aPrefix, aValue, aNotify);
     249                 : 
     250                 :   // The ordering of the parent class's SetAttr call and Link::ResetLinkState
     251                 :   // is important here!  The attribute is not set until SetAttr returns, and
     252                 :   // we will need the updated attribute value because notifying the document
     253                 :   // that content states have changed will call IntrinsicState, which will try
     254                 :   // to get updated information about the visitedness from Link.
     255               0 :   if (aName == nsGkAtoms::href && aNameSpaceID == kNameSpaceID_None) {
     256               0 :     Link::ResetLinkState(!!aNotify);
     257                 :   }
     258                 : 
     259               0 :   return rv;
     260                 : }
     261                 : 
     262                 : nsresult
     263               0 : nsHTMLAreaElement::UnsetAttr(PRInt32 aNameSpaceID, nsIAtom* aAttribute,
     264                 :                              bool aNotify)
     265                 : {
     266                 :   nsresult rv = nsGenericHTMLElement::UnsetAttr(aNameSpaceID, aAttribute,
     267               0 :                                                 aNotify);
     268                 : 
     269                 :   // The ordering of the parent class's UnsetAttr call and Link::ResetLinkState
     270                 :   // is important here!  The attribute is not unset until UnsetAttr returns, and
     271                 :   // we will need the updated attribute value because notifying the document
     272                 :   // that content states have changed will call IntrinsicState, which will try
     273                 :   // to get updated information about the visitedness from Link.
     274               0 :   if (aAttribute == nsGkAtoms::href && kNameSpaceID_None == aNameSpaceID) {
     275               0 :     Link::ResetLinkState(!!aNotify);
     276                 :   }
     277                 : 
     278               0 :   return rv;
     279                 : }
     280                 : 
     281                 : #define IMPL_URI_PART(_part)                                 \
     282                 :   NS_IMETHODIMP                                              \
     283                 :   nsHTMLAreaElement::Get##_part(nsAString& a##_part)         \
     284                 :   {                                                          \
     285                 :     return Link::Get##_part(a##_part);                       \
     286                 :   }                                                          \
     287                 :   NS_IMETHODIMP                                              \
     288                 :   nsHTMLAreaElement::Set##_part(const nsAString& a##_part)   \
     289                 :   {                                                          \
     290                 :     return Link::Set##_part(a##_part);                       \
     291                 :   }
     292                 : 
     293               0 : IMPL_URI_PART(Protocol)
     294               0 : IMPL_URI_PART(Host)
     295               0 : IMPL_URI_PART(Hostname)
     296               0 : IMPL_URI_PART(Pathname)
     297               0 : IMPL_URI_PART(Search)
     298               0 : IMPL_URI_PART(Port)
     299               0 : IMPL_URI_PART(Hash)
     300                 : 
     301                 : #undef IMPL_URI_PART
     302                 : 
     303                 : NS_IMETHODIMP
     304               0 : nsHTMLAreaElement::ToString(nsAString& aSource)
     305                 : {
     306               0 :   return GetHref(aSource);
     307                 : }
     308                 : 
     309                 : NS_IMETHODIMP    
     310               0 : nsHTMLAreaElement::GetPing(nsAString& aValue)
     311                 : {
     312               0 :   return GetURIListAttr(nsGkAtoms::ping, aValue);
     313                 : }
     314                 : 
     315                 : NS_IMETHODIMP
     316               0 : nsHTMLAreaElement::SetPing(const nsAString& aValue)
     317                 : {
     318               0 :   return SetAttr(kNameSpaceID_None, nsGkAtoms::ping, aValue, true);
     319                 : }
     320                 : 
     321                 : nsLinkState
     322               0 : nsHTMLAreaElement::GetLinkState() const
     323                 : {
     324               0 :   return Link::GetLinkState();
     325                 : }
     326                 : 
     327                 : already_AddRefed<nsIURI>
     328               0 : nsHTMLAreaElement::GetHrefURI() const
     329                 : {
     330               0 :   return GetHrefURIForAnchors();
     331                 : }
     332                 : 
     333                 : nsEventStates
     334               0 : nsHTMLAreaElement::IntrinsicState() const
     335                 : {
     336               0 :   return Link::LinkState() | nsGenericHTMLElement::IntrinsicState();
     337                 : }
     338                 : 
     339                 : size_t
     340               0 : nsHTMLAreaElement::SizeOfExcludingThis(nsMallocSizeOfFun aMallocSizeOf) const
     341                 : {
     342               0 :   return nsGenericHTMLElement::SizeOfExcludingThis(aMallocSizeOf) +
     343               0 :          Link::SizeOfExcludingThis(aMallocSizeOf);
     344                 : }
     345                 : 

Generated by: LCOV version 1.7