Make the docked Web Inspector resizable.

WebCore:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Make the docked Web Inspector resizable. This is the cross platform
        portion of the code. Each InspectorClient needs to implement the
        real resize code.

        https://bugs.webkit.org/show_bug.cgi?id=14282

        Reviewed by Kevin McCullough.

        * loader/EmptyClients.h: Added an empty setAttachedWindowHeight.
        * page/InspectorClient.h: Added setAttachedWindowHeight.
        * page/InspectorController.cpp:
        (WebCore::setAttachedWindowHeight): Call setAttachedWindowHeight
        on the InspectorController.
        (WebCore::InspectorController::setAttachedWindowHeight): Call
        setAttachedWindowHeight on the client.
        (WebCore::InspectorController::windowScriptObjectAvailable):
        Added setAttachedWindowHeight to the script class.
        * page/InspectorController.h:
        * page/inspector/inspector.css: Make the cursor on the toolbar be
        row-resize when docked.
        * page/inspector/inspector.js:
        (WebInspector.loaded): Always add the toolbarDragStart event listener.
        (WebInspector.toolbarDragStart): Return early if we are not attached
        and not on Leopard. Call WebInspector.elementDragStart.
        (WebInspector.toolbarDragEnd): Call WebInspector.elementDragEnd.
        (WebInspector.toolbarDrag): When attached call setAttachedWindowHeight,
        otherwise call moveByUnrestricted.

WebKit/gtk:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Add a stub for InspectorClient::setAttachedWindowHeight.

        * WebCoreSupport/InspectorClientGtk.cpp:
        (WebKit::InspectorClient::setAttachedWindowHeight):
        Call notImplemented().
        * WebCoreSupport/InspectorClientGtk.h:

WebKit/mac:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Make the docked Web Inspector resizable.

        https://bugs.webkit.org/show_bug.cgi?id=14282

        Reviewed by Kevin McCullough.

        * WebCoreSupport/WebInspectorClient.h:
        * WebCoreSupport/WebInspectorClient.mm:
        (WebInspectorClient::setAttachedWindowHeight): Call setAttachedWindowHeight:
        on the WebInspectorWindowController.
        (-[WebInspectorWindowController showWindow:]): Call setAttachedWindowHeight:.
        (-[WebInspectorWindowController setAttachedWindowHeight:]): Moved code
        from showWindow: and generalized to allow being called multiple times.
        Remembers the last height passed, which is used by showWindow: the next
        time the Inspector attaches.

WebKit/qt:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Add a stub for InspectorClient::setAttachedWindowHeight.

        * WebCoreSupport/InspectorClientQt.cpp:
        (WebCore::InspectorClientQt::setAttachedWindowHeight):
        Call notImplemented().
        * WebCoreSupport/InspectorClientQt.h:

WebKit/win:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Add a stub for InspectorClient::setAttachedWindowHeight.

        * WebCoreSupport/WebInspectorClient.cpp:
        (WebInspectorClient::setAttachedWindowHeight): Add a FIXME to implement this.
        * WebCoreSupport/WebInspectorClient.h:

WebKit/wx:

2008-08-12  Timothy Hatcher  <timothy@apple.com>

        Add a stub for InspectorClient::setAttachedWindowHeight.

        * WebKitSupport/InspectorClientWx.cpp:
        (WebCore::InspectorClientWx::setAttachedWindowHeight):
        Call notImplemented().
        * WebKitSupport/InspectorClientWx.h:

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@35719 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/page/InspectorClient.h b/WebCore/page/InspectorClient.h
index ec1ee92..9ee4a26 100644
--- a/WebCore/page/InspectorClient.h
+++ b/WebCore/page/InspectorClient.h
@@ -48,6 +48,8 @@
     virtual void attachWindow() = 0;
     virtual void detachWindow() = 0;
 
+    virtual void setAttachedWindowHeight(unsigned height) = 0;
+
     virtual void highlight(Node*) = 0;
     virtual void hideHighlight() = 0;
 
diff --git a/WebCore/page/InspectorController.cpp b/WebCore/page/InspectorController.cpp
index 01826a4..9cd07a9 100644
--- a/WebCore/page/InspectorController.cpp
+++ b/WebCore/page/InspectorController.cpp
@@ -779,6 +779,24 @@
     return JSValueMakeUndefined(ctx);
 }
 
