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

Side by Side Diff: third_party/WebKit/Source/core/editing/CaretDisplayItemClient.h

Issue 2754993002: Fix caret invalidation when a block is removed (Closed)
Patch Set: Created 3 years, 9 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/CaretDisplayItemClient.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 // TODO(yosin,wangxianzhu): Make these two static functions private or 49 // TODO(yosin,wangxianzhu): Make these two static functions private or
50 // combine them into updateForPaintInvalidation() when the callsites in 50 // combine them into updateForPaintInvalidation() when the callsites in
51 // FrameCaret are removed. 51 // FrameCaret are removed.
52 52
53 // Creating VisiblePosition causes synchronous layout so we should use the 53 // Creating VisiblePosition causes synchronous layout so we should use the
54 // PositionWithAffinity version if possible. 54 // PositionWithAffinity version if possible.
55 // A position in HTMLTextFromControlElement is a typical example. 55 // A position in HTMLTextFromControlElement is a typical example.
56 static LayoutRect computeCaretRect(const PositionWithAffinity& caretPosition); 56 static LayoutRect computeCaretRect(const PositionWithAffinity& caretPosition);
57 static LayoutBlock* caretLayoutBlock(const Node*); 57 static LayoutBlock* caretLayoutBlock(const Node*);
58 58
59 // Called indirectly from LayoutObject::clearPreviousVisualRects(). 59 // Called indirectly from LayoutBlock::clearPreviousVisualRects().
60 void clearPreviousVisualRect(const LayoutBlock& block) { 60 void clearPreviousVisualRect(const LayoutBlock&);
61 if (shouldPaintCaret(block))
62 m_visualRect = LayoutRect();
63 }
64 61
65 void layoutBlockWillBeDestroyed(const LayoutBlock& block) { 62 // Called indirectly from LayoutBlock::willBeDestroyed().
66 if (!shouldPaintCaret(block)) 63 void layoutBlockWillBeDestroyed(const LayoutBlock&);
67 return;
68 m_visualRect = LayoutRect();
69 m_layoutBlock = nullptr;
70 }
71 64
72 // Called when a FrameView finishes layout. Updates style and geometry of the 65 // Called when a FrameView finishes layout. Updates style and geometry of the
73 // caret for paint invalidation and painting. 66 // caret for paint invalidation and painting.
74 void updateStyleAndLayoutIfNeeded(const PositionWithAffinity& caretPosition); 67 void updateStyleAndLayoutIfNeeded(const PositionWithAffinity& caretPosition);
75 68
76 // Called during LayoutBlock paint invalidation. 69 // Called during LayoutBlock paint invalidation.
77 void invalidatePaintIfNeeded(const LayoutBlock&, 70 void invalidatePaintIfNeeded(const LayoutBlock&,
78 const PaintInvalidatorContext&); 71 const PaintInvalidatorContext&);
79 72
80 bool shouldPaintCaret(const LayoutBlock& block) const { 73 bool shouldPaintCaret(const LayoutBlock& block) const {
81 return &block == m_layoutBlock; 74 return &block == m_layoutBlock;
82 } 75 }
83 void paintCaret(GraphicsContext&, 76 void paintCaret(GraphicsContext&,
84 const LayoutPoint& paintOffset, 77 const LayoutPoint& paintOffset,
85 DisplayItem::Type) const; 78 DisplayItem::Type) const;
86 79
87 // DisplayItemClient methods. 80 // DisplayItemClient methods.
88 LayoutRect visualRect() const final; 81 LayoutRect visualRect() const final;
89 String debugName() const final; 82 String debugName() const final;
90 83
91 private: 84 private:
85 friend class CaretDisplayItemClientTest;
86
92 void invalidatePaintInCurrentLayoutBlock(const PaintInvalidatorContext&); 87 void invalidatePaintInCurrentLayoutBlock(const PaintInvalidatorContext&);
93
94 void invalidatePaintInPreviousLayoutBlock(const PaintInvalidatorContext&); 88 void invalidatePaintInPreviousLayoutBlock(const PaintInvalidatorContext&);
95 89
96 // These are updated by updateStyleAndLayoutIfNeeded(). 90 // These are updated by updateStyleAndLayoutIfNeeded().
97 Color m_color; 91 Color m_color;
98 LayoutRect m_localRect; 92 LayoutRect m_localRect;
99 LayoutBlock* m_layoutBlock = nullptr; 93 LayoutBlock* m_layoutBlock = nullptr;
100 94
101 // Visual rect of the caret in m_layoutBlock. This is updated by 95 // Visual rect of the caret in m_layoutBlock. This is updated by
102 // invalidatePaintIfNeeded(). 96 // invalidatePaintIfNeeded().
103 LayoutRect m_visualRect; 97 LayoutRect m_visualRect;
104 98
105 // These are set to the previous value of m_layoutBlock and m_visualRect 99 // These are set to the previous value of m_layoutBlock and m_visualRect
106 // during updateStyleAndLayoutIfNeeded() if they haven't been set since the 100 // during updateStyleAndLayoutIfNeeded() if they haven't been set since the
107 // last paint invalidation. They can only be used in invalidatePaintIfNeeded() 101 // last paint invalidation. They can only be used in invalidatePaintIfNeeded()
108 // to invalidate the caret in the previous layout block. 102 // to invalidate the caret in the previous layout block.
109 const LayoutBlock* m_previousLayoutBlock = nullptr; 103 const LayoutBlock* m_previousLayoutBlock = nullptr;
110 LayoutRect m_visualRectInPreviousLayoutBlock; 104 LayoutRect m_visualRectInPreviousLayoutBlock;
111 105
112 bool m_needsPaintInvalidation = false; 106 bool m_needsPaintInvalidation = false;
113 }; 107 };
114 108
115 } // namespace blink 109 } // namespace blink
116 110
117 #endif // CaretDisplayItemClient_h 111 #endif // CaretDisplayItemClient_h
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/CaretDisplayItemClient.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698