Changeset 208886 in webkit


Ignore:
Timestamp:
Nov 18, 2016, 11:09:13 AM (9 years ago)
Author:
[email protected]
Message:

[CSS Parser] Hook up InspectorStyleSheet to the new CSS parser.
https://bugs.webkit.org/show_bug.cgi?id=164886

Reviewed by Dean Jackson.

  • css/CSSGrammar.y.in:

Get rid of the CSSRuleSourceData type enum, since StyleRule's type
enum is exactly the same.

  • css/CSSPropertySourceData.cpp:

(WebCore::CSSPropertySourceData::CSSPropertySourceData):

  • css/CSSPropertySourceData.h:

Add a concept of disabled to CSSPropertySourceData. This is used for
commented out properties.

(WebCore::CSSRuleSourceData::create):
(WebCore::CSSRuleSourceData::createUnknown):
(WebCore::CSSRuleSourceData::CSSRuleSourceData):
Get rid of the CSSRuleSourceData type enum, since StyleRule's type
enum is exactly the same.

  • css/parser/CSSParser.cpp:

(WebCore::CSSParserContext::CSSParserContext):
(WebCore::CSSParser::parseSheetForInspector):
(WebCore::CSSParser::parseDeclarationForInspector):
(WebCore::CSSParser::markSupportsRuleHeaderStart):
(WebCore::CSSParser::markRuleHeaderStart):
(WebCore::CSSParser::markPropertyEnd):

  • css/parser/CSSParser.h:

Add functions that represent the new API for inspector sheet
and declaration parsing. Patch the old parse code to use StyleRule::Type
now that the CSSRuleSourceData type is gone.

  • css/parser/CSSParserObserver.h:

Tweak the API for our memory management.

  • inspector/InspectorStyleSheet.cpp:

