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

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

Issue 1958093002: CONTINUED Make FrameSelection to hold non-canonicalized positions Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 2017-01-16T20:04:35 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/editing/CaretBase.h" 30 #include "core/dom/SynchronousMutationObserver.h"
31 #include "platform/geometry/IntRect.h" 31 #include "core/editing/PositionWithAffinity.h"
32 #include "platform/Timer.h"
33 #include "platform/geometry/LayoutRect.h"
34 #include "platform/heap/GarbageCollected.h"
35 #include "platform/heap/Member.h"
36 #include "wtf/Noncopyable.h"
37 #include <memory>
32 38
33 namespace blink { 39 namespace blink {
34 40
41 class CaretBase;
42 class CharacterData;
43 class DisplayItemClient;
44 class Document;
45 class GraphicsContext;
46 class Node;
47 class LocalFrame;
35 class SelectionEditor; 48 class SelectionEditor;
36 49
37 enum class CaretVisibility { Visible, Hidden }; 50 enum class CaretVisibility { Visible, Hidden };
38 51
39 class CORE_EXPORT FrameCaret final : public CaretBase { 52 class CORE_EXPORT FrameCaret final
53 : public GarbageCollectedFinalized<FrameCaret>,
54 public SynchronousMutationObserver {
55 WTF_MAKE_NONCOPYABLE(FrameCaret);
56 USING_GARBAGE_COLLECTED_MIXIN(FrameCaret);
57
40 public: 58 public:
41 FrameCaret(LocalFrame&, const SelectionEditor&); 59 FrameCaret(LocalFrame&, const SelectionEditor&);
42 ~FrameCaret() override; 60 ~FrameCaret();
43 61
62 const DisplayItemClient& displayItemClient() const;
44 bool isActive() const { return caretPosition().isNotNull(); } 63 bool isActive() const { return caretPosition().isNotNull(); }
45 64
65 void documentAttached(Document*);
46 void updateAppearance(); 66 void updateAppearance();
47 67
48 // Used to suspend caret blinking while the mouse is down. 68 // Used to suspend caret blinking while the mouse is down.
49 void setCaretBlinkingSuspended(bool suspended) { 69 void setCaretBlinkingSuspended(bool suspended) {
50 m_isCaretBlinkingSuspended = suspended; 70 m_isCaretBlinkingSuspended = suspended;
51 } 71 }
52 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; } 72 bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; }
53 void stopCaretBlinkTimer(); 73 void stopCaretBlinkTimer();
54 void startBlinkCaret(); 74 void startBlinkCaret();
55 75
56 void setCaretVisibility(CaretVisibility); 76 void setCaretVisibility(CaretVisibility);
57 bool isCaretBoundsDirty() const { return m_caretRectDirty; } 77 bool isCaretBoundsDirty() const { return m_didScheduleUpdate; }
58 void setCaretRectNeedsUpdate(); 78 void setCaretRectNeedsUpdate();
59 // If |forceInvalidation| is true the caret's previous and new rectangles 79 // If |forceInvalidation| is true the caret's previous and new rectangles
60 // are forcibly invalidated regardless of the state of the blink timer. 80 // are forcibly invalidated regardless of the state of the blink timer.
61 void invalidateCaretRect(bool forceInvalidation); 81 void invalidateCaretRect(bool forceInvalidation);
62 IntRect absoluteCaretBounds(); 82 IntRect absoluteCaretBounds();
63 83
64 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; } 84 bool shouldShowBlockCursor() const { return m_shouldShowBlockCursor; }
65 void setShouldShowBlockCursor(bool); 85 void setShouldShowBlockCursor(bool);
66 86
67 void paintCaret(GraphicsContext&, const LayoutPoint&); 87 void paintCaret(GraphicsContext&, const LayoutPoint&);
68 88
69 void dataWillChange(const CharacterData&);
70 void nodeWillBeRemoved(Node&);
71
72 void documentDetached();
73
74 // For unittests 89 // For unittests
75 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; } 90 bool shouldPaintCaretForTesting() const { return m_shouldPaintCaret; }
76 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; } 91 bool isPreviousCaretDirtyForTesting() const { return m_previousCaretNode; }
77 92
78 DECLARE_VIRTUAL_TRACE(); 93 DECLARE_TRACE();
79 94
80 private: 95 private:
81 friend class FrameSelectionTest; 96 friend class FrameSelectionTest;
82 97
83 const PositionWithAffinity caretPosition() const; 98 const PositionWithAffinity caretPosition() const;
84 99
85 bool shouldBlinkCaret() const; 100 bool shouldBlinkCaret() const;
86 void caretBlinkTimerFired(TimerBase*); 101 void caretBlinkTimerFired(TimerBase*);
87 bool caretPositionIsValidForDocument(const Document&) const; 102 bool caretPositionIsValidForDocument(const Document&) const;
88 103
104 // Implementation of |SynchronousMutationObserver| member functions.
105 void contextDestroyed(Document*) final;
106 void nodeWillBeRemoved(Node&) final;
107
108 // TODO(yosin): We should get rid of |dataWillChange()|.
109 void dataWillChange(const CharacterData&);
110
89 const Member<const SelectionEditor> m_selectionEditor; 111 const Member<const SelectionEditor> m_selectionEditor;
90 const Member<LocalFrame> m_frame; 112 const Member<LocalFrame> m_frame;
113 const std::unique_ptr<CaretBase> m_caretBase;
91 // The last node which painted the caret. Retained for clearing the old 114 // The last node which painted the caret. Retained for clearing the old
92 // caret when it moves. 115 // caret when it moves.
93 Member<Node> m_previousCaretNode; 116 Member<Node> m_previousCaretNode;
94 Member<Node> m_previousCaretAnchorNode; 117 Member<Node> m_previousCaretAnchorNode;
95 LayoutRect m_previousCaretRect; 118 LayoutRect m_previousCaretRect;
119 Color m_previousCaretColor;
96 CaretVisibility m_caretVisibility; 120 CaretVisibility m_caretVisibility;
97 CaretVisibility m_previousCaretVisibility; 121 CaretVisibility m_previousCaretVisibility;
98 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this. 122 // TODO(https://crbug.com/668758): Consider using BeginFrame update for this.
99 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer; 123 TaskRunnerTimer<FrameCaret> m_caretBlinkTimer;
100 bool m_caretRectDirty : 1; 124 bool m_didScheduleUpdate : 1;
101 bool m_shouldPaintCaret : 1; 125 bool m_shouldPaintCaret : 1;
102 bool m_isCaretBlinkingSuspended : 1; 126 bool m_isCaretBlinkingSuspended : 1;
103 bool m_shouldShowBlockCursor : 1; 127 bool m_shouldShowBlockCursor : 1;
104 }; 128 };
105 129
106 } // namespace blink 130 } // namespace blink
107 131
108 #endif // FrameCaret_h 132 #endif // FrameCaret_h
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/DragCaretController.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