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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 } | 74 } |
75 | 75 |
76 bool dispatchSelectStart(Node* node) | 76 bool dispatchSelectStart(Node* node) |
77 { | 77 { |
78 if (!node || !node->layoutObject()) | 78 if (!node || !node->layoutObject()) |
79 return true; | 79 return true; |
80 | 80 |
81 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel
ectstart)); | 81 return node->dispatchEvent(Event::createCancelableBubble(EventTypeNames::sel
ectstart)); |
82 } | 82 } |
83 | 83 |
84 template <typename Strategy> | 84 template <typename SelectionType> |
85 VisibleSelection expandSelectionToRespectUserSelectAllAlgorithm(Node* targetNode
, const VisibleSelection& selection) | 85 VisibleSelection expandSelectionToRespectUserSelectAllAlgorithm(Node* targetNode
, const VisibleSelection& selection) |
86 { | 86 { |
87 using PositionType = typename Strategy::PositionType; | 87 using PositionType = typename SelectionType::PositionType; |
88 | 88 |
89 Node* rootUserSelectAll = PositionType::rootUserSelectAllForNode(targetNode)
; | 89 Node* rootUserSelectAll = SelectionType::Strategy::rootUserSelectAllForNode(
targetNode); |
90 if (!rootUserSelectAll) | 90 if (!rootUserSelectAll) |
91 return selection; | 91 return selection; |
92 | 92 |
93 VisibleSelection newSelection(selection); | 93 VisibleSelection newSelection(selection); |
94 newSelection.setBase(PositionType::beforeNode(rootUserSelectAll).upstream(Ca
nCrossEditingBoundary)); | 94 newSelection.setBase(PositionType::beforeNode(rootUserSelectAll).upstream(Ca
nCrossEditingBoundary)); |
95 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll).downstream
(CanCrossEditingBoundary)); | 95 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll).downstream
(CanCrossEditingBoundary)); |
96 | 96 |
97 return newSelection; | 97 return newSelection; |
98 } | 98 } |
99 | 99 |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
242 // |newSelection| are valid for |m_frame->document()|. | 242 // |newSelection| are valid for |m_frame->document()|. |
243 // |dispatchSelectStart()| can change them by "selectstart" event handler. | 243 // |dispatchSelectStart()| can change them by "selectstart" event handler. |
244 | 244 |
245 if (m_selectionState != SelectionState::ExtendedSelection) { | 245 if (m_selectionState != SelectionState::ExtendedSelection) { |
246 // Always extend selection here because it's caused by a mouse drag | 246 // Always extend selection here because it's caused by a mouse drag |
247 m_selectionState = SelectionState::ExtendedSelection; | 247 m_selectionState = SelectionState::ExtendedSelection; |
248 newSelection = VisibleSelection(targetPosition); | 248 newSelection = VisibleSelection(targetPosition); |
249 } | 249 } |
250 | 250 |
251 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { | 251 if (RuntimeEnabledFeatures::userSelectAllEnabled()) { |
252 Node* rootUserSelectAllForMousePressNode = Position::rootUserSelectAllFo
rNode(mousePressNode); | 252 // TODO(yosin) Should we use |Strategy::rootUserSelectAllForNode()|? |
253 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == Position::rootUserSelectAllForNode(target)) { | 253 Node* rootUserSelectAllForMousePressNode = EditingStrategy::rootUserSele
ctAllForNode(mousePressNode); |
| 254 if (rootUserSelectAllForMousePressNode && rootUserSelectAllForMousePress
Node == EditingStrategy::rootUserSelectAllForNode(target)) { |
254 newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMo
usePressNode).upstream(CanCrossEditingBoundary)); | 255 newSelection.setBase(PositionType::beforeNode(rootUserSelectAllForMo
usePressNode).upstream(CanCrossEditingBoundary)); |
255 newSelection.setExtent(PositionType::afterNode(rootUserSelectAllForM
ousePressNode).downstream(CanCrossEditingBoundary)); | 256 newSelection.setExtent(PositionType::afterNode(rootUserSelectAllForM
ousePressNode).downstream(CanCrossEditingBoundary)); |
256 } else { | 257 } else { |
257 // Reset base for user select all when base is inside user-select-al
l area and extent < base. | 258 // Reset base for user select all when base is inside user-select-al
l area and extent < base. |
258 if (rootUserSelectAllForMousePressNode) { | 259 if (rootUserSelectAllForMousePressNode) { |
259 PositionType eventPosition = Strategy::toPositionType(target->la
youtObject()->positionForPoint(hitTestResult.localPoint()).position()); | 260 PositionType eventPosition = Strategy::toPositionType(target->la
youtObject()->positionForPoint(hitTestResult.localPoint()).position()); |
260 PositionType dragStartPosition = Strategy::toPositionType(mouseP
ressNode->layoutObject()->positionForPoint(dragStartPos).position()); | 261 PositionType dragStartPosition = Strategy::toPositionType(mouseP
ressNode->layoutObject()->positionForPoint(dragStartPos).position()); |
261 if (eventPosition.compareTo(dragStartPosition) < 0) | 262 if (eventPosition.compareTo(dragStartPosition) < 0) |
262 newSelection.setBase(PositionType::afterNode(rootUserSelectA
llForMousePressNode).downstream(CanCrossEditingBoundary)); | 263 newSelection.setBase(PositionType::afterNode(rootUserSelectA
llForMousePressNode).downstream(CanCrossEditingBoundary)); |
263 } | 264 } |
264 | 265 |
265 Node* rootUserSelectAllForTarget = Position::rootUserSelectAllForNod
e(target); | 266 Node* rootUserSelectAllForTarget = EditingStrategy::rootUserSelectAl
lForNode(target); |
266 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
Strategy::toPositionType(target->layoutObject()->positionForPoint(hitTestResult.
localPoint()).position()).compareTo(Strategy::toPositionType(mousePressNode->lay
outObject()->positionForPoint(dragStartPos).position())) < 0) | 267 if (rootUserSelectAllForTarget && mousePressNode->layoutObject() &&
Strategy::toPositionType(target->layoutObject()->positionForPoint(hitTestResult.
localPoint()).position()).compareTo(Strategy::toPositionType(mousePressNode->lay
outObject()->positionForPoint(dragStartPos).position())) < 0) |
267 newSelection.setExtent(PositionType::beforeNode(rootUserSelectAl
lForTarget).upstream(CanCrossEditingBoundary)); | 268 newSelection.setExtent(PositionType::beforeNode(rootUserSelectAl
lForTarget).upstream(CanCrossEditingBoundary)); |
268 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) | 269 else if (rootUserSelectAllForTarget && mousePressNode->layoutObject(
)) |
269 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll
ForTarget).downstream(CanCrossEditingBoundary)); | 270 newSelection.setExtent(PositionType::afterNode(rootUserSelectAll
ForTarget).downstream(CanCrossEditingBoundary)); |
270 else | 271 else |
271 newSelection.setExtent(targetPosition); | 272 newSelection.setExtent(targetPosition); |
272 } | 273 } |
273 } else { | 274 } else { |
274 newSelection.setExtent(targetPosition); | 275 newSelection.setExtent(targetPosition); |
275 } | 276 } |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 else | 650 else |
650 m_selectionState = SelectionState::HaveNotStartedSelection; | 651 m_selectionState = SelectionState::HaveNotStartedSelection; |
651 } | 652 } |
652 | 653 |
653 FrameSelection& SelectionController::selection() const | 654 FrameSelection& SelectionController::selection() const |
654 { | 655 { |
655 return m_frame->selection(); | 656 return m_frame->selection(); |
656 } | 657 } |
657 | 658 |
658 } // namespace blink | 659 } // namespace blink |
OLD | NEW |