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

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: Comments + fix fast/events/message-port-gc-closed.html 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 1d869b877be2dd4e79864a9402922adb4f07b887..dd306097ea2c6179e6b552de6d05329cec959cbe 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 = m_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 = m_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 = m_frame->selection().toNormalizedRange())
+ m_frame->document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::Spelling);
}
void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
@@ -167,8 +167,8 @@ 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());
- RefPtrWillBeRawPtr<Range> spellingSearchRange(rangeOfContents(m_frame.document()));
+ VisibleSelection selection(m_frame->selection().selection());
+ RefPtrWillBeRawPtr<Range> spellingSearchRange(rangeOfContents(m_frame->document()));
bool startedWithSelection = false;
if (selection.start().deprecatedNode()) {
@@ -191,7 +191,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, m_frame->document()->documentElement()).deepEquivalent();
if (position.isNull())
return;
@@ -300,20 +300,20 @@ void SpellChecker::advanceToNextMisspelling(bool startBeforeSelection)
// FIXME 4859190: This gets confused with doubled punctuation at the end of a paragraph
RefPtrWillBeRawPtr<Range> badGrammarRange = TextIterator::subrange(grammarSearchRange.get(), grammarPhraseOffset + grammarDetail.location, grammarDetail.length);
- m_frame.selection().setSelection(VisibleSelection(badGrammarRange.get(), SEL_DEFAULT_AFFINITY));
- m_frame.selection().revealSelection();
+ m_frame->selection().setSelection(VisibleSelection(badGrammarRange.get(), SEL_DEFAULT_AFFINITY));
+ m_frame->selection().revealSelection();
- m_frame.document()->markers().addMarker(badGrammarRange.get(), DocumentMarker::Grammar, grammarDetail.userDescription);
+ m_frame->document()->markers().addMarker(badGrammarRange.get(), 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.
RefPtrWillBeRawPtr<Range> misspellingRange = TextIterator::subrange(spellingSearchRange.get(), misspellingOffset, misspelledWord.length());
- m_frame.selection().setSelection(VisibleSelection(misspellingRange.get(), DOWNSTREAM));
- m_frame.selection().revealSelection();
+ m_frame->selection().setSelection(VisibleSelection(misspellingRange.get(), DOWNSTREAM));
+ m_frame->selection().revealSelection();
spellCheckerClient().updateSpellingUIWithMisspelledWord(misspelledWord);
- m_frame.document()->markers().addMarker(misspellingRange.get(), DocumentMarker::Spelling);
+ m_frame->document()->markers().addMarker(misspellingRange.get(), DocumentMarker::Spelling);
}
}
@@ -332,7 +332,7 @@ void SpellChecker::clearMisspellingsAndBadGrammar(const VisibleSelection &moving
{
RefPtrWillBeRawPtr<Range> selectedRange = movingSelection.toNormalizedRange();
if (selectedRange)
- m_frame.document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::MisspellingMarkers());
+ m_frame->document()->markers().removeMarkers(selectedRange.get(), DocumentMarker::MisspellingMarkers());
}
void SpellChecker::markMisspellingsAndBadGrammar(const VisibleSelection &movingSelection)
@@ -406,15 +406,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 != m_frame->selection().selection()) {
+ m_frame->selection().setSelection(newSelection);
}
- m_frame.editor().replaceSelectionWithText(autocorrectedString, false, false);
+ m_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);
+ m_frame->selection().moveTo(m_frame->selection().selection().visibleEnd());
+ m_frame->selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
}
if (!isGrammarCheckingEnabled())
@@ -465,7 +465,7 @@ bool SpellChecker::isSpellCheckingEnabledFor(Node* node) const
bool SpellChecker::isSpellCheckingEnabledInFocusedNode() const
{
- return isSpellCheckingEnabledFor(m_frame.selection().start().deprecatedNode());
+ return isSpellCheckingEnabledFor(m_frame->selection().start().deprecatedNode());
}
void SpellChecker::markMisspellings(const VisibleSelection& selection, RefPtrWillBeRawPtr<Range>& firstMisspellingRange)
@@ -500,7 +500,7 @@ void SpellChecker::markAllMisspellingsAndBadGrammarInRanges(TextCheckingTypeMask
Range* rangeToCheck = shouldMarkGrammar ? grammarRange : spellingRange;
TextCheckingParagraph fullParagraphToCheck(rangeToCheck);
- bool asynchronous = m_frame.settings() && m_frame.settings()->asynchronousSpellCheckingEnabled();
+ bool asynchronous = m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled();
chunkAndMarkAllMisspellingsAndBadGrammar(textCheckingOptions, fullParagraphToCheck, asynchronous);
}
@@ -508,7 +508,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(*m_frame->document(), firstPositionInNode(node), lastPositionInNode(node));
TextCheckingParagraph textToCheck(rangeToCheck, rangeToCheck);
bool asynchronous = true;
chunkAndMarkAllMisspellingsAndBadGrammar(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), textToCheck, asynchronous);
@@ -550,7 +550,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);
@@ -561,7 +561,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);
@@ -579,9 +579,9 @@ void SpellChecker::markAndReplaceFor(PassRefPtr<SpellCheckRequest> request, cons
bool adjustSelectionForParagraphBoundaries = false;
if (shouldMarkSpelling) {
- if (m_frame.selection().isCaret()) {
+ if (m_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 = m_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))
@@ -630,13 +630,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);
+ m_frame->selection().moveTo(selectionRange->endPosition(), DOWNSTREAM);
if (adjustSelectionForParagraphBoundaries)
- m_frame.selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
+ m_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);
+ m_frame->selection().moveTo(m_frame->selection().selection().visibleEnd());
+ m_frame->selection().modify(FrameSelection::AlterationMove, DirectionForward, CharacterGranularity);
}
}
}
@@ -676,8 +676,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 = m_frame->selection().selection().visibleStart();
+ VisiblePosition endOfSelection = m_frame->selection().selection().visibleEnd();
if (startOfSelection.isNull())
return;
// First word is the word that ends after or on the start of selection.
@@ -724,7 +724,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 = m_frame->document();
ASSERT(document);
RefPtrWillBeRawPtr<Range> wordRange = Range::create(*document, startOfFirstWord.deepEquivalent(), endOfLastWord.deepEquivalent());
@@ -742,23 +742,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);
+ m_frame->document()->markers().removeMarkers(node, markerTypes);
}
}
void SpellChecker::replaceMisspelledRange(const String& text)
{
- RefPtrWillBeRawPtr<Range> caretRange = m_frame.selection().toNormalizedRange();
+ RefPtrWillBeRawPtr<Range> caretRange = m_frame->selection().toNormalizedRange();
if (!caretRange)
return;
- DocumentMarkerVector markers = m_frame.document()->markers().markersInRange(caretRange.get(), DocumentMarker::MisspellingMarkers());
+ DocumentMarkerVector markers = m_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);
+ m_frame->selection().setSelection(VisibleSelection(markerRange.get()), CharacterGranularity);
+ m_frame->editor().replaceSelectionWithText(text, false, false);
}
void SpellChecker::respondToChangedSelection(const VisibleSelection& oldSelection, FrameSelection::SetSelectionOptions options)
@@ -769,8 +769,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 = m_frame->settings() && m_frame->settings()->caretBrowsingEnabled();
+ const VisibleSelection newSelection = m_frame->selection().selection();
if (isSelectionInTextFormControl(newSelection)) {
Position newStart = newSelection.start();
newAdjacentWords.setWithoutValidation(HTMLTextFormControlElement::startOfWord(newStart), HTMLTextFormControlElement::endOfWord(newStart));
@@ -805,48 +805,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);
+ m_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);
+ m_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);
+ m_frame->document()->markers().removeMarkers(DocumentMarker::Spelling);
if (!isContinuousGrammarCheckingEnabled)
- m_frame.document()->markers().removeMarkers(DocumentMarker::Grammar);
+ m_frame->document()->markers().removeMarkers(DocumentMarker::Grammar);
}
void SpellChecker::removeSpellingMarkers()
{
- m_frame.document()->markers().removeMarkers(DocumentMarker::MisspellingMarkers());
+ m_frame->document()->markers().removeMarkers(DocumentMarker::MisspellingMarkers());
}
void SpellChecker::removeSpellingMarkersUnderWords(const Vector<String>& words)
{
MarkerRemoverPredicate removerPredicate(words);
- DocumentMarkerController& markerController = m_frame.document()->markers();
+ DocumentMarkerController& markerController = m_frame->document()->markers();
markerController.removeMarkers(removerPredicate);
markerController.repaintMarkers();
}
void SpellChecker::spellCheckAfterBlur()
{
- if (!m_frame.selection().selection().isContentEditable())
+ if (!m_frame->selection().selection().isContentEditable())
return;
- if (isSelectionInTextField(m_frame.selection().selection())) {
+ if (isSelectionInTextField(m_frame->selection().selection())) {
// textFieldDidEndEditing() and textFieldDidBeginEditing() handle this.
return;
}
VisibleSelection empty;
- spellCheckOldSelection(m_frame.selection().selection(), empty);
+ spellCheckOldSelection(m_frame->selection().selection(), empty);
}
void SpellChecker::spellCheckOldSelection(const VisibleSelection& oldSelection, const VisibleSelection& newAdjacentWords)
@@ -883,13 +883,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(m_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 = m_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)
@@ -920,7 +920,7 @@ TextCheckingTypeMask SpellChecker::resolveTextCheckingTypeMask(TextCheckingTypeM
bool SpellChecker::unifiedTextCheckerEnabled() const
{
- return blink::unifiedTextCheckerEnabled(&m_frame);
+ return blink::unifiedTextCheckerEnabled(m_frame);
}
void SpellChecker::cancelCheck()
@@ -934,5 +934,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