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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
161 DCHECK(!document().needsLayoutTreeUpdate()); | 161 DCHECK(!document().needsLayoutTreeUpdate()); |
162 | 162 |
163 Element* const editable = rootEditableElement(); | 163 Element* const editable = rootEditableElement(); |
164 if (!editable) | 164 if (!editable) |
165 return; | 165 return; |
166 | 166 |
167 const VisiblePosition position = | 167 const VisiblePosition position = |
168 visiblePositionForContentsPoint(point, frame()); | 168 visiblePositionForContentsPoint(point, frame()); |
169 SelectionInDOMTree::Builder builder; | 169 SelectionInDOMTree::Builder builder; |
170 builder.setIsDirectional(selection().isDirectional()); | 170 builder.setIsDirectional(selection().isDirectional()); |
171 builder.setIsHandleVisible(true); | |
171 if (position.isNotNull()) | 172 if (position.isNotNull()) |
172 builder.collapse(position.toPositionWithAffinity()); | 173 builder.collapse(position.toPositionWithAffinity()); |
173 setSelection(builder.build(), | 174 setSelection(builder.build(), CloseTyping | ClearTypingStyle | UserTriggered); |
174 CloseTyping | ClearTypingStyle | UserTriggered | HandleVisible); | |
175 } | 175 } |
176 | 176 |
177 template <typename Strategy> | 177 template <typename Strategy> |
178 void FrameSelection::setSelectionAlgorithm( | 178 void FrameSelection::setSelectionAlgorithm( |
179 const VisibleSelectionTemplate<Strategy>& newSelection, | 179 const VisibleSelectionTemplate<Strategy>& newSelection, |
180 HandleVisibility handleVisibility, | |
180 SetSelectionOptions options, | 181 SetSelectionOptions options, |
181 CursorAlignOnScroll align, | 182 CursorAlignOnScroll align, |
182 TextGranularity granularity) { | 183 TextGranularity granularity) { |
183 DCHECK(isAvailable()); | 184 DCHECK(isAvailable()); |
184 DCHECK(newSelection.isValidFor(document())); | 185 DCHECK(newSelection.isValidFor(document())); |
185 const Document& currentDocument = document(); | 186 const Document& currentDocument = document(); |
186 if (m_granularityStrategy && | 187 if (m_granularityStrategy && |
187 (options & FrameSelection::DoNotClearStrategy) == 0) | 188 (options & FrameSelection::DoNotClearStrategy) == 0) |
188 m_granularityStrategy->Clear(); | 189 m_granularityStrategy->Clear(); |
189 bool closeTyping = options & CloseTyping; | 190 bool closeTyping = options & CloseTyping; |
190 bool shouldClearTypingStyle = options & ClearTypingStyle; | 191 bool shouldClearTypingStyle = options & ClearTypingStyle; |
191 const HandleVisibility handleVisibility = options & HandleVisible | |
192 ? HandleVisibility::Visible | |
193 : HandleVisibility::NotVisible; | |
194 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); | 192 EUserTriggered userTriggered = selectionOptionsToUserTriggered(options); |
195 | 193 |
196 // TODO(editing-dev): We should rename variable |s| to another name to avoid | 194 // TODO(editing-dev): We should rename variable |s| to another name to avoid |
197 // using one letter variable name. | 195 // using one letter variable name. |
198 VisibleSelectionTemplate<Strategy> s = newSelection; | 196 VisibleSelectionTemplate<Strategy> s = newSelection; |
199 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 197 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
200 s.setIsDirectional(true); | 198 s.setIsDirectional(true); |
201 | 199 |
202 m_granularity = granularity; | 200 m_granularity = granularity; |
203 | 201 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
297 CursorAlignOnScroll align, | 295 CursorAlignOnScroll align, |
298 TextGranularity granularity) { | 296 TextGranularity granularity) { |
299 if (!newSelection.isNone()) { | 297 if (!newSelection.isNone()) { |
300 // TODO(editing-dev): The use of | 298 // TODO(editing-dev): The use of |
301 // updateStyleAndLayoutIgnorePendingStylesheets | 299 // updateStyleAndLayoutIgnorePendingStylesheets |
302 // needs to be audited. See http://crbug.com/590369 for more details. | 300 // needs to be audited. See http://crbug.com/590369 for more details. |
303 newSelection.base() | 301 newSelection.base() |
304 .document() | 302 .document() |
305 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 303 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
306 } | 304 } |
307 setSelection(createVisibleSelection(newSelection), options, align, | 305 setSelection(createVisibleSelection(newSelection), |
308 granularity); | 306 newSelection.isHandleVisible() ? HandleVisibility::Visible |
307 : HandleVisibility::NotVisible, | |
308 options, align, granularity); | |
309 } | 309 } |
310 | 310 |
311 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| | 311 // TODO(yosin): We will make |selectionInFlatTree| version of |SetSelection()| |
312 // as primary function instead of wrapper. | 312 // as primary function instead of wrapper. |
313 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, | 313 void FrameSelection::setSelection(const SelectionInFlatTree& newSelection, |
314 SetSelectionOptions options, | 314 SetSelectionOptions options, |
315 CursorAlignOnScroll align, | 315 CursorAlignOnScroll align, |
316 TextGranularity granularity) { | 316 TextGranularity granularity) { |
317 if (!newSelection.isNone()) { | 317 if (!newSelection.isNone()) { |
318 // TODO(editing-dev): The use of | 318 // TODO(editing-dev): The use of |
319 // updateStyleAndLayoutIgnorePendingStylesheets | 319 // updateStyleAndLayoutIgnorePendingStylesheets |
320 // needs to be audited. See http://crbug.com/590369 for more details. | 320 // needs to be audited. See http://crbug.com/590369 for more details. |
321 newSelection.base() | 321 newSelection.base() |
322 .document() | 322 .document() |
323 ->updateStyleAndLayoutIgnorePendingStylesheets(); | 323 ->updateStyleAndLayoutIgnorePendingStylesheets(); |
324 } | 324 } |
325 setSelection(createVisibleSelection(newSelection), options, align, | 325 setSelection(createVisibleSelection(newSelection), |
326 granularity); | 326 newSelection.isHandleVisible() ? HandleVisibility::Visible |
327 : HandleVisibility::NotVisible, | |
328 options, align, granularity); | |
327 } | 329 } |
328 | 330 |
329 void FrameSelection::setSelection(const VisibleSelection& newSelection, | 331 void FrameSelection::setSelection(const VisibleSelection& newSelection, |
332 HandleVisibility handleVisibility, | |
330 SetSelectionOptions options, | 333 SetSelectionOptions options, |
331 CursorAlignOnScroll align, | 334 CursorAlignOnScroll align, |
332 TextGranularity granularity) { | 335 TextGranularity granularity) { |
333 setSelectionAlgorithm<EditingStrategy>(newSelection, options, align, | 336 setSelectionAlgorithm<EditingStrategy>(newSelection, handleVisibility, |
334 granularity); | 337 options, align, granularity); |
335 } | 338 } |
336 | 339 |
337 void FrameSelection::setSelection( | 340 void FrameSelection::setSelection( |
338 const VisibleSelectionInFlatTree& newSelection, | 341 const VisibleSelectionInFlatTree& newSelection, |
342 HandleVisibility handleVisibility, | |
339 SetSelectionOptions options, | 343 SetSelectionOptions options, |
340 CursorAlignOnScroll align, | 344 CursorAlignOnScroll align, |
341 TextGranularity granularity) { | 345 TextGranularity granularity) { |
342 setSelectionAlgorithm<EditingInFlatTreeStrategy>(newSelection, options, align, | 346 setSelectionAlgorithm<EditingInFlatTreeStrategy>( |
343 granularity); | 347 newSelection, handleVisibility, options, align, granularity); |
344 } | 348 } |
345 | 349 |
346 static bool removingNodeRemovesPosition(Node& node, const Position& position) { | 350 static bool removingNodeRemovesPosition(Node& node, const Position& position) { |
347 if (!position.anchorNode()) | 351 if (!position.anchorNode()) |
348 return false; | 352 return false; |
349 | 353 |
350 if (position.anchorNode() == node) | 354 if (position.anchorNode() == node) |
351 return true; | 355 return true; |
352 | 356 |
353 if (!node.isElementNode()) | 357 if (!node.isElementNode()) |
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
609 return; | 613 return; |
610 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 614 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
611 // |Editor| class. | 615 // |Editor| class. |
612 if (!document().isRunningExecCommand()) | 616 if (!document().isRunningExecCommand()) |
613 TypingCommand::closeTyping(m_frame); | 617 TypingCommand::closeTyping(m_frame); |
614 VisibleSelection newSelection; | 618 VisibleSelection newSelection; |
615 if (selection().isBaseFirst()) | 619 if (selection().isBaseFirst()) |
616 newSelection.setWithoutValidation(start, end); | 620 newSelection.setWithoutValidation(start, end); |
617 else | 621 else |
618 newSelection.setWithoutValidation(end, start); | 622 newSelection.setWithoutValidation(end, start); |
619 setSelection(newSelection, DoNotSetFocus); | 623 setSelection(newSelection, HandleVisibility::NotVisible, DoNotSetFocus); |
yosin_UTC9
2017/02/06 05:33:28
To reduce code change, can we introduce:
FrameSel
| |
620 } | 624 } |
621 | 625 |
622 void FrameSelection::didChangeFocus() { | 626 void FrameSelection::didChangeFocus() { |
623 // Hits in | 627 // Hits in |
624 // virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disable d.html | 628 // virtual/gpu/compositedscrolling/scrollbars/scrollbar-miss-mousemove-disable d.html |
625 DisableCompositingQueryAsserts disabler; | 629 DisableCompositingQueryAsserts disabler; |
626 updateAppearance(); | 630 updateAppearance(); |
627 } | 631 } |
628 | 632 |
629 static DispatchEventResult dispatchSelectStart( | 633 static DispatchEventResult dispatchSelectStart( |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
661 // another element. See snav-input.html and snav-textarea.html | 665 // another element. See snav-input.html and snav-textarea.html |
662 if (isSpatialNavigationEnabled(m_frame)) | 666 if (isSpatialNavigationEnabled(m_frame)) |
663 return false; | 667 return false; |
664 // Even if selection isn't changed, we prevent to default action, e.g. | 668 // Even if selection isn't changed, we prevent to default action, e.g. |
665 // scroll window when caret is at end of content editable. | 669 // scroll window when caret is at end of content editable. |
666 return true; | 670 return true; |
667 } | 671 } |
668 | 672 |
669 const SetSelectionOptions options = | 673 const SetSelectionOptions options = |
670 CloseTyping | ClearTypingStyle | userTriggered; | 674 CloseTyping | ClearTypingStyle | userTriggered; |
671 setSelection(selectionModifier.selection(), options); | 675 setSelection(selectionModifier.selection(), HandleVisibility::NotVisible, |
676 options); | |
672 | 677 |
673 if (granularity == LineGranularity || granularity == ParagraphGranularity) | 678 if (granularity == LineGranularity || granularity == ParagraphGranularity) |
674 m_xPosForVerticalArrowNavigation = | 679 m_xPosForVerticalArrowNavigation = |
675 selectionModifier.xPosForVerticalArrowNavigation(); | 680 selectionModifier.xPosForVerticalArrowNavigation(); |
676 | 681 |
677 if (userTriggered == UserTriggered) | 682 if (userTriggered == UserTriggered) |
678 m_granularity = CharacterGranularity; | 683 m_granularity = CharacterGranularity; |
679 | 684 |
680 m_frameCaret->setCaretRectNeedsUpdate(); | 685 m_frameCaret->setCaretRectNeedsUpdate(); |
681 | 686 |
682 return true; | 687 return true; |
683 } | 688 } |
684 | 689 |
685 bool FrameSelection::modify(EAlteration alter, | 690 bool FrameSelection::modify(EAlteration alter, |
686 unsigned verticalDistance, | 691 unsigned verticalDistance, |
687 VerticalDirection direction) { | 692 VerticalDirection direction) { |
688 SelectionModifier selectionModifier(*frame(), selection()); | 693 SelectionModifier selectionModifier(*frame(), selection()); |
689 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, | 694 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, |
690 direction)) { | 695 direction)) { |
691 return false; | 696 return false; |
692 } | 697 } |
693 | 698 |
694 setSelection(selectionModifier.selection(), | 699 setSelection(selectionModifier.selection(), HandleVisibility::NotVisible, |
695 CloseTyping | ClearTypingStyle | UserTriggered, | 700 CloseTyping | ClearTypingStyle | UserTriggered, |
696 alter == AlterationMove ? CursorAlignOnScroll::Always | 701 alter == AlterationMove ? CursorAlignOnScroll::Always |
697 : CursorAlignOnScroll::IfNeeded); | 702 : CursorAlignOnScroll::IfNeeded); |
698 | 703 |
699 m_granularity = CharacterGranularity; | 704 m_granularity = CharacterGranularity; |
700 | 705 |
701 return true; | 706 return true; |
702 } | 707 } |
703 | 708 |
704 void FrameSelection::clear() { | 709 void FrameSelection::clear() { |
(...skipping 650 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1355 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); | 1360 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); |
1356 return m_granularityStrategy.get(); | 1361 return m_granularityStrategy.get(); |
1357 } | 1362 } |
1358 | 1363 |
1359 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { | 1364 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { |
1360 if (isNone()) | 1365 if (isNone()) |
1361 return; | 1366 return; |
1362 | 1367 |
1363 VisibleSelection newSelection = | 1368 VisibleSelection newSelection = |
1364 granularityStrategy()->updateExtent(contentsPoint, m_frame); | 1369 granularityStrategy()->updateExtent(contentsPoint, m_frame); |
1365 setSelection(newSelection, | 1370 setSelection(newSelection, HandleVisibility::Visible, |
1366 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | | 1371 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | |
1367 FrameSelection::DoNotClearStrategy | UserTriggered | | 1372 FrameSelection::DoNotClearStrategy | UserTriggered, |
1368 FrameSelection::HandleVisible, | |
1369 CursorAlignOnScroll::IfNeeded, CharacterGranularity); | 1373 CursorAlignOnScroll::IfNeeded, CharacterGranularity); |
1370 } | 1374 } |
1371 | 1375 |
1372 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take | 1376 // TODO(yosin): We should make |FrameSelection::moveRangeSelection()| to take |
1373 // two |IntPoint| instead of two |VisiblePosition| like | 1377 // two |IntPoint| instead of two |VisiblePosition| like |
1374 // |moveRangeSelectionExtent()|. | 1378 // |moveRangeSelectionExtent()|. |
1375 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, | 1379 void FrameSelection::moveRangeSelection(const VisiblePosition& basePosition, |
1376 const VisiblePosition& extentPosition, | 1380 const VisiblePosition& extentPosition, |
1377 TextGranularity granularity) { | 1381 TextGranularity granularity) { |
1378 VisibleSelection newSelection = createVisibleSelection( | 1382 VisibleSelection newSelection = createVisibleSelection( |
1379 SelectionInDOMTree::Builder() | 1383 SelectionInDOMTree::Builder() |
1380 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), | 1384 .setBaseAndExtentDeprecated(basePosition.deepEquivalent(), |
1381 extentPosition.deepEquivalent()) | 1385 extentPosition.deepEquivalent()) |
1382 .setAffinity(basePosition.affinity()) | 1386 .setAffinity(basePosition.affinity()) |
1383 .setGranularity(granularity) | 1387 .setGranularity(granularity) |
1384 .build()); | 1388 .build()); |
1385 | 1389 |
1386 if (newSelection.isNone()) | 1390 if (newSelection.isNone()) |
1387 return; | 1391 return; |
1388 | 1392 |
1389 SetSelectionOptions options = CloseTyping | ClearTypingStyle; | 1393 setSelection(newSelection, m_handleVisibility, CloseTyping | ClearTypingStyle, |
1390 if (isHandleVisible()) | 1394 CursorAlignOnScroll::IfNeeded, granularity); |
1391 options |= HandleVisible; | |
1392 setSelection(newSelection, options, CursorAlignOnScroll::IfNeeded, | |
1393 granularity); | |
1394 } | 1395 } |
1395 | 1396 |
1396 void FrameSelection::updateIfNeeded() { | 1397 void FrameSelection::updateIfNeeded() { |
1397 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); | 1398 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); |
1398 m_selectionEditor->updateIfNeeded(); | 1399 m_selectionEditor->updateIfNeeded(); |
1399 } | 1400 } |
1400 | 1401 |
1401 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1402 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1402 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1403 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1403 : CaretVisibility::Hidden); | 1404 : CaretVisibility::Hidden); |
(...skipping 28 matching lines...) Expand all Loading... | |
1432 } | 1433 } |
1433 | 1434 |
1434 void showTree(const blink::FrameSelection* sel) { | 1435 void showTree(const blink::FrameSelection* sel) { |
1435 if (sel) | 1436 if (sel) |
1436 sel->showTreeForThis(); | 1437 sel->showTreeForThis(); |
1437 else | 1438 else |
1438 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1439 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1439 } | 1440 } |
1440 | 1441 |
1441 #endif | 1442 #endif |
OLD | NEW |