| 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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 case CommandFromDOM: | 113 case CommandFromDOM: |
| 114 frame.editor().applyStyle(style); | 114 frame.editor().applyStyle(style); |
| 115 return true; | 115 return true; |
| 116 } | 116 } |
| 117 ASSERT_NOT_REACHED(); | 117 ASSERT_NOT_REACHED(); |
| 118 return false; | 118 return false; |
| 119 } | 119 } |
| 120 | 120 |
| 121 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) | 121 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) |
| 122 { | 122 { |
| 123 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 123 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 124 style->setProperty(propertyID, propertyValue); | 124 style->setProperty(propertyID, propertyValue); |
| 125 return applyCommandToFrame(frame, source, action, style.get()); | 125 return applyCommandToFrame(frame, source, action, style.get()); |
| 126 } | 126 } |
| 127 | 127 |
| 128 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, CSSValueID propertyValue) | 128 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, CSSValueID propertyValue) |
| 129 { | 129 { |
| 130 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 130 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 131 style->setProperty(propertyID, propertyValue); | 131 style->setProperty(propertyID, propertyValue); |
| 132 return applyCommandToFrame(frame, source, action, style.get()); | 132 return applyCommandToFrame(frame, source, action, style.get()); |
| 133 } | 133 } |
| 134 | 134 |
| 135 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b>
<u>hello</u>world</b> properly. | 135 // FIXME: executeToggleStyleInList does not handle complicated cases such as <b>
<u>hello</u>world</b> properly. |
| 136 // This function must use Editor::selectionHasStyle to determine the curr
ent style but we cannot fix this | 136 // This function must use Editor::selectionHasStyle to determine the curr
ent style but we cannot fix this |
| 137 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved. | 137 // until https://bugs.webkit.org/show_bug.cgi?id=27818 is resolved. |
| 138 static bool executeToggleStyleInList(LocalFrame& frame, EditorCommandSource sour
ce, EditAction action, CSSPropertyID propertyID, CSSValue* value) | 138 static bool executeToggleStyleInList(LocalFrame& frame, EditorCommandSource sour
ce, EditAction action, CSSPropertyID propertyID, CSSValue* value) |
| 139 { | 139 { |
| 140 RefPtrWillBeRawPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelec
tionStart(frame.selection().selection()); | 140 RefPtrWillBeRawPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelec
tionStart(frame.selection().selection()); |
| 141 if (!selectionStyle || !selectionStyle->style()) | 141 if (!selectionStyle || !selectionStyle->style()) |
| 142 return false; | 142 return false; |
| 143 | 143 |
| 144 RefPtrWillBeRawPtr<CSSValue> selectedCSSValue = selectionStyle->style()->get
PropertyCSSValue(propertyID); | 144 RefPtrWillBeRawPtr<CSSValue> selectedCSSValue = selectionStyle->style()->get
PropertyCSSValue(propertyID); |
| 145 String newStyle("none"); | 145 String newStyle("none"); |
| 146 if (selectedCSSValue->isValueList()) { | 146 if (selectedCSSValue->isValueList()) { |
| 147 RefPtrWillBeRawPtr<CSSValueList> selectedCSSValueList = toCSSValueList(s
electedCSSValue.get()); | 147 RefPtrWillBeRawPtr<CSSValueList> selectedCSSValueList = toCSSValueList(s
electedCSSValue.get()); |
| 148 if (!selectedCSSValueList->removeAll(value)) | 148 if (!selectedCSSValueList->removeAll(value)) |
| 149 selectedCSSValueList->append(value); | 149 selectedCSSValueList->append(value); |
| 150 if (selectedCSSValueList->length()) | 150 if (selectedCSSValueList->length()) |
| 151 newStyle = selectedCSSValueList->cssText(); | 151 newStyle = selectedCSSValueList->cssText(); |
| 152 | 152 |
| 153 } else if (selectedCSSValue->cssText() == "none") { | 153 } else if (selectedCSSValue->cssText() == "none") { |
| 154 newStyle = value->cssText(); | 154 newStyle = value->cssText(); |
| 155 } | 155 } |
| 156 | 156 |
| 157 // FIXME: We shouldn't be having to convert new style into text. We should
have setPropertyCSSValue. | 157 // FIXME: We shouldn't be having to convert new style into text. We should
have setPropertyCSSValue. |
| 158 RefPtrWillBeRawPtr<MutableStylePropertySet> newMutableStyle = MutableStylePr
opertySet::create(); | 158 RefPtrWillBeRawPtr<MutableStylePropertySet> newMutableStyle = MutableStylePr
opertySet::create(HTMLQuirksMode); |
| 159 newMutableStyle->setProperty(propertyID, newStyle); | 159 newMutableStyle->setProperty(propertyID, newStyle); |
| 160 return applyCommandToFrame(frame, source, action, newMutableStyle.get()); | 160 return applyCommandToFrame(frame, source, action, newMutableStyle.get()); |
| 161 } | 161 } |
| 162 | 162 |
| 163 static bool executeToggleStyle(LocalFrame& frame, EditorCommandSource source, Ed
itAction action, CSSPropertyID propertyID, const char* offValue, const char* onV
alue) | 163 static bool executeToggleStyle(LocalFrame& frame, EditorCommandSource source, Ed
itAction action, CSSPropertyID propertyID, const char* offValue, const char* onV
alue) |
| 164 { | 164 { |
| 165 // Style is considered present when | 165 // Style is considered present when |
| 166 // Mac: present at the beginning of selection | 166 // Mac: present at the beginning of selection |
| 167 // other: present throughout the selection | 167 // other: present throughout the selection |
| 168 | 168 |
| 169 bool styleIsPresent; | 169 bool styleIsPresent; |
| 170 if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection()) | 170 if (frame.editor().behavior().shouldToggleStyleBasedOnStartOfSelection()) |
| 171 styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onVal
ue); | 171 styleIsPresent = frame.editor().selectionStartHasStyle(propertyID, onVal
ue); |
| 172 else | 172 else |
| 173 styleIsPresent = frame.editor().selectionHasStyle(propertyID, onValue) =
= TrueTriState; | 173 styleIsPresent = frame.editor().selectionHasStyle(propertyID, onValue) =
= TrueTriState; |
| 174 | 174 |
| 175 RefPtrWillBeRawPtr<EditingStyle> style = EditingStyle::create(propertyID, st
yleIsPresent ? offValue : onValue); | 175 RefPtrWillBeRawPtr<EditingStyle> style = EditingStyle::create(propertyID, st
yleIsPresent ? offValue : onValue); |
| 176 return applyCommandToFrame(frame, source, action, style->style()); | 176 return applyCommandToFrame(frame, source, action, style->style()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 static bool executeApplyParagraphStyle(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) | 179 static bool executeApplyParagraphStyle(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) |
| 180 { | 180 { |
| 181 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 181 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 182 style->setProperty(propertyID, propertyValue); | 182 style->setProperty(propertyID, propertyValue); |
| 183 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? | 183 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? |
| 184 switch (source) { | 184 switch (source) { |
| 185 case CommandFromMenuOrKeyBinding: | 185 case CommandFromMenuOrKeyBinding: |
| 186 frame.editor().applyParagraphStyleToSelection(style.get(), action); | 186 frame.editor().applyParagraphStyleToSelection(style.get(), action); |
| 187 return true; | 187 return true; |
| 188 case CommandFromDOM: | 188 case CommandFromDOM: |
| 189 frame.editor().applyParagraphStyle(style.get()); | 189 frame.editor().applyParagraphStyle(style.get()); |
| 190 return true; | 190 return true; |
| 191 } | 191 } |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 603 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro
pertyTextAlign, "left"); | 603 return executeApplyParagraphStyle(frame, source, EditActionAlignLeft, CSSPro
pertyTextAlign, "left"); |
| 604 } | 604 } |
| 605 | 605 |
| 606 static bool executeJustifyRight(LocalFrame& frame, Event*, EditorCommandSource s
ource, const String&) | 606 static bool executeJustifyRight(LocalFrame& frame, Event*, EditorCommandSource s
ource, const String&) |
| 607 { | 607 { |
| 608 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr
opertyTextAlign, "right"); | 608 return executeApplyParagraphStyle(frame, source, EditActionAlignRight, CSSPr
opertyTextAlign, "right"); |
| 609 } | 609 } |
| 610 | 610 |
| 611 static bool executeMakeTextWritingDirectionLeftToRight(LocalFrame& frame, Event*
, EditorCommandSource, const String&) | 611 static bool executeMakeTextWritingDirectionLeftToRight(LocalFrame& frame, Event*
, EditorCommandSource, const String&) |
| 612 { | 612 { |
| 613 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 613 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 614 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); | 614 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
| 615 style->setProperty(CSSPropertyDirection, CSSValueLtr); | 615 style->setProperty(CSSPropertyDirection, CSSValueLtr); |
| 616 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); | 616 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); |
| 617 return true; | 617 return true; |
| 618 } | 618 } |
| 619 | 619 |
| 620 static bool executeMakeTextWritingDirectionNatural(LocalFrame& frame, Event*, Ed
itorCommandSource, const String&) | 620 static bool executeMakeTextWritingDirectionNatural(LocalFrame& frame, Event*, Ed
itorCommandSource, const String&) |
| 621 { | 621 { |
| 622 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 622 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 623 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); | 623 style->setProperty(CSSPropertyUnicodeBidi, CSSValueNormal); |
| 624 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); | 624 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); |
| 625 return true; | 625 return true; |
| 626 } | 626 } |
| 627 | 627 |
| 628 static bool executeMakeTextWritingDirectionRightToLeft(LocalFrame& frame, Event*
, EditorCommandSource, const String&) | 628 static bool executeMakeTextWritingDirectionRightToLeft(LocalFrame& frame, Event*
, EditorCommandSource, const String&) |
| 629 { | 629 { |
| 630 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 630 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(HTMLQuirksMode); |
| 631 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); | 631 style->setProperty(CSSPropertyUnicodeBidi, CSSValueEmbed); |
| 632 style->setProperty(CSSPropertyDirection, CSSValueRtl); | 632 style->setProperty(CSSPropertyDirection, CSSValueRtl); |
| 633 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); | 633 frame.editor().applyStyle(style.get(), EditActionSetWritingDirection); |
| 634 return true; | 634 return true; |
| 635 } | 635 } |
| 636 | 636 |
| 637 static bool executeMoveBackward(LocalFrame& frame, Event*, EditorCommandSource,
const String&) | 637 static bool executeMoveBackward(LocalFrame& frame, Event*, EditorCommandSource,
const String&) |
| 638 { | 638 { |
| 639 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward,
CharacterGranularity, UserTriggered); | 639 frame.selection().modify(FrameSelection::AlterationMove, DirectionBackward,
CharacterGranularity, UserTriggered); |
| 640 return true; | 640 return true; |
| (...skipping 1150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1791 { | 1791 { |
| 1792 return m_command && m_command->isTextInsertion; | 1792 return m_command && m_command->isTextInsertion; |
| 1793 } | 1793 } |
| 1794 | 1794 |
| 1795 int Editor::Command::idForHistogram() const | 1795 int Editor::Command::idForHistogram() const |
| 1796 { | 1796 { |
| 1797 return isSupported() ? m_command->idForUserMetrics : 0; | 1797 return isSupported() ? m_command->idForUserMetrics : 0; |
| 1798 } | 1798 } |
| 1799 | 1799 |
| 1800 } // namespace blink | 1800 } // namespace blink |
| OLD | NEW |