Chromium Code Reviews| 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 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 217 return 1; | 217 return 1; |
| 218 if (frame() | 218 if (frame() |
| 219 ->selection() | 219 ->selection() |
| 220 .computeVisibleSelectionInDOMTreeDeprecated() | 220 .computeVisibleSelectionInDOMTreeDeprecated() |
| 221 .isNone()) | 221 .isNone()) |
| 222 return 0; | 222 return 0; |
| 223 // Any selection can be adjusted to Range for Document. | 223 // Any selection can be adjusted to Range for Document. |
| 224 if (isSelectionOfDocument()) | 224 if (isSelectionOfDocument()) |
| 225 return 1; | 225 return 1; |
| 226 // In ShadowRoot, we need to try adjustment. | 226 // In ShadowRoot, we need to try adjustment. |
| 227 return createRangeFromSelectionEditor() ? 1 : 0; | 227 if (createRangeFromSelectionEditor().isNotNull()) |
|
yosin_UTC9
2017/03/28 07:04:31
nit: I prefer using "?:" as original
return creat
yoichio
2017/03/28 09:32:51
New early-return follows above early returns of 1
| |
| 228 return 1; | |
| 229 return 0; | |
| 228 } | 230 } |
| 229 | 231 |
| 230 // https://www.w3.org/TR/selection-api/#dom-selection-collapse | 232 // https://www.w3.org/TR/selection-api/#dom-selection-collapse |
| 231 void DOMSelection::collapse(Node* node, | 233 void DOMSelection::collapse(Node* node, |
| 232 unsigned offset, | 234 unsigned offset, |
| 233 ExceptionState& exceptionState) { | 235 ExceptionState& exceptionState) { |
| 234 if (!isAvailable()) | 236 if (!isAvailable()) |
| 235 return; | 237 return; |
| 236 | 238 |
| 237 // 1. If node is null, this method must behave identically as | 239 // 1. If node is null, this method must behave identically as |
| (...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 523 IndexSizeError, String::number(index) + " is not a valid index."); | 525 IndexSizeError, String::number(index) + " is not a valid index."); |
| 524 return nullptr; | 526 return nullptr; |
| 525 } | 527 } |
| 526 | 528 |
| 527 // If you're hitting this, you've added broken multi-range selection support | 529 // If you're hitting this, you've added broken multi-range selection support |
| 528 DCHECK_EQ(rangeCount(), 1u); | 530 DCHECK_EQ(rangeCount(), 1u); |
| 529 | 531 |
| 530 if (Range* cachedRange = documentCachedRange()) | 532 if (Range* cachedRange = documentCachedRange()) |
| 531 return cachedRange; | 533 return cachedRange; |
| 532 | 534 |
| 533 Range* range = createRangeFromSelectionEditor(); | 535 Range* range = createRange(createRangeFromSelectionEditor()); |
| 534 cacheRangeIfSelectionOfDocument(range); | 536 cacheRangeIfSelectionOfDocument(range); |
| 535 return range; | 537 return range; |
| 536 } | 538 } |
| 537 | 539 |
| 538 Range* DOMSelection::primaryRangeOrNull() const { | 540 Range* DOMSelection::primaryRangeOrNull() const { |
| 539 return rangeCount() > 0 ? getRangeAt(0, ASSERT_NO_EXCEPTION) : nullptr; | 541 return rangeCount() > 0 ? getRangeAt(0, ASSERT_NO_EXCEPTION) : nullptr; |
| 540 } | 542 } |
| 541 | 543 |
| 542 Range* DOMSelection::createRangeFromSelectionEditor() const { | 544 EphemeralRange DOMSelection::createRangeFromSelectionEditor() const { |
| 543 const VisibleSelection& selection = visibleSelection(); | 545 const VisibleSelection& selection = visibleSelection(); |
| 544 const Position& anchor = blink::anchorPosition(selection); | 546 const Position& anchor = blink::anchorPosition(selection); |
| 545 if (isSelectionOfDocument() && !anchor.anchorNode()->isInShadowTree()) | 547 if (isSelectionOfDocument() && !anchor.anchorNode()->isInShadowTree()) |
| 546 return createRange(firstEphemeralRangeOf(selection)); | 548 return firstEphemeralRangeOf(selection); |
| 547 | 549 |
| 548 Node* const node = shadowAdjustedNode(anchor); | 550 Node* const anchorNode = shadowAdjustedNode(anchor); |
| 549 if (!node) // crbug.com/595100 | 551 if (!anchorNode) // crbug.com/595100 |
| 550 return nullptr; | 552 return EphemeralRange(); |
| 553 | |
| 551 const Position& focus = focusPosition(selection); | 554 const Position& focus = focusPosition(selection); |
| 552 if (!selection.isBaseFirst()) { | 555 const Position shadowAdjustedFocus = |
| 553 return Range::create(*anchor.document(), shadowAdjustedNode(focus), | 556 Position(shadowAdjustedNode(focus), shadowAdjustedOffset(focus)); |
| 554 shadowAdjustedOffset(focus), node, | 557 const Position shadowAdjustedAnchor = |
| 555 shadowAdjustedOffset(anchor)); | 558 Position(anchorNode, shadowAdjustedOffset(anchor)); |
| 556 } | 559 if (selection.isBaseFirst()) |
| 557 return Range::create(*anchor.document(), node, shadowAdjustedOffset(anchor), | 560 return EphemeralRange(shadowAdjustedAnchor, shadowAdjustedFocus); |
| 558 shadowAdjustedNode(focus), shadowAdjustedOffset(focus)); | 561 return EphemeralRange(shadowAdjustedFocus, shadowAdjustedAnchor); |
| 559 } | 562 } |
| 560 | 563 |
| 561 bool DOMSelection::isSelectionOfDocument() const { | 564 bool DOMSelection::isSelectionOfDocument() const { |
| 562 return m_treeScope == m_treeScope->document(); | 565 return m_treeScope == m_treeScope->document(); |
| 563 } | 566 } |
| 564 | 567 |
| 565 void DOMSelection::cacheRangeIfSelectionOfDocument(Range* range) const { | 568 void DOMSelection::cacheRangeIfSelectionOfDocument(Range* range) const { |
| 566 if (!isSelectionOfDocument()) | 569 if (!isSelectionOfDocument()) |
| 567 return; | 570 return; |
| 568 if (!frame()) | 571 if (!frame()) |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 819 m_treeScope->document().addConsoleMessage( | 822 m_treeScope->document().addConsoleMessage( |
| 820 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); | 823 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); |
| 821 } | 824 } |
| 822 | 825 |
| 823 DEFINE_TRACE(DOMSelection) { | 826 DEFINE_TRACE(DOMSelection) { |
| 824 visitor->trace(m_treeScope); | 827 visitor->trace(m_treeScope); |
| 825 ContextClient::trace(visitor); | 828 ContextClient::trace(visitor); |
| 826 } | 829 } |
| 827 | 830 |
| 828 } // namespace blink | 831 } // namespace blink |
| OLD | NEW |