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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/editing/DragCaret.h" | 26 #include "core/editing/DragCaret.h" |
27 | 27 |
| 28 #include "core/editing/CaretDisplayItemClient.h" |
28 #include "core/editing/EditingUtilities.h" | 29 #include "core/editing/EditingUtilities.h" |
29 #include "core/frame/Settings.h" | 30 #include "core/frame/Settings.h" |
30 #include "core/layout/api/LayoutViewItem.h" | 31 #include "core/layout/api/LayoutViewItem.h" |
31 #include "core/paint/PaintLayer.h" | 32 #include "core/paint/PaintLayer.h" |
32 | 33 |
33 namespace blink { | 34 namespace blink { |
34 | 35 |
35 DragCaret::DragCaret() : m_caretBase(new CaretDisplayItemClient()) {} | 36 DragCaret::DragCaret() : m_caretBase(new CaretDisplayItemClient()) {} |
36 | 37 |
37 DragCaret::~DragCaret() = default; | 38 DragCaret::~DragCaret() = default; |
38 | 39 |
39 DragCaret* DragCaret::create() { | 40 DragCaret* DragCaret::create() { |
40 return new DragCaret; | 41 return new DragCaret; |
41 } | 42 } |
42 | 43 |
43 bool DragCaret::hasCaretIn(const LayoutBlock& layoutBlock) const { | 44 void DragCaret::clearPreviousVisualRect(const LayoutBlock& block) { |
44 Node* node = m_position.anchorNode(); | 45 m_caretBase->clearPreviousVisualRect(block); |
45 if (!node) | 46 } |
46 return false; | 47 |
47 if (layoutBlock != CaretDisplayItemClient::caretLayoutObject(node)) | 48 void DragCaret::layoutBlockWillBeDestroyed(const LayoutBlock& block) { |
48 return false; | 49 m_caretBase->layoutBlockWillBeDestroyed(block); |
49 return rootEditableElementOf(m_position.position()); | 50 } |
| 51 |
| 52 void DragCaret::updateStyleAndLayoutIfNeeded() { |
| 53 m_caretBase->updateStyleAndLayoutIfNeeded( |
| 54 rootEditableElementOf(m_position.position()) ? m_position |
| 55 : PositionWithAffinity()); |
| 56 } |
| 57 |
| 58 void DragCaret::invalidatePaintIfNeeded(const LayoutBlock& block, |
| 59 const PaintInvalidatorContext& context, |
| 60 PaintInvalidationReason reason) { |
| 61 m_caretBase->invalidatePaintIfNeeded(block, context, reason); |
50 } | 62 } |
51 | 63 |
52 bool DragCaret::isContentRichlyEditable() const { | 64 bool DragCaret::isContentRichlyEditable() const { |
53 return isRichlyEditablePosition(m_position.position()); | 65 return isRichlyEditablePosition(m_position.position()); |
54 } | 66 } |
55 | 67 |
56 void DragCaret::invalidateCaretRect(Node* node, | |
57 const LayoutRect& caretLocalRect) { | |
58 // TODO(editing-dev): The use of updateStyleAndLayout | |
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 | |
68 void DragCaret::setCaretPosition(const PositionWithAffinity& position) { | 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(); | 69 m_position = createVisiblePosition(position).toPositionWithAffinity(); |
77 Document* document = nullptr; | 70 Document* document = nullptr; |
78 if (Node* node = m_position.anchorNode()) { | 71 if (Node* node = m_position.anchorNode()) { |
79 invalidateCaretRect(node, m_caretLocalRect); | |
80 document = &node->document(); | 72 document = &node->document(); |
81 setContext(document); | 73 setContext(document); |
82 } | 74 } |
83 if (m_position.isNull()) { | 75 if (!m_position.isNull()) { |
84 m_caretLocalRect = LayoutRect(); | |
85 } else { | |
86 DCHECK(!m_position.isOrphan()); | 76 DCHECK(!m_position.isOrphan()); |
87 document->updateStyleAndLayoutTree(); | 77 document->updateStyleAndLayoutTree(); |
88 m_caretLocalRect = CaretDisplayItemClient::computeCaretRect(m_position); | |
89 } | 78 } |
90 } | 79 } |
91 | 80 |
92 void DragCaret::nodeChildrenWillBeRemoved(ContainerNode& container) { | 81 void DragCaret::nodeChildrenWillBeRemoved(ContainerNode& container) { |
93 if (!hasCaret() || !container.inActiveDocument()) | 82 if (!hasCaret() || !container.inActiveDocument()) |
94 return; | 83 return; |
95 Node* const anchorNode = m_position.position().anchorNode(); | 84 Node* const anchorNode = m_position.position().anchorNode(); |
96 if (!anchorNode || anchorNode == container) | 85 if (!anchorNode || anchorNode == container) |
97 return; | 86 return; |
98 if (!container.isShadowIncludingInclusiveAncestorOf(anchorNode)) | 87 if (!container.isShadowIncludingInclusiveAncestorOf(anchorNode)) |
(...skipping 12 matching lines...) Expand all Loading... |
111 return; | 100 return; |
112 m_position.document()->layoutViewItem().clearSelection(); | 101 m_position.document()->layoutViewItem().clearSelection(); |
113 clear(); | 102 clear(); |
114 } | 103 } |
115 | 104 |
116 DEFINE_TRACE(DragCaret) { | 105 DEFINE_TRACE(DragCaret) { |
117 visitor->trace(m_position); | 106 visitor->trace(m_position); |
118 SynchronousMutationObserver::trace(visitor); | 107 SynchronousMutationObserver::trace(visitor); |
119 } | 108 } |
120 | 109 |
121 void DragCaret::paintDragCaret(LocalFrame* frame, | 110 bool DragCaret::shouldPaintCaret(const LayoutBlock& block) const { |
| 111 return m_caretBase->shouldPaintCaret(block); |
| 112 } |
| 113 |
| 114 void DragCaret::paintDragCaret(const LocalFrame* frame, |
122 GraphicsContext& context, | 115 GraphicsContext& context, |
123 const LayoutPoint& paintOffset) const { | 116 const LayoutPoint& paintOffset) const { |
124 if (m_position.anchorNode()->document().frame() == frame) { | 117 if (m_position.anchorNode()->document().frame() == frame) |
125 m_caretBase->paintCaret(m_position.anchorNode(), context, m_caretLocalRect, | 118 m_caretBase->paintCaret(context, paintOffset, DisplayItem::kDragCaret); |
126 paintOffset, DisplayItem::kDragCaret); | |
127 } | |
128 } | 119 } |
129 | 120 |
130 } // namespace blink | 121 } // namespace blink |
OLD | NEW |