2017-12-21 04:09:22 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
|
|
|
/* 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/. */
|
|
|
|
|
2017-12-21 01:29:21 +03:00
|
|
|
#ifndef mozilla_dom_DocumentOrShadowRoot_h__
|
|
|
|
#define mozilla_dom_DocumentOrShadowRoot_h__
|
2017-12-21 04:09:22 +03:00
|
|
|
|
2018-05-11 13:57:38 +03:00
|
|
|
#include "mozilla/dom/NameSpaceConstants.h"
|
|
|
|
#include "nsContentListDeclarations.h"
|
2017-12-21 04:09:22 +03:00
|
|
|
#include "nsTArray.h"
|
2017-12-20 08:46:01 +03:00
|
|
|
#include "nsIdentifierMapEntry.h"
|
2017-12-21 04:09:22 +03:00
|
|
|
|
2017-12-20 08:46:01 +03:00
|
|
|
class nsContentList;
|
2018-04-16 16:18:48 +03:00
|
|
|
class nsIDocument;
|
2017-12-21 04:09:22 +03:00
|
|
|
class nsINode;
|
2018-08-30 01:19:42 +03:00
|
|
|
class nsWindowSizes;
|
2017-12-21 04:09:22 +03:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
class StyleSheet;
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2018-04-16 16:18:48 +03:00
|
|
|
class Element;
|
2017-12-21 04:09:22 +03:00
|
|
|
class StyleSheetList;
|
2017-12-20 08:46:01 +03:00
|
|
|
class ShadowRoot;
|
2017-12-21 04:09:22 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class meant to be shared by ShadowRoot and Document, that holds a list of
|
|
|
|
* stylesheets.
|
|
|
|
*
|
|
|
|
* TODO(emilio, bug 1418159): In the future this should hold most of the
|
|
|
|
* relevant style state, this should allow us to fix bug 548397.
|
|
|
|
*/
|
2017-12-21 01:29:21 +03:00
|
|
|
class DocumentOrShadowRoot
|
2017-12-21 04:09:22 +03:00
|
|
|
{
|
2017-12-21 01:29:21 +03:00
|
|
|
enum class Kind
|
|
|
|
{
|
2017-12-20 08:44:24 +03:00
|
|
|
Document,
|
|
|
|
ShadowRoot,
|
|
|
|
};
|
|
|
|
|
2017-12-21 04:09:22 +03:00
|
|
|
public:
|
2017-12-21 01:29:21 +03:00
|
|
|
explicit DocumentOrShadowRoot(nsIDocument&);
|
|
|
|
explicit DocumentOrShadowRoot(mozilla::dom::ShadowRoot&);
|
2017-12-20 08:44:24 +03:00
|
|
|
|
2018-08-30 01:19:42 +03:00
|
|
|
void AddSizeOfExcludingThis(nsWindowSizes&) const;
|
|
|
|
static void AddSizeOfOwnedSheetArrayExcludingThis(
|
|
|
|
nsWindowSizes&,
|
|
|
|
const nsTArray<RefPtr<StyleSheet>>&);
|
|
|
|
|
2017-12-20 08:44:24 +03:00
|
|
|
nsINode& AsNode()
|
|
|
|
{
|
|
|
|
return mAsNode;
|
|
|
|
}
|
2017-12-21 04:09:22 +03:00
|
|
|
|
|
|
|
const nsINode& AsNode() const
|
|
|
|
{
|
2017-12-20 08:44:24 +03:00
|
|
|
return mAsNode;
|
2017-12-21 04:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
StyleSheet* SheetAt(size_t aIndex) const
|
|
|
|
{
|
|
|
|
return mStyleSheets.SafeElementAt(aIndex);
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t SheetCount() const
|
|
|
|
{
|
|
|
|
return mStyleSheets.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t IndexOfSheet(const StyleSheet& aSheet) const
|
|
|
|
{
|
|
|
|
return mStyleSheets.IndexOf(&aSheet);
|
|
|
|
}
|
|
|
|
|
|
|
|
StyleSheetList& EnsureDOMStyleSheets();
|
|
|
|
|
2017-12-20 08:46:01 +03:00
|
|
|
Element* GetElementById(const nsAString& aElementId);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method returns _all_ the elements in this scope which have id
|
|
|
|
* aElementId, if there are any. Otherwise it returns null.
|
|
|
|
*
|
|
|
|
* This is useful for stuff like QuerySelector optimization and such.
|
|
|
|
*/
|
|
|
|
inline const nsTArray<Element*>*
|
|
|
|
GetAllElementsForId(const nsAString& aElementId) const;
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByTagName(const nsAString& aTagName)
|
|
|
|
{
|
|
|
|
return NS_GetContentList(&AsNode(), kNameSpaceID_Unknown, aTagName);
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName);
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByTagNameNS(const nsAString& aNamespaceURI,
|
|
|
|
const nsAString& aLocalName,
|
|
|
|
mozilla::ErrorResult&);
|
|
|
|
|
|
|
|
already_AddRefed<nsContentList>
|
|
|
|
GetElementsByClassName(const nsAString& aClasses);
|
|
|
|
|
2018-07-14 17:06:03 +03:00
|
|
|
~DocumentOrShadowRoot();
|
2017-12-21 04:09:22 +03:00
|
|
|
|
2018-02-03 23:08:30 +03:00
|
|
|
Element* GetPointerLockElement();
|
2018-02-13 19:57:32 +03:00
|
|
|
Element* GetFullscreenElement();
|
2018-02-16 21:42:58 +03:00
|
|
|
|
|
|
|
Element* ElementFromPoint(float aX, float aY);
|
|
|
|
void ElementsFromPoint(float aX, float aY,
|
|
|
|
nsTArray<RefPtr<mozilla::dom::Element>>& aElements);
|
|
|
|
|
|
|
|
/**
|
2018-05-11 20:46:15 +03:00
|
|
|
* Helper for elementFromPoint implementation that allows
|
2018-02-16 21:42:58 +03:00
|
|
|
* ignoring the scroll frame and/or avoiding layout flushes.
|
|
|
|
*
|
|
|
|
* @see nsIDOMWindowUtils::elementFromPoint
|
|
|
|
*/
|
|
|
|
Element* ElementFromPointHelper(float aX, float aY,
|
|
|
|
bool aIgnoreRootScrollFrame,
|
|
|
|
bool aFlushLayout);
|
|
|
|
enum ElementsFromPointFlags
|
|
|
|
{
|
|
|
|
IGNORE_ROOT_SCROLL_FRAME = 1,
|
|
|
|
FLUSH_LAYOUT = 2,
|
|
|
|
IS_ELEMENT_FROM_POINT = 4
|
|
|
|
};
|
|
|
|
|
|
|
|
void ElementsFromPointHelper(float aX, float aY, uint32_t aFlags,
|
|
|
|
nsTArray<RefPtr<mozilla::dom::Element>>& aElements);
|
|
|
|
|
2018-05-14 21:39:53 +03:00
|
|
|
/**
|
|
|
|
* This gets fired when the element that an id refers to changes.
|
|
|
|
* This fires at difficult times. It is generally not safe to do anything
|
|
|
|
* which could modify the DOM in any way. Use
|
|
|
|
* nsContentUtils::AddScriptRunner.
|
|
|
|
* @return true to keep the callback in the callback set, false
|
|
|
|
* to remove it.
|
|
|
|
*/
|
|
|
|
typedef bool (* IDTargetObserver)(Element* aOldElement,
|
|
|
|
Element* aNewelement, void* aData);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add an IDTargetObserver for a specific ID. The IDTargetObserver
|
|
|
|
* will be fired whenever the content associated with the ID changes
|
|
|
|
* in the future. If aForImage is true, mozSetImageElement can override
|
|
|
|
* what content is associated with the ID. In that case the IDTargetObserver
|
|
|
|
* will be notified at those times when the result of LookupImageElement
|
|
|
|
* changes.
|
|
|
|
* At most one (aObserver, aData, aForImage) triple can be
|
|
|
|
* registered for each ID.
|
|
|
|
* @return the content currently associated with the ID.
|
|
|
|
*/
|
|
|
|
Element* AddIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
|
|
|
|
void* aData, bool aForImage);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the (aObserver, aData, aForImage) triple for a specific ID, if
|
|
|
|
* registered.
|
|
|
|
*/
|
|
|
|
void RemoveIDTargetObserver(nsAtom* aID, IDTargetObserver aObserver,
|
|
|
|
void* aData, bool aForImage);
|
|
|
|
|
2018-08-17 14:35:15 +03:00
|
|
|
/**
|
|
|
|
* Lookup an image element using its associated ID, which is usually provided
|
|
|
|
* by |-moz-element()|. Similar to GetElementById, with the difference that
|
|
|
|
* elements set using mozSetImageElement have higher priority.
|
|
|
|
* @param aId the ID associated the element we want to lookup
|
|
|
|
* @return the element associated with |aId|
|
|
|
|
*/
|
|
|
|
Element* LookupImageElement(const nsAString& aElementId);
|
|
|
|
|
2018-05-14 21:39:53 +03:00
|
|
|
/**
|
|
|
|
* Check that aId is not empty and log a message to the console
|
|
|
|
* service if it is.
|
|
|
|
* @returns true if aId looks correct, false otherwise.
|
|
|
|
*/
|
|
|
|
inline bool CheckGetElementByIdArg(const nsAString& aId)
|
|
|
|
{
|
|
|
|
if (aId.IsEmpty()) {
|
|
|
|
ReportEmptyGetElementByIdArg();
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ReportEmptyGetElementByIdArg();
|
|
|
|
|
2017-12-21 04:09:22 +03:00
|
|
|
protected:
|
2018-05-11 13:57:38 +03:00
|
|
|
// Returns the reference to the sheet, if found in mStyleSheets.
|
|
|
|
already_AddRefed<StyleSheet> RemoveSheet(StyleSheet& aSheet);
|
|
|
|
void InsertSheetAt(size_t aIndex, StyleSheet& aSheet);
|
|
|
|
|
2018-01-15 09:42:47 +03:00
|
|
|
nsIContent* Retarget(nsIContent* aContent) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* If focused element's subtree root is this document or shadow root, return
|
|
|
|
* focused element, otherwise, get the shadow host recursively until the
|
|
|
|
* shadow host's subtree root is this document or shadow root.
|
|
|
|
*/
|
|
|
|
Element* GetRetargetedFocusedElement();
|
|
|
|
|
2017-12-21 04:09:22 +03:00
|
|
|
nsTArray<RefPtr<mozilla::StyleSheet>> mStyleSheets;
|
|
|
|
RefPtr<mozilla::dom::StyleSheetList> mDOMStyleSheets;
|
2017-12-20 08:44:24 +03:00
|
|
|
|
2017-12-20 08:46:01 +03:00
|
|
|
/*
|
|
|
|
* mIdentifierMap works as follows for IDs:
|
|
|
|
* 1) Attribute changes affect the table immediately (removing and adding
|
|
|
|
* entries as needed).
|
|
|
|
* 2) Removals from the DOM affect the table immediately
|
|
|
|
* 3) Additions to the DOM always update existing entries for names, and add
|
|
|
|
* new ones for IDs.
|
|
|
|
*/
|
|
|
|
nsTHashtable<nsIdentifierMapEntry> mIdentifierMap;
|
|
|
|
|
2017-12-20 08:44:24 +03:00
|
|
|
nsINode& mAsNode;
|
|
|
|
const Kind mKind;
|
2017-12-21 04:09:22 +03:00
|
|
|
};
|
|
|
|
|
2017-12-20 08:46:01 +03:00
|
|
|
inline const nsTArray<Element*>*
|
2017-12-21 01:29:21 +03:00
|
|
|
DocumentOrShadowRoot::GetAllElementsForId(const nsAString& aElementId) const
|
2017-12-20 08:46:01 +03:00
|
|
|
{
|
|
|
|
if (aElementId.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIdentifierMapEntry* entry = mIdentifierMap.GetEntry(aElementId);
|
|
|
|
return entry ? &entry->GetIdElements() : nullptr;
|
|
|
|
}
|
|
|
|
|
2017-12-21 04:09:22 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|