Add a settings to disallow initializing background-size if background shorthand doesn't include it.

https://bugs.webkit.org/show_bug.cgi?id=113363

Source/WebCore:

Patch by KyungTae Kim <ktf.kim@samsung.com> and Yongjun Zhang <yongjun_zhang@apple.com> on 2013-03-27
Reviewed by David Kilzer.

This is based on KyungTae Kim's patch in https://bugs.webkit.org/show_bug.cgi?id=97761.  Many legacy sites set
background-size first and then set background for setting background-image.  For backward-compatibility
in some WebKit based clients, if 'background' shorthand have no 'background-size' attribute, we could add
a settings to let the css parser not initialize 'background-size'.

Test: fast/backgrounds/background-shorthand-after-set-backgroundSize.html

* css/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext): initialize useLegacyBackgroundSizeShorthandBehavior.
(WebCore::operator==):
(WebCore::CSSParser::useLegacyBackgroundSizeShorthandBehavior): add a method to return if we want background-size
    to be initialized by background shorthand.
(WebCore):
(WebCore::CSSParser::parseFillShorthand): don't initialize background-size in background shorthand if we have
    useLegacyBackgroundSizeShorthandBehavior set to true.
* css/CSSParser.h:
(CSSParser):
* css/CSSParserMode.h: add member useLegacyBackgroundSizeShorthandBehavior to CSSParserContext.
(CSSParserContext):
* page/Settings.in: initialize useLegacyBackgroundSizeShorthandBehavior to false.
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup): add the new settings useLegacyBackgroundSizeShorthandBehavior to Backup.
(WebCore::InternalSettings::Backup::restoreTo): restore useLegacyBackgroundSizeShorthandBehavior from Backup.
(WebCore::InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior):
(WebCore):
* testing/InternalSettings.h:
(Backup):
(InternalSettings):
* testing/InternalSettings.idl: add a JS testing API setUseLegacyBackgroundSizeShorthandBehavior to turn on/off
    the new settings.

LayoutTests:

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2013-03-27
Reviewed by David Kilzer.

Add test for the new settings useLegacyBackgroundSizeShorthandBehavior.

