LCOV - code coverage report
Current view: directory - layout/xul/base/src/tree/src - nsTreeUtils.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 72 0 0.0 %
Date: 2012-06-02 Functions: 5 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                 :  *   Chris Waterson <waterson@netscape.com>
      24                 :  *   Jan Varga <varga@ku.sk>
      25                 :  *   Nate Nielsen <nielsen@memberwebs.com>
      26                 :  *
      27                 :  * Alternatively, the contents of this file may be used under the terms of
      28                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      29                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      30                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      31                 :  * of those above. If you wish to allow use of your version of this file only
      32                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      33                 :  * use your version of this file under the terms of the MPL, indicate your
      34                 :  * decision by deleting the provisions above and replace them with the notice
      35                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      36                 :  * the provisions above, a recipient may use your version of this file under
      37                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      38                 :  *
      39                 :  * ***** END LICENSE BLOCK ***** */
      40                 : 
      41                 : #include "nsReadableUtils.h"
      42                 : #include "nsTreeUtils.h"
      43                 : #include "nsChildIterator.h"
      44                 : #include "nsCRT.h"
      45                 : #include "nsIAtom.h"
      46                 : #include "nsINameSpaceManager.h"
      47                 : #include "nsGkAtoms.h"
      48                 : #include "nsINodeInfo.h"
      49                 : 
      50                 : nsresult
      51               0 : nsTreeUtils::TokenizeProperties(const nsAString& aProperties, nsISupportsArray* aPropertiesArray)
      52                 : {
      53               0 :   NS_PRECONDITION(aPropertiesArray != nsnull, "null ptr");
      54               0 :   if (! aPropertiesArray)
      55               0 :      return NS_ERROR_NULL_POINTER;
      56                 : 
      57               0 :   nsAString::const_iterator end;
      58               0 :   aProperties.EndReading(end);
      59                 : 
      60               0 :   nsAString::const_iterator iter;
      61               0 :   aProperties.BeginReading(iter);
      62                 : 
      63               0 :   do {
      64                 :     // Skip whitespace
      65               0 :     while (iter != end && nsCRT::IsAsciiSpace(*iter))
      66               0 :       ++iter;
      67                 : 
      68                 :     // If only whitespace, we're done
      69               0 :     if (iter == end)
      70               0 :       break;
      71                 : 
      72                 :     // Note the first non-whitespace character
      73               0 :     nsAString::const_iterator first = iter;
      74                 : 
      75                 :     // Advance to the next whitespace character
      76               0 :     while (iter != end && ! nsCRT::IsAsciiSpace(*iter))
      77               0 :       ++iter;
      78                 : 
      79                 :     // XXX this would be nonsensical
      80               0 :     NS_ASSERTION(iter != first, "eh? something's wrong here");
      81               0 :     if (iter == first)
      82               0 :       break;
      83                 : 
      84               0 :     nsCOMPtr<nsIAtom> atom = do_GetAtom(Substring(first, iter));
      85               0 :     aPropertiesArray->AppendElement(atom);
      86                 :   } while (iter != end);
      87                 : 
      88               0 :   return NS_OK;
      89                 : }
      90                 : 
      91                 : nsIContent*
      92               0 : nsTreeUtils::GetImmediateChild(nsIContent* aContainer, nsIAtom* aTag)
      93                 : {
      94               0 :   ChildIterator iter, last;
      95               0 :   for (ChildIterator::Init(aContainer, &iter, &last); iter != last; ++iter) {
      96               0 :     nsIContent* child = *iter;
      97                 : 
      98               0 :     if (child->Tag() == aTag) {
      99               0 :       return child;
     100                 :     }
     101                 :   }
     102                 : 
     103               0 :   return nsnull;
     104                 : }
     105                 : 
     106                 : nsIContent*
     107               0 : nsTreeUtils::GetDescendantChild(nsIContent* aContainer, nsIAtom* aTag)
     108                 : {
     109               0 :   ChildIterator iter, last;
     110               0 :   for (ChildIterator::Init(aContainer, &iter, &last); iter != last; ++iter) {
     111               0 :     nsIContent* child = *iter;
     112               0 :     if (child->Tag() == aTag) {
     113               0 :       return child;
     114                 :     }
     115                 : 
     116               0 :     child = GetDescendantChild(child, aTag);
     117               0 :     if (child) {
     118               0 :       return child;
     119                 :     }
     120                 :   }
     121                 : 
     122               0 :   return nsnull;
     123                 : }
     124                 : 
     125                 : nsresult
     126               0 : nsTreeUtils::UpdateSortIndicators(nsIContent* aColumn, const nsAString& aDirection)
     127                 : {
     128               0 :   aColumn->SetAttr(kNameSpaceID_None, nsGkAtoms::sortDirection, aDirection, true);
     129               0 :   aColumn->SetAttr(kNameSpaceID_None, nsGkAtoms::sortActive, NS_LITERAL_STRING("true"), true);
     130                 : 
     131                 :   // Unset sort attribute(s) on the other columns
     132               0 :   nsCOMPtr<nsIContent> parentContent = aColumn->GetParent();
     133               0 :   if (parentContent &&
     134                 :       parentContent->NodeInfo()->Equals(nsGkAtoms::treecols,
     135               0 :                                         kNameSpaceID_XUL)) {
     136               0 :     PRUint32 i, numChildren = parentContent->GetChildCount();
     137               0 :     for (i = 0; i < numChildren; ++i) {
     138               0 :       nsCOMPtr<nsIContent> childContent = parentContent->GetChildAt(i);
     139                 : 
     140               0 :       if (childContent &&
     141               0 :           childContent != aColumn &&
     142                 :           childContent->NodeInfo()->Equals(nsGkAtoms::treecol,
     143               0 :                                            kNameSpaceID_XUL)) {
     144               0 :         childContent->UnsetAttr(kNameSpaceID_None,
     145               0 :                                 nsGkAtoms::sortDirection, true);
     146               0 :         childContent->UnsetAttr(kNameSpaceID_None,
     147               0 :                                 nsGkAtoms::sortActive, true);
     148                 :       }
     149                 :     }
     150                 :   }
     151                 : 
     152               0 :   return NS_OK;
     153                 : }
     154                 : 
     155                 : nsresult
     156               0 : nsTreeUtils::GetColumnIndex(nsIContent* aColumn, PRInt32* aResult)
     157                 : {
     158               0 :   nsIContent* parentContent = aColumn->GetParent();
     159               0 :   if (parentContent &&
     160                 :       parentContent->NodeInfo()->Equals(nsGkAtoms::treecols,
     161               0 :                                         kNameSpaceID_XUL)) {
     162               0 :     PRUint32 i, numChildren = parentContent->GetChildCount();
     163               0 :     PRInt32 colIndex = 0;
     164               0 :     for (i = 0; i < numChildren; ++i) {
     165               0 :       nsIContent *childContent = parentContent->GetChildAt(i);
     166               0 :       if (childContent &&
     167                 :           childContent->NodeInfo()->Equals(nsGkAtoms::treecol,
     168               0 :                                            kNameSpaceID_XUL)) {
     169               0 :         if (childContent == aColumn) {
     170               0 :           *aResult = colIndex;
     171               0 :           return NS_OK;
     172                 :         }
     173               0 :         ++colIndex;
     174                 :       }
     175                 :     }
     176                 :   }
     177                 : 
     178               0 :   *aResult = -1;
     179               0 :   return NS_OK;
     180                 : }

Generated by: LCOV version 1.7