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