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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 static inline bool caretRendersInsideNode(Node* node) | 121 static inline bool caretRendersInsideNode(Node* node) |
122 { | 122 { |
123 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; | 123 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; |
124 } | 124 } |
125 | 125 |
126 RenderBlock* CaretBase::caretRenderer(Node* node) | 126 RenderBlock* CaretBase::caretRenderer(Node* node) |
127 { | 127 { |
128 if (!node) | 128 if (!node) |
129 return 0; | 129 return 0; |
130 | 130 |
131 RenderObject* renderer = node->renderer(); | 131 LayoutObject* renderer = node->renderer(); |
132 if (!renderer) | 132 if (!renderer) |
133 return 0; | 133 return 0; |
134 | 134 |
135 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block | 135 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block |
136 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no
de); | 136 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no
de); |
137 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock(
); | 137 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock(
); |
138 } | 138 } |
139 | 139 |
140 static void mapCaretRectToCaretPainter(RenderObject* caretRenderer, RenderBlock*
caretPainter, LayoutRect& caretRect) | 140 static void mapCaretRectToCaretPainter(LayoutObject* caretRenderer, RenderBlock*
caretPainter, LayoutRect& caretRect) |
141 { | 141 { |
142 // FIXME: This shouldn't be called on un-rooted subtrees. | 142 // FIXME: This shouldn't be called on un-rooted subtrees. |
143 // FIXME: This should probably just use mapLocalToContainer. | 143 // FIXME: This should probably just use mapLocalToContainer. |
144 // Compute an offset between the caretRenderer and the caretPainter. | 144 // Compute an offset between the caretRenderer and the caretPainter. |
145 | 145 |
146 ASSERT(caretRenderer->isDescendantOf(caretPainter)); | 146 ASSERT(caretRenderer->isDescendantOf(caretPainter)); |
147 | 147 |
148 bool unrooted = false; | 148 bool unrooted = false; |
149 while (caretRenderer != caretPainter) { | 149 while (caretRenderer != caretPainter) { |
150 RenderObject* containerObject = caretRenderer->container(); | 150 LayoutObject* containerObject = caretRenderer->container(); |
151 if (!containerObject) { | 151 if (!containerObject) { |
152 unrooted = true; | 152 unrooted = true; |
153 break; | 153 break; |
154 } | 154 } |
155 caretRect.move(caretRenderer->offsetFromContainer(containerObject, caret
Rect.location())); | 155 caretRect.move(caretRenderer->offsetFromContainer(containerObject, caret
Rect.location())); |
156 caretRenderer = containerObject; | 156 caretRenderer = containerObject; |
157 } | 157 } |
158 | 158 |
159 if (unrooted) | 159 if (unrooted) |
160 caretRect = LayoutRect(); | 160 caretRect = LayoutRect(); |
161 } | 161 } |
162 | 162 |
163 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) | 163 bool CaretBase::updateCaretRect(Document* document, const PositionWithAffinity&
caretPosition) |
164 { | 164 { |
165 m_caretLocalRect = LayoutRect(); | 165 m_caretLocalRect = LayoutRect(); |
166 | 166 |
167 if (caretPosition.position().isNull()) | 167 if (caretPosition.position().isNull()) |
168 return false; | 168 return false; |
169 | 169 |
170 ASSERT(caretPosition.position().deprecatedNode()->renderer()); | 170 ASSERT(caretPosition.position().deprecatedNode()->renderer()); |
171 | 171 |
172 // First compute a rect local to the renderer at the selection start. | 172 // First compute a rect local to the renderer at the selection start. |
173 RenderObject* renderer; | 173 LayoutObject* renderer; |
174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, renderer); | 174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, renderer); |
175 | 175 |
176 // Get the renderer that will be responsible for painting the caret | 176 // Get the renderer that will be responsible for painting the caret |
177 // (which is either the renderer we just found, or one of its containers). | 177 // (which is either the renderer we just found, or one of its containers). |
178 RenderBlock* caretPainter = caretRenderer(caretPosition.position().deprecate
dNode()); | 178 RenderBlock* caretPainter = caretRenderer(caretPosition.position().deprecate
dNode()); |
179 | 179 |
180 mapCaretRectToCaretPainter(renderer, caretPainter, m_caretLocalRect); | 180 mapCaretRectToCaretPainter(renderer, caretPainter, m_caretLocalRect); |
181 | 181 |
182 return true; | 182 return true; |
183 } | 183 } |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
276 context->fillRect(caret, caretColor); | 276 context->fillRect(caret, caretColor); |
277 } | 277 } |
278 | 278 |
279 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 |
280 { | 280 { |
281 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 281 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
282 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 282 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
283 } | 283 } |
284 | 284 |
285 } | 285 } |
OLD | NEW |