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

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

Issue 2292353003: Cherry-pick r415013 to M53. (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 16 matching lines...) Expand all
27 27
28 #include "core/editing/EditingUtilities.h" 28 #include "core/editing/EditingUtilities.h"
29 #include "core/editing/VisibleUnits.h" 29 #include "core/editing/VisibleUnits.h"
30 #include "core/frame/FrameView.h" 30 #include "core/frame/FrameView.h"
31 #include "core/frame/Settings.h" 31 #include "core/frame/Settings.h"
32 #include "core/layout/LayoutBlock.h" 32 #include "core/layout/LayoutBlock.h"
33 #include "core/layout/LayoutView.h" 33 #include "core/layout/LayoutView.h"
34 #include "core/layout/api/LayoutBlockItem.h" 34 #include "core/layout/api/LayoutBlockItem.h"
35 #include "core/layout/api/LayoutItem.h" 35 #include "core/layout/api/LayoutItem.h"
36 #include "core/paint/PaintInfo.h" 36 #include "core/paint/PaintInfo.h"
37 #include "core/paint/PaintLayer.h"
37 #include "platform/graphics/GraphicsContext.h" 38 #include "platform/graphics/GraphicsContext.h"
39 #include "platform/graphics/GraphicsLayer.h"
40 #include "platform/graphics/paint/DrawingRecorder.h"
38 41
39 namespace blink { 42 namespace blink {
40 43
41 CaretBase::CaretBase(CaretVisibility visibility) 44 CaretBase::CaretBase(CaretVisibility visibility)
42 : m_caretVisibility(visibility) 45 : m_caretVisibility(visibility)
43 { 46 {
44 } 47 }
45 48
46 CaretBase::~CaretBase() = default; 49 CaretBase::~CaretBase() = default;
47 50
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
132 { 135 {
133 LayoutBlock* caretPainter = caretLayoutObject(node); 136 LayoutBlock* caretPainter = caretLayoutObject(node);
134 if (!caretPainter) 137 if (!caretPainter)
135 return IntRect(); 138 return IntRect();
136 139
137 LayoutRect localRect(rect); 140 LayoutRect localRect(rect);
138 caretPainter->flipForWritingMode(localRect); 141 caretPainter->flipForWritingMode(localRect);
139 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox(); 142 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun dingBox();
140 } 143 }
141 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
142 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad 153 // TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad
143 // design. We should use only previous layoutObject or Rectangle to invalidate 154 // design. We should use only previous layoutObject or Rectangle to invalidate
144 // old caret. 155 // old caret.
145 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) 156 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect)
146 { 157 {
147 LayoutBlockItem caretPainter = LayoutBlockItem(caretLayoutObject(node)); 158 LayoutBlock* caretLayoutBlock = caretLayoutObject(node);
148 if (!caretPainter) 159 if (!caretLayoutBlock)
149 return; 160 return;
150 161
151 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. 162 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems.
152 // https://bugs.webkit.org/show_bug.cgi?id=108283 163 // https://bugs.webkit.org/show_bug.cgi?id=108283
153 LayoutRect inflatedRect = rect; 164 LayoutRect inflatedRect = rect;
154 inflatedRect.inflate(LayoutUnit(1)); 165 inflatedRect.inflate(LayoutUnit(1));
155 166
156 // FIXME: We should use mapLocalToAncestor() since we know we're not un-root ed.
157 mapCaretRectToCaretPainter(LayoutItem(node->layoutObject()), caretPainter, i nflatedRect);
158
159 // FIXME: We should not allow paint invalidation out of paint invalidation s tate. crbug.com/457415 167 // FIXME: We should not allow paint invalidation out of paint invalidation s tate. crbug.com/457415
160 DisablePaintInvalidationStateAsserts disabler; 168 DisablePaintInvalidationStateAsserts disabler;
161 caretPainter.invalidatePaintRectangle(inflatedRect); 169
170 node->layoutObject()->invalidatePaintRectangle(inflatedRect, displayItemClie ntForCaret(node));
162 } 171 }
163 172
164 bool CaretBase::shouldRepaintCaret(Node& node) const 173 bool CaretBase::shouldRepaintCaret(Node& node) const
165 { 174 {
166 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, 175 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor,
167 // carets need to be repainted not only when the node is contentEditable but 176 // carets need to be repainted not only when the node is contentEditable but
168 // also when its parentNode() is contentEditable. 177 // also when its parentNode() is contentEditable.
169 return node.isContentEditable() || (node.parentNode() && node.parentNode()-> isContentEditable()); 178 return node.isContentEditable() || (node.parentNode() && node.parentNode()-> isContentEditable());
170 } 179 }
171 180
(...skipping 11 matching lines...) Expand all
183 { 192 {
184 if (caretRectChanged) 193 if (caretRectChanged)
185 return; 194 return;
186 195
187 if (LayoutViewItem view = node->document().layoutViewItem()) { 196 if (LayoutViewItem view = node->document().layoutViewItem()) {
188 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable) || s houldRepaintCaret(view)) 197 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable) || s houldRepaintCaret(view))
189 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); 198 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate());
190 } 199 }
191 } 200 }
192 201
193 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi nt& paintOffset) const 202 void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi nt& paintOffset, DisplayItem::Type displayItemType) const
194 { 203 {
195 if (m_caretVisibility == CaretVisibility::Hidden) 204 if (m_caretVisibility == CaretVisibility::Hidden)
196 return; 205 return;
197 206
207 if (DrawingRecorder::useCachedDrawingIfPossible(context, *displayItemClientF orCaret(node), displayItemType))
208 return;
209
198 LayoutRect drawingRect = localCaretRectWithoutUpdate(); 210 LayoutRect drawingRect = localCaretRectWithoutUpdate();
199 if (LayoutBlock* layoutObject = caretLayoutObject(node)) 211 if (LayoutBlock* layoutObject = caretLayoutObject(node))
200 layoutObject->flipForWritingMode(drawingRect); 212 layoutObject->flipForWritingMode(drawingRect);
201 drawingRect.moveBy(roundedIntPoint(paintOffset)); 213 drawingRect.moveBy(roundedIntPoint(paintOffset));
202 214
203 Color caretColor = Color::black; 215 Color caretColor = Color::black;
204 216
205 Element* element; 217 Element* element;
206 if (node->isElementNode()) 218 if (node->isElementNode())
207 element = toElement(node); 219 element = toElement(node);
208 else 220 else
209 element = node->parentElement(); 221 element = node->parentElement();
210 222
211 if (element && element->layoutObject()) 223 if (element && element->layoutObject())
212 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); 224 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor);
213 225
226 DrawingRecorder drawingRecorder(context, *displayItemClientForCaret(node), D isplayItem::Caret, FloatRect(drawingRect));
227
214 context.fillRect(FloatRect(drawingRect), caretColor); 228 context.fillRect(FloatRect(drawingRect), caretColor);
215 } 229 }
216 230
217 void CaretBase::setCaretVisibility(CaretVisibility visibility) 231 void CaretBase::setCaretVisibility(CaretVisibility visibility)
218 { 232 {
219 m_caretVisibility = visibility; 233 m_caretVisibility = visibility;
220 } 234 }
221 235
222 } // namespace blink 236 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/CaretBase.h ('k') | third_party/WebKit/Source/core/editing/DragCaretController.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698