NS_IMETHODIMP mozSpellChecker::NextMisspelledWord(nsAString &aWord, nsTArray<nsString> *aSuggestions) { if(!aSuggestions||!mConverter) return NS_ERROR_NULL_POINTER; int32_t selOffset; int32_t begin,end; nsresult result; result = SetupDoc(&selOffset); bool isMisspelled,done; if (NS_FAILED(result)) return result; while( NS_SUCCEEDED(mTsDoc->IsDone(&done)) && !done ) { nsString str; result = mTsDoc->GetCurrentTextBlock(&str); if (NS_FAILED(result)) return result; do{ result = mConverter->FindNextWord(str.get(),str.Length(),selOffset,&begin,&end); if(NS_SUCCEEDED(result)&&(begin != -1)){ const nsAString &currWord = Substring(str, begin, end - begin); result = CheckWord(currWord, &isMisspelled, aSuggestions); if(isMisspelled){ aWord = currWord; mTsDoc->SetSelection(begin, end-begin); // After ScrollSelectionIntoView(), the pending notifications might // be flushed and PresShell/PresContext/Frames may be dead. // See bug 418470. mTsDoc->ScrollSelectionIntoView(); return NS_OK; } } selOffset = end; }while(end != -1); mTsDoc->NextBlock(); selOffset=0; } return NS_OK; }
nsresult nsTextControlFrame::SelectAllOrCollapseToEndOfText(PRBool aSelect) { nsCOMPtr<nsIDOMElement> rootElement; nsresult rv = GetRootNodeAndInitializeEditor(getter_AddRefs(rootElement)); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIContent> rootContent = do_QueryInterface(rootElement); nsCOMPtr<nsIDOMNode> rootNode(do_QueryInterface(rootElement)); NS_ENSURE_TRUE(rootNode && rootContent, NS_ERROR_FAILURE); PRInt32 numChildren = rootContent->GetChildCount(); if (numChildren > 0) { // We never want to place the selection after the last // br under the root node! nsIContent *child = rootContent->GetChildAt(numChildren - 1); if (child) { if (child->Tag() == nsGkAtoms::br) --numChildren; } if (!aSelect && numChildren) { child = rootContent->GetChildAt(numChildren - 1); if (child && child->IsNodeOfType(nsINode::eTEXT)) { rootNode = do_QueryInterface(child); const nsTextFragment* fragment = child->GetText(); numChildren = fragment ? fragment->GetLength() : 0; } } } rv = SetSelectionInternal(rootNode, aSelect ? 0 : numChildren, rootNode, numChildren); NS_ENSURE_SUCCESS(rv, rv); return ScrollSelectionIntoView(); }