Inspector: Introduce Input.dispatchKeyEvent and DOM.focus for typing simulation.
authorcommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2012 18:04:21 +0000 (18:04 +0000)
committercommit-queue@webkit.org <commit-queue@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 4 Dec 2012 18:04:21 +0000 (18:04 +0000)
https://bugs.webkit.org/show_bug.cgi?id=103530

Patch by Ken Kania <kkania@chromium.org> on 2012-12-04
Reviewed by Yury Semikhatsky.

Input.dispatchKeyEvent simply calls EventHandler::keyEvent with the key event data
from the command parameters. The client will be responsible for providing proper
events to simulate desired typing behavior.
DOM.focus calls focus on a dom element.

Source/WebCore:

Tests: inspector-protocol/dom-focus.html
       inspector-protocol/input-dispatchKeyEvent.html

* CMakeLists.txt:
* GNUmakefile.list.am:
* Target.pri:
* WebCore.gypi:
* WebCore.vcproj/WebCore.vcproj:
* WebCore.xcodeproj/project.pbxproj:
* inspector/Inspector.json:
* inspector/InspectorAllInOne.cpp:
* inspector/InspectorController.cpp:
(WebCore::InspectorController::InspectorController):
* inspector/InspectorDOMAgent.cpp:
(WebCore::InspectorDOMAgent::focus):
(WebCore):
(WebCore::InspectorDOMAgent::resolveNode):
* inspector/InspectorDOMAgent.h:
(InspectorDOMAgent):
* inspector/InspectorInputAgent.cpp: Added.
(WebCore):
(WebCore::InspectorInputAgent::InspectorInputAgent):
(WebCore::InspectorInputAgent::~InspectorInputAgent):
(WebCore::InspectorInputAgent::dispatchKeyEvent):
* inspector/InspectorInputAgent.h: Added.
(WebCore):
(InspectorInputAgent):
(WebCore::InspectorInputAgent::create):

LayoutTests:

* inspector-protocol/dom-focus-expected.txt: Added.
* inspector-protocol/dom-focus.html: Added.
* inspector-protocol/input/dispatchKeyEvent-expected.txt: Added.
* inspector-protocol/input/dispatchKeyEvent.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@136521 268f45cc-cd09-0410-ab3c-d52691b4dbfc

19 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector-protocol/dom-focus-expected.txt [new file with mode: 0644]
LayoutTests/inspector-protocol/dom-focus.html [new file with mode: 0644]
LayoutTests/inspector-protocol/input/dispatchKeyEvent-expected.txt [new file with mode: 0644]
LayoutTests/inspector-protocol/input/dispatchKeyEvent.html [new file with mode: 0644]
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/GNUmakefile.list.am
Source/WebCore/Target.pri
Source/WebCore/WebCore.gypi
Source/WebCore/WebCore.vcproj/WebCore.vcproj
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/inspector/Inspector.json
Source/WebCore/inspector/InspectorAllInOne.cpp
Source/WebCore/inspector/InspectorController.cpp
Source/WebCore/inspector/InspectorDOMAgent.cpp
Source/WebCore/inspector/InspectorDOMAgent.h
Source/WebCore/inspector/InspectorInputAgent.cpp [new file with mode: 0644]
Source/WebCore/inspector/InspectorInputAgent.h [new file with mode: 0644]

index 3530816..8fa0768 100644 (file)
@@ -1,3 +1,20 @@
+2012-12-04  Ken Kania  <kkania@chromium.org>
+
+        Inspector: Introduce Input.dispatchKeyEvent and DOM.focus for typing simulation.
+        https://bugs.webkit.org/show_bug.cgi?id=103530
+
+        Reviewed by Yury Semikhatsky.
+
+        Input.dispatchKeyEvent simply calls EventHandler::keyEvent with the key event data
+        from the command parameters. The client will be responsible for providing proper
+        events to simulate desired typing behavior.
+        DOM.focus calls focus on a dom element.
+
+        * inspector-protocol/dom-focus-expected.txt: Added.
+        * inspector-protocol/dom-focus.html: Added.
+        * inspector-protocol/input/dispatchKeyEvent-expected.txt: Added.
+        * inspector-protocol/input/dispatchKeyEvent.html: Added.
+
 2012-12-04  Emil A Eklund  <eae@chromium.org>
 
         Unreviewed mathml rebaseline.
