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

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

Issue 2708763002: Revert of Selection API: collapseToStart() and collapseToEnd() should recreate a Range. (Closed)
Patch Set: Created 3 years, 10 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
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/first-letter-rtc-crash-expected.txt ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after
251 251
252 // 6. Set the context object's range to newRange. 252 // 6. Set the context object's range to newRange.
253 frame()->selection().setSelection( 253 frame()->selection().setSelection(
254 SelectionInDOMTree::Builder() 254 SelectionInDOMTree::Builder()
255 .collapse(Position(node, offset)) 255 .collapse(Position(node, offset))
256 .setIsDirectional(frame()->selection().isDirectional()) 256 .setIsDirectional(frame()->selection().isDirectional())
257 .build()); 257 .build());
258 cacheRangeIfSelectionOfDocument(newRange); 258 cacheRangeIfSelectionOfDocument(newRange);
259 } 259 }
260 260
261 // https://www.w3.org/TR/selection-api/#dom-selection-collapsetoend
262 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { 261 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) {
263 if (!isAvailable()) 262 if (!isAvailable())
264 return; 263 return;
265 264
266 // The method must throw InvalidStateError exception if the context object is 265 const VisibleSelection& selection =
267 // empty. 266 frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
268 if (rangeCount() == 0) { 267
268 if (selection.isNone()) {
269 exceptionState.throwDOMException(InvalidStateError, 269 exceptionState.throwDOMException(InvalidStateError,
270 "there is no selection."); 270 "there is no selection.");
271 return; 271 return;
272 } 272 }
273 273
274 // Otherwise, it must create a new range, set both its start and end to the
275 // end of the context object's range,
276 Range* newRange = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
277 newRange->collapse(false);
278
279 // and then set the context object's range to the newly-created range.
280 SelectionInDOMTree::Builder builder; 274 SelectionInDOMTree::Builder builder;
281 builder.collapse(newRange->endPosition()); 275 builder.collapse(selection.end());
282 frame()->selection().setSelection(builder.build()); 276 frame()->selection().setSelection(builder.build());
283 cacheRangeIfSelectionOfDocument(newRange);
284 } 277 }
285 278
286 // https://www.w3.org/TR/selection-api/#dom-selection-collapsetostart
287 void DOMSelection::collapseToStart(ExceptionState& exceptionState) { 279 void DOMSelection::collapseToStart(ExceptionState& exceptionState) {
288 if (!isAvailable()) 280 if (!isAvailable())
289 return; 281 return;
290 282
291 // The method must throw InvalidStateError ([DOM4]) exception if the context 283 const VisibleSelection& selection =
292 // object is empty. 284 frame()->selection().computeVisibleSelectionInDOMTreeDeprecated();
293 if (rangeCount() == 0) { 285
286 if (selection.isNone()) {
294 exceptionState.throwDOMException(InvalidStateError, 287 exceptionState.throwDOMException(InvalidStateError,
295 "there is no selection."); 288 "there is no selection.");
296 return; 289 return;
297 } 290 }
298 291
299 // Otherwise, it must create a new range, set both its start and end to the
300 // start of the context object's range,
301 Range* newRange = getRangeAt(0, ASSERT_NO_EXCEPTION)->cloneRange();
302 newRange->collapse(true);
303
304 // and then set the context object's range to the newly-created range.
305 SelectionInDOMTree::Builder builder; 292 SelectionInDOMTree::Builder builder;
306 builder.collapse(newRange->startPosition()); 293 builder.collapse(selection.start());
307 frame()->selection().setSelection(builder.build()); 294 frame()->selection().setSelection(builder.build());
308 cacheRangeIfSelectionOfDocument(newRange);
309 } 295 }
310 296
311 void DOMSelection::empty() { 297 void DOMSelection::empty() {
312 if (!isAvailable()) 298 if (!isAvailable())
313 return; 299 return;
314 frame()->selection().clear(); 300 frame()->selection().clear();
315 } 301 }
316 302
317 void DOMSelection::setBaseAndExtent(Node* baseNode, 303 void DOMSelection::setBaseAndExtent(Node* baseNode,
318 int baseOffset, 304 int baseOffset,
(...skipping 504 matching lines...) Expand 10 before | Expand all | Expand 10 after
823 m_treeScope->document().addConsoleMessage( 809 m_treeScope->document().addConsoleMessage(
824 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 810 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
825 } 811 }
826 812
827 DEFINE_TRACE(DOMSelection) { 813 DEFINE_TRACE(DOMSelection) {
828 visitor->trace(m_treeScope); 814 visitor->trace(m_treeScope);
829 ContextClient::trace(visitor); 815 ContextClient::trace(visitor);
830 } 816 }
831 817
832 } // namespace blink 818 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/css/first-letter-rtc-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698