| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. | 2 * Copyright (C) 2006, 2007, 2008, 2009, 2010, 2011 Apple Inc. All rights reserv
ed. |
| 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) | 3 * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) | 4 * Copyright (C) 2012 Digia Plc. and/or its subsidiary(-ies) |
| 5 * Copyright (C) 2015 Google Inc. All rights reserved. | 5 * Copyright (C) 2015 Google Inc. All rights reserved. |
| 6 * | 6 * |
| 7 * Redistribution and use in source and binary forms, with or without | 7 * Redistribution and use in source and binary forms, with or without |
| 8 * modification, are permitted provided that the following conditions | 8 * modification, are permitted provided that the following conditions |
| 9 * are met: | 9 * are met: |
| 10 * 1. Redistributions of source code must retain the above copyright | 10 * 1. Redistributions of source code must retain the above copyright |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 DispatchEventResult dispatchSelectStart(Node* node) | 78 DispatchEventResult dispatchSelectStart(Node* node) |
| 79 { | 79 { |
| 80 if (!node || !node->layoutObject()) | 80 if (!node || !node->layoutObject()) |
| 81 return DispatchEventResult::NotCanceled; | 81 return DispatchEventResult::NotCanceled; |
| 82 | 82 |
| 83 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel
ectstart)); | 83 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel
ectstart)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 VisibleSelectionInFlatTree expandSelectionToRespectUserSelectAll(Node* targetNod
e, const VisibleSelectionInFlatTree& selection) | 86 VisibleSelectionInFlatTree expandSelectionToRespectUserSelectAll(Node* targetNod
e, const VisibleSelectionInFlatTree& selection) |
| 87 { | 87 { |
| 88 Node* rootUserSelectAll = EditingInFlatTreeStrategy::rootUserSelectAllForNod
e(targetNode); | 88 Node* const rootUserSelectAll = EditingInFlatTreeStrategy::rootUserSelectAll
ForNode(targetNode); |
| 89 if (!rootUserSelectAll) | 89 if (!rootUserSelectAll) |
| 90 return selection; | 90 return selection; |
| 91 if (rootUserSelectAll->isHTMLElement() && toHTMLElement(rootUserSelectAll)->
isTextFormControl()) | |
| 92 return selection; | |
| 93 if (rootUserSelectAll->layoutObject()->style()->userModify() != READ_ONLY) | |
| 94 return selection; | |
| 95 | 91 |
| 96 VisibleSelectionInFlatTree newSelection(selection); | 92 VisibleSelectionInFlatTree newSelection(selection); |
| 97 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::beforeNod
e(rootUserSelectAll), CanCrossEditingBoundary)); | 93 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::beforeNod
e(rootUserSelectAll), CanCrossEditingBoundary)); |
| 98 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::afterNod
e(rootUserSelectAll), CanCrossEditingBoundary)); | 94 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::afterNod
e(rootUserSelectAll), CanCrossEditingBoundary)); |
| 99 | 95 |
| 100 return newSelection; | 96 return newSelection; |
| 101 } | 97 } |
| 102 | 98 |
| 103 static int textDistance(const PositionInFlatTree& start, const PositionInFlatTre
e& end) | 99 static int textDistance(const PositionInFlatTree& start, const PositionInFlatTre
e& end) |
| 104 { | 100 { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 231 // |dispatchSelectStart()| can change them by "selectstart" event handler. | 227 // |dispatchSelectStart()| can change them by "selectstart" event handler. |
| 232 | 228 |
| 233 if (m_selectionState != SelectionState::ExtendedSelection) { | 229 if (m_selectionState != SelectionState::ExtendedSelection) { |
| 234 // Always extend selection here because it's caused by a mouse drag | 230 // Always extend selection here because it's caused by a mouse drag |
| 235 m_selectionState = SelectionState::ExtendedSelection; | 231 m_selectionState = SelectionState::ExtendedSelection; |
| 236 newSelection = VisibleSelectionInFlatTree(targetPosition); | 232 newSelection = VisibleSelectionInFlatTree(targetPosition); |
| 237 } | 233 } |
| 238 | 234 |
| 239 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { | 235 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { |
| 240 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? | 236 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? |
| 241 Node* rootUserSelectAllForMousePressNode = EditingInFlatTreeStrategy::ro
otUserSelectAllForNode(mousePressNode); | 237 Node* const rootUserSelectAllForMousePressNode = EditingInFlatTreeStrate
gy::rootUserSelectAllForNode(mousePressNode); |
| 242 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == EditingInFlatTreeStrategy::rootUserSelectAllForNode(target)) { | 238 Node* const rootUserSelectAllForTarget = EditingInFlatTreeStrategy::root
UserSelectAllForNode(target); |
| 239 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == rootUserSelectAllForTarget) { |
| 243 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::b
eforeNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 240 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::b
eforeNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 244 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::
afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 241 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::
afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 245 } else { | 242 } else { |
| 246 // Reset base for user select all when base is inside user-select-al
l area and extent < base. | 243 // Reset base for user select all when base is inside user-select-al
l area and extent < base. |
| 247 if (rootUserSelectAllForMousePressNode) { | 244 if (rootUserSelectAllForMousePressNode) { |
| 248 PositionInFlatTree eventPosition = toPositionInFlatTree(target->
layoutObject()->positionForPoint(hitTestResult.localPoint()).position()); | 245 PositionInFlatTree eventPosition = toPositionInFlatTree(target->
layoutObject()->positionForPoint(hitTestResult.localPoint()).position()); |
| 249 PositionInFlatTree dragStartPosition = toPositionInFlatTree(mous
ePressNode->layoutObject()->positionForPoint(dragStartPos).position()); | 246 PositionInFlatTree dragStartPosition = toPositionInFlatTree(mous
ePressNode->layoutObject()->positionForPoint(dragStartPos).position()); |
| 250 if (eventPosition.compareTo(dragStartPosition) < 0) | 247 if (eventPosition.compareTo(dragStartPosition) < 0) |
| 251 newSelection.setBase(mostForwardCaretPosition(PositionInFlat
Tree::afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 248 newSelection.setBase(mostForwardCaretPosition(PositionInFlat
Tree::afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 252 } | 249 } |
| 253 | 250 |
| 254 Node* rootUserSelectAllForTarget = EditingInFlatTreeStrategy::rootUs
erSelectAllForNode(target); | |
| 255 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
toPositionInFlatTree(target->layoutObject()->positionForPoint(hitTestResult.loca
lPoint()).position()).compareTo(toPositionInFlatTree(mousePressNode->layoutObjec
t()->positionForPoint(dragStartPos).position())) < 0) | 251 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
toPositionInFlatTree(target->layoutObject()->positionForPoint(hitTestResult.loca
lPoint()).position()).compareTo(toPositionInFlatTree(mousePressNode->layoutObjec
t()->positionForPoint(dragStartPos).position())) < 0) |
| 256 newSelection.setExtent(mostBackwardCaretPosition(PositionInFlatT
ree::beforeNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); | 252 newSelection.setExtent(mostBackwardCaretPosition(PositionInFlatT
ree::beforeNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); |
| 257 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) | 253 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) |
| 258 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTr
ee::afterNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); | 254 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTr
ee::afterNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); |
| 259 else | 255 else |
| 260 newSelection.setExtent(targetPosition); | 256 newSelection.setExtent(targetPosition); |
| 261 } | 257 } |
| 262 } else { | 258 } else { |
| 263 newSelection.setExtent(targetPosition); | 259 newSelection.setExtent(targetPosition); |
| 264 } | 260 } |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 return event.event().altKey() && event.isOverLink(); | 671 return event.event().altKey() && event.isOverLink(); |
| 676 } | 672 } |
| 677 | 673 |
| 678 bool isExtendingSelection(const MouseEventWithHitTestResults& event) | 674 bool isExtendingSelection(const MouseEventWithHitTestResults& event) |
| 679 { | 675 { |
| 680 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult().
image(); | 676 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult().
image(); |
| 681 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 677 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 682 } | 678 } |
| 683 | 679 |
| 684 } // namespace blink | 680 } // namespace blink |
| OLD | NEW |