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 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
103 } | 103 } |
104 | 104 |
105 static bool applyCommandToFrame(LocalFrame& frame, EditorCommandSource source, E
ditAction action, StylePropertySet* style) | 105 static bool applyCommandToFrame(LocalFrame& frame, EditorCommandSource source, E
ditAction action, StylePropertySet* style) |
106 { | 106 { |
107 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? | 107 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? |
108 switch (source) { | 108 switch (source) { |
109 case CommandFromMenuOrKeyBinding: | 109 case CommandFromMenuOrKeyBinding: |
110 frame.editor().applyStyleToSelection(style, action); | 110 frame.editor().applyStyleToSelection(style, action); |
111 return true; | 111 return true; |
112 case CommandFromDOM: | 112 case CommandFromDOM: |
113 case CommandFromDOMWithUserInterface: | |
114 frame.editor().applyStyle(style); | 113 frame.editor().applyStyle(style); |
115 return true; | 114 return true; |
116 } | 115 } |
117 ASSERT_NOT_REACHED(); | 116 ASSERT_NOT_REACHED(); |
118 return false; | 117 return false; |
119 } | 118 } |
120 | 119 |
121 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) | 120 static bool executeApplyStyle(LocalFrame& frame, EditorCommandSource source, Edi
tAction action, CSSPropertyID propertyID, const String& propertyValue) |
122 { | 121 { |
123 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 122 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
178 static bool executeApplyParagraphStyle(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) | 177 static bool executeApplyParagraphStyle(LocalFrame& frame, EditorCommandSource so
urce, EditAction action, CSSPropertyID propertyID, const String& propertyValue) |
179 { | 178 { |
180 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); | 179 RefPtrWillBeRawPtr<MutableStylePropertySet> style = MutableStylePropertySet:
:create(); |
181 style->setProperty(propertyID, propertyValue); | 180 style->setProperty(propertyID, propertyValue); |
182 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? | 181 // FIXME: We don't call shouldApplyStyle when the source is DOM; is there a
good reason for that? |
183 switch (source) { | 182 switch (source) { |
184 case CommandFromMenuOrKeyBinding: | 183 case CommandFromMenuOrKeyBinding: |
185 frame.editor().applyParagraphStyleToSelection(style.get(), action); | 184 frame.editor().applyParagraphStyleToSelection(style.get(), action); |
186 return true; | 185 return true; |
187 case CommandFromDOM: | 186 case CommandFromDOM: |
188 case CommandFromDOMWithUserInterface: | |
189 frame.editor().applyParagraphStyle(style.get()); | 187 frame.editor().applyParagraphStyle(style.get()); |
190 return true; | 188 return true; |
191 } | 189 } |
192 ASSERT_NOT_REACHED(); | 190 ASSERT_NOT_REACHED(); |
193 return false; | 191 return false; |
194 } | 192 } |
195 | 193 |
196 static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu
mentFragment> fragment) | 194 static bool executeInsertFragment(LocalFrame& frame, PassRefPtrWillBeRawPtr<Docu
mentFragment> fragment) |
197 { | 195 { |
198 ASSERT(frame.document()); | 196 ASSERT(frame.document()); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 } | 295 } |
298 | 296 |
299 static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource, const St
ring&) | 297 static bool executeCopy(LocalFrame& frame, Event*, EditorCommandSource, const St
ring&) |
300 { | 298 { |
301 frame.editor().copy(); | 299 frame.editor().copy(); |
302 return true; | 300 return true; |
303 } | 301 } |
304 | 302 |
305 static bool executeCreateLink(LocalFrame& frame, Event*, EditorCommandSource, co
nst String& value) | 303 static bool executeCreateLink(LocalFrame& frame, Event*, EditorCommandSource, co
nst String& value) |
306 { | 304 { |
307 // FIXME: If userInterface is true, we should display a dialog box to let th
e user enter a URL. | |
308 if (value.isEmpty()) | 305 if (value.isEmpty()) |
309 return false; | 306 return false; |
310 ASSERT(frame.document()); | 307 ASSERT(frame.document()); |
311 CreateLinkCommand::create(*frame.document(), value)->apply(); | 308 CreateLinkCommand::create(*frame.document(), value)->apply(); |
312 return true; | 309 return true; |
313 } | 310 } |
314 | 311 |
315 static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource, const Str
ing&) | 312 static bool executeCut(LocalFrame& frame, Event*, EditorCommandSource, const Str
ing&) |
316 { | 313 { |
317 frame.editor().cut(); | 314 frame.editor().cut(); |
(...skipping 12 matching lines...) Expand all Loading... |
330 | 327 |
331 static bool executeDelete(LocalFrame& frame, Event*, EditorCommandSource source,
const String&) | 328 static bool executeDelete(LocalFrame& frame, Event*, EditorCommandSource source,
const String&) |
332 { | 329 { |
333 switch (source) { | 330 switch (source) { |
334 case CommandFromMenuOrKeyBinding: { | 331 case CommandFromMenuOrKeyBinding: { |
335 // Doesn't modify the text if the current selection isn't a range. | 332 // Doesn't modify the text if the current selection isn't a range. |
336 frame.editor().performDelete(); | 333 frame.editor().performDelete(); |
337 return true; | 334 return true; |
338 } | 335 } |
339 case CommandFromDOM: | 336 case CommandFromDOM: |
340 case CommandFromDOMWithUserInterface: | |
341 // If the current selection is a caret, delete the preceding character.
IE performs forwardDelete, but we currently side with Firefox. | 337 // If the current selection is a caret, delete the preceding character.
IE performs forwardDelete, but we currently side with Firefox. |
342 // Doesn't scroll to make the selection visible, or modify the kill ring
(this time, siding with IE, not Firefox). | 338 // Doesn't scroll to make the selection visible, or modify the kill ring
(this time, siding with IE, not Firefox). |
343 ASSERT(frame.document()); | 339 ASSERT(frame.document()); |
344 TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().gra
nularity() == WordGranularity ? TypingCommand::SmartDelete : 0); | 340 TypingCommand::deleteKeyPressed(*frame.document(), frame.selection().gra
nularity() == WordGranularity ? TypingCommand::SmartDelete : 0); |
345 return true; | 341 return true; |
346 } | 342 } |
347 ASSERT_NOT_REACHED(); | 343 ASSERT_NOT_REACHED(); |
348 return false; | 344 return false; |
349 } | 345 } |
350 | 346 |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
466 return command->didApply(); | 462 return command->didApply(); |
467 } | 463 } |
468 | 464 |
469 static bool executeForwardDelete(LocalFrame& frame, Event*, EditorCommandSource
source, const String&) | 465 static bool executeForwardDelete(LocalFrame& frame, Event*, EditorCommandSource
source, const String&) |
470 { | 466 { |
471 switch (source) { | 467 switch (source) { |
472 case CommandFromMenuOrKeyBinding: | 468 case CommandFromMenuOrKeyBinding: |
473 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularit
y, false, true); | 469 frame.editor().deleteWithDirection(DirectionForward, CharacterGranularit
y, false, true); |
474 return true; | 470 return true; |
475 case CommandFromDOM: | 471 case CommandFromDOM: |
476 case CommandFromDOMWithUserInterface: | |
477 // Doesn't scroll to make the selection visible, or modify the kill ring
. | 472 // Doesn't scroll to make the selection visible, or modify the kill ring
. |
478 // ForwardDelete is not implemented in IE or Firefox, so this behavior i
s only needed for | 473 // ForwardDelete is not implemented in IE or Firefox, so this behavior i
s only needed for |
479 // backward compatibility with ourselves, and for consistency with Delet
e. | 474 // backward compatibility with ourselves, and for consistency with Delet
e. |
480 ASSERT(frame.document()); | 475 ASSERT(frame.document()); |
481 TypingCommand::forwardDeleteKeyPressed(*frame.document()); | 476 TypingCommand::forwardDeleteKeyPressed(*frame.document()); |
482 return true; | 477 return true; |
483 } | 478 } |
484 ASSERT_NOT_REACHED(); | 479 ASSERT_NOT_REACHED(); |
485 return false; | 480 return false; |
486 } | 481 } |
(...skipping 26 matching lines...) Expand all Loading... |
513 } | 508 } |
514 | 509 |
515 static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, co
nst String& value) | 510 static bool executeInsertHTML(LocalFrame& frame, Event*, EditorCommandSource, co
nst String& value) |
516 { | 511 { |
517 ASSERT(frame.document()); | 512 ASSERT(frame.document()); |
518 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document
(), value, "")); | 513 return executeInsertFragment(frame, createFragmentFromMarkup(*frame.document
(), value, "")); |
519 } | 514 } |
520 | 515 |
521 static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c
onst String& value) | 516 static bool executeInsertImage(LocalFrame& frame, Event*, EditorCommandSource, c
onst String& value) |
522 { | 517 { |
523 // FIXME: If userInterface is true, we should display a dialog box and let t
he user choose a local image. | |
524 ASSERT(frame.document()); | 518 ASSERT(frame.document()); |
525 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame
.document()); | 519 RefPtrWillBeRawPtr<HTMLImageElement> image = HTMLImageElement::create(*frame
.document()); |
526 image->setSrc(value); | 520 image->setSrc(value); |
527 return executeInsertElement(frame, image.release()); | 521 return executeInsertElement(frame, image.release()); |
528 } | 522 } |
529 | 523 |
530 static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorComman
dSource source, const String&) | 524 static bool executeInsertLineBreak(LocalFrame& frame, Event* event, EditorComman
dSource source, const String&) |
531 { | 525 { |
532 switch (source) { | 526 switch (source) { |
533 case CommandFromMenuOrKeyBinding: | 527 case CommandFromMenuOrKeyBinding: |
534 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\
n", event, TextEventInputLineBreak); | 528 return targetFrame(frame, event)->eventHandler().handleTextInputEvent("\
n", event, TextEventInputLineBreak); |
535 case CommandFromDOM: | 529 case CommandFromDOM: |
536 case CommandFromDOMWithUserInterface: | |
537 // Doesn't scroll to make the selection visible, or modify the kill ring
. | 530 // Doesn't scroll to make the selection visible, or modify the kill ring
. |
538 // InsertLineBreak is not implemented in IE or Firefox, so this behavior
is only needed for | 531 // InsertLineBreak is not implemented in IE or Firefox, so this behavior
is only needed for |
539 // backward compatibility with ourselves, and for consistency with other
commands. | 532 // backward compatibility with ourselves, and for consistency with other
commands. |
540 ASSERT(frame.document()); | 533 ASSERT(frame.document()); |
541 TypingCommand::insertLineBreak(*frame.document(), 0); | 534 TypingCommand::insertLineBreak(*frame.document(), 0); |
542 return true; | 535 return true; |
543 } | 536 } |
544 ASSERT_NOT_REACHED(); | 537 ASSERT_NOT_REACHED(); |
545 return false; | 538 return false; |
546 } | 539 } |
(...skipping 702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1249 { | 1242 { |
1250 return frame.editor().selectionForCommand(event).rootEditableElement(); | 1243 return frame.editor().selectionForCommand(event).rootEditableElement(); |
1251 } | 1244 } |
1252 | 1245 |
1253 static bool enabledDelete(LocalFrame& frame, Event* event, EditorCommandSource s
ource) | 1246 static bool enabledDelete(LocalFrame& frame, Event* event, EditorCommandSource s
ource) |
1254 { | 1247 { |
1255 switch (source) { | 1248 switch (source) { |
1256 case CommandFromMenuOrKeyBinding: | 1249 case CommandFromMenuOrKeyBinding: |
1257 return frame.editor().canDelete(); | 1250 return frame.editor().canDelete(); |
1258 case CommandFromDOM: | 1251 case CommandFromDOM: |
1259 case CommandFromDOMWithUserInterface: | |
1260 // "Delete" from DOM is like delete/backspace keypress, affects selected
range if non-empty, | 1252 // "Delete" from DOM is like delete/backspace keypress, affects selected
range if non-empty, |
1261 // otherwise removes a character | 1253 // otherwise removes a character |
1262 return enabledInEditableText(frame, event, source); | 1254 return enabledInEditableText(frame, event, source); |
1263 } | 1255 } |
1264 ASSERT_NOT_REACHED(); | 1256 ASSERT_NOT_REACHED(); |
1265 return false; | 1257 return false; |
1266 } | 1258 } |
1267 | 1259 |
1268 static bool enabledInEditableTextOrCaretBrowsing(LocalFrame& frame, Event* event
, EditorCommandSource) | 1260 static bool enabledInEditableTextOrCaretBrowsing(LocalFrame& frame, Event* event
, EditorCommandSource) |
1269 { | 1261 { |
(...skipping 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1753 } | 1745 } |
1754 | 1746 |
1755 bool Editor::Command::isSupported() const | 1747 bool Editor::Command::isSupported() const |
1756 { | 1748 { |
1757 if (!m_command) | 1749 if (!m_command) |
1758 return false; | 1750 return false; |
1759 switch (m_source) { | 1751 switch (m_source) { |
1760 case CommandFromMenuOrKeyBinding: | 1752 case CommandFromMenuOrKeyBinding: |
1761 return true; | 1753 return true; |
1762 case CommandFromDOM: | 1754 case CommandFromDOM: |
1763 case CommandFromDOMWithUserInterface: | |
1764 return m_command->isSupportedFromDOM(m_frame.get()); | 1755 return m_command->isSupportedFromDOM(m_frame.get()); |
1765 } | 1756 } |
1766 ASSERT_NOT_REACHED(); | 1757 ASSERT_NOT_REACHED(); |
1767 return false; | 1758 return false; |
1768 } | 1759 } |
1769 | 1760 |
1770 bool Editor::Command::isEnabled(Event* triggeringEvent) const | 1761 bool Editor::Command::isEnabled(Event* triggeringEvent) const |
1771 { | 1762 { |
1772 if (!isSupported() || !m_frame) | 1763 if (!isSupported() || !m_frame) |
1773 return false; | 1764 return false; |
(...skipping 20 matching lines...) Expand all Loading... |
1794 { | 1785 { |
1795 return m_command && m_command->isTextInsertion; | 1786 return m_command && m_command->isTextInsertion; |
1796 } | 1787 } |
1797 | 1788 |
1798 int Editor::Command::idForHistogram() const | 1789 int Editor::Command::idForHistogram() const |
1799 { | 1790 { |
1800 return isSupported() ? m_command->idForUserMetrics : 0; | 1791 return isSupported() ? m_command->idForUserMetrics : 0; |
1801 } | 1792 } |
1802 | 1793 |
1803 } // namespace blink | 1794 } // namespace blink |
OLD | NEW |