| 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 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 exceptionState.throwDOMException( | 202 exceptionState.throwDOMException( |
| 203 IndexSizeError, String::number(offset) + " is not a valid offset."); | 203 IndexSizeError, String::number(offset) + " is not a valid offset."); |
| 204 return; | 204 return; |
| 205 } | 205 } |
| 206 | 206 |
| 207 if (!isValidForPosition(node)) | 207 if (!isValidForPosition(node)) |
| 208 return; | 208 return; |
| 209 Range::checkNodeWOffset(node, offset, exceptionState); | 209 Range::checkNodeWOffset(node, offset, exceptionState); |
| 210 if (exceptionState.hadException()) | 210 if (exceptionState.hadException()) |
| 211 return; | 211 return; |
| 212 frame()->selection().setSelection(createVisibleSelectionDeprecated( | 212 |
| 213 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 214 // needs to be audited. See http://crbug.com/590369 for more details. |
| 215 // In the long term, we should change FrameSelection::setSelection to take a |
| 216 // parameter that does not require clean layout, so that modifying selection |
| 217 // no longer performs synchronous layout by itself. |
| 218 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 219 |
| 220 frame()->selection().setSelection(createVisibleSelection( |
| 213 Position(node, offset), frame()->selection().isDirectional())); | 221 Position(node, offset), frame()->selection().isDirectional())); |
| 214 } | 222 } |
| 215 | 223 |
| 216 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { | 224 void DOMSelection::collapseToEnd(ExceptionState& exceptionState) { |
| 217 if (!isAvailable()) | 225 if (!isAvailable()) |
| 218 return; | 226 return; |
| 219 | 227 |
| 220 const VisibleSelection& selection = frame()->selection().selection(); | 228 const VisibleSelection& selection = frame()->selection().selection(); |
| 221 | 229 |
| 222 if (selection.isNone()) { | 230 if (selection.isNone()) { |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 | 281 |
| 274 if (!baseNode || !extentNode) | 282 if (!baseNode || !extentNode) |
| 275 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); | 283 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); |
| 276 | 284 |
| 277 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) | 285 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) |
| 278 return; | 286 return; |
| 279 | 287 |
| 280 Position base = createPosition(baseNode, baseOffset); | 288 Position base = createPosition(baseNode, baseOffset); |
| 281 Position extent = createPosition(extentNode, extentOffset); | 289 Position extent = createPosition(extentNode, extentOffset); |
| 282 const bool selectionHasDirection = true; | 290 const bool selectionHasDirection = true; |
| 283 frame()->selection().setSelection(createVisibleSelectionDeprecated( | 291 |
| 292 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 293 // needs to be audited. See http://crbug.com/590369 for more details. |
| 294 // In the long term, we should change FrameSelection::setSelection to take a |
| 295 // parameter that does not require clean layout, so that modifying selection |
| 296 // no longer performs synchronous layout by itself. |
| 297 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 298 |
| 299 frame()->selection().setSelection(createVisibleSelection( |
| 284 base, extent, SelDefaultAffinity, selectionHasDirection)); | 300 base, extent, SelDefaultAffinity, selectionHasDirection)); |
| 285 } | 301 } |
| 286 | 302 |
| 287 void DOMSelection::modify(const String& alterString, | 303 void DOMSelection::modify(const String& alterString, |
| 288 const String& directionString, | 304 const String& directionString, |
| 289 const String& granularityString) { | 305 const String& granularityString) { |
| 290 if (!isAvailable()) | 306 if (!isAvailable()) |
| 291 return; | 307 return; |
| 292 | 308 |
| 293 FrameSelection::EAlteration alter; | 309 FrameSelection::EAlteration alter; |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 354 String::number(offset) + " is larger than the given node's length."); | 370 String::number(offset) + " is larger than the given node's length."); |
| 355 return; | 371 return; |
| 356 } | 372 } |
| 357 | 373 |
| 358 if (!isValidForPosition(node)) | 374 if (!isValidForPosition(node)) |
| 359 return; | 375 return; |
| 360 | 376 |
| 361 const Position& base = frame()->selection().base(); | 377 const Position& base = frame()->selection().base(); |
| 362 const Position& extent = createPosition(node, offset); | 378 const Position& extent = createPosition(node, offset); |
| 363 const bool selectionHasDirection = true; | 379 const bool selectionHasDirection = true; |
| 364 const VisibleSelection newSelection = createVisibleSelectionDeprecated( | 380 |
| 381 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 382 // needs to be audited. See http://crbug.com/590369 for more details. |
| 383 // In the long term, we should change FrameSelection::setSelection to take a |
| 384 // parameter that does not require clean layout, so that modifying selection |
| 385 // no longer performs synchronous layout by itself. |
| 386 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 387 |
| 388 const VisibleSelection newSelection = createVisibleSelection( |
| 365 base, extent, TextAffinity::Downstream, selectionHasDirection); | 389 base, extent, TextAffinity::Downstream, selectionHasDirection); |
| 366 frame()->selection().setSelection(newSelection); | 390 frame()->selection().setSelection(newSelection); |
| 367 } | 391 } |
| 368 | 392 |
| 369 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) { | 393 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) { |
| 370 if (!isAvailable()) | 394 if (!isAvailable()) |
| 371 return nullptr; | 395 return nullptr; |
| 372 | 396 |
| 373 if (index < 0 || index >= rangeCount()) { | 397 if (index < 0 || index >= rangeCount()) { |
| 374 exceptionState.throwDOMException( | 398 exceptionState.throwDOMException( |
| (...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 612 m_treeScope->document().addConsoleMessage( | 636 m_treeScope->document().addConsoleMessage( |
| 613 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 637 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 614 } | 638 } |
| 615 | 639 |
| 616 DEFINE_TRACE(DOMSelection) { | 640 DEFINE_TRACE(DOMSelection) { |
| 617 visitor->trace(m_treeScope); | 641 visitor->trace(m_treeScope); |
| 618 DOMWindowProperty::trace(visitor); | 642 DOMWindowProperty::trace(visitor); |
| 619 } | 643 } |
| 620 | 644 |
| 621 } // namespace blink | 645 } // namespace blink |
| OLD | NEW |