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

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

Issue 2710593002: Selection API: collapse(), setBaseAndExtent(), and extend() don't need to have code to check negati… (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
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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 // 1. If node is null, this method must behave identically as 217 // 1. If node is null, this method must behave identically as
218 // removeAllRanges() and abort these steps. 218 // removeAllRanges() and abort these steps.
219 if (!node) { 219 if (!node) {
220 UseCounter::count(frame(), UseCounter::SelectionCollapseNull); 220 UseCounter::count(frame(), UseCounter::SelectionCollapseNull);
221 frame()->selection().clear(); 221 frame()->selection().clear();
222 return; 222 return;
223 } 223 }
224 224
225 // 2. The method must throw an IndexSizeError exception if offset is longer 225 // 2. The method must throw an IndexSizeError exception if offset is longer
226 // than node's length ([DOM4]) and abort these steps. 226 // than node's length ([DOM4]) and abort these steps.
227 if (offset < 0) {
228 exceptionState.throwDOMException(
229 IndexSizeError, String::number(offset) + " is not a valid offset.");
230 return;
231 }
232 Range::checkNodeWOffset(node, offset, exceptionState); 227 Range::checkNodeWOffset(node, offset, exceptionState);
233 if (exceptionState.hadException()) 228 if (exceptionState.hadException())
234 return; 229 return;
235 230
236 // 3. If node's root is not the document associated with the context object, 231 // 3. If node's root is not the document associated with the context object,
237 // abort these steps. 232 // abort these steps.
238 if (!isValidForPosition(node)) 233 if (!isValidForPosition(node))
239 return; 234 return;
240 235
241 // 4. Otherwise, let newRange be a new range. 236 // 4. Otherwise, let newRange be a new range.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 310 }
316 311
317 void DOMSelection::setBaseAndExtent(Node* baseNode, 312 void DOMSelection::setBaseAndExtent(Node* baseNode,
318 int baseOffset, 313 int baseOffset,
319 Node* extentNode, 314 Node* extentNode,
320 int extentOffset, 315 int extentOffset,
321 ExceptionState& exceptionState) { 316 ExceptionState& exceptionState) {
322 if (!isAvailable()) 317 if (!isAvailable())
323 return; 318 return;
324 319
325 if (baseOffset < 0) {
326 exceptionState.throwDOMException(
327 IndexSizeError,
328 String::number(baseOffset) + " is not a valid base offset.");
329 return;
330 }
331
332 if (extentOffset < 0) {
333 exceptionState.throwDOMException(
334 IndexSizeError,
335 String::number(extentOffset) + " is not a valid extent offset.");
336 return;
337 }
338
339 // TODO(editing-dev): Behavior on where base or extent is null is still 320 // TODO(editing-dev): Behavior on where base or extent is null is still
340 // under discussion: https://github.com/w3c/selection-api/issues/72 321 // under discussion: https://github.com/w3c/selection-api/issues/72
341 if (!baseNode) { 322 if (!baseNode) {
342 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 323 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
343 frame()->selection().clear(); 324 frame()->selection().clear();
344 return; 325 return;
345 } 326 }
346 if (!extentNode) { 327 if (!extentNode) {
347 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 328 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
348 extentOffset = 0; 329 extentOffset = 0;
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
464 return; 445 return;
465 446
466 // 2. If the context object is empty, throw an InvalidStateError exception and 447 // 2. If the context object is empty, throw an InvalidStateError exception and
467 // abort these steps. 448 // abort these steps.
468 if (rangeCount() == 0) { 449 if (rangeCount() == 0) {
469 exceptionState.throwDOMException( 450 exceptionState.throwDOMException(
470 InvalidStateError, "This Selection object doesn't have any Ranges."); 451 InvalidStateError, "This Selection object doesn't have any Ranges.");
471 return; 452 return;
472 } 453 }
473 454
474 if (offset < 0) {
475 exceptionState.throwDOMException(
476 IndexSizeError, String::number(offset) + " is not a valid offset.");
477 return;
478 }
479 Range::checkNodeWOffset(node, offset, exceptionState); 455 Range::checkNodeWOffset(node, offset, exceptionState);
480 if (exceptionState.hadException()) 456 if (exceptionState.hadException())
481 return; 457 return;
482 458
483 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and 459 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and
484 // let newFocus be the boundary point (node, offset). 460 // let newFocus be the boundary point (node, offset).
485 const Position& oldAnchor = anchorPosition(); 461 const Position& oldAnchor = anchorPosition();
486 // TODO(tkent): Diagnostic checks for crbug.com/693578. They should be 462 // TODO(tkent): Diagnostic checks for crbug.com/693578. They should be
487 // removed before M58 branch. 463 // removed before M58 branch.
488 if (oldAnchor.isNull()) { 464 if (oldAnchor.isNull()) {
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
837 m_treeScope->document().addConsoleMessage( 813 m_treeScope->document().addConsoleMessage(
838 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 814 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
839 } 815 }
840 816
841 DEFINE_TRACE(DOMSelection) { 817 DEFINE_TRACE(DOMSelection) {
842 visitor->trace(m_treeScope); 818 visitor->trace(m_treeScope);
843 ContextClient::trace(visitor); 819 ContextClient::trace(visitor);
844 } 820 }
845 821
846 } // namespace blink 822 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698