Changeset 238946 in webkit


Ignore:
Timestamp:
Dec 6, 2018 5:35:25 PM (5 years ago)
Author:
commit-queue@webkit.org
Message:

We should ignore minimumEffectiveDeviceWidth if the page specifies device-width in viewport meta-tag.
https://bugs.webkit.org/show_bug.cgi?id=192377
<rdar://problem/46364206>

Patch by Yongjun Zhang <yongjun_zhang@apple.com> on 2018-12-06
Reviewed by Tim Horton.

Source/WebCore:

If the page specifies width=device-width or initial-scale=1 in the viewport meta tag, we should use the
native device width and ignore the minimum effective device width in ViewportConfiguration. The patch
also introduces scalableNativeWebpageParameters() which uses the device width as default and also allows the page
to shrink-to-fit. If a page doesn't have viewport meta tag, or if the width argument isn't device-width
and the initial scale isn't 1, we will use scalableNativeWebpageParameters() as the default configuration.

Tests: fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width.html

fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta.html

  • page/ViewportConfiguration.cpp:

(WebCore::ViewportConfiguration::updateDefaultConfiguration): pick the default configuration based on

the page's viewport arguments. Also, we will always fall back to scalableNativeWebpageParameters() if we
can ignore scaling constraints.

(WebCore::ViewportConfiguration::setViewportArguments): When page sends us new ViewportArguments, pick

up the correponsding default configuration before updating the configuration.

(WebCore::ViewportConfiguration::setCanIgnoreScalingConstraints): When m_canIgnoreScalingConstraints is

changed, try to pick up the correponsding default configuration.

(WebCore::ViewportConfiguration::scalableNativeWebpageParameters): Add a new default set of viewport Parameters

this is very close to nativeWebpageParameters() excpet that it allows shrink to fit and its minimum scale
is 0.25. We will use this Parameters for pages that doesn't have viewport meta tag; or the width is
not device-width and initial scale is not 1.

(WebCore::ViewportConfiguration::updateConfiguration): If the page's viewport argument doesn't override

the default width, use the m_minimumLayoutSize.width().

  • page/ViewportConfiguration.h:

(WebCore::ViewportConfiguration::shouldIgnoreMinimumEffectiveDeviceWidth const): A helper method to tell

if we should avoid using minimum effective device width.

(WebCore::ViewportConfiguration::canOverrideConfigurationParameters const): If we are using a default

configuration that is neither nativeWebpageParameters() nor scalableNativeWebpageParameters(), don't override
it.

(WebCore::ViewportConfiguration::minimumEffectiveDeviceWidth const): Add a helper method to return minimum

effective device width based on shouldIgnoreMinimumEffectiveDeviceWidth().

(WebCore::ViewportConfiguration::effectiveLayoutSizeScaleFactor const): Use minimumEffectiveDeviceWidth().

Source/WebKit:

Since we are using page's viewport arguments to decide the default viewport parameters and
whether we can use mininum effective device width, we should always call setViewportArguments()
regardless of shouldIgnoreMetaViewport settings.

  • WebProcess/WebPage/WebPage.cpp:

(WebKit::WebPage::viewportPropertiesDidChange): Always call setViewportArguments().
(WebKit::WebPage::didCommitLoad): Ditto.

LayoutTests:

  • fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width-expected.txt: Added.
  • fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width.html: Added.
  • fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta-expected.txt: Added.
  • fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta.html: Added.
