OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights
reserved. | 2 * Copyright (C) 2004, 2005, 2006, 2007, 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 #ifndef DragCaretController_h | 26 #ifndef DragCaretController_h |
27 #define DragCaretController_h | 27 #define DragCaretController_h |
28 | 28 |
29 #include "core/CoreExport.h" | 29 #include "core/editing/Caret.h" |
30 #include "core/editing/VisiblePosition.h" | |
31 #include "platform/geometry/IntRect.h" | |
32 #include "platform/geometry/LayoutRect.h" | |
33 #include "wtf/Noncopyable.h" | |
34 | 30 |
35 namespace blink { | 31 namespace blink { |
36 | 32 |
37 class LocalFrame; | |
38 class GraphicsContext; | |
39 class LayoutBlock; | |
40 class LayoutView; | |
41 | |
42 class CORE_EXPORT CaretBase { | |
43 WTF_MAKE_NONCOPYABLE(CaretBase); | |
44 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(CaretBase); | |
45 protected: | |
46 enum CaretVisibility { Visible, Hidden }; | |
47 explicit CaretBase(CaretVisibility = Hidden); | |
48 | |
49 void invalidateCaretRect(Node*, bool caretRectChanged = false); | |
50 void clearCaretRect(); | |
51 // Creating VisiblePosition causes synchronous layout so we should use the | |
52 // PositionWithAffinity version if possible. | |
53 // A position in HTMLTextFromControlElement is a typical example. | |
54 bool updateCaretRect(Document*, const PositionWithAffinity& caretPosition); | |
55 bool updateCaretRect(Document*, const VisiblePosition& caretPosition); | |
56 IntRect absoluteBoundsForLocalRect(Node*, const LayoutRect&) const; | |
57 bool shouldRepaintCaret(Node&) const; | |
58 bool shouldRepaintCaret(const LayoutView*) const; | |
59 void paintCaret(Node*, GraphicsContext*, const LayoutPoint&, const LayoutRec
t& clipRect) const; | |
60 | |
61 const LayoutRect& localCaretRectWithoutUpdate() const { return m_caretLocalR
ect; } | |
62 LayoutBlock* caretPainter() const { return m_caretPainter; } | |
63 | |
64 void setCaretVisibility(CaretVisibility visibility) { m_caretVisibility = vi
sibility; } | |
65 bool caretIsVisible() const { return m_caretVisibility == Visible; } | |
66 CaretVisibility caretVisibility() const { return m_caretVisibility; } | |
67 | |
68 static LayoutBlock* caretLayoutObject(Node*); | |
69 static void invalidateLocalCaretRect(Node*, const LayoutRect&); | |
70 | |
71 private: | |
72 LayoutBlock* m_caretPainter; // layout object responsible for painting the c
aret | |
73 LayoutRect m_caretLocalRect; // caret rect in coords local to the layoutObje
ct responsible for painting the caret | |
74 CaretVisibility m_caretVisibility; | |
75 }; | |
76 | |
77 class DragCaretController final : public NoBaseWillBeGarbageCollected<DragCaretC
ontroller>, private CaretBase { | 33 class DragCaretController final : public NoBaseWillBeGarbageCollected<DragCaretC
ontroller>, private CaretBase { |
78 WTF_MAKE_NONCOPYABLE(DragCaretController); | 34 WTF_MAKE_NONCOPYABLE(DragCaretController); |
79 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(DragCaretController); | 35 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(DragCaretController); |
80 public: | 36 public: |
81 static PassOwnPtrWillBeRawPtr<DragCaretController> create(); | 37 static PassOwnPtrWillBeRawPtr<DragCaretController> create(); |
82 | 38 |
83 LayoutBlock* caretLayoutObject() const { return CaretBase::caretPainter(); } | 39 LayoutBlock* caretLayoutObject() const { return CaretBase::caretPainter(); } |
84 void paintDragCaret(LocalFrame*, GraphicsContext*, const LayoutPoint&, const
LayoutRect& clipRect) const; | 40 void paintDragCaret(LocalFrame*, GraphicsContext*, const LayoutPoint&, const
LayoutRect& clipRect) const; |
85 | 41 |
86 bool isContentEditable() const { return m_position.rootEditableElement(); } | 42 bool isContentEditable() const { return m_position.rootEditableElement(); } |
87 bool isContentRichlyEditable() const; | 43 bool isContentRichlyEditable() const; |
88 | 44 |
89 bool hasCaret() const { return m_position.isNotNull(); } | 45 bool hasCaret() const { return m_position.isNotNull(); } |
90 const VisiblePosition& caretPosition() { return m_position; } | 46 const VisiblePosition& caretPosition() { return m_position; } |
91 void setCaretPosition(const VisiblePosition&); | 47 void setCaretPosition(const VisiblePosition&); |
92 void clear() { setCaretPosition(VisiblePosition()); } | 48 void clear() { setCaretPosition(VisiblePosition()); } |
93 | 49 |
94 void nodeWillBeRemoved(Node&); | 50 void nodeWillBeRemoved(Node&); |
95 | 51 |
96 DECLARE_TRACE(); | 52 DECLARE_TRACE(); |
97 | 53 |
98 private: | 54 private: |
99 DragCaretController(); | 55 DragCaretController(); |
100 | 56 |
101 VisiblePosition m_position; | 57 VisiblePosition m_position; |
102 }; | 58 }; |
103 | 59 |
104 } // namespace blink | 60 } // namespace blink |
105 | 61 |
106 | |
107 #endif // DragCaretController_h | 62 #endif // DragCaretController_h |
OLD | NEW |