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

Side by Side Diff: third_party/WebKit/Source/core/editing/spellcheck/SpellChecker.cpp

Issue 2966223003: [SelectMisspellingAsync #1] Move SelectMisspellingAsync() from ContextMenuClient.cpp to SpellChecker (Closed)
Patch Set: Rebase Created 3 years, 5 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) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 // TODO(yosin): We should fix |startOfWord()| and |endOfWord()| not to return 87 // TODO(yosin): We should fix |startOfWord()| and |endOfWord()| not to return
88 // null position. 88 // null position.
89 const VisiblePosition& start = StartOfWord(position, kLeftWordIfOnBoundary); 89 const VisiblePosition& start = StartOfWord(position, kLeftWordIfOnBoundary);
90 const VisiblePosition& end = EndOfWord(position, kRightWordIfOnBoundary); 90 const VisiblePosition& end = EndOfWord(position, kRightWordIfOnBoundary);
91 return SelectionInDOMTree::Builder() 91 return SelectionInDOMTree::Builder()
92 .SetBaseAndExtentDeprecated(start.DeepEquivalent(), end.DeepEquivalent()) 92 .SetBaseAndExtentDeprecated(start.DeepEquivalent(), end.DeepEquivalent())
93 .SetAffinity(start.Affinity()) 93 .SetAffinity(start.Affinity())
94 .Build(); 94 .Build();
95 } 95 }
96 96
97 static bool IsWhiteSpaceOrPunctuation(UChar c) {
98 return IsSpaceOrNewline(c) || WTF::Unicode::IsPunct(c);
99 }
100
97 } // namespace 101 } // namespace
98 102
99 SpellChecker* SpellChecker::Create(LocalFrame& frame) { 103 SpellChecker* SpellChecker::Create(LocalFrame& frame) {
100 return new SpellChecker(frame); 104 return new SpellChecker(frame);
101 } 105 }
102 106
103 static SpellCheckerClient& GetEmptySpellCheckerClient() { 107 static SpellCheckerClient& GetEmptySpellCheckerClient() {
104 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ()); 108 DEFINE_STATIC_LOCAL(EmptySpellCheckerClient, client, ());
105 return client; 109 return client;
106 } 110 }
(...skipping 753 matching lines...) Expand 10 before | Expand all | Expand 10 after
860 DocumentMarker* const marker = 864 DocumentMarker* const marker =
861 GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange( 865 GetFrame().GetDocument()->Markers().FirstMarkerIntersectingOffsetRange(
862 ToText(*selection_start_container), selection_start_offset, 866 ToText(*selection_start_container), selection_start_offset,
863 selection_end_offset, DocumentMarker::MisspellingMarkers()); 867 selection_end_offset, DocumentMarker::MisspellingMarkers());
864 if (!marker) 868 if (!marker)
865 return Optional<std::pair<Node*, SpellCheckMarker*>>(); 869 return Optional<std::pair<Node*, SpellCheckMarker*>>();
866 870
867 return std::make_pair(selection_start_container, ToSpellCheckMarker(marker)); 871 return std::make_pair(selection_start_container, ToSpellCheckMarker(marker));
868 } 872 }
869 873
874 String SpellChecker::SelectMisspellingAsync(String& description) {
875 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker =
876 GetSpellCheckMarkerUnderSelection();
877 if (!node_and_marker)
878 return String();
879
880 Node* const marker_node = node_and_marker.value().first;
881 const SpellCheckMarker* const marker = node_and_marker.value().second;
882 description = marker->Description();
883
884 Range* const marker_range =
885 Range::Create(*GetFrame().GetDocument(), marker_node,
886 marker->StartOffset(), marker_node, marker->EndOffset());
887
888 VisibleSelection selection =
889 GetFrame().Selection().ComputeVisibleSelectionInDOMTree();
890 // Caret and range selections (one of which we must have since we found a
891 // marker) always return valid normalized ranges.
892 const EphemeralRange& selection_range =
893 selection.ToNormalizedEphemeralRange();
894
895 if (marker_range->GetText().StripWhiteSpace(&IsWhiteSpaceOrPunctuation) !=
896 CreateRange(selection_range)
897 ->GetText()
898 .StripWhiteSpace(&IsWhiteSpaceOrPunctuation))
899 return String();
900
901 return marker_range->GetText();
902 }
903
870 void SpellChecker::ReplaceMisspelledRange(const String& text) { 904 void SpellChecker::ReplaceMisspelledRange(const String& text) {
871 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker = 905 const Optional<std::pair<Node*, SpellCheckMarker*>>& node_and_marker =
872 GetSpellCheckMarkerUnderSelection(); 906 GetSpellCheckMarkerUnderSelection();
873 if (!node_and_marker) 907 if (!node_and_marker)
874 return; 908 return;
875 909
876 Node* const container_node = node_and_marker.value().first; 910 Node* const container_node = node_and_marker.value().first;
877 const SpellCheckMarker* const marker = node_and_marker.value().second; 911 const SpellCheckMarker* const marker = node_and_marker.value().second;
878 912
879 GetFrame().Selection().SetSelection( 913 GetFrame().Selection().SetSelection(
(...skipping 384 matching lines...) Expand 10 before | Expand all | Expand 10 after
1264 if (!input.IsFocusedElementInDocument()) 1298 if (!input.IsFocusedElementInDocument())
1265 return false; 1299 return false;
1266 } 1300 }
1267 } 1301 }
1268 HTMLElement* element = 1302 HTMLElement* element =
1269 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode()); 1303 Traversal<HTMLElement>::FirstAncestorOrSelf(*position.AnchorNode());
1270 return element && element->IsSpellCheckingEnabled(); 1304 return element && element->IsSpellCheckingEnabled();
1271 } 1305 }
1272 1306
1273 } // namespace blink 1307 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698