| 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 21 matching lines...) Expand all Loading... |
| 32 | 32 |
| 33 namespace blink { | 33 namespace blink { |
| 34 | 34 |
| 35 DragCaretController::DragCaretController() : m_caretBase(new CaretBase()) {} | 35 DragCaretController::DragCaretController() : m_caretBase(new CaretBase()) {} |
| 36 | 36 |
| 37 DragCaretController* DragCaretController::create() { | 37 DragCaretController* DragCaretController::create() { |
| 38 return new DragCaretController; | 38 return new DragCaretController; |
| 39 } | 39 } |
| 40 | 40 |
| 41 bool DragCaretController::hasCaretIn(const LayoutBlock& layoutBlock) const { | 41 bool DragCaretController::hasCaretIn(const LayoutBlock& layoutBlock) const { |
| 42 Node* node = m_position.deepEquivalent().anchorNode(); | 42 Node* node = m_position.position().anchorNode(); |
| 43 if (!node) | 43 if (!node) |
| 44 return false; | 44 return false; |
| 45 if (layoutBlock != CaretBase::caretLayoutObject(node)) | 45 if (layoutBlock != CaretBase::caretLayoutObject(node)) |
| 46 return false; | 46 return false; |
| 47 if (rootEditableElementOf(m_position)) | 47 if (rootEditableElementOf(m_position.position())) |
| 48 return true; | 48 return true; |
| 49 Settings* settings = node->ownerDocument()->frame()->settings(); | 49 Settings* settings = node->ownerDocument()->frame()->settings(); |
| 50 return settings && settings->caretBrowsingEnabled(); | 50 return settings && settings->caretBrowsingEnabled(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 bool DragCaretController::isContentRichlyEditable() const { | 53 bool DragCaretController::isContentRichlyEditable() const { |
| 54 return isRichlyEditablePosition(m_position.deepEquivalent()); | 54 return isRichlyEditablePosition(m_position.position()); |
| 55 } | 55 } |
| 56 | 56 |
| 57 void DragCaretController::setCaretPosition( | 57 void DragCaretController::setCaretPosition( |
| 58 const PositionWithAffinity& position) { | 58 const PositionWithAffinity& position) { |
| 59 // for querying Layer::compositingState() | 59 // for querying Layer::compositingState() |
| 60 // This code is probably correct, since it doesn't occur in a stack that | 60 // This code is probably correct, since it doesn't occur in a stack that |
| 61 // involves updating compositing state. | 61 // involves updating compositing state. |
| 62 DisableCompositingQueryAsserts disabler; | 62 DisableCompositingQueryAsserts disabler; |
| 63 | 63 |
| 64 if (Node* node = m_position.deepEquivalent().anchorNode()) | 64 if (Node* node = m_position.position().anchorNode()) |
| 65 m_caretBase->invalidateCaretRect(node); | 65 m_caretBase->invalidateCaretRect(node); |
| 66 m_position = createVisiblePosition(position); | 66 m_position = createVisiblePosition(position).toPositionWithAffinity(); |
| 67 Document* document = nullptr; | 67 Document* document = nullptr; |
| 68 if (Node* node = m_position.deepEquivalent().anchorNode()) { | 68 if (Node* node = m_position.position().anchorNode()) { |
| 69 m_caretBase->invalidateCaretRect(node); | 69 m_caretBase->invalidateCaretRect(node); |
| 70 document = &node->document(); | 70 document = &node->document(); |
| 71 } | 71 } |
| 72 if (m_position.isNull() || m_position.isOrphan()) { | 72 if (m_position.isNull()) { |
| 73 m_caretBase->clearCaretRect(); | 73 m_caretBase->clearCaretRect(); |
| 74 } else { | 74 } else { |
| 75 DCHECK(!m_position.position().isOrphan()); |
| 75 document->updateStyleAndLayoutTree(); | 76 document->updateStyleAndLayoutTree(); |
| 76 m_caretBase->updateCaretRect(m_position); | 77 m_caretBase->updateCaretRect(m_position); |
| 77 } | 78 } |
| 78 } | 79 } |
| 79 | 80 |
| 80 static bool removingNodeRemovesPosition(Node& node, const Position& position) { | 81 static bool removingNodeRemovesPosition(Node& node, const Position& position) { |
| 81 if (!position.anchorNode()) | 82 if (!position.anchorNode()) |
| 82 return false; | 83 return false; |
| 83 | 84 |
| 84 if (position.anchorNode() == node) | 85 if (position.anchorNode() == node) |
| 85 return true; | 86 return true; |
| 86 | 87 |
| 87 if (!node.isElementNode()) | 88 if (!node.isElementNode()) |
| 88 return false; | 89 return false; |
| 89 | 90 |
| 90 Element& element = toElement(node); | 91 Element& element = toElement(node); |
| 91 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode()); | 92 return element.isShadowIncludingInclusiveAncestorOf(position.anchorNode()); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void DragCaretController::nodeWillBeRemoved(Node& node) { | 95 void DragCaretController::nodeWillBeRemoved(Node& node) { |
| 95 if (!hasCaret() || !node.inActiveDocument()) | 96 if (!hasCaret() || !node.inActiveDocument()) |
| 96 return; | 97 return; |
| 97 | 98 |
| 98 if (!removingNodeRemovesPosition(node, m_position.deepEquivalent())) | 99 if (!removingNodeRemovesPosition(node, m_position.position())) |
| 99 return; | 100 return; |
| 100 | 101 |
| 101 m_position.deepEquivalent().document()->layoutViewItem().clearSelection(); | 102 m_position.position().document()->layoutViewItem().clearSelection(); |
| 102 clear(); | 103 clear(); |
| 103 } | 104 } |
| 104 | 105 |
| 105 DEFINE_TRACE(DragCaretController) { | 106 DEFINE_TRACE(DragCaretController) { |
| 106 visitor->trace(m_position); | 107 visitor->trace(m_position); |
| 107 visitor->trace(m_caretBase); | 108 visitor->trace(m_caretBase); |
| 108 } | 109 } |
| 109 | 110 |
| 110 void DragCaretController::paintDragCaret(LocalFrame* frame, | 111 void DragCaretController::paintDragCaret(LocalFrame* frame, |
| 111 GraphicsContext& context, | 112 GraphicsContext& context, |
| 112 const LayoutPoint& paintOffset) const { | 113 const LayoutPoint& paintOffset) const { |
| 113 if (m_position.deepEquivalent().anchorNode()->document().frame() == frame) | 114 if (m_position.position().anchorNode()->document().frame() == frame) |
| 114 m_caretBase->paintCaret(m_position.deepEquivalent().anchorNode(), context, | 115 m_caretBase->paintCaret(m_position.position().anchorNode(), context, |
| 115 paintOffset, DisplayItem::kDragCaret); | 116 paintOffset, DisplayItem::kDragCaret); |
| 116 } | 117 } |
| 117 | 118 |
| 118 } // namespace blink | 119 } // namespace blink |
| OLD | NEW |