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

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

Issue 2693813002: Selection API: Some functions should throw InvalidNodeTypeError and IndexSizeError. (Closed)
Patch Set: adjust 2 more tests 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 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
190 UseCounter::count(frame(), UseCounter::SelectionCollapseNull); 190 UseCounter::count(frame(), UseCounter::SelectionCollapseNull);
191 frame()->selection().clear(); 191 frame()->selection().clear();
192 return; 192 return;
193 } 193 }
194 194
195 if (offset < 0) { 195 if (offset < 0) {
196 exceptionState.throwDOMException( 196 exceptionState.throwDOMException(
197 IndexSizeError, String::number(offset) + " is not a valid offset."); 197 IndexSizeError, String::number(offset) + " is not a valid offset.");
198 return; 198 return;
199 } 199 }
200 Range::checkNodeWOffset(node, offset, exceptionState);
201 if (exceptionState.hadException())
202 return;
200 203
201 if (!isValidForPosition(node)) 204 if (!isValidForPosition(node))
202 return; 205 return;
203 Range::checkNodeWOffset(node, offset, exceptionState);
204 if (exceptionState.hadException())
205 return;
206 206
207 frame()->selection().setSelection( 207 frame()->selection().setSelection(
208 SelectionInDOMTree::Builder() 208 SelectionInDOMTree::Builder()
209 .collapse(Position(node, offset)) 209 .collapse(Position(node, offset))
210 .setIsDirectional(frame()->selection().isDirectional()) 210 .setIsDirectional(frame()->selection().isDirectional())
211 .build()); 211 .build());
212 } 212 }
213 213
214 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { 214 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) {
215 if (!isAvailable()) 215 if (!isAvailable())
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 if (!baseNode) { 278 if (!baseNode) {
279 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 279 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
280 frame()->selection().clear(); 280 frame()->selection().clear();
281 return; 281 return;
282 } 282 }
283 if (!extentNode) { 283 if (!extentNode) {
284 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 284 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
285 extentOffset = 0; 285 extentOffset = 0;
286 } 286 }
287 287
288 Range::checkNodeWOffset(baseNode, baseOffset, exceptionState);
289 if (exceptionState.hadException())
290 return;
291 if (extentNode) {
292 Range::checkNodeWOffset(extentNode, extentOffset, exceptionState);
293 if (exceptionState.hadException())
294 return;
295 }
296
288 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) 297 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
289 return; 298 return;
290 299
291 clearCachedRangeIfSelectionOfDocument(); 300 clearCachedRangeIfSelectionOfDocument();
292 301
293 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 302 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
294 // needs to be audited. See http://crbug.com/590369 for more details. 303 // needs to be audited. See http://crbug.com/590369 for more details.
295 // In the long term, we should change FrameSelection::setSelection to take a 304 // In the long term, we should change FrameSelection::setSelection to take a
296 // parameter that does not require clean layout, so that modifying selection 305 // parameter that does not require clean layout, so that modifying selection
297 // no longer performs synchronous layout by itself. 306 // no longer performs synchronous layout by itself.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
373 exceptionState.throwDOMException( 382 exceptionState.throwDOMException(
374 InvalidStateError, "This Selection object doesn't have any Ranges."); 383 InvalidStateError, "This Selection object doesn't have any Ranges.");
375 return; 384 return;
376 } 385 }
377 386
378 if (offset < 0) { 387 if (offset < 0) {
379 exceptionState.throwDOMException( 388 exceptionState.throwDOMException(
380 IndexSizeError, String::number(offset) + " is not a valid offset."); 389 IndexSizeError, String::number(offset) + " is not a valid offset.");
381 return; 390 return;
382 } 391 }
383 if (static_cast<unsigned>(offset) > node->lengthOfContents()) { 392 Range::checkNodeWOffset(node, offset, exceptionState);
384 exceptionState.throwDOMException( 393 if (exceptionState.hadException())
385 IndexSizeError,
386 String::number(offset) + " is larger than the given node's length.");
387 return; 394 return;
388 }
389 395
390 if (!isValidForPosition(node)) 396 if (!isValidForPosition(node))
391 return; 397 return;
392 398
393 clearCachedRangeIfSelectionOfDocument(); 399 clearCachedRangeIfSelectionOfDocument();
394 const Position& base = frame()->selection().base(); 400 const Position& base = frame()->selection().base();
395 if (base.isNull()) { 401 if (base.isNull()) {
396 // TODO(editing-dev): We should throw |InvalidStateError| if selection is 402 // TODO(editing-dev): We should throw |InvalidStateError| if selection is
397 // none to follow the spec. 403 // none to follow the spec.
398 frame()->selection().setSelection(SelectionInDOMTree::Builder() 404 frame()->selection().setSelection(SelectionInDOMTree::Builder()
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
709 m_treeScope->document().addConsoleMessage( 715 m_treeScope->document().addConsoleMessage(
710 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 716 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
711 } 717 }
712 718
713 DEFINE_TRACE(DOMSelection) { 719 DEFINE_TRACE(DOMSelection) {
714 visitor->trace(m_treeScope); 720 visitor->trace(m_treeScope);
715 ContextClient::trace(visitor); 721 ContextClient::trace(visitor);
716 } 722 }
717 723
718 } // namespace blink 724 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698