| 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 240 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 |
| 261 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { | 262 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { |
| 262 if (!isAvailable()) | 263 if (!isAvailable()) |
| 263 return; | 264 return; |
| 264 | 265 |
| 265 const VisibleSelection& selection = | 266 // The method must throw InvalidStateError exception if the context object is |
| 266 frame()->selection().computeVisibleSelectionInDOMTreeDeprecated(); | 267 // empty. |
| 267 | 268 if (rangeCount() == 0) { |
| 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. |
| 274 SelectionInDOMTree::Builder builder; | 280 SelectionInDOMTree::Builder builder; |
| 275 builder.collapse(selection.end()); | 281 builder.collapse(newRange->endPosition()); |
| 276 frame()->selection().setSelection(builder.build()); | 282 frame()->selection().setSelection(builder.build()); |
| 283 cacheRangeIfSelectionOfDocument(newRange); |
| 277 } | 284 } |
| 278 | 285 |
| 286 // https://www.w3.org/TR/selection-api/#dom-selection-collapsetostart |
| 279 void DOMSelection::collapseToStart(ExceptionState& exceptionState) { | 287 void DOMSelection::collapseToStart(ExceptionState& exceptionState) { |
| 280 if (!isAvailable()) | 288 if (!isAvailable()) |
| 281 return; | 289 return; |
| 282 | 290 |
| 283 const VisibleSelection& selection = | 291 // The method must throw InvalidStateError ([DOM4]) exception if the context |
| 284 frame()->selection().computeVisibleSelectionInDOMTreeDeprecated(); | 292 // object is empty. |
| 285 | 293 if (rangeCount() == 0) { |
| 286 if (selection.isNone()) { | |
| 287 exceptionState.throwDOMException(InvalidStateError, | 294 exceptionState.throwDOMException(InvalidStateError, |
| 288 "there is no selection."); | 295 "there is no selection."); |
| 289 return; | 296 return; |
| 290 } | 297 } |
| 291 | 298 |
| 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. |
| 292 SelectionInDOMTree::Builder builder; | 305 SelectionInDOMTree::Builder builder; |
| 293 builder.collapse(selection.start()); | 306 builder.collapse(newRange->startPosition()); |
| 294 frame()->selection().setSelection(builder.build()); | 307 frame()->selection().setSelection(builder.build()); |
| 308 cacheRangeIfSelectionOfDocument(newRange); |
| 295 } | 309 } |
| 296 | 310 |
| 297 void DOMSelection::empty() { | 311 void DOMSelection::empty() { |
| 298 if (!isAvailable()) | 312 if (!isAvailable()) |
| 299 return; | 313 return; |
| 300 frame()->selection().clear(); | 314 frame()->selection().clear(); |
| 301 } | 315 } |
| 302 | 316 |
| 303 void DOMSelection::setBaseAndExtent(Node* baseNode, | 317 void DOMSelection::setBaseAndExtent(Node* baseNode, |
| 304 int baseOffset, | 318 int baseOffset, |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 823 m_treeScope->document().addConsoleMessage( | 837 m_treeScope->document().addConsoleMessage( |
| 824 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 838 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 825 } | 839 } |
| 826 | 840 |
| 827 DEFINE_TRACE(DOMSelection) { | 841 DEFINE_TRACE(DOMSelection) { |
| 828 visitor->trace(m_treeScope); | 842 visitor->trace(m_treeScope); |
| 829 ContextClient::trace(visitor); | 843 ContextClient::trace(visitor); |
| 830 } | 844 } |
| 831 | 845 |
| 832 } // namespace blink | 846 } // namespace blink |
| OLD | NEW |