[webkit-changes] cvs commit: WebCore/kwq DOM.mm DOMExtensions.h
Adele
adele at opensource.apple.com
Mon Nov 14 18:05:46 PST 2005
adele 05/11/14 18:05:45
Modified: . ChangeLog
. ChangeLog
khtml/ecma kjs_dom.cpp kjs_dom.h
khtml/html html_elementimpl.cpp
khtml/xml dom_docimpl.cpp dom_docimpl.h dom_elementimpl.cpp
dom_elementimpl.h
kwq DOM.mm DOMExtensions.h
Added: fast/dom blur-contenteditable-expected.checksum
blur-contenteditable-expected.png
blur-contenteditable-expected.txt
blur-contenteditable.html
focus-contenteditable-expected.checksum
focus-contenteditable-expected.png
focus-contenteditable-expected.txt
focus-contenteditable.html
Log:
LayoutTests:
Reviewed by Maciej.
Added layout tests for:
<rdar://problem/4233938> calling focus on contentEditable block elements should scroll them into view
<rdar://problem/3624946> No 'blur' method defined on editable non-form DOM objects
* fast/dom/blur-contenteditable-expected.checksum: Added.
* fast/dom/blur-contenteditable-expected.png: Added.
* fast/dom/blur-contenteditable-expected.txt: Added.
* fast/dom/blur-contenteditable.html: Added.
* fast/dom/focus-contenteditable-expected.checksum: Added.
* fast/dom/focus-contenteditable-expected.png: Added.
* fast/dom/focus-contenteditable-expected.txt: Added.
* fast/dom/focus-contenteditable.html: Added.
WebCore:
Reviewed by Maciej and Darin.
- fix for <rdar://problem/4233938> calling focus on contentEditable block elements should scroll them into view
- fix for <rdar://problem/3624946> No 'blur' method defined on editable non-form DOM objects
Added
* fast/dom/focus-contenteditable.html
* fast/dom/blur-contenteditable.html
* khtml/ecma/kjs_dom.cpp: Added ElementFocus and ElementBlur to DOMElementProtoTable
(KJS::DOMElementProtoFunc::callAsFunction): Added cases for ElementFocus and ElementBlur
* khtml/ecma/kjs_dom.h: (KJS::DOMElement::): Added ElementFocus and ElementBlur to enum
* khtml/html/html_elementimpl.cpp:
(HTMLElementImpl::parseMappedAttribute): Added case for onblur.
* khtml/xml/dom_elementimpl.cpp:
(ElementImpl::focus): If the element isFocusable, calls setFocusNode to give element focus.
(ElementImpl::blur): If the element is focused, calls setFocusNode to take away focus.
* khtml/xml/dom_elementimpl.h: Added focus and blur functions
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::setFocusNode): If we're trying to take focus away from a node, then we should clear the selection before we fire events.
If we don't, then efforts to focus the cursor during the event can reset focus on the old node.
(DocumentImpl::clearSelectionIfNeeded): Added function since we need to clear the selection at multiple points.
* khtml/xml/dom_docimpl.h: Added clearSelectionIfNeeded.
* kwq/DOMExtensions.h: Added Obj-C bindings for focus and blur.
* kwq/DOM.mm:
(-[DOMElement focus]):
(-[DOMElement blur]):
Revision Changes Path
1.91 +17 -0 LayoutTests/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/LayoutTests/ChangeLog,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- ChangeLog 14 Nov 2005 22:09:31 -0000 1.90
+++ ChangeLog 15 Nov 2005 02:05:36 -0000 1.91
@@ -1,3 +1,20 @@
+2005-11-14 Adele Peterson <adele at apple.com>
+
+ Reviewed by Maciej.
+
+ Added layout tests for:
+ <rdar://problem/4233938> calling focus on contentEditable block elements should scroll them into view
+ <rdar://problem/3624946> No 'blur' method defined on editable non-form DOM objects
+
+ * fast/dom/blur-contenteditable-expected.checksum: Added.
+ * fast/dom/blur-contenteditable-expected.png: Added.
+ * fast/dom/blur-contenteditable-expected.txt: Added.
+ * fast/dom/blur-contenteditable.html: Added.
+ * fast/dom/focus-contenteditable-expected.checksum: Added.
+ * fast/dom/focus-contenteditable-expected.png: Added.
+ * fast/dom/focus-contenteditable-expected.txt: Added.
+ * fast/dom/focus-contenteditable.html: Added.
+
2005-11-14 Justin Garcia <justin.garcia at apple.com>
Reviewed by harrison
1.1 LayoutTests/fast/dom/blur-contenteditable-expected.checksum
Index: blur-contenteditable-expected.checksum
===================================================================
f850f33ed4ad2cb667247f9ff760df9d
1.1 LayoutTests/fast/dom/blur-contenteditable-expected.png
<<Binary file>>
1.1 LayoutTests/fast/dom/blur-contenteditable-expected.txt
Index: blur-contenteditable-expected.txt
===================================================================
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
EDITING DELEGATE: shouldEndEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
layer at (0,0) size 800x600
RenderCanvas at (0,0) size 800x600
layer at (0,0) size 800x600
RenderBlock {HTML} at (0,0) size 800x600
RenderBody {BODY} at (8,8) size 784x584
RenderBlock (anonymous) at (0,0) size 784x18
RenderText {TEXT} at (0,0) size 486x18
text run at (0,0) width 486: "This test will try to call blur() on a contenteditable div, and then a normal div."
RenderBlock {DIV} at (0,18) size 784x24 [border: (3px solid #000000)]
RenderText {TEXT} at (3,3) size 122x18
text run at (3,3) width 122: "contentEditable div"
RenderBlock {DIV} at (0,42) size 784x18
RenderText {TEXT} at (0,0) size 78x18
text run at (0,0) width 78: "Test Passed."
RenderBlock {DIV} at (0,60) size 784x0
1.1 LayoutTests/fast/dom/blur-contenteditable.html
Index: blur-contenteditable.html
===================================================================
<html>
<head>
<script>
var result;
var pass1;
var pass2;
var pass3;
var exceptions;
function blurIt() {
pass1 = true;
pass2 = true;
pass3 = false;
exceptions = "";
try {
document.getElementById('mydiv').focus();
document.getElementById('mydiv').blur();
} catch(e) {
exceptions += "Exception: " + e + "\n";
pass1 = false;
}
try {
document.getElementById('result').blur();
} catch(e) {
exceptions += "Exception: " + e + "\n";
pass2 = false;
}
if (pass1 && pass2 && pass3) {
result = "Test Passed.";
} else {
result = "Test Failed.";
}
document.getElementById('result').innerHTML = result;
document.getElementById('exc').innerHTML = exceptions;
}
</script>
</head>
<body onload="blurIt()">
This test will try to call blur() on a contenteditable div, and then a normal div.
<div id="mydiv" onblur="pass3 = true;" style="border-style:solid" contenteditable>contentEditable div</div>
<div id="result"></div>
<div id="exc"></div>
</body>
</html>
1.1 LayoutTests/fast/dom/focus-contenteditable-expected.checksum
Index: focus-contenteditable-expected.checksum
===================================================================
ff8ef386c92b498b42277fc80caccb67
1.1 LayoutTests/fast/dom/focus-contenteditable-expected.png
<<Binary file>>
1.1 LayoutTests/fast/dom/focus-contenteditable-expected.txt
Index: focus-contenteditable-expected.txt
===================================================================
EDITING DELEGATE: shouldBeginEditingInDOMRange:range from 0 of DIV > BODY > HTML > #document to 1 of DIV > BODY > HTML > #document
layer at (0,0) size 785x894
RenderCanvas at (0,0) size 785x600
layer at (0,0) size 785x894
RenderBlock {HTML} at (0,0) size 785x894
RenderBody {BODY} at (8,8) size 769x878
RenderBlock (anonymous) at (0,0) size 769x36
RenderText {TEXT} at (0,0) size 499x18
text run at (0,0) width 499: "This test will try to call focus() on a contenteditable div, and then a normal div. "
RenderBR {BR} at (0,0) size 0x0
RenderText {TEXT} at (0,18) size 373x18
text run at (0,18) width 373: "The window should scroll to reveal the contenteditable div."
RenderBlock {DIV} at (0,36) size 500x800
RenderBlock {DIV} at (0,836) size 769x24 [border: (3px solid #000000)]
RenderText {TEXT} at (3,3) size 122x18
text run at (3,3) width 122: "contentEditable div"
RenderBlock {DIV} at (0,860) size 769x18
RenderText {TEXT} at (0,0) size 78x18
text run at (0,0) width 78: "Test Passed."
RenderBlock {DIV} at (0,878) size 769x0
1.1 LayoutTests/fast/dom/focus-contenteditable.html
Index: focus-contenteditable.html
===================================================================
<html>
<head>
<script>
var result;
var pass1;
var pass2;
var pass3;
var exceptions;
function focusIt() {
pass1 = true;
pass2 = true;
pass3 = false;
exceptions = "";
try {
document.getElementById('mydiv').focus();
} catch(e) {
exceptions += "Exception: " + e + "\n";
pass1 = false;
}
try {
document.getElementById('result').focus();
} catch(e) {
exceptions += "Exception: " + e + "\n";
pass2 = true;
}
if (pass1 && pass2 && pass3) {
result = "Test Passed.";
} else {
result = "Test Failed.";
}
document.getElementById('result').innerHTML = result;
document.getElementById('exc').innerHTML = exceptions;
}
</script>
</head>
<body onload="focusIt()">
This test will try to call focus() on a contenteditable div, and then a normal div.
<br>The window should scroll to reveal the contenteditable div.
<div style="width:500px;height:800px"></div>
<div id="mydiv" onfocus="pass3 = true;" style="border-style:solid" contenteditable>contentEditable div</div>
<div id="result"></div>
<div id="exc"></div>
</body>
</html>
1.368 +31 -1 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.367
retrieving revision 1.368
diff -u -r1.367 -r1.368
--- ChangeLog 14 Nov 2005 22:09:03 -0000 1.367
+++ ChangeLog 15 Nov 2005 02:05:38 -0000 1.368
@@ -1,3 +1,33 @@
+2005-11-14 Adele Peterson <adele at apple.com>
+
+ Reviewed by Maciej and Darin.
+
+ - fix for <rdar://problem/4233938> calling focus on contentEditable block elements should scroll them into view
+ - fix for <rdar://problem/3624946> No 'blur' method defined on editable non-form DOM objects
+
+ Added
+ * fast/dom/focus-contenteditable.html
+ * fast/dom/blur-contenteditable.html
+
+ * khtml/ecma/kjs_dom.cpp: Added ElementFocus and ElementBlur to DOMElementProtoTable
+ (KJS::DOMElementProtoFunc::callAsFunction): Added cases for ElementFocus and ElementBlur
+ * khtml/ecma/kjs_dom.h: (KJS::DOMElement::): Added ElementFocus and ElementBlur to enum
+ * khtml/html/html_elementimpl.cpp:
+ (HTMLElementImpl::parseMappedAttribute): Added case for onblur.
+ * khtml/xml/dom_elementimpl.cpp:
+ (ElementImpl::focus): If the element isFocusable, calls setFocusNode to give element focus.
+ (ElementImpl::blur): If the element is focused, calls setFocusNode to take away focus.
+ * khtml/xml/dom_elementimpl.h: Added focus and blur functions
+ * khtml/xml/dom_docimpl.cpp:
+ (DocumentImpl::setFocusNode): If we're trying to take focus away from a node, then we should clear the selection before we fire events.
+ If we don't, then efforts to focus the cursor during the event can reset focus on the old node.
+ (DocumentImpl::clearSelectionIfNeeded): Added function since we need to clear the selection at multiple points.
+ * khtml/xml/dom_docimpl.h: Added clearSelectionIfNeeded.
+ * kwq/DOMExtensions.h: Added Obj-C bindings for focus and blur.
+ * kwq/DOM.mm:
+ (-[DOMElement focus]):
+ (-[DOMElement blur]):
+
2005-11-14 Justin Garcia <justin.garcia at apple.com>
Reviewed by harrison
@@ -3297,7 +3327,7 @@
(QWidget::paint):
(QWidget::setDeferFirstResponderChanges):
-2005-10-11 Rob Buis <rwlbuis at xs4all.nl>>
+2005-10-11 Rob Buis <rwlbuis at xs4all.nl>
Reviewed by eseidel.
1.107 +8 -0 WebCore/khtml/ecma/kjs_dom.cpp
Index: kjs_dom.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_dom.cpp,v
retrieving revision 1.106
retrieving revision 1.107
diff -u -r1.106 -r1.107
--- kjs_dom.cpp 13 Nov 2005 18:52:36 -0000 1.106
+++ kjs_dom.cpp 15 Nov 2005 02:05:42 -0000 1.107
@@ -1119,6 +1119,8 @@
getElementsByTagNameNS DOMElement::GetElementsByTagNameNS DontDelete|Function 2
hasAttributeNS DOMElement::HasAttributeNS DontDelete|Function 2
scrollIntoView DOMElement::ScrollIntoView DontDelete|Function 1
+ focus DOMElement::ElementFocus DontDelete|Function 0
+ blur DOMElement::ElementBlur DontDelete|Function 0
# extension for Safari RSS
scrollByLines DOMElement::ScrollByLines DontDelete|Function 1
@@ -1267,6 +1269,12 @@
}
}
return Undefined();
+ case DOMElement::ElementFocus:
+ element.focus();
+ return Undefined();
+ case DOMElement::ElementBlur:
+ element.blur();
+ return Undefined();
default:
return Undefined();
}
1.57 +1 -1 WebCore/khtml/ecma/kjs_dom.h
Index: kjs_dom.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/ecma/kjs_dom.h,v
retrieving revision 1.56
retrieving revision 1.57
diff -u -r1.56 -r1.57
--- kjs_dom.h 1 Nov 2005 16:59:47 -0000 1.56
+++ kjs_dom.h 15 Nov 2005 02:05:42 -0000 1.57
@@ -165,7 +165,7 @@
SetAttributeNode, RemoveAttributeNode, GetElementsByTagName,
GetAttributeNS, SetAttributeNS, RemoveAttributeNS, GetAttributeNodeNS,
SetAttributeNodeNS, GetElementsByTagNameNS, HasAttribute, HasAttributeNS,
- ScrollByLines, ScrollByPages, ScrollIntoView};
+ ScrollByLines, ScrollByPages, ScrollIntoView, ElementFocus, ElementBlur};
protected:
// Constructor for inherited classes; doesn't set up a prototype.
DOMElement(DOM::ElementImpl *e);
1.111 +3 -0 WebCore/khtml/html/html_elementimpl.cpp
Index: html_elementimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_elementimpl.cpp,v
retrieving revision 1.110
retrieving revision 1.111
diff -u -r1.110 -r1.111
--- html_elementimpl.cpp 8 Nov 2005 08:10:58 -0000 1.110
+++ html_elementimpl.cpp 15 Nov 2005 02:05:42 -0000 1.111
@@ -189,6 +189,9 @@
} else if (attr->name() == onfocusAttr) {
setHTMLEventListener(DOMFocusInEvent,
getDocument()->createHTMLEventListener(attr->value().qstring(), this));
+ } else if (attr->name() == onblurAttr) {
+ setHTMLEventListener(DOMFocusOutEvent,
+ getDocument()->createHTMLEventListener(attr->value().qstring(), this));
} else if (attr->name() == onkeydownAttr) {
setHTMLEventListener(keydownEvent,
getDocument()->createHTMLEventListener(attr->value().qstring(), this));
1.271 +15 -8 WebCore/khtml/xml/dom_docimpl.cpp
Index: dom_docimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.cpp,v
retrieving revision 1.270
retrieving revision 1.271
diff -u -r1.270 -r1.271
--- dom_docimpl.cpp 13 Nov 2005 23:52:53 -0000 1.270
+++ dom_docimpl.cpp 15 Nov 2005 02:05:43 -0000 1.271
@@ -2265,6 +2265,7 @@
bool focusChangeBlocked = false;
SharedPtr<NodeImpl> oldFocusNode = m_focusNode;
m_focusNode = 0;
+ clearSelectionIfNeeded(newFocusNode);
// Remove focus from the existing focus node (if any)
if (oldFocusNode) {
@@ -2278,24 +2279,18 @@
focusChangeBlocked = true;
newFocusNode = 0;
}
+ clearSelectionIfNeeded(newFocusNode);
oldFocusNode->dispatchUIEvent(DOMFocusOutEvent);
if (m_focusNode) {
// handler shifted focus
focusChangeBlocked = true;
newFocusNode = 0;
}
+ clearSelectionIfNeeded(newFocusNode);
if ((oldFocusNode.get() == this) && oldFocusNode->hasOneRef())
return true;
}
- // Clear the selection when changing the focus node to null or to a node that is not
- // contained by the current selection.
- if (part()) {
- NodeImpl *startContainer = part()->selection().start().node();
- if (!newFocusNode || (startContainer && startContainer != newFocusNode && !startContainer->isAncestor(newFocusNode)))
- part()->clearSelection();
- }
-
if (newFocusNode) {
#if APPLE_CHANGES
if (newFocusNode->isContentEditable() && !acceptsEditingFocus(newFocusNode)) {
@@ -2353,6 +2348,18 @@
return !focusChangeBlocked;
}
+void DocumentImpl::clearSelectionIfNeeded(NodeImpl *newFocusNode)
+{
+ if (!part())
+ return;
+
+ // Clear the selection when changing the focus node to null or to a node that is not
+ // contained by the current selection.
+ NodeImpl *startContainer = part()->selection().start().node();
+ if (!newFocusNode || (startContainer && startContainer != newFocusNode && !startContainer->isAncestor(newFocusNode)))
+ part()->clearSelection();
+}
+
void DocumentImpl::setCSSTarget(NodeImpl* n)
{
if (m_cssTarget)
1.137 +1 -0 WebCore/khtml/xml/dom_docimpl.h
Index: dom_docimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.h,v
retrieving revision 1.136
retrieving revision 1.137
diff -u -r1.136 -r1.137
--- dom_docimpl.h 11 Nov 2005 02:15:36 -0000 1.136
+++ dom_docimpl.h 15 Nov 2005 02:05:43 -0000 1.137
@@ -426,6 +426,7 @@
NodeImpl *focusNode() const { return m_focusNode.get(); }
bool setFocusNode(NodeImpl *newFocusNode);
+ void clearSelectionIfNeeded(NodeImpl *newFocusNode);
NodeImpl *hoverNode() const { return m_hoverNode.get(); }
void setHoverNode(NodeImpl *newHoverNode);
1.91 +14 -0 WebCore/khtml/xml/dom_elementimpl.cpp
Index: dom_elementimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_elementimpl.cpp,v
retrieving revision 1.90
retrieving revision 1.91
diff -u -r1.90 -r1.91
--- dom_elementimpl.cpp 8 Nov 2005 08:11:12 -0000 1.90
+++ dom_elementimpl.cpp 15 Nov 2005 02:05:43 -0000 1.91
@@ -805,6 +805,20 @@
return 0;
}
+void ElementImpl::focus()
+{
+ DocumentImpl* doc = getDocument();
+ if (doc && isFocusable())
+ doc->setFocusNode(this);
+}
+
+void ElementImpl::blur()
+{
+ DocumentImpl* doc = getDocument();
+ if (doc && doc->focusNode() == this)
+ doc->setFocusNode(0);
+}
+
// -------------------------------------------------------------------------
NamedAttrMapImpl::NamedAttrMapImpl(ElementImpl *e)
1.60 +3 -0 WebCore/khtml/xml/dom_elementimpl.h
Index: dom_elementimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_elementimpl.h,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -r1.59 -r1.60
--- dom_elementimpl.h 8 Nov 2005 08:11:12 -0000 1.59
+++ dom_elementimpl.h 15 Nov 2005 02:05:43 -0000 1.60
@@ -252,6 +252,9 @@
virtual DOMString toString() const;
virtual bool isURLAttribute(AttributeImpl *attr) const;
+
+ void focus();
+ void blur();
#ifndef NDEBUG
virtual void dump(QTextStream *stream, QString ind = "") const;
1.56 +14 -0 WebCore/kwq/DOM.mm
Index: DOM.mm
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOM.mm,v
retrieving revision 1.55
retrieving revision 1.56
diff -u -r1.55 -r1.56
--- DOM.mm 1 Nov 2005 16:59:53 -0000 1.55
+++ DOM.mm 15 Nov 2005 02:05:45 -0000 1.56
@@ -1433,6 +1433,20 @@
@end
+ at implementation DOMElement (DOMElementExtensions)
+
+- (void)focus
+{
+ [self _elementImpl]->focus();
+}
+
+- (void)blur
+{
+ [self _elementImpl]->blur();
+}
+
+ at end
+
@implementation DOMElement (WebCoreInternal)
+ (DOMElement *)_elementWithImpl:(ElementImpl *)impl
1.13 +5 -0 WebCore/kwq/DOMExtensions.h
Index: DOMExtensions.h
===================================================================
RCS file: /cvs/root/WebCore/kwq/DOMExtensions.h,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- DOMExtensions.h 16 Sep 2005 22:42:23 -0000 1.12
+++ DOMExtensions.h 15 Nov 2005 02:05:45 -0000 1.13
@@ -32,6 +32,11 @@
- (DOMCSSStyleDeclaration *)createCSSStyleDeclaration;
@end
+ at interface DOMElement (DOMElementExtensions)
+- (void)focus;
+- (void)blur;
+ at end
+
@interface DOMHTMLElement (DOMHTMLElementExtensions)
- (NSString *)innerHTML;
- (void)setInnerHTML:(NSString *)innerHTML;
More information about the webkit-changes
mailing list