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

Side by Side Diff: third_party/WebKit/Source/core/testing/Internals.cpp

Issue 2493873002: Introduce Internals#replaceMisspelled() and Internals#setMarker() (Closed)
Patch Set: yosin's comments addressed 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 unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2012 Google Inc. All rights reserved. 2 * Copyright (C) 2012 Google Inc. All rights reserved.
3 * Copyright (C) 2013 Apple Inc. All rights reserved. 3 * Copyright (C) 2013 Apple Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 ExceptionState& exceptionState) override { 165 ExceptionState& exceptionState) override {
166 if (m_index >= 5) 166 if (m_index >= 5)
167 return false; 167 return false;
168 value = m_index * m_index; 168 value = m_index * m_index;
169 return true; 169 return true;
170 } 170 }
171 }; 171 };
172 172
173 } // namespace 173 } // namespace
174 174
175 static bool markerTypesFrom(const String& markerType, 175 // return true if markerType is valid.
176 DocumentMarker::MarkerTypes& result) { 176 static bool markerTypeFrom(const String& markerType,
yosin_UTC9 2016/11/14 05:18:59 How about returning |WTF::Optional<DocumetnMarker:
177 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) 177 DocumentMarker::MarkerType& result) {
178 result = DocumentMarker::AllMarkers(); 178 if (equalIgnoringCase(markerType, "Spelling"))
179 else if (equalIgnoringCase(markerType, "Spelling"))
180 result = DocumentMarker::Spelling; 179 result = DocumentMarker::Spelling;
181 else if (equalIgnoringCase(markerType, "Grammar")) 180 else if (equalIgnoringCase(markerType, "Grammar"))
182 result = DocumentMarker::Grammar; 181 result = DocumentMarker::Grammar;
183 else if (equalIgnoringCase(markerType, "TextMatch")) 182 else if (equalIgnoringCase(markerType, "TextMatch"))
184 result = DocumentMarker::TextMatch; 183 result = DocumentMarker::TextMatch;
185 else 184 else
186 return false; 185 return false;
187 186
188 return true; 187 return true;
189 } 188 }
190 189
190 // return true if markerType is valid.
191 static bool markerTypesFrom(const String& markerType,
192 DocumentMarker::MarkerTypes& result) {
193 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) {
194 result = DocumentMarker::AllMarkers();
195 return true;
196 }
197
198 DocumentMarker::MarkerType type;
199 if (markerTypeFrom(markerType, type)) {
200 result = type;
201 return true;
202 }
203 return false;
204 }
205
191 static SpellCheckRequester* spellCheckRequester(Document* document) { 206 static SpellCheckRequester* spellCheckRequester(Document* document) {
192 if (!document || !document->frame()) 207 if (!document || !document->frame())
193 return 0; 208 return 0;
194 return &document->frame()->spellChecker().spellCheckRequester(); 209 return &document->frame()->spellChecker().spellCheckRequester();
195 } 210 }
196 211
197 static ScrollableArea* scrollableAreaForNode(Node* node) { 212 static ScrollableArea* scrollableAreaForNode(Node* node) {
198 if (!node) 213 if (!node)
199 return nullptr; 214 return nullptr;
200 215
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 ASSERT(element); 921 ASSERT(element);
907 922
908 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); 923 element->document().updateStyleAndLayoutIgnorePendingStylesheets();
909 LayoutObject* layoutObject = element->layoutObject(); 924 LayoutObject* layoutObject = element->layoutObject();
910 if (!layoutObject) 925 if (!layoutObject)
911 return ClientRect::create(); 926 return ClientRect::create();
912 return ClientRect::create( 927 return ClientRect::create(
913 layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); 928 layoutObject->absoluteBoundingBoxRectIgnoringTransforms());
914 } 929 }
915 930
931 void Internals::setMarker(Document* document,
932 const Range* range,
933 const String& markerType,
934 ExceptionState& exceptionState) {
935 if (!document) {
936 exceptionState.throwDOMException(InvalidAccessError,
937 "No context document is available.");
938 return;
939 }
940
941 DocumentMarker::MarkerType type;
942 if (!markerTypeFrom(markerType, type)) {
943 exceptionState.throwDOMException(
944 SyntaxError,
945 "The marker type provided ('" + markerType + "') is invalid.");
946 return;
947 }
948
949 document->markers().addMarker(range->startPosition(), range->endPosition(),
950 type);
951 }
952
916 unsigned Internals::markerCountForNode(Node* node, 953 unsigned Internals::markerCountForNode(Node* node,
917 const String& markerType, 954 const String& markerType,
918 ExceptionState& exceptionState) { 955 ExceptionState& exceptionState) {
919 ASSERT(node); 956 ASSERT(node);
920 DocumentMarker::MarkerTypes markerTypes = 0; 957 DocumentMarker::MarkerTypes markerTypes = 0;
921 if (!markerTypesFrom(markerType, markerTypes)) { 958 if (!markerTypesFrom(markerType, markerTypes)) {
922 exceptionState.throwDOMException( 959 exceptionState.throwDOMException(
923 SyntaxError, 960 SyntaxError,
924 "The marker type provided ('" + markerType + "') is invalid."); 961 "The marker type provided ('" + markerType + "') is invalid.");
925 return 0; 962 return 0;
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 InvalidAccessError, 1856 InvalidAccessError,
1820 "No frame can be obtained from the provided document."); 1857 "No frame can be obtained from the provided document.");
1821 return; 1858 return;
1822 } 1859 }
1823 1860
1824 if (enabled != 1861 if (enabled !=
1825 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled()) 1862 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled())
1826 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled(); 1863 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled();
1827 } 1864 }
1828 1865
1866 void Internals::replaceMisspelled(Document* document,
1867 const String& replacement,
1868 ExceptionState& exceptionState) {
1869 if (!document || !document->frame()) {
1870 exceptionState.throwDOMException(
1871 InvalidAccessError,
1872 "No frame can be obtained from the provided document.");
1873 return;
1874 }
1875
1876 document->updateStyleAndLayoutIgnorePendingStylesheets();
1877 document->frame()->spellChecker().replaceMisspelledRange(replacement);
1878 }
1879
1829 bool Internals::canHyphenate(const AtomicString& locale) { 1880 bool Internals::canHyphenate(const AtomicString& locale) {
1830 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale)) 1881 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale))
1831 .getHyphenation(); 1882 .getHyphenation();
1832 } 1883 }
1833 1884
1834 void Internals::setMockHyphenation(const AtomicString& locale) { 1885 void Internals::setMockHyphenation(const AtomicString& locale) {
1835 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation)); 1886 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation));
1836 } 1887 }
1837 1888
1838 bool Internals::isOverwriteModeEnabled(Document* document) { 1889 bool Internals::isOverwriteModeEnabled(Document* document) {
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 return ClientRect::create(); 3086 return ClientRect::create();
3036 3087
3037 return ClientRect::create(FloatRect(node->layoutObject()->visualRect())); 3088 return ClientRect::create(FloatRect(node->layoutObject()->visualRect()));
3038 } 3089 }
3039 3090
3040 void Internals::crash() { 3091 void Internals::crash() {
3041 CHECK(false) << "Intentional crash"; 3092 CHECK(false) << "Intentional crash";
3042 } 3093 }
3043 3094
3044 } // namespace blink 3095 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/testing/Internals.h ('k') | third_party/WebKit/Source/core/testing/Internals.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698