2001-09-26 02:53:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* 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/. */
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
#ifndef mozilla_PendingStyles_h
|
|
|
|
#define mozilla_PendingStyles_h
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2018-03-15 15:25:41 +03:00
|
|
|
#include "mozilla/EditorDOMPoint.h"
|
2022-04-20 17:46:16 +03:00
|
|
|
#include "mozilla/EditorForwards.h"
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
#include "mozilla/EventForwards.h"
|
2022-08-26 06:25:19 +03:00
|
|
|
#include "mozilla/Maybe.h"
|
2017-02-08 12:14:53 +03:00
|
|
|
#include "mozilla/UniquePtr.h"
|
2022-08-26 06:25:19 +03:00
|
|
|
#include "nsAtom.h"
|
2002-05-01 00:59:43 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsCycleCollectionParticipant.h"
|
2019-08-20 04:51:36 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nsISupportsImpl.h"
|
2000-01-19 00:50:15 +03:00
|
|
|
#include "nsString.h"
|
2009-04-22 12:43:15 +04:00
|
|
|
#include "nsTArray.h"
|
2012-07-13 10:33:42 +04:00
|
|
|
#include "nscore.h"
|
|
|
|
|
2018-02-28 05:32:28 +03:00
|
|
|
class nsINode;
|
2016-07-08 05:51:46 +03:00
|
|
|
|
2014-11-02 15:04:13 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2021-01-13 04:55:27 +03:00
|
|
|
class MouseEvent;
|
2014-11-02 15:04:13 +03:00
|
|
|
class Selection;
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace dom
|
2000-03-29 16:53:23 +04:00
|
|
|
|
Bug 1697249 - Stop creating `<span>` element for keeping same style as the link when the link will be unlinked r=m_kato
When typing at edge of a link, editor splits the link element at the edge (i.e.,
creating an empty link element). Then, unlink the new link element (i.e.,
clearing the "link style"). At this time, `class` attribute and `style`
attribute are cloned to new `<span>` element for keeping the original style.
However, in this case, other browsers discard the specified style of the link.
On the other hand, when unlinking a link with `execCommand("unlink")`, the
other browsers keep specified style coming from `style` attribute.
Therefore, this patch adds new state to `PropItem`, which indicates whether
the `class` and `style` attribute should be cloned or discarded. And then,
when preparing for inserting text, this patch makes it pass to the utility
method.
For better compatibility, we should stop cloning `class` attribute, but not
in this bug because this patch should be minimized for requesting uplift to
beta channel.
Differential Revision: https://phabricator.services.mozilla.com/D107801
2021-03-11 10:19:33 +03:00
|
|
|
enum class SpecifiedStyle : uint8_t { Preserve, Discard };
|
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
class PendingStyle final {
|
|
|
|
public:
|
|
|
|
PendingStyle() = delete;
|
|
|
|
PendingStyle(nsStaticAtom* aTag, nsAtom* aAttribute, const nsAString& aValue,
|
|
|
|
SpecifiedStyle aSpecifiedStyle = SpecifiedStyle::Preserve)
|
|
|
|
: mTag(aTag),
|
|
|
|
mAttribute(aAttribute != nsGkAtoms::_empty ? aAttribute : nullptr),
|
|
|
|
mAttributeValueOrCSSValue(aValue),
|
|
|
|
mSpecifiedStyle(aSpecifiedStyle) {
|
|
|
|
MOZ_COUNT_CTOR(PendingStyle);
|
|
|
|
}
|
|
|
|
MOZ_COUNTED_DTOR(PendingStyle)
|
|
|
|
|
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom* GetTag() const { return mTag; }
|
|
|
|
MOZ_KNOWN_LIVE nsAtom* GetAttribute() const { return mAttribute; }
|
|
|
|
const nsString& AttributeValueOrCSSValueRef() const {
|
|
|
|
return mAttributeValueOrCSSValue;
|
|
|
|
}
|
|
|
|
void UpdateAttributeValueOrCSSValue(const nsAString& aNewValue) {
|
|
|
|
mAttributeValueOrCSSValue = aNewValue;
|
|
|
|
}
|
|
|
|
SpecifiedStyle GetSpecifiedStyle() const { return mSpecifiedStyle; }
|
|
|
|
|
2022-11-25 05:15:51 +03:00
|
|
|
EditorInlineStyle ToInlineStyle() const;
|
2022-11-25 08:20:49 +03:00
|
|
|
EditorInlineStyleAndValue ToInlineStyleAndValue() const;
|
2022-11-25 05:15:51 +03:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
private:
|
2022-08-26 06:10:30 +03:00
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom* const mTag = nullptr;
|
2022-08-26 06:10:31 +03:00
|
|
|
// TODO: Once we stop using `HTMLEditor::SetInlinePropertiesAsSubAction` to
|
|
|
|
// add any attributes of <a href>, we can make this `nsStaticAtom*`.
|
|
|
|
MOZ_KNOWN_LIVE const RefPtr<nsAtom> mAttribute;
|
2022-08-26 06:10:31 +03:00
|
|
|
// If the editor is in CSS mode, this value is the property value.
|
|
|
|
// If the editor is in HTML mode, this value is not empty only when
|
|
|
|
// - mAttribute is not nullptr
|
|
|
|
// - mTag is CSS invertible style and "-moz-editor-invert-value"
|
|
|
|
nsString mAttributeValueOrCSSValue;
|
2022-08-26 06:10:32 +03:00
|
|
|
// Whether the class and style attribute should be preserved or discarded.
|
|
|
|
const SpecifiedStyle mSpecifiedStyle = SpecifiedStyle::Preserve;
|
2019-08-20 04:51:36 +03:00
|
|
|
};
|
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
class PendingStyleCache final {
|
2020-01-31 10:14:42 +03:00
|
|
|
public:
|
2022-08-26 06:31:26 +03:00
|
|
|
PendingStyleCache() = delete;
|
2022-11-25 09:43:51 +03:00
|
|
|
PendingStyleCache(const nsStaticAtom& aTag, const nsStaticAtom* aAttribute,
|
2022-08-26 06:31:26 +03:00
|
|
|
const nsAString& aValue)
|
2022-11-25 09:43:51 +03:00
|
|
|
// Needs const_cast hack here because the this class users may want
|
|
|
|
// non-const nsStaticAtom reference/pointer due to bug 1794954
|
|
|
|
: mTag(const_cast<nsStaticAtom&>(aTag)),
|
|
|
|
mAttribute(const_cast<nsStaticAtom*>(aAttribute)),
|
|
|
|
mAttributeValueOrCSSValue(aValue) {}
|
|
|
|
PendingStyleCache(const nsStaticAtom& aTag, const nsStaticAtom* aAttribute,
|
|
|
|
nsAString&& aValue)
|
|
|
|
// Needs const_cast hack here because the this class users may want
|
|
|
|
// non-const nsStaticAtom reference/pointer due to bug 1794954
|
|
|
|
: mTag(const_cast<nsStaticAtom&>(aTag)),
|
|
|
|
mAttribute(const_cast<nsStaticAtom*>(aAttribute)),
|
|
|
|
mAttributeValueOrCSSValue(std::move(aValue)) {}
|
2019-08-20 04:51:36 +03:00
|
|
|
|
2022-08-26 06:10:30 +03:00
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom& TagRef() const { return mTag; }
|
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom* GetAttribute() const { return mAttribute; }
|
2022-08-26 06:10:31 +03:00
|
|
|
const nsString& AttributeValueOrCSSValueRef() const {
|
|
|
|
return mAttributeValueOrCSSValue;
|
|
|
|
}
|
2019-08-20 04:51:36 +03:00
|
|
|
|
2022-11-25 03:54:55 +03:00
|
|
|
EditorInlineStyle ToInlineStyle() const;
|
|
|
|
|
2020-01-31 10:14:42 +03:00
|
|
|
private:
|
2022-08-26 06:10:30 +03:00
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom& mTag;
|
|
|
|
MOZ_KNOWN_LIVE nsStaticAtom* const mAttribute;
|
2022-08-26 06:10:31 +03:00
|
|
|
const nsString mAttributeValueOrCSSValue;
|
2019-08-20 04:51:36 +03:00
|
|
|
};
|
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
class MOZ_STACK_CLASS AutoPendingStyleCacheArray final
|
|
|
|
: public AutoTArray<PendingStyleCache, 21> {
|
2019-08-20 04:51:36 +03:00
|
|
|
public:
|
2022-08-26 06:10:30 +03:00
|
|
|
index_type IndexOf(const nsStaticAtom& aTag,
|
2020-01-31 10:14:42 +03:00
|
|
|
const nsStaticAtom* aAttribute) const {
|
|
|
|
for (index_type index = 0; index < Length(); ++index) {
|
2022-08-26 06:31:26 +03:00
|
|
|
const PendingStyleCache& styleCache = ElementAt(index);
|
2022-08-26 06:10:30 +03:00
|
|
|
if (&styleCache.TagRef() == &aTag &&
|
|
|
|
styleCache.GetAttribute() == aAttribute) {
|
2020-01-31 10:14:42 +03:00
|
|
|
return index;
|
|
|
|
}
|
2019-08-20 04:51:36 +03:00
|
|
|
}
|
2020-01-31 10:14:42 +03:00
|
|
|
return NoIndex;
|
2019-08-20 04:51:36 +03:00
|
|
|
}
|
2000-03-29 16:53:23 +04:00
|
|
|
};
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
enum class PendingStyleState {
|
|
|
|
// Will be not changed in new content
|
|
|
|
NotUpdated,
|
|
|
|
// Will be applied to new content
|
|
|
|
BeingPreserved,
|
|
|
|
// Will be cleared from new content
|
|
|
|
BeingCleared,
|
|
|
|
};
|
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
/******************************************************************************
|
|
|
|
* PendingStyles stores pending inline styles which WILL be applied to new
|
|
|
|
* content when it'll be inserted. I.e., updating styles of this class means
|
|
|
|
* that it does NOT update the DOM tree immediately.
|
|
|
|
******************************************************************************/
|
|
|
|
class PendingStyles final {
|
1999-04-01 22:40:35 +04:00
|
|
|
public:
|
2022-08-26 06:31:26 +03:00
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(PendingStyles)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_NATIVE_CLASS(PendingStyles)
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
PendingStyles() = default;
|
|
|
|
|
|
|
|
void Reset() {
|
|
|
|
mClearingStyles.Clear();
|
|
|
|
mPreservingStyles.Clear();
|
|
|
|
}
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-04-21 02:35:18 +03:00
|
|
|
nsresult UpdateSelState(const HTMLEditor& aHTMLEditor);
|
2005-02-01 02:47:26 +03:00
|
|
|
|
2021-01-13 04:55:27 +03:00
|
|
|
/**
|
|
|
|
* PreHandleMouseEvent() is called when `HTMLEditorEventListener` receives
|
|
|
|
* "mousedown" and "mouseup" events. Note that `aMouseDownOrUpEvent` may not
|
|
|
|
* be acceptable event for the `HTMLEditor`, but this is called even in
|
|
|
|
* the case because the event may cause a following `OnSelectionChange()`
|
|
|
|
* call.
|
|
|
|
*/
|
|
|
|
void PreHandleMouseEvent(const dom::MouseEvent& aMouseDownOrUpEvent);
|
|
|
|
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
void PreHandleSelectionChangeCommand(Command aCommand);
|
2021-01-13 04:55:32 +03:00
|
|
|
void PostHandleSelectionChangeCommand(const HTMLEditor& aHTMLEditor,
|
|
|
|
Command aCommand);
|
Bug 1357365 - part 3: Make `TypeInState::OnSelectionChange()` stop keeping link style if caret is positioned at edge of a link element and not moved in the link r=m_kato,edgar
Although different from the other browsers' behavior, our traditional behavior
might be better than them because the behavior on the other browser does not
allow users to insert new content at start nor end of a link.
However, we can relax more about keeping traditional behavior for web-compat.
Perhaps, only when caret is moved from the other side of first or last character
in the link and moves caret to the edge of the link with arrow key, we should
allow users to modify the link text.
Otherwise, e.g., `Home` and `End` key press should make it stop keeping the
link style. This helps advanced users who are familiar with keyboard navigatin
in editor.
Note that this patch also changes the condition which checks
`aReason & nsISelectionListener::KEYPRESS_REASON` to check also
`nsISelectionListener::COLLAPSETO_START_REASON` and
`nsISelectionListener::COLLAPSETO_END_REASON` because all of them are
set by `nsFrameSelection::MoveCaret` exclusively.
https://searchfox.org/mozilla-central/rev/a0ccd492719b1ad2106f6456549be62a76f45acb/layout/generic/nsFrameSelection.cpp#738,741,745
Therefore, they should be treated as same as a key press.
Note that they are also set by `Selection::CollapseToStart` and
`Selection::CollapseToEnd` too. But a following patch will add a new
reason to notify selection listeners of caused by JS. So, the problem
will be fixed by the following patch.
Differential Revision: https://phabricator.services.mozilla.com/D101002
2021-01-13 04:55:29 +03:00
|
|
|
|
2021-01-13 04:56:05 +03:00
|
|
|
void OnSelectionChange(const HTMLEditor& aHTMLEditor, int16_t aReason);
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-08-26 06:20:14 +03:00
|
|
|
/**
|
|
|
|
* Preserve the style for next inserting content. E.g., when user types next
|
|
|
|
* character, an inline element which provides the style will be inserted
|
|
|
|
* and the typing character will appear in it.
|
|
|
|
*
|
|
|
|
* @param aHTMLProperty The HTML tag name which represents the style.
|
|
|
|
* For example, nsGkAtoms::b for bold text.
|
|
|
|
* @param aAttribute nullptr or attribute name which represents the
|
|
|
|
* style with aHTMLProperty. E.g., nsGkAtoms::size
|
|
|
|
* for nsGkAtoms::font.
|
|
|
|
* @param aAttributeValueOrCSSValue
|
|
|
|
* New value of aAttribute or new CSS value if the
|
|
|
|
* editor is in the CSS mode.
|
|
|
|
*/
|
|
|
|
void PreserveStyle(nsStaticAtom& aHTMLProperty, nsAtom* aAttribute,
|
|
|
|
const nsAString& aAttributeValueOrCSSValue);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preserve the styles with new values in aStylesToPreserve.
|
|
|
|
* See above for the detail.
|
|
|
|
*/
|
|
|
|
void PreserveStyles(
|
|
|
|
const nsTArray<EditorInlineStyleAndValue>& aStylesToPreserve);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Preserve the style with new value specified with aStyleToPreserve.
|
|
|
|
* See above for the detail.
|
|
|
|
*/
|
2022-08-26 06:31:26 +03:00
|
|
|
void PreserveStyle(const PendingStyleCache& aStyleToPreserve) {
|
2022-08-26 06:20:14 +03:00
|
|
|
PreserveStyle(aStyleToPreserve.TagRef(), aStyleToPreserve.GetAttribute(),
|
|
|
|
aStyleToPreserve.AttributeValueOrCSSValueRef());
|
|
|
|
}
|
2000-03-31 02:57:19 +04:00
|
|
|
|
2022-08-26 06:25:19 +03:00
|
|
|
/**
|
|
|
|
* Clear the style when next content is inserted. E.g., when user types next
|
|
|
|
* character, it'll will be inserted after parent element which provides the
|
|
|
|
* style and clones element which represents other styles in the parent
|
|
|
|
* element.
|
|
|
|
*
|
|
|
|
* @param aHTMLProperty The HTML tag name which represents the style.
|
|
|
|
* For example, nsGkAtoms::b for bold text.
|
|
|
|
* @param aAttribute nullptr or attribute name which represents the
|
|
|
|
* style with aHTMLProperty. E.g., nsGkAtoms::size
|
|
|
|
* for nsGkAtoms::font.
|
|
|
|
*/
|
|
|
|
void ClearStyle(nsStaticAtom& aHTMLProperty, nsAtom* aAttribute) {
|
|
|
|
ClearStyleInternal(&aHTMLProperty, aAttribute);
|
|
|
|
}
|
2015-05-28 18:58:42 +03:00
|
|
|
|
2016-07-08 05:51:46 +03:00
|
|
|
/**
|
2022-08-26 06:25:19 +03:00
|
|
|
* Clear all styles specified by aStylesToClear when next content is inserted.
|
|
|
|
* See above for the detail.
|
2016-07-08 05:51:46 +03:00
|
|
|
*/
|
2022-08-26 06:25:19 +03:00
|
|
|
void ClearStyles(const nsTArray<EditorInlineStyle>& aStylesToClear);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all styles when next inserting content. E.g., when user types next
|
|
|
|
* character, it will be inserted outside any inline parents which provides
|
|
|
|
* current text style.
|
|
|
|
*/
|
|
|
|
void ClearAllStyles() {
|
|
|
|
// XXX Why don't we clear mClearingStyles first?
|
|
|
|
ClearStyleInternal(nullptr, nullptr);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear <a> element and discard styles which is applied by it.
|
|
|
|
*/
|
|
|
|
void ClearLinkAndItsSpecifiedStyle() {
|
|
|
|
ClearStyleInternal(nsGkAtoms::a, nullptr, SpecifiedStyle::Discard);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* TakeClearingStyle() hands back next property item on the clearing styles.
|
|
|
|
* This must be used only for handling to clear the styles from inserting
|
|
|
|
* content.
|
|
|
|
*/
|
2022-08-26 06:31:26 +03:00
|
|
|
UniquePtr<PendingStyle> TakeClearingStyle() {
|
2022-08-26 06:25:19 +03:00
|
|
|
if (mClearingStyles.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mClearingStyles.PopLastElement();
|
|
|
|
}
|
2000-03-31 02:57:19 +04:00
|
|
|
|
2016-07-08 05:51:46 +03:00
|
|
|
/**
|
2022-08-26 06:20:14 +03:00
|
|
|
* TakePreservedStyle() hands back next property item on the preserving
|
|
|
|
* styles. This should be used only for handling setting new style for
|
|
|
|
* inserted content.
|
2016-07-08 05:51:46 +03:00
|
|
|
*/
|
2022-08-26 06:31:26 +03:00
|
|
|
UniquePtr<PendingStyle> TakePreservedStyle() {
|
2022-08-26 06:20:14 +03:00
|
|
|
if (mPreservingStyles.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
return mPreservingStyles.PopLastElement();
|
|
|
|
}
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2016-07-08 05:51:46 +03:00
|
|
|
/**
|
|
|
|
* TakeRelativeFontSize() hands back relative font value, which is then
|
|
|
|
* cleared out.
|
|
|
|
*/
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t TakeRelativeFontSize();
|
fixes:
14753, 29843, 39864, 40141,
40139, 36679, 39542, 34729,
34855, 37216, 39292, 26447
r=sfraser,cmanske,fm; a=beppe
2000-05-25 03:00:24 +04:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
/**
|
|
|
|
* GetStyleState() returns whether the style will be applied to new content,
|
|
|
|
* removed from new content or not changed.
|
|
|
|
*
|
|
|
|
* @param aHTMLProperty The HTML tag name which represents the style.
|
|
|
|
* For example, nsGkAtoms::b for bold text.
|
|
|
|
* @param aAttribute nullptr or attribute name which represents the
|
|
|
|
* style with aHTMLProperty. E.g., nsGkAtoms::size
|
|
|
|
* for nsGkAtoms::font.
|
|
|
|
* @param aOutNewAttributeValueOrCSSValue
|
|
|
|
* [out, optional] If applied to new content, this
|
|
|
|
* is set to the new value.
|
|
|
|
*/
|
|
|
|
PendingStyleState GetStyleState(
|
|
|
|
nsStaticAtom& aHTMLProperty, nsAtom* aAttribute = nullptr,
|
|
|
|
nsString* aOutNewAttributeValueOrCSSValue = nullptr) const;
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2000-03-29 16:53:23 +04:00
|
|
|
protected:
|
2022-08-26 06:31:26 +03:00
|
|
|
virtual ~PendingStyles() { Reset(); };
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2022-08-26 06:25:19 +03:00
|
|
|
void ClearStyleInternal(
|
|
|
|
nsStaticAtom* aHTMLProperty, nsAtom* aAttribute,
|
|
|
|
SpecifiedStyle aSpecifiedStyle = SpecifiedStyle::Preserve);
|
|
|
|
|
2022-08-26 06:25:19 +03:00
|
|
|
void CancelPreservingStyle(nsStaticAtom* aHTMLProperty, nsAtom* aAttribute);
|
|
|
|
void CancelClearingStyle(nsStaticAtom& aHTMLProperty, nsAtom* aAttribute);
|
|
|
|
|
|
|
|
Maybe<size_t> IndexOfPreservingStyle(nsStaticAtom& aHTMLProperty,
|
|
|
|
nsAtom* aAttribute,
|
|
|
|
nsAString* aOutValue = nullptr) const {
|
|
|
|
return IndexOfStyleInArray(&aHTMLProperty, aAttribute, aOutValue,
|
|
|
|
mPreservingStyles);
|
|
|
|
}
|
|
|
|
Maybe<size_t> IndexOfClearingStyle(nsStaticAtom* aHTMLProperty,
|
|
|
|
nsAtom* aAttribute) const {
|
|
|
|
return IndexOfStyleInArray(aHTMLProperty, aAttribute, nullptr,
|
|
|
|
mClearingStyles);
|
|
|
|
}
|
1999-04-01 22:40:35 +04:00
|
|
|
|
2021-01-13 04:55:27 +03:00
|
|
|
bool IsLinkStyleSet() const {
|
2022-08-26 06:25:19 +03:00
|
|
|
return IndexOfPreservingStyle(*nsGkAtoms::a, nullptr).isSome();
|
2021-01-13 04:55:27 +03:00
|
|
|
}
|
|
|
|
bool IsExplicitlyLinkStyleCleared() const {
|
2022-08-26 06:25:19 +03:00
|
|
|
return IndexOfClearingStyle(nsGkAtoms::a, nullptr).isSome();
|
2021-01-13 04:55:27 +03:00
|
|
|
}
|
|
|
|
bool IsOnlyLinkStyleCleared() const {
|
2022-08-26 06:20:14 +03:00
|
|
|
return mClearingStyles.Length() == 1 && IsExplicitlyLinkStyleCleared();
|
2021-01-13 04:55:27 +03:00
|
|
|
}
|
2022-08-26 06:25:19 +03:00
|
|
|
bool IsStyleCleared(nsStaticAtom* aHTMLProperty, nsAtom* aAttribute) const {
|
|
|
|
return IndexOfClearingStyle(aHTMLProperty, aAttribute).isSome() ||
|
|
|
|
AreAllStylesCleared();
|
|
|
|
}
|
2021-01-13 04:55:27 +03:00
|
|
|
bool AreAllStylesCleared() const {
|
2022-08-26 06:25:19 +03:00
|
|
|
return IndexOfClearingStyle(nullptr, nullptr).isSome();
|
2021-01-13 04:55:27 +03:00
|
|
|
}
|
2022-08-26 06:20:14 +03:00
|
|
|
bool AreSomeStylesSet() const { return !mPreservingStyles.IsEmpty(); }
|
|
|
|
bool AreSomeStylesCleared() const { return !mClearingStyles.IsEmpty(); }
|
|
|
|
|
2022-08-26 06:25:19 +03:00
|
|
|
static Maybe<size_t> IndexOfStyleInArray(
|
|
|
|
nsStaticAtom* aHTMLProperty, nsAtom* aAttribute, nsAString* aOutValue,
|
2022-08-26 06:31:26 +03:00
|
|
|
const nsTArray<UniquePtr<PendingStyle>>& aArray);
|
2021-01-13 04:55:27 +03:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
nsTArray<UniquePtr<PendingStyle>> mPreservingStyles;
|
|
|
|
nsTArray<UniquePtr<PendingStyle>> mClearingStyles;
|
2018-03-15 15:25:41 +03:00
|
|
|
EditorDOMPoint mLastSelectionPoint;
|
2022-08-26 06:31:26 +03:00
|
|
|
int32_t mRelativeFontSize = 0;
|
|
|
|
Command mLastSelectionCommand = Command::DoNothing;
|
|
|
|
bool mMouseDownFiredInLinkElement = false;
|
|
|
|
bool mMouseUpFiredInLinkElement = false;
|
1999-04-01 22:40:35 +04:00
|
|
|
};
|
|
|
|
|
2016-07-08 05:51:46 +03:00
|
|
|
} // namespace mozilla
|
1999-09-22 05:18:51 +04:00
|
|
|
|
2022-08-26 06:31:26 +03:00
|
|
|
#endif // #ifndef mozilla_PendingStyles_h
|