Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Static Public Member Functions | Public Attributes | Static Public Attributes | Protected Member Functions | Static Protected Member Functions | Protected Attributes | Friends
nsAccessibleEditableText Class Reference

#include <nsAccessibleText.h>

Inheritance diagram for nsAccessibleEditableText:
Inheritance graph
[legend]
Collaboration diagram for nsAccessibleEditableText:
Collaboration graph
[legend]

List of all members.

Public Member Functions

NS_DECL_ISUPPORTS
NS_DECL_NSIACCESSIBLEEDITABLETEXT
NS_DECL_NSIEDITACTIONLISTENER 
nsAccessibleEditableText (nsIDOMNode *aNode)
 nsAccessibleEditableText implements the nsIAccessibleText interface for editable text, such as HTML <input>, <textarea> and XUL <editor>
virtual ~nsAccessibleEditableText ()
NS_IMETHOD GetCaretOffset (PRInt32 *aCaretOffset)
 nsIAccessibleText impl.
NS_IMETHOD SetCaretOffset (PRInt32 aCaretOffset)
NS_IMETHOD GetCharacterCount (PRInt32 *aCharacterCount)
NS_IMETHOD GetText (PRInt32 startOffset, PRInt32 endOffset, nsAString &aText)
NS_IMETHOD GetTextBeforeOffset (PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString &aText)
NS_IMETHOD GetTextAtOffset (PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString &aText)
NS_IMETHOD GetTextAfterOffset (PRInt32 aOffset, nsAccessibleTextBoundary aBoundaryType, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsAString &aText)
void ShutdownEditor ()
AString getText (in long startOffset, in long endOffset)
 String methods may need to return multibyte-encoded strings, since some locales can't be encoded using 16-bit chars.
AString getTextAfterOffset (in long offset, in nsAccessibleTextBoundary boundaryType, out long startOffset, out long endOffset)
AString getTextAtOffset (in long offset, in nsAccessibleTextBoundary boundaryType, out long startOffset, out long endOffset)
AString getTextBeforeOffset (in long offset, in nsAccessibleTextBoundary boundaryType, out long startOffset, out long endOffset)
wchar getCharacterAtOffset (in long offset)
 It would be better to return an unsigned long here, to allow unicode chars > 16 bits.
nsISupports getAttributeRange (in long offset, out long rangeStartOffset, out long rangeEndOffset)
void getCharacterExtents (in long offset, out long x, out long y, out long width, out long height, in nsAccessibleCoordType coordType)
long getOffsetAtPoint (in long x, in long y, in nsAccessibleCoordType coordType)
void getSelectionBounds (in long selectionNum, out long startOffset, out long endOffset)
void setSelectionBounds (in long selectionNum, in long startOffset, in long endOffset)
void addSelection (in long startOffset, in long endOffset)
void removeSelection (in long selectionNum)
void setAttributes (in long startPos, in long endPos, in nsISupports attributes)
 Set font styles, such as italic, bold...
void setTextContents (in AString text)
void insertText (in AString text, in long position)
void copyText (in long startPos, in long endPos)
void cutText (in long startPos, in long endPos)
void deleteText (in long startPos, in long endPos)
void pasteText (in long position)
void WillCreateNode (in DOMString aTag, in nsIDOMNode aParent, in long aPosition)
 Called before the editor creates a node.
void DidCreateNode (in DOMString aTag, in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition, in nsresult aResult)
 Called after the editor creates a node.
void WillInsertNode (in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition)
 Called before the editor inserts a node.
void DidInsertNode (in nsIDOMNode aNode, in nsIDOMNode aParent, in long aPosition, in nsresult aResult)
 Called after the editor inserts a node.
void WillDeleteNode (in nsIDOMNode aChild)
 Called before the editor deletes a node.
void DidDeleteNode (in nsIDOMNode aChild, in nsresult aResult)
 Called after the editor deletes a node.
void WillSplitNode (in nsIDOMNode aExistingRightNode, in long aOffset)
 Called before the editor splits a node.
void DidSplitNode (in nsIDOMNode aExistingRightNode, in long aOffset, in nsIDOMNode aNewLeftNode, in nsresult aResult)
 Called after the editor splits a node.
void WillJoinNodes (in nsIDOMNode aLeftNode, in nsIDOMNode aRightNode, in nsIDOMNode aParent)
 Called before the editor joins 2 nodes.
void DidJoinNodes (in nsIDOMNode aLeftNode, in nsIDOMNode aRightNode, in nsIDOMNode aParent, in nsresult aResult)
 Called after the editor joins 2 nodes.
void WillInsertText (in nsIDOMCharacterData aTextNode, in long aOffset, in DOMString aString)
 Called before the editor inserts text.
void DidInsertText (in nsIDOMCharacterData aTextNode, in long aOffset, in DOMString aString, in nsresult aResult)
 Called after the editor inserts text.
void WillDeleteText (in nsIDOMCharacterData aTextNode, in long aOffset, in long aLength)
 Called before the editor deletes text.
void DidDeleteText (in nsIDOMCharacterData aTextNode, in long aOffset, in long aLength, in nsresult aResult)
 Called before the editor deletes text.
void WillDeleteSelection (in nsISelection aSelection)
 Called before the editor deletes the selection.
void DidDeleteSelection (in nsISelection aSelection)
 Called after the editor deletes the selection.

Static Public Member Functions

static PRBool IsSingleLineTextControl (nsIDOMNode *aDomNode)

Public Attributes

