OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2011, Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 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 13 matching lines...) Expand all Loading... |
24 | 24 |
25 #include "config.h" | 25 #include "config.h" |
26 #include "core/inspector/InspectorStyleTextEditor.h" | 26 #include "core/inspector/InspectorStyleTextEditor.h" |
27 | 27 |
28 #include "core/css/CSSPropertySourceData.h" | 28 #include "core/css/CSSPropertySourceData.h" |
29 #include "core/html/parser/HTMLParserIdioms.h" | 29 #include "core/html/parser/HTMLParserIdioms.h" |
30 #include "core/inspector/InspectorStyleSheet.h" | 30 #include "core/inspector/InspectorStyleSheet.h" |
31 | 31 |
32 namespace WebCore { | 32 namespace WebCore { |
33 | 33 |
34 InspectorStyleTextEditor::InspectorStyleTextEditor(Vector<InspectorStyleProperty
>* allProperties, const String& styleText, const NewLineAndWhitespace& format) | 34 InspectorStyleTextEditor::InspectorStyleTextEditor(WillBeHeapVector<InspectorSty
leProperty>* allProperties, const String& styleText, const NewLineAndWhitespace&
format) |
35 : m_allProperties(allProperties) | 35 : m_allProperties(allProperties) |
36 , m_styleText(styleText) | 36 , m_styleText(styleText) |
37 , m_format(format) | 37 , m_format(format) |
38 { | 38 { |
39 } | 39 } |
40 | 40 |
41 void InspectorStyleTextEditor::insertProperty(unsigned index, const String& prop
ertyText, unsigned styleBodyLength) | 41 void InspectorStyleTextEditor::insertProperty(unsigned index, const String& prop
ertyText, unsigned styleBodyLength) |
42 { | 42 { |
43 long propertyStart = 0; | 43 long propertyStart = 0; |
44 | 44 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 m_styleText.insert(textToSet, propertyStart); | 104 m_styleText.insert(textToSet, propertyStart); |
105 } | 105 } |
106 | 106 |
107 void InspectorStyleTextEditor::replaceProperty(unsigned index, const String& new
Text) | 107 void InspectorStyleTextEditor::replaceProperty(unsigned index, const String& new
Text) |
108 { | 108 { |
109 ASSERT_WITH_SECURITY_IMPLICATION(index < m_allProperties->size()); | 109 ASSERT_WITH_SECURITY_IMPLICATION(index < m_allProperties->size()); |
110 internalReplaceProperty(m_allProperties->at(index), newText); | 110 internalReplaceProperty(m_allProperties->at(index), newText); |
111 } | 111 } |
112 | 112 |
113 void InspectorStyleTextEditor::removeProperty(unsigned index) | |
114 { | |
115 replaceProperty(index, ""); | |
116 } | |
117 | |
118 void InspectorStyleTextEditor::internalReplaceProperty(const InspectorStylePrope
rty& property, const String& newText) | 113 void InspectorStyleTextEditor::internalReplaceProperty(const InspectorStylePrope
rty& property, const String& newText) |
119 { | 114 { |
120 const SourceRange& range = property.sourceData.range; | 115 const SourceRange& range = property.sourceData.range; |
121 long replaceRangeStart = range.start; | 116 long replaceRangeStart = range.start; |
122 long replaceRangeEnd = range.end; | 117 long replaceRangeEnd = range.end; |
123 long newTextLength = newText.length(); | 118 long newTextLength = newText.length(); |
124 String finalNewText = newText; | 119 String finalNewText = newText; |
125 | 120 |
126 // Removing a property - remove preceding prefix. | 121 // Removing a property - remove preceding prefix. |
127 String fullPrefix = m_format.first + m_format.second; | 122 String fullPrefix = m_format.first + m_format.second; |
(...skipping 24 matching lines...) Expand all Loading... |
152 if (fullPrefixLength > replaceRangeStart || m_styleText.substring(replac
eRangeStart - fullPrefixLength, fullPrefixLength) != fullPrefix) | 147 if (fullPrefixLength > replaceRangeStart || m_styleText.substring(replac
eRangeStart - fullPrefixLength, fullPrefixLength) != fullPrefix) |
153 finalNewText.insert(fullPrefix, 0); | 148 finalNewText.insert(fullPrefix, 0); |
154 } | 149 } |
155 | 150 |
156 int replacedLength = replaceRangeEnd - replaceRangeStart; | 151 int replacedLength = replaceRangeEnd - replaceRangeStart; |
157 m_styleText.replace(replaceRangeStart, replacedLength, finalNewText); | 152 m_styleText.replace(replaceRangeStart, replacedLength, finalNewText); |
158 } | 153 } |
159 | 154 |
160 } // namespace WebCore | 155 } // namespace WebCore |
161 | 156 |
OLD | NEW |