Location:
trunk
Files:
4 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r238939 r238946  
     12018-12-06  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should ignore minimumEffectiveDeviceWidth if the page specifies device-width in viewport meta-tag.
     4        https://bugs.webkit.org/show_bug.cgi?id=192377
     5        <rdar://problem/46364206>
     6
     7        Reviewed by Tim Horton.
     8
     9        * fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width-expected.txt: Added.
     10        * fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width.html: Added.
     11        * fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta-expected.txt: Added.
     12        * fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta.html: Added.
     13
    1142018-12-06  Wenson Hsieh  <wenson_hsieh@apple.com>
    215
  • trunk/Source/WebCore/ChangeLog

    r238942 r238946  
     12018-12-06  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should ignore minimumEffectiveDeviceWidth if the page specifies device-width in viewport meta-tag.
     4        https://bugs.webkit.org/show_bug.cgi?id=192377
     5        <rdar://problem/46364206>
     6
     7        Reviewed by Tim Horton.
     8
     9        If the page specifies width=device-width or initial-scale=1 in the viewport meta tag, we should use the
     10        native device width and ignore the minimum effective device width in ViewportConfiguration. The patch
     11        also introduces scalableNativeWebpageParameters() which uses the device width as default and also allows the page
     12        to shrink-to-fit. If a page doesn't have viewport meta tag, or if the width argument isn't device-width
     13        and the initial scale isn't 1, we will use scalableNativeWebpageParameters() as the default configuration.
     14
     15        Tests: fast/viewport/ios/ignore-minimum-device-width-for-page-with-viewport-device-width.html
     16               fast/viewport/ios/use-minimum-device-width-for-page-without-viewport-meta.html
     17
     18        * page/ViewportConfiguration.cpp:
     19        (WebCore::ViewportConfiguration::updateDefaultConfiguration): pick the default configuration based on
     20            the page's viewport arguments. Also, we will always fall back to scalableNativeWebpageParameters() if we
     21            can ignore scaling constraints.
     22        (WebCore::ViewportConfiguration::setViewportArguments): When page sends us new ViewportArguments, pick
     23            up the correponsding default configuration before updating the configuration.
     24        (WebCore::ViewportConfiguration::setCanIgnoreScalingConstraints): When m_canIgnoreScalingConstraints is
     25            changed, try to pick up the correponsding default configuration.
     26        (WebCore::ViewportConfiguration::scalableNativeWebpageParameters): Add a new default set of viewport Parameters
     27            this is very close to nativeWebpageParameters() excpet that it allows shrink to fit and its minimum scale
     28            is 0.25. We will use this Parameters for pages that doesn't have viewport meta tag; or the width is
     29            not device-width and initial scale is not 1.
     30        (WebCore::ViewportConfiguration::updateConfiguration): If the page's viewport argument doesn't override
     31            the default width, use the m_minimumLayoutSize.width().
     32        * page/ViewportConfiguration.h:
     33        (WebCore::ViewportConfiguration::shouldIgnoreMinimumEffectiveDeviceWidth const): A helper method to tell
     34            if we should avoid using minimum effective device width.
     35        (WebCore::ViewportConfiguration::canOverrideConfigurationParameters const): If we are using a default
     36            configuration that is neither nativeWebpageParameters() nor scalableNativeWebpageParameters(), don't override
     37            it.
     38        (WebCore::ViewportConfiguration::minimumEffectiveDeviceWidth const): Add a helper method to return minimum
     39            effective device width based on shouldIgnoreMinimumEffectiveDeviceWidth().
     40        (WebCore::ViewportConfiguration::effectiveLayoutSizeScaleFactor const): Use minimumEffectiveDeviceWidth().
     41
    1422018-12-06  Adrian Perez de Castro  <aperez@igalia.com>
    243
  • trunk/Source/WebCore/page/ViewportConfiguration.cpp

    r238623 r238946  
    144144}
    145145
     146bool ViewportConfiguration::canOverrideConfigurationParameters() const
     147{
     148    return m_defaultConfiguration == ViewportConfiguration::nativeWebpageParameters() || m_defaultConfiguration == ViewportConfiguration::scalableNativeWebpageParameters();
     149}
     150
     151void ViewportConfiguration::updateDefaultConfiguration()
     152{
     153    if (!canOverrideConfigurationParameters())
     154        return;
     155
     156    if (m_canIgnoreScalingConstraints) {
     157        m_defaultConfiguration = ViewportConfiguration::scalableNativeWebpageParameters();
     158        return;
     159    }
     160
     161    if (shouldIgnoreMinimumEffectiveDeviceWidth())
     162        m_defaultConfiguration = ViewportConfiguration::nativeWebpageParameters();
     163    else
     164        m_defaultConfiguration = ViewportConfiguration::scalableNativeWebpageParameters();
     165}
     166
    146167bool ViewportConfiguration::setViewportArguments(const ViewportArguments& viewportArguments)
    147168{
     
    152173    m_viewportArguments = viewportArguments;
    153174
     175    updateDefaultConfiguration();
    154176    updateMinimumLayoutSize();
    155177    updateConfiguration();
     
    163185   
    164186    m_canIgnoreScalingConstraints = canIgnoreScalingConstraints;
     187    updateDefaultConfiguration();
    165188    updateConfiguration();
    166189    return true;
     
    326349}
    327350
     351ViewportConfiguration::Parameters ViewportConfiguration::scalableNativeWebpageParameters()
     352{
     353    Parameters parameters = ViewportConfiguration::nativeWebpageParameters();
     354    parameters.allowsShrinkToFit = true;
     355    parameters.minimumScale = 0.25;
     356    return parameters;
     357}
     358
    328359ViewportConfiguration::Parameters ViewportConfiguration::webpageParameters()
    329360{
     
    448479    else if (booleanViewportArgumentIsSet(m_viewportArguments.shrinkToFit))
    449480        m_configuration.allowsShrinkToFit = m_viewportArguments.shrinkToFit != 0.;
     481
     482    if (canOverrideConfigurationParameters() && !viewportArgumentsOverridesWidth)
     483        m_configuration.width = m_minimumLayoutSize.width();
    450484
    451485    m_configuration.avoidsUnsafeArea = m_viewportArguments.viewportFit != ViewportFit::Cover;
  • trunk/Source/WebCore/page/ViewportConfiguration.h

    r238623 r238946  
    104104    // Matches a width=device-width, initial-scale=1 viewport.
    105105    WEBCORE_EXPORT static Parameters nativeWebpageParameters();
     106    static Parameters scalableNativeWebpageParameters();
    106107    WEBCORE_EXPORT static Parameters webpageParameters();
    107108    WEBCORE_EXPORT static Parameters textDocumentParameters();
     
    127128    bool shouldIgnoreVerticalScalingConstraints() const;
    128129    bool shouldIgnoreHorizontalScalingConstraints() const;
     130    void updateDefaultConfiguration();
     131    bool canOverrideConfigurationParameters() const;
     132
     133    constexpr bool shouldIgnoreMinimumEffectiveDeviceWidth() const
     134    {
     135        if (m_canIgnoreScalingConstraints)
     136            return true;
     137
     138        if (m_viewportArguments == ViewportArguments())
     139            return false;
     140
     141        if (m_viewportArguments.width == ViewportArguments::ValueDeviceWidth || m_viewportArguments.zoom == 1.)
     142            return true;
     143
     144        return false;
     145    }
     146
     147    constexpr double minimumEffectiveDeviceWidth() const
     148    {
     149        if (shouldIgnoreMinimumEffectiveDeviceWidth())
     150            return 0;
     151        return m_minimumEffectiveDeviceWidth;
     152    }
    129153
    130154    constexpr double forceAlwaysUserScalableMaximumScale() const
     
    142166    constexpr double effectiveLayoutSizeScaleFactor() const
    143167    {
    144         if (!m_viewLayoutSize.width() || !m_minimumEffectiveDeviceWidth)
     168        if (!m_viewLayoutSize.width() || !minimumEffectiveDeviceWidth())
    145169            return m_layoutSizeScaleFactor;
    146         return m_layoutSizeScaleFactor * m_viewLayoutSize.width() / std::max<double>(m_minimumEffectiveDeviceWidth, m_viewLayoutSize.width());
     170        return m_layoutSizeScaleFactor * m_viewLayoutSize.width() / std::max<double>(minimumEffectiveDeviceWidth(), m_viewLayoutSize.width());
    147171    }
    148172
  • trunk/Source/WebKit/ChangeLog

    r238941 r238946  
     12018-12-06  Yongjun Zhang  <yongjun_zhang@apple.com>
     2
     3        We should ignore minimumEffectiveDeviceWidth if the page specifies device-width in viewport meta-tag.
     4        https://bugs.webkit.org/show_bug.cgi?id=192377
     5        <rdar://problem/46364206>
     6
     7        Reviewed by Tim Horton.
     8
     9        Since we are using page's viewport arguments to decide the default viewport parameters and
     10        whether we can use mininum effective device width, we should always call setViewportArguments()
     11        regardless of shouldIgnoreMetaViewport settings.
     12
     13        * WebProcess/WebPage/WebPage.cpp:
     14        (WebKit::WebPage::viewportPropertiesDidChange): Always call setViewportArguments().
     15        (WebKit::WebPage::didCommitLoad): Ditto.
     16
    1172018-12-06  Tim Horton  <timothy_horton@apple.com>
    218
  • trunk/Source/WebKit/WebProcess/WebPage/WebPage.cpp

    r238939 r238946  
    19331933{
    19341934#if PLATFORM(IOS_FAMILY)
    1935     if (!m_page->settings().shouldIgnoreMetaViewport() && m_viewportConfiguration.setViewportArguments(viewportArguments))
     1935    if (m_viewportConfiguration.setViewportArguments(viewportArguments))
    19361936        viewportConfigurationChanged();
    19371937#endif
     
    55485548        viewportChanged = true;
    55495549
    5550     if (!m_page->settings().shouldIgnoreMetaViewport() && m_viewportConfiguration.setViewportArguments(coreFrame->document()->viewportArguments()))
     5550    if (m_viewportConfiguration.setViewportArguments(coreFrame->document()->viewportArguments()))
    55515551        viewportChanged = true;
    55525552
Note: See TracChangeset for help on using the changeset viewer.