[webkit-changes] cvs commit: WebCore/khtml/editing
SelectionController.cpp SelectionController.h
Justin
justing at opensource.apple.com
Sat Dec 3 16:48:06 PST 2005
justing 05/12/03 16:48:06
Modified: . ChangeLog
khtml/editing SelectionController.cpp SelectionController.h
Log:
<http://bugzilla.opendarwin.org/show_bug.cgi?id=5856>
Selection based in an editable block can extend outside
validate() used to do expansion of the selection. The expansion
itself wasn't validated, so it could create a selection
that extended outside an editable area. Also m_base and
m_extent weren't updated with the results of the expansion.
Reviewed by darin
Layout tests added:
* editing/selection/expanding-selections
* editing/selection/expanding-selections2
* khtml/editing/SelectionController.cpp:
(khtml::SelectionController::expandUsingGranularity): Does the expansion.
(khtml::SelectionController::validate): Removed the granularity parameter.
* khtml/editing/SelectionController.h:
Revision Changes Path
1.466 +21 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.465
retrieving revision 1.466
diff -u -r1.465 -r1.466
--- ChangeLog 4 Dec 2005 00:32:32 -0000 1.465
+++ ChangeLog 4 Dec 2005 00:48:00 -0000 1.466
@@ -1,3 +1,24 @@
+2005-12-03 Justin Garcia <justin.garcia at apple.com>
+
+ <http://bugzilla.opendarwin.org/show_bug.cgi?id=5856>
+ Selection based in an editable block can extend outside
+
+ validate() used to do expansion of the selection. The expansion
+ itself wasn't validated, so it could create a selection
+ that extended outside an editable area. Also m_base and
+ m_extent weren't updated with the results of the expansion.
+
+ Reviewed by darin
+
+ Layout tests added:
+ * editing/selection/expanding-selections
+ * editing/selection/expanding-selections2
+
+ * khtml/editing/SelectionController.cpp:
+ (khtml::SelectionController::expandUsingGranularity): Does the expansion.
+ (khtml::SelectionController::validate): Removed the granularity parameter.
+ * khtml/editing/SelectionController.h:
+
2005-12-03 Geoffrey Garen <ggaren at apple.com>
Reviewed by Kevin.
1.104 +62 -71 WebCore/khtml/editing/SelectionController.cpp
Index: SelectionController.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/SelectionController.cpp,v
retrieving revision 1.103
retrieving revision 1.104
diff -u -r1.103 -r1.104
--- SelectionController.cpp 1 Dec 2005 10:32:14 -0000 1.103
+++ SelectionController.cpp 4 Dec 2005 00:48:05 -0000 1.104
@@ -491,7 +491,61 @@
{
if (isNone())
return false;
- validate(granularity);
+
+ switch (granularity) {
+ case CHARACTER:
+ break;
+ case WORD: {
+ // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
+ // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
+ // the document, select that last word (LeftWordIfOnBoundary).
+ // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
+ // last word to the line break (also RightWordIfOnBoundary);
+ VisiblePosition start = VisiblePosition(m_start, m_affinity);
+ VisiblePosition end = VisiblePosition(m_end, m_affinity);
+ EWordSide side = RightWordIfOnBoundary;
+ if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
+ side = LeftWordIfOnBoundary;
+ m_start = startOfWord(start, side).deepEquivalent();
+ side = RightWordIfOnBoundary;
+ if (isEndOfDocument(end) || (isEndOfLine(end) && !isStartOfLine(end) && !isEndOfParagraph(end)))
+ side = LeftWordIfOnBoundary;
+ m_end = endOfWord(end, side).deepEquivalent();
+
+ break;
+ }
+ case LINE:
+ case LINE_BOUNDARY:
+ m_start = startOfLine(VisiblePosition(m_start, m_affinity)).deepEquivalent();
+ m_end = endOfLine(VisiblePosition(m_end, m_affinity), IncludeLineBreak).deepEquivalent();
+ break;
+ case PARAGRAPH: {
+ VisiblePosition pos(m_start, m_affinity);
+ if (isStartOfLine(pos) && isEndOfDocument(pos))
+ pos = pos.previous();
+ m_start = startOfParagraph(pos).deepEquivalent();
+ m_end = endOfParagraph(VisiblePosition(m_end, m_affinity), IncludeLineBreak).deepEquivalent();
+ break;
+ }
+ case DOCUMENT_BOUNDARY:
+ m_start = startOfDocument(VisiblePosition(m_start, m_affinity)).deepEquivalent();
+ m_end = endOfDocument(VisiblePosition(m_end, m_affinity)).deepEquivalent();
+ break;
+ case PARAGRAPH_BOUNDARY:
+ m_start = startOfParagraph(VisiblePosition(m_start, m_affinity)).deepEquivalent();
+ m_end = endOfParagraph(VisiblePosition(m_end, m_affinity)).deepEquivalent();
+ break;
+ }
+
+ if (m_baseIsStart) {
+ m_base = m_start;
+ m_extent = m_end;
+ } else {
+ m_base = m_end;
+ m_extent = m_start;
+ }
+
+ validate();
return true;
}
@@ -571,7 +625,6 @@
validate();
}
-
void SelectionController::setBase(const Position &pos, EAffinity baseAffinity)
{
m_affinity = baseAffinity;
@@ -821,7 +874,7 @@
}
}
-void SelectionController::validate(ETextGranularity granularity)
+void SelectionController::validate()
{
adjustExtentForEditableContent();
// Move the selection to rendered positions, if possible.
@@ -872,74 +925,12 @@
m_baseIsStart = RangeImpl::compareBoundaryPoints(m_base.node(), m_base.offset(), m_extent.node(), m_extent.offset()) <= 0;
}
- m_start.clear();
- m_end.clear();
-
- // calculate the correct start and end positions
- switch (granularity) {
- case CHARACTER:
- if (m_baseIsStart) {
- m_start = m_base;
- m_end = m_extent;
- } else {
- m_start = m_extent;
- m_end = m_base;
- }
- break;
- case WORD: {
- // General case: Select the word the caret is positioned inside of, or at the start of (RightWordIfOnBoundary).
- // Edge case: If the caret is after the last word in a soft-wrapped line or the last word in
- // the document, select that last word (LeftWordIfOnBoundary).
- // Edge case: If the caret is after the last word in a paragraph, select from the the end of the
- // last word to the line break (also RightWordIfOnBoundary);
- VisiblePosition start = m_baseIsStart ? VisiblePosition(m_base, m_affinity) : VisiblePosition(m_extent, m_affinity);
- VisiblePosition end = m_baseIsStart ? VisiblePosition(m_extent, m_affinity) : VisiblePosition(m_base, m_affinity);
- EWordSide side = RightWordIfOnBoundary;
- if (isEndOfDocument(start) || (isEndOfLine(start) && !isStartOfLine(start) && !isEndOfParagraph(start)))
- side = LeftWordIfOnBoundary;
- m_start = startOfWord(start, side).deepEquivalent();
- side = RightWordIfOnBoundary;
- if (isEndOfDocument(end) || (isEndOfLine(end) && !isStartOfLine(end) && !isEndOfParagraph(end)))
- side = LeftWordIfOnBoundary;
- m_end = endOfWord(end, side).deepEquivalent();
-
- break;
- }
- case LINE:
- case LINE_BOUNDARY:
- if (m_baseIsStart) {
- m_start = startOfLine(VisiblePosition(m_base, m_affinity)).deepEquivalent();
- m_end = endOfLine(VisiblePosition(m_extent, m_affinity), IncludeLineBreak).deepEquivalent();
- } else {
- m_start = startOfLine(VisiblePosition(m_extent, m_affinity)).deepEquivalent();
- m_end = endOfLine(VisiblePosition(m_base, m_affinity), IncludeLineBreak).deepEquivalent();
- }
- break;
- case PARAGRAPH:
- if (m_baseIsStart) {
- VisiblePosition pos(m_base, m_affinity);
- if (isStartOfLine(pos) && isEndOfDocument(pos))
- pos = pos.previous();
- m_start = startOfParagraph(pos).deepEquivalent();
- m_end = endOfParagraph(VisiblePosition(m_extent, m_affinity), IncludeLineBreak).deepEquivalent();
- } else {
- m_start = startOfParagraph(VisiblePosition(m_extent, m_affinity)).deepEquivalent();
- m_end = endOfParagraph(VisiblePosition(m_base, m_affinity), IncludeLineBreak).deepEquivalent();
- }
- break;
- case DOCUMENT_BOUNDARY:
- m_start = startOfDocument(VisiblePosition(m_base, m_affinity)).deepEquivalent();
- m_end = endOfDocument(VisiblePosition(m_base, m_affinity)).deepEquivalent();
- break;
- case PARAGRAPH_BOUNDARY:
- if (m_baseIsStart) {
- m_start = startOfParagraph(VisiblePosition(m_base, m_affinity)).deepEquivalent();
- m_end = endOfParagraph(VisiblePosition(m_extent, m_affinity)).deepEquivalent();
- } else {
- m_start = startOfParagraph(VisiblePosition(m_extent, m_affinity)).deepEquivalent();
- m_end = endOfParagraph(VisiblePosition(m_base, m_affinity)).deepEquivalent();
- }
- break;
+ if (m_baseIsStart) {
+ m_start = m_base;
+ m_end = m_extent;
+ } else {
+ m_start = m_extent;
+ m_end = m_base;
}
// adjust the state
1.46 +1 -1 WebCore/khtml/editing/SelectionController.h
Index: SelectionController.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/SelectionController.h,v
retrieving revision 1.45
retrieving revision 1.46
diff -u -r1.45 -r1.46
--- SelectionController.h 1 Dec 2005 10:32:14 -0000 1.45
+++ SelectionController.h 4 Dec 2005 00:48:05 -0000 1.46
@@ -121,7 +121,7 @@
enum EPositionType { START, END, BASE, EXTENT };
void init(EAffinity affinity);
- void validate(ETextGranularity granularity = CHARACTER);
+ void validate();
void adjustExtentForEditableContent();
VisiblePosition modifyExtendingRightForward(ETextGranularity);
More information about the webkit-changes
mailing list