| 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::caretRenderer(Node* node) | 126 LayoutBlock* CaretBase::caretRenderer(Node* node) |
| 127 { | 127 { |
| 128 if (!node) | 128 if (!node) |
| 129 return 0; | 129 return 0; |
| 130 | 130 |
| 131 LayoutObject* renderer = node->renderer(); | 131 LayoutObject* renderer = node->layoutObject(); |
| 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->isLayoutBlock() && caretRendersInsideNode(no
de); | 136 bool paintedByBlock = renderer->isLayoutBlock() && caretRendersInsideNode(no
de); |
| 137 return paintedByBlock ? toLayoutBlock(renderer) : renderer->containingBlock(
); | 137 return paintedByBlock ? toLayoutBlock(renderer) : renderer->containingBlock(
); |
| 138 } | 138 } |
| 139 | 139 |
| 140 static void mapCaretRectToCaretPainter(LayoutObject* caretRenderer, LayoutBlock*
caretPainter, LayoutRect& caretRect) | 140 static void mapCaretRectToCaretPainter(LayoutObject* caretRenderer, LayoutBlock*
caretPainter, LayoutRect& caretRect) |
| 141 { | 141 { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 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()->layoutObject()); |
| 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 LayoutObject* 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 LayoutBlock* caretPainter = caretRenderer(caretPosition.position().deprecate
dNode()); | 178 LayoutBlock* caretPainter = caretRenderer(caretPosition.position().deprecate
dNode()); |
| 179 | 179 |
| 180 mapCaretRectToCaretPainter(renderer, caretPainter, m_caretLocalRect); | 180 mapCaretRectToCaretPainter(renderer, caretPainter, m_caretLocalRect); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 208 LayoutBlock* caretPainter = caretRenderer(node); | 208 LayoutBlock* caretPainter = caretRenderer(node); |
| 209 if (!caretPainter) | 209 if (!caretPainter) |
| 210 return; | 210 return; |
| 211 | 211 |
| 212 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | 212 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
| 213 // https://bugs.webkit.org/show_bug.cgi?id=108283 | 213 // https://bugs.webkit.org/show_bug.cgi?id=108283 |
| 214 LayoutRect inflatedRect = rect; | 214 LayoutRect inflatedRect = rect; |
| 215 inflatedRect.inflate(1); | 215 inflatedRect.inflate(1); |
| 216 | 216 |
| 217 // FIXME: We should use mapLocalToContainer() since we know we're not un-roo
ted. | 217 // FIXME: We should use mapLocalToContainer() since we know we're not un-roo
ted. |
| 218 mapCaretRectToCaretPainter(node->renderer(), caretPainter, inflatedRect); | 218 mapCaretRectToCaretPainter(node->layoutObject(), caretPainter, inflatedRect)
; |
| 219 | 219 |
| 220 // FIXME: We should not allow paint invalidation out of paint invalidation s
tate. crbug.com/457415 | 220 // FIXME: We should not allow paint invalidation out of paint invalidation s
tate. crbug.com/457415 |
| 221 DisablePaintInvalidationStateAsserts disabler; | 221 DisablePaintInvalidationStateAsserts disabler; |
| 222 caretPainter->invalidatePaintRectangle(inflatedRect); | 222 caretPainter->invalidatePaintRectangle(inflatedRect); |
| 223 } | 223 } |
| 224 | 224 |
| 225 bool CaretBase::shouldRepaintCaret(Node& node) const | 225 bool CaretBase::shouldRepaintCaret(Node& node) const |
| 226 { | 226 { |
| 227 // If PositionIsBeforeAnchor or PositionIsAfterAnchor, carets need to be | 227 // If PositionIsBeforeAnchor or PositionIsAfterAnchor, carets need to be |
| 228 // repainted not only when the node is contentEditable but also when its | 228 // repainted not only when the node is contentEditable but also when its |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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->renderer()) | 275 if (element && element->layoutObject()) |
| 276 caretColor = element->renderer()->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 |