const nsAccessibleTextBoundary BOUNDARY_CHAR = 0
const nsAccessibleTextBoundary BOUNDARY_WORD_START = 1
const nsAccessibleTextBoundary BOUNDARY_WORD_END = 2
const nsAccessibleTextBoundary BOUNDARY_SENTENCE_START = 3
const nsAccessibleTextBoundary BOUNDARY_SENTENCE_END = 4
const nsAccessibleTextBoundary BOUNDARY_LINE_START = 5
const nsAccessibleTextBoundary BOUNDARY_LINE_END = 6
const nsAccessibleTextBoundary BOUNDARY_ATTRIBUTE_RANGE = 7
const nsAccessibleCoordType COORD_TYPE_SCREEN = 0
const nsAccessibleCoordType COORD_TYPE_WINDOW = 1
attribute long caretOffset
readonly attribute long characterCount
readonly attribute long selectionCount

Static Public Attributes

static PRBool gSuppressedNotifySelectionChanged = PR_FALSE

Protected Member Functions

virtual nsresult GetSelections (nsISelectionController **aSelCon, nsISelection **aDomSel)
 nsIAccessibleText helpers
void SetEditor (nsIEditor *aEditor)
 nsIAccessibleText helpers
nsITextControlFrameGetTextFrame ()
nsresult GetSelectionRange (PRInt32 *aStartPos, PRInt32 *aEndPos)
nsresult SetSelectionRange (PRInt32 aStartPos, PRInt32 aEndPos)
nsresult FireTextChangeEvent (AtkTextChange *aTextData)
nsresult GetTextHelperCore (EGetTextType aType, nsAccessibleTextBoundary aBoundaryType, PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsISelectionController *aSelCon, nsISelection *aDomSel, nsISupports *aClosure, nsAString &aText)
nsresult GetTextHelper (EGetTextType aType, nsAccessibleTextBoundary aBoundaryType, PRInt32 aOffset, PRInt32 *aStartOffset, PRInt32 *aEndOffset, nsISupports *aClosure, nsAString &aText)

Static Protected Member Functions

static nsresult DOMPointToOffset (nsISupports *aClosure, nsIDOMNode *aNode, PRInt32 aNodeOffset, PRInt32 *aResult)
static nsresult OffsetToDOMPoint (nsISupports *aClosure, PRInt32 aOffset, nsIDOMNode **aResult, PRInt32 *aPosition)
static nsresult GetCurrentOffset (nsISupports *aClosure, nsISelection *aDomSel, PRInt32 *aOffset)

Protected Attributes

nsCOMPtr< nsIEditormPlainEditor
nsCOMPtr< nsIDOMNodemTextNode

Friends

class nsAccessibleHyperText

Detailed Description

Definition at line 86 of file nsAccessibleText.h.


Constructor & Destructor Documentation

nsAccessibleEditableText implements the nsIAccessibleText interface for editable text, such as HTML <input>, <textarea> and XUL <editor>

Definition at line 911 of file nsAccessibleText.cpp.

                                                                   :
nsAccessibleText(aNode)
{
}

Definition at line 96 of file nsAccessibleText.h.

{};

Member Function Documentation

void nsIAccessibleText::addSelection ( in long  startOffset,
in long  endOffset 
) [inherited]
void nsIAccessibleEditableText::copyText ( in long  startPos,
in long  endPos 
) [inherited]
void nsIAccessibleEditableText::cutText ( in long  startPos,
in long  endPos 
) [inherited]
void nsIAccessibleEditableText::deleteText ( in long  startPos,
in long  endPos 
) [inherited]
void nsIEditActionListener::DidCreateNode ( in DOMString  aTag,
in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition,
in nsresult  aResult 
) [inherited]

Called after the editor creates a node.

Parameters:
aTagThe tag name of the DOM Node to create.
aNodeThe DOM Node that was created.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
aResultThe result of the create node operation.
void nsIEditActionListener::DidDeleteNode ( in nsIDOMNode  aChild,
in nsresult  aResult 
) [inherited]

Called after the editor deletes a node.

Parameters:
aChildThe node to delete
aResultThe result of the delete node operation.

Called after the editor deletes the selection.

Parameters:
aSelectionThe selection, after deletion

Here is the caller graph for this function:

void nsIEditActionListener::DidDeleteText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in long  aLength,
in nsresult  aResult 
) [inherited]

Called before the editor deletes text.

Parameters:
aTextNodeThis node getting text deleted
aOffsetThe offset in aTextNode to delete at.
aLengthThe amount of text to delete.
aResultThe result of the delete text operation.

Here is the caller graph for this function:

void nsIEditActionListener::DidInsertNode ( in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition,
in nsresult  aResult 
) [inherited]

Called after the editor inserts a node.

Parameters:
aNodeThe DOM Node to insert.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
aResultThe result of the insert node operation.
void nsIEditActionListener::DidInsertText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in DOMString  aString,
in nsresult  aResult 
) [inherited]

Called after the editor inserts text.

Parameters:
aTextNodeThis node getting inserted text
aOffsetThe offset in aTextNode to insert at.
aStringThe string that gets inserted.
aResultThe result of the insert text operation.

Here is the caller graph for this function:

void nsIEditActionListener::DidJoinNodes ( in nsIDOMNode  aLeftNode,
in nsIDOMNode  aRightNode,
in nsIDOMNode  aParent,
in nsresult  aResult 
) [inherited]

Called after the editor joins 2 nodes.

