Changeset 68059 in webkit
- Timestamp:
- Sep 22, 2010 11:30:34 AM (14 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r68034 r68059 1 2010-09-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 queryCommandState returns false for Underline command when no selection is made 6 https://bugs.webkit.org/show_bug.cgi?id=17594 7 8 Added a test to ensure queryCommandValue('underline') and queryCommandValue('strikeThrough') 9 correctly incorporates the typing style. 10 11 * editing/execCommand/query-text-decoration-with-typing-style-expected.txt: Added. 12 * editing/execCommand/query-text-decoration-with-typing-style.html: Added. 13 1 14 2010-09-22 Adam Barth <abarth@webkit.org> 2 15 -
trunk/WebCore/ChangeLog
r68056 r68059 1 2010-09-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 queryCommandState returns false for Underline command when no selection is made 6 https://bugs.webkit.org/show_bug.cgi?id=17594 7 8 The bug was caused by selectionComputedStyle's adding -webkit-text-decorations-in-effect property 9 to a dummy span used to obtain the computed style when there is a typing style. 10 Since this property is for internal use only, the CSS parser always stripped the property. 11 As a result, we were always ignoring the text decorations set by the typing style. 12 13 Fixed the bug by making selectionComputedStyle directly merge the computed style of the current 14 caret position and the typing style. This also eliminates the need for a dummy span element. 15 Due to the merge, the return value of selectionComputedStyle had to be changed to CSSMutableStyleDeclaration 16 from CSSComputedStyleDeclaration. 17 18 Test: editing/execCommand/query-text-decoration-with-typing-style.html 19 20 * editing/ApplyStyleCommand.cpp: 21 (WebCore::StyleChange::init): Calls getPropertiesNotIn. 22 (WebCore::getPropertiesNotIn): Renamed from getPropertiesNotInComputedStyle since it takes 23 CSSStyleDeclaration* instead of CSSComputedStyleDeclaration* for the second argument. 24 (WebCore::ApplyStyleCommand::removeNonEditingProperties): Extracted from editingStyleAtPosition. 25 (WebCore::ApplyStyleCommand::editingStyleAtPosition): Calls removeNonEditingProperties. 26 * editing/ApplyStyleCommand.h: 27 * editing/Editor.cpp: 28 (WebCore::triStateOfStyle): Calls getPropertiesNotIn. Renamed from triStateOfStyleInComputedStyle 29 since it no longer takes CSSComputedStyleDeclaration. 30 (WebCore::Editor::selectionStartHasStyle): Calls selectionComputedStyle and triStateOfStyle. 31 (WebCore::Editor::selectionHasStyle): Ditto. 32 (WebCore::Editor::selectionStartCSSPropertyValue): Calls selectionComputedStyle. 33 (WebCore::Editor::selectionComputedStyle): See above. 34 * editing/Editor.h: 35 * editing/EditorCommand.cpp: 36 (WebCore::executeToggleStyleInList): Calls selectionComputedStyle. 37 1 38 2010-09-22 Jamey Hicks <jamey.hicks@nokia.com> 2 39 -
trunk/WebCore/editing/ApplyStyleCommand.cpp
r68014 r68059 146 146 147 147 RefPtr<CSSComputedStyleDeclaration> computedStyle = position.computedStyle(); 148 RefPtr<CSSMutableStyleDeclaration> mutableStyle = getPropertiesNotIn ComputedStyle(style.get(), computedStyle.get());148 RefPtr<CSSMutableStyleDeclaration> mutableStyle = getPropertiesNotIn(style.get(), computedStyle.get()); 149 149 150 150 reconcileTextDecorationProperties(mutableStyle.get()); … … 157 157 158 158 // If unicode-bidi is present in mutableStyle and direction is not, then add direction to mutableStyle. 159 // FIXME: Shouldn't this be done in getPropertiesNotIn ComputedStyle?159 // FIXME: Shouldn't this be done in getPropertiesNotIn? 160 160 if (mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi) && !style->getPropertyCSSValue(CSSPropertyDirection)) 161 161 mutableStyle->setProperty(CSSPropertyDirection, style->getPropertyValue(CSSPropertyDirection)); … … 389 389 } 390 390 391 RefPtr<CSSMutableStyleDeclaration> getPropertiesNotIn ComputedStyle(CSSStyleDeclaration* style, CSSComputedStyleDeclaration* computedStyle)392 { 393 ASSERT(style );391 RefPtr<CSSMutableStyleDeclaration> getPropertiesNotIn(CSSStyleDeclaration* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle) 392 { 393 ASSERT(styleWithRedundantProperties); 394 394 ASSERT(computedStyle); 395 RefPtr<CSSMutableStyleDeclaration> result = style ->copy();396 computedStyle->diff(result.get());397 398 RefPtr<CSSValue> computedTextDecorationsInEffect = computedStyle->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect);399 diffTextDecorations(result.get(), CSSPropertyTextDecoration, computedTextDecorationsInEffect.get());400 diffTextDecorations(result.get(), CSSPropertyWebkitTextDecorationsInEffect, computedTextDecorationsInEffect.get());401 402 if (fontWeightIsBold(result.get()) == fontWeightIsBold( computedStyle))395 RefPtr<CSSMutableStyleDeclaration> result = styleWithRedundantProperties->copy(); 396 baseStyle->diff(result.get()); 397 398 RefPtr<CSSValue> baseTextDecorationsInEffect = baseStyle->getPropertyCSSValue(CSSPropertyWebkitTextDecorationsInEffect); 399 diffTextDecorations(result.get(), CSSPropertyTextDecoration, baseTextDecorationsInEffect.get()); 400 diffTextDecorations(result.get(), CSSPropertyWebkitTextDecorationsInEffect, baseTextDecorationsInEffect.get()); 401 402 if (fontWeightIsBold(result.get()) == fontWeightIsBold(baseStyle)) 403 403 result->removeProperty(CSSPropertyFontWeight); 404 404 405 if (getRGBAFontColor(result.get()) == getRGBAFontColor( computedStyle))405 if (getRGBAFontColor(result.get()) == getRGBAFontColor(baseStyle)) 406 406 result->removeProperty(CSSPropertyColor); 407 407 … … 440 440 size_t numEditingStyleProperties = sizeof(editingStyleProperties)/sizeof(editingStyleProperties[0]); 441 441 442 RefPtr<CSSMutableStyleDeclaration> ApplyStyleCommand::removeNonEditingProperties(CSSStyleDeclaration* style) 443 { 444 return style->copyPropertiesInSet(editingStyleProperties, numEditingStyleProperties); 445 } 446 442 447 PassRefPtr<CSSMutableStyleDeclaration> ApplyStyleCommand::editingStyleAtPosition(Position pos, ShouldIncludeTypingStyle shouldIncludeTypingStyle) 443 448 { … … 447 452 style = CSSMutableStyleDeclaration::create(); 448 453 else 449 style = computedStyleAtPosition->copyPropertiesInSet(editingStyleProperties, numEditingStyleProperties);454 style = removeNonEditingProperties(computedStyleAtPosition.get()); 450 455 451 456 if (style && pos.node() && pos.node()->computedStyle()) { -
trunk/WebCore/editing/ApplyStyleCommand.h
r68014 r68059 58 58 return adoptRef(new ApplyStyleCommand(element, removeOnly, action)); 59 59 } 60 60 61 static RefPtr<CSSMutableStyleDeclaration> removeNonEditingProperties(CSSStyleDeclaration* style); 61 62 static PassRefPtr<CSSMutableStyleDeclaration> editingStyleAtPosition(Position pos, ShouldIncludeTypingStyle shouldIncludeTypingStyle = IgnoreTypingStyle); 62 63 … … 126 127 bool isStyleSpan(const Node*); 127 128 PassRefPtr<HTMLElement> createStyleSpanElement(Document*); 128 RefPtr<CSSMutableStyleDeclaration> getPropertiesNotIn ComputedStyle(CSSStyleDeclaration* style, CSSComputedStyleDeclaration* computedStyle);129 RefPtr<CSSMutableStyleDeclaration> getPropertiesNotIn(CSSStyleDeclaration* styleWithRedundantProperties, CSSStyleDeclaration* baseStyle); 129 130 130 131 void prepareEditingStyleToApplyAt(CSSMutableStyleDeclaration*, Position); -
trunk/WebCore/editing/Editor.cpp
r67653 r68059 863 863 }; 864 864 865 static TriState triStateOfStyle InComputedStyle(CSSStyleDeclaration* desiredStyle, CSSComputedStyleDeclaration* computedStyle, bool ignoreTextOnlyProperties = false)866 { 867 RefPtr<CSSMutableStyleDeclaration> diff = getPropertiesNotIn ComputedStyle(desiredStyle, computedStyle);865 static TriState triStateOfStyle(CSSStyleDeclaration* desiredStyle, CSSStyleDeclaration* styleToCompare, bool ignoreTextOnlyProperties = false) 866 { 867 RefPtr<CSSMutableStyleDeclaration> diff = getPropertiesNotIn(desiredStyle, styleToCompare); 868 868 869 869 if (ignoreTextOnlyProperties) … … 879 879 bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const 880 880 { 881 Node* nodeToRemove;882 RefPtr<CSS ComputedStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);881 bool shouldUseFixedFontDefaultSize; 882 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 883 883 if (!selectionStyle) 884 884 return false; 885 TriState state = triStateOfStyleInComputedStyle(style, selectionStyle.get()); 886 if (nodeToRemove) { 887 ExceptionCode ec = 0; 888 nodeToRemove->remove(ec); 889 ASSERT(!ec); 890 } 891 return state == TrueTriState; 885 return triStateOfStyle(style, selectionStyle.get()) == TrueTriState; 892 886 } 893 887 … … 897 891 898 892 if (!m_frame->selection()->isRange()) { 899 Node* nodeToRemove;900 RefPtr<CSS ComputedStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);893 bool shouldUseFixedFontDefaultSize; 894 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 901 895 if (!selectionStyle) 902 896 return FalseTriState; 903 state = triStateOfStyleInComputedStyle(style, selectionStyle.get()); 904 if (nodeToRemove) { 905 ExceptionCode ec = 0; 906 nodeToRemove->remove(ec); 907 ASSERT(!ec); 908 } 897 state = triStateOfStyle(style, selectionStyle.get()); 909 898 } else { 910 899 for (Node* node = m_frame->selection()->start().node(); node; node = node->traverseNextNode()) { 911 900 RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node); 912 901 if (nodeStyle) { 913 TriState nodeState = triStateOfStyle InComputedStyle(style, nodeStyle.get(), !node->isTextNode());902 TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode()); 914 903 if (node == m_frame->selection()->start().node()) 915 904 state = nodeState; … … 945 934 String Editor::selectionStartCSSPropertyValue(int propertyID) 946 935 { 947 Node* nodeToRemove;948 RefPtr<CSS ComputedStyleDeclaration> selectionStyle = selectionComputedStyle(nodeToRemove);936 bool shouldUseFixedFontDefaultSize = false; 937 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 949 938 if (!selectionStyle) 950 939 return String(); … … 959 948 ExceptionCode ec = 0; 960 949 for (Node* ancestor = range->commonAncestorContainer(ec); ancestor; ancestor = ancestor->parentNode()) { 961 selectionStyle = computedStyle(ancestor) ;950 selectionStyle = computedStyle(ancestor)->copy(); 962 951 if (!hasTransparentBackgroundColor(selectionStyle.get())) { 963 952 value = selectionStyle->getPropertyValue(CSSPropertyBackgroundColor); … … 971 960 ASSERT(cssValue->isPrimitiveValue()); 972 961 int fontPixelSize = static_cast<CSSPrimitiveValue*>(cssValue.get())->getIntValue(CSSPrimitiveValue::CSS_PX); 973 int size = CSSStyleSelector::legacyFontSize(m_frame->document(), fontPixelSize, s electionStyle->useFixedFontDefaultSize());962 int size = CSSStyleSelector::legacyFontSize(m_frame->document(), fontPixelSize, shouldUseFixedFontDefaultSize); 974 963 value = String::number(size); 975 }976 977 if (nodeToRemove) {978 ExceptionCode ec = 0;979 nodeToRemove->remove(ec);980 ASSERT(!ec);981 964 } 982 965 … … 3247 3230 } 3248 3231 3249 PassRefPtr<CSSComputedStyleDeclaration> Editor::selectionComputedStyle(Node*& nodeToRemove) const 3250 { 3251 nodeToRemove = 0; 3252 3232 PassRefPtr<CSSMutableStyleDeclaration> Editor::selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const 3233 { 3253 3234 if (m_frame->selection()->isNone()) 3254 3235 return 0; … … 3270 3251 3271 3252 RefPtr<Element> styleElement = element; 3272 ExceptionCode ec = 0; 3273 3274 if (m_frame->selection()->typingStyle()) { 3275 styleElement = m_frame->document()->createElement(spanTag, false); 3276 3277 styleElement->setAttribute(styleAttr, m_frame->selection()->typingStyle()->cssText(), ec); 3278 ASSERT(!ec); 3279 3280 styleElement->appendChild(m_frame->document()->createEditingTextNode(""), ec); 3281 ASSERT(!ec); 3282 3283 if (element->renderer() && element->renderer()->canHaveChildren()) 3284 element->appendChild(styleElement, ec); 3285 else { 3286 Node* parent = element->parent(); 3287 Node* next = element->nextSibling(); 3288 3289 if (next) 3290 parent->insertBefore(styleElement, next, ec); 3291 else 3292 parent->appendChild(styleElement, ec); 3293 } 3294 ASSERT(!ec); 3295 3296 nodeToRemove = styleElement.get(); 3297 } 3298 3299 return computedStyle(styleElement.release()); 3253 RefPtr<CSSComputedStyleDeclaration> style = computedStyle(styleElement.release()); 3254 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->copy(); 3255 shouldUseFixedFontDefaultSize = style->useFixedFontDefaultSize(); 3256 3257 if (!m_frame->selection()->typingStyle()) 3258 return mutableStyle; 3259 3260 RefPtr<CSSMutableStyleDeclaration> typingStyle = m_frame->selection()->typingStyle()->copy(); 3261 ApplyStyleCommand::removeNonEditingProperties(typingStyle.get()); 3262 prepareEditingStyleToApplyAt(typingStyle.get(), position); 3263 mutableStyle->merge(typingStyle.get()); 3264 3265 return mutableStyle; 3300 3266 } 3301 3267 -
trunk/WebCore/editing/Editor.h
r67534 r68059 348 348 void setMarkedTextMatchesAreHighlighted(bool); 349 349 350 PassRefPtr<CSS ComputedStyleDeclaration> selectionComputedStyle(Node*& nodeToRemove) const;350 PassRefPtr<CSSMutableStyleDeclaration> selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const; 351 351 352 352 void textFieldDidBeginEditing(Element*); -
trunk/WebCore/editing/EditorCommand.cpp
r67534 r68059 132 132 { 133 133 ExceptionCode ec = 0; 134 Node* nodeToRemove = 0;135 RefPtr<CSS ComputedStyleDeclaration> selectionStyle = frame->editor()->selectionComputedStyle(nodeToRemove);134 bool shouldUseFixedFontDefaultSize; 135 RefPtr<CSSMutableStyleDeclaration> selectionStyle = frame->editor()->selectionComputedStyle(shouldUseFixedFontDefaultSize); 136 136 if (!selectionStyle) 137 137 return false; … … 148 148 } else if (selectedCSSValue->cssText() == "none") 149 149 newStyle = value->cssText(); 150 151 ASSERT(!ec);152 if (nodeToRemove) {153 nodeToRemove->remove(ec);154 ASSERT(!ec);155 }156 150 157 151 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
Note: See TracChangeset
for help on using the changeset viewer.