Changeset 72573 in webkit
- Timestamp:
- Nov 22, 2010 4:25:10 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r72572 r72573 1 2010-11-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 SelectionController::typingStyle() should return EditingStyle* 6 https://bugs.webkit.org/show_bug.cgi?id=49813 7 8 Changed the return type of SelectionController::typingStyle to EditingStyle*. 9 10 Extracted textDirection from Editor::textDirectionForSelection to hide the underlying 11 CSSMutableStyleDeclaration. 12 13 Also extracted the code to preserve unicode-bidi and direction CSS properties in 14 InsertTextCommand::input, and moved into EditingStyle::prepareToApplyAt. ShouldPreserveWritingDirection, 15 which is added to the argument list of EditingStyle::prepareToApplyAt, decides whether or not 16 these two properties are preserved. 17 18 Also added SelectionController::copyTypingStyle() to copy the typing style as an instance of 19 CSSMutableStyleDeclaration. 20 21 No new tests are added since this is a refactoring. 22 23 * editing/EditingStyle.cpp: 24 (WebCore::EditingStyle::textDirection): Extracted from Editor::textDirectionForSelection. 25 (WebCore::EditingStyle::removeStyleConflictingWithStyleOfNode): Added a missing null check. 26 (WebCore::EditingStyle::prepareToApplyAt): See above. 27 (WebCore::editingStyleIncludingTypingStyle): Calls SelectionController::typingStyle. 28 * editing/EditingStyle.h: Moved WritingDirection from Editor.h 29 * editing/Editor.cpp: 30 (WebCore::Editor::textDirectionForSelection): Calls EditingStyle::textDirection. 31 (WebCore::Editor::computeAndSetTypingStyle): Calls SelectionController::typingStyle. 32 (WebCore::Editor::selectionComputedStyle): Ditto. 33 (WebCore::Editor::styleForSelectionStart): Ditto. 34 * editing/Editor.h: 35 * editing/InsertLineBreakCommand.cpp: 36 (WebCore::InsertLineBreakCommand::doApply): Ditto. 37 * editing/InsertTextCommand.cpp: 38 (WebCore::InsertTextCommand::input): Calls EditingStyle::prepareToApplyAt with PreserveWritingDirection. 39 * editing/SelectionController.h: 40 (WebCore::SelectionController::typingStyle): Returns EditingStyle* rather than CSSMutableStyleDeclaration*. 41 (WebCore::SelectionController::copyTypingStyle): Added. 42 1 43 2010-11-22 Patrick Gansterer <paroga@webkit.org> 2 44 -
trunk/WebCore/editing/EditingStyle.cpp
r72500 r72573 31 31 #include "CSSComputedStyleDeclaration.h" 32 32 #include "CSSMutableStyleDeclaration.h" 33 #include "CSSValueKeywords.h" 33 34 #include "Frame.h" 34 35 #include "RenderStyle.h" … … 142 143 } 143 144 145 bool EditingStyle::textDirection(WritingDirection& writingDirection) const 146 { 147 RefPtr<CSSValue> unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); 148 if (!unicodeBidi) 149 return false; 150 151 ASSERT(unicodeBidi->isPrimitiveValue()); 152 int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent(); 153 if (unicodeBidiValue == CSSValueEmbed) { 154 RefPtr<CSSValue> direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); 155 ASSERT(!direction || direction->isPrimitiveValue()); 156 if (!direction) 157 return false; 158 159 writingDirection = static_cast<CSSPrimitiveValue*>(direction.get())->getIdent() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; 160 161 return true; 162 } 163 164 if (unicodeBidiValue == CSSValueNormal) { 165 writingDirection = NaturalWritingDirection; 166 return true; 167 } 168 169 return false; 170 } 171 144 172 void EditingStyle::setStyle(PassRefPtr<CSSMutableStyleDeclaration> style) 145 173 { … … 176 204 void EditingStyle::removeStyleConflictingWithStyleOfNode(Node* node) 177 205 { 178 if (!node || !node->parentNode() )206 if (!node || !node->parentNode() || !m_mutableStyle) 179 207 return; 180 208 RefPtr<CSSMutableStyleDeclaration> parentStyle = editingStyleFromComputedStyle(computedStyle(node->parentNode())); … … 193 221 } 194 222 195 void EditingStyle::prepareToApplyAt(const Position& position) 196 { 223 void EditingStyle::prepareToApplyAt(const Position& position, ShouldPreserveWritingDirection shouldPreserveWritingDirection) 224 { 225 if (!m_mutableStyle) 226 return; 227 197 228 // ReplaceSelectionCommand::handleStyleSpans() requires that this function only removes the editing style. 198 229 // If this function was modified in the future to delete all redundant properties, then add a boolean value to indicate 199 230 // which one of editingStyleAtPosition or computedStyle is called. 200 231 RefPtr<EditingStyle> style = EditingStyle::create(position); 232 233 RefPtr<CSSValue> unicodeBidi; 234 RefPtr<CSSValue> direction; 235 if (shouldPreserveWritingDirection == PreserveWritingDirection) { 236 unicodeBidi = m_mutableStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); 237 direction = m_mutableStyle->getPropertyCSSValue(CSSPropertyDirection); 238 } 239 201 240 style->m_mutableStyle->diff(m_mutableStyle.get()); 202 241 … … 208 247 m_mutableStyle->removeProperty(CSSPropertyBackgroundColor, ec); 209 248 } 249 250 if (unicodeBidi) { 251 ASSERT(unicodeBidi->isPrimitiveValue()); 252 m_mutableStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent()); 253 if (direction) { 254 ASSERT(direction->isPrimitiveValue()); 255 m_mutableStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent()); 256 } 257 } 210 258 } 211 259 … … 213 261 { 214 262 RefPtr<EditingStyle> editingStyle = EditingStyle::create(position); 215 RefPtr< CSSMutableStyleDeclaration> typingStyle = position.node()->document()->frame()->selection()->typingStyle();216 if (typingStyle )217 editingStyle->style()->merge(copyEditingProperties(typingStyle .get()).get());263 RefPtr<EditingStyle> typingStyle = position.node()->document()->frame()->selection()->typingStyle(); 264 if (typingStyle && typingStyle->style()) 265 editingStyle->style()->merge(copyEditingProperties(typingStyle->style()).get()); 218 266 return editingStyle; 219 267 } -
trunk/WebCore/editing/EditingStyle.h
r71556 r72573 41 41 class CSSComputedStyleDeclaration; 42 42 43 enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection }; 44 43 45 class EditingStyle : public RefCounted<EditingStyle> { 44 46 public: 47 48 enum ShouldPreserveWritingDirection { PreserveWritingDirection, DoNotPreserveWritingDirection }; 45 49 46 50 static PassRefPtr<EditingStyle> create() … … 65 69 66 70 CSSMutableStyleDeclaration* style() { return m_mutableStyle.get(); } 71 bool textDirection(WritingDirection&) const; 67 72 bool isEmpty() const; 68 73 void setStyle(PassRefPtr<CSSMutableStyleDeclaration>); … … 72 77 void removeStyleConflictingWithStyleOfNode(Node* node); 73 78 void removeNonEditingProperties(); 74 void prepareToApplyAt(const Position& );79 void prepareToApplyAt(const Position&, ShouldPreserveWritingDirection = DoNotPreserveWritingDirection); 75 80 76 81 private: -
trunk/WebCore/editing/Editor.cpp
r72500 r72573 617 617 618 618 if (m_frame->selection()->isCaret()) { 619 RefPtr<CSSMutableStyleDeclaration> typingStyle = m_frame->selection()->typingStyle(); 620 if (typingStyle) { 621 RefPtr<CSSValue> unicodeBidi = typingStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); 622 if (unicodeBidi) { 623 ASSERT(unicodeBidi->isPrimitiveValue()); 624 int unicodeBidiValue = static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent(); 625 if (unicodeBidiValue == CSSValueEmbed) { 626 RefPtr<CSSValue> direction = typingStyle->getPropertyCSSValue(CSSPropertyDirection); 627 ASSERT(!direction || direction->isPrimitiveValue()); 628 if (direction) { 629 hasNestedOrMultipleEmbeddings = false; 630 return static_cast<CSSPrimitiveValue*>(direction.get())->getIdent() == CSSValueLtr ? LeftToRightWritingDirection : RightToLeftWritingDirection; 631 } 632 } else if (unicodeBidiValue == CSSValueNormal) { 633 hasNestedOrMultipleEmbeddings = false; 634 return NaturalWritingDirection; 635 } 636 } 619 RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle(); 620 WritingDirection direction; 621 if (typingStyle && typingStyle->textDirection(direction)) { 622 hasNestedOrMultipleEmbeddings = false; 623 return direction; 637 624 } 638 625 node = m_frame->selection()->selection().visibleStart().deepEquivalent().node(); … … 3028 3015 // Calculate the current typing style. 3029 3016 RefPtr<CSSMutableStyleDeclaration> mutableStyle = style->makeMutable(); 3030 if (m_frame->selection()->typingStyle()) { 3031 m_frame->selection()->typingStyle()->merge(mutableStyle.get()); 3032 mutableStyle = m_frame->selection()->typingStyle(); 3017 RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle(); 3018 if (typingStyle && typingStyle->style()) { 3019 typingStyle->style()->merge(mutableStyle.get()); 3020 mutableStyle = typingStyle->style(); 3033 3021 } 3034 3022 … … 3090 3078 return mutableStyle; 3091 3079 3092 RefPtr<EditingStyle> typingStyle = EditingStyle::create(m_frame->selection()->typingStyle());3080 RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle(); 3093 3081 typingStyle->removeNonEditingProperties(); 3094 3082 typingStyle->prepareToApplyAt(position); … … 3174 3162 return 0; 3175 3163 3176 if (!m_frame->selection()->typingStyle()) 3164 RefPtr<EditingStyle> typingStyle = m_frame->selection()->typingStyle(); 3165 if (!typingStyle || !typingStyle->style()) 3177 3166 return position.node()->renderer()->style(); 3178 3167 … … 3180 3169 3181 3170 ExceptionCode ec = 0; 3182 String styleText = m_frame->selection()->typingStyle()->cssText() + " display: inline";3171 String styleText = typingStyle->style()->cssText() + " display: inline"; 3183 3172 styleElement->setAttribute(styleAttr, styleText.impl(), ec); 3184 3173 ASSERT(!ec); -
trunk/WebCore/editing/Editor.h
r72469 r72573 71 71 enum TriState { FalseTriState, TrueTriState, MixedTriState }; 72 72 enum EditorCommandSource { CommandFromMenuOrKeyBinding, CommandFromDOM, CommandFromDOMWithUserInterface }; 73 enum WritingDirection { NaturalWritingDirection, LeftToRightWritingDirection, RightToLeftWritingDirection };74 73 75 74 class Editor { -
trunk/WebCore/editing/InsertLineBreakCommand.cpp
r71469 r72573 165 165 166 166 // Handle the case where there is a typing style. 167 168 RefPtr< CSSMutableStyleDeclaration> typingStyle = document()->frame()->selection()->typingStyle();169 170 if (typingStyle && typingStyle->length() > 0) {167 168 RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle(); 169 170 if (typingStyle && !typingStyle->isEmpty()) { 171 171 // Apply the typing style to the inserted line break, so that if the selection 172 172 // leaves and then comes back, new input will have the right style. 173 173 // FIXME: We shouldn't always apply the typing style to the line break here, 174 174 // see <rdar://problem/5794462>. 175 applyStyle(typingStyle .get(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get()));175 applyStyle(typingStyle->style(), firstDeepEditingPositionForNode(nodeToInsert.get()), lastDeepEditingPositionForNode(nodeToInsert.get())); 176 176 // Even though this applyStyle operates on a Range, it still sets an endingSelection(). 177 177 // It tries to set a VisibleSelection around the content it operated on. So, that VisibleSelection -
trunk/WebCore/editing/InsertTextCommand.cpp
r71469 r72573 191 191 192 192 // Handle the case where there is a typing style. 193 RefPtr<CSSMutableStyleDeclaration> typingStyle = document()->frame()->selection()->typingStyle(); 194 RefPtr<CSSComputedStyleDeclaration> endingStyle = endPosition.computedStyle(); 195 RefPtr<CSSValue> unicodeBidi; 196 RefPtr<CSSValue> direction; 197 if (typingStyle) { 198 unicodeBidi = typingStyle->getPropertyCSSValue(CSSPropertyUnicodeBidi); 199 direction = typingStyle->getPropertyCSSValue(CSSPropertyDirection); 200 } 201 endingStyle->diff(typingStyle.get()); 202 if (typingStyle && unicodeBidi) { 203 ASSERT(unicodeBidi->isPrimitiveValue()); 204 typingStyle->setProperty(CSSPropertyUnicodeBidi, static_cast<CSSPrimitiveValue*>(unicodeBidi.get())->getIdent()); 205 if (direction) { 206 ASSERT(direction->isPrimitiveValue()); 207 typingStyle->setProperty(CSSPropertyDirection, static_cast<CSSPrimitiveValue*>(direction.get())->getIdent()); 208 } 209 } 210 211 if (typingStyle && typingStyle->length()) 212 applyStyle(typingStyle.get()); 193 if (RefPtr<EditingStyle> typingStyle = document()->frame()->selection()->typingStyle()) { 194 typingStyle->prepareToApplyAt(endPosition, EditingStyle::PreserveWritingDirection); 195 if (!typingStyle->isEmpty()) 196 applyStyle(typingStyle->style()); 197 } 213 198 214 199 if (!selectInsertedText) -
trunk/WebCore/editing/SelectionController.h
r71469 r72573 161 161 void paintDragCaret(GraphicsContext*, int tx, int ty, const IntRect& clipRect) const; 162 162 163 CSSMutableStyleDeclaration* typingStyle() const; 163 EditingStyle* typingStyle() const; 164 PassRefPtr<CSSMutableStyleDeclaration> copyTypingStyle() const; 164 165 void setTypingStyle(PassRefPtr<EditingStyle>); 165 166 void clearTypingStyle(); … … 234 235 }; 235 236 236 inline CSSMutableStyleDeclaration* SelectionController::typingStyle() const 237 { 238 return m_typingStyle ? m_typingStyle->style() : 0; 237 inline EditingStyle* SelectionController::typingStyle() const 238 { 239 return m_typingStyle.get(); 240 } 241 242 inline PassRefPtr<CSSMutableStyleDeclaration> SelectionController::copyTypingStyle() const 243 { 244 if (!m_typingStyle || !m_typingStyle->style()) 245 return 0; 246 return m_typingStyle->style()->copy(); 239 247 } 240 248 -
trunk/WebKit/mac/ChangeLog
r72443 r72573 1 2010-11-22 Ryosuke Niwa <rniwa@webkit.org> 2 3 Reviewed by Tony Chang. 4 5 SelectionController::typingStyle() should return EditingStyle* 6 https://bugs.webkit.org/show_bug.cgi?id=49813 7 8 Changed the return value of SelectionController::typingStyle() to EditingStyle*. 9 Also added SelectionController::copyTypingStyle() to copy the typing style 10 as an instance of CSSMutableStyleDeclaration. 11 12 No tests are added since this is no behavioral change. 13 14 * WebView/WebFrame.mm: 15 (-[WebFrame _typingStyle]): Calls SelectionController::copyTypingStyle() 16 1 17 2010-11-19 Michael Saboff <msaboff@apple.com> 2 18 -
trunk/WebKit/mac/WebView/WebFrame.mm
r71451 r72573 902 902 - (DOMCSSStyleDeclaration *)_typingStyle 903 903 { 904 if (!_private->coreFrame || !_private->coreFrame->selection()->typingStyle()) 905 return nil; 906 return kit(_private->coreFrame->selection()->typingStyle()->copy().get()); 904 if (!_private->coreFrame) 905 return nil; 906 RefPtr<CSSMutableStyleDeclaration> typingStyle = _private->coreFrame->selection()->copyTypingStyle(); 907 if (!typingStyle) 908 return nil; 909 return kit(typingStyle.get()); 907 910 } 908 911
Note: See TracChangeset
for help on using the changeset viewer.