From c828e574cc3c47349e9bbd60fd35dc52ad32d385 Mon Sep 17 00:00:00 2001 From: "cmanske%netscape.com" Date: Thu, 25 May 2000 03:34:20 +0000 Subject: [PATCH] Fixed object properties bug 39649. r=sfraser git-svn-id: svn://10.0.0.236/trunk@70791 18797224-902f-48f8-a5cc-f745e15eee43 --- mozilla/editor/base/nsEditorShell.cpp | 13 +- .../base/nsEditorShellMouseListener.cpp | 158 ++++++++++++++---- .../editor/base/nsEditorShellMouseListener.h | 5 +- mozilla/editor/composer/src/nsEditorShell.cpp | 13 +- .../src/nsEditorShellMouseListener.cpp | 158 ++++++++++++++---- .../composer/src/nsEditorShellMouseListener.h | 5 +- 6 files changed, 268 insertions(+), 84 deletions(-) diff --git a/mozilla/editor/base/nsEditorShell.cpp b/mozilla/editor/base/nsEditorShell.cpp index e2db4b30d02..53a36c214fc 100644 --- a/mozilla/editor/base/nsEditorShell.cpp +++ b/mozilla/editor/base/nsEditorShell.cpp @@ -4930,11 +4930,20 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick nsCOMPtr composerController = do_QueryInterface(controller); // Execute the command - nsAutoString commandName(NS_ConvertASCIItoUCS2("cmd_advancedProperties")); + nsAutoString commandName; + + // In "All Tags" mode, use AdvancedProperties, + // in others use appriate object property dialog + if (mDisplayMode != eDisplayModeAllTags) + commandName = NS_ConvertASCIItoUCS2("cmd_objectProperties"); + else + commandName = NS_ConvertASCIItoUCS2("cmd_advancedProperties"); + rv = composerController->DoCommand(commandName.GetUnicode()); + // We handled the message -- don't propogate to frames if (NS_SUCCEEDED(rv)) - *_retval = PR_FALSE; + *_retval = PR_TRUE; } return rv; diff --git a/mozilla/editor/base/nsEditorShellMouseListener.cpp b/mozilla/editor/base/nsEditorShellMouseListener.cpp index 79d186172ea..552e96242a7 100644 --- a/mozilla/editor/base/nsEditorShellMouseListener.cpp +++ b/mozilla/editor/base/nsEditorShellMouseListener.cpp @@ -31,6 +31,8 @@ #include "nsIDOMMouseEvent.h" #include "nsIDOMSelection.h" #include "nsIDOMEventTarget.h" +#include "nsIDOMHTMLTableElement.h" +#include "nsIDOMHTMLTableCellElement.h" /* * nsEditorShellMouseListener implementation @@ -39,11 +41,11 @@ NS_IMPL_ADDREF(nsEditorShellMouseListener) NS_IMPL_RELEASE(nsEditorShellMouseListener) - nsEditorShellMouseListener::nsEditorShellMouseListener() { NS_INIT_REFCNT(); } + nsEditorShellMouseListener::~nsEditorShellMouseListener() { } @@ -78,6 +80,68 @@ nsEditorShellMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr) } return NS_NOINTERFACE; } +// Helpers to test if in a table + +PRBool GetParentTable(nsIDOMEvent* aMouseEvent, nsIDOMElement **aTableElement) +{ + nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); + if (!mouseEvent) return PR_FALSE; + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) + { + nsCOMPtr node = do_QueryInterface(target); + + while (node) + { + nsCOMPtr table = do_QueryInterface(node); + if (table) + { + nsCOMPtr tableElement = do_QueryInterface(table); + if (tableElement) + { + *aTableElement = tableElement; + NS_ADDREF(*aTableElement); + return PR_TRUE; + } + } + nsCOMPtrparent; + if (NS_FAILED(node->GetParentNode(getter_AddRefs(parent))) || !parent) + return PR_FALSE; + node = parent; + } + } + return PR_FALSE; +} + +PRBool GetParentCell(nsIDOMEvent* aMouseEvent, nsIDOMElement **aCellElement) +{ + nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); + if (!mouseEvent) return PR_FALSE; + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) + { + nsCOMPtr node = do_QueryInterface(target); + while (node) + { + nsCOMPtr cell = do_QueryInterface(node); + if (cell) + { + nsCOMPtr cellElement = do_QueryInterface(cell); + if (cellElement) + { + *aCellElement = cellElement; + NS_ADDREF(*aCellElement); + return PR_TRUE; + } + } + nsCOMPtrparent; + if (NS_FAILED(node->GetParentNode(getter_AddRefs(parent))) || !parent) + return PR_FALSE; + node = parent; + } + } + return PR_FALSE; +} nsresult nsEditorShellMouseListener::HandleEvent(nsIDOMEvent* aEvent) @@ -89,52 +153,57 @@ nsresult nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) { nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); - if (!mouseEvent) { + if (!mouseEvent || !mEditorShell) { //non-ui event passed in. bad things. return NS_OK; } + PRUint16 buttonNumber; nsresult res = mouseEvent->GetButton(&buttonNumber); if (NS_FAILED(res)) return res; - // Should we do this only for "right" mouse button? - // What about Mac? - if (mEditorShell && buttonNumber == 3) - { - nsCOMPtr target; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) - { - // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(target); - if (element) - { - // Set selection to node clicked on - mEditorShell->SelectElement(element); - return NS_ERROR_BASE; // consumed - } - } - } - return NS_OK; -} - -nsresult -nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) -{ - nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); - if (!mouseEvent) { - //non-ui event passed in. bad things. - return NS_OK; - } - // Detect double click message: - PRInt32 clickCount; - nsresult res = mouseEvent->GetDetail(&clickCount); + nsCOMPtr targetNode; + res = aMouseEvent->GetTarget(getter_AddRefs(targetNode)); if (NS_FAILED(res)) return res; + if (!targetNode) return NS_ERROR_NULL_POINTER; - nsCOMPtr node; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) + nsCOMPtr element = do_QueryInterface(targetNode); + + if (buttonNumber == 1) { - // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(node); + PRInt32 clickCount; + nsresult res = mouseEvent->GetDetail(&clickCount); + if (NS_FAILED(res)) return res; + +#ifdef DEBUG_cmanske +printf("nsEditorShellMouseListener::MouseDown: clickCount=%d\n",clickCount); +#endif + // Test if special 'table selection' key is pressed when double-clicking + // so we look for an enclosing cell or table + PRBool tableMode = PR_FALSE; + +#ifdef XP_MAC + res = mouseEvent->GetMetaKey(&tableMode); +#else + res = mouseEvent->GetCtrlKey(&tableMode); +#endif + if (NS_FAILED(res)) return res; + if (tableMode && clickCount == 2) + { +#ifdef DEBUG_cmanske +printf("nsEditorShellMouseListener:MouseDown-DoubleClick in TableMode\n"); +#endif + if (!GetParentCell(aMouseEvent, getter_AddRefs(element))) + GetParentTable(aMouseEvent, getter_AddRefs(element)); +#ifdef DEBUG_cmanske + else +printf("nsEditorShellMouseListener::MouseDown-DoubleClick in cell\n"); +#endif + } + // No table or cell -- look for other element (ignore text nodes) + if (!element) + element = do_QueryInterface(targetNode); + if (element) { PRInt32 x,y; @@ -152,6 +221,21 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) return NS_ERROR_BASE; // consumed } } + // Should we do this only for "right" mouse button? + // What about Mac? + else if (buttonNumber == 3) + { + if (element) + // Set selection to node clicked on + mEditorShell->SelectElement(element); + // Always fall through to do other actions, such as context menu + } + return NS_OK; +} + +nsresult +nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) +{ return NS_OK; // didn't handle event } diff --git a/mozilla/editor/base/nsEditorShellMouseListener.h b/mozilla/editor/base/nsEditorShellMouseListener.h index 25014eeb4d2..a4f2658bafc 100644 --- a/mozilla/editor/base/nsEditorShellMouseListener.h +++ b/mozilla/editor/base/nsEditorShellMouseListener.h @@ -25,12 +25,12 @@ #include "nsCOMPtr.h" #include "nsWeakReference.h" - - #include "nsIDOMEvent.h" #include "nsIDOMMouseListener.h" #include "nsIEditorShell.h" +class nsString; + class nsEditorShellMouseListener : public nsIDOMMouseListener, public nsSupportsWeakReference { @@ -62,7 +62,6 @@ public: protected: nsIEditorShell* mEditorShell; // weak reference - }; /** factory for the mouse listener diff --git a/mozilla/editor/composer/src/nsEditorShell.cpp b/mozilla/editor/composer/src/nsEditorShell.cpp index e2db4b30d02..53a36c214fc 100644 --- a/mozilla/editor/composer/src/nsEditorShell.cpp +++ b/mozilla/editor/composer/src/nsEditorShell.cpp @@ -4930,11 +4930,20 @@ nsEditorShell::HandleMouseClickOnElement(nsIDOMElement *aElement, PRInt32 aClick nsCOMPtr composerController = do_QueryInterface(controller); // Execute the command - nsAutoString commandName(NS_ConvertASCIItoUCS2("cmd_advancedProperties")); + nsAutoString commandName; + + // In "All Tags" mode, use AdvancedProperties, + // in others use appriate object property dialog + if (mDisplayMode != eDisplayModeAllTags) + commandName = NS_ConvertASCIItoUCS2("cmd_objectProperties"); + else + commandName = NS_ConvertASCIItoUCS2("cmd_advancedProperties"); + rv = composerController->DoCommand(commandName.GetUnicode()); + // We handled the message -- don't propogate to frames if (NS_SUCCEEDED(rv)) - *_retval = PR_FALSE; + *_retval = PR_TRUE; } return rv; diff --git a/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp b/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp index 79d186172ea..552e96242a7 100644 --- a/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp +++ b/mozilla/editor/composer/src/nsEditorShellMouseListener.cpp @@ -31,6 +31,8 @@ #include "nsIDOMMouseEvent.h" #include "nsIDOMSelection.h" #include "nsIDOMEventTarget.h" +#include "nsIDOMHTMLTableElement.h" +#include "nsIDOMHTMLTableCellElement.h" /* * nsEditorShellMouseListener implementation @@ -39,11 +41,11 @@ NS_IMPL_ADDREF(nsEditorShellMouseListener) NS_IMPL_RELEASE(nsEditorShellMouseListener) - nsEditorShellMouseListener::nsEditorShellMouseListener() { NS_INIT_REFCNT(); } + nsEditorShellMouseListener::~nsEditorShellMouseListener() { } @@ -78,6 +80,68 @@ nsEditorShellMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr) } return NS_NOINTERFACE; } +// Helpers to test if in a table + +PRBool GetParentTable(nsIDOMEvent* aMouseEvent, nsIDOMElement **aTableElement) +{ + nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); + if (!mouseEvent) return PR_FALSE; + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) + { + nsCOMPtr node = do_QueryInterface(target); + + while (node) + { + nsCOMPtr table = do_QueryInterface(node); + if (table) + { + nsCOMPtr tableElement = do_QueryInterface(table); + if (tableElement) + { + *aTableElement = tableElement; + NS_ADDREF(*aTableElement); + return PR_TRUE; + } + } + nsCOMPtrparent; + if (NS_FAILED(node->GetParentNode(getter_AddRefs(parent))) || !parent) + return PR_FALSE; + node = parent; + } + } + return PR_FALSE; +} + +PRBool GetParentCell(nsIDOMEvent* aMouseEvent, nsIDOMElement **aCellElement) +{ + nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); + if (!mouseEvent) return PR_FALSE; + nsCOMPtr target; + if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) + { + nsCOMPtr node = do_QueryInterface(target); + while (node) + { + nsCOMPtr cell = do_QueryInterface(node); + if (cell) + { + nsCOMPtr cellElement = do_QueryInterface(cell); + if (cellElement) + { + *aCellElement = cellElement; + NS_ADDREF(*aCellElement); + return PR_TRUE; + } + } + nsCOMPtrparent; + if (NS_FAILED(node->GetParentNode(getter_AddRefs(parent))) || !parent) + return PR_FALSE; + node = parent; + } + } + return PR_FALSE; +} nsresult nsEditorShellMouseListener::HandleEvent(nsIDOMEvent* aEvent) @@ -89,52 +153,57 @@ nsresult nsEditorShellMouseListener::MouseDown(nsIDOMEvent* aMouseEvent) { nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); - if (!mouseEvent) { + if (!mouseEvent || !mEditorShell) { //non-ui event passed in. bad things. return NS_OK; } + PRUint16 buttonNumber; nsresult res = mouseEvent->GetButton(&buttonNumber); if (NS_FAILED(res)) return res; - // Should we do this only for "right" mouse button? - // What about Mac? - if (mEditorShell && buttonNumber == 3) - { - nsCOMPtr target; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(target))) && target) - { - // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(target); - if (element) - { - // Set selection to node clicked on - mEditorShell->SelectElement(element); - return NS_ERROR_BASE; // consumed - } - } - } - return NS_OK; -} - -nsresult -nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) -{ - nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); - if (!mouseEvent) { - //non-ui event passed in. bad things. - return NS_OK; - } - // Detect double click message: - PRInt32 clickCount; - nsresult res = mouseEvent->GetDetail(&clickCount); + nsCOMPtr targetNode; + res = aMouseEvent->GetTarget(getter_AddRefs(targetNode)); if (NS_FAILED(res)) return res; + if (!targetNode) return NS_ERROR_NULL_POINTER; - nsCOMPtr node; - if (NS_SUCCEEDED(aMouseEvent->GetTarget(getter_AddRefs(node))) && node) + nsCOMPtr element = do_QueryInterface(targetNode); + + if (buttonNumber == 1) { - // We are only interested in elements, not text nodes - nsCOMPtr element = do_QueryInterface(node); + PRInt32 clickCount; + nsresult res = mouseEvent->GetDetail(&clickCount); + if (NS_FAILED(res)) return res; + +#ifdef DEBUG_cmanske +printf("nsEditorShellMouseListener::MouseDown: clickCount=%d\n",clickCount); +#endif + // Test if special 'table selection' key is pressed when double-clicking + // so we look for an enclosing cell or table + PRBool tableMode = PR_FALSE; + +#ifdef XP_MAC + res = mouseEvent->GetMetaKey(&tableMode); +#else + res = mouseEvent->GetCtrlKey(&tableMode); +#endif + if (NS_FAILED(res)) return res; + if (tableMode && clickCount == 2) + { +#ifdef DEBUG_cmanske +printf("nsEditorShellMouseListener:MouseDown-DoubleClick in TableMode\n"); +#endif + if (!GetParentCell(aMouseEvent, getter_AddRefs(element))) + GetParentTable(aMouseEvent, getter_AddRefs(element)); +#ifdef DEBUG_cmanske + else +printf("nsEditorShellMouseListener::MouseDown-DoubleClick in cell\n"); +#endif + } + // No table or cell -- look for other element (ignore text nodes) + if (!element) + element = do_QueryInterface(targetNode); + if (element) { PRInt32 x,y; @@ -152,6 +221,21 @@ nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) return NS_ERROR_BASE; // consumed } } + // Should we do this only for "right" mouse button? + // What about Mac? + else if (buttonNumber == 3) + { + if (element) + // Set selection to node clicked on + mEditorShell->SelectElement(element); + // Always fall through to do other actions, such as context menu + } + return NS_OK; +} + +nsresult +nsEditorShellMouseListener::MouseUp(nsIDOMEvent* aMouseEvent) +{ return NS_OK; // didn't handle event } diff --git a/mozilla/editor/composer/src/nsEditorShellMouseListener.h b/mozilla/editor/composer/src/nsEditorShellMouseListener.h index 25014eeb4d2..a4f2658bafc 100644 --- a/mozilla/editor/composer/src/nsEditorShellMouseListener.h +++ b/mozilla/editor/composer/src/nsEditorShellMouseListener.h @@ -25,12 +25,12 @@ #include "nsCOMPtr.h" #include "nsWeakReference.h" - - #include "nsIDOMEvent.h" #include "nsIDOMMouseListener.h" #include "nsIEditorShell.h" +class nsString; + class nsEditorShellMouseListener : public nsIDOMMouseListener, public nsSupportsWeakReference { @@ -62,7 +62,6 @@ public: protected: nsIEditorShell* mEditorShell; // weak reference - }; /** factory for the mouse listener