| 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 |
| 11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
| 12 * | 12 * |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 */ | 24 */ |
| 25 | 25 |
| 26 #include "config.h" | 26 #include "config.h" |
| 27 #include "core/editing/Caret.h" | 27 #include "core/editing/Caret.h" |
| 28 | 28 |
| 29 #include "core/dom/Document.h" | |
| 30 #include "core/editing/VisibleUnits.h" | 29 #include "core/editing/VisibleUnits.h" |
| 31 #include "core/editing/htmlediting.h" | 30 #include "core/editing/htmlediting.h" |
| 32 #include "core/frame/LocalFrame.h" | |
| 33 #include "core/frame/Settings.h" | 31 #include "core/frame/Settings.h" |
| 34 #include "core/html/HTMLTextFormControlElement.h" | |
| 35 #include "core/layout/LayoutBlock.h" | 32 #include "core/layout/LayoutBlock.h" |
| 36 #include "core/layout/LayoutView.h" | 33 #include "core/layout/LayoutView.h" |
| 37 #include "core/paint/DeprecatedPaintLayer.h" | |
| 38 #include "platform/graphics/GraphicsContext.h" | 34 #include "platform/graphics/GraphicsContext.h" |
| 39 | 35 |
| 40 namespace blink { | 36 namespace blink { |
| 41 | 37 |
| 42 CaretBase::CaretBase(CaretVisibility visibility) | 38 CaretBase::CaretBase(CaretVisibility visibility) |
| 43 : m_caretPainter(nullptr) | 39 : m_caretPainter(nullptr) |
| 44 , m_caretVisibility(visibility) | 40 , m_caretVisibility(visibility) |
| 45 { | 41 { |
| 46 } | 42 } |
| 47 | 43 |
| 48 DragCaretController::DragCaretController() | |
| 49 : CaretBase(Visible) | |
| 50 { | |
| 51 } | |
| 52 | |
| 53 PassOwnPtrWillBeRawPtr<DragCaretController> DragCaretController::create() | |
| 54 { | |
| 55 return adoptPtrWillBeNoop(new DragCaretController); | |
| 56 } | |
| 57 | |
| 58 bool DragCaretController::isContentRichlyEditable() const | |
| 59 { | |
| 60 return isRichlyEditablePosition(m_position.deepEquivalent()); | |
| 61 } | |
| 62 | |
| 63 void DragCaretController::setCaretPosition(const VisiblePosition& position) | |
| 64 { | |
| 65 // for querying Layer::compositingState() | |
| 66 // This code is probably correct, since it doesn't occur in a stack that inv
olves updating compositing state. | |
| 67 DisableCompositingQueryAsserts disabler; | |
| 68 | |
| 69 if (Node* node = m_position.deepEquivalent().deprecatedNode()) | |
| 70 invalidateCaretRect(node); | |
| 71 m_position = position; | |
| 72 Document* document = nullptr; | |
| 73 if (Node* node = m_position.deepEquivalent().deprecatedNode()) { | |
| 74 invalidateCaretRect(node); | |
| 75 document = &node->document(); | |
| 76 } | |
| 77 if (m_position.isNull() || m_position.isOrphan()) { | |
| 78 clearCaretRect(); | |
| 79 } else { | |
| 80 document->updateLayoutTreeIfNeeded(); | |
| 81 updateCaretRect(document, m_position); | |
| 82 } | |
| 83 } | |
| 84 | |
| 85 static bool removingNodeRemovesPosition(Node& node, const Position& position) | |
| 86 { | |
| 87 if (!position.anchorNode()) | |
| 88 return false; | |
| 89 | |
| 90 if (position.anchorNode() == node) | |
| 91 return true; | |
| 92 | |
| 93 if (!node.isElementNode()) | |
| 94 return false; | |
| 95 | |
| 96 Element& element = toElement(node); | |
| 97 return element.containsIncludingShadowDOM(position.anchorNode()); | |
| 98 } | |
| 99 | |
| 100 void DragCaretController::nodeWillBeRemoved(Node& node) | |
| 101 { | |
| 102 if (!hasCaret() || !node.inActiveDocument()) | |
| 103 return; | |
| 104 | |
| 105 if (!removingNodeRemovesPosition(node, m_position.deepEquivalent())) | |
| 106 return; | |
| 107 | |
| 108 m_position.deepEquivalent().document()->layoutView()->clearSelection(); | |
| 109 clear(); | |
| 110 } | |
| 111 | |
| 112 DEFINE_TRACE(DragCaretController) | |
| 113 { | |
| 114 visitor->trace(m_position); | |
| 115 } | |
| 116 | |
| 117 void CaretBase::clearCaretRect() | 44 void CaretBase::clearCaretRect() |
| 118 { | 45 { |
| 119 m_caretPainter = nullptr; | 46 m_caretPainter = nullptr; |
| 120 m_caretLocalRect = LayoutRect(); | 47 m_caretLocalRect = LayoutRect(); |
| 121 } | 48 } |
| 122 | 49 |
| 123 static inline bool caretRendersInsideNode(Node* node) | 50 static inline bool caretRendersInsideNode(Node* node) |
| 124 { | 51 { |
| 125 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; | 52 return node && !isRenderedTableElement(node) && !editingIgnoresContent(node)
; |
| 126 } | 53 } |
| (...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 element = toElement(node); | 196 element = toElement(node); |
| 270 else | 197 else |
| 271 element = node->parentElement(); | 198 element = node->parentElement(); |
| 272 | 199 |
| 273 if (element && element->layoutObject()) | 200 if (element && element->layoutObject()) |
| 274 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); | 201 caretColor = element->layoutObject()->resolveColor(CSSPropertyColor); |
| 275 | 202 |
| 276 context->fillRect(caret, caretColor); | 203 context->fillRect(caret, caretColor); |
| 277 } | 204 } |
| 278 | 205 |
| 279 void DragCaretController::paintDragCaret(LocalFrame* frame, GraphicsContext* p,
const LayoutPoint& paintOffset, const LayoutRect& clipRect) const | 206 } // namespace blink |
| 280 { | |
| 281 if (m_position.deepEquivalent().deprecatedNode()->document().frame() == fram
e) | |
| 282 paintCaret(m_position.deepEquivalent().deprecatedNode(), p, paintOffset,
clipRect); | |
| 283 } | |
| 284 | |
| 285 } | |
| OLD | NEW |