Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Enumerations | Functions
mozInlineSpellWordUtil.cpp File Reference
#include "cattable.h"
#include "mozInlineSpellWordUtil.h"
#include "nsDebug.h"
#include "nsIAtom.h"
#include "nsComponentManagerUtils.h"
#include "nsIDOMCSSStyleDeclaration.h"
#include "nsIDOMDocumentView.h"
#include "nsIDOMElement.h"
#include "nsIDOMNSRange.h"
#include "nsIDOMRange.h"
#include "nsIEditor.h"
#include "nsIDOMNode.h"
#include "nsIDOMHTMLBRElement.h"

Go to the source code of this file.

Classes

struct  CheckLeavingBreakElementClosure
struct  WordSplitState

Defines

#define CHAR_CAT_NUMBER   2
#define CHAR_CAT_SPACE   3
#define CHAR_CAT_CONTROL   4
#define CHAR_CAT_WORD   5
#define CHAR_CAT_PUNCTUATION1   6
#define CHAR_CAT_PUNCTUATION2   7

Typedefs

typedef void(* OnLeaveNodeFunPtr )(nsIDOMNode *aNode, void *aClosure)

Enumerations

enum  CharClass { CHAR_CLASS_WORD, CHAR_CLASS_SEPARATOR, CHAR_CLASS_END_OF_INPUT }

Functions

PRBool IsIgnorableCharacter (PRUnichar ch)
PRBool IsConditionalPunctuation (PRUnichar ch)
static PRBool IsTextNode (nsIDOMNode *aNode)
static nsIDOMNodeFindNextNode (nsIDOMNode *aNode, nsIDOMNode *aRoot, OnLeaveNodeFunPtr aOnLeaveNode=nsnull, void *aClosure=nsnull)
static nsIDOMNodeFindNextTextNode (nsIDOMNode *aNode, PRInt32 aOffset, nsIDOMNode *aRoot)
static void NormalizeWord (const nsSubstring &aInput, PRInt32 aPos, PRInt32 aLen, nsAString &aOutput)
static PRBool IsDOMWordSeparator (PRUnichar ch)
static PRBool IsBRElement (nsIDOMNode *aNode)
static void GetNodeText (nsIDOMNode *aNode, nsAutoString &aText)
static nsIDOMNodeFindPrevNode (nsIDOMNode *aNode, nsIDOMNode *aRoot)
static PRBool ContainsDOMWordSeparator (nsIDOMNode *aNode, PRInt32 aBeforeOffset, PRInt32 *aSeparatorOffset)
 Check if there's a DOM word separator before aBeforeOffset in this node.
static PRBool IsBreakElement (nsIDOMViewCSS *aDocView, nsIDOMNode *aNode)
static void CheckLeavingBreakElement (nsIDOMNode *aNode, void *aClosure)

Class Documentation

struct CheckLeavingBreakElementClosure

Definition at line 530 of file mozInlineSpellWordUtil.cpp.

Collaboration diagram for CheckLeavingBreakElementClosure:
Class Members
nsIDOMViewCSS * mDocView
PRPackedBool mLeftBreakElement

Define Documentation

Definition at line 56 of file mozInlineSpellWordUtil.cpp.

Definition at line 54 of file mozInlineSpellWordUtil.cpp.

Definition at line 58 of file mozInlineSpellWordUtil.cpp.

Definition at line 59 of file mozInlineSpellWordUtil.cpp.

Definition at line 55 of file mozInlineSpellWordUtil.cpp.

Definition at line 57 of file mozInlineSpellWordUtil.cpp.


Typedef Documentation

Definition at line 134 of file mozInlineSpellWordUtil.cpp.


Enumeration Type Documentation

enum CharClass
Enumerator:
CHAR_CLASS_WORD 
CHAR_CLASS_SEPARATOR 
CHAR_CLASS_END_OF_INPUT 

Definition at line 797 of file mozInlineSpellWordUtil.cpp.


Function Documentation

static void CheckLeavingBreakElement ( nsIDOMNode aNode,
void aClosure 
) [static]

Definition at line 536 of file mozInlineSpellWordUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool ContainsDOMWordSeparator ( nsIDOMNode aNode,
PRInt32  aBeforeOffset,
PRInt32 aSeparatorOffset 
) [static]

