2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
26 #ifndef SelectionEditor_h
27 #define SelectionEditor_h
29 #include "core/editing/FrameSelection.h"
33 class SelectionEditor final
: public NoBaseWillBeGarbageCollectedFinalized
<SelectionEditor
>, public VisibleSelectionChangeObserver
{
34 WTF_MAKE_NONCOPYABLE(SelectionEditor
);
35 WTF_MAKE_FAST_ALLOCATED_WILL_BE_REMOVED(SelectionEditor
);
36 WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(SelectionEditor
);
38 // TODO(yosin) We should move |EAlteration| and |VerticalDirection| out
39 // from |FrameSelection| class like |EUserTriggered|.
40 typedef FrameSelection::EAlteration EAlteration
;
41 typedef FrameSelection::VerticalDirection VerticalDirection
;
43 static PassOwnPtrWillBeRawPtr
<SelectionEditor
> create(FrameSelection
& frameSelection
)
45 return adoptPtrWillBeNoop(new SelectionEditor(frameSelection
));
47 virtual ~SelectionEditor();
49 bool hasEditableStyle() const { return m_selection
.hasEditableStyle(); }
50 bool isContentEditable() const { return m_selection
.isContentEditable(); }
51 bool isContentRichlyEditable() const { return m_selection
.isContentRichlyEditable(); }
53 bool setSelectedRange(const EphemeralRange
&, TextAffinity
, SelectionDirectionalMode
, FrameSelection::SetSelectionOptions
);
55 bool modify(EAlteration
, SelectionDirection
, TextGranularity
, EUserTriggered
);
56 bool modify(EAlteration
, unsigned verticalDistance
, VerticalDirection
, EUserTriggered
, CursorAlignOnScroll
);
58 const VisibleSelection
& visibleSelection() const { return m_selection
; }
59 void setVisibleSelection(const VisibleSelection
& selection
) { m_selection
= selection
; }
61 void setIsDirectional(bool);
62 void setWithoutValidation(const Position
& start
, const Position
& end
);
64 void resetXPosForVerticalArrowNavigation();
66 void willBeModified(EAlteration
, SelectionDirection
);
68 // If this FrameSelection has a logical range which is still valid, this
69 // function return its clone. Otherwise, the return value from underlying
70 // |VisibleSelection|'s |firstRange()| is returned.
71 PassRefPtrWillBeRawPtr
<Range
> firstRange() const;
73 // VisibleSelectionChangeObserver interface.
74 void didChangeVisibleSelection() override
;
76 DECLARE_VIRTUAL_TRACE();
79 explicit SelectionEditor(FrameSelection
&);
81 // TODO(yosin) We should use capitalized name for |EPositionType|.
82 enum EPositionType
{ START
, END
, BASE
, EXTENT
}; // NOLINT
84 LocalFrame
* frame() const;
86 TextDirection
directionOfEnclosingBlock();
87 TextDirection
directionOfSelection();
89 VisiblePosition
positionForPlatform(bool isGetStart
) const;
90 VisiblePosition
startForPlatform() const;
91 VisiblePosition
endForPlatform() const;
92 VisiblePosition
nextWordPositionForPlatform(const VisiblePosition
&);
94 VisiblePosition
modifyExtendingRight(TextGranularity
);
95 VisiblePosition
modifyExtendingForward(TextGranularity
);
96 VisiblePosition
modifyMovingRight(TextGranularity
);
97 VisiblePosition
modifyMovingForward(TextGranularity
);
98 VisiblePosition
modifyExtendingLeft(TextGranularity
);
99 VisiblePosition
modifyExtendingBackward(TextGranularity
);
100 VisiblePosition
modifyMovingLeft(TextGranularity
);
101 VisiblePosition
modifyMovingBackward(TextGranularity
);
103 void startObservingVisibleSelectionChange();
104 void stopObservingVisibleSelectionChangeIfNecessary();
106 LayoutUnit
lineDirectionPointForBlockDirectionNavigation(EPositionType
);
107 bool dispatchSelectStart();
109 RawPtrWillBeMember
<FrameSelection
> m_frameSelection
;
111 LayoutUnit m_xPosForVerticalArrowNavigation
;
112 VisibleSelection m_selection
;
113 bool m_observingVisibleSelection
;
115 // The range specified by the user, which may not be visually canonicalized
116 // (hence "logical"). This will be invalidated if the underlying
117 // |VisibleSelection| changes. If that happens, this variable will
118 // become |nullptr|, in which case logical positions == visible positions.
119 RefPtrWillBeMember
<Range
> m_logicalRange
;
124 #endif // SelectionEditor_h