Merge mozilla-central to autoland. a=merge CLOSED TREE

This commit is contained in:
shindli 2018-04-27 00:44:51 +03:00
commit c72db9830d
226 changed files with 2845 additions and 4229 deletions

View File

@ -141,3 +141,4 @@ f7e9777221a34f9f23c2e4933307eb38b621b679 FIREFOX_NIGHTLY_57_END
5faab9e619901b1513fd4ca137747231be550def FIREFOX_NIGHTLY_59_END
e33efdb3e1517d521deb949de3fcd6d9946ea440 FIREFOX_BETA_60_BASE
fdd1a0082c71673239fc2f3a6a93de889c07a1be FIREFOX_NIGHTLY_60_END
ccfd7b716a91241ddbc084cb7116ec561e56d5d1 FIREFOX_BETA_61_BASE

View File

@ -761,7 +761,9 @@ Accessible::TakeFocus()
nsFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
AutoHandlingUserInputStatePusher inputStatePusher(true, nullptr, focusContent->OwnerDoc());
nsCOMPtr<nsIDOMElement> element(do_QueryInterface(focusContent));
// XXXbz: Can we actually have a non-element content here?
RefPtr<Element> element =
focusContent->IsElement() ? focusContent->AsElement() : nullptr;
fm->SetFocus(element, 0);
}
}
@ -1756,9 +1758,10 @@ Accessible::RelationByType(RelationType aType)
}
} else {
// In XUL, use first <button default="true" .../> in the document
dom::XULDocument* xulDoc = mContent->OwnerDoc()->AsXULDocument();
nsIDocument* doc = mContent->OwnerDoc();
nsCOMPtr<nsIDOMXULButtonElement> buttonEl;
if (xulDoc) {
if (doc->IsXULDocument()) {
dom::XULDocument* xulDoc = doc->AsXULDocument();
nsCOMPtr<nsINodeList> possibleDefaultButtons =
xulDoc->GetElementsByAttribute(NS_LITERAL_STRING("default"),
NS_LITERAL_STRING("true"));

View File

@ -325,7 +325,7 @@ DocAccessible::TakeFocus()
{
// Focus the document.
nsFocusManager* fm = nsFocusManager::GetFocusManager();
nsCOMPtr<nsIDOMElement> newFocus;
RefPtr<dom::Element> newFocus;
AutoHandlingUserInputStatePusher inputStatePusher(true, nullptr, mDocumentNode);
fm->MoveFocus(mDocumentNode->GetWindow(), nullptr,
nsFocusManager::MOVEFOCUS_ROOT, 0, getter_AddRefs(newFocus));

View File

@ -1372,7 +1372,7 @@ HyperTextAccessible::SetSelectionRange(int32_t aStartPos, int32_t aEndPos)
nsIDocument* docNode = mDoc->DocumentNode();
NS_ENSURE_TRUE(docNode, NS_ERROR_FAILURE);
nsCOMPtr<nsPIDOMWindowOuter> window = docNode->GetWindow();
nsCOMPtr<nsIDOMElement> result;
RefPtr<dom::Element> result;
DOMFocusManager->MoveFocus(window, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
nsIFocusManager::FLAG_BYMOVEFOCUS, getter_AddRefs(result));
}

View File

@ -53,7 +53,7 @@ class FlexboxItem extends PureComponent {
onFlexboxInspectIconClick(nodeFront) {
const { setSelectedNode } = this.props;
setSelectedNode(nodeFront, { reason: "layout-panel" }).catch(e => console.error(e));
setSelectedNode(nodeFront, { reason: "layout-panel" });
nodeFront.scrollIntoView().catch(e => console.error(e));
}

View File

@ -85,7 +85,7 @@ class GridItem extends PureComponent {
onGridInspectIconClick(nodeFront) {
let { setSelectedNode } = this.props;
setSelectedNode(nodeFront, { reason: "layout-panel" }).catch(e => console.error(e));
setSelectedNode(nodeFront, { reason: "layout-panel" });
nodeFront.scrollIntoView().catch(e => console.error(e));
}

View File

@ -61,7 +61,7 @@ class MachCommands(MachCommandBase):
preferences = [
(name, pref)
for name, prop, id, flags, pref, proptype in data
if 'CSS_PROPERTY_INTERNAL' not in flags and pref]
if 'CSSPropFlags::Internal' not in flags and pref]
return preferences

View File

@ -609,7 +609,7 @@ EffectCompositor::GetOverriddenProperties(EffectSet& aEffectSet,
for (KeyframeEffectReadOnly* effect : aEffectSet) {
for (const AnimationProperty& property : effect->Properties()) {
if (nsCSSProps::PropHasFlags(property.mProperty,
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR) &&
CSSPropFlags::CanAnimateOnCompositor) &&
!propertiesToTrackAsSet.HasProperty(property.mProperty)) {
propertiesToTrackAsSet.AddProperty(property.mProperty);
propertiesToTrack.AppendElement(property.mProperty);

View File

@ -499,7 +499,7 @@ KeyframeEffectReadOnly::SetIsRunningOnCompositor(nsCSSPropertyID aProperty,
bool aIsRunning)
{
MOZ_ASSERT(nsCSSProps::PropHasFlags(aProperty,
CSS_PROPERTY_CAN_ANIMATE_ON_COMPOSITOR),
CSSPropFlags::CanAnimateOnCompositor),
"Property being animated on compositor is a recognized "
"compositor-animatable property");
for (AnimationProperty& property : mProperties) {

View File

@ -0,0 +1,125 @@
/* -*- 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/. */
#ifndef mozilla_dom_DOMMozPromiseRequestHolder_h
#define mozilla_dom_DOMMozPromiseRequestHolder_h
#include "mozilla/DOMEventTargetHelper.h"
#include "mozilla/MozPromise.h"
namespace mozilla {
namespace dom {
/**
* This is a helper class that can be used when MozPromises are
* being consumed by binding layer code. It effectively creates
* a MozPromiseRequestHolder that auto-disconnects when the binding's
* global is disconnected.
*
* It can be used like this:
*
* RefPtr<Promise>
* SomeAsyncAPI(Args& aArgs, ErrorResult& aRv)
* {
* nsIGlobalObject* global = GetParentObject();
* if (!global) {
* aRv.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
* return nullptr;
* }
*
* RefPtr<Promise> outer = Promise::Create(global, aRv);
* if (aRv.Failed()) {
* return nullptr;
* }
*
* RefPtr<DOMMozPromiseRequestHolder> holder =
* new DOMMozPromiseRequestHolder(global);
*
* DoAsyncStuff()->Then(
* global->EventTargetFor(TaskCategory::Other), __func__,
* [holder, outer] (const Result& aResult) {
* holder->Complete();
* outer->MaybeResolve(aResult);
* }, [holder, outer] (nsresult aRv) {
* holder->Complete();
* outer->MaybeReject(aRv);
* })->Track(*holder);
*
* return outer.forget();
* }
*
* NOTE: Currently this helper class extends DETH. This is only
* so that it can bind to the global and receive the
* DisconnectFromOwner() method call. In this future the
* binding code should be factored out so DETH is not
* needed here. See bug 1456893.
*/
template<typename PromiseType>
class DOMMozPromiseRequestHolder final : public DOMEventTargetHelper
{
MozPromiseRequestHolder<PromiseType> mHolder;
~DOMMozPromiseRequestHolder() = default;
void
DisconnectFromOwner() override
{
mHolder.DisconnectIfExists();
DOMEventTargetHelper::DisconnectFromOwner();
}
JSObject*
WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override
{
// We are extending DETH to get notified when the global goes
// away, but this object should never actually be exposed to
// script.
MOZ_CRASH("illegal method");
}
public:
explicit DOMMozPromiseRequestHolder(nsIGlobalObject* aGlobal)
: DOMEventTargetHelper(aGlobal)
{
MOZ_DIAGNOSTIC_ASSERT(aGlobal);
}
operator MozPromiseRequestHolder<PromiseType>& ()
{
return mHolder;
}
operator const MozPromiseRequestHolder<PromiseType>& () const
{
return mHolder;
}
void
Complete()
{
mHolder.Complete();
DisconnectFromOwner();
}
void
DisconnectIfExists()
{
mHolder.DisconnectIfExists();
}
bool
Exists() const
{
return mHolder.Exists();
}
NS_INLINE_DECL_REFCOUNTING_INHERITED(DOMMozPromiseRequestHolder, DOMEventTargetHelper)
};
} // namespace dom
} // namespace mozilla
#endif // mozilla_dom_DOMMozPromiseRequestHolder_h

View File

@ -338,15 +338,14 @@ Element::TabIndex()
void
Element::Focus(mozilla::ErrorResult& aError)
{
nsCOMPtr<nsIDOMElement> domElement = do_QueryInterface(this);
nsFocusManager* fm = nsFocusManager::GetFocusManager();
// Also other browsers seem to have the hack to not re-focus (and flush) when
// the element is already focused.
if (fm && domElement) {
if (fm) {
if (fm->CanSkipFocus(this)) {
fm->NeedsFlushBeforeEventHandling(this);
} else {
aError = fm->SetFocus(domElement, 0);
aError = fm->SetFocus(this, 0);
}
}
}
@ -3306,9 +3305,9 @@ Element::PostHandleEventForLinks(EventChainPostVisitor& aVisitor)
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
aVisitor.mEvent->mFlags.mMultipleActionsPrevented = true;
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(this);
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
RefPtr<Element> kungFuDeathGrip(this);
fm->SetFocus(kungFuDeathGrip, nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL);
}
EventStateManager::SetActiveManager(

View File

@ -74,6 +74,7 @@ namespace dom {
struct ScrollToOptions;
class DOMIntersectionObserver;
class DOMMatrixReadOnly;
class Element;
class ElementOrCSSPseudoElement;
class UnrestrictedDoubleOrKeyframeAnimationOptions;
enum class CallerType : uint32_t;
@ -82,6 +83,8 @@ namespace dom {
} // namespace dom
} // namespace mozilla
// Declared here because of include hell.
extern "C" bool Servo_Element_IsDisplayContents(const mozilla::dom::Element*);
already_AddRefed<nsContentList>
NS_GetContentList(nsINode* aRootNode,
@ -1435,6 +1438,11 @@ public:
// Work around silly C++ name hiding stuff
nsIFrame* GetPrimaryFrame() const { return nsIContent::GetPrimaryFrame(); }
bool IsDisplayContents() const
{
return HasServoData() && Servo_Element_IsDisplayContents(this);
}
const nsAttrValue* GetParsedAttr(nsAtom* aAttr) const
{
return mAttrsAndChildren.GetAttr(aAttr);

View File

@ -13,6 +13,8 @@
using namespace mozilla;
using namespace mozilla::dom;
bool ProcessGlobal::sWasCreated = false;
ProcessGlobal::ProcessGlobal(nsFrameMessageManager* aMessageManager)
: MessageManagerGlobal(aMessageManager),
mInitialized(false)
@ -63,7 +65,17 @@ ProcessGlobal::Get()
if (!service) {
return nullptr;
}
return static_cast<ProcessGlobal*>(service.get());
ProcessGlobal* global = static_cast<ProcessGlobal*>(service.get());
if (global) {
sWasCreated = true;
}
return global;
}
bool
ProcessGlobal::WasCreated()
{
return sWasCreated;
}
void

View File

@ -51,6 +51,7 @@ public:
bool Init();
static ProcessGlobal* Get();
static bool WasCreated();
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(ProcessGlobal, nsIMessageSender)
@ -100,6 +101,8 @@ protected:
private:
bool mInitialized;
static bool sWasCreated;
};
} // namespace dom

View File

@ -3737,8 +3737,6 @@ Selection::NotifySelectionListeners()
// focus but only selection range is updated.
if (newEditingHost && newEditingHost != focusedElement) {
MOZ_ASSERT(!newEditingHost->IsInNativeAnonymousSubtree());
nsCOMPtr<nsIDOMElement> domElementToFocus =
do_QueryInterface(newEditingHost->AsDOMNode());
// Note that don't steal focus from focused window if the window doesn't
// have focus and if the window isn't focused window, shouldn't be
// scrolled to the new focused element.
@ -3746,7 +3744,7 @@ Selection::NotifySelectionListeners()
if (focusedWindow != fm->GetFocusedWindow()) {
flags |= nsIFocusManager::FLAG_NOSCROLL;
}
fm->SetFocus(domElementToFocus, flags);
fm->SetFocus(newEditingHost, flags);
}
}
}

View File

@ -169,6 +169,7 @@ EXPORTS.mozilla.dom += [
'DOMImplementation.h',
'DOMIntersectionObserver.h',
'DOMMatrix.h',
'DOMMozPromiseRequestHolder.h',
'DOMParser.h',
'DOMPoint.h',
'DOMPrefs.h',

View File

@ -469,7 +469,7 @@ mozilla::dom::TraceBlackJS(JSTracer* aTrc, bool aIsShutdownGC)
return;
}
if (nsFrameMessageManager::GetChildProcessManager()) {
if (ProcessGlobal::WasCreated() && nsFrameMessageManager::GetChildProcessManager()) {
ProcessGlobal* pg = ProcessGlobal::Get();
if (pg) {
mozilla::TraceScriptHolder(ToSupports(pg), aTrc);

View File

@ -235,12 +235,12 @@ nsContentSink::Init(nsIDocument* aDoc,
NS_IMETHODIMP
nsContentSink::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
NS_ASSERTION(!mRunsToCompletion, "How come a fragment parser observed sheets?");
if (!aWasAlternate) {
NS_ASSERTION(mPendingSheetCount > 0, "How'd that happen?");
MOZ_ASSERT(!mRunsToCompletion, "How come a fragment parser observed sheets?");
if (!aWasDeferred) {
MOZ_ASSERT(mPendingSheetCount > 0, "How'd that happen?");
--mPendingSheetCount;
if (mPendingSheetCount == 0 &&
@ -790,15 +790,16 @@ nsContentSink::ProcessStyleLinkFromHeader(const nsAString& aHref,
}
// If this is a fragment parser, we don't want to observe.
// We don't support CORS for processing instructions
bool isAlternate;
rv = mCSSLoader->LoadStyleLink(nullptr, url, nullptr, aTitle, aMedia, aAlternate,
CORS_NONE, referrerPolicy,
/* integrity = */ EmptyString(),
mRunsToCompletion ? nullptr : this,
&isAlternate);
NS_ENSURE_SUCCESS(rv, rv);
auto loadResultOrErr =
mCSSLoader->LoadStyleLink(nullptr, url, nullptr, aTitle, aMedia, aAlternate,
CORS_NONE, referrerPolicy,
/* integrity = */ EmptyString(),
mRunsToCompletion ? nullptr : this);
if (loadResultOrErr.isErr()) {
return loadResultOrErr.unwrapErr();
}
if (!isAlternate && !mRunsToCompletion) {
if (loadResultOrErr.unwrap().ShouldBlock() && !mRunsToCompletion) {
++mPendingSheetCount;
mScriptLoader->AddParserBlockingScriptExecutionBlocker();
}

View File

@ -15,6 +15,7 @@
#include "mozilla/ArrayUtils.h"
#include "mozilla/AutoRestore.h"
#include "mozilla/BinarySearch.h"
#include "mozilla/CSSEnabledState.h"
#include "mozilla/DebugOnly.h"
#include "mozilla/EffectSet.h"
#include "mozilla/EnumSet.h"
@ -3524,11 +3525,10 @@ nsIDocument::GetActiveElement()
}
// No focused element anywhere in this document. Try to get the BODY.
RefPtr<nsHTMLDocument> htmlDoc = AsHTMLDocument();
if (htmlDoc) {
if (IsHTMLOrXHTML()) {
// Because of IE compatibility, return null when html document doesn't have
// a body.
return htmlDoc->GetBody();
return AsHTMLDocument()->GetBody();
}
// If we couldn't get a BODY, return the root element.
@ -5744,7 +5744,7 @@ GetPseudoElementType(const nsString& aString, ErrorResult& aRv)
}
RefPtr<nsAtom> pseudo = NS_Atomize(Substring(aString, 1));
return nsCSSPseudoElements::GetPseudoType(pseudo,
nsCSSProps::EnabledState::eInUASheets);
CSSEnabledState::eInUASheets);
}
already_AddRefed<Element>

View File

@ -105,16 +105,25 @@ protected:
if (mFlags & SkipInvisibleContent) {
// Treat the visibility of the ShadowRoot as if it were
// the host content.
nsCOMPtr<nsIContent> content = do_QueryInterface(aNode);
if (ShadowRoot* shadowRoot = ShadowRoot::FromNodeOrNull(content)) {
content = shadowRoot->GetHost();
//
// FIXME(emilio): I suspect instead of this a bunch of the GetParent()
// calls here should be doing GetFlattenedTreeParent, then this condition
// should be unreachable...
if (ShadowRoot* shadowRoot = ShadowRoot::FromNode(aNode)) {
aNode = shadowRoot->GetHost();
}
if (content) {
nsIFrame* frame = content->GetPrimaryFrame();
if (aNode->IsContent()) {
nsIFrame* frame = aNode->AsContent()->GetPrimaryFrame();
if (!frame) {
if (aNode->IsElement() && aNode->AsElement()->IsDisplayContents()) {
return true;
}
if (aNode->IsText()) {
// We have already checked that our parent is visible.
//
// FIXME(emilio): Text not assigned to a <slot> in Shadow DOM should
// probably return false...
return true;
}
if (aNode->IsHTMLElement(nsGkAtoms::rp)) {
@ -1248,11 +1257,14 @@ nsHTMLCopyEncoder::SetSelection(nsISelection* aSelection)
// we'll just use the common parent of the first range. Implicit assumption
// here that multi-range selections are table cell selections, in which case
// the common parent is somewhere in the table and we don't really care where.
//
// FIXME(emilio, bug 1455894): This assumption is already wrong, and will
// probably be more wrong in a Shadow DOM world...
//
// We should be able to write this as "Find the common ancestor of the
// selection, then go through the flattened tree and serialize the selected
// nodes", effectively serializing the composed tree.
RefPtr<nsRange> range = selection->GetRangeAt(0);
if (!range) {
// XXXbz can this happen given rangeCount > 0?
return NS_ERROR_NULL_POINTER;
}
nsINode* commonParent = range->GetCommonAncestor();
for (nsCOMPtr<nsIContent> selContent(do_QueryInterface(commonParent));

View File

@ -302,7 +302,7 @@ GetCurrentWindow(nsIContent* aContent)
}
// static
nsIContent*
Element*
nsFocusManager::GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
SearchRange aSearchRange,
nsPIDOMWindowOuter** aFocusedWindow)
@ -311,7 +311,7 @@ nsFocusManager::GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
*aFocusedWindow = nullptr;
nsIContent* currentContent = nullptr;
Element* currentContent = nullptr;
nsPIDOMWindowOuter* window = aWindow;
for (;;) {
*aFocusedWindow = window;
@ -349,7 +349,7 @@ nsFocusManager::GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
}
// static
nsIContent*
Element*
nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
{
// For input number, redirect focus to our anonymous text control.
@ -365,7 +365,7 @@ nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
if (numberControlFrame) {
HTMLInputElement* textControl =
numberControlFrame->GetAnonTextControl();
return static_cast<nsIContent*>(textControl);
return textControl;
}
}
}
@ -392,13 +392,13 @@ nsFocusManager::GetRedirectedFocus(nsIContent* aContent)
if (children) {
nsIContent* child = children->Item(0);
if (child && child->IsXULElement(nsGkAtoms::slider))
return child;
return child->AsElement();
}
}
}
if (inputField) {
nsCOMPtr<nsIContent> retval = do_QueryInterface(inputField);
nsCOMPtr<Element> retval = do_QueryInterface(inputField);
return retval;
}
}
@ -513,14 +513,13 @@ nsFocusManager::GetLastFocusMethod(mozIDOMWindowProxy* aWindow, uint32_t* aLastF
}
NS_IMETHODIMP
nsFocusManager::SetFocus(nsIDOMElement* aElement, uint32_t aFlags)
nsFocusManager::SetFocus(Element* aElement, uint32_t aFlags)
{
LOGFOCUS(("<<SetFocus begin>>"));
nsCOMPtr<nsIContent> newFocus = do_QueryInterface(aElement);
NS_ENSURE_ARG(newFocus);
NS_ENSURE_ARG(aElement);
SetFocusInner(newFocus, aFlags, true, true);
SetFocusInner(aElement, aFlags, true, true);
LOGFOCUS(("<<SetFocus end>>"));
@ -528,21 +527,19 @@ nsFocusManager::SetFocus(nsIDOMElement* aElement, uint32_t aFlags)
}
NS_IMETHODIMP
nsFocusManager::ElementIsFocusable(nsIDOMElement* aElement, uint32_t aFlags,
nsFocusManager::ElementIsFocusable(Element* aElement, uint32_t aFlags,
bool* aIsFocusable)
{
NS_ENSURE_TRUE(aElement, NS_ERROR_INVALID_ARG);
nsCOMPtr<nsIContent> aContent = do_QueryInterface(aElement);
*aIsFocusable = CheckIfFocusable(aContent, aFlags) != nullptr;
*aIsFocusable = CheckIfFocusable(aElement, aFlags) != nullptr;
return NS_OK;
}
NS_IMETHODIMP
nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, nsIDOMElement* aStartElement,
uint32_t aType, uint32_t aFlags, nsIDOMElement** aElement)
nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, Element* aStartElement,
uint32_t aType, uint32_t aFlags, Element** aElement)
{
*aElement = nullptr;
@ -568,12 +565,8 @@ nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, nsIDOMElement* aStartElem
}
nsCOMPtr<nsPIDOMWindowOuter> window;
nsCOMPtr<nsIContent> startContent;
if (aStartElement) {
startContent = do_QueryInterface(aStartElement);
NS_ENSURE_TRUE(startContent, NS_ERROR_INVALID_ARG);
window = GetCurrentWindow(startContent);
window = GetCurrentWindow(aStartElement);
} else {
window = aWindow ? nsPIDOMWindowOuter::From(aWindow) : mFocusedWindow.get();
}
@ -582,7 +575,7 @@ nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, nsIDOMElement* aStartElem
bool noParentTraversal = aFlags & FLAG_NOPARENTFRAME;
nsCOMPtr<nsIContent> newFocus;
nsresult rv = DetermineElementToMoveFocus(window, startContent, aType, noParentTraversal,
nsresult rv = DetermineElementToMoveFocus(window, aStartElement, aType, noParentTraversal,
getter_AddRefs(newFocus));
if (rv == NS_SUCCESS_DOM_NO_OPERATION) {
return NS_OK;
@ -592,13 +585,14 @@ nsFocusManager::MoveFocus(mozIDOMWindowProxy* aWindow, nsIDOMElement* aStartElem
LOGCONTENTNAVIGATION("Element to be focused: %s", newFocus.get());
if (newFocus) {
if (newFocus && newFocus->IsElement()) {
// for caret movement, pass false for the aFocusChanged argument,
// otherwise the caret will end up moving to the focus position. This
// would be a problem because the caret would move to the beginning of the
// focused link making it impossible to navigate the caret over a link.
SetFocusInner(newFocus, aFlags, aType != MOVEFOCUS_CARET, true);
CallQueryInterface(newFocus, aElement);
SetFocusInner(newFocus->AsElement(), aFlags, aType != MOVEFOCUS_CARET,
true);
*aElement = do_AddRef(newFocus->AsElement()).take();
}
else if (aType == MOVEFOCUS_ROOT || aType == MOVEFOCUS_CARET) {
// no content was found, so clear the focus for these two types.
@ -766,7 +760,7 @@ nsFocusManager::WindowRaised(mozIDOMWindowProxy* aWindow)
// retrieve the last focused element within the window that was raised
nsCOMPtr<nsPIDOMWindowOuter> currentWindow;
nsCOMPtr<nsIContent> currentFocus =
RefPtr<Element> currentFocus =
GetFocusedDescendant(window, eIncludeAllDescendants,
getter_AddRefs(currentWindow));
@ -940,7 +934,7 @@ nsFocusManager::WindowShown(mozIDOMWindowProxy* aWindow, bool aNeedsFocus)
if (aNeedsFocus) {
nsCOMPtr<nsPIDOMWindowOuter> currentWindow;
nsCOMPtr<nsIContent> currentFocus =
RefPtr<Element> currentFocus =
GetFocusedDescendant(window, eIncludeAllDescendants,
getter_AddRefs(currentWindow));
if (currentWindow)
@ -1105,10 +1099,10 @@ nsFocusManager::FireDelayedEvents(nsIDocument* aDocument)
}
NS_IMETHODIMP
nsFocusManager::FocusPlugin(nsIContent* aContent)
nsFocusManager::FocusPlugin(Element* aPlugin)
{
NS_ENSURE_ARG(aContent);
SetFocusInner(aContent, 0, true, false);
NS_ENSURE_ARG(aPlugin);
SetFocusInner(aPlugin, 0, true, false);
return NS_OK;
}
@ -1229,11 +1223,11 @@ nsFocusManager::ActivateOrDeactivate(nsPIDOMWindowOuter* aWindow, bool aActive)
}
void
nsFocusManager::SetFocusInner(nsIContent* aNewContent, int32_t aFlags,
nsFocusManager::SetFocusInner(Element* aNewContent, int32_t aFlags,
bool aFocusChanged, bool aAdjustWidget)
{
// if the element is not focusable, just return and leave the focus as is
nsCOMPtr<nsIContent> contentToFocus = CheckIfFocusable(aNewContent, aFlags);
RefPtr<Element> contentToFocus = CheckIfFocusable(aNewContent, aFlags);
if (!contentToFocus)
return;
@ -1375,7 +1369,7 @@ nsFocusManager::SetFocusInner(nsIContent* aNewContent, int32_t aFlags,
isElementInActiveWindow, isElementInFocusedWindow, sendFocusEvent));
if (sendFocusEvent) {
nsCOMPtr<nsIContent> oldFocusedContent = mFocusedContent;
RefPtr<Element> oldFocusedContent = mFocusedContent;
// return if blurring fails or the focus changes during the blur
if (mFocusedWindow) {
// if the focus is being moved to another element in the same document,
@ -1584,17 +1578,18 @@ nsFocusManager::IsNonFocusableRoot(nsIContent* aContent)
nsContentUtils::IsUserFocusIgnored(aContent));
}
nsIContent*
nsFocusManager::CheckIfFocusable(nsIContent* aContent, uint32_t aFlags)
Element*
nsFocusManager::CheckIfFocusable(Element* aContent, uint32_t aFlags)
{
if (!aContent)
return nullptr;
// this is a special case for some XUL elements or input number, where an
// anonymous child is actually focusable and not the element itself.
nsCOMPtr<nsIContent> redirectedFocus = GetRedirectedFocus(aContent);
if (redirectedFocus)
RefPtr<Element> redirectedFocus = GetRedirectedFocus(aContent);
if (redirectedFocus) {
return CheckIfFocusable(redirectedFocus, aFlags);
}
nsCOMPtr<nsIDocument> doc = aContent->GetComposedDoc();
// can't focus elements that are not in documents
@ -1614,8 +1609,9 @@ nsFocusManager::CheckIfFocusable(nsIContent* aContent, uint32_t aFlags)
// the root content can always be focused,
// except in userfocusignored context.
if (aContent == doc->GetRootElement())
if (aContent == doc->GetRootElement()) {
return nsContentUtils::IsUserFocusIgnored(aContent) ? nullptr : aContent;
}
// cannot focus content in print preview mode. Only the root can be focused.
nsPresContext* presContext = shell->GetPresContext();
@ -1663,7 +1659,7 @@ nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
LOGFOCUS(("<<Blur begin>>"));
// hold a reference to the focused content, which may be null
nsCOMPtr<nsIContent> content = mFocusedContent;
RefPtr<Element> content = mFocusedContent;
if (content) {
if (!content->IsInComposedDoc()) {
mFocusedContent = nullptr;
@ -1838,7 +1834,7 @@ nsFocusManager::Blur(nsPIDOMWindowOuter* aWindowToClear,
void
nsFocusManager::Focus(nsPIDOMWindowOuter* aWindow,
nsIContent* aContent,
Element* aContent,
uint32_t aFlags,
bool aIsNewDocument,
bool aFocusChanged,

View File

@ -15,6 +15,7 @@
#include "nsIWidget.h"
#include "nsWeakReference.h"
#include "mozilla/Attributes.h"
#include "mozilla/RefPtr.h"
#define FOCUSMETHOD_MASK 0xF000
#define FOCUSMETHODANDRING_MASK 0xF0F000
@ -27,6 +28,7 @@ class nsPIDOMWindowOuter;
namespace mozilla {
namespace dom {
class Element;
class TabParent;
}
}
@ -62,10 +64,10 @@ public:
/**
* A faster version of nsIFocusManager::GetFocusedElement, returning a
* raw nsIContent pointer (instead of having AddRef-ed nsIDOMElement
* raw Element pointer (instead of having AddRef-ed nsIDOMElement
* pointer filled in to an out-parameter).
*/
nsIContent* GetFocusedContent() { return mFocusedContent; }
mozilla::dom::Element* GetFocusedContent() { return mFocusedContent; }
/**
* Returns true if aContent currently has focus.
@ -98,9 +100,9 @@ public:
return handlingDocument.forget();
}
void NeedsFlushBeforeEventHandling(nsIContent* aContent)
void NeedsFlushBeforeEventHandling(mozilla::dom::Element* aElement)
{
if (mFocusedContent == aContent) {
if (mFocusedContent == aElement) {
mEventHandlingNeedsFlush = true;
}
}
@ -142,9 +144,10 @@ public:
// Return focused content in aWindow or one of visible sub windows.
eIncludeVisibleDescendants,
};
static nsIContent* GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
SearchRange aSearchRange,
nsPIDOMWindowOuter** aFocusedWindow);
static mozilla::dom::Element*
GetFocusedDescendant(nsPIDOMWindowOuter* aWindow,
SearchRange aSearchRange,
nsPIDOMWindowOuter** aFocusedWindow);
/**
* Returns the content node that focus will be redirected to if aContent was
@ -156,7 +159,7 @@ public:
* XXXndeakin this should be removed eventually but I want to do that as
* followup work.
*/
static nsIContent* GetRedirectedFocus(nsIContent* aContent);
static mozilla::dom::Element* GetRedirectedFocus(nsIContent* aContent);
/**
* Returns an InputContextAction cause for aFlags.
@ -193,7 +196,7 @@ protected:
* All actual focus changes must use this method to do so. (as opposed
* to those that update the focus in an inactive window for instance).
*/
void SetFocusInner(nsIContent* aNewContent, int32_t aFlags,
void SetFocusInner(mozilla::dom::Element* aNewContent, int32_t aFlags,
bool aFocusChanged, bool aAdjustWidget);
/**
@ -244,7 +247,8 @@ protected:
* frame, so only the IsFocusable method on the content node must be
* true.
*/
nsIContent* CheckIfFocusable(nsIContent* aContent, uint32_t aFlags);
mozilla::dom::Element* CheckIfFocusable(mozilla::dom::Element* aContent,
uint32_t aFlags);
/**
* Blurs the currently focused element. Returns false if another element was
@ -302,7 +306,7 @@ protected:
* If aAdjustWidget is false, don't change the widget focus state.
*/
void Focus(nsPIDOMWindowOuter* aWindow,
nsIContent* aContent,
mozilla::dom::Element* aContent,
uint32_t aFlags,
bool aIsNewDocument,
bool aFocusChanged,
@ -641,7 +645,7 @@ private:
// the currently focused content, which is always inside mFocusedWindow. This
// is a cached copy of the mFocusedWindow's current content. This may be null
// if no content is focused.
nsCOMPtr<nsIContent> mFocusedContent;
RefPtr<mozilla::dom::Element> mFocusedContent;
// these fields store a content node temporarily while it is being focused
// or blurred to ensure that a recursive call doesn't refire the same event.

View File

@ -843,7 +843,8 @@ nsFrameLoader::Show(int32_t marginWidth, int32_t marginHeight,
presShell = mDocShell->GetPresShell();
if (presShell) {
nsIDocument* doc = presShell->GetDocument();
nsHTMLDocument* htmlDoc = doc ? doc->AsHTMLDocument() : nullptr;
nsHTMLDocument* htmlDoc =
doc && doc->IsHTMLOrXHTML() ? doc->AsHTMLDocument() : nullptr;
if (htmlDoc) {
nsAutoString designMode;

View File

@ -241,7 +241,7 @@ AdjustFocusAfterCaretMove(nsPIDOMWindowOuter* aWindow)
// adjust the focus to the new caret position
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> result;
RefPtr<dom::Element> result;
fm->MoveFocus(aWindow, nullptr, nsIFocusManager::MOVEFOCUS_CARET,
nsIFocusManager::FLAG_NOSCROLL, getter_AddRefs(result));
}

View File

@ -4652,7 +4652,7 @@ static bool ShouldShowFocusRingIfFocusedByMouse(nsIContent* aNode)
}
void
nsGlobalWindowInner::SetFocusedNode(nsIContent* aNode,
nsGlobalWindowInner::SetFocusedNode(Element* aNode,
uint32_t aFocusMethod,
bool aNeedsFocus)
{
@ -5234,10 +5234,8 @@ nsGlobalWindowInner::FireOfflineStatusEventIfChanged()
// The event is fired at the body element, or if there is no body element,
// at the document.
nsCOMPtr<EventTarget> eventTarget = mDoc.get();
nsHTMLDocument* htmlDoc = mDoc->AsHTMLDocument();
if (htmlDoc) {
Element* body = htmlDoc->GetBody();
if (body) {
if (mDoc->IsHTMLOrXHTML()) {
if (Element* body = mDoc->GetBody()) {
eventTarget = body;
}
} else {

View File

@ -1197,7 +1197,7 @@ public:
bool IsInModalState();
virtual void SetFocusedNode(nsIContent* aNode,
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;

View File

@ -4828,13 +4828,12 @@ nsGlobalWindowOuter::FocusOuter(ErrorResult& aError)
return;
}
nsIContent* frame = parentdoc->FindContentForSubDocument(mDoc);
nsCOMPtr<nsIDOMElement> frameElement = do_QueryInterface(frame);
if (frameElement) {
RefPtr<Element> frame = parentdoc->FindContentForSubDocument(mDoc);
if (frame) {
uint32_t flags = nsIFocusManager::FLAG_NOSCROLL;
if (canFocus)
flags |= nsIFocusManager::FLAG_RAISE;
aError = fm->SetFocus(frameElement, flags);
aError = fm->SetFocus(frame, flags);
}
return;
}
@ -6299,14 +6298,16 @@ nsGlobalWindowOuter::UpdateCommands(const nsAString& anAction,
}
nsIDocument* doc = rootWindow->GetExtantDoc();
XULDocument* xulDoc = doc ? doc->AsXULDocument() : nullptr;
// See if we contain a XUL document.
if (!doc || !doc->IsXULDocument()) {
return;
}
// selectionchange action is only used for mozbrowser, not for XUL. So we bypass
// XUL command dispatch if anAction is "selectionchange".
if (xulDoc && !anAction.EqualsLiteral("selectionchange")) {
if (!anAction.EqualsLiteral("selectionchange")) {
// Retrieve the command dispatcher and call updateCommands on it.
nsIDOMXULCommandDispatcher* xulCommandDispatcher =
xulDoc->GetCommandDispatcher();
doc->AsXULDocument()->GetCommandDispatcher();
if (xulCommandDispatcher) {
nsContentUtils::AddScriptRunner(new CommandDispatcher(xulCommandDispatcher,
anAction));
@ -6625,7 +6626,7 @@ nsGlobalWindowOuter::SetChromeEventHandler(EventTarget* aChromeEventHandler)
}
void
nsGlobalWindowOuter::SetFocusedNode(nsIContent* aNode,
nsGlobalWindowOuter::SetFocusedNode(Element* aNode,
uint32_t aFocusMethod,
bool aNeedsFocus)
{
@ -6677,13 +6678,12 @@ nsGlobalWindowOuter::SetKeyboardIndicators(UIStateChangeType aShowAccelerators,
bool newShouldShowFocusRing = ShouldShowFocusRing();
if (mInnerWindow && nsGlobalWindowInner::Cast(mInnerWindow)->mHasFocus &&
mInnerWindow->mFocusedNode &&
oldShouldShowFocusRing != newShouldShowFocusRing &&
mInnerWindow->mFocusedNode->IsElement()) {
oldShouldShowFocusRing != newShouldShowFocusRing) {
// Update focusedNode's state.
if (newShouldShowFocusRing) {
mInnerWindow->mFocusedNode->AsElement()->AddStates(NS_EVENT_STATE_FOCUSRING);
mInnerWindow->mFocusedNode->AddStates(NS_EVENT_STATE_FOCUSRING);
} else {
mInnerWindow->mFocusedNode->AsElement()->RemoveStates(NS_EVENT_STATE_FOCUSRING);
mInnerWindow->mFocusedNode->RemoveStates(NS_EVENT_STATE_FOCUSRING);
}
}
}
@ -7258,11 +7258,12 @@ nsGlobalWindowOuter::RestoreWindowState(nsISupports *aState)
// if a link is focused, refocus with the FLAG_SHOWRING flag set. This makes
// it easy to tell which link was last clicked when going back a page.
nsIContent* focusedNode = inner->GetFocusedNode();
Element* focusedNode = inner->GetFocusedNode();
if (nsContentUtils::ContentIsLink(focusedNode)) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> focusedElement(do_QueryInterface(focusedNode));
// XXXbz Do we need the stack strong ref here?
RefPtr<Element> focusedElement = focusedNode;
fm->SetFocus(focusedElement, nsIFocusManager::FLAG_NOSCROLL |
nsIFocusManager::FLAG_SHOWRING);
}

View File

@ -979,7 +979,7 @@ public:
nsIntSize DevToCSSIntPixels(nsIntSize px);
nsIntSize CSSToDevIntPixels(nsIntSize px);
virtual void SetFocusedNode(nsIContent* aNode,
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) override;

View File

@ -3347,9 +3347,23 @@ public:
nsIHTMLCollection* Children();
uint32_t ChildElementCount();
virtual nsHTMLDocument* AsHTMLDocument() { return nullptr; }
virtual mozilla::dom::SVGDocument* AsSVGDocument() { return nullptr; }
virtual mozilla::dom::XULDocument* AsXULDocument() { return nullptr; }
/**
* Asserts IsHTMLOrXHTML, and can't return null.
* Defined inline in nsHTMLDocument.h
*/
inline nsHTMLDocument* AsHTMLDocument();
/**
* Asserts IsSVGDocument, and can't return null.
* Defined inline in SVGDocument.h
*/
inline mozilla::dom::SVGDocument* AsSVGDocument();
/**
* Asserts IsXULDocument, and can't return null.
* Defined inline in XULDocument.h
*/
inline mozilla::dom::XULDocument* AsXULDocument();
/*
* Given a node, get a weak reference to it and append that reference to

View File

@ -9,6 +9,7 @@
#include "nsISupports.h"
#include "mozilla/StyleSheet.h"
#include "mozilla/Result.h"
class nsICSSLoaderObserver;
class nsIURI;
@ -19,6 +20,65 @@ class nsIURI;
class nsIStyleSheetLinkingElement : public nsISupports {
public:
enum class ForceUpdate
{
Yes,
No,
};
enum class IsAlternate
{
Yes,
No,
};
enum class Completed
{
Yes,
No,
};
enum class MediaMatched
{
Yes,
No,
};
struct Update
{
private:
bool mWillNotify;
bool mIsAlternate;
bool mMediaMatched;
public:
Update()
: mWillNotify(false)
, mIsAlternate(false)
, mMediaMatched(false)
{ }
Update(Completed aCompleted, IsAlternate aIsAlternate, MediaMatched aMediaMatched)
: mWillNotify(aCompleted == Completed::No)
, mIsAlternate(aIsAlternate == IsAlternate::Yes)
, mMediaMatched(aMediaMatched == MediaMatched::Yes)
{ }
bool WillNotify() const
{
return mWillNotify;
}
bool ShouldBlock() const
{
if (!mWillNotify) {
return false;
}
return !mIsAlternate && mMediaMatched;
}
};
NS_DECLARE_STATIC_IID_ACCESSOR(NS_ISTYLESHEETLINKINGELEMENT_IID)
/**
@ -50,21 +110,12 @@ public:
*
* @param aObserver observer to notify once the stylesheet is loaded.
* This will be passed to the CSSLoader
* @param [out] aWillNotify whether aObserver will be notified when the sheet
* loads. If this is false, then either we didn't
* start the sheet load at all, the load failed, or
* this was an inline sheet that completely finished
* loading. In the case when the load failed the
* failure code will be returned.
* @param [out] whether the sheet is an alternate sheet. This value is only
* meaningful if aWillNotify is true.
* @param aForceUpdate whether we wand to force the update, flushing the
* cached version if any.
*/
virtual nsresult UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
bool *aWillNotify,
bool *aIsAlternate,
bool aForceUpdate = false) = 0;
virtual mozilla::Result<Update, nsresult>
UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
ForceUpdate = ForceUpdate::No) = 0;
/**
* Tells this element whether to update the stylesheet when the

View File

@ -484,8 +484,8 @@ public:
* DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
* INSTEAD.
*/
inline nsIContent* GetFocusedNode() const;
virtual void SetFocusedNode(nsIContent* aNode,
inline mozilla::dom::Element* GetFocusedNode() const;
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;
@ -659,8 +659,8 @@ protected:
nsCOMPtr<nsPIDOMWindowOuter> mOuterWindow;
// the element within the document that is currently focused when this
// window is active
nsCOMPtr<nsIContent> mFocusedNode;
// window is active.
RefPtr<mozilla::dom::Element> mFocusedNode;
// The AudioContexts created for the current document, if any.
nsTArray<mozilla::dom::AudioContext*> mAudioContexts; // Weak
@ -973,8 +973,8 @@ public:
* DO NOT CALL EITHER OF THESE METHODS DIRECTLY. USE THE FOCUS MANAGER
* INSTEAD.
*/
inline nsIContent* GetFocusedNode() const;
virtual void SetFocusedNode(nsIContent* aNode,
inline mozilla::dom::Element* GetFocusedNode() const;
virtual void SetFocusedNode(mozilla::dom::Element* aNode,
uint32_t aFocusMethod = 0,
bool aNeedsFocus = false) = 0;

View File

@ -89,13 +89,13 @@ nsPIDOMWindowInner::GetDocShell() const
return mOuterWindow ? mOuterWindow->GetDocShell() : nullptr;
}
nsIContent*
mozilla::dom::Element*
nsPIDOMWindowOuter::GetFocusedNode() const
{
return mInnerWindow ? mInnerWindow->GetFocusedNode() : nullptr;
}
nsIContent*
mozilla::dom::Element*
nsPIDOMWindowInner::GetFocusedNode() const
{
return mFocusedNode;

View File

@ -176,13 +176,11 @@ uint32_t nsStyleLinkElement::ParseLinkTypes(const nsAString& aTypes)
return linkMask;
}
nsresult
Result<nsStyleLinkElement::Update, nsresult>
nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
bool* aWillNotify,
bool* aIsAlternate,
bool aForceReload)
ForceUpdate aForceUpdate)
{
if (aForceReload) {
if (aForceUpdate == ForceUpdate::Yes) {
// We remove this stylesheet from the cache to load a new version.
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
@ -192,30 +190,24 @@ nsStyleLinkElement::UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
doc->CSSLoader()->ObsoleteSheet(mStyleSheet->GetOriginalURI());
}
}
return DoUpdateStyleSheet(nullptr, nullptr, aObserver, aWillNotify,
aIsAlternate, aForceReload);
return DoUpdateStyleSheet(nullptr, nullptr, aObserver, aForceUpdate);
}
nsresult
nsStyleLinkElement::UpdateStyleSheetInternal(nsIDocument *aOldDocument,
ShadowRoot *aOldShadowRoot,
bool aForceUpdate)
Result<nsStyleLinkElement::Update, nsresult>
nsStyleLinkElement::UpdateStyleSheetInternal(nsIDocument* aOldDocument,
ShadowRoot* aOldShadowRoot,
ForceUpdate aForceUpdate)
{
bool notify, alternate;
return DoUpdateStyleSheet(aOldDocument, aOldShadowRoot, nullptr, &notify,
&alternate, aForceUpdate);
return DoUpdateStyleSheet(
aOldDocument, aOldShadowRoot, nullptr, aForceUpdate);
}
nsresult
Result<nsStyleLinkElement::Update, nsresult>
nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
ShadowRoot* aOldShadowRoot,
nsICSSLoaderObserver* aObserver,
bool* aWillNotify,
bool* aIsAlternate,
bool aForceUpdate)
ForceUpdate aForceUpdate)
{
*aWillNotify = false;
nsCOMPtr<nsIContent> thisContent = do_QueryInterface(this);
// All instances of nsStyleLinkElement should implement nsIContent.
MOZ_ASSERT(thisContent);
@ -224,7 +216,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
thisContent->IsAnonymousContentInSVGUseSubtree()) {
// Stylesheets in <use>-cloned subtrees are disabled until we figure out
// how they should behave.
return NS_OK;
return Update { };
}
// Check for a ShadowRoot because link elements are inert in a
@ -232,7 +224,7 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
ShadowRoot* containingShadow = thisContent->GetContainingShadow();
if (thisContent->IsHTMLElement(nsGkAtoms::link) &&
(aOldShadowRoot || containingShadow)) {
return NS_OK;
return Update { };
}
if (mStyleSheet && (aOldDocument || aOldShadowRoot)) {
@ -259,26 +251,25 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
// When static documents are created, stylesheets are cloned manually.
if (mDontLoadStyle || !mUpdatesEnabled ||
thisContent->OwnerDoc()->IsStaticDocument()) {
return NS_OK;
return Update { };
}
nsCOMPtr<nsIDocument> doc = thisContent->IsInShadowTree() ?
thisContent->OwnerDoc() : thisContent->GetUncomposedDoc();
if (!doc || !doc->CSSLoader()->GetEnabled()) {
return NS_OK;
return Update { };
}
bool isInline;
nsCOMPtr<nsIPrincipal> triggeringPrincipal;
nsCOMPtr<nsIURI> uri = GetStyleSheetURL(&isInline, getter_AddRefs(triggeringPrincipal));
if (!aForceUpdate && mStyleSheet && !isInline && uri) {
nsIURI* oldURI = mStyleSheet->GetSheetURI();
if (oldURI) {
if (aForceUpdate == ForceUpdate::No && mStyleSheet && !isInline && uri) {
if (nsIURI* oldURI = mStyleSheet->GetSheetURI()) {
bool equal;
nsresult rv = oldURI->Equals(uri, &equal);
if (NS_SUCCEEDED(rv) && equal) {
return NS_OK; // We already loaded this stylesheet
return Update { };
}
}
}
@ -297,21 +288,17 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
}
if (!uri && !isInline) {
return NS_OK; // If href is empty and this is not inline style then just bail
// If href is empty and this is not inline style then just bail
return Update { };
}
nsAutoString title, type, media;
bool isAlternate;
GetStyleSheetInfo(title, type, media, &isAlternate);
bool hasAlternateRel;
GetStyleSheetInfo(title, type, media, &hasAlternateRel);
if (!type.LowerCaseEqualsLiteral("text/css")) {
return NS_OK;
return Update { };
}
bool doneLoading = false;
nsresult rv = NS_OK;
// Load the link's referrerpolicy attribute. If the link does not provide a
// referrerpolicy attribute, ignore this and use the document's referrer
// policy
@ -324,58 +311,57 @@ nsStyleLinkElement::DoUpdateStyleSheet(nsIDocument* aOldDocument,
if (isInline) {
nsAutoString text;
if (!nsContentUtils::GetNodeTextContent(thisContent, false, text, fallible)) {
return NS_ERROR_OUT_OF_MEMORY;
return Err(NS_ERROR_OUT_OF_MEMORY);
}
MOZ_ASSERT(thisContent->NodeInfo()->NameAtom() != nsGkAtoms::link,
"<link> is not 'inline', and needs different CSP checks");
MOZ_ASSERT(thisContent->IsElement());
nsresult rv = NS_OK;
if (!nsStyleUtil::CSPAllowsInlineStyle(thisContent->AsElement(),
thisContent->NodePrincipal(),
triggeringPrincipal,
doc->GetDocumentURI(),
mLineNumber, text, &rv))
return rv;
mLineNumber, text, &rv)) {
if (NS_FAILED(rv)) {
return Err(rv);
}
return Update { };
}
// Parse the style sheet.
rv = doc->CSSLoader()->
return doc->CSSLoader()->
LoadInlineStyle(thisContent, text, triggeringPrincipal, mLineNumber,
title, media, referrerPolicy,
aObserver, &doneLoading, &isAlternate);
} else {
nsAutoString integrity;
if (thisContent->IsElement()) {
thisContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity,
integrity);
}
if (!integrity.IsEmpty()) {
MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
("nsStyleLinkElement::DoUpdateStyleSheet, integrity=%s",
NS_ConvertUTF16toUTF8(integrity).get()));
}
// XXXbz clone the URI here to work around content policies modifying URIs.
nsCOMPtr<nsIURI> clonedURI;
uri->Clone(getter_AddRefs(clonedURI));
NS_ENSURE_TRUE(clonedURI, NS_ERROR_OUT_OF_MEMORY);
rv = doc->CSSLoader()->
LoadStyleLink(thisContent, clonedURI, triggeringPrincipal, title, media,
isAlternate, GetCORSMode(), referrerPolicy, integrity,
aObserver, &isAlternate);
if (NS_FAILED(rv)) {
// Don't propagate LoadStyleLink() errors further than this, since some
// consumers (e.g. nsXMLContentSink) will completely abort on innocuous
// things like a stylesheet load being blocked by the security system.
doneLoading = true;
isAlternate = false;
rv = NS_OK;
}
aObserver);
}
NS_ENSURE_SUCCESS(rv, rv);
*aWillNotify = !doneLoading;
*aIsAlternate = isAlternate;
return NS_OK;
nsAutoString integrity;
if (thisContent->IsElement()) {
thisContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::integrity,
integrity);
}
if (!integrity.IsEmpty()) {
MOZ_LOG(SRILogHelper::GetSriLog(), mozilla::LogLevel::Debug,
("nsStyleLinkElement::DoUpdateStyleSheet, integrity=%s",
NS_ConvertUTF16toUTF8(integrity).get()));
}
auto resultOrError =
doc->CSSLoader()->LoadStyleLink(thisContent,
uri,
triggeringPrincipal,
title,
media,
hasAlternateRel,
GetCORSMode(),
referrerPolicy,
integrity,
aObserver);
if (resultOrError.isErr()) {
// Don't propagate LoadStyleLink() errors further than this, since some
// consumers (e.g. nsXMLContentSink) will completely abort on innocuous
// things like a stylesheet load being blocked by the security system.
return Update { };
}
return resultOrError;
}

View File

@ -16,6 +16,7 @@
#include "mozilla/Attributes.h"
#include "mozilla/CORSMode.h"
#include "mozilla/StyleSheetInlines.h"
#include "mozilla/Unused.h"
#include "mozilla/net/ReferrerPolicy.h"
#include "nsCOMPtr.h"
#include "nsIStyleSheetLinkingElement.h"
@ -45,16 +46,16 @@ public:
void SetStyleSheet(mozilla::StyleSheet* aStyleSheet) override;
mozilla::StyleSheet* GetStyleSheet() override;
void InitStyleLinkElement(bool aDontLoadStyle) override;
nsresult UpdateStyleSheet(nsICSSLoaderObserver* aObserver,
bool* aWillNotify,
bool* aIsAlternate,
bool aForceReload) override;
mozilla::Result<Update, nsresult>
UpdateStyleSheet(nsICSSLoaderObserver*, ForceUpdate) override;
void SetEnableUpdates(bool aEnableUpdates) override;
void GetCharset(nsAString& aCharset) override;
virtual void OverrideBaseURI(nsIURI* aNewBaseURI) override;
virtual void SetLineNumber(uint32_t aLineNumber) override;
virtual uint32_t GetLineNumber() override;
void OverrideBaseURI(nsIURI* aNewBaseURI) override;
void SetLineNumber(uint32_t aLineNumber) override;
uint32_t GetLineNumber() override;
enum RelValue {
ePREFETCH = 0x00000001,
@ -72,20 +73,25 @@ public:
void UpdateStyleSheetInternal()
{
UpdateStyleSheetInternal(nullptr, nullptr);
mozilla::Unused << UpdateStyleSheetInternal(nullptr, nullptr);
}
protected:
/**
* @param aOldDocument should be non-null only if we're updating because we
* removed the node from the document.
* @param aOldDocument should be non-null only if we're updating because we
* removed the node from the document.
* @param aOldShadowRoot should be non-null only if we're updating because we
* removed the node from a shadow tree.
* @param aForceUpdate true will force the update even if the URI has not
* changed. This should be used in cases when something
* about the content that affects the resulting sheet
* changed but the URI may not have changed.
*
* TODO(emilio): Should probably pass a single DocumentOrShadowRoot.
*/
nsresult UpdateStyleSheetInternal(nsIDocument *aOldDocument,
mozilla::dom::ShadowRoot *aOldShadowRoot,
bool aForceUpdate = false);
mozilla::Result<Update, nsresult> UpdateStyleSheetInternal(
nsIDocument* aOldDocument,
mozilla::dom::ShadowRoot* aOldShadowRoot,
ForceUpdate = ForceUpdate::No);
virtual already_AddRefed<nsIURI> GetStyleSheetURL(bool* aIsInline, nsIPrincipal** aTriggeringPrincipal) = 0;
virtual void GetStyleSheetInfo(nsAString& aTitle,
@ -121,12 +127,11 @@ private:
* about the content that affects the resulting sheet
* changed but the URI may not have changed.
*/
nsresult DoUpdateStyleSheet(nsIDocument* aOldDocument,
mozilla::dom::ShadowRoot* aOldShadowRoot,
nsICSSLoaderObserver* aObserver,
bool* aWillNotify,
bool* aIsAlternate,
bool aForceUpdate);
mozilla::Result<Update, nsresult>
DoUpdateStyleSheet(nsIDocument* aOldDocument,
mozilla::dom::ShadowRoot* aOldShadowRoot,
nsICSSLoaderObserver* aObserver,
ForceUpdate);
RefPtr<mozilla::StyleSheet> mStyleSheet;
protected:

View File

@ -17,7 +17,7 @@ def generate(output, idlFilename, dataFile):
propList = eval(f.read())
props = ""
for name, prop, id, flags, pref, proptype in propList:
if "CSS_PROPERTY_INTERNAL" in flags:
if "CSSPropFlags::Internal" in flags:
continue
# Unfortunately, even some of the getters here are fallible
# (e.g. on nsComputedDOMStyle).

View File

@ -1083,7 +1083,7 @@ EventStateManager::LookForAccessKeyAndExecute(
if (start == -1 && focusedContent->GetBindingParent())
start = mAccessKeys.IndexOf(focusedContent->GetBindingParent());
}
nsIContent *content;
RefPtr<Element> element;
nsIFrame *frame;
int32_t length = mAccessKeys.Count();
for (uint32_t i = 0; i < aAccessCharCodes.Length(); ++i) {
@ -1091,9 +1091,10 @@ EventStateManager::LookForAccessKeyAndExecute(
nsAutoString accessKey;
AppendUCS4ToUTF16(ch, accessKey);
for (count = 1; count <= length; ++count) {
content = mAccessKeys[(start + count) % length];
frame = content->GetPrimaryFrame();
if (IsAccessKeyTarget(content, frame, accessKey)) {
// mAccessKeys always stores Element instances.
element = mAccessKeys[(start + count) % length]->AsElement();
frame = element->GetPrimaryFrame();
if (IsAccessKeyTarget(element, frame, accessKey)) {
if (!aExecute) {
return true;
}
@ -1107,11 +1108,10 @@ EventStateManager::LookForAccessKeyAndExecute(
bool focusChanged = false;
if (shouldActivate) {
focusChanged = content->PerformAccesskey(shouldActivate, aIsTrustedEvent);
focusChanged = element->PerformAccesskey(shouldActivate, aIsTrustedEvent);
} else {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(content);
fm->SetFocus(element, nsIFocusManager::FLAG_BYKEY);
focusChanged = true;
}
@ -3133,7 +3133,7 @@ EventStateManager::PostHandleKeyboardEvent(WidgetKeyboardEvent* aKeyboardEvent,
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARD)) :
(isDocMove ? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARDDOC) :
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARD));
nsCOMPtr<nsIDOMElement> result;
RefPtr<Element> result;
fm->MoveFocus(mDocument->GetWindow(), nullptr, dir,
nsIFocusManager::FLAG_BYKEY,
getter_AddRefs(result));
@ -3308,6 +3308,8 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
}
}
MOZ_ASSERT_IF(newFocus, newFocus->IsElement());
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
// if something was found to focus, focus it. Otherwise, if the
@ -3329,8 +3331,7 @@ EventStateManager::PostHandleEvent(nsPresContext* aPresContext,
if (mouseEvent->inputSource == MouseEventBinding::MOZ_SOURCE_TOUCH) {
flags |= nsIFocusManager::FLAG_BYTOUCH;
}
nsCOMPtr<nsIDOMElement> newFocusElement = do_QueryInterface(newFocus);
fm->SetFocus(newFocusElement, flags);
fm->SetFocus(newFocus->AsElement(), flags);
}
else if (!suppressBlur) {
// clear the focus within the frame and then set it as the

View File

@ -7,6 +7,8 @@
#include "mozilla/dom/HTMLHRElement.h"
#include "mozilla/dom/HTMLHRElementBinding.h"
#include "nsCSSProps.h"
NS_IMPL_NS_NEW_HTML_ELEMENT(HR)
namespace mozilla {

View File

@ -3210,7 +3210,7 @@ HTMLInputElement::Focus(ErrorResult& aError)
nsCOMPtr<nsIFormControl> formCtrl =
do_QueryInterface(childFrame->GetContent());
if (formCtrl && formCtrl->ControlType() == NS_FORM_BUTTON_BUTTON) {
nsCOMPtr<nsIDOMElement> element = do_QueryInterface(formCtrl);
nsCOMPtr<Element> element = do_QueryInterface(formCtrl);
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm && element) {
fm->SetFocus(element, 0);

View File

@ -61,9 +61,10 @@ HTMLLabelElement::Focus(ErrorResult& aError)
// retarget the focus method at the for content
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elem = do_QueryObject(GetLabeledElement());
if (elem)
RefPtr<Element> elem = GetLabeledElement();
if (elem) {
fm->SetFocus(elem, 0);
}
}
}
@ -156,12 +157,12 @@ HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
// pass FLAG_BYMOUSE so that we get correct focus ring behavior,
// but we don't want to pass FLAG_BYMOUSE if this click event was
// caused by the user pressing an accesskey.
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(content);
bool byMouse = (mouseEvent->inputSource != MouseEventBinding::MOZ_SOURCE_KEYBOARD);
bool byTouch = (mouseEvent->inputSource == MouseEventBinding::MOZ_SOURCE_TOUCH);
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOVEFOCUS |
(byMouse ? nsIFocusManager::FLAG_BYMOUSE : 0) |
(byTouch ? nsIFocusManager::FLAG_BYTOUCH : 0));
fm->SetFocus(content,
nsIFocusManager::FLAG_BYMOVEFOCUS |
(byMouse ? nsIFocusManager::FLAG_BYMOUSE : 0) |
(byTouch ? nsIFocusManager::FLAG_BYTOUCH : 0));
}
}
// Dispatch a new click event to |content|

View File

@ -107,7 +107,7 @@ HTMLLegendElement::Focus(ErrorResult& aError)
return;
}
nsCOMPtr<nsIDOMElement> result;
RefPtr<Element> result;
aError = fm->MoveFocus(nullptr, this, nsIFocusManager::MOVEFOCUS_FORWARD,
nsIFocusManager::FLAG_NOPARENTFRAME,
getter_AddRefs(result));

View File

@ -192,7 +192,7 @@ HTMLLinkElement::UnbindFromTree(bool aDeep, bool aNullParent)
CreateAndDispatchEvent(oldDoc, NS_LITERAL_STRING("DOMLinkRemoved"));
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
Unused << UpdateStyleSheetInternal(oldDoc, oldShadowRoot);
}
bool
@ -328,11 +328,13 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
UpdatePreload(aName, aValue, aOldValue);
}
UpdateStyleSheetInternal(nullptr, nullptr,
dropSheet ||
(aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type));
const bool forceUpdate = dropSheet ||
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type;
Unused << UpdateStyleSheetInternal(
nullptr, nullptr, forceUpdate ? ForceUpdate::Yes : ForceUpdate::No);
}
} else {
// Since removing href or rel makes us no longer link to a
@ -343,7 +345,7 @@ HTMLLinkElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
}
if ((aName == nsGkAtoms::as || aName == nsGkAtoms::type ||
aName == nsGkAtoms::crossorigin || aName == nsGkAtoms::media) &&

View File

@ -94,7 +94,7 @@ HTMLStyleElement::ContentChanged(nsIContent* aContent)
{
mTriggeringPrincipal = nullptr;
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
UpdateStyleSheetInternal(nullptr, nullptr);
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
}
}
@ -130,7 +130,7 @@ HTMLStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
return;
}
UpdateStyleSheetInternal(oldDoc, oldShadow);
Unused << UpdateStyleSheetInternal(oldDoc, oldShadow);
}
nsresult
@ -144,7 +144,7 @@ HTMLStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
}
}
@ -191,7 +191,7 @@ HTMLStyleElement::SetTextContentInternal(const nsAString& aTextContent,
mTriggeringPrincipal = aScriptedPrincipal;
UpdateStyleSheetInternal(nullptr, nullptr);
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
}
already_AddRefed<nsIURI>

View File

@ -34,6 +34,7 @@ EXPORTS += [
'nsGenericHTMLElement.h',
'nsGenericHTMLFrameElement.h',
'nsHTMLDNSPrefetch.h',
'nsHTMLDocument.h',
'nsIConstraintValidation.h',
'nsIForm.h',
'nsIFormControl.h',

View File

@ -15,7 +15,6 @@
#include "PLDHashTable.h"
#include "nsIHttpChannel.h"
#include "nsHTMLStyleSheet.h"
#include "nsThreadUtils.h"
#include "nsICommandManager.h"
#include "mozilla/dom/HTMLSharedElement.h"
@ -225,8 +224,6 @@ public:
return nsIDocument::GetLocation();
}
virtual nsHTMLDocument* AsHTMLDocument() override { return this; }
static bool MatchFormControls(Element* aElement, int32_t aNamespaceID,
nsAtom* aAtom, void* aData);
@ -367,6 +364,13 @@ protected:
bool mPendingMaybeEditingStateChanged;
};
inline nsHTMLDocument*
nsIDocument::AsHTMLDocument()
{
MOZ_ASSERT(IsHTMLOrXHTML());
return static_cast<nsHTMLDocument*>(this);
}
#define NS_HTML_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
NS_DOCUMENT_INTERFACE_TABLE_BEGIN(_class) \
NS_INTERFACE_TABLE_ENTRY(_class, nsIHTMLDocument)

View File

@ -7,7 +7,8 @@
interface mozIDOMWindowProxy;
interface nsIDocument;
interface nsIContent;
webidl Element;
[scriptable, uuid(86e1f1e1-365d-493b-b52a-a649f3f311dc)]
/**
@ -81,7 +82,7 @@ interface nsIFocusManager : nsISupports
* Changes the focused element reference within the window containing
* aElement to aElement.
*/
void setFocus(in nsIDOMElement aElement, in unsigned long aFlags);
void setFocus(in Element aElement, in unsigned long aFlags);
/**
* Move the focus to another element. If aStartElement is specified, then
@ -101,9 +102,9 @@ interface nsIFocusManager : nsISupports
* Returns the element that was focused. The return value may be null if focus
* was moved into a child process.
*/
nsIDOMElement moveFocus(in mozIDOMWindowProxy aWindow,
in nsIDOMElement aStartElement,
in unsigned long aType, in unsigned long aFlags);
Element moveFocus(in mozIDOMWindowProxy aWindow,
in Element aStartElement,
in unsigned long aType, in unsigned long aFlags);
/**
* Clears the focused element within aWindow. If the current focusedWindow
@ -142,7 +143,7 @@ interface nsIFocusManager : nsISupports
/***
* Check if given element is focusable.
*/
boolean elementIsFocusable(in nsIDOMElement aElement, in unsigned long aFlags);
boolean elementIsFocusable(in Element aElement, in unsigned long aFlags);
/*
* Raise the window when switching focus
@ -265,7 +266,7 @@ interface nsIFocusManager : nsISupports
* normal focus except that the widget focus is not changed. Updating the
* widget focus state is the responsibility of the caller.
*/
[noscript] void focusPlugin(in nsIContent aPlugin);
[noscript] void focusPlugin(in Element aPlugin);
/**
* Used in a child process to indicate that the parent window is now

View File

@ -10,11 +10,12 @@ interface nsIController;
interface nsIControllers;
interface mozIDOMWindowProxy;
webidl Element;
[scriptable, uuid(a9fa9fd3-8d62-4f94-9ed8-3ea9c3cf0773)]
interface nsIDOMXULCommandDispatcher : nsISupports
{
attribute nsIDOMElement focusedElement;
attribute Element focusedElement;
attribute mozIDOMWindowProxy focusedWindow;
void addCommandUpdater(in nsIDOMElement updater,
@ -29,7 +30,7 @@ interface nsIDOMXULCommandDispatcher : nsISupports
void advanceFocus();
void rewindFocus();
void advanceFocusIntoSubtree(in nsIDOMElement elt);
void advanceFocusIntoSubtree(in Element elt);
// When locked, command updating is batched until unlocked. Always ensure that
// lock and unlock is called in a pair.

View File

@ -2684,7 +2684,7 @@ TabChild::RecvNavigateByKey(const bool& aForward, const bool& aForDocumentNaviga
{
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> result;
RefPtr<Element> result;
nsCOMPtr<nsPIDOMWindowOuter> window = do_GetInterface(WebNavigation());
// Move to the first or last document.

View File

@ -488,15 +488,14 @@ TabParent::RecvMoveFocus(const bool& aForward, const bool& aForDocumentNavigatio
{
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
if (fm) {
nsCOMPtr<nsIDOMElement> dummy;
RefPtr<Element> dummy;
uint32_t type = aForward ?
(aForDocumentNavigation ? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARDDOC) :
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_FORWARD)) :
(aForDocumentNavigation ? static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARDDOC) :
static_cast<uint32_t>(nsIFocusManager::MOVEFOCUS_BACKWARD));
nsCOMPtr<nsIDOMElement> frame = do_QueryInterface(mFrameElement);
fm->MoveFocus(nullptr, frame, type, nsIFocusManager::FLAG_BYKEY,
fm->MoveFocus(nullptr, mFrameElement, type, nsIFocusManager::FLAG_BYKEY,
getter_AddRefs(dummy));
}
return IPC_OK();
@ -2029,8 +2028,8 @@ TabParent::RecvRequestFocus(const bool& aCanRaise)
if (aCanRaise)
flags |= nsIFocusManager::FLAG_RAISE;
nsCOMPtr<nsIDOMElement> node = do_QueryInterface(mFrameElement);
fm->SetFocus(node, flags);
RefPtr<Element> element = mFrameElement;
fm->SetFocus(element, flags);
return IPC_OK();
}

View File

@ -930,7 +930,6 @@ Saiz::Parse(Box& aBox)
uint32_t flags;
MOZ_TRY_VAR(flags, reader->ReadU32());
uint8_t version = flags >> 24;
if (flags & 1) {
MOZ_TRY_VAR(mAuxInfoType, reader->ReadU32());
MOZ_TRY_VAR(mAuxInfoTypeParameter, reader->ReadU32());

View File

@ -1481,7 +1481,7 @@ nsPluginInstanceOwner::ProcessMouseDown(Event* aMouseEvent)
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elem = do_QueryReferent(mContent);
nsCOMPtr<Element> elem = do_QueryReferent(mContent);
fm->SetFocus(elem, 0);
}
}

View File

@ -10,6 +10,7 @@
#include "mozilla/BasicEvents.h"
#include "mozilla/Preferences.h"
#include "mozilla/Telemetry.h"
#include "mozilla/dom/Element.h"
#include "PluginInstanceParent.h"
#include "BrowserStreamParent.h"
#include "PluginBackgroundDestroyer.h"
@ -2224,7 +2225,8 @@ PluginInstanceParent::AnswerPluginFocusChange(const bool& gotFocus)
nsCOMPtr<nsIDOMElement> element;
owner->GetDOMElement(getter_AddRefs(element));
if (fm && element) {
fm->SetFocus(element, 0);
nsCOMPtr<dom::Element> domElement(do_QueryInterface(element));
fm->SetFocus(domElement, 0);
}
}
}

View File

@ -13,6 +13,9 @@
class nsSVGElement;
namespace mozilla {
class SVGContextPaint;
namespace dom {
class SVGForeignObjectElement;
@ -36,17 +39,33 @@ public:
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult,
bool aPreallocateChildren) const override;
virtual SVGDocument* AsSVGDocument() override {
return this;
void SetCurrentContextPaint(const SVGContextPaint* aContextPaint)
{
mCurrentContextPaint = aContextPaint;
}
const SVGContextPaint* GetCurrentContextPaint() const
{
return mCurrentContextPaint;
}
private:
void EnsureNonSVGUserAgentStyleSheetsLoaded();
bool mHasLoadedNonSVGUserAgentStyleSheets;
// This is maintained by AutoSetRestoreSVGContextPaint.
const SVGContextPaint* mCurrentContextPaint = nullptr;
};
} // namespace dom
} // namespace mozilla
inline mozilla::dom::SVGDocument*
nsIDocument::AsSVGDocument()
{
MOZ_ASSERT(IsSVGDocument());
return static_cast<mozilla::dom::SVGDocument*>(this);
}
#endif // mozilla_dom_SVGDocument_h

View File

@ -86,7 +86,7 @@ SVGStyleElement::UnbindFromTree(bool aDeep, bool aNullParent)
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
ShadowRoot* oldShadow = GetContainingShadow();
SVGStyleElementBase::UnbindFromTree(aDeep, aNullParent);
UpdateStyleSheetInternal(oldDoc, oldShadow);
Unused << UpdateStyleSheetInternal(oldDoc, oldShadow);
}
nsresult
@ -100,7 +100,7 @@ SVGStyleElement::AfterSetAttr(int32_t aNameSpaceID, nsAtom* aName,
if (aName == nsGkAtoms::title ||
aName == nsGkAtoms::media ||
aName == nsGkAtoms::type) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
}
}
@ -159,7 +159,7 @@ void
SVGStyleElement::ContentChanged(nsIContent* aContent)
{
if (nsContentUtils::IsInSameAnonymousTree(this, aContent)) {
UpdateStyleSheetInternal(nullptr, nullptr);
Unused << UpdateStyleSheetInternal(nullptr, nullptr);
}
}

View File

@ -5,6 +5,7 @@
* You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "hasht.h"
#include "nsHTMLDocument.h"
#include "nsICryptoHash.h"
#include "nsNetCID.h"
#include "nsThreadUtils.h"
@ -136,10 +137,6 @@ RelaxSameOrigin(nsPIDOMWindowInner* aParent,
return NS_ERROR_FAILURE;
}
nsHTMLDocument* html = document->AsHTMLDocument();
if (NS_WARN_IF(!html)) {
return NS_ERROR_FAILURE;
}
if (!html->IsRegistrableDomainSuffixOfOrEqualTo(aInputRpId, originHost)) {
return NS_ERROR_DOM_SECURITY_ERR;
}

View File

@ -41,13 +41,6 @@
*
*/
// Forward decl because of nsHTMLDocument.h's complex dependency on /layout/style
class nsHTMLDocument {
public:
bool IsRegistrableDomainSuffixOfOrEqualTo(const nsAString& aHostSuffixString,
const nsACString& aOrigHost);
};
namespace mozilla {
namespace dom {

View File

@ -78,11 +78,8 @@ EvaluateAppID(nsPIDOMWindowInner* aParent, const nsString& aOrigin,
if (!document || !document->IsHTMLDocument()) {
return false;
}
nsHTMLDocument* html = document->AsHTMLDocument();
if (NS_WARN_IF(!html)) {
return false;
}
nsHTMLDocument* html = document->AsHTMLDocument();
// Use the base domain as the facet for evaluation. This lets this algorithm
// relax the whole eTLD+1.
nsCOMPtr<nsIEffectiveTLDService> tldService =

View File

@ -3258,12 +3258,6 @@ WorkerPrivate::DoRunLoop(JSContext* aCx)
currentStatus = mStatus;
}
if (currentStatus >= Terminating && previousStatus < Terminating) {
if (mScope) {
mScope->NoteTerminating();
}
}
// if all holders are done then we can kill this thread.
if (currentStatus != Running && !HasActiveHolders()) {
@ -4519,6 +4513,13 @@ WorkerPrivate::NotifyInternal(WorkerStatus aStatus)
return true;
}
if (aStatus >= Terminating) {
if (mScope) {
MutexAutoUnlock unlock(mMutex);
mScope->NoteTerminating();
}
}
// Make sure the hybrid event target stops dispatching runnables
// once we reaching the killing state.
if (aStatus == Killing) {

View File

@ -226,9 +226,8 @@ nsXBLBinding::BindAnonymousContent(nsIContent* aAnonParent,
// To make XUL templates work (and other goodies that happen when
// an element is added to a XUL document), we need to notify the
// XUL document using its special API.
XULDocument* xuldoc = doc ? doc->AsXULDocument() : nullptr;
if (xuldoc) {
xuldoc->AddSubtreeToDocument(child);
if (doc && doc->IsXULDocument()) {
doc->AsXULDocument()->AddSubtreeToDocument(child);
}
#endif
}
@ -243,15 +242,15 @@ nsXBLBinding::UnbindAnonymousContent(nsIDocument* aDocument,
// Hold a strong ref while doing this, just in case.
nsCOMPtr<nsIContent> anonParent = aAnonParent;
#ifdef MOZ_XUL
XULDocument* xuldoc = aDocument ? aDocument->AsXULDocument() : nullptr;
const bool isXULDocument = aDocument && aDocument->IsXULDocument();
#endif
for (nsIContent* child = aAnonParent->GetFirstChild();
child;
child = child->GetNextSibling()) {
child->UnbindFromTree(true, aNullParent);
#ifdef MOZ_XUL
if (xuldoc) {
xuldoc->RemoveSubtreeFromDocument(child);
if (isXULDocument) {
aDocument->AsXULDocument()->RemoveSubtreeFromDocument(child);
}
#endif
}

View File

@ -164,7 +164,7 @@ nsXBLResourceLoader::LoadResources(nsIContent* aBoundElement)
// nsICSSLoaderObserver
NS_IMETHODIMP
nsXBLResourceLoader::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
if (!mResources) {

View File

@ -69,7 +69,7 @@ XMLStylesheetProcessingInstruction::UnbindFromTree(bool aDeep, bool aNullParent)
nsCOMPtr<nsIDocument> oldDoc = GetUncomposedDoc();
ProcessingInstruction::UnbindFromTree(aDeep, aNullParent);
UpdateStyleSheetInternal(oldDoc, nullptr);
Unused << UpdateStyleSheetInternal(oldDoc, nullptr);
}
// nsIDOMNode
@ -80,7 +80,7 @@ XMLStylesheetProcessingInstruction::SetNodeValueInternal(const nsAString& aNodeV
{
CharacterData::SetNodeValueInternal(aNodeValue, aError);
if (!aError.Failed()) {
UpdateStyleSheetInternal(nullptr, nullptr, true);
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
}
}

View File

@ -8,6 +8,7 @@
#define mozilla_dom_XMLStylesheetProcessingInstruction_h
#include "mozilla/Attributes.h"
#include "mozilla/Unused.h"
#include "mozilla/dom/ProcessingInstruction.h"
#include "nsIURI.h"
#include "nsStyleLinkElement.h"
@ -68,7 +69,7 @@ public:
if (rv.Failed()) {
return;
}
UpdateStyleSheetInternal(nullptr, nullptr, true);
Unused << UpdateStyleSheetInternal(nullptr, nullptr, ForceUpdate::Yes);
}
protected:

View File

@ -425,11 +425,11 @@ nsXMLContentSink::OnTransformDone(nsresult aResult,
NS_IMETHODIMP
nsXMLContentSink::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
if (!mPrettyPrinting) {
return nsContentSink::StyleSheetLoaded(aSheet, aWasAlternate, aStatus);
return nsContentSink::StyleSheetLoaded(aSheet, aWasDeferred, aStatus);
}
if (!mDocument->CSSLoader()->HasPendingLoads()) {
@ -603,12 +603,11 @@ nsXMLContentSink::CloseElement(nsIContent* aContent)
nsCOMPtr<nsIStyleSheetLinkingElement> ssle(do_QueryInterface(aContent));
if (ssle) {
ssle->SetEnableUpdates(true);
bool willNotify;
bool isAlternate;
rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
&willNotify,
&isAlternate);
if (NS_SUCCEEDED(rv) && willNotify && !isAlternate && !mRunsToCompletion) {
auto updateOrError =
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
if (updateOrError.isErr()) {
rv = updateOrError.unwrapErr();
} else if (updateOrError.unwrap().ShouldBlock() && !mRunsToCompletion) {
++mPendingSheetCount;
mScriptLoader->AddParserBlockingScriptExecutionBlocker();
}
@ -1268,20 +1267,19 @@ nsXMLContentSink::HandleProcessingInstruction(const char16_t *aTarget,
// This is an xml-stylesheet processing instruction... but it might not be
// a CSS one if the type is set to something else.
ssle->SetEnableUpdates(true);
bool willNotify;
bool isAlternate;
rv = ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this,
&willNotify,
&isAlternate);
NS_ENSURE_SUCCESS(rv, rv);
auto updateOrError =
ssle->UpdateStyleSheet(mRunsToCompletion ? nullptr : this);
if (updateOrError.isErr()) {
return updateOrError.unwrapErr();
}
if (willNotify) {
auto update = updateOrError.unwrap();
if (update.WillNotify()) {
// Successfully started a stylesheet load
if (!isAlternate && !mRunsToCompletion) {
if (update.ShouldBlock() && !mRunsToCompletion) {
++mPendingSheetCount;
mScriptLoader->AddParserBlockingScriptExecutionBlocker();
}
return NS_OK;
}
}

View File

@ -322,11 +322,10 @@ txMozillaXMLOutput::endElement()
do_QueryInterface(mCurrentNode);
if (ssle) {
ssle->SetEnableUpdates(true);
bool willNotify;
bool isAlternate;
nsresult rv = ssle->UpdateStyleSheet(mNotifier, &willNotify,
&isAlternate);
if (mNotifier && NS_SUCCEEDED(rv) && willNotify && !isAlternate) {
auto updateOrError = ssle->UpdateStyleSheet(mNotifier);
if (mNotifier &&
updateOrError.isOk() &&
updateOrError.unwrap().ShouldBlock()) {
mNotifier->AddPendingStylesheet();
}
}
@ -400,10 +399,10 @@ txMozillaXMLOutput::processingInstruction(const nsString& aTarget, const nsStrin
if (ssle) {
ssle->SetEnableUpdates(true);
bool willNotify;
bool isAlternate;
rv = ssle->UpdateStyleSheet(mNotifier, &willNotify, &isAlternate);
if (mNotifier && NS_SUCCEEDED(rv) && willNotify && !isAlternate) {
auto updateOrError = ssle->UpdateStyleSheet(mNotifier);
if (mNotifier &&
updateOrError.isOk() &&
updateOrError.unwrap().ShouldBlock()) {
mNotifier->AddPendingStylesheet();
}
}
@ -975,7 +974,7 @@ txTransformNotifier::ScriptEvaluated(nsresult aResult,
NS_IMETHODIMP
txTransformNotifier::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
if (mPendingStylesheetCount == 0) {
@ -986,7 +985,7 @@ txTransformNotifier::StyleSheetLoaded(StyleSheet* aSheet,
}
// We're never waiting for alternate stylesheets
if (!aWasAlternate) {
if (!aWasDeferred) {
--mPendingStylesheetCount;
SignalTransformEnd();
}

View File

@ -2104,18 +2104,20 @@ XULDocument::InsertXMLStylesheetPI(const nsXULPrototypePI* aProtoPI,
// load the stylesheet if necessary, passing ourselves as
// nsICSSObserver
bool willNotify;
bool isAlternate;
rv = ssle->UpdateStyleSheet(this, &willNotify, &isAlternate);
if (NS_SUCCEEDED(rv) && willNotify && !isAlternate) {
++mPendingSheets;
auto result = ssle->UpdateStyleSheet(this);
if (result.isErr()) {
// Ignore errors from UpdateStyleSheet; we don't want failure to
// do that to break the XUL document load. But do propagate out
// NS_ERROR_OUT_OF_MEMORY.
if (result.unwrapErr() == NS_ERROR_OUT_OF_MEMORY) {
return result.unwrapErr();
}
return NS_OK;
}
// Ignore errors from UpdateStyleSheet; we don't want failure to
// do that to break the XUL document load. But do propagate out
// NS_ERROR_OUT_OF_MEMORY.
if (rv == NS_ERROR_OUT_OF_MEMORY) {
return rv;
auto update = result.unwrap();
if (update.ShouldBlock()) {
++mPendingSheets;
}
return NS_OK;
@ -2492,10 +2494,7 @@ XULDocument::ResumeWalk()
do_QueryInterface(element);
NS_ASSERTION(ssle, "<html:style> doesn't implement "
"nsIStyleSheetLinkingElement?");
bool willNotify;
bool isAlternate;
ssle->UpdateStyleSheet(nullptr, &willNotify,
&isAlternate);
Unused << ssle->UpdateStyleSheet(nullptr);
}
}
}
@ -2880,14 +2879,13 @@ XULDocument::DoneWalking()
NS_IMETHODIMP
XULDocument::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
if (!aWasAlternate) {
if (!aWasDeferred) {
// Don't care about when alternate sheets finish loading
NS_ASSERTION(mPendingSheets > 0,
"Unexpected StyleSheetLoaded notification");
MOZ_ASSERT(mPendingSheets > 0,
"Unexpected StyleSheetLoaded notification");
--mPendingSheets;

View File

@ -83,10 +83,6 @@ public:
virtual void EndLoad() override;
virtual XULDocument* AsXULDocument() override {
return this;
}
// nsIMutationObserver interface
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
@ -722,4 +718,11 @@ private:
} // namespace dom
} // namespace mozilla
inline mozilla::dom::XULDocument*
nsIDocument::AsXULDocument()
{
MOZ_ASSERT(IsXULDocument());
return static_cast<mozilla::dom::XULDocument*>(this);
}
#endif // mozilla_dom_XULDocument_h

View File

@ -34,6 +34,7 @@
#include "mozilla/dom/Element.h"
using namespace mozilla;
using mozilla::dom::Element;
static LazyLogModule gCommandLog("nsXULCommandDispatcher");
@ -98,7 +99,7 @@ nsXULCommandDispatcher::GetWindowRoot()
return nullptr;
}
nsIContent*
Element*
nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow)
{
*aWindow = nullptr;
@ -120,27 +121,25 @@ nsXULCommandDispatcher::GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWin
}
NS_IMETHODIMP
nsXULCommandDispatcher::GetFocusedElement(nsIDOMElement** aElement)
nsXULCommandDispatcher::GetFocusedElement(Element** aElement)
{
*aElement = nullptr;
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
nsIContent* focusedContent =
RefPtr<Element> focusedContent =
GetRootFocusedContentAndWindow(getter_AddRefs(focusedWindow));
if (focusedContent) {
CallQueryInterface(focusedContent, aElement);
// Make sure the caller can access the focused element.
nsCOMPtr<nsINode> node = do_QueryInterface(*aElement);
if (!node || !nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->Subsumes(node->NodePrincipal())) {
if (!nsContentUtils::SubjectPrincipalOrSystemIfNativeCaller()->
Subsumes(focusedContent->NodePrincipal())) {
// XXX This might want to return null, but we use that return value
// to mean "there is no focused element," so to be clear, throw an
// exception.
NS_RELEASE(*aElement);
return NS_ERROR_DOM_SECURITY_ERR;
}
}
focusedContent.forget(aElement);
return NS_OK;
}
@ -168,13 +167,14 @@ nsXULCommandDispatcher::GetFocusedWindow(mozIDOMWindowProxy** aWindow)
}
NS_IMETHODIMP
nsXULCommandDispatcher::SetFocusedElement(nsIDOMElement* aElement)
nsXULCommandDispatcher::SetFocusedElement(Element* aElement)
{
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
NS_ENSURE_TRUE(fm, NS_ERROR_FAILURE);
if (aElement)
if (aElement) {
return fm->SetFocus(aElement, 0);
}
// if aElement is null, clear the focus in the currently focused child window
nsCOMPtr<nsPIDOMWindowOuter> focusedWindow;
@ -197,10 +197,10 @@ nsXULCommandDispatcher::SetFocusedWindow(mozIDOMWindowProxy* aWindow)
// end up focusing whatever is currently focused inside the frame. Since
// setting the command dispatcher's focused window doesn't raise the window,
// setting it to a top-level window doesn't need to do anything.
nsCOMPtr<nsIDOMElement> frameElement =
do_QueryInterface(window->GetFrameElementInternal());
if (frameElement)
RefPtr<Element> frameElement = window->GetFrameElementInternal();
if (frameElement) {
return fm->SetFocus(frameElement, 0);
}
return NS_OK;
}
@ -217,7 +217,7 @@ nsXULCommandDispatcher::RewindFocus()
nsCOMPtr<nsPIDOMWindowOuter> win;
GetRootFocusedContentAndWindow(getter_AddRefs(win));
nsCOMPtr<nsIDOMElement> result;
RefPtr<Element> result;
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm)
return fm->MoveFocus(win, nullptr, nsIFocusManager::MOVEFOCUS_BACKWARD,
@ -226,12 +226,12 @@ nsXULCommandDispatcher::RewindFocus()
}
NS_IMETHODIMP
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(nsIDOMElement* aElt)
nsXULCommandDispatcher::AdvanceFocusIntoSubtree(Element* aElt)
{
nsCOMPtr<nsPIDOMWindowOuter> win;
GetRootFocusedContentAndWindow(getter_AddRefs(win));
nsCOMPtr<nsIDOMElement> result;
RefPtr<Element> result;
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm)
return fm->MoveFocus(win, aElt, nsIFocusManager::MOVEFOCUS_FORWARD,
@ -359,9 +359,8 @@ nsXULCommandDispatcher::UpdateCommands(const nsAString& aEventName)
}
nsAutoString id;
nsCOMPtr<nsIDOMElement> domElement;
GetFocusedElement(getter_AddRefs(domElement));
nsCOMPtr<Element> element = do_QueryInterface(domElement);
RefPtr<Element> element;
GetFocusedElement(getter_AddRefs(element));
if (element) {
element->GetAttribute(NS_LITERAL_STRING("id"), id);
}

View File

@ -23,6 +23,12 @@
class nsIDOMElement;
class nsPIWindowRoot;
namespace mozilla {
namespace dom {
class Element;
} // namespace dom
} // namespace mozilla
class nsXULCommandDispatcher : public nsIDOMXULCommandDispatcher,
public nsSupportsWeakReference
{
@ -43,7 +49,8 @@ protected:
already_AddRefed<nsPIWindowRoot> GetWindowRoot();
nsIContent* GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow);
mozilla::dom::Element*
GetRootFocusedContentAndWindow(nsPIDOMWindowOuter** aWindow);
nsCOMPtr<nsIDocument> mDocument;

View File

@ -673,8 +673,9 @@ XULContentSinkImpl::ReportError(const char16_t* aErrorText,
return NS_OK;
};
XULDocument* doc = idoc ? idoc->AsXULDocument() : nullptr;
if (doc && !doc->OnDocumentParserError()) {
if (idoc &&
idoc->IsXULDocument() &&
!idoc->AsXULDocument()->OnDocumentParserError()) {
// The overlay was broken. Don't add a messy element to the master doc.
return NS_OK;
}

View File

@ -121,11 +121,11 @@ nsXULContentUtils::SetCommandUpdater(nsIDocument* aDocument, Element* aElement)
nsresult rv;
XULDocument* xuldoc = aDocument->AsXULDocument();
NS_ASSERTION(xuldoc != nullptr, "not a xul document");
if (! xuldoc)
NS_ASSERTION(aDocument->IsXULDocument(), "not a xul document");
if (! aDocument->IsXULDocument())
return NS_ERROR_UNEXPECTED;
XULDocument* xuldoc = aDocument->AsXULDocument();
nsCOMPtr<nsIDOMXULCommandDispatcher> dispatcher =
xuldoc->GetCommandDispatcher();
NS_ASSERTION(dispatcher != nullptr, "no dispatcher");

View File

@ -543,7 +543,7 @@ bool
nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
bool aIsTrustedEvent)
{
nsCOMPtr<nsIContent> content(this);
RefPtr<Element> content(this);
if (IsXULElement(nsGkAtoms::label)) {
nsAutoString control;
@ -577,7 +577,7 @@ nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
if (!content->IsXULElement(nsGkAtoms::toolbarbutton)) {
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
nsCOMPtr<nsIDOMElement> elementToFocus;
nsCOMPtr<Element> elementToFocus;
// for radio buttons, focus the radiogroup instead
if (content->IsXULElement(nsGkAtoms::radio)) {
nsCOMPtr<nsIDOMXULSelectControlItemElement> controlItem(do_QueryInterface(content));
@ -591,7 +591,7 @@ nsXULElement::PerformAccesskey(bool aKeyCausesActivation,
}
}
} else {
elementToFocus = do_QueryInterface(content);
elementToFocus = content;
}
if (elementToFocus) {
fm->SetFocus(elementToFocus, nsIFocusManager::FLAG_BYKEY);
@ -1118,16 +1118,14 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
aValue->Equals(NS_LITERAL_STRING("true"), eCaseMatters));
} else if (aName == nsGkAtoms::localedir) {
// if the localedir changed on the root element, reset the document direction
XULDocument* xuldoc = document->AsXULDocument();
if (xuldoc) {
xuldoc->ResetDocumentDirection();
if (document->IsXULDocument()) {
document->AsXULDocument()->ResetDocumentDirection();
}
} else if (aName == nsGkAtoms::lwtheme ||
aName == nsGkAtoms::lwthemetextcolor) {
// if the lwtheme changed, make sure to reset the document lwtheme cache
XULDocument* xuldoc = document->AsXULDocument();
if (xuldoc) {
xuldoc->ResetDocumentLWTheme();
if (document->IsXULDocument()) {
document->AsXULDocument()->ResetDocumentLWTheme();
UpdateBrightTitlebarForeground(document);
}
} else if (aName == nsGkAtoms::brighttitlebarforeground) {
@ -1151,16 +1149,14 @@ nsXULElement::AfterSetAttr(int32_t aNamespaceID, nsAtom* aName,
if (doc && doc->GetRootElement() == this) {
if (aName == nsGkAtoms::localedir) {
// if the localedir changed on the root element, reset the document direction
XULDocument* xuldoc = doc->AsXULDocument();
if (xuldoc) {
xuldoc->ResetDocumentDirection();
if (doc->IsXULDocument()) {
doc->AsXULDocument()->ResetDocumentDirection();
}
} else if ((aName == nsGkAtoms::lwtheme ||
aName == nsGkAtoms::lwthemetextcolor)) {
// if the lwtheme changed, make sure to restyle appropriately
XULDocument* xuldoc = doc->AsXULDocument();
if (xuldoc) {
xuldoc->ResetDocumentLWTheme();
if (doc->IsXULDocument()) {
doc->AsXULDocument()->ResetDocumentLWTheme();
UpdateBrightTitlebarForeground(doc);
}
} else if (aName == nsGkAtoms::brighttitlebarforeground) {
@ -1234,13 +1230,13 @@ nsXULElement::ParseAttribute(int32_t aNamespaceID,
void
nsXULElement::RemoveBroadcaster(const nsAString & broadcasterId)
{
XULDocument* xuldoc = OwnerDoc()->AsXULDocument();
if (xuldoc) {
Element* broadcaster = xuldoc->GetElementById(broadcasterId);
if (broadcaster) {
xuldoc->RemoveBroadcastListenerFor(*broadcaster, *this,
NS_LITERAL_STRING("*"));
}
nsIDocument* doc = OwnerDoc();
if (!doc->IsXULDocument()) {
return;
}
if (Element* broadcaster = doc->GetElementById(broadcasterId)) {
doc->AsXULDocument()->RemoveBroadcastListenerFor(
*broadcaster, *this, NS_LITERAL_STRING("*"));
}
}

View File

@ -11,7 +11,6 @@
#include "nsXULPopupListener.h"
#include "nsCOMPtr.h"
#include "nsGkAtoms.h"
#include "nsIDOMElement.h"
#include "nsContentCID.h"
#include "nsContentUtils.h"
#include "nsXULPopupManager.h"
@ -26,6 +25,7 @@
#include "mozilla/EventStateManager.h"
#include "mozilla/EventStates.h"
#include "mozilla/Preferences.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/Event.h" // for Event
#include "mozilla/dom/EventTarget.h"
#include "mozilla/dom/FragmentOrElement.h"
@ -234,33 +234,29 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode, bool aIsTo
const nsStyleUserInterface* ui = targetFrame->StyleUserInterface();
bool suppressBlur = (ui->mUserFocus == StyleUserFocus::Ignore);
nsCOMPtr<nsIDOMElement> element;
nsCOMPtr<nsIContent> newFocus = content;
RefPtr<Element> newFocusElement;
nsIFrame* currFrame = targetFrame;
// Look for the nearest enclosing focusable frame.
while (currFrame) {
int32_t tabIndexUnused;
if (currFrame->IsFocusable(&tabIndexUnused, true)) {
newFocus = currFrame->GetContent();
nsCOMPtr<nsIDOMElement> domElement(do_QueryInterface(newFocus));
if (domElement) {
element = domElement;
break;
}
if (currFrame->IsFocusable(&tabIndexUnused, true) &&
currFrame->GetContent()->IsElement()) {
newFocusElement = currFrame->GetContent()->AsElement();
break;
}
currFrame = currFrame->GetParent();
}
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
if (fm) {
if (element) {
if (newFocusElement) {
uint32_t focusFlags = nsIFocusManager::FLAG_BYMOUSE |
nsIFocusManager::FLAG_NOSCROLL;
if (aIsTouch) {
focusFlags |= nsIFocusManager::FLAG_BYTOUCH;
}
fm->SetFocus(element, focusFlags);
fm->SetFocus(newFocusElement, focusFlags);
} else if (!suppressBlur) {
nsPIDOMWindowOuter *window = doc->GetWindow();
fm->ClearFocus(window);
@ -268,8 +264,7 @@ nsXULPopupListener::FireFocusOnTargetContent(nsIDOMNode* aTargetNode, bool aIsTo
}
EventStateManager* esm = context->EventStateManager();
nsCOMPtr<nsIContent> focusableContent = do_QueryInterface(element);
esm->SetContentState(focusableContent, NS_EVENT_STATE_ACTIVE);
esm->SetContentState(newFocusElement, NS_EVENT_STATE_ACTIVE);
return NS_OK;
}

View File

@ -664,7 +664,8 @@ nsEditingSession::OnStateChange(nsIWebProgress *aWebProgress,
auto* piWindow = nsPIDOMWindowOuter::From(window);
nsCOMPtr<nsIDocument> doc = piWindow->GetDoc();
nsHTMLDocument* htmlDoc = doc ? doc->AsHTMLDocument() : nullptr;
nsHTMLDocument* htmlDoc = doc && doc->IsHTMLOrXHTML()
? doc->AsHTMLDocument() : nullptr;
if (htmlDoc && htmlDoc->IsWriting()) {
nsAutoString designMode;
htmlDoc->GetDesignMode(designMode);

View File

@ -3440,7 +3440,7 @@ HTMLEditor::DebugUnitTests(int32_t* outNumTests,
NS_IMETHODIMP
HTMLEditor::StyleSheetLoaded(StyleSheet* aSheet,
bool aWasAlternate,
bool aWasDeferred,
nsresult aStatus)
{
AutoPlaceholderBatch batchIt(this);
@ -5131,6 +5131,9 @@ HTMLEditor::GetHTMLDocument() const
if (NS_WARN_IF(!doc)) {
return nullptr;
}
if (!doc->IsHTMLOrXHTML()) {
return nullptr;
}
return doc->AsHTMLDocument();
}

View File

@ -173,6 +173,12 @@ async function runTest() {
verifyContent('<pre id="paste_here">Hello Kitty<span>Hello</span></pre>');
is(pasteCount, 1, "paste event was not triggered");
await copyToClipBoard('1<span style="display: contents">2</span>3', true);
trans = getTransferableFromClipboard(true);
pasteInto(trans, '<div id="paste_here"></div>',"paste_here");
verifyContent('<div id="paste_here">1<span style="display: contents">2</span>3</div>');
is(pasteCount, 1, "paste event was not triggered");
// test that we can preventDefault pastes
pasteFunc = function (event) { event.preventDefault(); return false; };
await copyToClipBoard("<pre>Kitty</pre><span>Hello</span>", true);

View File

@ -731,10 +731,10 @@ APZCTreeManager::RecycleOrCreateNode(TreeBuildingState& aState,
// Find a node without an APZC and return it. Note that unless the layer tree
// actually changes, this loop should generally do an early-return on the
// first iteration, so it should be cheap in the common case.
for (size_t i = 0; i < aState.mNodesToDestroy.Length(); i++) {
for (int32_t i = aState.mNodesToDestroy.Length() - 1; i >= 0; i--) {
RefPtr<HitTestingTreeNode> node = aState.mNodesToDestroy[i];
if (!node->IsPrimaryHolder()) {
aState.mNodesToDestroy.RemoveElement(node);
aState.mNodesToDestroy.RemoveElementAt(i);
node->RecycleWith(aApzc, aLayersId);
return node.forget();
}

View File

@ -618,6 +618,60 @@ FT2FontEntry::GetFontTable(uint32_t aTableTag)
return gfxFontEntry::GetFontTable(aTableTag);
}
bool
FT2FontEntry::HasVariations()
{
if (mHasVariationsInitialized) {
return mHasVariations;
}
mHasVariationsInitialized = true;
AutoFTFace face(this);
if (face) {
mHasVariations =
FT_Face(face)->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS;
}
return mHasVariations;
}
void
FT2FontEntry::GetVariationAxes(nsTArray<gfxFontVariationAxis>& aAxes)
{
if (!HasVariations()) {
return;
}
AutoFTFace face(this);
if (!face) {
return;
}
FT_MM_Var* mmVar;
if (FT_Err_Ok != (FT_Get_MM_Var(face, &mmVar))) {
return;
}
gfxFT2Utils::GetVariationAxes(mmVar, aAxes);
FT_Done_MM_Var(FT_Face(face)->glyph->library, mmVar);
}
void
FT2FontEntry::GetVariationInstances(
nsTArray<gfxFontVariationInstance>& aInstances)
{
if (!HasVariations()) {
return;
}
AutoFTFace face(this);
if (!face) {
return;
}
FT_MM_Var* mmVar;
if (FT_Err_Ok != (FT_Get_MM_Var(face, &mmVar))) {
return;
}
gfxFT2Utils::GetVariationInstances(this, mmVar, aInstances);
FT_Done_MM_Var(FT_Face(face)->glyph->library, mmVar);
}
void
FT2FontEntry::AddSizeOfExcludingThis(MallocSizeOf aMallocSizeOf,
FontListSizes* aSizes) const

View File

@ -87,6 +87,10 @@ public:
virtual nsresult CopyFontTable(uint32_t aTableTag,
nsTArray<uint8_t>& aBuffer) override;
bool HasVariations() override;
void GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes) override;
void GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances) override;
// Check for various kinds of brokenness, and set flags on the entry
// accordingly so that we avoid using bad font tables
void CheckForBrokenFont(gfxFontFamily *aFamily);
@ -103,6 +107,9 @@ public:
uint8_t mFTFontIndex;
mozilla::ThreadSafeWeakPtr<mozilla::gfx::UnscaledFontFreeType> mUnscaledFont;
bool mHasVariations = false;
bool mHasVariationsInitialized = false;
};
class FT2FontFamily : public gfxFontFamily

View File

@ -11,6 +11,9 @@
#include <fontconfig/fcfreetype.h>
#endif
#include "ft2build.h"
#include FT_MULTIPLE_MASTERS_H
#include "prlink.h"
uint32_t
@ -96,3 +99,62 @@ gfxFT2LockedFace::FindCharVariantFunction()
return function;
}
/*static*/
void
gfxFT2Utils::GetVariationAxes(const FT_MM_Var* aMMVar,
nsTArray<gfxFontVariationAxis>& aAxes)
{
MOZ_ASSERT(aAxes.IsEmpty());
if (!aMMVar) {
return;
}
aAxes.SetCapacity(aMMVar->num_axis);
for (unsigned i = 0; i < aMMVar->num_axis; i++) {
const auto& a = aMMVar->axis[i];
gfxFontVariationAxis axis;
axis.mMinValue = a.minimum / 65536.0;
axis.mMaxValue = a.maximum / 65536.0;
axis.mDefaultValue = a.def / 65536.0;
axis.mTag = a.tag;
axis.mName.Assign(NS_ConvertUTF8toUTF16(a.name));
aAxes.AppendElement(axis);
}
}
/*static*/
void
gfxFT2Utils::GetVariationInstances(
gfxFontEntry* aFontEntry,
const FT_MM_Var* aMMVar,
nsTArray<gfxFontVariationInstance>& aInstances)
{
MOZ_ASSERT(aInstances.IsEmpty());
if (!aMMVar) {
return;
}
hb_blob_t* nameTable =
aFontEntry->GetFontTable(TRUETYPE_TAG('n','a','m','e'));
if (!nameTable) {
return;
}
aInstances.SetCapacity(aMMVar->num_namedstyles);
for (unsigned i = 0; i < aMMVar->num_namedstyles; i++) {
const auto& ns = aMMVar->namedstyle[i];
gfxFontVariationInstance inst;
nsresult rv =
gfxFontUtils::ReadCanonicalName(nameTable, ns.strid, inst.mName);
if (NS_FAILED(rv)) {
continue;
}
inst.mValues.SetCapacity(aMMVar->num_axis);
for (unsigned j = 0; j < aMMVar->num_axis; j++) {
gfxFontVariationValue value;
value.mAxis = aMMVar->axis[j].tag;
value.mValue = ns.coords[j] / 65536.0;
inst.mValues.AppendElement(value);
}
aInstances.AppendElement(inst);
}
hb_blob_destroy(nameTable);
}

View File

@ -63,4 +63,22 @@ protected:
FT_Face mFace;
};
// A couple of FreeType-based utilities shared by gfxFontconfigFontEntry
// and FT2FontEntry.
typedef struct FT_MM_Var_ FT_MM_Var;
class gfxFT2Utils {
public:
static void
GetVariationAxes(const FT_MM_Var* aMMVar,
nsTArray<gfxFontVariationAxis>& aAxes);
static void
GetVariationInstances(gfxFontEntry* aFontEntry,
const FT_MM_Var* aMMVar,
nsTArray<gfxFontVariationInstance>& aInstances);
};
#endif /* GFX_FT2UTILS_H */

View File

@ -1112,56 +1112,20 @@ gfxFontconfigFontEntry::GetMMVar()
void
gfxFontconfigFontEntry::GetVariationAxes(nsTArray<gfxFontVariationAxis>& aAxes)
{
MOZ_ASSERT(aAxes.IsEmpty());
FT_MM_Var* mmVar = GetMMVar();
if (!mmVar) {
if (!HasVariations()) {
return;
}
aAxes.SetCapacity(mmVar->num_axis);
for (unsigned i = 0; i < mmVar->num_axis; i++) {
const auto& a = mmVar->axis[i];
gfxFontVariationAxis axis;
axis.mMinValue = a.minimum / 65536.0;
axis.mMaxValue = a.maximum / 65536.0;
axis.mDefaultValue = a.def / 65536.0;
axis.mTag = a.tag;
axis.mName.Assign(NS_ConvertUTF8toUTF16(a.name));
aAxes.AppendElement(axis);
}
gfxFT2Utils::GetVariationAxes(GetMMVar(), aAxes);
}
void
gfxFontconfigFontEntry::GetVariationInstances(
nsTArray<gfxFontVariationInstance>& aInstances)
{
MOZ_ASSERT(aInstances.IsEmpty());
FT_MM_Var* mmVar = GetMMVar();
if (!mmVar) {
if (!HasVariations()) {
return;
}
hb_blob_t* nameTable = GetFontTable(TRUETYPE_TAG('n','a','m','e'));
if (!nameTable) {
return;
}
aInstances.SetCapacity(mmVar->num_namedstyles);
for (unsigned i = 0; i < mmVar->num_namedstyles; i++) {
const auto& ns = mmVar->namedstyle[i];
gfxFontVariationInstance inst;
nsresult rv =
gfxFontUtils::ReadCanonicalName(nameTable, ns.strid, inst.mName);
if (NS_FAILED(rv)) {
continue;
}
inst.mValues.SetCapacity(mmVar->num_axis);
for (unsigned j = 0; j < mmVar->num_axis; j++) {
gfxFontVariationValue value;
value.mAxis = mmVar->axis[j].tag;
value.mValue = ns.coords[j] / 65536.0;
inst.mValues.AppendElement(value);
}
aInstances.AppendElement(inst);
}
hb_blob_destroy(nameTable);
gfxFT2Utils::GetVariationInstances(this, GetMMVar(), aInstances);
}
nsresult

View File

@ -1082,27 +1082,44 @@ gfxFontEntry::GetVariationsForStyle(nsTArray<gfxFontVariation>& aResult,
// Resolve high-level CSS properties from the requested style
// (font-{style,weight,stretch}) to the appropriate variations.
float clampedWeight = Weight().Clamp(aStyle.weight).ToFloat();
// The value used is clamped to the range available in the font face,
// unless the face is a user font where no explicit descriptor was
// given, indicated by the corresponding 'auto' range-flag.
float weight = (IsUserFont() && (mRangeFlags & RangeFlags::eAutoWeight))
? aStyle.weight.ToFloat()
: Weight().Clamp(aStyle.weight).ToFloat();
aResult.AppendElement(gfxFontVariation{HB_TAG('w','g','h','t'),
clampedWeight});
weight});
float clampedStretch = Stretch().Clamp(aStyle.stretch).Percentage();
float stretch = (IsUserFont() && (mRangeFlags & RangeFlags::eAutoStretch))
? aStyle.stretch.Percentage()
: Stretch().Clamp(aStyle.stretch).Percentage();
aResult.AppendElement(gfxFontVariation{HB_TAG('w','d','t','h'),
clampedStretch});
stretch});
if (SlantStyle().Min().IsOblique()) {
float clampedSlant =
aStyle.style.IsOblique()
? SlantStyle().Clamp(aStyle.style).ObliqueAngle()
: aStyle.style.IsItalic()
? SlantStyle().Clamp(FontSlantStyle::Oblique()).ObliqueAngle()
: SlantStyle().Clamp(FontSlantStyle::Oblique(0.0f)).ObliqueAngle();
// Figure out what slant angle we should try to match from the
// requested style.
float angle =
aStyle.style.IsNormal()
? 0.0f
: aStyle.style.IsItalic()
? FontSlantStyle::Oblique().ObliqueAngle()
: aStyle.style.ObliqueAngle();
// Clamp to the available range, unless the face is a user font
// with no explicit descriptor.
if (!(IsUserFont() && (mRangeFlags & RangeFlags::eAutoSlantStyle))) {
angle = SlantStyle().Clamp(
FontSlantStyle::Oblique(angle)).ObliqueAngle();
}
aResult.AppendElement(gfxFontVariation{HB_TAG('s','l','n','t'),
clampedSlant});
angle});
}
// Although there is a registered tag 'ital', it is normally considered
// a binary toggle rather than a variable axis,
// a binary toggle rather than a variable axis, so not set here.
// (For a non-standard font that implements 'ital' as an actual variation,
// authors can still use font-variation-settings to control it.)
auto replaceOrAppend = [&aResult](const gfxFontVariation& aSetting) {
struct TagEquals {

View File

@ -365,18 +365,19 @@ public:
bool SupportsScriptInGSUB(const hb_tag_t* aScriptTags);
// For variation font support, which is not yet implemented on all
// platforms; default implementations assume it is not present.
virtual bool HasVariations()
{
return false;
}
virtual void GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes)
{
}
virtual void GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances)
{
}
/**
* Font-variation query methods.
*
* Font backends that don't support variations should provide empty
* implementations.
*/
virtual bool HasVariations() = 0;
virtual void
GetVariationAxes(nsTArray<gfxFontVariationAxis>& aVariationAxes) = 0;
virtual void
GetVariationInstances(nsTArray<gfxFontVariationInstance>& aInstances) = 0;
// Set up the entry's weight/stretch/style ranges according to axes found
// by GetVariationAxes (for installed fonts; do NOT call this for user
@ -423,6 +424,20 @@ public:
StretchRange mStretchRange = StretchRange(FontStretch::Normal());
SlantStyleRange mStyleRange = SlantStyleRange(FontSlantStyle::Normal());
// For user fonts (only), we need to record whether or not weight/stretch/
// slant variations should be clamped to the range specified in the entry
// properties. When the @font-face rule omitted one or more of these
// descriptors, it is treated as the initial value for font-matching (and
// so that is what we record in the font entry), but when rendering the
// range is NOT clamped.
enum class RangeFlags : uint8_t {
eNoFlags = 0,
eAutoWeight = (1 << 0),
eAutoStretch = (1 << 1),
eAutoSlantStyle = (1 << 2)
};
RangeFlags mRangeFlags = RangeFlags::eNoFlags;
bool mFixedPitch : 1;
bool mIsBadUnderlineFont : 1;
bool mIsUserFontContainer : 1; // userfont entry
@ -627,6 +642,7 @@ private:
gfxFontEntry& operator=(const gfxFontEntry&);
};
MOZ_MAKE_ENUM_CLASS_BITWISE_OPERATORS(gfxFontEntry::RangeFlags)
// used when iterating over all fonts looking for a match for a given character
struct GlobalFontMatch {

View File

@ -163,6 +163,11 @@ public:
gfxFontEntry* Clone() const override;
// GDI backend doesn't support font variations:
bool HasVariations() override { return false; }
void GetVariationAxes(nsTArray<gfxFontVariationAxis>&) override {}
void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {}
// create a font entry for a font with a given name
static GDIFontEntry* CreateFontEntry(const nsAString& aName,
gfxWindowsFontType aFontType,

View File

@ -23,6 +23,7 @@
#include "nsIPrincipal.h"
#include "mozilla/BasePrincipal.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/SVGDocument.h"
#include "mozilla/LoadInfo.h"
#include "nsSVGUtils.h"
#include "nsHostObjectProtocolHandler.h"
@ -215,10 +216,11 @@ gfxSVGGlyphs::RenderGlyph(gfxContext *aContext, uint32_t aGlyphId,
{
gfxContextAutoSaveRestore aContextRestorer(aContext);
Element *glyph = mGlyphIdMap.Get(aGlyphId);
Element* glyph = mGlyphIdMap.Get(aGlyphId);
MOZ_ASSERT(glyph, "No glyph element. Should check with HasSVGGlyph() first!");
AutoSetRestoreSVGContextPaint autoSetRestore(aContextPaint, glyph->OwnerDoc());
AutoSetRestoreSVGContextPaint autoSetRestore(
*aContextPaint, *glyph->OwnerDoc()->AsSVGDocument());
nsSVGUtils::PaintSVGGlyph(glyph, aContext);
}

View File

@ -112,7 +112,8 @@ gfxUserFontEntry::gfxUserFontEntry(gfxUserFontSet* aFontSet,
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay)
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
: gfxFontEntry(NS_LITERAL_STRING("userfont")),
mUserFontLoadState(STATUS_NOT_LOADED),
mFontDataLoadingState(NOT_LOADING),
@ -131,6 +132,7 @@ gfxUserFontEntry::gfxUserFontEntry(gfxUserFontSet* aFontSet,
mVariationSettings.AppendElements(aVariationSettings);
mLanguageOverride = aLanguageOverride;
mCharacterMap = aUnicodeRanges;
mRangeFlags = aRangeFlags;
}
gfxUserFontEntry::~gfxUserFontEntry()
@ -150,7 +152,8 @@ gfxUserFontEntry::Matches(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay)
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
return Weight() == aWeight &&
Stretch() == aStretch &&
@ -160,6 +163,7 @@ gfxUserFontEntry::Matches(const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
mLanguageOverride == aLanguageOverride &&
mSrcList == aFontFaceSrcList &&
mFontDisplay == aFontDisplay &&
mRangeFlags == aRangeFlags &&
((!aUnicodeRanges && !mCharacterMap) ||
(aUnicodeRanges && mCharacterMap && mCharacterMap->Equals(aUnicodeRanges)));
}
@ -534,6 +538,7 @@ gfxUserFontEntry::DoLoadNextSrc(bool aForceAsync)
fe->mVariationSettings.AppendElements(mVariationSettings);
fe->mLanguageOverride = mLanguageOverride;
fe->mFamilyName = mFamilyName;
fe->mRangeFlags = mRangeFlags;
// For src:local(), we don't care whether the request is from
// a private window as there's no issue of caching resources;
// local fonts are just available all the time.
@ -804,6 +809,7 @@ gfxUserFontEntry::LoadPlatformFont(const uint8_t* aFontData, uint32_t& aLength)
fe->mVariationSettings.AppendElements(mVariationSettings);
fe->mLanguageOverride = mLanguageOverride;
fe->mFamilyName = mFamilyName;
fe->mRangeFlags = mRangeFlags;
StoreUserFontData(fe, mFontSet->GetPrivateBrowsing(), originalFullName,
&metadata, metaOrigLen, compression);
if (LOG_ENABLED()) {
@ -941,7 +947,8 @@ gfxUserFontSet::FindOrCreateUserFontEntry(
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay)
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
RefPtr<gfxUserFontEntry> entry;
@ -957,40 +964,21 @@ gfxUserFontSet::FindOrCreateUserFontEntry(
aStretch, aStyle,
aFeatureSettings, aVariationSettings,
aLanguageOverride,
aUnicodeRanges, aFontDisplay);
aUnicodeRanges, aFontDisplay,
aRangeFlags);
}
if (!entry) {
entry = CreateUserFontEntry(aFontFaceSrcList, aWeight, aStretch,
aStyle, aFeatureSettings, aVariationSettings,
aLanguageOverride, aUnicodeRanges,
aFontDisplay);
aFontDisplay, aRangeFlags);
entry->mFamilyName = aFamilyName;
}
return entry.forget();
}
already_AddRefed<gfxUserFontEntry>
gfxUserFontSet::CreateUserFontEntry(
const nsTArray<gfxFontFaceSrc>& aFontFaceSrcList,
WeightRange aWeight,
StretchRange aStretch,
SlantStyleRange aStyle,
const nsTArray<gfxFontFeature>& aFeatureSettings,
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay)
{
RefPtr<gfxUserFontEntry> userFontEntry =
new gfxUserFontEntry(this, aFontFaceSrcList, aWeight,
aStretch, aStyle, aFeatureSettings, aVariationSettings,
aLanguageOverride, aUnicodeRanges, aFontDisplay);
return userFontEntry.forget();
}
gfxUserFontEntry*
gfxUserFontSet::FindExistingUserFontEntry(
gfxUserFontFamily* aFamily,
@ -1002,7 +990,8 @@ gfxUserFontSet::FindExistingUserFontEntry(
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay)
uint8_t aFontDisplay,
RangeFlags aRangeFlags)
{
nsTArray<RefPtr<gfxFontEntry>>& fontList = aFamily->GetFontList();
@ -1017,7 +1006,8 @@ gfxUserFontSet::FindExistingUserFontEntry(
aWeight, aStretch, aStyle,
aFeatureSettings, aVariationSettings,
aLanguageOverride,
aUnicodeRanges, aFontDisplay)) {
aUnicodeRanges, aFontDisplay,
aRangeFlags)) {
continue;
}

View File

@ -191,6 +191,7 @@ public:
typedef mozilla::SlantStyleRange SlantStyleRange;
typedef mozilla::FontWeight FontWeight;
typedef mozilla::WeightRange WeightRange;
typedef gfxFontEntry::RangeFlags RangeFlags;
NS_INLINE_DECL_THREADSAFE_REFCOUNTING(gfxUserFontSet)
@ -243,7 +244,8 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay) = 0;
uint8_t aFontDisplay,
RangeFlags aRangeFlags) = 0;
// creates a font face for the specified family, or returns an existing
// matching entry on the family if there is one
@ -257,7 +259,8 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay);
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
// add in a font face for which we have the gfxUserFontEntry already
void AddUserFontEntry(const nsAString& aFamilyName,
@ -511,7 +514,8 @@ protected:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay);
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
// creates a new gfxUserFontFamily in mFontFamilies, or returns an existing
// family if there is one
@ -561,7 +565,8 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay);
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
virtual ~gfxUserFontEntry();
@ -574,7 +579,8 @@ public:
const nsTArray<gfxFontVariation>& aVariationSettings,
uint32_t aLanguageOverride,
gfxCharacterMap* aUnicodeRanges,
uint8_t aFontDisplay);
uint8_t aFontDisplay,
RangeFlags aRangeFlags);
gfxFont* CreateFontInstance(const gfxFontStyle* aFontStyle,
bool aNeedsBold) override;
@ -633,6 +639,18 @@ public:
return mSrcList;
}
// The variation-query APIs should not be called on placeholders.
bool HasVariations() override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
return false;
}
void GetVariationAxes(nsTArray<gfxFontVariationAxis>&) override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
}
void GetVariationInstances(nsTArray<gfxFontVariationInstance>&) override {
MOZ_ASSERT_UNREACHABLE("not meaningful for a userfont placeholder");
}
protected:
const uint8_t* SanitizeOpenTypeData(const uint8_t* aData,
uint32_t aLength,

View File

@ -89,7 +89,7 @@ static struct FontDeleteLog {
}
void AddAll() {
AddEntry(0);
AddEntry(~0);
}
// Find a matching entry in the log, searching backwards starting at the newest
@ -105,7 +105,7 @@ static struct FontDeleteLog {
return "deleted font";
} else if (mEntries[offset] == namespaceEntry) {
return "cleared namespace";
} else if (!mEntries[offset]) {
} else if (mEntries[offset] == (uint64_t)~0) {
return "cleared all";
}
} while (offset != mNextEntry);

View File

@ -7,10 +7,10 @@
#include "mozilla/dom/DocumentTimeline.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/SVGDocument.h"
#include "nsICategoryManager.h"
#include "nsIChannel.h"
#include "nsIContentViewer.h"
#include "nsIDocument.h"
#include "nsIDocumentLoaderFactory.h"
#include "nsIHttpChannel.h"
#include "nsIObserverService.h"
@ -418,19 +418,22 @@ SVGDocumentWrapper::UnregisterForXPCOMShutdown()
void
SVGDocumentWrapper::FlushLayout()
{
if (nsIDocument* doc = GetDocument()) {
if (SVGDocument* doc = GetDocument()) {
doc->FlushPendingNotifications(FlushType::Layout);
}
}
nsIDocument*
SVGDocument*
SVGDocumentWrapper::GetDocument()
{
if (!mViewer) {
return nullptr;
}
return mViewer->GetDocument(); // May be nullptr.
nsIDocument* doc = mViewer->GetDocument();
if (!doc) {
return nullptr;
}
return doc->AsSVGDocument();
}
SVGSVGElement*

View File

@ -30,6 +30,7 @@ class nsIFrame;
namespace mozilla {
namespace dom {
class SVGSVGElement;
class SVGDocument;
} // namespace dom
namespace image {
@ -54,7 +55,7 @@ public:
/**
* Returns the wrapped document, or nullptr on failure. (No AddRef.)
*/
nsIDocument* GetDocument();
mozilla::dom::SVGDocument* GetDocument();
/**
* Returns the root <svg> element for the wrapped document, or nullptr on

View File

@ -15,6 +15,7 @@
#include "mozilla/MemoryReporting.h"
#include "mozilla/dom/Event.h"
#include "mozilla/dom/SVGSVGElement.h"
#include "mozilla/dom/SVGDocument.h"
#include "mozilla/gfx/2D.h"
#include "mozilla/RefPtr.h"
#include "mozilla/Tuple.h"
@ -127,7 +128,7 @@ class SVGParseCompleteListener final : public nsStubDocumentObserver {
public:
NS_DECL_ISUPPORTS
SVGParseCompleteListener(nsIDocument* aDocument,
SVGParseCompleteListener(SVGDocument* aDocument,
VectorImage* aImage)
: mDocument(aDocument)
, mImage(aImage)
@ -171,7 +172,7 @@ public:
}
private:
nsCOMPtr<nsIDocument> mDocument;
RefPtr<SVGDocument> mDocument;
VectorImage* const mImage; // Raw pointer to owner.
};
@ -342,12 +343,15 @@ public:
, mTime(aSVGDocumentWrapper->GetRootSVGElem(), aParams.animationTime)
{
MOZ_ASSERT(!aIsDrawing);
MOZ_ASSERT(aSVGDocumentWrapper->GetDocument());
aIsDrawing = true;
// Set context paint (if specified) on the document:
if (aContextPaint) {
mContextPaint.emplace(aParams.svgContext->GetContextPaint(),
aSVGDocumentWrapper->GetDocument());
MOZ_ASSERT(aParams.svgContext->GetContextPaint());
mContextPaint.emplace(*aParams.svgContext->GetContextPaint(),
*aSVGDocumentWrapper->GetDocument());
}
}
@ -418,7 +422,7 @@ VectorImage::SizeOfSourceWithComputedFallback(SizeOfState& aState) const
return 0; // No document, so no memory used for the document.
}
nsIDocument* doc = mSVGDocumentWrapper->GetDocument();
SVGDocument* doc = mSVGDocumentWrapper->GetDocument();
if (!doc) {
return 0; // No document, so no memory used for the document.
}
@ -1373,7 +1377,7 @@ VectorImage::OnStartRequest(nsIRequest* aRequest, nsISupports* aCtxt)
// listener that waits for parsing to complete and cancels the
// SVGLoadEventListener if needed. The listeners are automatically attached
// to the document by their constructors.
nsIDocument* document = mSVGDocumentWrapper->GetDocument();
SVGDocument* document = mSVGDocumentWrapper->GetDocument();
mLoadEventListener = new SVGLoadEventListener(document, this);
mParseCompleteListener = new SVGParseCompleteListener(document, this);

View File

@ -708,13 +708,14 @@ function CreateArrayIterator(obj, kind) {
// http://www.ecma-international.org/ecma-262/6.0/index.html#sec-%arrayiteratorprototype%.next
function ArrayIteratorNext() {
// Step 1-3.
if (!IsObject(this) || !IsArrayIterator(this)) {
var obj;
if (!IsObject(this) || (obj = GuardToArrayIterator(this)) === null) {
return callFunction(CallArrayIteratorMethodIfWrapped, this,
"ArrayIteratorNext");
}
// Step 4.
var a = UnsafeGetReservedSlot(this, ITERATOR_SLOT_TARGET);
var a = UnsafeGetReservedSlot(obj, ITERATOR_SLOT_TARGET);
var result = { value: undefined, done: false };
// Step 5.
@ -725,10 +726,10 @@ function ArrayIteratorNext() {
// Step 6.
// The index might not be an integer, so we have to do a generic get here.
var index = UnsafeGetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX);
var index = UnsafeGetReservedSlot(obj, ITERATOR_SLOT_NEXT_INDEX);
// Step 7.
var itemKind = UnsafeGetInt32FromReservedSlot(this, ITERATOR_SLOT_ITEM_KIND);
var itemKind = UnsafeGetInt32FromReservedSlot(obj, ITERATOR_SLOT_ITEM_KIND);
// Step 8-9.
var len;
@ -746,13 +747,13 @@ function ArrayIteratorNext() {
// Step 10.
if (index >= len) {
UnsafeSetReservedSlot(this, ITERATOR_SLOT_TARGET, null);
UnsafeSetReservedSlot(obj, ITERATOR_SLOT_TARGET, null);
result.done = true;
return result;
}
// Step 11.
UnsafeSetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX, index + 1);
UnsafeSetReservedSlot(obj, ITERATOR_SLOT_NEXT_INDEX, index + 1);
// Step 16.
if (itemKind === ITEM_KIND_VALUE) {

View File

@ -32,8 +32,8 @@ function MapForEach(callbackfn, thisArg = undefined) {
var M = this;
// Steps 2-3.
if (!IsObject(M) || !IsMapObject(M))
return callFunction(CallMapMethodIfWrapped, M, callbackfn, thisArg, "MapForEach");
if (!IsObject(M) || (M = GuardToMapObject(M)) === null)
return callFunction(CallMapMethodIfWrapped, this, callbackfn, thisArg, "MapForEach");
// Step 4.
if (!IsCallable(callbackfn))
@ -75,8 +75,8 @@ function MapIteratorNext() {
var O = this;
// Steps 2-3.
if (!IsObject(O) || !IsMapIterator(O))
return callFunction(CallMapIteratorMethodIfWrapped, O, "MapIteratorNext");
if (!IsObject(O) || (O = GuardToMapIterator(O)) === null)
return callFunction(CallMapIteratorMethodIfWrapped, this, "MapIteratorNext");
// Steps 4-5 (implemented in _GetNextMapEntryForIterator).
// Steps 8-9 (omitted).
@ -95,7 +95,7 @@ function MapIteratorNext() {
// Steps 10.b-c (omitted).
// Step 6.
var itemKind = UnsafeGetInt32FromReservedSlot(this, ITERATOR_SLOT_ITEM_KIND);
var itemKind = UnsafeGetInt32FromReservedSlot(O, ITERATOR_SLOT_ITEM_KIND);
var result;
if (itemKind === ITEM_KIND_KEY) {

View File

@ -812,7 +812,8 @@ ModuleObject::initialEnvironment() const
ModuleEnvironmentObject*
ModuleObject::environment() const
{
MOZ_ASSERT(!hadEvaluationError());
// Note that this it's valid to call this even if there was an error
// evaluating the module.
// According to the spec the environment record is created during
// instantiation, but we create it earlier than that.

View File

@ -26,8 +26,8 @@ function SetForEach(callbackfn, thisArg = undefined) {
var S = this;
// Steps 2-3.
if (!IsObject(S) || !IsSetObject(S))
return callFunction(CallSetMethodIfWrapped, S, callbackfn, thisArg, "SetForEach");
if (!IsObject(S) || (S = GuardToSetObject(S)) === null)
return callFunction(CallSetMethodIfWrapped, this, callbackfn, thisArg, "SetForEach");
// Step 4.
if (!IsCallable(callbackfn))
@ -73,8 +73,8 @@ function SetIteratorNext() {
var O = this;
// Steps 2-3.
if (!IsObject(O) || !IsSetIterator(O))
return callFunction(CallSetIteratorMethodIfWrapped, O, "SetIteratorNext");
if (!IsObject(O) || (O = GuardToSetIterator(O)) === null)
return callFunction(CallSetIteratorMethodIfWrapped, this, "SetIteratorNext");
// Steps 4-5 (implemented in _GetNextSetEntryForIterator).
// Steps 8-9 (omitted).
@ -91,7 +91,7 @@ function SetIteratorNext() {
// Steps 10.b-c (omitted).
// Step 6.
var itemKind = UnsafeGetInt32FromReservedSlot(this, ITERATOR_SLOT_ITEM_KIND);
var itemKind = UnsafeGetInt32FromReservedSlot(O, ITERATOR_SLOT_ITEM_KIND);
var result;
if (itemKind === ITEM_KIND_VALUE) {

View File

@ -542,16 +542,17 @@ function String_iterator() {
}
function StringIteratorNext() {
if (!IsObject(this) || !IsStringIterator(this)) {
var obj;
if (!IsObject(this) || (obj = GuardToStringIterator(this)) === null) {
return callFunction(CallStringIteratorMethodIfWrapped, this,
"StringIteratorNext");
}
var S = UnsafeGetStringFromReservedSlot(this, ITERATOR_SLOT_TARGET);
var S = UnsafeGetStringFromReservedSlot(obj, ITERATOR_SLOT_TARGET);
// We know that JSString::MAX_LENGTH <= INT32_MAX (and assert this in
// SelfHostring.cpp) so our current index can never be anything other than
// an Int32Value.
var index = UnsafeGetInt32FromReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX);
var index = UnsafeGetInt32FromReservedSlot(obj, ITERATOR_SLOT_NEXT_INDEX);
var size = S.length;
var result = { value: undefined, done: false };
@ -570,7 +571,7 @@ function StringIteratorNext() {
}
}
UnsafeSetReservedSlot(this, ITERATOR_SLOT_NEXT_INDEX, index + charCount);
UnsafeSetReservedSlot(obj, ITERATOR_SLOT_NEXT_INDEX, index + charCount);
// Communicate |first|'s possible range to the compiler.
result.value = callFunction(std_String_fromCodePoint, null, first & 0x1fffff);

View File

@ -6,7 +6,7 @@ function ViewedArrayBufferIfReified(tarray) {
assert(IsTypedArray(tarray), "non-typed array asked for its buffer");
var buf = UnsafeGetReservedSlot(tarray, JS_TYPEDARRAYLAYOUT_BUFFER_SLOT);
assert(buf === null || (IsObject(buf) && (IsArrayBuffer(buf) || IsSharedArrayBuffer(buf))),
assert(buf === null || (IsObject(buf) && (GuardToArrayBuffer(buf) !== null || GuardToSharedArrayBuffer(buf) !== null)),
"unexpected value in buffer slot");
return buf;
}
@ -17,7 +17,7 @@ function IsDetachedBuffer(buffer) {
if (buffer === null)
return false;
assert(IsArrayBuffer(buffer) || IsSharedArrayBuffer(buffer),
assert(GuardToArrayBuffer(buffer) !== null || GuardToSharedArrayBuffer(buffer) !== null,
"non-ArrayBuffer passed to IsDetachedBuffer");
// Shared array buffers are not detachable.
@ -26,7 +26,7 @@ function IsDetachedBuffer(buffer) {
// only hot for non-shared memory in SetFromNonTypedArray, so there is an
// optimization in place there to avoid incurring the cost here. An
// alternative is to give SharedArrayBuffer the same layout as ArrayBuffer.
if (IsSharedArrayBuffer(buffer))
if ((buffer = GuardToArrayBuffer(buffer)) === null)
return false;
var flags = UnsafeGetInt32FromReservedSlot(buffer, JS_ARRAYBUFFER_FLAGS_SLOT);
@ -891,7 +891,8 @@ function SetFromNonTypedArray(target, array, targetOffset, targetLength, targetB
// Optimization: if the buffer is shared then it is not detachable
// and also not inline, so avoid checking overhead inside the loop in
// that case.
var isShared = targetBuffer !== null && IsSharedArrayBuffer(targetBuffer);
var isShared = targetBuffer !== null
&& (targetBuffer = GuardToSharedArrayBuffer(targetBuffer)) !== null;
// Steps 12-15, 21, 23-24.
while (targetOffset < limitOffset) {
@ -1608,8 +1609,8 @@ function ArrayBufferSlice(start, end) {
// Steps 2-3,
// This function is not generic.
if (!IsObject(O) || !IsArrayBuffer(O)) {
return callFunction(CallArrayBufferMethodIfWrapped, O, start, end,
if (!IsObject(O) || (O = GuardToArrayBuffer(O)) === null) {
return callFunction(CallArrayBufferMethodIfWrapped, this, start, end,
"ArrayBufferSlice");
}
@ -1645,28 +1646,30 @@ function ArrayBufferSlice(start, end) {
var new_ = new ctor(newLen);
var isWrapped = false;
if (IsArrayBuffer(new_)) {
var newBuffer;
if ((newBuffer = GuardToArrayBuffer(new_)) !== null) {
// Step 14.
if (IsDetachedBuffer(new_))
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
} else {
newBuffer = new_;
// Step 13.
if (!IsWrappedArrayBuffer(new_))
if (!IsWrappedArrayBuffer(newBuffer))
ThrowTypeError(JSMSG_NON_ARRAY_BUFFER_RETURNED);
isWrapped = true;
// Step 14.
if (callFunction(CallArrayBufferMethodIfWrapped, new_, "IsDetachedBufferThis"))
if (callFunction(CallArrayBufferMethodIfWrapped, newBuffer, "IsDetachedBufferThis"))
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
}
// Step 15.
if (new_ === O)
if (newBuffer === O)
ThrowTypeError(JSMSG_SAME_ARRAY_BUFFER_RETURNED);
// Step 16.
var actualLen = PossiblyWrappedArrayBufferByteLength(new_);
var actualLen = PossiblyWrappedArrayBufferByteLength(newBuffer);
if (actualLen < newLen)
ThrowTypeError(JSMSG_SHORT_ARRAY_BUFFER_RETURNED, newLen, actualLen);
@ -1675,7 +1678,7 @@ function ArrayBufferSlice(start, end) {
ThrowTypeError(JSMSG_TYPED_ARRAY_DETACHED);
// Steps 19-21.
ArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);
ArrayBufferCopyData(newBuffer, 0, O, first | 0, newLen | 0, isWrapped);
// Step 22.
return new_;
@ -1707,8 +1710,8 @@ function SharedArrayBufferSlice(start, end) {
// Steps 2-4,
// This function is not generic.
if (!IsObject(O) || !IsSharedArrayBuffer(O)) {
return callFunction(CallSharedArrayBufferMethodIfWrapped, O, start, end,
if (!IsObject(O) || (O = GuardToSharedArrayBuffer(O)) === null) {
return callFunction(CallSharedArrayBufferMethodIfWrapped, this, start, end,
"SharedArrayBufferSlice");
}
@ -1741,27 +1744,29 @@ function SharedArrayBufferSlice(start, end) {
// Step 13.
var isWrapped = false;
if (!IsSharedArrayBuffer(new_)) {
var newObj;
if ((newObj = GuardToSharedArrayBuffer(new_)) === null) {
if (!IsWrappedSharedArrayBuffer(new_))
ThrowTypeError(JSMSG_NON_SHARED_ARRAY_BUFFER_RETURNED);
isWrapped = true;
newObj = new_;
}
// Step 14.
if (new_ === O)
if (newObj === O)
ThrowTypeError(JSMSG_SAME_SHARED_ARRAY_BUFFER_RETURNED);
// Steb 14b.
if (SharedArrayBuffersMemorySame(new_, O))
if (SharedArrayBuffersMemorySame(newObj, O))
ThrowTypeError(JSMSG_SAME_SHARED_ARRAY_BUFFER_RETURNED);
// Step 15.
var actualLen = PossiblyWrappedSharedArrayBufferByteLength(new_);
var actualLen = PossiblyWrappedSharedArrayBufferByteLength(newObj);
if (actualLen < newLen)
ThrowTypeError(JSMSG_SHORT_SHARED_ARRAY_BUFFER_RETURNED, newLen, actualLen);
// Steps 16-18.
SharedArrayBufferCopyData(new_, 0, O, first | 0, newLen | 0, isWrapped);
SharedArrayBufferCopyData(newObj, 0, O, first | 0, newLen | 0, isWrapped);
// Step 19.
return new_;

View File

@ -80,7 +80,7 @@ function resolveCollatorInternals(lazyCollatorData) {
*/
function getCollatorInternals(obj) {
assert(IsObject(obj), "getCollatorInternals called with non-object");
assert(IsCollator(obj), "getCollatorInternals called with non-Collator");
assert(GuardToCollator(obj) !== null, "getCollatorInternals called with non-Collator");
var internals = getIntlObjectInternals(obj);
assert(internals.type === "Collator", "bad type escaped getIntlObjectInternals");
@ -109,7 +109,7 @@ function getCollatorInternals(obj) {
*/
function InitializeCollator(collator, locales, options) {
assert(IsObject(collator), "InitializeCollator called with non-object");
assert(IsCollator(collator), "InitializeCollator called with non-Collator");
assert(GuardToCollator(collator) != null, "InitializeCollator called with non-Collator");
// Lazy Collator data has the following structure:
//
@ -329,7 +329,7 @@ function collatorCompareToBind(x, y) {
// Step 2.
assert(IsObject(collator), "collatorCompareToBind called with non-object");
assert(IsCollator(collator), "collatorCompareToBind called with non-Collator");
assert(GuardToCollator(collator) !== null, "collatorCompareToBind called with non-Collator");
// Steps 3-6
var X = ToString(x);
@ -353,7 +353,7 @@ function Intl_Collator_compare_get() {
var collator = this;
// Steps 2-3.
if (!IsObject(collator) || !IsCollator(collator))
if (!IsObject(collator) || (collator = GuardToCollator(collator)) === null)
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "Collator", "compare", "Collator");
var internals = getCollatorInternals(collator);
@ -382,7 +382,7 @@ function Intl_Collator_resolvedOptions() {
var collator = this;
// Steps 2-3.
if (!IsObject(collator) || !IsCollator(collator))
if (!IsObject(collator) || (collator = GuardToCollator(collator)) === null)
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "Collator", "resolvedOptions", "Collator");
var internals = getCollatorInternals(collator);

View File

@ -1444,11 +1444,11 @@ function intlFallbackSymbol() {
*/
function initializeIntlObject(obj, type, lazyData) {
assert(IsObject(obj), "Non-object passed to initializeIntlObject");
assert((type === "Collator" && IsCollator(obj)) ||
(type === "DateTimeFormat" && IsDateTimeFormat(obj)) ||
(type === "NumberFormat" && IsNumberFormat(obj)) ||
(type === "PluralRules" && IsPluralRules(obj)) ||
(type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
assert((type === "Collator" && GuardToCollator(obj) !== null) ||
(type === "DateTimeFormat" && GuardToDateTimeFormat(obj) !== null) ||
(type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
(type === "PluralRules" && GuardToPluralRules(obj) !== null) ||
(type === "RelativeTimeFormat" && GuardToRelativeTimeFormat(obj) !== null),
"type must match the object's class");
assert(IsObject(lazyData), "non-object lazy data");
@ -1512,20 +1512,20 @@ function maybeInternalProperties(internals) {
*/
function getIntlObjectInternals(obj) {
assert(IsObject(obj), "getIntlObjectInternals called with non-Object");
assert(IsCollator(obj) || IsDateTimeFormat(obj) ||
IsNumberFormat(obj) || IsPluralRules(obj) ||
IsRelativeTimeFormat(obj),
assert(GuardToCollator(obj) !== null || GuardToDateTimeFormat(obj) !== null ||
GuardToNumberFormat(obj) !== null || GuardToPluralRules(obj) !== null ||
GuardToRelativeTimeFormat(obj) !== null,
"getIntlObjectInternals called with non-Intl object");
var internals = UnsafeGetReservedSlot(obj, INTL_INTERNALS_OBJECT_SLOT);
assert(IsObject(internals), "internals not an object");
assert(hasOwn("type", internals), "missing type");
assert((internals.type === "Collator" && IsCollator(obj)) ||
(internals.type === "DateTimeFormat" && IsDateTimeFormat(obj)) ||
(internals.type === "NumberFormat" && IsNumberFormat(obj)) ||
(internals.type === "PluralRules" && IsPluralRules(obj)) ||
(internals.type === "RelativeTimeFormat" && IsRelativeTimeFormat(obj)),
assert((internals.type === "Collator" && GuardToCollator(obj) !== null) ||
(internals.type === "DateTimeFormat" && GuardToDateTimeFormat(obj) !== null) ||
(internals.type === "NumberFormat" && GuardToNumberFormat(obj) !== null) ||
(internals.type === "PluralRules" && GuardToPluralRules(obj) !== null) ||
(internals.type === "RelativeTimeFormat" && GuardToRelativeTimeFormat(obj) !== null),
"type must match the object's class");
assert(hasOwn("lazyData", internals), "missing lazyData");
assert(hasOwn("internalProps", internals), "missing internalProps");

View File

@ -169,7 +169,7 @@ function replaceHourRepresentation(pattern, hourCycle) {
*/
function getDateTimeFormatInternals(obj) {
assert(IsObject(obj), "getDateTimeFormatInternals called with non-object");
assert(IsDateTimeFormat(obj), "getDateTimeFormatInternals called with non-DateTimeFormat");
assert(GuardToDateTimeFormat(obj) !== null, "getDateTimeFormatInternals called with non-DateTimeFormat");
var internals = getIntlObjectInternals(obj);
assert(internals.type === "DateTimeFormat", "bad type escaped getIntlObjectInternals");
@ -192,11 +192,11 @@ function UnwrapDateTimeFormat(dtf, methodName) {
// Step 1 (not applicable in our implementation).
// Step 2.
if (IsObject(dtf) && !IsDateTimeFormat(dtf) && dtf instanceof GetDateTimeFormatConstructor())
if (IsObject(dtf) && (GuardToDateTimeFormat(dtf)) === null && dtf instanceof GetDateTimeFormatConstructor())
dtf = dtf[intlFallbackSymbol()];
// Step 3.
if (!IsObject(dtf) || !IsDateTimeFormat(dtf)) {
if (!IsObject(dtf) || (dtf = GuardToDateTimeFormat(dtf)) === null) {
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "DateTimeFormat", methodName,
"DateTimeFormat");
}
@ -302,7 +302,7 @@ function DefaultTimeZone() {
*/
function InitializeDateTimeFormat(dateTimeFormat, thisValue, locales, options, mozExtensions) {
assert(IsObject(dateTimeFormat), "InitializeDateTimeFormat called with non-Object");
assert(IsDateTimeFormat(dateTimeFormat),
assert(GuardToDateTimeFormat(dateTimeFormat) !== null,
"InitializeDateTimeFormat called with non-DateTimeFormat");
// Lazy DateTimeFormat data has the following structure:
@ -785,7 +785,7 @@ function dateTimeFormatFormatToBind(date) {
// Step 2.
assert(IsObject(dtf), "dateTimeFormatFormatToBind called with non-Object");
assert(IsDateTimeFormat(dtf), "dateTimeFormatFormatToBind called with non-DateTimeFormat");
assert(GuardToDateTimeFormat(dtf) !== null, "dateTimeFormatFormatToBind called with non-DateTimeFormat");
// Steps 3-4.
var x = (date === undefined) ? std_Date_now() : ToNumber(date);
@ -831,7 +831,7 @@ function Intl_DateTimeFormat_formatToParts(date) {
var dtf = this;
// Steps 2-3.
if (!IsObject(dtf) || !IsDateTimeFormat(dtf)) {
if (!IsObject(dtf) || (dtf = GuardToDateTimeFormat(dtf)) == null) {
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "DateTimeFormat", "formatToParts",
"DateTimeFormat");
}

View File

@ -88,7 +88,7 @@ function resolveNumberFormatInternals(lazyNumberFormatData) {
*/
function getNumberFormatInternals(obj) {
assert(IsObject(obj), "getNumberFormatInternals called with non-object");
assert(IsNumberFormat(obj), "getNumberFormatInternals called with non-NumberFormat");
assert(GuardToNumberFormat(obj) !== null, "getNumberFormatInternals called with non-NumberFormat");
var internals = getIntlObjectInternals(obj);
assert(internals.type === "NumberFormat", "bad type escaped getIntlObjectInternals");
@ -111,11 +111,11 @@ function UnwrapNumberFormat(nf, methodName) {
// Step 1 (not applicable in our implementation).
// Step 2.
if (IsObject(nf) && !IsNumberFormat(nf) && nf instanceof GetNumberFormatConstructor())
if (IsObject(nf) && (GuardToNumberFormat(nf)) === null && nf instanceof GetNumberFormatConstructor())
nf = nf[intlFallbackSymbol()];
// Step 3.
if (!IsObject(nf) || !IsNumberFormat(nf))
if (!IsObject(nf) || (nf = GuardToNumberFormat(nf)) === null)
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "NumberFormat", methodName, "NumberFormat");
// Step 4.
@ -205,7 +205,7 @@ function IsWellFormedCurrencyCode(currency) {
*/
function InitializeNumberFormat(numberFormat, thisValue, locales, options) {
assert(IsObject(numberFormat), "InitializeNumberFormat called with non-object");
assert(IsNumberFormat(numberFormat), "InitializeNumberFormat called with non-NumberFormat");
assert(GuardToNumberFormat(numberFormat) !== null, "InitializeNumberFormat called with non-NumberFormat");
// Lazy NumberFormat data has the following structure:
//
@ -405,7 +405,7 @@ function numberFormatFormatToBind(value) {
// Step 2.
assert(IsObject(nf), "InitializeNumberFormat called with non-object");
assert(IsNumberFormat(nf), "InitializeNumberFormat called with non-NumberFormat");
assert(GuardToNumberFormat(nf) !== null, "InitializeNumberFormat called with non-NumberFormat");
// Steps 3-4.
var x = ToNumber(value);
@ -449,7 +449,7 @@ function Intl_NumberFormat_formatToParts(value) {
var nf = this;
// Steps 2-3.
if (!IsObject(nf) || !IsNumberFormat(nf)) {
if (!IsObject(nf) || (nf = GuardToNumberFormat(nf)) === null) {
ThrowTypeError(JSMSG_INTL_OBJECT_NOT_INITED, "NumberFormat", "formatToParts",
"NumberFormat");
}

Some files were not shown because too many files have changed in this diff Show More