LCOV - code coverage report
Current view: directory - accessible/src/base - TextUpdater.h (source / functions) Found Hit Coverage
Test: app.info Lines: 12 0 0.0 %
Date: 2012-06-02 Functions: 4 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.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Mozilla Foundation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2011
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Alexander Surkov <surkov.alexander@gmail.com> (original author)
      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                 : 
      39                 : #ifndef TextUpdater_h_
      40                 : #define TextUpdater_h_
      41                 : 
      42                 : #include "AccEvent.h"
      43                 : #include "nsHyperTextAccessible.h"
      44                 : 
      45                 : /**
      46                 :  * Used to find a difference between old and new text and fire text change
      47                 :  * events.
      48                 :  */
      49                 : class TextUpdater
      50                 : {
      51                 : public:
      52                 :   /**
      53                 :    * Start text of the text leaf update.
      54                 :    */
      55                 :   static void Run(nsDocAccessible* aDocument, nsTextAccessible* aTextLeaf,
      56                 :                   const nsAString& aNewText);
      57                 : 
      58                 : private:
      59               0 :   TextUpdater(nsDocAccessible* aDocument, nsTextAccessible* aTextLeaf) :
      60                 :     mDocument(aDocument), mTextLeaf(aTextLeaf), mHyperText(nsnull),
      61               0 :     mTextOffset(-1) { }
      62                 : 
      63               0 :   ~TextUpdater()
      64               0 :     { mDocument = nsnull; mTextLeaf = nsnull; mHyperText = nsnull; }
      65                 : 
      66                 :   /**
      67                 :    * Update text of the text leaf accessible, fire text change and value change
      68                 :    * (if applicable) events for its container hypertext accessible.
      69                 :    */
      70                 :   void DoUpdate(const nsAString& aNewText, const nsAString& aOldText,
      71                 :                 PRUint32 aSkipStart);
      72                 : 
      73                 : private:
      74                 :   TextUpdater();
      75                 :   TextUpdater(const TextUpdater&);
      76                 :   TextUpdater& operator=(const TextUpdater&);
      77                 : 
      78                 :   /**
      79                 :    * Fire text change events based on difference between strings.
      80                 :    */
      81                 :   void ComputeTextChangeEvents(const nsAString& aStr1,
      82                 :                                const nsAString& aStr2,
      83                 :                                PRUint32* aEntries,
      84                 :                                nsTArray<nsRefPtr<AccEvent> >& aEvents);
      85                 : 
      86                 :   /**
      87                 :    * Helper to create text change events for inserted text.
      88                 :    */
      89               0 :   inline void FireInsertEvent(const nsAString& aText, PRUint32 aAddlOffset,
      90                 :                               nsTArray<nsRefPtr<AccEvent> >& aEvents)
      91                 :   {
      92                 :     nsRefPtr<AccEvent> event =
      93                 :       new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
      94               0 :                              aText, true);
      95               0 :     aEvents.AppendElement(event);
      96               0 :   }
      97                 : 
      98                 :   /**
      99                 :    * Helper to create text change events for removed text.
     100                 :    */
     101               0 :   inline void FireDeleteEvent(const nsAString& aText, PRUint32 aAddlOffset,
     102                 :                               nsTArray<nsRefPtr<AccEvent> >& aEvents)
     103                 :   {
     104                 :     nsRefPtr<AccEvent> event =
     105                 :       new AccTextChangeEvent(mHyperText, mTextOffset + aAddlOffset,
     106               0 :                              aText, false);
     107               0 :     aEvents.AppendElement(event);
     108               0 :   }
     109                 : 
     110                 :   /**
     111                 :    * The constant used to skip string difference calculation in case of long
     112                 :    * strings.
     113                 :    */
     114                 :   const static PRUint32 kMaxStrLen = 1 << 6;
     115                 : 
     116                 : private:
     117                 :   nsDocAccessible* mDocument;
     118                 :   nsTextAccessible* mTextLeaf;
     119                 :   nsHyperTextAccessible* mHyperText;
     120                 :   PRInt32 mTextOffset;
     121                 : };
     122                 : 
     123                 : #endif

Generated by: LCOV version 1.7