| 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 void setNeedsPaintInvalidation() { m_needsPaintInvalidation = true; } |
| 54 GraphicsContext&, | |
| 55 const LayoutRect& caretLocalRect, | |
| 56 const LayoutPoint&, | |
| 57 DisplayItem::Type); | |
| 58 | 60 |
| 59 static LayoutBlock* caretLayoutObject(Node*); | 61 // Called indirectly from LayoutObject::clearPreviousVisualRects(). |
| 60 void invalidateLocalCaretRect(Node*, const LayoutRect&); | 62 void clearPreviousVisualRect(const LayoutBlock& block) { |
| 63 if (shouldPaintCaret(block)) |
| 64 m_visualRect = LayoutRect(); |
| 65 } |
| 66 |
| 67 void layoutBlockWillBeDestroyed(const LayoutBlock& block) { |
| 68 if (!shouldPaintCaret(block)) |
| 69 return; |
| 70 m_visualRect = LayoutRect(); |
| 71 m_layoutBlock = nullptr; |
| 72 } |
| 73 |
| 74 // Called before a paint invalidation tree walk of the FrameView. Updates |
| 75 // paint invalidation status and sets paint invalidation flags if needed. |
| 76 void updateForPaintInvalidation(const PositionWithAffinity& caretPosition); |
| 77 |
| 78 // Called during LayoutBlock paint invalidation. |
| 79 void invalidatePaintIfNeeded( |
| 80 const LayoutBlock&, |
| 81 const PaintInvalidatorContext&, |
| 82 PaintInvalidationReason layoutBlockPaintInvalidationReason); |
| 83 |
| 84 bool shouldPaintCaret(const LayoutBlock& block) const { |
| 85 return &block == m_layoutBlock; |
| 86 } |
| 87 void paintCaret(GraphicsContext&, |
| 88 const LayoutPoint& paintOffset, |
| 89 DisplayItem::Type) const; |
| 61 | 90 |
| 62 // DisplayItemClient methods. | 91 // DisplayItemClient methods. |
| 63 LayoutRect visualRect() const final; | 92 LayoutRect visualRect() const final; |
| 64 String debugName() const final; | 93 String debugName() const final; |
| 65 | 94 |
| 66 private: | 95 private: |
| 96 // These are updated by updateForPaintInvalidation(). |
| 97 Color m_color; |
| 98 LayoutRect m_localRect; |
| 99 LayoutBlock* m_layoutBlock = nullptr; |
| 100 |
| 101 // This is set to the previous m_layoutBlock if m_layoutLayout will change |
| 102 // during updateForPaintInvalidation() and can be used in |
| 103 // invalidatePaintIfNeeded() only. |
| 104 const LayoutBlock* m_previousLayoutBlock = nullptr; |
| 105 |
| 106 // This is updated by invalidatePaintIfNeeded(). |
| 67 LayoutRect m_visualRect; | 107 LayoutRect m_visualRect; |
| 108 |
| 109 bool m_needsPaintInvalidation = false; |
| 68 }; | 110 }; |
| 69 | 111 |
| 70 } // namespace blink | 112 } // namespace blink |
| 71 | 113 |
| 72 #endif // CaretDisplayItemClient_h | 114 #endif // CaretDisplayItemClient_h |
| OLD | NEW |