Changeset 100890 in webkit


Ignore:
Timestamp:
Nov 21, 2011 1:20:57 AM (12 years ago)
Author:
commit-queue@webkit.org
Message:

Refactoring: SpellChecker::requestCheckingFor should take Range instead of Node.
https://bugs.webkit.org/show_bug.cgi?id=72847

Patch by Shinya Kawanaka <shinyak@google.com> 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:
Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r100886 r100890  
     12011-11-21  Shinya Kawanaka  <shinyak@google.com>
     2
     3        Refactoring: SpellChecker::requestCheckingFor should take Range instead of Node.
     4        https://bugs.webkit.org/show_bug.cgi?id=72847
     5
     6        Reviewed by Hajime Morita.
     7
     8        Covered by existing test.
     9
     10        * editing/Editor.cpp:
     11        (WebCore::Editor::replaceSelectionWithFragment):
     12          Passes Range to requestCheckingFor instead of Node.
     13        * editing/SpellChecker.cpp:
     14          Changed argument type from Node to Range.
     15          The corresponding changes are also done in dependent methods.
     16        (WebCore::SpellChecker::initRequest):
     17        (WebCore::SpellChecker::clearRequest):
     18        (WebCore::SpellChecker::canCheckAsynchronously):
     19        (WebCore::SpellChecker::isBusy):
     20        (WebCore::SpellChecker::isValid):
     21        (WebCore::SpellChecker::isCheckable):
     22        (WebCore::SpellChecker::requestCheckingFor):
     23          Changed argument type from Node to Range.
     24        (WebCore::SpellChecker::doRequestCheckingFor):
     25        (WebCore::SpellChecker::didCheck):
     26        * editing/SpellChecker.h:
     27
    1282011-11-20  Kenichi Ishibashi  <bashi@chromium.org>
    229
  • trunk/Source/WebCore/editing/Editor.cpp

    r100874 r100890  
    414414
    415415    Node* nodeToCheck = m_frame->selection()->rootEditableElement();
    416     if (m_spellChecker->canCheckAsynchronously(nodeToCheck))
    417         m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar), nodeToCheck);
     416    if (!nodeToCheck)
     417        return;
     418
     419    m_spellChecker->requestCheckingFor(resolveTextCheckingTypeMask(TextCheckingTypeSpelling | TextCheckingTypeGrammar),
     420        Range::create(m_frame->document(), firstPositionInNode(nodeToCheck), lastPositionInNode(nodeToCheck)));
    418421}
    419422
  • trunk/Source/WebCore/editing/SpellChecker.cpp

    r95901 r100890  
    4040#include "Settings.h"
    4141#include "TextCheckerClient.h"
     42#include "TextCheckingHelper.h"
    4243#include "TextIterator.h"
    4344#include "htmlediting.h"
     
    6364}
    6465
    65 bool SpellChecker::initRequest(Node* node)
    66 {
    67     ASSERT(canCheckAsynchronously(node));
    68 
    69     String text = node->textContent();
     66bool SpellChecker::initRequest(PassRefPtr<Range> range)
     67{
     68    ASSERT(canCheckAsynchronously(range.get()));
     69
     70    String text = range->text();
    7071    if (!text.length())
    7172        return false;
    7273
    73     m_requestNode = node;
     74    m_requestRange = range;
    7475    m_requestText = text;
    7576    m_requestSequence++;
     
    8081void SpellChecker::clearRequest()
    8182{
    82     m_requestNode.clear();
     83    m_requestRange.clear();
    8384    m_requestText = String();
    8485}
     
    8990}
    9091
    91 bool SpellChecker::canCheckAsynchronously(Node* node) const
    92 {
    93     return client() && isCheckable(node) && isAsynchronousEnabled() && !isBusy();
     92bool SpellChecker::canCheckAsynchronously(Range* range) const
     93{
     94    return client() && isCheckable(range) && isAsynchronousEnabled() && !isBusy();
    9495}
    9596
    9697bool SpellChecker::isBusy() const
    9798{
    98     return m_requestNode.get();
     99    return m_requestRange.get();
    99100}
    100101
    101102bool SpellChecker::isValid(int sequence) const
    102103{
    103     return m_requestNode.get() && m_requestText.length() && m_requestSequence == sequence;
    104 }
    105 
    106 bool SpellChecker::isCheckable(Node* node) const
    107 {
    108     return node && node->renderer();
    109 }
    110 
    111 void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, Node* node)
    112 {
    113     ASSERT(canCheckAsynchronously(node));
    114 
    115     if (!initRequest(node))
     104    return m_requestRange.get() && m_requestText.length() && m_requestSequence == sequence;
     105}
     106
     107bool SpellChecker::isCheckable(Range* range) const
     108{
     109    return range && range->firstNode() && range->firstNode()->renderer();
     110}
     111
     112void SpellChecker::requestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range)
     113{
     114    if (!canCheckAsynchronously(range.get()))
     115        return;
     116
     117    doRequestCheckingFor(mask, range);
     118}
     119
     120void SpellChecker::doRequestCheckingFor(TextCheckingTypeMask mask, PassRefPtr<Range> range)
     121{
     122    ASSERT(canCheckAsynchronously(range.get()));
     123
     124    if (!initRequest(range))
    116125        return;
    117126    client()->requestCheckingOfString(this, m_requestSequence, mask, m_requestText);
     
    154163        return;
    155164
    156     if (!m_requestNode->renderer()) {
     165    if (!isCheckable(m_requestRange.get())) {
    157166        clearRequest();
    158167        return;
     
    160169
    161170    int startOffset = 0;
    162     PositionIterator start = firstPositionInOrBeforeNode(m_requestNode.get());
     171    PositionIterator start = m_requestRange->startPosition();
    163172    for (size_t i = 0; i < results.size(); ++i) {
    164173        if (results[i].type != TextCheckingTypeSpelling && results[i].type != TextCheckingTypeGrammar)
     
    178187        // JavaScript applications, retrieve the words in the specified region and compare them with
    179188        // the original ones.
    180         RefPtr<Range> range = Range::create(m_requestNode->document(), start, end);
     189        RefPtr<Range> range = Range::create(m_requestRange->ownerDocument(), start, end);
    181190        // FIXME: Use textContent() compatible string conversion.
    182191        String destination = range->text();
    183192        String source = m_requestText.substring(results[i].location, results[i].length);
    184193        if (destination == source)
    185             m_requestNode->document()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
     194            m_requestRange->ownerDocument()->markers()->addMarker(range.get(), toMarkerType(results[i].type));
    186195
    187196        startOffset = results[i].location;
  • trunk/Source/WebCore/editing/SpellChecker.h

    r95901 r100890  
    3939class TextCheckerClient;
    4040struct TextCheckingResult;
     41class Range;
    4142
    4243class SpellChecker {
     
    4748
    4849    bool isAsynchronousEnabled() const;
    49     bool canCheckAsynchronously(Node*) const;
     50    bool canCheckAsynchronously(Range*) const;
    5051    bool isBusy() const;
    5152    bool isValid(int sequence) const;
    52     bool isCheckable(Node*) const;
    53     void requestCheckingFor(TextCheckingTypeMask, Node*);
     53    bool isCheckable(Range*) const;
     54    void requestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
    5455    void didCheck(int sequence, const Vector<TextCheckingResult>&);
    5556
    5657private:
    57     bool initRequest(Node*);
     58    bool initRequest(PassRefPtr<Range>);
    5859    void clearRequest();
     60    void doRequestCheckingFor(TextCheckingTypeMask, PassRefPtr<Range>);
    5961    TextCheckerClient* client() const;
    6062
    6163    Frame* m_frame;
    6264
    63     RefPtr<Node> m_requestNode;
     65    RefPtr<Range> m_requestRange;
    6466    String m_requestText;
    6567    int m_requestSequence;
Note: See TracChangeset for help on using the changeset viewer.