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

Side by Side Diff: Source/core/page/DOMSelection.cpp

Issue 224113002: Oilpan: move Range object to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use STACK_ALLOCATED() + incorporate ager's overview of macros in this area. Created 6 years, 8 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
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 331 matching lines...) Expand 10 before | Expand all | Expand 10 after
342 return; 342 return;
343 } 343 }
344 344
345 if (!isValidForPosition(node)) 345 if (!isValidForPosition(node))
346 return; 346 return;
347 347
348 // FIXME: Eliminate legacy editing positions 348 // FIXME: Eliminate legacy editing positions
349 m_frame->selection().setExtent(VisiblePosition(createLegacyEditingPosition(n ode, offset), DOWNSTREAM)); 349 m_frame->selection().setExtent(VisiblePosition(createLegacyEditingPosition(n ode, offset), DOWNSTREAM));
350 } 350 }
351 351
352 PassRefPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState& exceptionS tate) 352 PassRefPtrWillBeRawPtr<Range> DOMSelection::getRangeAt(int index, ExceptionState & exceptionState)
353 { 353 {
354 if (!m_frame) 354 if (!m_frame)
355 return nullptr; 355 return nullptr;
356 356
357 if (index < 0 || index >= rangeCount()) { 357 if (index < 0 || index >= rangeCount()) {
358 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index."); 358 exceptionState.throwDOMException(IndexSizeError, String::number(index) + " is not a valid index.");
359 return nullptr; 359 return nullptr;
360 } 360 }
361 361
362 // If you're hitting this, you've added broken multi-range selection support 362 // If you're hitting this, you've added broken multi-range selection support
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 return; 395 return;
396 } 396 }
397 397
398 FrameSelection& selection = m_frame->selection(); 398 FrameSelection& selection = m_frame->selection();
399 399
400 if (selection.isNone()) { 400 if (selection.isNone()) {
401 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY); 401 selection.setSelectedRange(newRange, VP_DEFAULT_AFFINITY);
402 return; 402 return;
403 } 403 }
404 404
405 RefPtr<Range> originalRange = selection.firstRange(); 405 RefPtrWillBeRawPtr<Range> originalRange = selection.firstRange();
406 406
407 if (originalRange->startContainer()->document() != newRange->startContainer( )->document()) { 407 if (originalRange->startContainer()->document() != newRange->startContainer( )->document()) {
408 addConsoleError("The given range does not belong to the current selectio n's document."); 408 addConsoleError("The given range does not belong to the current selectio n's document.");
409 return; 409 return;
410 } 410 }
411 if (originalRange->startContainer()->treeScope() != newRange->startContainer ()->treeScope()) { 411 if (originalRange->startContainer()->treeScope() != newRange->startContainer ()->treeScope()) {
412 addConsoleError("The given range and the current selection belong to two different document fragments."); 412 addConsoleError("The given range and the current selection belong to two different document fragments.");
413 return; 413 return;
414 } 414 }
415 415
416 if (originalRange->compareBoundaryPoints(Range::START_TO_END, newRange, ASSE RT_NO_EXCEPTION) < 0 416 if (originalRange->compareBoundaryPoints(Range::START_TO_END, newRange, ASSE RT_NO_EXCEPTION) < 0
417 || newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.ge t(), ASSERT_NO_EXCEPTION) < 0) { 417 || newRange->compareBoundaryPoints(Range::START_TO_END, originalRange.ge t(), ASSERT_NO_EXCEPTION) < 0) {
418 addConsoleError("Discontiguous selection is not supported."); 418 addConsoleError("Discontiguous selection is not supported.");
419 return; 419 return;
420 } 420 }
421 421
422 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; o ther browsers supporting discontiguous 422 // FIXME: "Merge the ranges if they intersect" is Blink-specific behavior; o ther browsers supporting discontiguous
423 // selection (obviously) keep each Range added and return it in getRangeAt() . But it's unclear if we can really 423 // selection (obviously) keep each Range added and return it in getRangeAt() . But it's unclear if we can really
424 // do the same, since we don't support discontiguous selection. Further disc ussions at 424 // do the same, since we don't support discontiguous selection. Further disc ussions at
425 // <https://code.google.com/p/chromium/issues/detail?id=353069>. 425 // <https://code.google.com/p/chromium/issues/detail?id=353069>.
426 426
427 Range* start = originalRange->compareBoundaryPoints(Range::START_TO_START, n ewRange, ASSERT_NO_EXCEPTION) < 0 ? originalRange.get() : newRange; 427 Range* start = originalRange->compareBoundaryPoints(Range::START_TO_START, n ewRange, ASSERT_NO_EXCEPTION) < 0 ? originalRange.get() : newRange;
428 Range* end = originalRange->compareBoundaryPoints(Range::END_TO_END, newRang e, ASSERT_NO_EXCEPTION) < 0 ? newRange : originalRange.get(); 428 Range* end = originalRange->compareBoundaryPoints(Range::END_TO_END, newRang e, ASSERT_NO_EXCEPTION) < 0 ? newRange : originalRange.get();
429 RefPtr<Range> merged = Range::create(originalRange->startContainer()->docume nt(), start->startContainer(), start->startOffset(), end->endContainer(), end->e ndOffset()); 429 RefPtrWillBeRawPtr<Range> merged = Range::create(originalRange->startContain er()->document(), start->startContainer(), start->startOffset(), end->endContain er(), end->endOffset());
430 EAffinity affinity = selection.selection().affinity(); 430 EAffinity affinity = selection.selection().affinity();
431 selection.setSelectedRange(merged.get(), affinity); 431 selection.setSelectedRange(merged.get(), affinity);
432 } 432 }
433 433
434 void DOMSelection::deleteFromDocument() 434 void DOMSelection::deleteFromDocument()
435 { 435 {
436 if (!m_frame) 436 if (!m_frame)
437 return; 437 return;
438 438
439 FrameSelection& selection = m_frame->selection(); 439 FrameSelection& selection = m_frame->selection();
440 440
441 if (selection.isNone()) 441 if (selection.isNone())
442 return; 442 return;
443 443
444 if (isCollapsed()) 444 if (isCollapsed())
445 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, Ch aracterGranularity); 445 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, Ch aracterGranularity);
446 446
447 RefPtr<Range> selectedRange = selection.selection().toNormalizedRange(); 447 RefPtrWillBeRawPtr<Range> selectedRange = selection.selection().toNormalized Range();
448 if (!selectedRange) 448 if (!selectedRange)
449 return; 449 return;
450 450
451 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); 451 selectedRange->deleteContents(ASSERT_NO_EXCEPTION);
452 452
453 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION); 453 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION);
454 } 454 }
455 455
456 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const 456 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const
457 { 457 {
458 if (!m_frame) 458 if (!m_frame)
459 return false; 459 return false;
460 460
461 FrameSelection& selection = m_frame->selection(); 461 FrameSelection& selection = m_frame->selection();
462 462
463 if (!n || m_frame->document() != n->document() || selection.isNone()) 463 if (!n || m_frame->document() != n->document() || selection.isNone())
464 return false; 464 return false;
465 465
466 unsigned nodeIndex = n->nodeIndex(); 466 unsigned nodeIndex = n->nodeIndex();
467 RefPtr<Range> selectedRange = selection.selection().toNormalizedRange(); 467 RefPtrWillBeRawPtr<Range> selectedRange = selection.selection().toNormalized Range();
468 468
469 ContainerNode* parentNode = n->parentNode(); 469 ContainerNode* parentNode = n->parentNode();
470 if (!parentNode) 470 if (!parentNode)
471 return false; 471 return false;
472 472
473 TrackExceptionState exceptionState; 473 TrackExceptionState exceptionState;
474 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), exceptionState) >= 0 && !exceptionState.hadException() 474 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), exceptionState) >= 0 && !exceptionState.hadException()
475 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), exceptionState) <= 0 && !exception State.hadException(); 475 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), exceptionState) <= 0 && !exception State.hadException();
476 if (exceptionState.hadException()) 476 if (exceptionState.hadException())
477 return false; 477 return false;
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 return node->document() == m_frame->document(); 547 return node->document() == m_frame->document();
548 } 548 }
549 549
550 void DOMSelection::addConsoleError(const String& message) 550 void DOMSelection::addConsoleError(const String& message)
551 { 551 {
552 if (m_treeScope) 552 if (m_treeScope)
553 m_treeScope->document().addConsoleMessage(JSMessageSource, ErrorMessageL evel, message); 553 m_treeScope->document().addConsoleMessage(JSMessageSource, ErrorMessageL evel, message);
554 } 554 }
555 555
556 } // namespace WebCore 556 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698