diff --git a/LayoutTests/inspector-protocol/dom-focus-expected.txt b/LayoutTests/inspector-protocol/dom-focus-expected.txt
new file mode 100644 (file)
index 0000000..207b5c2
--- /dev/null
@@ -0,0 +1,3 @@
+focused
+
diff --git a/LayoutTests/inspector-protocol/dom-focus.html b/LayoutTests/inspector-protocol/dom-focus.html
new file mode 100644 (file)
index 0000000..787b54d
--- /dev/null
@@ -0,0 +1,51 @@
+<html>
+<head>
+<script type="text/javascript" src="../http/tests/inspector-protocol/resources/protocol-test.js"></script>
+<script>
+
+window.addEventListener("load", function() {
+    document.querySelector("#second").addEventListener("focus", onFocus);
+
+    function onFocus() {
+        log("focused");
+    }
+});
+
+function test()
+{
+    InspectorTest.sendCommand("DOM.getDocument", {}, onGotDocument);
+
+    function onGotDocument(msg) {
+        if (msg.error) {
+            InspectorTest.log(msg.error.message);
+            InspectorTest.completeTest();
+            return;
+        }
+        var node = msg.result.root;
+        InspectorTest.sendCommand("DOM.querySelector", { "nodeId": node.nodeId, "selector": "#second" }, onQuerySelector);
+    }
+
+    function onQuerySelector(msg) {
+        if (msg.error) {
+            InspectorTest.log(msg.error.message);
+            InspectorTest.completeTest();
+            return;
+        }
+        var node = msg.result;
+        InspectorTest.sendCommand("DOM.focus", { "nodeId": node.nodeId }, onFocus);
+    }
+
+    function onFocus(msg) {
+        if (msg.error)
+            InspectorTest.log(msg.error);
+        InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+<body onload="runTest()">
+<input></input>
+<input id="second"></input>
+</body>
+</html>
diff --git a/LayoutTests/inspector-protocol/input/dispatchKeyEvent-expected.txt b/LayoutTests/inspector-protocol/input/dispatchKeyEvent-expected.txt
new file mode 100644 (file)
index 0000000..b83a7a6
--- /dev/null
@@ -0,0 +1,17 @@
+-----Event-----
+type: keydown
+keyCode: 65
+keyIdentifier: U+0041
+
+-----Event-----
+type: keypress
+shiftKey
+keyCode: 65
+charCode: 65
+
+-----Event-----
+type: keyup
+keyCode: 65
+keyIdentifier: U+0041
+
+
diff --git a/LayoutTests/inspector-protocol/input/dispatchKeyEvent.html b/LayoutTests/inspector-protocol/input/dispatchKeyEvent.html
new file mode 100644 (file)
index 0000000..300cf45
--- /dev/null
@@ -0,0 +1,73 @@
+<html>
+<head>
+<script type="text/javascript" src="../../http/tests/inspector-protocol/resources/protocol-test.js"></script>
+<script>
+
+window.addEventListener("keydown", logEvent);
+window.addEventListener("keypress", logEvent);
+window.addEventListener("keyup", logEvent);
+
+function logEvent(event) {
+    log("-----Event-----");
+    log("type: " + event.type);
+    if (event.altKey)
+        log("altKey");
+    if (event.ctrlKey)
+        log("ctrlKey");
+    if (event.metaKey)
+        log("metaKey");
+    if (event.shiftKey)
+        log("shiftKey");
+    if (event.keyCode)
+        log("keyCode: " + event.keyCode);
+    if (event.keyIdentifier)
+        log("keyIdentifier: " + event.keyIdentifier);
+    if (event.charCode)
+        log("charCode: " + event.charCode);
+    if (event.text)
+        log("text: " + event.text);
+    log("");
+}
+
+function test()
+{
+    var events = [
+        {
+            "type": "rawKeyDown",
+            "windowsVirtualKeyCode": 65, // VK_A
+            "keyIdentifier": "U+0041",
+        },
+        {
+            "type": "char",
+            "modifiers": 8, // shift
+            "text": "A",
+            "unmodifiedText": "a",
+        },
+        {
+            "type": "keyUp",
+            "windowsVirtualKeyCode": 65,
+            "keyIdentifier": "U+0041"
+        }
+    ];
+
+    InspectorTest.sendCommand("Input.dispatchKeyEvent", events.shift(), continueTest);
+
+    function continueTest(msg) {
+        if (msg.error) {
+            InspectorTest.log("Error: " + msg.error.message);
+            InspectorTest.completeTest();
+            return;
+        }
+
+        if (events.length)
+            InspectorTest.sendCommand("Input.dispatchKeyEvent", events.shift(), continueTest);
+        else
+            InspectorTest.completeTest();
+    }
+}
+
+</script>
+</head>
+<body onload="runTest()">
+</body>
+</html>
index 950a360..9afa724 100644 (file)
@@ -1598,6 +1598,7 @@ SET(WebCore_SOURCES
     inspector/InspectorFrontendHost.cpp
     inspector/InspectorHistory.cpp
     inspector/InspectorIndexedDBAgent.cpp
+    inspector/InspectorInputAgent.cpp
     inspector/InspectorInstrumentation.cpp
     inspector/InspectorMemoryAgent.cpp
     inspector/InspectorOverlay.cpp
index 0e16fde..e265c7b 100644 (file)
@@ -1,3 +1,44 @@
+2012-12-04  Ken Kania  <kkania@chromium.org>
+
+        Inspector: Introduce Input.dispatchKeyEvent and DOM.focus for typing simulation.
+        https://bugs.webkit.org/show_bug.cgi?id=103530
+
+        Reviewed by Yury Semikhatsky.
+
+        Input.dispatchKeyEvent simply calls EventHandler::keyEvent with the key event data
+        from the command parameters. The client will be responsible for providing proper
+        events to simulate desired typing behavior.
+        DOM.focus calls focus on a dom element.
+
+        Tests: inspector-protocol/dom-focus.html
+               inspector-protocol/input-dispatchKeyEvent.html
+
+        * CMakeLists.txt:
+        * GNUmakefile.list.am:
+        * Target.pri:
+        * WebCore.gypi:
+        * WebCore.vcproj/WebCore.vcproj:
+        * WebCore.xcodeproj/project.pbxproj:
+        * inspector/Inspector.json:
+        * inspector/InspectorAllInOne.cpp:
+        * inspector/InspectorController.cpp:
+        (WebCore::InspectorController::InspectorController):
+        * inspector/InspectorDOMAgent.cpp:
+        (WebCore::InspectorDOMAgent::focus):
+        (WebCore):
+        (WebCore::InspectorDOMAgent::resolveNode):
+        * inspector/InspectorDOMAgent.h:
+        (InspectorDOMAgent):
+        * inspector/InspectorInputAgent.cpp: Added.
+        (WebCore):
+        (WebCore::InspectorInputAgent::InspectorInputAgent):
+        (WebCore::InspectorInputAgent::~InspectorInputAgent):
+        (WebCore::InspectorInputAgent::dispatchKeyEvent):
+        * inspector/InspectorInputAgent.h: Added.
+        (WebCore):
+        (InspectorInputAgent):
+        (WebCore::InspectorInputAgent::create):
+
 2012-12-04  Dan Bernstein  <mitz@apple.com>
 
         FontPlatformData has unnecessary m_textOrientation member
index 5af7ef5..7ee344a 100644 (file)
@@ -3740,6 +3740,8 @@ webcore_sources += \
        Source/WebCore/inspector/InspectorHistory.h \
        Source/WebCore/inspector/InspectorIndexedDBAgent.h \
        Source/WebCore/inspector/InspectorIndexedDBAgent.cpp \
+       Source/WebCore/inspector/InspectorInputAgent.cpp \
+       Source/WebCore/inspector/InspectorInputAgent.h \
        Source/WebCore/inspector/InspectorInstrumentation.cpp \
        Source/WebCore/inspector/InspectorInstrumentation.h \
        Source/WebCore/inspector/InspectorMemoryAgent.cpp \
index 299021c..34cd638 100644 (file)
@@ -772,6 +772,7 @@ SOURCES += \
     inspector/InspectorFrontendClientLocal.cpp \
     inspector/InspectorFrontendHost.cpp \
     inspector/InspectorHistory.cpp \
+    inspector/InspectorInputAgent.cpp \
     inspector/InspectorInstrumentation.cpp \
     inspector/InspectorMemoryAgent.cpp \
     inspector/InspectorOverlay.cpp \
index dbffa54..4087611 100644 (file)
             'inspector/InspectorHistory.h',
             'inspector/InspectorIndexedDBAgent.cpp',
             'inspector/InspectorIndexedDBAgent.h',
+            'inspector/InspectorInputAgent.cpp',
+            'inspector/InspectorInputAgent.h',
             'inspector/InspectorInstrumentation.cpp',
             'inspector/InspectorInstrumentation.h',
             'inspector/InspectorMemoryAgent.cpp',
index e99480c..a9970e6 100755 (executable)
                                >
                        </File>
                        <File
+                               RelativePath="..\inspector\InspectorInputAgent.cpp"
+                               >
+                               <FileConfiguration
+                                       Name="Release|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                               <FileConfiguration
+                                       Name="Production|Win32"
+                                       ExcludedFromBuild="true"
+                                       >
+                                       <Tool
+                                               Name="VCCLCompilerTool"
+                                       />
+                               </FileConfiguration>
+                       </File>
+                       <File
+                               RelativePath="..\inspector\InspectorInputAgent.h"
+                               >
+                       </File>
+                       <File
                                RelativePath="..\inspector\InspectorInstrumentation.cpp"
                                >
                                <FileConfiguration
index 70fe378..bde6cf9 100644 (file)
                4B6FA6F70C39E4A100087011 /* SmartReplaceCF.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */; };
                4B8AF4AA0B1CE02B00687690 /* ClipboardAccessPolicy.h in Headers */ = {isa = PBXBuildFile; fileRef = 4B8AF4A90B1CE02B00687690 /* ClipboardAccessPolicy.h */; settings = {ATTRIBUTES = (Private, ); }; };
                4BAE95B10B2FA9CE00AED8A0 /* EditorDeleteAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */; settings = {ATTRIBUTES = (Private, ); }; };
+               4D273CF91669420800259CA1 /* InspectorInputAgent.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4D273CF71669420800259CA1 /* InspectorInputAgent.cpp */; };
+               4D273CFA1669420800259CA1 /* InspectorInputAgent.h in Headers */ = {isa = PBXBuildFile; fileRef = 4D273CF81669420800259CA1 /* InspectorInputAgent.h */; };
                4E1959210A39DABA00220FE5 /* MediaFeatureNames.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */; };
                4E1959220A39DABA00220FE5 /* MediaFeatureNames.h in Headers */ = {isa = PBXBuildFile; fileRef = 4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */; };
                4E1959290A39DACC00220FE5 /* MediaQuery.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4E1959230A39DACC00220FE5 /* MediaQuery.cpp */; };
                4B6FA6F60C39E4A100087011 /* SmartReplaceCF.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SmartReplaceCF.cpp; sourceTree = "<group>"; };
                4B8AF4A90B1CE02B00687690 /* ClipboardAccessPolicy.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = ClipboardAccessPolicy.h; sourceTree = "<group>"; };
                4BAE95B00B2FA9CE00AED8A0 /* EditorDeleteAction.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EditorDeleteAction.h; sourceTree = "<group>"; };
+               4D273CF71669420800259CA1 /* InspectorInputAgent.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = InspectorInputAgent.cpp; sourceTree = "<group>"; };
+               4D273CF81669420800259CA1 /* InspectorInputAgent.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = InspectorInputAgent.h; sourceTree = "<group>"; };
                4E19591F0A39DABA00220FE5 /* MediaFeatureNames.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaFeatureNames.cpp; sourceTree = "<group>"; };
                4E1959200A39DABA00220FE5 /* MediaFeatureNames.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = MediaFeatureNames.h; sourceTree = "<group>"; };
                4E1959230A39DACC00220FE5 /* MediaQuery.cpp */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.cpp.cpp; path = MediaQuery.cpp; sourceTree = "<group>"; };
                                7A54857E14E02D51006AE05A /* InspectorHistory.h */,
                                7ACD88D114C08BD60084EDD2 /* InspectorIndexedDBAgent.cpp */,
                                7ACD88D214C08BD60084EDD2 /* InspectorIndexedDBAgent.h */,
