| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2010, Google Inc. All rights reserved. | 2 * Copyright (C) 2010, Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 564 if (propertyCount < 2) | 564 if (propertyCount < 2) |
| 565 return false; | 565 return false; |
| 566 | 566 |
| 567 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). | 567 // Check for the proper propertyText termination (the parser could at least
restore to the PROPERTY_NAME state). |
| 568 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) | 568 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) |
| 569 return false; | 569 return false; |
| 570 | 570 |
| 571 return true; | 571 return true; |
| 572 } | 572 } |
| 573 | 573 |
| 574 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, String* oldText, ExceptionState& exceptionState) | 574 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText,
bool overwrite, ExceptionState& exceptionState) |
| 575 { | 575 { |
| 576 ASSERT(m_parentStyleSheet); | 576 ASSERT(m_parentStyleSheet); |
| 577 | 577 |
| 578 if (!m_parentStyleSheet->ensureParsedDataReady()) { | 578 if (!m_parentStyleSheet->ensureParsedDataReady()) { |
| 579 exceptionState.throwDOMException(NotFoundError, "The parent style sheet'
s data hasn't been processed."); | 579 exceptionState.throwDOMException(NotFoundError, "The parent style sheet'
s data hasn't been processed."); |
| 580 return false; | 580 return false; |
| 581 } | 581 } |
| 582 | 582 |
| 583 if (!propertyText.stripWhiteSpace().isEmpty()) { | 583 if (!propertyText.stripWhiteSpace().isEmpty()) { |
| 584 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop
ertyText, true)) { | 584 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop
ertyText, true)) { |
| (...skipping 17 matching lines...) Expand all Loading... |
| 602 | 602 |
| 603 Vector<InspectorStyleProperty> allProperties; | 603 Vector<InspectorStyleProperty> allProperties; |
| 604 populateAllProperties(allProperties); | 604 populateAllProperties(allProperties); |
| 605 | 605 |
| 606 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); | 606 InspectorStyleTextEditor editor(&allProperties, text, newLineAndWhitespaceDe
limiters()); |
| 607 if (overwrite) { | 607 if (overwrite) { |
| 608 if (index >= allProperties.size()) { | 608 if (index >= allProperties.size()) { |
| 609 exceptionState.throwDOMException(IndexSizeError, "The index provided
(" + String::number(index) + ") is greater than or equal to the maximum bound (
" + String::number(allProperties.size()) + ")."); | 609 exceptionState.throwDOMException(IndexSizeError, "The index provided
(" + String::number(index) + ") is greater than or equal to the maximum bound (
" + String::number(allProperties.size()) + ")."); |
| 610 return false; | 610 return false; |
| 611 } | 611 } |
| 612 *oldText = allProperties.at(index).rawText; | |
| 613 editor.replaceProperty(index, propertyText); | 612 editor.replaceProperty(index, propertyText); |
| 614 } else | 613 } else { |
| 615 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); | 614 editor.insertProperty(index, propertyText, sourceData->ruleBodyRange.len
gth()); |
| 615 } |
| 616 | 616 |
| 617 return applyStyleText(editor.styleText()); | 617 return m_parentStyleSheet->setStyleText(m_styleId, editor.styleText()); |
| 618 } | 618 } |
| 619 | 619 |
| 620 bool InspectorStyle::styleText(String* result) const | 620 bool InspectorStyle::styleText(String* result) const |
| 621 { | 621 { |
| 622 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); | 622 RefPtr<CSSRuleSourceData> sourceData = extractSourceData(); |
| 623 if (!sourceData) | 623 if (!sourceData) |
| 624 return false; | 624 return false; |
| 625 | 625 |
| 626 String styleSheetText; | 626 String styleSheetText; |
| 627 bool success = m_parentStyleSheet->getText(&styleSheetText); | 627 bool success = m_parentStyleSheet->getText(&styleSheetText); |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 726 return result.release(); | 726 return result.release(); |
| 727 } | 727 } |
| 728 | 728 |
| 729 PassRefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const | 729 PassRefPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() const |
| 730 { | 730 { |
| 731 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) | 731 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) |
| 732 return nullptr; | 732 return nullptr; |
| 733 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); | 733 return m_parentStyleSheet->ruleSourceDataFor(m_style.get()); |
| 734 } | 734 } |
| 735 | 735 |
| 736 bool InspectorStyle::applyStyleText(const String& text) | |
| 737 { | |
| 738 return m_parentStyleSheet->setStyleText(m_style.get(), text); | |
| 739 } | |
| 740 | |
| 741 String InspectorStyle::shorthandValue(const String& shorthandProperty) const | 736 String InspectorStyle::shorthandValue(const String& shorthandProperty) const |
| 742 { | 737 { |
| 743 String value = m_style->getPropertyValue(shorthandProperty); | 738 String value = m_style->getPropertyValue(shorthandProperty); |
| 744 if (value.isEmpty()) { | 739 if (value.isEmpty()) { |
| 745 StringBuilder builder; | 740 StringBuilder builder; |
| 746 | 741 |
| 747 for (unsigned i = 0; i < m_style->length(); ++i) { | 742 for (unsigned i = 0; i < m_style->length(); ++i) { |
| 748 String individualProperty = m_style->item(i); | 743 String individualProperty = m_style->item(i); |
| 749 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr
operty) | 744 if (m_style->getPropertyShorthand(individualProperty) != shorthandPr
operty) |
| 750 continue; | 745 continue; |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 832 { | 827 { |
| 833 return m_parentStyleSheet->ownerDocument(); | 828 return m_parentStyleSheet->ownerDocument(); |
| 834 } | 829 } |
| 835 | 830 |
| 836 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis
tener) | 831 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis
tener) |
| 837 : m_id(id) | 832 : m_id(id) |
| 838 , m_listener(listener) | 833 , m_listener(listener) |
| 839 { | 834 { |
| 840 } | 835 } |
| 841 | 836 |
| 842 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned
propertyIndex, const String& text, bool overwrite, String* oldText, ExceptionSt
ate& exceptionState) | 837 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned
propertyIndex, const String& text, bool overwrite, ExceptionState& exceptionSta
te) |
| 843 { | 838 { |
| 844 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); | 839 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); |
| 845 if (!inspectorStyle) { | 840 if (!inspectorStyle) { |
| 846 exceptionState.throwDOMException(NotFoundError, "No property could be fo
und for the given ID."); | 841 exceptionState.throwDOMException(NotFoundError, "No property could be fo
und for the given ID."); |
| 847 return false; | 842 return false; |
| 848 } | 843 } |
| 844 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep
tionState); |
| 845 } |
| 849 | 846 |
| 850 bool success = inspectorStyle->setPropertyText(propertyIndex, text, overwrit
e, oldText, exceptionState); | 847 bool InspectorStyleSheetBase::getStyleText(const InspectorCSSId& id, String* tex
t) |
| 851 if (success) | 848 { |
| 852 fireStyleSheetChanged(); | 849 RefPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); |
| 853 return success; | 850 if (!inspectorStyle) |
| 851 return false; |
| 852 return inspectorStyle->styleText(text); |
| 854 } | 853 } |
| 855 | 854 |
| 856 void InspectorStyleSheetBase::fireStyleSheetChanged() | 855 void InspectorStyleSheetBase::fireStyleSheetChanged() |
| 857 { | 856 { |
| 858 if (listener()) | 857 if (listener()) |
| 859 listener()->styleSheetChanged(this); | 858 listener()->styleSheetChanged(this); |
| 860 } | 859 } |
| 861 | 860 |
| 862 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) | 861 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt
yle(CSSStyleDeclaration* style) |
| 863 { | 862 { |
| (...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1382 } | 1381 } |
| 1383 } | 1382 } |
| 1384 | 1383 |
| 1385 void InspectorStyleSheet::ensureFlatRules() const | 1384 void InspectorStyleSheet::ensureFlatRules() const |
| 1386 { | 1385 { |
| 1387 // We are fine with redoing this for empty stylesheets as this will run fast
. | 1386 // We are fine with redoing this for empty stylesheets as this will run fast
. |
| 1388 if (m_flatRules.isEmpty()) | 1387 if (m_flatRules.isEmpty()) |
| 1389 collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules); | 1388 collectFlatRules(asCSSRuleList(pageStyleSheet()), &m_flatRules); |
| 1390 } | 1389 } |
| 1391 | 1390 |
| 1392 bool InspectorStyleSheet::setStyleText(CSSStyleDeclaration* style, const String&
text) | 1391 bool InspectorStyleSheet::setStyleText(const InspectorCSSId& id, const String& t
ext) |
| 1393 { | 1392 { |
| 1393 CSSStyleDeclaration* style = styleForId(id); |
| 1394 if (!style) |
| 1395 return false; |
| 1396 |
| 1394 if (!ensureParsedDataReady()) | 1397 if (!ensureParsedDataReady()) |
| 1395 return false; | 1398 return false; |
| 1396 | 1399 |
| 1397 String patchedStyleSheetText; | 1400 String patchedStyleSheetText; |
| 1398 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee
tText); | 1401 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee
tText); |
| 1399 if (!success) | 1402 if (!success) |
| 1400 return false; | 1403 return false; |
| 1401 | 1404 |
| 1402 InspectorCSSId id = styleId(style); | |
| 1403 if (id.isEmpty()) | |
| 1404 return false; | |
| 1405 | |
| 1406 TrackExceptionState exceptionState; | 1405 TrackExceptionState exceptionState; |
| 1407 style->setCSSText(text, exceptionState); | 1406 style->setCSSText(text, exceptionState); |
| 1408 if (!exceptionState.hadException()) | 1407 if (!exceptionState.hadException()) { |
| 1409 m_parsedStyleSheet->setText(patchedStyleSheetText); | 1408 m_parsedStyleSheet->setText(patchedStyleSheetText); |
| 1409 fireStyleSheetChanged(); |
| 1410 } |
| 1410 | 1411 |
| 1411 return !exceptionState.hadException(); | 1412 return !exceptionState.hadException(); |
| 1412 } | 1413 } |
| 1413 | 1414 |
| 1414 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) | 1415 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st
yle, const String& newStyleText, String* result) |
| 1415 { | 1416 { |
| 1416 if (!style) | 1417 if (!style) |
| 1417 return false; | 1418 return false; |
| 1418 | |
| 1419 if (!ensureParsedDataReady()) | 1419 if (!ensureParsedDataReady()) |
| 1420 return false; | 1420 return false; |
| 1421 | 1421 |
| 1422 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style); | 1422 RefPtr<CSSRuleSourceData> sourceData = ruleSourceDataFor(style); |
| 1423 unsigned bodyStart = sourceData->ruleBodyRange.start; | 1423 unsigned bodyStart = sourceData->ruleBodyRange.start; |
| 1424 unsigned bodyEnd = sourceData->ruleBodyRange.end; | 1424 unsigned bodyEnd = sourceData->ruleBodyRange.end; |
| 1425 ASSERT(bodyStart <= bodyEnd); | 1425 ASSERT(bodyStart <= bodyEnd); |
| 1426 | 1426 |
| 1427 String text = m_parsedStyleSheet->text(); | 1427 String text = m_parsedStyleSheet->text(); |
| 1428 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex
clusive | 1428 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex
clusive |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1490 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() | 1490 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() |
| 1491 { | 1491 { |
| 1492 m_isStyleTextValid = false; | 1492 m_isStyleTextValid = false; |
| 1493 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle->
cssStyle()) | 1493 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle->
cssStyle()) |
| 1494 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin
eStyle(), this); | 1494 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin
eStyle(), this); |
| 1495 m_ruleSourceData.clear(); | 1495 m_ruleSourceData.clear(); |
| 1496 } | 1496 } |
| 1497 | 1497 |
| 1498 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta
te& exceptionState) | 1498 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta
te& exceptionState) |
| 1499 { | 1499 { |
| 1500 bool success = setStyleText(inlineStyle(), text); | 1500 bool success = setStyleText(InspectorCSSId(id(), 0), text); |
| 1501 if (!success) | 1501 if (!success) |
| 1502 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval
id."); | 1502 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval
id."); |
| 1503 else | 1503 else |
| 1504 fireStyleSheetChanged(); | 1504 fireStyleSheetChanged(); |
| 1505 return success; | 1505 return success; |
| 1506 } | 1506 } |
| 1507 | 1507 |
| 1508 bool InspectorStyleSheetForInlineStyle::getText(String* result) const | 1508 bool InspectorStyleSheetForInlineStyle::getText(String* result) const |
| 1509 { | 1509 { |
| 1510 if (!m_isStyleTextValid) { | 1510 if (!m_isStyleTextValid) { |
| 1511 m_styleText = elementStyleText(); | 1511 m_styleText = elementStyleText(); |
| 1512 m_isStyleTextValid = true; | 1512 m_isStyleTextValid = true; |
| 1513 } | 1513 } |
| 1514 *result = m_styleText; | 1514 *result = m_styleText; |
| 1515 return true; | 1515 return true; |
| 1516 } | 1516 } |
| 1517 | 1517 |
| 1518 bool InspectorStyleSheetForInlineStyle::setStyleText(CSSStyleDeclaration* style,
const String& text) | 1518 bool InspectorStyleSheetForInlineStyle::setStyleText(const InspectorCSSId& id, c
onst String& text) |
| 1519 { | 1519 { |
| 1520 CSSStyleDeclaration* style = styleForId(id); |
| 1521 if (!style) |
| 1522 return false; |
| 1520 ASSERT_UNUSED(style, style == inlineStyle()); | 1523 ASSERT_UNUSED(style, style == inlineStyle()); |
| 1521 TrackExceptionState exceptionState; | 1524 TrackExceptionState exceptionState; |
| 1522 | 1525 |
| 1523 { | 1526 { |
| 1524 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own
erDocument()); | 1527 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own
erDocument()); |
| 1525 m_element->setAttribute("style", AtomicString(text), exceptionState); | 1528 m_element->setAttribute("style", AtomicString(text), exceptionState); |
| 1526 } | 1529 } |
| 1527 | 1530 if (!exceptionState.hadException()) { |
| 1528 m_styleText = text; | 1531 m_styleText = text; |
| 1529 m_isStyleTextValid = true; | 1532 m_isStyleTextValid = true; |
| 1530 m_ruleSourceData.clear(); | 1533 m_ruleSourceData.clear(); |
| 1534 fireStyleSheetChanged(); |
| 1535 } |
| 1531 return !exceptionState.hadException(); | 1536 return !exceptionState.hadException(); |
| 1532 } | 1537 } |
| 1533 | 1538 |
| 1534 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const | 1539 Document* InspectorStyleSheetForInlineStyle::ownerDocument() const |
| 1535 { | 1540 { |
| 1536 return &m_element->document(); | 1541 return &m_element->document(); |
| 1537 } | 1542 } |
| 1538 | 1543 |
| 1539 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() | 1544 bool InspectorStyleSheetForInlineStyle::ensureParsedDataReady() |
| 1540 { | 1545 { |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1590 | 1595 |
| 1591 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); | 1596 RefPtrWillBeRawPtr<MutableStylePropertySet> tempDeclaration = MutableStylePr
opertySet::create(); |
| 1592 RuleSourceDataList ruleSourceDataResult; | 1597 RuleSourceDataList ruleSourceDataResult; |
| 1593 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); | 1598 StyleSheetHandler handler(m_styleText, &m_element->document(), m_element->do
cument().elementSheet().contents(), &ruleSourceDataResult); |
| 1594 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge
t(), m_styleText, &handler, m_element->document().elementSheet().contents()); | 1599 createCSSParser(&m_element->document())->parseDeclaration(tempDeclaration.ge
t(), m_styleText, &handler, m_element->document().elementSheet().contents()); |
| 1595 return ruleSourceDataResult.first().release(); | 1600 return ruleSourceDataResult.first().release(); |
| 1596 } | 1601 } |
| 1597 | 1602 |
| 1598 } // namespace WebCore | 1603 } // namespace WebCore |
| 1599 | 1604 |
| OLD | NEW |