* fast/backgrounds/background-shorthand-after-set-backgroundSize-expected.txt: Added.
* fast/backgrounds/background-shorthand-after-set-backgroundSize.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@147034 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 09211e93
2013-03-27 Yongjun Zhang <yongjun_zhang@apple.com>
Add a settings to disallow initializing background-size if background shorthand doesn't include it.
https://bugs.webkit.org/show_bug.cgi?id=113363
Reviewed by David Kilzer.
Add test for the new settings useLegacyBackgroundSizeShorthandBehavior.
* fast/backgrounds/background-shorthand-after-set-backgroundSize-expected.txt: Added.
* fast/backgrounds/background-shorthand-after-set-backgroundSize.html: Added.
2013-03-27 Andrey Lushnikov <lushnikov@chromium.org>
Web Inspector: [DTE] implement "tokenAtTextPosition" method
Tests a flag to make background shorthand property not override background-size when it's already set.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS e.style.background is 'url(dummy://test.png) 50% 50% / cover no-repeat border-box border-box red'
PASS e.style.backgroundSize is 'cover'
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE html>
<html>
<script src="../js/resources/js-test-pre.js"></script>
<div id="test"> </div>
<script>
description("Tests a flag to make background shorthand property not override background-size when it's already set.");
var e = document.getElementById('test');
if (window.internals) {
window.internals.settings.setUseLegacyBackgroundSizeShorthandBehavior(true);
e.style.backgroundSize = "cover";
e.style.background = "center red url(dummy://test.png) no-repeat border-box";
shouldBe("e.style.background", "'url(dummy://test.png) 50% 50% / cover no-repeat border-box border-box red'")
shouldBe("e.style.backgroundSize", "'cover'");
debug("")
window.internals.settings.setUseLegacyBackgroundSizeShorthandBehavior(false);
}
</script>
<script src="../js/resources/js-test-post.js"></script>
</body>
</html>
2013-03-27 KyungTae Kim <ktf.kim@samsung.com> and Yongjun Zhang <yongjun_zhang@apple.com>
Add a settings to disallow initializing background-size if background shorthand doesn't include it.
https://bugs.webkit.org/show_bug.cgi?id=113363
Reviewed by David Kilzer.
This is based on KyungTae Kim's patch in https://bugs.webkit.org/show_bug.cgi?id=97761. Many legacy sites set
background-size first and then set background for setting background-image. For backward-compatibility
in some WebKit based clients, if 'background' shorthand have no 'background-size' attribute, we could add
a settings to let the css parser not initialize 'background-size'.
Test: fast/backgrounds/background-shorthand-after-set-backgroundSize.html
* css/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext): initialize useLegacyBackgroundSizeShorthandBehavior.
(WebCore::operator==):
(WebCore::CSSParser::useLegacyBackgroundSizeShorthandBehavior): add a method to return if we want background-size
to be initialized by background shorthand.
(WebCore):
(WebCore::CSSParser::parseFillShorthand): don't initialize background-size in background shorthand if we have
useLegacyBackgroundSizeShorthandBehavior set to true.
* css/CSSParser.h:
(CSSParser):
* css/CSSParserMode.h: add member useLegacyBackgroundSizeShorthandBehavior to CSSParserContext.
(CSSParserContext):
* page/Settings.in: initialize useLegacyBackgroundSizeShorthandBehavior to false.
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::Backup::Backup): add the new settings useLegacyBackgroundSizeShorthandBehavior to Backup.
(WebCore::InternalSettings::Backup::restoreTo): restore useLegacyBackgroundSizeShorthandBehavior from Backup.
(WebCore::InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior):
(WebCore):
* testing/InternalSettings.h:
(Backup):
(InternalSettings):
* testing/InternalSettings.idl: add a JS testing API setUseLegacyBackgroundSizeShorthandBehavior to turn on/off
the new settings.
2013-03-27 Florin Malita <fmalita@chromium.org>
Remove unused RenderLayer::renderBox{X,Y} methods
......@@ -265,6 +265,7 @@ CSSParserContext::CSSParserContext(CSSParserMode mode, const KURL& baseURL)
#endif
, needsSiteSpecificQuirks(false)
, enforcesCSSMIMETypeInNoQuirksMode(true)
, useLegacyBackgroundSizeShorthandBehavior(false)
{
}
......@@ -283,6 +284,7 @@ CSSParserContext::CSSParserContext(Document* document, const KURL& baseURL, cons
#endif
, needsSiteSpecificQuirks(document->settings() ? document->settings()->needsSiteSpecificQuirks() : false)
, enforcesCSSMIMETypeInNoQuirksMode(!document->settings() || document->settings()->enforceCSSMIMETypeInNoQuirksMode())
, useLegacyBackgroundSizeShorthandBehavior(document->settings() ? document->settings()->useLegacyBackgroundSizeShorthandBehavior() : false)
{
}
......@@ -301,7 +303,8 @@ bool operator==(const CSSParserContext& a, const CSSParserContext& b)
&& a.isCSSVariablesEnabled == b.isCSSVariablesEnabled
#endif
&& a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
&& a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode;
&& a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
&& a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior;
}
CSSParser::CSSParser(const CSSParserContext& context)
......@@ -3126,6 +3129,11 @@ static bool parseBackgroundClip(CSSParserValue* parserValue, RefPtr<CSSValue>& c
return false;
}
bool CSSParser::useLegacyBackgroundSizeShorthandBehavior() const
{
return m_context.useLegacyBackgroundSizeShorthandBehavior;
}
const int cMaxFillProperties = 9;
bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* properties, int numProperties, bool important)
......@@ -3257,6 +3265,8 @@ bool CSSParser::parseFillShorthand(CSSPropertyID propId, const CSSPropertyID* pr
} else if ((properties[i] == CSSPropertyBackgroundClip || properties[i] == CSSPropertyWebkitMaskClip) && !foundClip)
// Value is already set while updating origin
continue;
else if (properties[i] == CSSPropertyBackgroundSize && !parsedProperty[i] && useLegacyBackgroundSizeShorthandBehavior())
continue;
else
addProperty(properties[i], values[i].release(), important);
......
......@@ -597,6 +597,8 @@ private:
bool m_inViewport;
#endif
bool useLegacyBackgroundSizeShorthandBehavior() const;
int (CSSParser::*m_lexFunc)(void*);
Vector<RefPtr<StyleRuleBase> > m_parsedRules;
......
......@@ -74,6 +74,7 @@ public:
#endif
bool needsSiteSpecificQuirks;
bool enforcesCSSMIMETypeInNoQuirksMode;
bool useLegacyBackgroundSizeShorthandBehavior;
};
bool operator==(const CSSParserContext&, const CSSParserContext&);
......
......@@ -206,3 +206,4 @@ smartInsertDeleteEnabled initial=defaultSmartInsertDeleteEnabled
selectTrailingWhitespaceEnabled initial=defaultSelectTrailingWhitespaceEnabled
selectionIncludesAltImageText initial=false
useLegacyBackgroundSizeShorthandBehavior initial=false
......@@ -98,6 +98,7 @@ InternalSettings::Backup::Backup(Settings* settings)
#endif
, m_defaultVideoPosterURL(settings->defaultVideoPosterURL())
, m_originalTimeWithoutMouseMovementBeforeHidingControls(settings->timeWithoutMouseMovementBeforeHidingControls())
, m_useLegacyBackgroundSizeShorthandBehavior(settings->useLegacyBackgroundSizeShorthandBehavior())
{
}
......@@ -135,6 +136,7 @@ void InternalSettings::Backup::restoreTo(Settings* settings)
#endif
settings->setDefaultVideoPosterURL(m_defaultVideoPosterURL);
settings->setTimeWithoutMouseMovementBeforeHidingControls(m_originalTimeWithoutMouseMovementBeforeHidingControls);
settings->setUseLegacyBackgroundSizeShorthandBehavior(m_useLegacyBackgroundSizeShorthandBehavior);
}
// We can't use RefCountedSupplement because that would try to make InternalSettings RefCounted
......@@ -491,4 +493,10 @@ void InternalSettings::setTimeWithoutMouseMovementBeforeHidingControls(double ti
settings()->setTimeWithoutMouseMovementBeforeHidingControls(time);
}
void InternalSettings::setUseLegacyBackgroundSizeShorthandBehavior(bool enabled, ExceptionCode& ec)
{
InternalSettingsGuardForSettings();
settings()->setUseLegacyBackgroundSizeShorthandBehavior(enabled);
}
}
......@@ -83,6 +83,7 @@ public:
#endif
String m_defaultVideoPosterURL;
bool m_originalTimeWithoutMouseMovementBeforeHidingControls;
bool m_useLegacyBackgroundSizeShorthandBehavior;
};
static PassRefPtr<InternalSettings> create(Page* page)
......@@ -127,6 +128,7 @@ public:
void setMinimumTimerInterval(double intervalInSeconds, ExceptionCode&);
void setDefaultVideoPosterURL(const String& url, ExceptionCode&);
void setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode&);
void setUseLegacyBackgroundSizeShorthandBehavior(bool enabled, ExceptionCode&);
private:
explicit InternalSettings(Page*);
......
......@@ -59,4 +59,5 @@
void setMinimumTimerInterval(in double intervalInSeconds) raises(DOMException);
void setDefaultVideoPosterURL(in DOMString poster) raises(DOMException);
void setTimeWithoutMouseMovementBeforeHidingControls(in double time) raises(DOMException);
void setUseLegacyBackgroundSizeShorthandBehavior(in boolean enabled) raises(DOMException);
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment