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..6c8cc75b0536ef88d1116b4a792be84537006a04 100644 |
| --- a/third_party/WebKit/Source/core/testing/Internals.cpp |
| +++ b/third_party/WebKit/Source/core/testing/Internals.cpp |
| @@ -146,6 +146,7 @@ |
| #include "public/platform/WebLayer.h" |
| #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h" |
| #include "wtf/InstanceCounter.h" |
| +#include "wtf/Optional.h" |
| #include "wtf/PtrUtil.h" |
| #include "wtf/dtoa.h" |
| #include "wtf/text/StringBuffer.h" |
| @@ -172,20 +173,27 @@ class InternalsIterationSource final |
| } // namespace |
| -static bool markerTypesFrom(const String& markerType, |
| - DocumentMarker::MarkerTypes& result) { |
| +static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom( |
| + const String& markerType) { |
| + if (equalIgnoringCase(markerType, "Spelling")) |
| + return DocumentMarker::Spelling; |
| + if (equalIgnoringCase(markerType, "Grammar")) |
| + return DocumentMarker::Grammar; |
| + if (equalIgnoringCase(markerType, "TextMatch")) |
| + return DocumentMarker::TextMatch; |
| + |
|
yosin_UTC9
2016/11/15 02:14:06
nit: Please get rid of an extra blank line.
|
| + return WTF::nullopt; |
| +} |
| + |
| +static WTF::Optional<DocumentMarker::MarkerTypes> markerTypesFrom( |
| + const String& markerType) { |
| if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) |
| - result = DocumentMarker::AllMarkers(); |
| - else if (equalIgnoringCase(markerType, "Spelling")) |
| - result = DocumentMarker::Spelling; |
| - else if (equalIgnoringCase(markerType, "Grammar")) |
| - result = DocumentMarker::Grammar; |
| - else if (equalIgnoringCase(markerType, "TextMatch")) |
| - result = DocumentMarker::TextMatch; |
| - else |
| - return false; |
| + return DocumentMarker::AllMarkers(); |
| + WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType); |
| + if (type) |
| + return static_cast<DocumentMarker::MarkerTypes>(type.value()); |
|
yosin_UTC9
2016/11/15 02:14:06
Can we use |DocumentMarker::MarkerTypes(type.value
|
| - return true; |
| + return WTF::nullopt; |
|
yosin_UTC9
2016/11/15 02:14:06
It is more readable switching if-condition:
if (!
|
| } |
| static SpellCheckRequester* spellCheckRequester(Document* document) { |
| @@ -913,19 +921,45 @@ 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; |
| + } |
| + |
| + WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType); |
| + if (!type) { |
| + exceptionState.throwDOMException( |
| + SyntaxError, |
| + "The marker type provided ('" + markerType + "') is invalid."); |
| + return; |
| + } |
| + |
| + document->markers().addMarker(range->startPosition(), range->endPosition(), |
| + type.value()); |
| +} |
| + |
| unsigned Internals::markerCountForNode(Node* node, |
| const String& markerType, |
| ExceptionState& exceptionState) { |
| ASSERT(node); |
| - DocumentMarker::MarkerTypes markerTypes = 0; |
| - if (!markerTypesFrom(markerType, markerTypes)) { |
| + WTF::Optional<DocumentMarker::MarkerTypes> markerTypes = |
| + markerTypesFrom(markerType); |
| + if (!markerTypes) { |
| exceptionState.throwDOMException( |
| SyntaxError, |
| "The marker type provided ('" + markerType + "') is invalid."); |
| return 0; |
| } |
| - return node->document().markers().markersFor(node, markerTypes).size(); |
| + return node->document() |
| + .markers() |
| + .markersFor(node, markerTypes.value()) |
| + .size(); |
| } |
| unsigned Internals::activeMarkerCountForNode(Node* node) { |
| @@ -950,8 +984,9 @@ DocumentMarker* Internals::markerAt(Node* node, |
| unsigned index, |
| ExceptionState& exceptionState) { |
| ASSERT(node); |
| - DocumentMarker::MarkerTypes markerTypes = 0; |
| - if (!markerTypesFrom(markerType, markerTypes)) { |
| + WTF::Optional<DocumentMarker::MarkerTypes> markerTypes = |
| + markerTypesFrom(markerType); |
| + if (!markerTypes) { |
| exceptionState.throwDOMException( |
| SyntaxError, |
| "The marker type provided ('" + markerType + "') is invalid."); |
| @@ -959,7 +994,7 @@ DocumentMarker* Internals::markerAt(Node* node, |
| } |
| DocumentMarkerVector markers = |
| - node->document().markers().markersFor(node, markerTypes); |
| + node->document().markers().markersFor(node, markerTypes.value()); |
| if (markers.size() <= index) |
| return 0; |
| return markers[index]; |
| @@ -1826,6 +1861,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(); |