Changeset 215597 in webkit


Ignore:
Timestamp:
Apr 20, 2017, 6:00:46 PM (8 years ago)
Author:
[email protected]
Message:

Expose obscured insets to web content (as "safe area insets")
https://bugs.webkit.org/show_bug.cgi?id=171013
<rdar://problem/31564652>

Reviewed by Wenson Hsieh and Dave Hyatt.

Tests: fast/css/variables/constants/invalid-constant-name-fallback.html

fast/css/variables/constants/ios/safe-area-inset-set.html
fast/css/variables/constants/safe-area-inset-cannot-override.html
fast/css/variables/constants/safe-area-inset-zero.html

  • CMakeLists.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • css/CSSValueKeywords.in:
  • css/CSSVariableData.cpp:

(WebCore::CSSVariableData::checkVariablesForCyclesWithRange):
(WebCore::CSSVariableData::resolveTokenRange):

  • css/parser/CSSVariableParser.cpp:

(WebCore::isValidConstantName):
(WebCore::classifyBlock):
(WebCore::isValidConstantReference):
Add a constant() function, which takes both custom properties and
arbitrary idents which are looked up in ConstantPropertyMap, allowing
fallback from the arbitrary, UA-defined idents to custom properties.

  • dom/ConstantPropertyMap.cpp: Added.

(WebCore::ConstantPropertyMap::ConstantPropertyMap):
(WebCore::ConstantPropertyMap::values):
(WebCore::ConstantPropertyMap::nameForProperty):
(WebCore::ConstantPropertyMap::setValueForProperty):
(WebCore::ConstantPropertyMap::buildValues):
(WebCore::variableDataForSafeAreaInset):
(WebCore::ConstantPropertyMap::didChangeObscuredInsets):

  • dom/ConstantPropertyMap.h: Added.

Keep a mapping of UA-defined "constants", which can be looked up
from CSS via the aforementioned function. For now, this mapping
includes only safe-area-inset-{top, right, bottom, left}, which
expose the obscured insets (now that they can be painted into via
the viewport parameter clip-to-safe-area-inset=no).

  • dom/Document.cpp:

(WebCore::Document::Document):
(WebCore::Document::didChangeObscuredInsets):

  • dom/Document.h:

(WebCore::Document::constantProperties):

  • page/Page.cpp:

(WebCore::Page::setObscuredInsets):

  • page/Page.h:

(WebCore::Page::setObscuredInsets): Deleted.
Make setObscuredInsets and related storage not iOS-specific, though
nothing from the other platforms yet calls this code.

  • style/StyleResolveForDocument.cpp:

(WebCore::Style::resolveForDocument):
Grab the constant properties from ConstantPropertyMap and plop them into
the CustomPropertyValueMap. Constant properties aren't allowed to start
with --, and variable properties must, so there is no opportunity here
for exposing things to var() (or allowing custom properties to override
UA-defined constant properties).

  • TestExpectations:
  • fast/css/variables/constants/invalid-constant-name-fallback-expected.html: Added.
  • fast/css/variables/constants/invalid-constant-name-fallback.html: Added.
  • fast/css/variables/constants/ios/safe-area-inset-set-expected.html: Added.
  • fast/css/variables/constants/ios/safe-area-inset-set.html: Added.
  • fast/css/variables/constants/safe-area-inset-cannot-override-expected.html: Added.
  • fast/css/variables/constants/safe-area-inset-cannot-override.html: Added.
  • fast/css/variables/constants/safe-area-inset-zero-expected.html: Added.
  • fast/css/variables/constants/safe-area-inset-zero.html: Added.
  • platform/ios-wk2/TestExpectations:
