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

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

Issue 2325933002: Move m_caretVisibility from CaretBase to FrameCaret (Closed)
Patch Set: 2016-09-09T14:05:22 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
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 25 matching lines...) Expand all
36 #include "core/layout/api/LayoutViewItem.h" 36 #include "core/layout/api/LayoutViewItem.h"
37 #include "core/page/Page.h" 37 #include "core/page/Page.h"
38 #include "core/paint/PaintLayer.h" 38 #include "core/paint/PaintLayer.h"
39 #include "public/platform/WebTraceLocation.h" 39 #include "public/platform/WebTraceLocation.h"
40 40
41 namespace blink { 41 namespace blink {
42 42
43 FrameCaret::FrameCaret(LocalFrame* frame, const SelectionEditor& selectionEditor ) 43 FrameCaret::FrameCaret(LocalFrame* frame, const SelectionEditor& selectionEditor )
44 : m_selectionEditor(&selectionEditor) 44 : m_selectionEditor(&selectionEditor)
45 , m_frame(frame) 45 , m_frame(frame)
46 , m_caretVisibility(CaretVisibility::Hidden)
46 , m_previousCaretVisibility(CaretVisibility::Hidden) 47 , m_previousCaretVisibility(CaretVisibility::Hidden)
47 , m_caretBlinkTimer(this, &FrameCaret::caretBlinkTimerFired) 48 , m_caretBlinkTimer(this, &FrameCaret::caretBlinkTimerFired)
48 , m_caretRectDirty(true) 49 , m_caretRectDirty(true)
49 , m_shouldPaintCaret(true) 50 , m_shouldPaintCaret(true)
50 , m_isCaretBlinkingSuspended(false) 51 , m_isCaretBlinkingSuspended(false)
51 , m_shouldShowBlockCursor(false) 52 , m_shouldShowBlockCursor(false)
52 { 53 {
53 DCHECK(frame); 54 DCHECK(frame);
54 } 55 }
55 56
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
112 113
113 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval()) 114 if (double blinkInterval = LayoutTheme::theme().caretBlinkInterval())
114 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE); 115 m_caretBlinkTimer.startRepeating(blinkInterval, BLINK_FROM_HERE);
115 116
116 m_shouldPaintCaret = true; 117 m_shouldPaintCaret = true;
117 setCaretRectNeedsUpdate(); 118 setCaretRectNeedsUpdate();
118 } 119 }
119 120
120 void FrameCaret::setCaretVisibility(CaretVisibility visibility) 121 void FrameCaret::setCaretVisibility(CaretVisibility visibility)
121 { 122 {
122 if (getCaretVisibility() == visibility) 123 if (m_caretVisibility == visibility)
123 return; 124 return;
124 125
125 CaretBase::setCaretVisibility(visibility); 126 m_caretVisibility = visibility;
126 127
127 updateAppearance(); 128 updateAppearance();
128 } 129 }
129 130
130 void FrameCaret::setCaretRectNeedsUpdate() 131 void FrameCaret::setCaretRectNeedsUpdate()
131 { 132 {
132 if (m_caretRectDirty) 133 if (m_caretRectDirty)
133 return; 134 return;
134 m_caretRectDirty = true; 135 m_caretRectDirty = true;
135 136
(...skipping 26 matching lines...) Expand all
162 // It's possible for the timer to be inactive even though we want to 163 // 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 // 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 // caret blink interval could be zero and thus |m_caretBlinkTimer| will
165 // never be started. We provide |forceInvalidation| for use by paint 166 // never be started. We provide |forceInvalidation| for use by paint
166 // invalidation internals where we need to invalidate the caret regardless 167 // invalidation internals where we need to invalidate the caret regardless
167 // of timer state. 168 // of timer state.
168 if (!forceInvalidation 169 if (!forceInvalidation
169 && !m_caretBlinkTimer.isActive() 170 && !m_caretBlinkTimer.isActive()
170 && newNode == m_previousCaretNode 171 && newNode == m_previousCaretNode
171 && newRect == m_previousCaretRect 172 && newRect == m_previousCaretRect
172 && getCaretVisibility() == m_previousCaretVisibility) 173 && m_caretVisibility == m_previousCaretVisibility)
173 return; 174 return;
174 175
175 LayoutViewItem view = m_frame->document()->layoutViewItem(); 176 LayoutViewItem view = m_frame->document()->layoutViewItem();
176 if (m_previousCaretNode && (shouldRepaintCaret(*m_previousCaretNode) || shou ldRepaintCaret(view))) 177 if (m_previousCaretNode && (shouldRepaintCaret(*m_previousCaretNode) || shou ldRepaintCaret(view)))
177 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ; 178 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect) ;
178 if (newNode && (shouldRepaintCaret(*newNode) || shouldRepaintCaret(view))) 179 if (newNode && (shouldRepaintCaret(*newNode) || shouldRepaintCaret(view)))
179 invalidateLocalCaretRect(newNode, newRect); 180 invalidateLocalCaretRect(newNode, newRect);
180 m_previousCaretNode = newNode; 181 m_previousCaretNode = newNode;
181 m_previousCaretRect = newRect; 182 m_previousCaretRect = newRect;
182 m_previousCaretVisibility = getCaretVisibility(); 183 m_previousCaretVisibility = m_caretVisibility;
183 } 184 }
184 185
185 IntRect FrameCaret::absoluteCaretBounds() 186 IntRect FrameCaret::absoluteCaretBounds()
186 { 187 {
187 DCHECK_NE(m_frame->document()->lifecycle().state(), DocumentLifecycle::InPai ntInvalidation); 188 DCHECK_NE(m_frame->document()->lifecycle().state(), DocumentLifecycle::InPai ntInvalidation);
188 DCHECK(!m_frame->document()->needsLayoutTreeUpdate()); 189 DCHECK(!m_frame->document()->needsLayoutTreeUpdate());
189 DocumentLifecycle::DisallowTransitionScope disallowTransition(m_frame->docum ent()->lifecycle()); 190 DocumentLifecycle::DisallowTransitionScope disallowTransition(m_frame->docum ent()->lifecycle());
190 191
191 if (!isActive()) { 192 if (!isActive()) {
192 clearCaretRect(); 193 clearCaretRect();
(...skipping 14 matching lines...) Expand all
207 { 208 {
208 m_shouldShowBlockCursor = shouldShowBlockCursor; 209 m_shouldShowBlockCursor = shouldShowBlockCursor;
209 210
210 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 211 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
211 212
212 updateAppearance(); 213 updateAppearance();
213 } 214 }
214 215
215 void FrameCaret::paintCaret(GraphicsContext& context, const LayoutPoint& paintOf fset) 216 void FrameCaret::paintCaret(GraphicsContext& context, const LayoutPoint& paintOf fset)
216 { 217 {
218 if (m_caretVisibility == CaretVisibility::Hidden)
219 return;
220
217 if (!(isActive() && m_shouldPaintCaret)) 221 if (!(isActive() && m_shouldPaintCaret))
218 return; 222 return;
219 223
220 updateCaretRect(caretPosition()); 224 updateCaretRect(caretPosition());
221 CaretBase::paintCaret(caretPosition().position().anchorNode(), context, pain tOffset, DisplayItem::kCaret); 225 CaretBase::paintCaret(caretPosition().position().anchorNode(), context, pain tOffset, DisplayItem::kCaret);
222 } 226 }
223 227
224 void FrameCaret::dataWillChange(const CharacterData& node) 228 void FrameCaret::dataWillChange(const CharacterData& node)
225 { 229 {
226 if (node == m_previousCaretNode) { 230 if (node == m_previousCaretNode) {
(...skipping 16 matching lines...) Expand all
243 } 247 }
244 248
245 void FrameCaret::documentDetached() 249 void FrameCaret::documentDetached()
246 { 250 {
247 m_caretBlinkTimer.stop(); 251 m_caretBlinkTimer.stop();
248 m_previousCaretNode.clear(); 252 m_previousCaretNode.clear();
249 } 253 }
250 254
251 bool FrameCaret::shouldBlinkCaret() const 255 bool FrameCaret::shouldBlinkCaret() const
252 { 256 {
253 if (!caretIsVisible() || !isActive()) 257 if (m_caretVisibility != CaretVisibility::Visible || !isActive())
254 return false; 258 return false;
255 259
256 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled()) 260 if (m_frame->settings() && m_frame->settings()->caretBrowsingEnabled())
257 return false; 261 return false;
258 262
259 Element* root = rootEditableElementOf(caretPosition().position()); 263 Element* root = rootEditableElementOf(caretPosition().position());
260 if (!root) 264 if (!root)
261 return false; 265 return false;
262 266
263 Element* focusedElement = root->document().focusedElement(); 267 Element* focusedElement = root->document().focusedElement();
264 if (!focusedElement) 268 if (!focusedElement)
265 return false; 269 return false;
266 270
267 return focusedElement->isShadowIncludingInclusiveAncestorOf(caretPosition(). position().anchorNode()); 271 return focusedElement->isShadowIncludingInclusiveAncestorOf(caretPosition(). position().anchorNode());
268 } 272 }
269 273
270 void FrameCaret::caretBlinkTimerFired(TimerBase*) 274 void FrameCaret::caretBlinkTimerFired(TimerBase*)
271 { 275 {
272 DCHECK(caretIsVisible()); 276 DCHECK_EQ(m_caretVisibility, CaretVisibility::Visible);
273 if (isCaretBlinkingSuspended() && m_shouldPaintCaret) 277 if (isCaretBlinkingSuspended() && m_shouldPaintCaret)
274 return; 278 return;
275 m_shouldPaintCaret = !m_shouldPaintCaret; 279 m_shouldPaintCaret = !m_shouldPaintCaret;
276 setCaretRectNeedsUpdate(); 280 setCaretRectNeedsUpdate();
277 } 281 }
278 282
279 } // nemaspace blink 283 } // nemaspace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameCaret.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698