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 #include "core/frame/Settings.h" | 33 #include "core/frame/Settings.h" |
34 #include "core/html/HTMLTextFormControlElement.h" | 34 #include "core/html/HTMLTextFormControlElement.h" |
35 #include "core/layout/LayoutBlock.h" | 35 #include "core/layout/LayoutBlock.h" |
36 #include "core/layout/LayoutView.h" | 36 #include "core/layout/LayoutView.h" |
37 #include "core/paint/DeprecatedPaintLayer.h" | 37 #include "core/paint/DeprecatedPaintLayer.h" |
38 #include "platform/graphics/GraphicsContext.h" | 38 #include "platform/graphics/GraphicsContext.h" |
39 | 39 |
40 namespace blink { | 40 namespace blink { |
41 | 41 |
42 CaretBase::CaretBase(CaretVisibility visibility) | 42 CaretBase::CaretBase(CaretVisibility visibility) |
43 : m_caretVisibility(visibility) | 43 : m_caretPainter(nullptr) |
| 44 , m_caretVisibility(visibility) |
44 { | 45 { |
45 } | 46 } |
46 | 47 |
47 DragCaretController::DragCaretController() | 48 DragCaretController::DragCaretController() |
48 : CaretBase(Visible) | 49 : CaretBase(Visible) |
49 { | 50 { |
50 } | 51 } |
51 | 52 |
52 PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create() | 53 PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create() |
53 { | 54 { |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 clear(); | 109 clear(); |
109 } | 110 } |
110 | 111 |
111 DEFINE_TRACE(DragCaretController) | 112 DEFINE_TRACE(DragCaretController) |
112 { | 113 { |
113 visitor->trace(m_position); | 114 visitor->trace(m_position); |
114 } | 115 } |
115 | 116 |
116 void CaretBase::clearCaretRect() | 117 void CaretBase::clearCaretRect() |
117 { | 118 { |
| 119 m_caretPainter = nullptr; |
118 m_caretLocalRect = LayoutRect(); | 120 m_caretLocalRect = LayoutRect(); |
119 } | 121 } |
120 | 122 |
121 static inline bool caretRendersInsideNode(Node* node) | 123 static inline bool caretRendersInsideNode(Node* node) |
122 { | 124 { |
123 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; | 125 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; |
124 } | 126 } |
125 | 127 |
126 LayoutBlock* CaretBase::caretLayoutObject(Node* node) | 128 LayoutBlock* CaretBase::caretLayoutObject(Node* node) |
127 { | 129 { |
(...skipping 27 matching lines...) Expand all Loading... |
155 caretRect.move(caretLayoutObject->offsetFromContainer(containerObject, c
aretRect.location())); | 157 caretRect.move(caretLayoutObject->offsetFromContainer(containerObject, c
aretRect.location())); |
156 caretLayoutObject = containerObject; | 158 caretLayoutObject = containerObject; |
157 } | 159 } |
158 | 160 |
159 if (unrooted) | 161 if (unrooted) |
160 caretRect = LayoutRect(); | 162 caretRect = LayoutRect(); |
161 } | 163 } |
162 | 164 |
163 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) | 165 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) |
164 { | 166 { |
| 167 m_caretPainter = nullptr; |
165 m_caretLocalRect = LayoutRect(); | 168 m_caretLocalRect = LayoutRect(); |
166 | 169 |
167 if (caretPosition.position().isNull()) | 170 if (caretPosition.position().isNull()) |
168 return false; | 171 return false; |
169 | 172 |
170 ASSERT(caretPosition.position().deprecatedNode()->layoutObject()); | 173 ASSERT(caretPosition.position().deprecatedNode()->layoutObject()); |
171 | 174 |
172 // First compute a rect local to the layoutObject at the selection start. | 175 // First compute a rect local to the layoutObject at the selection start. |
173 LayoutObject* layoutObject; | 176 LayoutObject* layoutObject; |
174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); | 177 m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); |
175 | 178 |
176 // Get the layoutObject that will be responsible for painting the caret | 179 // Get the layoutObject that will be responsible for painting the caret |
177 // (which is either the layoutObject we just found, or one of its containers
). | 180 // (which is either the layoutObject we just found, or one of its containers
). |
178 LayoutBlock* caretPainter = caretLayoutObject(caretPosition.position().depre
catedNode()); | 181 m_caretPainter = caretLayoutObject(caretPosition.position().deprecatedNode()
); |
179 | 182 |
180 mapCaretRectToCaretPainter(layoutObject, caretPainter, m_caretLocalRect); | 183 mapCaretRectToCaretPainter(layoutObject, m_caretPainter, m_caretLocalRect); |
181 | 184 |
182 return true; | 185 return true; |
183 } | 186 } |
184 | 187 |
185 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) | 188 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) |
186 { | 189 { |
187 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui
valent(), caretPosition.affinity())); | 190 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui
valent(), caretPosition.affinity())); |
188 } | 191 } |
189 | 192 |
190 LayoutBlock* DragCaretController::caretLayoutObject() const | |
191 { | |
192 return CaretBase::caretLayoutObject(m_position.deepEquivalent().deprecatedNo
de()); | |
193 } | |
194 | |
195 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const | 193 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const |
196 { | 194 { |
197 LayoutBlock* caretPainter = caretLayoutObject(node); | 195 LayoutBlock* caretPainter = caretLayoutObject(node); |
198 if (!caretPainter) | 196 if (!caretPainter) |
199 return IntRect(); | 197 return IntRect(); |
200 | 198 |
201 LayoutRect localRect(rect); | 199 LayoutRect localRect(rect); |
202 caretPainter->flipForWritingMode(localRect); | 200 caretPainter->flipForWritingMode(localRect); |
203 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); | 201 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); |
204 } | 202 } |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 context->fillRect(caret, caretColor); | 276 context->fillRect(caret, caretColor); |
279 } | 277 } |
280 | 278 |
281 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 279 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
282 { | 280 { |
283 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 281 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
284 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 282 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
285 } | 283 } |
286 | 284 |
287 } | 285 } |
OLD | NEW |