/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// add the mouse listener so we can detect a click on a resizer
DebugOnly<nsresult> rvIgnored =
resizer->AddEventListener(u"mousedown"_ns, mEventListener, true);
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored), "EventTarget::AddEventListener(mousedown) failed, but ignored");
nsAutoString locationStr; switch (aLocation) { case nsIHTMLObjectResizer::eTopLeft:
locationStr = kTopLeft; break; case nsIHTMLObjectResizer::eTop:
locationStr = kTop; break; case nsIHTMLObjectResizer::eTopRight:
locationStr = kTopRight; break;
case nsIHTMLObjectResizer::eLeft:
locationStr = kLeft; break; case nsIHTMLObjectResizer::eRight:
locationStr = kRight; break;
case nsIHTMLObjectResizer::eBottomLeft:
locationStr = kBottomLeft; break; case nsIHTMLObjectResizer::eBottom:
locationStr = kBottom; break; case nsIHTMLObjectResizer::eBottomRight:
locationStr = kBottomRight; break;
}
ManualNACPtr HTMLEditor::CreateShadow(nsIContent& aParentContent,
Element& aOriginalObject) { // let's create an image through the element factory
RefPtr<nsAtom> name; if (HTMLEditUtils::IsImage(&aOriginalObject)) {
name = nsGkAtoms::img;
} else {
name = nsGkAtoms::span;
}
ManualNACPtr HTMLEditor::CreateResizingInfo(nsIContent& aParentContent) { // let's create an info box through the element factory return CreateAnonymousElement(nsGkAtoms::span, aParentContent,
u"mozResizingInfo"_ns, true);
}
nsresult HTMLEditor::SetAllResizersPosition() { if (NS_WARN_IF(!mTopLeftHandle)) { return NS_ERROR_FAILURE; // There are no resizers.
}
int32_t x = mResizedObjectX;
int32_t y = mResizedObjectY;
int32_t w = mResizedObjectWidth;
int32_t h = mResizedObjectHeight;
nsAutoString value; float resizerWidth, resizerHeight;
RefPtr<nsAtom> dummyUnit;
DebugOnly<nsresult> rvIgnored = NS_OK;
OwningNonNull<Element> topLeftHandle = *mTopLeftHandle.get(); // XXX Do we really need to computed value rather than specified value? // Because it's an anonymous node.
rvIgnored = CSSEditUtils::GetComputedProperty(*topLeftHandle,
*nsGkAtoms::width, value); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED;
} if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) { return NS_ERROR_FAILURE;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "CSSEditUtils::GetComputedProperty(nsGkAtoms::width) " "failed, but ignored");
rvIgnored = CSSEditUtils::GetComputedProperty(*topLeftHandle,
*nsGkAtoms::height, value); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED;
} if (NS_WARN_IF(topLeftHandle != mTopLeftHandle)) { return NS_ERROR_FAILURE;
}
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "CSSEditUtils::GetComputedProperty(nsGkAtoms::height) " "failed, but ignored");
CSSEditUtils::ParseLength(value, &resizerWidth, getter_AddRefs(dummyUnit));
CSSEditUtils::ParseLength(value, &resizerHeight, getter_AddRefs(dummyUnit));
// While moving each resizer, mutation event listener may hide the resizers. // And in worst case, new resizers may be recreated. So, we need to store // all resizers here, and then, if we detect a resizer is removed or replaced, // we should do nothing anymore. // FYI: Note that only checking if mTopLeftHandle is replaced is enough. // We're may be in hot path if user resizes an element a lot. So, // we should just add-ref mTopLeftHandle. auto setHandlePosition =
[this](ManualNACPtr& aHandleElement, int32_t aNewX, int32_t aNewY)
MOZ_CAN_RUN_SCRIPT_FOR_DEFINITION -> nsresult {
RefPtr<nsStyledElement> handleStyledElement =
nsStyledElement::FromNodeOrNull(aHandleElement.get()); if (!handleStyledElement) { return NS_OK;
}
nsresult rv = SetAnonymousElementPositionWithoutTransaction(
*handleStyledElement, aNewX, aNewY); if (NS_FAILED(rv)) {
NS_WARNING( "HTMLEditor::SetAnonymousElementPositionWithoutTransaction() " "failed"); return rv;
} return NS_WARN_IF(handleStyledElement != aHandleElement.get())
? NS_ERROR_FAILURE
: NS_OK;
};
nsresult rv;
rv = setHandlePosition(mTopLeftHandle, x - rw, y - rh); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set top-left handle position"); return rv;
}
rv = setHandlePosition(mTopHandle, x + w / 2 - rw, y - rh); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set top handle position"); return rv;
}
rv = setHandlePosition(mTopRightHandle, x + w - rw - 1, y - rh); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set top-right handle position"); return rv;
}
rv = setHandlePosition(mLeftHandle, x - rw, y + h / 2 - rh); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set left handle position"); return rv;
}
rv = setHandlePosition(mRightHandle, x + w - rw - 1, y + h / 2 - rh); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set right handle position"); return rv;
}
rv = setHandlePosition(mBottomLeftHandle, x - rw, y + h - rh - 1); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set bottom-left handle position"); return rv;
}
rv = setHandlePosition(mBottomHandle, x + w / 2 - rw, y + h - rh - 1); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set bottom handle position"); return rv;
}
rv = setHandlePosition(mBottomRightHandle, x + w - rw - 1, y + h - rh - 1); if (NS_FAILED(rv)) {
NS_WARNING("Failed to set bottom-right handle position"); return rv;
}
// Don't warn even if resizers are not visible since script cannot check // if they are visible and this is non-virtual method. So, the cost of // calling this can be ignored. if (!mResizedObject) { return NS_OK;
}
rv = SetAllResizersPosition(); if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetAllResizersPosition() failed"); return rv;
} if (NS_WARN_IF(resizedObject != mResizedObject)) { return NS_ERROR_FAILURE;
}
MOZ_ASSERT(
mResizingShadow, "SetAllResizersPosition() should return error if resizers are hidden");
RefPtr<Element> resizingShadow = mResizingShadow.get();
rv = SetShadowPosition(*resizingShadow, resizedObject, mResizedObjectX,
mResizedObjectY); if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetShadowPosition() failed"); return rv;
} if (NS_WARN_IF(resizedObject != mResizedObject)) { return NS_ERROR_FAILURE;
} return NS_OK;
}
nsresult HTMLEditor::ShowResizersInternal(Element& aResizedElement) { // When we have visible resizers, we cannot show new resizers. // So, the caller should call HideResizersInternal() first if this // returns error. if (NS_WARN_IF(mResizedObject)) { return NS_ERROR_UNEXPECTED;
}
nsCOMPtr<nsIContent> parentContent = aResizedElement.GetParent(); if (NS_WARN_IF(!parentContent)) { return NS_ERROR_FAILURE;
}
// Let's create and setup resizers. If we failed something, we should // cancel everything which we do in this method. do {
mResizedObject = &aResizedElement;
// The resizers and the shadow will be anonymous siblings of the element. // Note that creating a resizer or shadow may causes calling // HideRisizersInternal() via a mutation event listener. So, we should // store new resizer to a local variable, then, check: // - whether creating resizer is already set to the member or not // - whether resizing element is changed to another element // If showing resizers are canceled, we hit the latter check. // If resizers for another element is shown during this, we hit the latter // check too. // If resizers are just shown again for same element, we hit the former // check.
ManualNACPtr newResizer =
CreateResizer(nsIHTMLObjectResizer::eTopLeft, *parentContent); if (!newResizer) {
NS_WARNING("HTMLEditor::CreateResizer(eTopLeft) failed"); break;
} if (NS_WARN_IF(mTopLeftHandle) ||
NS_WARN_IF(mResizedObject != &aResizedElement)) { // Don't hide current resizers in this case because they are not what // we're creating. return NS_ERROR_FAILURE;
}
mTopLeftHandle = std::move(newResizer);
newResizer = CreateResizer(nsIHTMLObjectResizer::eTop, *parentContent); if (!newResizer) {
NS_WARNING("HTMLEditor::CreateResizer(eTop) failed"); break;
} if (NS_WARN_IF(mTopHandle) ||
NS_WARN_IF(mResizedObject != &aResizedElement)) { return NS_ERROR_FAILURE;
}
mTopHandle = std::move(newResizer);
newResizer = CreateResizer(nsIHTMLObjectResizer::eTopRight, *parentContent); if (!newResizer) {
NS_WARNING("HTMLEditor::CreateResizer(eTopRight) failed"); break;
} if (NS_WARN_IF(mTopRightHandle) ||
NS_WARN_IF(mResizedObject != &aResizedElement)) { return NS_ERROR_FAILURE;
}
mTopRightHandle = std::move(newResizer);
// Store the last resizer which we created. This is useful when we // need to check whether our resizers are hiddedn and recreated another // set of resizers or not.
RefPtr<Element> createdBottomRightHandle = mBottomRightHandle.get();
// and let's set their absolute positions in the document
rv = SetAllResizersPosition(); if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetAllResizersPosition() failed"); if (NS_WARN_IF(mBottomRightHandle.get() != createdBottomRightHandle)) { return NS_ERROR_FAILURE;
} break;
}
// and set its position
RefPtr<Element> resizingShadow = mResizingShadow.get();
rv = SetShadowPosition(*resizingShadow, aResizedElement, mResizedObjectX,
mResizedObjectY); if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetShadowPosition() failed"); if (NS_WARN_IF(mBottomRightHandle.get() != createdBottomRightHandle)) { return NS_ERROR_FAILURE;
} break;
}
// and then the resizing info tooltip
ManualNACPtr newResizingInfo = CreateResizingInfo(*parentContent); if (!newResizingInfo) {
NS_WARNING("HTMLEditor::CreateResizingInfo() failed"); break;
} if (NS_WARN_IF(mResizingInfo) ||
NS_WARN_IF(mResizedObject != &aResizedElement)) { return NS_ERROR_FAILURE;
}
mResizingInfo = std::move(newResizingInfo);
// and listen to the "resize" event on the window first, get the // window from the document... if (NS_WARN_IF(!mEventListener)) { break;
}
nsresult HTMLEditor::HideResizersInternal() { // Don't warn even if resizers are visible since script cannot check // if they are visible and this is non-virtual method. So, the cost of // calling this can be ignored. if (!mResizedObject) { return NS_OK;
}
// get the presshell's document observer interface.
RefPtr<PresShell> presShell = GetPresShell();
NS_WARNING_ASSERTION(presShell, "There is no presShell"); // We allow the pres shell to be null; when it is, we presume there // are no document observers to notify, but we still want to // UnbindFromTree.
constexpr auto mousedown = u"mousedown"_ns;
// HTMLEditor should forget all members related to resizers first since // removing a part of UI may cause showing the resizers again. In such // case, the members may be overwritten by ShowResizers() and this will // lose the chance to release the old resizers.
ManualNACPtr topLeftHandle(std::move(mTopLeftHandle));
ManualNACPtr topHandle(std::move(mTopHandle));
ManualNACPtr topRightHandle(std::move(mTopRightHandle));
ManualNACPtr leftHandle(std::move(mLeftHandle));
ManualNACPtr rightHandle(std::move(mRightHandle));
ManualNACPtr bottomLeftHandle(std::move(mBottomLeftHandle));
ManualNACPtr bottomHandle(std::move(mBottomHandle));
ManualNACPtr bottomRightHandle(std::move(mBottomRightHandle));
ManualNACPtr resizingShadow(std::move(mResizingShadow));
ManualNACPtr resizingInfo(std::move(mResizingInfo));
RefPtr<Element> activatedHandle(std::move(mActivatedHandle));
RefPtr<Element> resizedObject(std::move(mResizedObject));
// Remvoe all handles.
RemoveListenerAndDeleteRef(mousedown, mEventListener, true,
std::move(topLeftHandle), presShell);
if (classList.Contains(u"mozResizer"_ns)) {
AutoEditActionDataSetter editActionData(*this,
EditAction::eResizingElement); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED;
}
// If we have an anonymous element and that element is a resizer, // let's start resizing!
aMouseDownEvent.PreventDefault();
mOriginalX = aMouseDownEvent.ClientX();
mOriginalY = aMouseDownEvent.ClientY();
nsresult rv = StartResizing(aEventTargetElement);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::StartResizing() failed"); return EditorBase::ToGenericNSResult(rv);
}
if (classList.Contains(u"mozGrabber"_ns)) {
AutoEditActionDataSetter editActionData(*this, EditAction::eMovingElement); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED;
}
// If we have an anonymous element and that element is a grabber, // let's start moving the element!
mOriginalX = aMouseDownEvent.ClientX();
mOriginalY = aMouseDownEvent.ClientY();
nsresult rv = GrabberClicked();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::GrabberClicked() failed"); return EditorBase::ToGenericNSResult(rv);
}
return NS_OK;
}
nsresult HTMLEditor::StopDraggingResizerOrGrabberAt( const CSSIntPoint& aClientPoint) { if (mIsResizing) {
AutoEditActionDataSetter editActionData(*this, EditAction::eResizeElement); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED;
}
// we are resizing and release the mouse button, so let's // end the resizing process
mIsResizing = false;
HideShadowAndInfo();
nsresult HTMLEditor::SetResizingInfoPosition(int32_t aX, int32_t aY, int32_t aW,
int32_t aH) { // Determine the position of the resizing info box based upon the new // position and size of the element (aX, aY, aW, aH), and which // resizer is the "activated handle". For example, place the resizing // info box at the bottom-right corner of the new element, if the element // is being resized by the bottom-right resizer.
int32_t infoXPosition;
int32_t infoYPosition;
if (mActivatedHandle == mTopLeftHandle || mActivatedHandle == mLeftHandle ||
mActivatedHandle == mBottomLeftHandle) {
infoXPosition = aX;
} elseif (mActivatedHandle == mTopHandle ||
mActivatedHandle == mBottomHandle) {
infoXPosition = aX + (aW / 2);
} else { // should only occur when mActivatedHandle is one of the 3 right-side // handles, but this is a reasonable default if it isn't any of them (?)
infoXPosition = aX + aW;
}
if (mActivatedHandle == mTopLeftHandle || mActivatedHandle == mTopHandle ||
mActivatedHandle == mTopRightHandle) {
infoYPosition = aY;
} elseif (mActivatedHandle == mLeftHandle ||
mActivatedHandle == mRightHandle) {
infoYPosition = aY + (aH / 2);
} else { // should only occur when mActivatedHandle is one of the 3 bottom-side // handles, but this is a reasonable default if it isn't any of them (?)
infoYPosition = aY + aH;
}
// Offset info box by 20 so it's not directly under the mouse cursor. constint mouseCursorOffset = 20; if (RefPtr<nsStyledElement> resizingInfoStyledElement =
nsStyledElement::FromNodeOrNull(mResizingInfo.get())) {
nsresult rv;
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingInfoStyledElement, *nsGkAtoms::left,
infoXPosition + mouseCursorOffset); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::left) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::left) " "failed, but ignored");
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingInfoStyledElement, *nsGkAtoms::top,
infoYPosition + mouseCursorOffset); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::top) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::top) " "failed, but ignored");
}
nsresult HTMLEditor::UpdateResizerOrGrabberPositionTo( const CSSIntPoint& aClientPoint) { if (mIsResizing) {
AutoEditActionDataSetter editActionData(*this,
EditAction::eResizingElement); if (NS_WARN_IF(!editActionData.CanHandle())) { return NS_ERROR_NOT_INITIALIZED;
}
// we are resizing and the mouse pointer's position has changed // we have to resdisplay the shadow const int32_t newX = GetNewResizingX(aClientPoint.x, aClientPoint.y); const int32_t newY = GetNewResizingY(aClientPoint.x, aClientPoint.y); const int32_t newWidth =
GetNewResizingWidth(aClientPoint.x, aClientPoint.y); const int32_t newHeight =
GetNewResizingHeight(aClientPoint.x, aClientPoint.y);
if (RefPtr<nsStyledElement> resizingShadowStyledElement =
nsStyledElement::FromNodeOrNull(mResizingShadow.get())) {
nsresult rv;
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingShadowStyledElement, *nsGkAtoms::left, newX); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::left)" " destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::left) " "failed, but ignored");
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingShadowStyledElement, *nsGkAtoms::top, newY); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::top)" " destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::top) " "failed, but ignored");
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingShadowStyledElement, *nsGkAtoms::width, newWidth); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "width) destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::width) " "failed, but ignored");
rv = CSSEditUtils::SetCSSPropertyPixelsWithoutTransaction(
*resizingShadowStyledElement, *nsGkAtoms::height, newHeight); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "height) destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::height)" " failed, but ignored");
}
if (mActivatedHandle) {
mActivatedHandle->ClassList()->Remove(u"active"_ns, IgnoreErrors());
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
AutoPlaceholderBatch treatAsOneTransaction(
*this, ScrollSelectionIntoView::Yes, __FUNCTION__);
RefPtr<Element> resizedElement(mResizedObject);
RefPtr<nsStyledElement> resizedStyleElement =
nsStyledElement::FromNodeOrNull(mResizedObject);
if (mResizedObjectIsAbsolutelyPositioned && resizedStyleElement) { if (setHeight) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::top, y); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "top) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::top) " "failed, but ignored");
} if (setWidth) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::left, x); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "left) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::left) " "failed, but ignored");
}
} if (IsCSSEnabled() || mResizedObjectIsAbsolutelyPositioned) { if (setWidth && resizedElement->HasAttr(nsGkAtoms::width)) {
nsresult rv =
RemoveAttributeWithTransaction(*resizedElement, *nsGkAtoms::width); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
NS_WARNING( "EditorBase::RemoveAttributeWithTransaction(nsGkAtoms::width) " "failed"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "EditorBase::RemoveAttributeWithTransaction(nsGkAtoms::width) " "failed, but ignored");
}
if (setHeight && resizedElement->HasAttr(nsGkAtoms::height)) {
nsresult rv =
RemoveAttributeWithTransaction(*resizedElement, *nsGkAtoms::height); if (MOZ_UNLIKELY(rv == NS_ERROR_EDITOR_DESTROYED)) {
NS_WARNING( "EditorBase::RemoveAttributeWithTransaction(nsGkAtoms::height) " "failed"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "EditorBase::RemoveAttributeWithTransaction(nsGkAtoms::height) " "failed, but ignored");
}
if (resizedStyleElement) { if (setWidth) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::width, width); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "width) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixels(nsGkAtoms::width) " "failed, but ignored");
} if (setHeight) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::height, height); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "height) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixels(nsGkAtoms::height) " "failed, but ignored");
}
}
} 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 (resizedStyleElement) { if (setWidth) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::width, width); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "width) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "width) failed, but ignored");
} if (setHeight) {
nsresult rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::height, height); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "height) destoyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::SetCSSPropertyPixelsWithTransaction(nsGkAtoms::" "height) failed, but ignored");
}
} if (setWidth) {
nsAutoString w;
w.AppendInt(width);
DebugOnly<nsresult> rvIgnored =
SetAttributeWithTransaction(*resizedElement, *nsGkAtoms::width, w); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored), "EditorBase::SetAttributeWithTransaction(nsGkAtoms::width) " "failed, but ignored");
} if (setHeight) {
nsAutoString h;
h.AppendInt(height);
DebugOnly<nsresult> rvIgnored =
SetAttributeWithTransaction(*resizedElement, *nsGkAtoms::height, h); if (NS_WARN_IF(Destroyed())) { return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored), "EditorBase::SetAttributeWithTransaction(nsGkAtoms::height) " "failed, but ignored");
}
if (resizedStyleElement) { if (setWidth) {
nsresult rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::width, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::width)" " destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::width) " "failed, but ignored");
} if (setHeight) {
nsresult rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, *resizedStyleElement, *nsGkAtoms::height, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::" "height) destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::height) " "failed, but ignored");
}
}
}
// keep track of that size
mResizedObjectWidth = width;
mResizedObjectHeight = height;
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.29Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.