OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 361 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
372 if (startRemoved) | 372 if (startRemoved) |
373 updatePositionForNodeRemoval(start, node); | 373 updatePositionForNodeRemoval(start, node); |
374 if (endRemoved) | 374 if (endRemoved) |
375 updatePositionForNodeRemoval(end, node); | 375 updatePositionForNodeRemoval(end, node); |
376 | 376 |
377 if (Position::commonAncestorTreeScope(start, end) && start.isNotNull() &
& end.isNotNull()) { | 377 if (Position::commonAncestorTreeScope(start, end) && start.isNotNull() &
& end.isNotNull()) { |
378 if (m_selection.isBaseFirst()) | 378 if (m_selection.isBaseFirst()) |
379 m_selection.setWithoutValidation(start, end); | 379 m_selection.setWithoutValidation(start, end); |
380 else | 380 else |
381 m_selection.setWithoutValidation(end, start); | 381 m_selection.setWithoutValidation(end, start); |
382 } else | 382 } else { |
383 clearDOMTreeSelection = true; | 383 clearDOMTreeSelection = true; |
| 384 } |
384 | 385 |
385 clearLayoutTreeSelection = true; | 386 clearLayoutTreeSelection = true; |
386 } else if (baseRemoved || extentRemoved) { | 387 } else if (baseRemoved || extentRemoved) { |
387 // The base and/or extent are about to be removed, but the start and end
aren't. | 388 // The base and/or extent are about to be removed, but the start and end
aren't. |
388 // Change the base and extent to the start and end, but don't re-validat
e the | 389 // Change the base and extent to the start and end, but don't re-validat
e the |
389 // selection, since doing so could move the start and end into the node | 390 // selection, since doing so could move the start and end into the node |
390 // that is about to be removed. | 391 // that is about to be removed. |
391 if (m_selection.isBaseFirst()) | 392 if (m_selection.isBaseFirst()) |
392 m_selection.setWithoutValidation(m_selection.start(), m_selection.en
d()); | 393 m_selection.setWithoutValidation(m_selection.start(), m_selection.en
d()); |
393 else | 394 else |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1013 if (alter == AlterationExtend) | 1014 if (alter == AlterationExtend) |
1014 position = modifyExtendingBackward(granularity); | 1015 position = modifyExtendingBackward(granularity); |
1015 else | 1016 else |
1016 position = modifyMovingBackward(granularity); | 1017 position = modifyMovingBackward(granularity); |
1017 break; | 1018 break; |
1018 } | 1019 } |
1019 | 1020 |
1020 if (position.isNull()) | 1021 if (position.isNull()) |
1021 return false; | 1022 return false; |
1022 | 1023 |
1023 if (isSpatialNavigationEnabled(m_frame)) | 1024 if (isSpatialNavigationEnabled(m_frame)) { |
1024 if (!wasRange && alter == AlterationMove && position.deepEquivalent() ==
originalStartPosition.deepEquivalent()) | 1025 if (!wasRange && alter == AlterationMove && position.deepEquivalent() ==
originalStartPosition.deepEquivalent()) |
1025 return false; | 1026 return false; |
| 1027 } |
1026 | 1028 |
1027 // Some of the above operations set an xPosForVerticalArrowNavigation. | 1029 // Some of the above operations set an xPosForVerticalArrowNavigation. |
1028 // Setting a selection will clear it, so save it to possibly restore later. | 1030 // Setting a selection will clear it, so save it to possibly restore later. |
1029 // Note: the START position type is arbitrary because it is unused, it would
be | 1031 // Note: the START position type is arbitrary because it is unused, it would
be |
1030 // the requested position type if there were no xPosForVerticalArrowNavigati
on set. | 1032 // the requested position type if there were no xPosForVerticalArrowNavigati
on set. |
1031 LayoutUnit x = lineDirectionPointForBlockDirectionNavigation(START); | 1033 LayoutUnit x = lineDirectionPointForBlockDirectionNavigation(START); |
1032 m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_frame) ||
alter == AlterationExtend); | 1034 m_selection.setIsDirectional(shouldAlwaysUseDirectionalSelection(m_frame) ||
alter == AlterationExtend); |
1033 | 1035 |
1034 switch (alter) { | 1036 switch (alter) { |
1035 case AlterationMove: | 1037 case AlterationMove: |
1036 moveTo(position, userTriggered); | 1038 moveTo(position, userTriggered); |
1037 break; | 1039 break; |
1038 case AlterationExtend: | 1040 case AlterationExtend: |
1039 | 1041 |
1040 if (!m_selection.isCaret() | 1042 if (!m_selection.isCaret() |
1041 && (granularity == WordGranularity || granularity == ParagraphGranul
arity || granularity == LineGranularity) | 1043 && (granularity == WordGranularity || granularity == ParagraphGranul
arity || granularity == LineGranularity) |
1042 && m_frame && !m_frame->editor().behavior().shouldExtendSelectionByW
ordOrLineAcrossCaret()) { | 1044 && m_frame && !m_frame->editor().behavior().shouldExtendSelectionByW
ordOrLineAcrossCaret()) { |
1043 // Don't let the selection go across the base position directly. Nee
ded to match mac | 1045 // Don't let the selection go across the base position directly. Nee
ded to match mac |
1044 // behavior when, for instance, word-selecting backwards starting wi
th the caret in | 1046 // behavior when, for instance, word-selecting backwards starting wi
th the caret in |
1045 // the middle of a word and then word-selecting forward, leaving the
caret in the | 1047 // the middle of a word and then word-selecting forward, leaving the
caret in the |
1046 // same place where it was, instead of directly selecting to the end
of the word. | 1048 // same place where it was, instead of directly selecting to the end
of the word. |
1047 VisibleSelection newSelection = m_selection; | 1049 VisibleSelection newSelection = m_selection; |
1048 newSelection.setExtent(position); | 1050 newSelection.setExtent(position); |
1049 if (m_selection.isBaseFirst() != newSelection.isBaseFirst()) | 1051 if (m_selection.isBaseFirst() != newSelection.isBaseFirst()) |
1050 position = m_selection.visibleBase(); | 1052 position = m_selection.visibleBase(); |
1051 } | 1053 } |
1052 | 1054 |
1053 // Standard Mac behavior when extending to a boundary is grow the select
ion rather than leaving the | 1055 // Standard Mac behavior when extending to a boundary is grow the |
1054 // base in place and moving the extent. Matches NSTextView. | 1056 // selection rather than leaving the base in place and moving the |
1055 if (!m_frame || !m_frame->editor().behavior().shouldAlwaysGrowSelectionW
henExtendingToBoundary() || m_selection.isCaret() || !isBoundary(granularity)) | 1057 // extent. Matches NSTextView. |
| 1058 if (!m_frame || !m_frame->editor().behavior().shouldAlwaysGrowSelectionW
henExtendingToBoundary() |
| 1059 || m_selection.isCaret() |
| 1060 || !isBoundary(granularity)) { |
1056 setExtent(position, userTriggered); | 1061 setExtent(position, userTriggered); |
1057 else { | 1062 } else { |
1058 TextDirection textDirection = directionOfEnclosingBlock(); | 1063 TextDirection textDirection = directionOfEnclosingBlock(); |
1059 if (direction == DirectionForward || (textDirection == LTR && direct
ion == DirectionRight) || (textDirection == RTL && direction == DirectionLeft)) | 1064 if (direction == DirectionForward || (textDirection == LTR && direct
ion == DirectionRight) || (textDirection == RTL && direction == DirectionLeft)) |
1060 setEnd(position, userTriggered); | 1065 setEnd(position, userTriggered); |
1061 else | 1066 else |
1062 setStart(position, userTriggered); | 1067 setStart(position, userTriggered); |
1063 } | 1068 } |
1064 break; | 1069 break; |
1065 } | 1070 } |
1066 | 1071 |
1067 if (granularity == LineGranularity || granularity == ParagraphGranularity) | 1072 if (granularity == LineGranularity || granularity == ParagraphGranularity) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1189 LocalFrame* frame = pos.document()->frame(); | 1194 LocalFrame* frame = pos.document()->frame(); |
1190 if (!frame) | 1195 if (!frame) |
1191 return x; | 1196 return x; |
1192 | 1197 |
1193 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation())
{ | 1198 if (m_xPosForVerticalArrowNavigation == NoXPosForVerticalArrowNavigation())
{ |
1194 VisiblePosition visiblePosition(pos, m_selection.affinity()); | 1199 VisiblePosition visiblePosition(pos, m_selection.affinity()); |
1195 // VisiblePosition creation can fail here if a node containing the selec
tion becomes visibility:hidden | 1200 // VisiblePosition creation can fail here if a node containing the selec
tion becomes visibility:hidden |
1196 // after the selection is created and before this function is called. | 1201 // after the selection is created and before this function is called. |
1197 x = visiblePosition.lineDirectionPointForBlockDirectionNavigation(); | 1202 x = visiblePosition.lineDirectionPointForBlockDirectionNavigation(); |
1198 m_xPosForVerticalArrowNavigation = x; | 1203 m_xPosForVerticalArrowNavigation = x; |
1199 } else | 1204 } else { |
1200 x = m_xPosForVerticalArrowNavigation; | 1205 x = m_xPosForVerticalArrowNavigation; |
| 1206 } |
1201 | 1207 |
1202 return x; | 1208 return x; |
1203 } | 1209 } |
1204 | 1210 |
1205 void FrameSelection::clear() | 1211 void FrameSelection::clear() |
1206 { | 1212 { |
1207 m_granularity = CharacterGranularity; | 1213 m_granularity = CharacterGranularity; |
1208 if (m_granularityStrategy) | 1214 if (m_granularityStrategy) |
1209 m_granularityStrategy->Clear(); | 1215 m_granularityStrategy->Clear(); |
1210 setSelection(VisibleSelection()); | 1216 setSelection(VisibleSelection()); |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1434 RefPtrWillBeRawPtr<Node> root = nullptr; | 1440 RefPtrWillBeRawPtr<Node> root = nullptr; |
1435 Node* selectStartTarget = nullptr; | 1441 Node* selectStartTarget = nullptr; |
1436 if (isContentEditable()) { | 1442 if (isContentEditable()) { |
1437 root = highestEditableRoot(m_selection.start()); | 1443 root = highestEditableRoot(m_selection.start()); |
1438 if (Node* shadowRoot = m_selection.nonBoundaryShadowTreeRootNode()) | 1444 if (Node* shadowRoot = m_selection.nonBoundaryShadowTreeRootNode()) |
1439 selectStartTarget = shadowRoot->shadowHost(); | 1445 selectStartTarget = shadowRoot->shadowHost(); |
1440 else | 1446 else |
1441 selectStartTarget = root.get(); | 1447 selectStartTarget = root.get(); |
1442 } else { | 1448 } else { |
1443 root = m_selection.nonBoundaryShadowTreeRootNode(); | 1449 root = m_selection.nonBoundaryShadowTreeRootNode(); |
1444 if (root) | 1450 if (root) { |
1445 selectStartTarget = root->shadowHost(); | 1451 selectStartTarget = root->shadowHost(); |
1446 else { | 1452 } else { |
1447 root = document->documentElement(); | 1453 root = document->documentElement(); |
1448 selectStartTarget = document->body(); | 1454 selectStartTarget = document->body(); |
1449 } | 1455 } |
1450 } | 1456 } |
1451 if (!root) | 1457 if (!root) |
1452 return; | 1458 return; |
1453 | 1459 |
1454 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventTypeNames::selectstart))) | 1460 if (selectStartTarget && !selectStartTarget->dispatchEvent(Event::createCanc
elableBubble(EventTypeNames::selectstart))) |
1455 return; | 1461 return; |
1456 | 1462 |
(...skipping 594 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2051 | 2057 |
2052 void showTree(const blink::FrameSelection* sel) | 2058 void showTree(const blink::FrameSelection* sel) |
2053 { | 2059 { |
2054 if (sel) | 2060 if (sel) |
2055 sel->showTreeForThis(); | 2061 sel->showTreeForThis(); |
2056 else | 2062 else |
2057 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); | 2063 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); |
2058 } | 2064 } |
2059 | 2065 |
2060 #endif | 2066 #endif |
OLD | NEW |