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

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

Issue 2293293003: Make CaretBase a DisplayItemClient. (Closed)
Patch Set: Update docs and sync to head. Created 4 years, 3 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
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 // Start blinking with a black caret. Be sure not to restart if we're 108 // Start blinking with a black caret. Be sure not to restart if we're
109 // already blinking in the right location. 109 // already blinking in the right location.
110 if (m_caretBlinkTimer.isActive()) 110 if (m_caretBlinkTimer.isActive())
111 return; 111 return;
112 112
113 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval()) 113 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval())
114 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE); 114 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE);
115 115
116 m_shouldPaintCaret = true; 116 m_shouldPaintCaret = true;
117 setCaretRectNeedsUpdate(); 117 setCaretRectNeedsUpdate();
118
119 } 118 }
120 119
121 void FrameCaret::setCaretVisibility(CaretVisibility visibility) 120 void FrameCaret::setCaretVisibility(CaretVisibility visibility)
122 { 121 {
123 if (getCaretVisibility() == visibility) 122 if (getCaretVisibility() == visibility)
124 return; 123 return;
125 124
126 CaretBase::setCaretVisibility(visibility); 125 CaretBase::setCaretVisibility(visibility);
127 126
128 updateAppearance(); 127 updateAppearance();
(...skipping 11 matching lines...) Expand all
140 139
141 bool FrameCaret::caretPositionIsValidForDocument(const Document& document) const 140 bool FrameCaret::caretPositionIsValidForDocument(const Document& document) const
142 { 141 {
143 if (!isActive()) 142 if (!isActive())
144 return true; 143 return true;
145 144
146 return caretPosition().position().document() == document 145 return caretPosition().position().document() == document
147 && !caretPosition().position().isOrphan(); 146 && !caretPosition().position().isOrphan();
148 } 147 }
149 148
150 void FrameCaret::invalidateCaretRect() 149 void FrameCaret::invalidateCaretRect(bool forceInvalidation)
151 { 150 {
152 if (!m_caretRectDirty) 151 if (!m_caretRectDirty)
153 return; 152 return;
154 m_caretRectDirty = false; 153 m_caretRectDirty = false;
155 154
156 DCHECK(caretPositionIsValidForDocument(*m_frame->document())); 155 DCHECK(caretPositionIsValidForDocument(*m_frame->document()));
157 LayoutObject* layoutObject = nullptr; 156 LayoutObject* layoutObject = nullptr;
158 LayoutRect newRect; 157 LayoutRect newRect;
159 if (isActive()) 158 if (isActive())
160 newRect = localCaretRectOfPosition(caretPosition(), layoutObject); 159 newRect = localCaretRectOfPosition(caretPosition(), layoutObject);
161 Node* newNode = layoutObject ? layoutObject->node() : nullptr; 160 Node* newNode = layoutObject ? layoutObject->node() : nullptr;
162 161
163 if (!m_caretBlinkTimer.isActive() 162 // It's possible for the timer to be inactive even though we want to
163 // invalidate the caret. For example, when running as a layout test the
164 // caret blink interval could be zero and thus |m_caretBlinkTimer| will
165 // never be started. We provide |forceInvalidation| for use by paint
166 // invalidation internals where we need to invalidate the caret regardless
167 // of timer state.
168 if (!forceInvalidation
169 && !m_caretBlinkTimer.isActive()
164 && newNode == m_previousCaretNode 170 && newNode == m_previousCaretNode
165 && newRect == m_previousCaretRect 171 && newRect == m_previousCaretRect
166 && getCaretVisibility() == m_previousCaretVisibility) 172 && getCaretVisibility() == m_previousCaretVisibility)
167 return; 173 return;
168 174
169 LayoutViewItem view = m_frame->document()->layoutViewItem(); 175 LayoutViewItem view = m_frame->document()->layoutViewItem();
170 if (m_previousCaretNode && (shouldRepaintCaret(*m_previousCaretNode) || shou ldRepaintCaret(view))) 176 if (m_previousCaretNode && (shouldRepaintCaret(*m_previousCaretNode) || shou ldRepaintCaret(view)))
171 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ; 177 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ;
172 if (newNode && (shouldRepaintCaret(*newNode) || shouldRepaintCaret(view))) 178 if (newNode && (shouldRepaintCaret(*newNode) || shouldRepaintCaret(view)))
173 invalidateLocalCaretRect(newNode, newRect); 179 invalidateLocalCaretRect(newNode, newRect);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
262 void FrameCaret::caretBlinkTimerFired(TimerBase*) 268 void FrameCaret::caretBlinkTimerFired(TimerBase*)
263 { 269 {
264 DCHECK(caretIsVisible()); 270 DCHECK(caretIsVisible());
265 if (isCaretBlinkingSuspended() && m_shouldPaintCaret) 271 if (isCaretBlinkingSuspended() && m_shouldPaintCaret)
266 return; 272 return;
267 m_shouldPaintCaret = !m_shouldPaintCaret; 273 m_shouldPaintCaret = !m_shouldPaintCaret;
268 setCaretRectNeedsUpdate(); 274 setCaretRectNeedsUpdate();
269 } 275 }
270 276
271 } // nemaspace blink 277 } // nemaspace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.h ('k') | third_party/WebKit/Source/core/editing/FrameSelection.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698