Index: third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h |
diff --git a/third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h b/third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h |
index 042a3e570e5ed604beda6811dcb38d1a925a47cf..2c740f516e5d0ab355188a9d6a217f3575a613fc 100644 |
--- a/third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h |
+++ b/third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h |
@@ -37,6 +37,7 @@ namespace blink { |
class GraphicsContext; |
class LayoutBlock; |
+struct PaintInvalidatorContext; |
class CaretDisplayItemClient final : public DisplayItemClient { |
WTF_MAKE_NONCOPYABLE(CaretDisplayItemClient); |
@@ -45,26 +46,65 @@ class CaretDisplayItemClient final : public DisplayItemClient { |
CaretDisplayItemClient(); |
virtual ~CaretDisplayItemClient(); |
+ // TODO(yosin,wangxianzhu): Make these two static functions private or |
+ // combine them into updateForPaintInvalidation() when the callsites in |
+ // FrameCaret are removed. |
+ |
// Creating VisiblePosition causes synchronous layout so we should use the |
// PositionWithAffinity version if possible. |
// A position in HTMLTextFromControlElement is a typical example. |
static LayoutRect computeCaretRect(const PositionWithAffinity& caretPosition); |
+ static LayoutBlock* caretLayoutBlock(const Node*); |
+ |
+ // Called indirectly from LayoutObject::clearPreviousVisualRects(). |
+ void clearPreviousVisualRect(const LayoutBlock& block) { |
+ if (shouldPaintCaret(block)) |
+ m_visualRect = LayoutRect(); |
+ } |
+ |
+ void layoutBlockWillBeDestroyed(const LayoutBlock& block) { |
+ if (!shouldPaintCaret(block)) |
+ return; |
+ m_visualRect = LayoutRect(); |
+ m_layoutBlock = nullptr; |
+ } |
+ |
+ // Called when a FrameView finishes layout. Updates style and geometry of the |
+ // caret for paint invalidation and painting. |
+ void updateStyleAndLayoutIfNeeded(const PositionWithAffinity& caretPosition); |
- void paintCaret(Node*, |
- GraphicsContext&, |
- const LayoutRect& caretLocalRect, |
- const LayoutPoint&, |
- DisplayItem::Type); |
+ // Called during LayoutBlock paint invalidation. |
+ void invalidatePaintIfNeeded( |
+ const LayoutBlock&, |
+ const PaintInvalidatorContext&, |
+ PaintInvalidationReason layoutBlockPaintInvalidationReason); |
- static LayoutBlock* caretLayoutObject(Node*); |
- void invalidateLocalCaretRect(Node*, const LayoutRect&); |
+ bool shouldPaintCaret(const LayoutBlock& block) const { |
+ return &block == m_layoutBlock; |
+ } |
+ void paintCaret(GraphicsContext&, |
+ const LayoutPoint& paintOffset, |
+ DisplayItem::Type) const; |
// DisplayItemClient methods. |
LayoutRect visualRect() const final; |
String debugName() const final; |
private: |
+ // These are updated by updateStyleAndLayoutIfNeeded(). |
+ Color m_color; |
+ LayoutRect m_localRect; |
+ LayoutBlock* m_layoutBlock = nullptr; |
+ |
+ // This is set to the previous m_layoutBlock if m_layoutLayout will change |
+ // during updateStyleAndLayoutIfNeeded() and can be used in |
+ // invalidatePaintIfNeeded() only. |
+ const LayoutBlock* m_previousLayoutBlock = nullptr; |
+ |
+ // This is updated by invalidatePaintIfNeeded(). |
LayoutRect m_visualRect; |
+ |
+ bool m_needsPaintInvalidation = false; |
}; |
} // namespace blink |