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

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

Issue 1377963004: Use FrameSelection::selectedText where possible. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Check whether selection is range. Created 5 years, 2 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) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 1083 matching lines...) Expand 10 before | Expand all | Expand 10 after
1094 } 1094 }
1095 1095
1096 if (caretBrowsing) 1096 if (caretBrowsing)
1097 m_frame->page()->focusController().setFocusedElement(0, m_frame); 1097 m_frame->page()->focusController().setFocusedElement(0, m_frame);
1098 } 1098 }
1099 1099
1100 template <typename Strategy> 1100 template <typename Strategy>
1101 String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato rBehavior behavior) 1101 String extractSelectedTextAlgorithm(const FrameSelection& selection, TextIterato rBehavior behavior)
1102 { 1102 {
1103 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>(); 1103 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>();
1104 if (!visibleSelection.isRange())
yosin_UTC9 2015/10/06 05:41:51 I think it is easier to make |normalizeRange()| to
kotenkov 2015/10/06 12:29:23 Actually, now the problem is not in |normalizeRang
yosin_UTC9 2015/10/15 07:45:46 Let's make both |normalizeRange()| and |createMark
1105 return String();
1104 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange(); 1106 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange();
1105 // We remove '\0' characters because they are not visibly rendered to the us er. 1107 // We remove '\0' characters because they are not visibly rendered to the us er.
1106 return plainText(range, behavior).replace(0, ""); 1108 return plainText(range, behavior).replace(0, "");
1107 } 1109 }
1108 1110
1109 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior) 1111 static String extractSelectedText(const FrameSelection& selection, TextIteratorB ehavior behavior)
1110 { 1112 {
1111 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) 1113 if (RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
1112 return extractSelectedTextAlgorithm<EditingInComposedTreeStrategy>(selec tion, behavior); 1114 return extractSelectedTextAlgorithm<EditingInComposedTreeStrategy>(selec tion, behavior);
1113 return extractSelectedTextAlgorithm<EditingStrategy>(selection, behavior); 1115 return extractSelectedTextAlgorithm<EditingStrategy>(selection, behavior);
1114 } 1116 }
1115 1117
1116 template <typename Strategy> 1118 template <typename Strategy>
1117 static String extractSelectedHTMLAlgorithm(const FrameSelection& selection) 1119 static String extractSelectedHTMLAlgorithm(const FrameSelection& selection)
1118 { 1120 {
1119 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>(); 1121 const VisibleSelectionTemplate<Strategy> visibleSelection = selection.visibl eSelection<Strategy>();
1122 if (!visibleSelection.isRange())
1123 return String();
1120 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange(); 1124 const EphemeralRangeTemplate<Strategy> range = visibleSelection.toNormalized EphemeralRange();
1121 return createMarkup(range.startPosition(), range.endPosition(), AnnotateForI nterchange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs); 1125 return createMarkup(range.startPosition(), range.endPosition(), AnnotateForI nterchange, ConvertBlocksToInlines::NotConvert, ResolveNonLocalURLs);
1122 } 1126 }
1123 1127
1124 String FrameSelection::selectedHTMLForClipboard() const 1128 String FrameSelection::selectedHTMLForClipboard() const
1125 { 1129 {
1126 if (!RuntimeEnabledFeatures::selectionForComposedTreeEnabled()) 1130 if (!RuntimeEnabledFeatures::selectionForComposedTreeEnabled())
1127 return extractSelectedHTMLAlgorithm<EditingStrategy>(*this); 1131 return extractSelectedHTMLAlgorithm<EditingStrategy>(*this);
1128 return extractSelectedHTMLAlgorithm<EditingInComposedTreeStrategy>(*this); 1132 return extractSelectedHTMLAlgorithm<EditingInComposedTreeStrategy>(*this);
1129 } 1133 }
1130 1134
1131 String FrameSelection::selectedText() const 1135 String FrameSelection::selectedText(TextIteratorBehavior behavior) const
1132 { 1136 {
1133 return extractSelectedText(*this, TextIteratorDefaultBehavior); 1137 return extractSelectedText(*this, behavior);
1134 } 1138 }
1135 1139
1136 String FrameSelection::selectedTextForClipboard() const 1140 String FrameSelection::selectedTextForClipboard() const
1137 { 1141 {
1138 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t()) 1142 if (m_frame->settings() && m_frame->settings()->selectionIncludesAltImageTex t())
1139 return extractSelectedText(*this, TextIteratorEmitsImageAltText); 1143 return extractSelectedText(*this, TextIteratorEmitsImageAltText);
1140 return selectedText(); 1144 return selectedText();
1141 } 1145 }
1142 1146
1143 LayoutRect FrameSelection::bounds() const 1147 LayoutRect FrameSelection::bounds() const
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1393 1397
1394 void showTree(const blink::FrameSelection* sel) 1398 void showTree(const blink::FrameSelection* sel)
1395 { 1399 {
1396 if (sel) 1400 if (sel)
1397 sel->showTreeForThis(); 1401 sel->showTreeForThis();
1398 else 1402 else
1399 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); 1403 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n");
1400 } 1404 }
1401 1405
1402 #endif 1406 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/core/html/HTMLTextAreaElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698