+                               4D273CF71669420800259CA1 /* InspectorInputAgent.cpp */,
+                               4D273CF81669420800259CA1 /* InspectorInputAgent.h */,
                                20D629241253690B00081543 /* InspectorInstrumentation.cpp */,
                                20D629251253690B00081543 /* InspectorInstrumentation.h */,
                                7AA51DD3148506A900AD2752 /* InspectorMemoryAgent.cpp */,
                                7A0E770F10C00A8800A0276E /* InspectorFrontendHost.h in Headers */,
                                7A54858014E02D51006AE05A /* InspectorHistory.h in Headers */,
                                7ACD88D414C08BD60084EDD2 /* InspectorIndexedDBAgent.h in Headers */,
+                               4D273CFA1669420800259CA1 /* InspectorInputAgent.h in Headers */,
                                20D629271253690B00081543 /* InspectorInstrumentation.h in Headers */,
                                7AA51DD6148506A900AD2752 /* InspectorMemoryAgent.h in Headers */,
                                4F6FDD651341DEDD001F8EE3 /* InspectorPageAgent.h in Headers */,
                                7A0E770E10C00A8800A0276E /* InspectorFrontendHost.cpp in Sources */,
                                7A54857F14E02D51006AE05A /* InspectorHistory.cpp in Sources */,
                                7ACD88D314C08BD60084EDD2 /* InspectorIndexedDBAgent.cpp in Sources */,
