| 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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 void CaretBase::clearCaretRect() | 109 void CaretBase::clearCaretRect() |
| 110 { | 110 { |
| 111 m_caretLocalRect = LayoutRect(); | 111 m_caretLocalRect = LayoutRect(); |
| 112 } | 112 } |
| 113 | 113 |
| 114 static inline bool caretRendersInsideNode(Node* node) | 114 static inline bool caretRendersInsideNode(Node* node) |
| 115 { | 115 { |
| 116 return node && !isRenderedTable(node) && !editingIgnoresContent(node); | 116 return node && !isRenderedTable(node) && !editingIgnoresContent(node); |
| 117 } | 117 } |
| 118 | 118 |
| 119 RenderObject* CaretBase::caretRenderer(Node* node) | 119 RenderBlock* CaretBase::caretRenderer(Node* node) |
| 120 { | 120 { |
| 121 if (!node) | 121 if (!node) |
| 122 return 0; | 122 return 0; |
| 123 | 123 |
| 124 RenderObject* renderer = node->renderer(); | 124 RenderObject* renderer = node->renderer(); |
| 125 if (!renderer) | 125 if (!renderer) |
| 126 return 0; | 126 return 0; |
| 127 | 127 |
| 128 // if caretNode is a block and caret is inside it then caret should be paint
ed by that block | 128 // 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); | 129 bool paintedByBlock = renderer->isRenderBlock() && caretRendersInsideNode(no
de); |
| 130 return paintedByBlock ? renderer : renderer->containingBlock(); | 130 return paintedByBlock ? toRenderBlock(renderer) : renderer->containingBlock(
); |
| 131 } | 131 } |
| 132 | 132 |
| 133 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) | 133 bool CaretBase::updateCaretRect(Document* document, const VisiblePosition& caret
Position) |
| 134 { | 134 { |
| 135 document->updateRenderTreeIfNeeded(); | 135 document->updateRenderTreeIfNeeded(); |
| 136 m_caretLocalRect = LayoutRect(); | 136 m_caretLocalRect = LayoutRect(); |
| 137 | 137 |
| 138 m_caretRectNeedsUpdate = false; | 138 m_caretRectNeedsUpdate = false; |
| 139 | 139 |
| 140 if (caretPosition.isNull()) | 140 if (caretPosition.isNull()) |
| 141 return false; | 141 return false; |
| 142 | 142 |
| 143 ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer()); | 143 ASSERT(caretPosition.deepEquivalent().deprecatedNode()->renderer()); |
| 144 | 144 |
| 145 // First compute a rect local to the renderer at the selection start. | 145 // First compute a rect local to the renderer at the selection start. |
| 146 RenderObject* renderer; | 146 RenderObject* renderer; |
| 147 LayoutRect localRect = caretPosition.localCaretRect(renderer); | 147 LayoutRect localRect = caretPosition.localCaretRect(renderer); |
| 148 | 148 |
| 149 // Get the renderer that will be responsible for painting the caret | 149 // 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). | 150 // (which is either the renderer we just found, or one of its containers). |
| 151 RenderObject* caretPainter = caretRenderer(caretPosition.deepEquivalent().de
precatedNode()); | 151 RenderBlock* caretPainter = caretRenderer(caretPosition.deepEquivalent().dep
recatedNode()); |
| 152 | 152 |
| 153 // Compute an offset between the renderer and the caretPainter. | 153 // Compute an offset between the renderer and the caretPainter. |
| 154 bool unrooted = false; | 154 bool unrooted = false; |
| 155 while (renderer != caretPainter) { | 155 while (renderer != caretPainter) { |
| 156 RenderObject* containerObject = renderer->container(); | 156 RenderObject* containerObject = renderer->container(); |
| 157 if (!containerObject) { | 157 if (!containerObject) { |
| 158 unrooted = true; | 158 unrooted = true; |
| 159 break; | 159 break; |
| 160 } | 160 } |
| 161 localRect.move(renderer->offsetFromContainer(containerObject, localRect.
location())); | 161 localRect.move(renderer->offsetFromContainer(containerObject, localRect.
location())); |
| 162 renderer = containerObject; | 162 renderer = containerObject; |
| 163 } | 163 } |
| 164 | 164 |
| 165 if (!unrooted) | 165 if (!unrooted) |
| 166 m_caretLocalRect = localRect; | 166 m_caretLocalRect = localRect; |
| 167 | 167 |
| 168 return true; | 168 return true; |
| 169 } | 169 } |
| 170 | 170 |
| 171 RenderObject* DragCaretController::caretRenderer() const | 171 RenderBlock* DragCaretController::caretRenderer() const |
| 172 { | 172 { |
| 173 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode()
); | 173 return CaretBase::caretRenderer(m_position.deepEquivalent().deprecatedNode()
); |
| 174 } | 174 } |
| 175 | 175 |
| 176 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const | 176 IntRect CaretBase::absoluteBoundsForLocalRect(Node* node, const LayoutRect& rect
) const |
| 177 { | 177 { |
| 178 RenderObject* caretPainter = caretRenderer(node); | 178 RenderBlock* caretPainter = caretRenderer(node); |
| 179 if (!caretPainter) | 179 if (!caretPainter) |
| 180 return IntRect(); | 180 return IntRect(); |
| 181 | 181 |
| 182 LayoutRect localRect(rect); | 182 LayoutRect localRect(rect); |
| 183 if (caretPainter->isBox()) | 183 caretPainter->flipForWritingMode(localRect); |
| 184 toRenderBox(caretPainter)->flipForWritingMode(localRect); | |
| 185 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); | 184 return caretPainter->localToAbsoluteQuad(FloatRect(localRect)).enclosingBoun
dingBox(); |
| 186 } | 185 } |
| 187 | 186 |
| 188 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) | 187 void CaretBase::repaintCaretForLocalRect(Node* node, const LayoutRect& rect) |
| 189 { | 188 { |
| 190 RenderObject* caretPainter = caretRenderer(node); | 189 RenderBlock* caretPainter = caretRenderer(node); |
| 191 if (!caretPainter) | 190 if (!caretPainter) |
| 192 return; | 191 return; |
| 193 | 192 |
| 194 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. | 193 // FIXME: Need to over-paint 1 pixel to workaround some rounding problems. |
| 195 // https://bugs.webkit.org/show_bug.cgi?id=108283 | 194 // https://bugs.webkit.org/show_bug.cgi?id=108283 |
| 196 LayoutRect inflatedRect = rect; | 195 LayoutRect inflatedRect = rect; |
| 197 inflatedRect.inflate(1); | 196 inflatedRect.inflate(1); |
| 198 | 197 |
| 199 caretPainter->invalidatePaintRectangle(inflatedRect); | 198 caretPainter->invalidatePaintRectangle(inflatedRect); |
| 200 } | 199 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 233 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); | 232 repaintCaretForLocalRect(node, localCaretRectWithoutUpdate()); |
| 234 } | 233 } |
| 235 } | 234 } |
| 236 | 235 |
| 237 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const | 236 void CaretBase::paintCaret(Node* node, GraphicsContext* context, const LayoutPoi
nt& paintOffset, const LayoutRect& clipRect) const |
| 238 { | 237 { |
| 239 if (m_caretVisibility == Hidden) | 238 if (m_caretVisibility == Hidden) |
| 240 return; | 239 return; |
| 241 | 240 |
| 242 LayoutRect drawingRect = localCaretRectWithoutUpdate(); | 241 LayoutRect drawingRect = localCaretRectWithoutUpdate(); |
| 243 RenderObject* renderer = caretRenderer(node); | 242 if (RenderBlock* renderer = caretRenderer(node)) |
| 244 if (renderer && renderer->isBox()) | 243 renderer->flipForWritingMode(drawingRect); |
| 245 toRenderBox(renderer)->flipForWritingMode(drawingRect); | |
| 246 drawingRect.moveBy(roundedIntPoint(paintOffset)); | 244 drawingRect.moveBy(roundedIntPoint(paintOffset)); |
| 247 LayoutRect caret = intersection(drawingRect, clipRect); | 245 LayoutRect caret = intersection(drawingRect, clipRect); |
| 248 if (caret.isEmpty()) | 246 if (caret.isEmpty()) |
| 249 return; | 247 return; |
| 250 | 248 |
| 251 Color caretColor = Color::black; | 249 Color caretColor = Color::black; |
| 252 | 250 |
| 253 Element* element; | 251 Element* element; |
| 254 if (node->isElementNode()) | 252 if (node->isElementNode()) |
| 255 element = toElement(node); | 253 element = toElement(node); |
| 256 else | 254 else |
| 257 element = node->parentElement(); | 255 element = node->parentElement(); |
| 258 | 256 |
| 259 if (element && element->renderer()) | 257 if (element && element->renderer()) |
| 260 caretColor = element->renderer()->resolveColor(CSSPropertyColor); | 258 caretColor = element->renderer()->resolveColor(CSSPropertyColor); |
| 261 | 259 |
| 262 context->fillRect(caret, caretColor); | 260 context->fillRect(caret, caretColor); |
| 263 } | 261 } |
| 264 | 262 |
| 265 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 263 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const |
| 266 { | 264 { |
| 267 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | 265 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) |
| 268 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | 266 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); |
| 269 } | 267 } |
| 270 | 268 |
| 271 } | 269 } |
| OLD | NEW |