Chromium Code Reviews| Index: third_party/WebKit/Source/core/testing/Internals.cpp |
| diff --git a/third_party/WebKit/Source/core/testing/Internals.cpp b/third_party/WebKit/Source/core/testing/Internals.cpp |
| index 738cb42c4369aa551c5fe1d2f715f1f6c5974fd7..b12881813ea20c41e387c9a43ac7ade1bfa892e8 100644 |
| --- a/third_party/WebKit/Source/core/testing/Internals.cpp |
| +++ b/third_party/WebKit/Source/core/testing/Internals.cpp |
| @@ -172,11 +172,10 @@ class InternalsIterationSource final |
| } // namespace |
| -static bool markerTypesFrom(const String& markerType, |
| - DocumentMarker::MarkerTypes& result) { |
| - if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) |
| - result = DocumentMarker::AllMarkers(); |
| - else if (equalIgnoringCase(markerType, "Spelling")) |
| +// return true if markerType is valid. |
| +static bool markerTypeFrom(const String& markerType, |
|
yosin_UTC9
2016/11/14 05:18:59
How about returning |WTF::Optional<DocumetnMarker:
|
| + DocumentMarker::MarkerType& result) { |
| + if (equalIgnoringCase(markerType, "Spelling")) |
| result = DocumentMarker::Spelling; |
| else if (equalIgnoringCase(markerType, "Grammar")) |
| result = DocumentMarker::Grammar; |
| @@ -188,6 +187,22 @@ static bool markerTypesFrom(const String& markerType, |
| return true; |
| } |
| +// return true if markerType is valid. |
| +static bool markerTypesFrom(const String& markerType, |
| + DocumentMarker::MarkerTypes& result) { |
| + if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) { |
| + result = DocumentMarker::AllMarkers(); |
| + return true; |
| + } |
| + |
| + DocumentMarker::MarkerType type; |
| + if (markerTypeFrom(markerType, type)) { |
| + result = type; |
| + return true; |
| + } |
| + return false; |
| +} |
| + |
| static SpellCheckRequester* spellCheckRequester(Document* document) { |
| if (!document || !document->frame()) |
| return 0; |
| @@ -913,6 +928,28 @@ ClientRect* Internals::boundingBox(Element* element) { |
| layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); |
| } |
| +void Internals::setMarker(Document* document, |
| + const Range* range, |
| + const String& markerType, |
| + ExceptionState& exceptionState) { |
| + if (!document) { |
| + exceptionState.throwDOMException(InvalidAccessError, |
| + "No context document is available."); |
| + return; |
| + } |
| + |
| + DocumentMarker::MarkerType type; |
| + if (!markerTypeFrom(markerType, type)) { |
| + exceptionState.throwDOMException( |
| + SyntaxError, |
| + "The marker type provided ('" + markerType + "') is invalid."); |
| + return; |
| + } |
| + |
| + document->markers().addMarker(range->startPosition(), range->endPosition(), |
| + type); |
| +} |
| + |
| unsigned Internals::markerCountForNode(Node* node, |
| const String& markerType, |
| ExceptionState& exceptionState) { |
| @@ -1826,6 +1863,20 @@ void Internals::setSpellCheckingEnabled(bool enabled, |
| contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled(); |
| } |
| +void Internals::replaceMisspelled(Document* document, |
| + const String& replacement, |
| + ExceptionState& exceptionState) { |
| + if (!document || !document->frame()) { |
| + exceptionState.throwDOMException( |
| + InvalidAccessError, |
| + "No frame can be obtained from the provided document."); |
| + return; |
| + } |
| + |
| + document->updateStyleAndLayoutIgnorePendingStylesheets(); |
| + document->frame()->spellChecker().replaceMisspelledRange(replacement); |
| +} |
| + |
| bool Internals::canHyphenate(const AtomicString& locale) { |
| return LayoutLocale::valueOrDefault(LayoutLocale::get(locale)) |
| .getHyphenation(); |