示例#1
0
void InspectorStyleTextEditor::disableProperty(unsigned index)
{
    ASSERT(!m_allProperties->at(index).disabled);

    const InspectorStyleProperty& property = m_allProperties->at(index);
    InspectorStyleProperty disabledProperty(property);
    disabledProperty.setRawTextFromStyleDeclaration(m_styleText);
    disabledProperty.disabled = true;

    SourceRange removedRange;
    unsigned insertedLength;
    internalReplaceProperty(property, "", &removedRange, &insertedLength);

    // If some preceding formatting has been removed, move the property to the start of the removed range.
    if (property.sourceData.range.start > removedRange.start)
        disabledProperty.sourceData.range.start = removedRange.start;
    disabledProperty.sourceData.range.end = disabledProperty.sourceData.range.start;

    // Add disabled property at correct position.
    unsigned insertionIndex = disabledIndexByOrdinal(index, true);
    if (insertionIndex == UINT_MAX)
        m_disabledProperties->append(disabledProperty);
    else {
        m_disabledProperties->insert(insertionIndex, disabledProperty);
        long styleLengthDelta = -(static_cast<long>(removedRange.length()));
        shiftDisabledProperties(insertionIndex + 1, styleLengthDelta); // Property removed from text - shift these back.
    }
}
示例#2
0
void InspectorStyleTextEditor::replaceProperty(unsigned index, const String& newText)
{
    ASSERT_WITH_SECURITY_IMPLICATION(index < m_allProperties->size());

    const InspectorStyleProperty& property = m_allProperties->at(index);
    long propertyStart = property.sourceData.range.start;
    long propertyEnd = property.sourceData.range.end;
    long oldLength = propertyEnd - propertyStart;
    long newLength = newText.length();
    long propertyLengthDelta = newLength - oldLength;

    if (!property.disabled) {
        SourceRange overwrittenRange;
        unsigned insertedLength;
        internalReplaceProperty(property, newText, &overwrittenRange, &insertedLength);
        propertyLengthDelta = static_cast<long>(insertedLength) - static_cast<long>(overwrittenRange.length());

        // Recompute subsequent disabled property ranges if acting on a non-disabled property.
        shiftDisabledProperties(disabledIndexByOrdinal(index, true), propertyLengthDelta);
    } else {
        long textLength = newText.length();
        unsigned disabledIndex = disabledIndexByOrdinal(index, false);
        if (!textLength) {
            // Delete disabled property.
            m_disabledProperties->remove(disabledIndex);
        } else {
            // Patch disabled property text.
            m_disabledProperties->at(disabledIndex).rawText = newText;
        }
    }
}
示例#3
0
void InspectorStyleTextEditor::enableProperty(unsigned index)
{
    ASSERT(m_allProperties->at(index).disabled);

    unsigned disabledIndex = disabledIndexByOrdinal(index, false);
    ASSERT(disabledIndex != UINT_MAX);

    InspectorStyleProperty disabledProperty = m_disabledProperties->at(disabledIndex);
    m_disabledProperties->remove(disabledIndex);
    SourceRange removedRange;
    unsigned insertedLength;
    internalReplaceProperty(disabledProperty, disabledProperty.rawText, &removedRange, &insertedLength);
    shiftDisabledProperties(disabledIndex, static_cast<long>(insertedLength) - static_cast<long>(removedRange.length()));
}