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

Side by Side Diff: Source/core/editing/VisibleSelection.cpp

Issue 1328493002: Move static member function normalizeRange() out from VisibleSelection (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: 2015-09-01T16:34:49 Created 5 years, 3 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, 2005, 2006 Apple Computer, Inc. All rights reserved. 2 * Copyright (C) 2004, 2005, 2006 Apple Computer, 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 223
224 PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection& selection) 224 PassRefPtrWillBeRawPtr<Range> firstRangeOf(const VisibleSelection& selection)
225 { 225 {
226 if (selection.isNone()) 226 if (selection.isNone())
227 return nullptr; 227 return nullptr;
228 Position start = selection.start().parentAnchoredEquivalent(); 228 Position start = selection.start().parentAnchoredEquivalent();
229 Position end = selection.end().parentAnchoredEquivalent(); 229 Position end = selection.end().parentAnchoredEquivalent();
230 return Range::create(*start.document(), start, end); 230 return Range::create(*start.document(), start, end);
231 } 231 }
232 232
233 template <typename Strategy>
234 static EphemeralRangeTemplate<Strategy> normalizeRangeAlgorithm(const EphemeralR angeTemplate<Strategy>& range)
235 {
236 ASSERT(range.isNotNull());
237 range.document().updateLayoutIgnorePendingStylesheets();
238
239 // TODO(yosin) We should not call |parentAnchoredEquivalent()|, it is
240 // redundant.
241 const PositionAlgorithm<Strategy> normalizedStart = mostForwardCaretPosition (range.startPosition()).parentAnchoredEquivalent();
242 const PositionAlgorithm<Strategy> normalizedEnd = mostBackwardCaretPosition( range.endPosition()).parentAnchoredEquivalent();
243 // The order of the positions of |start| and |end| can be swapped after
244 // upstream/downstream. e.g. editing/pasteboard/copy-display-none.html
245 if (normalizedStart.compareTo(normalizedEnd) > 0)
246 return EphemeralRangeTemplate<Strategy>(normalizedEnd, normalizedStart);
247 return EphemeralRangeTemplate<Strategy>(normalizedStart, normalizedEnd);
248 }
249
250 EphemeralRange VisibleSelection::normalizeRange(const EphemeralRange& range)
251 {
252 return normalizeRangeAlgorithm<EditingStrategy>(range);
253 }
254
255 EphemeralRangeInComposedTree VisibleSelection::normalizeRange(const EphemeralRan geInComposedTree& range)
256 {
257 return normalizeRangeAlgorithm<EditingInComposedTreeStrategy>(range);
258 }
259
260 EphemeralRange VisibleSelection::toNormalizedEphemeralRange() const 233 EphemeralRange VisibleSelection::toNormalizedEphemeralRange() const
261 { 234 {
262 if (isNone()) 235 if (isNone())
263 return EphemeralRange(); 236 return EphemeralRange();
264 237
265 // Make sure we have an updated layout since this function is called 238 // Make sure we have an updated layout since this function is called
266 // in the course of running edit commands which modify the DOM. 239 // in the course of running edit commands which modify the DOM.
267 // Failing to call this can result in equivalentXXXPosition calls returning 240 // Failing to call this can result in equivalentXXXPosition calls returning
268 // incorrect results. 241 // incorrect results.
269 m_start.document()->updateLayout(); 242 m_start.document()->updateLayout();
(...skipping 977 matching lines...) Expand 10 before | Expand all | Expand 10 after
1247 sel.showTreeForThis(); 1220 sel.showTreeForThis();
1248 } 1221 }
1249 1222
1250 void showTree(const blink::VisibleSelection* sel) 1223 void showTree(const blink::VisibleSelection* sel)
1251 { 1224 {
1252 if (sel) 1225 if (sel)
1253 sel->showTreeForThis(); 1226 sel->showTreeForThis();
1254 } 1227 }
1255 1228
1256 #endif 1229 #endif
OLDNEW
« no previous file with comments | « Source/core/editing/VisibleSelection.h ('k') | Source/core/editing/serializers/Serialization.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698