Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(708)

Unified Diff: Source/core/editing/SpellChecker.cpp

Issue 517043003: Move Frame to the Oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Back out non-Oilpan experiment + tidy up by adding frame() ref accessors Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: Source/core/editing/SpellChecker.cpp
diff --git a/Source/core/editing/SpellChecker.cpp b/Source/core/editing/SpellChecker.cpp
index 9f3e8ddf11666e84a6227d13fce09400cd0ac87f..7bf2259219b734d486899eaeea042d4df9c5776a 100644
--- a/Source/core/editing/SpellChecker.cpp
+++ b/Source/core/editing/SpellChecker.cpp
@@ -71,9 +71,9 @@ bool isSelectionInTextFormControl(const VisibleSelection& selection)
} // namespace
-PassOwnPtr<SpellChecker> SpellChecker::create(LocalFrame& frame)
+PassOwnPtrWillBeRawPtr<SpellChecker> SpellChecker::create(LocalFrame& frame)
{
- return adoptPtr(new SpellChecker(frame));
+ return adoptPtrWillBeNoop(new SpellChecker(frame));
}
static SpellCheckerClient& emptySpellCheckerClient()
@@ -84,7 +84,7 @@ static SpellCheckerClient& emptySpellCheckerClient()
SpellCheckerClient& SpellChecker::spellCheckerClient() const
{
- if (Page* page = m_frame.page())
+ if (Page* page = frame().page())
return page->spellCheckerClient();
return emptySpellCheckerClient();
}
@@ -95,8 +95,8 @@ TextCheckerClient& SpellChecker::textChecker() const
}
SpellChecker::SpellChecker(LocalFrame& frame)
- : m_frame(frame)
- , m_spellCheckRequester(adoptPtr(new SpellCheckRequester(frame)))
+ : m_frame(&frame)
+ , m_spellCheckRequester(SpellCheckRequester::create(frame))
{
}
@@ -114,7 +114,7 @@ void SpellChecker::toggleContinuousSpellChecking()
spellCheckerClient().toggleContinuousSpellChecking();
if (isContinuousSpellCheckingEnabled())
return;
- for (Frame* frame = m_frame.page()->mainFrame(); frame; frame = frame->tree().traverseNext()) {
+ for (Frame* frame = this->frame().page()->mainFrame(); frame; frame = frame->tree().traverseNext()) {
if (!frame->isLocalFrame())
continue;
for (Node* node = &toLocalFrame(frame)->document()->rootNode(); node; node = NodeTraversal::next(*node)) {
@@ -156,8 +156,8 @@ void SpellChecker::didBeginEditing(Element* element)
void SpellChecker::ignoreSpelling()
{
- if (RefPtrWillBeRawPtr<Range> selectedRange = m_frame.selection().toNormalizedRange())
- m_frame.document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::Spelling);
+ if (RefPtrWillBeRawPtr<Range> selectedRange = frame().selection().toNormalizedRange())
+ frame().document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::Spelling);
}
void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
@@ -167,9 +167,9 @@ void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
// Start at the end of the selection, search to edge of document. Starting at the selection end makes
// repeated "check spelling" commands work.
- VisibleSelection selection(m_frame.selection().selection());
+ VisibleSelection selection(frame().selection().selection());
Position spellingSearchStart, spellingSearchEnd;
- Range::selectNodeContents(m_frame.document(), spellingSearchStart, spellingSearchEnd);
+ Range::selectNodeContents(frame().document(), spellingSearchStart, spellingSearchEnd);
bool startedWithSelection = false;
if (selection.start().deprecatedNode()) {
@@ -192,7 +192,7 @@ void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
// when spell checking the whole document before sending the message.
// In that case the document might not be editable, but there are editable pockets that need to be spell checked.
- position = firstEditableVisiblePositionAfterPositionInRoot(position, m_frame.document()->documentElement()).deepEquivalent();
+ position = firstEditableVisiblePositionAfterPositionInRoot(position, frame().document()->documentElement()).deepEquivalent();
if (position.isNull())
return;
@@ -306,10 +306,10 @@ void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
Position badGrammarStart = grammarSearchStart;
Position badGrammarEnd = grammarSearchEnd;
TextIterator::subrange(badGrammarStart, badGrammarEnd, grammarPhraseOffset + grammarDetail.location, grammarDetail.length);
- m_frame.selection().setSelection(VisibleSelection(badGrammarStart, badGrammarEnd));
- m_frame.selection().revealSelection();
+ frame().selection().setSelection(VisibleSelection(badGrammarStart, badGrammarEnd));
+ frame().selection().revealSelection();
- m_frame.document()->markers().addMarker(badGrammarStart, badGrammarEnd, DocumentMarker::Grammar, grammarDetail.userDescription);
+ frame().document()->markers().addMarker(badGrammarStart, badGrammarEnd, DocumentMarker::Grammar, grammarDetail.userDescription);
} else if (!misspelledWord.isEmpty()) {
// We found a misspelling, but not any earlier bad grammar. Select the misspelling, update the spelling panel, and store
// a marker so we draw the red squiggle later.
@@ -317,11 +317,11 @@ void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
Position misspellingStart = spellingSearchStart;
Position misspellingEnd = spellingSearchEnd;
TextIterator::subrange(misspellingStart, misspellingEnd, misspellingOffset, misspelledWord.length());
- m_frame.selection().setSelection(VisibleSelection(misspellingStart, misspellingEnd, DOWNSTREAM));
- m_frame.selection().revealSelection();
+ frame().selection().setSelection(VisibleSelection(misspellingStart, misspellingEnd, DOWNSTREAM));
+ frame().selection().revealSelection();
spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord);
- m_frame.document()->markers().addMarker(misspellingStart, misspellingEnd, DocumentMarker::Spelling);
+ frame().document()->markers().addMarker(misspellingStart, misspellingEnd, DocumentMarker::Spelling);
}
}
@@ -340,7 +340,7 @@ void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving
{
RefPtrWillBeRawPtr<Range> selectedRange = movingSelection.toNormalizedRange();
if (selectedRange)
- m_frame.document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::MisspellingMarkers());
+ frame().document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::MisspellingMarkers());
}
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection &movingSelection)
@@ -414,15 +414,15 @@ void SpellChecker::markMisspellingsAfterTypingToWord(const VisiblePosition &word
// If autocorrected word is non empty, replace the misspelled word by this word.
if (!autocorrectedString.isEmpty()) {
VisibleSelection newSelection(misspellingRange.get(), DOWNSTREAM);
- if (newSelection != m_frame.selection().selection()) {
- m_frame.selection().setSelection(newSelection);
+ if (newSelection != frame().selection().selection()) {
+ frame().selection().setSelection(newSelection);
}
- m_frame.editor().replaceSelectionWithText(autocorrectedString, false, false);
+ frame().editor().replaceSelectionWithText(autocorrectedString, false, false);
// Reset the charet one character further.
- m_frame.selection().moveTo(m_frame.selection().selection().visibleEnd());
- m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
+ frame().selection().moveTo(frame().selection().selection().visibleEnd());
+ frame().selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
}
if (!isGrammarCheckingEnabled())
@@ -473,7 +473,7 @@ bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const
bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const
{
- return isSpellCheckingEnabledFor(m_frame.selection().start().deprecatedNode());
+ return isSpellCheckingEnabledFor(frame().selection().start().deprecatedNode());
}
void SpellChecker::markMisspellings(const VisibleSelection& selection, RefPtrWillBeRawPtr<Range>& firstMisspellingRange)
@@ -508,7 +508,7 @@ void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
- bool asynchronous = m_frame.settings() && m_frame.settings()->asynchronousSpellCheckingEnabled();
+ bool asynchronous = frame().settings() && frame().settings()->asynchronousSpellCheckingEnabled();
chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphToCheck, asynchronous);
}
@@ -516,7 +516,7 @@ void SpellChecker::chunkAndMarkAllMisspellingsAndBadGrammar(Node* node)
{
if (!node)
return;
- RefPtrWillBeRawPtr<Range> rangeToCheck = Range::create(*m_frame.document(), firstPositionInNode(node), lastPositionInNode(node));
+ RefPtrWillBeRawPtr<Range> rangeToCheck = Range::create(*frame().document(), firstPositionInNode(node), lastPositionInNode(node));
TextCheckingParagraph textToCheck(rangeToCheck, rangeToCheck);
bool asynchronous = true;
chunkAndMarkAllMisspellingsAndBadGrammar(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), textToCheck, asynchronous);
@@ -558,7 +558,7 @@ void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
if (checkingLength)
*checkingLength = sentenceToCheck.checkingLength();
- RefPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, requestNumber);
+ RefPtrWillBeRawPtr<SpellCheckRequest> request = SpellCheckRequest::create(resolveTextCheckingTypeMask(textCheckingOptions), TextCheckingProcessBatch, checkRange, paragraphRange, requestNumber);
if (asynchronous) {
m_spellCheckRequester->requestCheckingFor(request);
@@ -569,7 +569,7 @@ void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
}
}
-void SpellChecker::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
+void SpellChecker::markAndReplaceFor(PassRefPtrWillBeRawPtr<SpellCheckRequest> request, const Vector<TextCheckingResult>& results)
{
ASSERT(request);
@@ -587,9 +587,9 @@ void SpellChecker::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, cons
bool adjustSelectionForParagraphBoundaries = false;
if (shouldMarkSpelling) {
- if (m_frame.selection().isCaret()) {
+ if (frame().selection().isCaret()) {
// Attempt to save the caret position so we can restore it later if needed
- Position caretPosition = m_frame.selection().end();
+ Position caretPosition = frame().selection().end();
selectionOffset = paragraph.offsetTo(caretPosition, ASSERT_NO_EXCEPTION);
restoreSelectionAfterChange = true;
if (selectionOffset > 0 && (static_cast<unsigned>(selectionOffset) > paragraph.text().length() || paragraph.textCharAt(selectionOffset - 1) == newlineCharacter))
@@ -638,13 +638,13 @@ void SpellChecker::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, cons
extendedParagraph.expandRangeToNextEnd();
if (restoreSelectionAfterChange && selectionOffset >= 0 && selectionOffset <= extendedParagraph.rangeLength()) {
RefPtrWillBeRawPtr<Range> selectionRange = extendedParagraph.subrange(0, selectionOffset);
- m_frame.selection().moveTo(selectionRange->endPosition(), DOWNSTREAM);
+ frame().selection().moveTo(selectionRange->endPosition(), DOWNSTREAM);
if (adjustSelectionForParagraphBoundaries)
- m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
+ frame().selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
} else {
// If this fails for any reason, the fallback is to go one position beyond the last replacement
- m_frame.selection().moveTo(m_frame.selection().selection().visibleEnd());
- m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
+ frame().selection().moveTo(frame().selection().selection().visibleEnd());
+ frame().selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
}
}
}
@@ -684,8 +684,8 @@ void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele
// Of course, if current selection is a range, we potentially will edit two words that fall on the boundaries of
// selection, and remove words between the selection boundaries.
//
- VisiblePosition startOfSelection = m_frame.selection().selection().visibleStart();
- VisiblePosition endOfSelection = m_frame.selection().selection().visibleEnd();
+ VisiblePosition startOfSelection = frame().selection().selection().visibleStart();
+ VisiblePosition endOfSelection = frame().selection().selection().visibleEnd();
if (startOfSelection.isNull())
return;
// First word is the word that ends after or on the start of selection.
@@ -732,7 +732,7 @@ void SpellChecker::updateMarkersForWordsAffectedByEditing(bool doNotRemoveIfSele
// garde", we will have CorrectionIndicator marker on both words and on the whitespace between them. If we then edit garde,
// we would like to remove the marker from word "avant" and whitespace as well. So we need to get the continous range of
// of marker that contains the word in question, and remove marker on that whole range.
- Document* document = m_frame.document();
+ Document* document = frame().document();
ASSERT(document);
RefPtrWillBeRawPtr<Range> wordRange = Range::create(*document, startOfFirstWord.deepEquivalent(), endOfLastWord.deepEquivalent());
document->markers().removeMarkers(wordRange.get(), DocumentMarker::MisspellingMarkers(), DocumentMarkerController::RemovePartiallyOverlappingMarker);
@@ -749,23 +749,23 @@ void SpellChecker::didEndEditingOnTextField(Element* e)
if (isGrammarCheckingEnabled() || unifiedTextCheckerEnabled())
markerTypes.add(DocumentMarker::Grammar);
for (Node* node = innerEditor; node; node = NodeTraversal::next(*node, innerEditor)) {
- m_frame.document()->markers().removeMarkers(node, markerTypes);
+ frame().document()->markers().removeMarkers(node, markerTypes);
}
}
void SpellChecker::replaceMisspelledRange(const String& text)
{
- RefPtrWillBeRawPtr<Range> caretRange = m_frame.selection().toNormalizedRange();
+ RefPtrWillBeRawPtr<Range> caretRange = frame().selection().toNormalizedRange();
if (!caretRange)
return;
- DocumentMarkerVector markers = m_frame.document()->markers().markersInRange(caretRange.get(), DocumentMarker::MisspellingMarkers());
+ DocumentMarkerVector markers = frame().document()->markers().markersInRange(caretRange.get(), DocumentMarker::MisspellingMarkers());
if (markers.size() < 1 || markers[0]->startOffset() >= markers[0]->endOffset())
return;
RefPtrWillBeRawPtr<Range> markerRange = Range::create(caretRange->ownerDocument(), caretRange->startContainer(), markers[0]->startOffset(), caretRange->endContainer(), markers[0]->endOffset());
if (!markerRange)
return;
- m_frame.selection().setSelection(VisibleSelection(markerRange.get()), CharacterGranularity);
- m_frame.editor().replaceSelectionWithText(text, false, false);
+ frame().selection().setSelection(VisibleSelection(markerRange.get()), CharacterGranularity);
+ frame().editor().replaceSelectionWithText(text, false, false);
}
void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions options)
@@ -776,8 +776,8 @@ void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
if (isContinuousSpellCheckingEnabled) {
VisibleSelection newAdjacentWords;
VisibleSelection newSelectedSentence;
- bool caretBrowsing = m_frame.settings() && m_frame.settings()->caretBrowsingEnabled();
- const VisibleSelection newSelection = m_frame.selection().selection();
+ bool caretBrowsing = frame().settings() && frame().settings()->caretBrowsingEnabled();
+ const VisibleSelection newSelection = frame().selection().selection();
if (isSelectionInTextFormControl(newSelection)) {
Position newStart = newSelection.start();
newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
@@ -812,48 +812,48 @@ void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelectio
if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTypeSpelling)) {
Position start, end;
if (newAdjacentWords.toNormalizedPositions(start, end))
- m_frame.document()->markers().removeMarkers(start, end, DocumentMarker::Spelling);
+ frame().document()->markers().removeMarkers(start, end, DocumentMarker::Spelling);
}
if (textChecker().shouldEraseMarkersAfterChangeSelection(TextCheckingTypeGrammar)) {
Position start, end;
if (newSelectedSentence.toNormalizedPositions(start, end))
- m_frame.document()->markers().removeMarkers(start, end, DocumentMarker::Grammar);
+ frame().document()->markers().removeMarkers(start, end, DocumentMarker::Grammar);
}
}
// When continuous spell checking is off, existing markers disappear after the selection changes.
if (!isContinuousSpellCheckingEnabled)
- m_frame.document()->markers().removeMarkers(DocumentMarker::Spelling);
+ frame().document()->markers().removeMarkers(DocumentMarker::Spelling);
if (!isContinuousGrammarCheckingEnabled)
- m_frame.document()->markers().removeMarkers(DocumentMarker::Grammar);
+ frame().document()->markers().removeMarkers(DocumentMarker::Grammar);
}
void SpellChecker::removeSpellingMarkers()
{
- m_frame.document()->markers().removeMarkers(DocumentMarker::MisspellingMarkers());
+ frame().document()->markers().removeMarkers(DocumentMarker::MisspellingMarkers());
}
void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words)
{
MarkerRemoverPredicate removerPredicate(words);
- DocumentMarkerController& markerController = m_frame.document()->markers();
+ DocumentMarkerController& markerController = frame().document()->markers();
markerController.removeMarkers(removerPredicate);
markerController.repaintMarkers();
}
void SpellChecker::spellCheckAfterBlur()
{
- if (!m_frame.selection().selection().isContentEditable())
+ if (!frame().selection().selection().isContentEditable())
return;
- if (isSelectionInTextField(m_frame.selection().selection())) {
+ if (isSelectionInTextField(frame().selection().selection())) {
// textFieldDidEndEditing() and textFieldDidBeginEditing() handle this.
return;
}
VisibleSelection empty;
- spellCheckOldSelection(m_frame.selection().selection(), empty);
+ spellCheckOldSelection(frame().selection().selection(), empty);
}
void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords)
@@ -890,13 +890,13 @@ static Node* findFirstMarkable(Node* node)
bool SpellChecker::selectionStartHasMarkerFor(DocumentMarker::MarkerType markerType, int from, int length) const
{
- Node* node = findFirstMarkable(m_frame.selection().start().deprecatedNode());
+ Node* node = findFirstMarkable(frame().selection().start().deprecatedNode());
if (!node)
return false;
unsigned startOffset = static_cast<unsigned>(from);
unsigned endOffset = static_cast<unsigned>(from + length);
- DocumentMarkerVector markers = m_frame.document()->markers().markersFor(node);
+ DocumentMarkerVector markers = frame().document()->markers().markersFor(node);
for (size_t i = 0; i < markers.size(); ++i) {
DocumentMarker* marker = markers[i];
if (marker->startOffset() <= startOffset && endOffset <= marker->endOffset() && marker->type() == markerType)
@@ -927,7 +927,7 @@ TextCheckingTypeMask SpellChecker::resolveTextCheckingTypeMask(TextCheckingTypeM
bool SpellChecker::unifiedTextCheckerEnabled() const
{
- return blink::unifiedTextCheckerEnabled(&m_frame);
+ return blink::unifiedTextCheckerEnabled(m_frame);
}
void SpellChecker::cancelCheck()
@@ -941,5 +941,10 @@ void SpellChecker::requestTextChecking(const Element& element)
m_spellCheckRequester->requestCheckingFor(SpellCheckRequest::create(TextCheckingTypeSpelling | TextCheckingTypeGrammar, TextCheckingProcessBatch, rangeToCheck, rangeToCheck));
}
+void SpellChecker::trace(Visitor* visitor)
+{
+ visitor->trace(m_frame);
+ visitor->trace(m_spellCheckRequester);
+}
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698