Commit 5a38d268 authored by yosin@chromium.org's avatar yosin@chromium.org

Move implementation of WebFrameImpl::executeCommand to Editor

This patch moves |WebFrameImpl::executeComamnd()| to |Editor| class to make
"web" as thin API layer and ease of maintenance.

This patch also get rid of |WebViewImpl::bubblingScroll|, which
becomes unused function as result of moving |WebFrameImpl::executeCommand()|.

BUG=n/a
TEST=n/a; no behavior changes

Review URL: https://codereview.chromium.org/337473010

git-svn-id: svn://svn.chromium.org/blink/trunk@177179 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent c60a0590
...@@ -155,6 +155,11 @@ public: ...@@ -155,6 +155,11 @@ public:
Command command(const String& commandName); // Command source is CommandFromMenuOrKeyBinding. Command command(const String& commandName); // Command source is CommandFromMenuOrKeyBinding.
Command command(const String& commandName, EditorCommandSource); Command command(const String& commandName, EditorCommandSource);
// |Editor::executeCommand| is implementation of |WebFrame::executeCommand|
// rather than |Document::execCommand|.
bool executeCommand(const String&);
bool executeCommand(const String& commandName, const String& value);
bool insertText(const String&, Event* triggeringEvent); bool insertText(const String&, Event* triggeringEvent);
bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, TextEvent* triggeringEvent); bool insertTextWithoutSendingTextEvent(const String&, bool selectInsertedText, TextEvent* triggeringEvent);
bool insertLineBreak(); bool insertLineBreak();
......
...@@ -1675,6 +1675,48 @@ Editor::Command Editor::command(const String& commandName, EditorCommandSource s ...@@ -1675,6 +1675,48 @@ Editor::Command Editor::command(const String& commandName, EditorCommandSource s
return Command(internalCommand(commandName), source, &m_frame); return Command(internalCommand(commandName), source, &m_frame);
} }
bool Editor::executeCommand(const String& commandName)
{
// Specially handling commands that Editor::execCommand does not directly
// support.
if (commandName == "DeleteToEndOfParagraph") {
if (!deleteWithDirection(DirectionForward, ParagraphBoundary, true, false))
deleteWithDirection(DirectionForward, CharacterGranularity, true, false);
return true;
}
if (commandName == "DeleteBackward")
return command(AtomicString("BackwardDelete")).execute();
if (commandName == "DeleteForward")
return command(AtomicString("ForwardDelete")).execute();
if (commandName == "AdvanceToNextMisspelling") {
// Wee need to pass false here or else the currently selected word will never be skipped.
spellChecker().advanceToNextMisspelling(false);
return true;
}
if (commandName == "ToggleSpellPanel") {
spellChecker().showSpellingGuessPanel();
return true;
}
return command(commandName).execute();
}
bool Editor::executeCommand(const String& commandName, const String& value)
{
// moveToBeginningOfDocument and moveToEndfDocument are only handled by WebKit for editable nodes.
if (!canEdit() && commandName == "moveToBeginningOfDocument")
return m_frame.eventHandler().bubblingScroll(ScrollUp, ScrollByDocument);
if (!canEdit() && commandName == "moveToEndOfDocument")
return m_frame.eventHandler().bubblingScroll(ScrollDown, ScrollByDocument);
if (commandName == "showGuessPanel") {
spellChecker().showSpellingGuessPanel();
return true;
}
return command(commandName).execute(value);
}
Editor::Command::Command() Editor::Command::Command()
: m_command(0) : m_command(0)
{ {
......
...@@ -1051,50 +1051,18 @@ bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebNode& nod ...@@ -1051,50 +1051,18 @@ bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebNode& nod
if (pluginContainer && pluginContainer->executeEditCommand(name)) if (pluginContainer && pluginContainer->executeEditCommand(name))
return true; return true;
bool result = true; return frame()->editor().executeCommand(command);
// Specially handling commands that Editor::execCommand does not directly
// support.
if (command == "DeleteToEndOfParagraph") {
if (!frame()->editor().deleteWithDirection(DirectionForward, ParagraphBoundary, true, false))
frame()->editor().deleteWithDirection(DirectionForward, CharacterGranularity, true, false);
} else if (command == "DeleteBackward") {
result = frame()->editor().command(AtomicString("BackwardDelete")).execute();
} else if (command == "DeleteForward") {
result = frame()->editor().command(AtomicString("ForwardDelete")).execute();
} else if (command == "AdvanceToNextMisspelling") {
// Wee need to pass false here or else the currently selected word will never be skipped.
frame()->spellChecker().advanceToNextMisspelling(false);
} else if (command == "ToggleSpellPanel") {
frame()->spellChecker().showSpellingGuessPanel();
} else {
result = frame()->editor().command(command).execute();
}
return result;
} }
bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebString& value, const WebNode& node) bool WebLocalFrameImpl::executeCommand(const WebString& name, const WebString& value, const WebNode& node)
{ {
ASSERT(frame()); ASSERT(frame());
String webName = name;
WebPluginContainerImpl* pluginContainer = pluginContainerFromNode(frame(), node); WebPluginContainerImpl* pluginContainer = pluginContainerFromNode(frame(), node);
if (pluginContainer && pluginContainer->executeEditCommand(name, value)) if (pluginContainer && pluginContainer->executeEditCommand(name, value))
return true; return true;
// moveToBeginningOfDocument and moveToEndfDocument are only handled by WebKit for editable nodes. return frame()->editor().executeCommand(name, value);
if (!frame()->editor().canEdit() && webName == "moveToBeginningOfDocument")
return viewImpl()->bubblingScroll(ScrollUp, ScrollByDocument);
if (!frame()->editor().canEdit() && webName == "moveToEndOfDocument")
return viewImpl()->bubblingScroll(ScrollDown, ScrollByDocument);
if (webName == "showGuessPanel") {
frame()->spellChecker().showSpellingGuessPanel();
return true;
}
return frame()->editor().command(webName).execute(value);
} }
bool WebLocalFrameImpl::isCommandEnabled(const WebString& name) const bool WebLocalFrameImpl::isCommandEnabled(const WebString& name) const
......
...@@ -1412,7 +1412,11 @@ bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers) ...@@ -1412,7 +1412,11 @@ bool WebViewImpl::scrollViewWithKeyboard(int keyCode, int modifiers)
#endif #endif
if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity)) if (!mapKeyCodeForScroll(keyCode, &scrollDirection, &scrollGranularity))
return false; return false;
return bubblingScroll(scrollDirection, scrollGranularity);
LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
if (!frame)
return false;
return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranularity);
} }
bool WebViewImpl::mapKeyCodeForScroll(int keyCode, bool WebViewImpl::mapKeyCodeForScroll(int keyCode,
...@@ -1465,15 +1469,6 @@ void WebViewImpl::hideSelectPopup() ...@@ -1465,15 +1469,6 @@ void WebViewImpl::hideSelectPopup()
m_selectPopup->hidePopup(); m_selectPopup->hidePopup();
} }
bool WebViewImpl::bubblingScroll(ScrollDirection scrollDirection, ScrollGranularity scrollGranularity)
{
LocalFrame* frame = toLocalFrame(focusedWebCoreFrame());
if (!frame)
return false;
return frame->eventHandler().bubblingScroll(scrollDirection, scrollGranularity);
}
void WebViewImpl::popupOpened(PopupContainer* popupContainer) void WebViewImpl::popupOpened(PopupContainer* popupContainer)
{ {
ASSERT(!m_selectPopup); ASSERT(!m_selectPopup);
......
...@@ -386,10 +386,6 @@ public: ...@@ -386,10 +386,6 @@ public:
const WebImage& dragImage, const WebImage& dragImage,
const WebPoint& dragImageOffset); const WebPoint& dragImageOffset);
// Tries to scroll the currently focused element and bubbles up through the
// DOM and frame hierarchies. Returns true if something was scrolled.
bool bubblingScroll(WebCore::ScrollDirection, WebCore::ScrollGranularity);
// Notification that a popup was opened/closed. // Notification that a popup was opened/closed.
void popupOpened(PopupContainer*); void popupOpened(PopupContainer*);
void popupClosed(PopupContainer*); void popupClosed(PopupContainer*);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment