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

Side by Side Diff: Source/core/editing/EditorCommand.cpp

Issue 15864004: Move create() methods from StylePropertySet to MutableStylePropertySet. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/Editor.cpp ('k') | Source/core/html/HTMLTableElement.cpp » ('j') | 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) 2006, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
4 * Copyright (C) 2009 Igalia S.L. 4 * Copyright (C) 2009 Igalia S.L.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 case CommandFromDOMWithUserInterface: 111 case CommandFromDOMWithUserInterface:
112 frame->editor()->applyStyle(style); 112 frame->editor()->applyStyle(style);
113 return true; 113 return true;
114 } 114 }
115 ASSERT_NOT_REACHED(); 115 ASSERT_NOT_REACHED();
116 return false; 116 return false;
117 } 117 }
118 118
119 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditActi on action, CSSPropertyID propertyID, const String& propertyValue) 119 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditActi on action, CSSPropertyID propertyID, const String& propertyValue)
120 { 120 {
121 RefPtr<StylePropertySet> style = StylePropertySet::create(); 121 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
122 style->setProperty(propertyID, propertyValue); 122 style->setProperty(propertyID, propertyValue);
123 return applyCommandToFrame(frame, source, action, style.get()); 123 return applyCommandToFrame(frame, source, action, style.get());
124 } 124 }
125 125
126 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditActi on action, CSSPropertyID propertyID, int propertyValue) 126 static bool executeApplyStyle(Frame* frame, EditorCommandSource source, EditActi on action, CSSPropertyID propertyID, int propertyValue)
127 { 127 {
128 RefPtr<StylePropertySet> style = StylePropertySet::create(); 128 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
129 style->setProperty(propertyID, propertyValue); 129 style->setProperty(propertyID, propertyValue);
130 return applyCommandToFrame(frame, source, action, style.get()); 130 return applyCommandToFrame(frame, source, action, style.get());
131 } 131 }
132 132
133 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b> <u>hello</u>world</b> properly. 133 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b> <u>hello</u>world</b> properly.
134 // This function must use Editor::selectionHasStyle to determine the curr ent style but we cannot fix this 134 // This function must use Editor::selectionHasStyle to determine the curr ent style but we cannot fix this
135 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved. 135 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved.
136 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, E ditAction action, CSSPropertyID propertyID, CSSValue* value) 136 static bool executeToggleStyleInList(Frame* frame, EditorCommandSource source, E ditAction action, CSSPropertyID propertyID, CSSValue* value)
137 { 137 {
138 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(fr ame->selection()->selection()); 138 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(fr ame->selection()->selection());
139 if (!selectionStyle || !selectionStyle->style()) 139 if (!selectionStyle || !selectionStyle->style())
140 return false; 140 return false;
141 141
142 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSV alue(propertyID); 142 RefPtr<CSSValue> selectedCSSValue = selectionStyle->style()->getPropertyCSSV alue(propertyID);
143 String newStyle = ASCIILiteral("none"); 143 String newStyle = ASCIILiteral("none");
144 if (selectedCSSValue->isValueList()) { 144 if (selectedCSSValue->isValueList()) {
145 RefPtr<CSSValueList> selectedCSSValueList = static_cast<CSSValueList*>(s electedCSSValue.get()); 145 RefPtr<CSSValueList> selectedCSSValueList = static_cast<CSSValueList*>(s electedCSSValue.get());
146 if (!selectedCSSValueList->removeAll(value)) 146 if (!selectedCSSValueList->removeAll(value))
147 selectedCSSValueList->append(value); 147 selectedCSSValueList->append(value);
148 if (selectedCSSValueList->length()) 148 if (selectedCSSValueList->length())
149 newStyle = selectedCSSValueList->cssText(); 149 newStyle = selectedCSSValueList->cssText();
150 150
151 } else if (selectedCSSValue->cssText() == "none") 151 } else if (selectedCSSValue->cssText() == "none")
152 newStyle = value->cssText(); 152 newStyle = value->cssText();
153 153
154 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue. 154 // FIXME: We shouldn't be having to convert new style into text. We should have setPropertyCSSValue.
155 RefPtr<StylePropertySet> newMutableStyle = StylePropertySet::create(); 155 RefPtr<MutableStylePropertySet> newMutableStyle = MutableStylePropertySet::c reate();
156 newMutableStyle->setProperty(propertyID, newStyle); 156 newMutableStyle->setProperty(propertyID, newStyle);
157 return applyCommandToFrame(frame, source, action, newMutableStyle.get()); 157 return applyCommandToFrame(frame, source, action, newMutableStyle.get());
158 } 158 }
159 159
160 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAct ion action, CSSPropertyID propertyID, const char* offValue, const char* onValue) 160 static bool executeToggleStyle(Frame* frame, EditorCommandSource source, EditAct ion action, CSSPropertyID propertyID, const char* offValue, const char* onValue)
161 { 161 {
162 // Style is considered present when 162 // Style is considered present when
163 // Mac: present at the beginning of selection 163 // Mac: present at the beginning of selection
164 // other: present throughout the selection 164 // other: present throughout the selection
165 165
166 bool styleIsPresent; 166 bool styleIsPresent;
167 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection()) 167 if (frame->editor()->behavior().shouldToggleStyleBasedOnStartOfSelection())
168 styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onV alue); 168 styleIsPresent = frame->editor()->selectionStartHasStyle(propertyID, onV alue);
169 else 169 else
170 styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState; 170 styleIsPresent = frame->editor()->selectionHasStyle(propertyID, onValue) == TrueTriState;
171 171
172 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue); 172 RefPtr<EditingStyle> style = EditingStyle::create(propertyID, styleIsPresent ? offValue : onValue);
173 return applyCommandToFrame(frame, source, action, style->style()); 173 return applyCommandToFrame(frame, source, action, style->style());
174 } 174 }
175 175
176 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue) 176 static bool executeApplyParagraphStyle(Frame* frame, EditorCommandSource source, EditAction action, CSSPropertyID propertyID, const String& propertyValue)
177 { 177 {
178 RefPtr<StylePropertySet> style = StylePropertySet::create(); 178 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
179 style->setProperty(propertyID, propertyValue); 179 style->setProperty(propertyID, propertyValue);
180 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that? 180 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a good reason for that?
181 switch (source) { 181 switch (source) {
182 case CommandFromMenuOrKeyBinding: 182 case CommandFromMenuOrKeyBinding:
183 frame->editor()->applyParagraphStyleToSelection(style.get(), action); 183 frame->editor()->applyParagraphStyleToSelection(style.get(), action);
184 return true; 184 return true;
185 case CommandFromDOM: 185 case CommandFromDOM:
186 case CommandFromDOMWithUserInterface: 186 case CommandFromDOMWithUserInterface:
187 frame->editor()->applyParagraphStyle(style.get()); 187 frame->editor()->applyParagraphStyle(style.get());
188 return true; 188 return true;
(...skipping 392 matching lines...) Expand 10 before | Expand all | Expand 10 after
581 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro pertyTextAlign, "left"); 581 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro pertyTextAlign, "left");
582 } 582 }
583 583
584 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source , const String&) 584 static bool executeJustifyRight(Frame* frame, Event*, EditorCommandSource source , const String&)
585 { 585 {
586 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr opertyTextAlign, "right"); 586 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr opertyTextAlign, "right");
587 } 587 }
588 588
589 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, Edi torCommandSource, const String&) 589 static bool executeMakeTextWritingDirectionLeftToRight(Frame* frame, Event*, Edi torCommandSource, const String&)
590 { 590 {
591 RefPtr<StylePropertySet> style = StylePropertySet::create(); 591 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
592 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); 592 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
593 style->setProperty(CSSPropertyDirection, CSSValueLtr); 593 style->setProperty(CSSPropertyDirection, CSSValueLtr);
594 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection); 594 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
595 return true; 595 return true;
596 } 596 }
597 597
598 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorC ommandSource, const String&) 598 static bool executeMakeTextWritingDirectionNatural(Frame* frame, Event*, EditorC ommandSource, const String&)
599 { 599 {
600 RefPtr<StylePropertySet> style = StylePropertySet::create(); 600 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
601 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); 601 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal);
602 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection); 602 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
603 return true; 603 return true;
604 } 604 }
605 605
606 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, Edi torCommandSource, const String&) 606 static bool executeMakeTextWritingDirectionRightToLeft(Frame* frame, Event*, Edi torCommandSource, const String&)
607 { 607 {
608 RefPtr<StylePropertySet> style = StylePropertySet::create(); 608 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create();
609 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); 609 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed);
610 style->setProperty(CSSPropertyDirection, CSSValueRtl); 610 style->setProperty(CSSPropertyDirection, CSSValueRtl);
611 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection); 611 frame->editor()->applyStyle(style.get(), EditActionSetWritingDirection);
612 return true; 612 return true;
613 } 613 }
614 614
615 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&) 615 static bool executeMoveBackward(Frame* frame, Event*, EditorCommandSource, const String&)
616 { 616 {
617 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward , CharacterGranularity, UserTriggered); 617 frame->selection()->modify(FrameSelection::AlterationMove, DirectionBackward , CharacterGranularity, UserTriggered);
618 return true; 618 return true;
(...skipping 1110 matching lines...) Expand 10 before | Expand all | Expand 10 after
1729 return m_command->state(m_frame.get(), triggeringEvent) == TrueTriState ? "true" : "false"; 1729 return m_command->state(m_frame.get(), triggeringEvent) == TrueTriState ? "true" : "false";
1730 return m_command->value(m_frame.get(), triggeringEvent); 1730 return m_command->value(m_frame.get(), triggeringEvent);
1731 } 1731 }
1732 1732
1733 bool Editor::Command::isTextInsertion() const 1733 bool Editor::Command::isTextInsertion() const
1734 { 1734 {
1735 return m_command && m_command->isTextInsertion; 1735 return m_command && m_command->isTextInsertion;
1736 } 1736 }
1737 1737
1738 } // namespace WebCore 1738 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/Editor.cpp ('k') | Source/core/html/HTMLTableElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698