+2006-09-28 Alice Liu <alice.liu@apple.com>
+
+ Reviewed by Adam Roben.
+
+ This patch adds a command class that is attached to the frame so the frame can more easily execute commands such as copy, paste, select, etc.
+ This patch also exposes some UBRK-related utilities so that they can be used elsewhere.
+ This patch also changes windows PlatformMouseEvent so that we can detect multiple-click mouse events
+
+ * editing/CommandByName.cpp: Added.
+ Added a command class that hangs off the frame so the frame can call commands more easily.
+ (WebCore::Frame::commandImp):
+ (WebCore::Frame::execCopy):
+ (WebCore::Frame::execCut):
+ (WebCore::Frame::execDelete):
+ (WebCore::Frame::execForwardDelete):
+ (WebCore::Frame::execPaste):
+ (WebCore::Frame::execMoveLeft):
+ (WebCore::Frame::execMoveRight):
+ (WebCore::Frame::execMoveUp):
+ (WebCore::Frame::execMoveDown):
+ (WebCore::Frame::execSelectAll):
+ (WebCore::Frame::execSelectLeft):
+ (WebCore::Frame::execSelectRight):
+ (WebCore::Frame::execSelectUp):
+ (WebCore::Frame::execSelectDown):
+ (WebCore::Frame::enabled):
+ (WebCore::Frame::enabledAnySelection):
+ (WebCore::Frame::enabledAnyEditableSelection):
+ (WebCore::Frame::enabledPaste):
+ (WebCore::Frame::enabledAnyRangeSelection):
+ (WebCore::Frame::enabledAnyEditableRangeSelection):
+ (WebCore::Frame::createCommandDictionary):
+ (WebCore::Frame::Command::):
+ (WebCore:::m_frame):
+ (WebCore::CommandByName::execCommand):
+ * editing/CommandByName.h: Added.
+ * page/Frame.cpp:
+ Added implementation of accessor for CommandByName member
+ (WebCore::Frame::command):
+ * page/Frame.h:
+ Added accessor for CommandByName member
+ * page/FramePrivate.h:
+ Added a CommandByName member
+ (WebCore::FramePrivate::FramePrivate):
+ * platform/PlatformMouseEvent.h:
+ Changed constructor prototype
+ * platform/StringImpl.cpp:
+ Exposing getWordBreakIterator to be used elsewhere
+ (WebCore::getWordBreakIterator):
+ * platform/StringImpl.h:
+ Exposing getWordBreakIterator to be used elsewhere
+ * platform/win/MouseEventWin.cpp:
+ Changed the PlatformMouseEvent on windows so that we "roll our own" multi-click mouse events instead of relying on the system to tell us, enabling us to detect triple-clicks
+ (WebCore::PlatformMouseEvent::PlatformMouseEvent):
+
2006-09-28 Adam Roben <aroben@apple.com>
Reviewed by Adele.
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CommandByName.h"
+
+#include <wtf/HashMap.h>
+#include "Document.h"
+#include "Frame.h"
+#include "PlatformString.h"
+#include "SelectionController.h"
+#include "StringHash.h"
+#include "TypingCommand.h"
+
+namespace WebCore {
+
+class Frame;
+
+namespace {
+//FIXME: there's a setter for this. Bring it in later when we need it
+bool supportsPasteCommand = false;
+
+struct CommandImp {
+ bool (*execFn)(Frame* frame);
+ bool (*enabledFn)(Frame* frame);
+};
+
+typedef HashMap<StringImpl*, const CommandImp*, CaseInsensitiveHash> CommandMap;
+
+CommandMap* createCommandDictionary();
+
+const CommandImp* commandImp(const String& command)
+{
+ static CommandMap* commandDictionary = createCommandDictionary();
+ return commandDictionary->get(command.impl());
+}
+
+// ============================================================================
+//
+// execCommand function implementations
+//
+
+bool execCopy(Frame* frame)
+{
+ frame->copyToPasteboard();
+ return true;
+}
+
+bool execCut(Frame* frame)
+{
+ frame->cutToPasteboard();
+ return true;
+}
+
+bool execDelete(Frame* frame)
+{
+ TypingCommand::deleteKeyPressed(frame->document(), frame->selectionGranularity() == WordGranularity);
+ return true;
+}
+
+bool execForwardDelete(Frame* frame)
+{
+ TypingCommand::forwardDeleteKeyPressed(frame->document());
+ return true;
+}
+
+bool execPaste(Frame* frame)
+{
+ frame->pasteFromPasteboard();
+ return true;
+}
+
+bool execMoveLeft(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::MOVE, SelectionController::LEFT, CharacterGranularity, true);
+ return true;
+}
+
+bool execMoveRight(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::MOVE, SelectionController::RIGHT, CharacterGranularity, true);
+ return true;
+}
+
+bool execMoveUp(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::MOVE, SelectionController::BACKWARD, LineGranularity, true);
+ return true;
+}
+
+bool execMoveDown(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::MOVE, SelectionController::FORWARD, LineGranularity, true);
+ return true;
+}
+
+bool execSelectAll(Frame* frame)
+{
+ frame->selectAll();
+ return true;
+}
+
+bool execSelectLeft(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::LEFT, CharacterGranularity, true);
+ return true;
+}
+
+bool execSelectRight(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::RIGHT, CharacterGranularity, true);
+ return true;
+}
+
+bool execSelectUp(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::BACKWARD, LineGranularity, true);
+ return true;
+}
+
+bool execSelectDown(Frame* frame)
+{
+ frame->selectionController()->modify(SelectionController::EXTEND, SelectionController::FORWARD, LineGranularity, true);
+ return true;
+}
+
+// ============================================================================
+//
+// enabled functions implementations
+//
+
+bool enabled(Frame*)
+{
+ return true;
+}
+
+bool enabledAnySelection(Frame* frame)
+{
+ return frame->selectionController()->isCaretOrRange();
+}
+
+bool enabledAnyEditableSelection(Frame* frame)
+{
+ return frame->selectionController()->isCaretOrRange() && frame->selectionController()->isContentEditable();
+}
+
+bool enabledPaste(Frame* frame)
+{
+ return supportsPasteCommand && frame->canPaste();
+}
+
+bool enabledAnyRangeSelection(Frame* frame)
+{
+ return frame->selectionController()->isRange();
+}
+
+bool enabledAnyEditableRangeSelection(Frame* frame)
+{
+ return frame->selectionController()->isRange() && frame->selectionController()->isContentEditable();
+}
+
+CommandMap* createCommandDictionary()
+{
+ struct Command { const char* name; CommandImp imp; };
+
+ static const Command commands[] = {
+ { "Copy", { execCopy, enabledAnyRangeSelection } },
+ { "Cut", { execCut, enabledAnyEditableRangeSelection } },
+ { "Delete", { execDelete, enabledAnyEditableSelection } },
+ { "ForwardDelete", { execForwardDelete, enabledAnyEditableSelection } },
+ { "Paste", { execPaste, enabledPaste } },
+ { "SelectAll", { execSelectAll, enabled } },
+ // FIXME: not sure if the following 8 should be enabledAnyRangeSelection or enabledAnySelection
+ { "MoveLeft", { execMoveLeft, enabledAnyRangeSelection } },
+ { "MoveRight", { execMoveRight, enabledAnyRangeSelection } },
+ { "MoveUp", { execMoveUp, enabledAnyRangeSelection } },
+ { "MoveDown", { execMoveDown, enabledAnyRangeSelection } },
+ { "SelectLeft", { execSelectLeft, enabledAnyRangeSelection } },
+ { "SelectRight", { execSelectRight, enabledAnyRangeSelection } },
+ { "SelectUp", { execSelectUp, enabledAnyRangeSelection } },
+ { "SelectDown", { execSelectDown, enabledAnyRangeSelection } }
+ };
+
+ CommandMap* commandMap = new CommandMap;
+
+ const int numCommands = sizeof(commands) / sizeof(commands[0]);
+ for (int i = 0; i < numCommands; ++i) {
+ StringImpl *name = new StringImpl(commands[i].name);
+ name->ref();
+ commandMap->set(name, &commands[i].imp);
+ }
+
+ return commandMap;
+}
+
+} // anonymous namespace
+
+CommandByName::CommandByName(Frame* frame)
+ : m_frame(frame)
+{
+}
+
+const bool CommandByName::execCommand(const String& command)
+{
+ bool handled = false;
+ const CommandImp* cmd = commandImp(command);
+ if (!cmd)
+ return false;
+ if (!m_frame)
+ return false;
+ if (cmd->enabledFn(m_frame)) {
+ m_frame->document()->updateLayoutIgnorePendingStylesheets();
+ handled = cmd->execFn(m_frame);
+ }
+ return handled;
+}
+
+} // namespace WebCore
--- /dev/null
+/*
+ * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef command_by_name_h__
+#define command_by_name_h__
+
+namespace WebCore {
+
+class Frame;
+class String;
+
+class CommandByName {
+public:
+ CommandByName(Frame* frame);
+ const bool execCommand(const String& command);
+
+private:
+ Frame* m_frame;
+};
+
+} // namespace WebCore
+
+#endif // command_by_name_h__