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 12 matching lines...) Expand all Loading... |
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 "config.h" | 26 #include "config.h" |
27 #include "core/editing/Caret.h" | 27 #include "core/editing/Caret.h" |
28 | 28 |
29 #include "core/dom/Document.h" | 29 #include "core/dom/Document.h" |
30 #include "core/editing/htmlediting.h" | 30 #include "core/editing/htmlediting.h" |
31 #include "core/frame/LocalFrame.h" | 31 #include "core/frame/LocalFrame.h" |
32 #include "core/frame/Settings.h" | 32 #include "core/frame/Settings.h" |
| 33 #include "core/html/HTMLTextFormControlElement.h" |
33 #include "core/rendering/RenderBlock.h" | 34 #include "core/rendering/RenderBlock.h" |
34 #include "core/rendering/RenderView.h" | 35 #include "core/rendering/RenderView.h" |
35 #include "platform/graphics/GraphicsContext.h" | 36 #include "platform/graphics/GraphicsContext.h" |
36 | 37 |
37 namespace blink { | 38 namespace blink { |
38 | 39 |
39 CaretBase::CaretBase(CaretVisibility visibility) | 40 CaretBase::CaretBase(CaretVisibility visibility) |
40 : m_caretRectNeedsUpdate(true) | 41 : m_caretRectNeedsUpdate(true) |
41 , m_caretVisibility(visibility) | 42 , m_caretVisibility(visibility) |
42 { | 43 { |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
123 | 124 |
124 RenderObject* renderer = node->renderer(); | 125 RenderObject* renderer = node->renderer(); |
125 if (!renderer) | 126 if (!renderer) |
126 return 0; | 127 return 0; |
127 | 128 |
128 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block | 129 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block |
129 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no
de); | 130 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no
de); |
130 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock(
); | 131 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock(
); |
131 } | 132 } |
132 | 133 |
133 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) | 134 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) |
134 { | 135 { |
135 document->updateRenderTreeIfNeeded(); | 136 document->updateRenderTreeIfNeeded(); |
136 m_caretLocalRect = LayoutRect(); | 137 m_caretLocalRect = LayoutRect(); |
137 | 138 |
138 m_caretRectNeedsUpdate = false; | 139 m_caretRectNeedsUpdate = false; |
139 | 140 |
140 if (caretPosition.isNull()) | 141 if (caretPosition.position().isNull()) |
141 return false; | 142 return false; |
142 | 143 |
143 ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer()); | 144 ASSERT(caretPosition.position().deprecatedNode()->renderer()); |
144 | 145 |
145 // First compute a rect local to the renderer at the selection start. | 146 // First compute a rect local to the renderer at the selection start. |
146 RenderObject* renderer; | 147 RenderObject* renderer; |
147 LayoutRect localRect = caretPosition.localCaretRect(renderer); | 148 LayoutRect localRect = caretPosition.localCaretRect(renderer); |
148 | 149 |
149 // Get the renderer that will be responsible for painting the caret | 150 // Get the renderer that will be responsible for painting the caret |
150 // (which is either the renderer we just found, or one of its containers). | 151 // (which is either the renderer we just found, or one of its containers). |
151 RenderBlock* caretPainter = caretRenderer(caretPosition.deepEquivalent().dep
recatedNode()); | 152 RenderBlock* caretPainter = caretRenderer(caretPosition.position().deprecate
dNode()); |
152 | 153 |
153 // Compute an offset between the renderer and the caretPainter. | 154 // Compute an offset between the renderer and the caretPainter. |
154 bool unrooted = false; | 155 bool unrooted = false; |
155 while (renderer != caretPainter) { | 156 while (renderer != caretPainter) { |
156 RenderObject* containerObject = renderer->container(); | 157 RenderObject* containerObject = renderer->container(); |
157 if (!containerObject) { | 158 if (!containerObject) { |
158 unrooted = true; | 159 unrooted = true; |
159 break; | 160 break; |
160 } | 161 } |
161 localRect.move(renderer->offsetFromContainer(containerObject, localRect.
location())); | 162 localRect.move(renderer->offsetFromContainer(containerObject, localRect.
location())); |
162 renderer = containerObject; | 163 renderer = containerObject; |
163 } | 164 } |
164 | 165 |
165 if (!unrooted) | 166 if (!unrooted) |
166 m_caretLocalRect = localRect; | 167 m_caretLocalRect = localRect; |
167 | 168 |
168 return true; | 169 return true; |
169 } | 170 } |
170 | 171 |
| 172 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) |
| 173 { |
| 174 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui
valent(), caretPosition.affinity())); |
| 175 } |
| 176 |
171 RenderBlock* DragCaretController::caretRenderer() const | 177 RenderBlock* DragCaretController::caretRenderer() const |
172 { | 178 { |
173 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode()
); | 179 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode()
); |
174 } | 180 } |
175 | 181 |
176 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const | 182 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const |
177 { | 183 { |
178 RenderBlock* caretPainter = caretRenderer(node); | 184 RenderBlock* caretPainter = caretRenderer(node); |
179 if (!caretPainter) | 185 if (!caretPainter) |
180 return IntRect(); | 186 return IntRect(); |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 context->fillRect(caret, caretColor); | 266 context->fillRect(caret, caretColor); |
261 } | 267 } |
262 | 268 |
263 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 269 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
264 { | 270 { |
265 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 271 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
266 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 272 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
267 } | 273 } |
268 | 274 |
269 } | 275 } |
OLD | NEW |