OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
3 * reserved. | 3 * reserved. |
4 * | 4 * |
5 * Redistribution and use in source and binary forms, with or without | 5 * Redistribution and use in source and binary forms, with or without |
6 * modification, are permitted provided that the following conditions | 6 * modification, are permitted provided that the following conditions |
7 * are met: | 7 * are met: |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 19 matching lines...) Expand all Loading... |
30 #include "core/editing/PositionWithAffinity.h" | 30 #include "core/editing/PositionWithAffinity.h" |
31 #include "platform/geometry/IntRect.h" | 31 #include "platform/geometry/IntRect.h" |
32 #include "platform/geometry/LayoutRect.h" | 32 #include "platform/geometry/LayoutRect.h" |
33 #include "platform/graphics/paint/DisplayItem.h" | 33 #include "platform/graphics/paint/DisplayItem.h" |
34 #include "wtf/Noncopyable.h" | 34 #include "wtf/Noncopyable.h" |
35 | 35 |
36 namespace blink { | 36 namespace blink { |
37 | 37 |
38 class GraphicsContext; | 38 class GraphicsContext; |
39 class LayoutBlock; | 39 class LayoutBlock; |
| 40 struct PaintInvalidatorContext; |
40 | 41 |
41 class CaretDisplayItemClient final : public DisplayItemClient { | 42 class CaretDisplayItemClient final : public DisplayItemClient { |
42 WTF_MAKE_NONCOPYABLE(CaretDisplayItemClient); | 43 WTF_MAKE_NONCOPYABLE(CaretDisplayItemClient); |
43 | 44 |
44 public: | 45 public: |
45 CaretDisplayItemClient(); | 46 CaretDisplayItemClient(); |
46 virtual ~CaretDisplayItemClient(); | 47 virtual ~CaretDisplayItemClient(); |
47 | 48 |
| 49 // TODO(yosin,wangxianzhu): Make these two static functions private or |
| 50 // combine them into updateForPaintInvalidation() when the callsites in |
| 51 // FrameCaret are removed. |
| 52 |
48 // Creating VisiblePosition causes synchronous layout so we should use the | 53 // Creating VisiblePosition causes synchronous layout so we should use the |
49 // PositionWithAffinity version if possible. | 54 // PositionWithAffinity version if possible. |
50 // A position in HTMLTextFromControlElement is a typical example. | 55 // A position in HTMLTextFromControlElement is a typical example. |
51 static LayoutRect computeCaretRect(const PositionWithAffinity& caretPosition); | 56 static LayoutRect computeCaretRect(const PositionWithAffinity& caretPosition); |
| 57 static LayoutBlock* caretLayoutBlock(const Node*); |
52 | 58 |
53 void paintCaret(Node*, | 59 // Called indirectly from LayoutObject::clearPreviousVisualRects(). |
54 GraphicsContext&, | 60 void clearPreviousVisualRect(const LayoutBlock& block) { |
55 const LayoutRect& caretLocalRect, | 61 if (shouldPaintCaret(block)) |
56 const LayoutPoint&, | 62 m_visualRect = LayoutRect(); |
57 DisplayItem::Type); | 63 } |
58 | 64 |
59 static LayoutBlock* caretLayoutObject(Node*); | 65 void layoutBlockWillBeDestroyed(const LayoutBlock& block) { |
60 void invalidateLocalCaretRect(Node*, const LayoutRect&); | 66 if (!shouldPaintCaret(block)) |
| 67 return; |
| 68 m_visualRect = LayoutRect(); |
| 69 m_layoutBlock = nullptr; |
| 70 } |
| 71 |
| 72 // Called when a FrameView finishes layout. Updates style and geometry of the |
| 73 // caret for paint invalidation and painting. |
| 74 void updateStyleAndLayoutIfNeeded(const PositionWithAffinity& caretPosition); |
| 75 |
| 76 // Called during LayoutBlock paint invalidation. |
| 77 void invalidatePaintIfNeeded( |
| 78 const LayoutBlock&, |
| 79 const PaintInvalidatorContext&, |
| 80 PaintInvalidationReason layoutBlockPaintInvalidationReason); |
| 81 |
| 82 bool shouldPaintCaret(const LayoutBlock& block) const { |
| 83 return &block == m_layoutBlock; |
| 84 } |
| 85 void paintCaret(GraphicsContext&, |
| 86 const LayoutPoint& paintOffset, |
| 87 DisplayItem::Type) const; |
61 | 88 |
62 // DisplayItemClient methods. | 89 // DisplayItemClient methods. |
63 LayoutRect visualRect() const final; | 90 LayoutRect visualRect() const final; |
64 String debugName() const final; | 91 String debugName() const final; |
65 | 92 |
66 private: | 93 private: |
| 94 // These are updated by updateStyleAndLayoutIfNeeded(). |
| 95 Color m_color; |
| 96 LayoutRect m_localRect; |
| 97 LayoutBlock* m_layoutBlock = nullptr; |
| 98 |
| 99 // This is set to the previous m_layoutBlock if m_layoutLayout will change |
| 100 // during updateStyleAndLayoutIfNeeded() and can be used in |
| 101 // invalidatePaintIfNeeded() only. |
| 102 const LayoutBlock* m_previousLayoutBlock = nullptr; |
| 103 |
| 104 // This is updated by invalidatePaintIfNeeded(). |
67 LayoutRect m_visualRect; | 105 LayoutRect m_visualRect; |
| 106 |
| 107 bool m_needsPaintInvalidation = false; |
68 }; | 108 }; |
69 | 109 |
70 } // namespace blink | 110 } // namespace blink |
71 | 111 |
72 #endif // CaretDisplayItemClient_h | 112 #endif // CaretDisplayItemClient_h |
OLD | NEW |