| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #ifndef FrameCaret_h | 26 #ifndef FrameCaret_h |
| 27 #define FrameCaret_h | 27 #define FrameCaret_h |
| 28 | 28 |
| 29 #include "core/CoreExport.h" | 29 #include "core/CoreExport.h" |
| 30 #include "core/dom/SynchronousMutationObserver.h" | |
| 31 #include "core/editing/PositionWithAffinity.h" | 30 #include "core/editing/PositionWithAffinity.h" |
| 32 #include "platform/Timer.h" | 31 #include "platform/Timer.h" |
| 33 #include "platform/geometry/LayoutRect.h" | 32 #include "platform/geometry/LayoutRect.h" |
| 33 #include "platform/graphics/PaintInvalidationReason.h" |
| 34 #include "platform/heap/GarbageCollected.h" | 34 #include "platform/heap/GarbageCollected.h" |
| 35 #include "platform/heap/Member.h" | 35 #include "platform/heap/Member.h" |
| 36 #include <memory> | 36 #include <memory> |
| 37 | 37 |
| 38 namespace blink { | 38 namespace blink { |
| 39 | 39 |
| 40 class CaretDisplayItemClient; | 40 class CaretDisplayItemClient; |
| 41 class CharacterData; | |
| 42 class DisplayItemClient; | 41 class DisplayItemClient; |
| 43 class Document; | 42 class Document; |
| 43 class FrameCaret; |
| 44 class GraphicsContext; | 44 class GraphicsContext; |
| 45 class Node; | 45 class LayoutBlock; |
| 46 class LocalFrame; | 46 class LocalFrame; |
| 47 class SelectionEditor; | 47 class SelectionEditor; |
| 48 struct PaintInvalidatorContext; |
| 48 | 49 |
| 49 enum class CaretVisibility { Visible, Hidden }; | 50 enum class CaretVisibility { Visible, Hidden }; |
| 50 | 51 |
| 51 class CORE_EXPORT FrameCaret final | 52 class CORE_EXPORT FrameCaret final |
| 52 : public GarbageCollectedFinalized<FrameCaret>, | 53 : public GarbageCollectedFinalized<FrameCaret> { |
| 53 public SynchronousMutationObserver { | |
| 54 USING_GARBAGE_COLLECTED_MIXIN(FrameCaret); | |
| 55 | |
| 56 public: | 54 public: |
| 57 FrameCaret(LocalFrame&, const SelectionEditor&); | 55 FrameCaret(LocalFrame&, const SelectionEditor&); |
| 58 ~FrameCaret(); | 56 ~FrameCaret(); |
| 59 | 57 |
| 60 const DisplayItemClient& displayItemClient() const; | 58 const DisplayItemClient& displayItemClient() const; |
| 61 bool isActive() const { return caretPosition().isNotNull(); } | 59 bool isActive() const { return caretPosition().isNotNull(); } |
| 62 | 60 |
| 63 void documentAttached(Document*); | |
| 64 void updateAppearance(); | 61 void updateAppearance(); |
| 65 | 62 |
| 66 // Used to suspend caret blinking while the mouse is down. | 63 // Used to suspend caret blinking while the mouse is down. |
| 67 void setCaretBlinkingSuspended(bool suspended) { | 64 void setCaretBlinkingSuspended(bool suspended) { |
| 68 m_isCaretBlinkingSuspended = suspended; | 65 m_isCaretBlinkingSuspended = suspended; |
| 69 } | 66 } |
| 70 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } | 67 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } |
| 71 void stopCaretBlinkTimer(); | 68 void stopCaretBlinkTimer(); |
| 72 void startBlinkCaret(); | 69 void startBlinkCaret(); |
| 73 | |
| 74 void setCaretVisibility(CaretVisibility); | 70 void setCaretVisibility(CaretVisibility); |
| 75 void setCaretRectNeedsUpdate(); | |
| 76 // If |forceInvalidation| is true the caret's previous and new rectangles | |
| 77 // are forcibly invalidated regardless of the state of the blink timer. | |
| 78 void invalidateCaretRect(bool forceInvalidation); | |
| 79 IntRect absoluteCaretBounds() const; | 71 IntRect absoluteCaretBounds() const; |
| 80 | 72 |
| 81 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } | 73 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } |
| 82 void setShouldShowBlockCursor(bool); | 74 void setShouldShowBlockCursor(bool); |
| 83 | 75 |
| 84 void paintCaret(GraphicsContext&, const LayoutPoint&); | 76 // Paint invalidation methods delegating to DisplayItemClient. |
| 77 void setNeedsPaintInvalidation(); |
| 78 void clearPreviousVisualRect(const LayoutBlock&); |
| 79 void layoutBlockWillBeDestroyed(const LayoutBlock&); |
| 80 void updateForPaintInvalidation(); |
| 81 void invalidatePaintIfNeeded(const LayoutBlock&, |
| 82 const PaintInvalidatorContext&, |
| 83 PaintInvalidationReason); |
| 85 | 84 |
| 86 void dataWillChange(const CharacterData&); | 85 bool shouldPaintCaret(const LayoutBlock&) const; |
| 86 void paintCaret(GraphicsContext&, const LayoutPoint&) const; |
| 87 | 87 |
| 88 // For unittests | 88 // For unit tests. |
| 89 const DisplayItemClient& caretDisplayItemClientForTesting() const; |
| 90 const LayoutBlock* caretLayoutBlockForTesting() const; |
| 89 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } | 91 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } |
| 90 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; } | |
| 91 | 92 |
| 92 DECLARE_TRACE(); | 93 DECLARE_TRACE(); |
| 93 | 94 |
| 94 private: | 95 private: |
| 95 friend class FrameSelectionTest; | 96 friend class FrameSelectionTest; |
| 96 | 97 |
| 97 const PositionWithAffinity caretPosition() const; | 98 const PositionWithAffinity caretPosition() const; |
| 98 | 99 |
| 99 bool shouldBlinkCaret() const; | 100 bool shouldBlinkCaret() const; |
| 100 void caretBlinkTimerFired(TimerBase*); | 101 void caretBlinkTimerFired(TimerBase*); |
| 101 bool caretPositionIsValidForDocument(const Document&) const; | 102 bool caretPositionIsValidForDocument(const Document&) const; |
| 102 | 103 |
| 103 // Implementation of |SynchronousMutationObserver| member functions. | |
| 104 void contextDestroyed(Document*) final; | |
| 105 void nodeWillBeRemoved(Node&) final; | |
| 106 | |
| 107 const Member<const SelectionEditor> m_selectionEditor; | 104 const Member<const SelectionEditor> m_selectionEditor; |
| 108 const Member<LocalFrame> m_frame; | 105 const Member<LocalFrame> m_frame; |
| 109 const std::unique_ptr<CaretDisplayItemClient> m_caretBase; | 106 const std::unique_ptr<CaretDisplayItemClient> m_caretBase; |
| 110 // The last node which painted the caret. Retained for clearing the old | |
| 111 // caret when it moves. | |
| 112 Member<Node> m_previousCaretNode; | |
| 113 Member<Node> m_previousCaretAnchorNode; | |
| 114 LayoutRect m_previousCaretRect; | |
| 115 CaretVisibility m_caretVisibility; | 107 CaretVisibility m_caretVisibility; |
| 116 CaretVisibility m_previousCaretVisibility; | |
| 117 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. | 108 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. |
| 118 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; | 109 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; |
| 119 bool m_caretRectDirty : 1; | |
| 120 bool m_shouldPaintCaret : 1; | 110 bool m_shouldPaintCaret : 1; |
| 121 bool m_isCaretBlinkingSuspended : 1; | 111 bool m_isCaretBlinkingSuspended : 1; |
| 122 bool m_shouldShowBlockCursor : 1; | 112 bool m_shouldShowBlockCursor : 1; |
| 123 | 113 |
| 124 DISALLOW_COPY_AND_ASSIGN(FrameCaret); | 114 DISALLOW_COPY_AND_ASSIGN(FrameCaret); |
| 125 }; | 115 }; |
| 126 | 116 |
| 127 } // namespace blink | 117 } // namespace blink |
| 128 | 118 |
| 129 #endif // FrameCaret_h | 119 #endif // FrameCaret_h |
| OLD | NEW |