Changeset 88332 in webkit


Ignore:
Timestamp:
Jun 8, 2011 1:54:12 AM (13 years ago)
Author:
morrita@google.com
Message:

2011-06-08 Hironori Bono <hbono@chromium.org>

Reviewed by Brent Fulgham.

Add SpellCheck API
https://bugs.webkit.org/show_bug.cgi?id=59693

This change adds two SpellCheck API functions (addSpellcheckRange and
removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
the public-webapps ML. This change is currently available only on Chromium.

  • editing/spelling/spellcheck-api-expected.txt: Added.
  • editing/spelling/spellcheck-api-pixel.html: Added.
  • editing/spelling/spellcheck-api.html: Added.
  • platform/chromium/test_expectations.txt:
  • platform/gtk/Skipped:
  • platform/mac/Skipped:
  • platform/qt/Skipped:
  • platform/win/Skipped:

2011-06-08 Hironori Bono <hbono@chromium.org>

Reviewed by Brent Fulgham.

Add SpellCheck API
https://bugs.webkit.org/show_bug.cgi?id=59693

This change adds two SpellCheck API functions (addSpellcheckRange and
removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
the public-webapps ML. This change is currently available only on Chromium.

Tests: editing/spelling/spellcheck-api-pixel.html

editing/spelling/spellcheck-api.html

  • WebCore.gypi:
  • bindings/generic/RuntimeEnabledFeatures.cpp:
  • bindings/generic/RuntimeEnabledFeatures.h: (WebCore::RuntimeEnabledFeatures::spellCheckAPIEnabled): (WebCore::RuntimeEnabledFeatures::setSpellCheckAPIEnabled):
  • dom/DocumentMarker.h: (WebCore::DocumentMarker::length):
  • dom/DocumentMarkerController.cpp: (WebCore::DocumentMarkerController::userSpellingMarkersForNode): (WebCore::DocumentMarkerController::addUserSpellingMarker): (WebCore::DocumentMarkerController::removeUserSpellingMarker): (WebCore::DocumentMarkerController::userSpellingNode):
  • dom/DocumentMarkerController.h:
  • html/HTMLDivElement.cpp: (WebCore::HTMLDivElement::spellcheckRanges): (WebCore::HTMLDivElement::addSpellcheckRange): (WebCore::HTMLDivElement::removeSpellcheckRange):
  • html/HTMLDivElement.h:
  • html/HTMLDivElement.idl:
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::spellcheckRanges): (WebCore::HTMLInputElement::addSpellcheckRange): (WebCore::HTMLInputElement::removeSpellcheckRange):
  • html/HTMLInputElement.h:
  • html/HTMLInputElement.idl:
  • html/HTMLTextAreaElement.cpp: (WebCore::HTMLTextAreaElement::spellcheckRanges): (WebCore::HTMLTextAreaElement::addSpellcheckRange): (WebCore::HTMLTextAreaElement::removeSpellcheckRange):
  • html/HTMLTextAreaElement.h:
  • html/HTMLTextAreaElement.idl:
  • html/SpellcheckRange.cpp: Added. (WebCore::SpellcheckRange::SpellcheckRange): (WebCore::SpellcheckRange::~SpellcheckRange):
  • html/SpellcheckRange.h: Added. (WebCore::SpellcheckRange::create): (WebCore::SpellcheckRange::start): (WebCore::SpellcheckRange::length): (WebCore::SpellcheckRange::suggestions): (WebCore::SpellcheckRange::options):
  • html/SpellcheckRange.idl: Added.
  • html/SpellcheckRangeList.cpp: Added. (WebCore::SpellcheckRangeList::SpellcheckRangeList): (WebCore::SpellcheckRangeList::~SpellcheckRangeList): (WebCore::SpellcheckRangeList::item):
  • html/SpellcheckRangeList.h: Added. (WebCore::SpellcheckRangeList::create): (WebCore::SpellcheckRangeList::isEmpty): (WebCore::SpellcheckRangeList::clear): (WebCore::SpellcheckRangeList::append): (WebCore::SpellcheckRangeList::remove): (WebCore::SpellcheckRangeList::length):
  • html/SpellcheckRangeList.idl: Added.
  • rendering/InlineTextBox.cpp: (WebCore::textCheckingLineStyleForMarkerType): (WebCore::InlineTextBox::paintDocumentMarkers):

2011-06-08 Hironori Bono <hbono@chromium.org>

Reviewed by Brent Fulgham.

Add SpellCheck API
https://bugs.webkit.org/show_bug.cgi?id=59693

This change adds two SpellCheck API functions (addSpellcheckRange and
removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
the public-webapps ML. This change is currently available only on Chromium.

  • features.gypi:
  • public/WebRuntimeFeatures.h:
  • src/ContextMenuClientImpl.cpp: (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):
  • src/WebRuntimeFeatures.cpp: (WebKit::WebRuntimeFeatures::enableSpellCheckAPI): (WebKit::WebRuntimeFeatures::isSpellCheckAPIEnabled):
Location:
trunk
Files:
9 added
28 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r88331 r88332  
     12011-06-08  Hironori Bono  <hbono@chromium.org>
     2
     3        Reviewed by Brent Fulgham.
     4
     5        Add SpellCheck API
     6        https://bugs.webkit.org/show_bug.cgi?id=59693
     7
     8        This change adds two SpellCheck API functions (addSpellcheckRange and
     9        removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
     10        the public-webapps ML. This change is currently available only on Chromium.
     11
     12        * editing/spelling/spellcheck-api-expected.txt: Added.
     13        * editing/spelling/spellcheck-api-pixel.html: Added.
     14        * editing/spelling/spellcheck-api.html: Added.
     15        * platform/chromium/test_expectations.txt:       
     16        * platform/gtk/Skipped:
     17        * platform/mac/Skipped:
     18        * platform/qt/Skipped:
     19        * platform/win/Skipped:
     20
    1212011-06-07  Andrey Kosyakov  <caseq@chromium.org>
    222
  • trunk/LayoutTests/platform/chromium/test_expectations.txt

    r88323 r88332  
    746746BUGCR58254 MAC : platform/mac/editing/spelling/autocorrection-removing-underline.html = IMAGE+TEXT
    747747BUGCR58254 MAC : platform/mac/editing/spelling/autocorrection-simple.html = IMAGE+TEXT
     748
     749// Needs rebaseline
     750BUGMORRITA : editing/spelling/spellcheck-api-pixel.html = MISSING
    748751
    749752// Directionality of mixed-direction text in selected choice should
  • trunk/LayoutTests/platform/gtk/Skipped

    r88255 r88332  
    395395storage/storageinfo-request-quota.html
    396396storage/storageinfo-no-callbacks.html
     397
     398# Spellcheck API is not implemented.
     399editing/spelling/spellcheck-api.html
     400editing/spelling/spellcheck-api-pixel.html
    397401
    398402# This platform does not support the Page Visibility API.
  • trunk/LayoutTests/platform/mac/Skipped

    r88144 r88332  
    341341storage/storageinfo-no-callbacks.html
    342342
     343# Spellcheck API is not implemented.
     344editing/spelling/spellcheck-api.html
     345editing/spelling/spellcheck-api-pixel.html
     346
    343347# Expose title direction in WebKit API
    344348# https://bugs.webkit.org/show_bug.cgi?id=58845
  • trunk/LayoutTests/platform/qt/Skipped

    r88327 r88332  
    24482448http/tests/misc/redirect-to-external-url.html
    24492449
     2450# Spellcheck API is not implemented.
     2451editing/spelling/spellcheck-api.html
     2452editing/spelling/spellcheck-api-pixel.html
     2453
    24502454# Expose title direction in WebKit API
    24512455# https://bugs.webkit.org/show_bug.cgi?id=58845
  • trunk/LayoutTests/platform/win/Skipped

    r88331 r88332  
    12691269storage/storageinfo-no-callbacks.html
    12701270
     1271# Spellcheck API is not implemented.
     1272editing/spelling/spellcheck-api.html
     1273editing/spelling/spellcheck-api-pixel.html
     1274
    12711275# Expose title direction in WebKit API
    12721276# https://bugs.webkit.org/show_bug.cgi?id=58845
  • trunk/Source/WebCore/ChangeLog

    r88331 r88332  
     12011-06-08  Hironori Bono  <hbono@chromium.org>
     2
     3        Reviewed by Brent Fulgham.
     4
     5        Add SpellCheck API
     6        https://bugs.webkit.org/show_bug.cgi?id=59693
     7
     8        This change adds two SpellCheck API functions (addSpellcheckRange and
     9        removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
     10        the public-webapps ML. This change is currently available only on Chromium.
     11
     12        Tests: editing/spelling/spellcheck-api-pixel.html
     13               editing/spelling/spellcheck-api.html
     14
     15        * WebCore.gypi:
     16        * bindings/generic/RuntimeEnabledFeatures.cpp:
     17        * bindings/generic/RuntimeEnabledFeatures.h:
     18        (WebCore::RuntimeEnabledFeatures::spellCheckAPIEnabled):
     19        (WebCore::RuntimeEnabledFeatures::setSpellCheckAPIEnabled):
     20        * dom/DocumentMarker.h:
     21        (WebCore::DocumentMarker::length):
     22        * dom/DocumentMarkerController.cpp:
     23        (WebCore::DocumentMarkerController::userSpellingMarkersForNode):
     24        (WebCore::DocumentMarkerController::addUserSpellingMarker):
     25        (WebCore::DocumentMarkerController::removeUserSpellingMarker):
     26        (WebCore::DocumentMarkerController::userSpellingNode):
     27        * dom/DocumentMarkerController.h:
     28        * html/HTMLDivElement.cpp:
     29        (WebCore::HTMLDivElement::spellcheckRanges):
     30        (WebCore::HTMLDivElement::addSpellcheckRange):
     31        (WebCore::HTMLDivElement::removeSpellcheckRange):
     32        * html/HTMLDivElement.h:
     33        * html/HTMLDivElement.idl:
     34        * html/HTMLInputElement.cpp:
     35        (WebCore::HTMLInputElement::spellcheckRanges):
     36        (WebCore::HTMLInputElement::addSpellcheckRange):
     37        (WebCore::HTMLInputElement::removeSpellcheckRange):
     38        * html/HTMLInputElement.h:
     39        * html/HTMLInputElement.idl:
     40        * html/HTMLTextAreaElement.cpp:
     41        (WebCore::HTMLTextAreaElement::spellcheckRanges):
     42        (WebCore::HTMLTextAreaElement::addSpellcheckRange):
     43        (WebCore::HTMLTextAreaElement::removeSpellcheckRange):
     44        * html/HTMLTextAreaElement.h:
     45        * html/HTMLTextAreaElement.idl:
     46        * html/SpellcheckRange.cpp: Added.
     47        (WebCore::SpellcheckRange::SpellcheckRange):
     48        (WebCore::SpellcheckRange::~SpellcheckRange):
     49        * html/SpellcheckRange.h: Added.
     50        (WebCore::SpellcheckRange::create):
     51        (WebCore::SpellcheckRange::start):
     52        (WebCore::SpellcheckRange::length):
     53        (WebCore::SpellcheckRange::suggestions):
     54        (WebCore::SpellcheckRange::options):
     55        * html/SpellcheckRange.idl: Added.
     56        * html/SpellcheckRangeList.cpp: Added.
     57        (WebCore::SpellcheckRangeList::SpellcheckRangeList):
     58        (WebCore::SpellcheckRangeList::~SpellcheckRangeList):
     59        (WebCore::SpellcheckRangeList::item):
     60        * html/SpellcheckRangeList.h: Added.
     61        (WebCore::SpellcheckRangeList::create):
     62        (WebCore::SpellcheckRangeList::isEmpty):
     63        (WebCore::SpellcheckRangeList::clear):
     64        (WebCore::SpellcheckRangeList::append):
     65        (WebCore::SpellcheckRangeList::remove):
     66        (WebCore::SpellcheckRangeList::length):
     67        * html/SpellcheckRangeList.idl: Added.
     68        * rendering/InlineTextBox.cpp:
     69        (WebCore::textCheckingLineStyleForMarkerType):
     70        (WebCore::InlineTextBox::paintDocumentMarkers):
     71
    1722011-06-07  Andrey Kosyakov  <caseq@chromium.org>
    273
  • trunk/Source/WebCore/WebCore.gypi

    r88307 r88332  
    12961296            'html/MediaError.idl',
    12971297            'html/TextMetrics.idl',
     1298            'html/SpellcheckRange.idl',
     1299            'html/SpellcheckRangeList.idl',
    12981300            'html/TimeRanges.idl',
    12991301            'html/ValidityState.idl',
     
    30483050            'html/SearchInputType.cpp',
    30493051            'html/SearchInputType.h',
     3052            'html/SpellcheckRange.cpp',
     3053            'html/SpellcheckRange.h',
     3054            'html/SpellcheckRangeList.cpp',
     3055            'html/SpellcheckRangeList.h',
    30503056            'html/StepRange.cpp',
    30513057            'html/StepRange.h',
     
    78577863            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpeechInputResultList.cpp',
    78587864            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpeechInputResultList.h',
     7865            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpellcheckRange.cpp',
     7866            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpellcheckRange.h',
     7867            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpellcheckRangeList.cpp',
     7868            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSSpellcheckRangeList.h',
    78597869            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSStorage.cpp',
    78607870            '<(PRODUCT_DIR)/DerivedSources/WebCore/JSStorage.h',
  • trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.cpp

    r84247 r88332  
    147147#endif
    148148
     149#if ENABLE(SPELLCHECK_API)
     150bool RuntimeEnabledFeatures::isSpellCheckAPIEnabled = false;
     151#endif
     152
    149153} // namespace WebCore
  • trunk/Source/WebCore/bindings/generic/RuntimeEnabledFeatures.h

    r84247 r88332  
    156156#endif
    157157
     158#if ENABLE(SPELLCHECK_API)
     159    static bool spellCheckAPIEnabled() { return isSpellCheckAPIEnabled; }
     160    static void setSpellCheckAPIEnabled(bool isEnabled) { isSpellCheckAPIEnabled = isEnabled; }
     161#endif
     162
    158163private:
    159164    // Never instantiate.
     
    192197    static bool isQuotaEnabled;
    193198#endif
     199
     200#if ENABLE(SPELLCHECK_API)
     201    static bool isSpellCheckAPIEnabled;
     202#endif
    194203};
    195204
  • trunk/Source/WebCore/dom/DocumentMarker.h

    r86813 r88332  
    6060        // word again at this position, it will not be autocorrected again. The description of this
    6161        // marker is the original word before autocorrection was applied.
    62         DeletedAutocorrection = 1 << 8
     62        DeletedAutocorrection = 1 << 8,
     63        // A misspelled marker added by users with the SpellCheck API. (Even though
     64        // this marker is almost identical to the above Spelling marker, we need
     65        // another type for user-added markers because it raises privacy concerns
     66        // to provide a list of system-added markers.)
     67        UserSpelling = 1 << 9,
    6368    };
    6469
     
    98103    bool hasDescription() const { return !m_description.isEmpty(); }
    99104    bool activeMatch() const { return m_activeMatch; }
     105    unsigned length() const
     106    {
     107        ASSERT(m_endOffset >= m_startOffset);
     108        return m_endOffset - m_startOffset;
     109    }
    100110
    101111    void setActiveMatch(bool);
  • trunk/Source/WebCore/dom/DocumentMarkerController.cpp

    r87483 r88332  
    3232#include "RenderObject.h"
    3333#include "RenderedDocumentMarker.h"
     34#include "SpellcheckRange.h"
     35#include "SpellcheckRangeList.h"
    3436#include "TextIterator.h"
    3537
     
    654656}
    655657
     658#if ENABLE(SPELLCHECK_API)
     659PassRefPtr<SpellcheckRangeList> DocumentMarkerController::userSpellingMarkersForNode(Node* node) const
     660{
     661    RefPtr<SpellcheckRangeList> result = SpellcheckRangeList::create();
     662
     663    MarkerList* list = m_markers.get(userSpellingNode(node));
     664    if (!list)
     665        return result;
     666
     667    for (size_t i = 0; i < list->size(); ++i) {
     668        const DocumentMarker& marker = list->at(i);
     669        if (marker.length() > 0) {
     670            RefPtr<DOMStringList> suggestions = DOMStringList::create();
     671            Vector<String> descriptions;
     672            marker.description().split('\n', descriptions);
     673            for (size_t j = 0; j < descriptions.size(); ++j)
     674                suggestions->append(descriptions[j]);
     675            result->append(SpellcheckRange::create(marker.startOffset(), marker.length(), suggestions.release(), 0));
     676        }
     677    }
     678
     679    return result;
     680}
     681
     682bool DocumentMarkerController::addUserSpellingMarker(Node* node, unsigned start, unsigned length, RefPtr<DOMStringList> suggestions, unsigned options)
     683{
     684    if (!node || !length)
     685        return false;
     686
     687    Node* spellingNode = userSpellingNode(node);
     688    if (!spellingNode)
     689        return false;
     690
     691    // Serialize the suggestions into text until the DocumentMarker class supports multiple descriptions.
     692    String description;
     693    for (size_t i = 0; i < suggestions->length(); i++) {
     694        description += suggestions->item(i);
     695        description.append('\n');
     696    }
     697    addMarker(spellingNode, DocumentMarker(DocumentMarker::UserSpelling, start, start + length, description));
     698
     699    UNUSED_PARAM(options);
     700    return true;
     701}
     702
     703void DocumentMarkerController::removeUserSpellingMarker(Node* node, unsigned start, unsigned length)
     704{
     705    if (!node || !length)
     706        return;
     707
     708    Node* spellingNode = userSpellingNode(node);
     709    if (!spellingNode)
     710        return;
     711
     712    removeMarkers(spellingNode, start, length, DocumentMarker::UserSpelling, DoNotRemovePartiallyOverlappingMarker);
     713}
     714
     715Node* DocumentMarkerController::userSpellingNode(Node* node) const
     716{
     717    for (const RenderObject* renderer = node->renderer(); renderer; renderer = renderer->childAt(0)) {
     718        if (renderer->isText())
     719            return renderer->node();
     720    }
     721    return 0;
     722}
     723#endif
     724
    656725#ifndef NDEBUG
    657726void DocumentMarkerController::showMarkers() const
  • trunk/Source/WebCore/dom/DocumentMarkerController.h

    r87483 r88332  
    4040class RenderedDocumentMarker;
    4141
     42#if ENABLE(SPELLCHECK_API)
     43class DOMStringList;
     44class SpellcheckRangeList;
     45#endif
     46
    4247class DocumentMarkerController {
    4348    WTF_MAKE_NONCOPYABLE(DocumentMarkerController); WTF_MAKE_FAST_ALLOCATED;
     
    7782    void clearDescriptionOnMarkersIntersectingRange(Range*, DocumentMarker::MarkerTypes);
    7883
     84#if ENABLE(SPELLCHECK_API)
     85    PassRefPtr<SpellcheckRangeList> userSpellingMarkersForNode(Node*) const;
     86    bool addUserSpellingMarker(Node*, unsigned startOffset, unsigned length, RefPtr<DOMStringList>, unsigned option);
     87    void removeUserSpellingMarker(Node*, unsigned startOffset, unsigned length);
     88#endif
     89
    7990#ifndef NDEBUG
    8091    void showMarkers() const;
     
    8394private:
    8495    void addMarker(Node*, const DocumentMarker&);
     96
     97#if ENABLE(SPELLCHECK_API)
     98    Node* userSpellingNode(Node*) const;
     99#endif
    85100
    86101    typedef Vector<RenderedDocumentMarker> MarkerList;
  • trunk/Source/WebCore/html/HTMLDivElement.cpp

    r61959 r88332  
    2727#include "CSSPropertyNames.h"
    2828#include "CSSValueKeywords.h"
     29#include "DOMStringList.h"
     30#include "DocumentMarkerController.h"
    2931#include "HTMLNames.h"
     32#include "SpellcheckRange.h"
     33#include "SpellcheckRangeList.h"
    3034
    3135namespace WebCore {
     
    7478}
    7579
     80#if ENABLE(SPELLCHECK_API)
     81PassRefPtr<SpellcheckRangeList> HTMLDivElement::spellcheckRanges()
     82{
     83    return document()->markers()->userSpellingMarkersForNode(this);
    7684}
     85
     86void HTMLDivElement::addSpellcheckRange(unsigned long start, unsigned long length)
     87{
     88    addSpellcheckRange(start, length, DOMStringList::create(), 0);
     89}
     90
     91void HTMLDivElement::addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList> suggestions, unsigned short options)
     92{
     93    document()->markers()->addUserSpellingMarker(this, start, length, suggestions, options);
     94}
     95
     96void HTMLDivElement::removeSpellcheckRange(RefPtr<SpellcheckRange> range)
     97{
     98    document()->markers()->removeUserSpellingMarker(this, range->start(), range->length());
     99}
     100#endif
     101
     102}
  • trunk/Source/WebCore/html/HTMLDivElement.h

    r66057 r88332  
    2828namespace WebCore {
    2929
     30#if ENABLE(SPELLCHECK_API)
     31class DOMStringList;
     32class SpellcheckRange;
     33class SpellcheckRangeList;
     34#endif
     35
    3036class HTMLDivElement : public HTMLElement {
    3137public:
    3238    static PassRefPtr<HTMLDivElement> create(Document*);
    3339    static PassRefPtr<HTMLDivElement> create(const QualifiedName&, Document*);
     40
     41#if ENABLE(SPELLCHECK_API)
     42    PassRefPtr<SpellcheckRangeList> spellcheckRanges();
     43    void addSpellcheckRange(unsigned long start, unsigned long length);
     44    void addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList>, unsigned short options = 0);
     45    void removeSpellcheckRange(RefPtr<SpellcheckRange>);
     46#endif
    3447
    3548protected:
  • trunk/Source/WebCore/html/HTMLDivElement.idl

    r61413 r88332  
    2222    interface HTMLDivElement : HTMLElement {
    2323        attribute [Reflect] DOMString align;
     24
     25#if defined(ENABLE_SPELLCHECK_API) && ENABLE_SPELLCHECK_API
     26        readonly attribute SpellcheckRangeList spellcheckRanges;
     27        void addSpellcheckRange(in unsigned long start, in unsigned long length, in [Optional] DOMStringList suggestions, in [Optional] unsigned short options);
     28        void removeSpellcheckRange(in SpellcheckRange range);
     29#endif
    2430    };
    2531
  • trunk/Source/WebCore/html/HTMLInputElement.cpp

    r88329 r88332  
    3535#include "ChromeClient.h"
    3636#include "CSSPropertyNames.h"
     37#include "DOMStringList.h"
    3738#include "Document.h"
     39#include "DocumentMarkerController.h"
    3840#include "EventNames.h"
    3941#include "ExceptionCode.h"
     
    5658#include "RuntimeEnabledFeatures.h"
    5759#include "ScriptEventListener.h"
     60#include "SpellcheckRange.h"
     61#include "SpellcheckRangeList.h"
    5862#include "WheelEvent.h"
    5963#include <wtf/MathExtras.h>
     
    18401844}
    18411845
     1846#if ENABLE(SPELLCHECK_API)
     1847PassRefPtr<SpellcheckRangeList> HTMLInputElement::spellcheckRanges()
     1848{
     1849    return document()->markers()->userSpellingMarkersForNode(this);
     1850}
     1851
     1852void HTMLInputElement::addSpellcheckRange(unsigned long start, unsigned long length)
     1853{
     1854    addSpellcheckRange(start, length, DOMStringList::create(), 0);
     1855}
     1856
     1857void HTMLInputElement::addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList> suggestions, unsigned short options)
     1858{
     1859    document()->markers()->addUserSpellingMarker(this, start, length, suggestions, options);
     1860}
     1861
     1862void HTMLInputElement::removeSpellcheckRange(RefPtr<SpellcheckRange> range)
     1863{
     1864    document()->markers()->removeUserSpellingMarker(this, range->start(), range->length());
     1865}
     1866#endif
     1867
    18421868} // namespace
  • trunk/Source/WebCore/html/HTMLInputElement.h

    r88329 r88332  
    3434class InputType;
    3535class KURL;
     36
     37#if ENABLE(SPELLCHECK_API)
     38class DOMStringList;
     39class SpellcheckRange;
     40class SpellcheckRangeList;
     41#endif
    3642
    3743class HTMLInputElement : public HTMLTextFormControlElement {
     
    228234    void cacheSelection(int start, int end);
    229235
     236#if ENABLE(SPELLCHECK_API)
     237    PassRefPtr<SpellcheckRangeList> spellcheckRanges();
     238    void addSpellcheckRange(unsigned long start, unsigned long length);
     239    void addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList>, unsigned short options = 0);
     240    void removeSpellcheckRange(RefPtr<SpellcheckRange>);
     241#endif
     242
    230243    static const int maximumLength;
    231244
  • trunk/Source/WebCore/html/HTMLInputElement.idl

    r73168 r88332  
    108108        attribute [DontEnum] EventListener onwebkitspeechchange;
    109109#endif
     110
     111#if defined(ENABLE_SPELLCHECK_API) && ENABLE_SPELLCHECK_API
     112        readonly attribute SpellcheckRangeList spellcheckRanges;
     113        void addSpellcheckRange(in unsigned long start, in unsigned long length, in [Optional] DOMStringList suggestions, in [Optional] unsigned short options);
     114        void removeSpellcheckRange(in SpellcheckRange range);
     115#endif
    110116    };
    111117
  • trunk/Source/WebCore/html/HTMLTextAreaElement.cpp

    r87067 r88332  
    3232#include "Chrome.h"
    3333#include "ChromeClient.h"
     34#include "DOMStringList.h"
    3435#include "Document.h"
     36#include "DocumentMarkerController.h"
    3537#include "Event.h"
    3638#include "EventNames.h"
     
    4547#include "ScriptEventListener.h"
    4648#include "ShadowRoot.h"
     49#include "SpellcheckRange.h"
     50#include "SpellcheckRangeList.h"
    4751#include "Text.h"
    4852#include "TextControlInnerElements.h"
     
    441445}
    442446
     447#if ENABLE(SPELLCHECK_API)
     448PassRefPtr<SpellcheckRangeList> HTMLTextAreaElement::spellcheckRanges()
     449{
     450    return document()->markers()->userSpellingMarkersForNode(this);
     451}
     452
     453void HTMLTextAreaElement::addSpellcheckRange(unsigned long start, unsigned long length)
     454{
     455    addSpellcheckRange(start, length, DOMStringList::create(), 0);
     456}
     457
     458void HTMLTextAreaElement::addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList> suggestions, unsigned short options)
     459{
     460    document()->markers()->addUserSpellingMarker(this, start, length, suggestions, options);
     461}
     462
     463void HTMLTextAreaElement::removeSpellcheckRange(RefPtr<SpellcheckRange> range)
     464{
     465    document()->markers()->removeUserSpellingMarker(this, range->start(), range->length());
     466}
     467#endif
     468
    443469} // namespace
  • trunk/Source/WebCore/html/HTMLTextAreaElement.h

    r87067 r88332  
    3232class VisibleSelection;
    3333
     34#if ENABLE(SPELLCHECK_API)
     35class DOMStringList;
     36class SpellcheckRange;
     37class SpellcheckRangeList;
     38#endif
     39
    3440class HTMLTextAreaElement : public HTMLTextFormControlElement {
    3541public:
     
    6066
    6167    void cacheSelection(int s, int e) { m_cachedSelectionStart = s; m_cachedSelectionEnd = e; };
     68
     69#if ENABLE(SPELLCHECK_API)
     70    PassRefPtr<SpellcheckRangeList> spellcheckRanges();
     71    void addSpellcheckRange(unsigned long start, unsigned long length);
     72    void addSpellcheckRange(unsigned long start, unsigned long length, RefPtr<DOMStringList>, unsigned short options = 0);
     73    void removeSpellcheckRange(RefPtr<SpellcheckRange>);
     74#endif
    6275
    6376private:
  • trunk/Source/WebCore/html/HTMLTextAreaElement.idl

    r61959 r88332  
    5151        void setSelectionRange(in long start, in long end);
    5252        readonly attribute NodeList labels;
     53
     54#if defined(ENABLE_SPELLCHECK_API) && ENABLE_SPELLCHECK_API
     55        readonly attribute SpellcheckRangeList spellcheckRanges;
     56        void addSpellcheckRange(in unsigned long start, in unsigned long length, in [Optional] DOMStringList suggestions, in [Optional] unsigned short options);
     57        void removeSpellcheckRange(in SpellcheckRange range);
     58#endif
    5359    };
    5460
  • trunk/Source/WebCore/rendering/InlineTextBox.cpp

    r88319 r88332  
    964964    switch (markerType) {
    965965    case DocumentMarker::Spelling:
     966    case DocumentMarker::UserSpelling:
    966967        return GraphicsContext::TextCheckingSpellingLineStyle;
    967968    case DocumentMarker::Grammar:
     
    11051106            case DocumentMarker::Grammar:
    11061107            case DocumentMarker::Spelling:
     1108            case DocumentMarker::UserSpelling:
    11071109            case DocumentMarker::CorrectionIndicator:
    11081110            case DocumentMarker::Replacement:
     
    11301132        switch (marker->type()) {
    11311133            case DocumentMarker::Spelling:
     1134            case DocumentMarker::UserSpelling:
    11321135                paintSpellingOrGrammarMarker(pt, boxOrigin, marker, style, font, false);
    11331136                break;
  • trunk/Source/WebKit/chromium/ChangeLog

    r88320 r88332  
     12011-06-08  Hironori Bono  <hbono@chromium.org>
     2
     3        Reviewed by Brent Fulgham.
     4
     5        Add SpellCheck API
     6        https://bugs.webkit.org/show_bug.cgi?id=59693
     7
     8        This change adds two SpellCheck API functions (addSpellcheckRange and
     9        removeSpellcheckRange) and one attribute (spellcheckRange) discussed in
     10        the public-webapps ML. This change is currently available only on Chromium.
     11
     12        * features.gypi:
     13        * public/WebRuntimeFeatures.h:
     14        * src/ContextMenuClientImpl.cpp:
     15        (WebKit::ContextMenuClientImpl::getCustomMenuFromDefaultItems):
     16        * src/WebRuntimeFeatures.cpp:
     17        (WebKit::WebRuntimeFeatures::enableSpellCheckAPI):
     18        (WebKit::WebRuntimeFeatures::isSpellCheckAPIEnabled):
     19
    1202011-06-07  James Kozianski  <koz@chromium.org>
    221
  • trunk/Source/WebKit/chromium/features.gypi

    r88271 r88332  
    8484        'ENABLE_REQUEST_ANIMATION_FRAME=1',
    8585        'ENABLE_SHARED_WORKERS=1',
     86        'ENABLE_SPELLCHECK_API=1',
    8687        'ENABLE_SVG=1',
    8788        'ENABLE_SVG_ANIMATION=1',
  • trunk/Source/WebKit/chromium/public/WebRuntimeFeatures.h

    r84247 r88332  
    104104    WEBKIT_API static bool isQuotaEnabled();
    105105
     106    WEBKIT_API static void enableSpellCheckAPI(bool);
     107    WEBKIT_API static bool isSpellCheckAPIEnabled();
     108
    106109private:
    107110    WebRuntimeFeatures();
  • trunk/Source/WebKit/chromium/src/ContextMenuClientImpl.cpp

    r88030 r88332  
    3838#include "Document.h"
    3939#include "DocumentLoader.h"
     40#include "DocumentMarkerController.h"
    4041#include "Editor.h"
    4142#include "EventHandler.h"
     
    260261    if (r.isContentEditable()) {
    261262        data.isEditable = true;
    262         if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
     263        // If the selected text has markers added by Spellcheck API, use their description as suggestions.
     264        RefPtr<Range> range = selectedFrame->selection()->toNormalizedRange();
     265        Vector<DocumentMarker*> markers = selectedFrame->document()->markers()->markersInRange(range.get(), DocumentMarker::UserSpelling);
     266        if (!markers.isEmpty()) {
     267            Vector<String> suggestions;
     268            for (size_t i = 0; i < markers.size(); ++i) {
     269                if (markers[i]->hasDescription()) {
     270                    Vector<String> descriptions;
     271                    markers[i]->description().split('\n', descriptions);
     272                    suggestions.append(descriptions);
     273                }
     274            }
     275            data.dictionarySuggestions = suggestions;
     276            data.misspelledWord = range->text();
     277        } else if (m_webView->focusedWebCoreFrame()->editor()->isContinuousSpellCheckingEnabled()) {
    263278            data.isSpellCheckingEnabled = true;
    264279            // Spellchecking might be enabled for the field, but could be disabled on the node.
  • trunk/Source/WebKit/chromium/src/WebRuntimeFeatures.cpp

    r84247 r88332  
    337337}
    338338
     339void WebRuntimeFeatures::enableSpellCheckAPI(bool enable)
     340{
     341#if ENABLE(SPELLCHECK_API)
     342    RuntimeEnabledFeatures::setSpellCheckAPIEnabled(enable);
     343#else
     344    UNUSED_PARAM(enable);
     345#endif
     346}
     347
     348bool WebRuntimeFeatures::isSpellCheckAPIEnabled()
     349{
     350#if ENABLE(SPELLCHECK_API)
     351    return RuntimeEnabledFeatures::spellCheckAPIEnabled();
     352#else
     353    return false;
     354#endif
     355}
     356
    339357} // namespace WebKit
Note: See TracChangeset for help on using the changeset viewer.