OLD | NEW |
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 Loading... |
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(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) | 119 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) |
120 { | 120 { |
121 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 121 RefPtrWillBeRawPtr<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(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, CSSValueID propertyValue) | 126 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, CSSValueID propertyValue) |
127 { | 127 { |
128 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 128 RefPtrWillBeRawPtr<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(LocalFrame& frame, EditorCommandSource sour
ce, EditAction action, CSSPropertyID propertyID, CSSValue* value) | 136 static bool executeToggleStyleInList(LocalFrame& frame, EditorCommandSource sour
ce, EditAction 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 RefPtrWillBeRawPtr<CSSValue> selectedCSSValue = selectionStyle->style()->get
PropertyCSSValue(propertyID); | 142 RefPtrWillBeRawPtr<CSSValue> selectedCSSValue = selectionStyle->style()->get
PropertyCSSValue(propertyID); |
143 String newStyle("none"); | 143 String newStyle("none"); |
144 if (selectedCSSValue->isValueList()) { | 144 if (selectedCSSValue->isValueList()) { |
145 RefPtrWillBeRawPtr<CSSValueList> selectedCSSValueList = toCSSValueList(s
electedCSSValue.get()); | 145 RefPtrWillBeRawPtr<CSSValueList> selectedCSSValueList = toCSSValueList(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<MutableStylePropertySet> newMutableStyle = MutableStylePropertySet::c
reate(); | 155 RefPtrWillBeRawPtr<MutableStylePropertySet> newMutableStyle = MutableStylePr
opertySet::create(); |
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(LocalFrame& frame, EditorCommandSource source, Ed
itAction action, CSSPropertyID propertyID, const char* offValue, const char* onV
alue) | 160 static bool executeToggleStyle(LocalFrame& frame, EditorCommandSource source, Ed
itAction action, CSSPropertyID propertyID, const char* offValue, const char* onV
alue) |
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, onVal
ue); | 168 styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onVal
ue); |
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(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) | 176 static bool executeApplyParagraphStyle(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) |
177 { | 177 { |
178 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 178 RefPtrWillBeRawPtr<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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
589 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro
pertyTextAlign, "left"); | 589 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro
pertyTextAlign, "left"); |
590 } | 590 } |
591 | 591 |
592 static bool executeJustifyRight(LocalFrame& frame, Event*, EditorCommandSource s
ource, const String&) | 592 static bool executeJustifyRight(LocalFrame& frame, Event*, EditorCommandSource s
ource, const String&) |
593 { | 593 { |
594 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr
opertyTextAlign, "right"); | 594 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr
opertyTextAlign, "right"); |
595 } | 595 } |
596 | 596 |
597 static bool executeMakeTextWritingDirectionLeftToRight(LocalFrame& frame, Event*
, EditorCommandSource, const String&) | 597 static bool executeMakeTextWritingDirectionLeftToRight(LocalFrame& frame, Event*
, EditorCommandSource, const String&) |
598 { | 598 { |
599 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 599 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); |
600 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); | 600 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
601 style->setProperty(CSSPropertyDirection, CSSValueLtr); | 601 style->setProperty(CSSPropertyDirection, CSSValueLtr); |
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 executeMakeTextWritingDirectionNatural(LocalFrame& frame, Event*, Ed
itorCommandSource, const String&) | 606 static bool executeMakeTextWritingDirectionNatural(LocalFrame& frame, Event*, Ed
itorCommandSource, const String&) |
607 { | 607 { |
608 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 608 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); |
609 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); | 609 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); |
610 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); | 610 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); |
611 return true; | 611 return true; |
612 } | 612 } |
613 | 613 |
614 static bool executeMakeTextWritingDirectionRightToLeft(LocalFrame& frame, Event*
, EditorCommandSource, const String&) | 614 static bool executeMakeTextWritingDirectionRightToLeft(LocalFrame& frame, Event*
, EditorCommandSource, const String&) |
615 { | 615 { |
616 RefPtr<MutableStylePropertySet> style = MutableStylePropertySet::create(); | 616 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); |
617 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); | 617 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
618 style->setProperty(CSSPropertyDirection, CSSValueRtl); | 618 style->setProperty(CSSPropertyDirection, CSSValueRtl); |
619 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); | 619 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); |
620 return true; | 620 return true; |
621 } | 621 } |
622 | 622 |
623 static bool executeMoveBackward(LocalFrame& frame, Event*, EditorCommandSource,
const String&) | 623 static bool executeMoveBackward(LocalFrame& frame, Event*, EditorCommandSource,
const String&) |
624 { | 624 { |
625 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward,
CharacterGranularity, UserTriggered); | 625 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward,
CharacterGranularity, UserTriggered); |
626 return true; | 626 return true; |
(...skipping 1103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1730 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "tr
ue" : "false"; | 1730 return m_command->state(*m_frame, triggeringEvent) == TrueTriState ? "tr
ue" : "false"; |
1731 return m_command->value(*m_frame, triggeringEvent); | 1731 return m_command->value(*m_frame, triggeringEvent); |
1732 } | 1732 } |
1733 | 1733 |
1734 bool Editor::Command::isTextInsertion() const | 1734 bool Editor::Command::isTextInsertion() const |
1735 { | 1735 { |
1736 return m_command && m_command->isTextInsertion; | 1736 return m_command && m_command->isTextInsertion; |
1737 } | 1737 } |
1738 | 1738 |
1739 } // namespace WebCore | 1739 } // namespace WebCore |
OLD | NEW |