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

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: 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 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
574 if (overwrite) { 574 if (overwrite) {
575 if (index >= allProperties.size()) { 575 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()) + ")."); 576 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; 577 return false;
578 } 578 }
579 editor.replaceProperty(index, propertyText); 579 editor.replaceProperty(index, propertyText);
580 } else { 580 } else {
581 editor.insertProperty(index, propertyText); 581 editor.insertProperty(index, propertyText);
582 } 582 }
583 583
584 return m_parentStyleSheet->setStyleText(m_styleId, editor.styleText()); 584 return m_parentStyleSheet->setStyleText(m_ruleIndex, editor.styleText());
585 } 585 }
586 586
587 bool InspectorStyle::styleText(String* result) const 587 bool InspectorStyle::styleText(String* result) const
588 { 588 {
589 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData(); 589 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = extractSourceData();
590 if (!sourceData) 590 if (!sourceData)
591 return false; 591 return false;
592 592
593 return textForRange(sourceData->ruleBodyRange, result); 593 return textForRange(sourceData->ruleBodyRange, result);
594 } 594 }
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
690 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te() 690 RefPtr<TypeBuilder::CSS::CSSStyle> result = TypeBuilder::CSS::CSSStyle::crea te()
691 .setCssProperties(propertiesObject) 691 .setCssProperties(propertiesObject)
692 .setShorthandEntries(shorthandEntries); 692 .setShorthandEntries(shorthandEntries);
693 return result.release(); 693 return result.release();
694 } 694 }
695 695
696 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co nst 696 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyle::extractSourceData() co nst
697 { 697 {
698 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady()) 698 if (!m_parentStyleSheet || !m_parentStyleSheet->ensureParsedDataReady())
699 return nullptr; 699 return nullptr;
700 return m_parentStyleSheet->ruleSourceDataAt(m_styleId.ordinal()); 700 return m_parentStyleSheet->ruleSourceDataAt(m_ruleIndex);
701 } 701 }
702 702
703 String InspectorStyle::shorthandValue(const String& shorthandProperty) const 703 String InspectorStyle::shorthandValue(const String& shorthandProperty) const
704 { 704 {
705 String value = m_style->getPropertyValue(shorthandProperty); 705 String value = m_style->getPropertyValue(shorthandProperty);
706 if (value.isEmpty()) { 706 if (value.isEmpty()) {
707 StringBuilder builder; 707 StringBuilder builder;
708 708
709 for (unsigned i = 0; i < m_style->length(); ++i) { 709 for (unsigned i = 0; i < m_style->length(); ++i) {
710 String individualProperty = m_style->item(i); 710 String individualProperty = m_style->item(i);
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
801 visitor->trace(m_parentStyleSheet); 801 visitor->trace(m_parentStyleSheet);
802 } 802 }
803 803
804 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener) 804 InspectorStyleSheetBase::InspectorStyleSheetBase(const String& id, Listener* lis tener)
805 : m_id(id) 805 : m_id(id)
806 , m_listener(listener) 806 , m_listener(listener)
807 , m_lineEndings(adoptPtr(new LineEndings())) 807 , m_lineEndings(adoptPtr(new LineEndings()))
808 { 808 {
809 } 809 }
810 810
811 bool InspectorStyleSheetBase::setPropertyText(const InspectorCSSId& id, unsigned propertyIndex, const String& text, bool overwrite, ExceptionState& exceptionSta te) 811 bool InspectorStyleSheetBase::setPropertyText(unsigned ruleIndex, unsigned prope rtyIndex, const String& text, bool overwrite, ExceptionState& exceptionState)
812 { 812 {
813 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 813 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
814 if (!inspectorStyle) { 814 if (!inspectorStyle) {
815 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID."); 815 exceptionState.throwDOMException(NotFoundError, "No property could be fo und for the given ID.");
816 return false; 816 return false;
817 } 817 }
818 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep tionState); 818 return inspectorStyle->setPropertyText(propertyIndex, text, overwrite, excep tionState);
819 } 819 }
820 820
821 bool InspectorStyleSheetBase::getStyleText(const InspectorCSSId& id, String* tex t) 821 bool InspectorStyleSheetBase::getStyleText(unsigned ruleIndex, String* text)
822 { 822 {
823 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 823 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
824 if (!inspectorStyle) 824 if (!inspectorStyle)
825 return false; 825 return false;
826 return inspectorStyle->styleText(text); 826 return inspectorStyle->styleText(text);
827 } 827 }
828 828
829 void InspectorStyleSheetBase::onStyleSheetTextChanged() 829 void InspectorStyleSheetBase::onStyleSheetTextChanged()
830 { 830 {
831 m_lineEndings = adoptPtr(new LineEndings()); 831 m_lineEndings = adoptPtr(new LineEndings());
832 if (listener()) 832 if (listener())
833 listener()->styleSheetChanged(this); 833 listener()->styleSheetChanged(this);
834 } 834 }
835 835
836 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style) 836 PassRefPtr<TypeBuilder::CSS::CSSStyle> InspectorStyleSheetBase::buildObjectForSt yle(CSSStyleDeclaration* style)
837 { 837 {
838 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; 838 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
839 if (ensureParsedDataReady()) 839 if (ensureParsedDataReady())
840 sourceData = ruleSourceDataAt(styleId(style).ordinal()); 840 sourceData = ruleSourceDataAt(indexOf(style));
841 841
842 InspectorCSSId id = styleId(style); 842 unsigned ruleIndex = indexOf(style);
843 if (id.isEmpty()) { 843 if (id().isEmpty()) {
844 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id. 844 // Any rule coming from User Agent and not from DefaultStyleSheet will n ot have id.
845 // See InspectorCSSAgent::buildObjectForRule for details. 845 // See InspectorCSSAgent::buildObjectForRule for details.
846 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::crea te(id, style, this); 846 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = InspectorStyle::crea te(ruleIndex, style, this);
847 return inspectorStyle->buildObjectForStyle(); 847 return inspectorStyle->buildObjectForStyle();
848 } 848 }
849 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleForId(id); 849 RefPtrWillBeRawPtr<InspectorStyle> inspectorStyle = inspectorStyleAt(ruleInd ex);
850 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle(); 850 RefPtr<TypeBuilder::CSS::CSSStyle> result = inspectorStyle->buildObjectForSt yle();
851 851
852 // Style text cannot be retrieved without stylesheet, so set cssText here. 852 // Style text cannot be retrieved without stylesheet, so set cssText here.
853 if (sourceData) { 853 if (sourceData) {
854 String sheetText; 854 String sheetText;
855 bool success = getText(&sheetText); 855 bool success = getText(&sheetText);
856 if (success) { 856 if (success) {
857 const SourceRange& bodyRange = sourceData->ruleBodyRange; 857 const SourceRange& bodyRange = sourceData->ruleBodyRange;
858 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start)); 858 result->setCssText(sheetText.substring(bodyRange.start, bodyRange.en d - bodyRange.start));
859 } 859 }
(...skipping 18 matching lines...) Expand all
878 if (lineNumber >= endings->size()) 878 if (lineNumber >= endings->size())
879 return false; 879 return false;
880 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin gs->at(lineNumber - 1) - 1 : endings->at(0); 880 unsigned charactersInLine = lineNumber > 0 ? endings->at(lineNumber) - endin gs->at(lineNumber - 1) - 1 : endings->at(0);
881 if (columnNumber > charactersInLine) 881 if (columnNumber > charactersInLine)
882 return false; 882 return false;
883 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu mber::fromZeroBasedInt(columnNumber)); 883 TextPosition position(OrdinalNumber::fromZeroBasedInt(lineNumber), OrdinalNu mber::fromZeroBasedInt(columnNumber));
884 *offset = position.toOffset(*endings).zeroBasedInt(); 884 *offset = position.toOffset(*endings).zeroBasedInt();
885 return true; 885 return true;
886 } 886 }
887 887
888 bool InspectorStyleSheetBase::findPropertyByRange(const SourceRange& sourceRange , InspectorCSSId* ruleId, unsigned* propertyIndex, bool* overwrite) 888 bool InspectorStyleSheetBase::findPropertyByRange(const SourceRange& sourceRange , unsigned* ruleIndex, unsigned* propertyIndex, bool* overwrite)
889 { 889 {
890 if (!ensureParsedDataReady()) 890 if (!ensureParsedDataReady())
891 return false; 891 return false;
892 for (size_t i = 0; i < ruleCount(); ++i) { 892 for (size_t i = 0; i < ruleCount(); ++i) {
893 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 893 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
894 RefPtrWillBeRawPtr<CSSStyleSourceData> styleSourceData = ruleSourceData- >styleSourceData; 894 RefPtrWillBeRawPtr<CSSStyleSourceData> styleSourceData = ruleSourceData- >styleSourceData;
895 if (!styleSourceData) 895 if (!styleSourceData)
896 continue; 896 continue;
897 if (ruleSourceData->ruleBodyRange.end < sourceRange.start || sourceRange .end < ruleSourceData->ruleBodyRange.start) 897 if (ruleSourceData->ruleBodyRange.end < sourceRange.start || sourceRange .end < ruleSourceData->ruleBodyRange.start)
898 continue; 898 continue;
899 WillBeHeapVector<CSSPropertySourceData>& propertyData = styleSourceData- >propertyData; 899 WillBeHeapVector<CSSPropertySourceData>& propertyData = styleSourceData- >propertyData;
900 for (size_t j = 0; j < propertyData.size(); ++j) { 900 for (size_t j = 0; j < propertyData.size(); ++j) {
901 CSSPropertySourceData& property = propertyData.at(j); 901 CSSPropertySourceData& property = propertyData.at(j);
902 unsigned styleStart = ruleSourceData->ruleBodyRange.start; 902 unsigned styleStart = ruleSourceData->ruleBodyRange.start;
903 if (sourceRange.length() && property.range.start == sourceRange.star t && property.range.end == sourceRange.end) { 903 if (sourceRange.length() && property.range.start == sourceRange.star t && property.range.end == sourceRange.end) {
904 *ruleId = InspectorCSSId(id(), i); 904 *ruleIndex = i;
905 *propertyIndex = j; 905 *propertyIndex = j;
906 *overwrite = true; 906 *overwrite = true;
907 return true; 907 return true;
908 } 908 }
909 if (!sourceRange.length() && styleStart <= sourceRange.start && sour ceRange.start <= property.range.start) { 909 if (!sourceRange.length() && styleStart <= sourceRange.start && sour ceRange.start <= property.range.start) {
910 *ruleId = InspectorCSSId(id(), i); 910 *ruleIndex = i;
911 *propertyIndex = j; 911 *propertyIndex = j;
912 *overwrite = false; 912 *overwrite = false;
913 return true; 913 return true;
914 } 914 }
915 } 915 }
916 if (!sourceRange.length() && ruleSourceData->ruleBodyRange.start <= sour ceRange.start && sourceRange.start <= ruleSourceData->ruleBodyRange.end) { 916 if (!sourceRange.length() && ruleSourceData->ruleBodyRange.start <= sour ceRange.start && sourceRange.start <= ruleSourceData->ruleBodyRange.end) {
917 *ruleId = InspectorCSSId(id(), i); 917 *ruleIndex = i;
918 *propertyIndex = propertyData.size(); 918 *propertyIndex = propertyData.size();
919 *overwrite = false; 919 *overwrite = false;
920 return true; 920 return true;
921 } 921 }
922 } 922 }
923 return false; 923 return false;
924 } 924 }
925 925
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) 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)
927 { 927 {
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
984 m_pageStyleSheet->contents()->parseString(text); 984 m_pageStyleSheet->contents()->parseString(text);
985 } 985 }
986 986
987 if (listener()) 987 if (listener())
988 listener()->didReparseStyleSheet(); 988 listener()->didReparseStyleSheet();
989 onStyleSheetTextChanged(); 989 onStyleSheetTextChanged();
990 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate); 990 m_pageStyleSheet->ownerDocument()->styleResolverChanged(FullStyleUpdate);
991 return true; 991 return true;
992 } 992 }
993 993
994 String InspectorStyleSheet::ruleSelector(const InspectorCSSId& id, ExceptionStat e& exceptionState) 994 String InspectorStyleSheet::ruleSelector(unsigned ruleIndex, ExceptionState& exc eptionState)
995 { 995 {
996 CSSStyleRule* rule = ruleForId(id); 996 CSSStyleRule* rule = ruleAt(ruleIndex);
997 if (!rule) { 997 if (!rule) {
998 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 998 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
999 return ""; 999 return "";
1000 } 1000 }
1001 return rule->selectorText(); 1001 return rule->selectorText();
1002 } 1002 }
1003 1003
1004 bool InspectorStyleSheet::setRuleSelector(const InspectorCSSId& id, const String & selector, ExceptionState& exceptionState) 1004 bool InspectorStyleSheet::setRuleSelector(unsigned ruleIndex, const String& sele ctor, ExceptionState& exceptionState)
1005 { 1005 {
1006 CSSStyleRule* rule = ruleForId(id); 1006 CSSStyleRule* rule = ruleAt(ruleIndex);
1007 if (!rule) { 1007 if (!rule) {
1008 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID."); 1008 exceptionState.throwDOMException(NotFoundError, "No rule was found for t he given ID.");
1009 return false; 1009 return false;
1010 } 1010 }
1011 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1011 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1012 if (!styleSheet || !ensureParsedDataReady()) { 1012 if (!styleSheet || !ensureParsedDataReady()) {
1013 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector."); 1013 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the selector.");
1014 return false; 1014 return false;
1015 } 1015 }
1016 1016
1017 if (!verifySelectorText(selector)) { 1017 if (!verifySelectorText(selector)) {
1018 exceptionState.throwDOMException(SyntaxError, "Selector text is not vali d."); 1018 exceptionState.throwDOMException(SyntaxError, "Selector text is not vali d.");
1019 return false; 1019 return false;
1020 } 1020 }
1021 1021
1022 rule->setSelectorText(selector); 1022 rule->setSelectorText(selector);
1023 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1023 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1024 ASSERT(sourceData); 1024 ASSERT(sourceData);
1025 1025
1026 String sheetText = m_parsedStyleSheet->text(); 1026 String sheetText = m_parsedStyleSheet->text();
1027 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), selector); 1027 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), selector);
1028 updateText(sheetText); 1028 updateText(sheetText);
1029 onStyleSheetTextChanged(); 1029 onStyleSheetTextChanged();
1030 return true; 1030 return true;
1031 } 1031 }
1032 1032
1033 String InspectorStyleSheet::mediaRuleText(const InspectorCSSId& id, ExceptionSta te& exceptionState) 1033 String InspectorStyleSheet::mediaRuleText(unsigned ruleIndex, ExceptionState& ex ceptionState)
1034 { 1034 {
1035 CSSMediaRule* rule = mediaRuleForId(id); 1035 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1036 if (!rule) { 1036 if (!rule) {
1037 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID."); 1037 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1038 return ""; 1038 return "";
1039 } 1039 }
1040 return rule->media()->mediaText(); 1040 return rule->media()->mediaText();
1041 } 1041 }
1042 1042
1043 bool InspectorStyleSheet::setMediaRuleText(const InspectorCSSId& id, const Strin g& text, ExceptionState& exceptionState) 1043 bool InspectorStyleSheet::setMediaRuleText(unsigned ruleIndex, const String& tex t, ExceptionState& exceptionState)
1044 { 1044 {
1045 CSSMediaRule* rule = mediaRuleForId(id); 1045 CSSMediaRule* rule = mediaRuleAt(ruleIndex);
1046 if (!rule) { 1046 if (!rule) {
1047 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID."); 1047 exceptionState.throwDOMException(NotFoundError, "No media rule was found for the given ID.");
1048 return false; 1048 return false;
1049 } 1049 }
1050 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1050 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1051 if (!styleSheet || !ensureParsedDataReady()) { 1051 if (!styleSheet || !ensureParsedDataReady()) {
1052 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the media text."); 1052 exceptionState.throwDOMException(NotFoundError, "No stylesheet could be found in which to set the media text.");
1053 return false; 1053 return false;
1054 } 1054 }
1055 if (!verifyMediaText(text)) { 1055 if (!verifyMediaText(text)) {
1056 exceptionState.throwDOMException(SyntaxError, "Media text is not valid." ); 1056 exceptionState.throwDOMException(SyntaxError, "Media text is not valid." );
1057 return false; 1057 return false;
1058 } 1058 }
1059 1059
1060 rule->media()->setMediaText(text); 1060 rule->media()->setMediaText(text);
1061 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1061 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1062 ASSERT(sourceData && sourceData->mediaSourceData); 1062 ASSERT(sourceData && sourceData->mediaSourceData);
1063 1063
1064 String sheetText = m_parsedStyleSheet->text(); 1064 String sheetText = m_parsedStyleSheet->text();
1065 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), text); 1065 sheetText.replace(sourceData->ruleHeaderRange.start, sourceData->ruleHeaderR ange.length(), text);
1066 updateText(sheetText); 1066 updateText(sheetText);
1067 onStyleSheetTextChanged(); 1067 onStyleSheetTextChanged();
1068 return true; 1068 return true;
1069 } 1069 }
1070 1070
1071 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange) 1071 unsigned InspectorStyleSheet::ruleIndexBySourceRange(const CSSMediaRule* parentM ediaRule, const SourceRange& sourceRange)
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
1257 1257
1258 text.insert(ruleText, location.start); 1258 text.insert(ruleText, location.start);
1259 1259
1260 updateText(text); 1260 updateText(text);
1261 m_flatRules.clear(); 1261 m_flatRules.clear();
1262 1262
1263 onStyleSheetTextChanged(); 1263 onStyleSheetTextChanged();
1264 return styleRule; 1264 return styleRule;
1265 } 1265 }
1266 1266
1267 bool InspectorStyleSheet::deleteRule(const InspectorCSSId& id, const String& old Text, ExceptionState& exceptionState) 1267 bool InspectorStyleSheet::deleteRule(unsigned ruleIndex, const String& oldText, ExceptionState& exceptionState)
1268 { 1268 {
1269 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleForId(id); 1269 RefPtrWillBeRawPtr<CSSStyleRule> rule = ruleAt(ruleIndex);
1270 if (!rule) { 1270 if (!rule) {
1271 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1271 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1272 return false; 1272 return false;
1273 } 1273 }
1274 CSSStyleSheet* styleSheet = rule->parentStyleSheet(); 1274 CSSStyleSheet* styleSheet = rule->parentStyleSheet();
1275 if (!styleSheet || !ensureParsedDataReady()) { 1275 if (!styleSheet || !ensureParsedDataReady()) {
1276 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found."); 1276 exceptionState.throwDOMException(NotFoundError, "No parent stylesheet co uld be found.");
1277 return false; 1277 return false;
1278 } 1278 }
1279 1279
1280 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(id.ordin al()); 1280 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(ruleInde x);
1281 if (!sourceData) { 1281 if (!sourceData) {
1282 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID."); 1282 exceptionState.throwDOMException(NotFoundError, "No style rule could be found for the provided ID.");
1283 return false; 1283 return false;
1284 } 1284 }
1285 1285
1286 CSSRule* parentRule = rule->parentRule(); 1286 CSSRule* parentRule = rule->parentRule();
1287 if (parentRule) { 1287 if (parentRule) {
1288 if (parentRule->type() != CSSRule::MEDIA_RULE) { 1288 if (parentRule->type() != CSSRule::MEDIA_RULE) {
1289 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule."); 1289 exceptionState.throwDOMException(NotFoundError, "Cannot remove rule from non-media rule.");
1290 return false; 1290 return false;
(...skipping 25 matching lines...) Expand all
1316 void InspectorStyleSheet::updateText(const String& newText) 1316 void InspectorStyleSheet::updateText(const String& newText)
1317 { 1317 {
1318 Element* element = ownerStyleElement(); 1318 Element* element = ownerStyleElement();
1319 if (element) 1319 if (element)
1320 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t); 1320 m_cssAgent->addEditedStyleElement(DOMNodeIds::idForNode(element), newTex t);
1321 else 1321 else
1322 m_cssAgent->addEditedStyleSheet(finalURL(), newText); 1322 m_cssAgent->addEditedStyleSheet(finalURL(), newText);
1323 m_parsedStyleSheet->setText(newText); 1323 m_parsedStyleSheet->setText(newText);
1324 } 1324 }
1325 1325
1326 CSSStyleRule* InspectorStyleSheet::ruleForId(const InspectorCSSId& id) const 1326 CSSStyleRule* InspectorStyleSheet::ruleAt(unsigned ruleIndex) const
1327 { 1327 {
1328 ASSERT(!id.isEmpty());
1329 ensureFlatRules(); 1328 ensureFlatRules();
1330 return InspectorCSSAgent::asCSSStyleRule(id.ordinal() >= m_flatRules.size() ? nullptr : m_flatRules.at(id.ordinal()).get()); 1329 return InspectorCSSAgent::asCSSStyleRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get());
1331 } 1330 }
1332 1331
1333 CSSMediaRule* InspectorStyleSheet::mediaRuleForId(const InspectorCSSId& id) cons t 1332 CSSMediaRule* InspectorStyleSheet::mediaRuleAt(unsigned ruleIndex) const
1334 { 1333 {
1335 ASSERT(!id.isEmpty()); 1334 ASSERT(!id().isEmpty());
1336 ensureFlatRules(); 1335 ensureFlatRules();
1337 return InspectorCSSAgent::asCSSMediaRule(id.ordinal() >= m_flatRules.size() ? nullptr : m_flatRules.at(id.ordinal()).get()); 1336 return InspectorCSSAgent::asCSSMediaRule(ruleIndex >= m_flatRules.size() ? n ullptr : m_flatRules.at(ruleIndex).get());
1338 } 1337 }
1339 1338
1340 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const 1339 PassRefPtr<TypeBuilder::CSS::CSSStyleSheetHeader> InspectorStyleSheet::buildObje ctForStyleSheetInfo() const
1341 { 1340 {
1342 CSSStyleSheet* styleSheet = pageStyleSheet(); 1341 CSSStyleSheet* styleSheet = pageStyleSheet();
1343 if (!styleSheet) 1342 if (!styleSheet)
1344 return nullptr; 1343 return nullptr;
1345 1344
1346 Document* document = styleSheet->ownerDocument(); 1345 Document* document = styleSheet->ownerDocument();
1347 LocalFrame* frame = document ? document->frame() : nullptr; 1346 LocalFrame* frame = document ? document->frame() : nullptr;
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
1389 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings())); 1388 simpleSelector->setRange(buildSourceRangeObject(range, lineEndings()));
1390 result->addItem(simpleSelector.release()); 1389 result->addItem(simpleSelector.release());
1391 } 1390 }
1392 return result.release(); 1391 return result.release();
1393 } 1392 }
1394 1393
1395 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule) 1394 PassRefPtr<TypeBuilder::CSS::SelectorList> InspectorStyleSheet::buildObjectForSe lectorList(CSSStyleRule* rule)
1396 { 1395 {
1397 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr; 1396 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = nullptr;
1398 if (ensureParsedDataReady()) 1397 if (ensureParsedDataReady())
1399 sourceData = ruleSourceDataAt(styleId(rule->style()).ordinal()); 1398 sourceData = ruleSourceDataAt(indexOf(rule->style()));
1400 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors; 1399 RefPtr<TypeBuilder::Array<TypeBuilder::CSS::Selector> > selectors;
1401 1400
1402 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{'). 1401 // This intentionally does not rely on the source data to avoid catching the trailing comments (before the declaration starting '{').
1403 String selectorText = rule->selectorText(); 1402 String selectorText = rule->selectorText();
1404 1403
1405 if (sourceData) 1404 if (sourceData)
1406 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt()); 1405 selectors = selectorsFromSource(sourceData.get(), m_parsedStyleSheet->te xt());
1407 else { 1406 else {
1408 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create(); 1407 selectors = TypeBuilder::Array<TypeBuilder::CSS::Selector>::create();
1409 const CSSSelectorList& selectorList = rule->styleRule()->selectorList(); 1408 const CSSSelectorList& selectorList = rule->styleRule()->selectorList();
(...skipping 17 matching lines...) Expand all
1427 CSSStyleSheet* styleSheet = pageStyleSheet(); 1426 CSSStyleSheet* styleSheet = pageStyleSheet();
1428 if (!styleSheet) 1427 if (!styleSheet)
1429 return nullptr; 1428 return nullptr;
1430 1429
1431 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create () 1430 RefPtr<TypeBuilder::CSS::CSSRule> result = TypeBuilder::CSS::CSSRule::create ()
1432 .setSelectorList(buildObjectForSelectorList(rule)) 1431 .setSelectorList(buildObjectForSelectorList(rule))
1433 .setOrigin(m_origin) 1432 .setOrigin(m_origin)
1434 .setStyle(buildObjectForStyle(rule->style())); 1433 .setStyle(buildObjectForStyle(rule->style()));
1435 1434
1436 if (canBind(m_origin)) { 1435 if (canBind(m_origin)) {
1437 InspectorCSSId id(ruleId(rule)); 1436 if (!id().isEmpty())
1438 if (!id.isEmpty()) 1437 result->setStyleSheetId(id());
1439 result->setStyleSheetId(id.styleSheetId());
1440 } 1438 }
1441 1439
1442 if (mediaStack) 1440 if (mediaStack)
1443 result->setMedia(mediaStack); 1441 result->setMedia(mediaStack);
1444 1442
1445 return result.release(); 1443 return result.release();
1446 } 1444 }
1447 1445
1448 bool InspectorStyleSheet::getText(String* result) const 1446 bool InspectorStyleSheet::getText(String* result) const
1449 { 1447 {
1450 if (!ensureText()) 1448 if (!ensureText())
1451 return false; 1449 return false;
1452 *result = m_parsedStyleSheet->text(); 1450 *result = m_parsedStyleSheet->text();
1453 return true; 1451 return true;
1454 } 1452 }
1455 1453
1456 CSSStyleDeclaration* InspectorStyleSheet::styleForId(const InspectorCSSId& id) c onst 1454 CSSStyleDeclaration* InspectorStyleSheet::styleAt(unsigned ruleIndex) const
1457 { 1455 {
1458 CSSStyleRule* rule = ruleForId(id); 1456 CSSStyleRule* rule = ruleAt(ruleIndex);
1459 if (!rule) 1457 if (!rule)
1460 return nullptr; 1458 return nullptr;
1461 1459
1462 return rule->style(); 1460 return rule->style();
1463 } 1461 }
1464 1462
1465 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule) 1463 PassRefPtr<TypeBuilder::CSS::SourceRange> InspectorStyleSheet::ruleHeaderSourceR ange(const CSSRule* rule)
1466 { 1464 {
1467 if (!ensureParsedDataReady()) 1465 if (!ensureParsedDataReady())
1468 return nullptr; 1466 return nullptr;
(...skipping 19 matching lines...) Expand all
1488 return nullptr; 1486 return nullptr;
1489 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index)); 1487 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = m_parsedStyleSheet->ruleS ourceDataAt(static_cast<unsigned>(index));
1490 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size()) 1488 if (!sourceData->mediaSourceData || mediaQueryIndex >= sourceData->mediaSour ceData->queryData.size())
1491 return nullptr; 1489 return nullptr;
1492 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex); 1490 RefPtrWillBeRawPtr<CSSMediaQuerySourceData> mediaQueryData = sourceData->med iaSourceData->queryData.at(mediaQueryIndex);
1493 if (mediaQueryExpIndex >= mediaQueryData->expData.size()) 1491 if (mediaQueryExpIndex >= mediaQueryData->expData.size())
1494 return nullptr; 1492 return nullptr;
1495 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings()); 1493 return buildSourceRangeObject(mediaQueryData->expData.at(mediaQueryExpIndex) .valueRange, lineEndings());
1496 } 1494 }
1497 1495
1498 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleForId( const InspectorCSSId& id) 1496 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheet::inspectorStyleAt(uns igned ruleIndex)
1499 { 1497 {
1500 CSSStyleDeclaration* style = styleForId(id); 1498 CSSStyleDeclaration* style = styleAt(ruleIndex);
1501 if (!style) 1499 if (!style)
1502 return nullptr; 1500 return nullptr;
1503 1501
1504 return InspectorStyle::create(id, style, this); 1502 return InspectorStyle::create(ruleIndex, style, this);
1505 } 1503 }
1506 1504
1507 unsigned InspectorStyleSheet::ruleCount() 1505 unsigned InspectorStyleSheet::ruleCount()
1508 { 1506 {
1509 return m_parsedStyleSheet->ruleCount(); 1507 return m_parsedStyleSheet->ruleCount();
1510 } 1508 }
1511 1509
1512 String InspectorStyleSheet::sourceURL() const 1510 String InspectorStyleSheet::sourceURL() const
1513 { 1511 {
1514 if (!m_sourceURL.isNull()) 1512 if (!m_sourceURL.isNull())
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
1577 bool deprecated; 1575 bool deprecated;
1578 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated); 1576 String commentValue = ContentSearchUtils::findSourceMapURL(styleSheetTex t, ContentSearchUtils::CSSMagicComment, &deprecated);
1579 if (!commentValue.isEmpty()) { 1577 if (!commentValue.isEmpty()) {
1580 // FIXME: add deprecated console message here. 1578 // FIXME: add deprecated console message here.
1581 return commentValue; 1579 return commentValue;
1582 } 1580 }
1583 } 1581 }
1584 return m_pageStyleSheet->contents()->sourceMapURL(); 1582 return m_pageStyleSheet->contents()->sourceMapURL();
1585 } 1583 }
1586 1584
1587 InspectorCSSId InspectorStyleSheet::styleId(CSSStyleDeclaration* style) const 1585 unsigned InspectorStyleSheet::indexOf(CSSStyleDeclaration* style) const
1588 { 1586 {
1589 unsigned index = ruleIndexByStyle(style); 1587 ensureFlatRules();
1590 if (index != UINT_MAX) 1588 for (unsigned i = 0, size = m_flatRules.size(); i < size; ++i) {
1591 return InspectorCSSId(id(), index); 1589 CSSStyleRule* styleRule = InspectorCSSAgent::asCSSStyleRule(m_flatRules. at(i).get());
1592 return InspectorCSSId(); 1590 if (styleRule && styleRule->style() == style)
1591 return i;
1592 }
1593 return 0;
1593 } 1594 }
1594 1595
1595 bool InspectorStyleSheet::findRuleBySelectorRange(const SourceRange& sourceRange , InspectorCSSId* ruleId) 1596 bool InspectorStyleSheet::findRuleBySelectorRange(const SourceRange& sourceRange , unsigned* ruleIndex)
1596 { 1597 {
1597 if (!ensureParsedDataReady()) 1598 if (!ensureParsedDataReady())
1598 return false; 1599 return false;
1599 for (size_t i = 0; i < ruleCount(); ++i) { 1600 for (size_t i = 0; i < ruleCount(); ++i) {
1600 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 1601 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1601 if (!ruleSourceData->styleSourceData) 1602 if (!ruleSourceData->styleSourceData)
1602 continue; 1603 continue;
1603 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { 1604 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1604 *ruleId = InspectorCSSId(id(), i); 1605 *ruleIndex = i;
1605 return true; 1606 return true;
1606 } 1607 }
1607 } 1608 }
1608 return false; 1609 return false;
1609 } 1610 }
1610 1611
1611 bool InspectorStyleSheet::findMediaRuleByRange(const SourceRange& sourceRange, I nspectorCSSId* ruleId) 1612 bool InspectorStyleSheet::findMediaRuleByRange(const SourceRange& sourceRange, u nsigned* ruleIndex)
1612 { 1613 {
1613 if (!ensureParsedDataReady()) 1614 if (!ensureParsedDataReady())
1614 return false; 1615 return false;
1615 for (size_t i = 0; i < ruleCount(); ++i) { 1616 for (size_t i = 0; i < ruleCount(); ++i) {
1616 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i); 1617 RefPtrWillBeRawPtr<CSSRuleSourceData> ruleSourceData = ruleSourceDataAt( i);
1617 if (!ruleSourceData->mediaSourceData) 1618 if (!ruleSourceData->mediaSourceData)
1618 continue; 1619 continue;
1619 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) { 1620 if (ruleSourceData->ruleHeaderRange.start == sourceRange.start && ruleSo urceData->ruleHeaderRange.end == sourceRange.end) {
1620 *ruleId = InspectorCSSId(id(), i); 1621 *ruleIndex = i;
1621 return true; 1622 return true;
1622 } 1623 }
1623 } 1624 }
1624 return false; 1625 return false;
1625 } 1626 }
1626 1627
1627 const CSSRuleVector& InspectorStyleSheet::flatRules() 1628 const CSSRuleVector& InspectorStyleSheet::flatRules()
1628 { 1629 {
1629 ensureFlatRules(); 1630 ensureFlatRules();
1630 return m_flatRules; 1631 return m_flatRules;
1631 } 1632 }
1632 1633
1633 Document* InspectorStyleSheet::ownerDocument() const 1634 Document* InspectorStyleSheet::ownerDocument() const
1634 { 1635 {
1635 return m_pageStyleSheet->ownerDocument(); 1636 return m_pageStyleSheet->ownerDocument();
1636 } 1637 }
1637 1638
1638 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const 1639 PassRefPtrWillBeRawPtr<CSSRuleSourceData> InspectorStyleSheet::ruleSourceDataAt( unsigned ruleIndex) const
1639 { 1640 {
1640 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex); 1641 return m_parsedStyleSheet->ruleSourceDataAt(ruleIndex);
1641 } 1642 }
1642 1643
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() 1644 bool InspectorStyleSheet::ensureParsedDataReady()
1655 { 1645 {
1656 return ensureText() && m_parsedStyleSheet->ensureSourceData(); 1646 return ensureText() && m_parsedStyleSheet->ensureSourceData();
1657 } 1647 }
1658 1648
1659 bool InspectorStyleSheet::ensureText() const 1649 bool InspectorStyleSheet::ensureText() const
1660 { 1650 {
1661 if (m_parsedStyleSheet->hasText()) 1651 if (m_parsedStyleSheet->hasText())
1662 return true; 1652 return true;
1663 1653
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1701 } 1691 }
1702 } 1692 }
1703 1693
1704 void InspectorStyleSheet::ensureFlatRules() const 1694 void InspectorStyleSheet::ensureFlatRules() const
1705 { 1695 {
1706 // We are fine with redoing this for empty stylesheets as this will run fast . 1696 // We are fine with redoing this for empty stylesheets as this will run fast .
1707 if (m_flatRules.isEmpty()) 1697 if (m_flatRules.isEmpty())
1708 collectFlatRules(pageStyleSheet(), &m_flatRules); 1698 collectFlatRules(pageStyleSheet(), &m_flatRules);
1709 } 1699 }
1710 1700
1711 bool InspectorStyleSheet::setStyleText(const InspectorCSSId& id, const String& t ext) 1701 bool InspectorStyleSheet::setStyleText(unsigned ruleIndex, const String& text)
1712 { 1702 {
1713 CSSStyleDeclaration* style = styleForId(id); 1703 CSSStyleDeclaration* style = styleAt(ruleIndex);
1714 if (!style) 1704 if (!style)
1715 return false; 1705 return false;
1716 1706
1717 if (!ensureParsedDataReady()) 1707 if (!ensureParsedDataReady())
1718 return false; 1708 return false;
1719 1709
1720 String patchedStyleSheetText; 1710 String patchedStyleSheetText;
1721 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText); 1711 bool success = styleSheetTextWithChangedStyle(style, text, &patchedStyleShee tText);
1722 if (!success) 1712 if (!success)
1723 return false; 1713 return false;
1724 1714
1725 TrackExceptionState exceptionState; 1715 TrackExceptionState exceptionState;
1726 style->setCSSText(text, exceptionState); 1716 style->setCSSText(text, exceptionState);
1727 if (!exceptionState.hadException()) { 1717 if (!exceptionState.hadException()) {
1728 updateText(patchedStyleSheetText); 1718 updateText(patchedStyleSheetText);
1729 onStyleSheetTextChanged(); 1719 onStyleSheetTextChanged();
1730 } 1720 }
1731 1721
1732 return !exceptionState.hadException(); 1722 return !exceptionState.hadException();
1733 } 1723 }
1734 1724
1735 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result) 1725 bool InspectorStyleSheet::styleSheetTextWithChangedStyle(CSSStyleDeclaration* st yle, const String& newStyleText, String* result)
1736 { 1726 {
1737 if (!style) 1727 if (!style)
1738 return false; 1728 return false;
1739 if (!ensureParsedDataReady()) 1729 if (!ensureParsedDataReady())
1740 return false; 1730 return false;
1741 1731
1742 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(styleId( style).ordinal()); 1732 RefPtrWillBeRawPtr<CSSRuleSourceData> sourceData = ruleSourceDataAt(indexOf( style));
1743 unsigned bodyStart = sourceData->ruleBodyRange.start; 1733 unsigned bodyStart = sourceData->ruleBodyRange.start;
1744 unsigned bodyEnd = sourceData->ruleBodyRange.end; 1734 unsigned bodyEnd = sourceData->ruleBodyRange.end;
1745 ASSERT(bodyStart <= bodyEnd); 1735 ASSERT(bodyStart <= bodyEnd);
1746 1736
1747 String text = m_parsedStyleSheet->text(); 1737 String text = m_parsedStyleSheet->text();
1748 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive 1738 ASSERT_WITH_SECURITY_IMPLICATION(bodyEnd <= text.length()); // bodyEnd is ex clusive
1749 1739
1750 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText); 1740 text.replace(bodyStart, bodyEnd - bodyStart, newStyleText);
1751 *result = text; 1741 *result = text;
1752 return true; 1742 return true;
1753 } 1743 }
1754 1744
1755 InspectorCSSId InspectorStyleSheet::ruleId(CSSStyleRule* rule) const 1745 unsigned InspectorStyleSheet::indexOf(CSSStyleRule* rule) const
1756 { 1746 {
1757 return styleId(rule->style()); 1747 return indexOf(rule->style());
1758 } 1748 }
1759 1749
1760 bool InspectorStyleSheet::originalStyleSheetText(String* result) const 1750 bool InspectorStyleSheet::originalStyleSheetText(String* result) const
1761 { 1751 {
1762 bool success = inlineStyleSheetText(result); 1752 bool success = inlineStyleSheetText(result);
1763 if (!success) 1753 if (!success)
1764 success = resourceStyleSheetText(result); 1754 success = resourceStyleSheetText(result);
1765 return success; 1755 return success;
1766 } 1756 }
1767 1757
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1810 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener)); 1800 return adoptRefWillBeNoop(new InspectorStyleSheetForInlineStyle(id, element, listener));
1811 } 1801 }
1812 1802
1813 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener) 1803 InspectorStyleSheetForInlineStyle::InspectorStyleSheetForInlineStyle(const Strin g& id, PassRefPtrWillBeRawPtr<Element> element, Listener* listener)
1814 : InspectorStyleSheetBase(id, listener) 1804 : InspectorStyleSheetBase(id, listener)
1815 , m_element(element) 1805 , m_element(element)
1816 , m_ruleSourceData(nullptr) 1806 , m_ruleSourceData(nullptr)
1817 , m_isStyleTextValid(false) 1807 , m_isStyleTextValid(false)
1818 { 1808 {
1819 ASSERT(m_element); 1809 ASSERT(m_element);
1820 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id, 0), inlineStyle (), this); 1810 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this);
1821 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String(); 1811 m_styleText = m_element->isStyledElement() ? m_element->getAttribute("style" ).string() : String();
1822 } 1812 }
1823 1813
1824 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute() 1814 void InspectorStyleSheetForInlineStyle::didModifyElementAttribute()
1825 { 1815 {
1826 m_isStyleTextValid = false; 1816 m_isStyleTextValid = false;
1827 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle()) 1817 if (m_element->isStyledElement() && m_element->style() != m_inspectorStyle-> cssStyle())
1828 m_inspectorStyle = InspectorStyle::create(InspectorCSSId(id(), 0), inlin eStyle(), this); 1818 m_inspectorStyle = InspectorStyle::create(0, inlineStyle(), this);
1829 m_ruleSourceData.clear(); 1819 m_ruleSourceData.clear();
1830 } 1820 }
1831 1821
1832 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState) 1822 bool InspectorStyleSheetForInlineStyle::setText(const String& text, ExceptionSta te& exceptionState)
1833 { 1823 {
1834 bool success = setStyleText(InspectorCSSId(id(), 0), text); 1824 bool success = setStyleText(0, text);
1835 if (!success) 1825 if (!success)
1836 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id."); 1826 exceptionState.throwDOMException(SyntaxError, "Style sheet text is inval id.");
1837 return success; 1827 return success;
1838 } 1828 }
1839 1829
1840 bool InspectorStyleSheetForInlineStyle::getText(String* result) const 1830 bool InspectorStyleSheetForInlineStyle::getText(String* result) const
1841 { 1831 {
1842 if (!m_isStyleTextValid) { 1832 if (!m_isStyleTextValid) {
1843 m_styleText = elementStyleText(); 1833 m_styleText = elementStyleText();
1844 m_isStyleTextValid = true; 1834 m_isStyleTextValid = true;
1845 } 1835 }
1846 *result = m_styleText; 1836 *result = m_styleText;
1847 return true; 1837 return true;
1848 } 1838 }
1849 1839
1850 bool InspectorStyleSheetForInlineStyle::setStyleText(const InspectorCSSId& id, c onst String& text) 1840 bool InspectorStyleSheetForInlineStyle::setStyleText(unsigned ruleIndex, const S tring& text)
1851 { 1841 {
1852 CSSStyleDeclaration* style = styleForId(id); 1842 CSSStyleDeclaration* style = styleAt(ruleIndex);
1853 if (!style) 1843 if (!style)
1854 return false; 1844 return false;
1855 ASSERT_UNUSED(style, style == inlineStyle()); 1845 ASSERT_UNUSED(style, style == inlineStyle());
1856 TrackExceptionState exceptionState; 1846 TrackExceptionState exceptionState;
1857 1847
1858 { 1848 {
1859 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument()); 1849 InspectorCSSAgent::InlineStyleOverrideScope overrideScope(m_element->own erDocument());
1860 m_element->setAttribute("style", AtomicString(text), exceptionState); 1850 m_element->setAttribute("style", AtomicString(text), exceptionState);
1861 } 1851 }
1862 if (!exceptionState.hadException()) { 1852 if (!exceptionState.hadException()) {
(...skipping 27 matching lines...) Expand all
1890 1880
1891 bool success = !!m_ruleSourceData; 1881 bool success = !!m_ruleSourceData;
1892 if (!success) { 1882 if (!success) {
1893 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style); 1883 m_ruleSourceData = CSSRuleSourceData::create(StyleRule::Style);
1894 return false; 1884 return false;
1895 } 1885 }
1896 1886
1897 return true; 1887 return true;
1898 } 1888 }
1899 1889
1900 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleForId(const InspectorCSSId& id) 1890 PassRefPtrWillBeRawPtr<InspectorStyle> InspectorStyleSheetForInlineStyle::inspec torStyleAt(unsigned ruleIndex)
1901 { 1891 {
1902 ASSERT_UNUSED(id, !id.ordinal()); 1892 ASSERT_UNUSED(!ruleIndex, !ruleIndex);
kozy 2015/06/15 09:49:28 ASSERT_UNUSED(ruleIndex, !ruleIndex)
1903 return m_inspectorStyle; 1893 return m_inspectorStyle;
1904 } 1894 }
1905 1895
1906 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const 1896 CSSStyleDeclaration* InspectorStyleSheetForInlineStyle::inlineStyle() const
1907 { 1897 {
1908 return m_element->style(); 1898 return m_element->style();
1909 } 1899 }
1910 1900
1911 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const 1901 const String& InspectorStyleSheetForInlineStyle::elementStyleText() const
1912 { 1902 {
(...skipping 20 matching lines...) Expand all
1933 1923
1934 DEFINE_TRACE(InspectorStyleSheetForInlineStyle) 1924 DEFINE_TRACE(InspectorStyleSheetForInlineStyle)
1935 { 1925 {
1936 visitor->trace(m_element); 1926 visitor->trace(m_element);
1937 visitor->trace(m_ruleSourceData); 1927 visitor->trace(m_ruleSourceData);
1938 visitor->trace(m_inspectorStyle); 1928 visitor->trace(m_inspectorStyle);
1939 InspectorStyleSheetBase::trace(visitor); 1929 InspectorStyleSheetBase::trace(visitor);
1940 } 1930 }
1941 1931
1942 } // namespace blink 1932 } // 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