diff --git a/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp b/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp index 8f7b21ae5f9..5c7cee3b95a 100644 --- a/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLAbsPosition.cpp @@ -78,6 +78,7 @@ nsHTMLEditor::AbsolutePositionSelection(PRBool aEnabled) kOpRemoveAbsolutePosition, nsIEditor::eNext); + // the line below does not match the code; should it be removed? // Find out if the selection is collapsed: nsCOMPtr selection; nsresult res = GetSelection(getter_AddRefs(selection)); @@ -194,6 +195,7 @@ nsHTMLEditor::RelativeChangeZIndex(PRInt32 aChange) kOpIncreaseZIndex, nsIEditor::eNext); + // brade: can we get rid of this comment? // Find out if the selection is collapsed: nsCOMPtr selection; nsresult res = GetSelection(getter_AddRefs(selection)); @@ -215,8 +217,8 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement, { nsAutoString zIndexStr; *aZindex = 0; - nsCOMPtr node = do_QueryInterface(aElement); - nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(node, + + nsresult res = mHTMLCSSUtils->GetSpecifiedProperty(aElement, nsEditProperty::cssZIndex, zIndexStr); if (NS_FAILED(res)) return res; @@ -224,9 +226,9 @@ nsHTMLEditor::GetElementZIndex(nsIDOMElement * aElement, // we have to look at the positioned ancestors // cf. CSS 2 spec section 9.9.1 nsCOMPtr parentNode; - res = node->GetParentNode(getter_AddRefs(parentNode)); + res = aElement->GetParentNode(getter_AddRefs(parentNode)); if (NS_FAILED(res)) return res; - node = parentNode; + nsCOMPtr node = parentNode; nsAutoString positionStr; while (node && zIndexStr.Equals(NS_LITERAL_STRING("auto")) && @@ -311,8 +313,6 @@ nsHTMLEditor::HideGrabber() NS_ENSURE_TRUE(mGrabber, NS_ERROR_NULL_POINTER); // get the presshell's document observer interface. - - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -324,10 +324,9 @@ nsHTMLEditor::HideGrabber() nsCOMPtr bodyElement; res = GetRootElement(getter_AddRefs(bodyElement)); if (NS_FAILED(res)) return res; - if (!bodyElement) return NS_ERROR_NULL_POINTER; nsCOMPtr bodyContent = do_QueryInterface(bodyElement); - if (!bodyContent) return res; + if (!bodyContent) return NS_ERROR_NULL_POINTER; DeleteRefToAnonymousNode(mGrabber, bodyContent, docObserver); mGrabber = nsnull; @@ -358,9 +357,7 @@ nsHTMLEditor::ShowGrabberOnElement(nsIDOMElement * aElement) if (NS_FAILED(res)) return res; if (!bodyElement) return NS_ERROR_NULL_POINTER; - nsCOMPtr bodyNode( do_QueryInterface(bodyElement) ); - - res = CreateGrabber(bodyNode, getter_AddRefs(mGrabber)); + res = CreateGrabber(bodyElement, getter_AddRefs(mGrabber)); if (NS_FAILED(res)) return res; // and set its position return RefreshGrabber(); @@ -374,10 +371,8 @@ nsHTMLEditor::StartMoving(nsIDOMElement *aHandle) if (NS_FAILED(result)) return result; if (!bodyElement) return NS_ERROR_NULL_POINTER; - nsCOMPtr bodyNode( do_QueryInterface(bodyElement) ); - // now, let's create the resizing shadow - result = CreateShadow(getter_AddRefs(mPositioningShadow), bodyNode, + result = CreateShadow(getter_AddRefs(mPositioningShadow), bodyElement, mAbsolutelyPositionedObject); if (NS_FAILED(result)) return result; result = SetShadowPosition(mPositioningShadow, mAbsolutelyPositionedObject, @@ -388,15 +383,12 @@ nsHTMLEditor::StartMoving(nsIDOMElement *aHandle) mPositioningShadow->RemoveAttribute(NS_LITERAL_STRING("class")); // position it - nsAutoString w, h; - w.AppendInt(mPositionedObjectWidth); - h.AppendInt(mPositionedObjectHeight); - mHTMLCSSUtils->SetCSSProperty(mPositioningShadow, - NS_LITERAL_STRING("width"), - w + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mPositioningShadow, - NS_LITERAL_STRING("height"), - h + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, + NS_LITERAL_STRING("width"), + mPositionedObjectWidth); + mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, + NS_LITERAL_STRING("height"), + mPositionedObjectHeight); mIsMoving = PR_TRUE; return result; @@ -438,7 +430,6 @@ nsresult nsHTMLEditor::EndMoving() { if (mPositioningShadow) { - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -450,7 +441,6 @@ nsHTMLEditor::EndMoving() nsCOMPtr bodyElement; nsresult res = GetRootElement(getter_AddRefs(bodyElement)); if (NS_FAILED(res)) return res; - if (!bodyElement) return NS_ERROR_NULL_POINTER; nsCOMPtr bodyContent( do_QueryInterface(bodyElement) ); if (!bodyContent) return NS_ERROR_FAILURE; @@ -492,14 +482,14 @@ nsHTMLEditor::SetFinalPosition(PRInt32 aX, PRInt32 aY) // we want one transaction only from a user's point of view nsAutoEditBatch batchIt(this); - mHTMLCSSUtils->SetCSSProperty(mAbsolutelyPositionedObject, - nsEditProperty::cssTop, - y + NS_LITERAL_STRING("px"), - PR_FALSE); - mHTMLCSSUtils->SetCSSProperty(mAbsolutelyPositionedObject, - nsEditProperty::cssLeft, - x + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mAbsolutelyPositionedObject, + nsEditProperty::cssTop, + newY, + PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mAbsolutelyPositionedObject, + nsEditProperty::cssLeft, + newX, + PR_FALSE); // keep track of that size mPositionedObjectX = newX; mPositionedObjectY = newY; @@ -532,8 +522,7 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, NS_ENSURE_ARG_POINTER(aElement); nsAutoString positionStr; - nsCOMPtr node = do_QueryInterface(aElement); - mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssPosition, + mHTMLCSSUtils->GetComputedProperty(aElement, nsEditProperty::cssPosition, positionStr); PRBool isPositioned = (positionStr.Equals(NS_LITERAL_STRING("absolute"))); @@ -560,7 +549,7 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, // we may need to create a br if the positioned element is alone in its // container nsCOMPtr parentNode; - res = node->GetParentNode(getter_AddRefs(parentNode)); + res = aElement->GetParentNode(getter_AddRefs(parentNode)); if (NS_FAILED(res)) return res; nsCOMPtr childNodes; @@ -592,7 +581,7 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, nsEditProperty::cssZIndex, emptyStr, PR_FALSE); - if (!nsHTMLEditUtils::IsImage(node)) { + if (!nsHTMLEditUtils::IsImage(aElement)) { mHTMLCSSUtils->RemoveCSSProperty(aElement, nsEditProperty::cssWidth, emptyStr, PR_FALSE); @@ -604,12 +593,12 @@ nsHTMLEditor::AbsolutelyPositionElement(nsIDOMElement * aElement, PRBool hasStyleOrIdOrClass; res = HasStyleOrIdOrClass(aElement, &hasStyleOrIdOrClass); if (NS_FAILED(res)) return res; - if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(node)) { + if (!hasStyleOrIdOrClass && nsHTMLEditUtils::IsDiv(aElement)) { nsCOMPtr htmlRules = do_QueryInterface(mRules); if (!htmlRules) return NS_ERROR_FAILURE; res = htmlRules->MakeSureElemStartsOrEndsOnCR(aElement); if (NS_FAILED(res)) return res; - res = RemoveContainer(node); + res = RemoveContainer(aElement); } } return res; @@ -647,20 +636,16 @@ nsHTMLEditor::GetGridSize(PRUint32 * aSize) NS_IMETHODIMP nsHTMLEditor::SetElementPosition(nsIDOMElement *aElement, PRInt32 aX, PRInt32 aY) { - nsAutoString x, y; - x.AppendInt(aX); - y.AppendInt(aY); - nsAutoEditBatch batchIt(this); - mHTMLCSSUtils->SetCSSProperty(aElement, - nsEditProperty::cssLeft, - x + NS_LITERAL_STRING("px"), - PR_FALSE); - mHTMLCSSUtils->SetCSSProperty(aElement, - nsEditProperty::cssTop, - y + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(aElement, + nsEditProperty::cssLeft, + aX, + PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(aElement, + nsEditProperty::cssTop, + aY, + PR_FALSE); return NS_OK; } diff --git a/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp b/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp index 0a599d9bc85..db5a4b255d6 100644 --- a/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLAnonymousUtils.cpp @@ -123,7 +123,6 @@ nsHTMLEditor::CreateAnonymousElement(const nsAString & aTag, nsIDOMNode * aPare if (!doc) return NS_ERROR_NULL_POINTER; // Get the pres shell - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -232,12 +231,12 @@ nsHTMLEditor::CheckSelectionStateForAnonymousButtons(nsISelection * aSelection) if (mIsObjectResizingEnabled && cellElement) { // we are here because Resizing is enabled AND selection is contained in // a cell - nsCOMPtr tableNode, cellNode = do_QueryInterface(cellElement); + // get the enclosing table - tableNode = GetEnclosingTable(cellNode); if (nsEditProperty::img != focusTagAtom) { // the element container of the selection is not an image, so we'll show // the resizers around the table + nsCOMPtr tableNode = GetEnclosingTable(cellElement); focusElement = do_QueryInterface(tableNode); focusTagAtom = nsEditProperty::table; } @@ -383,13 +382,6 @@ nsHTMLEditor::GetPositionAndDimensions(nsIDOMElement * aElement, void nsHTMLEditor::SetAnonymousElementPosition(PRInt32 aX, PRInt32 aY, nsIDOMElement *aElement) { - nsAutoString x, y; - x.AppendInt(aX); - y.AppendInt(aY); - mHTMLCSSUtils->SetCSSProperty(aElement, - NS_LITERAL_STRING("left"), - x + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(aElement, - NS_LITERAL_STRING("top"), - y + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("left"), aX); + mHTMLCSSUtils->SetCSSPropertyPixels(aElement, NS_LITERAL_STRING("top"), aY); } diff --git a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp index 283eadf184b..30e466829bc 100644 --- a/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLEditorStyle.cpp @@ -66,7 +66,6 @@ NS_IMETHODIMP nsHTMLEditor::AddDefaultProperty(nsIAtom *aProperty, const nsAString & aAttribute, const nsAString & aValue) { - nsresult res = NS_OK; nsString outValue; PRInt32 index; nsString attr(aAttribute); @@ -81,14 +80,13 @@ NS_IMETHODIMP nsHTMLEditor::AddDefaultProperty(nsIAtom *aProperty, PropItem *propItem = new PropItem(aProperty, attr, value); mDefaultStyles.AppendElement((void*)propItem); } - return res; + return NS_OK; } NS_IMETHODIMP nsHTMLEditor::RemoveDefaultProperty(nsIAtom *aProperty, const nsAString & aAttribute, const nsAString & aValue) { - nsresult res = NS_OK; nsString outValue; PRInt32 index; nsString attr(aAttribute); @@ -98,7 +96,7 @@ NS_IMETHODIMP nsHTMLEditor::RemoveDefaultProperty(nsIAtom *aProperty, if (item) delete item; mDefaultStyles.RemoveElementAt(index); } - return res; + return NS_OK; } NS_IMETHODIMP nsHTMLEditor::RemoveAllDefaultProperties() @@ -120,14 +118,12 @@ NS_IMETHODIMP nsHTMLEditor::SetCSSInlineProperty(nsIAtom *aProperty, const nsAString & aAttribute, const nsAString & aValue) { - nsresult res = NS_OK; PRBool useCSS; - GetIsCSSEnabled(&useCSS); if (useCSS) { - res = SetInlineProperty(aProperty, aAttribute, aValue); + return SetInlineProperty(aProperty, aAttribute, aValue); } - return res; + return NS_OK; } NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, @@ -138,9 +134,8 @@ NS_IMETHODIMP nsHTMLEditor::SetInlineProperty(nsIAtom *aProperty, if (!mRules) { return NS_ERROR_NOT_INITIALIZED; } ForceCompositionEnd(); - nsresult res; nsCOMPtrselection; - res = GetSelection(getter_AddRefs(selection)); + nsresult res = GetSelection(getter_AddRefs(selection)); if (NS_FAILED(res)) return res; if (!selection) return NS_ERROR_NULL_POINTER; nsCOMPtr selPriv(do_QueryInterface(selection)); @@ -305,22 +300,21 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, const nsAString *aValue) { if (!aTextNode) return NS_ERROR_NULL_POINTER; - nsresult res = NS_OK; nsCOMPtr parent; - res = aTextNode->GetParentNode(getter_AddRefs(parent)); + nsresult res = aTextNode->GetParentNode(getter_AddRefs(parent)); if (NS_FAILED(res)) return res; + nsAutoString tagString; aProperty->ToString(tagString); if (!CanContainTag(parent, tagString)) return NS_OK; - // dont need to do anything if no characters actually selected + // don't need to do anything if no characters actually selected if (aStartOffset == aEndOffset) return NS_OK; - nsCOMPtr tmp, node = do_QueryInterface(aTextNode); + nsCOMPtr node = do_QueryInterface(aTextNode); - // dont need to do anything if property already set on node + // don't need to do anything if property already set on node PRBool bHasProp; - nsCOMPtr styleNode; PRBool useCSS; GetIsCSSEnabled(&useCSS); @@ -335,13 +329,18 @@ nsHTMLEditor::SetInlinePropertyOnTextNode( nsIDOMCharacterData *aTextNode, COMPUTED_STYLE_TYPE); } else + { + nsCOMPtr styleNode; IsTextPropertySetByContent(node, aProperty, aAttribute, aValue, bHasProp, getter_AddRefs(styleNode)); + } + if (bHasProp) return NS_OK; // do we need to split the text node? PRUint32 textLen; aTextNode->GetLength(&textLen); + nsCOMPtr tmp; if ( (PRUint32)aEndOffset != textLen ) { // we need to split off back of text node diff --git a/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp b/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp index 1477a9e8653..1dcd30cc1c2 100644 --- a/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLInlineTableEditor.cpp @@ -77,25 +77,23 @@ nsHTMLEditor::ShowInlineTableEditingUI(nsIDOMElement * aCell) if (NS_FAILED(res)) return res; if (!bodyElement) return NS_ERROR_NULL_POINTER; - nsCOMPtr bodyNode( do_QueryInterface(bodyElement) ); - - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableAddColumnBefore"), PR_FALSE, getter_AddRefs(mAddColumnBeforeButton)); - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableRemoveColumn"), PR_FALSE, getter_AddRefs(mRemoveColumnButton)); - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableAddColumnAfter"), PR_FALSE, getter_AddRefs(mAddColumnAfterButton)); - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableAddRowBefore"), PR_FALSE, getter_AddRefs(mAddRowBeforeButton)); - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableRemoveRow"), PR_FALSE, getter_AddRefs(mRemoveRowButton)); - CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyNode, + CreateAnonymousElement(NS_LITERAL_STRING("a"), bodyElement, NS_LITERAL_STRING("mozTableAddRowAfter"), PR_FALSE, getter_AddRefs(mAddRowAfterButton)); @@ -123,8 +121,6 @@ nsHTMLEditor::HideInlineTableEditingUI() RemoveMouseClickListener(mAddRowAfterButton); // get the presshell's document observer interface. - - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -171,8 +167,7 @@ nsHTMLEditor::DoInlineTableEditingAction(nsIDOMElement * aElement) if (!StringBeginsWith(anonclass, NS_LITERAL_STRING("mozTable"))) return NS_OK; - nsCOMPtr cellNode = do_QueryInterface(mInlineEditedCell); - nsCOMPtr tableNode = GetEnclosingTable(cellNode); + nsCOMPtr tableNode = GetEnclosingTable(mInlineEditedCell); nsCOMPtr tableElement = do_QueryInterface(tableNode); PRInt32 rowCount, colCount; res = GetTableSize(tableElement, &rowCount, &colCount); @@ -247,8 +242,7 @@ nsHTMLEditor::RefreshInlineTableEditingUI() PRInt32 xHoriz = xCell + wCell/2; PRInt32 yVert = yCell + hCell/2; - nsCOMPtr cellNode = do_QueryInterface(mInlineEditedCell); - nsCOMPtr tableNode = GetEnclosingTable(cellNode); + nsCOMPtr tableNode = GetEnclosingTable(mInlineEditedCell); nsCOMPtr tableElement = do_QueryInterface(tableNode); PRInt32 rowCount, colCount; res = GetTableSize(tableElement, &rowCount, &colCount); @@ -256,15 +250,17 @@ nsHTMLEditor::RefreshInlineTableEditingUI() SetAnonymousElementPosition(xHoriz-10, yCell-7, mAddColumnBeforeButton); #ifdef DISABLE_TABLE_DELETION + NS_NAMED_LITERAL_STRING(classStr, "class"); + if (colCount== 1) { - mRemoveColumnButton->SetAttribute(NS_LITERAL_STRING("class"), + mRemoveColumnButton->SetAttribute(classStr, NS_LITERAL_STRING("hidden")); } else { PRBool hasClass = PR_FALSE; - res = mRemoveColumnButton->HasAttribute(NS_LITERAL_STRING("class"), &hasClass); + res = mRemoveColumnButton->HasAttribute(classStr, &hasClass); if (NS_SUCCEEDED(res) && hasClass) - mRemoveColumnButton->RemoveAttribute(NS_LITERAL_STRING("class")); + mRemoveColumnButton->RemoveAttribute(classStr); #endif SetAnonymousElementPosition(xHoriz-4, yCell-7, mRemoveColumnButton); #ifdef DISABLE_TABLE_DELETION @@ -275,14 +271,14 @@ nsHTMLEditor::RefreshInlineTableEditingUI() SetAnonymousElementPosition(xCell-7, yVert-10, mAddRowBeforeButton); #ifdef DISABLE_TABLE_DELETION if (rowCount== 1) { - mRemoveRowButton->SetAttribute(NS_LITERAL_STRING("class"), + mRemoveRowButton->SetAttribute(classStr, NS_LITERAL_STRING("hidden")); } else { PRBool hasClass = PR_FALSE; - res = mRemoveRowButton->HasAttribute(NS_LITERAL_STRING("class"), &hasClass); + res = mRemoveRowButton->HasAttribute(classStr, &hasClass); if (NS_SUCCEEDED(res) && hasClass) - mRemoveRowButton->RemoveAttribute(NS_LITERAL_STRING("class")); + mRemoveRowButton->RemoveAttribute(classStr); #endif SetAnonymousElementPosition(xCell-7, yVert-4, mRemoveRowButton); #ifdef DISABLE_TABLE_DELETION diff --git a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp index 9351244e3bc..2540cf4937f 100644 --- a/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp +++ b/mozilla/editor/libeditor/html/nsHTMLObjectResizer.cpp @@ -138,19 +138,17 @@ ResizerMouseMotionListener::~ResizerMouseMotionListener() NS_IMETHODIMP ResizerMouseMotionListener::MouseMove(nsIDOMEvent* aMouseEvent) { - NS_ENSURE_ARG_POINTER(aMouseEvent); nsCOMPtr mouseEvent ( do_QueryInterface(aMouseEvent) ); if (!mouseEvent) { //non-ui event passed in. bad things. return NS_OK; } - // Don't do anything special if not an HTML editor - nsCOMPtr htmlEditor = do_QueryInterface(mEditor); - if (htmlEditor) + // Don't do anything special if not an HTML object resizer editor + nsCOMPtr objectResizer = do_QueryInterface(mEditor); + if (objectResizer) { // check if we have to redisplay a resizing shadow - nsCOMPtr objectResizer = do_QueryInterface(htmlEditor); objectResizer->MouseMove(aMouseEvent); } @@ -277,10 +275,9 @@ nsHTMLEditor::SetAllResizersPosition() nsAutoString value; float resizerWidth, resizerHeight; nsCOMPtr dummyUnit; - nsCOMPtr node = do_QueryInterface(mTopLeftHandle); - mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssWidth, value); + mHTMLCSSUtils->GetComputedProperty(mTopLeftHandle, nsEditProperty::cssWidth, value); mHTMLCSSUtils->ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit)); - mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssHeight, value); + mHTMLCSSUtils->GetComputedProperty(mTopLeftHandle, nsEditProperty::cssHeight, value); mHTMLCSSUtils->ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit)); PRInt32 rw = (PRInt32)((resizerWidth + 1) / 2); @@ -336,34 +333,32 @@ nsHTMLEditor::ShowResizers(nsIDOMElement *aResizedElement) if (NS_FAILED(res)) return res; if (!bodyElement) return NS_ERROR_NULL_POINTER; - nsCOMPtr bodyNode( do_QueryInterface(bodyElement) ); - // let's create the resizers res = CreateResizer(getter_AddRefs(mTopLeftHandle), - nsIHTMLObjectResizer::eTopLeft, bodyNode); + nsIHTMLObjectResizer::eTopLeft, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mTopHandle), - nsIHTMLObjectResizer::eTop, bodyNode); + nsIHTMLObjectResizer::eTop, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mTopRightHandle), - nsIHTMLObjectResizer::eTopRight, bodyNode); + nsIHTMLObjectResizer::eTopRight, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mLeftHandle), - nsIHTMLObjectResizer::eLeft, bodyNode); + nsIHTMLObjectResizer::eLeft, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mRightHandle), - nsIHTMLObjectResizer::eRight, bodyNode); + nsIHTMLObjectResizer::eRight, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mBottomLeftHandle), - nsIHTMLObjectResizer::eBottomLeft, bodyNode); + nsIHTMLObjectResizer::eBottomLeft, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mBottomHandle), - nsIHTMLObjectResizer::eBottom, bodyNode); + nsIHTMLObjectResizer::eBottom, bodyElement); if (NS_FAILED(res)) return res; res = CreateResizer(getter_AddRefs(mBottomRightHandle), - nsIHTMLObjectResizer::eBottomRight, bodyNode); + nsIHTMLObjectResizer::eBottomRight, bodyElement); if (NS_FAILED(res)) return res; res = GetPositionAndDimensions(aResizedElement, @@ -382,7 +377,7 @@ nsHTMLEditor::ShowResizers(nsIDOMElement *aResizedElement) if (NS_FAILED(res)) return res; // now, let's create the resizing shadow - res = CreateShadow(getter_AddRefs(mResizingShadow), bodyNode, + res = CreateShadow(getter_AddRefs(mResizingShadow), bodyElement, aResizedElement); if (NS_FAILED(res)) return res; // and set its position @@ -391,7 +386,7 @@ nsHTMLEditor::ShowResizers(nsIDOMElement *aResizedElement) if (NS_FAILED(res)) return res; // and then the resizing info tooltip - res = CreateResizingInfo(getter_AddRefs(mResizingInfo), bodyNode); + res = CreateResizingInfo(getter_AddRefs(mResizingInfo), bodyElement); if (NS_FAILED(res)) return res; @@ -423,8 +418,6 @@ nsHTMLEditor::HideResizers(void) return NS_OK; // get the presshell's document observer interface. - - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; @@ -586,15 +579,12 @@ nsHTMLEditor::StartResizing(nsIDOMElement *aHandle) mResizingShadow->RemoveAttribute(NS_LITERAL_STRING("class")); // position it - nsAutoString w, h; - w.AppendInt(mResizedObjectWidth); - h.AppendInt(mResizedObjectHeight); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - NS_LITERAL_STRING("width"), - w + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - NS_LITERAL_STRING("height"), - h + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + NS_LITERAL_STRING("width"), + mResizedObjectWidth); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + NS_LITERAL_STRING("height"), + mResizedObjectHeight); // add a mouse move listener to the editor if (!mMouseMotionListenerP) { @@ -683,9 +673,6 @@ nsHTMLEditor::SetResizeIncrements(PRInt32 aX, PRInt32 aY, nsresult nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt32 aH) { - // get the root content - nsCOMPtr rootContent; - nsCOMPtr domdoc; nsEditor::GetDocument(getter_AddRefs(domdoc)); @@ -693,6 +680,8 @@ nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt3 if (!doc) return NS_ERROR_UNEXPECTED; + // get the root content + nsCOMPtr rootContent; doc->GetRootContent(getter_AddRefs(rootContent)); nsCOMPtr nsElement = do_QueryInterface(rootContent); if (!nsElement) {return NS_ERROR_NULL_POINTER; } @@ -707,19 +696,16 @@ nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt3 if (mInfoYIncrement < 0) aY = h - aY; - nsAutoString xStr, yStr; - xStr.AppendInt(aX + PR_ABS(mInfoXIncrement)); - yStr.AppendInt(aY + PR_ABS(mInfoYIncrement)); NS_NAMED_LITERAL_STRING(rightStr, "right"); NS_NAMED_LITERAL_STRING(leftStr, "left"); NS_NAMED_LITERAL_STRING(topStr, "top"); NS_NAMED_LITERAL_STRING(bottomStr, "bottom"); - mHTMLCSSUtils->SetCSSProperty(mResizingInfo, - (mInfoXIncrement < 0) ? rightStr : leftStr, - xStr + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mResizingInfo, - (mInfoYIncrement < 0) ? bottomStr : topStr, - yStr + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, + (mInfoXIncrement < 0) ? rightStr : leftStr, + aX + PR_ABS(mInfoXIncrement)); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, + (mInfoYIncrement < 0) ? bottomStr : topStr, + aY + PR_ABS(mInfoYIncrement)); mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo, (mInfoXIncrement >= 0) ? rightStr : leftStr); @@ -728,27 +714,22 @@ nsHTMLEditor::SetResizingInfoPosition(PRInt32 aX, PRInt32 aY, PRInt32 aW, PRInt3 // let's make sure the info box does not go beyond the limits of the viewport nsAutoString value; - nsCOMPtr node = do_QueryInterface(mResizingInfo); float f; nsCOMPtr unit; if (mInfoXIncrement < 0) { - mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssLeft, value); + mHTMLCSSUtils->GetComputedProperty(mResizingInfo, nsEditProperty::cssLeft, value); mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit)); if (f <= 0) { - mHTMLCSSUtils->SetCSSProperty(mResizingInfo, - leftStr, - NS_LITERAL_STRING("0px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, leftStr, 0); mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo, rightStr); } } if (mInfoYIncrement < 0) { - mHTMLCSSUtils->GetComputedProperty(node, nsEditProperty::cssTop, value); + mHTMLCSSUtils->GetComputedProperty(mResizingInfo, nsEditProperty::cssTop, value); mHTMLCSSUtils->ParseLength(value, &f, getter_AddRefs(unit)); if (f <= 0) { - mHTMLCSSUtils->SetCSSProperty(mResizingInfo, - topStr, - NS_LITERAL_STRING("0px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingInfo, topStr, 0); mHTMLCSSUtils->RemoveCSSProperty(mResizingInfo, bottomStr); } @@ -897,8 +878,6 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) { NS_NAMED_LITERAL_STRING(leftStr, "left"); NS_NAMED_LITERAL_STRING(topStr, "top"); - NS_NAMED_LITERAL_STRING(widthStr, "width"); - NS_NAMED_LITERAL_STRING(heightStr, "height"); if (mIsResizing) { // we are resizing and the mouse pointer's position has changed @@ -908,26 +887,21 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); - nsAutoString x, y, w, h; PRInt32 newWidth = GetNewResizingWidth(clientX, clientY); PRInt32 newHeight = GetNewResizingHeight(clientX, clientY); - x.AppendInt(GetNewResizingX(clientX, clientY)); - y.AppendInt(GetNewResizingY(clientX, clientY)); - w.AppendInt(newWidth); - h.AppendInt(newHeight); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - leftStr, - x + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - topStr, - y + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - widthStr, - w + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mResizingShadow, - heightStr, - h + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + leftStr, + GetNewResizingX(clientX, clientY)); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + topStr, + GetNewResizingY(clientX, clientY)); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + NS_LITERAL_STRING("width"), + newWidth); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizingShadow, + NS_LITERAL_STRING("height"), + newHeight); return SetResizingInfoPosition(clientX, clientY, newWidth, newHeight); } @@ -938,7 +912,6 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); - if (!mPresShellWeak) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr ps = do_QueryReferent(mPresShellWeak); if (!ps) return NS_ERROR_NOT_INITIALIZED; nsCOMPtr pcontext; @@ -947,7 +920,7 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) nsCOMPtr look; nsresult res = pcontext->GetLookAndFeel(getter_AddRefs(look)); - PRInt32 xThreshold, yThreshold; + PRInt32 xThreshold=1, yThreshold=1; if (NS_SUCCEEDED(res) && look) { look->GetMetric(nsILookAndFeel::eMetric_DragThresholdX, xThreshold); look->GetMetric(nsILookAndFeel::eMetric_DragThresholdY, yThreshold); @@ -965,22 +938,13 @@ nsHTMLEditor::MouseMove(nsIDOMEvent* aMouseEvent) mouseEvent->GetClientX(&clientX); mouseEvent->GetClientY(&clientY); - nsAutoString x, y, w, h; PRInt32 newX = mPositionedObjectX + clientX - mOriginalX; PRInt32 newY = mPositionedObjectY + clientY - mOriginalY; SnapToGrid(newX, newY); - x.AppendInt(newX); - y.AppendInt(newY); - w.AppendInt(mPositionedObjectWidth); - h.AppendInt(mPositionedObjectHeight); - mHTMLCSSUtils->SetCSSProperty(mPositioningShadow, - leftStr, - x + NS_LITERAL_STRING("px")); - mHTMLCSSUtils->SetCSSProperty(mPositioningShadow, - topStr, - y + NS_LITERAL_STRING("px")); + mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, leftStr, newX); + mHTMLCSSUtils->SetCSSPropertyPixels(mPositioningShadow, topStr, newY); } return NS_OK; } @@ -1008,11 +972,9 @@ nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) PRBool setWidth = !mResizedObjectIsAbsolutelyPositioned || (width != mResizedObjectWidth); PRBool setHeight = !mResizedObjectIsAbsolutelyPositioned || (height != mResizedObjectHeight); - nsAutoString x, y, w, h; - x.AppendInt(left - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderLeft+mResizedObjectMarginLeft : 0)); - y.AppendInt(top - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderTop+mResizedObjectMarginTop : 0)); - w.AppendInt(width); - h.AppendInt(height); + PRInt32 x, y; + x = left - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderLeft+mResizedObjectMarginLeft : 0); + y = top - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderTop+mResizedObjectMarginTop : 0); // we need to know if we're in a CSS-enabled editor or not PRBool useCSS; @@ -1027,15 +989,15 @@ nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) PRBool hasAttr = PR_FALSE; if (mResizedObjectIsAbsolutelyPositioned) { if (setHeight) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, - nsEditProperty::cssTop, - y + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, + nsEditProperty::cssTop, + y, + PR_FALSE); if (setWidth) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, - nsEditProperty::cssLeft, - x + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, + nsEditProperty::cssLeft, + x, + PR_FALSE); } if (useCSS || mResizedObjectIsAbsolutelyPositioned) { if (setWidth && NS_SUCCEEDED(mResizedObject->HasAttribute(widthStr, &hasAttr)) && hasAttr) @@ -1046,14 +1008,14 @@ nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) RemoveAttribute(mResizedObject, heightStr); if (setWidth) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, - nsEditProperty::cssWidth, - w + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, + nsEditProperty::cssWidth, + width, + PR_FALSE); if (setHeight) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssHeight, - h + NS_LITERAL_STRING("px"), + height, PR_FALSE); } else { @@ -1063,20 +1025,26 @@ nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) // triggering an immediate reflow; otherwise, we have problems // with asynchronous reflow if (setWidth) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, - nsEditProperty::cssWidth, - w + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, + nsEditProperty::cssWidth, + width, + PR_FALSE); if (setHeight) - mHTMLCSSUtils->SetCSSProperty(mResizedObject, - nsEditProperty::cssHeight, - h + NS_LITERAL_STRING("px"), - PR_FALSE); + mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, + nsEditProperty::cssHeight, + height, + PR_FALSE); - if (setWidth) + if (setWidth) { + nsAutoString w; + w.AppendInt(width); SetAttribute(mResizedObject, widthStr, w); - if (setHeight) + } + if (setHeight) { + nsAutoString h; + h.AppendInt(height); SetAttribute(mResizedObject, heightStr, h); + } if (setWidth) mHTMLCSSUtils->RemoveCSSProperty(mResizedObject,