ElementInlines.h (2041B)
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */ 3 /* This Source Code Form is subject to the terms of the Mozilla Public 4 * License, v. 2.0. If a copy of the MPL was not distributed with this 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 6 7 #ifndef mozilla_dom_ElementInlines_h 8 #define mozilla_dom_ElementInlines_h 9 10 #include "mozilla/ServoBindingTypes.h" 11 #include "mozilla/dom/Document.h" 12 #include "mozilla/dom/Element.h" 13 #include "nsGenericHTMLElement.h" 14 #include "nsIContentInlines.h" 15 16 namespace mozilla::dom { 17 18 inline void Element::RegisterActivityObserver() { 19 OwnerDoc()->RegisterActivityObserver(this); 20 } 21 22 inline void Element::UnregisterActivityObserver() { 23 OwnerDoc()->UnregisterActivityObserver(this); 24 } 25 26 inline bool Element::IsContentEditablePlainTextOnly() const { 27 const auto* const htmlElement = nsGenericHTMLElement::FromNode(this); 28 return htmlElement && !htmlElement->IsInDesignMode() && 29 htmlElement->GetContentEditableState() == 30 nsGenericHTMLElement::ContentEditableState::PlainTextOnly; 31 } 32 33 } // namespace mozilla::dom 34 35 inline mozilla::dom::Element* nsINode::GetFlattenedTreeParentElement() const { 36 nsINode* parentNode = GetFlattenedTreeParentNode(); 37 if MOZ_LIKELY (parentNode && parentNode->IsElement()) { 38 return parentNode->AsElement(); 39 } 40 41 return nullptr; 42 } 43 44 inline mozilla::dom::Element* nsINode::GetFlattenedTreeParentElementForStyle() 45 const { 46 nsINode* parentNode = GetFlattenedTreeParentNodeForStyle(); 47 if (MOZ_LIKELY(parentNode && parentNode->IsElement())) { 48 return parentNode->AsElement(); 49 } 50 return nullptr; 51 } 52 53 inline mozilla::dom::Element* 54 nsINode::GetInclusiveFlattenedTreeAncestorElement() const { 55 nsIContent* content = const_cast<nsIContent*>(nsIContent::FromNode(this)); 56 while (content && !content->IsElement()) { 57 content = content->GetFlattenedTreeParent(); 58 } 59 return mozilla::dom::Element::FromNodeOrNull(content); 60 } 61 62 #endif // mozilla_dom_ElementInlines_h