[webkit-changes] cvs commit: WebCore/khtml/xml dom_docimpl.cpp
dom_docimpl.h
Adele
adele at opensource.apple.com
Tue Jul 12 11:29:06 PDT 2005
adele 05/07/12 11:29:06
Modified: . Tag: Safari-2-0-branch ChangeLog
khtml/dom Tag: Safari-2-0-branch html_head.cpp
khtml/html Tag: Safari-2-0-branch html_headimpl.cpp
html_headimpl.h
khtml/xml Tag: Safari-2-0-branch dom_docimpl.cpp
dom_docimpl.h
Log:
Merged fix from TOT to Safari-2-0-branch
<rdar://problem/4164941> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
2005-06-22 Anders Carlsson <andersca at mac.com>
Reviewed and landed by Darin Adler.
Test cases added:
* layout-tests/fast/dom/title-text-property-expected.txt: Added
* layout-tests/fast/dom/title-text-property.html: Added
* layout-tests/fast/dom/title-text-property-expected-2.txt: Added
* layout-tests/fast/dom/title-text-property-2.html: Added
- fixed <rdar://problem/3831364> getting or setting text for a <title> element doesn't work
- fixed <rdar://problem/4091225> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
- fixed <http://bugzilla.opendarwin.org/show_bug.cgi?id=3586>
Setting and getting title's text attribute does not work
* khtml/dom/html_head.cpp:
(HTMLTitleElement::text):
(HTMLTitleElement::setText):
Call HTMLTitleElementImpl::text() and ::setText().
* khtml/html/html_headimpl.cpp:
(HTMLTitleElementImpl::HTMLTitleElementImpl):
(HTMLTitleElementImpl::insertedIntoDocument):
(HTMLTitleElementImpl::removedFromDocument):
(HTMLTitleElementImpl::childrenChanged):
Pass the current title node to DocumentImpl::setTitle
and ::removeTitle.
(HTMLTitleElementImpl::text):
Return the title.
(HTMLTitleElementImpl::setText):
Set the new title.
* khtml/xml/dom_docimpl.cpp:
(DocumentImpl::DocumentImpl):
(DocumentImpl::~DocumentImpl):
(DocumentImpl::updateTitle):
(DocumentImpl::setTitle):
(DocumentImpl::removeTitle):
* khtml/xml/dom_docimpl.h:
Only update the title if it's done by setting document.title
or by changing the child nodes of the title element.
Revision Changes Path
No revision
No revision
1.4104.2.49 +49 -0 WebCore/ChangeLog
Index: ChangeLog
===================================================================
RCS file: /cvs/root/WebCore/ChangeLog,v
retrieving revision 1.4104.2.48
retrieving revision 1.4104.2.49
diff -u -r1.4104.2.48 -r1.4104.2.49
--- ChangeLog 12 Jul 2005 17:52:24 -0000 1.4104.2.48
+++ ChangeLog 12 Jul 2005 18:28:57 -0000 1.4104.2.49
@@ -1,3 +1,52 @@
+2005-07-12 Adele Peterson <adele at apple.com>
+
+ Merged fix from TOT to Safari-2-0-branch
+ <rdar://problem/4164941> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
+
+ 2005-06-22 Anders Carlsson <andersca at mac.com>
+
+ Reviewed and landed by Darin Adler.
+
+ Test cases added:
+ * layout-tests/fast/dom/title-text-property-expected.txt: Added
+ * layout-tests/fast/dom/title-text-property.html: Added
+ * layout-tests/fast/dom/title-text-property-expected-2.txt: Added
+ * layout-tests/fast/dom/title-text-property-2.html: Added
+
+ - fixed <rdar://problem/3831364> getting or setting text for a <title> element doesn't work
+ - fixed <rdar://problem/4091225> REGRESSION (1.2.4-1.3): many titles with non-ASCII characters do not display properly (XHTML strict only)
+ - fixed <http://bugzilla.opendarwin.org/show_bug.cgi?id=3586>
+ Setting and getting title's text attribute does not work
+
+ * khtml/dom/html_head.cpp:
+ (HTMLTitleElement::text):
+ (HTMLTitleElement::setText):
+ Call HTMLTitleElementImpl::text() and ::setText().
+
+ * khtml/html/html_headimpl.cpp:
+ (HTMLTitleElementImpl::HTMLTitleElementImpl):
+ (HTMLTitleElementImpl::insertedIntoDocument):
+ (HTMLTitleElementImpl::removedFromDocument):
+ (HTMLTitleElementImpl::childrenChanged):
+ Pass the current title node to DocumentImpl::setTitle
+ and ::removeTitle.
+
+ (HTMLTitleElementImpl::text):
+ Return the title.
+
+ (HTMLTitleElementImpl::setText):
+ Set the new title.
+
+ * khtml/xml/dom_docimpl.cpp:
+ (DocumentImpl::DocumentImpl):
+ (DocumentImpl::~DocumentImpl):
+ (DocumentImpl::updateTitle):
+ (DocumentImpl::setTitle):
+ (DocumentImpl::removeTitle):
+ * khtml/xml/dom_docimpl.h:
+ Only update the title if it's done by setting document.title
+ or by changing the child nodes of the title element.
+
2005-07-12 Vicki Murley <vicki at apple.com>
- merge this fix from HEAD
No revision
No revision
1.8.28.1 +2 -2 WebCore/khtml/dom/html_head.cpp
Index: html_head.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/dom/html_head.cpp,v
retrieving revision 1.8
retrieving revision 1.8.28.1
diff -u -r1.8 -r1.8.28.1
--- html_head.cpp 3 Nov 2003 06:32:04 -0000 1.8
+++ html_head.cpp 12 Jul 2005 18:29:03 -0000 1.8.28.1
@@ -513,11 +513,11 @@
DOMString HTMLTitleElement::text() const
{
if(!impl) return DOMString();
- return ((ElementImpl *)impl)->getAttribute(ATTR_TEXT);
+ return ((HTMLTitleElementImpl *)impl)->text();
}
void HTMLTitleElement::setText( const DOMString &value )
{
- if(impl) ((ElementImpl *)impl)->setAttribute(ATTR_TEXT, value);
+ if(impl) ((HTMLTitleElementImpl *)impl)->setText(value);
}
No revision
No revision
1.43.16.2 +33 -17 WebCore/khtml/html/html_headimpl.cpp
Index: html_headimpl.cpp
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.cpp,v
retrieving revision 1.43.16.1
retrieving revision 1.43.16.2
diff -u -r1.43.16.1 -r1.43.16.2
--- html_headimpl.cpp 1 Jul 2005 22:46:56 -0000 1.43.16.1
+++ html_headimpl.cpp 12 Jul 2005 18:29:04 -0000 1.43.16.2
@@ -538,7 +538,7 @@
// -------------------------------------------------------------------------
HTMLTitleElementImpl::HTMLTitleElementImpl(DocumentPtr *doc)
- : HTMLElementImpl(doc)
+ : HTMLElementImpl(doc), m_title("")
{
}
@@ -554,21 +554,13 @@
void HTMLTitleElementImpl::insertedIntoDocument()
{
HTMLElementImpl::insertedIntoDocument();
-#if APPLE_CHANGES
- // Only allow title to be set by first <title> encountered.
- if (getDocument()->title().isEmpty())
- getDocument()->setTitle(m_title);
-#else
- getDocument()->setTitle(m_title);
-#endif
+ getDocument()->setTitle(m_title, this);
}
void HTMLTitleElementImpl::removedFromDocument()
{
HTMLElementImpl::removedFromDocument();
- // Title element removed, so we have no title... we ignore the case of multiple title elements, as it's invalid
- // anyway (?)
- getDocument()->setTitle(DOMString());
+ getDocument()->removeTitle(this);
}
void HTMLTitleElementImpl::childrenChanged()
@@ -579,11 +571,35 @@
if ((c->nodeType() == Node::TEXT_NODE) || (c->nodeType() == Node::CDATA_SECTION_NODE))
m_title += c->nodeValue();
}
-#if APPLE_CHANGES
- // Only allow title to be set by first <title> encountered.
- if (inDocument() && getDocument()->title().isEmpty())
-#else
if (inDocument())
-#endif
- getDocument()->setTitle(m_title);
+ getDocument()->setTitle(m_title, this);
}
+
+DOMString HTMLTitleElementImpl::text() const
+{
+ DOMString val = "";
+
+ for (NodeImpl *n = firstChild(); n; n = n->nextSibling()) {
+ if (n->isTextNode())
+ val += static_cast<TextImpl *>(n)->data();
+ }
+
+ return val;
+}
+
+void HTMLTitleElementImpl::setText(const DOMString &value)
+{
+ int exceptioncode = 0;
+ int numChildren = childNodeCount();
+
+ if (numChildren == 1 && firstChild()->isTextNode()) {
+ static_cast<DOM::TextImpl *>(firstChild())->setData(value, exceptioncode);
+ } else {
+ if (numChildren > 0) {
+ removeChildren();
+ }
+
+ appendChild(getDocument()->createTextNode(value.implementation()), exceptioncode);
+ }
+}
+
1.15.16.2 +3 -0 WebCore/khtml/html/html_headimpl.h
Index: html_headimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/html/html_headimpl.h,v
retrieving revision 1.15.16.1
retrieving revision 1.15.16.2
diff -u -r1.15.16.1 -r1.15.16.2
--- html_headimpl.h 1 Jul 2005 22:46:56 -0000 1.15.16.1
+++ html_headimpl.h 12 Jul 2005 18:29:04 -0000 1.15.16.2
@@ -197,6 +197,9 @@
virtual void insertedIntoDocument();
virtual void removedFromDocument();
virtual void childrenChanged();
+
+ DOMString text() const;
+ void setText(const DOMString &);
protected:
DOMString m_title;
No revision
No revision
1.211.6.5 +54 -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.211.6.4
retrieving revision 1.211.6.5
diff -u -r1.211.6.4 -r1.211.6.5
--- dom_docimpl.cpp 1 Jul 2005 22:36:03 -0000 1.211.6.4
+++ dom_docimpl.cpp 12 Jul 2005 18:29:05 -0000 1.211.6.5
@@ -264,6 +264,9 @@
DocumentImpl::DocumentImpl(DOMImplementationImpl *_implementation, KHTMLView *v)
: NodeBaseImpl( new DocumentPtr() )
, m_domtree_version(0)
+ , m_title("")
+ , m_titleSetExplicitly(false)
+ , m_titleElement(0)
, m_imageLoadEventTimer(0)
#ifndef KHTML_NO_XBL
, m_bindingManager(new XBLBindingManager(this))
@@ -408,7 +411,10 @@
m_focusNode->deref();
if (m_hoverNode)
m_hoverNode->deref();
-
+
+ if (m_titleElement)
+ m_titleElement->deref();
+
if (m_renderArena){
delete m_renderArena;
m_renderArena = 0;
@@ -693,15 +699,14 @@
return m_elementsByAccessKey.find(k);
}
-void DocumentImpl::setTitle(DOMString _title)
+void DocumentImpl::updateTitle()
{
- m_title = _title;
-
- if (!part())
+ KHTMLPart *p = part();
+ if (!p)
return;
#if APPLE_CHANGES
- KWQ(part())->setTitle(_title);
+ KWQ(p)->setTitle(m_title);
#else
QString titleStr = m_title.string();
for (int i = 0; i < titleStr.length(); ++i)
@@ -709,7 +714,7 @@
titleStr[i] = ' ';
titleStr = titleStr.stripWhiteSpace();
titleStr.compose();
- if ( !part()->parentPart() ) {
+ if ( !p->parentPart() ) {
if (titleStr.isNull() || titleStr.isEmpty()) {
// empty title... set window caption as the URL
KURL url = m_url;
@@ -718,11 +723,52 @@
titleStr = url.url();
}
- emit part()->setWindowCaption( KStringHandler::csqueeze( titleStr, 128 ) );
+ emit p->setWindowCaption( KStringHandler::csqueeze( titleStr, 128 ) );
}
#endif
}
+void DocumentImpl::setTitle(DOMString title, NodeImpl *titleElement)
+{
+ if (!titleElement) {
+ // Title set by JavaScript -- overrides any title elements.
+ m_titleSetExplicitly = true;
+ if (m_titleElement) {
+ m_titleElement->deref();
+ m_titleElement = 0;
+ }
+ } else if (titleElement != m_titleElement) {
+ if (m_titleElement) {
+ // Only allow the first title element to change the title -- others have no effect.
+ return;
+ }
+ m_titleElement = titleElement;
+ titleElement->ref();
+ }
+
+ if (m_title == title)
+ return;
+
+ m_title = title;
+ updateTitle();
+}
+
+void DocumentImpl::removeTitle(NodeImpl *titleElement)
+{
+ if (m_titleElement != titleElement)
+ return;
+
+ // FIXME: Ideally we might want this to search for the first remaining title element, and use it.
+ m_titleElement = 0;
+
+ titleElement->deref();
+
+ if (!m_title.isEmpty()) {
+ m_title = "";
+ updateTitle();
+ }
+}
+
DOMString DocumentImpl::nodeName() const
{
return "#document";
1.104.6.3 +5 -1 WebCore/khtml/xml/dom_docimpl.h
Index: dom_docimpl.h
===================================================================
RCS file: /cvs/root/WebCore/khtml/xml/dom_docimpl.h,v
retrieving revision 1.104.6.2
retrieving revision 1.104.6.3
diff -u -r1.104.6.2 -r1.104.6.3
--- dom_docimpl.h 1 Jul 2005 22:36:04 -0000 1.104.6.2
+++ dom_docimpl.h 12 Jul 2005 18:29:05 -0000 1.104.6.3
@@ -201,7 +201,8 @@
// Actually part of HTMLDocument, but used for giving XML documents a window title as well
DOMString title() const { return m_title; }
- void setTitle(DOMString _title);
+ void setTitle(DOMString, NodeImpl *titleElement = 0);
+ void removeTitle(NodeImpl *titleElement);
// DOM methods overridden from parent classes
@@ -673,6 +674,8 @@
bool m_usesSiblingRules;
DOMString m_title;
+ bool m_titleSetExplicitly;
+ NodeImpl *m_titleElement;
RenderArena* m_renderArena;
@@ -744,6 +747,7 @@
void unregisterDisconnectedNodeWithEventListeners(NodeImpl *node);
private:
+ void updateTitle();
void removeAllDisconnectedNodeEventListeners();
JSEditor *jsEditor();
More information about the webkit-changes
mailing list