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 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
98 m_pendingSelection(PendingSelection::create(*this)), | 98 m_pendingSelection(PendingSelection::create(*this)), |
99 m_selectionEditor(SelectionEditor::create(frame)), | 99 m_selectionEditor(SelectionEditor::create(frame)), |
100 m_granularity(CharacterGranularity), | 100 m_granularity(CharacterGranularity), |
101 m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()), | 101 m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()), |
102 m_focused(frame.page() && | 102 m_focused(frame.page() && |
103 frame.page()->focusController().focusedFrame() == frame), | 103 frame.page()->focusController().focusedFrame() == frame), |
104 m_frameCaret(new FrameCaret(frame, *m_selectionEditor)) {} | 104 m_frameCaret(new FrameCaret(frame, *m_selectionEditor)) {} |
105 | 105 |
106 FrameSelection::~FrameSelection() {} | 106 FrameSelection::~FrameSelection() {} |
107 | 107 |
108 const DisplayItemClient& FrameSelection::caretDisplayItemClientForTesting() | 108 void FrameSelection::setCaretVisualRect(const LayoutRect& r) { |
109 const { | 109 m_frameCaret->setVisualRect(r); |
110 return m_frameCaret->displayItemClient(); | 110 } |
111 | |
112 const DisplayItemClient& FrameSelection::getCaretDisplayItemClient() const { | |
yosin_UTC9
2017/01/31 20:12:58
I guess this renaming to help grate reformatting =
| |
113 return m_frameCaret->getDisplayItemClient(); | |
111 } | 114 } |
112 | 115 |
113 const Document& FrameSelection::document() const { | 116 const Document& FrameSelection::document() const { |
114 DCHECK(lifecycleContext()); | 117 DCHECK(lifecycleContext()); |
115 return *lifecycleContext(); | 118 return *lifecycleContext(); |
116 } | 119 } |
117 | 120 |
118 Document& FrameSelection::document() { | 121 Document& FrameSelection::document() { |
119 DCHECK(lifecycleContext()); | 122 DCHECK(lifecycleContext()); |
120 return *lifecycleContext(); | 123 return *lifecycleContext(); |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
217 notifyLayoutObjectOfSelectionChange(userTriggered); | 220 notifyLayoutObjectOfSelectionChange(userTriggered); |
218 return; | 221 return; |
219 } | 222 } |
220 | 223 |
221 const VisibleSelectionTemplate<Strategy> oldSelection = | 224 const VisibleSelectionTemplate<Strategy> oldSelection = |
222 visibleSelection<Strategy>(); | 225 visibleSelection<Strategy>(); |
223 const Position& oldSelectionStart = selection().start(); | 226 const Position& oldSelectionStart = selection().start(); |
224 | 227 |
225 m_handleVisibility = handleVisibility; | 228 m_handleVisibility = handleVisibility; |
226 m_selectionEditor->setVisibleSelection(s, options); | 229 m_selectionEditor->setVisibleSelection(s, options); |
227 m_frameCaret->setCaretRectNeedsUpdate(); | 230 setCaretMayNeedPaintInvalidation(); |
228 | 231 |
229 if (!s.isNone() && !(options & DoNotSetFocus)) { | 232 if (!s.isNone() && !(options & DoNotSetFocus)) { |
230 setFocusedNodeIfNeeded(); | 233 setFocusedNodeIfNeeded(); |
231 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and | 234 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and |
232 // "FocusIn", |m_frame| may associate to another document. | 235 // "FocusIn", |m_frame| may associate to another document. |
233 if (!isAvailable() || document() != currentDocument) { | 236 if (!isAvailable() || document() != currentDocument) { |
234 // Once we get test case to reach here, we should change this | 237 // Once we get test case to reach here, we should change this |
235 // if-statement to |DCHECK()|. | 238 // if-statement to |DCHECK()|. |
236 NOTREACHED(); | 239 NOTREACHED(); |
237 return; | 240 return; |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
379 const Position& oldExtent = selection().extent(); | 382 const Position& oldExtent = selection().extent(); |
380 const Position& newExtent = | 383 const Position& newExtent = |
381 computePositionForChildrenRemoval(oldExtent, container); | 384 computePositionForChildrenRemoval(oldExtent, container); |
382 if (newStart == oldStart && newEnd == oldEnd && newBase == oldBase && | 385 if (newStart == oldStart && newEnd == oldEnd && newBase == oldBase && |
383 newExtent == oldExtent) | 386 newExtent == oldExtent) |
384 return; | 387 return; |
385 if (selection().isBaseFirst()) | 388 if (selection().isBaseFirst()) |
386 m_selectionEditor->setWithoutValidation(newStart, newEnd); | 389 m_selectionEditor->setWithoutValidation(newStart, newEnd); |
387 else | 390 else |
388 m_selectionEditor->setWithoutValidation(newEnd, newStart); | 391 m_selectionEditor->setWithoutValidation(newEnd, newStart); |
389 m_frameCaret->setCaretRectNeedsUpdate(); | 392 setCaretMayNeedPaintInvalidation(); |
390 if (document().isRunningExecCommand()) | 393 if (document().isRunningExecCommand()) |
391 return; | 394 return; |
392 TypingCommand::closeTyping(m_frame); | 395 TypingCommand::closeTyping(m_frame); |
393 } | 396 } |
394 | 397 |
395 void FrameSelection::nodeWillBeRemoved(Node& node) { | 398 void FrameSelection::nodeWillBeRemoved(Node& node) { |
396 // There can't be a selection inside a fragment, so if a fragment's node is | 399 // There can't be a selection inside a fragment, so if a fragment's node is |
397 // being removed, the selection in the document that created the fragment | 400 // being removed, the selection in the document that created the fragment |
398 // needs no adjustment. | 401 // needs no adjustment. |
399 if (isNone() || !node.inActiveDocument()) | 402 if (isNone() || !node.inActiveDocument()) |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 // TODO(yosin): We should paint changed area only rather than whole | 462 // TODO(yosin): We should paint changed area only rather than whole |
460 // selected range. | 463 // selected range. |
461 clearLayoutTreeSelection = true; | 464 clearLayoutTreeSelection = true; |
462 } | 465 } |
463 | 466 |
464 if (clearLayoutTreeSelection) | 467 if (clearLayoutTreeSelection) |
465 selection().start().document()->layoutViewItem().clearSelection(); | 468 selection().start().document()->layoutViewItem().clearSelection(); |
466 | 469 |
467 if (clearDOMTreeSelection) | 470 if (clearDOMTreeSelection) |
468 setSelection(SelectionInDOMTree(), DoNotSetFocus); | 471 setSelection(SelectionInDOMTree(), DoNotSetFocus); |
469 m_frameCaret->setCaretRectNeedsUpdate(); | 472 setCaretMayNeedPaintInvalidation(); |
470 | 473 |
471 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to | 474 // TODO(yosin): We should move to call |TypingCommand::closeTyping()| to |
472 // |Editor| class. | 475 // |Editor| class. |
473 if (!document().isRunningExecCommand()) | 476 if (!document().isRunningExecCommand()) |
474 TypingCommand::closeTyping(m_frame); | 477 TypingCommand::closeTyping(m_frame); |
475 } | 478 } |
476 | 479 |
477 static Position updatePositionAfterAdoptingTextReplacement( | 480 static Position updatePositionAfterAdoptingTextReplacement( |
478 const Position& position, | 481 const Position& position, |
479 CharacterData* node, | 482 CharacterData* node, |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
670 CloseTyping | ClearTypingStyle | userTriggered; | 673 CloseTyping | ClearTypingStyle | userTriggered; |
671 setSelection(selectionModifier.selection(), options); | 674 setSelection(selectionModifier.selection(), options); |
672 | 675 |
673 if (granularity == LineGranularity || granularity == ParagraphGranularity) | 676 if (granularity == LineGranularity || granularity == ParagraphGranularity) |
674 m_xPosForVerticalArrowNavigation = | 677 m_xPosForVerticalArrowNavigation = |
675 selectionModifier.xPosForVerticalArrowNavigation(); | 678 selectionModifier.xPosForVerticalArrowNavigation(); |
676 | 679 |
677 if (userTriggered == UserTriggered) | 680 if (userTriggered == UserTriggered) |
678 m_granularity = CharacterGranularity; | 681 m_granularity = CharacterGranularity; |
679 | 682 |
680 m_frameCaret->setCaretRectNeedsUpdate(); | 683 setCaretMayNeedPaintInvalidation(); |
681 | 684 |
682 return true; | 685 return true; |
683 } | 686 } |
684 | 687 |
685 bool FrameSelection::modify(EAlteration alter, | 688 bool FrameSelection::modify(EAlteration alter, |
686 unsigned verticalDistance, | 689 unsigned verticalDistance, |
687 VerticalDirection direction) { | 690 VerticalDirection direction) { |
688 SelectionModifier selectionModifier(*frame(), selection()); | 691 SelectionModifier selectionModifier(*frame(), selection()); |
689 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, | 692 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, |
690 direction)) { | 693 direction)) { |
(...skipping 29 matching lines...) Expand all Loading... | |
720 m_granularity = CharacterGranularity; | 723 m_granularity = CharacterGranularity; |
721 | 724 |
722 LayoutViewItem view = m_frame->contentLayoutItem(); | 725 LayoutViewItem view = m_frame->contentLayoutItem(); |
723 if (!view.isNull()) | 726 if (!view.isNull()) |
724 view.clearSelection(); | 727 view.clearSelection(); |
725 | 728 |
726 m_frame->editor().clearTypingStyle(); | 729 m_frame->editor().clearTypingStyle(); |
727 m_selectionEditor->documentDetached(*document); | 730 m_selectionEditor->documentDetached(*document); |
728 } | 731 } |
729 | 732 |
730 bool FrameSelection::hasCaretIn(const LayoutBlock& layoubBlock) const { | 733 bool FrameSelection::hasCaretIn(const LayoutBlock& layoutBlock) const { |
731 DCHECK(selection().isValidFor(document())); | 734 DCHECK(selection().isValidFor(document())); |
732 if (!isCaret()) | 735 return caretLayoutBlock() == layoutBlock; |
733 return false; | 736 } |
734 return CaretDisplayItemClient::caretLayoutObject( | 737 |
735 selection().start().anchorNode()) == layoubBlock && | 738 LayoutBlock* FrameSelection::caretLayoutBlock() const { |
736 hasEditableStyle(); | 739 if (!isCaret() || !hasEditableStyle()) |
740 return nullptr; | |
741 return m_frameCaret->caretLayoutBlock(); | |
742 } | |
743 | |
744 LayoutRect FrameSelection::caretLocalRect() const { | |
745 return m_frameCaret->caretLocalRect(); | |
737 } | 746 } |
738 | 747 |
739 IntRect FrameSelection::absoluteCaretBounds() { | 748 IntRect FrameSelection::absoluteCaretBounds() { |
740 DCHECK(selection().isValidFor(*m_frame->document())); | 749 DCHECK(selection().isValidFor(*m_frame->document())); |
741 return m_frameCaret->absoluteCaretBounds(); | 750 return m_frameCaret->absoluteCaretBounds(); |
742 } | 751 } |
743 | 752 |
744 void FrameSelection::invalidateCaretRect(bool forceInvalidation) { | |
745 m_frameCaret->invalidateCaretRect(forceInvalidation); | |
746 } | |
747 | |
748 void FrameSelection::dataWillChange(const CharacterData& node) { | |
749 m_frameCaret->dataWillChange(node); | |
750 } | |
751 | |
752 void FrameSelection::paintCaret(GraphicsContext& context, | 753 void FrameSelection::paintCaret(GraphicsContext& context, |
753 const LayoutPoint& paintOffset) { | 754 const LayoutPoint& paintOffset) { |
754 m_frameCaret->paintCaret(context, paintOffset); | 755 m_frameCaret->paintCaret(context, paintOffset); |
755 } | 756 } |
756 | 757 |
757 bool FrameSelection::contains(const LayoutPoint& point) { | 758 bool FrameSelection::contains(const LayoutPoint& point) { |
758 if (document().layoutViewItem().isNull()) | 759 if (document().layoutViewItem().isNull()) |
759 return false; | 760 return false; |
760 | 761 |
761 // Treat a collapsed selection like no selection. | 762 // Treat a collapsed selection like no selection. |
(...skipping 282 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1044 | 1045 |
1045 bool FrameSelection::isAppearanceDirty() const { | 1046 bool FrameSelection::isAppearanceDirty() const { |
1046 return m_pendingSelection->hasPendingSelection(); | 1047 return m_pendingSelection->hasPendingSelection(); |
1047 } | 1048 } |
1048 | 1049 |
1049 void FrameSelection::commitAppearanceIfNeeded(LayoutView& layoutView) { | 1050 void FrameSelection::commitAppearanceIfNeeded(LayoutView& layoutView) { |
1050 return m_pendingSelection->commit(layoutView); | 1051 return m_pendingSelection->commit(layoutView); |
1051 } | 1052 } |
1052 | 1053 |
1053 void FrameSelection::didLayout() { | 1054 void FrameSelection::didLayout() { |
1054 setCaretRectNeedsUpdate(); | 1055 setCaretMayNeedPaintInvalidation(); |
1055 updateAppearance(); | 1056 updateAppearance(); |
1056 } | 1057 } |
1057 | 1058 |
1058 void FrameSelection::updateAppearance() { | 1059 void FrameSelection::updateAppearance() { |
1059 m_frameCaret->updateAppearance(); | 1060 m_frameCaret->updateAppearance(); |
1060 | 1061 |
1061 if (m_frame->contentLayoutItem().isNull()) | 1062 if (m_frame->contentLayoutItem().isNull()) |
1062 return; | 1063 return; |
1063 m_pendingSelection->setHasPendingSelection(); | 1064 m_pendingSelection->setHasPendingSelection(); |
1064 } | 1065 } |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1397 | 1398 |
1398 void FrameSelection::setCaretVisible(bool caretIsVisible) { | 1399 void FrameSelection::setCaretVisible(bool caretIsVisible) { |
1399 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible | 1400 m_frameCaret->setCaretVisibility(caretIsVisible ? CaretVisibility::Visible |
1400 : CaretVisibility::Hidden); | 1401 : CaretVisibility::Hidden); |
1401 } | 1402 } |
1402 | 1403 |
1403 bool FrameSelection::shouldPaintCaretForTesting() const { | 1404 bool FrameSelection::shouldPaintCaretForTesting() const { |
1404 return m_frameCaret->shouldPaintCaretForTesting(); | 1405 return m_frameCaret->shouldPaintCaretForTesting(); |
1405 } | 1406 } |
1406 | 1407 |
1407 bool FrameSelection::isPreviousCaretDirtyForTesting() const { | 1408 void FrameSelection::setCaretMayNeedPaintInvalidation() { |
1408 return m_frameCaret->isPreviousCaretDirtyForTesting(); | 1409 m_frameCaret->setMayNeedPaintInvalidation(); |
1409 } | 1410 } |
1410 | 1411 |
1411 void FrameSelection::setCaretRectNeedsUpdate() { | 1412 void FrameSelection::setCaretNeedsPaintInvalidation() { |
1412 m_frameCaret->setCaretRectNeedsUpdate(); | 1413 m_frameCaret->setNeedsPaintInvalidation(); |
1413 } | 1414 } |
1414 | 1415 |
1415 void FrameSelection::setCaretBlinkingSuspended(bool suspended) { | 1416 void FrameSelection::setCaretBlinkingSuspended(bool suspended) { |
1416 m_frameCaret->setCaretBlinkingSuspended(suspended); | 1417 m_frameCaret->setCaretBlinkingSuspended(suspended); |
1417 } | 1418 } |
1418 | 1419 |
1419 bool FrameSelection::isCaretBlinkingSuspended() const { | 1420 bool FrameSelection::isCaretBlinkingSuspended() const { |
1420 return m_frameCaret->isCaretBlinkingSuspended(); | 1421 return m_frameCaret->isCaretBlinkingSuspended(); |
1421 } | 1422 } |
1422 | 1423 |
1423 } // namespace blink | 1424 } // namespace blink |
1424 | 1425 |
1425 #ifndef NDEBUG | 1426 #ifndef NDEBUG |
1426 | 1427 |
1427 void showTree(const blink::FrameSelection& sel) { | 1428 void showTree(const blink::FrameSelection& sel) { |
1428 sel.showTreeForThis(); | 1429 sel.showTreeForThis(); |
1429 } | 1430 } |
1430 | 1431 |
1431 void showTree(const blink::FrameSelection* sel) { | 1432 void showTree(const blink::FrameSelection* sel) { |
1432 if (sel) | 1433 if (sel) |
1433 sel->showTreeForThis(); | 1434 sel->showTreeForThis(); |
1434 else | 1435 else |
1435 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; | 1436 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; |
1436 } | 1437 } |
1437 | 1438 |
1438 #endif | 1439 #endif |
OLD | NEW |