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

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

Issue 2686663004: Selection API: Selection.extend() should throw if rangeCount is 0. (Closed)
Patch Set: focus() -> collapse() 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/text/selection-exceptions.html ('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 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
358 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 358 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
359 359
360 frame()->selection().modify(alter, direction, granularity); 360 frame()->selection().modify(alter, direction, granularity);
361 } 361 }
362 362
363 void DOMSelection::extend(Node* node, 363 void DOMSelection::extend(Node* node,
364 int offset, 364 int offset,
365 ExceptionState& exceptionState) { 365 ExceptionState& exceptionState) {
366 DCHECK(node); 366 DCHECK(node);
367 367
368 if (!isAvailable()) 368 if (rangeCount() == 0) {
369 exceptionState.throwDOMException(
370 InvalidStateError, "This Selection object doesn't have any Ranges.");
369 return; 371 return;
372 }
370 373
371 if (offset < 0) { 374 if (offset < 0) {
372 exceptionState.throwDOMException( 375 exceptionState.throwDOMException(
373 IndexSizeError, String::number(offset) + " is not a valid offset."); 376 IndexSizeError, String::number(offset) + " is not a valid offset.");
374 return; 377 return;
375 } 378 }
376 if (static_cast<unsigned>(offset) > node->lengthOfContents()) { 379 if (static_cast<unsigned>(offset) > node->lengthOfContents()) {
377 exceptionState.throwDOMException( 380 exceptionState.throwDOMException(
378 IndexSizeError, 381 IndexSizeError,
379 String::number(offset) + " is larger than the given node's length."); 382 String::number(offset) + " is larger than the given node's length.");
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after
668 m_treeScope->document().addConsoleMessage( 671 m_treeScope->document().addConsoleMessage(
669 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 672 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
670 } 673 }
671 674
672 DEFINE_TRACE(DOMSelection) { 675 DEFINE_TRACE(DOMSelection) {
673 visitor->trace(m_treeScope); 676 visitor->trace(m_treeScope);
674 ContextClient::trace(visitor); 677 ContextClient::trace(visitor);
675 } 678 }
676 679
677 } // namespace blink 680 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/text/selection-exceptions.html ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698