Ejemplo n.º 1
0
bool Element::classChangeNeedsStyleRecalc(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses)
{
    // Class vectors tend to be very short. This is faster than using a hash table.
    BitVector remainingClassBits;
    remainingClassBits.ensureSize(oldClasses.size());

    for (unsigned i = 0; i < newClasses.size(); ++i) {
        bool found = false;
        for (unsigned j = 0; j < oldClasses.size(); ++j) {
            if (newClasses[i] == oldClasses[j]) {
                // Mark each class that is still in the newClasses so we can skip doing
                // an n^2 search below when looking for removals. We can't break from
                // this loop early since a class can appear more than once.
                remainingClassBits.quickSet(j);
                found = true;
            }
        }
        // Class was added.
        if (!found && affectedByClassSelector(newClasses[i]))
            return true;
    }

    for (unsigned i = 0; i < oldClasses.size(); ++i) {
        if (remainingClassBits.quickGet(i))
            continue;
        // Class was removed.
        if (affectedByClassSelector(oldClasses[i]))
            return true;
    }
    return false;
}
Ejemplo n.º 2
0
void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Element& element)
{
    if (!oldClasses.size())
        scheduleStyleInvalidationForClassChange(newClasses, element);

    // Class vectors tend to be very short. This is faster than using a hash table.
    BitVector remainingClassBits;
    remainingClassBits.ensureSize(oldClasses.size());

    for (unsigned i = 0; i < newClasses.size(); ++i) {
        bool found = false;
        for (unsigned j = 0; j < oldClasses.size(); ++j) {
            if (newClasses[i] == oldClasses[j]) {
                // Mark each class that is still in the newClasses so we can skip doing
                // an n^2 search below when looking for removals. We can't break from
                // this loop early since a class can appear more than once.
                remainingClassBits.quickSet(j);
                found = true;
            }
        }
        // Class was added.
        if (!found)
            addClassToInvalidationSet(newClasses[i], element);
    }

    for (unsigned i = 0; i < oldClasses.size(); ++i) {
        if (remainingClassBits.quickGet(i))
            continue;
        // Class was removed.
        addClassToInvalidationSet(oldClasses[i], element);
    }
}
Ejemplo n.º 3
0
void RuleFeatureSet::scheduleStyleInvalidationForClassChange(const SpaceSplitString& changedClasses, Element& element)
{
    unsigned changedSize = changedClasses.size();
    for (unsigned i = 0; i < changedSize; ++i) {
        addClassToInvalidationSet(changedClasses[i], element);
    }
}
void GraphicsContextAnnotator::annotate(const PaintInfo& paintInfo, const LayoutObject* object)
{
    ASSERT(!m_context);

    ASSERT(paintInfo.context);
    ASSERT(object);

    AnnotationList annotations;
    AnnotationModeFlags mode = paintInfo.context->annotationMode();
    Element* element = object->node() && object->node()->isElementNode() ? toElement(object->node()) : 0;

    if (mode & AnnotateLayoutObjectName)
        annotations.append(std::make_pair(AnnotationKeyLayoutObjectName, object->decoratedName()));

    if (mode & AnnotatePaintPhase)
        annotations.append(std::make_pair(AnnotationKeyPaintPhase, paintPhaseName(paintInfo.phase)));

    if ((mode & AnnotateElementId) && element && element->hasID())
        annotations.append(std::make_pair(AnnotationKeyElementId, element->getIdAttribute().string()));

    if ((mode & AnnotateElementClass) && element && element->hasClass()) {
        SpaceSplitString classes = element->classNames();
        if (!classes.isNull() && classes.size() > 0) {
            StringBuilder classBuilder;
            for (size_t i = 0; i < classes.size(); ++i) {
                if (i > 0)
                    classBuilder.append(' ');
                classBuilder.append(classes[i]);
            }

            annotations.append(std::make_pair(AnnotationKeyElementClass, classBuilder.toString()));
        }
    }

    if ((mode & AnnotateElementTag) && element)
        annotations.append(std::make_pair(AnnotationKeyElementTag, element->tagName()));

    if (mode & AnnotateInspectorId) {
        if (Node* ownerNode = object->generatingNode()) {
            annotations.append(std::make_pair(AnnotationKeyInspectorNodeId,
                String::number(DOMNodeIds::idForNode(ownerNode))));
        }
    }

    m_context = paintInfo.context;
    m_context->beginAnnotation(annotations);
}
Ejemplo n.º 5
0
bool SharedStyleFinder::classNamesAffectedByRules(const SpaceSplitString& classNames) const
{
    unsigned count = classNames.size();
    for (unsigned i = 0; i < count; ++i) {
        if (m_features.hasSelectorForClass(classNames[i]))
            return true;
    }
    return false;
}
Ejemplo n.º 6
0
bool SelectRuleFeatureSet::checkSelectorsForClassChange(
    const SpaceSplitString& changedClasses) const {
  unsigned changedSize = changedClasses.size();
  for (unsigned i = 0; i < changedSize; ++i) {
    if (hasSelectorForClass(changedClasses[i]))
      return true;
  }
  return false;
}
Ejemplo n.º 7
0
void StyleEngine::classChangedForElement(const SpaceSplitString& changedClasses, Element& element)
{
    ASSERT(isMaster());
    InvalidationSetVector invalidationSets;
    unsigned changedSize = changedClasses.size();
    RuleFeatureSet& ruleFeatureSet = ensureResolver().ensureUpdatedRuleFeatureSet();
    for (unsigned i = 0; i < changedSize; ++i)
        ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, changedClasses[i]);
    scheduleInvalidationSetsForElement(invalidationSets, element);
}
Ejemplo n.º 8
0
bool RuleFeatureSet::computeInvalidationSetsForClassChange(const SpaceSplitString& changedClasses, Element* element)
{
    unsigned changedSize = changedClasses.size();
    for (unsigned i = 0; i < changedSize; ++i) {
        if (classInvalidationRequiresSubtreeRecalc(changedClasses[i]))
            return true;
        addClassToInvalidationSet(changedClasses[i], element);
    }
    return false;
}
Ejemplo n.º 9
0
void StyleEngine::classChangedForElement(const SpaceSplitString& oldClasses, const SpaceSplitString& newClasses, Element& element)
{
    ASSERT(isMaster());
    InvalidationSetVector invalidationSets;
    if (!oldClasses.size()) {
        classChangedForElement(newClasses, element);
        return;
    }

    // Class vectors tend to be very short. This is faster than using a hash table.
    BitVector remainingClassBits;
    remainingClassBits.ensureSize(oldClasses.size());

    RuleFeatureSet& ruleFeatureSet = ensureResolver().ensureUpdatedRuleFeatureSet();

    for (unsigned i = 0; i < newClasses.size(); ++i) {
        bool found = false;
        for (unsigned j = 0; j < oldClasses.size(); ++j) {
            if (newClasses[i] == oldClasses[j]) {
                // Mark each class that is still in the newClasses so we can skip doing
                // an n^2 search below when looking for removals. We can't break from
                // this loop early since a class can appear more than once.
                remainingClassBits.quickSet(j);
                found = true;
            }
        }
        // Class was added.
        if (!found)
            ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, newClasses[i]);
    }

    for (unsigned i = 0; i < oldClasses.size(); ++i) {
        if (remainingClassBits.quickGet(i))
            continue;
        // Class was removed.
        ruleFeatureSet.collectInvalidationSetsForClass(invalidationSets, element, oldClasses[i]);
    }

    scheduleInvalidationSetsForElement(invalidationSets, element);
}
Ejemplo n.º 10
0
SandboxFlags parseSandboxPolicy(const SpaceSplitString& policy, String& invalidTokensErrorMessage)
{
    // http://www.w3.org/TR/html5/the-iframe-element.html#attr-iframe-sandbox
    // Parse the unordered set of unique space-separated tokens.
    SandboxFlags flags = SandboxAll;
    unsigned length = policy.size();
    unsigned numberOfTokenErrors = 0;
    StringBuilder tokenErrors;

    for (unsigned index = 0; index < length; index++) {
        // Turn off the corresponding sandbox flag if it's set as "allowed".
        String sandboxToken(policy[index]);
        if (equalIgnoringCase(sandboxToken, "allow-same-origin")) {
            flags &= ~SandboxOrigin;
        } else if (equalIgnoringCase(sandboxToken, "allow-forms")) {
            flags &= ~SandboxForms;
        } else if (equalIgnoringCase(sandboxToken, "allow-scripts")) {
            flags &= ~SandboxScripts;
            flags &= ~SandboxAutomaticFeatures;
        } else if (equalIgnoringCase(sandboxToken, "allow-top-navigation")) {
            flags &= ~SandboxTopNavigation;
        } else if (equalIgnoringCase(sandboxToken, "allow-popups")) {
            flags &= ~SandboxPopups;
        } else if (equalIgnoringCase(sandboxToken, "allow-pointer-lock")) {
            flags &= ~SandboxPointerLock;
        } else if (equalIgnoringCase(sandboxToken, "allow-orientation-lock")) {
            flags &= ~SandboxOrientationLock;
        } else if (equalIgnoringCase(sandboxToken, "allow-popups-to-escape-sandbox") && RuntimeEnabledFeatures::unsandboxedAuxiliaryEnabled()) {
            flags &= ~SandboxPropagatesToAuxiliaryBrowsingContexts;
        } else if (equalIgnoringCase(sandboxToken, "allow-modals") && RuntimeEnabledFeatures::sandboxBlocksModalsEnabled()) {
            flags &= ~SandboxModals;
        } else {
            if (numberOfTokenErrors)
                tokenErrors.appendLiteral(", '");
            else
                tokenErrors.append('\'');
            tokenErrors.append(sandboxToken);
            tokenErrors.append('\'');
            numberOfTokenErrors++;
        }
    }

    if (numberOfTokenErrors) {
        if (numberOfTokenErrors > 1)
            tokenErrors.appendLiteral(" are invalid sandbox flags.");
        else
            tokenErrors.appendLiteral(" is an invalid sandbox flag.");
        invalidTokensErrorMessage = tokenErrors.toString();
    }

    return flags;
}