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

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

Issue 2293293003: Make CaretBase a DisplayItemClient. (Closed)
Patch Set: Fix unit test and disable failing test on SPv2. 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
135 { 135 {
136 LayoutBlock* caretPainter = caretLayoutObject(node); 136 LayoutBlock* caretPainter = caretLayoutObject(node);
137 if (!caretPainter) 137 if (!caretPainter)
138 return IntRect(); 138 return IntRect();
139 139
140 LayoutRect localRect(rect); 140 LayoutRect localRect(rect);
141 caretPainter->flipForWritingMode(localRect); 141 caretPainter->flipForWritingMode(localRect);
142 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox(); 142 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox();
143 } 143 }
144 144
145 DisplayItemClient* CaretBase::displayItemClientForCaret(Node* node)
146 {
147 LayoutBlock* caretLayoutBlock = caretLayoutObject(node);
148 if (!caretLayoutBlock)
149 return nullptr;
150 if (caretLayoutBlock->usesCompositedScrolling())
151 return static_cast<DisplayItemClient*>(caretLayoutBlock->layer()->graphi csLayerBackingForScrolling());
152 return caretLayoutBlock;
153 }
154
155 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad 145 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad
156 // design. We should use only previous layoutObject or Rectangle to invalidate 146 // design. We should use only previous layoutObject or Rectangle to invalidate
157 // old caret. 147 // old caret.
158 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) 148 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect)
159 { 149 {
160 LayoutBlock* caretLayoutBlock = caretLayoutObject(node); 150 LayoutBlock* caretLayoutBlock = caretLayoutObject(node);
161 if (!caretLayoutBlock) 151 if (!caretLayoutBlock)
162 return; 152 return;
163 153
164 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. 154 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems.
165 // https://bugs.webkit.org/show_bug.cgi?id=108283 155 // https://bugs.webkit.org/show_bug.cgi?id=108283
166 LayoutRect inflatedRect = rect; 156 LayoutRect inflatedRect = rect;
167 inflatedRect.inflate(LayoutUnit(1)); 157 inflatedRect.inflate(LayoutUnit(1));
168 158
169 // FIXME: We should not allow paint invalidation out of paint invalidation s tate. crbug.com/457415 159 // FIXME: We should not allow paint invalidation out of paint invalidation s tate. crbug.com/457415
170 DisablePaintInvalidationStateAsserts disabler; 160 DisablePaintInvalidationStateAsserts disabler;
171 161
172 node->layoutObject()->invalidatePaintRectangle(inflatedRect, displayItemClie ntForCaret(node)); 162 m_visualRect = node->layoutObject()->invalidatePaintRectangle(inflatedRect, this);
173 } 163 }
174 164
175 bool CaretBase::shouldRepaintCaret(Node& node) const 165 bool CaretBase::shouldRepaintCaret(Node& node) const
176 { 166 {
177 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, 167 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor,
178 // carets need to be repainted not only when the node is contentEditable but 168 // carets need to be repainted not only when the node is contentEditable but
179 // also when its parentNode() is contentEditable. 169 // also when its parentNode() is contentEditable.
180 node.document().updateStyleAndLayoutTree(); 170 node.document().updateStyleAndLayoutTree();
181 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod e.parentNode())); 171 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod e.parentNode()));
182 } 172 }
(...skipping 18 matching lines...) Expand all
201 if (hasEditableStyle(*node) || shouldRepaintCaret(view)) 191 if (hasEditableStyle(*node) || shouldRepaintCaret(view))
202 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); 192 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate());
203 } 193 }
204 } 194 }
205 195
206 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi nt& paintOffset, DisplayItem::Type displayItemType) const 196 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi nt& paintOffset, DisplayItem::Type displayItemType) const
207 { 197 {
208 if (m_caretVisibility == CaretVisibility::Hidden) 198 if (m_caretVisibility == CaretVisibility::Hidden)
209 return; 199 return;
210 200
211 DisplayItemClient* displayItemClient = displayItemClientForCaret(node); 201 if (DrawingRecorder::useCachedDrawingIfPossible(context, *this, displayItemT ype))
212 if (!displayItemClient)
213 return;
214
215 if (DrawingRecorder::useCachedDrawingIfPossible(context, *displayItemClient, displayItemType))
216 return; 202 return;
217 203
218 LayoutRect drawingRect = localCaretRectWithoutUpdate(); 204 LayoutRect drawingRect = localCaretRectWithoutUpdate();
219 if (LayoutBlock* layoutObject = caretLayoutObject(node)) 205 if (LayoutBlock* layoutObject = caretLayoutObject(node))
220 layoutObject->flipForWritingMode(drawingRect); 206 layoutObject->flipForWritingMode(drawingRect);
221 drawingRect.moveBy(roundedIntPoint(paintOffset)); 207 drawingRect.moveBy(roundedIntPoint(paintOffset));
222 208
223 Color caretColor = Color::black; 209 Color caretColor = Color::black;
224 210
225 Element* element; 211 Element* element;
226 if (node->isElementNode()) 212 if (node->isElementNode())
227 element = toElement(node); 213 element = toElement(node);
228 else 214 else
229 element = node->parentElement(); 215 element = node->parentElement();
230 216
231 if (element && element->layoutObject()) 217 if (element && element->layoutObject())
232 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); 218 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor);
233 219
234 DrawingRecorder drawingRecorder(context, *displayItemClientForCaret(node), D isplayItem::kCaret, FloatRect(drawingRect)); 220 DrawingRecorder drawingRecorder(context, *this, DisplayItem::kCaret, FloatRe ct(drawingRect));
235 221
236 context.fillRect(FloatRect(drawingRect), caretColor); 222 context.fillRect(FloatRect(drawingRect), caretColor);
237 } 223 }
238 224
239 void CaretBase::setCaretVisibility(CaretVisibility visibility) 225 void CaretBase::setCaretVisibility(CaretVisibility visibility)
240 { 226 {
241 m_caretVisibility = visibility; 227 m_caretVisibility = visibility;
242 } 228 }
243 229
230 String CaretBase::debugName() const
231 {
232 return "Caret";
233 }
234
235 LayoutRect CaretBase::visualRect() const
236 {
237 return m_visualRect;
238 }
239
244 } // namespace blink 240 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/CaretBase.h ('k') | third_party/WebKit/Source/core/editing/FrameCaret.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698