Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 | |
|
yosin_UTC9
2016/11/15 02:14:06
nit: Please get rid of an extra blank line.
| |
| 185 return WTF::nullopt; | |
| 186 } | |
| 187 | |
| 188 static WTF::Optional<DocumentMarker::MarkerTypes> markerTypesFrom( | |
| 189 const String& markerType) { | |
| 177 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) | 190 if (markerType.isEmpty() || equalIgnoringCase(markerType, "all")) |
| 178 result = DocumentMarker::AllMarkers(); | 191 return DocumentMarker::AllMarkers(); |
| 179 else if (equalIgnoringCase(markerType, "Spelling")) | 192 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType); |
| 180 result = DocumentMarker::Spelling; | 193 if (type) |
| 181 else if (equalIgnoringCase(markerType, "Grammar")) | 194 return static_cast<DocumentMarker::MarkerTypes>(type.value()); |
|
yosin_UTC9
2016/11/15 02:14:06
Can we use |DocumentMarker::MarkerTypes(type.value
| |
| 182 result = DocumentMarker::Grammar; | |
| 183 else if (equalIgnoringCase(markerType, "TextMatch")) | |
| 184 result = DocumentMarker::TextMatch; | |
| 185 else | |
| 186 return false; | |
| 187 | 195 |
| 188 return true; | 196 return WTF::nullopt; |
|
yosin_UTC9
2016/11/15 02:14:06
It is more readable switching if-condition:
if (!
| |
| 189 } | 197 } |
| 190 | 198 |
| 191 static SpellCheckRequester* spellCheckRequester(Document* document) { | 199 static SpellCheckRequester* spellCheckRequester(Document* document) { |
| 192 if (!document || !document->frame()) | 200 if (!document || !document->frame()) |
| 193 return 0; | 201 return 0; |
| 194 return &document->frame()->spellChecker().spellCheckRequester(); | 202 return &document->frame()->spellChecker().spellCheckRequester(); |
| 195 } | 203 } |
| 196 | 204 |
| 197 static ScrollableArea* scrollableAreaForNode(Node* node) { | 205 static ScrollableArea* scrollableAreaForNode(Node* node) { |
| 198 if (!node) | 206 if (!node) |
| (...skipping 707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 906 ASSERT(element); | 914 ASSERT(element); |
| 907 | 915 |
| 908 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); | 916 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); |
| 909 LayoutObject* layoutObject = element->layoutObject(); | 917 LayoutObject* layoutObject = element->layoutObject(); |
| 910 if (!layoutObject) | 918 if (!layoutObject) |
| 911 return ClientRect::create(); | 919 return ClientRect::create(); |
| 912 return ClientRect::create( | 920 return ClientRect::create( |
| 913 layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); | 921 layoutObject->absoluteBoundingBoxRectIgnoringTransforms()); |
| 914 } | 922 } |
| 915 | 923 |
| 924 void Internals::setMarker(Document* document, | |
| 925 const Range* range, | |
| 926 const String& markerType, | |
| 927 ExceptionState& exceptionState) { | |
| 928 if (!document) { | |
| 929 exceptionState.throwDOMException(InvalidAccessError, | |
| 930 "No context document is available."); | |
| 931 return; | |
| 932 } | |
| 933 | |
| 934 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType); | |
| 935 if (!type) { | |
| 936 exceptionState.throwDOMException( | |
| 937 SyntaxError, | |
| 938 "The marker type provided ('" + markerType + "') is invalid."); | |
| 939 return; | |
| 940 } | |
| 941 | |
| 942 document->markers().addMarker(range->startPosition(), range->endPosition(), | |
| 943 type.value()); | |
| 944 } | |
| 945 | |
| 916 unsigned Internals::markerCountForNode(Node* node, | 946 unsigned Internals::markerCountForNode(Node* node, |
| 917 const String& markerType, | 947 const String& markerType, |
| 918 ExceptionState& exceptionState) { | 948 ExceptionState& exceptionState) { |
| 919 ASSERT(node); | 949 ASSERT(node); |
| 920 DocumentMarker::MarkerTypes markerTypes = 0; | 950 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes = |
| 921 if (!markerTypesFrom(markerType, markerTypes)) { | 951 markerTypesFrom(markerType); |
| 952 if (!markerTypes) { | |
| 922 exceptionState.throwDOMException( | 953 exceptionState.throwDOMException( |
| 923 SyntaxError, | 954 SyntaxError, |
| 924 "The marker type provided ('" + markerType + "') is invalid."); | 955 "The marker type provided ('" + markerType + "') is invalid."); |
| 925 return 0; | 956 return 0; |
| 926 } | 957 } |
| 927 | 958 |
| 928 return node->document().markers().markersFor(node, markerTypes).size(); | 959 return node->document() |
| 960 .markers() | |
| 961 .markersFor(node, markerTypes.value()) | |
| 962 .size(); | |
| 929 } | 963 } |
| 930 | 964 |
| 931 unsigned Internals::activeMarkerCountForNode(Node* node) { | 965 unsigned Internals::activeMarkerCountForNode(Node* node) { |
| 932 ASSERT(node); | 966 ASSERT(node); |
| 933 | 967 |
| 934 // Only TextMatch markers can be active. | 968 // Only TextMatch markers can be active. |
| 935 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch; | 969 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch; |
| 936 DocumentMarkerVector markers = | 970 DocumentMarkerVector markers = |
| 937 node->document().markers().markersFor(node, markerType); | 971 node->document().markers().markersFor(node, markerType); |
| 938 | 972 |
| 939 unsigned activeMarkerCount = 0; | 973 unsigned activeMarkerCount = 0; |
| 940 for (const auto& marker : markers) { | 974 for (const auto& marker : markers) { |
| 941 if (marker->activeMatch()) | 975 if (marker->activeMatch()) |
| 942 activeMarkerCount++; | 976 activeMarkerCount++; |
| 943 } | 977 } |
| 944 | 978 |
| 945 return activeMarkerCount; | 979 return activeMarkerCount; |
| 946 } | 980 } |
| 947 | 981 |
| 948 DocumentMarker* Internals::markerAt(Node* node, | 982 DocumentMarker* Internals::markerAt(Node* node, |
| 949 const String& markerType, | 983 const String& markerType, |
| 950 unsigned index, | 984 unsigned index, |
| 951 ExceptionState& exceptionState) { | 985 ExceptionState& exceptionState) { |
| 952 ASSERT(node); | 986 ASSERT(node); |
| 953 DocumentMarker::MarkerTypes markerTypes = 0; | 987 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes = |
| 954 if (!markerTypesFrom(markerType, markerTypes)) { | 988 markerTypesFrom(markerType); |
| 989 if (!markerTypes) { | |
| 955 exceptionState.throwDOMException( | 990 exceptionState.throwDOMException( |
| 956 SyntaxError, | 991 SyntaxError, |
| 957 "The marker type provided ('" + markerType + "') is invalid."); | 992 "The marker type provided ('" + markerType + "') is invalid."); |
| 958 return 0; | 993 return 0; |
| 959 } | 994 } |
| 960 | 995 |
| 961 DocumentMarkerVector markers = | 996 DocumentMarkerVector markers = |
| 962 node->document().markers().markersFor(node, markerTypes); | 997 node->document().markers().markersFor(node, markerTypes.value()); |
| 963 if (markers.size() <= index) | 998 if (markers.size() <= index) |
| 964 return 0; | 999 return 0; |
| 965 return markers[index]; | 1000 return markers[index]; |
| 966 } | 1001 } |
| 967 | 1002 |
| 968 Range* Internals::markerRangeForNode(Node* node, | 1003 Range* Internals::markerRangeForNode(Node* node, |
| 969 const String& markerType, | 1004 const String& markerType, |
| 970 unsigned index, | 1005 unsigned index, |
| 971 ExceptionState& exceptionState) { | 1006 ExceptionState& exceptionState) { |
| 972 ASSERT(node); | 1007 ASSERT(node); |
| (...skipping 846 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1819 InvalidAccessError, | 1854 InvalidAccessError, |
| 1820 "No frame can be obtained from the provided document."); | 1855 "No frame can be obtained from the provided document."); |
| 1821 return; | 1856 return; |
| 1822 } | 1857 } |
| 1823 | 1858 |
| 1824 if (enabled != | 1859 if (enabled != |
| 1825 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled()) | 1860 contextDocument()->frame()->spellChecker().isSpellCheckingEnabled()) |
| 1826 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled(); | 1861 contextDocument()->frame()->spellChecker().toggleSpellCheckingEnabled(); |
| 1827 } | 1862 } |
| 1828 | 1863 |
| 1864 void Internals::replaceMisspelled(Document* document, | |
| 1865 const String& replacement, | |
| 1866 ExceptionState& exceptionState) { | |
| 1867 if (!document || !document->frame()) { | |
| 1868 exceptionState.throwDOMException( | |
| 1869 InvalidAccessError, | |
| 1870 "No frame can be obtained from the provided document."); | |
| 1871 return; | |
| 1872 } | |
| 1873 | |
| 1874 document->updateStyleAndLayoutIgnorePendingStylesheets(); | |
| 1875 document->frame()->spellChecker().replaceMisspelledRange(replacement); | |
| 1876 } | |
| 1877 | |
| 1829 bool Internals::canHyphenate(const AtomicString& locale) { | 1878 bool Internals::canHyphenate(const AtomicString& locale) { |
| 1830 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale)) | 1879 return LayoutLocale::valueOrDefault(LayoutLocale::get(locale)) |
| 1831 .getHyphenation(); | 1880 .getHyphenation(); |
| 1832 } | 1881 } |
| 1833 | 1882 |
| 1834 void Internals::setMockHyphenation(const AtomicString& locale) { | 1883 void Internals::setMockHyphenation(const AtomicString& locale) { |
| 1835 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation)); | 1884 LayoutLocale::setHyphenationForTesting(locale, adoptRef(new MockHyphenation)); |
| 1836 } | 1885 } |
| 1837 | 1886 |
| 1838 bool Internals::isOverwriteModeEnabled(Document* document) { | 1887 bool Internals::isOverwriteModeEnabled(Document* document) { |
| (...skipping 1196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3035 return ClientRect::create(); | 3084 return ClientRect::create(); |
| 3036 | 3085 |
| 3037 return ClientRect::create(FloatRect(node->layoutObject()->visualRect())); | 3086 return ClientRect::create(FloatRect(node->layoutObject()->visualRect())); |
| 3038 } | 3087 } |
| 3039 | 3088 |
| 3040 void Internals::crash() { | 3089 void Internals::crash() { |
| 3041 CHECK(false) << "Intentional crash"; | 3090 CHECK(false) << "Intentional crash"; |
| 3042 } | 3091 } |
| 3043 | 3092 |
| 3044 } // namespace blink | 3093 } // namespace blink |
| OLD | NEW |