| 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 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 return adoptPtr(new DragCaretController); | 54 return adoptPtr(new DragCaretController); |
| 55 } | 55 } |
| 56 | 56 |
| 57 bool DragCaretController::isContentRichlyEditable() const | 57 bool DragCaretController::isContentRichlyEditable() const |
| 58 { | 58 { |
| 59 return isRichlyEditablePosition(m_position.deepEquivalent()); | 59 return isRichlyEditablePosition(m_position.deepEquivalent()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void DragCaretController::setCaretPosition(const VisiblePosition& position) | 62 void DragCaretController::setCaretPosition(const VisiblePosition& position) |
| 63 { | 63 { |
| 64 if (Node* node = m_position.deepEquivalent().deprecatedNode()) | |
| 65 invalidateCaretRect(node); | |
| 66 m_position = position; | 64 m_position = position; |
| 67 setCaretRectNeedsUpdate(); | 65 setCaretRectNeedsUpdate(); |
| 68 Document* document = 0; | 66 Document* document = 0; |
| 69 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { | 67 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { |
| 70 invalidateCaretRect(node); | |
| 71 document = &node->document(); | 68 document = &node->document(); |
| 72 } | 69 } |
| 73 if (m_position.isNull() || m_position.isOrphan()) { | 70 if (m_position.isNull() || m_position.isOrphan()) { |
| 74 clearCaretRect(); | 71 clearCaretRect(); |
| 75 } else { | 72 } else { |
| 76 document->updateRenderTreeIfNeeded(); | 73 document->updateRenderTreeIfNeeded(); |
| 77 updateCaretRect(document, m_position); | 74 updateCaretRect(document, m_position); |
| 78 } | 75 } |
| 79 } | 76 } |
| 80 | 77 |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 177 } | 174 } |
| 178 | 175 |
| 179 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const | 176 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const |
| 180 { | 177 { |
| 181 RenderBlock* caretPainter = caretRenderer(node); | 178 RenderBlock* caretPainter = caretRenderer(node); |
| 182 if (!caretPainter) | 179 if (!caretPainter) |
| 183 return IntRect(); | 180 return IntRect(); |
| 184 return caretPainter->localToAbsoluteQuad(FloatRect(rect)).enclosingBoundingB
ox(); | 181 return caretPainter->localToAbsoluteQuad(FloatRect(rect)).enclosingBoundingB
ox(); |
| 185 } | 182 } |
| 186 | 183 |
| 187 void CaretBase::invalidateLocalCaretRect(Node* node, const LayoutRect& rect) | |
| 188 { | |
| 189 RenderBlock* caretPainter = caretRenderer(node); | |
| 190 if (!caretPainter) | |
| 191 return; | |
| 192 | |
| 193 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | |
| 194 // https://bugs.webkit.org/show_bug.cgi?id=108283 | |
| 195 LayoutRect inflatedRect = rect; | |
| 196 inflatedRect.inflate(1); | |
| 197 | |
| 198 caretPainter->invalidatePaintRectangle(inflatedRect); | |
| 199 } | |
| 200 | |
| 201 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) | |
| 202 { | |
| 203 // EDIT FIXME: This is an unfortunate hack. | |
| 204 // Basically, we can't trust this layout position since we | |
| 205 // can't guarantee that the check to see if we are in unrendered | |
| 206 // content will work at this point. We may have to wait for | |
| 207 // a layout and re-render of the document to happen. So, resetting this | |
| 208 // flag will cause another caret layout to happen the first time | |
| 209 // that we try to paint the caret after this call. That one will work since | |
| 210 // it happens after the document has accounted for any editing | |
| 211 // changes which may have been done. | |
| 212 // And, we need to leave this layout here so the caret moves right | |
| 213 // away after clicking. | |
| 214 m_caretRectNeedsUpdate = true; | |
| 215 | |
| 216 if (caretRectChanged) | |
| 217 return; | |
| 218 | |
| 219 if (node->isContentEditable(Node::UserSelectAllIsAlwaysNonEditable)) | |
| 220 invalidateLocalCaretRect(node, localCaretRectWithoutUpdate()); | |
| 221 } | |
| 222 | |
| 223 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const | 184 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const |
| 224 { | 185 { |
| 225 if (m_caretVisibility == Hidden) | 186 if (m_caretVisibility == Hidden) |
| 226 return; | 187 return; |
| 227 | 188 |
| 228 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 189 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 229 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 190 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
| 230 LayoutRect caret = intersection(drawingRect, clipRect); | 191 LayoutRect caret = intersection(drawingRect, clipRect); |
| 231 if (caret.isEmpty()) | 192 if (caret.isEmpty()) |
| 232 return; | 193 return; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 245 context->fillRect(caret, caretColor); | 206 context->fillRect(caret, caretColor); |
| 246 } | 207 } |
| 247 | 208 |
| 248 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 209 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
| 249 { | 210 { |
| 250 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 211 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
| 251 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 212 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
| 252 } | 213 } |
| 253 | 214 |
| 254 } | 215 } |
| OLD | NEW |