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

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

Issue 2493873002: Introduce Internals#replaceMisspelled() and Internals#setMarker() (Closed)
Patch Set: for yosin's nit 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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 #include "platform/scroll/ProgrammaticScrollAnimator.h" 139 #include "platform/scroll/ProgrammaticScrollAnimator.h"
140 #include "platform/testing/URLTestHelpers.h" 140 #include "platform/testing/URLTestHelpers.h"
141 #include "platform/tracing/TraceEvent.h" 141 #include "platform/tracing/TraceEvent.h"
142 #include "platform/weborigin/SchemeRegistry.h" 142 #include "platform/weborigin/SchemeRegistry.h"
143 #include "public/platform/Platform.h" 143 #include "public/platform/Platform.h"
144 #include "public/platform/WebConnectionType.h" 144 #include "public/platform/WebConnectionType.h"
145 #include "public/platform/WebGraphicsContext3DProvider.h" 145 #include "public/platform/WebGraphicsContext3DProvider.h"
146 #include "public/platform/WebLayer.h" 146 #include "public/platform/WebLayer.h"
147 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h " 147 #include "public/platform/modules/remoteplayback/WebRemotePlaybackAvailability.h "
148 #include "wtf/InstanceCounter.h" 148 #include "wtf/InstanceCounter.h"
149 #include "wtf/Optional.h"
149 #include "wtf/PtrUtil.h" 150 #include "wtf/PtrUtil.h"
150 #include "wtf/dtoa.h" 151 #include "wtf/dtoa.h"
151 #include "wtf/text/StringBuffer.h" 152 #include "wtf/text/StringBuffer.h"
152 #include <deque> 153 #include <deque>
153 #include <memory> 154 #include <memory>
154 #include <v8.h> 155 #include <v8.h>
155 156
156 namespace blink { 157 namespace blink {
157 158
158 namespace { 159 namespace {
159 160
160 class InternalsIterationSource final 161 class InternalsIterationSource final
161 : public ValueIterable<int>::IterationSource { 162 : public ValueIterable<int>::IterationSource {
162 public: 163 public:
163 bool next(ScriptState* scriptState, 164 bool next(ScriptState* scriptState,
164 int& value, 165 int& value,
165 ExceptionState& exceptionState) override { 166 ExceptionState& exceptionState) override {
166 if (m_index >= 5) 167 if (m_index >= 5)
167 return false; 168 return false;
168 value = m_index * m_index; 169 value = m_index * m_index;
169 return true; 170 return true;
170 } 171 }
171 }; 172 };
172 173
173 } // namespace 174 } // namespace
174 175
175 static bool markerTypesFrom(const String& markerType, 176 static WTF::Optional<DocumentMarker::MarkerType> markerTypeFrom(
176 DocumentMarker::MarkerTypes& result) { 177 const String& markerType) {
178 if (equalIgnoringCase(markerType, "Spelling"))
179 return DocumentMarker::Spelling;
180 if (equalIgnoringCase(markerType, "Grammar"))
181 return DocumentMarker::Grammar;
182 if (equalIgnoringCase(markerType, "TextMatch"))
183 return DocumentMarker::TextMatch;
184 return WTF::nullopt;
185 }
186
187 static WTF::Optional<DocumentMarker::MarkerTypes> markerTypesFrom(
188 const String& markerType) {
177 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) 189 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all"))
178 result = DocumentMarker::AllMarkers(); 190 return DocumentMarker::AllMarkers();
179 else if (equalIgnoringCase(markerType, "Spelling")) 191 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType);
180 result = DocumentMarker::Spelling; 192 if (!type)
181 else if (equalIgnoringCase(markerType, "Grammar")) 193 return WTF::nullopt;
182 result = DocumentMarker::Grammar; 194 return DocumentMarker::MarkerTypes(type.value());
183 else if (equalIgnoringCase(markerType, "TextMatch"))
184 result = DocumentMarker::TextMatch;
185 else
186 return false;
187
188 return true;
189 } 195 }
190 196
191 static SpellCheckRequester* spellCheckRequester(Document* document) { 197 static SpellCheckRequester* spellCheckRequester(Document* document) {
192 if (!document || !document->frame()) 198 if (!document || !document->frame())
193 return 0; 199 return 0;
194 return &document->frame()->spellChecker().spellCheckRequester(); 200 return &document->frame()->spellChecker().spellCheckRequester();
195 } 201 }
196 202
197 static ScrollableArea* scrollableAreaForNode(Node* node) { 203 static ScrollableArea* scrollableAreaForNode(Node* node) {
198 if (!node) 204 if (!node)
(...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after
906 ASSERT(element); 912 ASSERT(element);
907 913
908 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); 914 element->document().updateStyleAndLayoutIgnorePendingStylesheets();
909 LayoutObject* layoutObject = element->layoutObject(); 915 LayoutObject* layoutObject = element->layoutObject();
910 if (!layoutObject) 916 if (!layoutObject)
911 return ClientRect::create(); 917 return ClientRect::create();
912 return ClientRect::create( 918 return ClientRect::create(
913 layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); 919 layoutObject->absoluteBoundingBoxRectIgnoringTransforms());
914 } 920 }
915 921
922 void Internals::setMarker(Document* document,
923 const Range* range,
924 const String& markerType,
925 ExceptionState& exceptionState) {
926 if (!document) {
927 exceptionState.throwDOMException(InvalidAccessError,
928 "No context document is available.");
929 return;
930 }
931
932 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType);
933 if (!type) {
934 exceptionState.throwDOMException(
935 SyntaxError,
936 "The marker type provided ('" + markerType + "') is invalid.");
937 return;
938 }
939
940 document->markers().addMarker(range->startPosition(), range->endPosition(),
941 type.value());
942 }
943
916 unsigned Internals::markerCountForNode(Node* node, 944 unsigned Internals::markerCountForNode(Node* node,
917 const String& markerType, 945 const String& markerType,
918 ExceptionState& exceptionState) { 946 ExceptionState& exceptionState) {
919 ASSERT(node); 947 ASSERT(node);
920 DocumentMarker::MarkerTypes markerTypes = 0; 948 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes =
921 if (!markerTypesFrom(markerType, markerTypes)) { 949 markerTypesFrom(markerType);
950 if (!markerTypes) {
922 exceptionState.throwDOMException( 951 exceptionState.throwDOMException(
923 SyntaxError, 952 SyntaxError,
924 "The marker type provided ('" + markerType + "') is invalid."); 953 "The marker type provided ('" + markerType + "') is invalid.");
925 return 0; 954 return 0;
926 } 955 }
927 956
928 return node->document().markers().markersFor(node, markerTypes).size(); 957 return node->document()
958 .markers()
959 .markersFor(node, markerTypes.value())
960 .size();
929 } 961 }
930 962
931 unsigned Internals::activeMarkerCountForNode(Node* node) { 963 unsigned Internals::activeMarkerCountForNode(Node* node) {
932 ASSERT(node); 964 ASSERT(node);
933 965
934 // Only TextMatch markers can be active. 966 // Only TextMatch markers can be active.
935 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch; 967 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
936 DocumentMarkerVector markers = 968 DocumentMarkerVector markers =
937 node->document().markers().markersFor(node, markerType); 969 node->document().markers().markersFor(node, markerType);
938 970
939 unsigned activeMarkerCount = 0; 971 unsigned activeMarkerCount = 0;
940 for (const auto& marker : markers) { 972 for (const auto& marker : markers) {
941 if (marker->activeMatch()) 973 if (marker->activeMatch())
942 activeMarkerCount++; 974 activeMarkerCount++;
943 } 975 }
944 976
945 return activeMarkerCount; 977 return activeMarkerCount;
946 } 978 }
947 979
948 DocumentMarker* Internals::markerAt(Node* node, 980 DocumentMarker* Internals::markerAt(Node* node,
949 const String& markerType, 981 const String& markerType,
950 unsigned index, 982 unsigned index,
951 ExceptionState& exceptionState) { 983 ExceptionState& exceptionState) {
952 ASSERT(node); 984 ASSERT(node);
953 DocumentMarker::MarkerTypes markerTypes = 0; 985 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes =
954 if (!markerTypesFrom(markerType, markerTypes)) { 986 markerTypesFrom(markerType);
987 if (!markerTypes) {
955 exceptionState.throwDOMException( 988 exceptionState.throwDOMException(
956 SyntaxError, 989 SyntaxError,
957 "The marker type provided ('" + markerType + "') is invalid."); 990 "The marker type provided ('" + markerType + "') is invalid.");
958 return 0; 991 return 0;
959 } 992 }
960 993
961 DocumentMarkerVector markers = 994 DocumentMarkerVector markers =
962 node->document().markers().markersFor(node, markerTypes); 995 node->document().markers().markersFor(node, markerTypes.value());
963 if (markers.size() <= index) 996 if (markers.size() <= index)
964 return 0; 997 return 0;
965 return markers[index]; 998 return markers[index];
966 } 999 }
967 1000
968 Range* Internals::markerRangeForNode(Node* node, 1001 Range* Internals::markerRangeForNode(Node* node,
969 const String& markerType, 1002 const String& markerType,
970 unsigned index, 1003 unsigned index,
971 ExceptionState& exceptionState) { 1004 ExceptionState& exceptionState) {
972 ASSERT(node); 1005 ASSERT(node);
(...skipping 846 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
« 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