Check if there's a DOM word separator before aBeforeOffset in this node.

Always returns PR_TRUE if it's a BR element. aSeparatorOffset is set to the index of the last separator if any is found (0 for BR elements).

Definition at line 469 of file mozInlineSpellWordUtil.cpp.

{
  if (IsBRElement(aNode)) {
    *aSeparatorOffset = 0;
    return PR_TRUE;
  }
  
  if (!IsTextNode(aNode))
    return PR_FALSE;

  nsAutoString str;
  GetNodeText(aNode, str);
  for (PRInt32 i = PR_MIN(aBeforeOffset, PRInt32(str.Length())) - 1; i >= 0; --i) {
    if (IsDOMWordSeparator(str.CharAt(i))) {
      *aSeparatorOffset = i;
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIDOMNode* FindNextNode ( nsIDOMNode aNode,
nsIDOMNode aRoot,
OnLeaveNodeFunPtr  aOnLeaveNode = nsnull,
void aClosure = nsnull 
) [static]

Definition at line 140 of file mozInlineSpellWordUtil.cpp.

{
  NS_PRECONDITION(aNode, "Null starting node?");

  nsCOMPtr<nsIDOMNode> next;
  aNode->GetFirstChild(getter_AddRefs(next));
  if (next)
    return next;
  
  // Don't look at siblings or otherwise outside of aRoot
  if (aNode == aRoot)
    return nsnull;

  aNode->GetNextSibling(getter_AddRefs(next));
  if (next)
    return next;

  // Go up
  for (;;) {
    if (aOnLeaveNode) {
      aOnLeaveNode(aNode, aClosure);
    }
    
    aNode->GetParentNode(getter_AddRefs(next));
    if (next == aRoot || ! next)
      return nsnull;
    aNode = next;
    
    aNode->GetNextSibling(getter_AddRefs(next));
    if (next)
      return next;
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIDOMNode* FindNextTextNode ( nsIDOMNode aNode,
PRInt32  aOffset,
nsIDOMNode aRoot 
) [static]

Definition at line 178 of file mozInlineSpellWordUtil.cpp.

{
  NS_PRECONDITION(aNode, "Null starting node?");
  NS_ASSERTION(!IsTextNode(aNode), "FindNextTextNode should start with a non-text node");

  nsIDOMNode* checkNode;
  // Need to start at the aOffset'th child
  nsCOMPtr<nsIDOMNode> child;
  aNode->GetFirstChild(getter_AddRefs(child));
  while (child && aOffset > 0) {
    nsCOMPtr<nsIDOMNode> next;
    child->GetNextSibling(getter_AddRefs(next));
    child.swap(next);
    --aOffset;
  }
  if (child) {
    checkNode = child;
  } else {
    // aOffset was beyond the end of the child list. Start checking at the next
    // node after the last child, or aNode if there are no children.
    aNode->GetLastChild(getter_AddRefs(child));
    if (child) {
      checkNode = FindNextNode(child, aRoot);
    } else {
      checkNode = FindNextNode(aNode, aRoot);
    }
  }
  
  while (checkNode && !IsTextNode(checkNode)) {
    checkNode = FindNextNode(checkNode, aRoot);
  }
  return checkNode;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static nsIDOMNode* FindPrevNode ( nsIDOMNode aNode,
nsIDOMNode aRoot 
) [static]

Definition at line 439 of file mozInlineSpellWordUtil.cpp.

{
  if (aNode == aRoot)
    return nsnull;
  
  nsCOMPtr<nsIDOMNode> prev;
  aNode->GetPreviousSibling(getter_AddRefs(prev));
  if (prev) {
    for (;;) {
      nsCOMPtr<nsIDOMNode> lastChild;
      prev->GetLastChild(getter_AddRefs(lastChild));
      if (!lastChild)
        return prev;
      prev = lastChild;
    }
  }

  // No prev sibling. So we are the first child of our parent, if any. Our
  // parent is our previous node.
  aNode->GetParentNode(getter_AddRefs(prev));
  return prev;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void GetNodeText ( nsIDOMNode aNode,
nsAutoString aText 
) [static]

Definition at line 430 of file mozInlineSpellWordUtil.cpp.

{
  nsresult rv = aNode->GetNodeValue(aText);
  NS_ASSERTION(NS_SUCCEEDED(rv), "Unable to get node text");
}

Here is the caller graph for this function:

static PRBool IsBreakElement ( nsIDOMViewCSS aDocView,
nsIDOMNode aNode 
) [static]

Definition at line 492 of file mozInlineSpellWordUtil.cpp.

{
  nsCOMPtr<nsIDOMElement> element = do_QueryInterface(aNode);
  if (!element)
    return PR_FALSE;
    
  if (IsBRElement(aNode))
    return PR_TRUE;
  
  nsCOMPtr<nsIDOMCSSStyleDeclaration> style;
  aDocView->GetComputedStyle(element, EmptyString(), getter_AddRefs(style));
  if (!style)
    return PR_FALSE;

#ifdef DEBUG_SPELLCHECK
  printf("    searching element %p\n", (void*)aNode);
#endif

  nsAutoString display;
  style->GetPropertyValue(NS_LITERAL_STRING("display"), display);
#ifdef DEBUG_SPELLCHECK
  printf("      display=\"%s\"\n", NS_ConvertUTF16toUTF8(display).get());
#endif
  if (!display.EqualsLiteral("inline"))
    return PR_TRUE;

  nsAutoString position;
  style->GetPropertyValue(NS_LITERAL_STRING("position"), position);
#ifdef DEBUG_SPELLCHECK
  printf("      position=%s\n", NS_ConvertUTF16toUTF8(position).get());
#endif
  if (!position.EqualsLiteral("static"))
    return PR_TRUE;
    
  // XXX What about floats? What else?
  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static PRBool IsBRElement ( nsIDOMNode aNode) [static]

Definition at line 422 of file mozInlineSpellWordUtil.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 77 of file mozInlineSpellWordUtil.cpp.

{
  return (ch == '\'' ||
          ch == 0x2019); // RIGHT SINGLE QUOTATION MARK
}

Here is the caller graph for this function:

static PRBool IsDOMWordSeparator ( PRUnichar  ch) [static]

Definition at line 401 of file mozInlineSpellWordUtil.cpp.

{
  // simple spaces
  if (ch == ' ' || ch == '\t' || ch == '\n' || ch == '\r')
    return PR_TRUE;

  // complex spaces - check only if char isn't ASCII (uncommon)
  if (ch >= 0xA0 &&
      (ch == 0x00A0 ||  // NO-BREAK SPACE
       ch == 0x2002 ||  // EN SPACE
       ch == 0x2003 ||  // EM SPACE
       ch == 0x2009 ||  // THIN SPACE
       ch == 0x200C ||  // ZERO WIDTH NON-JOINER
       ch == 0x3000))   // IDEOGRAPHIC SPACE
    return PR_TRUE;

  // otherwise not a space
  return PR_FALSE;
}

Here is the caller graph for this function:

Definition at line 65 of file mozInlineSpellWordUtil.cpp.

{
  return (ch == 0x200D || // ZERO-WIDTH JOINER
          ch == 0xAD ||   // SOFT HYPHEN
          ch == 0x1806);  // MONGOLIAN TODO SOFT HYPHEN
}

Here is the caller graph for this function:

static PRBool IsTextNode ( nsIDOMNode aNode) [static]

Definition at line 127 of file mozInlineSpellWordUtil.cpp.

{
  PRUint16 type = 0;
  aNode->GetNodeType(&type);
  return type == nsIDOMNode::TEXT_NODE;
}

Here is the caller graph for this function:

static void NormalizeWord ( const nsSubstring aInput,
PRInt32  aPos,
PRInt32  aLen,
nsAString &  aOutput 
) [static]

Definition at line 311 of file mozInlineSpellWordUtil.cpp.

{
  aOutput.Truncate();
  for (PRInt32 i = 0; i < aLen; i++) {
    PRUnichar ch = aInput.CharAt(i + aPos);

    // remove ignorable characters from the word
    if (IsIgnorableCharacter(ch))
      continue;

    // the spellchecker doesn't handle curly apostrophes in all languages
    if (ch == 0x2019) { // RIGHT SINGLE QUOTATION MARK
      ch = '\'';
    }

    aOutput.Append(ch);
  }
}

Here is the call graph for this function: