Changeset 50639 in webkit


Ignore:
Timestamp:
Nov 8, 2009 10:39:32 PM (14 years ago)
Author:
eric@webkit.org
Message:

2009-11-08 Keishi Hattori <casey.hattori@gmail.com>

Reviewed by Pavel Feldman.

Web Inspector: Inspector should support copy() in the command line
https://bugs.webkit.org/show_bug.cgi?id=31238

  • inspector/InspectorBackend.cpp: (WebCore::InspectorBackend::copyText): Added.
  • inspector/InspectorBackend.h: Added copyText
  • inspector/InspectorBackend.idl: Added copyText
  • inspector/front-end/InjectedScript.js: (InjectedScript._copy): Added. (InjectedScript._ensureCommandLineAPIInstalled):
Location:
trunk/WebCore
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r50638 r50639  
     12009-11-08  Keishi Hattori  <casey.hattori@gmail.com>
     2
     3        Reviewed by Pavel Feldman.
     4
     5        Web Inspector: Inspector should support copy() in the command line
     6        https://bugs.webkit.org/show_bug.cgi?id=31238
     7
     8        * inspector/InspectorBackend.cpp:
     9        (WebCore::InspectorBackend::copyText): Added.
     10        * inspector/InspectorBackend.h: Added copyText
     11        * inspector/InspectorBackend.idl: Added copyText
     12        * inspector/front-end/InjectedScript.js:
     13        (InjectedScript._copy): Added.
     14        (InjectedScript._ensureCommandLineAPIInstalled):
     15
    1162009-11-08  Drew Wilson  <atwilson@chromium.org>
    217
  • trunk/WebCore/inspector/InspectorBackend.cpp

    r50528 r50639  
    508508}
    509509
     510void InspectorBackend::copyText(const String& text)
     511{
     512    Pasteboard::generalPasteboard()->writePlainText(text);
     513}
     514
    510515void InspectorBackend::highlight(long nodeId)
    511516{
  • trunk/WebCore/inspector/InspectorBackend.h

    r50528 r50639  
    144144    void deleteCookie(const String& cookieName, const String& domain);
    145145
     146    void copyText(const String& text);
     147
    146148    // Generic code called from custom implementations.
    147149    void highlight(long nodeId);
  • trunk/WebCore/inspector/InspectorBackend.idl

    r50528 r50639  
    118118        // Called from InjectedScript.
    119119        // TODO: extract into a separate IDL.
     120        void copyText(in DOMString text);
    120121        [Custom] DOMObject nodeForId(in long nodeId);
    121122        [Custom] long wrapObject(in DOMObject object, in DOMString objectGroup);
  • trunk/WebCore/inspector/front-end/InjectedScript.js

    r50574 r50639  
    904904}
    905905
     906InjectedScript._copy = function(o)
     907{
     908    if (Object.type(o) === "node") {
     909        var nodeId = InspectorController.pushNodePathToFrontend(o, false);
     910        InspectorController.copyNode(nodeId);
     911    } else {
     912        InspectorController.copyText(o);
     913    }
     914}
     915
    906916InjectedScript._ensureCommandLineAPIInstalled = function(evalFunction, evalObject)
    907917{
    908918    if (evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI"))
    909919        return;
    910     var inspectorCommandLineAPI = evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI = { \
    911         $: function() { return document.getElementById.apply(document, arguments) }, \
    912         $$: function() { return document.querySelectorAll.apply(document, arguments) }, \
    913         $x: function(xpath, context) { \
    914             var nodes = []; \
    915             try { \
    916                 var doc = context || document; \
    917                 var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \
    918                 var node; \
    919                 while (node = results.iterateNext()) nodes.push(node); \
    920             } catch (e) {} \
    921             return nodes; \
    922         }, \
    923         dir: function() { return console.dir.apply(console, arguments) }, \
    924         dirxml: function() { return console.dirxml.apply(console, arguments) }, \
    925         keys: function(o) { var a = []; for (var k in o) a.push(k); return a; }, \
    926         values: function(o) { var a = []; for (var k in o) a.push(o[k]); return a; }, \
    927         profile: function() { return console.profile.apply(console, arguments) }, \
    928         profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \
    929         _logEvent: function _inspectorCommandLineAPI_logEvent(e) { console.log(e.type, e); }, \
    930         _allEventTypes: [\"mouse\", \"key\", \"load\", \"unload\", \"abort\", \"error\", \
    931             \"select\", \"change\", \"submit\", \"reset\", \"focus\", \"blur\", \
    932             \"resize\", \"scroll\"], \
    933         _normalizeEventTypes: function(t) { \
    934             if (typeof t === \"undefined\") \
    935                 t = console._inspectorCommandLineAPI._allEventTypes; \
    936             else if (typeof t === \"string\") \
    937                 t = [t]; \
    938             var i, te = []; \
    939             for (i = 0; i < t.length; i++) { \
    940                 if (t[i] === \"mouse\") \
    941                     te.splice(0, 0, \"mousedown\", \"mouseup\", \"click\", \"dblclick\", \
    942                         \"mousemove\", \"mouseover\", \"mouseout\"); \
    943                 else if (t[i] === \"key\") \
    944                     te.splice(0, 0, \"keydown\", \"keyup\", \"keypress\"); \
    945                 else \
    946                     te.push(t[i]); \
    947             } \
    948             return te; \
    949         }, \
    950         monitorEvents: function(o, t) { \
    951             if (!o || !o.addEventListener || !o.removeEventListener) \
    952                 return; \
    953             t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \
    954             for (i = 0; i < t.length; i++) { \
    955                 o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \
    956                 o.addEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \
    957             } \
    958         }, \
    959         unmonitorEvents: function(o, t) { \
    960             if (!o || !o.removeEventListener) \
    961                 return; \
    962             t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \
    963             for (i = 0; i < t.length; i++) { \
    964                 o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \
    965             } \
    966         }, \
    967         _inspectedNodes: [], \
    968         get $0() { return console._inspectorCommandLineAPI._inspectedNodes[0] }, \
    969         get $1() { return console._inspectorCommandLineAPI._inspectedNodes[1] }, \
    970         get $2() { return console._inspectorCommandLineAPI._inspectedNodes[2] }, \
    971         get $3() { return console._inspectorCommandLineAPI._inspectedNodes[3] }, \
    972         get $4() { return console._inspectorCommandLineAPI._inspectedNodes[4] } \
     920    var inspectorCommandLineAPI = evalFunction.call(evalObject, "window.console._inspectorCommandLineAPI = { \n\
     921        $: function() { return document.getElementById.apply(document, arguments) }, \n\
     922        $$: function() { return document.querySelectorAll.apply(document, arguments) }, \n\
     923        $x: function(xpath, context) \n\
     924        { \n\
     925            var nodes = []; \n\
     926            try { \n\
     927                var doc = context || document; \n\
     928                var results = doc.evaluate(xpath, doc, null, XPathResult.ANY_TYPE, null); \n\
     929                var node; \n\
     930                while (node = results.iterateNext()) nodes.push(node); \n\
     931            } catch (e) {} \n\
     932            return nodes; \n\
     933        }, \n\
     934        dir: function() { return console.dir.apply(console, arguments) }, \n\
     935        dirxml: function() { return console.dirxml.apply(console, arguments) }, \n\
     936        keys: function(o) { var a = []; for (var k in o) a.push(k); return a; }, \n\
     937        values: function(o) { var a = []; for (var k in o) a.push(o[k]); return a; }, \n\
     938        profile: function() { return console.profile.apply(console, arguments) }, \n\
     939        profileEnd: function() { return console.profileEnd.apply(console, arguments) }, \n\
     940        _logEvent: function _inspectorCommandLineAPI_logEvent(e) { console.log(e.type, e); }, \n\
     941        _allEventTypes: [\"mouse\", \"key\", \"load\", \"unload\", \"abort\", \"error\", \n\
     942            \"select\", \"change\", \"submit\", \"reset\", \"focus\", \"blur\", \n\
     943            \"resize\", \"scroll\"], \n\
     944        _normalizeEventTypes: function(t) \n\
     945        { \n\
     946            if (typeof t === \"undefined\") \n\
     947                t = console._inspectorCommandLineAPI._allEventTypes; \n\
     948            else if (typeof t === \"string\") \n\
     949                t = [t]; \n\
     950            var i, te = []; \n\
     951            for (i = 0; i < t.length; i++) { \n\
     952                if (t[i] === \"mouse\") \n\
     953                    te.splice(0, 0, \"mousedown\", \"mouseup\", \"click\", \"dblclick\", \n\
     954                        \"mousemove\", \"mouseover\", \"mouseout\"); \n\
     955                else if (t[i] === \"key\") \n\
     956                    te.splice(0, 0, \"keydown\", \"keyup\", \"keypress\"); \n\
     957                else \n\
     958                    te.push(t[i]); \n\
     959            } \n\
     960            return te; \n\
     961        }, \n\
     962        monitorEvents: function(o, t) \n\
     963        { \n\
     964            if (!o || !o.addEventListener || !o.removeEventListener) \n\
     965                return; \n\
     966            t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \n\
     967            for (i = 0; i < t.length; i++) { \n\
     968                o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
     969                o.addEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
     970            } \n\
     971        }, \n\
     972        unmonitorEvents: function(o, t) \n\
     973        { \n\
     974            if (!o || !o.removeEventListener) \n\
     975                return; \n\
     976            t = console._inspectorCommandLineAPI._normalizeEventTypes(t); \n\
     977            for (i = 0; i < t.length; i++) { \n\
     978                o.removeEventListener(t[i], console._inspectorCommandLineAPI._logEvent, false); \n\
     979            } \n\
     980        }, \n\
     981        _inspectedNodes: [], \n\
     982        get $0() { return console._inspectorCommandLineAPI._inspectedNodes[0] }, \n\
     983        get $1() { return console._inspectorCommandLineAPI._inspectedNodes[1] }, \n\
     984        get $2() { return console._inspectorCommandLineAPI._inspectedNodes[2] }, \n\
     985        get $3() { return console._inspectorCommandLineAPI._inspectedNodes[3] }, \n\
     986        get $4() { return console._inspectorCommandLineAPI._inspectedNodes[4] }, \n\
    973987    };");
    974988
    975989    inspectorCommandLineAPI.clear = InspectorController.wrapCallback(InjectedScript._clearConsoleMessages);
    976990    inspectorCommandLineAPI.inspect = InspectorController.wrapCallback(InjectedScript._inspectObject);
     991    inspectorCommandLineAPI.copy = InspectorController.wrapCallback(InjectedScript._copy);
    977992}
    978993
Note: See TracChangeset for help on using the changeset viewer.