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

Side by Side 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 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 static bool markerTypeFrom(const String& markerType,
176 DocumentMarker::MarkerTypes& result) { 176 DocumentMarker::MarkerType& result) {
177 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) 177 if (equalIgnoringCase(markerType, "Spelling"))
178 result = DocumentMarker::AllMarkers();
179 else if (equalIgnoringCase(markerType, "Spelling"))
180 result = DocumentMarker::Spelling; 178 result = DocumentMarker::Spelling;
181 else if (equalIgnoringCase(markerType, "Grammar")) 179 else if (equalIgnoringCase(markerType, "Grammar"))
182 result = DocumentMarker::Grammar; 180 result = DocumentMarker::Grammar;
183 else if (equalIgnoringCase(markerType, "TextMatch")) 181 else if (equalIgnoringCase(markerType, "TextMatch"))
184 result = DocumentMarker::TextMatch; 182 result = DocumentMarker::TextMatch;
185 else 183 else
186 return false; 184 return false;
187 185
188 return true; 186 return true;
189 } 187 }
190 188
189 static bool markerTypesFrom(const String& markerType,
yosin_UTC9 2016/11/14 02:28:17 Please add a comment for meaning of |bool| return
190 DocumentMarker::MarkerTypes& result) {
191 DocumentMarker::MarkerType type;
192 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
yosin_UTC9 2016/11/14 02:28:17 should be early return style if (markerType.isEm
193 result = DocumentMarker::AllMarkers();
194 else if (markerTypeFrom(markerType, type))
195 result = type;
196 else
197 return false;
198
199 return true;
200 }
201
191 static SpellCheckRequester* spellCheckRequester(Document* document) { 202 static SpellCheckRequester* spellCheckRequester(Document* document) {
192 if (!document || !document->frame()) 203 if (!document || !document->frame())
193 return 0; 204 return 0;
194 return &document->frame()->spellChecker().spellCheckRequester(); 205 return &document->frame()->spellChecker().spellCheckRequester();
195 } 206 }
196 207
197 static ScrollableArea* scrollableAreaForNode(Node* node) { 208 static ScrollableArea* scrollableAreaForNode(Node* node) {
198 if (!node) 209 if (!node)
199 return nullptr; 210 return nullptr;
200 211
(...skipping 705 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 ASSERT(element); 917 ASSERT(element);
907 918
908 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); 919 element->document().updateStyleAndLayoutIgnorePendingStylesheets();
909 LayoutObject* layoutObject = element->layoutObject(); 920 LayoutObject* layoutObject = element->layoutObject();
910 if (!layoutObject) 921 if (!layoutObject)
911 return ClientRect::create(); 922 return ClientRect::create();
912 return ClientRect::create( 923 return ClientRect::create(
913 layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); 924 layoutObject->absoluteBoundingBoxRectIgnoringTransforms());
914 } 925 }
915 926
927 void Internals::setMarker(Document* document,
928 const Range* range,
929 const String& markerType,
930 ExceptionState& exceptionState) {
931 if (!document) {
932 exceptionState.throwDOMException(InvalidAccessError,
933 "No context document is available.");
934 return;
935 }
936
937 DocumentMarker::MarkerType type;
938 if (!markerTypeFrom(markerType, type)) {
939 exceptionState.throwDOMException(
940 SyntaxError,
941 "The marker type provided ('" + markerType + "') is invalid.");
942 return;
943 }
944
945 document->markers().addMarker(range->startPosition(), range->endPosition(),
946 type);
947 }
948
916 unsigned Internals::markerCountForNode(Node* node, 949 unsigned Internals::markerCountForNode(Node* node,
917 const String& markerType, 950 const String& markerType,
918 ExceptionState& exceptionState) { 951 ExceptionState& exceptionState) {
919 ASSERT(node); 952 ASSERT(node);
920 DocumentMarker::MarkerTypes markerTypes = 0; 953 DocumentMarker::MarkerTypes markerTypes = 0;
921 if (!markerTypesFrom(markerType, markerTypes)) { 954 if (!markerTypesFrom(markerType, markerTypes)) {
922 exceptionState.throwDOMException( 955 exceptionState.throwDOMException(
923 SyntaxError, 956 SyntaxError,
924 "The marker type provided ('" + markerType + "') is invalid."); 957 "The marker type provided ('" + markerType + "') is invalid.");
925 return 0; 958 return 0;
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after
1819 InvalidAccessError, 1852 InvalidAccessError,
1820 "No frame can be obtained from the provided document."); 1853 "No frame can be obtained from the provided document.");
1821 return; 1854 return;
1822 } 1855 }
1823 1856
1824 if (enabled != 1857 if (enabled !=
1825 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled()) 1858 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled())
1826 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled(); 1859 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled();
1827 } 1860 }
1828 1861
1862 void Internals::replaceMisspelled(Document* document,
1863 const String& replacement,
1864 ExceptionState& exceptionState) {
1865 if (!document || !document->frame()) {
1866 exceptionState.throwDOMException(
1867 InvalidAccessError,
1868 "No frame can be obtained from the provided document.");
1869 return;
1870 }
1871
1872 document->updateStyleAndLayoutIgnorePendingStylesheets();
1873 document->frame()->spellChecker().replaceMisspelledRange(replacement);
1874 }
1875
1829 bool Internals::canHyphenate(const AtomicString& locale) { 1876 bool Internals::canHyphenate(const AtomicString& locale) {
1830 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale)) 1877 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale))
1831 .getHyphenation(); 1878 .getHyphenation();
1832 } 1879 }
1833 1880
1834 void Internals::setMockHyphenation(const AtomicString& locale) { 1881 void Internals::setMockHyphenation(const AtomicString& locale) {
1835 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation)); 1882 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation));
1836 } 1883 }
1837 1884
1838 bool Internals::isOverwriteModeEnabled(Document* document) { 1885 bool Internals::isOverwriteModeEnabled(Document* document) {
(...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after
3035 return ClientRect::create(); 3082 return ClientRect::create();
3036 3083
3037 return ClientRect::create(FloatRect(node->layoutObject()->visualRect())); 3084 return ClientRect::create(FloatRect(node->layoutObject()->visualRect()));
3038 } 3085 }
3039 3086
3040 void Internals::crash() { 3087 void Internals::crash() {
3041 CHECK(false) << "Intentional crash"; 3088 CHECK(false) << "Intentional crash";
3042 } 3089 }
3043 3090
3044 } // namespace blink 3091 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698