+                               4D273CF91669420800259CA1 /* InspectorInputAgent.cpp in Sources */,
                                20D629261253690B00081543 /* InspectorInstrumentation.cpp in Sources */,
                                7AA51DD5148506A900AD2752 /* InspectorMemoryAgent.cpp in Sources */,
                                7C522D4B15B477E8009B7C95 /* InspectorOverlay.cpp in Sources */,
index 17743dd..8f22c7a 100644 (file)
                 "name": "markUndoableState",
                 "description": "Marks last undoable state.",
                 "hidden": true
+            },
+            {
+                "name": "focus",
+                "parameters": [
+                    { "name": "nodeId", "$ref": "DOM.NodeId", "description": "Id of the node to focus." }
+                ],
+                "description": "Focuses the given element.",
+                "hidden": true
             }
         ],
         "events": [
             }
         ],
         "events": []
+    },
+    {
+        "domain": "Input",
+        "hidden": true,
+        "types": [],
+        "commands": [
+            {
+                "name": "dispatchKeyEvent",
+                "parameters": [
+                    { "name": "type", "type": "string", "enum": ["keyDown", "keyUp", "rawKeyDown", "char"], "description": "Type of the key event." },
+                    { "name": "modifiers", "type": "integer", "optional": true, "description": "Bit field representing pressed modifier keys. Alt=1, Ctrl=2, Meta/Command=4, Shift=8 (default: 0)." },
+                    { "name": "timestamp", "type": "number", "optional": true, "description": "Time at which the event occurred. Measured in UTC time in seconds since January 1, 1970 (default: current time)." },
+                    { "name": "text", "type": "string", "optional": true, "description": "Text as generated by processing a virtual key code with a keyboard layout. Not needed for for <code>keyUp</code> and <code>rawKeyDown</code> events (default: \"\")" },
+                    { "name": "unmodifiedText", "type": "string", "optional": true, "description": "Text that would have been generated by the keyboard if no modifiers were pressed (except for shift). Useful for shortcut (accelerator) key handling (default: \"\")." },
+                    { "name": "keyIdentifier", "type": "string", "optional": true, "description": "Unique key identifier (e.g., 'U+0041') (default: \"\")." },
+                    { "name": "windowsVirtualKeyCode", "type": "integer", "optional": true, "description": "Windows virtual key code (default: 0)." },
+                    { "name": "nativeVirtualKeyCode", "type": "integer", "optional": true, "description": "Native virtual key code (default: 0)." },
+                    { "name": "macCharCode", "type": "integer", "optional": true, "description": "Mac character code (default: 0)." },
+                    { "name": "autoRepeat", "type": "boolean", "optional": true, "description": "Whether the event was generated from auto repeat (default: false)." },
+                    { "name": "isKeypad", "type": "boolean", "optional": true, "description": "Whether the event was generated from the keypad (default: false)." },
+                    { "name": "isSystemKey", "type": "boolean", "optional": true, "description": "Whether the event was a system key event (default: false)." }
+                ],
+                "description": "Dispatches a key event to the page."
+            }
+        ],
+        "events": []
     }]
 }
