diff options
author | dominicc <dominicc@chromium.org> | 2015-11-17 01:20:30 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-11-17 09:21:27 +0000 |
commit | df022c0a2cdcfb98b5acadd982ade450d86b6864 (patch) | |
tree | fc9aa794806b38a01041dd020c1aa4da4fac2ec1 /third_party/WebKit | |
parent | f0c74ba417388d1e120713b12022299e3a0ca84e (diff) | |
download | chromium_src-df022c0a2cdcfb98b5acadd982ade450d86b6864.zip chromium_src-df022c0a2cdcfb98b5acadd982ade450d86b6864.tar.gz chromium_src-df022c0a2cdcfb98b5acadd982ade450d86b6864.tar.bz2 |
Setting link.sizes.value should be reflected in the sizes attribute.
BUG=545518
Committed: https://crrev.com/f3fec1337a6ae3433a378e2742d3d6e968970257
Cr-Commit-Position: refs/heads/master@{#360008}
Review URL: https://codereview.chromium.org/1435223002
Cr-Commit-Position: refs/heads/master@{#360040}
Diffstat (limited to 'third_party/WebKit')
10 files changed, 61 insertions, 15 deletions
diff --git a/third_party/WebKit/Source/core/dom/DOMSettableTokenList.cpp b/third_party/WebKit/Source/core/dom/DOMSettableTokenList.cpp index 6022a44b..c5940b2 100644 --- a/third_party/WebKit/Source/core/dom/DOMSettableTokenList.cpp +++ b/third_party/WebKit/Source/core/dom/DOMSettableTokenList.cpp @@ -97,7 +97,7 @@ void DOMSettableTokenList::setValue(const AtomicString& value) m_value = value; m_tokens.set(value, SpaceSplitString::ShouldNotFoldCase); if (m_observer) - m_observer->valueChanged(); + m_observer->valueWasSet(); } } // namespace blink diff --git a/third_party/WebKit/Source/core/dom/DOMSettableTokenList.h b/third_party/WebKit/Source/core/dom/DOMSettableTokenList.h index c03751b..a2f8db5 100644 --- a/third_party/WebKit/Source/core/dom/DOMSettableTokenList.h +++ b/third_party/WebKit/Source/core/dom/DOMSettableTokenList.h @@ -35,14 +35,16 @@ namespace blink { class ExceptionState; -class DOMSettableTokenListObserver : public WillBeGarbageCollectedMixin { +class CORE_EXPORT DOMSettableTokenListObserver : public WillBeGarbageCollectedMixin { public: - virtual void valueChanged() = 0; + // Called when the value property is set, even if the tokens in + // the set have not changed. + virtual void valueWasSet() = 0; DEFINE_INLINE_VIRTUAL_TRACE() { } }; -class DOMSettableTokenList final +class CORE_EXPORT DOMSettableTokenList final : public DOMTokenList #if !ENABLE(OILPAN) , public RefCounted<DOMSettableTokenList> diff --git a/third_party/WebKit/Source/core/dom/DOMTokenList.h b/third_party/WebKit/Source/core/dom/DOMTokenList.h index 2af89ca5..36b205a 100644 --- a/third_party/WebKit/Source/core/dom/DOMTokenList.h +++ b/third_party/WebKit/Source/core/dom/DOMTokenList.h @@ -36,7 +36,7 @@ namespace blink { class Element; class ExceptionState; -class DOMTokenList : public NoBaseWillBeGarbageCollectedFinalized<DOMTokenList>, public ScriptWrappable, public ValueIterable<String> { +class CORE_EXPORT DOMTokenList : public NoBaseWillBeGarbageCollectedFinalized<DOMTokenList>, public ScriptWrappable, public ValueIterable<String> { DEFINE_WRAPPERTYPEINFO(); USING_FAST_MALLOC_WILL_BE_REMOVED(DOMTokenList); WTF_MAKE_NONCOPYABLE(DOMTokenList); diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElement.cpp b/third_party/WebKit/Source/core/html/HTMLIFrameElement.cpp index cc61980..0cb90a4 100644 --- a/third_party/WebKit/Source/core/html/HTMLIFrameElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLIFrameElement.cpp @@ -169,7 +169,7 @@ bool HTMLIFrameElement::isInteractiveContent() const return true; } -void HTMLIFrameElement::valueChanged() +void HTMLIFrameElement::valueWasSet() { String invalidTokens; setSandboxFlags(m_sandbox->value().isNull() ? SandboxNone : parseSandboxPolicy(m_sandbox->tokens(), invalidTokens)); diff --git a/third_party/WebKit/Source/core/html/HTMLIFrameElement.h b/third_party/WebKit/Source/core/html/HTMLIFrameElement.h index df2a792..d127548 100644 --- a/third_party/WebKit/Source/core/html/HTMLIFrameElement.h +++ b/third_party/WebKit/Source/core/html/HTMLIFrameElement.h @@ -56,7 +56,7 @@ private: void didLoadNonEmptyDocument() override { m_didLoadNonEmptyDocument = true; } bool isInteractiveContent() const override; - void valueChanged() override; + void valueWasSet() override; ReferrerPolicy referrerPolicyAttribute() override; diff --git a/third_party/WebKit/Source/core/html/HTMLLinkElement.cpp b/third_party/WebKit/Source/core/html/HTMLLinkElement.cpp index c3a524b..4dd509e 100644 --- a/third_party/WebKit/Source/core/html/HTMLLinkElement.cpp +++ b/third_party/WebKit/Source/core/html/HTMLLinkElement.cpp @@ -140,7 +140,7 @@ void HTMLLinkElement::parseSizesAttribute(const AtomicString& value, Vector<IntS inline HTMLLinkElement::HTMLLinkElement(Document& document, bool createdByParser) : HTMLElement(linkTag, document) , m_linkLoader(this) - , m_sizes(DOMSettableTokenList::create()) + , m_sizes(DOMSettableTokenList::create(this)) , m_createdByParser(createdByParser) , m_isInShadowTree(false) { @@ -154,12 +154,11 @@ PassRefPtrWillBeRawPtr<HTMLLinkElement> HTMLLinkElement::create(Document& docume HTMLLinkElement::~HTMLLinkElement() { #if !ENABLE(OILPAN) + m_sizes->setObserver(nullptr); m_link.clear(); - if (inDocument()) document().styleEngine().removeStyleSheetCandidateNode(this); #endif - linkLoadEventSender().cancelEvent(this); } @@ -178,8 +177,6 @@ void HTMLLinkElement::parseAttribute(const QualifiedName& name, const AtomicStri process(); } else if (name == sizesAttr) { m_sizes->setValue(value); - parseSizesAttribute(value, m_iconSizes); - process(); } else if (name == mediaAttr) { m_media = value.lower(); process(); @@ -356,6 +353,14 @@ void HTMLLinkElement::didSendDOMContentLoadedForLinkPrerender() dispatchEvent(Event::create(EventTypeNames::webkitprerenderdomcontentloaded)); } +void HTMLLinkElement::valueWasSet() +{ + setSynchronizedLazyAttribute(HTMLNames::sizesAttr, m_sizes->value()); + m_iconSizes.clear(); + parseSizesAttribute(m_sizes->value(), m_iconSizes); + process(); +} + bool HTMLLinkElement::sheetLoaded() { ASSERT(linkStyle()); @@ -456,6 +461,7 @@ DEFINE_TRACE(HTMLLinkElement) visitor->trace(m_sizes); visitor->trace(m_linkLoader); HTMLElement::trace(visitor); + DOMSettableTokenListObserver::trace(visitor); } void HTMLLinkElement::attributeWillChange(const QualifiedName& name, const AtomicString& oldValue, const AtomicString& newValue) diff --git a/third_party/WebKit/Source/core/html/HTMLLinkElement.h b/third_party/WebKit/Source/core/html/HTMLLinkElement.h index ae55074..2d804e7 100644 --- a/third_party/WebKit/Source/core/html/HTMLLinkElement.h +++ b/third_party/WebKit/Source/core/html/HTMLLinkElement.h @@ -127,8 +127,9 @@ private: }; -class CORE_EXPORT HTMLLinkElement final : public HTMLElement, public LinkLoaderClient { +class CORE_EXPORT HTMLLinkElement final : public HTMLElement, public LinkLoaderClient, private DOMSettableTokenListObserver { DEFINE_WRAPPERTYPEINFO(); + WILL_BE_USING_GARBAGE_COLLECTED_MIXIN(HTMLLinkElement); public: static PassRefPtrWillBeRawPtr<HTMLLinkElement> create(Document&, bool createdByParser); ~HTMLLinkElement() override; @@ -181,6 +182,8 @@ public: DECLARE_VIRTUAL_TRACE(); private: + HTMLLinkElement(Document&, bool createdByParser); + void attributeWillChange(const QualifiedName&, const AtomicString& oldValue, const AtomicString& newValue) override; void parseAttribute(const QualifiedName&, const AtomicString&) override; @@ -210,8 +213,8 @@ private: void didSendLoadForLinkPrerender() override; void didSendDOMContentLoadedForLinkPrerender() override; -private: - HTMLLinkElement(Document&, bool createdByParser); + // From DOMSettableTokenListObserver + void valueWasSet() final; OwnPtrWillBeMember<LinkResource> m_link; LinkLoader m_linkLoader; diff --git a/third_party/WebKit/Source/core/html/HTMLLinkElementSizesAttributeTest.cpp b/third_party/WebKit/Source/core/html/HTMLLinkElementSizesAttributeTest.cpp index d7830ac..c0d4163 100644 --- a/third_party/WebKit/Source/core/html/HTMLLinkElementSizesAttributeTest.cpp +++ b/third_party/WebKit/Source/core/html/HTMLLinkElementSizesAttributeTest.cpp @@ -5,6 +5,9 @@ #include "config.h" #include "core/html/HTMLLinkElement.h" +#include "core/HTMLNames.h" +#include "core/dom/DOMSettableTokenList.h" +#include "core/dom/Document.h" #include <gtest/gtest.h> namespace blink { @@ -72,4 +75,25 @@ TEST(HTMLLinkElementSizesAttributeTest, parseSizes) ASSERT_EQ(0U, sizes.size()); } +TEST(HTMLLinkElementSizesAttributeTest, setSizesPropertyValue_updatesAttribute) +{ + RefPtrWillBeRawPtr<Document> document = Document::create(); + RefPtrWillBeRawPtr<HTMLLinkElement> link = HTMLLinkElement::create(*document, /* createdByParser: */ false); + RefPtrWillBeRawPtr<DOMSettableTokenList> sizes = link->sizes(); + EXPECT_EQ(nullAtom, sizes->value()); + sizes->setValue(" a b c "); + EXPECT_EQ(" a b c ", link->getAttribute(HTMLNames::sizesAttr)); + EXPECT_EQ(" a b c ", sizes->value()); +} + +TEST(HTMLLinkElementSizesAttributeTest, setSizesAttribute_updatesSizesPropertyValue) +{ + RefPtrWillBeRawPtr<Document> document = Document::create(); + RefPtrWillBeRawPtr<HTMLLinkElement> link = HTMLLinkElement::create(*document, /* createdByParser: */ false); + RefPtrWillBeRawPtr<DOMSettableTokenList> sizes = link->sizes(); + EXPECT_EQ(nullAtom, sizes->value()); + link->setAttribute(HTMLNames::sizesAttr, "y x "); + EXPECT_EQ("y x ", sizes->value()); +} + } // namespace blink diff --git a/third_party/WebKit/Source/wtf/testing/WTFTestPrinters.cpp b/third_party/WebKit/Source/wtf/testing/WTFTestPrinters.cpp index 19586bb..1ad3888 100644 --- a/third_party/WebKit/Source/wtf/testing/WTFTestPrinters.cpp +++ b/third_party/WebKit/Source/wtf/testing/WTFTestPrinters.cpp @@ -30,6 +30,7 @@ #include "config.h" +#include "wtf/text/AtomicString.h" #include "wtf/text/WTFString.h" #include <ostream> // NOLINT @@ -78,4 +79,9 @@ std::ostream& operator<<(std::ostream& out, const String& string) return out << '"'; } +std::ostream& operator<<(std::ostream& out, const AtomicString& s) +{ + return out << s.string(); +} + } // namespace WTF diff --git a/third_party/WebKit/Source/wtf/text/AtomicString.h b/third_party/WebKit/Source/wtf/text/AtomicString.h index 3a7c995..0a83aa7 100644 --- a/third_party/WebKit/Source/wtf/text/AtomicString.h +++ b/third_party/WebKit/Source/wtf/text/AtomicString.h @@ -23,8 +23,10 @@ #include "wtf/HashTableDeletedValueType.h" #include "wtf/WTFExport.h" +#include "wtf/testing/WTFUnitTestHelpersExport.h" #include "wtf/text/CString.h" #include "wtf/text/WTFString.h" +#include <iosfwd> namespace WTF { @@ -241,6 +243,9 @@ template<> struct DefaultHash<AtomicString> { typedef AtomicStringHash Hash; }; +// Pretty printer for gtest. +WTF_UNITTEST_HELPERS_EXPORT std::ostream& operator<<(std::ostream&, const AtomicString&); + } // namespace WTF WTF_ALLOW_MOVE_INIT_AND_COMPARE_WITH_MEM_FUNCTIONS(AtomicString); |