nsresult nsCoreUtils::ScrollSubstringTo(nsIFrame* aFrame, nsRange* aRange, nsIPresShell::ScrollAxis aVertical, nsIPresShell::ScrollAxis aHorizontal) { if (!aFrame) return NS_ERROR_FAILURE; nsPresContext *presContext = aFrame->PresContext(); nsCOMPtr<nsISelectionController> selCon; aFrame->GetSelectionController(presContext, getter_AddRefs(selCon)); NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE); nsCOMPtr<nsISelection> selection; selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY, getter_AddRefs(selection)); nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(selection)); selection->RemoveAllRanges(); selection->AddRange(aRange); privSel->ScrollIntoViewInternal( nsISelectionController::SELECTION_ANCHOR_REGION, true, aVertical, aHorizontal); selection->CollapseToStart(); return NS_OK; }
nsresult nsCoreUtils::ScrollSubstringTo(nsIFrame *aFrame, nsIDOMNode *aStartNode, PRInt32 aStartIndex, nsIDOMNode *aEndNode, PRInt32 aEndIndex, PRInt16 aVPercent, PRInt16 aHPercent) { if (!aFrame || !aStartNode || !aEndNode) return NS_ERROR_FAILURE; nsPresContext *presContext = aFrame->PresContext(); nsRefPtr<nsIDOMRange> scrollToRange = new nsRange(); nsCOMPtr<nsISelectionController> selCon; aFrame->GetSelectionController(presContext, getter_AddRefs(selCon)); NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE); scrollToRange->SetStart(aStartNode, aStartIndex); scrollToRange->SetEnd(aEndNode, aEndIndex); nsCOMPtr<nsISelection> selection; selCon->GetSelection(nsISelectionController::SELECTION_ACCESSIBILITY, getter_AddRefs(selection)); nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(selection)); selection->RemoveAllRanges(); selection->AddRange(scrollToRange); privSel->ScrollIntoView(nsISelectionController::SELECTION_ANCHOR_REGION, true, aVPercent, aHPercent); selection->CollapseToStart(); return NS_OK; }
void nsCaretAccessible::ProcessSelectionChanged(nsISelection* aSelection) { nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(aSelection)); PRInt16 type = 0; privSel->GetType(&type); if (type == nsISelectionController::SELECTION_NORMAL) NormalSelectionChanged(aSelection); else if (type == nsISelectionController::SELECTION_SPELLCHECK) SpellcheckSelectionChanged(aSelection); }
NS_IMETHODIMP nsCaretAccessible::NotifySelectionChanged(nsIDOMDocument* aDOMDocument, nsISelection* aSelection, PRInt16 aReason) { NS_ENSURE_ARG(aDOMDocument); NS_ENSURE_STATE(mRootAccessible); nsCOMPtr<nsIDocument> documentNode(do_QueryInterface(aDOMDocument)); nsDocAccessible* document = GetAccService()->GetDocAccessible(documentNode); #ifdef DEBUG_NOTIFICATIONS nsCOMPtr<nsISelectionPrivate> privSel(do_QueryInterface(aSelection)); PRInt16 type = 0; privSel->GetType(&type); if (type == nsISelectionController::SELECTION_NORMAL || type == nsISelectionController::SELECTION_SPELLCHECK) { bool isNormalSelection = (type == nsISelectionController::SELECTION_NORMAL); bool isIgnored = !document || !document->IsContentLoaded(); printf("\nSelection changed, selection type: %s, notification %s\n", (isNormalSelection ? "normal" : "spellcheck"), (isIgnored ? "ignored" : "pending")); } else { bool isIgnored = !document || !document->IsContentLoaded(); printf("\nSelection changed, selection type: unknown, notification %s\n", (isIgnored ? "ignored" : "pending")); } #endif // Don't fire events until document is loaded. if (document && document->IsContentLoaded()) { // The caret accessible has the same lifetime as the root accessible, and // this outlives all its descendant document accessibles, so that we are // guaranteed that the notification is processed before the caret accessible // is destroyed. document->HandleNotification<nsCaretAccessible, nsISelection> (this, &nsCaretAccessible::ProcessSelectionChanged, aSelection); } return NS_OK; }