Parameters:
aLeftNodeThis node will be merged into the right node
aRightNodeThe node that will be merged into. There is no requirement that the two nodes be of the same type.
aParentThe parent of aRightNode
aResultThe result of the join operation.
void nsIEditActionListener::DidSplitNode ( in nsIDOMNode  aExistingRightNode,
in long  aOffset,
in nsIDOMNode  aNewLeftNode,
in nsresult  aResult 
) [inherited]

Called after the editor splits a node.

Parameters:
aExistingRightNodethe node to split. It will become the new node's next sibling.
aOffsetthe offset of aExistingRightNode's content|children to do the split at
aNewLeftNode[OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.
nsresult nsAccessibleText::DOMPointToOffset ( nsISupports *  aClosure,
nsIDOMNode aNode,
PRInt32  aNodeOffset,
PRInt32 aResult 
) [static, protected, inherited]

Definition at line 133 of file nsAccessibleText.cpp.

{
  NS_ENSURE_ARG_POINTER(aNode && aResult);

  *aResult = aNodeOffset;

  nsCOMPtr<nsIArray> domNodeArray(do_QueryInterface(aClosure));
  if (domNodeArray) {
    // Static text, calculate the offset from a given set of (text) node
    PRUint32 textLength, totalLength = 0;
    PRUint32 index, count;
    domNodeArray->GetLength(&count);
    for (index = 0; index < count; index++) {
      nsCOMPtr<nsIDOMNode> domNode(do_QueryElementAt(domNodeArray, index));
      if (aNode == domNode) {
        *aResult = aNodeOffset + totalLength;
        break;
      }
      nsCOMPtr<nsIDOMText> domText(do_QueryInterface(domNode));
      if (domText) {
        domText->GetLength(&textLength);
        totalLength += textLength;
      }
    }

    return NS_OK;
  }

  nsCOMPtr<nsIEditor> editor(do_QueryInterface(aClosure));
  if (editor) { // revised according to nsTextControlFrame::DOMPointToOffset
    // Editable text, calculate the offset from the editor
    nsCOMPtr<nsIDOMElement> rootElement;
    editor->GetRootElement(getter_AddRefs(rootElement));
    nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));

    NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);

    nsCOMPtr<nsIDOMNodeList> nodeList;

    nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);

    PRUint32 length = 0;
    rv = nodeList->GetLength(&length);
    NS_ENSURE_SUCCESS(rv, rv);

    if (!length || aNodeOffset < 0)
      return NS_OK;

    PRInt32 i, textOffset = 0;
    PRInt32 lastIndex = (PRInt32)length - 1;

    for (i = 0; i < (PRInt32)length; i++) {
      if (rootNode == aNode && i == aNodeOffset) {
        *aResult = textOffset;
        return NS_OK;
      }

      nsCOMPtr<nsIDOMNode> item;
      rv = nodeList->Item(i, getter_AddRefs(item));
      NS_ENSURE_SUCCESS(rv, rv);
      NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);

      if (item == aNode) {
        *aResult = textOffset + aNodeOffset;
        return NS_OK;
      }

      nsCOMPtr<nsIDOMText> domText(do_QueryInterface(item));

      if (domText) {
        PRUint32 textLength = 0;

        rv = domText->GetLength(&textLength);
        NS_ENSURE_SUCCESS(rv, rv);

        textOffset += textLength;
      }
      else {
        // Must be a BR node. If it's not the last BR node
        // under the root, count it as a newline.
        if (i != lastIndex)
          ++textOffset;
      }
    }

    NS_ASSERTION((aNode == rootNode && aNodeOffset == (PRInt32)length),
                 "Invalid node offset!");

    *aResult = textOffset;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 941 of file nsAccessibleText.cpp.

{
  nsCOMPtr<nsIAccessible> accessible(do_QueryInterface(NS_STATIC_CAST(nsIAccessibleText*, this)));
  nsCOMPtr<nsPIAccessible> privAccessible(do_QueryInterface(accessible));
  if (privAccessible) {
#ifdef DEBUG
    printf("  [start=%d, length=%d, add=%d]\n", aTextData->start, aTextData->length, aTextData->add);
#endif
    privAccessible->FireToolkitEvent(nsIAccessibleEvent::EVENT_ATK_TEXT_CHANGE, accessible, aTextData);
  }

  return NS_OK;
}

Here is the call graph for this function:

nsISupports nsIAccessibleText::getAttributeRange ( in long  offset,
out long  rangeStartOffset,
out long  rangeEndOffset 
) [inherited]

nsIAccessibleText impl.

Definition at line 1125 of file nsAccessibleText.cpp.

