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

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

Issue 2406163004: Simplify the usage of PositionWithAffinity (Closed)
Patch Set: Created 4 years, 2 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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 133
134 if (Page* page = m_frame->page()) 134 if (Page* page = m_frame->page())
135 page->animator().scheduleVisualUpdate(m_frame->localFrameRoot()); 135 page->animator().scheduleVisualUpdate(m_frame->localFrameRoot());
136 } 136 }
137 137
138 bool FrameCaret::caretPositionIsValidForDocument( 138 bool FrameCaret::caretPositionIsValidForDocument(
139 const Document& document) const { 139 const Document& document) const {
140 if (!isActive()) 140 if (!isActive())
141 return true; 141 return true;
142 142
143 return caretPosition().position().document() == document && 143 return caretPosition().document() == document && !caretPosition().isOrphan();
144 !caretPosition().position().isOrphan();
145 } 144 }
146 145
147 void FrameCaret::invalidateCaretRect(bool forceInvalidation) { 146 void FrameCaret::invalidateCaretRect(bool forceInvalidation) {
148 if (!m_caretRectDirty) 147 if (!m_caretRectDirty)
149 return; 148 return;
150 m_caretRectDirty = false; 149 m_caretRectDirty = false;
151 150
152 DCHECK(caretPositionIsValidForDocument(*m_frame->document())); 151 DCHECK(caretPositionIsValidForDocument(*m_frame->document()));
153 LayoutObject* layoutObject = nullptr; 152 LayoutObject* layoutObject = nullptr;
154 LayoutRect newRect; 153 LayoutRect newRect;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 } else { 187 } else {
189 if (enclosingTextFormControl(caretPosition().position())) { 188 if (enclosingTextFormControl(caretPosition().position())) {
190 if (isVisuallyEquivalentCandidate(caretPosition().position())) 189 if (isVisuallyEquivalentCandidate(caretPosition().position()))
191 updateCaretRect(caretPosition()); 190 updateCaretRect(caretPosition());
192 else 191 else
193 updateCaretRect(createVisiblePosition(caretPosition())); 192 updateCaretRect(createVisiblePosition(caretPosition()));
194 } else { 193 } else {
195 updateCaretRect(createVisiblePosition(caretPosition())); 194 updateCaretRect(createVisiblePosition(caretPosition()));
196 } 195 }
197 } 196 }
198 return absoluteBoundsForLocalRect(caretPosition().position().anchorNode(), 197 return absoluteBoundsForLocalRect(caretPosition().anchorNode(),
199 localCaretRectWithoutUpdate()); 198 localCaretRectWithoutUpdate());
200 } 199 }
201 200
202 void FrameCaret::setShouldShowBlockCursor(bool shouldShowBlockCursor) { 201 void FrameCaret::setShouldShowBlockCursor(bool shouldShowBlockCursor) {
203 m_shouldShowBlockCursor = shouldShowBlockCursor; 202 m_shouldShowBlockCursor = shouldShowBlockCursor;
204 203
205 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 204 m_frame->document()->updateStyleAndLayoutIgnorePendingStylesheets();
206 205
207 updateAppearance(); 206 updateAppearance();
208 } 207 }
209 208
210 void FrameCaret::paintCaret(GraphicsContext& context, 209 void FrameCaret::paintCaret(GraphicsContext& context,
211 const LayoutPoint& paintOffset) { 210 const LayoutPoint& paintOffset) {
212 if (m_caretVisibility == CaretVisibility::Hidden) 211 if (m_caretVisibility == CaretVisibility::Hidden)
213 return; 212 return;
214 213
215 if (!(isActive() && m_shouldPaintCaret)) 214 if (!(isActive() && m_shouldPaintCaret))
216 return; 215 return;
217 216
218 updateCaretRect(caretPosition()); 217 updateCaretRect(caretPosition());
219 CaretBase::paintCaret(caretPosition().position().anchorNode(), context, 218 CaretBase::paintCaret(caretPosition().anchorNode(), context, paintOffset,
220 paintOffset, DisplayItem::kCaret); 219 DisplayItem::kCaret);
221 } 220 }
222 221
223 void FrameCaret::dataWillChange(const CharacterData& node) { 222 void FrameCaret::dataWillChange(const CharacterData& node) {
224 if (node == m_previousCaretNode) { 223 if (node == m_previousCaretNode) {
225 // This invalidation is eager, and intentionally uses stale state. 224 // This invalidation is eager, and intentionally uses stale state.
226 DisableCompositingQueryAsserts disabler; 225 DisableCompositingQueryAsserts disabler;
227 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect); 226 invalidateLocalCaretRect(m_previousCaretNode.get(), m_previousCaretRect);
228 } 227 }
229 } 228 }
230 229
(...skipping 19 matching lines...) Expand all
250 249
251 Element* root = rootEditableElementOf(caretPosition().position()); 250 Element* root = rootEditableElementOf(caretPosition().position());
252 if (!root) 251 if (!root)
253 return false; 252 return false;
254 253
255 Element* focusedElement = root->document().focusedElement(); 254 Element* focusedElement = root->document().focusedElement();
256 if (!focusedElement) 255 if (!focusedElement)
257 return false; 256 return false;
258 257
259 return focusedElement->isShadowIncludingInclusiveAncestorOf( 258 return focusedElement->isShadowIncludingInclusiveAncestorOf(
260 caretPosition().position().anchorNode()); 259 caretPosition().anchorNode());
261 } 260 }
262 261
263 void FrameCaret::caretBlinkTimerFired(TimerBase*) { 262 void FrameCaret::caretBlinkTimerFired(TimerBase*) {
264 DCHECK_EQ(m_caretVisibility, CaretVisibility::Visible); 263 DCHECK_EQ(m_caretVisibility, CaretVisibility::Visible);
265 if (isCaretBlinkingSuspended() && m_shouldPaintCaret) 264 if (isCaretBlinkingSuspended() && m_shouldPaintCaret)
266 return; 265 return;
267 m_shouldPaintCaret = !m_shouldPaintCaret; 266 m_shouldPaintCaret = !m_shouldPaintCaret;
268 setCaretRectNeedsUpdate(); 267 setCaretRectNeedsUpdate();
269 } 268 }
270 269
271 } // nemaspace blink 270 } // nemaspace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698