[prev in list] [next in list] [prev in thread] [next in thread]
List: kfm-devel
Subject: [PATCH] Implement "readonly" attribute
From: "Dawit A." <adawit () kde ! org>
Date: 2002-05-22 6:00:31
[Download RAW message or body]
Hi,
This is my attempt to implement readonly attribute for the two elements
that support it: TEXTAREA's and INPUT elements of type text and password.
A patch and a small testcase are attached below.
The patch changes HTMLGenericFormElementImpl::setReadOnly to virtual. This
way it can be re-implemented as needed. The default function now simply does
nothing. Also, I hacked the RenderTextArea class to add a widget() function which
seems to be missing unlike the other RenderXXXX widgets.
I do not know if this is an acceptable implementation. It does work properly as you
can try for yourself using the included testcase, but that of course means nothing
since I am not completely familiar with khtml's code.
Regards,
Dawit A.
["html_formimpl.diff" (text/x-diff)]
Index: html/html_formimpl.cpp
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.cpp,v
retrieving revision 1.271
diff -u -p -b -B -w -r1.271 html_formimpl.cpp
--- html/html_formimpl.cpp 2002/05/09 23:18:24 1.271
+++ html/html_formimpl.cpp 2002/05/22 05:39:02
@@ -506,7 +506,7 @@ void HTMLGenericFormElementImpl::parseAt
setDisabled( attr->val() != 0 );
break;
case ATTR_READONLY:
- m_readOnly = attr->val() != 0;
+ setReadOnly( attr->val() != 0 );
break;
default:
HTMLElementImpl::parseAttribute(attr);
@@ -875,6 +875,20 @@ void HTMLInputElementImpl::click( )
#endif
}
+void HTMLInputElementImpl::setReadOnly( bool _readOnly )
+{
+ // Only input elements of type TEXT and PASSWORD
+ // support the readonly attribute...
+ if (m_type != TEXT && m_type != PASSWORD)
+ return;
+
+ if ( m_readOnly != _readOnly ) {
+ m_readOnly = _readOnly;
+ if ( m_render && m_render->isWidget() && m_render->layouted() )
+ static_cast<RenderLineEdit *>(m_render)->widget()->setReadOnly( !m_readOnly );
+ }
+}
+
void HTMLInputElementImpl::parseAttribute(AttributeImpl *attr)
{
// ### IMPORTANT: check that the type can't be changed after the first time
@@ -2029,6 +2043,15 @@ void HTMLTextAreaElementImpl::select( )
if (m_render)
static_cast<RenderTextArea*>(m_render)->select();
onSelect();
+}
+
+void HTMLTextAreaElementImpl::setReadOnly( bool _readOnly )
+{
+ if ( m_readOnly != _readOnly ) {
+ m_readOnly = _readOnly;
+ if ( m_render && m_render->isWidget() && m_render->layouted() )
+ static_cast<RenderTextArea *>(m_render)->widget()->setReadOnly( !m_readOnly );
+ }
}
void HTMLTextAreaElementImpl::parseAttribute(AttributeImpl *attr)
Index: html/html_formimpl.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/html/html_formimpl.h,v
retrieving revision 1.120
diff -u -p -b -B -w -r1.120 html_formimpl.h
--- html/html_formimpl.h 2002/05/21 12:40:55 1.120
+++ html/html_formimpl.h 2002/05/22 05:39:02
@@ -138,7 +138,7 @@ public:
virtual bool isEnumeratable() const { return false; }
bool readOnly() const { return m_readOnly; }
- void setReadOnly(bool _readOnly) { m_readOnly = _readOnly; }
+ virtual void setReadOnly(bool) {}
virtual void recalcStyle( StyleChange );
@@ -264,6 +264,8 @@ public:
void select();
void click();
+ virtual void setReadOnly(bool _readOnly);
+
virtual void parseAttribute(AttributeImpl *attr);
virtual void init();
@@ -517,6 +519,8 @@ public:
void select ( );
+ virtual void setReadOnly(bool _readOnly);
+
virtual void parseAttribute(AttributeImpl *attr);
virtual void init();
virtual void attach();
Index: rendering/render_form.h
===================================================================
RCS file: /home/kde/kdelibs/khtml/rendering/render_form.h,v
retrieving revision 1.71
diff -u -p -b -B -w -r1.71 render_form.h
--- rendering/render_form.h 2002/05/09 23:18:24 1.71
+++ rendering/render_form.h 2002/05/22 05:39:02
@@ -394,6 +394,8 @@ public:
virtual void close ( );
virtual void updateFromElement();
+ QTextEdit *widget() const { return static_cast<QTextEdit*>(m_widget); }
+
// don't even think about making this method virtual!
DOM::HTMLTextAreaElementImpl* element() const
{ return static_cast<DOM::HTMLTextAreaElementImpl*>(RenderObject::element()); }
["test.html" (text/html)]
<html>
<head>
<title>"readonly" attribute test</title>
</head>
<body>
<input type="text" name="readonly" id="readolny" value="Read only text input" readonly>
<P>
<textarea name="comments" rows="8" cols="50" readonly>
This is a read only text area
</textarea>
</html>
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic