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 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
437 | 437 |
438 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); | 438 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); |
439 if (!selectedRange) | 439 if (!selectedRange) |
440 return; | 440 return; |
441 | 441 |
442 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); | 442 selectedRange->deleteContents(ASSERT_NO_EXCEPTION); |
443 | 443 |
444 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION); | 444 setBaseAndExtent(selectedRange->startContainer(ASSERT_NO_EXCEPTION), selecte dRange->startOffset(), selectedRange->startContainer(), selectedRange->startOffs et(), ASSERT_NO_EXCEPTION); |
445 } | 445 } |
446 | 446 |
447 bool DOMSelection::containsNode(const Node* n, bool allowPartial) const | 447 bool DOMSelection::containsNode(Node* n, bool allowPartial) const |
448 { | 448 { |
449 if (!m_frame) | 449 if (!m_frame) |
450 return false; | 450 return false; |
451 | 451 |
452 // toNormalizedRange can trigger layout, which can remove the last | |
453 // reference to node |n|, | |
ojan
2013/05/20 02:30:48
The render tree doesn't hold refptrs to Nodes AFAI
| |
454 RefPtr<Node> protect(n); | |
455 | |
452 FrameSelection* selection = m_frame->selection(); | 456 FrameSelection* selection = m_frame->selection(); |
453 | 457 |
454 if (!n || m_frame->document() != n->document() || selection->isNone()) | 458 if (!n || m_frame->document() != n->document() || selection->isNone()) |
455 return false; | 459 return false; |
456 | 460 |
457 ContainerNode* parentNode = n->parentNode(); | |
458 unsigned nodeIndex = n->nodeIndex(); | 461 unsigned nodeIndex = n->nodeIndex(); |
459 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); | 462 RefPtr<Range> selectedRange = selection->selection().toNormalizedRange(); |
460 | 463 |
464 ContainerNode* parentNode = n->parentNode(); | |
461 if (!parentNode) | 465 if (!parentNode) |
462 return false; | 466 return false; |
463 | 467 |
464 ExceptionCode ec = 0; | 468 ExceptionCode ec = 0; |
465 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), ec) >= 0 && !ec | 469 bool nodeFullySelected = Range::compareBoundaryPoints(parentNode, nodeIndex, selectedRange->startContainer(), selectedRange->startOffset(), ec) >= 0 && !ec |
466 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), ec) <= 0 && !ec; | 470 && Range::compareBoundaryPoints(parentNode, nodeIndex + 1, selectedRange ->endContainer(), selectedRange->endOffset(), ec) <= 0 && !ec; |
467 ASSERT(!ec); | 471 ASSERT(!ec); |
468 if (nodeFullySelected) | 472 if (nodeFullySelected) |
469 return true; | 473 return true; |
470 | 474 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 | 534 |
531 bool DOMSelection::isValidForPosition(Node* node) const | 535 bool DOMSelection::isValidForPosition(Node* node) const |
532 { | 536 { |
533 ASSERT(m_frame); | 537 ASSERT(m_frame); |
534 if (!node) | 538 if (!node) |
535 return true; | 539 return true; |
536 return node->document() == m_frame->document(); | 540 return node->document() == m_frame->document(); |
537 } | 541 } |
538 | 542 |
539 } // namespace WebCore | 543 } // namespace WebCore |
OLD | NEW |