void nsHTMLEditor::SetFinalSize(PRInt32 aX, PRInt32 aY) { if (!mResizedObject) { // paranoia return; } if (mActivatedHandle) { mActivatedHandle->RemoveAttribute(NS_LITERAL_STRING("_moz_activated")); mActivatedHandle = nsnull; } // we have now to set the new width and height of the resized object // we don't set the x and y position because we don't control that in // a normal HTML layout PRInt32 left = GetNewResizingX(aX, aY); PRInt32 top = GetNewResizingY(aX, aY); PRInt32 width = GetNewResizingWidth(aX, aY); PRInt32 height = GetNewResizingHeight(aX, aY); PRBool setWidth = !mResizedObjectIsAbsolutelyPositioned || (width != mResizedObjectWidth); PRBool setHeight = !mResizedObjectIsAbsolutelyPositioned || (height != mResizedObjectHeight); 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; GetIsCSSEnabled(&useCSS); // we want one transaction only from a user's point of view nsAutoEditBatch batchIt(this); NS_NAMED_LITERAL_STRING(widthStr, "width"); NS_NAMED_LITERAL_STRING(heightStr, "height"); PRBool hasAttr = PR_FALSE; if (mResizedObjectIsAbsolutelyPositioned) { if (setHeight) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssTop, y, PR_FALSE); if (setWidth) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssLeft, x, PR_FALSE); } if (useCSS || mResizedObjectIsAbsolutelyPositioned) { if (setWidth && NS_SUCCEEDED(mResizedObject->HasAttribute(widthStr, &hasAttr)) && hasAttr) RemoveAttribute(mResizedObject, widthStr); hasAttr = PR_FALSE; if (setHeight && NS_SUCCEEDED(mResizedObject->HasAttribute(heightStr, &hasAttr)) && hasAttr) RemoveAttribute(mResizedObject, heightStr); if (setWidth) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssWidth, width, PR_FALSE); if (setHeight) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssHeight, height, PR_FALSE); } else { // we use HTML size and remove all equivalent CSS properties // we set the CSS width and height to remove it later, // triggering an immediate reflow; otherwise, we have problems // with asynchronous reflow if (setWidth) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssWidth, width, PR_FALSE); if (setHeight) mHTMLCSSUtils->SetCSSPropertyPixels(mResizedObject, nsEditProperty::cssHeight, height, PR_FALSE); if (setWidth) { nsAutoString w; w.AppendInt(width); SetAttribute(mResizedObject, widthStr, w); } if (setHeight) { nsAutoString h; h.AppendInt(height); SetAttribute(mResizedObject, heightStr, h); } if (setWidth) mHTMLCSSUtils->RemoveCSSProperty(mResizedObject, nsEditProperty::cssWidth, EmptyString(), PR_FALSE); if (setHeight) mHTMLCSSUtils->RemoveCSSProperty(mResizedObject, nsEditProperty::cssHeight, EmptyString(), PR_FALSE); } // finally notify the listeners if any PRInt32 listenersCount = objectResizeEventListeners.Count(); if (listenersCount) { nsCOMPtr<nsIHTMLObjectResizeListener> listener; PRInt32 index; for (index = 0; index < listenersCount; index++) { listener = objectResizeEventListeners[index]; listener->OnEndResizing(mResizedObject, mResizedObjectWidth, mResizedObjectHeight, width, height); } } // keep track of that size mResizedObjectWidth = width; mResizedObjectHeight = height; RefreshResizers(); }
void HTMLEditor::SetFinalSize(int32_t aX, int32_t aY) { if (!mResizedObject) { // paranoia return; } if (mActivatedHandle) { mActivatedHandle->UnsetAttr(kNameSpaceID_None, nsGkAtoms::_moz_activated, true); mActivatedHandle = nullptr; } // we have now to set the new width and height of the resized object // we don't set the x and y position because we don't control that in // a normal HTML layout int32_t left = GetNewResizingX(aX, aY); int32_t top = GetNewResizingY(aX, aY); int32_t width = GetNewResizingWidth(aX, aY); int32_t height = GetNewResizingHeight(aX, aY); bool setWidth = !mResizedObjectIsAbsolutelyPositioned || (width != mResizedObjectWidth); bool setHeight = !mResizedObjectIsAbsolutelyPositioned || (height != mResizedObjectHeight); int32_t x, y; x = left - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderLeft+mResizedObjectMarginLeft : 0); y = top - ((mResizedObjectIsAbsolutelyPositioned) ? mResizedObjectBorderTop+mResizedObjectMarginTop : 0); // we want one transaction only from a user's point of view AutoEditBatch batchIt(this); if (mResizedObjectIsAbsolutelyPositioned) { if (setHeight) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::top, y); } if (setWidth) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::left, x); } } if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) { if (setWidth && mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::width)) { RemoveAttribute(mResizedObject, nsGkAtoms::width); } if (setHeight && mResizedObject->HasAttr(kNameSpaceID_None, nsGkAtoms::height)) { RemoveAttribute(mResizedObject, nsGkAtoms::height); } if (setWidth) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width, width); } if (setHeight) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height, height); } } else { // we use HTML size and remove all equivalent CSS properties // we set the CSS width and height to remove it later, // triggering an immediate reflow; otherwise, we have problems // with asynchronous reflow if (setWidth) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::width, width); } if (setHeight) { mCSSEditUtils->SetCSSPropertyPixels(*mResizedObject, *nsGkAtoms::height, height); } if (setWidth) { nsAutoString w; w.AppendInt(width); SetAttribute(mResizedObject, nsGkAtoms::width, w); } if (setHeight) { nsAutoString h; h.AppendInt(height); SetAttribute(mResizedObject, nsGkAtoms::height, h); } if (setWidth) { mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::width, EmptyString()); } if (setHeight) { mCSSEditUtils->RemoveCSSProperty(*mResizedObject, *nsGkAtoms::height, EmptyString()); } } // keep track of that size mResizedObjectWidth = width; mResizedObjectHeight = height; RefreshResizers(); }