Fix for bug 200549:Double click selects just the image in a -moz-user-select:all

subtree


mozilla/editor/libeditor/html/nsHTMLEditor.cpp
    - jfrancis' fix for netscape bug 615240 (applying mozilla patch
      on branch. Fixing problems of improper handling of del and
      backspace keys with file attachments.) which was originally
      landed in revision 1.445.6.3. This patch is necessary to make
      the fix for bug 200549 work properly.

r=sfraser@netscape.com  sr=kin@netscape.com


mozilla/editor/libeditor/html/nsHTMLEditorMouseListener.cpp
mozilla/editor/libeditor/html/nsHTMLEditorMouseListener.h

    - Modified nsHTMLEditorMouseListener::MouseDown() to
      call FindUserSelectAllNode() so that the root of a
      -moz-user-select:all subtree gets selected during
      a double or context click.

    - Modified nsHTMLEditorMouseListener so that it stores an nsHTMLEditor*
      instead of an nsIEditor* so we could have access to FindUserSelectAllNode().

r=brade@netscape.com  sr=sfraser@netscape.com
This commit is contained in:
kin%netscape.com 2003-04-07 14:32:23 +00:00
parent 9885ed4d9c
commit 35f69e36ef
3 changed files with 48 additions and 18 deletions

View File

@ -4012,27 +4012,37 @@ NS_IMETHODIMP nsHTMLEditor::DeleteText(nsIDOMCharacterData *aTextNode,
#endif
/* This routine examines aNode and it's ancestors looking for any node which has the
-moz-user-select: all style lit. Return the ighest such ancestor. */
-moz-user-select: all style lit. Return the highest such ancestor. */
nsCOMPtr<nsIDOMNode> nsHTMLEditor::FindUserSelectAllNode(nsIDOMNode *aNode)
{
nsCOMPtr<nsIDOMNode> resultNode; // starts out empty
nsCOMPtr<nsIDOMNode> node = aNode;
nsCOMPtr<nsIDOMElement>root;
GetRootElement(getter_AddRefs(root));
if (!nsEditorUtils::IsDescendantOf(aNode, root))
return nsnull;
// retrieve the computed style of -moz-user-select for aNode
nsAutoString mozUserSelectValue;
while (node)
{
mHTMLCSSUtils->GetComputedProperty(node, nsIEditProperty::cssMozUserSelect, mozUserSelectValue);
if (!mozUserSelectValue.Equals(NS_LITERAL_STRING("all")))
if (mozUserSelectValue.Equals(NS_LITERAL_STRING("all")))
{
return resultNode;
resultNode = node;
}
resultNode = node;
nsCOMPtr<nsIDOMNode> tmp;
node->GetParentNode(getter_AddRefs(tmp));
node = tmp;
}
if (node != root)
{
nsCOMPtr<nsIDOMNode> tmp;
node->GetParentNode(getter_AddRefs(tmp));
node = tmp;
}
else
{
node = nsnull;
}
}
return resultNode;
}

View File

@ -66,8 +66,10 @@
* moves the caret or selects an element as it does for normal click
*/
nsHTMLEditorMouseListener::nsHTMLEditorMouseListener()
nsHTMLEditorMouseListener::nsHTMLEditorMouseListener(nsHTMLEditor *aHTMLEditor)
: mHTMLEditor(aHTMLEditor)
{
SetEditor(mHTMLEditor); // Tell the base class about the editor.
}
nsHTMLEditorMouseListener::~nsHTMLEditorMouseListener()
@ -85,7 +87,6 @@ nsHTMLEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
//non-ui event passed in. bad things.
return NS_OK;
}
nsresult res;
// Don't do anything special if not an HTML editor
nsCOMPtr<nsIHTMLEditor> htmlEditor = do_QueryInterface(mEditor);
@ -234,6 +235,23 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
// and not the entire body, or table-related elements
if (element)
{
nsCOMPtr<nsIDOMNode> eleNode = do_QueryInterface(element);
if (eleNode)
{
nsCOMPtr<nsIDOMNode> selectAllNode = mHTMLEditor->FindUserSelectAllNode(eleNode);
if (selectAllNode)
{
nsCOMPtr<nsIDOMElement> newElement = do_QueryInterface(selectAllNode);
if (newElement)
{
node = selectAllNode;
element = newElement;
}
}
}
if (nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("body")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("td")) ||
nsTextEditUtils::NodeIsType(node, NS_LITERAL_STRING("th")) ||
@ -263,7 +281,7 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
return NS_OK;
}
}
else if (!isContextClick & buttonNumber == 0 && clickCount == 1)
else if (!isContextClick && buttonNumber == 0 && clickCount == 1)
{
// if the target element is an image, we have to display resizers
nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryInterface(htmlEditor);
@ -279,13 +297,11 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
nsresult
NS_NewHTMLEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult,
nsIEditor *aEditor)
nsHTMLEditor *aHTMLEditor)
{
nsHTMLEditorMouseListener* listener = new nsHTMLEditorMouseListener();
nsHTMLEditorMouseListener* listener = new nsHTMLEditorMouseListener(aHTMLEditor);
if (!listener)
return NS_ERROR_OUT_OF_MEMORY;
listener->SetEditor(aEditor);
return listener->QueryInterface(NS_GET_IID(nsIDOMEventListener), (void **) aInstancePtrResult);
}

View File

@ -48,6 +48,7 @@
#include "nsIPlaintextEditor.h"
#include "nsIHTMLEditor.h"
#include "nsEditorEventListeners.h"
#include "nsHTMLEditor.h"
class nsString;
@ -56,7 +57,7 @@ class nsHTMLEditorMouseListener : public nsTextEditorMouseListener
public:
/** default constructor
*/
nsHTMLEditorMouseListener();
nsHTMLEditorMouseListener(nsHTMLEditor *aHTMLEditor);
/** default destructor
*/
virtual ~nsHTMLEditorMouseListener();
@ -71,11 +72,14 @@ public:
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
/*END implementations of mouseevent handler interface*/
protected:
nsHTMLEditor *mHTMLEditor; // un-addref'd weak pointer
};
/** factory for the mouse listener
*/
extern nsresult NS_NewHTMLEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsIEditor *aEditor);
extern nsresult NS_NewHTMLEditorMouseListener(nsIDOMEventListener ** aInstancePtrResult, nsHTMLEditor *aHTMLEditor);
#endif //htmlEditorMouseListener_h__