| 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 LayoutBlock* CaretBase::caretLayoutObject(Node* node) | 126 LayoutBlock* CaretBase::caretLayoutObject(Node* node) |
| 127 { | 127 { |
| 128 if (!node) | 128 if (!node) |
| 129 return 0; | 129 return 0; |
| 130 | 130 |
| 131 LayoutObject* renderer = node->layoutObject(); | 131 LayoutObject* layoutObject = node->layoutObject(); |
| 132 if (!renderer) | 132 if (!layoutObject) |
| 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->isLayoutBlock() && caretRendersInsideNode(no
de); | 136 bool paintedByBlock = layoutObject->isLayoutBlock() && caretRendersInsideNod
e(node); |
| 137 return paintedByBlock ? toLayoutBlock(renderer) : renderer->containingBlock(
); | 137 return paintedByBlock ? toLayoutBlock(layoutObject) : layoutObject->containi
ngBlock(); |
| 138 } | 138 } |
| 139 | 139 |
| 140 static void mapCaretRectToCaretPainter(LayoutObject* caretLayoutObject, LayoutBl
ock* caretPainter, LayoutRect& caretRect) | 140 static void mapCaretRectToCaretPainter(LayoutObject* caretLayoutObject, LayoutBl
ock* 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 caretLayoutObject and the caretPainter. | 144 // Compute an offset between the caretLayoutObject and the caretPainter. |
| 145 | 145 |
| 146 ASSERT(caretLayoutObject->isDescendantOf(caretPainter)); | 146 ASSERT(caretLayoutObject->isDescendantOf(caretPainter)); |
| 147 | 147 |
| (...skipping 14 matching lines...) Expand all Loading... |
| 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()->layoutObject()); | 170 ASSERT(caretPosition.position().deprecatedNode()->layoutObject()); |
| 171 | 171 |
| 172 // First compute a rect local to the renderer at the selection start. | 172 // First compute a rect local to the layoutObject at the selection start. |
| 173 LayoutObject* renderer; | 173 LayoutObject* layoutObject; |
| 174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, renderer); | 174 m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); |
| 175 | 175 |
| 176 // Get the renderer that will be responsible for painting the caret | 176 // Get the layoutObject 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 layoutObject we just found, or one of its containers
). |
| 178 LayoutBlock* caretPainter = caretLayoutObject(caretPosition.position().depre
catedNode()); | 178 LayoutBlock* caretPainter = caretLayoutObject(caretPosition.position().depre
catedNode()); |
| 179 | 179 |
| 180 mapCaretRectToCaretPainter(renderer, caretPainter, m_caretLocalRect); | 180 mapCaretRectToCaretPainter(layoutObject, caretPainter, m_caretLocalRect); |
| 181 | 181 |
| 182 return true; | 182 return true; |
| 183 } | 183 } |
| 184 | 184 |
| 185 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) | 185 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) |
| 186 { | 186 { |
| 187 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui
valent(), caretPosition.affinity())); | 187 return updateCaretRect(document, PositionWithAffinity(caretPosition.deepEqui
valent(), caretPosition.affinity())); |
| 188 } | 188 } |
| 189 | 189 |
| 190 LayoutBlock* DragCaretController::caretLayoutObject() const | 190 LayoutBlock* DragCaretController::caretLayoutObject() const |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 250 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); | 250 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); |
| 251 } | 251 } |
| 252 } | 252 } |
| 253 | 253 |
| 254 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const | 254 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const |
| 255 { | 255 { |
| 256 if (m_caretVisibility == Hidden) | 256 if (m_caretVisibility == Hidden) |
| 257 return; | 257 return; |
| 258 | 258 |
| 259 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 259 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 260 if (LayoutBlock* renderer = caretLayoutObject(node)) | 260 if (LayoutBlock* layoutObject = caretLayoutObject(node)) |
| 261 renderer->flipForWritingMode(drawingRect); | 261 layoutObject->flipForWritingMode(drawingRect); |
| 262 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 262 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
| 263 LayoutRect caret = intersection(drawingRect, clipRect); | 263 LayoutRect caret = intersection(drawingRect, clipRect); |
| 264 if (caret.isEmpty()) | 264 if (caret.isEmpty()) |
| 265 return; | 265 return; |
| 266 | 266 |
| 267 Color caretColor = Color::black; | 267 Color caretColor = Color::black; |
| 268 | 268 |
| 269 Element* element; | 269 Element* element; |
| 270 if (node->isElementNode()) | 270 if (node->isElementNode()) |
| 271 element = toElement(node); | 271 element = toElement(node); |
| 272 else | 272 else |
| 273 element = node->parentElement(); | 273 element = node->parentElement(); |
| 274 | 274 |
| 275 if (element && element->layoutObject()) | 275 if (element && element->layoutObject()) |
| 276 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); | 276 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); |
| 277 | 277 |
| 278 context->fillRect(caret, caretColor); | 278 context->fillRect(caret, caretColor); |
| 279 } | 279 } |
| 280 | 280 |
| 281 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 281 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
| 282 { | 282 { |
| 283 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 283 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
| 284 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 284 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
| 285 } | 285 } |
| 286 | 286 |
| 287 } | 287 } |
| OLD | NEW |