(flattenSourceData):
(WebCore::parserContextForDocument):
(WebCore::StyleSheetHandler::StyleSheetHandler):
(WebCore::StyleSheetHandler::startRuleHeader):
(WebCore::StyleSheetHandler::setRuleHeaderEnd):
(WebCore::StyleSheetHandler::endRuleHeader):
(WebCore::StyleSheetHandler::observeSelector):
(WebCore::StyleSheetHandler::startRuleBody):
(WebCore::StyleSheetHandler::endRuleBody):
(WebCore::StyleSheetHandler::popRuleData):
(WebCore::fixUnparsedProperties):
(WebCore::StyleSheetHandler::fixUnparsedPropertyRanges):
(WebCore::StyleSheetHandler::observeProperty):
(WebCore::StyleSheetHandler::observeComment):
(WebCore::InspectorStyle::populateAllProperties):
(WebCore::isValidSelectorListString):
(WebCore::InspectorStyleSheet::ensureSourceData):
(WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
(WebCore::InspectorStyleSheetForInlineStyle::ruleSourceData):
(WebCore::createCSSParser): Deleted.
(WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges): Deleted.

  • inspector/InspectorStyleSheet.h:

(WebCore::InspectorStyleProperty::setRawTextFromStyleDeclaration):
Add the new implementation. This involves duplicating most of the old
parser code for this into a new class, StyleSheetHandler, that implements
the observer interface and builds up the same data structures as the old
parser did in response to the callbacks.

Location:
trunk/Source/WebCore
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r208884 r208886  
     12016-11-18  Dave Hyatt  <[email protected]>
     2
     3        [CSS Parser] Hook up InspectorStyleSheet to the new CSS parser.
     4        https://bugs.webkit.org/show_bug.cgi?id=164886
     5
     6        Reviewed by Dean Jackson.
     7
     8        * css/CSSGrammar.y.in:
     9        Get rid of the CSSRuleSourceData type enum, since StyleRule's type
     10        enum is exactly the same.
     11
     12        * css/CSSPropertySourceData.cpp:
     13        (WebCore::CSSPropertySourceData::CSSPropertySourceData):
     14        * css/CSSPropertySourceData.h:
     15        Add a concept of disabled to CSSPropertySourceData. This is used for
     16        commented out properties.
     17
     18        (WebCore::CSSRuleSourceData::create):
     19        (WebCore::CSSRuleSourceData::createUnknown):
     20        (WebCore::CSSRuleSourceData::CSSRuleSourceData):
     21        Get rid of the CSSRuleSourceData type enum, since StyleRule's type
     22        enum is exactly the same.
     23
     24        * css/parser/CSSParser.cpp:
     25        (WebCore::CSSParserContext::CSSParserContext):
     26        (WebCore::CSSParser::parseSheetForInspector):
     27        (WebCore::CSSParser::parseDeclarationForInspector):
     28        (WebCore::CSSParser::markSupportsRuleHeaderStart):
     29        (WebCore::CSSParser::markRuleHeaderStart):
     30        (WebCore::CSSParser::markPropertyEnd):
     31        * css/parser/CSSParser.h:
     32        Add functions that represent the new API for inspector sheet
     33        and declaration parsing. Patch the old parse code to use StyleRule::Type
     34        now that the CSSRuleSourceData type is gone.
     35
     36        * css/parser/CSSParserObserver.h:
     37        Tweak the API for our memory management.
     38
     39        * inspector/InspectorStyleSheet.cpp:
     40        (flattenSourceData):
     41        (WebCore::parserContextForDocument):
     42        (WebCore::StyleSheetHandler::StyleSheetHandler):
     43        (WebCore::StyleSheetHandler::startRuleHeader):
     44        (WebCore::StyleSheetHandler::setRuleHeaderEnd):
     45        (WebCore::StyleSheetHandler::endRuleHeader):
     46        (WebCore::StyleSheetHandler::observeSelector):
     47        (WebCore::StyleSheetHandler::startRuleBody):
     48        (WebCore::StyleSheetHandler::endRuleBody):
     49        (WebCore::StyleSheetHandler::popRuleData):
     50        (WebCore::fixUnparsedProperties):
     51        (WebCore::StyleSheetHandler::fixUnparsedPropertyRanges):
     52        (WebCore::StyleSheetHandler::observeProperty):
     53        (WebCore::StyleSheetHandler::observeComment):
     54        (WebCore::InspectorStyle::populateAllProperties):
     55        (WebCore::isValidSelectorListString):
     56        (WebCore::InspectorStyleSheet::ensureSourceData):
     57        (WebCore::InspectorStyleSheetForInlineStyle::ensureParsedDataReady):
     58        (WebCore::InspectorStyleSheetForInlineStyle::ruleSourceData):
     59        (WebCore::createCSSParser): Deleted.
     60        (WebCore::InspectorStyleSheetForInlineStyle::getStyleAttributeRanges): Deleted.
     61        * inspector/InspectorStyleSheet.h:
     62        (WebCore::InspectorStyleProperty::setRawTextFromStyleDeclaration):
     63        Add the new implementation. This involves duplicating most of the old
     64        parser code for this into a new class, StyleSheetHandler, that implements
     65        the observer interface and builds up the same data structures as the old
     66        parser did in response to the callbacks.
     67
    1682016-11-18  Dan Bernstein  <[email protected]>
    269
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r206641 r208886  
    517517before_import_rule:
    518518    /* empty */ {
    519         parser->markRuleHeaderStart(CSSRuleSourceData::IMPORT_RULE);
     519        parser->markRuleHeaderStart(StyleRule::Import);
    520520    }
    521521    ;
     
    655655before_media_rule:
    656656    /* empty */ {
    657         parser->markRuleHeaderStart(CSSRuleSourceData::MEDIA_RULE);
     657        parser->markRuleHeaderStart(StyleRule::Media);
    658658    }
    659659    ;
     
    700700before_supports_rule:
    701701    /* empty */ {
    702         parser->markRuleHeaderStart(CSSRuleSourceData::SUPPORTS_RULE);
     702        parser->markRuleHeaderStart(StyleRule::Supports);
    703703        parser->markSupportsRuleHeaderStart();
    704704    }
     
    768768before_keyframes_rule:
    769769    /* empty */ {
    770         parser->markRuleHeaderStart(CSSRuleSourceData::KEYFRAMES_RULE);
     770        parser->markRuleHeaderStart(StyleRule::Keyframe);
    771771    }
    772772    ;
     
    830830before_page_rule:
    831831    /* empty */ {
    832         parser->markRuleHeaderStart(CSSRuleSourceData::PAGE_RULE);
     832        parser->markRuleHeaderStart(StyleRule::Page);
    833833    }
    834834    ;
     
    943943before_font_face_rule:
    944944    /* empty */ {
    945         parser->markRuleHeaderStart(CSSRuleSourceData::FONT_FACE_RULE);
     945        parser->markRuleHeaderStart(StyleRule::FontFace);
    946946    }
    947947    ;
     
    966966    /* empty */ {
    967967        parser->markViewportRuleBodyStart();
    968         parser->markRuleHeaderStart(CSSRuleSourceData::VIEWPORT_RULE);
     968        parser->markRuleHeaderStart(StyleRule::Viewport);
    969969    }
    970970    ;
     
    992992before_region_rule:
    993993    /* empty */ {
    994         parser->markRuleHeaderStart(CSSRuleSourceData::REGION_RULE);
     994        parser->markRuleHeaderStart(StyleRule::Region);
    995995    }
    996996    ;
     
    10251025before_selector_list:
    10261026    {
    1027         parser->markRuleHeaderStart(CSSRuleSourceData::STYLE_RULE);
     1027        parser->markRuleHeaderStart(StyleRule::Style);
    10281028        parser->markSelectorStart();
    10291029    }
  • trunk/Source/WebCore/css/CSSPropertySourceData.cpp

    r203322 r208886  
    5656}
    5757
    58 CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool parsedOk, const SourceRange& range)
     58CSSPropertySourceData::CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange& range)
    5959    : name(name)
    6060    , value(value)
    6161    , important(important)
     62    , disabled(disabled)
    6263    , parsedOk(parsedOk)
    6364    , range(range)
     
    6970    , value(other.value)
    7071    , important(other.important)
     72    , disabled(other.disabled)
    7173    , parsedOk(other.parsedOk)
    7274    , range(other.range)
     
    7880    , value(emptyString())
    7981    , important(false)
     82    , disabled(false)
    8083    , parsedOk(false)
    8184    , range(SourceRange(0, 0))
  • trunk/Source/WebCore/css/CSSPropertySourceData.h

    r208668 r208886  
    3131#pragma once
    3232
     33#include "StyleRule.h"
    3334#include <utility>
    3435#include <wtf/Forward.h>
     
    5253
    5354struct CSSPropertySourceData {
    54     CSSPropertySourceData(const String& name, const String& value, bool important, bool parsedOk, const SourceRange& range);
     55    CSSPropertySourceData(const String& name, const String& value, bool important, bool disabled, bool parsedOk, const SourceRange&);
    5556    CSSPropertySourceData(const CSSPropertySourceData& other);
    5657    CSSPropertySourceData();
     
    6263    String value;
    6364    bool important;
     65    bool disabled;
    6466    bool parsedOk;
    6567    SourceRange range;
     
    8082
    8183struct CSSRuleSourceData : public RefCounted<CSSRuleSourceData> {
    82     enum Type {
    83         UNKNOWN_RULE,
    84         STYLE_RULE,
    85         IMPORT_RULE,
    86         MEDIA_RULE,
    87         FONT_FACE_RULE,
    88         PAGE_RULE,
    89         KEYFRAMES_RULE,
    90         REGION_RULE,
    91         HOST_RULE,
    92         VIEWPORT_RULE,
    93         SUPPORTS_RULE,
    94     };
    95 
    96     static Ref<CSSRuleSourceData> create(Type type)
     84    static Ref<CSSRuleSourceData> create(StyleRule::Type type)
    9785    {
    9886        return adoptRef(*new CSSRuleSourceData(type));
     
    10189    static Ref<CSSRuleSourceData> createUnknown()
    10290    {
    103         return adoptRef(*new CSSRuleSourceData(UNKNOWN_RULE));
     91        return adoptRef(*new CSSRuleSourceData(StyleRule::Unknown));
    10492    }
    10593
    106     CSSRuleSourceData(Type type)
     94    CSSRuleSourceData(StyleRule::Type type)
    10795        : type(type)
    10896    {
    109         if (type == STYLE_RULE || type == FONT_FACE_RULE || type == PAGE_RULE)
     97        if (type == StyleRule::Style || type == StyleRule::FontFace || type == StyleRule::Page)
    11098            styleSourceData = CSSStyleSourceData::create();
    11199    }
    112100
    113     Type type;
     101    StyleRule::Type type;
    114102
    115103    // Range of the selector list in the enclosing source.
  • trunk/Source/WebCore/css/parser/CSSParser.cpp

    r208847 r208886  
    5959#include "CSSParserFastPaths.h"
    6060#include "CSSParserImpl.h"
     61#include "CSSParserObserver.h"
    6162#include "CSSPendingSubstitutionValue.h"
    6263#include "CSSPrimitiveValue.h"
     
    393394}
    394395
     396void CSSParser::parseSheetForInspector(const CSSParserContext& context, StyleSheetContents* sheet, const String& string, CSSParserObserver& observer)
     397{
     398    return CSSParserImpl::parseStyleSheetForInspector(string, context, sheet, observer);
     399}
     400
    395401RefPtr<StyleRuleBase> CSSParser::parseRule(StyleSheetContents* sheet, const String& string)
    396402{
     
    15141520
    15151521    return ok;
     1522}
     1523
     1524void CSSParser::parseDeclarationForInspector(const CSSParserContext& context, const String& string, CSSParserObserver& observer)
     1525{
     1526    CSSParserImpl::parseDeclarationListForInspector(string, context, observer);
    15161527}
    15171528
     
    1292612937        m_supportsRuleDataStack = std::make_unique<RuleSourceDataList>();
    1292712938
    12928     auto data = CSSRuleSourceData::create(CSSRuleSourceData::SUPPORTS_RULE);
     12939    auto data = CSSRuleSourceData::create(StyleRule::Supports);
    1292912940    data->ruleHeaderRange.start = tokenStartOffset();
    1293012941    m_supportsRuleDataStack->append(WTFMove(data));
     
    1332613337}
    1332713338
    13328 void CSSParser::markRuleHeaderStart(CSSRuleSourceData::Type ruleType)
     13339void CSSParser::markRuleHeaderStart(StyleRule::Type ruleType)
    1332913340{
    1333013341    if (!isExtractingSourceData())
     
    1345113462        SourceRange& topRuleBodyRange = m_currentRuleDataStack->last()->ruleBodyRange;
    1345213463        m_currentRuleDataStack->last()->styleSourceData->propertyData.append(
    13453             CSSPropertySourceData(name, value, isImportantFound, isPropertyParsed, SourceRange(start - topRuleBodyRange.start, end - topRuleBodyRange.start)));
     13464            CSSPropertySourceData(name, value, isImportantFound, false, isPropertyParsed, SourceRange(start - topRuleBodyRange.start, end - topRuleBodyRange.start)));
    1345413465    }
    1345513466    resetPropertyRange();
  • trunk/Source/WebCore/css/parser/CSSParser.h

    r208847 r208886  
    5151class CSSBorderImageSliceValue;
    5252class CSSContentDistributionValue;
     53class CSSParserObserver;
    5354class CSSPrimitiveValue;
    5455class CSSSelectorList;
     
    133134    bool parseSupportsCondition(const String&);
    134135
     136    static void parseSheetForInspector(const CSSParserContext&, StyleSheetContents*, const String&, CSSParserObserver&);
     137    static void parseDeclarationForInspector(const CSSParserContext&, const String&, CSSParserObserver&);
     138
    135139    static ParseResult parseValue(MutableStyleProperties&, CSSPropertyID, const String&, bool important, const CSSParserContext&, StyleSheetContents*);
    136140    static ParseResult parseCustomPropertyValue(MutableStyleProperties&, const AtomicString& propertyName, const String&, bool important, const CSSParserContext&, StyleSheetContents* contextStyleSheet);
     
    142146    RefPtr<CSSPrimitiveValue> parseValidPrimitive(CSSValueID ident, ValueWithCalculation&);
    143147
     148    // FIXME-NEWPARSER: Can remove the last two arguments once the new parser is turned on.
    144149    WEBCORE_EXPORT bool parseDeclaration(MutableStyleProperties&, const String&, RefPtr<CSSRuleSourceData>&&, StyleSheetContents* contextStyleSheet);
    145150    static Ref<ImmutableStyleProperties> parseInlineStyleDeclaration(const String&, Element*);
     
    457462
    458463    void fixUnparsedPropertyRanges(CSSRuleSourceData&);
    459     void markRuleHeaderStart(CSSRuleSourceData::Type);
     464    void markRuleHeaderStart(StyleRule::Type);
    460465    void markRuleHeaderEnd();
    461466
  • trunk/Source/WebCore/css/parser/CSSParserObserver.h

    r208668 r208886  
    4343    virtual void observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed) = 0;
    4444    virtual void observeComment(unsigned startOffset, unsigned endOffset) = 0;
    45     // FIXME: Unused, should be removed
    46     virtual void startMediaQueryExp(unsigned offset) = 0;
    47     virtual void endMediaQueryExp(unsigned offset) = 0;
    48     virtual void startMediaQuery() = 0;
    49     virtual void endMediaQuery() = 0;
    5045};
    5146
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp

    r208688 r208886  
    3030#include "CSSMediaRule.h"
    3131#include "CSSParser.h"
     32#include "CSSParserObserver.h"
    3233#include "CSSPropertyNames.h"
    3334#include "CSSPropertySourceData.h"
     
    101102{
    102103    for (auto& data : dataList) {
    103         if (data->type == CSSRuleSourceData::STYLE_RULE)
     104        if (data->type == WebCore::StyleRule::Style)
    104105            target.append(data.copyRef());
    105         else if (data->type == CSSRuleSourceData::MEDIA_RULE)
     106        else if (data->type == WebCore::StyleRule::Media)
    106107            flattenSourceData(data->childRules, target);
    107         else if (data->type == CSSRuleSourceData::SUPPORTS_RULE)
     108        else if (data->type == WebCore::StyleRule::Supports)
    108109            flattenSourceData(data->childRules, target);
    109110    }
     
    136137
    137138namespace WebCore {
     139
     140static CSSParserContext parserContextForDocument(Document* document)
     141{
     142    return document ? CSSParserContext(*document) : strictCSSParserContext();
     143}
     144
     145class StyleSheetHandler : public CSSParserObserver {
     146public:
     147    StyleSheetHandler(const String& parsedText, Document* document, RuleSourceDataList* result)
     148        : m_parsedText(parsedText)
     149        , m_document(document)
     150        , m_ruleSourceDataResult(result)
     151    {
     152        ASSERT(m_ruleSourceDataResult);
     153    }
     154   
     155private:
     156    void startRuleHeader(StyleRule::Type, unsigned) override;
     157    void endRuleHeader(unsigned) override;
     158    void observeSelector(unsigned startOffset, unsigned endOffset) override;
     159    void startRuleBody(unsigned) override;
     160    void endRuleBody(unsigned) override;
     161    void observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed) override;
     162    void observeComment(unsigned startOffset, unsigned endOffset) override;
     163   
     164    Ref<CSSRuleSourceData> popRuleData();
     165    template <typename CharacterType> inline void setRuleHeaderEnd(const CharacterType*, unsigned);
     166    void fixUnparsedPropertyRanges(CSSRuleSourceData*);
     167   
     168    const String& m_parsedText;
     169    Document* m_document;
     170   
     171    RuleSourceDataList m_currentRuleDataStack;
     172    RefPtr<CSSRuleSourceData> m_currentRuleData;
     173    RuleSourceDataList* m_ruleSourceDataResult { nullptr };
     174};
     175
     176void StyleSheetHandler::startRuleHeader(StyleRule::Type type, unsigned offset)
     177{
     178    // Pop off data for a previous invalid rule.
     179    if (m_currentRuleData)
     180        m_currentRuleDataStack.removeLast();
     181   
     182    auto data = CSSRuleSourceData::create(type);
     183    data->ruleHeaderRange.start = offset;
     184    m_currentRuleData = data.copyRef();
     185    m_currentRuleDataStack.append(WTFMove(data));
     186}
     187
     188template <typename CharacterType> inline void StyleSheetHandler::setRuleHeaderEnd(const CharacterType* dataStart, unsigned listEndOffset)
     189{
     190    while (listEndOffset > 1) {
     191        if (isHTMLSpace<CharacterType>(*(dataStart + listEndOffset - 1)))
     192            --listEndOffset;
     193        else
     194            break;
     195    }
     196
     197    m_currentRuleDataStack.last()->ruleHeaderRange.end = listEndOffset;
     198    if (!m_currentRuleDataStack.last()->selectorRanges.isEmpty())
     199        m_currentRuleDataStack.last()->selectorRanges.last().end = listEndOffset;
     200}
     201
     202void StyleSheetHandler::endRuleHeader(unsigned offset)
     203{
     204    ASSERT(!m_currentRuleDataStack.isEmpty());
     205   
     206    if (m_parsedText.is8Bit())
     207        setRuleHeaderEnd<LChar>(m_parsedText.characters8(), offset);
     208    else
     209        setRuleHeaderEnd<UChar>(m_parsedText.characters16(), offset);
     210}
     211
     212void StyleSheetHandler::observeSelector(unsigned startOffset, unsigned endOffset)
     213{
     214    ASSERT(m_currentRuleDataStack.size());
     215    m_currentRuleDataStack.last()->selectorRanges.append(SourceRange(startOffset, endOffset));
     216}
     217
     218void StyleSheetHandler::startRuleBody(unsigned offset)
     219{
     220    m_currentRuleData = nullptr;
     221    ASSERT(!m_currentRuleDataStack.isEmpty());
     222   
     223    // Skip the rule body opening brace.
     224    if (m_parsedText[offset] == '{')
     225        ++offset;
     226
     227    m_currentRuleDataStack.last()->ruleBodyRange.start = offset;
     228}
     229
     230void StyleSheetHandler::endRuleBody(unsigned offset)
     231{
     232    ASSERT(!m_currentRuleDataStack.isEmpty());
     233    m_currentRuleDataStack.last()->ruleBodyRange.end = offset;
     234    auto rule = popRuleData();
     235    fixUnparsedPropertyRanges(rule.ptr());
     236    if (m_currentRuleDataStack.isEmpty())
     237        m_ruleSourceDataResult->append(WTFMove(rule));
     238    else
     239        m_currentRuleDataStack.last()->childRules.append(WTFMove(rule));
     240}
     241
     242Ref<CSSRuleSourceData> StyleSheetHandler::popRuleData()
     243{
     244    ASSERT(!m_currentRuleDataStack.isEmpty());
     245    m_currentRuleData = nullptr;
     246    auto data = WTFMove(m_currentRuleDataStack.last());
     247    m_currentRuleDataStack.removeLast();
     248    return data;
     249}
     250
     251template <typename CharacterType>
     252static inline void fixUnparsedProperties(const CharacterType* characters, CSSRuleSourceData* ruleData)
     253{
     254    Vector<CSSPropertySourceData>& propertyData = ruleData->styleSourceData->propertyData;
     255    unsigned size = propertyData.size();
     256    if (!size)
     257        return;
     258   
     259    unsigned styleStart = ruleData->ruleBodyRange.start;
     260   
     261    CSSPropertySourceData* nextData = &(propertyData.at(0));
     262    for (unsigned i = 0; i < size; ++i) {
     263        CSSPropertySourceData* currentData = nextData;
     264        nextData = i < size - 1 ? &(propertyData.at(i + 1)) : nullptr;
     265       
     266        if (currentData->parsedOk)
     267            continue;
     268        if (currentData->range.end > 0 && characters[styleStart + currentData->range.end - 1] == ';')
     269            continue;
     270       
     271        unsigned propertyEnd;
     272        if (!nextData)
     273            propertyEnd = ruleData->ruleBodyRange.end - 1;
     274        else
     275            propertyEnd = styleStart + nextData->range.start - 1;
     276       
     277        while (isHTMLSpace<CharacterType>(characters[propertyEnd]))
     278            --propertyEnd;
     279       
     280        // propertyEnd points at the last property text character.
     281        unsigned newPropertyEnd = propertyEnd + styleStart + 1;
     282        if (currentData->range.end != newPropertyEnd) {
     283            currentData->range.end = newPropertyEnd;
     284            unsigned valueStart = styleStart + currentData->range.start + currentData->name.length();
     285            while (valueStart < propertyEnd && characters[valueStart] != ':')
     286                ++valueStart;
     287           
     288            // Shift past the ':'.
     289            if (valueStart < propertyEnd)
     290                ++valueStart;
     291
     292            while (valueStart < propertyEnd && isHTMLSpace<CharacterType>(characters[valueStart]))
     293                ++valueStart;
     294           
     295            // Need to exclude the trailing ';' from the property value.
     296            currentData->value = String(characters + valueStart, propertyEnd - valueStart + (characters[propertyEnd] == ';' ? 0 : 1));
     297        }
     298    }
     299}
     300
     301void StyleSheetHandler::fixUnparsedPropertyRanges(CSSRuleSourceData* ruleData)
     302{
     303    if (!ruleData->styleSourceData)
     304        return;
     305   
     306    if (m_parsedText.is8Bit()) {
     307        fixUnparsedProperties<LChar>(m_parsedText.characters8(), ruleData);
     308        return;
     309    }
     310   
     311    fixUnparsedProperties<UChar>(m_parsedText.characters16(), ruleData);
     312}
     313
     314void StyleSheetHandler::observeProperty(unsigned startOffset, unsigned endOffset, bool isImportant, bool isParsed)
     315{
     316    if (m_currentRuleDataStack.isEmpty() || !m_currentRuleDataStack.last()->styleSourceData)
     317        return;
     318   
     319    ASSERT(endOffset <= m_parsedText.length());
     320   
     321    // Include semicolon in the property text.
     322    if (endOffset < m_parsedText.length() && m_parsedText[endOffset] == ';')
     323        ++endOffset;
     324   
     325    ASSERT(startOffset < endOffset);
     326    String propertyString = m_parsedText.substring(startOffset, endOffset - startOffset).stripWhiteSpace();
     327    if (propertyString.endsWith(';'))
     328        propertyString = propertyString.left(propertyString.length() - 1);
     329    size_t colonIndex = propertyString.find(':');
     330    ASSERT(colonIndex != notFound);
     331
     332    String name = propertyString.left(colonIndex).stripWhiteSpace();
     333    String value = propertyString.substring(colonIndex + 1, propertyString.length()).stripWhiteSpace();
     334   
     335    // FIXME-NEWPARSER: The property range is relative to the declaration start offset, but no
     336    // good reason for it, and it complicates fixUnparsedProperties.
     337    SourceRange& topRuleBodyRange = m_currentRuleDataStack.last()->ruleBodyRange;
     338    m_currentRuleDataStack.last()->styleSourceData->propertyData.append(CSSPropertySourceData(name, value, isImportant, false, isParsed, SourceRange(startOffset - topRuleBodyRange.start, endOffset - topRuleBodyRange.start)));
     339}
     340
     341void StyleSheetHandler::observeComment(unsigned startOffset, unsigned endOffset)
     342{
     343    ASSERT(endOffset <= m_parsedText.length());
     344
     345    if (m_currentRuleDataStack.isEmpty() || !m_currentRuleDataStack.last()->ruleHeaderRange.end || !m_currentRuleDataStack.last()->styleSourceData)
     346        return;
     347   
     348    // The lexer is not inside a property AND it is scanning a declaration-aware
     349    // rule body.
     350    String commentText = m_parsedText.substring(startOffset, endOffset - startOffset);
     351   
     352    ASSERT(commentText.startsWith("/*"));
     353    commentText = commentText.substring(2);
     354   
     355    // Require well-formed comments.
     356    if (!commentText.endsWith("*/"))
     357        return;
     358    commentText = commentText.substring(0, commentText.length() - 2).stripWhiteSpace();
     359    if (commentText.isEmpty())
     360        return;
     361   
     362    // FIXME: Use the actual rule type rather than STYLE_RULE?
     363    RuleSourceDataList sourceData;
     364   
     365    StyleSheetHandler handler(commentText, m_document, &sourceData);
     366    CSSParser::parseDeclarationForInspector(parserContextForDocument(m_document), commentText, handler);
     367    Vector<CSSPropertySourceData>& commentPropertyData = sourceData.first()->styleSourceData->propertyData;
     368    if (commentPropertyData.size() != 1)
     369        return;
     370    CSSPropertySourceData& propertyData = commentPropertyData.at(0);
     371    bool parsedOk = propertyData.parsedOk || propertyData.name.startsWith("-moz-") || propertyData.name.startsWith("-o-") || propertyData.name.startsWith("-webkit-") || propertyData.name.startsWith("-ms-");
     372    if (!parsedOk || propertyData.range.length() != commentText.length())
     373        return;
     374   
     375    // FIXME-NEWPARSER: The property range is relative to the declaration start offset, but no
     376    // good reason for it, and it complicates fixUnparsedProperties.
     377    SourceRange& topRuleBodyRange = m_currentRuleDataStack.last()->ruleBodyRange;
     378    m_currentRuleDataStack.last()->styleSourceData->propertyData.append(CSSPropertySourceData(propertyData.name, propertyData.value, false, true, true, SourceRange(startOffset - topRuleBodyRange.start, endOffset - topRuleBodyRange.start)));
     379}
    138380
    139381enum MediaListSource {
     
    274516}
    275517
    276 static std::unique_ptr<CSSParser> createCSSParser(Document* document)
    277 {
    278     return std::make_unique<CSSParser>(document ? CSSParserContext(*document) : strictCSSParserContext());
    279 }
    280 
    281518Ref<InspectorStyle> InspectorStyle::create(const InspectorCSSId& styleId, RefPtr<CSSStyleDeclaration>&& style, InspectorStyleSheet* parentStyleSheet)
    282519{
     
    364601        String styleDeclaration = styleDeclarationOrException.hasException() ? emptyString() : styleDeclarationOrException.releaseReturnValue();
    365602        for (auto& sourceData : *sourcePropertyData) {
    366             InspectorStyleProperty p(sourceData, true, false);
     603            InspectorStyleProperty p(sourceData, true, sourceData.disabled);
    367604            p.setRawTextFromStyleDeclaration(styleDeclaration);
    368605            result->append(p);
     
    374611        String name = m_style->item(i);
    375612        if (sourcePropertyNames.add(lowercasePropertyName(name)))
    376             result->append(InspectorStyleProperty(CSSPropertySourceData(name, m_style->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), true, SourceRange()), false, false));
     613            result->append(InspectorStyleProperty(CSSPropertySourceData(name, m_style->getPropertyValue(name), !m_style->getPropertyPriority(name).isEmpty(), false, true, SourceRange()), false, false));
    377614    }
    378615}
     
    636873{
    637874    CSSSelectorList selectorList;
    638     createCSSParser(document)->parseSelector(selector, selectorList);
     875    CSSParser parser(parserContextForDocument(document));
     876    parser.parseSelector(selector, selectorList);
    639877    return selectorList.isValid();
    640878}
     
    10901328    RefPtr<StyleSheetContents> newStyleSheet = StyleSheetContents::create();
    10911329    auto ruleSourceDataResult = std::make_unique<RuleSourceDataList>();
    1092     createCSSParser(m_pageStyleSheet->ownerDocument())->parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), TextPosition(), ruleSourceDataResult.get(), false);
     1330   
     1331    CSSParserContext context(parserContextForDocument(m_pageStyleSheet->ownerDocument()));
     1332    if (context.useNewParser) {
     1333        StyleSheetHandler handler(m_parsedStyleSheet->text(), m_pageStyleSheet->ownerDocument(), ruleSourceDataResult.get());
     1334        CSSParser::parseSheetForInspector(context, newStyleSheet.get(), m_parsedStyleSheet->text(), handler);
     1335    } else
     1336        CSSParser(context).parseSheet(newStyleSheet.get(), m_parsedStyleSheet->text(), TextPosition(), ruleSourceDataResult.get(), false);
    10931337    m_parsedStyleSheet->setSourceData(WTFMove(ruleSourceDataResult));
    10941338    return m_parsedStyleSheet->hasSourceData();
     
    12961540        return true;
    12971541
    1298     m_ruleSourceData = CSSRuleSourceData::create(CSSRuleSourceData::STYLE_RULE);
    1299     bool success = getStyleAttributeRanges(m_ruleSourceData.get());
    1300     if (!success)
     1542    if (!m_element->isStyledElement())
    13011543        return false;
    13021544
     1545    m_ruleSourceData = ruleSourceData();
    13031546    return true;
    13041547}
     
    13201563}
    13211564
    1322 bool InspectorStyleSheetForInlineStyle::getStyleAttributeRanges(CSSRuleSourceData* result) const
    1323 {
    1324     if (!m_element->isStyledElement())
    1325         return false;
    1326 
     1565Ref<CSSRuleSourceData> InspectorStyleSheetForInlineStyle::ruleSourceData() const
     1566{
    13271567    if (m_styleText.isEmpty()) {
     1568        auto result = CSSRuleSourceData::create(StyleRule::Style);
    13281569        result->ruleBodyRange.start = 0;
    13291570        result->ruleBodyRange.end = 0;
    1330         return true;
    1331     }
    1332 
     1571        return result;
     1572    }
     1573
     1574    CSSParserContext context(parserContextForDocument(&m_element->document()));
     1575    if (context.useNewParser) {
     1576        RuleSourceDataList ruleSourceDataResult;
     1577        StyleSheetHandler handler(m_styleText, &m_element->document(), &ruleSourceDataResult);
     1578        CSSParser::parseDeclarationForInspector(context, m_styleText, handler);
     1579        return WTFMove(ruleSourceDataResult.first());
     1580    }
     1581   
     1582    auto result = CSSRuleSourceData::create(StyleRule::Style);
    13331583    auto tempDeclaration = MutableStyleProperties::create();
    1334     createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration, m_styleText, result, nullptr);
    1335     return true;
     1584    CSSParser(context).parseDeclaration(tempDeclaration, m_styleText, result.ptr(), nullptr);
     1585    return result;
    13361586}
    13371587
  • trunk/Source/WebCore/inspector/InspectorStyleSheet.h

    r208603 r208886  
    252252    CSSStyleDeclaration* inlineStyle() const;
    253253    const String& elementStyleText() const;
    254     bool getStyleAttributeRanges(CSSRuleSourceData* result) const;
     254    Ref<CSSRuleSourceData> ruleSourceData() const;
    255255
    256256    RefPtr<Element> m_element;
Note: See TracChangeset for help on using the changeset viewer.