1 /*
2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 #include "config.h"
27 #include "WebEditCommandProxy.h"
28
29 #include "WebPageMessages.h"
30 #include "WebPageProxy.h"
31 #include "WebProcessProxy.h"
32 #include <WebCore/LocalizedStrings.h>
33 #include <wtf/text/WTFString.h>
34
35 using namespace WebCore;
36
37 namespace WebKit {
38
WebEditCommandProxy(uint64_t commandID,WebCore::EditAction editAction,WebPageProxy * page)39 WebEditCommandProxy::WebEditCommandProxy(uint64_t commandID, WebCore::EditAction editAction, WebPageProxy* page)
40 : m_commandID(commandID)
41 , m_editAction(editAction)
42 , m_page(page)
43 {
44 m_page->addEditCommand(this);
45 }
46
~WebEditCommandProxy()47 WebEditCommandProxy::~WebEditCommandProxy()
48 {
49 if (m_page)
50 m_page->removeEditCommand(this);
51 }
52
unapply()53 void WebEditCommandProxy::unapply()
54 {
55 if (!m_page || !m_page->isValid())
56 return;
57
58 m_page->process()->send(Messages::WebPage::UnapplyEditCommand(m_commandID), m_page->pageID(), CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
59 m_page->registerEditCommand(this, WebPageProxy::Redo);
60 }
61
reapply()62 void WebEditCommandProxy::reapply()
63 {
64 if (!m_page || !m_page->isValid())
65 return;
66
67 m_page->process()->send(Messages::WebPage::ReapplyEditCommand(m_commandID), m_page->pageID(), CoreIPC::DispatchMessageEvenWhenWaitingForSyncReply);
68 m_page->registerEditCommand(this, WebPageProxy::Undo);
69 }
70
nameForEditAction(EditAction editAction)71 String WebEditCommandProxy::nameForEditAction(EditAction editAction)
72 {
73 switch (editAction) {
74 case EditActionUnspecified:
75 return String();
76 case EditActionSetColor:
77 return WEB_UI_STRING_KEY("Set Color", "Set Color (Undo action name)", "Undo action name");
78 case EditActionSetBackgroundColor:
79 return WEB_UI_STRING_KEY("Set Background Color", "Set Background Color (Undo action name)", "Undo action name");
80 case EditActionTurnOffKerning:
81 return WEB_UI_STRING_KEY("Turn Off Kerning", "Turn Off Kerning (Undo action name)", "Undo action name");
82 case EditActionTightenKerning:
83 return WEB_UI_STRING_KEY("Tighten Kerning", "Tighten Kerning (Undo action name)", "Undo action name");
84 case EditActionLoosenKerning:
85 return WEB_UI_STRING_KEY("Loosen Kerning", "Loosen Kerning (Undo action name)", "Undo action name");
86 case EditActionUseStandardKerning:
87 return WEB_UI_STRING_KEY("Use Standard Kerning", "Use Standard Kerning (Undo action name)", "Undo action name");
88 case EditActionTurnOffLigatures:
89 return WEB_UI_STRING_KEY("Turn Off Ligatures", "Turn Off Ligatures (Undo action name)", "Undo action name");
90 case EditActionUseStandardLigatures:
91 return WEB_UI_STRING_KEY("Use Standard Ligatures", "Use Standard Ligatures (Undo action name)", "Undo action name");
92 case EditActionUseAllLigatures:
93 return WEB_UI_STRING_KEY("Use All Ligatures", "Use All Ligatures (Undo action name)", "Undo action name");
94 case EditActionRaiseBaseline:
95 return WEB_UI_STRING_KEY("Raise Baseline", "Raise Baseline (Undo action name)", "Undo action name");
96 case EditActionLowerBaseline:
97 return WEB_UI_STRING_KEY("Lower Baseline", "Lower Baseline (Undo action name)", "Undo action name");
98 case EditActionSetTraditionalCharacterShape:
99 return WEB_UI_STRING_KEY("Set Traditional Character Shape", "Set Traditional Character Shape (Undo action name)", "Undo action name");
100 case EditActionSetFont:
101 return WEB_UI_STRING_KEY("Set Font", "Set Font (Undo action name)", "Undo action name");
102 case EditActionChangeAttributes:
103 return WEB_UI_STRING_KEY("Change Attributes", "Change Attributes (Undo action name)", "Undo action name");
104 case EditActionAlignLeft:
105 return WEB_UI_STRING_KEY("Align Left", "Align Left (Undo action name)", "Undo action name");
106 case EditActionAlignRight:
107 return WEB_UI_STRING_KEY("Align Right", "Align Right (Undo action name)", "Undo action name");
108 case EditActionCenter:
109 return WEB_UI_STRING_KEY("Center", "Center (Undo action name)", "Undo action name");
110 case EditActionJustify:
111 return WEB_UI_STRING_KEY("Justify", "Justify (Undo action name)", "Undo action name");
112 case EditActionSetWritingDirection:
113 return WEB_UI_STRING_KEY("Set Writing Direction", "Set Writing Direction (Undo action name)", "Undo action name");
114 case EditActionSubscript:
115 return WEB_UI_STRING_KEY("Subscript", "Subscript (Undo action name)", "Undo action name");
116 case EditActionSuperscript:
117 return WEB_UI_STRING_KEY("Superscript", "Superscript (Undo action name)", "Undo action name");
118 case EditActionUnderline:
119 return WEB_UI_STRING_KEY("Underline", "Underline (Undo action name)", "Undo action name");
120 case EditActionOutline:
121 return WEB_UI_STRING_KEY("Outline", "Outline (Undo action name)", "Undo action name");
122 case EditActionUnscript:
123 return WEB_UI_STRING_KEY("Unscript", "Unscript (Undo action name)", "Undo action name");
124 case EditActionDrag:
125 return WEB_UI_STRING_KEY("Drag", "Drag (Undo action name)", "Undo action name");
126 case EditActionCut:
127 return WEB_UI_STRING_KEY("Cut", "Cut (Undo action name)", "Undo action name");
128 case EditActionPaste:
129 return WEB_UI_STRING_KEY("Paste", "Paste (Undo action name)", "Undo action name");
130 case EditActionPasteFont:
131 return WEB_UI_STRING_KEY("Paste Font", "Paste Font (Undo action name)", "Undo action name");
132 case EditActionPasteRuler:
133 return WEB_UI_STRING_KEY("Paste Ruler", "Paste Ruler (Undo action name)", "Undo action name");
134 case EditActionTyping:
135 return WEB_UI_STRING_KEY("Typing", "Typing (Undo action name)", "Undo action name");
136 case EditActionCreateLink:
137 return WEB_UI_STRING_KEY("Create Link", "Create Link (Undo action name)", "Undo action name");
138 case EditActionUnlink:
139 return WEB_UI_STRING_KEY("Unlink", "Unlink (Undo action name)", "Undo action name");
140 case EditActionInsertList:
141 return WEB_UI_STRING_KEY("Insert List", "Insert List (Undo action name)", "Undo action name");
142 case EditActionFormatBlock:
143 return WEB_UI_STRING_KEY("Formatting", "Format Block (Undo action name)", "Undo action name");
144 case EditActionIndent:
145 return WEB_UI_STRING_KEY("Indent", "Indent (Undo action name)", "Undo action name");
146 case EditActionOutdent:
147 return WEB_UI_STRING_KEY("Outdent", "Outdent (Undo action name)", "Undo action name");
148 }
149 return String();
150 }
151
152 } // namespace WebKit
153