Chromium Code Reviews| 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 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 75 } | 75 } |
| 76 | 76 |
| 77 DispatchEventResult dispatchSelectStart(Node* node) | 77 DispatchEventResult dispatchSelectStart(Node* node) |
| 78 { | 78 { |
| 79 if (!node || !node->layoutObject()) | 79 if (!node || !node->layoutObject()) |
| 80 return DispatchEventResult::NotCanceled; | 80 return DispatchEventResult::NotCanceled; |
| 81 | 81 |
| 82 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel ectstart)); | 82 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel ectstart)); |
| 83 } | 83 } |
| 84 | 84 |
| 85 static Node* rootUserSelectAllAndNotEditableNode(Node* const node) | |
| 86 { | |
| 87 Node* const rootUserSelectAll = EditingInFlatTreeStrategy::rootUserSelectAll ForNode(node); | |
|
yosin_UTC9
2016/07/20 06:58:58
As talked offline, we should have a function, used
yoichio
2016/07/27 02:27:21
Created the function and use it in rootUserSelectA
| |
| 88 if (!rootUserSelectAll) | |
| 89 return nullptr; | |
| 90 if (rootUserSelectAll->isHTMLElement() && toHTMLElement(rootUserSelectAll)-> isTextFormControl()) | |
| 91 return nullptr; | |
| 92 if (rootUserSelectAll->layoutObject()->style()->userModify() != READ_ONLY) | |
| 93 return nullptr; | |
| 94 | |
| 95 return rootUserSelectAll; | |
| 96 } | |
| 97 | |
| 85 VisibleSelectionInFlatTree expandSelectionToRespectUserSelectAll(Node* targetNod e, const VisibleSelectionInFlatTree& selection) | 98 VisibleSelectionInFlatTree expandSelectionToRespectUserSelectAll(Node* targetNod e, const VisibleSelectionInFlatTree& selection) |
| 86 { | 99 { |
| 87 Node* rootUserSelectAll = EditingInFlatTreeStrategy::rootUserSelectAllForNod e(targetNode); | 100 Node* const rootUserSelectAll = rootUserSelectAllAndNotEditableNode(targetNo de); |
| 88 if (!rootUserSelectAll) | 101 if (!rootUserSelectAll) |
| 89 return selection; | 102 return selection; |
| 90 if (rootUserSelectAll->isHTMLElement() && toHTMLElement(rootUserSelectAll)-> isTextFormControl()) | |
| 91 return selection; | |
| 92 if (rootUserSelectAll->layoutObject()->style()->userModify() != READ_ONLY) | |
| 93 return selection; | |
| 94 | 103 |
| 95 VisibleSelectionInFlatTree newSelection(selection); | 104 VisibleSelectionInFlatTree newSelection(selection); |
| 96 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::beforeNod e(rootUserSelectAll), CanCrossEditingBoundary)); | 105 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::beforeNod e(rootUserSelectAll), CanCrossEditingBoundary)); |
| 97 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::afterNod e(rootUserSelectAll), CanCrossEditingBoundary)); | 106 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree::afterNod e(rootUserSelectAll), CanCrossEditingBoundary)); |
| 98 | 107 |
| 99 return newSelection; | 108 return newSelection; |
| 100 } | 109 } |
| 101 | 110 |
| 102 static int textDistance(const PositionInFlatTree& start, const PositionInFlatTre e& end) | 111 static int textDistance(const PositionInFlatTree& start, const PositionInFlatTre e& end) |
| 103 { | 112 { |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 230 // |dispatchSelectStart()| can change them by "selectstart" event handler. | 239 // |dispatchSelectStart()| can change them by "selectstart" event handler. |
| 231 | 240 |
| 232 if (m_selectionState != SelectionState::ExtendedSelection) { | 241 if (m_selectionState != SelectionState::ExtendedSelection) { |
| 233 // Always extend selection here because it's caused by a mouse drag | 242 // Always extend selection here because it's caused by a mouse drag |
| 234 m_selectionState = SelectionState::ExtendedSelection; | 243 m_selectionState = SelectionState::ExtendedSelection; |
| 235 newSelection = VisibleSelectionInFlatTree(targetPosition); | 244 newSelection = VisibleSelectionInFlatTree(targetPosition); |
| 236 } | 245 } |
| 237 | 246 |
| 238 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { | 247 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { |
| 239 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? | 248 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? |
| 240 Node* rootUserSelectAllForMousePressNode = EditingInFlatTreeStrategy::ro otUserSelectAllForNode(mousePressNode); | 249 Node* const rootUserSelectAllForMousePressNode = rootUserSelectAllAndNot EditableNode(mousePressNode); |
| 241 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress Node == EditingInFlatTreeStrategy::rootUserSelectAllForNode(target)) { | 250 Node* const rootUserSelectAllForTarget = rootUserSelectAllAndNotEditable Node(target); |
| 251 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress Node == rootUserSelectAllForTarget) { | |
| 242 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::b eforeNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 252 newSelection.setBase(mostBackwardCaretPosition(PositionInFlatTree::b eforeNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 243 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree:: afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 253 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTree:: afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 244 } else { | 254 } else { |
| 245 // Reset base for user select all when base is inside user-select-al l area and extent < base. | 255 // Reset base for user select all when base is inside user-select-al l area and extent < base. |
| 246 if (rootUserSelectAllForMousePressNode) { | 256 if (rootUserSelectAllForMousePressNode) { |
| 247 PositionInFlatTree eventPosition = toPositionInFlatTree(target-> layoutObject()->positionForPoint(hitTestResult.localPoint()).position()); | 257 PositionInFlatTree eventPosition = toPositionInFlatTree(target-> layoutObject()->positionForPoint(hitTestResult.localPoint()).position()); |
| 248 PositionInFlatTree dragStartPosition = toPositionInFlatTree(mous ePressNode->layoutObject()->positionForPoint(dragStartPos).position()); | 258 PositionInFlatTree dragStartPosition = toPositionInFlatTree(mous ePressNode->layoutObject()->positionForPoint(dragStartPos).position()); |
| 249 if (eventPosition.compareTo(dragStartPosition) < 0) | 259 if (eventPosition.compareTo(dragStartPosition) < 0) |
| 250 newSelection.setBase(mostForwardCaretPosition(PositionInFlat Tree::afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); | 260 newSelection.setBase(mostForwardCaretPosition(PositionInFlat Tree::afterNode(rootUserSelectAllForMousePressNode), CanCrossEditingBoundary)); |
| 251 } | 261 } |
| 252 | 262 |
| 253 Node* rootUserSelectAllForTarget = EditingInFlatTreeStrategy::rootUs erSelectAllForNode(target); | |
| 254 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() && toPositionInFlatTree(target->layoutObject()->positionForPoint(hitTestResult.loca lPoint()).position()).compareTo(toPositionInFlatTree(mousePressNode->layoutObjec t()->positionForPoint(dragStartPos).position())) < 0) | 263 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() && toPositionInFlatTree(target->layoutObject()->positionForPoint(hitTestResult.loca lPoint()).position()).compareTo(toPositionInFlatTree(mousePressNode->layoutObjec t()->positionForPoint(dragStartPos).position())) < 0) |
| 255 newSelection.setExtent(mostBackwardCaretPosition(PositionInFlatT ree::beforeNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); | 264 newSelection.setExtent(mostBackwardCaretPosition(PositionInFlatT ree::beforeNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); |
| 256 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( )) | 265 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject( )) |
| 257 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTr ee::afterNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); | 266 newSelection.setExtent(mostForwardCaretPosition(PositionInFlatTr ee::afterNode(rootUserSelectAllForTarget), CanCrossEditingBoundary)); |
| 258 else | 267 else |
| 259 newSelection.setExtent(targetPosition); | 268 newSelection.setExtent(targetPosition); |
| 260 } | 269 } |
| 261 } else { | 270 } else { |
| 262 newSelection.setExtent(targetPosition); | 271 newSelection.setExtent(targetPosition); |
| 263 } | 272 } |
| (...skipping 410 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 return event.event().altKey() && event.isOverLink(); | 683 return event.event().altKey() && event.isOverLink(); |
| 675 } | 684 } |
| 676 | 685 |
| 677 bool isExtendingSelection(const MouseEventWithHitTestResults& event) | 686 bool isExtendingSelection(const MouseEventWithHitTestResults& event) |
| 678 { | 687 { |
| 679 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult(). image(); | 688 bool isMouseDownOnLinkOrImage = event.isOverLink() || event.hitTestResult(). image(); |
| 680 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; | 689 return event.event().shiftKey() && !isMouseDownOnLinkOrImage; |
| 681 } | 690 } |
| 682 | 691 |
| 683 } // namespace blink | 692 } // namespace blink |
| OLD | NEW |