OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
(...skipping 22 matching lines...) Expand all Loading... |
33 namespace blink { | 33 namespace blink { |
34 | 34 |
35 DragCaret::DragCaret() : m_caretBase(new CaretDisplayItemClient()) {} | 35 DragCaret::DragCaret() : m_caretBase(new CaretDisplayItemClient()) {} |
36 | 36 |
37 DragCaret::~DragCaret() = default; | 37 DragCaret::~DragCaret() = default; |
38 | 38 |
39 DragCaret* DragCaret::create() { | 39 DragCaret* DragCaret::create() { |
40 return new DragCaret; | 40 return new DragCaret; |
41 } | 41 } |
42 | 42 |
| 43 LayoutBlock* DragCaret::caretLayoutBlock() const { |
| 44 LayoutBlock* block = |
| 45 CaretDisplayItemClient::caretLayoutObject(m_position.anchorNode()); |
| 46 if (!block) |
| 47 return nullptr; |
| 48 if (!rootEditableElementOf(m_position.position())) |
| 49 return nullptr; |
| 50 return block; |
| 51 } |
| 52 |
43 bool DragCaret::hasCaretIn(const LayoutBlock& layoutBlock) const { | 53 bool DragCaret::hasCaretIn(const LayoutBlock& layoutBlock) const { |
44 Node* node = m_position.anchorNode(); | 54 return layoutBlock == this->caretLayoutBlock(); |
45 if (!node) | |
46 return false; | |
47 if (layoutBlock != CaretDisplayItemClient::caretLayoutObject(node)) | |
48 return false; | |
49 return rootEditableElementOf(m_position.position()); | |
50 } | 55 } |
51 | 56 |
52 bool DragCaret::isContentRichlyEditable() const { | 57 bool DragCaret::isContentRichlyEditable() const { |
53 return isRichlyEditablePosition(m_position.position()); | 58 return isRichlyEditablePosition(m_position.position()); |
54 } | 59 } |
55 | 60 |
56 void DragCaret::invalidateCaretRect(Node* node, | 61 void DragCaret::setCaretPosition(const PositionWithAffinity& position) { |
57 const LayoutRect& caretLocalRect) { | 62 if (LayoutBlock* block = caretLayoutBlock()) |
58 // TODO(editing-dev): The use of updateStyleAndLayout | 63 block->setMayNeedPaintInvalidation(); |
59 // needs to be audited. See http://crbug.com/590369 for more details. | |
60 // In the long term we should use idle time spell checker to prevent | |
61 // synchronous layout caused by spell checking (see crbug.com/517298). | |
62 node->document().updateStyleAndLayoutTree(); | |
63 if (!hasEditableStyle(*node)) | |
64 return; | |
65 m_caretBase->invalidateLocalCaretRect(node, caretLocalRect); | |
66 } | |
67 | 64 |
68 void DragCaret::setCaretPosition(const PositionWithAffinity& position) { | |
69 // for querying Layer::compositingState() | |
70 // This code is probably correct, since it doesn't occur in a stack that | |
71 // involves updating compositing state. | |
72 DisableCompositingQueryAsserts disabler; | |
73 | |
74 if (Node* node = m_position.anchorNode()) | |
75 invalidateCaretRect(node, m_caretLocalRect); | |
76 m_position = createVisiblePosition(position).toPositionWithAffinity(); | 65 m_position = createVisiblePosition(position).toPositionWithAffinity(); |
77 Document* document = nullptr; | 66 Document* document = nullptr; |
78 if (Node* node = m_position.anchorNode()) { | 67 if (Node* node = m_position.anchorNode()) { |
79 invalidateCaretRect(node, m_caretLocalRect); | |
80 document = &node->document(); | 68 document = &node->document(); |
81 setContext(document); | 69 setContext(document); |
82 } | 70 } |
83 if (m_position.isNull()) { | 71 if (m_position.isNull()) { |
84 m_caretLocalRect = LayoutRect(); | 72 m_caretLocalRect = LayoutRect(); |
85 } else { | 73 } else { |
86 DCHECK(!m_position.isOrphan()); | 74 DCHECK(!m_position.isOrphan()); |
87 document->updateStyleAndLayoutTree(); | 75 document->updateStyleAndLayoutTree(); |
88 m_caretLocalRect = CaretDisplayItemClient::computeCaretRect(m_position); | 76 m_caretLocalRect = CaretDisplayItemClient::computeCaretRect(m_position); |
89 } | 77 } |
| 78 |
| 79 if (LayoutBlock* block = caretLayoutBlock()) |
| 80 block->setMayNeedPaintInvalidation(); |
90 } | 81 } |
91 | 82 |
92 void DragCaret::nodeChildrenWillBeRemoved(ContainerNode& container) { | 83 void DragCaret::nodeChildrenWillBeRemoved(ContainerNode& container) { |
93 if (!hasCaret() || !container.inActiveDocument()) | 84 if (!hasCaret() || !container.inActiveDocument()) |
94 return; | 85 return; |
95 Node* const anchorNode = m_position.position().anchorNode(); | 86 Node* const anchorNode = m_position.position().anchorNode(); |
96 if (!anchorNode || anchorNode == container) | 87 if (!anchorNode || anchorNode == container) |
97 return; | 88 return; |
98 if (!container.isShadowIncludingInclusiveAncestorOf(anchorNode)) | 89 if (!container.isShadowIncludingInclusiveAncestorOf(anchorNode)) |
99 return; | 90 return; |
(...skipping 21 matching lines...) Expand all Loading... |
121 void DragCaret::paintDragCaret(LocalFrame* frame, | 112 void DragCaret::paintDragCaret(LocalFrame* frame, |
122 GraphicsContext& context, | 113 GraphicsContext& context, |
123 const LayoutPoint& paintOffset) const { | 114 const LayoutPoint& paintOffset) const { |
124 if (m_position.anchorNode()->document().frame() == frame) { | 115 if (m_position.anchorNode()->document().frame() == frame) { |
125 m_caretBase->paintCaret(m_position.anchorNode(), context, m_caretLocalRect, | 116 m_caretBase->paintCaret(m_position.anchorNode(), context, m_caretLocalRect, |
126 paintOffset, DisplayItem::kDragCaret); | 117 paintOffset, DisplayItem::kDragCaret); |
127 } | 118 } |
128 } | 119 } |
129 | 120 |
130 } // namespace blink | 121 } // namespace blink |
OLD | NEW |