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

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

Issue 2296203002: Make CaretBase a DisplayItemClient. (Closed)
Patch Set: 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->usesCompositedScrolling())
149 return static_cast<DisplayItemClient*>(caretLayoutBlock->layer()->graphi csLayerBackingForScrolling());
150 return caretLayoutBlock;
151 }
152
153 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad 145 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad
154 // design. We should use only previous layoutObject or Rectangle to invalidate 146 // design. We should use only previous layoutObject or Rectangle to invalidate
155 // old caret. 147 // old caret.
156 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) 148 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect)
157 { 149 {
158 LayoutBlock* caretLayoutBlock = caretLayoutObject(node); 150 LayoutBlock* caretLayoutBlock = caretLayoutObject(node);
159 if (!caretLayoutBlock) 151 if (!caretLayoutBlock)
160 return; 152 return;
161 153
162 // 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.
163 // https://bugs.webkit.org/show_bug.cgi?id=108283 155 // https://bugs.webkit.org/show_bug.cgi?id=108283
164 LayoutRect inflatedRect = rect; 156 LayoutRect inflatedRect = rect;
165 inflatedRect.inflate(LayoutUnit(1)); 157 inflatedRect.inflate(LayoutUnit(1));
166 158
167 // 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
168 DisablePaintInvalidationStateAsserts disabler; 160 DisablePaintInvalidationStateAsserts disabler;
169 161
170 node->layoutObject()->invalidatePaintRectangle(inflatedRect, displayItemClie ntForCaret(node)); 162 m_visualRect = node->layoutObject()->invalidatePaintRectangle(inflatedRect, this);
171 } 163 }
172 164
173 bool CaretBase::shouldRepaintCaret(Node& node) const 165 bool CaretBase::shouldRepaintCaret(Node& node) const
174 { 166 {
175 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, 167 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor,
176 // 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
177 // also when its parentNode() is contentEditable. 169 // also when its parentNode() is contentEditable.
178 node.document().updateStyleAndLayoutTree(); 170 node.document().updateStyleAndLayoutTree();
179 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod e.parentNode())); 171 return hasEditableStyle(node) || (node.parentNode() && hasEditableStyle(*nod e.parentNode()));
180 } 172 }
(...skipping 18 matching lines...) Expand all
199 if (hasEditableStyle(*node) || shouldRepaintCaret(view)) 191 if (hasEditableStyle(*node) || shouldRepaintCaret(view))
200 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); 192 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate());
201 } 193 }
202 } 194 }
203 195
204 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
205 { 197 {
206 if (m_caretVisibility == CaretVisibility::Hidden) 198 if (m_caretVisibility == CaretVisibility::Hidden)
207 return; 199 return;
208 200
209 if (DrawingRecorder::useCachedDrawingIfPossible(context, *displayItemClientF orCaret(node), displayItemType)) 201 if (DrawingRecorder::useCachedDrawingIfPossible(context, *this, displayItemT ype))
210 return; 202 return;
211 203
212 LayoutRect drawingRect = localCaretRectWithoutUpdate(); 204 LayoutRect drawingRect = localCaretRectWithoutUpdate();
213 if (LayoutBlock* layoutObject = caretLayoutObject(node)) 205 if (LayoutBlock* layoutObject = caretLayoutObject(node))
214 layoutObject->flipForWritingMode(drawingRect); 206 layoutObject->flipForWritingMode(drawingRect);
215 drawingRect.moveBy(roundedIntPoint(paintOffset)); 207 drawingRect.moveBy(roundedIntPoint(paintOffset));
216 208
217 Color caretColor = Color::black; 209 Color caretColor = Color::black;
218 210
219 Element* element; 211 Element* element;
220 if (node->isElementNode()) 212 if (node->isElementNode())
221 element = toElement(node); 213 element = toElement(node);
222 else 214 else
223 element = node->parentElement(); 215 element = node->parentElement();
224 216
225 if (element && element->layoutObject()) 217 if (element && element->layoutObject())
226 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); 218 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor);
227 219
228 DrawingRecorder drawingRecorder(context, *displayItemClientForCaret(node), D isplayItem::kCaret, FloatRect(drawingRect)); 220 DrawingRecorder drawingRecorder(context, *this, DisplayItem::kCaret, FloatRe ct(drawingRect));
229 221
230 context.fillRect(FloatRect(drawingRect), caretColor); 222 context.fillRect(FloatRect(drawingRect), caretColor);
231 } 223 }
232 224
233 void CaretBase::setCaretVisibility(CaretVisibility visibility) 225 void CaretBase::setCaretVisibility(CaretVisibility visibility)
234 { 226 {
235 m_caretVisibility = visibility; 227 m_caretVisibility = visibility;
236 } 228 }
237 229
230 String CaretBase::debugName() const
231 {
232 return "Caret";
233 }
234
235 LayoutRect CaretBase::visualRect() const
236 {
237 return m_visualRect;
238 }
239
238 } // 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/layout/LayoutObject.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698