+static JSValueRef setAttachedWindowHeight(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
+{
+    InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
+    if (!controller)
+        return JSValueMakeUndefined(ctx);
+
+    if (argumentCount < 1)
+        return JSValueMakeUndefined(ctx);
+
+    unsigned height = static_cast<unsigned>(JSValueToNumber(ctx, arguments[0], exception));
+    if (exception && *exception)
+        return JSValueMakeUndefined(ctx);
+
+    controller->setAttachedWindowHeight(height);
+
+    return JSValueMakeUndefined(ctx);
+}
+
 static JSValueRef wrapCallback(JSContextRef ctx, JSObjectRef /*function*/, JSObjectRef thisObject, size_t argumentCount, const JSValueRef arguments[], JSValueRef* exception)
 {
     InspectorController* controller = reinterpret_cast<InspectorController*>(JSObjectGetPrivate(thisObject));
@@ -1297,6 +1315,13 @@
     m_client->detachWindow();
 }
 
+void InspectorController::setAttachedWindowHeight(unsigned height)
+{
+    if (!enabled())
+        return;
+    m_client->setAttachedWindowHeight(height);
+}
+
 void InspectorController::inspectedWindowScriptObjectCleared(Frame* frame)
 {
     if (!enabled() || !m_scriptContext || !m_scriptObject)
@@ -1339,6 +1364,7 @@
         { "localizedStringsURL", localizedStrings, kJSPropertyAttributeNone },
         { "platform", platform, kJSPropertyAttributeNone },
         { "moveByUnrestricted", moveByUnrestricted, kJSPropertyAttributeNone },
+        { "setAttachedWindowHeight", WebCore::setAttachedWindowHeight, kJSPropertyAttributeNone },
         { "wrapCallback", wrapCallback, kJSPropertyAttributeNone },
         { "startDebuggingAndReloadInspectedPage", WebCore::startDebuggingAndReloadInspectedPage, kJSPropertyAttributeNone },
         { "stopDebugging", WebCore::stopDebugging, kJSPropertyAttributeNone },
diff --git a/WebCore/page/InspectorController.h b/WebCore/page/InspectorController.h
index 56974c9..171134c 100644
--- a/WebCore/page/InspectorController.h
+++ b/WebCore/page/InspectorController.h
@@ -119,6 +119,8 @@
     void attachWindow();
     void detachWindow();
 
+    void setAttachedWindowHeight(unsigned height);
+
     JSContextRef scriptContext() const { return m_scriptContext; };
     void setScriptContext(JSContextRef context) { m_scriptContext = context; };
 
diff --git a/WebCore/page/inspector/inspector.css b/WebCore/page/inspector/inspector.css
index 24fc0db..3911118 100644
--- a/WebCore/page/inspector/inspector.css
+++ b/WebCore/page/inspector/inspector.css
@@ -89,6 +89,7 @@
 body.attached #toolbar {
     height: 34px;
     border-top: 1px solid rgb(100, 100, 100);
+    cursor: row-resize;
 }
 
 body.attached.inactive #toolbar {
diff --git a/WebCore/page/inspector/inspector.js b/WebCore/page/inspector/inspector.js
index d2d5fb9..1c74012 100644
--- a/WebCore/page/inspector/inspector.js
+++ b/WebCore/page/inspector/inspector.js
@@ -343,8 +343,7 @@
     var searchField = document.getElementById("search");
     searchField.addEventListener("keyup", this.performSearch.bind(this), false);
 
-    if (platform === "mac-leopard")
-        document.getElementById("toolbar").addEventListener("mousedown", this.toolbarDragStart, true);
+    document.getElementById("toolbar").addEventListener("mousedown", this.toolbarDragStart, true);
 
     InspectorController.loaded();
 }
@@ -583,7 +582,7 @@
 
 WebInspector.toolbarDragStart = function(event)
 {
-    if (WebInspector.attached)
+    if (!WebInspector.attached && InspectorController.platform() !== "mac-leopard")
         return;
 
     var target = event.target;
@@ -597,40 +596,39 @@
     toolbar.lastScreenX = event.screenX;
     toolbar.lastScreenY = event.screenY;
 
-    document.addEventListener("mousemove", WebInspector.toolbarDrag, true);
-    document.addEventListener("mouseup", WebInspector.toolbarDragEnd, true);
-    document.body.style.cursor = "default";
-
-    event.preventDefault();
+    WebInspector.elementDragStart(toolbar, WebInspector.toolbarDrag, WebInspector.toolbarDragEnd, event, (WebInspector.attached ? "row-resize" : "default"));
 }
 
 WebInspector.toolbarDragEnd = function(event)
 {
     var toolbar = document.getElementById("toolbar");
+
+    WebInspector.elementDragEnd(event);
+
     delete toolbar.lastScreenX;
     delete toolbar.lastScreenY;
-
-    document.removeEventListener("mousemove", WebInspector.toolbarDrag, true);
-    document.removeEventListener("mouseup", WebInspector.toolbarDragEnd, true);
-    document.body.style.removeProperty("cursor");
-
-    event.preventDefault();
 }
 
 WebInspector.toolbarDrag = function(event)
 {
     var toolbar = document.getElementById("toolbar");
 
-    var x = event.screenX - toolbar.lastScreenX;
-    var y = event.screenY - toolbar.lastScreenY;
+    if (WebInspector.attached) {
+        var height = window.innerHeight - (event.screenY - toolbar.lastScreenY);
+
+        InspectorController.setAttachedWindowHeight(height);
+    } else {
+        var x = event.screenX - toolbar.lastScreenX;
+        var y = event.screenY - toolbar.lastScreenY;
+
+        // We cannot call window.moveBy here because it restricts the movement
+        // of the window at the edges.
+        InspectorController.moveByUnrestricted(x, y);
+    }
 
     toolbar.lastScreenX = event.screenX;
     toolbar.lastScreenY = event.screenY;
 
-    // We cannot call window.moveBy here because it restricts the movement of the window
-    // at the edges.
-    InspectorController.moveByUnrestricted(x, y);
-
     event.preventDefault();
 }