| 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 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 66 bool paintedByBlock = layoutObject->isLayoutBlock() && caretRendersInsideNod
e(node); | 66 bool paintedByBlock = layoutObject->isLayoutBlock() && caretRendersInsideNod
e(node); |
| 67 return paintedByBlock ? toLayoutBlock(layoutObject) : layoutObject->containi
ngBlock(); | 67 return paintedByBlock ? toLayoutBlock(layoutObject) : layoutObject->containi
ngBlock(); |
| 68 } | 68 } |
| 69 | 69 |
| 70 static void mapCaretRectToCaretPainter(LayoutItem caretLayoutItem, LayoutBlockIt
em caretPainterItem, LayoutRect& caretRect) | 70 static void mapCaretRectToCaretPainter(LayoutItem caretLayoutItem, LayoutBlockIt
em caretPainterItem, LayoutRect& caretRect) |
| 71 { | 71 { |
| 72 // FIXME: This shouldn't be called on un-rooted subtrees. | 72 // FIXME: This shouldn't be called on un-rooted subtrees. |
| 73 // FIXME: This should probably just use mapLocalToAncestor. | 73 // FIXME: This should probably just use mapLocalToAncestor. |
| 74 // Compute an offset between the caretLayoutItem and the caretPainterItem. | 74 // Compute an offset between the caretLayoutItem and the caretPainterItem. |
| 75 | 75 |
| 76 ASSERT(caretLayoutItem.isDescendantOf(caretPainterItem)); | 76 DCHECK(caretLayoutItem.isDescendantOf(caretPainterItem)); |
| 77 | 77 |
| 78 bool unrooted = false; | 78 bool unrooted = false; |
| 79 while (caretLayoutItem != caretPainterItem) { | 79 while (caretLayoutItem != caretPainterItem) { |
| 80 LayoutItem containerItem = caretLayoutItem.container(); | 80 LayoutItem containerItem = caretLayoutItem.container(); |
| 81 if (containerItem.isNull()) { | 81 if (containerItem.isNull()) { |
| 82 unrooted = true; | 82 unrooted = true; |
| 83 break; | 83 break; |
| 84 } | 84 } |
| 85 caretRect.move(caretLayoutItem.offsetFromContainer(containerItem)); | 85 caretRect.move(caretLayoutItem.offsetFromContainer(containerItem)); |
| 86 caretLayoutItem = containerItem; | 86 caretLayoutItem = containerItem; |
| 87 } | 87 } |
| 88 | 88 |
| 89 if (unrooted) | 89 if (unrooted) |
| 90 caretRect = LayoutRect(); | 90 caretRect = LayoutRect(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 bool CaretBase::updateCaretRect(const PositionWithAffinity& caretPosition) | 93 bool CaretBase::updateCaretRect(const PositionWithAffinity& caretPosition) |
| 94 { | 94 { |
| 95 m_caretLocalRect = LayoutRect(); | 95 m_caretLocalRect = LayoutRect(); |
| 96 | 96 |
| 97 if (caretPosition.position().isNull()) | 97 if (caretPosition.position().isNull()) |
| 98 return false; | 98 return false; |
| 99 | 99 |
| 100 ASSERT(caretPosition.position().anchorNode()->layoutObject()); | 100 DCHECK(caretPosition.position().anchorNode()->layoutObject()); |
| 101 | 101 |
| 102 // First compute a rect local to the layoutObject at the selection start. | 102 // First compute a rect local to the layoutObject at the selection start. |
| 103 LayoutObject* layoutObject; | 103 LayoutObject* layoutObject; |
| 104 m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); | 104 m_caretLocalRect = localCaretRectOfPosition(caretPosition, layoutObject); |
| 105 | 105 |
| 106 // Get the layoutObject that will be responsible for painting the caret | 106 // Get the layoutObject that will be responsible for painting the caret |
| 107 // (which is either the layoutObject we just found, or one of its containers
). | 107 // (which is either the layoutObject we just found, or one of its containers
). |
| 108 LayoutBlockItem caretPainterItem = LayoutBlockItem(caretLayoutObject(caretPo
sition.position().anchorNode())); | 108 LayoutBlockItem caretPainterItem = LayoutBlockItem(caretLayoutObject(caretPo
sition.position().anchorNode())); |
| 109 | 109 |
| 110 mapCaretRectToCaretPainter(LayoutItem(layoutObject), caretPainterItem, m_car
etLocalRect); | 110 mapCaretRectToCaretPainter(LayoutItem(layoutObject), caretPainterItem, m_car
etLocalRect); |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 150 bool CaretBase::shouldRepaintCaret(Node& node) const | 150 bool CaretBase::shouldRepaintCaret(Node& node) const |
| 151 { | 151 { |
| 152 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, | 152 // If PositionAnchorType::BeforeAnchor or PositionAnchorType::AfterAnchor, |
| 153 // carets need to be repainted not only when the node is contentEditable but | 153 // carets need to be repainted not only when the node is contentEditable but |
| 154 // also when its parentNode() is contentEditable. | 154 // also when its parentNode() is contentEditable. |
| 155 return node.isContentEditable() || (node.parentNode() && node.parentNode()->
isContentEditable()); | 155 return node.isContentEditable() || (node.parentNode() && node.parentNode()->
isContentEditable()); |
| 156 } | 156 } |
| 157 | 157 |
| 158 bool CaretBase::shouldRepaintCaret(const LayoutView* view) const | 158 bool CaretBase::shouldRepaintCaret(const LayoutView* view) const |
| 159 { | 159 { |
| 160 ASSERT(view); | 160 DCHECK(view); |
| 161 if (FrameView* frameView = view->frameView()) { | 161 if (FrameView* frameView = view->frameView()) { |
| 162 LocalFrame& frame = frameView->frame(); // The frame where the selection
started | 162 LocalFrame& frame = frameView->frame(); // The frame where the selection
started |
| 163 return frame.settings() && frame.settings()->caretBrowsingEnabled(); | 163 return frame.settings() && frame.settings()->caretBrowsingEnabled(); |
| 164 } | 164 } |
| 165 return false; | 165 return false; |
| 166 } | 166 } |
| 167 | 167 |
| 168 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) | 168 void CaretBase::invalidateCaretRect(Node* node, bool caretRectChanged) |
| 169 { | 169 { |
| 170 if (caretRectChanged) | 170 if (caretRectChanged) |
| (...skipping 23 matching lines...) Expand all Loading... |
| 194 else | 194 else |
| 195 element = node->parentElement(); | 195 element = node->parentElement(); |
| 196 | 196 |
| 197 if (element && element->layoutObject()) | 197 if (element && element->layoutObject()) |
| 198 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); | 198 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); |
| 199 | 199 |
| 200 context.fillRect(FloatRect(drawingRect), caretColor); | 200 context.fillRect(FloatRect(drawingRect), caretColor); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace blink | 203 } // namespace blink |
| OLD | NEW |