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

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

Issue 2451613003: Get rid of createVisibleSelection() taking two Position (Closed)
Patch Set: 2016-10-26T15:09:55 Created 4 years, 1 month 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 | « no previous file | third_party/WebKit/Source/core/editing/FrameSelection.cpp » ('j') | 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 29 matching lines...) Expand all
40 #include "core/editing/EditingUtilities.h" 40 #include "core/editing/EditingUtilities.h"
41 #include "core/editing/FrameSelection.h" 41 #include "core/editing/FrameSelection.h"
42 #include "core/editing/iterators/TextIterator.h" 42 #include "core/editing/iterators/TextIterator.h"
43 #include "core/frame/LocalFrame.h" 43 #include "core/frame/LocalFrame.h"
44 #include "core/frame/UseCounter.h" 44 #include "core/frame/UseCounter.h"
45 #include "core/inspector/ConsoleMessage.h" 45 #include "core/inspector/ConsoleMessage.h"
46 #include "wtf/text/WTFString.h" 46 #include "wtf/text/WTFString.h"
47 47
48 namespace blink { 48 namespace blink {
49 49
50 static Position createPosition(Node* node, int offset) {
51 DCHECK_GE(offset, 0);
52 if (!node)
53 return Position();
54 return Position(node, offset);
55 }
56
57 static Node* selectionShadowAncestor(LocalFrame* frame) { 50 static Node* selectionShadowAncestor(LocalFrame* frame) {
58 Node* node = frame->selection().selection().base().anchorNode(); 51 Node* node = frame->selection().selection().base().anchorNode();
59 if (!node) 52 if (!node)
60 return 0; 53 return 0;
61 54
62 if (!node->isInShadowTree()) 55 if (!node->isInShadowTree())
63 return 0; 56 return 0;
64 57
65 return frame->document()->ancestorInThisScope(node); 58 return frame->document()->ancestorInThisScope(node);
66 } 59 }
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
292 String::number(extentOffset) + " is not a valid extent offset."); 285 String::number(extentOffset) + " is not a valid extent offset.");
293 return; 286 return;
294 } 287 }
295 288
296 if (!baseNode || !extentNode) 289 if (!baseNode || !extentNode)
297 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull); 290 UseCounter::count(frame(), UseCounter::SelectionSetBaseAndExtentNull);
298 291
299 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode)) 292 if (!isValidForPosition(baseNode) || !isValidForPosition(extentNode))
300 return; 293 return;
301 294
302 Position base = createPosition(baseNode, baseOffset); 295 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
303 Position extent = createPosition(extentNode, extentOffset);
304 const bool selectionHasDirection = true;
305
306 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
307 // needs to be audited. See http://crbug.com/590369 for more details. 296 // needs to be audited. See http://crbug.com/590369 for more details.
308 // In the long term, we should change FrameSelection::setSelection to take a 297 // In the long term, we should change FrameSelection::setSelection to take a
309 // parameter that does not require clean layout, so that modifying selection 298 // parameter that does not require clean layout, so that modifying selection
310 // no longer performs synchronous layout by itself. 299 // no longer performs synchronous layout by itself.
300 // TODO(editing-dev): Once SVG USE element doesn't modifies DOM tree, we
301 // should get rid of this update layout call.
302 // See http://crbug.com/566281
303 // See "svg/text/textpath-reference-crash.html"
311 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 304 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
312 305
313 frame()->selection().setSelection(createVisibleSelection( 306 frame()->selection().setSelection(
314 base, extent, SelDefaultAffinity, selectionHasDirection)); 307 SelectionInDOMTree::Builder()
308 .setBaseAndExtentDeprecated(Position(baseNode, baseOffset),
309 Position(extentNode, extentOffset))
310 .setIsDirectional(true)
311 .build());
315 } 312 }
316 313
317 void DOMSelection::modify(const String& alterString, 314 void DOMSelection::modify(const String& alterString,
318 const String& directionString, 315 const String& directionString,
319 const String& granularityString) { 316 const String& granularityString) {
320 if (!isAvailable()) 317 if (!isAvailable())
321 return; 318 return;
322 319
323 FrameSelection::EAlteration alter; 320 FrameSelection::EAlteration alter;
324 if (equalIgnoringCase(alterString, "extend")) 321 if (equalIgnoringCase(alterString, "extend"))
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
386 exceptionState.throwDOMException( 383 exceptionState.throwDOMException(
387 IndexSizeError, 384 IndexSizeError,
388 String::number(offset) + " is larger than the given node's length."); 385 String::number(offset) + " is larger than the given node's length.");
389 return; 386 return;
390 } 387 }
391 388
392 if (!isValidForPosition(node)) 389 if (!isValidForPosition(node))
393 return; 390 return;
394 391
395 const Position& base = frame()->selection().base(); 392 const Position& base = frame()->selection().base();
396 const Position& extent = createPosition(node, offset); 393 if (base.isNull()) {
397 const bool selectionHasDirection = true; 394 // TODO(editing-dev): We should throw |InvalidStateError| if selection is
398 395 // none to follow the spec.
399 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 396 frame()->selection().setSelection(SelectionInDOMTree::Builder()
400 // needs to be audited. See http://crbug.com/590369 for more details. 397 .collapse(Position(node, offset))
401 // In the long term, we should change FrameSelection::setSelection to take a 398 .setIsDirectional(true)
402 // parameter that does not require clean layout, so that modifying selection 399 .build());
403 // no longer performs synchronous layout by itself. 400 return;
404 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 401 }
405 402 frame()->selection().setSelection(SelectionInDOMTree::Builder()
406 const VisibleSelection newSelection = createVisibleSelection( 403 .collapse(base)
407 base, extent, TextAffinity::Downstream, selectionHasDirection); 404 .extend(Position(node, offset))
408 frame()->selection().setSelection(newSelection); 405 .setIsDirectional(true)
406 .build());
409 } 407 }
410 408
411 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) { 409 Range* DOMSelection::getRangeAt(int index, ExceptionState& exceptionState) {
412 if (!isAvailable()) 410 if (!isAvailable())
413 return nullptr; 411 return nullptr;
414 412
415 if (index < 0 || index >= rangeCount()) { 413 if (index < 0 || index >= rangeCount()) {
416 exceptionState.throwDOMException( 414 exceptionState.throwDOMException(
417 IndexSizeError, String::number(index) + " is not a valid index."); 415 IndexSizeError, String::number(index) + " is not a valid index.");
418 return nullptr; 416 return nullptr;
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 m_treeScope->document().addConsoleMessage( 671 m_treeScope->document().addConsoleMessage(
674 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 672 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
675 } 673 }
676 674
677 DEFINE_TRACE(DOMSelection) { 675 DEFINE_TRACE(DOMSelection) {
678 visitor->trace(m_treeScope); 676 visitor->trace(m_treeScope);
679 DOMWindowProperty::trace(visitor); 677 DOMWindowProperty::trace(visitor);
680 } 678 }
681 679
682 } // namespace blink 680 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/FrameSelection.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698