[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kfm-devel
Subject:    [PATCH] tracking form value changes in onclick-handlers
From:       Tobias Anton <TA () ESC-Electronics ! de>
Date:       2004-07-12 19:52:30
Message-ID: 200407122152.30825.TA () ESC-Electronics ! de
[Download RAW message or body]

Hi,

The attached patch introduces a variable that tracks changes caused by 
javascript during event handling. It basically prevents a form value that was 
set by a js event listener from being overwritten by accident in the default 
event handler.

This would enable us to complete our DOM events model and implement event 
listeners that can cancel "click" and "DOMActivate" events.
At the moment, event listeners of the form
	function clickEventListener(evt)
	{
		evt->preventDefault()
	}
cannot prevent the default action of form controls (toggling a checkbox, 
checking a radiobutton) because the default action, which should be done at 
the end of the DOMActivate-event, already has happened long before, during 
the mouseup_event.

To fix that, we'd have reorder the event flow to react on ACTIVATE_EVENTS, as 
defined by the HTML spec.

But we can't do this without this proposed patch, because current HTML would 
fail on DOM Level 0-compliant sites that use code like:
	<INPUT TYPE="checkbox" ONCLICK="this.checked=true">

They expect the state of this checkbox to be always checked after its first 
activation.

I'm planning to commit a patch like this one, and then I'd like to change the 
default event handlers of activatable elements (links, form controls and 
labels) to react on DOMACTIVATE_EVENT instead of CLICK_EVENT, or event worse, 
MOUSEUP_EVENTS.

Is there anything basically wrong or can I try this approach?

Cheers
-- Tobias
["temp.diff" (text/x-diff)]

? temp
? testregression
Index: html/html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.374
diff -u -3 -p -r1.374 html_formimpl.cpp
--- html/html_formimpl.cpp	12 Jul 2004 19:57:03 -0000	1.374
+++ html/html_formimpl.cpp	12 Jul 2004 20:34:18 -0000
@@ -1476,6 +1476,19 @@ void HTMLInputElementImpl::focus()
     getDocument()->setFocusNode(this);
 }
 
+void HTMLInputElementImpl::handleLocalEvents(EventImpl *evt, bool useCapture)
+{
+    if (evt->eventPhase()==Event::CAPTURING_PHASE || useCapture)
+	changedByJS = false;
+    HTMLGenericFormElementImpl::handleLocalEvents();
+}
+
+void HTMLInputElementImpl::setChanged(bool b)
+{
+    if (b)
+	changedByJS = true;
+}
+
 void HTMLInputElementImpl::defaultEventHandler(EventImpl *evt)
 {
     if ( !m_disabled )
@@ -1486,7 +1499,8 @@ void HTMLInputElementImpl::defaultEventH
             if ((m_type == RADIO || m_type == CHECKBOX)
 		&& me->id() == EventImpl::MOUSEUP_EVENT && me->detail() > 0) {
 		// click will follow
-		setChecked(m_type == RADIO ? true : !checked());
+		if (!changedByJS)
+		    setChecked(m_type == RADIO ? true : !checked());
 	    }
             if (evt->id() == EventImpl::CLICK_EVENT && m_type == IMAGE && m_render) \
{  // record the mouse position for when we get the DOMActivate event
@@ -1508,7 +1522,8 @@ void HTMLInputElementImpl::defaultEventH
 	    if (check) {
 	        if (evt->id() == EventImpl::KEYUP_EVENT) {
 		    if (m_type == RADIO || m_type == CHECKBOX)
-		        setChecked(m_type == RADIO ? true : !checked());
+			if (!changedByJS)
+			    setChecked(m_type == RADIO ? true : !checked());
 		    click();
 		}
 	        // Tell the parent that we handle this key (keyup and keydown), even though \
                only keyup activates (#70478)
Index: html/html_formimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.h,v
retrieving revision 1.154
diff -u -3 -p -r1.154 html_formimpl.h
--- html/html_formimpl.h	12 Jul 2004 19:57:03 -0000	1.154
+++ html/html_formimpl.h	12 Jul 2004 20:34:18 -0000
@@ -286,6 +286,9 @@ public:
     int clickX() const { return xPos; }
     int clickY() const { return yPos; }
 
+    virtual void handleLocalEvents(EventImpl *, bool);
+    virtual void setChanged(bool b);
+
     virtual void defaultEventHandler(EventImpl *evt);
     virtual bool isEditable();
 
@@ -307,6 +310,7 @@ protected:
     bool m_autocomplete : 1;
     bool m_inited : 1;
     bool m_unsubmittedFormChange : 1;
+    bool changedByJS : 1;
 };
 
 // -------------------------------------------------------------------------
Index: xml/dom_nodeimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/xml/dom_nodeimpl.h,v
retrieving revision 1.159
diff -u -3 -p -r1.159 dom_nodeimpl.h
--- xml/dom_nodeimpl.h	12 Jun 2004 15:05:03 -0000	1.159
+++ xml/dom_nodeimpl.h	12 Jul 2004 20:34:18 -0000
@@ -238,7 +238,7 @@ public:
     // this matches the logic in KHTMLView.
     bool dispatchKeyEvent(QKeyEvent *key, bool keypress);
 
-    void handleLocalEvents(EventImpl *evt, bool useCapture);
+    virtual void handleLocalEvents(EventImpl *evt, bool useCapture);
 
     /**
      * Perform the default action for an event e.g. submitting a form



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic