Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(710)

Unified Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2493873002: Introduce Internals#replaceMisspelled() and Internals#setMarker() (Closed)
Patch Set: add layout test Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..0a35347409f0aa6987a906104d0c253aad980367 100644
--- a/third_party/WebKit/Source/core/testing/Internals.cpp
+++ b/third_party/WebKit/Source/core/testing/Internals.cpp
@@ -172,11 +172,9 @@ 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"))
+static bool markerTypeFrom(const String& markerType,
+ DocumentMarker::MarkerType& result) {
+ if (equalIgnoringCase(markerType, "Spelling"))
result = DocumentMarker::Spelling;
else if (equalIgnoringCase(markerType, "Grammar"))
result = DocumentMarker::Grammar;
@@ -188,6 +186,19 @@ static bool markerTypesFrom(const String& markerType,
return true;
}
+static bool markerTypesFrom(const String& markerType,
yosin_UTC9 2016/11/14 02:28:17 Please add a comment for meaning of |bool| return
+ DocumentMarker::MarkerTypes& result) {
+ DocumentMarker::MarkerType type;
+ if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
yosin_UTC9 2016/11/14 02:28:17 should be early return style if (markerType.isEm
+ result = DocumentMarker::AllMarkers();
+ else if (markerTypeFrom(markerType, type))
+ result = type;
+ else
+ return false;
+
+ return true;
+}
+
static SpellCheckRequester* spellCheckRequester(Document* document) {
if (!document || !document->frame())
return 0;
@@ -913,6 +924,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 +1859,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();

Powered by Google App Engine
This is Rietveld 408576698