2
* Copyright (C) 2004 Apple Computer, 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 SelectionController_h
27
#define SelectionController_h
30
#include "Selection.h"
32
#include <wtf/Noncopyable.h>
37
class GraphicsContext;
39
class VisiblePosition;
41
class SelectionController : Noncopyable {
43
enum EAlteration { MOVE, EXTEND };
44
enum EDirection { FORWARD, BACKWARD, RIGHT, LEFT };
46
SelectionController(Frame* = 0, bool isDragCaretController = false);
48
Element* rootEditableElement() const { return m_sel.rootEditableElement(); }
49
bool isContentEditable() const { return m_sel.isContentEditable(); }
50
bool isContentRichlyEditable() const { return m_sel.isContentRichlyEditable(); }
52
void moveTo(const Range*, EAffinity, bool userTriggered = false);
53
void moveTo(const VisiblePosition&, bool userTriggered = false);
54
void moveTo(const VisiblePosition&, const VisiblePosition&, bool userTriggered = false);
55
void moveTo(const Position&, EAffinity, bool userTriggered = false);
56
void moveTo(const Position&, const Position&, EAffinity, bool userTriggered = false);
58
const Selection& selection() const { return m_sel; }
59
void setSelection(const Selection&, bool closeTyping = true, bool clearTypingStyle = true, bool userTriggered = false);
60
void setSelectedRange(Range*, EAffinity, bool closeTyping, ExceptionCode&);
64
// Call this after doing user-triggered selections to make it easy to delete the frame you entirely selected.
65
void selectFrameElementInParentIfFullySelected();
67
bool contains(const IntPoint&);
69
Selection::EState state() const { return m_sel.state(); }
71
EAffinity affinity() const { return m_sel.affinity(); }
73
bool modify(EAlteration, EDirection, TextGranularity, bool userTriggered = false);
74
bool modify(EAlteration, int verticalDistance, bool userTriggered = false);
75
bool expandUsingGranularity(TextGranularity);
77
void setBase(const VisiblePosition&, bool userTriggered = false);
78
void setBase(const Position&, EAffinity, bool userTriggered = false);
79
void setExtent(const VisiblePosition&, bool userTriggered = false);
80
void setExtent(const Position&, EAffinity, bool userTriggered = false);
82
Position base() const { return m_sel.base(); }
83
Position extent() const { return m_sel.extent(); }
84
Position start() const { return m_sel.start(); }
85
Position end() const { return m_sel.end(); }
87
IntRect caretRect() const;
88
void setNeedsLayout(bool flag = true);
90
void setLastChangeWasHorizontalExtension(bool b) { m_lastChangeWasHorizontalExtension = b; }
91
void willBeModified(EAlteration, EDirection);
93
bool isNone() const { return m_sel.isNone(); }
94
bool isCaret() const { return m_sel.isCaret(); }
95
bool isRange() const { return m_sel.isRange(); }
96
bool isCaretOrRange() const { return m_sel.isCaretOrRange(); }
97
bool isInPasswordField() const;
98
bool isInsideNode() const;
100
PassRefPtr<Range> toRange() const { return m_sel.toRange(); }
102
void debugRenderer(RenderObject*, bool selected) const;
104
void nodeWillBeRemoved(Node*);
106
// Safari Selection Object API
107
// These methods return the valid equivalents of internal editing positions.
108
Node* baseNode() const;
109
Node* extentNode() const;
110
int baseOffset() const;
111
int extentOffset() const;
113
void setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode&);
114
void setPosition(Node*, int offset, ExceptionCode&);
115
bool modify(const String& alterString, const String& directionString, const String& granularityString, bool userTriggered = false);
117
// Mozilla Selection Object API
118
// In FireFox, anchor/focus are the equal to the start/end of the selection,
119
// but reflect the direction in which the selection was made by the user. That does
120
// not mean that they are base/extent, since the base/extent don't reflect
122
// These methods return the valid equivalents of internal editing positions.
123
Node* anchorNode() const;
124
int anchorOffset() const;
125
Node* focusNode() const;
126
int focusOffset() const;
127
bool isCollapsed() const { return !isRange(); }
128
String toString() const;
129
void collapse(Node*, int offset, ExceptionCode&);
130
void collapseToEnd();
131
void collapseToStart();
132
void extend(Node*, int offset, ExceptionCode&);
133
PassRefPtr<Range> getRangeAt(int index, ExceptionCode&) const;
134
int rangeCount() const { return !isNone() ? 1 : 0; }
135
void removeAllRanges();
136
void addRange(const Range*);
137
//void deleteFromDocument();
138
//bool containsNode(Node *node, bool entirelyContained);
139
//void selectAllChildren(const Node *);
140
//void removeRange(const Range *);
142
// Microsoft Selection Object API
145
//TextRange *createRange();
147
bool recomputeCaretRect(); // returns true if caret rect moved
148
void invalidateCaretRect();
149
void paintCaret(GraphicsContext*, const IntRect&);
151
// Used to suspend caret blinking while the mouse is down.
152
void setCaretBlinkingSuspended(bool suspended) { m_isCaretBlinkingSuspended = suspended; }
153
bool isCaretBlinkingSuspended() const { return m_isCaretBlinkingSuspended; }
156
void formatForDebugger(char* buffer, unsigned length) const;
157
void showTreeForThis() const;
161
enum EPositionType { START, END, BASE, EXTENT };
163
VisiblePosition modifyExtendingRightForward(TextGranularity);
164
VisiblePosition modifyMovingRightForward(TextGranularity);
165
VisiblePosition modifyExtendingLeftBackward(TextGranularity);
166
VisiblePosition modifyMovingLeftBackward(TextGranularity);
169
IntRect caretRepaintRect() const;
171
int xPosForVerticalArrowNavigation(EPositionType);
174
void notifyAccessibilityForSelectionChange();
176
void notifyAccessibilityForSelectionChange() {};
181
IntRect m_caretRect; // caret coordinates, size, and position
183
// m_caretPositionOnLayout stores the scroll offset on the previous call to SelectionController::layout().
184
// When asked for caretRect(), we correct m_caretRect for offset due to scrolling since the last layout().
185
// This is faster than doing another layout().
186
IntPoint m_caretPositionOnLayout;
188
bool m_needsLayout : 1; // true if the caret and expectedVisible rectangles need to be calculated
189
bool m_lastChangeWasHorizontalExtension : 1;
191
bool m_isDragCaretController;
193
bool m_isCaretBlinkingSuspended;
195
int m_xPosForVerticalArrowNavigation;
198
inline bool operator==(const SelectionController& a, const SelectionController& b)
200
return a.start() == b.start() && a.end() == b.end() && a.affinity() == b.affinity();
203
inline bool operator!=(const SelectionController& a, const SelectionController& b)
208
} // namespace WebCore
211
// Outside the WebCore namespace for ease of invocation from gdb.
212
void showTree(const WebCore::SelectionController&);
213
void showTree(const WebCore::SelectionController*);
216
#endif // SelectionController_h