index d19ad2e..c9a80ad 100644 (file)
@@ -57,6 +57,7 @@
 #include "InspectorFrontendHost.cpp"
 #include "InspectorHistory.cpp"
 #include "InspectorIndexedDBAgent.cpp"
+#include "InspectorInputAgent.cpp"
 #include "InspectorInstrumentation.cpp"
 #include "InspectorMemoryAgent.cpp"
 #include "InspectorOverlay.cpp"
index 224ca17..c6f263d 100644 (file)
@@ -55,6 +55,7 @@
 #include "InspectorFrontend.h"
 #include "InspectorFrontendClient.h"
 #include "InspectorIndexedDBAgent.h"
+#include "InspectorInputAgent.h"
 #include "InspectorInstrumentation.h"
 #include "InspectorMemoryAgent.h"
 #include "InspectorOverlay.h"
@@ -151,6 +152,8 @@ InspectorController::InspectorController(Page* page, InspectorClient* inspectorC
 
     m_agents.append(InspectorCanvasAgent::create(m_instrumentingAgents.get(), m_state.get(), page, m_injectedScriptManager.get()));
 
+    m_agents.append(InspectorInputAgent::create(m_instrumentingAgents.get(), m_state.get(), page));
+
     ASSERT_ARG(inspectorClient, inspectorClient);
     m_injectedScriptManager->injectedScriptHost()->init(m_inspectorAgent
         , consoleAgent
index 9b8890a..3b6c112 100644 (file)
@@ -52,6 +52,7 @@
 #include "Document.h"
 #include "DocumentFragment.h"
 #include "DocumentType.h"
+#include "Element.h"
 #include "ElementShadow.h"
 #include "Event.h"
 #include "EventContext.h"
@@ -1156,17 +1157,29 @@ void InspectorDOMAgent::markUndoableState(ErrorString*)
     m_history->markUndoableState();
 }
 
-void InspectorDOMAgent::resolveNode(ErrorString* error, int nodeId, const String* const objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
+void InspectorDOMAgent::focus(ErrorString* errorString, int nodeId)
+{
+    Element* element = assertElement(errorString, nodeId);
+    if (!element)
+        return;
+    if (!element->isFocusable()) {
+        *errorString = "Element is not focusable";
+        return;
+    }
+    element->focus();
+}
+
+void InspectorDOMAgent::resolveNode(ErrorString* errorString, int nodeId, const String* const objectGroup, RefPtr<TypeBuilder::Runtime::RemoteObject>& result)
 {
     String objectGroupName = objectGroup ? *objectGroup : "";
     Node* node = nodeForId(nodeId);
     if (!node) {
-        *error = "No node with given id found";
+        *errorString = "No node with given id found";
         return;
     }
     RefPtr<TypeBuilder::Runtime::RemoteObject> object = resolveNode(node, objectGroupName);
     if (!object) {
-        *error = "Node with given id does not belong to the document";
+        *errorString = "Node with given id does not belong to the document";
         return;
     }
     result = object;
index f7cc5fb..707cad0 100644 (file)
@@ -147,6 +147,7 @@ public:
     virtual void undo(ErrorString*);
     virtual void redo(ErrorString*);
     virtual void markUndoableState(ErrorString*);
+    virtual void focus(ErrorString*, int nodeId);
 
     void getEventListeners(Node*, Vector<EventListenerInfo>& listenersArray, bool includeAncestors);
 
diff --git a/Source/WebCore/inspector/InspectorInputAgent.cpp b/Source/WebCore/inspector/InspectorInputAgent.cpp
new file mode 100644 (file)
index 0000000..e6834aa
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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"
+
+#if ENABLE(INSPECTOR)
+
+#include "InspectorInputAgent.h"
+
+#include "EventHandler.h"
+#include "Frame.h"
+#include "Page.h"
+#include "PlatformEvent.h"
+#include "PlatformKeyboardEvent.h"
+
+#include <wtf/CurrentTime.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+InspectorInputAgent::InspectorInputAgent(InstrumentingAgents* instrumentingAgents, InspectorState* inspectorState, Page* page)
+    : InspectorBaseAgent<InspectorInputAgent>("Input", instrumentingAgents, inspectorState)
+    , m_page(page)
+{
+}
+
+InspectorInputAgent::~InspectorInputAgent()
+{
+}
+
+void InspectorInputAgent::dispatchKeyEvent(ErrorString* error, const String& type, const int* modifiers, const double* timestamp, const String* text, const String* unmodifiedText, const String* keyIdentifier, const int* windowsVirtualKeyCode, const int* nativeVirtualKeyCode, const int* macCharCode, const bool* autoRepeat, const bool* isKeypad, const bool* isSystemKey)
+{
+    PlatformEvent::Type convertedType;
+    if (type == "keyDown")
+        convertedType = PlatformEvent::KeyDown;
+    else if (type == "keyUp")
+        convertedType = PlatformEvent::KeyUp;
+    else if (type == "char")
+        convertedType = PlatformEvent::Char;
+    else if (type == "rawKeyDown")
+        convertedType = PlatformEvent::RawKeyDown;
+    else {
+        *error = "Unrecognized type: " + type;
+        return;
+    }
+
+    PlatformKeyboardEvent event(
+        convertedType,
+        text ? *text : "",
+        unmodifiedText ? *unmodifiedText : "",
+        keyIdentifier ? *keyIdentifier : "",
+        windowsVirtualKeyCode ? *windowsVirtualKeyCode : 0,
+        nativeVirtualKeyCode ? *nativeVirtualKeyCode : 0,
+        macCharCode ? *macCharCode : 0,
+        autoRepeat ? *autoRepeat : false,
+        isKeypad ? *isKeypad : false,
+        isSystemKey ? *isSystemKey : false,
+        static_cast<PlatformEvent::Modifiers>(modifiers ? *modifiers : 0),
+        timestamp ? *timestamp : currentTime());
+    m_page->mainFrame()->eventHandler()->keyEvent(event);
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INSPECTOR)
diff --git a/Source/WebCore/inspector/InspectorInputAgent.h b/Source/WebCore/inspector/InspectorInputAgent.h
new file mode 100644 (file)
index 0000000..20c4c09
--- /dev/null
@@ -0,0 +1,71 @@
+/*
+ * Copyright (C) 2012 Google 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:
+ *
+ *     * Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *     * 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.
+ *     * Neither the name of Google Inc. nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "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 THE COPYRIGHT
+ * OWNER 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 InspectorInputAgent_h
+#define InspectorInputAgent_h
+
+#if ENABLE(INSPECTOR)
+
+#include "InspectorBaseAgent.h"
+
+#include <wtf/Noncopyable.h>
+#include <wtf/PassOwnPtr.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+class InspectorState;
+class Page;
+
+typedef String ErrorString;
+
+class InspectorInputAgent : public InspectorBaseAgent<InspectorInputAgent>, public InspectorBackendDispatcher::InputCommandHandler {
+    WTF_MAKE_NONCOPYABLE(InspectorInputAgent);
+public:
+    static PassOwnPtr<InspectorInputAgent> create(InstrumentingAgents* instrumentingAgents, InspectorState* inspectorState, Page* page)
+    {
+        return adoptPtr(new InspectorInputAgent(instrumentingAgents, inspectorState, page));
+    }
+
+    ~InspectorInputAgent();
+
+    // Methods called from the frontend for simulating input.
+    virtual void dispatchKeyEvent(ErrorString*, const String& type, const int* modifiers, const double* timestamp, const String* text, const String* unmodifiedText, const String* keyIdentifier, const int* windowsVirtualKeyCode, const int* nativeVirtualKeyCode, const int* macCharCode, const bool* autoRepeat, const bool* isKeypad, const bool* isSystemKey);
+
+private:
+    InspectorInputAgent(InstrumentingAgents*, InspectorState*, Page*);
+
+    Page* m_page;
+};
+
+#endif // ENABLE(INSPECTOR)
+
+} // namespace WebCore
+
+#endif // !defined(InspectorInputAgent_h)