Logo Search packages:      
Sourcecode: xulrunner version File versions  Download package

nsIContent * nsINode::GetSelectionRootContent ( nsIPresShell *  aPresShell  )  [inherited]

Get the nearest selection root, ie. the node that will be selected if the user does "Select All" while the focus is in this node. Note that if this node is not in an editor, the result comes from the nsFrameSelection that is related to aPresShell, so the result might not be the ancestor of this node.

Definition at line 373 of file nsGenericElement.cpp.

References nsINode::eCONTENT, nsINode::eDOCUMENT, nsINode::GetCurrentDoc(), nsIContent::GetDocument(), nsINode::GetParent(), nsIFrame::GetStateBits(), nsINode::GetTextEditorRootContent(), nsINode::HasFlag(), and nsINode::IsNodeOfType().

{
  NS_ENSURE_TRUE(aPresShell, nsnull);

  if (IsNodeOfType(eDOCUMENT))
    return static_cast<nsIDocument*>(this)->GetRootContent();
  if (!IsNodeOfType(eCONTENT))
    return nsnull;

  nsIFrame* frame =
    aPresShell->GetPrimaryFrameFor(static_cast<nsIContent*>(this));
  if (frame && frame->GetStateBits() & NS_FRAME_INDEPENDENT_SELECTION) {
    // This node should be a descendant of input/textarea editor.
    nsIContent* content = GetTextEditorRootContent();
    if (content)
      return content;
    NS_ERROR("Editor is not found!");
  }

  nsPresContext* presContext = aPresShell->GetPresContext();
  if (presContext) {
    nsIEditor* editor = GetHTMLEditor(presContext);
    if (editor) {
      // This node is in HTML editor.
      nsIDocument* doc = GetCurrentDoc();
      if (!doc || doc->HasFlag(NODE_IS_EDITABLE) || !HasFlag(NODE_IS_EDITABLE))
        return GetEditorRootContent(editor);
      // If the current document is not editable, but current content is
      // editable, we should assume that the child of the nearest non-editable
      // ancestor is selection root.
      nsIContent* content = static_cast<nsIContent*>(this);
      for (nsIContent* parent = GetParent();
           parent && parent->HasFlag(NODE_IS_EDITABLE);
           parent = content->GetParent())
        content = parent;
      return content;
    }
  }

  nsCOMPtr<nsFrameSelection> fs = aPresShell->FrameSelection();
  nsIContent* content = fs->GetLimiter();
  if (content)
    return content;
  content = fs->GetAncestorLimiter();
  if (content)
    return content;
  nsIDocument* doc = aPresShell->GetDocument();
  NS_ENSURE_TRUE(doc, nsnull);
  return doc->GetRootContent();
}


Generated by  Doxygen 1.6.0   Back to index