Location:
trunk
Files:
12 added
14 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r215591 r215597  
     12017-04-20  Timothy Horton  <[email protected]>
     2
     3        Expose obscured insets to web content (as "safe area insets")
     4        https://bugs.webkit.org/show_bug.cgi?id=171013
     5        <rdar://problem/31564652>
     6
     7        Reviewed by Wenson Hsieh and Dave Hyatt.
     8
     9        * TestExpectations:
     10        * fast/css/variables/constants/invalid-constant-name-fallback-expected.html: Added.
     11        * fast/css/variables/constants/invalid-constant-name-fallback.html: Added.
     12        * fast/css/variables/constants/ios/safe-area-inset-set-expected.html: Added.
     13        * fast/css/variables/constants/ios/safe-area-inset-set.html: Added.
     14        * fast/css/variables/constants/safe-area-inset-cannot-override-expected.html: Added.
     15        * fast/css/variables/constants/safe-area-inset-cannot-override.html: Added.
     16        * fast/css/variables/constants/safe-area-inset-zero-expected.html: Added.
     17        * fast/css/variables/constants/safe-area-inset-zero.html: Added.
     18        * platform/ios-wk2/TestExpectations:
     19
    1202017-04-20  Ryan Haddad  <[email protected]>
    221
  • trunk/LayoutTests/TestExpectations

    r215590 r215597  
    3535media/controls/ipad [ Skip ]
    3636fast/text-autosizing [ Skip ]
     37fast/css/variables/constants/ios [ Skip ]
    3738
    3839# window.showModalDialog is only tested in DumpRenderTree on Mac.
  • trunk/LayoutTests/platform/ios-wk2/TestExpectations

    r215348 r215597  
    1515tiled-drawing/ios [ Pass ]
    1616editing/selection/character-granularity-rect.html [ Pass ]
     17fast/css/variables/constants/ios [ Pass ]
    1718
    1819fast/media/mq-inverted-colors-live-update.html [ Pass ]
  • trunk/Source/WebCore/CMakeLists.txt

    r215492 r215597  
    14541454    dom/ComposedTreeIterator.cpp
    14551455    dom/CompositionEvent.cpp
     1456    dom/ConstantPropertyMap.cpp
    14561457    dom/ContainerNode.cpp
    14571458    dom/ContainerNodeAlgorithms.cpp
  • trunk/Source/WebCore/ChangeLog

    r215588 r215597  
     12017-04-20  Timothy Horton  <[email protected]>
     2
     3        Expose obscured insets to web content (as "safe area insets")
     4        https://bugs.webkit.org/show_bug.cgi?id=171013
     5        <rdar://problem/31564652>
     6
     7        Reviewed by Wenson Hsieh and Dave Hyatt.
     8
     9        Tests: fast/css/variables/constants/invalid-constant-name-fallback.html
     10               fast/css/variables/constants/ios/safe-area-inset-set.html
     11               fast/css/variables/constants/safe-area-inset-cannot-override.html
     12               fast/css/variables/constants/safe-area-inset-zero.html
     13
     14        * CMakeLists.txt:
     15        * WebCore.xcodeproj/project.pbxproj:
     16        * css/CSSValueKeywords.in:
     17        * css/CSSVariableData.cpp:
     18        (WebCore::CSSVariableData::checkVariablesForCyclesWithRange):
     19        (WebCore::CSSVariableData::resolveTokenRange):
     20        * css/parser/CSSVariableParser.cpp:
     21        (WebCore::isValidConstantName):
     22        (WebCore::classifyBlock):
     23        (WebCore::isValidConstantReference):
     24        Add a constant() function, which takes both custom properties and
     25        arbitrary idents which are looked up in ConstantPropertyMap, allowing
     26        fallback from the arbitrary, UA-defined idents to custom properties.
     27
     28        * dom/ConstantPropertyMap.cpp: Added.
     29        (WebCore::ConstantPropertyMap::ConstantPropertyMap):
     30        (WebCore::ConstantPropertyMap::values):
     31        (WebCore::ConstantPropertyMap::nameForProperty):
     32        (WebCore::ConstantPropertyMap::setValueForProperty):
     33        (WebCore::ConstantPropertyMap::buildValues):
     34        (WebCore::variableDataForSafeAreaInset):
     35        (WebCore::ConstantPropertyMap::didChangeObscuredInsets):
     36        * dom/ConstantPropertyMap.h: Added.
     37        Keep a mapping of UA-defined "constants", which can be looked up
     38        from CSS via the aforementioned function. For now, this mapping
     39        includes only safe-area-inset-{top, right, bottom, left}, which
     40        expose the obscured insets (now that they can be painted into via
     41        the viewport parameter clip-to-safe-area-inset=no).
     42
     43        * dom/Document.cpp:
     44        (WebCore::Document::Document):
     45        (WebCore::Document::didChangeObscuredInsets):
     46        * dom/Document.h:
     47        (WebCore::Document::constantProperties):
     48        * page/Page.cpp:
     49        (WebCore::Page::setObscuredInsets):
     50        * page/Page.h:
     51        (WebCore::Page::setObscuredInsets): Deleted.
     52        Make setObscuredInsets and related storage not iOS-specific, though
     53        nothing from the other platforms yet calls this code.
     54
     55        * style/StyleResolveForDocument.cpp:
     56        (WebCore::Style::resolveForDocument):
     57        Grab the constant properties from ConstantPropertyMap and plop them into
     58        the CustomPropertyValueMap. Constant properties aren't allowed to start
     59        with --, and variable properties must, so there is no opportunity here
     60        for exposing things to var() (or allowing custom properties to override
     61        UA-defined constant properties).
     62
    1632017-04-20  Anders Carlsson  <[email protected]>
    264
  • trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj

    r215548 r215597  
    12591259                2D9BF74A1DBFDDFF007A7D99 /* JSMediaKeySessionCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2D9BF7481DBFDDF8007A7D99 /* JSMediaKeySessionCustom.cpp */; };
    12601260                2D9F0E1314FF1CBF00BA0FF7 /* linearSRGB.icc in Resources */ = {isa = PBXBuildFile; fileRef = 2D9F0E1214FF1CBF00BA0FF7 /* linearSRGB.icc */; };
     1261                2DAF343C1EA7E0F100382CD3 /* ConstantPropertyMap.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 2DAF343A1EA7E0F100382CD3 /* ConstantPropertyMap.cpp */; };
     1262                2DAF343D1EA7E0F100382CD3 /* ConstantPropertyMap.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DAF343B1EA7E0F100382CD3 /* ConstantPropertyMap.h */; };
    12611263                2DB9C4AA1B3231F40070F27F /* NSEventSPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DB9C4A91B3231F40070F27F /* NSEventSPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
    12621264                2DC4CF791D2DD98900ECCC94 /* DataDetectorsUISPI.h in Headers */ = {isa = PBXBuildFile; fileRef = 2DC4CF781D2DD98900ECCC94 /* DataDetectorsUISPI.h */; settings = {ATTRIBUTES = (Private, ); }; };
     
    88018803                2DAAE32C19DCAF6000E002D2 /* MockPageOverlayClient.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = MockPageOverlayClient.cpp; sourceTree = "<group>"; };
    88028804                2DAAE32D19DCAF6000E002D2 /* MockPageOverlayClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MockPageOverlayClient.h; sourceTree = "<group>"; };
     8805                2DAF343A1EA7E0F100382CD3 /* ConstantPropertyMap.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ConstantPropertyMap.cpp; sourceTree = "<group>"; };
     8806                2DAF343B1EA7E0F100382CD3 /* ConstantPropertyMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ConstantPropertyMap.h; sourceTree = "<group>"; };
    88038807                2DB9C4A91B3231F40070F27F /* NSEventSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NSEventSPI.h; sourceTree = "<group>"; };
    88048808                2DC4CF781D2DD98900ECCC94 /* DataDetectorsUISPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DataDetectorsUISPI.h; sourceTree = "<group>"; };
     
    2545625460                                79F2F59F1091939A000D87CB /* CompositionEvent.h */,
    2545725461                                79F2F5A01091939A000D87CB /* CompositionEvent.idl */,
     25462                                2DAF343A1EA7E0F100382CD3 /* ConstantPropertyMap.cpp */,
     25463                                2DAF343B1EA7E0F100382CD3 /* ConstantPropertyMap.h */,
    2545825464                                A81872140977D3C0005826D9 /* ContainerNode.cpp */,
    2545925465                                A81872110977D3C0005826D9 /* ContainerNode.h */,
     
    2648826494                                E1C94AF9191303F000D5A893 /* BlobPart.h in Headers */,
    2648926495                                7C77C3D11DEE472400A50BFA /* BlobPropertyBag.h in Headers */,
     26496                                2DAF343D1EA7E0F100382CD3 /* ConstantPropertyMap.h in Headers */,
    2649026497                                2EDEF1F5121B0EFC00726DB2 /* BlobRegistry.h in Headers */,
    2649126498                                2EDEF1F7121B0EFC00726DB2 /* BlobRegistryImpl.h in Headers */,
     
    3183331840                                BC17F9660B64EBB8004A65CB /* JSHTMLSelectElementCustom.cpp in Sources */,
    3183431841                                9B69D3B81B99100700E3512B /* JSHTMLSlotElement.cpp in Sources */,
     31842                                2DAF343C1EA7E0F100382CD3 /* ConstantPropertyMap.cpp in Sources */,
    3183531843                                E446143B0CD689CC00FADA75 /* JSHTMLSourceElement.cpp in Sources */,
    3183631844                                9752D38D1413104B003305BD /* JSHTMLSpanElement.cpp in Sources */,
  • trunk/Source/WebCore/css/CSSValueKeywords.in

    r215146 r215597  
    845845
    846846//
     847// UA Constants
     848//
     849constant
     850
     851//
    847852// CSS_PROP_BREAK_BEFORE/AFTER/INSIDE
    848853//
  • trunk/Source/WebCore/css/CSSVariableData.cpp

    r209666 r215597  
    102102{
    103103    while (!range.atEnd()) {
    104         if (range.peek().functionId() == CSSValueVar) {
     104        if (range.peek().functionId() == CSSValueVar || range.peek().functionId() == CSSValueConstant) {
    105105            CSSParserTokenRange block = range.consumeBlock();
    106106           
     
    172172    bool success = true;
    173173    while (!range.atEnd()) {
    174         if (range.peek().functionId() == CSSValueVar)
     174        if (range.peek().functionId() == CSSValueVar || range.peek().functionId() == CSSValueConstant)
    175175            success &= resolveVariableReference(customProperties, range.consumeBlock(), result);
    176176        else
  • trunk/Source/WebCore/css/parser/CSSVariableParser.cpp

    r208006 r215597  
    5050}
    5151
     52static bool isValidConstantName(const CSSParserToken& token)
     53{
     54    return token.type() == IdentToken;
     55}
     56
    5257bool isValidVariableReference(CSSParserTokenRange, bool& hasAtApplyRule);
     58bool isValidConstantReference(CSSParserTokenRange, bool& hasAtApplyRule);
    5359
    5460static bool classifyBlock(CSSParserTokenRange range, bool& hasReferences, bool& hasAtApplyRule, bool isTopLevelBlock = true)
     
    6066            if (token.functionId() == CSSValueVar) {
    6167                if (!isValidVariableReference(block, hasAtApplyRule))
     68                    return false; // Bail if any references are invalid
     69                hasReferences = true;
     70                continue;
     71            }
     72            if (token.functionId() == CSSValueConstant) {
     73                if (!isValidConstantReference(block, hasAtApplyRule))
    6274                    return false; // Bail if any references are invalid
    6375                hasReferences = true;
     
    123135}
    124136
     137bool isValidConstantReference(CSSParserTokenRange range, bool& hasAtApplyRule)
     138{
     139    range.consumeWhitespace();
     140    if (!isValidConstantName(range.consumeIncludingWhitespace()))
     141        return false;
     142    if (range.atEnd())
     143        return true;
     144
     145    if (range.consume().type() != CommaToken)
     146        return false;
     147    if (range.atEnd())
     148        return false;
     149
     150    bool hasReferences = false;
     151    return classifyBlock(range, hasReferences, hasAtApplyRule);
     152}
     153
    125154static CSSValueID classifyVariableRange(CSSParserTokenRange range, bool& hasReferences, bool& hasAtApplyRule)
    126155{
  • trunk/Source/WebCore/dom/Document.cpp

    r215486 r215597  
    4444#include "CommonVM.h"
    4545#include "CompositionEvent.h"
     46#include "ConstantPropertyMap.h"
    4647#include "ContentSecurityPolicy.h"
    4748#include "CookieJar.h"
     
    453454    , m_moduleLoader(std::make_unique<ScriptModuleLoader>(*this))
    454455    , m_xmlVersion(ASCIILiteral("1.0"))
     456    , m_constantPropertyMap(std::make_unique<ConstantPropertyMap>(*this))
    455457    , m_documentClasses(documentClasses)
    456458    , m_eventQueue(*this)
     
    20512053void Document::fontsNeedUpdate(FontSelector&)
    20522054{
     2055    invalidateMatchedPropertiesCacheAndForceStyleRecalc();
     2056}
     2057
     2058void Document::invalidateMatchedPropertiesCacheAndForceStyleRecalc()
     2059{
    20532060    if (auto* resolver = styleScope().resolverIfExists())
    20542061        resolver->invalidateMatchedPropertiesCache();
  • trunk/Source/WebCore/dom/Document.h

    r215486 r215597  
    7474class Attr;
    7575class CDATASection;
     76class CSSCustomPropertyValue;
    7677class CSSFontSelector;
    7778class CSSStyleDeclaration;
     
    8485class CharacterData;
    8586class Comment;
     87class ConstantPropertyMap;
    8688class DOMImplementation;
    8789class DOMNamedFlowCollection;
     
    12071209    DocumentSharedObjectPool* sharedObjectPool() { return m_sharedObjectPool.get(); }
    12081210
     1211    void invalidateMatchedPropertiesCacheAndForceStyleRecalc();
     1212
    12091213    void didRemoveAllPendingStylesheet();
    12101214    void didClearStyleResolver();
     
    13001304    void detachFromCachedFrame(CachedFrameBase&);
    13011305
     1306    ConstantPropertyMap& constantProperties() const { return *m_constantPropertyMap; }
     1307
    13021308protected:
    13031309    enum ConstructionFlags { Synthesized = 1, NonRenderedPlaceholder = 1 << 1 };
     
    15351541
    15361542    DocumentOrderedMap m_imagesByUsemap;
     1543
     1544    std::unique_ptr<ConstantPropertyMap> m_constantPropertyMap;
    15371545
    15381546    std::unique_ptr<SelectorQueryCache> m_selectorQueryCache;
  • trunk/Source/WebCore/page/Page.cpp

    r215582 r215597  
    3030#include "ChromeClient.h"
    3131#include "ClientRectList.h"
     32#include "ConstantPropertyMap.h"
    3233#include "ContextMenuClient.h"
    3334#include "ContextMenuController.h"
     
    22902291}
    22912292
     2293void Page::setObscuredInsets(const FloatBoxExtent& insets)
     2294{
     2295    if (m_obscuredInsets == insets)
     2296        return;
     2297
     2298    m_obscuredInsets = insets;
     2299
     2300    for (Frame* frame = &mainFrame(); frame; frame = frame->tree().traverseNext()) {
     2301        if (!frame->document())
     2302            continue;
     2303        frame->document()->constantProperties().didChangeObscuredInsets();
     2304    }
     2305}
     2306
    22922307#if ENABLE(DATA_INTERACTION)
    22932308
  • trunk/Source/WebCore/page/Page.h

    r215446 r215597  
    330330    WEBCORE_EXPORT void setTopContentInset(float);
    331331
     332    const FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; }
     333    WEBCORE_EXPORT void setObscuredInsets(const FloatBoxExtent&);
     334
    332335#if PLATFORM(IOS)
    333     const FloatBoxExtent& obscuredInsets() const { return m_obscuredInsets; }
    334     void setObscuredInsets(FloatBoxExtent insets) { m_obscuredInsets = insets; }
    335    
    336336    bool enclosedInScrollableAncestorView() const { return m_enclosedInScrollableAncestorView; }
    337337    void setEnclosedInScrollableAncestorView(bool f) { m_enclosedInScrollableAncestorView = f; }
     
    687687
    688688    float m_topContentInset;
     689    FloatBoxExtent m_obscuredInsets;
    689690
    690691#if PLATFORM(IOS)
    691     // This is only used for history scroll position restoration.
    692     FloatBoxExtent m_obscuredInsets;
    693692    bool m_enclosedInScrollableAncestorView { false };
    694693#endif
  • trunk/Source/WebCore/style/StyleResolveForDocument.cpp

    r210436 r215597  
    3131
    3232#include "CSSFontSelector.h"
     33#include "ConstantPropertyMap.h"
    3334#include "Document.h"
    3435#include "Frame.h"
     
    125126    documentStyle.fontCascade().update(&const_cast<Document&>(document).fontSelector());
    126127
     128    for (auto& it : document.constantProperties().values())
     129        documentStyle.setCustomPropertyValue(it.key, makeRef(it.value.get()));
     130
    127131    return documentStyle;
    128132}
Note: See TracChangeset for help on using the changeset viewer.