Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(468)

Side by Side Diff: Source/core/inspector/InspectorStyleSheet.cpp

Issue 1177983006: DevTools: remove InspectorCSSId, it serves no purpose. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: properly encoding rules from UA styles. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 454 matching lines...) Expand 10 before | Expand all | Expand 10 after
465 465
466 if (rule->type() == CSSRule::MEDIA_RULE) 466 if (rule->type() == CSSRule::MEDIA_RULE)
467 return toCSSMediaRule(rule)->cssRules(); 467 return toCSSMediaRule(rule)->cssRules();
468 468
469 if (rule->type() == CSSRule::SUPPORTS_RULE) 469 if (rule->type() == CSSRule::SUPPORTS_RULE)
470 return toCSSSupportsRule(rule)->cssRules(); 470 return toCSSSupportsRule(rule)->cssRules();
471 471
472 return nullptr; 472 return nullptr;
473 } 473 }
474 474
475 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyle::create(const InspectorCSS Id& styleId, PassRefPtrWillBeRawPtr<CSSStyleDeclaration> style, InspectorStyleSh eetBase* parentStyleSheet) 475 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyle::create(unsigned ruleIndex , PassRefPtrWillBeRawPtr<CSSStyleDeclaration> style, InspectorStyleSheetBase* pa rentStyleSheet)
476 { 476 {
477 return adoptRefWillBeNoop(new InspectorStyle(styleId, style, parentStyleShee t)); 477 return adoptRefWillBeNoop(new InspectorStyle(ruleIndex, style, parentStyleSh eet));
478 } 478 }
479 479
480 InspectorStyle::InspectorStyle(const InspectorCSSId& styleId, PassRefPtrWillBeRa wPtr<CSSStyleDeclaration> style, InspectorStyleSheetBase* parentStyleSheet) 480 InspectorStyle::InspectorStyle(unsigned ruleIndex, PassRefPtrWillBeRawPtr<CSSSty leDeclaration> style, InspectorStyleSheetBase* parentStyleSheet)
481 : m_styleId(styleId) 481 : m_ruleIndex(ruleIndex)
482 , m_style(style) 482 , m_style(style)
483 , m_parentStyleSheet(parentStyleSheet) 483 , m_parentStyleSheet(parentStyleSheet)
484 , m_formatAcquired(false) 484 , m_formatAcquired(false)
485 { 485 {
486 ASSERT(m_style); 486 ASSERT(m_style);
487 } 487 }
488 488
489 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st 489 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyle::buildObjectForStyle() con st
490 { 490 {
491 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties(); 491 RefPtr<TypeBuilder::CSS::CSSStyle> result = styleWithProperties();
492 if (!m_styleId.isEmpty()) 492 if (m_parentStyleSheet && !m_parentStyleSheet->id().isEmpty())
493 result->setStyleSheetId(m_styleId.styleSheetId()); 493 result->setStyleSheetId(m_parentStyleSheet->id());
494 494
495 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); 495 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData();
496 if (sourceData) 496 if (sourceData)
497 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par entStyleSheet->lineEndings())); 497 result->setRange(buildSourceRangeObject(sourceData->ruleBodyRange, m_par entStyleSheet->lineEndings()));
498 498
499 return result.release(); 499 return result.release();
500 } 500 }
501 501
502 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp ectorStyle::buildArrayForComputedStyle() const 502 PassRefPtr<TypeBuilder::Array<TypeBuilder::CSS::CSSComputedStyleProperty> > Insp ectorStyle::buildArrayForComputedStyle() const
503 { 503 {
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 if (propertyData.at(propertyCount - 1).name != bogusPropertyName) 535 if (propertyData.at(propertyCount - 1).name != bogusPropertyName)
536 return false; 536 return false;
537 537
538 return true; 538 return true;
539 } 539 }
540 540
541 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText, bool overwrite, ExceptionState& exceptionState) 541 bool InspectorStyle::setPropertyText(unsigned index, const String& propertyText, bool overwrite, ExceptionState& exceptionState)
542 { 542 {
543 ASSERT(m_parentStyleSheet); 543 ASSERT(m_parentStyleSheet);
544 544
545 if (m_ruleIndex == UINT_MAX) {
546 exceptionState.throwDOMException(NotFoundError, "The style is read-only. ");
547 return false;
548 }
549
545 if (!m_parentStyleSheet->ensureParsedDataReady()) { 550 if (!m_parentStyleSheet->ensureParsedDataReady()) {
546 exceptionState.throwDOMException(NotFoundError, "The parent style sheet' s data hasn't been processed."); 551 exceptionState.throwDOMException(NotFoundError, "The parent style sheet' s data hasn't been processed.");
547 return false; 552 return false;
548 } 553 }
549 554
550 if (!propertyText.stripWhiteSpace().isEmpty()) { 555 if (!propertyText.stripWhiteSpace().isEmpty()) {
551 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop ertyText, true)) { 556 if (!verifyPropertyText(propertyText, false) && !verifyPropertyText(prop ertyText, true)) {
552 exceptionState.throwDOMException(SyntaxError, "The property '" + pro pertyText + "' could not be set."); 557 exceptionState.throwDOMException(SyntaxError, "The property '" + pro pertyText + "' could not be set.");
553 return false; 558 return false;
554 } 559 }
(...skipping 19 matching lines...) Expand all
574 if (overwrite) { 579 if (overwrite) {
575 if (index >= allProperties.size()) { 580 if (index >= allProperties.size()) {
576 exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is greater than or equal to the maximum bound ( " + String::number(allProperties.size()) + ")."); 581 exceptionState.throwDOMException(IndexSizeError, "The index provided (" + String::number(index) + ") is greater than or equal to the maximum bound ( " + String::number(allProperties.size()) + ").");
577 return false; 582 return false;
578 } 583 }
579 editor.replaceProperty(index, propertyText); 584 editor.replaceProperty(index, propertyText);
580 } else { 585 } else {
581 editor.insertProperty(index, propertyText); 586 editor.insertProperty(index, propertyText);
582 } 587 }
583 588
584 return m_parentStyleSheet->setStyleText(m_styleId, editor.styleText()); 589 return m_parentStyleSheet->setStyleText(m_ruleIndex, editor.styleText());
585 } 590 }
586 591
587 bool InspectorStyle::styleText(String* result) const 592 bool InspectorStyle::styleText(String* result) const
588 { 593 {
589 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); 594 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData();
590 if (!sourceData) 595 if (!sourceData)
591 return false; 596 return false;
592 597
593 return textForRange(sourceData->ruleBodyRange, result); 598 return textForRange(sourceData->ruleBodyRange, result);
594 } 599 }
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after
688 } 693 }
689 694
690 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() 695 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te()
691 .setCssProperties(propertiesObject) 696 .setCssProperties(propertiesObject)
692 .setShorthandEntries(shorthandEntries); 697 .setShorthandEntries(shorthandEntries);
693 return result.release(); 698 return result.release();
694 } 699 }
695 700
696 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co nst 701 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co nst
697 { 702 {
698 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) 703 if (m_ruleIndex == UINT_MAX || !m_parentStyleSheet || !m_parentStyleSheet->e nsureParsedDataReady())
699 return nullptr; 704 return nullptr;
700 return m_parentStyleSheet->ruleSourceDataAt(m_styleId.ordinal()); 705 return m_parentStyleSheet->ruleSourceDataAt(m_ruleIndex);
701 } 706 }
702 707
703 String InspectorStyle::shorthandValue(const String& shorthandProperty) const 708 String InspectorStyle::shorthandValue(const String& shorthandProperty) const
704 { 709 {
705 String value = m_style->getPropertyValue(shorthandProperty); 710 String value = m_style->getPropertyValue(shorthandProperty);
706 if (value.isEmpty()) { 711 if (value.isEmpty()) {
707 StringBuilder builder; 712 StringBuilder builder;
708 713
709 for (unsigned i = 0; i < m_style->length(); ++i) { 714 for (unsigned i = 0; i < m_style->length(); ++i) {
710 String individualProperty = m_style->item(i); 715 String individualProperty = m_style->item(i);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 visitor->trace(m_parentStyleSheet); 806 visitor->trace(m_parentStyleSheet);
802 } 807 }
803 808
804 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) 809 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener)
805 : m_id(id) 810 : m_id(id)
806 , m_listener(listener) 811 , m_listener(listener)
807 , m_lineEndings(adoptPtr(new LineEndings())) 812 , m_lineEndings(adoptPtr(new LineEndings()))
808 { 813 {
809 } 814 }
810 815
811 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, ExceptionState& exceptionSta te) 816 bool InspectorStyleSheetBase::setPropertyText(unsigned ruleIndex, unsigned prope rtyIndex, const String& text, bool overwrite, ExceptionState& exceptionState)
812 { 817 {
813 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 818 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
814 if (!inspectorStyle) { 819 if (!inspectorStyle) {
815 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID."); 820 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID.");
816 return false; 821 return false;
817 } 822 }
818 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep tionState); 823 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep tionState);
819 } 824 }
820 825
821 bool InspectorStyleSheetBase::getStyleText(const InspectorCSSId& id, String* tex t) 826 bool InspectorStyleSheetBase::getStyleText(unsigned ruleIndex, String* text)
822 { 827 {
823 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 828 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
824 if (!inspectorStyle) 829 if (!inspectorStyle)
825 return false; 830 return false;
826 return inspectorStyle->styleText(text); 831 return inspectorStyle->styleText(text);
827 } 832 }
828 833
829 void InspectorStyleSheetBase::onStyleSheetTextChanged() 834 void InspectorStyleSheetBase::onStyleSheetTextChanged()
830 { 835 {
831 m_lineEndings = adoptPtr(new LineEndings()); 836 m_lineEndings = adoptPtr(new LineEndings());
832 if (listener()) 837 if (listener())
833 listener()->styleSheetChanged(this); 838 listener()->styleSheetChanged(this);
834 } 839 }
835 840
836 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) 841 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style)
837 { 842 {
838 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; 843 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
839 if (ensureParsedDataReady()) 844 unsigned ruleIndex = indexOf(style);
840 sourceData = ruleSourceDataAt(styleId(style).ordinal()); 845 if (ruleIndex != UINT_MAX && ensureParsedDataReady())
846 sourceData = ruleSourceDataAt(ruleIndex);
841 847
842 InspectorCSSId id = styleId(style); 848 if (ruleIndex == UINT_MAX) {
843 if (id.isEmpty()) {
844 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. 849 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id.
845 // See InspectorCSSAgent::buildObjectForRule for details. 850 // See InspectorCSSAgent::buildObjectForRule for details.
846 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::crea te(id, style, this); 851 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::crea te(UINT_MAX, style, this);
847 return inspectorStyle->buildObjectForStyle(); 852 return inspectorStyle->buildObjectForStyle();
848 } 853 }
849 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 854 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
850 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle(); 855 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle();
851 856
852 // Style text cannot be retrieved without stylesheet, so set cssText here. 857 // Style text cannot be retrieved without stylesheet, so set cssText here.
853 if (sourceData) { 858 if (sourceData) {
854 String sheetText; 859 String sheetText;
855 bool success = getText(&sheetText); 860 bool success = getText(&sheetText);
856 if (success) { 861 if (success) {
857 const SourceRange& bodyRange = sourceData->ruleBodyRange; 862 const SourceRange& bodyRange = sourceData->ruleBodyRange;
858 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); 863 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start));
859 } 864 }
(...skipping 18 matching lines...) Expand all
878 if (lineNumber >= endings->size()) 883 if (lineNumber >= endings->size())
879 return false; 884 return false;
880 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin gs->at(lineNumber - 1) - 1 : endings->at(0); 885 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin gs->at(lineNumber - 1) - 1 : endings->at(0);
881 if (columnNumber > charactersInLine) 886 if (columnNumber > charactersInLine)
882 return false; 887 return false;
883 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu mber::fromZeroBasedInt(columnNumber)); 888 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu mber::fromZeroBasedInt(columnNumber));
884 *offset = position.toOffset(*endings).zeroBasedInt(); 889 *offset = position.toOffset(*endings).zeroBasedInt();
885 return true; 890 return true;
886 } 891 }
887 892
888 bool InspectorStyleSheetBase::findPropertyByRange(const SourceRange& sourceRange , InspectorCSSId* ruleId, unsigned* propertyIndex, bool* overwrite) 893 bool InspectorStyleSheetBase::findPropertyByRange(const SourceRange& sourceRange , unsigned* ruleIndex, unsigned* propertyIndex, bool* overwrite)
889 { 894 {
890 if (!ensureParsedDataReady()) 895 if (!ensureParsedDataReady())
891 return false; 896 return false;
892 for (size_t i = 0; i < ruleCount(); ++i) { 897 for (size_t i = 0; i < ruleCount(); ++i) {
893 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 898 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
894 RefPtrWillBeRawPtr<CSSStyleSourceData> styleSourceData = ruleSourceData- >styleSourceData; 899 RefPtrWillBeRawPtr<CSSStyleSourceData> styleSourceData = ruleSourceData- >styleSourceData;
895 if (!styleSourceData) 900 if (!styleSourceData)
896 continue; 901 continue;
897 if (ruleSourceData->ruleBodyRange.end < sourceRange.start || sourceRange .end < ruleSourceData->ruleBodyRange.start) 902 if (ruleSourceData->ruleBodyRange.end < sourceRange.start || sourceRange .end < ruleSourceData->ruleBodyRange.start)
898 continue; 903 continue;
899 WillBeHeapVector<CSSPropertySourceData>& propertyData = styleSourceData- >propertyData; 904 WillBeHeapVector<CSSPropertySourceData>& propertyData = styleSourceData- >propertyData;
900 for (size_t j = 0; j < propertyData.size(); ++j) { 905 for (size_t j = 0; j < propertyData.size(); ++j) {
901 CSSPropertySourceData& property = propertyData.at(j); 906 CSSPropertySourceData& property = propertyData.at(j);
902 unsigned styleStart = ruleSourceData->ruleBodyRange.start; 907 unsigned styleStart = ruleSourceData->ruleBodyRange.start;
903 if (sourceRange.length() && property.range.start == sourceRange.star t && property.range.end == sourceRange.end) { 908 if (sourceRange.length() && property.range.start == sourceRange.star t && property.range.end == sourceRange.end) {
904 *ruleId = InspectorCSSId(id(), i); 909 *ruleIndex = i;
905 *propertyIndex = j; 910 *propertyIndex = j;
906 *overwrite = true; 911 *overwrite = true;
907 return true; 912 return true;
908 } 913 }
909 if (!sourceRange.length() && styleStart <= sourceRange.start && sour ceRange.start <= property.range.start) { 914 if (!sourceRange.length() && styleStart <= sourceRange.start && sour ceRange.start <= property.range.start) {
910 *ruleId = InspectorCSSId(id(), i); 915 *ruleIndex = i;
911 *propertyIndex = j; 916 *propertyIndex = j;
912 *overwrite = false; 917 *overwrite = false;
913 return true; 918 return true;
914 } 919 }
915 } 920 }
916 if (!sourceRange.length() && ruleSourceData->ruleBodyRange.start <= sour ceRange.start && sourceRange.start <= ruleSourceData->ruleBodyRange.end) { 921 if (!sourceRange.length() && ruleSourceData->ruleBodyRange.start <= sour ceRange.start && sourceRange.start <= ruleSourceData->ruleBodyRange.end) {
917 *ruleId = InspectorCSSId(id(), i); 922 *ruleIndex = i;
918 *propertyIndex = propertyData.size(); 923 *propertyIndex = propertyData.size();
919 *overwrite = false; 924 *overwrite = false;
920 return true; 925 return true;
921 } 926 }
922 } 927 }
923 return false; 928 return false;
924 } 929 }
925 930
926 PassRefPtrWillBeRawPtr<InspectorStyleSheet> InspectorStyleSheet::create(Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyle Sheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const St ring& documentURL, InspectorCSSAgent* cssAgent) 931 PassRefPtrWillBeRawPtr<InspectorStyleSheet> InspectorStyleSheet::create(Inspecto rResourceAgent* resourceAgent, const String& id, PassRefPtrWillBeRawPtr<CSSStyle Sheet> pageStyleSheet, TypeBuilder::CSS::StyleSheetOrigin::Enum origin, const St ring& documentURL, InspectorCSSAgent* cssAgent)
927 { 932 {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 m_pageStyleSheet->contents()->parseString(text); 989 m_pageStyleSheet->contents()->parseString(text);
985 } 990 }
986 991
987 if (listener()) 992 if (listener())
988 listener()->didReparseStyleSheet(); 993 listener()->didReparseStyleSheet();
989 onStyleSheetTextChanged(); 994 onStyleSheetTextChanged();
990 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); 995 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate);
991 return true; 996 return true;
992 } 997 }
993 998
994 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) 999 String InspectorStyleSheet::ruleSelector(unsigned ruleIndex, ExceptionState& exc eptionState)
995 { 1000 {
996 CSSStyleRule* rule = ruleForId(id); 1001 CSSStyleRule* rule = ruleAt(ruleIndex);
997 if (!rule) { 1002 if (!rule) {
998 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1003 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
999 return ""; 1004 return "";
1000 } 1005 }
1001 return rule->selectorText(); 1006 return rule->selectorText();
1002 } 1007 }
1003 1008
1004 bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String & selector, ExceptionState& exceptionState) 1009 bool InspectorStyleSheet::setRuleSelector(unsigned ruleIndex, const String& sele ctor, ExceptionState& exceptionState)
1005 { 1010 {
1006 CSSStyleRule* rule = ruleForId(id); 1011 CSSStyleRule* rule = ruleAt(ruleIndex);
1007 if (!rule) { 1012 if (!rule) {
1008 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1013 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
1009 return false; 1014 return false;
1010 } 1015 }
1011 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1016 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1012 if (!styleSheet || !ensureParsedDataReady()) { 1017 if (!styleSheet || !ensureParsedDataReady()) {
1013 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector."); 1018 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector.");
1014 return false; 1019 return false;
1015 } 1020 }
1016 1021
1017 if (!verifySelectorText(selector)) { 1022 if (!verifySelectorText(selector)) {
1018 exceptionState.throwDOMException(SyntaxError, "Selector text is not vali d."); 1023 exceptionState.throwDOMException(SyntaxError, "Selector text is not vali d.");
1019 return false; 1024 return false;
1020 } 1025 }
1021 1026
1022 rule->setSelectorText(selector); 1027 rule->setSelectorText(selector);
1023 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1028 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1024 ASSERT(sourceData); 1029 ASSERT(sourceData);
1025 1030
1026 String sheetText = m_parsedStyleSheet->text(); 1031 String sheetText = m_parsedStyleSheet->text();
1027 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), selector); 1032 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), selector);
1028 updateText(sheetText); 1033 updateText(sheetText);
1029 onStyleSheetTextChanged(); 1034 onStyleSheetTextChanged();
1030 return true; 1035 return true;
1031 } 1036 }
1032 1037
1033 String InspectorStyleSheet::mediaRuleText(const InspectorCSSId& id, ExceptionSta te& exceptionState) 1038 String InspectorStyleSheet::mediaRuleText(unsigned ruleIndex, ExceptionState& ex ceptionState)
1034 { 1039 {
1035 CSSMediaRule* rule = mediaRuleForId(id); 1040 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1036 if (!rule) { 1041 if (!rule) {
1037 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID."); 1042 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1038 return ""; 1043 return "";
1039 } 1044 }
1040 return rule->media()->mediaText(); 1045 return rule->media()->mediaText();
1041 } 1046 }
1042 1047
1043 bool InspectorStyleSheet::setMediaRuleText(const InspectorCSSId& id, const Strin g& text, ExceptionState& exceptionState) 1048 bool InspectorStyleSheet::setMediaRuleText(unsigned ruleIndex, const String& tex t, ExceptionState& exceptionState)
1044 { 1049 {
1045 CSSMediaRule* rule = mediaRuleForId(id); 1050 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1046 if (!rule) { 1051 if (!rule) {
1047 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID."); 1052 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1048 return false; 1053 return false;
1049 } 1054 }
1050 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1055 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1051 if (!styleSheet || !ensureParsedDataReady()) { 1056 if (!styleSheet || !ensureParsedDataReady()) {
1052 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the media text."); 1057 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the media text.");
1053 return false; 1058 return false;
1054 } 1059 }
1055 if (!verifyMediaText(text)) { 1060 if (!verifyMediaText(text)) {
1056 exceptionState.throwDOMException(SyntaxError, "Media text is not valid." ); 1061 exceptionState.throwDOMException(SyntaxError, "Media text is not valid." );
1057 return false; 1062 return false;
1058 } 1063 }
1059 1064
1060 rule->media()->setMediaText(text); 1065 rule->media()->setMediaText(text);
1061 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1066 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1062 ASSERT(sourceData && sourceData->mediaSourceData); 1067 ASSERT(sourceData && sourceData->mediaSourceData);
1063 1068
1064 String sheetText = m_parsedStyleSheet->text(); 1069 String sheetText = m_parsedStyleSheet->text();
1065 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), text); 1070 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), text);
1066 updateText(sheetText); 1071 updateText(sheetText);
1067 onStyleSheetTextChanged(); 1072 onStyleSheetTextChanged();
1068 return true; 1073 return true;
1069 } 1074 }
1070 1075
1071 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) 1076 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange)
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1262
1258 text.insert(ruleText, location.start); 1263 text.insert(ruleText, location.start);
1259 1264
1260 updateText(text); 1265 updateText(text);
1261 m_flatRules.clear(); 1266 m_flatRules.clear();
1262 1267
1263 onStyleSheetTextChanged(); 1268 onStyleSheetTextChanged();
1264 return styleRule; 1269 return styleRule;
1265 } 1270 }
1266 1271
1267 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, const String& old Text, ExceptionState& exceptionState) 1272 bool InspectorStyleSheet::deleteRule(unsigned ruleIndex, const String& oldText, ExceptionState& exceptionState)
1268 { 1273 {
1269 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); 1274 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleAt(ruleIndex);
1270 if (!rule) { 1275 if (!rule) {
1271 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1276 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1272 return false; 1277 return false;
1273 } 1278 }
1274 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1279 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1275 if (!styleSheet || !ensureParsedDataReady()) { 1280 if (!styleSheet || !ensureParsedDataReady()) {
1276 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); 1281 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found.");
1277 return false; 1282 return false;
1278 } 1283 }
1279 1284
1280 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1285 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1281 if (!sourceData) { 1286 if (!sourceData) {
1282 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1287 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1283 return false; 1288 return false;
1284 } 1289 }
1285 1290
1286 CSSRule* parentRule = rule->parentRule(); 1291 CSSRule* parentRule = rule->parentRule();
1287 if (parentRule) { 1292 if (parentRule) {
1288 if (parentRule->type() != CSSRule::MEDIA_RULE) { 1293 if (parentRule->type() != CSSRule::MEDIA_RULE) {
1289 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule."); 1294 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule.");
1290 return false; 1295 return false;
(...skipping 25 matching lines...) Expand all
1316 void InspectorStyleSheet::updateText(const String& newText) 1321 void InspectorStyleSheet::updateText(const String& newText)
1317 { 1322 {
1318 Element* element = ownerStyleElement(); 1323 Element* element = ownerStyleElement();
1319 if (element) 1324 if (element)
1320 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); 1325 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t);
1321 else 1326 else
1322 m_cssAgent->addEditedStyleSheet(finalURL(), newText); 1327 m_cssAgent->addEditedStyleSheet(finalURL(), newText);
1323 m_parsedStyleSheet->setText(newText); 1328 m_parsedStyleSheet->setText(newText);
1324 } 1329 }
1325 1330
1326 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const 1331 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const
1327 { 1332 {
1328 ASSERT(!id.isEmpty()); 1333 ASSERT(!id().isEmpty());
1329 ensureFlatRules(); 1334 ensureFlatRules();
1330 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size() ? nullptr : m_flatRules.at(id.ordinal()).get()); 1335 return InspectorCSSAgent::asCSSStyleRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get());
1331 } 1336 }
1332 1337
1333 CSSMediaRule* InspectorStyleSheet::mediaRuleForId(const InspectorCSSId& id) cons t 1338 CSSMediaRule* InspectorStyleSheet::mediaRuleAt(unsigned ruleIndex) const
1334 { 1339 {
1335 ASSERT(!id.isEmpty()); 1340 ASSERT(!id().isEmpty());
1336 ensureFlatRules(); 1341 ensureFlatRules();
1337 return InspectorCSSAgent::asCSSMediaRule(id.ordinal() >= m_flatRules.size() ? nullptr : m_flatRules.at(id.ordinal()).get()); 1342 return InspectorCSSAgent::asCSSMediaRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get());
1338 } 1343 }
1339 1344
1340 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const 1345 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const
1341 { 1346 {
1342 CSSStyleSheet* styleSheet = pageStyleSheet(); 1347 CSSStyleSheet* styleSheet = pageStyleSheet();
1343 if (!styleSheet) 1348 if (!styleSheet)
1344 return nullptr; 1349 return nullptr;
1345 1350
1346 Document* document = styleSheet->ownerDocument(); 1351 Document* document = styleSheet->ownerDocument();
1347 LocalFrame* frame = document ? document->frame() : nullptr; 1352 LocalFrame* frame = document ? document->frame() : nullptr;
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 .setValue(selector.stripWhiteSpace()); 1393 .setValue(selector.stripWhiteSpace());
1389 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); 1394 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings()));
1390 result->addItem(simpleSelector.release()); 1395 result->addItem(simpleSelector.release());
1391 } 1396 }
1392 return result.release(); 1397 return result.release();
1393 } 1398 }
1394 1399
1395 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) 1400 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule)
1396 { 1401 {
1397 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; 1402 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
1398 if (ensureParsedDataReady()) 1403 unsigned ruleIndex = indexOf(rule->style());
1399 sourceData = ruleSourceDataAt(styleId(rule->style()).ordinal()); 1404 if (ruleIndex != UINT_MAX && ensureParsedDataReady())
1405 sourceData = ruleSourceDataAt(ruleIndex);
1400 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; 1406 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors;
1401 1407
1402 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). 1408 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{').
1403 String selectorText = rule->selectorText(); 1409 String selectorText = rule->selectorText();
1404 1410
1405 if (sourceData) 1411 if (sourceData)
1406 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); 1412 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt());
1407 else { 1413 else {
1408 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); 1414 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create();
1409 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); 1415 const CSSSelectorList& selectorList = rule->styleRule()->selectorList();
(...skipping 17 matching lines...) Expand all
1427 CSSStyleSheet* styleSheet = pageStyleSheet(); 1433 CSSStyleSheet* styleSheet = pageStyleSheet();
1428 if (!styleSheet) 1434 if (!styleSheet)
1429 return nullptr; 1435 return nullptr;
1430 1436
1431 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create () 1437 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create ()
1432 .setSelectorList(buildObjectForSelectorList(rule)) 1438 .setSelectorList(buildObjectForSelectorList(rule))
1433 .setOrigin(m_origin) 1439 .setOrigin(m_origin)
1434 .setStyle(buildObjectForStyle(rule->style())); 1440 .setStyle(buildObjectForStyle(rule->style()));
1435 1441
1436 if (canBind(m_origin)) { 1442 if (canBind(m_origin)) {
1437 InspectorCSSId id(ruleId(rule)); 1443 if (!id().isEmpty())
1438 if (!id.isEmpty()) 1444 result->setStyleSheetId(id());
1439 result->setStyleSheetId(id.styleSheetId());
1440 } 1445 }
1441 1446
1442 if (mediaStack) 1447 if (mediaStack)
1443 result->setMedia(mediaStack); 1448 result->setMedia(mediaStack);
1444 1449
1445 return result.release(); 1450 return result.release();
1446 } 1451 }
1447 1452
1448 bool InspectorStyleSheet::getText(String* result) const 1453 bool InspectorStyleSheet::getText(String* result) const
1449 { 1454 {
1450 if (!ensureText()) 1455 if (!ensureText())
1451 return false; 1456 return false;
1452 *result = m_parsedStyleSheet->text(); 1457 *result = m_parsedStyleSheet->text();
1453 return true; 1458 return true;
1454 } 1459 }
1455 1460
1456 CSSStyleDeclaration* InspectorStyleSheet::styleForId(const InspectorCSSId& id) c onst 1461 CSSStyleDeclaration* InspectorStyleSheet::styleAt(unsigned ruleIndex) const
1457 { 1462 {
1458 CSSStyleRule* rule = ruleForId(id); 1463 CSSStyleRule* rule = ruleAt(ruleIndex);
1459 if (!rule) 1464 if (!rule)
1460 return nullptr; 1465 return nullptr;
1461 1466
1462 return rule->style(); 1467 return rule->style();
1463 } 1468 }
1464 1469
1465 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) 1470 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule)
1466 { 1471 {
1467 if (!ensureParsedDataReady()) 1472 if (!ensureParsedDataReady())
1468 return nullptr; 1473 return nullptr;
(...skipping 19 matching lines...) Expand all
1488 return nullptr; 1493 return nullptr;
1489 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); 1494 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index));
1490 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) 1495 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size())
1491 return nullptr; 1496 return nullptr;
1492 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); 1497 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex);
1493 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) 1498 if (mediaQueryExpIndex >= mediaQueryData->expData.size())
1494 return nullptr; 1499 return nullptr;
1495 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); 1500 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings());
1496 } 1501 }
1497 1502
1498 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId( const InspectorCSSId& id) 1503 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleAt(uns igned ruleIndex)
1499 { 1504 {
1500 CSSStyleDeclaration* style = styleForId(id); 1505 CSSStyleDeclaration* style = styleAt(ruleIndex);
1501 if (!style) 1506 if (!style)
1502 return nullptr; 1507 return nullptr;
1503 1508
1504 return InspectorStyle::create(id, style, this); 1509 return InspectorStyle::create(ruleIndex, style, this);
1505 } 1510 }
1506 1511
1507 unsigned InspectorStyleSheet::ruleCount() 1512 unsigned InspectorStyleSheet::ruleCount()
1508 { 1513 {
1509 return m_parsedStyleSheet->ruleCount(); 1514 return m_parsedStyleSheet->ruleCount();
1510 } 1515 }
1511 1516
1512 String InspectorStyleSheet::sourceURL() const 1517 String InspectorStyleSheet::sourceURL() const
1513 { 1518 {
1514 if (!m_sourceURL.isNull()) 1519 if (!m_sourceURL.isNull())
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 bool deprecated; 1582 bool deprecated;
1578 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated); 1583 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated);
1579 if (!commentValue.isEmpty()) { 1584 if (!commentValue.isEmpty()) {
1580 // FIXME: add deprecated console message here. 1585 // FIXME: add deprecated console message here.
1581 return commentValue; 1586 return commentValue;
1582 } 1587 }
1583 } 1588 }
1584 return m_pageStyleSheet->contents()->sourceMapURL(); 1589 return m_pageStyleSheet->contents()->sourceMapURL();
1585 } 1590 }
1586 1591
1587 InspectorCSSId InspectorStyleSheet::styleId(CSSStyleDeclaration* style) const 1592 unsigned InspectorStyleSheet::indexOf(CSSStyleDeclaration* style) const
1588 { 1593 {
1589 unsigned index = ruleIndexByStyle(style); 1594 ensureFlatRules();
1590 if (index != UINT_MAX) 1595 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
1591 return InspectorCSSId(id(), index); 1596 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get());
1592 return InspectorCSSId(); 1597 if (styleRule && styleRule->style() == style)
1598 return i;
1599 }
1600 return UINT_MAX;
1593 } 1601 }
1594 1602
1595 bool InspectorStyleSheet::findRuleBySelectorRange(const SourceRange& sourceRange , InspectorCSSId* ruleId) 1603 bool InspectorStyleSheet::findRuleBySelectorRange(const SourceRange& sourceRange , unsigned* ruleIndex)
1596 { 1604 {
1597 if (!ensureParsedDataReady()) 1605 if (!ensureParsedDataReady())
1598 return false; 1606 return false;
1599 for (size_t i = 0; i < ruleCount(); ++i) { 1607 for (size_t i = 0; i < ruleCount(); ++i) {
1600 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 1608 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1601 if (!ruleSourceData->styleSourceData) 1609 if (!ruleSourceData->styleSourceData)
1602 continue; 1610 continue;
1603 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { 1611 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1604 *ruleId = InspectorCSSId(id(), i); 1612 *ruleIndex = i;
1605 return true; 1613 return true;
1606 } 1614 }
1607 } 1615 }
1608 return false; 1616 return false;
1609 } 1617 }
1610 1618
1611 bool InspectorStyleSheet::findMediaRuleByRange(const SourceRange& sourceRange, I nspectorCSSId* ruleId) 1619 bool InspectorStyleSheet::findMediaRuleByRange(const SourceRange& sourceRange, u nsigned* ruleIndex)
1612 { 1620 {
1613 if (!ensureParsedDataReady()) 1621 if (!ensureParsedDataReady())
1614 return false; 1622 return false;
1615 for (size_t i = 0; i < ruleCount(); ++i) { 1623 for (size_t i = 0; i < ruleCount(); ++i) {
1616 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 1624 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1617 if (!ruleSourceData->mediaSourceData) 1625 if (!ruleSourceData->mediaSourceData)
1618 continue; 1626 continue;
1619 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { 1627 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1620 *ruleId = InspectorCSSId(id(), i); 1628 *ruleIndex = i;
1621 return true; 1629 return true;
1622 } 1630 }
1623 } 1631 }
1624 return false; 1632 return false;
1625 } 1633 }
1626 1634
1627 const CSSRuleVector& InspectorStyleSheet::flatRules() 1635 const CSSRuleVector& InspectorStyleSheet::flatRules()
1628 { 1636 {
1629 ensureFlatRules(); 1637 ensureFlatRules();
1630 return m_flatRules; 1638 return m_flatRules;
1631 } 1639 }
1632 1640
1633 Document* InspectorStyleSheet::ownerDocument() const 1641 Document* InspectorStyleSheet::ownerDocument() const
1634 { 1642 {
1635 return m_pageStyleSheet->ownerDocument(); 1643 return m_pageStyleSheet->ownerDocument();
1636 } 1644 }
1637 1645
1638 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const 1646 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const
1639 { 1647 {
1640 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); 1648 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex);
1641 } 1649 }
1642 1650
1643 unsigned InspectorStyleSheet::ruleIndexByStyle(CSSStyleDeclaration* pageStyle) c onst
1644 {
1645 ensureFlatRules();
1646 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
1647 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get());
1648 if (styleRule && styleRule->style() == pageStyle)
1649 return i;
1650 }
1651 return UINT_MAX;
1652 }
1653
1654 bool InspectorStyleSheet::ensureParsedDataReady() 1651 bool InspectorStyleSheet::ensureParsedDataReady()
1655 { 1652 {
1656 return ensureText() && m_parsedStyleSheet->ensureSourceData(); 1653 return ensureText() && m_parsedStyleSheet->ensureSourceData();
1657 } 1654 }
1658 1655
1659 bool InspectorStyleSheet::ensureText() const 1656 bool InspectorStyleSheet::ensureText() const
1660 { 1657 {
1661 if (m_parsedStyleSheet->hasText()) 1658 if (m_parsedStyleSheet->hasText())
1662 return true; 1659 return true;
1663 1660
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 } 1698 }
1702 } 1699 }
1703 1700
1704 void InspectorStyleSheet::ensureFlatRules() const 1701 void InspectorStyleSheet::ensureFlatRules() const
1705 { 1702 {
1706 // We are fine with redoing this for empty stylesheets as this will run fast . 1703 // We are fine with redoing this for empty stylesheets as this will run fast .
1707 if (m_flatRules.isEmpty()) 1704 if (m_flatRules.isEmpty())
1708 collectFlatRules(pageStyleSheet(), &m_flatRules); 1705 collectFlatRules(pageStyleSheet(), &m_flatRules);
1709 } 1706 }
1710 1707
1711 bool InspectorStyleSheet::setStyleText(const InspectorCSSId& id, const String& t ext) 1708 bool InspectorStyleSheet::setStyleText(unsigned ruleIndex, const String& text)
1712 { 1709 {
1713 CSSStyleDeclaration* style = styleForId(id); 1710 CSSStyleDeclaration* style = styleAt(ruleIndex);
1714 if (!style) 1711 if (!style)
1715 return false; 1712 return false;
1716 1713
1717 if (!ensureParsedDataReady()) 1714 if (!ensureParsedDataReady())
1718 return false; 1715 return false;
1719 1716
1720 String patchedStyleSheetText; 1717 String patchedStyleSheetText;
1721 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); 1718 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText);
1722 if (!success) 1719 if (!success)
1723 return false; 1720 return false;
1724 1721
1725 TrackExceptionState exceptionState; 1722 TrackExceptionState exceptionState;
1726 style->setCSSText(text, exceptionState); 1723 style->setCSSText(text, exceptionState);
1727 if (!exceptionState.hadException()) { 1724 if (!exceptionState.hadException()) {
1728 updateText(patchedStyleSheetText); 1725 updateText(patchedStyleSheetText);
1729 onStyleSheetTextChanged(); 1726 onStyleSheetTextChanged();
1730 } 1727 }
1731 1728
1732 return !exceptionState.hadException(); 1729 return !exceptionState.hadException();
1733 } 1730 }
1734 1731
1735 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result) 1732 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result)
1736 { 1733 {
1737 if (!style) 1734 if (!style)
1738 return false; 1735 return false;
1739 if (!ensureParsedDataReady()) 1736
1737 unsigned ruleIndex = indexOf(style);
1738 if (!ensureParsedDataReady() || ruleIndex == UINT_MAX)
1740 return false; 1739 return false;
1741 1740
1742 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(styleId( style).ordinal()); 1741 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1743 unsigned bodyStart = sourceData->ruleBodyRange.start; 1742 unsigned bodyStart = sourceData->ruleBodyRange.start;
1744 unsigned bodyEnd = sourceData->ruleBodyRange.end; 1743 unsigned bodyEnd = sourceData->ruleBodyRange.end;
1745 ASSERT(bodyStart <= bodyEnd); 1744 ASSERT(bodyStart <= bodyEnd);
1746 1745
1747 String text = m_parsedStyleSheet->text(); 1746 String text = m_parsedStyleSheet->text();
1748 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive 1747 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive
1749 1748
1750 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); 1749 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText);
1751 *result = text; 1750 *result = text;
1752 return true; 1751 return true;
1753 } 1752 }
1754 1753
1755 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const 1754 unsigned InspectorStyleSheet::indexOf(CSSStyleRule* rule) const
1756 { 1755 {
1757 return styleId(rule->style()); 1756 return indexOf(rule->style());
1758 } 1757 }
1759 1758
1760 bool InspectorStyleSheet::originalStyleSheetText(String* result) const 1759 bool InspectorStyleSheet::originalStyleSheetText(String* result) const
1761 { 1760 {
1762 bool success = inlineStyleSheetText(result); 1761 bool success = inlineStyleSheetText(result);
1763 if (!success) 1762 if (!success)
1764 success = resourceStyleSheetText(result); 1763 success = resourceStyleSheetText(result);
1765 return success; 1764 return success;
1766 } 1765 }
1767 1766
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); 1809 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener));
1811 } 1810 }
1812 1811
1813 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) 1812 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener)
1814 : InspectorStyleSheetBase(id, listener) 1813 : InspectorStyleSheetBase(id, listener)
1815 , m_element(element) 1814 , m_element(element)
1816 , m_ruleSourceData(nullptr) 1815 , m_ruleSourceData(nullptr)
1817 , m_isStyleTextValid(false) 1816 , m_isStyleTextValid(false)
1818 { 1817 {
1819 ASSERT(m_element); 1818 ASSERT(m_element);
1820 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle (), this); 1819 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this);
1821 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String(); 1820 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String();
1822 } 1821 }
1823 1822
1824 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() 1823 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute()
1825 { 1824 {
1826 m_isStyleTextValid = false; 1825 m_isStyleTextValid = false;
1827 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) 1826 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle())
1828 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin eStyle(), this); 1827 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this);
1829 m_ruleSourceData.clear(); 1828 m_ruleSourceData.clear();
1830 } 1829 }
1831 1830
1832 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) 1831 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState)
1833 { 1832 {
1834 bool success = setStyleText(InspectorCSSId(id(), 0), text); 1833 bool success = setStyleText(0, text);
1835 if (!success) 1834 if (!success)
1836 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); 1835 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id.");
1837 return success; 1836 return success;
1838 } 1837 }
1839 1838
1840 bool InspectorStyleSheetForInlineStyle::getText(String* result) const 1839 bool InspectorStyleSheetForInlineStyle::getText(String* result) const
1841 { 1840 {
1842 if (!m_isStyleTextValid) { 1841 if (!m_isStyleTextValid) {
1843 m_styleText = elementStyleText(); 1842 m_styleText = elementStyleText();
1844 m_isStyleTextValid = true; 1843 m_isStyleTextValid = true;
1845 } 1844 }
1846 *result = m_styleText; 1845 *result = m_styleText;
1847 return true; 1846 return true;
1848 } 1847 }
1849 1848
1850 bool InspectorStyleSheetForInlineStyle::setStyleText(const InspectorCSSId& id, c onst String& text) 1849 bool InspectorStyleSheetForInlineStyle::setStyleText(unsigned ruleIndex, const S tring& text)
1851 { 1850 {
1852 CSSStyleDeclaration* style = styleForId(id); 1851 CSSStyleDeclaration* style = styleAt(ruleIndex);
1853 if (!style) 1852 if (!style)
1854 return false; 1853 return false;
1855 ASSERT_UNUSED(style, style == inlineStyle()); 1854 ASSERT_UNUSED(style, style == inlineStyle());
1856 TrackExceptionState exceptionState; 1855 TrackExceptionState exceptionState;
1857 1856
1858 { 1857 {
1859 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); 1858 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument());
1860 m_element->setAttribute("style", AtomicString(text), exceptionState); 1859 m_element->setAttribute("style", AtomicString(text), exceptionState);
1861 } 1860 }
1862 if (!exceptionState.hadException()) { 1861 if (!exceptionState.hadException()) {
(...skipping 27 matching lines...) Expand all
1890 1889
1891 bool success = !!m_ruleSourceData; 1890 bool success = !!m_ruleSourceData;
1892 if (!success) { 1891 if (!success) {
1893 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); 1892 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style);
1894 return false; 1893 return false;
1895 } 1894 }
1896 1895
1897 return true; 1896 return true;
1898 } 1897 }
1899 1898
1900 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleForId(const InspectorCSSId& id) 1899 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleAt(unsigned ruleIndex)
1901 { 1900 {
1902 ASSERT_UNUSED(id, !id.ordinal()); 1901 ASSERT_UNUSED(ruleIndex, !ruleIndex);
1903 return m_inspectorStyle; 1902 return m_inspectorStyle;
1904 } 1903 }
1905 1904
1906 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const 1905 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const
1907 { 1906 {
1908 return m_element->style(); 1907 return m_element->style();
1909 } 1908 }
1910 1909
1911 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const 1910 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const
1912 { 1911 {
(...skipping 20 matching lines...) Expand all
1933 1932
1934 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1933 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1935 { 1934 {
1936 visitor->trace(m_element); 1935 visitor->trace(m_element);
1937 visitor->trace(m_ruleSourceData); 1936 visitor->trace(m_ruleSourceData);
1938 visitor->trace(m_inspectorStyle); 1937 visitor->trace(m_inspectorStyle);
1939 InspectorStyleSheetBase::trace(visitor); 1938 InspectorStyleSheetBase::trace(visitor);
1940 } 1939 }
1941 1940
1942 } // namespace blink 1941 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/inspector/InspectorStyleSheet.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698