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

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

Issue 2763893002: [WIP] Clean up DocumentMarkerController API (Closed)
Patch Set: Created 3 years, 9 months 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 944 matching lines...) Expand 10 before | Expand all | Expand 10 after
955 } 955 }
956 956
957 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType); 957 WTF::Optional<DocumentMarker::MarkerType> type = markerTypeFrom(markerType);
958 if (!type) { 958 if (!type) {
959 exceptionState.throwDOMException( 959 exceptionState.throwDOMException(
960 SyntaxError, 960 SyntaxError,
961 "The marker type provided ('" + markerType + "') is invalid."); 961 "The marker type provided ('" + markerType + "') is invalid.");
962 return; 962 return;
963 } 963 }
964 964
965 // Grammar and Spelling markers are the only marker types that can be set with
966 // just a range
967 if (type != DocumentMarker::Grammar && type != DocumentMarker::Spelling) {
968 exceptionState.throwDOMException(
969 SyntaxError,
970 "Marker of type '" + markerType +
971 "' was provided; type must be either Grammar or Spelling.");
972 return;
973 }
974
965 document->updateStyleAndLayoutIgnorePendingStylesheets(); 975 document->updateStyleAndLayoutIgnorePendingStylesheets();
966 document->markers().addMarker(range->startPosition(), range->endPosition(), 976
967 type.value()); 977 if (type == DocumentMarker::Grammar) {
978 document->markers().addGrammarMarker(range->startPosition(),
979 range->endPosition());
980 } else {
981 document->markers().addSpellingMarker(range->startPosition(),
982 range->endPosition());
983 }
968 } 984 }
969 985
970 unsigned Internals::markerCountForNode(Node* node, 986 unsigned Internals::markerCountForNode(Node* node,
971 const String& markerType, 987 const String& markerType,
972 ExceptionState& exceptionState) { 988 ExceptionState& exceptionState) {
973 DCHECK(node); 989 DCHECK(node);
974 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes = 990 WTF::Optional<DocumentMarker::MarkerTypes> markerTypes =
975 markerTypesFrom(markerType); 991 markerTypesFrom(markerType);
976 if (!markerTypes) { 992 if (!markerTypes) {
977 exceptionState.throwDOMException( 993 exceptionState.throwDOMException(
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 return String(); 1061 return String();
1046 return marker->description(); 1062 return marker->description();
1047 } 1063 }
1048 1064
1049 void Internals::addTextMatchMarker(const Range* range, bool isActive) { 1065 void Internals::addTextMatchMarker(const Range* range, bool isActive) {
1050 DCHECK(range); 1066 DCHECK(range);
1051 if (!range->ownerDocument().view()) 1067 if (!range->ownerDocument().view())
1052 return; 1068 return;
1053 1069
1054 range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets(); 1070 range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
1055 range->ownerDocument().markers().addTextMatchMarker(EphemeralRange(range), 1071 range->ownerDocument().markers().addTextMatchMarker(
1056 isActive); 1072 range->startPosition(), range->endPosition(), isActive);
1057 1073
1058 // This simulates what the production code does after 1074 // This simulates what the production code does after
1059 // DocumentMarkerController::addTextMatchMarker(). 1075 // DocumentMarkerController::addTextMatchMarker().
1060 range->ownerDocument().view()->invalidatePaintForTickmarks(); 1076 range->ownerDocument().view()->invalidatePaintForTickmarks();
1061 } 1077 }
1062 1078
1063 static bool parseColor(const String& value, 1079 static bool parseColor(const String& value,
1064 Color& color, 1080 Color& color,
1065 ExceptionState& exceptionState, 1081 ExceptionState& exceptionState,
1066 String errorMessage) { 1082 String errorMessage) {
(...skipping 22 matching lines...) Expand all
1089 range->startPosition(), range->endPosition(), underlineColor, thick, 1105 range->startPosition(), range->endPosition(), underlineColor, thick,
1090 backgroundColor); 1106 backgroundColor);
1091 } 1107 }
1092 } 1108 }
1093 1109
1094 void Internals::setMarkersActive(Node* node, 1110 void Internals::setMarkersActive(Node* node,
1095 unsigned startOffset, 1111 unsigned startOffset,
1096 unsigned endOffset, 1112 unsigned endOffset,
1097 bool active) { 1113 bool active) {
1098 DCHECK(node); 1114 DCHECK(node);
1099 node->document().markers().setMarkersActive(node, startOffset, endOffset, 1115 node->document().markers().setTextMatchMarkersActive(node, startOffset,
1100 active); 1116 endOffset, active);
1101 } 1117 }
1102 1118
1103 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, 1119 void Internals::setMarkedTextMatchesAreHighlighted(Document* document,
1104 bool highlight) { 1120 bool highlight) {
1105 if (!document || !document->frame()) 1121 if (!document || !document->frame())
1106 return; 1122 return;
1107 1123
1108 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight); 1124 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
1109 } 1125 }
1110 1126
(...skipping 2115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3226 3242
3227 void Internals::crash() { 3243 void Internals::crash() {
3228 CHECK(false) << "Intentional crash"; 3244 CHECK(false) << "Intentional crash";
3229 } 3245 }
3230 3246
3231 void Internals::setIsLowEndDevice(bool isLowEndDevice) { 3247 void Internals::setIsLowEndDevice(bool isLowEndDevice) {
3232 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice); 3248 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice);
3233 } 3249 }
3234 3250
3235 } // namespace blink 3251 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698