зеркало из https://github.com/mozilla/gecko-dev.git
Allow mouse-driven resizing of images and tables in all instances of editor.
For the default Mozilla build, this includes Composer and Mail Composition. Embeddors willing to disable this feature should look at |nsHTMLEditor::SetIsImageResizingEnabled()| Displays eight resizing handles plus an info box. Images are resized real-time. Uses HTML attributes in pure HTML mode (mail composition for instance) and CSS properties when available. Undoable and Redoable. Does not grind coffe and make a good expresso yet. Thanks if you really read to that line. b=47066, r=brade, r=cmanske (for the algo part inheriting from the XBL patch), sr=kin
This commit is contained in:
Родитель
7ccd32e87c
Коммит
7d058dbd34
|
@ -108,3 +108,65 @@ option {
|
|||
-moz-user-input: none ! important;
|
||||
}
|
||||
|
||||
/* the following rules are for Image Resizing */
|
||||
|
||||
*[\_moz_anonclass="mozResizer"] {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
border: 1px black solid;
|
||||
background-color: black;
|
||||
-moz-user-select: none;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizer"].hidden,
|
||||
*[\_moz_anonclass="mozResizingShadow"].hidden,
|
||||
*[\_moz_anonclass="mozResizingInfo"].hidden {
|
||||
display: none ! important;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="nw"] {
|
||||
cursor: nw-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="n"] {
|
||||
cursor: n-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="ne"] {
|
||||
cursor: ne-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="w"] {
|
||||
cursor: w-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="e"] {
|
||||
cursor: e-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="sw"] {
|
||||
cursor: sw-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="s"] {
|
||||
cursor: s-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="se"] {
|
||||
cursor: se-resize;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizingShadow"] {
|
||||
border: thin dashed black;
|
||||
-moz-user-select: none;
|
||||
display: block;
|
||||
-moz-opacity: 0.5;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizingInfo"] {
|
||||
font-family: sans-serif;
|
||||
font-size: x-small;
|
||||
color: black;
|
||||
background-color: #d0d0d0;
|
||||
border: ridge 2px #d0d0d0;
|
||||
padding: 2px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
|
|
@ -26,6 +26,7 @@ nsIDocumentStateListener.idl
|
|||
nsPIEditorTransaction.idl
|
||||
nsIEditor.idl
|
||||
nsIHTMLEditor.idl
|
||||
nsIHTMLObjectResizer.idl
|
||||
nsIURIRefObject.idl
|
||||
nsICiter.idl
|
||||
nsIEditActionListener.idl
|
||||
|
|
|
@ -41,6 +41,7 @@ XPIDLSRCS = \
|
|||
nsIEditorSpellCheck.idl \
|
||||
nsIEditorStyleSheets.idl \
|
||||
nsIHTMLEditor.idl \
|
||||
nsIHTMLObjectResizer.idl \
|
||||
nsIPlaintextEditor.idl \
|
||||
nsITableEditor.idl \
|
||||
nsIURIRefObject.idl \
|
||||
|
|
|
@ -48,6 +48,7 @@
|
|||
#include "nsUnicharUtils.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsIHTMLObjectResizer.h"
|
||||
|
||||
#define kNullCh (PRUnichar('\0'))
|
||||
|
||||
|
@ -262,6 +263,8 @@ NS_IMETHODIMP ChangeCSSInlineStyleTxn::DoTransaction(void)
|
|||
else
|
||||
mRedoAttributeWasSet = PR_TRUE;
|
||||
|
||||
CheckObjectResizing();
|
||||
|
||||
return cssDecl->GetPropertyValue(propertyNameString, mRedoValue);
|
||||
}
|
||||
|
||||
|
@ -305,12 +308,18 @@ nsresult ChangeCSSInlineStyleTxn::SetStyle(PRBool aAttributeWasSet,
|
|||
|
||||
NS_IMETHODIMP ChangeCSSInlineStyleTxn::UndoTransaction(void)
|
||||
{
|
||||
return SetStyle(mUndoAttributeWasSet, mUndoValue);
|
||||
nsresult res = SetStyle(mUndoAttributeWasSet, mUndoValue);
|
||||
if (NS_SUCCEEDED(res))
|
||||
CheckObjectResizing();
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeCSSInlineStyleTxn::RedoTransaction(void)
|
||||
{
|
||||
return SetStyle(mRedoAttributeWasSet, mRedoValue);
|
||||
nsresult res = SetStyle(mRedoAttributeWasSet, mRedoValue);
|
||||
if (NS_SUCCEEDED(res))
|
||||
CheckObjectResizing();
|
||||
return res;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP ChangeCSSInlineStyleTxn::Merge(nsITransaction *aTransaction, PRBool *aDidMerge)
|
||||
|
@ -365,3 +374,18 @@ ChangeCSSInlineStyleTxn::AddValueToMultivalueProperty(nsAString & aValues, const
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
void
|
||||
ChangeCSSInlineStyleTxn::CheckObjectResizing()
|
||||
{
|
||||
// HACK !!!!! We absolutely need this because setting an inline CSS
|
||||
// property does not trigger a DOMAttrModified event related to the
|
||||
// style attribute (perf reasons I suppose)
|
||||
|
||||
nsCOMPtr<nsIHTMLObjectResizer> imageResizer = do_QueryInterface(mEditor);
|
||||
if (imageResizer) {
|
||||
nsCOMPtr<nsIDOMElement> resizedObject;
|
||||
imageResizer->GetResizedObject(getter_AddRefs(resizedObject));
|
||||
if (resizedObject == mElement)
|
||||
imageResizer->RefreshResizers();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -124,6 +124,8 @@ private:
|
|||
*/
|
||||
nsresult SetStyle(PRBool aAttributeWasSet, nsAString & aValue);
|
||||
|
||||
void CheckObjectResizing();
|
||||
|
||||
public:
|
||||
|
||||
NS_IMETHOD DoTransaction(void);
|
||||
|
|
|
@ -159,16 +159,18 @@ public:
|
|||
static nsIAtom *cssFontStyle;
|
||||
static nsIAtom *cssFontWeight;
|
||||
static nsIAtom *cssHeight;
|
||||
static nsIAtom *cssLeft;
|
||||
static nsIAtom *cssListStyleType;
|
||||
static nsIAtom *cssMarginLeft;
|
||||
static nsIAtom *cssMarginRight;
|
||||
static nsIAtom *cssTextAlign;
|
||||
static nsIAtom *cssTextDecoration;
|
||||
static nsIAtom *cssTop;
|
||||
static nsIAtom *cssVerticalAlign;
|
||||
static nsIAtom *cssWhitespace;
|
||||
static nsIAtom *cssWidth;
|
||||
static nsIAtom *cssMozUserSelect;
|
||||
|
||||
static nsIAtom *cssMozUserSelect;
|
||||
|
||||
static nsIAtom *cssPxUnit;
|
||||
static nsIAtom *cssEmUnit;
|
||||
|
|
|
@ -42,6 +42,7 @@ REQUIRES = xpcom \
|
|||
pref \
|
||||
gfx \
|
||||
widget \
|
||||
view \
|
||||
$(NULL)
|
||||
|
||||
# Building the full blown HTML Editor so add its source files and objects:
|
||||
|
@ -54,6 +55,7 @@ CPPSRCS = \
|
|||
nsHTMLEditorStyle.cpp \
|
||||
nsHTMLEditRules.cpp \
|
||||
nsHTMLEditUtils.cpp \
|
||||
nsHTMLObjectResizer.cpp \
|
||||
nsHTMLEditorMouseListener.cpp \
|
||||
nsHTMLURIRefObject.cpp \
|
||||
nsTableEditor.cpp \
|
||||
|
|
|
@ -136,16 +136,18 @@ nsIAtom * nsIEditProperty::cssFontSize;
|
|||
nsIAtom * nsIEditProperty::cssFontStyle;
|
||||
nsIAtom * nsIEditProperty::cssFontWeight;
|
||||
nsIAtom * nsIEditProperty::cssHeight;
|
||||
nsIAtom * nsIEditProperty::cssLeft;
|
||||
nsIAtom * nsIEditProperty::cssListStyleType;
|
||||
nsIAtom * nsIEditProperty::cssMarginLeft;
|
||||
nsIAtom * nsIEditProperty::cssMarginRight;
|
||||
nsIAtom * nsIEditProperty::cssTextAlign;
|
||||
nsIAtom * nsIEditProperty::cssTextDecoration;
|
||||
nsIAtom * nsIEditProperty::cssTop;
|
||||
nsIAtom * nsIEditProperty::cssVerticalAlign;
|
||||
nsIAtom * nsIEditProperty::cssWhitespace;
|
||||
nsIAtom * nsIEditProperty::cssWidth;
|
||||
nsIAtom * nsIEditProperty::cssMozUserSelect;
|
||||
|
||||
nsIAtom * nsIEditProperty::cssMozUserSelect;
|
||||
|
||||
nsIAtom * nsIEditProperty::cssPxUnit;
|
||||
nsIAtom * nsIEditProperty::cssEmUnit;
|
||||
|
@ -275,15 +277,17 @@ nsEditProperty::nsEditProperty()
|
|||
nsIEditProperty::cssFontWeight = NS_NewAtom("font-weight");
|
||||
nsIEditProperty::cssHeight = NS_NewAtom("height");
|
||||
nsIEditProperty::cssListStyleType = NS_NewAtom("list-style-type");
|
||||
nsIEditProperty::cssLeft = NS_NewAtom("left");
|
||||
nsIEditProperty::cssMarginRight = NS_NewAtom("margin-right");
|
||||
nsIEditProperty::cssMarginLeft = NS_NewAtom("margin-left");
|
||||
nsIEditProperty::cssTextAlign = NS_NewAtom("text-align");
|
||||
nsIEditProperty::cssTextDecoration = NS_NewAtom("text-decoration");
|
||||
nsIEditProperty::cssTop = NS_NewAtom("top");
|
||||
nsIEditProperty::cssVerticalAlign = NS_NewAtom("vertical-align");
|
||||
nsIEditProperty::cssWhitespace = NS_NewAtom("white-space");
|
||||
nsIEditProperty::cssWidth = NS_NewAtom("width");
|
||||
nsIEditProperty::cssMozUserSelect = NS_NewAtom("-moz-user-select");
|
||||
|
||||
nsIEditProperty::cssMozUserSelect = NS_NewAtom("-moz-user-select");
|
||||
|
||||
nsIEditProperty::cssPxUnit = NS_NewAtom("px");
|
||||
nsIEditProperty::cssEmUnit = NS_NewAtom("em");
|
||||
|
@ -388,13 +392,16 @@ nsEditProperty::~nsEditProperty()
|
|||
NS_IF_RELEASE(nsIEditProperty::cssFontWeight);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssHeight);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssListStyleType);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssLeft);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssMarginRight);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssMarginLeft);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssTextAlign);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssTextDecoration);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssTop);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssVerticalAlign);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssWhitespace);
|
||||
NS_IF_RELEASE(nsIEditProperty::cssWidth);
|
||||
|
||||
NS_IF_RELEASE(nsIEditProperty::cssMozUserSelect);
|
||||
|
||||
NS_IF_RELEASE(nsIEditProperty::cssPxUnit);
|
||||
|
|
|
@ -136,6 +136,11 @@
|
|||
#include "nsParserCIID.h"
|
||||
#include "nsITextContent.h"
|
||||
#include "nsWSRunObject.h"
|
||||
#include "nsHTMLObjectResizer.h"
|
||||
|
||||
#include "nsIFrame.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
static NS_DEFINE_CID(kCContentIteratorCID, NS_CONTENTITERATOR_CID);
|
||||
static NS_DEFINE_IID(kSubtreeIteratorCID, NS_SUBTREEITERATOR_CID);
|
||||
|
@ -156,6 +161,9 @@ static char hrefText[] = "href";
|
|||
static char anchorTxt[] = "anchor";
|
||||
static char namedanchorText[] = "namedanchor";
|
||||
|
||||
#define kBaseEditorStyleSheet NS_LITERAL_STRING("chrome://editor/content/EditorOverride.css")
|
||||
#define kNormalStyleSheet NS_LITERAL_STRING("chrome://editor/content/EditorContent.css")
|
||||
|
||||
nsCOMPtr<nsIParserService> nsHTMLEditor::sParserService;
|
||||
PRInt32 nsHTMLEditor::sInstanceCount = 0;
|
||||
|
||||
|
@ -172,6 +180,10 @@ nsHTMLEditor::nsHTMLEditor()
|
|||
, mTypeInState(nsnull)
|
||||
, mSelectedCellIndex(0)
|
||||
, mHTMLCSSUtils(nsnull)
|
||||
, mIsImageResizingEnabled(PR_TRUE) // this can be overriden
|
||||
, mIsShowingResizeHandles(PR_FALSE)
|
||||
, mIsResizing(PR_FALSE)
|
||||
, mResizedObject(nsnull)
|
||||
{
|
||||
mBoldAtom = getter_AddRefs(NS_NewAtom("b"));
|
||||
mItalicAtom = getter_AddRefs(NS_NewAtom("i"));
|
||||
|
@ -201,9 +213,14 @@ nsHTMLEditor::~nsHTMLEditor()
|
|||
if (listener) {
|
||||
selPriv->RemoveSelectionListener(listener);
|
||||
}
|
||||
listener = do_QueryInterface(mSelectionListenerP);
|
||||
if (listener) {
|
||||
selPriv->RemoveSelectionListener(listener);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(mTypeInState);
|
||||
mSelectionListenerP = nsnull;
|
||||
|
||||
if (--sInstanceCount == 0 && sParserService)
|
||||
sParserService = 0;
|
||||
|
@ -233,6 +250,11 @@ NS_IMETHODIMP nsHTMLEditor::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
|||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIHTMLObjectResizer))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIHTMLObjectResizer*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIEditorMailSupport))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIEditorMailSupport*, this);
|
||||
NS_ADDREF_THIS();
|
||||
|
@ -316,6 +338,10 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc,
|
|||
if (!mTypeInState) {return NS_ERROR_NULL_POINTER;}
|
||||
NS_ADDREF(mTypeInState);
|
||||
|
||||
// init the selection listener for image resizing
|
||||
mSelectionListenerP = new ResizerSelectionListener(this);
|
||||
if (!mSelectionListenerP) {return NS_ERROR_NULL_POINTER;}
|
||||
|
||||
nsCOMPtr<nsISelection>selection;
|
||||
result = GetSelection(getter_AddRefs(selection));
|
||||
if (NS_FAILED(result)) { return result; }
|
||||
|
@ -327,10 +353,19 @@ NS_IMETHODIMP nsHTMLEditor::Init(nsIDOMDocument *aDoc,
|
|||
if (listener) {
|
||||
selPriv->AddSelectionListener(listener);
|
||||
}
|
||||
listener = do_QueryInterface(mSelectionListenerP);
|
||||
if (listener) {
|
||||
selPriv->AddSelectionListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (NS_FAILED(rulesRes)) return rulesRes;
|
||||
|
||||
result = AddOverrideStyleSheet(kBaseEditorStyleSheet);
|
||||
if (NS_FAILED(result)) return result;
|
||||
return AddOverrideStyleSheet(kNormalStyleSheet);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -5953,3 +5988,56 @@ nsHTMLEditor::CopyLastEditableChildStyles(nsIDOMNode * aPreviousBlock, nsIDOMNod
|
|||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditor::GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & aY)
|
||||
{
|
||||
// we are going to need the PresShell
|
||||
if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED;
|
||||
nsCOMPtr<nsIPresShell> ps = do_QueryReferent(mPresShellWeak);
|
||||
if (!ps) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
|
||||
nsIFrame *frame = 0; // not ref-counted
|
||||
ps->GetPrimaryFrameFor(content, &frame);
|
||||
|
||||
float t2p;
|
||||
nsCOMPtr<nsIPresContext> pcontext;
|
||||
ps->GetPresContext(getter_AddRefs(pcontext));
|
||||
pcontext->GetTwipsToPixels(&t2p);
|
||||
|
||||
|
||||
if (NodeIsType(aElement, NS_LITERAL_STRING("hr"))) {
|
||||
nsIFrame* childFrame;
|
||||
//frame->FirstChild(pcontext, nsnull, &childFrame);
|
||||
frame->GetNextSibling(&childFrame);
|
||||
frame = childFrame;
|
||||
}
|
||||
PRInt32 offsetX = 0, offsetY = 0;
|
||||
nsCOMPtr<nsIWidget> widget;
|
||||
nsresult rv;
|
||||
while (frame) {
|
||||
// Look for a widget so we can get screen coordinates
|
||||
nsIView* view = nsnull;
|
||||
rv = frame->GetView(pcontext, &view);
|
||||
if (NS_SUCCEEDED(rv) && view) {
|
||||
rv = view->GetWidget(*getter_AddRefs(widget));
|
||||
if (widget)
|
||||
break;
|
||||
}
|
||||
|
||||
// No widget yet, so count up the coordinates of the frame
|
||||
nsPoint origin;
|
||||
frame->GetOrigin(origin);
|
||||
offsetX += origin.x;
|
||||
offsetY += origin.y;
|
||||
|
||||
frame->GetParent(&frame);
|
||||
}
|
||||
|
||||
aX = NSTwipsToIntPixels(offsetX , t2p);
|
||||
aY = NSTwipsToIntPixels(offsetY , t2p);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
|
|
@ -65,6 +65,10 @@
|
|||
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsHTMLObjectResizer.h"
|
||||
|
||||
#include "nsPoint.h"
|
||||
|
||||
class nsIDOMKeyEvent;
|
||||
class nsITransferable;
|
||||
class nsIDOMEventReceiver;
|
||||
|
@ -79,6 +83,7 @@ class TypeInState;
|
|||
*/
|
||||
class nsHTMLEditor : public nsPlaintextEditor,
|
||||
public nsIHTMLEditor,
|
||||
public nsIHTMLObjectResizer,
|
||||
public nsITableEditor,
|
||||
public nsIEditorStyleSheets,
|
||||
public nsICSSLoaderObserver
|
||||
|
@ -105,6 +110,13 @@ public:
|
|||
kOpLoadHTML = 3013
|
||||
};
|
||||
|
||||
enum ResizingRequestID
|
||||
{
|
||||
kX = 0,
|
||||
kY = 1,
|
||||
kWidth = 2,
|
||||
kHeight = 3
|
||||
};
|
||||
|
||||
// see nsIHTMLEditor for documentation
|
||||
|
||||
|
@ -123,6 +135,9 @@ public:
|
|||
NS_IMETHOD GetIsDocumentEditable(PRBool *aIsDocumentEditable);
|
||||
NS_IMETHODIMP BeginningOfDocument();
|
||||
|
||||
/* ------------ nsIHTMLObjectResizer methods -------------- */
|
||||
NS_DECL_NSIHTMLOBJECTRESIZER
|
||||
|
||||
/* ------------ nsIHTMLEditor methods -------------- */
|
||||
NS_IMETHOD UpdateBaseURL();
|
||||
|
||||
|
@ -826,6 +841,66 @@ protected:
|
|||
// ... which means that we need an instance count to know when to delete it
|
||||
static PRInt32 sInstanceCount;
|
||||
|
||||
protected:
|
||||
PRPackedBool mIsImageResizingEnabled;
|
||||
PRPackedBool mIsShowingResizeHandles;
|
||||
PRPackedBool mIsResizing;
|
||||
PRPackedBool mPreserveRatio;
|
||||
PRPackedBool mResizedObjectIsAnImage;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mTopLeftHandle;
|
||||
nsCOMPtr<nsIDOMElement> mTopHandle;
|
||||
nsCOMPtr<nsIDOMElement> mTopRightHandle;
|
||||
nsCOMPtr<nsIDOMElement> mLeftHandle;
|
||||
nsCOMPtr<nsIDOMElement> mRightHandle;
|
||||
nsCOMPtr<nsIDOMElement> mBottomLeftHandle;
|
||||
nsCOMPtr<nsIDOMElement> mBottomHandle;
|
||||
nsCOMPtr<nsIDOMElement> mBottomRightHandle;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mResizingShadow;
|
||||
nsCOMPtr<nsIDOMElement> mResizingInfo;
|
||||
|
||||
nsCOMPtr<nsIDOMElement> mResizedObject;
|
||||
|
||||
nsCOMPtr<nsIDOMEventListener> mMouseMotionListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mMutationListenerP;
|
||||
nsCOMPtr<nsISelectionListener> mSelectionListenerP;
|
||||
nsCOMPtr<nsIDOMEventListener> mResizeEventListenerP;
|
||||
|
||||
PRInt32 mOriginalX;
|
||||
PRInt32 mOriginalY;
|
||||
|
||||
PRInt32 mResizedObjectX;
|
||||
PRInt32 mResizedObjectY;
|
||||
PRInt32 mResizedObjectWidth;
|
||||
PRInt32 mResizedObjectHeight;
|
||||
|
||||
PRInt32 mXIncrementFactor;
|
||||
PRInt32 mYIncrementFactor;
|
||||
PRInt32 mWidthIncrementFactor;
|
||||
PRInt32 mHeightIncrementFactor;
|
||||
|
||||
nsresult CreateResizer(nsIDOMElement ** aReturn, PRInt16 aLocation, nsISupportsArray * aArray);
|
||||
void SetResizerPosition(PRInt32 aX, PRInt32 aY, nsIDOMElement *aResizer);
|
||||
nsresult SetAllResizersPosition(nsIDOMElement * aResizedElement, PRInt32 & aX, PRInt32 & aY);
|
||||
nsresult CreateShadow(nsIDOMElement ** aReturn, nsISupportsArray * aArray);
|
||||
nsresult SetShadowPosition(nsIDOMElement *aResizedObject,
|
||||
PRInt32 aX, PRInt32 aY);
|
||||
nsresult CreateResizingInfo(nsIDOMElement ** aReturn, nsISupportsArray * aArray);
|
||||
nsresult SetResizingInfoPosition(PRInt32 aX, PRInt32 aY,
|
||||
PRInt32 aW, PRInt32 aH);
|
||||
|
||||
PRInt32 GetNewResizingIncrement(PRInt32 aX, PRInt32 aY, PRInt32 aID);
|
||||
nsresult StartResizing(nsIDOMElement * aHandle);
|
||||
PRInt32 GetNewResizingX(PRInt32 aX, PRInt32 aY);
|
||||
PRInt32 GetNewResizingY(PRInt32 aX, PRInt32 aY);
|
||||
PRInt32 GetNewResizingWidth(PRInt32 aX, PRInt32 aY);
|
||||
PRInt32 GetNewResizingHeight(PRInt32 aX, PRInt32 aY);
|
||||
void HideShadowAndInfo();
|
||||
void SetFinalSize(PRInt32 aX, PRInt32 aY);
|
||||
void DeleteRefToAnonymousNode(nsIDOMNode * aNode);
|
||||
void SetResizeIncrements(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt32 aH, PRBool aPreserveRatio);
|
||||
nsresult GetElementOrigin(nsIDOMElement * aElement, PRInt32 & aX, PRInt32 & aY);
|
||||
public:
|
||||
|
||||
// friends
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Charles Manske (cmanske@netscape.com)
|
||||
* Daniel Glazman (glazman@netscape.com)
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
|
@ -54,6 +55,7 @@
|
|||
|
||||
#include "nsIEditor.h"
|
||||
#include "nsIHTMLEditor.h"
|
||||
#include "nsIHTMLObjectResizer.h"
|
||||
#include "nsIEditProperty.h"
|
||||
#include "nsTextEditUtils.h"
|
||||
|
||||
|
@ -74,6 +76,36 @@ nsHTMLEditorMouseListener::~nsHTMLEditorMouseListener()
|
|||
|
||||
NS_IMPL_ISUPPORTS_INHERITED1(nsHTMLEditorMouseListener, nsTextEditorMouseListener, nsIDOMMouseListener)
|
||||
|
||||
nsresult
|
||||
nsHTMLEditorMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aMouseEvent);
|
||||
nsCOMPtr<nsIDOMMouseEvent> mouseEvent ( do_QueryInterface(aMouseEvent) );
|
||||
if (!mouseEvent) {
|
||||
//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);
|
||||
if (htmlEditor)
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsresult res = aMouseEvent->GetTarget(getter_AddRefs(target));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!target) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryInterface(htmlEditor);
|
||||
PRInt32 clientX, clientY;
|
||||
mouseEvent->GetClientX(&clientX);
|
||||
mouseEvent->GetClientY(&clientY);
|
||||
objectResizer->MouseUp(clientX, clientY, element);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
||||
{
|
||||
|
@ -111,15 +143,15 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|||
res = mouseEvent->GetDetail(&clickCount);
|
||||
if (NS_FAILED(res)) return res;
|
||||
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsCOMPtr<nsIDOMNSEvent> internalEvent = do_QueryInterface(aMouseEvent);
|
||||
res = internalEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!target) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
if (isContextClick || (buttonNumber == 0 && clickCount == 2))
|
||||
{
|
||||
nsCOMPtr<nsIDOMEventTarget> target;
|
||||
nsCOMPtr<nsIDOMNSEvent> internalEvent = do_QueryInterface(aMouseEvent);
|
||||
res = internalEvent->GetExplicitOriginalTarget(getter_AddRefs(target));
|
||||
if (NS_FAILED(res)) return res;
|
||||
if (!target) return NS_ERROR_NULL_POINTER;
|
||||
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(target);
|
||||
|
||||
nsCOMPtr<nsISelection> selection;
|
||||
mEditor->GetSelection(getter_AddRefs(selection));
|
||||
if (!selection) return NS_OK;
|
||||
|
@ -218,6 +250,11 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|||
}
|
||||
}
|
||||
}
|
||||
// HACK !!! Context click places the caret but the context menu consumes
|
||||
// the event; so we need to check resizing state ourselves
|
||||
nsCOMPtr<nsIHTMLObjectResizer> objectResizer = do_QueryInterface(htmlEditor);
|
||||
objectResizer->CheckResizingState(selection);
|
||||
|
||||
// Prevent bubbling if we changed selection or
|
||||
// for all context clicks
|
||||
if (element || isContextClick)
|
||||
|
@ -226,6 +263,15 @@ nsHTMLEditorMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
|
|||
return NS_OK;
|
||||
}
|
||||
}
|
||||
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);
|
||||
PRInt32 clientX, clientY;
|
||||
mouseEvent->GetClientX(&clientX);
|
||||
mouseEvent->GetClientY(&clientY);
|
||||
objectResizer->MouseDown(clientX, clientY, element);
|
||||
}
|
||||
}
|
||||
|
||||
return nsTextEditorMouseListener::MouseDown(aMouseEvent);
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
*
|
||||
* Contributor(s):
|
||||
* Charles Manske (cmanske@netscape.com)
|
||||
* Daniel Glazman (glazman@netscape.com)
|
||||
*
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
|
@ -67,6 +68,7 @@ public:
|
|||
|
||||
/*BEGIN implementations of mouseevent handler interface*/
|
||||
NS_IMETHOD MouseDown(nsIDOMEvent* aMouseEvent);
|
||||
NS_IMETHOD MouseUp(nsIDOMEvent* aMouseEvent);
|
||||
/*END implementations of mouseevent handler interface*/
|
||||
|
||||
};
|
||||
|
|
|
@ -762,6 +762,14 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIHTMLObjectResizer.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsICiter.idl</PATH>
|
||||
|
@ -864,6 +872,11 @@
|
|||
<PATH>nsIHTMLEditor.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIHTMLObjectResizer.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsICiter.idl</PATH>
|
||||
|
@ -1625,6 +1638,13 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIHTMLObjectResizer.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS></FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsICiter.idl</PATH>
|
||||
|
@ -1727,6 +1747,11 @@
|
|||
<PATH>nsIHTMLEditor.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIHTMLObjectResizer.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsICiter.idl</PATH>
|
||||
|
@ -1823,6 +1848,12 @@
|
|||
<PATH>nsIHTMLEditor.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>editor.xpt</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsIHTMLObjectResizer.idl</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>editor.xpt</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
|
|
|
@ -1077,6 +1077,13 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLObjectResizer.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLEditorMouseListener.cpp</PATH>
|
||||
|
@ -1455,6 +1462,11 @@
|
|||
<PATH>nsHTMLEditor.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLObjectResizer.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLEditorMouseListener.cpp</PATH>
|
||||
|
@ -2666,6 +2678,13 @@
|
|||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLObjectResizer.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
<FILEKIND>Text</FILEKIND>
|
||||
<FILEFLAGS>Debug</FILEFLAGS>
|
||||
</FILE>
|
||||
<FILE>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLEditorMouseListener.cpp</PATH>
|
||||
|
@ -3037,6 +3056,11 @@
|
|||
<PATH>nsHTMLEditor.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLObjectResizer.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLEditorMouseListener.cpp</PATH>
|
||||
|
@ -6220,6 +6244,12 @@
|
|||
<PATH>nsHTMLEditor.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>HTMLEditorDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
<PATH>nsHTMLObjectResizer.cpp</PATH>
|
||||
<PATHFORMAT>MacOS</PATHFORMAT>
|
||||
</FILEREF>
|
||||
<FILEREF>
|
||||
<TARGETNAME>HTMLEditorDebug.shlb</TARGETNAME>
|
||||
<PATHTYPE>Name</PATHTYPE>
|
||||
|
|
|
@ -108,3 +108,65 @@ option {
|
|||
-moz-user-input: none ! important;
|
||||
}
|
||||
|
||||
/* the following rules are for Image Resizing */
|
||||
|
||||
*[\_moz_anonclass="mozResizer"] {
|
||||
width: 4px;
|
||||
height: 4px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
border: 1px black solid;
|
||||
background-color: black;
|
||||
-moz-user-select: none;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizer"].hidden,
|
||||
*[\_moz_anonclass="mozResizingShadow"].hidden,
|
||||
*[\_moz_anonclass="mozResizingInfo"].hidden {
|
||||
display: none ! important;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="nw"] {
|
||||
cursor: nw-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="n"] {
|
||||
cursor: n-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="ne"] {
|
||||
cursor: ne-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="w"] {
|
||||
cursor: w-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="e"] {
|
||||
cursor: e-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="sw"] {
|
||||
cursor: sw-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="s"] {
|
||||
cursor: s-resize;
|
||||
}
|
||||
*[\_moz_anonclass="mozResizer"][anonlocation="se"] {
|
||||
cursor: se-resize;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizingShadow"] {
|
||||
border: thin dashed black;
|
||||
-moz-user-select: none;
|
||||
display: block;
|
||||
-moz-opacity: 0.5;
|
||||
position: absolute;
|
||||
}
|
||||
|
||||
*[\_moz_anonclass="mozResizingInfo"] {
|
||||
font-family: sans-serif;
|
||||
font-size: x-small;
|
||||
color: black;
|
||||
background-color: #d0d0d0;
|
||||
border: ridge 2px #d0d0d0;
|
||||
padding: 2px;
|
||||
position: absolute;
|
||||
display: block;
|
||||
}
|
||||
|
||||
|
|
|
@ -1751,6 +1751,7 @@ function SetDisplayMode(mode)
|
|||
try {
|
||||
var editor = GetCurrentEditor();
|
||||
editor.QueryInterface(nsIEditorStyleSheets);
|
||||
editor instanceof Components.interfaces.nsIHTMLObjectResizer;
|
||||
|
||||
switch (mode)
|
||||
{
|
||||
|
@ -1758,17 +1759,25 @@ function SetDisplayMode(mode)
|
|||
// Disable all extra "edit mode" style sheets
|
||||
editor.enableStyleSheet(kNormalStyleSheet, false);
|
||||
editor.enableStyleSheet(kAllTagsStyleSheet, false);
|
||||
editor.isImageResizingEnabled = true;
|
||||
break;
|
||||
|
||||
case kDisplayModeNormal:
|
||||
editor.addOverrideStyleSheet(kNormalStyleSheet);
|
||||
// Disable ShowAllTags mode
|
||||
editor.enableStyleSheet(kAllTagsStyleSheet, false);
|
||||
editor.isImageResizingEnabled = true;
|
||||
break;
|
||||
|
||||
case kDisplayModeAllTags:
|
||||
editor.addOverrideStyleSheet(kNormalStyleSheet);
|
||||
editor.addOverrideStyleSheet(kAllTagsStyleSheet);
|
||||
// don't allow resizing in AllTags mode because the visible tags
|
||||
// change the computed size of images and tables...
|
||||
if (editor.resizedObject) {
|
||||
editor.hideResizers();
|
||||
}
|
||||
editor.isImageResizingEnabled = false;
|
||||
break;
|
||||
}
|
||||
} catch(e) {}
|
||||
|
|
Загрузка…
Ссылка в новой задаче