Index: third_party/WebKit/Source/core/editing/CaretBase.cpp |
diff --git a/third_party/WebKit/Source/core/editing/CaretBase.cpp b/third_party/WebKit/Source/core/editing/CaretBase.cpp |
index 9781217137343403d52c8a7a8792b44c9c4e04f2..c3e64a223da90e036e741bba2d716dd11e1dca2f 100644 |
--- a/third_party/WebKit/Source/core/editing/CaretBase.cpp |
+++ b/third_party/WebKit/Source/core/editing/CaretBase.cpp |
@@ -34,7 +34,10 @@ |
#include "core/layout/api/LayoutBlockItem.h" |
#include "core/layout/api/LayoutItem.h" |
#include "core/paint/PaintInfo.h" |
+#include "core/paint/PaintLayer.h" |
#include "platform/graphics/GraphicsContext.h" |
+#include "platform/graphics/GraphicsLayer.h" |
+#include "platform/graphics/paint/DrawingRecorder.h" |
namespace blink { |
@@ -139,13 +142,21 @@ IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect |
return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoundingBox(); |
} |
+DisplayItemClient* CaretBase::displayItemClientForCaret(Node* node) |
+{ |
+ LayoutBlock* caretLayoutBlock = caretLayoutObject(node); |
+ if (caretLayoutBlock->usesCompositedScrolling()) |
+ return static_cast<DisplayItemClient*>(caretLayoutBlock->layer()->graphicsLayerBackingForScrolling()); |
+ return caretLayoutBlock; |
+} |
+ |
// TODO(yoichio): |node| is FrameSelection::m_previousCaretNode and this is bad |
// design. We should use only previous layoutObject or Rectangle to invalidate |
// old caret. |
void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) |
{ |
- LayoutBlockItem caretPainter = LayoutBlockItem(caretLayoutObject(node)); |
- if (!caretPainter) |
+ LayoutBlock* caretLayoutBlock = caretLayoutObject(node); |
+ if (!caretLayoutBlock) |
return; |
// FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
@@ -153,12 +164,10 @@ void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) |
LayoutRect inflatedRect = rect; |
inflatedRect.inflate(LayoutUnit(1)); |
- // FIXME: We should use mapLocalToAncestor() since we know we're not un-rooted. |
- mapCaretRectToCaretPainter(LayoutItem(node->layoutObject()), caretPainter, inflatedRect); |
- |
// FIXME: We should not allow paint invalidation out of paint invalidation state. crbug.com/457415 |
DisablePaintInvalidationStateAsserts disabler; |
- caretPainter.invalidatePaintRectangle(inflatedRect); |
+ |
+ node->layoutObject()->invalidatePaintRectangle(inflatedRect, displayItemClientForCaret(node)); |
} |
bool CaretBase::shouldRepaintCaret(Node& node) const |
@@ -192,11 +201,14 @@ void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) |
} |
} |
-void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoint& paintOffset) const |
+void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoint& paintOffset, DisplayItem::Type displayItemType) const |
{ |
if (m_caretVisibility == CaretVisibility::Hidden) |
return; |
+ if (DrawingRecorder::useCachedDrawingIfPossible(context, *displayItemClientForCaret(node), displayItemType)) |
+ return; |
+ |
LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
if (LayoutBlock* layoutObject = caretLayoutObject(node)) |
layoutObject->flipForWritingMode(drawingRect); |
@@ -213,6 +225,8 @@ void CaretBase::paintCaret(Node* node, GraphicsContext& context, const LayoutPoi |
if (element && element->layoutObject()) |
caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); |
+ DrawingRecorder drawingRecorder(context, *displayItemClientForCaret(node), DisplayItem::Caret, FloatRect(drawingRect)); |
+ |
context.fillRect(FloatRect(drawingRect), caretColor); |
} |