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 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
531 | 531 |
532 if (Range* cachedRange = documentCachedRange()) | 532 if (Range* cachedRange = documentCachedRange()) |
533 return cachedRange; | 533 return cachedRange; |
534 | 534 |
535 Range* range = createRange(createRangeFromSelectionEditor()); | 535 Range* range = createRange(createRangeFromSelectionEditor()); |
536 cacheRangeIfSelectionOfDocument(range); | 536 cacheRangeIfSelectionOfDocument(range); |
537 return range; | 537 return range; |
538 } | 538 } |
539 | 539 |
540 Range* DOMSelection::primaryRangeOrNull() const { | 540 Range* DOMSelection::primaryRangeOrNull() const { |
541 return rangeCount() > 0 ? getRangeAt(0, ASSERT_NO_EXCEPTION) : nullptr; | 541 if (rangeCount() <= 0) |
542 return nullptr; | |
543 Range* range = getRangeAt(0, ASSERT_NO_EXCEPTION); | |
544 if (!isSelectionOfDocument()) | |
yosin_UTC9
2017/04/04 04:50:07
I'm not a fan of this approach. We still create te
yoichio
2017/04/04 05:32:42
Creating temporary Ranges and Disposing them is di
yosin_UTC9
2017/04/04 07:21:31
Calling Range::dispose() is error prone in this ca
tkent
2017/04/04 08:41:24
I agree that it's a hack :)
If we have no reason t
| |
545 range->dispose(); | |
546 return range; | |
542 } | 547 } |
543 | 548 |
544 EphemeralRange DOMSelection::createRangeFromSelectionEditor() const { | 549 EphemeralRange DOMSelection::createRangeFromSelectionEditor() const { |
545 const VisibleSelection& selection = visibleSelection(); | 550 const VisibleSelection& selection = visibleSelection(); |
546 const Position& anchor = blink::anchorPosition(selection); | 551 const Position& anchor = blink::anchorPosition(selection); |
547 if (isSelectionOfDocument() && !anchor.anchorNode()->isInShadowTree()) | 552 if (isSelectionOfDocument() && !anchor.anchorNode()->isInShadowTree()) |
548 return firstEphemeralRangeOf(selection); | 553 return firstEphemeralRangeOf(selection); |
549 | 554 |
550 Node* const anchorNode = shadowAdjustedNode(anchor); | 555 Node* const anchorNode = shadowAdjustedNode(anchor); |
551 if (!anchorNode) // crbug.com/595100 | 556 if (!anchorNode) // crbug.com/595100 |
(...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 m_treeScope->document().addConsoleMessage( | 827 m_treeScope->document().addConsoleMessage( |
823 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 828 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
824 } | 829 } |
825 | 830 |
826 DEFINE_TRACE(DOMSelection) { | 831 DEFINE_TRACE(DOMSelection) { |
827 visitor->trace(m_treeScope); | 832 visitor->trace(m_treeScope); |
828 ContextClient::trace(visitor); | 833 ContextClient::trace(visitor); |
829 } | 834 } |
830 | 835 |
831 } // namespace blink | 836 } // namespace blink |
OLD | NEW |