summaryrefslogtreecommitdiffstats
path: root/dom/base/Element.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'dom/base/Element.cpp')
-rw-r--r--dom/base/Element.cpp81
1 files changed, 59 insertions, 22 deletions
diff --git a/dom/base/Element.cpp b/dom/base/Element.cpp
index 79b36a314..0054f4800 100644
--- a/dom/base/Element.cpp
+++ b/dom/base/Element.cpp
@@ -145,7 +145,6 @@
#include "mozilla/dom/KeyframeEffectBinding.h"
#include "mozilla/dom/WindowBinding.h"
#include "mozilla/dom/ElementBinding.h"
-#include "mozilla/dom/VRDisplay.h"
#include "mozilla/IntegerPrintfMacros.h"
#include "mozilla/Preferences.h"
#include "nsComputedDOMStyle.h"
@@ -688,19 +687,23 @@ Element::GetScrollFrame(nsIFrame **aStyledFrame, bool aFlushLayout)
}
void
-Element::ScrollIntoView()
+Element::ScrollIntoView(const BooleanOrScrollIntoViewOptions& aObject)
{
- ScrollIntoView(ScrollIntoViewOptions());
-}
+ if (aObject.IsScrollIntoViewOptions()) {
+ return ScrollIntoView(aObject.GetAsScrollIntoViewOptions());
+ }
+
+ MOZ_DIAGNOSTIC_ASSERT(aObject.IsBoolean());
-void
-Element::ScrollIntoView(bool aTop)
-{
ScrollIntoViewOptions options;
- if (!aTop) {
+ if (aObject.GetAsBoolean()) {
+ options.mBlock = ScrollLogicalPosition::Start;
+ options.mInline = ScrollLogicalPosition::Nearest;
+ } else {
options.mBlock = ScrollLogicalPosition::End;
+ options.mInline = ScrollLogicalPosition::Nearest;
}
- ScrollIntoView(options);
+ return ScrollIntoView(options);
}
void
@@ -717,9 +720,41 @@ Element::ScrollIntoView(const ScrollIntoViewOptions &aOptions)
return;
}
- int16_t vpercent = (aOptions.mBlock == ScrollLogicalPosition::Start)
- ? nsIPresShell::SCROLL_TOP
- : nsIPresShell::SCROLL_BOTTOM;
+ int16_t vpercent = nsIPresShell::SCROLL_CENTER;
+ switch (aOptions.mBlock) {
+ case ScrollLogicalPosition::Start:
+ vpercent = nsIPresShell::SCROLL_TOP;
+ break;
+ case ScrollLogicalPosition::Center:
+ vpercent = nsIPresShell::SCROLL_CENTER;
+ break;
+ case ScrollLogicalPosition::End:
+ vpercent = nsIPresShell::SCROLL_BOTTOM;
+ break;
+ case ScrollLogicalPosition::Nearest:
+ vpercent = nsIPresShell::SCROLL_MINIMUM;
+ break;
+ default:
+ MOZ_ASSERT_UNREACHABLE("Unexpected ScrollLogicalPosition value");
+ }
+
+ int16_t hpercent = nsIPresShell::SCROLL_CENTER;
+ switch (aOptions.mInline) {
+ case ScrollLogicalPosition::Start:
+ hpercent = nsIPresShell::SCROLL_LEFT;
+ break;
+ case ScrollLogicalPosition::Center:
+ hpercent = nsIPresShell::SCROLL_CENTER;
+ break;
+ case ScrollLogicalPosition::End:
+ hpercent = nsIPresShell::SCROLL_RIGHT;
+ break;
+ case ScrollLogicalPosition::Nearest:
+ hpercent = nsIPresShell::SCROLL_MINIMUM;
+ break;
+ default:
+ MOZ_ASSERT_UNREACHABLE("Unexpected ScrollLogicalPosition value");
+ }
uint32_t flags = nsIPresShell::SCROLL_OVERFLOW_HIDDEN;
if (aOptions.mBehavior == ScrollBehavior::Smooth) {
@@ -732,7 +767,9 @@ Element::ScrollIntoView(const ScrollIntoViewOptions &aOptions)
nsIPresShell::ScrollAxis(
vpercent,
nsIPresShell::SCROLL_ALWAYS),
- nsIPresShell::ScrollAxis(),
+ nsIPresShell::ScrollAxis(
+ hpercent,
+ nsIPresShell::SCROLL_ALWAYS),
flags);
}
@@ -1246,7 +1283,7 @@ Element::ToggleAttribute(const nsAString& aName,
if (aForce.WasPassed() && !aForce.Value()) {
return false;
}
- nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(nameToUse);
+ nsCOMPtr<nsIAtom> nameAtom = NS_AtomizeMainThread(nameToUse);
if (!nameAtom) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return false;
@@ -1279,7 +1316,7 @@ Element::SetAttribute(const nsAString& aName,
nsAutoString nameToUse;
const nsAttrName* name = InternalGetAttrNameFromQName(aName, &nameToUse);
if (!name) {
- nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(nameToUse);
+ nsCOMPtr<nsIAtom> nameAtom = NS_AtomizeMainThread(nameToUse);
if (!nameAtom) {
aError.Throw(NS_ERROR_OUT_OF_MEMORY);
return;
@@ -1361,7 +1398,7 @@ Element::GetAttributeNS(const nsAString& aNamespaceURI,
return;
}
- nsCOMPtr<nsIAtom> name = NS_Atomize(aLocalName);
+ nsCOMPtr<nsIAtom> name = NS_AtomizeMainThread(aLocalName);
bool hasAttr = GetAttr(nsid, name, aReturn);
if (!hasAttr) {
SetDOMStringToNull(aReturn);
@@ -1393,7 +1430,7 @@ Element::RemoveAttributeNS(const nsAString& aNamespaceURI,
const nsAString& aLocalName,
ErrorResult& aError)
{
- nsCOMPtr<nsIAtom> name = NS_Atomize(aLocalName);
+ nsCOMPtr<nsIAtom> name = NS_AtomizeMainThread(aLocalName);
int32_t nsid =
nsContentUtils::NameSpaceManager()->GetNameSpaceID(aNamespaceURI,
nsContentUtils::IsChromeDoc(OwnerDoc()));
@@ -1481,7 +1518,7 @@ Element::HasAttributeNS(const nsAString& aNamespaceURI,
return false;
}
- nsCOMPtr<nsIAtom> name = NS_Atomize(aLocalName);
+ nsCOMPtr<nsIAtom> name = NS_AtomizeMainThread(aLocalName);
return HasAttr(nsid, name);
}
@@ -3948,7 +3985,7 @@ Element::ClearDataset()
slots->mDataset = nullptr;
}
-nsDataHashtable<nsPtrHashKey<DOMIntersectionObserver>, int32_t>*
+nsDataHashtable<nsRefPtrHashKey<DOMIntersectionObserver>, int32_t>*
Element::RegisteredIntersectionObservers()
{
nsDOMSlots* slots = DOMSlots();
@@ -3963,7 +4000,7 @@ enum nsPreviousIntersectionThreshold {
void
Element::RegisterIntersectionObserver(DOMIntersectionObserver* aObserver)
{
- nsDataHashtable<nsPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
+ nsDataHashtable<nsRefPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
RegisteredIntersectionObservers();
if (observers->Contains(aObserver)) {
return;
@@ -3980,7 +4017,7 @@ Element::RegisterIntersectionObserver(DOMIntersectionObserver* aObserver)
void
Element::UnregisterIntersectionObserver(DOMIntersectionObserver* aObserver)
{
- nsDataHashtable<nsPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
+ nsDataHashtable<nsRefPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
RegisteredIntersectionObservers();
observers->Remove(aObserver);
}
@@ -3988,7 +4025,7 @@ Element::UnregisterIntersectionObserver(DOMIntersectionObserver* aObserver)
bool
Element::UpdateIntersectionObservation(DOMIntersectionObserver* aObserver, int32_t aThreshold)
{
- nsDataHashtable<nsPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
+ nsDataHashtable<nsRefPtrHashKey<DOMIntersectionObserver>, int32_t>* observers =
RegisteredIntersectionObservers();
if (!observers->Contains(aObserver)) {
return false;