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

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla Communicator client code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Ryan Jones <sciguyryan@gmail.com>
      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 "nsIDOMHTMLTitleElement.h"
      39                 : #include "nsIDOMEventTarget.h"
      40                 : #include "nsGenericHTMLElement.h"
      41                 : #include "nsStyleConsts.h"
      42                 : #include "nsIDocument.h"
      43                 : #include "nsIDOMHTMLDocument.h"
      44                 : #include "nsContentUtils.h"
      45                 : 
      46                 : class nsHTMLTitleElement : public nsGenericHTMLElement,
      47                 :                            public nsIDOMHTMLTitleElement,
      48                 :                            public nsStubMutationObserver
      49                 : {
      50                 : public:
      51                 :   using nsGenericElement::GetText;
      52                 :   using nsGenericElement::SetText;
      53                 : 
      54                 :   nsHTMLTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo);
      55                 :   virtual ~nsHTMLTitleElement();
      56                 : 
      57                 :   // nsISupports
      58                 :   NS_DECL_ISUPPORTS_INHERITED
      59                 : 
      60                 :   // nsIDOMNode
      61               0 :   NS_FORWARD_NSIDOMNODE(nsGenericHTMLElement::)
      62                 : 
      63                 :   // nsIDOMElement
      64               0 :   NS_FORWARD_NSIDOMELEMENT(nsGenericHTMLElement::)
      65                 : 
      66                 :   // nsIDOMHTMLElement
      67               0 :   NS_FORWARD_NSIDOMHTMLELEMENT(nsGenericHTMLElement::)
      68                 : 
      69                 :   // nsIDOMHTMLTitleElement
      70                 :   NS_DECL_NSIDOMHTMLTITLEELEMENT
      71                 : 
      72                 :   // nsIMutationObserver
      73                 :   NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
      74                 :   NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
      75                 :   NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
      76                 :   NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
      77                 : 
      78                 :   virtual nsresult Clone(nsINodeInfo *aNodeInfo, nsINode **aResult) const;
      79                 : 
      80                 :   virtual nsresult BindToTree(nsIDocument *aDocument, nsIContent *aParent,
      81                 :                               nsIContent *aBindingParent,
      82                 :                               bool aCompileEventHandlers);
      83                 : 
      84                 :   virtual void UnbindFromTree(bool aDeep = true,
      85                 :                               bool aNullParent = true);
      86                 : 
      87                 :   virtual void DoneAddingChildren(bool aHaveNotified);
      88                 : 
      89                 :   virtual nsXPCClassInfo* GetClassInfo();
      90                 : private:
      91                 :   void SendTitleChangeEvent(bool aBound);
      92                 : };
      93                 : 
      94                 : 
      95               0 : NS_IMPL_NS_NEW_HTML_ELEMENT(Title)
      96                 : 
      97                 : 
      98               0 : nsHTMLTitleElement::nsHTMLTitleElement(already_AddRefed<nsINodeInfo> aNodeInfo)
      99               0 :   : nsGenericHTMLElement(aNodeInfo)
     100                 : {
     101               0 :   AddMutationObserver(this);
     102               0 : }
     103                 : 
     104               0 : nsHTMLTitleElement::~nsHTMLTitleElement()
     105                 : {
     106               0 : }
     107                 : 
     108                 : 
     109               0 : NS_IMPL_ADDREF_INHERITED(nsHTMLTitleElement, nsGenericElement) 
     110               0 : NS_IMPL_RELEASE_INHERITED(nsHTMLTitleElement, nsGenericElement) 
     111                 : 
     112                 : 
     113               0 : DOMCI_NODE_DATA(HTMLTitleElement, nsHTMLTitleElement)
     114                 : 
     115                 : // QueryInterface implementation for nsHTMLTitleElement
     116               0 : NS_INTERFACE_TABLE_HEAD(nsHTMLTitleElement)
     117               0 :   NS_HTML_CONTENT_INTERFACE_TABLE2(nsHTMLTitleElement,
     118                 :                                    nsIDOMHTMLTitleElement,
     119                 :                                    nsIMutationObserver)
     120               0 :   NS_HTML_CONTENT_INTERFACE_TABLE_TO_MAP_SEGUE(nsHTMLTitleElement,
     121                 :                                                nsGenericHTMLElement)
     122               0 : NS_HTML_CONTENT_INTERFACE_TABLE_TAIL_CLASSINFO(HTMLTitleElement)
     123                 : 
     124                 : 
     125               0 : NS_IMPL_ELEMENT_CLONE(nsHTMLTitleElement)
     126                 : 
     127                 : 
     128                 : NS_IMETHODIMP 
     129               0 : nsHTMLTitleElement::GetText(nsAString& aTitle)
     130                 : {
     131               0 :   nsContentUtils::GetNodeTextContent(this, false, aTitle);
     132               0 :   return NS_OK;
     133                 : }
     134                 : 
     135                 : NS_IMETHODIMP 
     136               0 : nsHTMLTitleElement::SetText(const nsAString& aTitle)
     137                 : {
     138               0 :   return nsContentUtils::SetNodeTextContent(this, aTitle, true);
     139                 : }
     140                 : 
     141                 : void
     142               0 : nsHTMLTitleElement::CharacterDataChanged(nsIDocument *aDocument,
     143                 :                                          nsIContent *aContent,
     144                 :                                          CharacterDataChangeInfo *aInfo)
     145                 : {
     146               0 :   SendTitleChangeEvent(false);
     147               0 : }
     148                 : 
     149                 : void
     150               0 : nsHTMLTitleElement::ContentAppended(nsIDocument *aDocument,
     151                 :                                     nsIContent *aContainer,
     152                 :                                     nsIContent *aFirstNewContent,
     153                 :                                     PRInt32 aNewIndexInContainer)
     154                 : {
     155               0 :   SendTitleChangeEvent(false);
     156               0 : }
     157                 : 
     158                 : void
     159               0 : nsHTMLTitleElement::ContentInserted(nsIDocument *aDocument,
     160                 :                                     nsIContent *aContainer,
     161                 :                                     nsIContent *aChild,
     162                 :                                     PRInt32 aIndexInContainer)
     163                 : {
     164               0 :   SendTitleChangeEvent(false);
     165               0 : }
     166                 : 
     167                 : void
     168               0 : nsHTMLTitleElement::ContentRemoved(nsIDocument *aDocument,
     169                 :                                    nsIContent *aContainer,
     170                 :                                    nsIContent *aChild,
     171                 :                                    PRInt32 aIndexInContainer,
     172                 :                                    nsIContent *aPreviousSibling)
     173                 : {
     174               0 :   SendTitleChangeEvent(false);
     175               0 : }
     176                 : 
     177                 : nsresult
     178               0 : nsHTMLTitleElement::BindToTree(nsIDocument *aDocument,
     179                 :                                nsIContent *aParent,
     180                 :                                nsIContent *aBindingParent,
     181                 :                                bool aCompileEventHandlers)
     182                 : {
     183                 :   // Let this fall through.
     184                 :   nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
     185                 :                                                  aBindingParent,
     186               0 :                                                  aCompileEventHandlers);
     187               0 :   NS_ENSURE_SUCCESS(rv, rv);
     188                 : 
     189               0 :   SendTitleChangeEvent(true);
     190                 : 
     191               0 :   return NS_OK;
     192                 : }
     193                 : 
     194                 : void
     195               0 : nsHTMLTitleElement::UnbindFromTree(bool aDeep, bool aNullParent)
     196                 : {
     197               0 :   SendTitleChangeEvent(false);
     198                 : 
     199                 :   // Let this fall through.
     200               0 :   nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
     201               0 : }
     202                 : 
     203                 : void
     204               0 : nsHTMLTitleElement::DoneAddingChildren(bool aHaveNotified)
     205                 : {
     206               0 :   if (!aHaveNotified) {
     207               0 :     SendTitleChangeEvent(false);
     208                 :   }
     209               0 : }
     210                 : 
     211                 : void
     212               0 : nsHTMLTitleElement::SendTitleChangeEvent(bool aBound)
     213                 : {
     214               0 :   nsIDocument* doc = GetCurrentDoc();
     215               0 :   if (doc) {
     216               0 :     doc->NotifyPossibleTitleChange(aBound);
     217                 :   }
     218               0 : }

Generated by: LCOV version 1.7