| OLD | NEW |
| 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 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 else | 421 else |
| 422 return; | 422 return; |
| 423 | 423 |
| 424 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 424 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 425 // needs to be audited. See http://crbug.com/590369 for more details. | 425 // needs to be audited. See http://crbug.com/590369 for more details. |
| 426 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 426 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 427 | 427 |
| 428 frame()->selection().modify(alter, direction, granularity); | 428 frame()->selection().modify(alter, direction, granularity); |
| 429 } | 429 } |
| 430 | 430 |
| 431 // https://www.w3.org/TR/selection-api/#dom-selection-extend |
| 431 void DOMSelection::extend(Node* node, | 432 void DOMSelection::extend(Node* node, |
| 432 int offset, | 433 int offset, |
| 433 ExceptionState& exceptionState) { | 434 ExceptionState& exceptionState) { |
| 434 DCHECK(node); | 435 DCHECK(node); |
| 435 // https://www.w3.org/TR/selection-api/#dom-selection-extend | 436 // 1. If node's root is not the document associated with the context object, |
| 437 // abort these steps. |
| 438 if (!isValidForPosition(node)) |
| 439 return; |
| 436 | 440 |
| 437 // 2. If the context object is empty, throw an InvalidStateError exception and | 441 // 2. If the context object is empty, throw an InvalidStateError exception and |
| 438 // abort these steps. | 442 // abort these steps. |
| 439 if (rangeCount() == 0) { | 443 if (rangeCount() == 0) { |
| 440 exceptionState.throwDOMException( | 444 exceptionState.throwDOMException( |
| 441 InvalidStateError, "This Selection object doesn't have any Ranges."); | 445 InvalidStateError, "This Selection object doesn't have any Ranges."); |
| 442 return; | 446 return; |
| 443 } | 447 } |
| 444 | 448 |
| 445 if (offset < 0) { | 449 if (offset < 0) { |
| 446 exceptionState.throwDOMException( | 450 exceptionState.throwDOMException( |
| 447 IndexSizeError, String::number(offset) + " is not a valid offset."); | 451 IndexSizeError, String::number(offset) + " is not a valid offset."); |
| 448 return; | 452 return; |
| 449 } | 453 } |
| 450 Range::checkNodeWOffset(node, offset, exceptionState); | 454 Range::checkNodeWOffset(node, offset, exceptionState); |
| 451 if (exceptionState.hadException()) | 455 if (exceptionState.hadException()) |
| 452 return; | 456 return; |
| 453 | 457 |
| 454 // 1. If node's root is not the document associated with the context object, | |
| 455 // abort these steps. | |
| 456 if (!isValidForPosition(node)) | |
| 457 return; | |
| 458 | |
| 459 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and | 458 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and |
| 460 // let newFocus be the boundary point (node, offset). | 459 // let newFocus be the boundary point (node, offset). |
| 461 const Position& oldAnchor = anchorPosition(); | 460 const Position& oldAnchor = anchorPosition(); |
| 462 DCHECK(!oldAnchor.isNull()); | 461 DCHECK(!oldAnchor.isNull()); |
| 463 const Position newFocus(node, offset); | 462 const Position newFocus(node, offset); |
| 464 | 463 |
| 465 clearCachedRangeIfSelectionOfDocument(); | 464 clearCachedRangeIfSelectionOfDocument(); |
| 466 | 465 |
| 467 // 4. Let newRange be a new range. | 466 // 4. Let newRange be a new range. |
| 468 Range* newRange = Range::create(*frame()->document()); | 467 Range* newRange = Range::create(*frame()->document()); |
| (...skipping 340 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 809 m_treeScope->document().addConsoleMessage( | 808 m_treeScope->document().addConsoleMessage( |
| 810 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 809 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 811 } | 810 } |
| 812 | 811 |
| 813 DEFINE_TRACE(DOMSelection) { | 812 DEFINE_TRACE(DOMSelection) { |
| 814 visitor->trace(m_treeScope); | 813 visitor->trace(m_treeScope); |
| 815 ContextClient::trace(visitor); | 814 ContextClient::trace(visitor); |
| 816 } | 815 } |
| 817 | 816 |
| 818 } // namespace blink | 817 } // namespace blink |
| OLD | NEW |