Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(36)

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameCaret.h

Issue 2643033005: Make FrameCaret to utilize SynchronousMutationObserver (Closed)
Patch Set: 2017-01-20T14:30:09 Created 3 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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"
30 #include "core/editing/PositionWithAffinity.h" 31 #include "core/editing/PositionWithAffinity.h"
31 #include "platform/Timer.h" 32 #include "platform/Timer.h"
32 #include "platform/geometry/LayoutRect.h" 33 #include "platform/geometry/LayoutRect.h"
33 #include "platform/heap/GarbageCollected.h" 34 #include "platform/heap/GarbageCollected.h"
34 #include "platform/heap/Member.h" 35 #include "platform/heap/Member.h"
35 #include <memory> 36 #include <memory>
36 37
37 namespace blink { 38 namespace blink {
38 39
39 class CaretBase; 40 class CaretBase;
40 class CharacterData; 41 class CharacterData;
41 class DisplayItemClient; 42 class DisplayItemClient;
42 class Document; 43 class Document;
43 class GraphicsContext; 44 class GraphicsContext;
44 class Node; 45 class Node;
45 class LocalFrame; 46 class LocalFrame;
46 class SelectionEditor; 47 class SelectionEditor;
47 48
48 enum class CaretVisibility { Visible, Hidden }; 49 enum class CaretVisibility { Visible, Hidden };
49 50
50 class CORE_EXPORT FrameCaret final 51 class CORE_EXPORT FrameCaret final
51 : public GarbageCollectedFinalized<FrameCaret> { 52 : public GarbageCollectedFinalized<FrameCaret>,
53 public SynchronousMutationObserver {
54 USING_GARBAGE_COLLECTED_MIXIN(FrameCaret);
55
52 public: 56 public:
53 FrameCaret(LocalFrame&, const SelectionEditor&); 57 FrameCaret(LocalFrame&, const SelectionEditor&);
54 ~FrameCaret(); 58 ~FrameCaret();
55 59
56 const DisplayItemClient& displayItemClient() const; 60 const DisplayItemClient& displayItemClient() const;
57 bool isActive() const { return caretPosition().isNotNull(); } 61 bool isActive() const { return caretPosition().isNotNull(); }
58 62
63 void documentAttached(Document*);
59 void updateAppearance(); 64 void updateAppearance();
60 65
61 // Used to suspend caret blinking while the mouse is down. 66 // Used to suspend caret blinking while the mouse is down.
62 void setCaretBlinkingSuspended(bool suspended) { 67 void setCaretBlinkingSuspended(bool suspended) {
63 m_isCaretBlinkingSuspended = suspended; 68 m_isCaretBlinkingSuspended = suspended;
64 } 69 }
65 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } 70 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; }
66 void stopCaretBlinkTimer(); 71 void stopCaretBlinkTimer();
67 void startBlinkCaret(); 72 void startBlinkCaret();
68 73
69 void setCaretVisibility(CaretVisibility); 74 void setCaretVisibility(CaretVisibility);
70 void setCaretRectNeedsUpdate(); 75 void setCaretRectNeedsUpdate();
71 // If |forceInvalidation| is true the caret's previous and new rectangles 76 // If |forceInvalidation| is true the caret's previous and new rectangles
72 // are forcibly invalidated regardless of the state of the blink timer. 77 // are forcibly invalidated regardless of the state of the blink timer.
73 void invalidateCaretRect(bool forceInvalidation); 78 void invalidateCaretRect(bool forceInvalidation);
74 IntRect absoluteCaretBounds() const; 79 IntRect absoluteCaretBounds() const;
75 80
76 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } 81 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; }
77 void setShouldShowBlockCursor(bool); 82 void setShouldShowBlockCursor(bool);
78 83
79 void paintCaret(GraphicsContext&, const LayoutPoint&); 84 void paintCaret(GraphicsContext&, const LayoutPoint&);
80 85
81 void dataWillChange(const CharacterData&); 86 void dataWillChange(const CharacterData&);
82 void nodeWillBeRemoved(Node&);
83
84 void documentDetached();
85 87
86 // For unittests 88 // For unittests
87 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } 89 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; }
88 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; } 90 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; }
89 91
90 DECLARE_TRACE(); 92 DECLARE_TRACE();
91 93
92 private: 94 private:
93 friend class FrameSelectionTest; 95 friend class FrameSelectionTest;
94 96
95 const PositionWithAffinity caretPosition() const; 97 const PositionWithAffinity caretPosition() const;
96 98
97 bool shouldBlinkCaret() const; 99 bool shouldBlinkCaret() const;
98 void caretBlinkTimerFired(TimerBase*); 100 void caretBlinkTimerFired(TimerBase*);
99 bool caretPositionIsValidForDocument(const Document&) const; 101 bool caretPositionIsValidForDocument(const Document&) const;
100 102
103 // Implementation of |SynchronousMutationObserver| member functions.
104 void contextDestroyed(Document*) final;
105 void nodeWillBeRemoved(Node&) final;
106
101 const Member<const SelectionEditor> m_selectionEditor; 107 const Member<const SelectionEditor> m_selectionEditor;
102 const Member<LocalFrame> m_frame; 108 const Member<LocalFrame> m_frame;
103 const std::unique_ptr<CaretBase> m_caretBase; 109 const std::unique_ptr<CaretBase> m_caretBase;
104 // The last node which painted the caret. Retained for clearing the old 110 // The last node which painted the caret. Retained for clearing the old
105 // caret when it moves. 111 // caret when it moves.
106 Member<Node> m_previousCaretNode; 112 Member<Node> m_previousCaretNode;
107 Member<Node> m_previousCaretAnchorNode; 113 Member<Node> m_previousCaretAnchorNode;
108 LayoutRect m_previousCaretRect; 114 LayoutRect m_previousCaretRect;
109 CaretVisibility m_caretVisibility; 115 CaretVisibility m_caretVisibility;
110 CaretVisibility m_previousCaretVisibility; 116 CaretVisibility m_previousCaretVisibility;
111 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. 117 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this.
112 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; 118 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer;
113 bool m_caretRectDirty : 1; 119 bool m_caretRectDirty : 1;
114 bool m_shouldPaintCaret : 1; 120 bool m_shouldPaintCaret : 1;
115 bool m_isCaretBlinkingSuspended : 1; 121 bool m_isCaretBlinkingSuspended : 1;
116 bool m_shouldShowBlockCursor : 1; 122 bool m_shouldShowBlockCursor : 1;
117 }; 123 };
118 124
119 } // namespace blink 125 } // namespace blink
120 126
121 #endif // FrameCaret_h 127 #endif // FrameCaret_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698