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

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

Issue 2665823002: Invalidate caret during paint invalidation (Closed)
Patch Set: NeedsRebaseline Created 3 years, 10 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 <memory>
29 #include "core/CoreExport.h" 30 #include "core/CoreExport.h"
30 #include "core/dom/SynchronousMutationObserver.h"
31 #include "core/editing/PositionWithAffinity.h" 31 #include "core/editing/PositionWithAffinity.h"
32 #include "platform/Timer.h" 32 #include "platform/Timer.h"
33 #include "platform/geometry/LayoutRect.h" 33 #include "platform/geometry/LayoutRect.h"
34 #include "platform/graphics/PaintInvalidationReason.h"
34 #include "platform/heap/GarbageCollected.h" 35 #include "platform/heap/GarbageCollected.h"
35 #include "platform/heap/Member.h" 36 #include "platform/heap/Member.h"
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 clearPreviousVisualRect(const LayoutBlock&);
78 void layoutBlockWillBeDestroyed(const LayoutBlock&);
79 void updateStyleAndLayoutIfNeeded();
80 void invalidatePaintIfNeeded(const LayoutBlock&,
81 const PaintInvalidatorContext&,
82 PaintInvalidationReason);
85 83
86 void dataWillChange(const CharacterData&); 84 bool shouldPaintCaret(const LayoutBlock&) const;
85 void paintCaret(GraphicsContext&, const LayoutPoint&) const;
87 86
88 // For unittests 87 // For unit tests.
88 const DisplayItemClient& caretDisplayItemClientForTesting() const;
89 const LayoutBlock* caretLayoutBlockForTesting() const;
89 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } 90 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; }
90 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; }
91 91
92 DECLARE_TRACE(); 92 DECLARE_TRACE();
93 93
94 private: 94 private:
95 friend class FrameSelectionTest; 95 friend class FrameSelectionTest;
96 96
97 const PositionWithAffinity caretPosition() const; 97 const PositionWithAffinity caretPosition() const;
98 98
99 bool shouldBlinkCaret() const; 99 bool shouldBlinkCaret() const;
100 void caretBlinkTimerFired(TimerBase*); 100 void caretBlinkTimerFired(TimerBase*);
101 bool caretPositionIsValidForDocument(const Document&) const; 101 bool caretPositionIsValidForDocument(const Document&) const;
102 102
103 // Implementation of |SynchronousMutationObserver| member functions. 103 void scheduleVisualUpdateForPaintInvalidationIfNeeded();
104 void contextDestroyed(Document*) final;
105 void nodeWillBeRemoved(Node&) final;
106 104
107 const Member<const SelectionEditor> m_selectionEditor; 105 const Member<const SelectionEditor> m_selectionEditor;
108 const Member<LocalFrame> m_frame; 106 const Member<LocalFrame> m_frame;
109 const std::unique_ptr<CaretDisplayItemClient> m_caretBase; 107 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; 108 CaretVisibility m_caretVisibility;
116 CaretVisibility m_previousCaretVisibility;
117 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. 109 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this.
118 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; 110 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer;
119 bool m_caretRectDirty : 1;
120 bool m_shouldPaintCaret : 1; 111 bool m_shouldPaintCaret : 1;
121 bool m_isCaretBlinkingSuspended : 1; 112 bool m_isCaretBlinkingSuspended : 1;
122 bool m_shouldShowBlockCursor : 1; 113 bool m_shouldShowBlockCursor : 1;
123 114
124 DISALLOW_COPY_AND_ASSIGN(FrameCaret); 115 DISALLOW_COPY_AND_ASSIGN(FrameCaret);
125 }; 116 };
126 117
127 } // namespace blink 118 } // namespace blink
128 119
129 #endif // FrameCaret_h 120 #endif // FrameCaret_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/EditingUtilities.cpp ('k') | third_party/WebKit/Source/core/editing/FrameCaret.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698