[webkit-changes] cvs commit: WebCore/kwq KWQKHTMLPart.mm
Justin
justing at opensource.apple.com
Thu Oct 6 18:21:56 PDT 2005
justing 05/10/06 18:21:54
Modified: . ChangeLog
khtml khtml_part.cpp
khtml/editing SelectionController.cpp SelectionController.h
visible_position.h
khtml/xml dom_nodeimpl.cpp
kwq KWQKHTMLPart.mm
Log:
Reviewed by harrison
<rdar://problem/4073133> Tabbing between editable elements leads to loss of keyboard focus
<rdar://problem/3690719> "Select All" when in an editable area selects the whole containing document
<rdar://problem/3690703> selection is allowed to span editable area and rest of document
* khtml/editing/SelectionController.cpp:
(khtml::SelectionController::adjustExtentForEditableContent):
Added, ensures that a selection cannot cross an editable/non-editable boundry.
(khtml::SelectionController::validate):
* khtml/editing/SelectionController.h:
* khtml/editing/visible_position.h:
* khtml/khtml_part.cpp:
(KHTMLPart::setSelection):
(KHTMLPart::setFocusNodeIfNeeded):
(KHTMLPart::selectAll):
Select only the contents of the rootEditableElement, if it exists. Also now calls the shouldChangeSelection delegate method.
* khtml/xml/dom_nodeimpl.cpp:
(DOM::ContainerNodeImpl::setFocus): Clicking on an editable element used to change the selection twice.
* kwq/KWQKHTMLPart.mm:
(KWQKHTMLPart::nextKeyViewInFrame): Select All when tabbing to an editable element, to match <textarea>s
Revision Changes Path
1.215 +24 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.214
retrieving revision 1.215
diff -u -r1.214 -r1.215
--- ChangeLog 7 Oct 2005 00:46:45 -0000 1.214
+++ ChangeLog 7 Oct 2005 01:21:36 -0000 1.215
@@ -1,3 +1,27 @@
+2005-10-06 Justin Garcia <justin.garcia at apple.com>
+
+ Reviewed by harrison
+
+ <rdar://problem/4073133> Tabbing between editable elements leads to loss of keyboard focus
+ <rdar://problem/3690719> "Select All" when in an editable area selects the whole containing document
+ <rdar://problem/3690703> selection is allowed to span editable area and rest of document
+
+ * khtml/editing/SelectionController.cpp:
+ (khtml::SelectionController::adjustExtentForEditableContent):
+ Added, ensures that a selection cannot cross an editable/non-editable boundry.
+ (khtml::SelectionController::validate):
+ * khtml/editing/SelectionController.h:
+ * khtml/editing/visible_position.h:
+ * khtml/khtml_part.cpp:
+ (KHTMLPart::setSelection):
+ (KHTMLPart::setFocusNodeIfNeeded):
+ (KHTMLPart::selectAll):
+ Select only the contents of the rootEditableElement, if it exists. Also now calls the shouldChangeSelection delegate method.
+ * khtml/xml/dom_nodeimpl.cpp:
+ (DOM::ContainerNodeImpl::setFocus): Clicking on an editable element used to change the selection twice.
+ * kwq/KWQKHTMLPart.mm:
+ (KWQKHTMLPart::nextKeyViewInFrame): Select All when tabbing to an editable element, to match <textarea>s
+
2005-10-06 Vicki Murley <vicki at apple.com>
Reviewed by Beth Dakin.
1.346 +10 -17 WebCore/khtml/khtml_part.cpp
Index: khtml_part.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/khtml_part.cpp,v
retrieving revision 1.345
retrieving revision 1.346
diff -u -r1.345 -r1.346
--- khtml_part.cpp 3 Oct 2005 23:12:30 -0000 1.345
+++ khtml_part.cpp 7 Oct 2005 01:21:40 -0000 1.346
@@ -2611,18 +2611,8 @@
if (!xmlDocImpl() || d->m_selection.isNone() || !d->m_isFocused)
return;
- NodeImpl *n = d->m_selection.start().node();
- NodeImpl *target = (n && n->isContentEditable()) ? n : 0;
- if (!target) {
- while (n && n != d->m_selection.end().node()) {
- if (n->isContentEditable()) {
- target = n;
- break;
- }
- n = n->traverseNextNode();
- }
- }
- assert(target == 0 || target->isContentEditable());
+ NodeImpl *startNode = d->m_selection.start().node();
+ NodeImpl *target = startNode ? startNode->rootEditableElement() : 0;
if (target) {
for ( ; target; target = target->parentNode()) {
@@ -5173,12 +5163,15 @@
{
if (!d->m_doc)
return;
- NodeImpl *de = d->m_doc->documentElement();
- int n = de ? de->childNodeCount() : 0;
- SelectionController sel = SelectionController(VisiblePosition(de, 0, khtml::DOWNSTREAM), VisiblePosition(de, n, khtml::DOWNSTREAM));
- if (shouldChangeSelection(sel)) {
+
+ NodeImpl *startNode = d->m_selection.start().node();
+ NodeImpl *root = startNode && startNode->isContentEditable() ? startNode->rootEditableElement() : d->m_doc->documentElement();
+
+ SelectionController sel = SelectionController(Position(root, 0), khtml::DOWNSTREAM, Position(root, root->maxDeepOffset()), khtml::DOWNSTREAM);
+
+ if (shouldChangeSelection(sel))
setSelection(sel);
- }
+
selectFrameElementInParentIfFullySelected();
}
1.98 +51 -0 WebCore/khtml/editing/SelectionController.cpp
Index: SelectionController.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/SelectionController.cpp,v
retrieving revision 1.97
retrieving revision 1.98
diff -u -r1.97 -r1.98
--- SelectionController.cpp 3 Oct 2005 21:12:18 -0000 1.97
+++ SelectionController.cpp 7 Oct 2005 01:21:41 -0000 1.98
@@ -787,8 +787,59 @@
p->fillRect(m_caretRect & rect, QBrush());
}
+void SelectionController::adjustExtentForEditableContent()
+{
+ Position base = this->base();
+ Position extent = this->extent();
+
+ if (!base.node() || !extent.node())
+ return;
+
+ NodeImpl *baseRoot = base.node()->rootEditableElement();
+ NodeImpl *extentRoot = extent.node()->rootEditableElement();
+
+ if (baseRoot == extentRoot)
+ return;
+
+ bool baseIsStart = RangeImpl::compareBoundaryPoints(base, extent) <= 0;
+
+ // base is in an editable region, but extent is not.
+ if (baseRoot) {
+ Position first(Position(baseRoot, 0));
+ Position last(Position(baseRoot, baseRoot->maxDeepOffset()));
+
+ m_extent = baseIsStart ? last : first;
+ // extent is in an editable region, but base is not.
+ } else {
+ if (baseIsStart) {
+ VisiblePosition previous;
+ do {
+ previous = VisiblePosition(Position(extentRoot, 0)).previous();
+ extentRoot = previous.deepEquivalent().node()->rootEditableElement();
+ } while (extentRoot);
+
+ // Since we know that base is before extent, and since we know that base is not in a content editable element,
+ // we know that we must have reached non editable content.
+ ASSERT(!previous.isNull());
+ m_extent = previous.deepEquivalent();
+ } else {
+ VisiblePosition next;
+ do {
+ next = VisiblePosition(Position(extentRoot, extentRoot->maxDeepOffset())).next();
+ extentRoot = next.deepEquivalent().node()->rootEditableElement();
+ } while (extentRoot);
+
+ // Since we know that extent is before base, and since we know that extent is not in a content editable element,
+ // we know that we must have reached non editable content.
+ ASSERT(!next.isNull());
+ m_extent = next.deepEquivalent();
+ }
+ }
+}
+
void SelectionController::validate(ETextGranularity granularity)
{
+ adjustExtentForEditableContent();
// Move the selection to rendered positions, if possible.
Position originalBase(m_base);
bool baseAndExtentEqual = m_base == m_extent;
1.42 +1 -0 WebCore/khtml/editing/SelectionController.h
Index: SelectionController.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/SelectionController.h,v
retrieving revision 1.41
retrieving revision 1.42
diff -u -r1.41 -r1.42
--- SelectionController.h 24 Sep 2005 01:18:54 -0000 1.41
+++ SelectionController.h 7 Oct 2005 01:21:42 -0000 1.42
@@ -123,6 +123,7 @@
void init(EAffinity affinity);
void validate(ETextGranularity granularity = CHARACTER);
+ void adjustExtentForEditableContent();
VisiblePosition modifyExtendingRightForward(ETextGranularity);
VisiblePosition modifyMovingRightForward(ETextGranularity);
1.33 +1 -1 WebCore/khtml/editing/visible_position.h
Index: visible_position.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/editing/visible_position.h,v
retrieving revision 1.32
retrieving revision 1.33
diff -u -r1.32 -r1.33
--- visible_position.h 27 Sep 2005 22:37:12 -0000 1.32
+++ visible_position.h 7 Oct 2005 01:21:42 -0000 1.33
@@ -62,7 +62,7 @@
// otherwise it will be converted to DOWNSTREAM
VisiblePosition() { m_affinity = VP_DEFAULT_AFFINITY; };
VisiblePosition(NodeImpl *, int offset, EAffinity);
- VisiblePosition(const Position &, EAffinity);
+ VisiblePosition(const Position &pos, EAffinity affinity = VP_DEFAULT_AFFINITY);
VisiblePosition(const VisiblePosition &);
void clear() { m_deepPosition.clear(); }
1.200 +0 -5 WebCore/khtml/xml/dom_nodeimpl.cpp
Index: dom_nodeimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_nodeimpl.cpp,v
retrieving revision 1.199
retrieving revision 1.200
diff -u -r1.199 -r1.200
--- dom_nodeimpl.cpp 6 Oct 2005 21:48:09 -0000 1.199
+++ dom_nodeimpl.cpp 7 Oct 2005 01:21:43 -0000 1.200
@@ -2343,11 +2343,6 @@
NodeImpl::setFocus(received);
- // FIXME: Move to ElementImpl
- if (received && isEditableBlock() && !hasChildNodes()) {
- getDocument()->part()->setSelection(SelectionController(Position(this, 0), DOWNSTREAM));
- }
-
// note that we need to recalc the style
setChanged();
}
1.677 +7 -0 WebCore/kwq/KWQKHTMLPart.mm
Index: KWQKHTMLPart.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/KWQKHTMLPart.mm,v
retrieving revision 1.676
retrieving revision 1.677
diff -u -r1.676 -r1.677
--- KWQKHTMLPart.mm 3 Oct 2005 21:13:04 -0000 1.676
+++ KWQKHTMLPart.mm 7 Oct 2005 01:21:47 -0000 1.677
@@ -1261,6 +1261,13 @@
}
else {
doc->setFocusNode(node);
+
+ if (node->isEditableBlock()) {
+ SelectionController sel(Position(node, 0), DOWNSTREAM, Position(node, node->maxDeepOffset()), DOWNSTREAM);
+ if (((KHTMLPart *)this)->shouldChangeSelection(sel))
+ setSelection(sel);
+ }
+
if (view() && node->renderer() && !node->renderer()->isRoot()) {
view()->ensureRectVisibleCentered(node->getRect());
}
More information about the webkit-changes
mailing list