70
const VisibleSelection& DOMSelection::visibleSelection() const
73
return m_frame->selection()->selection();
76
static Position anchorPosition(const VisibleSelection& selection)
78
Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
79
return rangeCompliantEquivalent(anchor);
82
static Position focusPosition(const VisibleSelection& selection)
84
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
85
return rangeCompliantEquivalent(focus);
88
static Position basePosition(const VisibleSelection& selection)
90
return rangeCompliantEquivalent(selection.base());
93
static Position extentPosition(const VisibleSelection& selection)
95
return rangeCompliantEquivalent(selection.extent());
59
98
Node* DOMSelection::anchorNode() const
64
const Selection& selection = m_frame->selection()->selection();
65
Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
66
anchor = rangeCompliantEquivalent(anchor);
102
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
103
return shadowAncestor->parentNode();
104
return anchorPosition(visibleSelection()).node();
107
int DOMSelection::anchorOffset() const
111
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
112
return shadowAncestor->nodeIndex();
113
return anchorPosition(visibleSelection()).deprecatedEditingOffset();
116
Node* DOMSelection::focusNode() const
120
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
121
return shadowAncestor->parentNode();
122
return focusPosition(visibleSelection()).node();
125
int DOMSelection::focusOffset() const
129
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
130
return shadowAncestor->nodeIndex();
131
return focusPosition(visibleSelection()).deprecatedEditingOffset();
70
134
Node* DOMSelection::baseNode() const
74
return rangeCompliantEquivalent(m_frame->selection()->selection().base()).node();
77
int DOMSelection::anchorOffset() const
82
const Selection& selection = m_frame->selection()->selection();
83
Position anchor = selection.isBaseFirst() ? selection.start() : selection.end();
84
anchor = rangeCompliantEquivalent(anchor);
85
return anchor.offset();
138
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
139
return shadowAncestor->parentNode();
140
return basePosition(visibleSelection()).node();
88
143
int DOMSelection::baseOffset() const
92
return rangeCompliantEquivalent(m_frame->selection()->selection().base()).offset();
95
Node* DOMSelection::focusNode() const
100
const Selection& selection = m_frame->selection()->selection();
101
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
102
focus = rangeCompliantEquivalent(focus);
147
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
148
return shadowAncestor->nodeIndex();
149
return basePosition(visibleSelection()).deprecatedEditingOffset();
106
152
Node* DOMSelection::extentNode() const
110
return rangeCompliantEquivalent(m_frame->selection()->selection().extent()).node();
113
int DOMSelection::focusOffset() const
118
const Selection& selection = m_frame->selection()->selection();
119
Position focus = selection.isBaseFirst() ? selection.end() : selection.start();
120
focus = rangeCompliantEquivalent(focus);
121
return focus.offset();
156
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
157
return shadowAncestor->parentNode();
158
return extentPosition(visibleSelection()).node();
124
161
int DOMSelection::extentOffset() const
128
return rangeCompliantEquivalent(m_frame->selection()->selection().extent()).offset();
165
if (Node* shadowAncestor = selectionShadowAncestor(m_frame))
166
return shadowAncestor->nodeIndex();
167
return extentPosition(visibleSelection()).deprecatedEditingOffset();
131
170
bool DOMSelection::isCollapsed() const
172
if (!m_frame || selectionShadowAncestor(m_frame))
135
174
return !m_frame->selection()->isRange();
301
const Selection& selection = m_frame->selection()->selection();
302
return selection.toRange();
343
// If you're hitting this, you've added broken multi-range selection support
344
ASSERT(rangeCount() == 1);
346
if (Node* shadowAncestor = selectionShadowAncestor(m_frame)) {
347
Node* container = shadowAncestor->parentNode();
348
int offset = shadowAncestor->nodeIndex();
349
return Range::create(shadowAncestor->document(), container, offset, container, offset);
352
const VisibleSelection& selection = m_frame->selection()->selection();
353
return selection.firstRange();
305
356
void DOMSelection::removeAllRanges()
319
370
SelectionController* selection = m_frame->selection();
321
372
if (selection->isNone()) {
322
selection->setSelection(Selection(r));
373
selection->setSelection(VisibleSelection(r));
326
RefPtr<Range> range = selection->selection().toRange();
377
RefPtr<Range> range = selection->selection().toNormalizedRange();
327
378
ExceptionCode ec = 0;
328
379
if (r->compareBoundaryPoints(Range::START_TO_START, range.get(), ec) == -1) {
329
380
// We don't support discontiguous selection. We don't do anything if r and range don't intersect.
330
381
if (r->compareBoundaryPoints(Range::START_TO_END, range.get(), ec) > -1) {
331
382
if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), ec) == -1)
332
383
// The original range and r intersect.
333
selection->setSelection(Selection(r->startPosition(), range->endPosition(), DOWNSTREAM));
384
selection->setSelection(VisibleSelection(r->startPosition(), range->endPosition(), DOWNSTREAM));
335
386
// r contains the original range.
336
selection->setSelection(Selection(r));
387
selection->setSelection(VisibleSelection(r));
339
390
// We don't support discontiguous selection. We don't do anything if r and range don't intersect.
340
391
if (r->compareBoundaryPoints(Range::END_TO_START, range.get(), ec) < 1) {
341
392
if (r->compareBoundaryPoints(Range::END_TO_END, range.get(), ec) == -1)
342
393
// The original range contains r.
343
selection->setSelection(Selection(range.get()));
394
selection->setSelection(VisibleSelection(range.get()));
345
396
// The original range and r intersect.
346
selection->setSelection(Selection(range->startPosition(), r->endPosition(), DOWNSTREAM));
397
selection->setSelection(VisibleSelection(range->startPosition(), r->endPosition(), DOWNSTREAM));