Changeset 79398 in webkit
- Timestamp:
- Feb 22, 2011, 9:35:44 PM (14 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r79397 r79398 1 2011-02-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Darin Adler. 4 5 Make Editor::selectionComputedStyle return EditingStyle 6 https://bugs.webkit.org/show_bug.cgi?id=54933 7 8 Renamed selectionComputedStyle to selectionStartStyle and changed the return type to EditingStyle. 9 It also no longer takes a boolean shouldUseFixedFontDefaultSize. 10 11 Also added EditingStyle::mergeTypingStyle which replaced old editingStyleIncludingTypingStyle. This function 12 doesn't extract inheritable properties prior to merge because this turned out be a bug, which was revealed 13 by an existing layout test only after the code was shared with selectionStartStyle. 14 15 No tests are added since this is a refactoring. 16 17 * editing/CompositeEditCommand.cpp: 18 (WebCore::CompositeEditCommand::moveParagraphs): Calls EditingStyle::create and EditingStyle::mergeTypingStyle. 19 (WebCore::CompositeEditCommand::breakOutOfEmptyListItem): Ditto. 20 * editing/EditingStyle.cpp: Removed editingStyleIncludingTypingStyle. 21 (WebCore::EditingStyle::mergeTypingStyle): Added. 22 * editing/EditingStyle.h: 23 (WebCore::EditingStyle::shouldUseFixedDefaultFontSize): Added. 24 * editing/Editor.cpp: 25 (WebCore::Editor::selectionStartHasStyle): Calls selectionStartStyle. 26 (WebCore::Editor::selectionHasStyle): Ditto. 27 (WebCore::Editor::selectionStartCSSPropertyValue): Ditto. 28 (WebCore::Editor::selectionStartStyle): Renamed from selectionComputedStyle; returns EditingStyle. 29 * editing/Editor.h: 30 * editing/EditorCommand.cpp: 31 (WebCore::executeToggleStyleInList): Calls selectionStartStyle. 32 * editing/InsertLineBreakCommand.cpp: 33 * editing/InsertParagraphSeparatorCommand.cpp: 34 (WebCore::InsertParagraphSeparatorCommand::calculateStyleBeforeInsertion): Calls EditingStyle::create and 35 EditingStyle::mergeTypingStyle. 36 * editing/ReplaceSelectionCommand.cpp: 37 (WebCore::ReplaceSelectionCommand::doApply): Ditto. 38 1 39 2011-02-22 Robert Hogan <robert@webkit.org> 2 40 -
trunk/Source/WebCore/editing/CompositeEditCommand.cpp
r79196 r79398 968 968 RefPtr<EditingStyle> styleInEmptyParagraph; 969 969 if (startOfParagraphToMove == endOfParagraphToMove && preserveStyle) { 970 styleInEmptyParagraph = editingStyleIncludingTypingStyle(startOfParagraphToMove.deepEquivalent()); 970 styleInEmptyParagraph = EditingStyle::create(startOfParagraphToMove.deepEquivalent()); 971 styleInEmptyParagraph->mergeTypingStyle(document()); 971 972 // The moved paragraph should assume the block style of the destination. 972 973 styleInEmptyParagraph->removeBlockProperties(); … … 1037 1038 return false; 1038 1039 1039 RefPtr<EditingStyle> style = editingStyleIncludingTypingStyle(endingSelection().start()); 1040 RefPtr<EditingStyle> style = EditingStyle::create(endingSelection().start()); 1041 style->mergeTypingStyle(document()); 1040 1042 1041 1043 ContainerNode* listNode = emptyListItem->parentNode(); -
trunk/Source/WebCore/editing/EditingStyle.cpp
r79382 r79398 403 403 } 404 404 405 PassRefPtr<EditingStyle> editingStyleIncludingTypingStyle(const Position& position) 406 { 407 RefPtr<EditingStyle> editingStyle = EditingStyle::create(position); 408 RefPtr<EditingStyle> typingStyle = position.anchorNode()->document()->frame()->selection()->typingStyle(); 409 if (typingStyle && typingStyle->style()) 410 editingStyle->style()->merge(copyEditingProperties(typingStyle->style()).get()); 411 return editingStyle; 405 void EditingStyle::mergeTypingStyle(Document* document) 406 { 407 ASSERT(document); 408 409 RefPtr<EditingStyle> typingStyle = document->frame()->selection()->typingStyle(); 410 if (!typingStyle || !typingStyle->style() || typingStyle == this) 411 return; 412 413 if (m_mutableStyle) 414 m_mutableStyle->merge(typingStyle->style(), true); 415 else 416 m_mutableStyle = typingStyle->style()->copy(); 412 417 } 413 418 -
trunk/Source/WebCore/editing/EditingStyle.h
r79382 r79398 43 43 class CSSComputedStyleDeclaration; 44 44 class CSSMutableStyleDeclaration; 45 class Document; 45 46 class Node; 46 47 class Position; … … 97 98 } 98 99 void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection); 100 void mergeTypingStyle(Document*); 99 101 100 102 float fontSizeDelta() const { return m_fontSizeDelta; } 101 103 bool hasFontSizeDelta() const { return m_fontSizeDelta != NoFontDelta; } 104 bool shouldUseFixedDefaultFontSize() const { return m_shouldUseFixedDefaultFontSize; } 102 105 103 106 private: … … 117 120 }; 118 121 119 PassRefPtr<EditingStyle> editingStyleIncludingTypingStyle(const Position&);120 121 122 } // namespace WebCore 122 123 -
trunk/Source/WebCore/editing/Editor.cpp
r79196 r79398 986 986 bool Editor::selectionStartHasStyle(CSSStyleDeclaration* style) const 987 987 { 988 bool shouldUseFixedFontDefaultSize; 989 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 990 if (!selectionStyle) 991 return false; 992 return triStateOfStyle(style, selectionStyle.get()) == TrueTriState; 988 RefPtr<EditingStyle> selectionStyle = selectionStartStyle(); 989 if (!selectionStyle || !selectionStyle->style()) 990 return false; 991 return triStateOfStyle(style, selectionStyle->style()) == TrueTriState; 993 992 } 994 993 995 994 TriState Editor::selectionHasStyle(CSSStyleDeclaration* style) const 996 995 { 996 if (!m_frame->selection()->isCaretOrRange()) 997 return FalseTriState; 998 999 if (m_frame->selection()->isCaret()) { 1000 RefPtr<EditingStyle> selectionStyle = selectionStartStyle(); 1001 if (!selectionStyle || !selectionStyle->style()) 1002 return FalseTriState; 1003 return triStateOfStyle(style, selectionStyle->style()); 1004 } 1005 997 1006 TriState state = FalseTriState; 998 999 if (!m_frame->selection()->isRange()) { 1000 bool shouldUseFixedFontDefaultSize; 1001 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 1002 if (!selectionStyle) 1003 return FalseTriState; 1004 state = triStateOfStyle(style, selectionStyle.get()); 1005 } else { 1006 for (Node* node = m_frame->selection()->start().deprecatedNode(); node; node = node->traverseNextNode()) { 1007 RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node); 1008 if (nodeStyle) { 1009 TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode()); 1010 if (node == m_frame->selection()->start().deprecatedNode()) 1011 state = nodeState; 1012 else if (state != nodeState && node->isTextNode()) { 1013 state = MixedTriState; 1014 break; 1015 } 1007 for (Node* node = m_frame->selection()->start().deprecatedNode(); node; node = node->traverseNextNode()) { 1008 RefPtr<CSSComputedStyleDeclaration> nodeStyle = computedStyle(node); 1009 if (nodeStyle) { 1010 TriState nodeState = triStateOfStyle(style, nodeStyle.get(), !node->isTextNode()); 1011 if (node == m_frame->selection()->start().deprecatedNode()) 1012 state = nodeState; 1013 else if (state != nodeState && node->isTextNode()) { 1014 state = MixedTriState; 1015 break; 1016 1016 } 1017 if (node == m_frame->selection()->end().deprecatedNode())1018 break;1019 1017 } 1018 if (node == m_frame->selection()->end().deprecatedNode()) 1019 break; 1020 1020 } 1021 1021 … … 1041 1041 String Editor::selectionStartCSSPropertyValue(int propertyID) 1042 1042 { 1043 bool shouldUseFixedFontDefaultSize = false; 1044 RefPtr<CSSMutableStyleDeclaration> selectionStyle = selectionComputedStyle(shouldUseFixedFontDefaultSize); 1045 if (!selectionStyle) 1043 RefPtr<EditingStyle> selectionStyle = selectionStartStyle(); 1044 if (!selectionStyle->style()) 1046 1045 return String(); 1047 1046 1048 String value = selectionStyle-> getPropertyValue(propertyID);1047 String value = selectionStyle->style()->getPropertyValue(propertyID); 1049 1048 1050 1049 // If background color is transparent, traverse parent nodes until we hit a different value or document root 1051 1050 // Also, if the selection is a range, ignore the background color at the start of selection, 1052 1051 // and find the background color of the common ancestor. 1053 if (propertyID == CSSPropertyBackgroundColor && (m_frame->selection()->isRange() || hasTransparentBackgroundColor(selectionStyle .get()))) {1052 if (propertyID == CSSPropertyBackgroundColor && (m_frame->selection()->isRange() || hasTransparentBackgroundColor(selectionStyle->style()))) { 1054 1053 RefPtr<Range> range(m_frame->selection()->toNormalizedRange()); 1055 1054 ExceptionCode ec = 0; 1056 1055 for (Node* ancestor = range->commonAncestorContainer(ec); ancestor; ancestor = ancestor->parentNode()) { 1057 selectionStyle = computedStyle(ancestor)->copy(); 1058 if (!hasTransparentBackgroundColor(selectionStyle.get())) { 1059 value = selectionStyle->getPropertyValue(CSSPropertyBackgroundColor); 1060 break; 1061 } 1056 RefPtr<CSSComputedStyleDeclaration> ancestorStyle = computedStyle(ancestor); 1057 if (!hasTransparentBackgroundColor(ancestorStyle.get())) 1058 return ancestorStyle->getPropertyValue(CSSPropertyBackgroundColor); 1062 1059 } 1063 1060 } 1064 1061 1065 1062 if (propertyID == CSSPropertyFontSize) { 1066 RefPtr<CSSValue> cssValue = selectionStyle-> getPropertyCSSValue(CSSPropertyFontSize);1063 RefPtr<CSSValue> cssValue = selectionStyle->style()->getPropertyCSSValue(CSSPropertyFontSize); 1067 1064 if (cssValue->isPrimitiveValue()) { 1068 1065 value = String::number(legacyFontSizeFromCSSValue(m_frame->document(), static_cast<CSSPrimitiveValue*>(cssValue.get()), 1069 s houldUseFixedFontDefaultSize, AlwaysUseLegacyFontSize));1066 selectionStyle->shouldUseFixedDefaultFontSize(), AlwaysUseLegacyFontSize)); 1070 1067 } 1071 1068 } … … 3177 3174 } 3178 3175 3179 PassRefPtr< CSSMutableStyleDeclaration> Editor::selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const3176 PassRefPtr<EditingStyle> Editor::selectionStartStyle() const 3180 3177 { 3181 3178 if (m_frame->selection()->isNone()) … … 3197 3194 return 0; 3198 3195 3199 RefPtr<Element> styleElement = element; 3200 RefPtr<CSSComputedStyleDeclaration> style = computedStyle(styleElement.release()); 3201 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->copy(); 3202 shouldUseFixedFontDefaultSize = style->useFixedFontDefaultSize(); 3203 3204 if (!m_frame->selection()->typingStyle()) 3205 return mutableStyle; 3206 3207 RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle()->copy(); 3208 typingStyle->prepareToApplyAt(position); 3209 mutableStyle->merge(typingStyle->style()); 3210 3211 return mutableStyle; 3196 RefPtr<EditingStyle> style = EditingStyle::create(element, EditingStyle::AllProperties); 3197 style->mergeTypingStyle(m_frame->document()); 3198 return style; 3212 3199 } 3213 3200 -
trunk/Source/WebCore/editing/Editor.h
r78632 r79398 366 366 void setMarkedTextMatchesAreHighlighted(bool); 367 367 368 PassRefPtr< CSSMutableStyleDeclaration> selectionComputedStyle(bool& shouldUseFixedFontDefaultSize) const;368 PassRefPtr<EditingStyle> selectionStartStyle() const; 369 369 370 370 void textFieldDidBeginEditing(Element*); -
trunk/Source/WebCore/editing/EditorCommand.cpp
r78632 r79398 133 133 { 134 134 ExceptionCode ec = 0; 135 bool shouldUseFixedFontDefaultSize; 136 RefPtr<CSSMutableStyleDeclaration> selectionStyle = frame->editor()->selectionComputedStyle(shouldUseFixedFontDefaultSize); 137 if (!selectionStyle) 138 return false; 139 140 RefPtr<CSSValue> selectedCSSValue = selectionStyle->getPropertyCSSValue(propertyID); 135 RefPtr<EditingStyle> selectionStyle = frame->editor()->selectionStartStyle(); 136 if (!selectionStyle || !selectionStyle->style()) 137 return false; 138 139 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSValue(propertyID); 141 140 String newStyle = "none"; 142 141 if (selectedCSSValue->isValueList()) { -
trunk/Source/WebCore/editing/InsertLineBreakCommand.cpp
r79196 r79398 27 27 #include "InsertLineBreakCommand.h" 28 28 29 #include "CSSMutableStyleDeclaration.h"30 29 #include "Document.h" 31 30 #include "Frame.h" -
trunk/Source/WebCore/editing/InsertParagraphSeparatorCommand.cpp
r79196 r79398 79 79 if (!isStartOfParagraph(visiblePos) && !isEndOfParagraph(visiblePos)) 80 80 return; 81 82 m_style = editingStyleIncludingTypingStyle(pos); 81 82 ASSERT(pos.isNotNull()); 83 m_style = EditingStyle::create(pos); 84 m_style->mergeTypingStyle(pos.anchorNode()->document()); 83 85 } 84 86 -
trunk/Source/WebCore/editing/ReplaceSelectionCommand.cpp
r79196 r79398 798 798 m_matchStyle = false; 799 799 800 if (m_matchStyle) 801 m_insertionStyle = editingStyleIncludingTypingStyle(selection.start()); 800 if (m_matchStyle) { 801 m_insertionStyle = EditingStyle::create(selection.start()); 802 m_insertionStyle->mergeTypingStyle(document()); 803 } 802 804 803 805 VisiblePosition visibleStart = selection.visibleStart();
Note:
See TracChangeset
for help on using the changeset viewer.