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

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

Issue 2801483002: Add DocumentMarker::MatchStatus enum for text match markers (Closed)
Patch Set: Update tests Created 3 years, 8 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 936 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 unsigned Internals::activeMarkerCountForNode(Node* node) { 947 unsigned Internals::activeMarkerCountForNode(Node* node) {
948 DCHECK(node); 948 DCHECK(node);
949 949
950 // Only TextMatch markers can be active. 950 // Only TextMatch markers can be active.
951 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch; 951 DocumentMarker::MarkerType markerType = DocumentMarker::TextMatch;
952 DocumentMarkerVector markers = 952 DocumentMarkerVector markers =
953 node->document().markers().markersFor(node, markerType); 953 node->document().markers().markersFor(node, markerType);
954 954
955 unsigned activeMarkerCount = 0; 955 unsigned activeMarkerCount = 0;
956 for (const auto& marker : markers) { 956 for (const auto& marker : markers) {
957 if (marker->activeMatch()) 957 if (marker->activeMatch() == DocumentMarker::MatchStatus::Active)
958 activeMarkerCount++; 958 activeMarkerCount++;
959 } 959 }
960 960
961 return activeMarkerCount; 961 return activeMarkerCount;
962 } 962 }
963 963
964 DocumentMarker* Internals::markerAt(Node* node, 964 DocumentMarker* Internals::markerAt(Node* node,
965 const String& markerType, 965 const String& markerType,
966 unsigned index, 966 unsigned index,
967 ExceptionState& exceptionState) { 967 ExceptionState& exceptionState) {
(...skipping 29 matching lines...) Expand all
997 String Internals::markerDescriptionForNode(Node* node, 997 String Internals::markerDescriptionForNode(Node* node,
998 const String& markerType, 998 const String& markerType,
999 unsigned index, 999 unsigned index,
1000 ExceptionState& exceptionState) { 1000 ExceptionState& exceptionState) {
1001 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState); 1001 DocumentMarker* marker = markerAt(node, markerType, index, exceptionState);
1002 if (!marker) 1002 if (!marker)
1003 return String(); 1003 return String();
1004 return marker->description(); 1004 return marker->description();
1005 } 1005 }
1006 1006
1007 void Internals::addTextMatchMarker(const Range* range, bool isActive) { 1007 static WTF::Optional<DocumentMarker::MatchStatus> matchStatusFrom(
1008 const String& matchStatus) {
1009 if (equalIgnoringCase(matchStatus, "Active"))
1010 return DocumentMarker::MatchStatus::Active;
1011 if (equalIgnoringCase(matchStatus, "Inactive"))
1012 return DocumentMarker::MatchStatus::Inactive;
1013 return WTF::nullopt;
1014 }
1015
1016 void Internals::addTextMatchMarker(const Range* range,
1017 const String& matchStatus,
1018 ExceptionState& exceptionState) {
1008 DCHECK(range); 1019 DCHECK(range);
1009 if (!range->ownerDocument().view()) 1020 if (!range->ownerDocument().view())
1010 return; 1021 return;
1011 1022
1023 WTF::Optional<DocumentMarker::MatchStatus> matchStatusEnum =
1024 matchStatusFrom(matchStatus);
1025 if (!matchStatusEnum) {
1026 exceptionState.throwDOMException(
1027 SyntaxError,
1028 "The match status provided ('" + matchStatus + "') is invalid.");
1029 return;
1030 }
1031
1012 range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets(); 1032 range->ownerDocument().updateStyleAndLayoutIgnorePendingStylesheets();
1013 range->ownerDocument().markers().addTextMatchMarker(EphemeralRange(range), 1033 range->ownerDocument().markers().addTextMatchMarker(EphemeralRange(range),
1014 isActive); 1034 matchStatusEnum.value());
1015 1035
1016 // This simulates what the production code does after 1036 // This simulates what the production code does after
1017 // DocumentMarkerController::addTextMatchMarker(). 1037 // DocumentMarkerController::addTextMatchMarker().
1018 range->ownerDocument().view()->invalidatePaintForTickmarks(); 1038 range->ownerDocument().view()->invalidatePaintForTickmarks();
1019 } 1039 }
1020 1040
1021 static bool parseColor(const String& value, 1041 static bool parseColor(const String& value,
1022 Color& color, 1042 Color& color,
1023 ExceptionState& exceptionState, 1043 ExceptionState& exceptionState,
1024 String errorMessage) { 1044 String errorMessage) {
(...skipping 20 matching lines...) Expand all
1045 "Invalid background color.")) { 1065 "Invalid background color.")) {
1046 range->ownerDocument().markers().addCompositionMarker( 1066 range->ownerDocument().markers().addCompositionMarker(
1047 range->startPosition(), range->endPosition(), underlineColor, thick, 1067 range->startPosition(), range->endPosition(), underlineColor, thick,
1048 backgroundColor); 1068 backgroundColor);
1049 } 1069 }
1050 } 1070 }
1051 1071
1052 void Internals::setMarkersActive(Node* node, 1072 void Internals::setMarkersActive(Node* node,
1053 unsigned startOffset, 1073 unsigned startOffset,
1054 unsigned endOffset, 1074 unsigned endOffset,
1055 bool active) { 1075 const String& matchStatus,
1076 ExceptionState& exceptionState) {
1056 DCHECK(node); 1077 DCHECK(node);
1078
1079 WTF::Optional<DocumentMarker::MatchStatus> matchStatusEnum =
1080 matchStatusFrom(matchStatus);
1081 if (!matchStatusEnum) {
1082 exceptionState.throwDOMException(
1083 SyntaxError,
1084 "The match status provided ('" + matchStatus + "') is invalid.");
1085 return;
1086 }
1087
1057 node->document().markers().setMarkersActive(node, startOffset, endOffset, 1088 node->document().markers().setMarkersActive(node, startOffset, endOffset,
1058 active); 1089 matchStatusEnum.value());
1059 } 1090 }
1060 1091
1061 void Internals::setMarkedTextMatchesAreHighlighted(Document* document, 1092 void Internals::setMarkedTextMatchesAreHighlighted(Document* document,
1062 bool highlight) { 1093 bool highlight) {
1063 if (!document || !document->frame()) 1094 if (!document || !document->frame())
1064 return; 1095 return;
1065 1096
1066 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight); 1097 document->frame()->editor().setMarkedTextMatchesAreHighlighted(highlight);
1067 } 1098 }
1068 1099
(...skipping 2151 matching lines...) Expand 10 before | Expand all | Expand 10 after
3220 3251
3221 void Internals::crash() { 3252 void Internals::crash() {
3222 CHECK(false) << "Intentional crash"; 3253 CHECK(false) << "Intentional crash";
3223 } 3254 }
3224 3255
3225 void Internals::setIsLowEndDevice(bool isLowEndDevice) { 3256 void Internals::setIsLowEndDevice(bool isLowEndDevice) {
3226 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice); 3257 MemoryCoordinator::setIsLowEndDeviceForTesting(isLowEndDevice);
3227 } 3258 }
3228 3259
3229 } // namespace blink 3260 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698