- Revision
- 100890
- Author
- [email protected]
- Date
- 2011-11-21 01:20:57 -0800 (Mon, 21 Nov 2011)
Log Message
Refactoring: SpellChecker::requestCheckingFor should take Range instead of Node.
https://bugs.webkit.org/show_bug.cgi?id=72847
Patch by Shinya Kawanaka <[email protected]> on 2011-11-21
Reviewed by Hajime Morita.
Covered by existing test.
* editing/Editor.cpp:
(WebCore::Editor::replaceSelectionWithFragment):
Passes Range to requestCheckingFor instead of Node.
* editing/SpellChecker.cpp:
Changed argument type from Node to Range.
The corresponding changes are also done in dependent methods.
(WebCore::SpellChecker::initRequest):
(WebCore::SpellChecker::clearRequest):
(WebCore::SpellChecker::canCheckAsynchronously):
(WebCore::SpellChecker::isBusy):
(WebCore::SpellChecker::isValid):
(WebCore::SpellChecker::isCheckable):
(WebCore::SpellChecker::requestCheckingFor):
Changed argument type from Node to Range.
(WebCore::SpellChecker::doRequestCheckingFor):
(WebCore::SpellChecker::didCheck):
* editing/SpellChecker.h:
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (100889 => 100890)
--- trunk/Source/WebCore/ChangeLog 2011-11-21 09:12:09 UTC (rev 100889)
+++ trunk/Source/WebCore/ChangeLog 2011-11-21 09:20:57 UTC (rev 100890)
@@ -1,3 +1,30 @@
+2011-11-21 Shinya Kawanaka <[email protected]>
+
+ Refactoring: SpellChecker::requestCheckingFor should take Range instead of Node.
+ https://bugs.webkit.org/show_bug.cgi?id=72847
+
+ Reviewed by Hajime Morita.
+
+ Covered by existing test.
+
+ * editing/Editor.cpp:
+ (WebCore::Editor::replaceSelectionWithFragment):
+ Passes Range to requestCheckingFor instead of Node.
+ * editing/SpellChecker.cpp:
+ Changed argument type from Node to Range.
+ The corresponding changes are also done in dependent methods.
+ (WebCore::SpellChecker::initRequest):
+ (WebCore::SpellChecker::clearRequest):
+ (WebCore::SpellChecker::canCheckAsynchronously):
+ (WebCore::SpellChecker::isBusy):
+ (WebCore::SpellChecker::isValid):
+ (WebCore::SpellChecker::isCheckable):
+ (WebCore::SpellChecker::requestCheckingFor):
+ Changed argument type from Node to Range.
+ (WebCore::SpellChecker::doRequestCheckingFor):
+ (WebCore::SpellChecker::didCheck):
+ * editing/SpellChecker.h:
+
2011-11-20 Kenichi Ishibashi <[email protected]>
[Chromium] Remove old getFontFamilyForCharacters() and familyForChars() APIs.
Modified: trunk/Source/WebCore/editing/Editor.cpp (100889 => 100890)
--- trunk/Source/WebCore/editing/Editor.cpp 2011-11-21 09:12:09 UTC (rev 100889)
+++ trunk/Source/WebCore/editing/Editor.cpp 2011-11-21 09:20:57 UTC (rev 100890)
@@ -413,8 +413,11 @@
revealSelectionAfterEditingOperation();
Node* nodeToCheck = m_frame->selection()->rootEditableElement();
- if (m_spellChecker->canCheckAsynchronously(nodeToCheck))
- m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), nodeToCheck);
+ if (!nodeToCheck)
+ return;
+
+ m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar),
+ Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck)));
}
void Editor::replaceSelectionWithText(const String& text, bool selectReplacement, bool smartReplace)
Modified: trunk/Source/WebCore/editing/SpellChecker.cpp (100889 => 100890)
--- trunk/Source/WebCore/editing/SpellChecker.cpp 2011-11-21 09:12:09 UTC (rev 100889)
+++ trunk/Source/WebCore/editing/SpellChecker.cpp 2011-11-21 09:20:57 UTC (rev 100890)
@@ -39,6 +39,7 @@
#include "RenderObject.h"
#include "Settings.h"
#include "TextCheckerClient.h"
+#include "TextCheckingHelper.h"
#include "TextIterator.h"
#include "htmlediting.h"
@@ -62,15 +63,15 @@
return page->editorClient()->textChecker();
}
-bool SpellChecker::initRequest(Node* node)
+bool SpellChecker::initRequest(PassRefPtr<Range> range)
{
- ASSERT(canCheckAsynchronously(node));
+ ASSERT(canCheckAsynchronously(range.get()));
- String text = node->textContent();
+ String text = range->text();
if (!text.length())
return false;
- m_requestNode = node;
+ m_requestRange = range;
m_requestText = text;
m_requestSequence++;
@@ -79,7 +80,7 @@
void SpellChecker::clearRequest()
{
- m_requestNode.clear();
+ m_requestRange.clear();
m_requestText = String();
}
@@ -88,31 +89,39 @@
return m_frame->settings() && m_frame->settings()->asynchronousSpellCheckingEnabled();
}
-bool SpellChecker::canCheckAsynchronously(Node* node) const
+bool SpellChecker::canCheckAsynchronously(Range* range) const
{
- return client() && isCheckable(node) && isAsynchronousEnabled() && !isBusy();
+ return client() && isCheckable(range) && isAsynchronousEnabled() && !isBusy();
}
bool SpellChecker::isBusy() const
{
- return m_requestNode.get();
+ return m_requestRange.get();
}
bool SpellChecker::isValid(int sequence) const
{
- return m_requestNode.get() && m_requestText.length() && m_requestSequence == sequence;
+ return m_requestRange.get() && m_requestText.length() && m_requestSequence == sequence;
}
-bool SpellChecker::isCheckable(Node* node) const
+bool SpellChecker::isCheckable(Range* range) const
{
- return node && node->renderer();
+ return range && range->firstNode() && range->firstNode()->renderer();
}
-void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, Node* node)
+void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range)
{
- ASSERT(canCheckAsynchronously(node));
+ if (!canCheckAsynchronously(range.get()))
+ return;
- if (!initRequest(node))
+ doRequestCheckingFor(mask, range);
+}
+
+void SpellChecker::doRequestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range)
+{
+ ASSERT(canCheckAsynchronously(range.get()));
+
+ if (!initRequest(range))
return;
client()->requestCheckingOfString(this, m_requestSequence, mask, m_requestText);
}
@@ -153,13 +162,13 @@
if (!isValid(sequence))
return;
- if (!m_requestNode->renderer()) {
+ if (!isCheckable(m_requestRange.get())) {
clearRequest();
return;
}
int startOffset = 0;
- PositionIterator start = firstPositionInOrBeforeNode(m_requestNode.get());
+ PositionIterator start = m_requestRange->startPosition();
for (size_t i = 0; i < results.size(); ++i) {
if (results[i].type != TextCheckingTypeSpelling && results[i].type != TextCheckingTypeGrammar)
continue;
@@ -177,12 +186,12 @@
// spellings in the background. To avoid adding markers to the words modified by users or
// _javascript_ applications, retrieve the words in the specified region and compare them with
// the original ones.
- RefPtr<Range> range = Range::create(m_requestNode->document(), start, end);
+ RefPtr<Range> range = Range::create(m_requestRange->ownerDocument(), start, end);
// FIXME: Use textContent() compatible string conversion.
String destination = range->text();
String source = m_requestText.substring(results[i].location, results[i].length);
if (destination == source)
- m_requestNode->document()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
+ m_requestRange->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
startOffset = results[i].location;
}
Modified: trunk/Source/WebCore/editing/SpellChecker.h (100889 => 100890)
--- trunk/Source/WebCore/editing/SpellChecker.h 2011-11-21 09:12:09 UTC (rev 100889)
+++ trunk/Source/WebCore/editing/SpellChecker.h 2011-11-21 09:20:57 UTC (rev 100890)
@@ -38,6 +38,7 @@
class Node;
class TextCheckerClient;
struct TextCheckingResult;
+class Range;
class SpellChecker {
WTF_MAKE_NONCOPYABLE(SpellChecker);
@@ -46,21 +47,22 @@
~SpellChecker();
bool isAsynchronousEnabled() const;
- bool canCheckAsynchronously(Node*) const;
+ bool canCheckAsynchronously(Range*) const;
bool isBusy() const;
bool isValid(int sequence) const;
- bool isCheckable(Node*) const;
- void requestCheckingFor(TextCheckingTypeMask, Node*);
+ bool isCheckable(Range*) const;
+ void requestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
void didCheck(int sequence, const Vector<TextCheckingResult>&);
private:
- bool initRequest(Node*);
+ bool initRequest(PassRefPtr<Range>);
void clearRequest();
+ void doRequestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
TextCheckerClient* client() const;
Frame* m_frame;
- RefPtr<Node> m_requestNode;
+ RefPtr<Range> m_requestRange;
String m_requestText;
int m_requestSequence;
};