Chromium Code Reviews| 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 21 matching lines...) Expand all Loading... | |
| 32 #include "core/dom/AXObjectCache.h" | 32 #include "core/dom/AXObjectCache.h" |
| 33 #include "core/dom/CharacterData.h" | 33 #include "core/dom/CharacterData.h" |
| 34 #include "core/dom/Document.h" | 34 #include "core/dom/Document.h" |
| 35 #include "core/dom/Element.h" | 35 #include "core/dom/Element.h" |
| 36 #include "core/dom/ElementTraversal.h" | 36 #include "core/dom/ElementTraversal.h" |
| 37 #include "core/dom/NodeTraversal.h" | 37 #include "core/dom/NodeTraversal.h" |
| 38 #include "core/dom/Text.h" | 38 #include "core/dom/Text.h" |
| 39 #include "core/editing/CaretBase.h" | 39 #include "core/editing/CaretBase.h" |
| 40 #include "core/editing/EditingUtilities.h" | 40 #include "core/editing/EditingUtilities.h" |
| 41 #include "core/editing/Editor.h" | 41 #include "core/editing/Editor.h" |
| 42 #include "core/editing/FrameCaret.h" | |
| 42 #include "core/editing/GranularityStrategy.h" | 43 #include "core/editing/GranularityStrategy.h" |
| 43 #include "core/editing/InputMethodController.h" | 44 #include "core/editing/InputMethodController.h" |
| 44 #include "core/editing/PendingSelection.h" | 45 #include "core/editing/PendingSelection.h" |
| 45 #include "core/editing/RenderedPosition.h" | 46 #include "core/editing/RenderedPosition.h" |
| 46 #include "core/editing/SelectionController.h" | 47 #include "core/editing/SelectionController.h" |
| 47 #include "core/editing/SelectionEditor.h" | 48 #include "core/editing/SelectionEditor.h" |
| 48 #include "core/editing/SelectionModifier.h" | 49 #include "core/editing/SelectionModifier.h" |
| 49 #include "core/editing/TextAffinity.h" | 50 #include "core/editing/TextAffinity.h" |
| 50 #include "core/editing/VisibleUnits.h" | 51 #include "core/editing/VisibleUnits.h" |
| 51 #include "core/editing/commands/TypingCommand.h" | 52 #include "core/editing/commands/TypingCommand.h" |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 91 { | 92 { |
| 92 return !frame || frame->editor().behavior().shouldConsiderSelectionAsDirecti onal(); | 93 return !frame || frame->editor().behavior().shouldConsiderSelectionAsDirecti onal(); |
| 93 } | 94 } |
| 94 | 95 |
| 95 FrameSelection::FrameSelection(LocalFrame* frame) | 96 FrameSelection::FrameSelection(LocalFrame* frame) |
| 96 : m_frame(frame) | 97 : m_frame(frame) |
| 97 , m_pendingSelection(PendingSelection::create(*this)) | 98 , m_pendingSelection(PendingSelection::create(*this)) |
| 98 , m_selectionEditor(SelectionEditor::create(*this)) | 99 , m_selectionEditor(SelectionEditor::create(*this)) |
| 99 , m_granularity(CharacterGranularity) | 100 , m_granularity(CharacterGranularity) |
| 100 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) | 101 , m_xPosForVerticalArrowNavigation(NoXPosForVerticalArrowNavigation()) |
| 101 , m_previousCaretVisibility(CaretVisibility::Hidden) | |
| 102 , m_caretBlinkTimer(this, &FrameSelection::caretBlinkTimerFired) | |
| 103 , m_caretRectDirty(true) | |
| 104 , m_shouldPaintCaret(true) | |
| 105 , m_isCaretBlinkingSuspended(false) | |
| 106 , m_focused(frame && frame->page() && frame->page()->focusController().focus edFrame() == frame) | 102 , m_focused(frame && frame->page() && frame->page()->focusController().focus edFrame() == frame) |
| 107 , m_shouldShowBlockCursor(false) | 103 , m_shouldShowBlockCursor(false) |
| 108 , m_caretBase(adoptPtr(new CaretBase)) | 104 , m_frameCaret(new FrameCaret(frame)) |
| 109 { | 105 { |
| 110 // TODO(yosin): We should remove null check for |m_frame| in | 106 // TODO(yosin): We should remove null check for |m_frame| in |
| 111 // "FrameSelection.cpp", since it never be null. | 107 // "FrameSelection.cpp", since it never be null. |
| 112 DCHECK(frame); | 108 DCHECK(frame); |
| 113 if (shouldAlwaysUseDirectionalSelection(m_frame)) | 109 if (shouldAlwaysUseDirectionalSelection(m_frame)) |
| 114 m_selectionEditor->setIsDirectional(true); | 110 m_selectionEditor->setIsDirectional(true); |
| 115 } | 111 } |
| 116 | 112 |
| 117 FrameSelection::~FrameSelection() | 113 FrameSelection::~FrameSelection() |
| 118 { | 114 { |
| (...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 | 328 |
| 333 m_selectionEditor->setVisibleSelection(s, options); | 329 m_selectionEditor->setVisibleSelection(s, options); |
| 334 setCaretRectNeedsUpdate(); | 330 setCaretRectNeedsUpdate(); |
| 335 | 331 |
| 336 if (!s.isNone() && !(options & DoNotSetFocus)) | 332 if (!s.isNone() && !(options & DoNotSetFocus)) |
| 337 setFocusedNodeIfNeeded(); | 333 setFocusedNodeIfNeeded(); |
| 338 | 334 |
| 339 if (!(options & DoNotUpdateAppearance)) { | 335 if (!(options & DoNotUpdateAppearance)) { |
| 340 // Hits in compositing/overflow/do-not-paint-outline-into-composited-scr olling-contents.html | 336 // Hits in compositing/overflow/do-not-paint-outline-into-composited-scr olling-contents.html |
| 341 DisableCompositingQueryAsserts disabler; | 337 DisableCompositingQueryAsserts disabler; |
| 342 stopCaretBlinkTimer(); | 338 m_frameCaret->stopCaretBlinkTimer(); |
| 343 updateAppearance(); | 339 updateAppearance(); |
| 344 } | 340 } |
| 345 | 341 |
| 346 // Always clear the x position used for vertical arrow navigation. | 342 // Always clear the x position used for vertical arrow navigation. |
| 347 // It will be restored by the vertical arrow navigation code if necessary. | 343 // It will be restored by the vertical arrow navigation code if necessary. |
| 348 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); | 344 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); |
| 349 // This may dispatch a synchronous focus-related events. | 345 // This may dispatch a synchronous focus-related events. |
| 350 selectFrameElementInParentIfFullySelected(); | 346 selectFrameElementInParentIfFullySelected(); |
| 351 notifyLayoutObjectOfSelectionChange(userTriggered); | 347 notifyLayoutObjectOfSelectionChange(userTriggered); |
| 352 // If the selections are same in the DOM tree but not in the flat tree, | 348 // If the selections are same in the DOM tree but not in the flat tree, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 394 if (position.anchorNode() == node) | 390 if (position.anchorNode() == node) |
| 395 return true; | 391 return true; |
| 396 | 392 |
| 397 if (!node.isElementNode()) | 393 if (!node.isElementNode()) |
| 398 return false; | 394 return false; |
| 399 | 395 |
| 400 Element& element = toElement(node); | 396 Element& element = toElement(node); |
| 401 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode()); | 397 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode()); |
| 402 } | 398 } |
| 403 | 399 |
| 400 void FrameCaret::nodeWillBeRemoved(Node& node) | |
|
yosin_UTC9
2016/05/19 08:32:36
Please add TODO to move this function to "FrameCar
yoichio
2016/05/20 05:12:12
Done.
| |
| 401 { | |
| 402 if (node == m_previousCaretNode) { | |
|
yosin_UTC9
2016/05/19 08:32:36
Please use early return style.
yoichio
2016/05/20 05:12:12
Done.
| |
| 403 // Hits in ManualTests/caret-paint-after-last-text-is-removed.html | |
| 404 DisableCompositingQueryAsserts disabler; | |
| 405 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ; | |
| 406 m_previousCaretNode = nullptr; | |
| 407 m_previousCaretRect = LayoutRect(); | |
| 408 m_previousCaretVisibility = CaretVisibility::Hidden; | |
| 409 } | |
| 410 } | |
| 411 | |
| 404 void FrameSelection::nodeWillBeRemoved(Node& node) | 412 void FrameSelection::nodeWillBeRemoved(Node& node) |
| 405 { | 413 { |
| 406 // There can't be a selection inside a fragment, so if a fragment's node is being removed, | 414 // There can't be a selection inside a fragment, so if a fragment's node is being removed, |
| 407 // the selection in the document that created the fragment needs no adjustme nt. | 415 // the selection in the document that created the fragment needs no adjustme nt. |
| 408 if (isNone() || !node.inActiveDocument()) | 416 if (isNone() || !node.inActiveDocument()) |
| 409 return; | 417 return; |
| 410 | 418 |
| 411 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()), | 419 respondToNodeModification(node, removingNodeRemovesPosition(node, selection( ).base()), removingNodeRemovesPosition(node, selection().extent()), |
| 412 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end())); | 420 removingNodeRemovesPosition(node, selection().start()), removingNodeRemo vesPosition(node, selection().end())); |
| 413 | 421 |
| 414 if (node == m_previousCaretNode) { | 422 m_frameCaret->nodeWillBeRemoved(node); |
| 415 // Hits in ManualTests/caret-paint-after-last-text-is-removed.html | |
| 416 DisableCompositingQueryAsserts disabler; | |
| 417 m_caretBase->invalidateLocalCaretRect(m_previousCaretNode.get(), m_previ ousCaretRect); | |
| 418 m_previousCaretNode = nullptr; | |
| 419 m_previousCaretRect = LayoutRect(); | |
| 420 m_previousCaretVisibility = CaretVisibility::Hidden; | |
| 421 } | |
| 422 } | 423 } |
| 423 | 424 |
| 424 static bool intersectsNode(const VisibleSelection& selection, Node* node) | 425 static bool intersectsNode(const VisibleSelection& selection, Node* node) |
| 425 { | 426 { |
| 426 if (selection.isNone()) | 427 if (selection.isNone()) |
| 427 return false; | 428 return false; |
| 428 Position start = selection.start().parentAnchoredEquivalent(); | 429 Position start = selection.start().parentAnchoredEquivalent(); |
| 429 Position end = selection.end().parentAnchoredEquivalent(); | 430 Position end = selection.end().parentAnchoredEquivalent(); |
| 430 TrackExceptionState exceptionState; | 431 TrackExceptionState exceptionState; |
| 431 // TODO(yosin) We should avoid to use |Range::intersectsNode()|. | 432 // TODO(yosin) We should avoid to use |Range::intersectsNode()|. |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 | 628 |
| 628 const SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTri ggered; | 629 const SetSelectionOptions options = CloseTyping | ClearTypingStyle | userTri ggered; |
| 629 setSelection(selectionModifier.selection(), options); | 630 setSelection(selectionModifier.selection(), options); |
| 630 | 631 |
| 631 if (granularity == LineGranularity || granularity == ParagraphGranularity) | 632 if (granularity == LineGranularity || granularity == ParagraphGranularity) |
| 632 m_xPosForVerticalArrowNavigation = selectionModifier.xPosForVerticalArro wNavigation(); | 633 m_xPosForVerticalArrowNavigation = selectionModifier.xPosForVerticalArro wNavigation(); |
| 633 | 634 |
| 634 if (userTriggered == UserTriggered) | 635 if (userTriggered == UserTriggered) |
| 635 m_granularity = CharacterGranularity; | 636 m_granularity = CharacterGranularity; |
| 636 | 637 |
| 637 setCaretRectNeedsUpdate(); | 638 m_frameCaret->setCaretRectNeedsUpdate(); |
| 638 | 639 |
| 639 return true; | 640 return true; |
| 640 } | 641 } |
| 641 | 642 |
| 642 bool FrameSelection::modify(EAlteration alter, unsigned verticalDistance, Vertic alDirection direction, EUserTriggered userTriggered, CursorAlignOnScroll align) | 643 bool FrameSelection::modify(EAlteration alter, unsigned verticalDistance, Vertic alDirection direction, EUserTriggered userTriggered, CursorAlignOnScroll align) |
| 643 { | 644 { |
| 644 SelectionModifier selectionModifier(*frame(), selection()); | 645 SelectionModifier selectionModifier(*frame(), selection()); |
| 645 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, di rection)) | 646 if (!selectionModifier.modifyWithPageGranularity(alter, verticalDistance, di rection)) |
| 646 return false; | 647 return false; |
| 647 | 648 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 658 } | 659 } |
| 659 | 660 |
| 660 void FrameSelection::clear() | 661 void FrameSelection::clear() |
| 661 { | 662 { |
| 662 m_granularity = CharacterGranularity; | 663 m_granularity = CharacterGranularity; |
| 663 if (m_granularityStrategy) | 664 if (m_granularityStrategy) |
| 664 m_granularityStrategy->Clear(); | 665 m_granularityStrategy->Clear(); |
| 665 setSelection(VisibleSelection()); | 666 setSelection(VisibleSelection()); |
| 666 } | 667 } |
| 667 | 668 |
| 669 // TODO(yoiciho): We should move this function to FrameCaret.cpp | |
| 670 void FrameCaret::prepareForDestruction() | |
| 671 { | |
| 672 m_caretBlinkTimer.stop(); | |
| 673 m_previousCaretNode.clear(); | |
| 674 } | |
| 675 | |
| 668 void FrameSelection::prepareForDestruction() | 676 void FrameSelection::prepareForDestruction() |
| 669 { | 677 { |
| 670 m_granularity = CharacterGranularity; | 678 m_granularity = CharacterGranularity; |
| 671 | 679 |
| 672 m_caretBlinkTimer.stop(); | |
| 673 | |
| 674 LayoutViewItem view = m_frame->contentLayoutItem(); | 680 LayoutViewItem view = m_frame->contentLayoutItem(); |
| 675 if (!view.isNull()) | 681 if (!view.isNull()) |
| 676 view.clearSelection(); | 682 view.clearSelection(); |
| 677 | 683 |
| 678 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat eAppearance); | 684 setSelection(VisibleSelection(), CloseTyping | ClearTypingStyle | DoNotUpdat eAppearance); |
| 679 m_selectionEditor->dispose(); | 685 m_selectionEditor->dispose(); |
| 680 m_previousCaretNode.clear(); | 686 m_frameCaret->prepareForDestruction(); |
| 681 } | 687 } |
| 682 | 688 |
| 683 void FrameSelection::setBase(const VisiblePosition &pos, EUserTriggered userTrig gered) | 689 void FrameSelection::setBase(const VisiblePosition &pos, EUserTriggered userTrig gered) |
| 684 { | 690 { |
| 685 const bool selectionHasDirection = true; | 691 const bool selectionHasDirection = true; |
| 686 setSelection(VisibleSelection(pos.deepEquivalent(), selection().extent(), po s.affinity(), selectionHasDirection), CloseTyping | ClearTypingStyle | userTrigg ered); | 692 setSelection(VisibleSelection(pos.deepEquivalent(), selection().extent(), po s.affinity(), selectionHasDirection), CloseTyping | ClearTypingStyle | userTrigg ered); |
| 687 } | 693 } |
| 688 | 694 |
| 689 void FrameSelection::setExtent(const VisiblePosition &pos, EUserTriggered userTr iggered) | 695 void FrameSelection::setExtent(const VisiblePosition &pos, EUserTriggered userTr iggered) |
| 690 { | 696 { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 703 if (!isCaret()) | 709 if (!isCaret()) |
| 704 return nullptr; | 710 return nullptr; |
| 705 return CaretBase::caretLayoutObject(selection().start().anchorNode()); | 711 return CaretBase::caretLayoutObject(selection().start().anchorNode()); |
| 706 } | 712 } |
| 707 | 713 |
| 708 IntRect FrameSelection::absoluteCaretBounds() | 714 IntRect FrameSelection::absoluteCaretBounds() |
| 709 { | 715 { |
| 710 DCHECK(selection().isValidFor(*m_frame->document())); | 716 DCHECK(selection().isValidFor(*m_frame->document())); |
| 711 DCHECK_NE(m_frame->document()->lifecycle().state(), DocumentLifecycle::InPai ntInvalidation); | 717 DCHECK_NE(m_frame->document()->lifecycle().state(), DocumentLifecycle::InPai ntInvalidation); |
| 712 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 718 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 713 if (!isCaret()) { | 719 if (!isCaret()) { |
|
yosin_UTC9
2016/05/19 08:32:36
All of functionality should be in FrameCaret::abso
yoichio
2016/05/20 05:12:12
I agree, but this function use selection() deeply
| |
| 714 m_caretBase->clearCaretRect(); | 720 m_frameCaret->clearCaretRect(); |
| 715 } else { | 721 } else { |
| 716 if (isTextFormControl(selection())) | 722 if (isTextFormControl(selection())) |
| 717 m_caretBase->updateCaretRect(PositionWithAffinity(isVisuallyEquivale ntCandidate(selection().start()) ? selection().start() : Position(), selection() .affinity())); | 723 m_frameCaret->updateCaretRect(PositionWithAffinity(isVisuallyEquival entCandidate(selection().start()) ? selection().start() : Position(), selection( ).affinity())); |
| 718 else | 724 else |
| 719 m_caretBase->updateCaretRect(createVisiblePosition(selection().start (), selection().affinity())); | 725 m_frameCaret->updateCaretRect(createVisiblePosition(selection().star t(), selection().affinity())); |
| 720 } | 726 } |
| 721 return m_caretBase->absoluteBoundsForLocalRect(selection().start().anchorNod e(), m_caretBase->localCaretRectWithoutUpdate()); | 727 return m_frameCaret->absoluteBoundsForLocalRect(selection().start().anchorNo de(), m_frameCaret->localCaretRectWithoutUpdate()); |
| 722 } | 728 } |
| 723 | 729 |
| 724 void FrameSelection::invalidateCaretRect() | 730 // TODO(yoiciho): We should move this function to FrameCaret.cpp |
| 731 void FrameCaret::invalidateCaretRect(const VisibleSelection& selection) | |
| 725 { | 732 { |
| 726 if (!m_caretRectDirty) | 733 if (!m_caretRectDirty) |
| 727 return; | 734 return; |
| 728 m_caretRectDirty = false; | 735 m_caretRectDirty = false; |
| 729 | 736 |
| 730 DCHECK(selection().isValidFor(*m_frame->document())); | 737 DCHECK(selection.isValidFor(*m_frame->document())); |
| 731 LayoutObject* layoutObject = nullptr; | 738 LayoutObject* layoutObject = nullptr; |
| 732 LayoutRect newRect; | 739 LayoutRect newRect; |
| 733 if (selection().isCaret()) | 740 if (selection.isCaret()) |
| 734 newRect = localCaretRectOfPosition(PositionWithAffinity(selection().star t(), selection().affinity()), layoutObject); | 741 newRect = localCaretRectOfPosition(PositionWithAffinity(selection.start( ), selection.affinity()), layoutObject); |
| 735 Node* newNode = layoutObject ? layoutObject->node() : nullptr; | 742 Node* newNode = layoutObject ? layoutObject->node() : nullptr; |
| 736 | 743 |
| 737 if (!m_caretBlinkTimer.isActive() | 744 if (!m_caretBlinkTimer.isActive() |
| 738 && newNode == m_previousCaretNode | 745 && newNode == m_previousCaretNode |
| 739 && newRect == m_previousCaretRect | 746 && newRect == m_previousCaretRect |
| 740 && m_caretBase->getCaretVisibility() == m_previousCaretVisibility) | 747 && getCaretVisibility() == m_previousCaretVisibility) |
| 741 return; | 748 return; |
| 742 | 749 |
| 743 LayoutViewItem view = m_frame->document()->layoutViewItem(); | 750 LayoutViewItem view = m_frame->document()->layoutViewItem(); |
| 744 if (m_previousCaretNode && (m_caretBase->shouldRepaintCaret(*m_previousCaret Node) || m_caretBase->shouldRepaintCaret(view))) | 751 if (m_previousCaretNode && (shouldRepaintCaret(*m_previousCaretNode) || shou ldRepaintCaret(view))) |
| 745 m_caretBase->invalidateLocalCaretRect(m_previousCaretNode.get(), m_previ ousCaretRect); | 752 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ; |
| 746 if (newNode && (m_caretBase->shouldRepaintCaret(*newNode) || m_caretBase->sh ouldRepaintCaret(view))) | 753 if (newNode && (shouldRepaintCaret(*newNode) || shouldRepaintCaret(view))) |
| 747 m_caretBase->invalidateLocalCaretRect(newNode, newRect); | 754 invalidateLocalCaretRect(newNode, newRect); |
| 748 m_previousCaretNode = newNode; | 755 m_previousCaretNode = newNode; |
| 749 m_previousCaretRect = newRect; | 756 m_previousCaretRect = newRect; |
| 750 m_previousCaretVisibility = m_caretBase->getCaretVisibility(); | 757 m_previousCaretVisibility = getCaretVisibility(); |
| 758 } | |
| 759 | |
| 760 void FrameSelection::invalidateCaretRect() | |
| 761 { | |
| 762 m_frameCaret->invalidateCaretRect(selection()); | |
| 763 } | |
| 764 | |
| 765 // TODO(yoiciho): We should move this function to FrameCaret.cpp | |
| 766 void FrameCaret::dataWillChange(const CharacterData& node) | |
| 767 { | |
| 768 if (node == m_previousCaretNode) { | |
| 769 // This invalidation is eager, and intentionally uses stale state. | |
| 770 DisableCompositingQueryAsserts disabler; | |
| 771 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ; | |
| 772 } | |
| 751 } | 773 } |
| 752 | 774 |
| 753 void FrameSelection::dataWillChange(const CharacterData& node) | 775 void FrameSelection::dataWillChange(const CharacterData& node) |
| 754 { | 776 { |
| 755 if (node == m_previousCaretNode) { | 777 m_frameCaret->dataWillChange(node); |
| 756 // This invalidation is eager, and intentionally uses stale state. | 778 } |
| 757 DisableCompositingQueryAsserts disabler; | 779 |
| 758 m_caretBase->invalidateLocalCaretRect(m_previousCaretNode.get(), m_previ ousCaretRect); | 780 // TODO(yoiciho): We should move this function to FrameCaret.cpp |
| 781 void FrameCaret::paintCaret(GraphicsContext& context, const LayoutPoint& paintOf fset, const VisibleSelection& selection) | |
| 782 { | |
| 783 if (selection.isCaret() && m_shouldPaintCaret) { | |
| 784 updateCaretRect(PositionWithAffinity(selection.start(), selection.affini ty())); | |
| 785 CaretBase::paintCaret(selection.start().anchorNode(), context, paintOffs et); | |
| 759 } | 786 } |
| 760 } | 787 } |
| 761 | 788 |
| 762 void FrameSelection::paintCaret(GraphicsContext& context, const LayoutPoint& pai ntOffset) | 789 void FrameSelection::paintCaret(GraphicsContext& context, const LayoutPoint& pai ntOffset) |
| 763 { | 790 { |
| 764 if (selection().isCaret() && m_shouldPaintCaret) { | 791 m_frameCaret->paintCaret(context, paintOffset, selection()); |
| 765 m_caretBase->updateCaretRect(PositionWithAffinity(selection().start(), s election().affinity())); | |
| 766 m_caretBase->paintCaret(selection().start().anchorNode(), context, paint Offset); | |
| 767 } | |
| 768 } | 792 } |
| 769 | 793 |
| 770 bool FrameSelection::contains(const LayoutPoint& point) | 794 bool FrameSelection::contains(const LayoutPoint& point) |
| 771 { | 795 { |
| 772 Document* document = m_frame->document(); | 796 Document* document = m_frame->document(); |
| 773 if (document->layoutViewItem().isNull()) | 797 if (document->layoutViewItem().isNull()) |
| 774 return false; | 798 return false; |
| 775 | 799 |
| 776 // Treat a collapsed selection like no selection. | 800 // Treat a collapsed selection like no selection. |
| 777 const VisibleSelectionInFlatTree& visibleSelection = this->visibleSelection< EditingInFlatTreeStrategy>(); | 801 const VisibleSelectionInFlatTree& visibleSelection = this->visibleSelection< EditingInFlatTreeStrategy>(); |
| (...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1031 bool FrameSelection::isAppearanceDirty() const | 1055 bool FrameSelection::isAppearanceDirty() const |
| 1032 { | 1056 { |
| 1033 return m_pendingSelection->hasPendingSelection(); | 1057 return m_pendingSelection->hasPendingSelection(); |
| 1034 } | 1058 } |
| 1035 | 1059 |
| 1036 void FrameSelection::commitAppearanceIfNeeded(LayoutView& layoutView) | 1060 void FrameSelection::commitAppearanceIfNeeded(LayoutView& layoutView) |
| 1037 { | 1061 { |
| 1038 return m_pendingSelection->commit(layoutView); | 1062 return m_pendingSelection->commit(layoutView); |
| 1039 } | 1063 } |
| 1040 | 1064 |
| 1065 // TODO(yoiciho): We should move this function to FrameCaret.cpp | |
| 1066 void FrameCaret::startBlinkCaret() | |
| 1067 { | |
| 1068 // Start blinking with a black caret. Be sure not to restart if we're | |
| 1069 // already blinking in the right location. | |
| 1070 if (!m_caretBlinkTimer.isActive()) { | |
| 1071 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval()) | |
| 1072 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE); | |
| 1073 | |
| 1074 m_shouldPaintCaret = true; | |
| 1075 setCaretRectNeedsUpdate(); | |
| 1076 } | |
| 1077 } | |
| 1078 | |
| 1041 void FrameSelection::updateAppearance() | 1079 void FrameSelection::updateAppearance() |
| 1042 { | 1080 { |
| 1043 // Paint a block cursor instead of a caret in overtype mode unless the caret is at the end of a line (in this case | 1081 // Paint a block cursor instead of a caret in overtype mode unless the caret is at the end of a line (in this case |
| 1044 // the FrameSelection will paint a blinking caret as usual). | 1082 // the FrameSelection will paint a blinking caret as usual). |
| 1045 bool paintBlockCursor = m_shouldShowBlockCursor && selection().isCaret() && !isLogicalEndOfLine(selection().visibleEnd()); | 1083 bool paintBlockCursor = m_shouldShowBlockCursor && selection().isCaret() && !isLogicalEndOfLine(selection().visibleEnd()); |
| 1046 | 1084 |
| 1047 bool shouldBlink = !paintBlockCursor && shouldBlinkCaret(); | 1085 bool shouldBlink = !paintBlockCursor && shouldBlinkCaret(); |
| 1048 | 1086 |
| 1049 // If the caret moved, stop the blink timer so we can restart with a | 1087 // If the caret moved, stop the blink timer so we can restart with a |
| 1050 // black caret in the new location. | 1088 // black caret in the new location. |
| 1051 if (!shouldBlink || shouldStopBlinkingDueToTypingCommand(m_frame)) | 1089 if (!shouldBlink || shouldStopBlinkingDueToTypingCommand(m_frame)) |
| 1052 stopCaretBlinkTimer(); | 1090 m_frameCaret->stopCaretBlinkTimer(); |
|
yosin_UTC9
2016/05/19 08:32:36
It is better to have FrameCaret::updateApperance()
yoichio
2016/05/20 05:12:12
Ditto to FrameSelection::absoluteCaretBounds chang
| |
| 1053 | 1091 |
| 1054 // Start blinking with a black caret. Be sure not to restart if we're | 1092 // Start blinking with a black caret. Be sure not to restart if we're |
| 1055 // already blinking in the right location. | 1093 // already blinking in the right location. |
| 1056 if (shouldBlink && !m_caretBlinkTimer.isActive()) { | 1094 if (shouldBlink) |
| 1057 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval()) | 1095 m_frameCaret->startBlinkCaret(); |
| 1058 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE); | |
| 1059 | |
| 1060 m_shouldPaintCaret = true; | |
| 1061 setCaretRectNeedsUpdate(); | |
| 1062 } | |
| 1063 | 1096 |
| 1064 if (m_frame->contentLayoutItem().isNull()) | 1097 if (m_frame->contentLayoutItem().isNull()) |
| 1065 return; | 1098 return; |
| 1066 m_pendingSelection->setHasPendingSelection(); | 1099 m_pendingSelection->setHasPendingSelection(); |
| 1067 } | 1100 } |
| 1068 | 1101 |
| 1069 void FrameSelection::setCaretVisibility(CaretVisibility visibility) | 1102 void FrameSelection::setCaretVisibility(CaretVisibility visibility) |
| 1070 { | 1103 { |
| 1071 if (m_caretBase->getCaretVisibility() == visibility) | 1104 if (m_frameCaret->getCaretVisibility() == visibility) |
|
yosin_UTC9
2016/05/19 08:32:36
Checking newValue == oldValue should be in FrameCa
yoichio
2016/05/20 05:12:12
Ditto to appdateAppearance.
| |
| 1072 return; | 1105 return; |
| 1073 | 1106 |
| 1074 m_caretBase->setCaretVisibility(visibility); | 1107 m_frameCaret->setCaretVisibility(visibility); |
| 1075 | 1108 |
| 1076 updateAppearance(); | 1109 updateAppearance(); |
| 1077 } | 1110 } |
| 1078 | 1111 |
| 1079 bool FrameSelection::shouldBlinkCaret() const | 1112 bool FrameSelection::shouldBlinkCaret() const |
| 1080 { | 1113 { |
| 1081 if (!m_caretBase->caretIsVisible() || !isCaret()) | 1114 if (!m_frameCaret->caretIsVisible() || !isCaret()) |
|
yosin_UTC9
2016/05/19 08:32:36
FrameCaret should have bool shouldBlinkCaret()
yoichio
2016/05/20 05:12:12
Ditto.
| |
| 1082 return false; | 1115 return false; |
| 1083 | 1116 |
| 1084 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled()) | 1117 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled()) |
| 1085 return false; | 1118 return false; |
| 1086 | 1119 |
| 1087 Element* root = rootEditableElement(); | 1120 Element* root = rootEditableElement(); |
| 1088 if (!root) | 1121 if (!root) |
| 1089 return false; | 1122 return false; |
| 1090 | 1123 |
| 1091 Element* focusedElement = root->document().focusedElement(); | 1124 Element* focusedElement = root->document().focusedElement(); |
| 1092 if (!focusedElement) | 1125 if (!focusedElement) |
| 1093 return false; | 1126 return false; |
| 1094 | 1127 |
| 1095 return focusedElement->isShadowIncludingInclusiveAncestorOf(selection().star t().anchorNode()); | 1128 return focusedElement->isShadowIncludingInclusiveAncestorOf(selection().star t().anchorNode()); |
| 1096 } | 1129 } |
| 1097 | 1130 |
| 1098 void FrameSelection::caretBlinkTimerFired(Timer<FrameSelection>*) | 1131 // TODO(yoiciho): We should move this function to FrameCaret.cpp |
| 1132 void FrameCaret::caretBlinkTimerFired(Timer<FrameCaret>*) | |
| 1099 { | 1133 { |
| 1100 DCHECK(m_caretBase->caretIsVisible()); | 1134 DCHECK(caretIsVisible()); |
| 1101 DCHECK(isCaret()); | |
| 1102 if (isCaretBlinkingSuspended() && m_shouldPaintCaret) | 1135 if (isCaretBlinkingSuspended() && m_shouldPaintCaret) |
| 1103 return; | 1136 return; |
| 1104 m_shouldPaintCaret = !m_shouldPaintCaret; | 1137 m_shouldPaintCaret = !m_shouldPaintCaret; |
| 1105 setCaretRectNeedsUpdate(); | 1138 setCaretRectNeedsUpdate(); |
| 1106 } | 1139 } |
| 1107 | 1140 |
| 1108 void FrameSelection::stopCaretBlinkTimer() | 1141 // TODO(yoiciho): We should move this function to FrameCaret.cpp |
| 1142 void FrameCaret::stopCaretBlinkTimer() | |
| 1109 { | 1143 { |
| 1110 if (m_caretBlinkTimer.isActive() || m_shouldPaintCaret) | 1144 if (m_caretBlinkTimer.isActive() || m_shouldPaintCaret) |
| 1111 setCaretRectNeedsUpdate(); | 1145 setCaretRectNeedsUpdate(); |
| 1112 m_shouldPaintCaret = false; | 1146 m_shouldPaintCaret = false; |
| 1113 m_caretBlinkTimer.stop(); | 1147 m_caretBlinkTimer.stop(); |
| 1114 } | 1148 } |
| 1115 | 1149 |
| 1116 void FrameSelection::notifyLayoutObjectOfSelectionChange(EUserTriggered userTrig gered) | 1150 void FrameSelection::notifyLayoutObjectOfSelectionChange(EUserTriggered userTrig gered) |
| 1117 { | 1151 { |
| 1118 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start ())) | 1152 if (HTMLTextFormControlElement* textControl = enclosingTextFormControl(start ())) |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1349 | 1383 |
| 1350 #endif | 1384 #endif |
| 1351 | 1385 |
| 1352 DEFINE_TRACE(FrameSelection) | 1386 DEFINE_TRACE(FrameSelection) |
| 1353 { | 1387 { |
| 1354 visitor->trace(m_frame); | 1388 visitor->trace(m_frame); |
| 1355 visitor->trace(m_pendingSelection); | 1389 visitor->trace(m_pendingSelection); |
| 1356 visitor->trace(m_selectionEditor); | 1390 visitor->trace(m_selectionEditor); |
| 1357 visitor->trace(m_originalBase); | 1391 visitor->trace(m_originalBase); |
| 1358 visitor->trace(m_originalBaseInFlatTree); | 1392 visitor->trace(m_originalBaseInFlatTree); |
| 1359 visitor->trace(m_previousCaretNode); | |
| 1360 visitor->trace(m_typingStyle); | 1393 visitor->trace(m_typingStyle); |
| 1394 visitor->trace(m_frameCaret); | |
| 1361 } | 1395 } |
| 1362 | 1396 |
| 1363 void FrameSelection::setCaretRectNeedsUpdate() | 1397 // TODO(yoiciho): We should move this function to FrameCaret.cpp |
| 1398 void FrameCaret::setCaretRectNeedsUpdate() | |
| 1364 { | 1399 { |
| 1365 if (m_caretRectDirty) | 1400 if (m_caretRectDirty) |
| 1366 return; | 1401 return; |
| 1367 m_caretRectDirty = true; | 1402 m_caretRectDirty = true; |
| 1368 | 1403 |
| 1369 scheduleVisualUpdate(); | 1404 if (!m_frame) |
| 1405 return; | |
| 1406 if (Page* page = m_frame->page()) | |
| 1407 page->animator().scheduleVisualUpdate(m_frame->localFrameRoot()); | |
| 1370 } | 1408 } |
| 1371 | 1409 |
| 1372 void FrameSelection::scheduleVisualUpdate() const | 1410 void FrameSelection::scheduleVisualUpdate() const |
| 1373 { | 1411 { |
| 1374 if (!m_frame) | 1412 if (!m_frame) |
| 1375 return; | 1413 return; |
| 1376 if (Page* page = m_frame->page()) | 1414 if (Page* page = m_frame->page()) |
| 1377 page->animator().scheduleVisualUpdate(m_frame->localFrameRoot()); | 1415 page->animator().scheduleVisualUpdate(m_frame->localFrameRoot()); |
| 1378 } | 1416 } |
| 1379 | 1417 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1440 void FrameSelection::updateIfNeeded() | 1478 void FrameSelection::updateIfNeeded() |
| 1441 { | 1479 { |
| 1442 m_selectionEditor->updateIfNeeded(); | 1480 m_selectionEditor->updateIfNeeded(); |
| 1443 } | 1481 } |
| 1444 | 1482 |
| 1445 void FrameSelection::setCaretVisible(bool caretIsVisible) | 1483 void FrameSelection::setCaretVisible(bool caretIsVisible) |
| 1446 { | 1484 { |
| 1447 setCaretVisibility(caretIsVisible ? CaretVisibility::Visible : CaretVisibili ty::Hidden); | 1485 setCaretVisibility(caretIsVisible ? CaretVisibility::Visible : CaretVisibili ty::Hidden); |
| 1448 } | 1486 } |
| 1449 | 1487 |
| 1488 bool FrameSelection::shouldPaintCaretForTesting() const | |
| 1489 { | |
| 1490 return m_frameCaret->shouldPaintCaretForTesting(); | |
| 1491 } | |
| 1492 | |
| 1493 bool FrameSelection::isPreviousCaretDirtyForTesting() const | |
| 1494 { | |
| 1495 return m_frameCaret->isPreviousCaretDirtyForTesting(); | |
| 1496 } | |
| 1497 | |
| 1498 bool FrameSelection::isCaretBoundsDirty() const | |
| 1499 { | |
| 1500 return m_frameCaret->isCaretBoundsDirty(); | |
| 1501 } | |
| 1502 | |
| 1503 void FrameSelection::setCaretRectNeedsUpdate() | |
| 1504 { | |
| 1505 m_frameCaret->setCaretRectNeedsUpdate(); | |
| 1506 } | |
| 1507 | |
| 1508 void FrameSelection::setCaretBlinkingSuspended(bool suspended) | |
| 1509 { | |
| 1510 m_frameCaret->setCaretBlinkingSuspended(suspended); | |
| 1511 } | |
| 1512 | |
| 1513 bool FrameSelection::isCaretBlinkingSuspended() const | |
| 1514 { | |
| 1515 return m_frameCaret->isCaretBlinkingSuspended(); | |
| 1516 } | |
| 1517 | |
| 1450 } // namespace blink | 1518 } // namespace blink |
| 1451 | 1519 |
| 1452 #ifndef NDEBUG | 1520 #ifndef NDEBUG |
| 1453 | 1521 |
| 1454 void showTree(const blink::FrameSelection& sel) | 1522 void showTree(const blink::FrameSelection& sel) |
| 1455 { | 1523 { |
| 1456 sel.showTreeForThis(); | 1524 sel.showTreeForThis(); |
| 1457 } | 1525 } |
| 1458 | 1526 |
| 1459 void showTree(const blink::FrameSelection* sel) | 1527 void showTree(const blink::FrameSelection* sel) |
| 1460 { | 1528 { |
| 1461 if (sel) | 1529 if (sel) |
| 1462 sel->showTreeForThis(); | 1530 sel->showTreeForThis(); |
| 1463 else | 1531 else |
| 1464 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); | 1532 fprintf(stderr, "Cannot showTree for (nil) FrameSelection.\n"); |
| 1465 } | 1533 } |
| 1466 | 1534 |
| 1467 #endif | 1535 #endif |
| OLD | NEW |