/* 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/. */
Result<int32_t, nsresult> HTMLEditor::AddZIndexWithTransaction(
nsStyledElement& aStyledElement, int32_t aChange) { if (!aChange) { return 0; // XXX Why don't we return current z-index value in this case?
}
nsresult rv = CSSEditUtils::GetSpecifiedProperty(
aElement, *nsGkAtoms::z_index, zIndexValue); if (NS_FAILED(rv)) {
NS_WARNING("CSSEditUtils::GetSpecifiedProperty(nsGkAtoms::z_index) failed"); return 0;
} if (zIndexValue.EqualsLiteral("auto")) { if (!aElement.GetParentElement()) {
NS_WARNING("aElement was an orphan node or the root node"); return 0;
} // we have to look at the positioned ancestors // cf. CSS 2 spec section 9.9.1
nsAutoString positionValue; for (RefPtr<Element> element = aElement.GetParentElement(); element;
element = element->GetParentElement()) { if (element->IsHTMLElement(nsGkAtoms::body)) { return 0;
}
nsCOMPtr<nsINode> parentNode = element->GetParentElement();
nsresult rv = CSSEditUtils::GetComputedProperty(
*element, *nsGkAtoms::position, positionValue); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::GetComputedProperty(nsGkAtoms::position) failed"); return 0;
} if (NS_WARN_IF(Destroyed()) ||
NS_WARN_IF(parentNode != element->GetParentNode())) { return 0;
} if (!positionValue.EqualsLiteral("absolute")) { continue;
} // ah, we found one, what's its z-index ? If its z-index is auto, // we have to continue climbing the document's tree
rv = CSSEditUtils::GetComputedProperty(*element, *nsGkAtoms::z_index,
zIndexValue); if (NS_FAILED(rv)) {
NS_WARNING( "CSSEditUtils::GetComputedProperty(nsGkAtoms::z_index) failed"); return 0;
} if (NS_WARN_IF(Destroyed()) ||
NS_WARN_IF(parentNode != element->GetParentNode())) { return 0;
} if (!zIndexValue.EqualsLiteral("auto")) { break;
}
}
}
if (zIndexValue.EqualsLiteral("auto")) { return 0;
}
nsresult rvIgnored;
int32_t result = zIndexValue.ToInteger(&rvIgnored);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "nsAString::ToInteger() failed, but ignored"); return result;
}
bool HTMLEditor::CreateGrabberInternal(nsIContent& aParentContent) { if (NS_WARN_IF(mGrabber)) { returnfalse;
}
// mGrabber may be destroyed during creation due to there may be // mutation event listener. if (!mGrabber) {
NS_WARNING( "HTMLEditor::CreateAnonymousElement(nsGkAtoms::span, mozGrabber) " "failed"); returnfalse;
}
void HTMLEditor::HideGrabberInternal() { if (NS_WARN_IF(!mAbsolutelyPositionedObject)) { return;
}
// Move all members to the local variables first since mutation event // listener may try to show grabber while we're hiding them.
RefPtr<Element> absolutePositioningObject =
std::move(mAbsolutelyPositionedObject);
ManualNACPtr grabber = std::move(mGrabber);
ManualNACPtr positioningShadow = std::move(mPositioningShadow);
// If we're still in dragging mode, it means that the dragging is canceled // by the web app. if (mGrabberClicked || mIsMoving) {
mGrabberClicked = false;
mIsMoving = false; if (mEventListener) {
DebugOnly<nsresult> rvIgnored = static_cast<HTMLEditorEventListener*>(mEventListener.get())
->ListenToMouseMoveEventForGrabber(false);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "HTMLEditorEventListener::" "ListenToMouseMoveEventForGrabber(false) failed");
}
}
// 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.
RefPtr<PresShell> presShell = GetPresShell(); if (grabber) {
DeleteRefToAnonymousNode(std::move(grabber), presShell);
} if (positioningShadow) {
DeleteRefToAnonymousNode(std::move(positioningShadow), presShell);
}
}
Element* parentElement = aElement.GetParentElement(); if (NS_WARN_IF(!parentElement)) { return NS_ERROR_FAILURE;
}
if (!CreateGrabberInternal(*parentElement)) {
NS_WARNING("HTMLEditor::CreateGrabberInternal() failed"); return NS_ERROR_FAILURE;
}
// If we succeeded to create the grabber, HideGrabberInternal() hasn't been // called yet. So, mAbsolutelyPositionedObject should be non-nullptr.
MOZ_ASSERT(mAbsolutelyPositionedObject);
// Finally, move the grabber to proper position.
rv = RefreshGrabberInternal();
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "HTMLEditor::RefereshGrabberInternal() failed"); return rv;
}
// 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 newX = mPositionedObjectX + aX - mOriginalX -
(mPositionedObjectBorderLeft + mPositionedObjectMarginLeft);
int32_t newY = mPositionedObjectY + aY - mOriginalY -
(mPositionedObjectBorderTop + mPositionedObjectMarginTop);
// we want one transaction only from a user's point of view
AutoPlaceholderBatch treatAsOneTransaction(
*this, ScrollSelectionIntoView::Yes, __FUNCTION__);
if (NS_WARN_IF(!mAbsolutelyPositionedObject)) { return NS_ERROR_FAILURE;
} if (RefPtr<nsStyledElement> styledAbsolutelyPositionedElement =
nsStyledElement::FromNode(mAbsolutelyPositionedObject)) {
nsresult rv;
rv = CSSEditUtils::SetCSSPropertyPixelsWithTransaction(
*this, *styledAbsolutelyPositionedElement, *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::SetCSSPropertyPixelsWithTransaction(
*this, *styledAbsolutelyPositionedElement, *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");
} // keep track of that size
mPositionedObjectX = newX;
mPositionedObjectY = newY;
nsresult HTMLEditor::SetPositionToAbsoluteOrStatic(Element& aElement, bool aEnabled) {
nsAutoString positionValue;
DebugOnly<nsresult> rvIgnored = CSSEditUtils::GetComputedProperty(
aElement, *nsGkAtoms::position, positionValue);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rvIgnored), "CSSEditUtils::GetComputedProperty(nsGkAtoms::position) " "failed, but ignored"); // nothing to do if the element is already in the state we want if (positionValue.EqualsLiteral("absolute") == aEnabled) { return NS_OK;
}
nsStyledElement* styledElement = nsStyledElement::FromNode(&aElement); if (styledElement) { // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
nsresult rv = CSSEditUtils::SetCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::position,
u"absolute"_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::SetCSSProperyWithTransaction(nsGkAtoms::Position) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rvIgnored), "CSSEditUtils::SetCSSPropertyWithTransaction(nsGkAtoms::position, " "absolute) failed, but ignored");
}
SnapToGrid(x, y); if (styledElement) { // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
nsresult rv =
SetTopAndLeftWithTransaction(MOZ_KnownLive(*styledElement), x, y); if (NS_FAILED(rv)) {
NS_WARNING("HTMLEditor::SetTopAndLeftWithTransaction() failed"); return rv;
}
}
// we may need to create a br if the positioned element is alone in its // container
nsINode* parentNode = aElement.GetParentNode(); if (parentNode->GetChildCount() != 1) { return NS_OK;
}
Result<CreateLineBreakResult, nsresult> insertBRElementResultOrError =
InsertLineBreak(WithTransaction::Yes, LineBreakType::BRElement,
EditorDOMPoint(parentNode, 0u)); if (MOZ_UNLIKELY(insertBRElementResultOrError.isErr())) {
NS_WARNING( "HTMLEditor::InsertLineBreak(WithTransaction::Yes, " "LineBreakType::BRElement) failed"); return insertBRElementResultOrError.unwrapErr();
}
CreateLineBreakResult insertBRElementResult =
insertBRElementResultOrError.unwrap();
MOZ_ASSERT(insertBRElementResult.Handled()); // XXX Is this intentional selection change?
nsresult rv = insertBRElementResult.SuggestCaretPointTo(
*this, {SuggestCaret::OnlyIfHasSuggestion,
SuggestCaret::OnlyIfTransactionsAllowedToDoIt});
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "CreateElementResult::SuggestCaretPointTo() failed"); return rv;
}
nsresult rv; // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::position, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::position) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::position) " "failed, but ignored"); // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::top, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::top) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::top) " "failed, but ignored"); // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::left, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::left) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::left) " "failed, but ignored"); // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *nsGkAtoms::z_index, u""_ns); if (rv == NS_ERROR_EDITOR_DESTROYED) {
NS_WARNING( "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::z_index) " "destroyed the editor"); return NS_ERROR_EDITOR_DESTROYED;
}
NS_WARNING_ASSERTION(
NS_SUCCEEDED(rv), "CSSEditUtils::RemoveCSSPropertyWithTransaction(nsGkAtoms::z_index) " "failed, but ignored");
if (!HTMLEditUtils::IsImage(styledElement)) { // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *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"); // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
rv = CSSEditUtils::RemoveCSSPropertyWithTransaction(
*this, MOZ_KnownLive(*styledElement), *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");
}
if (!styledElement->IsHTMLElement(nsGkAtoms::div) ||
HTMLEditor::HasStyleOrIdOrClassAttribute(*styledElement)) { return NS_OK;
}
EditorDOMPoint pointToPutCaret; // Make sure the first fild and last child of aElement starts/ends hard // line(s) even after removing `aElement`.
{ // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
Result<CreateElementResult, nsresult>
maybeInsertBRElementBeforeFirstChildResult =
EnsureHardLineBeginsWithFirstChildOf(MOZ_KnownLive(*styledElement)); if (MOZ_UNLIKELY(maybeInsertBRElementBeforeFirstChildResult.isErr())) {
NS_WARNING("HTMLEditor::EnsureHardLineBeginsWithFirstChildOf() failed"); return maybeInsertBRElementBeforeFirstChildResult.unwrapErr();
}
CreateElementResult unwrappedResult =
maybeInsertBRElementBeforeFirstChildResult.unwrap(); if (unwrappedResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedResult.UnwrapCaretPoint();
}
}
{ // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
Result<CreateElementResult, nsresult>
maybeInsertBRElementAfterLastChildResult =
EnsureHardLineEndsWithLastChildOf(MOZ_KnownLive(*styledElement)); if (MOZ_UNLIKELY(maybeInsertBRElementAfterLastChildResult.isErr())) {
NS_WARNING("HTMLEditor::EnsureHardLineEndsWithLastChildOf() failed"); return maybeInsertBRElementAfterLastChildResult.unwrapErr();
}
CreateElementResult unwrappedResult =
maybeInsertBRElementAfterLastChildResult.unwrap(); if (unwrappedResult.HasCaretPointSuggestion()) {
pointToPutCaret = unwrappedResult.UnwrapCaretPoint();
}
}
{ // MOZ_KnownLive(*styledElement): aElement's lifetime must be guarantted // by the caller because of MOZ_CAN_RUN_SCRIPT method.
Result<EditorDOMPoint, nsresult> unwrapStyledElementResult =
RemoveContainerWithTransaction(MOZ_KnownLive(*styledElement)); if (MOZ_UNLIKELY(unwrapStyledElementResult.isErr())) {
NS_WARNING("HTMLEditor::RemoveContainerWithTransaction() failed"); return unwrapStyledElementResult.unwrapErr();
} if (unwrapStyledElementResult.inspect().IsSet()) {
pointToPutCaret = unwrapStyledElementResult.unwrap();
}
} if (!AllowsTransactionsToChangeSelection() || !pointToPutCaret.IsSet()) { return NS_OK;
}
rv = CollapseSelectionTo(pointToPutCaret);
NS_WARNING_ASSERTION(NS_SUCCEEDED(rv), "EditorBase::CollapseSelectionTo() failed"); return rv;
}
nsresult HTMLEditor::GetTemporaryStyleForFocusedPositionedElement(
Element& aElement, nsAString& aReturn) { // we are going to outline the positioned element and bring it to the // front to overlap any other element intersecting with it. But // first, let's see what's the background and foreground colors of the // positioned element. // if background-image computed value is 'none, // If the background color is 'auto' and R G B values of the foreground are // each above #d0, use a black background // If the background color is 'auto' and at least one of R G B values of // the foreground is below #d0, use a white background // Otherwise don't change background/foreground
aReturn.Truncate();
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.