{
  *aCaretOffset = 0;

  PRInt32 startPos, endPos;
  nsresult rv = GetSelectionRange(&startPos, &endPos);
  NS_ENSURE_SUCCESS(rv, rv);

  if (startPos == endPos) { // selection must be collapsed
    *aCaretOffset = startPos;
    return NS_OK;
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

wchar nsIAccessibleText::getCharacterAtOffset ( in long  offset) [inherited]

It would be better to return an unsigned long here, to allow unicode chars > 16 bits.

Definition at line 1152 of file nsAccessibleText.cpp.

{
  *aCharacterCount = 0;

  nsITextControlFrame *textFrame = GetTextFrame();
  if (textFrame) {
    return textFrame->GetTextLength(aCharacterCount);
  }

  NS_ENSURE_TRUE(mPlainEditor, NS_ERROR_FAILURE);
  NS_NAMED_LITERAL_STRING(format, "text/plain");
  nsAutoString text;
  mPlainEditor->OutputToString(format, nsIDocumentEncoder::OutputFormatted, text);
  *aCharacterCount = text.Length();

  return NS_OK;
}

Here is the call graph for this function:

void nsIAccessibleText::getCharacterExtents ( in long  offset,
out long  x,
out long  y,
out long  width,
out long  height,
in nsAccessibleCoordType  coordType 
) [inherited]
nsresult nsAccessibleText::GetCurrentOffset ( nsISupports *  aClosure,
nsISelection aDomSel,
PRInt32 aOffset 
) [static, protected, inherited]

Definition at line 321 of file nsAccessibleText.cpp.

{
  nsCOMPtr<nsIDOMNode> focusNode;
  aDomSel->GetFocusNode(getter_AddRefs(focusNode));
  aDomSel->GetFocusOffset(aOffset);
  return DOMPointToOffset(aClosure, focusNode, *aOffset, aOffset);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIAccessibleText::getSelectionBounds ( in long  selectionNum,
out long  startOffset,
out long  endOffset 
) [inherited]
nsresult nsAccessibleEditableText::GetSelectionRange ( PRInt32 aStartPos,
PRInt32 aEndPos 
) [protected]

Definition at line 1015 of file nsAccessibleText.cpp.

{
  *aStartPos = 0;
  *aEndPos = 0;

  nsITextControlFrame *textFrame = GetTextFrame();
  if (textFrame) {
    return textFrame->GetSelectionRange(aStartPos, aEndPos);
  }
  else {
    // editor, revised according to nsTextControlFrame::GetSelectionRange
    NS_ENSURE_TRUE(mPlainEditor, NS_ERROR_FAILURE);
    nsCOMPtr<nsISelection> selection;
    nsresult rv = mPlainEditor->GetSelection(getter_AddRefs(selection));  
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);

    PRInt32 numRanges = 0;
    selection->GetRangeCount(&numRanges);
    NS_ENSURE_TRUE(numRanges >= 1, NS_ERROR_FAILURE);

    nsCOMPtr<nsIDOMRange> firstRange;
    rv = selection->GetRangeAt(0, getter_AddRefs(firstRange));
    NS_ENSURE_TRUE(firstRange, NS_ERROR_FAILURE);

    nsCOMPtr<nsIDOMNode> startNode, endNode;
    PRInt32 startOffset = 0, endOffset = 0;

    // Get the start point of the range.
    rv = firstRange->GetStartContainer(getter_AddRefs(startNode));
    NS_ENSURE_TRUE(startNode, NS_ERROR_FAILURE);

    rv = firstRange->GetStartOffset(&startOffset);
    NS_ENSURE_SUCCESS(rv, rv);

    // Get the end point of the range.
    rv = firstRange->GetEndContainer(getter_AddRefs(endNode));
    NS_ENSURE_TRUE(endNode, NS_ERROR_FAILURE);

    rv = firstRange->GetEndOffset(&endOffset);
    NS_ENSURE_SUCCESS(rv, rv);

    // Convert the start/end point to a selection offset.
    rv = DOMPointToOffset(mPlainEditor, startNode, startOffset, aStartPos);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = DOMPointToOffset(mPlainEditor, endNode, endOffset, aEndPos);
    NS_ENSURE_SUCCESS(rv, rv);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAccessibleEditableText::GetSelections ( nsISelectionController **  aSelCon,
nsISelection **  aDomSel 
) [protected, virtual]

nsIAccessibleText helpers

Reimplemented from nsAccessibleText.

Definition at line 955 of file nsAccessibleText.cpp.

{
  nsCOMPtr<nsIDocument> doc(do_QueryInterface(mTextNode));
  if (!doc)
    return nsAccessibleText::GetSelections(aSelCon, aDomSel);
    
  // it's composer
  if (!mPlainEditor)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsISelectionController> selCon;
  nsCOMPtr<nsISelection> domSel;
  mPlainEditor->GetSelectionController(getter_AddRefs(selCon));
  if (selCon)
    selCon->GetSelection(nsISelectionController::SELECTION_NORMAL, getter_AddRefs(domSel));

  NS_ENSURE_TRUE(selCon && domSel, NS_ERROR_FAILURE);

  PRBool isSelectionCollapsed;
  domSel->GetIsCollapsed(&isSelectionCollapsed);
  // Don't perform any actions when the selection is not collapsed
  if (!isSelectionCollapsed) {
    return NS_ERROR_FAILURE;
  }

  if (aSelCon) {
    *aSelCon = selCon;
    NS_ADDREF(*aSelCon);
  }

  if (aDomSel) {
    *aDomSel = domSel;
    NS_ADDREF(*aDomSel);
  }

  return NS_OK;
}

Here is the call graph for this function:

AString nsIAccessibleText::getText ( in long  startOffset,
in long  endOffset 
) [inherited]

String methods may need to return multibyte-encoded strings, since some locales can't be encoded using 16-bit chars.

So the methods below might return UTF-16 strings, or they could return "string" values which are UTF-8.

NS_IMETHODIMP nsAccessibleEditableText::GetText ( PRInt32  startOffset,
PRInt32  endOffset,
nsAString &  aText 
)

Definition at line 1173 of file nsAccessibleText.cpp.

{
  if (aStartOffset == aEndOffset)
    return NS_OK;

  nsAutoString text;
  nsITextControlFrame *textFrame = GetTextFrame();
  if (textFrame) {
    textFrame->GetValue(text, PR_TRUE);
  }
  else {
    NS_ENSURE_TRUE(mPlainEditor, NS_ERROR_FAILURE);
    NS_NAMED_LITERAL_STRING(format, "text/plain");
    mPlainEditor->OutputToString(format, nsIDocumentEncoder::OutputFormatted, text);
  }

  PRInt32 length = text.Length();
  if (aEndOffset == -1) // get all text from aStartOffset
    aEndOffset = length;

  NS_ENSURE_TRUE((0 <= aStartOffset && aStartOffset < aEndOffset && aEndOffset <= length),
                 NS_ERROR_FAILURE);

  aText = Substring(text, aStartOffset, aEndOffset - aStartOffset);

  return NS_OK;
}

Here is the call graph for this function:

AString nsIAccessibleText::getTextAfterOffset ( in long  offset,
in nsAccessibleTextBoundary  boundaryType,
out long  startOffset,
out long  endOffset 
) [inherited]
NS_IMETHODIMP nsAccessibleEditableText::GetTextAfterOffset ( PRInt32  aOffset,
nsAccessibleTextBoundary  aBoundaryType,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAString &  aText 
)

Definition at line 1213 of file nsAccessibleText.cpp.

{
  return GetTextHelper(eGetAfter, aBoundaryType, aOffset, aStartOffset, aEndOffset, mPlainEditor, aText);
}

Here is the call graph for this function:

AString nsIAccessibleText::getTextAtOffset ( in long  offset,
in nsAccessibleTextBoundary  boundaryType,
out long  startOffset,
out long  endOffset 
) [inherited]
NS_IMETHODIMP nsAccessibleEditableText::GetTextAtOffset ( PRInt32  aOffset,
nsAccessibleTextBoundary  aBoundaryType,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAString &  aText 
)

Definition at line 1207 of file nsAccessibleText.cpp.

{
  return GetTextHelper(eGetAt, aBoundaryType, aOffset, aStartOffset, aEndOffset, mPlainEditor, aText);
}

Here is the call graph for this function:

AString nsIAccessibleText::getTextBeforeOffset ( in long  offset,
in nsAccessibleTextBoundary  boundaryType,
out long  startOffset,
out long  endOffset 
) [inherited]
NS_IMETHODIMP nsAccessibleEditableText::GetTextBeforeOffset ( PRInt32  aOffset,
nsAccessibleTextBoundary  aBoundaryType,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsAString &  aText 
)

Definition at line 1201 of file nsAccessibleText.cpp.

{
  return GetTextHelper(eGetBefore, aBoundaryType, aOffset, aStartOffset, aEndOffset, mPlainEditor, aText);
}

Here is the call graph for this function:

Definition at line 993 of file nsAccessibleText.cpp.

{
  nsCOMPtr<nsIDOMDocument> domDoc;
  mTextNode->GetOwnerDocument(getter_AddRefs(domDoc));
  nsCOMPtr<nsIDocument> doc(do_QueryInterface(domDoc));
  if (!doc) // that could be a composer
    return nsnull;

  nsIPresShell *shell = doc->GetShellAt(0);
  NS_ENSURE_TRUE(shell, nsnull);

  nsCOMPtr<nsIContent> content(do_QueryInterface(mTextNode));
  nsIFrame *frame = nsnull;
  shell->GetPrimaryFrameFor(content, &frame);
  NS_ENSURE_TRUE(frame, nsnull);

  nsITextControlFrame *textFrame;
  frame->QueryInterface(NS_GET_IID(nsITextControlFrame), (void**)&textFrame);

  return textFrame;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAccessibleText::GetTextHelper ( EGetTextType  aType,
nsAccessibleTextBoundary  aBoundaryType,
PRInt32  aOffset,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsISupports *  aClosure,
nsAString &  aText 
) [protected, inherited]

Definition at line 522 of file nsAccessibleText.cpp.

{
  NS_ENSURE_TRUE((aOffset >= 0), NS_ERROR_INVALID_ARG);
  
  nsCOMPtr<nsISelectionController> selCon;
  nsCOMPtr<nsISelection> domSel;

  nsresult rv = GetSelections(getter_AddRefs(selCon), getter_AddRefs(domSel));
  NS_ENSURE_SUCCESS(rv, rv);

  //backup old settings
  PRInt16 displaySelection;
  selCon->GetDisplaySelection(&displaySelection);
  PRBool caretEnable;
  selCon->GetCaretEnabled(&caretEnable);

  //turn off display and caret
  selCon->SetDisplaySelection(nsISelectionController::SELECTION_HIDDEN);
  selCon->SetCaretEnabled(PR_FALSE);

  //turn off nsCaretAccessible::NotifySelectionChanged
  gSuppressedNotifySelectionChanged = PR_TRUE;

  PRInt32 caretOffset = -1;
  if (NS_SUCCEEDED(GetCaretOffset(&caretOffset))) {
    if (caretOffset != aOffset)
      SetCaretOffset(aOffset);
  }

  *aStartOffset = *aEndOffset = aOffset;
  rv = GetTextHelperCore(aType, aBoundaryType, aOffset, aStartOffset, aEndOffset, selCon, domSel, aClosure, aText);

  //restore caret offset
  if (caretOffset >= 0) {
    SetCaretOffset(caretOffset);
  }

  //turn on nsCaretAccessible::NotifySelectionChanged
  gSuppressedNotifySelectionChanged = PR_FALSE;

  //restore old settings
  selCon->SetDisplaySelection(displaySelection);
  selCon->SetCaretEnabled(caretEnable);

  return rv;
}

Here is the call graph for this function:

Here is the caller graph for this function:

nsresult nsAccessibleText::GetTextHelperCore ( EGetTextType  aType,
nsAccessibleTextBoundary  aBoundaryType,
PRInt32  aOffset,
PRInt32 aStartOffset,
PRInt32 aEndOffset,
nsISelectionController aSelCon,
nsISelection aDomSel,
nsISupports *  aClosure,
nsAString &  aText 
) [protected, inherited]

Definition at line 355 of file nsAccessibleText.cpp.

{
  PRInt32 rangeCount;
  nsCOMPtr<nsIDOMRange> range, oldRange;
  aDomSel->GetRangeCount(&rangeCount);

  if (rangeCount == 0) { // ever happen?
    SetCaretOffset(aOffset); // a new range will be added here
    rangeCount++;
  }
  aDomSel->GetRangeAt(rangeCount - 1, getter_AddRefs(range));
  NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);

  // backup the original selection range to restore the selection status later
  range->CloneRange(getter_AddRefs(oldRange));

  // Step1: move caret to an appropriate start position
  // Step2: move caret to end postion and select the text
  PRBool isStep1Forward, isStep2Forward;  // Moving directions for two steps
  switch (aType)
  {
  case eGetBefore:
    isStep1Forward = PR_FALSE;
    isStep2Forward = PR_FALSE;
    break;
  case eGetAt:
    isStep1Forward = PR_FALSE;
    isStep2Forward = PR_TRUE;
    break;
  case eGetAfter:
    isStep1Forward = PR_TRUE;
    isStep2Forward = PR_TRUE;
    break;
  default:
    return NS_ERROR_INVALID_ARG;
  }

  // The start/end focus node may be not our mTextNode
  nsCOMPtr<nsIDOMNode> startFocusNode, endFocusNode;
  switch (aBoundaryType)
  {
  case BOUNDARY_CHAR:
    if (aType == eGetAfter) { // We need the character next to current position
      aSelCon->CharacterMove(isStep1Forward, PR_FALSE);
      GetCurrentOffset(aClosure, aDomSel, aStartOffset);
    }
    aSelCon->CharacterMove(isStep2Forward, PR_TRUE);
    GetCurrentOffset(aClosure, aDomSel, aEndOffset);
    break;
  case BOUNDARY_WORD_START:
    {
    PRBool dontMove = PR_FALSE;
    // If we are at the word boundary, don't move the caret in the first step
    if (aOffset == 0)
      dontMove = PR_TRUE;
    else {
      PRUnichar prevChar;
      GetCharacterAtOffset(aOffset - 1, &prevChar);
      if (prevChar == ' ' || prevChar == '\t' || prevChar == '\n')
        dontMove = PR_TRUE;
    }
    if (!dontMove) {
      aSelCon->WordMove(isStep1Forward, PR_FALSE); // Move caret to previous/next word start boundary
      GetCurrentOffset(aClosure, aDomSel, aStartOffset);
    }
    aSelCon->WordMove(isStep2Forward, PR_TRUE);  // Select previous/next word
    GetCurrentOffset(aClosure, aDomSel, aEndOffset);
    }
    break;
  case BOUNDARY_LINE_START:
    if (aType != eGetAt) {
      // XXX, don't support yet
      return NS_ERROR_NOT_IMPLEMENTED;
    }
    aSelCon->IntraLineMove(PR_FALSE, PR_FALSE);  // Move caret to the line start
    GetCurrentOffset(aClosure, aDomSel, aStartOffset);
    aSelCon->IntraLineMove(PR_TRUE, PR_TRUE);    // Move caret to the line end and select the whole line
    GetCurrentOffset(aClosure, aDomSel, aEndOffset);
    break;
  case BOUNDARY_WORD_END:
    {
    // please refer to atk implementation (atktext.c)
    // for specification of ATK_TEXT_BOUNDARY_WORD_END when before/at/after offset
    // XXX, need to follow exact definition of ATK_TEXT_BOUNDARY_WORD_END

    if (aType != eGetAt) {
      // XXX, don't support yet
      return NS_ERROR_NOT_IMPLEMENTED;
    }

    // Example of current code: _AB_CD_E_ ("_" is space)
    // offset      return string   startOffset endOffset
    //      0      AB_             1           4
    //      1      AB_             1           4
    //      2      AB_             1           4
    //      3      AB_             1           4
    //      4      CD_             4           7
    //      5      CD_             4           7
    //      6      CD_             4           7
    //      7      E_              7           9
    //      8      E_              7           9

    PRUnichar offsetChar;
    nsresult rv = GetCharacterAtOffset(aOffset, &offsetChar);
    NS_ENSURE_SUCCESS(rv, rv);
    PRBool isOffsetEmpty =  offsetChar == ' ' || offsetChar == '\t' || offsetChar == '\n';

    PRInt32 stepBackwardCount = 0; // Times of move backward to find the word(e.g. "AB_") start boundary
    if (aOffset == 0) {
      if (isOffsetEmpty)
        aSelCon->WordMove(PR_TRUE, PR_FALSE); // Move caret to the first word start boundary
    }
    else {
      PRUnichar prevChar;
      GetCharacterAtOffset(aOffset - 1, &prevChar);
      PRBool isPrevEmpty =  prevChar == ' ' || prevChar == '\t' || prevChar == '\n';
      if (!isPrevEmpty)
        stepBackwardCount = 1;
      else if (isOffsetEmpty)
        stepBackwardCount = 2;
      else
        stepBackwardCount = 0;

      PRInt32 step;
      for (step = 0; step < stepBackwardCount; step++)
        aSelCon->WordMove(PR_FALSE, PR_FALSE); // Move caret to current word start boundary
    }

    GetCurrentOffset(aClosure, aDomSel, aStartOffset);
    // Move twice to select a "word"
    aSelCon->WordMove(PR_TRUE, PR_TRUE);
    aSelCon->WordMove(PR_TRUE, PR_TRUE);
    GetCurrentOffset(aClosure, aDomSel, aEndOffset);
    }
    break;
  case BOUNDARY_LINE_END:
  case BOUNDARY_SENTENCE_START:
  case BOUNDARY_SENTENCE_END:
  case BOUNDARY_ATTRIBUTE_RANGE:
    return NS_ERROR_NOT_IMPLEMENTED;
  default:
    return NS_ERROR_INVALID_ARG;
  }

  nsXPIDLString text;
  // Get text from selection
  nsresult rv = aDomSel->ToString(getter_Copies(text));
  aDomSel->RemoveAllRanges();
  // restore the original selection range
  aDomSel->AddRange(oldRange);
  NS_ENSURE_SUCCESS(rv, rv);

  aText = text;

  // Ensure aStartOffset <= aEndOffset
  if (*aStartOffset > *aEndOffset) {
    PRInt32 tmp = *aStartOffset;
    *aStartOffset = *aEndOffset;
    *aEndOffset = tmp;
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIAccessibleEditableText::insertText ( in AString  text,
in long  position 
) [inherited]

Definition at line 935 of file nsAccessibleText.cpp.

Here is the call graph for this function:

nsresult nsAccessibleText::OffsetToDOMPoint ( nsISupports *  aClosure,
PRInt32  aOffset,
nsIDOMNode **  aResult,
PRInt32 aPosition 
) [static, protected, inherited]

Definition at line 229 of file nsAccessibleText.cpp.

{
  NS_ENSURE_ARG_POINTER(aResult && aPosition);

  *aResult = nsnull;
  *aPosition = 0;

  nsCOMPtr<nsIEditor> editor(do_QueryInterface(aClosure));
  if (editor) { // revised according to nsTextControlFrame::OffsetToDOMPoint
    nsCOMPtr<nsIDOMElement> rootElement;
    editor->GetRootElement(getter_AddRefs(rootElement));
    nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement));

    NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);

    nsCOMPtr<nsIDOMNodeList> nodeList;

    nsresult rv = rootNode->GetChildNodes(getter_AddRefs(nodeList));
    NS_ENSURE_SUCCESS(rv, rv);
    NS_ENSURE_TRUE(nodeList, NS_ERROR_FAILURE);

    PRUint32 length = 0;

    rv = nodeList->GetLength(&length);
    NS_ENSURE_SUCCESS(rv, rv);

    if (!length || aOffset < 0) {
      *aPosition = 0;
      *aResult = rootNode;
      NS_ADDREF(*aResult);
      return NS_OK;
    }

    PRInt32 textOffset = 0;
    PRUint32 lastIndex = length - 1;

    for (PRUint32 i=0; i<length; i++) {
      nsCOMPtr<nsIDOMNode> item;
      rv = nodeList->Item(i, getter_AddRefs(item));
      NS_ENSURE_SUCCESS(rv, rv);
      NS_ENSURE_TRUE(item, NS_ERROR_FAILURE);

      nsCOMPtr<nsIDOMText> domText(do_QueryInterface(item));

      if (domText) {
        PRUint32 textLength = 0;

        rv = domText->GetLength(&textLength);
        NS_ENSURE_SUCCESS(rv, rv);

        // Check if aOffset falls within this range.
        if (aOffset >= textOffset && aOffset <= textOffset+(PRInt32)textLength) {
          *aPosition = aOffset - textOffset;
          *aResult = item;
          NS_ADDREF(*aResult);
          return NS_OK;
        }

        textOffset += textLength;

        // If there aren't any more siblings after this text node,
        // return the point at the end of this text node!

        if (i == lastIndex) {
          *aPosition = textLength;
          *aResult = item;
          NS_ADDREF(*aResult);
          return NS_OK;
        }
      }
      else {
        // Must be a BR node, count it as a newline.

        if (aOffset == textOffset || i == lastIndex) {
          // We've found the correct position, or aOffset takes us
          // beyond the last child under rootNode, just return the point
          // under rootNode that is in front of this br.

          *aPosition = i;
          *aResult = rootNode;
          NS_ADDREF(*aResult);
          return NS_OK;
        }

        ++textOffset;
      }
    }
  }

  return NS_ERROR_FAILURE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIAccessibleEditableText::pasteText ( in long  position) [inherited]
void nsIAccessibleText::removeSelection ( in long  selectionNum) [inherited]
void nsIAccessibleEditableText::setAttributes ( in long  startPos,
in long  endPos,
in nsISupports  attributes 
) [inherited]

Set font styles, such as italic, bold...

Definition at line 1144 of file nsAccessibleText.cpp.

{
  return SetSelectionRange(aCaretOffset, aCaretOffset);
}

Here is the call graph for this function:

nsIAccessibleText helpers

Definition at line 928 of file nsAccessibleText.cpp.

{
  mPlainEditor = aEditor;
  if (mPlainEditor)
    mPlainEditor->AddEditActionListener(this);
}

Here is the caller graph for this function:

void nsIAccessibleText::setSelectionBounds ( in long  selectionNum,
in long  startOffset,
in long  endOffset 
) [inherited]
nsresult nsAccessibleEditableText::SetSelectionRange ( PRInt32  aStartPos,
PRInt32  aEndPos 
) [protected]

Definition at line 1068 of file nsAccessibleText.cpp.

{
  nsITextControlFrame *textFrame = GetTextFrame();
  if (textFrame) {
    return textFrame->SetSelectionRange(aStartPos, aEndPos);
  }
  else {
    // editor, revised according to nsTextControlFrame::SetSelectionRange
    NS_ENSURE_TRUE(mPlainEditor, NS_ERROR_FAILURE);
    if (aStartPos > aEndPos)
      return NS_ERROR_FAILURE;

    nsCOMPtr<nsIDOMNode> startNode, endNode;
    PRInt32 startOffset, endOffset;

    nsresult rv = OffsetToDOMPoint(mPlainEditor, aStartPos, getter_AddRefs(startNode), &startOffset);
    NS_ENSURE_SUCCESS(rv, rv);

    if (aStartPos == aEndPos) {
      endNode   = startNode;
      endOffset = startOffset;
    }
    else {
      rv = OffsetToDOMPoint(mPlainEditor, aEndPos, getter_AddRefs(endNode), &endOffset);
      NS_ENSURE_SUCCESS(rv, rv);
    }

    // Create a new range to represent the new selection.
    nsCOMPtr<nsIDOMRange> range = do_CreateInstance(kRangeCID);
    NS_ENSURE_TRUE(range, NS_ERROR_FAILURE);

    rv = range->SetStart(startNode, startOffset);
    NS_ENSURE_SUCCESS(rv, rv);

    rv = range->SetEnd(endNode, endOffset);
    NS_ENSURE_SUCCESS(rv, rv);

    // Get the selection, clear it and add the new range to it!
    nsCOMPtr<nsISelection> selection;
    mPlainEditor->GetSelection(getter_AddRefs(selection));
    NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);

    rv = selection->RemoveAllRanges();
    NS_ENSURE_SUCCESS(rv, rv);

    return selection->AddRange(range);
  }

  return NS_OK;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void nsIAccessibleEditableText::setTextContents ( in AString  text) [inherited]

Definition at line 916 of file nsAccessibleText.cpp.

{
  if (mPlainEditor) {
    mPlainEditor->RemoveEditActionListener(this);
    mPlainEditor = nsnull;
  }
}

Here is the caller graph for this function:

void nsIEditActionListener::WillCreateNode ( in DOMString  aTag,
in nsIDOMNode  aParent,
in long  aPosition 
) [inherited]

Called before the editor creates a node.

Parameters:
aTagThe tag name of the DOM Node to create.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child

Called before the editor deletes a node.

Parameters:
aChildThe node to delete

Called before the editor deletes the selection.

Parameters:
aSelectionThe selection to be deleted

Here is the caller graph for this function:

void nsIEditActionListener::WillDeleteText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in long  aLength 
) [inherited]

Called before the editor deletes text.

Parameters:
aTextNodeThis node getting text deleted
aOffsetThe offset in aTextNode to delete at.
aLengthThe amount of text to delete.

Here is the caller graph for this function:

void nsIEditActionListener::WillInsertNode ( in nsIDOMNode  aNode,
in nsIDOMNode  aParent,
in long  aPosition 
) [inherited]

Called before the editor inserts a node.

Parameters:
aNodeThe DOM Node to insert.
aParentThe node to insert the new object into
aPositionThe place in aParent to insert the new node 0=first child, 1=second child, etc. any number > number of current children = last child
void nsIEditActionListener::WillInsertText ( in nsIDOMCharacterData  aTextNode,
in long  aOffset,
in DOMString  aString 
) [inherited]

Called before the editor inserts text.

Parameters:
aTextNodeThis node getting inserted text
aOffsetThe offset in aTextNode to insert at.
aStringThe string that gets inserted.

Here is the caller graph for this function:

void nsIEditActionListener::WillJoinNodes ( in nsIDOMNode  aLeftNode,
in nsIDOMNode  aRightNode,
in nsIDOMNode  aParent 
) [inherited]

Called before the editor joins 2 nodes.

Parameters:
aLeftNodeThis node will be merged into the right node
aRightNodeThe node that will be merged into. There is no requirement that the two nodes be of the same type.
aParentThe parent of aRightNode
void nsIEditActionListener::WillSplitNode ( in nsIDOMNode  aExistingRightNode,
in long  aOffset 
) [inherited]

Called before the editor splits a node.

Parameters:
aExistingRightNodethe node to split. It will become the new node's next sibling.
aOffsetthe offset of aExistingRightNode's content|children to do the split at
aNewLeftNode[OUT] the new node resulting from the split, becomes aExistingRightNode's previous sibling.

Friends And Related Function Documentation

friend class nsAccessibleHyperText [friend, inherited]

Definition at line 83 of file nsAccessibleText.h.


Member Data Documentation

Definition at line 57 of file nsIAccessibleText.idl.

Definition at line 50 of file nsIAccessibleText.idl.

Definition at line 56 of file nsIAccessibleText.idl.

Definition at line 55 of file nsIAccessibleText.idl.

Definition at line 54 of file nsIAccessibleText.idl.

Definition at line 53 of file nsIAccessibleText.idl.

Definition at line 52 of file nsIAccessibleText.idl.

Definition at line 51 of file nsIAccessibleText.idl.

Definition at line 62 of file nsIAccessibleText.idl.

Definition at line 64 of file nsIAccessibleText.idl.

Definition at line 59 of file nsIAccessibleText.idl.

Definition at line 60 of file nsIAccessibleText.idl.

Definition at line 63 of file nsAccessibleText.h.

Definition at line 124 of file nsAccessibleText.h.

Definition at line 68 of file nsAccessibleText.h.

Definition at line 65 of file nsIAccessibleText.idl.


The documentation for this class was generated from the following files: