Changeset 189680 in webkit
- Timestamp:
- Sep 13, 2015 10:03:29 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/imported/w3c/ChangeLog
r189679 r189680 1 2015-09-13 Chris Dumez <cdumez@apple.com> 2 3 Document.title does not behave according to specification 4 https://bugs.webkit.org/show_bug.cgi?id=149098 5 6 Reviewed by Ryosuke Niwa. 7 8 Rebaseline several W3C tests now that more checks are passing. 9 10 * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-01-expected.txt: 11 * web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-02-expected.txt: 12 1 13 2015-09-13 Chris Dumez <cdumez@apple.com> 2 14 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-01-expected.txt
r189555 r189680 2 2 PASS document.title with head blown away 3 3 PASS document.title with head blown away 1 4 FAIL Untitled 2 assert_equals: expected "PASS" but got "" 5 FAIL PASS 3 assert_equals: expected "PASS2" but got "" 4 PASS Untitled 2 5 PASS PASS 3 6 6 -
trunk/LayoutTests/imported/w3c/web-platform-tests/html/dom/documents/dom-tree-accessors/document.title-02-expected.txt
r189555 r189680 2 2 PASS document.title with head blown away 3 3 PASS document.title with head blown away 1 4 FAIL Untitled 2 assert_equals: expected "PASS" but got "" 5 FAIL PASS 3 assert_equals: expected "PASS2" but got "" 4 PASS Untitled 2 5 PASS PASS 3 6 6 -
trunk/Source/WebCore/ChangeLog
r189679 r189680 1 2015-09-13 Chris Dumez <cdumez@apple.com> 2 3 Document.title does not behave according to specification 4 https://bugs.webkit.org/show_bug.cgi?id=149098 5 6 Reviewed by Ryosuke Niwa. 7 8 Update Document.title to behave according to the latest DOM specification: 9 https://html.spec.whatwg.org/multipage/dom.html#document.title 10 11 In particular, the following Web-Exposed changes were made: 12 1. The title Element should be the first title element in the document 13 (in tree order) [1]. Previously, WebKit would use the first title 14 Element *added* to the Document. Document.title returns the text 15 content of the title Element so this change is web-exposed. 16 2. If the title Element is replaced after the title has been set by the 17 JS (via the document.title setter), we should update the value 18 returned by the document.title getter. Previously, WebKit would set 19 a flag if the title was explicitly set by JS via document.title 20 setter and later title element changes would not override the title 21 set by the JS. This behavior isn't specified and does not match the 22 behavior of other browsers. 23 24 The new behavior is also consistent with the behavior of Firefox and 25 Chrome. 26 27 Some refactoring was made for the sake of clarity now that our 28 implementation has changed. See details below. 29 30 [1] https://html.spec.whatwg.org/multipage/dom.html#the-title-element-2 31 32 No new tests, already covered by existing tests. 33 34 * dom/Document.cpp: 35 (WebCore::Document::updateTitleFromTitleElement): 36 New convenience method that calls updateTitle() with the text of the 37 document's current title Element. If there is no title Element, it 38 clears the title. 39 40 (WebCore::Document::updateTitleElement): 41 Method which updates the Document's title Element whenever a title 42 Element is added or removed from the Document. Once the title Element 43 is updated, it takes care of calling updateTitleFromTitleElement() to 44 update the Document's title. 45 46 (WebCore::Document::titleElementAdded): 47 (WebCore::Document::titleElementRemoved): 48 (WebCore::Document::titleElementTextChanged): 49 New Document public API called by HTMLTitleElement / SVGTitleElement 50 whenever a title Element is added / removed from the Document or 51 whenever the title element's text has changed. These methods will 52 take care of calling updateTitleElement() / updateTitleFromTitleElement() 53 as necessary. 54 Previously, we would only have 2 methods: 55 - setTitleElement() which would be called whenever a title Element was 56 added to the document or when its text had changed. The name was 57 confusing because it would not necessarily set the document's title 58 Element and it would be used both for title element update and a 59 simple title update. This method has been split into 2: 60 titleElementAdded() and titleElementTextChanged(). 61 - removeTitle() which would be called whenever a title Element was 62 removed. The naming was confusing because it would not necessarily 63 remove the Document's title Element. This is now called 64 titleElementRemoved(). 65 66 * html/HTMLTitleElement.cpp: 67 (WebCore::HTMLTitleElement::insertedInto): 68 Call the new titleElementAdded() instead of setTitleElement(). 69 70 (WebCore::HTMLTitleElement::removedFrom): 71 Call the new titleElementRemoved() instead of removeTitle(). 72 73 (WebCore::HTMLTitleElement::childrenChanged): 74 Call the new titleElementTextChanged() instead of 75 setTitleElement() / removeTitle() as we don't really want 76 to remove or add a title Element. We merely want to notify 77 the document that the title element text has changed in 78 case it is the current title Element of the Document. 79 80 (WebCore::HTMLTitleElement::computedTextWithDirection): 81 Rename textWithDirection() to computedTextWithDirection() to 82 make it clear it is not a simple getter and make it private 83 as it is only used to set the m_title member which caches the 84 computed text. 85 86 * html/HTMLTitleElement.h: 87 Add new textWithDirection() getter which returns m_title. This 88 is needed so that Document can query the title of the Element. 89 Previously, HTMLTitleElement would pass directly m_title to 90 the Document when calling Document::setTitleElement(). 91 92 * svg/SVGTitleElement.cpp: 93 (WebCore::SVGTitleElement::insertedInto): 94 Call the new titleElementAdded() instead of setTitleElement(). 95 96 (WebCore::SVGTitleElement::removedFrom): 97 Call the new titleElementRemoved() instead of removeTitle(). 98 99 (WebCore::SVGTitleElement::childrenChanged): 100 Call the new titleElementTextChanged() instead of 101 setTitleElement(). 102 1 103 2015-09-13 Chris Dumez <cdumez@apple.com> 2 104 -
trunk/Source/WebCore/dom/Document.cpp
r189679 r189680 130 130 #include "SVGElementFactory.h" 131 131 #include "SVGNames.h" 132 #include "SVGTitleElement.h" 132 133 #include "SchemeRegistry.h" 133 134 #include "ScopedEventQueue.h" … … 454 455 , m_updateFocusAppearanceRestoresSelection(false) 455 456 , m_ignoreDestructiveWriteCount(0) 456 , m_titleSetExplicitly(false)457 457 , m_markers(std::make_unique<DocumentMarkerController>()) 458 458 , m_updateFocusAppearanceTimer(*this, &Document::updateFocusAppearanceTimerFired) … … 1533 1533 } 1534 1534 1535 void Document::updateTitleFromTitleElement() 1536 { 1537 if (!m_titleElement) { 1538 updateTitle(StringWithDirection()); 1539 return; 1540 } 1541 1542 if (is<HTMLTitleElement>(*m_titleElement)) 1543 updateTitle(downcast<HTMLTitleElement>(*m_titleElement).textWithDirection()); 1544 else if (is<SVGTitleElement>(*m_titleElement)) { 1545 // FIXME: does SVG have a title text direction? 1546 updateTitle(StringWithDirection(downcast<SVGTitleElement>(*m_titleElement).textContent(), LTR)); 1547 } 1548 } 1549 1535 1550 void Document::setTitle(const String& title) 1536 1551 { 1537 // Title set by JavaScript -- overrides any title elements.1538 m_titleSetExplicitly = true;1539 1552 if (!isHTMLDocument() && !isXHTMLDocument()) 1540 1553 m_titleElement = nullptr; … … 1554 1567 } 1555 1568 1556 void Document::setTitleElement(const StringWithDirection& title, Element* titleElement) 1557 { 1558 if (titleElement != m_titleElement) { 1559 if (m_titleElement || m_titleSetExplicitly) { 1560 // Only allow the first title element to change the title -- others have no effect. 1561 return; 1562 } 1563 m_titleElement = titleElement; 1564 } 1565 1566 updateTitle(title); 1567 } 1568 1569 void Document::removeTitle(Element* titleElement) 1570 { 1571 if (m_titleElement != titleElement) 1572 return; 1573 1574 m_titleElement = nullptr; 1575 m_titleSetExplicitly = false; 1576 1577 // Update title based on first title element in the head, if one exists. 1578 if (HTMLElement* headElement = head()) { 1579 if (auto firstTitle = childrenOfType<HTMLTitleElement>(*headElement).first()) 1580 setTitleElement(firstTitle->textWithDirection(), firstTitle); 1581 } 1582 1583 if (!m_titleElement) 1584 updateTitle(StringWithDirection()); 1569 void Document::updateTitleElement(Element* newTitleElement) 1570 { 1571 // Only allow the first title element in tree order to change the title -- others have no effect. 1572 if (m_titleElement) { 1573 if (isHTMLDocument() || isXHTMLDocument()) 1574 m_titleElement = descendantsOfType<HTMLTitleElement>(*this).first(); 1575 else if (isSVGDocument()) 1576 m_titleElement = descendantsOfType<SVGTitleElement>(*this).first(); 1577 } else 1578 m_titleElement = newTitleElement; 1579 1580 updateTitleFromTitleElement(); 1581 } 1582 1583 void Document::titleElementAdded(Element& titleElement) 1584 { 1585 if (m_titleElement == &titleElement) 1586 return; 1587 1588 updateTitleElement(&titleElement); 1589 } 1590 1591 void Document::titleElementRemoved(Element& titleElement) 1592 { 1593 if (m_titleElement != &titleElement) 1594 return; 1595 1596 updateTitleElement(nullptr); 1597 } 1598 1599 void Document::titleElementTextChanged(Element& titleElement) 1600 { 1601 if (m_titleElement != &titleElement) 1602 return; 1603 1604 updateTitleFromTitleElement(); 1585 1605 } 1586 1606 -
trunk/Source/WebCore/dom/Document.h
r189677 r189680 833 833 void setTitle(const String&); 834 834 835 void setTitleElement(const StringWithDirection&, Element* titleElement); 836 void removeTitle(Element* titleElement); 835 void titleElementAdded(Element& titleElement); 836 void titleElementRemoved(Element& titleElement); 837 void titleElementTextChanged(Element& titleElement); 837 838 838 839 String cookie(ExceptionCode&); … … 1288 1289 friend class IgnoreDestructiveWriteCountIncrementer; 1289 1290 1291 void updateTitleElement(Element* newTitleElement); 1292 1290 1293 void commonTeardown(); 1291 1294 … … 1321 1324 virtual double timerAlignmentInterval(bool hasReachedMaxNestingLevel) const override final; 1322 1325 1326 void updateTitleFromTitleElement(); 1323 1327 void updateTitle(const StringWithDirection&); 1324 1328 void updateFocusAppearanceTimerFired(); … … 1477 1481 StringWithDirection m_title; 1478 1482 StringWithDirection m_rawTitle; 1479 bool m_titleSetExplicitly;1480 1483 RefPtr<Element> m_titleElement; 1481 1484 -
trunk/Source/WebCore/html/HTMLTitleElement.cpp
r179143 r189680 54 54 HTMLElement::insertedInto(insertionPoint); 55 55 if (inDocument() && !isInShadowTree()) 56 document(). setTitleElement(m_title,this);56 document().titleElementAdded(*this); 57 57 return InsertionDone; 58 58 } … … 62 62 HTMLElement::removedFrom(insertionPoint); 63 63 if (insertionPoint.inDocument() && !insertionPoint.isInShadowTree()) 64 document(). removeTitle(this);64 document().titleElementRemoved(*this); 65 65 } 66 66 … … 68 68 { 69 69 HTMLElement::childrenChanged(change); 70 m_title = textWithDirection(); 71 if (inDocument()) { 72 if (!isInShadowTree()) 73 document().setTitleElement(m_title, this); 74 else 75 document().removeTitle(this); 76 } 70 m_title = computedTextWithDirection(); 71 document().titleElementTextChanged(*this); 77 72 } 78 73 … … 82 77 } 83 78 84 StringWithDirection HTMLTitleElement:: textWithDirection()79 StringWithDirection HTMLTitleElement::computedTextWithDirection() 85 80 { 86 81 TextDirection direction = LTR; -
trunk/Source/WebCore/html/HTMLTitleElement.h
r177996 r189680 35 35 void setText(const String&); 36 36 37 StringWithDirection textWithDirection();37 const StringWithDirection& textWithDirection() const { return m_title; } 38 38 39 39 private: … … 44 44 virtual void childrenChanged(const ChildChange&) override; 45 45 46 StringWithDirection computedTextWithDirection(); 47 46 48 StringWithDirection m_title; 47 49 }; -
trunk/Source/WebCore/svg/SVGTitleElement.cpp
r178048 r189680 44 44 return InsertionDone; 45 45 46 if (firstChild() && document().isSVGDocument()) { 47 // FIXME: does SVG have a title text direction? 48 document().setTitleElement(StringWithDirection(textContent(), LTR), this); 49 } 46 if (firstChild() && document().isSVGDocument()) 47 document().titleElementAdded(*this); 50 48 return InsertionDone; 51 49 } … … 55 53 SVGElement::removedFrom(rootParent); 56 54 if (rootParent.inDocument() && document().isSVGDocument()) 57 document(). removeTitle(this);55 document().titleElementRemoved(*this); 58 56 } 59 57 … … 61 59 { 62 60 SVGElement::childrenChanged(change); 63 if (inDocument() && document().isSVGDocument()) { 64 // FIXME: does SVG have title text direction? 65 document().setTitleElement(StringWithDirection(textContent(), LTR), this); 66 } 61 document().titleElementTextChanged(*this); 67 62 } 68 63
Note: See TracChangeset
for help on using the changeset viewer.