2015-05-03 22:32:37 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2013-12-09 06:52:54 +04:00
|
|
|
#include "mozilla/ArrayUtils.h"
|
2016-10-18 07:29:03 +03:00
|
|
|
#include "mozilla/DeclarationBlockInlines.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-03-17 10:56:53 +04:00
|
|
|
#include "mozilla/EventListenerManager.h"
|
2014-04-01 08:09:23 +04:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-03 08:18:36 +04:00
|
|
|
#include "mozilla/EventStates.h"
|
2017-01-27 03:51:01 +03:00
|
|
|
#include "mozilla/GenericSpecifiedValuesInlines.h"
|
2012-10-26 17:32:10 +04:00
|
|
|
#include "mozilla/Likely.h"
|
2017-06-22 09:21:31 +03:00
|
|
|
#include "mozilla/MouseEvents.h"
|
|
|
|
#include "mozilla/TextEditor.h"
|
2011-10-11 09:50:08 +04:00
|
|
|
|
2001-08-14 11:59:59 +04:00
|
|
|
#include "nscore.h"
|
1998-09-03 03:53:16 +04:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
1999-02-12 20:45:58 +03:00
|
|
|
#include "nsCOMPtr.h"
|
1998-08-29 03:27:19 +04:00
|
|
|
#include "nsIAtom.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
2013-10-02 15:40:07 +04:00
|
|
|
#include "nsIContentInlines.h"
|
2004-07-25 01:12:43 +04:00
|
|
|
#include "nsIContentViewer.h"
|
2015-11-09 10:57:16 +03:00
|
|
|
#include "mozilla/css/Declaration.h"
|
1998-08-29 03:27:19 +04:00
|
|
|
#include "nsIDocument.h"
|
2000-05-12 01:49:16 +04:00
|
|
|
#include "nsIDocumentEncoder.h"
|
2001-06-30 02:44:20 +04:00
|
|
|
#include "nsIDOMHTMLDocument.h"
|
1998-10-20 21:07:23 +04:00
|
|
|
#include "nsIDOMAttr.h"
|
1998-11-30 10:59:11 +03:00
|
|
|
#include "nsIDOMDocumentFragment.h"
|
2011-10-30 00:03:55 +04:00
|
|
|
#include "nsIDOMHTMLElement.h"
|
2004-04-13 02:47:24 +04:00
|
|
|
#include "nsIDOMWindow.h"
|
|
|
|
#include "nsIDOMDocument.h"
|
2004-01-26 22:22:05 +03:00
|
|
|
#include "nsMappedAttributes.h"
|
2004-04-13 01:56:09 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
1998-09-02 06:05:53 +04:00
|
|
|
#include "nsIHTMLDocument.h"
|
2000-11-27 10:55:20 +03:00
|
|
|
#include "nsPIDOMWindow.h"
|
1998-08-29 07:15:55 +04:00
|
|
|
#include "nsIURL.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsEscape.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "nsIFrameInlines.h"
|
2001-10-17 05:17:47 +04:00
|
|
|
#include "nsIScrollableFrame.h"
|
2013-01-03 17:23:11 +04:00
|
|
|
#include "nsView.h"
|
2013-01-05 07:12:24 +04:00
|
|
|
#include "nsViewManager.h"
|
2011-11-27 15:51:53 +04:00
|
|
|
#include "nsIWidget.h"
|
1998-12-30 11:28:16 +03:00
|
|
|
#include "nsRange.h"
|
1998-09-11 08:16:18 +04:00
|
|
|
#include "nsIPresShell.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
2003-05-30 04:21:01 +04:00
|
|
|
#include "nsIDocShell.h"
|
2014-02-28 03:04:46 +04:00
|
|
|
#include "nsNameSpaceManager.h"
|
2012-07-27 18:03:27 +04:00
|
|
|
#include "nsError.h"
|
2013-11-21 00:23:43 +04:00
|
|
|
#include "nsIPrincipal.h"
|
2014-05-25 02:20:39 +04:00
|
|
|
#include "nsContainerFrame.h"
|
2015-11-28 03:56:33 +03:00
|
|
|
#include "nsStyleUtil.h"
|
1998-08-29 03:27:19 +04:00
|
|
|
|
2005-01-28 01:52:53 +03:00
|
|
|
#include "nsPresState.h"
|
2000-01-14 12:28:54 +03:00
|
|
|
#include "nsILayoutHistoryState.h"
|
|
|
|
|
1998-09-04 04:19:32 +04:00
|
|
|
#include "nsHTMLParts.h"
|
2003-05-30 04:21:01 +04:00
|
|
|
#include "nsContentUtils.h"
|
2012-04-17 08:03:10 +04:00
|
|
|
#include "mozilla/dom/DirectionalityUtils.h"
|
1998-08-29 03:27:19 +04:00
|
|
|
#include "nsString.h"
|
2001-10-20 01:00:02 +04:00
|
|
|
#include "nsUnicharUtils.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
2000-12-30 22:22:22 +03:00
|
|
|
#include "nsIDOMEvent.h"
|
1998-10-06 05:39:33 +04:00
|
|
|
#include "nsDOMCSSDeclaration.h"
|
2005-09-07 22:19:26 +04:00
|
|
|
#include "nsITextControlFrame.h"
|
1999-07-28 09:26:55 +04:00
|
|
|
#include "nsIForm.h"
|
|
|
|
#include "nsIFormControl.h"
|
|
|
|
#include "nsIDOMHTMLFormElement.h"
|
2013-06-19 18:24:37 +04:00
|
|
|
#include "mozilla/dom/HTMLFormElement.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2012-11-21 14:13:57 +04:00
|
|
|
#include "nsAttrValueOrString.h"
|
1998-08-29 03:27:19 +04:00
|
|
|
|
2014-02-27 14:51:15 +04:00
|
|
|
#include "mozilla/InternalMutationEvent.h"
|
2011-05-20 21:23:49 +04:00
|
|
|
#include "nsDOMStringMap.h"
|
|
|
|
|
2006-06-21 01:21:47 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
2008-04-11 21:29:06 +04:00
|
|
|
#include "mozAutoDocUpdate.h"
|
2010-05-04 12:36:42 +04:00
|
|
|
#include "nsHtml5Module.h"
|
2010-04-22 00:17:41 +04:00
|
|
|
#include "nsITextControlElement.h"
|
2017-07-30 08:11:53 +03:00
|
|
|
#include "mozilla/dom/ElementInlines.h"
|
2013-02-08 20:34:47 +04:00
|
|
|
#include "HTMLFieldSetElement.h"
|
2015-10-30 08:37:03 +03:00
|
|
|
#include "nsTextNode.h"
|
|
|
|
#include "HTMLBRElement.h"
|
2013-02-18 15:59:08 +04:00
|
|
|
#include "HTMLMenuElement.h"
|
2012-03-31 20:30:13 +04:00
|
|
|
#include "nsDOMMutationObserver.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
#include "mozilla/Preferences.h"
|
2011-11-10 16:02:22 +04:00
|
|
|
#include "mozilla/dom/FromParser.h"
|
2013-08-08 09:26:32 +04:00
|
|
|
#include "mozilla/dom/Link.h"
|
2012-06-01 13:59:16 +04:00
|
|
|
#include "mozilla/BloomFilter.h"
|
2017-05-08 09:24:22 +03:00
|
|
|
#include "mozilla/dom/ScriptLoader.h"
|
2011-05-25 10:31:59 +04:00
|
|
|
|
2012-06-05 03:49:57 +04:00
|
|
|
#include "nsVariant.h"
|
2016-02-12 01:50:42 +03:00
|
|
|
#include "nsDOMTokenList.h"
|
2012-06-06 11:40:02 +04:00
|
|
|
#include "nsThreadUtils.h"
|
2012-07-02 03:45:59 +04:00
|
|
|
#include "nsTextFragment.h"
|
2012-09-06 00:49:53 +04:00
|
|
|
#include "mozilla/dom/BindingUtils.h"
|
2014-02-28 18:58:42 +04:00
|
|
|
#include "mozilla/dom/TouchEvent.h"
|
2012-09-06 00:49:53 +04:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2012-11-11 03:30:15 +04:00
|
|
|
#include "nsHTMLDocument.h"
|
2012-11-26 18:19:02 +04:00
|
|
|
#include "nsGlobalWindow.h"
|
2013-01-13 01:53:01 +04:00
|
|
|
#include "mozilla/dom/HTMLBodyElement.h"
|
2013-10-02 01:00:38 +04:00
|
|
|
#include "imgIContainer.h"
|
2015-10-30 08:37:03 +03:00
|
|
|
#include "nsComputedDOMStyle.h"
|
2016-02-24 10:01:11 +03:00
|
|
|
#include "mozilla/StyleSetHandle.h"
|
|
|
|
#include "mozilla/StyleSetHandleInlines.h"
|
2016-04-27 05:26:57 +03:00
|
|
|
#include "ReferrerPolicy.h"
|
2017-06-16 03:04:00 +03:00
|
|
|
#include "mozilla/dom/HTMLLabelElement.h"
|
2017-08-03 08:27:00 +03:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
2012-06-05 03:49:57 +04:00
|
|
|
|
2011-05-25 10:31:59 +04:00
|
|
|
using namespace mozilla;
|
2010-05-09 22:32:57 +04:00
|
|
|
using namespace mozilla::dom;
|
2005-11-15 02:55:24 +03:00
|
|
|
|
2010-05-19 21:52:17 +04:00
|
|
|
/**
|
|
|
|
* nsAutoFocusEvent is used to dispatch a focus event when a
|
|
|
|
* nsGenericHTMLFormElement is binded to the tree with the autofocus attribute
|
|
|
|
* enabled.
|
|
|
|
*/
|
2016-04-26 03:23:21 +03:00
|
|
|
class nsAutoFocusEvent : public Runnable
|
2010-05-19 21:52:17 +04:00
|
|
|
{
|
|
|
|
public:
|
2017-06-12 22:34:10 +03:00
|
|
|
explicit nsAutoFocusEvent(nsGenericHTMLFormElement* aElement)
|
|
|
|
: mozilla::Runnable("nsAutoFocusEvent")
|
|
|
|
, mElement(aElement)
|
|
|
|
{
|
|
|
|
}
|
2010-05-19 21:52:17 +04:00
|
|
|
|
2016-08-08 05:18:10 +03:00
|
|
|
NS_IMETHOD Run() override {
|
2010-05-19 21:52:17 +04:00
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (!fm) {
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
}
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* document = mElement->OwnerDoc();
|
2010-05-19 21:52:17 +04:00
|
|
|
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = document->GetWindow();
|
2010-12-22 03:58:24 +03:00
|
|
|
if (!window) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2010-12-17 20:47:58 +03:00
|
|
|
|
|
|
|
// Trying to found the top window (equivalent to window.top).
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsCOMPtr<nsPIDOMWindowOuter> top = window->GetTop()) {
|
2015-10-27 00:37:32 +03:00
|
|
|
window = top;
|
2010-12-17 20:47:58 +03:00
|
|
|
}
|
|
|
|
|
2010-12-22 03:58:24 +03:00
|
|
|
if (window->GetFocusedNode()) {
|
2010-12-18 05:01:12 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-06 11:19:52 +04:00
|
|
|
nsCOMPtr<nsIDocument> topDoc = window->GetExtantDoc();
|
2010-12-22 03:58:24 +03:00
|
|
|
if (topDoc && topDoc->GetReadyStateEnum() == nsIDocument::READYSTATE_COMPLETE) {
|
2010-05-19 21:52:17 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If something is focused in the same document, ignore autofocus.
|
|
|
|
if (!fm->GetFocusedContent() ||
|
2011-10-18 14:53:36 +04:00
|
|
|
fm->GetFocusedContent()->OwnerDoc() != document) {
|
2012-10-06 11:19:52 +04:00
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
mElement->Focus(rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2010-05-19 21:52:17 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
private:
|
|
|
|
// NOTE: nsGenericHTMLFormElement is saved as a nsGenericHTMLElement
|
|
|
|
// because AddRef/Release are ambiguous with nsGenericHTMLFormElement
|
|
|
|
// and Focus() is declared (and defined) in nsGenericHTMLElement class.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> mElement;
|
2010-05-19 21:52:17 +04:00
|
|
|
};
|
2001-10-30 13:14:06 +03:00
|
|
|
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(nsGenericHTMLElement, nsGenericHTMLElementBase)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(nsGenericHTMLElement, nsGenericHTMLElementBase)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-08 00:23:08 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsGenericHTMLElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMHTMLElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMElement)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIDOMNode)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElementBase)
|
2011-05-20 21:23:49 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
nsresult
|
2017-04-20 22:57:48 +03:00
|
|
|
nsGenericHTMLElement::CopyInnerTo(Element* aDst, bool aPreallocateChildren)
|
1999-01-15 02:14:02 +03:00
|
|
|
{
|
2017-06-15 19:56:18 +03:00
|
|
|
MOZ_ASSERT(!aDst->GetUncomposedDoc(),
|
|
|
|
"Should not CopyInnerTo an Element in a document");
|
2006-09-05 14:22:54 +04:00
|
|
|
nsresult rv;
|
2017-04-20 22:57:48 +03:00
|
|
|
|
2017-06-15 19:56:18 +03:00
|
|
|
bool reparse = (aDst->OwnerDoc() != OwnerDoc());
|
|
|
|
|
2017-04-20 22:57:48 +03:00
|
|
|
rv = static_cast<nsGenericHTMLElement*>(aDst)->mAttrsAndChildren.
|
|
|
|
EnsureCapacityToClone(mAttrsAndChildren, aPreallocateChildren);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i, count = GetAttrCount();
|
2004-01-26 22:22:05 +03:00
|
|
|
for (i = 0; i < count; ++i) {
|
2005-12-30 23:12:35 +03:00
|
|
|
const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
|
2005-09-11 21:15:08 +04:00
|
|
|
const nsAttrValue *value = mAttrsAndChildren.AttrAt(i);
|
2012-04-05 21:14:54 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (name->Equals(nsGkAtoms::style, kNameSpaceID_None) &&
|
2016-10-18 07:29:03 +03:00
|
|
|
value->Type() == nsAttrValue::eCSSDeclaration) {
|
2017-06-15 19:56:18 +03:00
|
|
|
// We still clone CSS attributes, even in the cross-document case.
|
|
|
|
// https://github.com/w3c/webappsec-csp/issues/212
|
|
|
|
|
2004-01-26 22:22:05 +03:00
|
|
|
// We can't just set this as a string, because that will fail
|
|
|
|
// to reparse the string into style data until the node is
|
2011-04-08 05:23:46 +04:00
|
|
|
// inserted into the document. Clone the Rule instead.
|
2017-06-17 00:43:45 +03:00
|
|
|
nsAttrValue valueCopy(*value);
|
|
|
|
rv = aDst->SetParsedAttr(name->NamespaceID(), name->LocalName(),
|
|
|
|
name->GetPrefix(), valueCopy, false);
|
2005-09-11 21:15:08 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2017-06-17 00:43:45 +03:00
|
|
|
|
|
|
|
DeclarationBlock* cssDeclaration = value->GetCSSDeclarationValue();
|
|
|
|
cssDeclaration->SetImmutable();
|
2017-06-15 19:56:18 +03:00
|
|
|
} else if (reparse) {
|
|
|
|
nsAutoString valStr;
|
|
|
|
value->ToString(valStr);
|
2005-09-11 19:42:31 +04:00
|
|
|
|
2017-06-15 19:56:18 +03:00
|
|
|
rv = aDst->SetAttr(name->NamespaceID(), name->LocalName(),
|
|
|
|
name->GetPrefix(), valStr, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
nsAttrValue valueCopy(*value);
|
|
|
|
rv = aDst->SetParsedAttr(name->NamespaceID(), name->LocalName(),
|
|
|
|
name->GetPrefix(), valueCopy, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2005-09-11 21:15:08 +04:00
|
|
|
}
|
1999-01-15 02:14:02 +03:00
|
|
|
}
|
|
|
|
|
2006-09-05 14:22:54 +04:00
|
|
|
return NS_OK;
|
1999-01-15 02:14:02 +03:00
|
|
|
}
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kDirTable[] = {
|
2012-11-21 14:13:57 +04:00
|
|
|
{ "ltr", eDir_LTR },
|
|
|
|
{ "rtl", eDir_RTL },
|
|
|
|
{ "auto", eDir_Auto },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1999-09-22 03:23:53 +04:00
|
|
|
};
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
void
|
2013-08-08 00:23:08 +04:00
|
|
|
nsGenericHTMLElement::GetAccessKeyLabel(nsString& aLabel)
|
2011-07-31 23:43:54 +04:00
|
|
|
{
|
2014-10-15 09:42:00 +04:00
|
|
|
nsAutoString suffix;
|
|
|
|
GetAccessKey(suffix);
|
|
|
|
if (!suffix.IsEmpty()) {
|
|
|
|
EventStateManager::GetAccessKeyLabelPrefix(this, aLabel);
|
|
|
|
aLabel.Append(suffix);
|
2011-07-31 23:43:54 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
static bool
|
2017-05-01 20:32:52 +03:00
|
|
|
IS_TABLE_CELL(LayoutFrameType frameType)
|
2017-04-30 18:30:08 +03:00
|
|
|
{
|
2017-05-01 20:32:52 +03:00
|
|
|
return LayoutFrameType::TableCell == frameType ||
|
|
|
|
LayoutFrameType::BCTableCell == frameType;
|
2007-06-14 04:08:10 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2007-06-14 04:08:10 +04:00
|
|
|
IsOffsetParent(nsIFrame* aFrame)
|
2001-11-29 08:08:25 +03:00
|
|
|
{
|
2017-05-01 20:32:52 +03:00
|
|
|
LayoutFrameType frameType = aFrame->Type();
|
2017-04-30 18:30:08 +03:00
|
|
|
|
2017-05-01 20:32:52 +03:00
|
|
|
if (IS_TABLE_CELL(frameType) || frameType == LayoutFrameType::Table) {
|
2012-12-11 17:48:04 +04:00
|
|
|
// Per the IDL for Element, only td, th, and table are acceptable offsetParents
|
|
|
|
// apart from body or positioned elements; we need to check the content type as
|
|
|
|
// well as the frame type so we ignore anonymous tables created by an element
|
|
|
|
// with display: table-cell with no actual table
|
|
|
|
nsIContent* content = aFrame->GetContent();
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
return content->IsAnyOfHTMLElements(nsGkAtoms::table,
|
|
|
|
nsGkAtoms::td,
|
|
|
|
nsGkAtoms::th);
|
2012-12-11 17:48:04 +04:00
|
|
|
}
|
|
|
|
return false;
|
2001-11-29 08:08:25 +03:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
Element*
|
2013-06-12 11:00:08 +04:00
|
|
|
nsGenericHTMLElement::GetOffsetRect(CSSIntRect& aRect)
|
2000-02-16 05:25:07 +03:00
|
|
|
{
|
2013-06-12 11:00:08 +04:00
|
|
|
aRect = CSSIntRect();
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2008-08-16 02:26:37 +04:00
|
|
|
nsIFrame* frame = GetStyledFrame();
|
2007-03-15 23:43:02 +03:00
|
|
|
if (!frame) {
|
2012-11-11 03:30:15 +04:00
|
|
|
return nullptr;
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
|
|
|
|
2007-03-15 23:43:02 +03:00
|
|
|
nsIFrame* parent = frame->GetParent();
|
|
|
|
nsPoint origin(0, 0);
|
2001-06-30 02:44:20 +04:00
|
|
|
|
2017-04-30 18:30:08 +03:00
|
|
|
if (parent && parent->IsTableWrapperFrame() && frame->IsTableFrame()) {
|
2007-03-15 23:43:02 +03:00
|
|
|
origin = parent->GetPositionIgnoringScrolling();
|
|
|
|
parent = parent->GetParent();
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
nsIContent* offsetParent = nullptr;
|
2014-09-05 14:54:00 +04:00
|
|
|
Element* docElement = GetComposedDoc()->GetRootElement();
|
2003-08-06 07:07:12 +04:00
|
|
|
nsIContent* content = frame->GetContent();
|
2001-06-30 02:44:20 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content && (content->IsHTMLElement(nsGkAtoms::body) ||
|
|
|
|
content == docElement)) {
|
2007-03-15 23:43:02 +03:00
|
|
|
parent = frame;
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
2007-03-15 23:43:02 +03:00
|
|
|
else {
|
2016-08-13 04:39:45 +03:00
|
|
|
const bool isPositioned = frame->IsAbsPosContainingBlock();
|
2012-08-02 15:38:50 +04:00
|
|
|
const bool isAbsolutelyPositioned = frame->IsAbsolutelyPositioned();
|
2007-03-15 23:43:02 +03:00
|
|
|
origin += frame->GetPositionIgnoringScrolling();
|
2001-06-30 02:44:20 +04:00
|
|
|
|
2007-03-15 23:43:02 +03:00
|
|
|
for ( ; parent ; parent = parent->GetParent()) {
|
|
|
|
content = parent->GetContent();
|
2001-06-30 02:44:20 +04:00
|
|
|
|
2007-03-15 23:43:02 +03:00
|
|
|
// Stop at the first ancestor that is positioned.
|
2016-08-13 04:39:45 +03:00
|
|
|
if (parent->IsAbsPosContainingBlock()) {
|
2012-11-11 03:30:15 +04:00
|
|
|
offsetParent = content;
|
2003-05-15 07:42:21 +04:00
|
|
|
break;
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
2000-02-16 05:25:07 +03:00
|
|
|
|
2001-06-30 02:44:20 +04:00
|
|
|
// Add the parent's origin to our own to get to the
|
2007-03-15 23:43:02 +03:00
|
|
|
// right coordinate system.
|
2011-09-29 10:19:26 +04:00
|
|
|
const bool isOffsetParent = !isPositioned && IsOffsetParent(parent);
|
2017-09-26 09:01:57 +03:00
|
|
|
if (!isOffsetParent) {
|
2006-06-21 01:21:47 +04:00
|
|
|
origin += parent->GetPositionIgnoringScrolling();
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (content) {
|
2007-03-15 23:43:02 +03:00
|
|
|
// If we've hit the document element, break here.
|
2001-06-30 02:44:20 +04:00
|
|
|
if (content == docElement) {
|
|
|
|
break;
|
2000-02-16 05:25:07 +03:00
|
|
|
}
|
|
|
|
|
2007-06-23 11:39:04 +04:00
|
|
|
// Break if the ancestor frame type makes it suitable as offset parent
|
|
|
|
// and this element is *not* positioned or if we found the body element.
|
2015-03-03 14:08:59 +03:00
|
|
|
if (isOffsetParent || content->IsHTMLElement(nsGkAtoms::body)) {
|
2012-11-11 03:30:15 +04:00
|
|
|
offsetParent = content;
|
2001-06-30 02:44:20 +04:00
|
|
|
break;
|
2000-02-16 05:25:07 +03:00
|
|
|
}
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
|
|
|
}
|
2000-02-16 05:25:07 +03:00
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
if (isAbsolutelyPositioned && !offsetParent) {
|
2001-06-30 02:44:20 +04:00
|
|
|
// If this element is absolutely positioned, but we don't have
|
|
|
|
// an offset parent it means this element is an absolutely
|
|
|
|
// positioned child that's not nested inside another positioned
|
|
|
|
// element, in this case the element's frame's parent is the
|
|
|
|
// frame for the HTML element so we fail to find the body in the
|
|
|
|
// parent chain. We want the offset parent in this case to be
|
|
|
|
// the body, so we just get the body element from the document.
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-09-05 14:54:00 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> html_doc(do_QueryInterface(GetComposedDoc()));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2001-06-30 02:44:20 +04:00
|
|
|
if (html_doc) {
|
2012-11-11 03:30:15 +04:00
|
|
|
offsetParent = static_cast<nsHTMLDocument*>(html_doc.get())->GetBody();
|
2000-02-16 05:25:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2007-03-15 23:43:02 +03:00
|
|
|
// Subtract the parent border unless it uses border-box sizing.
|
|
|
|
if (parent &&
|
2015-11-20 05:09:29 +03:00
|
|
|
parent->StylePosition()->mBoxSizing != StyleBoxSizing::Border) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleBorder* border = parent->StyleBorder();
|
2016-11-18 13:12:25 +03:00
|
|
|
origin.x -= border->GetComputedBorderWidth(eSideLeft);
|
|
|
|
origin.y -= border->GetComputedBorderWidth(eSideTop);
|
2001-06-30 02:44:20 +04:00
|
|
|
}
|
|
|
|
|
2002-09-11 05:58:59 +04:00
|
|
|
// XXX We should really consider subtracting out padding for
|
|
|
|
// content-box sizing, but we should see what IE does....
|
2001-06-30 02:44:20 +04:00
|
|
|
|
2008-02-27 12:26:15 +03:00
|
|
|
// Get the union of all rectangles in this and continuation frames.
|
|
|
|
// It doesn't really matter what we use as aRelativeTo here, since
|
2008-04-11 02:36:10 +04:00
|
|
|
// we only care about the size. We just have to use something non-null.
|
|
|
|
nsRect rcFrame = nsLayoutUtils::GetAllInFlowRectsUnion(frame, frame);
|
2013-06-12 11:00:08 +04:00
|
|
|
rcFrame.MoveTo(origin);
|
|
|
|
aRect = CSSIntRect::FromAppUnitsRounded(rcFrame);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
return offsetParent ? offsetParent->AsElement() : nullptr;
|
2000-02-16 05:25:07 +03:00
|
|
|
}
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLElement::Spellcheck()
|
2006-07-29 04:04:40 +04:00
|
|
|
{
|
|
|
|
// Has the state has been explicitly set?
|
2009-08-25 00:02:07 +04:00
|
|
|
nsIContent* node;
|
|
|
|
for (node = this; node; node = node->GetParent()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (node->IsHTMLElement()) {
|
2006-07-29 04:04:40 +04:00
|
|
|
static nsIContent::AttrValuesArray strings[] =
|
2012-07-30 18:20:58 +04:00
|
|
|
{&nsGkAtoms::_true, &nsGkAtoms::_false, nullptr};
|
2009-08-25 00:02:07 +04:00
|
|
|
switch (node->FindAttrValueIn(kNameSpaceID_None, nsGkAtoms::spellcheck,
|
|
|
|
strings, eCaseMatters)) {
|
2006-07-29 04:04:40 +04:00
|
|
|
case 0: // spellcheck = "true"
|
2012-11-11 03:30:15 +04:00
|
|
|
return true;
|
2006-07-29 04:04:40 +04:00
|
|
|
case 1: // spellcheck = "false"
|
2012-11-11 03:30:15 +04:00
|
|
|
return false;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-20 00:54:53 +04:00
|
|
|
// contenteditable/designMode are spellchecked by default
|
|
|
|
if (IsEditable()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2006-07-29 04:04:40 +04:00
|
|
|
// Is this a chrome element?
|
2011-10-18 14:53:36 +04:00
|
|
|
if (nsContentUtils::IsChromeDoc(OwnerDoc())) {
|
2012-11-11 03:30:15 +04:00
|
|
|
return false; // Not spellchecked by default
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2013-06-20 00:54:53 +04:00
|
|
|
// Anything else that's not a form control is not spellchecked by default
|
2013-08-08 00:23:08 +04:00
|
|
|
nsCOMPtr<nsIFormControl> formControl = do_QueryObject(this);
|
2006-07-29 04:04:40 +04:00
|
|
|
if (!formControl) {
|
2012-11-11 03:30:15 +04:00
|
|
|
return false; // Not spellchecked by default
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// Is this a multiline plaintext input?
|
2017-04-01 05:49:00 +03:00
|
|
|
int32_t controlType = formControl->ControlType();
|
2006-07-29 04:04:40 +04:00
|
|
|
if (controlType == NS_FORM_TEXTAREA) {
|
2012-11-11 03:30:15 +04:00
|
|
|
return true; // Spellchecked by default
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 11:17:07 +04:00
|
|
|
// Is this anything other than an input text?
|
|
|
|
// Other inputs are not spellchecked.
|
2006-07-29 04:04:40 +04:00
|
|
|
if (controlType != NS_FORM_INPUT_TEXT) {
|
2012-11-11 03:30:15 +04:00
|
|
|
return false; // Not spellchecked by default
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2010-05-12 11:17:07 +04:00
|
|
|
// Does the user want input text spellchecked by default?
|
2006-07-29 04:04:40 +04:00
|
|
|
// NOTE: Do not reflect a pref value of 0 back to the DOM getter.
|
|
|
|
// The web page should not know if the user has disabled spellchecking.
|
|
|
|
// We'll catch this in the editor itself.
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t spellcheckLevel = Preferences::GetInt("layout.spellcheckDefault", 1);
|
2012-11-11 03:30:15 +04:00
|
|
|
return spellcheckLevel == 2; // "Spellcheck multi- and single-line"
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
2001-10-17 05:17:47 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2000-12-23 13:56:31 +03:00
|
|
|
nsGenericHTMLElement::InNavQuirksMode(nsIDocument* aDoc)
|
1999-08-28 01:42:08 +04:00
|
|
|
{
|
2006-12-05 18:46:18 +03:00
|
|
|
return aDoc && aDoc->GetCompatibilityMode() == eCompatibility_NavQuirks;
|
1999-08-28 01:42:08 +04:00
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLElement::UpdateEditableState(bool aNotify)
|
2007-06-28 06:48:16 +04:00
|
|
|
{
|
|
|
|
// XXX Should we do this only when in a document?
|
|
|
|
ContentEditableTristate value = GetContentEditableValue();
|
|
|
|
if (value != eInherit) {
|
2011-06-01 05:46:57 +04:00
|
|
|
DoSetEditableFlag(!!value, aNotify);
|
2007-06-28 06:48:16 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-06-01 05:46:57 +04:00
|
|
|
nsStyledElement::UpdateEditableState(aNotify);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2012-04-17 08:03:10 +04:00
|
|
|
nsGenericHTMLElement::IntrinsicState() const
|
|
|
|
{
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElementBase::IntrinsicState();
|
2012-04-17 08:03:10 +04:00
|
|
|
|
|
|
|
if (GetDirectionality() == eDir_RTL) {
|
|
|
|
state |= NS_EVENT_STATE_RTL;
|
|
|
|
state &= ~NS_EVENT_STATE_LTR;
|
|
|
|
} else { // at least for HTML, directionality is exclusively LTR or RTL
|
|
|
|
NS_ASSERTION(GetDirectionality() == eDir_LTR,
|
|
|
|
"HTML element's directionality must be either RTL or LTR");
|
|
|
|
state |= NS_EVENT_STATE_LTR;
|
|
|
|
state &= ~NS_EVENT_STATE_RTL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2015-08-14 20:52:38 +03:00
|
|
|
uint32_t
|
|
|
|
nsGenericHTMLElement::EditableInclusiveDescendantCount()
|
|
|
|
{
|
|
|
|
bool isEditable = IsInUncomposedDoc() && HasFlag(NODE_IS_EDITABLE) &&
|
|
|
|
GetContentEditableValue() == eTrue;
|
|
|
|
return EditableDescendantCount() + isEditable;
|
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult
|
|
|
|
nsGenericHTMLElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCompileEventHandlers)
|
1998-08-29 03:27:19 +04:00
|
|
|
{
|
2007-08-06 19:27:19 +04:00
|
|
|
nsresult rv = nsGenericHTMLElementBase::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
2005-04-06 03:54:35 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
1998-10-27 02:26:01 +03:00
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
if (aDocument) {
|
2011-04-11 20:56:37 +04:00
|
|
|
RegAccessKey();
|
2017-07-29 18:56:53 +03:00
|
|
|
if (HasName() && CanHaveName(NodeInfo()->NameAtom())) {
|
2010-06-04 05:09:20 +04:00
|
|
|
aDocument->
|
|
|
|
AddToNameTable(this, GetParsedAttr(nsGkAtoms::name)->GetAtomValue());
|
|
|
|
}
|
2015-08-14 20:52:38 +03:00
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
if (HasFlag(NODE_IS_EDITABLE) && GetContentEditableValue() == eTrue) {
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(aDocument);
|
|
|
|
if (htmlDocument) {
|
|
|
|
htmlDocument->ChangeContentEditableCount(this, +1);
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
2005-04-06 03:54:35 +04:00
|
|
|
|
2017-06-16 03:04:00 +03:00
|
|
|
// We need to consider a labels element is moved to another subtree
|
|
|
|
// with different root, it needs to update labels list and its root
|
|
|
|
// as well.
|
2017-07-18 01:25:49 +03:00
|
|
|
nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots();
|
2017-06-16 03:04:00 +03:00
|
|
|
if (slots && slots->mLabelsList) {
|
|
|
|
slots->mLabelsList->MaybeResetRoot(SubtreeRoot());
|
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
return rv;
|
1998-08-29 03:27:19 +04:00
|
|
|
}
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2007-06-28 06:48:16 +04:00
|
|
|
{
|
2016-03-31 13:58:25 +03:00
|
|
|
if (IsInUncomposedDoc()) {
|
2011-04-11 20:56:37 +04:00
|
|
|
UnregAccessKey();
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2010-07-21 04:40:54 +04:00
|
|
|
RemoveFromNameTable();
|
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
if (GetContentEditableValue() == eTrue) {
|
2014-10-02 23:07:24 +04:00
|
|
|
//XXXsmaug Fix this for Shadow DOM, bug 1066965.
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument = do_QueryInterface(GetUncomposedDoc());
|
2007-06-28 06:48:16 +04:00
|
|
|
if (htmlDocument) {
|
|
|
|
htmlDocument->ChangeContentEditableCount(this, -1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-16 03:04:00 +03:00
|
|
|
// We need to consider a labels element is removed from tree,
|
|
|
|
// it needs to update labels list and its root as well.
|
2017-07-18 01:25:49 +03:00
|
|
|
nsExtendedDOMSlots* slots = GetExistingExtendedDOMSlots();
|
2017-06-16 03:04:00 +03:00
|
|
|
if (slots && slots->mLabelsList) {
|
|
|
|
slots->mLabelsList->MaybeResetRoot(SubtreeRoot());
|
|
|
|
}
|
|
|
|
|
2010-06-04 05:09:20 +04:00
|
|
|
nsStyledElement::UnbindFromTree(aDeep, aNullParent);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement*
|
|
|
|
nsGenericHTMLElement::FindAncestorForm(HTMLFormElement* aCurrentForm)
|
1999-07-28 09:26:55 +04:00
|
|
|
{
|
2013-06-20 22:07:57 +04:00
|
|
|
NS_ASSERTION(!HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
|
2015-03-03 14:08:59 +03:00
|
|
|
IsHTMLElement(nsGkAtoms::img),
|
2010-08-24 05:11:04 +04:00
|
|
|
"FindAncestorForm should not be called if @form is set!");
|
|
|
|
|
2007-07-18 05:50:18 +04:00
|
|
|
// Make sure we don't end up finding a form that's anonymous from
|
2017-09-22 22:34:00 +03:00
|
|
|
// our point of view. See also nsGenericHTMLFormElement::UpdateFieldSet.
|
2007-07-18 05:50:18 +04:00
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
|
2003-07-29 05:15:55 +04:00
|
|
|
nsIContent* content = this;
|
2007-07-18 05:50:18 +04:00
|
|
|
while (content != bindingParent && content) {
|
2003-09-27 08:18:26 +04:00
|
|
|
// If the current ancestor is a form, return it as our form
|
2015-03-03 14:08:59 +03:00
|
|
|
if (content->IsHTMLElement(nsGkAtoms::form)) {
|
2007-08-03 02:46:36 +04:00
|
|
|
#ifdef DEBUG
|
|
|
|
if (!nsContentUtils::IsInSameAnonymousTree(this, content)) {
|
|
|
|
// It's possible that we started unbinding at |content| or
|
|
|
|
// some ancestor of it, and |content| and |this| used to all be
|
|
|
|
// anonymous. Check for this the hard way.
|
|
|
|
for (nsIContent* child = this; child != content;
|
|
|
|
child = child->GetParent()) {
|
|
|
|
NS_ASSERTION(child->GetParent()->IndexOf(child) != -1,
|
|
|
|
"Walked too far?");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
2013-06-19 18:24:37 +04:00
|
|
|
return static_cast<HTMLFormElement*>(content);
|
1999-07-28 09:26:55 +04:00
|
|
|
}
|
|
|
|
|
2005-05-02 08:41:06 +04:00
|
|
|
nsIContent *prevContent = content;
|
|
|
|
content = prevContent->GetParent();
|
|
|
|
|
|
|
|
if (!content && aCurrentForm) {
|
|
|
|
// We got to the root of the subtree we're in, and we're being removed
|
|
|
|
// from the DOM (the only time we get into this method with a non-null
|
|
|
|
// aCurrentForm). Check whether aCurrentForm is in the same subtree. If
|
|
|
|
// it is, we want to return aCurrentForm, since this case means that
|
|
|
|
// we're one of those inputs-in-a-table that have a hacked mForm pointer
|
|
|
|
// and a subtree containing both us and the form got removed from the
|
|
|
|
// DOM.
|
2009-10-30 04:49:11 +03:00
|
|
|
if (nsContentUtils::ContentIsDescendantOf(aCurrentForm, prevContent)) {
|
|
|
|
return aCurrentForm;
|
|
|
|
}
|
2005-05-02 08:41:06 +04:00
|
|
|
}
|
1999-07-28 09:26:55 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2001-03-02 18:45:35 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2014-03-18 08:48:18 +04:00
|
|
|
nsGenericHTMLElement::CheckHandleEventForAnchorsPreconditions(
|
|
|
|
EventChainVisitor& aVisitor)
|
2000-02-11 04:24:59 +03:00
|
|
|
{
|
2013-08-08 09:26:32 +04:00
|
|
|
NS_PRECONDITION(nsCOMPtr<Link>(do_QueryObject(this)),
|
|
|
|
"should be called only when |this| implements |Link|");
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2006-03-07 20:08:51 +03:00
|
|
|
if (!aVisitor.mPresContext) {
|
2006-04-11 17:17:29 +04:00
|
|
|
// We need a pres context to do link stuff. Some events (e.g. mutation
|
|
|
|
// events) don't have one.
|
|
|
|
// XXX: ideally, shouldn't we be able to do what we need without one?
|
2017-07-06 15:00:35 +03:00
|
|
|
return false;
|
2003-06-16 14:37:59 +04:00
|
|
|
}
|
|
|
|
|
2000-09-15 10:15:31 +04:00
|
|
|
//Need to check if we hit an imagemap area and if so see if we're handling
|
|
|
|
//the event on that map or on a link farther up the tree. If we're on a
|
|
|
|
//link farther up, do nothing.
|
2011-04-21 21:35:52 +04:00
|
|
|
nsCOMPtr<nsIContent> target = aVisitor.mPresContext->EventStateManager()->
|
|
|
|
GetEventTargetContent(aVisitor.mEvent);
|
2000-09-15 10:15:31 +04:00
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
return !target || !target->IsHTMLElement(nsGkAtoms::area) ||
|
|
|
|
IsHTMLElement(nsGkAtoms::area);
|
2007-04-23 11:31:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
nsGenericHTMLElement::GetEventTargetParentForAnchors(EventChainPreVisitor& aVisitor)
|
2007-04-23 11:31:21 +04:00
|
|
|
{
|
2016-10-21 05:11:07 +03:00
|
|
|
nsresult rv = nsGenericHTMLElementBase::GetEventTargetParent(aVisitor);
|
2007-04-23 11:31:21 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!CheckHandleEventForAnchorsPreconditions(aVisitor)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-10-21 05:11:07 +03:00
|
|
|
return GetEventTargetParentForLinks(aVisitor);
|
2007-04-23 11:31:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2014-03-18 08:48:20 +04:00
|
|
|
nsGenericHTMLElement::PostHandleEventForAnchors(EventChainPostVisitor& aVisitor)
|
2007-04-23 11:31:21 +04:00
|
|
|
{
|
|
|
|
if (!CheckHandleEventForAnchorsPreconditions(aVisitor)) {
|
2007-01-04 13:53:59 +03:00
|
|
|
return NS_OK;
|
2000-09-15 10:15:31 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2007-01-04 13:53:59 +03:00
|
|
|
return PostHandleEventForLinks(aVisitor);
|
|
|
|
}
|
2006-08-03 21:21:27 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-01-04 13:53:59 +03:00
|
|
|
nsGenericHTMLElement::IsHTMLLink(nsIURI** aURI) const
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(aURI, "Must provide aURI out param");
|
2000-02-11 04:24:59 +03:00
|
|
|
|
2014-03-15 23:00:15 +04:00
|
|
|
*aURI = GetHrefURIForAnchors().take();
|
2007-01-04 13:53:59 +03:00
|
|
|
// We promise out param is non-null if we return true, so base rv on it
|
2012-07-30 18:20:58 +04:00
|
|
|
return *aURI != nullptr;
|
2000-02-11 04:24:59 +03:00
|
|
|
}
|
|
|
|
|
2009-07-13 15:48:06 +04:00
|
|
|
already_AddRefed<nsIURI>
|
|
|
|
nsGenericHTMLElement::GetHrefURIForAnchors() const
|
2003-06-17 20:22:51 +04:00
|
|
|
{
|
2013-08-08 09:26:32 +04:00
|
|
|
// This is used by the three Link implementations and
|
2003-06-17 20:22:51 +04:00
|
|
|
// nsHTMLStyleElement.
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
// Get href= attribute (relative URI).
|
2003-06-17 20:22:51 +04:00
|
|
|
|
2004-11-03 22:44:59 +03:00
|
|
|
// We use the nsAttrValue's copy of the URI string to avoid copying.
|
2009-07-13 15:48:06 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2012-07-30 18:20:58 +04:00
|
|
|
GetURIAttr(nsGkAtoms::href, nullptr, getter_AddRefs(uri));
|
2003-06-17 20:22:51 +04:00
|
|
|
|
2009-07-13 15:48:06 +04:00
|
|
|
return uri.forget();
|
2003-06-17 20:22:51 +04:00
|
|
|
}
|
|
|
|
|
2017-05-31 21:01:47 +03:00
|
|
|
nsresult
|
|
|
|
nsGenericHTMLElement::BeforeSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValueOrString* aValue,
|
|
|
|
bool aNotify)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
|
|
|
if (aName == nsGkAtoms::accesskey) {
|
|
|
|
// Have to unregister before clearing flag. See UnregAccessKey
|
|
|
|
UnregAccessKey();
|
|
|
|
if (!aValue) {
|
|
|
|
UnsetFlags(NODE_HAS_ACCESSKEY);
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::name) {
|
|
|
|
// Have to do this before clearing flag. See RemoveFromNameTable
|
|
|
|
RemoveFromNameTable();
|
|
|
|
if (!aValue || aValue->IsEmpty()) {
|
|
|
|
ClearHasName();
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::contenteditable) {
|
|
|
|
if (aValue) {
|
|
|
|
// Set this before the attribute is set so that any subclass code that
|
|
|
|
// runs before the attribute is set won't think we're missing a
|
|
|
|
// contenteditable attr when we actually have one.
|
|
|
|
SetMayHaveContentEditableAttr();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!aValue && IsEventAttributeName(aName)) {
|
|
|
|
if (EventListenerManager* manager = GetExistingListenerManager()) {
|
|
|
|
manager->RemoveEventHandler(aName, EmptyString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElementBase::BeforeSetAttr(aNamespaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLElement::AfterSetAttr(int32_t aNamespaceID, nsIAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue, bool aNotify)
|
2005-10-28 06:59:38 +04:00
|
|
|
{
|
2006-07-29 04:04:40 +04:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2013-01-03 00:24:07 +04:00
|
|
|
if (IsEventAttributeName(aName) && aValue) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue->Type() == nsAttrValue::eString,
|
|
|
|
"Expected string value for script body");
|
2012-08-30 20:25:10 +04:00
|
|
|
nsresult rv = SetEventHandler(aName, aValue->GetStringValue());
|
2006-07-29 04:04:40 +04:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
else if (aNotify && aName == nsGkAtoms::spellcheck) {
|
2006-08-25 04:15:14 +04:00
|
|
|
SyncEditorsOnSubtree(this);
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
else if (aName == nsGkAtoms::dir) {
|
2012-11-21 14:13:57 +04:00
|
|
|
Directionality dir = eDir_LTR;
|
2017-06-20 06:24:59 +03:00
|
|
|
// A boolean tracking whether we need to recompute our directionality.
|
|
|
|
// This needs to happen after we update our internal "dir" attribute
|
|
|
|
// state but before we call SetDirectionalityOnDescendants.
|
|
|
|
bool recomputeDirectionality = false;
|
|
|
|
// We don't want to have to keep getting the "dir" attribute in
|
|
|
|
// IntrinsicState, so we manually recompute our dir-related event states
|
|
|
|
// here and send the relevant update notifications.
|
|
|
|
EventStates dirStates;
|
2012-11-21 14:13:57 +04:00
|
|
|
if (aValue && aValue->Type() == nsAttrValue::eEnum) {
|
2012-04-17 08:03:10 +04:00
|
|
|
SetHasValidDir();
|
2017-06-20 06:24:59 +03:00
|
|
|
dirStates |= NS_EVENT_STATE_HAS_DIR_ATTR;
|
2012-11-21 14:13:57 +04:00
|
|
|
Directionality dirValue = (Directionality)aValue->GetEnumValue();
|
|
|
|
if (dirValue == eDir_Auto) {
|
2017-06-20 06:24:59 +03:00
|
|
|
dirStates |= NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO;
|
2012-11-21 14:13:57 +04:00
|
|
|
} else {
|
|
|
|
dir = dirValue;
|
|
|
|
SetDirectionality(dir, aNotify);
|
2017-06-20 06:24:59 +03:00
|
|
|
if (dirValue == eDir_LTR) {
|
|
|
|
dirStates |= NS_EVENT_STATE_DIR_ATTR_LTR;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(dirValue == eDir_RTL);
|
|
|
|
dirStates |= NS_EVENT_STATE_DIR_ATTR_RTL;
|
|
|
|
}
|
2012-11-21 14:13:57 +04:00
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
} else {
|
2017-06-20 06:24:59 +03:00
|
|
|
if (aValue) {
|
|
|
|
// We have a value, just not a valid one.
|
|
|
|
dirStates |= NS_EVENT_STATE_HAS_DIR_ATTR;
|
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
ClearHasValidDir();
|
2012-11-21 14:13:57 +04:00
|
|
|
if (NodeInfo()->Equals(nsGkAtoms::bdi)) {
|
2017-06-20 06:24:59 +03:00
|
|
|
dirStates |= NS_EVENT_STATE_DIR_ATTR_LIKE_AUTO;
|
2012-11-21 14:13:57 +04:00
|
|
|
} else {
|
2017-06-20 06:24:59 +03:00
|
|
|
recomputeDirectionality = true;
|
2012-11-21 14:13:57 +04:00
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
}
|
2017-06-20 06:24:59 +03:00
|
|
|
// Now figure out what's changed about our dir states.
|
|
|
|
EventStates oldDirStates = State() & DIR_ATTR_STATES;
|
|
|
|
EventStates changedStates = dirStates ^ oldDirStates;
|
|
|
|
ToggleStates(changedStates, aNotify);
|
|
|
|
if (recomputeDirectionality) {
|
|
|
|
dir = RecomputeDirectionality(this, aNotify);
|
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
SetDirectionalityOnDescendants(this, dir, aNotify);
|
2017-05-31 21:01:47 +03:00
|
|
|
} else if (aName == nsGkAtoms::contenteditable) {
|
|
|
|
int32_t editableCountDelta = 0;
|
|
|
|
if (aOldValue &&
|
|
|
|
(aOldValue->Equals(NS_LITERAL_STRING("true"), eIgnoreCase) ||
|
|
|
|
aOldValue->Equals(EmptyString(), eIgnoreCase))) {
|
|
|
|
editableCountDelta = -1;
|
|
|
|
}
|
|
|
|
if (aValue && (aValue->Equals(NS_LITERAL_STRING("true"), eIgnoreCase) ||
|
|
|
|
aValue->Equals(EmptyString(), eIgnoreCase))) {
|
|
|
|
++editableCountDelta;
|
|
|
|
}
|
|
|
|
ChangeEditableState(editableCountDelta);
|
|
|
|
} else if (aName == nsGkAtoms::accesskey) {
|
|
|
|
if (aValue && !aValue->Equals(EmptyString(), eIgnoreCase)) {
|
|
|
|
SetFlags(NODE_HAS_ACCESSKEY);
|
|
|
|
RegAccessKey();
|
|
|
|
}
|
|
|
|
} else if (aName == nsGkAtoms::name) {
|
2017-07-26 09:33:00 +03:00
|
|
|
if (aValue && !aValue->Equals(EmptyString(), eIgnoreCase)) {
|
2017-05-31 21:01:47 +03:00
|
|
|
// This may not be quite right because we can have subclass code run
|
|
|
|
// before here. But in practice subclasses don't care about this flag,
|
|
|
|
// and in particular selector matching does not care. Otherwise we'd
|
|
|
|
// want to handle it like we handle id attributes (in PreIdMaybeChange
|
|
|
|
// and PostIdMaybeChange).
|
|
|
|
SetHasName();
|
2017-07-26 09:33:00 +03:00
|
|
|
if (CanHaveName(NodeInfo()->NameAtom())) {
|
|
|
|
AddToNameTable(aValue->GetAtomValue());
|
|
|
|
}
|
2017-05-31 21:01:47 +03:00
|
|
|
}
|
2012-04-17 08:03:10 +04:00
|
|
|
}
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
return nsGenericHTMLElementBase::AfterSetAttr(aNamespaceID, aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
aValue, aOldValue, aNotify);
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
|
|
|
|
2014-03-17 10:56:53 +04:00
|
|
|
EventListenerManager*
|
2011-09-28 19:54:50 +04:00
|
|
|
nsGenericHTMLElement::GetEventListenerManagerForAttr(nsIAtom* aAttrName,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool* aDefer)
|
2005-10-28 06:59:38 +04:00
|
|
|
{
|
|
|
|
// Attributes on the body and frameset tags get set on the global object
|
2011-09-28 19:54:50 +04:00
|
|
|
if ((mNodeInfo->Equals(nsGkAtoms::body) ||
|
|
|
|
mNodeInfo->Equals(nsGkAtoms::frameset)) &&
|
|
|
|
// We only forward some event attributes from body/frameset to window
|
|
|
|
(0
|
|
|
|
#define EVENT(name_, id_, type_, struct_) /* nothing */
|
|
|
|
#define FORWARDED_EVENT(name_, id_, type_, struct_) \
|
|
|
|
|| nsGkAtoms::on##name_ == aAttrName
|
|
|
|
#define WINDOW_EVENT FORWARDED_EVENT
|
2014-04-01 15:42:12 +04:00
|
|
|
#include "mozilla/EventNameList.h" // IWYU pragma: keep
|
2011-09-28 19:54:50 +04:00
|
|
|
#undef WINDOW_EVENT
|
|
|
|
#undef FORWARDED_EVENT
|
|
|
|
#undef EVENT
|
|
|
|
)
|
|
|
|
) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner *win;
|
2005-10-28 06:59:38 +04:00
|
|
|
|
2005-11-29 04:34:37 +03:00
|
|
|
// If we have a document, and it has a window, add the event
|
|
|
|
// listener on the window (the inner window). If not, proceed as
|
|
|
|
// normal.
|
2014-10-02 23:07:24 +04:00
|
|
|
// XXXbz sXBL/XBL2 issue: should we instead use GetComposedDoc() here,
|
2005-10-28 06:59:38 +04:00
|
|
|
// override BindToTree for those classes and munge event listeners there?
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument *document = OwnerDoc();
|
2008-05-04 08:29:12 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aDefer = false;
|
2013-04-29 19:34:16 +04:00
|
|
|
if ((win = document->GetInnerWindow())) {
|
2013-04-06 04:44:15 +04:00
|
|
|
nsCOMPtr<EventTarget> piTarget(do_QueryInterface(win));
|
2005-10-28 06:59:38 +04:00
|
|
|
|
2013-10-23 03:32:04 +04:00
|
|
|
return piTarget->GetOrCreateListenerManager();
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
|
|
|
|
2011-09-28 19:54:50 +04:00
|
|
|
return nsGenericHTMLElementBase::GetEventListenerManagerForAttr(aAttrName,
|
|
|
|
aDefer);
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
|
|
|
|
2012-11-26 18:19:02 +04:00
|
|
|
#define EVENT(name_, id_, type_, struct_) /* nothing; handled by nsINode */
|
|
|
|
#define FORWARDED_EVENT(name_, id_, type_, struct_) \
|
|
|
|
EventHandlerNonNull* \
|
|
|
|
nsGenericHTMLElement::GetOn##name_() \
|
|
|
|
{ \
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset)) { \
|
2012-11-26 18:19:02 +04:00
|
|
|
/* XXXbz note to self: add tests for this! */ \
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow()) { \
|
|
|
|
nsGlobalWindow* globalWin = nsGlobalWindow::Cast(win); \
|
2012-11-26 18:19:02 +04:00
|
|
|
return globalWin->GetOn##name_(); \
|
|
|
|
} \
|
|
|
|
return nullptr; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
return nsINode::GetOn##name_(); \
|
|
|
|
} \
|
|
|
|
void \
|
2013-09-17 15:01:28 +04:00
|
|
|
nsGenericHTMLElement::SetOn##name_(EventHandlerNonNull* handler) \
|
2012-11-26 18:19:02 +04:00
|
|
|
{ \
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset)) { \
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow(); \
|
2013-04-29 19:34:16 +04:00
|
|
|
if (!win) { \
|
2012-11-26 18:19:02 +04:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
\
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* globalWin = nsGlobalWindow::Cast(win); \
|
2013-09-17 15:01:28 +04:00
|
|
|
return globalWin->SetOn##name_(handler); \
|
2012-11-26 18:19:02 +04:00
|
|
|
} \
|
|
|
|
\
|
2013-09-17 15:01:28 +04:00
|
|
|
return nsINode::SetOn##name_(handler); \
|
2012-11-26 18:19:02 +04:00
|
|
|
}
|
|
|
|
#define ERROR_EVENT(name_, id_, type_, struct_) \
|
|
|
|
already_AddRefed<EventHandlerNonNull> \
|
|
|
|
nsGenericHTMLElement::GetOn##name_() \
|
|
|
|
{ \
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset)) { \
|
2012-11-26 18:19:02 +04:00
|
|
|
/* XXXbz note to self: add tests for this! */ \
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow()) { \
|
|
|
|
nsGlobalWindow* globalWin = nsGlobalWindow::Cast(win); \
|
2012-11-26 18:19:02 +04:00
|
|
|
OnErrorEventHandlerNonNull* errorHandler = globalWin->GetOn##name_(); \
|
|
|
|
if (errorHandler) { \
|
2016-01-30 20:05:36 +03:00
|
|
|
RefPtr<EventHandlerNonNull> handler = \
|
2012-11-26 18:19:02 +04:00
|
|
|
new EventHandlerNonNull(errorHandler); \
|
|
|
|
return handler.forget(); \
|
|
|
|
} \
|
|
|
|
} \
|
|
|
|
return nullptr; \
|
|
|
|
} \
|
|
|
|
\
|
2016-01-30 20:05:36 +03:00
|
|
|
RefPtr<EventHandlerNonNull> handler = nsINode::GetOn##name_(); \
|
2012-11-26 18:19:02 +04:00
|
|
|
return handler.forget(); \
|
|
|
|
} \
|
|
|
|
void \
|
2013-09-17 15:01:28 +04:00
|
|
|
nsGenericHTMLElement::SetOn##name_(EventHandlerNonNull* handler) \
|
2012-11-26 18:19:02 +04:00
|
|
|
{ \
|
2015-03-03 14:09:00 +03:00
|
|
|
if (IsAnyOfHTMLElements(nsGkAtoms::body, nsGkAtoms::frameset)) { \
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowInner* win = OwnerDoc()->GetInnerWindow(); \
|
2013-04-29 19:34:16 +04:00
|
|
|
if (!win) { \
|
2012-11-26 18:19:02 +04:00
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
\
|
2016-01-30 20:05:36 +03:00
|
|
|
nsGlobalWindow* globalWin = nsGlobalWindow::Cast(win); \
|
|
|
|
RefPtr<OnErrorEventHandlerNonNull> errorHandler; \
|
2012-12-10 23:31:25 +04:00
|
|
|
if (handler) { \
|
|
|
|
errorHandler = new OnErrorEventHandlerNonNull(handler); \
|
|
|
|
} \
|
2013-09-17 15:01:28 +04:00
|
|
|
return globalWin->SetOn##name_(errorHandler); \
|
2012-11-26 18:19:02 +04:00
|
|
|
} \
|
|
|
|
\
|
2013-09-17 15:01:28 +04:00
|
|
|
return nsINode::SetOn##name_(handler); \
|
2012-11-26 18:19:02 +04:00
|
|
|
}
|
2014-04-01 15:42:12 +04:00
|
|
|
#include "mozilla/EventNameList.h" // IWYU pragma: keep
|
2012-11-26 18:19:02 +04:00
|
|
|
#undef ERROR_EVENT
|
|
|
|
#undef FORWARDED_EVENT
|
|
|
|
#undef EVENT
|
|
|
|
|
2004-02-20 22:00:43 +03:00
|
|
|
void
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::GetBaseTarget(nsAString& aBaseTarget) const
|
1999-01-15 04:59:42 +03:00
|
|
|
{
|
2011-10-18 15:19:44 +04:00
|
|
|
OwnerDoc()->GetBaseTarget(aBaseTarget);
|
1999-01-15 04:59:42 +03:00
|
|
|
}
|
|
|
|
|
1998-08-29 03:27:19 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLElement::ParseAttribute(int32_t aNamespaceID,
|
2005-11-29 19:37:15 +03:00
|
|
|
nsIAtom* aAttribute,
|
2004-03-04 05:06:28 +03:00
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
2004-01-26 22:22:05 +03:00
|
|
|
{
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::dir) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aValue, kDirTable, false);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::tabindex) {
|
2014-05-20 00:37:59 +04:00
|
|
|
return aResult.ParseIntValue(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2004-07-07 04:58:57 +04:00
|
|
|
|
2015-12-01 03:13:03 +03:00
|
|
|
if (aAttribute == nsGkAtoms::referrerpolicy) {
|
2015-06-06 01:25:24 +03:00
|
|
|
return ParseReferrerAttribute(aValue, aResult);
|
|
|
|
}
|
|
|
|
|
2010-06-04 05:09:20 +04:00
|
|
|
if (aAttribute == nsGkAtoms::name) {
|
2005-11-29 19:37:15 +03:00
|
|
|
// Store name as an atom. name="" means that the element has no name,
|
2017-05-31 21:01:47 +03:00
|
|
|
// not that it has an empty string as the name.
|
2010-06-04 05:09:20 +04:00
|
|
|
if (aValue.IsEmpty()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-06-04 05:09:20 +04:00
|
|
|
}
|
2005-11-29 19:37:15 +03:00
|
|
|
aResult.ParseAtom(aValue);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
|
|
|
if (aAttribute == nsGkAtoms::contenteditable) {
|
|
|
|
aResult.ParseAtom(aValue);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2012-06-05 03:49:57 +04:00
|
|
|
|
2016-05-21 06:13:17 +03:00
|
|
|
if (aAttribute == nsGkAtoms::rel) {
|
2012-06-05 03:49:57 +04:00
|
|
|
aResult.ParseAtomArray(aValue);
|
|
|
|
return true;
|
|
|
|
}
|
2005-11-16 05:55:29 +03:00
|
|
|
}
|
|
|
|
|
2007-08-06 19:27:19 +04:00
|
|
|
return nsGenericHTMLElementBase::ParseAttribute(aNamespaceID, aAttribute,
|
|
|
|
aValue, aResult);
|
2004-01-26 22:22:05 +03:00
|
|
|
}
|
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLElement::ParseBackgroundAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
if (aNamespaceID == kNameSpaceID_None &&
|
2012-09-04 19:53:11 +04:00
|
|
|
aAttribute == nsGkAtoms::background &&
|
|
|
|
!aValue.IsEmpty()) {
|
2012-08-24 21:50:49 +04:00
|
|
|
// Resolve url to an absolute url
|
|
|
|
nsIDocument* doc = OwnerDoc();
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
|
|
|
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(
|
|
|
|
getter_AddRefs(uri), aValue, doc, baseURI);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
mozilla::css::URLValue *url =
|
2017-04-14 01:18:25 +03:00
|
|
|
new mozilla::css::URLValue(uri, aValue, baseURI, doc->GetDocumentURI(),
|
2012-12-07 00:21:19 +04:00
|
|
|
NodePrincipal());
|
2012-08-24 21:50:49 +04:00
|
|
|
aResult.SetTo(url, &aValue);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2004-02-26 00:04:50 +03:00
|
|
|
nsGenericHTMLElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
2000-12-23 13:56:31 +03:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
sCommonAttributeMap
|
|
|
|
};
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
|
|
|
nsGenericHTMLElement::GetAttributeMappingFunction() const
|
2000-12-23 13:56:31 +03:00
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapCommonAttributesInto;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2006-06-12 20:14:31 +04:00
|
|
|
nsIFormControlFrame*
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLElement::GetFormControlFrame(bool aFlushFrames)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
2014-08-06 03:23:02 +04:00
|
|
|
if (aFlushFrames && IsInComposedDoc()) {
|
2009-04-22 03:53:52 +04:00
|
|
|
// Cause a flush of the frames, so we get up-to-date frame information
|
2017-01-05 10:31:56 +03:00
|
|
|
GetComposedDoc()->FlushPendingNotifications(FlushType::Frames);
|
2001-12-12 10:31:15 +03:00
|
|
|
}
|
2009-12-25 00:20:05 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2002-05-16 22:26:05 +04:00
|
|
|
if (frame) {
|
2009-01-12 22:20:59 +03:00
|
|
|
nsIFormControlFrame* form_frame = do_QueryFrame(frame);
|
2003-12-20 15:15:48 +03:00
|
|
|
if (form_frame) {
|
|
|
|
return form_frame;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we have generated content, the primary frame will be a
|
2003-12-20 15:19:41 +03:00
|
|
|
// wrapper frame.. out real frame will be in its child list.
|
2016-01-29 17:42:14 +03:00
|
|
|
for (frame = frame->PrincipalChildList().FirstChild();
|
2003-12-20 15:15:48 +03:00
|
|
|
frame;
|
|
|
|
frame = frame->GetNextSibling()) {
|
2009-01-12 22:20:59 +03:00
|
|
|
form_frame = do_QueryFrame(frame);
|
2003-12-20 15:15:48 +03:00
|
|
|
if (form_frame) {
|
|
|
|
return form_frame;
|
|
|
|
}
|
|
|
|
}
|
1999-10-26 08:44:41 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
1999-10-26 08:44:41 +04:00
|
|
|
|
2004-08-21 00:34:37 +04:00
|
|
|
nsPresContext*
|
2014-08-23 00:11:27 +04:00
|
|
|
nsGenericHTMLElement::GetPresContext(PresContextFor aFor)
|
1999-10-26 08:44:41 +04:00
|
|
|
{
|
2003-06-14 00:10:01 +04:00
|
|
|
// Get the document
|
2014-08-23 00:11:27 +04:00
|
|
|
nsIDocument* doc = (aFor == eForComposedDoc) ?
|
|
|
|
GetComposedDoc() : GetUncomposedDoc();
|
2003-06-14 00:10:01 +04:00
|
|
|
if (doc) {
|
2011-11-16 11:50:19 +04:00
|
|
|
// Get presentation shell.
|
2010-06-25 17:59:57 +04:00
|
|
|
nsIPresShell *presShell = doc->GetShell();
|
2003-06-14 00:10:01 +04:00
|
|
|
if (presShell) {
|
2004-08-21 00:34:37 +04:00
|
|
|
return presShell->GetPresContext();
|
1999-02-01 21:44:59 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kDivAlignTable[] = {
|
2005-06-16 03:45:06 +04:00
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_MOZ_LEFT },
|
1999-03-25 06:48:06 +03:00
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
|
|
|
|
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
|
|
|
|
{ "middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
|
|
|
|
{ "justify", NS_STYLE_TEXT_ALIGN_JUSTIFY },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1999-03-25 06:48:06 +03:00
|
|
|
};
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kFrameborderTable[] = {
|
1998-09-10 03:30:30 +04:00
|
|
|
{ "yes", NS_STYLE_FRAME_YES },
|
|
|
|
{ "no", NS_STYLE_FRAME_NO },
|
|
|
|
{ "1", NS_STYLE_FRAME_1 },
|
|
|
|
{ "0", NS_STYLE_FRAME_0 },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1998-09-10 03:30:30 +04:00
|
|
|
};
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kScrollingTable[] = {
|
1998-09-10 03:30:30 +04:00
|
|
|
{ "yes", NS_STYLE_FRAME_YES },
|
|
|
|
{ "no", NS_STYLE_FRAME_NO },
|
|
|
|
{ "on", NS_STYLE_FRAME_ON },
|
|
|
|
{ "off", NS_STYLE_FRAME_OFF },
|
|
|
|
{ "scroll", NS_STYLE_FRAME_SCROLL },
|
|
|
|
{ "noscroll", NS_STYLE_FRAME_NOSCROLL },
|
|
|
|
{ "auto", NS_STYLE_FRAME_AUTO },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1998-09-10 03:30:30 +04:00
|
|
|
};
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kTableVAlignTable[] = {
|
1998-09-15 21:58:24 +04:00
|
|
|
{ "top", NS_STYLE_VERTICAL_ALIGN_TOP },
|
|
|
|
{ "middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE },
|
|
|
|
{ "bottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM },
|
|
|
|
{ "baseline",NS_STYLE_VERTICAL_ALIGN_BASELINE },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1998-09-15 21:58:24 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseAlignValue(const nsAString& aString,
|
2004-03-04 05:06:28 +03:00
|
|
|
nsAttrValue& aResult)
|
1998-09-01 05:36:11 +04:00
|
|
|
{
|
2013-11-19 23:21:29 +04:00
|
|
|
static const nsAttrValue::EnumTable kAlignTable[] = {
|
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
|
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
|
|
|
|
|
|
|
|
{ "top", NS_STYLE_VERTICAL_ALIGN_TOP },
|
|
|
|
{ "middle", NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE },
|
|
|
|
{ "bottom", NS_STYLE_VERTICAL_ALIGN_BASELINE },
|
|
|
|
|
|
|
|
{ "center", NS_STYLE_VERTICAL_ALIGN_MIDDLE_WITH_BASELINE },
|
|
|
|
{ "baseline", NS_STYLE_VERTICAL_ALIGN_BASELINE },
|
|
|
|
|
|
|
|
{ "texttop", NS_STYLE_VERTICAL_ALIGN_TEXT_TOP },
|
|
|
|
{ "absmiddle", NS_STYLE_VERTICAL_ALIGN_MIDDLE },
|
|
|
|
{ "abscenter", NS_STYLE_VERTICAL_ALIGN_MIDDLE },
|
|
|
|
{ "absbottom", NS_STYLE_VERTICAL_ALIGN_BOTTOM },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
2013-11-19 23:21:29 +04:00
|
|
|
};
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kAlignTable, false);
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
|
|
|
|
1999-09-21 04:12:09 +04:00
|
|
|
//----------------------------------------
|
|
|
|
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kTableHAlignTable[] = {
|
1999-09-21 04:12:09 +04:00
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_LEFT },
|
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_RIGHT },
|
|
|
|
{ "center", NS_STYLE_TEXT_ALIGN_CENTER },
|
|
|
|
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
|
|
|
|
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1999-09-21 04:12:09 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseTableHAlignValue(const nsAString& aString,
|
2010-06-11 22:47:56 +04:00
|
|
|
nsAttrValue& aResult)
|
1999-09-21 04:12:09 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kTableHAlignTable, false);
|
1999-09-21 04:12:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------
|
|
|
|
|
2010-07-31 03:48:57 +04:00
|
|
|
// This table is used for td, th, tr, col, thead, tbody and tfoot.
|
2005-01-25 03:02:58 +03:00
|
|
|
static const nsAttrValue::EnumTable kTableCellHAlignTable[] = {
|
2005-06-16 03:45:06 +04:00
|
|
|
{ "left", NS_STYLE_TEXT_ALIGN_MOZ_LEFT },
|
2000-07-28 03:37:44 +04:00
|
|
|
{ "right", NS_STYLE_TEXT_ALIGN_MOZ_RIGHT },
|
|
|
|
{ "center", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
|
|
|
|
{ "char", NS_STYLE_TEXT_ALIGN_CHAR },
|
|
|
|
{ "justify",NS_STYLE_TEXT_ALIGN_JUSTIFY },
|
2000-02-16 04:08:54 +03:00
|
|
|
{ "middle", NS_STYLE_TEXT_ALIGN_MOZ_CENTER },
|
2000-07-06 17:42:57 +04:00
|
|
|
{ "absmiddle", NS_STYLE_TEXT_ALIGN_CENTER },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
1999-09-21 04:12:09 +04:00
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseTableCellHAlignValue(const nsAString& aString,
|
2010-07-31 03:48:57 +04:00
|
|
|
nsAttrValue& aResult)
|
1998-09-15 21:58:24 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kTableCellHAlignTable, false);
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
1999-09-21 04:12:09 +04:00
|
|
|
//----------------------------------------
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseTableVAlignValue(const nsAString& aString,
|
2004-03-04 05:06:28 +03:00
|
|
|
nsAttrValue& aResult)
|
1998-09-15 21:58:24 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kTableVAlignTable, false);
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseDivAlignValue(const nsAString& aString,
|
2010-07-06 08:25:52 +04:00
|
|
|
nsAttrValue& aResult)
|
1998-09-04 02:21:32 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kDivAlignTable, false);
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
1998-09-04 02:21:32 +04:00
|
|
|
nsGenericHTMLElement::ParseImageAttribute(nsIAtom* aAttribute,
|
2002-03-24 02:13:20 +03:00
|
|
|
const nsAString& aString,
|
2004-03-04 05:06:28 +03:00
|
|
|
nsAttrValue& aResult)
|
1998-09-01 05:36:11 +04:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
if ((aAttribute == nsGkAtoms::width) ||
|
|
|
|
(aAttribute == nsGkAtoms::height)) {
|
2011-02-04 22:46:16 +03:00
|
|
|
return aResult.ParseSpecialIntValue(aString);
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
if ((aAttribute == nsGkAtoms::hspace) ||
|
|
|
|
(aAttribute == nsGkAtoms::vspace) ||
|
|
|
|
(aAttribute == nsGkAtoms::border)) {
|
2004-03-04 05:06:28 +03:00
|
|
|
return aResult.ParseIntWithBounds(aString, 0);
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
|
|
|
|
2015-06-06 01:25:24 +03:00
|
|
|
bool
|
|
|
|
nsGenericHTMLElement::ParseReferrerAttribute(const nsAString& aString,
|
|
|
|
nsAttrValue& aResult)
|
|
|
|
{
|
|
|
|
static const nsAttrValue::EnumTable kReferrerTable[] = {
|
2016-09-07 05:20:17 +03:00
|
|
|
{ net::kRPS_No_Referrer, static_cast<int16_t>(net::RP_No_Referrer) },
|
|
|
|
{ net::kRPS_Origin, static_cast<int16_t>(net::RP_Origin) },
|
|
|
|
{ net::kRPS_Origin_When_Cross_Origin, static_cast<int16_t>(net::RP_Origin_When_Crossorigin) },
|
|
|
|
{ net::kRPS_No_Referrer_When_Downgrade, static_cast<int16_t>(net::RP_No_Referrer_When_Downgrade) },
|
|
|
|
{ net::kRPS_Unsafe_URL, static_cast<int16_t>(net::RP_Unsafe_URL) },
|
2016-09-23 02:27:42 +03:00
|
|
|
{ net::kRPS_Strict_Origin, static_cast<int16_t>(net::RP_Strict_Origin) },
|
|
|
|
{ net::kRPS_Same_Origin, static_cast<int16_t>(net::RP_Same_Origin) },
|
|
|
|
{ net::kRPS_Strict_Origin_When_Cross_Origin, static_cast<int16_t>(net::RP_Strict_Origin_When_Cross_Origin) },
|
2016-09-07 05:20:17 +03:00
|
|
|
{ nullptr, 0 }
|
2015-06-06 01:25:24 +03:00
|
|
|
};
|
|
|
|
return aResult.ParseEnumValue(aString, kReferrerTable, false);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseFrameborderValue(const nsAString& aString,
|
2004-03-04 05:06:28 +03:00
|
|
|
nsAttrValue& aResult)
|
1998-09-10 03:30:30 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kFrameborderTable, false);
|
1998-09-10 03:30:30 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2002-03-24 02:13:20 +03:00
|
|
|
nsGenericHTMLElement::ParseScrollingValue(const nsAString& aString,
|
2004-03-04 05:06:28 +03:00
|
|
|
nsAttrValue& aResult)
|
1998-09-10 03:30:30 +04:00
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return aResult.ParseEnumValue(aString, kScrollingTable, false);
|
1998-09-10 03:30:30 +04:00
|
|
|
}
|
|
|
|
|
2015-12-07 19:12:44 +03:00
|
|
|
static inline void
|
2017-01-27 03:51:01 +03:00
|
|
|
MapLangAttributeInto(const nsMappedAttributes* aAttributes, GenericSpecifiedValues* aData)
|
2015-12-07 19:12:44 +03:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Font) |
|
|
|
|
NS_STYLE_INHERIT_BIT(Text))) {
|
2015-12-07 19:12:44 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const nsAttrValue* langValue = aAttributes->GetAttr(nsGkAtoms::lang);
|
2017-06-15 22:48:26 +03:00
|
|
|
if (!langValue) {
|
2015-12-07 19:12:44 +03:00
|
|
|
return;
|
|
|
|
}
|
2017-06-15 22:48:26 +03:00
|
|
|
MOZ_ASSERT(langValue->Type() == nsAttrValue::eAtom);
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Font))) {
|
2017-06-17 03:27:59 +03:00
|
|
|
aData->SetIdentAtomValueIfUnset(eCSSProperty__x_lang,
|
|
|
|
langValue->GetAtomValue());
|
2015-12-07 19:12:44 +03:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Text))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_text_emphasis_position)) {
|
2017-06-15 22:48:26 +03:00
|
|
|
const nsIAtom* lang = langValue->GetAtomValue();
|
2016-07-21 08:03:25 +03:00
|
|
|
if (nsStyleUtil::MatchesLanguagePrefix(lang, u"zh")) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_text_emphasis_position,
|
|
|
|
NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT_ZH);
|
2016-07-21 08:03:25 +03:00
|
|
|
} else if (nsStyleUtil::MatchesLanguagePrefix(lang, u"ja") ||
|
|
|
|
nsStyleUtil::MatchesLanguagePrefix(lang, u"mn")) {
|
2015-12-07 19:12:44 +03:00
|
|
|
// This branch is currently no part of the spec.
|
|
|
|
// See bug 1040668 comment 69 and comment 75.
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_text_emphasis_position,
|
|
|
|
NS_STYLE_TEXT_EMPHASIS_POSITION_DEFAULT);
|
2015-12-07 19:12:44 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
/**
|
|
|
|
* Handle attributes common to all html elements
|
|
|
|
*/
|
|
|
|
void
|
2013-07-11 18:39:18 +04:00
|
|
|
nsGenericHTMLElement::MapCommonAttributesIntoExceptHidden(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(UserInterface))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty__moz_user_modify)) {
|
2007-06-28 06:48:16 +04:00
|
|
|
const nsAttrValue* value =
|
|
|
|
aAttributes->GetAttr(nsGkAtoms::contenteditable);
|
|
|
|
if (value) {
|
|
|
|
if (value->Equals(nsGkAtoms::_empty, eCaseMatters) ||
|
|
|
|
value->Equals(nsGkAtoms::_true, eIgnoreCase)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty__moz_user_modify,
|
|
|
|
StyleUserModify::ReadWrite);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
2008-10-10 20:09:37 +04:00
|
|
|
else if (value->Equals(nsGkAtoms::_false, eIgnoreCase)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty__moz_user_modify,
|
|
|
|
StyleUserModify::ReadOnly);
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-02 07:07:07 +04:00
|
|
|
|
2015-12-07 19:12:44 +03:00
|
|
|
MapLangAttributeInto(aAttributes, aData);
|
2013-07-11 18:39:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2013-07-11 18:39:18 +04:00
|
|
|
{
|
|
|
|
MapCommonAttributesIntoExceptHidden(aAttributes, aData);
|
2010-08-02 07:07:07 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Display))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_display)) {
|
2012-07-14 03:29:14 +04:00
|
|
|
if (aAttributes->IndexOfAttr(nsGkAtoms::hidden) >= 0) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_display, StyleDisplay::None);
|
2010-08-02 07:07:07 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
/* static */ const nsGenericHTMLElement::MappedAttributeEntry
|
2003-04-17 00:54:20 +04:00
|
|
|
nsGenericHTMLElement::sCommonAttributeMap[] = {
|
2007-06-28 06:48:16 +04:00
|
|
|
{ &nsGkAtoms::contenteditable },
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::lang },
|
2010-08-02 07:07:07 +04:00
|
|
|
{ &nsGkAtoms::hidden },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2003-07-12 01:16:12 +04:00
|
|
|
nsGenericHTMLElement::sImageMarginSizeAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
|
|
|
{ &nsGkAtoms::hspace },
|
|
|
|
{ &nsGkAtoms::vspace },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2003-04-17 00:54:20 +04:00
|
|
|
nsGenericHTMLElement::sImageAlignAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::align },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2003-07-12 01:16:12 +04:00
|
|
|
nsGenericHTMLElement::sDivAlignAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::align },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2003-07-12 01:16:12 +04:00
|
|
|
nsGenericHTMLElement::sImageBorderAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::border },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-07-12 01:16:12 +04:00
|
|
|
};
|
2003-04-17 00:54:20 +04:00
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2003-04-17 00:54:20 +04:00
|
|
|
nsGenericHTMLElement::sBackgroundAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::background },
|
|
|
|
{ &nsGkAtoms::bgcolor },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2003-04-17 00:54:20 +04:00
|
|
|
};
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
/* static */ const Element::MappedAttributeEntry
|
2005-10-27 00:23:56 +04:00
|
|
|
nsGenericHTMLElement::sBackgroundColorAttributeMap[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::bgcolor },
|
2012-07-30 18:20:58 +04:00
|
|
|
{ nullptr }
|
2005-10-27 00:23:56 +04:00
|
|
|
};
|
|
|
|
|
1998-09-01 05:36:11 +04:00
|
|
|
void
|
2004-01-26 22:22:05 +03:00
|
|
|
nsGenericHTMLElement::MapImageAlignAttributeInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-01 05:36:11 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Display))) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t align = value->GetEnumValue();
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_float_)) {
|
2016-04-12 08:52:41 +03:00
|
|
|
if (align == NS_STYLE_TEXT_ALIGN_LEFT) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_float_, StyleFloat::Left);
|
2016-04-12 08:52:41 +03:00
|
|
|
} else if (align == NS_STYLE_TEXT_ALIGN_RIGHT) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_float_, StyleFloat::Right);
|
2011-03-18 06:14:31 +03:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_vertical_align)) {
|
2016-04-12 08:52:41 +03:00
|
|
|
switch (align) {
|
|
|
|
case NS_STYLE_TEXT_ALIGN_LEFT:
|
|
|
|
case NS_STYLE_TEXT_ALIGN_RIGHT:
|
|
|
|
break;
|
|
|
|
default:
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_vertical_align, align);
|
2016-04-12 08:52:41 +03:00
|
|
|
break;
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
}
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-26 12:18:42 +04:00
|
|
|
void
|
2004-01-26 22:22:05 +03:00
|
|
|
nsGenericHTMLElement::MapDivAlignAttributeInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2002-09-26 12:18:42 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Text))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_text_align)) {
|
2002-09-26 12:18:42 +04:00
|
|
|
// align: enum
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eEnum)
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetKeywordValue(eCSSProperty_text_align, value->GetEnumValue());
|
2002-09-26 12:18:42 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapVAlignAttributeInto(const nsMappedAttributes* aAttributes,
|
|
|
|
GenericSpecifiedValues* aData)
|
|
|
|
{
|
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Display))) {
|
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_vertical_align)) {
|
|
|
|
// align: enum
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::valign);
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum)
|
|
|
|
aData->SetKeywordValue(eCSSProperty_vertical_align, value->GetEnumValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1998-09-01 05:36:11 +04:00
|
|
|
|
1999-07-07 05:24:40 +04:00
|
|
|
void
|
2004-01-26 22:22:05 +03:00
|
|
|
nsGenericHTMLElement::MapImageMarginAttributeInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Margin)))
|
2001-06-01 02:19:43 +04:00
|
|
|
return;
|
|
|
|
|
2004-04-13 20:45:59 +04:00
|
|
|
const nsAttrValue* value;
|
1998-09-01 05:36:11 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// hspace: value
|
2006-12-26 20:47:52 +03:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::hspace);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value) {
|
2017-01-27 03:51:01 +03:00
|
|
|
if (value->Type() == nsAttrValue::eInteger) {
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
} else if (value->Type() == nsAttrValue::ePercent) {
|
|
|
|
aData->SetPercentValueIfUnset(eCSSProperty_margin_left,
|
|
|
|
value->GetPercentValue());
|
|
|
|
aData->SetPercentValueIfUnset(eCSSProperty_margin_right,
|
|
|
|
value->GetPercentValue());
|
2004-04-13 20:45:59 +04:00
|
|
|
}
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
|
|
|
|
// vspace: value
|
2006-12-26 20:47:52 +03:00
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vspace);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value) {
|
2017-01-27 03:51:01 +03:00
|
|
|
if (value->Type() == nsAttrValue::eInteger) {
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
} else if (value->Type() == nsAttrValue::ePercent) {
|
|
|
|
aData->SetPercentValueIfUnset(eCSSProperty_margin_top,
|
|
|
|
value->GetPercentValue());
|
|
|
|
aData->SetPercentValueIfUnset(eCSSProperty_margin_bottom,
|
|
|
|
value->GetPercentValue());
|
2004-04-13 20:45:59 +04:00
|
|
|
}
|
1999-07-24 23:55:35 +04:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
1999-07-07 05:24:40 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLElement::MapWidthAttributeInto(const nsMappedAttributes* aAttributes,
|
|
|
|
GenericSpecifiedValues* aData)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position))) {
|
2001-06-01 02:19:43 +04:00
|
|
|
return;
|
2017-01-27 03:51:01 +03:00
|
|
|
}
|
1999-07-07 05:24:40 +04:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// width: value
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_width)) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::width);
|
2017-01-27 03:51:01 +03:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
aData->SetPixelValue(eCSSProperty_width,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
} else if (value && value->Type() == nsAttrValue::ePercent) {
|
|
|
|
aData->SetPercentValue(eCSSProperty_width,
|
|
|
|
value->GetPercentValue());
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapHeightAttributeInto(const nsMappedAttributes* aAttributes,
|
|
|
|
GenericSpecifiedValues* aData)
|
|
|
|
{
|
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Position)))
|
|
|
|
return;
|
2001-02-07 12:57:26 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// height: value
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_height)) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::height);
|
2017-01-27 03:51:01 +03:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
aData->SetPixelValue(eCSSProperty_height,
|
|
|
|
(float)value->GetIntegerValue());
|
|
|
|
} else if (value && value->Type() == nsAttrValue::ePercent) {
|
|
|
|
aData->SetPercentValue(eCSSProperty_height,
|
|
|
|
value->GetPercentValue());
|
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(const nsMappedAttributes* aAttributes,
|
|
|
|
GenericSpecifiedValues* aData)
|
|
|
|
{
|
|
|
|
nsGenericHTMLElement::MapWidthAttributeInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapHeightAttributeInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
void
|
2004-01-26 22:22:05 +03:00
|
|
|
nsGenericHTMLElement::MapImageBorderAttributeInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2001-06-01 02:19:43 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!(aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border))))
|
2001-06-01 02:19:43 +04:00
|
|
|
return;
|
1998-12-07 21:55:19 +03:00
|
|
|
|
2001-06-01 02:19:43 +04:00
|
|
|
// border: pixels
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::border);
|
2004-04-13 20:45:59 +04:00
|
|
|
if (!value)
|
2001-06-01 02:19:43 +04:00
|
|
|
return;
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2004-04-13 20:45:59 +04:00
|
|
|
nscoord val = 0;
|
|
|
|
if (value->Type() == nsAttrValue::eInteger)
|
|
|
|
val = value->GetIntegerValue();
|
2001-06-01 02:19:43 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, (float)val);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, (float)val);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, (float)val);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, (float)val);
|
|
|
|
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_top_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_right_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_bottom_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
aData->SetKeywordValueIfUnset(eCSSProperty_border_left_style,
|
|
|
|
NS_STYLE_BORDER_STYLE_SOLID);
|
|
|
|
|
|
|
|
aData->SetCurrentColorIfUnset(eCSSProperty_border_top_color);
|
|
|
|
aData->SetCurrentColorIfUnset(eCSSProperty_border_right_color);
|
|
|
|
aData->SetCurrentColorIfUnset(eCSSProperty_border_bottom_color);
|
|
|
|
aData->SetCurrentColorIfUnset(eCSSProperty_border_left_color);
|
1998-09-01 05:36:11 +04:00
|
|
|
}
|
|
|
|
|
1998-08-29 07:15:55 +04:00
|
|
|
void
|
2005-10-27 00:23:56 +04:00
|
|
|
nsGenericHTMLElement::MapBackgroundInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-04 02:21:32 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
|
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Background)))
|
2001-06-01 02:19:43 +04:00
|
|
|
return;
|
1998-09-04 02:21:32 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_background_image) &&
|
2017-04-10 10:28:48 +03:00
|
|
|
aData->PresContext()->UseDocumentColors()) {
|
2001-06-01 02:19:43 +04:00
|
|
|
// background
|
2012-08-24 21:50:49 +04:00
|
|
|
nsAttrValue* value =
|
|
|
|
const_cast<nsAttrValue*>(aAttributes->GetAttr(nsGkAtoms::background));
|
2012-09-04 19:53:11 +04:00
|
|
|
if (value) {
|
2017-04-10 10:28:48 +03:00
|
|
|
aData->SetBackgroundImage(*value);
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
2005-10-27 00:23:56 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapBGColorInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2005-10-27 00:23:56 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Background)))
|
2005-10-27 00:23:56 +04:00
|
|
|
return;
|
1998-09-04 02:21:32 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (!aData->PropertyIsSet(eCSSProperty_background_color) &&
|
|
|
|
aData->PresContext()->UseDocumentColors()) {
|
2006-12-26 20:47:52 +03:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bgcolor);
|
2004-02-11 03:09:59 +03:00
|
|
|
nscolor color;
|
2004-04-13 20:45:59 +04:00
|
|
|
if (value && value->GetColorValue(color)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetColorValue(eCSSProperty_background_color, color);
|
2004-02-11 03:09:59 +03:00
|
|
|
}
|
1998-09-04 02:21:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-10-27 00:23:56 +04:00
|
|
|
void
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2005-10-27 00:23:56 +04:00
|
|
|
{
|
|
|
|
MapBackgroundInto(aAttributes, aData);
|
|
|
|
MapBGColorInto(aAttributes, aData);
|
|
|
|
}
|
|
|
|
|
1998-08-29 03:27:19 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2004-06-01 02:26:41 +04:00
|
|
|
nsresult
|
|
|
|
nsGenericHTMLElement::SetAttrHelper(nsIAtom* aAttr, const nsAString& aValue)
|
|
|
|
{
|
2011-10-17 18:59:28 +04:00
|
|
|
return SetAttr(kNameSpaceID_None, aAttr, aValue, true);
|
2004-06-01 02:26:41 +04:00
|
|
|
}
|
|
|
|
|
2012-10-02 12:24:12 +04:00
|
|
|
int32_t
|
|
|
|
nsGenericHTMLElement::GetIntAttr(nsIAtom* aAttr, int32_t aDefault) const
|
2004-02-25 02:55:18 +03:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr);
|
2004-03-04 05:06:28 +03:00
|
|
|
if (attrVal && attrVal->Type() == nsAttrValue::eInteger) {
|
2012-10-02 12:24:12 +04:00
|
|
|
return attrVal->GetIntegerValue();
|
2004-02-25 02:55:18 +03:00
|
|
|
}
|
2012-10-02 12:24:12 +04:00
|
|
|
return aDefault;
|
2004-02-25 02:55:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLElement::SetIntAttr(nsIAtom* aAttr, int32_t aValue)
|
2004-02-25 02:55:18 +03:00
|
|
|
{
|
|
|
|
nsAutoString value;
|
|
|
|
value.AppendInt(aValue);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return SetAttr(kNameSpaceID_None, aAttr, value, true);
|
2004-02-25 02:55:18 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 11:03:50 +04:00
|
|
|
uint32_t
|
|
|
|
nsGenericHTMLElement::GetUnsignedIntAttr(nsIAtom* aAttr,
|
|
|
|
uint32_t aDefault) const
|
2010-11-06 12:30:27 +03:00
|
|
|
{
|
|
|
|
const nsAttrValue* attrVal = mAttrsAndChildren.GetAttr(aAttr);
|
2013-04-04 11:03:50 +04:00
|
|
|
if (!attrVal || attrVal->Type() != nsAttrValue::eInteger) {
|
|
|
|
return aDefault;
|
2010-11-06 12:30:27 +03:00
|
|
|
}
|
|
|
|
|
2013-04-04 11:03:50 +04:00
|
|
|
return attrVal->GetIntegerValue();
|
2010-11-06 12:30:27 +03:00
|
|
|
}
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
void
|
|
|
|
nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr,
|
|
|
|
nsAString& aResult) const
|
2004-02-25 02:55:18 +03:00
|
|
|
{
|
2009-03-10 16:51:34 +03:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool hadAttr = GetURIAttr(aAttr, aBaseAttr, getter_AddRefs(uri));
|
2010-10-29 01:48:48 +04:00
|
|
|
if (!hadAttr) {
|
2010-10-29 00:49:14 +04:00
|
|
|
aResult.Truncate();
|
2012-11-11 03:30:15 +04:00
|
|
|
return;
|
2004-02-25 02:55:18 +03:00
|
|
|
}
|
|
|
|
|
2010-10-29 01:48:48 +04:00
|
|
|
if (!uri) {
|
|
|
|
// Just return the attr value
|
|
|
|
GetAttr(kNameSpaceID_None, aAttr, aResult);
|
2012-11-11 03:30:15 +04:00
|
|
|
return;
|
2010-10-29 01:48:48 +04:00
|
|
|
}
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2009-03-10 16:51:34 +03:00
|
|
|
uri->GetSpec(spec);
|
|
|
|
CopyUTF8toUTF16(spec, aResult);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2011-05-17 17:54:09 +04:00
|
|
|
nsGenericHTMLElement::GetURIAttr(nsIAtom* aAttr, nsIAtom* aBaseAttr, nsIURI** aURI) const
|
2009-03-10 16:51:34 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aURI = nullptr;
|
2009-03-10 16:51:34 +03:00
|
|
|
|
|
|
|
const nsAttrValue* attr = mAttrsAndChildren.GetAttr(aAttr);
|
|
|
|
if (!attr) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2009-03-10 16:51:34 +03:00
|
|
|
}
|
|
|
|
|
2004-02-25 02:55:18 +03:00
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
2006-07-21 03:42:51 +04:00
|
|
|
|
|
|
|
if (aBaseAttr) {
|
|
|
|
nsAutoString baseAttrValue;
|
|
|
|
if (GetAttr(kNameSpaceID_None, aBaseAttr, baseAttrValue)) {
|
|
|
|
nsCOMPtr<nsIURI> baseAttrURI;
|
2009-03-10 16:51:34 +03:00
|
|
|
nsresult rv =
|
|
|
|
nsContentUtils::NewURIWithDocumentCharset(getter_AddRefs(baseAttrURI),
|
2011-10-18 14:53:36 +04:00
|
|
|
baseAttrValue, OwnerDoc(),
|
2009-03-10 16:51:34 +03:00
|
|
|
baseURI);
|
2006-07-21 03:42:51 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2006-07-21 03:42:51 +04:00
|
|
|
}
|
|
|
|
baseURI.swap(baseAttrURI);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-03-10 16:51:34 +03:00
|
|
|
// Don't care about return value. If it fails, we still want to
|
2011-10-17 18:59:28 +04:00
|
|
|
// return true, and *aURI will be null.
|
2009-03-10 16:51:34 +03:00
|
|
|
nsContentUtils::NewURIWithDocumentCharset(aURI,
|
2009-11-09 21:00:54 +03:00
|
|
|
attr->GetStringValue(),
|
2011-10-18 14:53:36 +04:00
|
|
|
OwnerDoc(), baseURI);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2004-02-25 02:55:18 +03:00
|
|
|
}
|
|
|
|
|
2013-02-18 15:59:08 +04:00
|
|
|
HTMLMenuElement*
|
2012-11-11 03:30:15 +04:00
|
|
|
nsGenericHTMLElement::GetContextMenu() const
|
2007-06-28 06:48:16 +04:00
|
|
|
{
|
2012-11-11 03:30:15 +04:00
|
|
|
nsAutoString value;
|
|
|
|
GetHTMLAttr(nsGkAtoms::contextmenu, value);
|
|
|
|
if (!value.IsEmpty()) {
|
2014-10-02 23:07:24 +04:00
|
|
|
//XXXsmaug How should this work in Shadow DOM?
|
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2012-11-11 03:30:15 +04:00
|
|
|
if (doc) {
|
2013-02-18 15:59:08 +04:00
|
|
|
return HTMLMenuElement::FromContentOrNull(doc->GetElementById(value));
|
2010-03-10 22:10:09 +03:00
|
|
|
}
|
|
|
|
}
|
2012-11-11 03:30:15 +04:00
|
|
|
return nullptr;
|
2010-03-10 22:10:09 +03:00
|
|
|
}
|
|
|
|
|
2012-06-07 22:41:59 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLElement::IsLabelable() const
|
|
|
|
{
|
2015-03-03 14:09:00 +03:00
|
|
|
return IsAnyOfHTMLElements(nsGkAtoms::progress, nsGkAtoms::meter);
|
2012-06-07 22:41:59 +04:00
|
|
|
}
|
|
|
|
|
2017-06-16 03:04:00 +03:00
|
|
|
/* static */ bool
|
|
|
|
nsGenericHTMLElement::MatchLabelsElement(Element* aElement, int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAtom, void* aData)
|
|
|
|
{
|
|
|
|
HTMLLabelElement* element = HTMLLabelElement::FromContent(aElement);
|
|
|
|
return element && element->GetControl() == aData;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsINodeList>
|
|
|
|
nsGenericHTMLElement::Labels()
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(IsLabelable(),
|
|
|
|
"Labels() only allow labelable elements to use it.");
|
2017-07-18 01:25:49 +03:00
|
|
|
nsExtendedDOMSlots* slots = ExtendedDOMSlots();
|
2017-06-16 03:04:00 +03:00
|
|
|
|
|
|
|
if (!slots->mLabelsList) {
|
|
|
|
slots->mLabelsList = new nsLabelsNodeList(SubtreeRoot(), MatchLabelsElement,
|
|
|
|
nullptr, this);
|
|
|
|
}
|
|
|
|
|
|
|
|
RefPtr<nsLabelsNodeList> labels = slots->mLabelsList;
|
|
|
|
return labels.forget();
|
|
|
|
}
|
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
bool
|
2015-03-17 23:42:14 +03:00
|
|
|
nsGenericHTMLElement::IsInteractiveHTMLContent(bool aIgnoreTabindex) const
|
2015-01-20 23:39:28 +03:00
|
|
|
{
|
2015-03-03 14:09:00 +03:00
|
|
|
return IsAnyOfHTMLElements(nsGkAtoms::details, nsGkAtoms::embed,
|
|
|
|
nsGkAtoms::keygen) ||
|
2015-03-17 23:42:14 +03:00
|
|
|
(!aIgnoreTabindex && HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex));
|
2015-01-20 23:39:28 +03:00
|
|
|
}
|
|
|
|
|
2012-11-19 14:59:13 +04:00
|
|
|
// static
|
|
|
|
bool
|
2016-07-18 17:26:38 +03:00
|
|
|
nsGenericHTMLElement::TouchEventsEnabled(JSContext* aCx, JSObject* aGlobal)
|
2013-02-19 20:54:41 +04:00
|
|
|
{
|
2016-07-18 17:26:38 +03:00
|
|
|
return TouchEvent::PrefEnabled(aCx, aGlobal);
|
2012-11-19 14:59:13 +04:00
|
|
|
}
|
|
|
|
|
2000-04-19 11:49:07 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2017-04-01 05:49:00 +03:00
|
|
|
nsGenericHTMLFormElement::nsGenericHTMLFormElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo,
|
|
|
|
uint8_t aType)
|
2010-09-19 01:33:16 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
2017-04-01 05:49:00 +03:00
|
|
|
, nsIFormControl(aType)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mForm(nullptr)
|
|
|
|
, mFieldSet(nullptr)
|
2000-04-19 11:49:07 +04:00
|
|
|
{
|
2011-06-01 05:46:57 +04:00
|
|
|
// We should add the NS_EVENT_STATE_ENABLED bit here as needed, but
|
|
|
|
// that depends on our type, which is not initialized yet. So we
|
|
|
|
// have to do this in subclasses.
|
2000-04-19 11:49:07 +04:00
|
|
|
}
|
|
|
|
|
2004-02-10 22:36:43 +03:00
|
|
|
nsGenericHTMLFormElement::~nsGenericHTMLFormElement()
|
2000-04-19 11:49:07 +04:00
|
|
|
{
|
2010-11-05 20:15:05 +03:00
|
|
|
if (mFieldSet) {
|
2011-09-18 13:22:18 +04:00
|
|
|
mFieldSet->RemoveElement(this);
|
2010-11-05 20:15:05 +03:00
|
|
|
}
|
|
|
|
|
2009-10-01 02:56:50 +04:00
|
|
|
// Check that this element doesn't know anything about its form at this point.
|
2010-09-19 01:33:16 +04:00
|
|
|
NS_ASSERTION(!mForm, "mForm should be null at this point!");
|
2000-04-19 11:49:07 +04:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(nsGenericHTMLFormElement,
|
|
|
|
nsGenericHTMLElement,
|
|
|
|
nsIFormControl)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-10-31 00:38:48 +03:00
|
|
|
nsINode*
|
|
|
|
nsGenericHTMLFormElement::GetScopeChainParent() const
|
|
|
|
{
|
|
|
|
return mForm ? mForm : nsGenericHTMLElement::GetScopeChainParent();
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLFormElement::IsNodeOfType(uint32_t aFlags) const
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
{
|
2010-04-30 17:12:06 +04:00
|
|
|
return !(aFlags & ~(eCONTENT | eHTML_FORM_CONTROL));
|
Landing the XPCDOM_20010329_BRANCH branch, changes mostly done by jband@netscape.com and jst@netscape.com, also some changes done by shaver@mozilla.org, peterv@netscape.com and markh@activestate.com. r= and sr= by vidur@netscape.com, jband@netscape.com, jst@netscpae.com, danm@netscape.com, hyatt@netscape.com, shaver@mozilla.org, dbradley@netscape.com, rpotts@netscape.com.
2001-05-08 20:46:42 +04:00
|
|
|
}
|
|
|
|
|
2007-11-30 20:57:03 +03:00
|
|
|
void
|
2008-04-11 02:47:01 +04:00
|
|
|
nsGenericHTMLFormElement::SaveSubtreeState()
|
2007-11-30 20:57:03 +03:00
|
|
|
{
|
|
|
|
SaveState();
|
2008-04-11 02:47:01 +04:00
|
|
|
|
|
|
|
nsGenericHTMLElement::SaveSubtreeState();
|
2007-11-30 20:57:03 +03:00
|
|
|
}
|
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::SetForm(nsIDOMHTMLFormElement* aForm)
|
2000-12-23 13:56:31 +03:00
|
|
|
{
|
2008-09-11 07:21:33 +04:00
|
|
|
NS_PRECONDITION(aForm, "Don't pass null here");
|
|
|
|
NS_ASSERTION(!mForm,
|
2008-09-08 17:19:49 +04:00
|
|
|
"We don't support switching from one non-null form to another.");
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2017-05-02 00:10:00 +03:00
|
|
|
SetForm(static_cast<HTMLFormElement*>(aForm), false);
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsGenericHTMLFormElement::SetForm(HTMLFormElement* aForm, bool aBindToTree)
|
|
|
|
{
|
|
|
|
if (aForm) {
|
|
|
|
BeforeSetForm(aBindToTree);
|
|
|
|
}
|
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
// keep a *weak* ref to the form here
|
2017-05-02 00:10:00 +03:00
|
|
|
mForm = aForm;
|
2008-09-11 07:21:33 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
void
|
2017-05-02 00:10:00 +03:00
|
|
|
nsGenericHTMLFormElement::ClearForm(bool aRemoveFromForm, bool aUnbindOrDelete)
|
2008-09-11 07:21:33 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION((mForm != nullptr) == HasFlag(ADDED_TO_FORM),
|
2008-09-11 07:21:33 +04:00
|
|
|
"Form control should have had flag set correctly");
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
if (!mForm) {
|
|
|
|
return;
|
|
|
|
}
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
if (aRemoveFromForm) {
|
|
|
|
nsAutoString nameVal, idVal;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, nameVal);
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, idVal);
|
2001-11-28 14:00:14 +03:00
|
|
|
|
2010-11-11 15:36:42 +03:00
|
|
|
mForm->RemoveElement(this, true);
|
2008-09-11 07:21:33 +04:00
|
|
|
|
|
|
|
if (!nameVal.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveElementFromTable(this, nameVal);
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
2007-07-26 08:26:07 +04:00
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
if (!idVal.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveElementFromTable(this, idVal);
|
2008-09-11 07:21:33 +04:00
|
|
|
}
|
2002-05-09 04:29:23 +04:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2008-09-11 07:21:33 +04:00
|
|
|
UnsetFlags(ADDED_TO_FORM);
|
2012-07-30 18:20:58 +04:00
|
|
|
mForm = nullptr;
|
2017-05-02 00:10:00 +03:00
|
|
|
|
|
|
|
AfterClearForm(aUnbindOrDelete);
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2010-05-09 22:32:57 +04:00
|
|
|
Element*
|
|
|
|
nsGenericHTMLFormElement::GetFormElement()
|
|
|
|
{
|
|
|
|
return mForm;
|
|
|
|
}
|
|
|
|
|
2013-08-17 04:32:47 +04:00
|
|
|
HTMLFieldSetElement*
|
|
|
|
nsGenericHTMLFormElement::GetFieldSet()
|
|
|
|
{
|
|
|
|
return mFieldSet;
|
|
|
|
}
|
|
|
|
|
2010-05-09 22:32:57 +04:00
|
|
|
nsresult
|
2004-02-10 22:36:43 +03:00
|
|
|
nsGenericHTMLFormElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
2000-12-23 13:56:31 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aForm);
|
2009-10-30 04:49:11 +03:00
|
|
|
NS_IF_ADDREF(*aForm = mForm);
|
2000-12-23 13:56:31 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-11-27 15:51:53 +04:00
|
|
|
nsIContent::IMEState
|
2005-11-15 02:55:24 +03:00
|
|
|
nsGenericHTMLFormElement::GetDesiredIMEState()
|
|
|
|
{
|
2017-06-22 09:21:31 +03:00
|
|
|
TextEditor* textEditor = GetTextEditorInternal();
|
|
|
|
if (!textEditor) {
|
2005-11-18 08:22:04 +03:00
|
|
|
return nsGenericHTMLElement::GetDesiredIMEState();
|
2017-06-22 09:21:31 +03:00
|
|
|
}
|
2011-11-27 15:51:53 +04:00
|
|
|
IMEState state;
|
2017-06-22 09:21:31 +03:00
|
|
|
nsresult rv = textEditor->GetPreferredIMEState(&state);
|
|
|
|
if (NS_FAILED(rv)) {
|
2005-11-18 08:22:04 +03:00
|
|
|
return nsGenericHTMLElement::GetDesiredIMEState();
|
2017-06-22 09:21:31 +03:00
|
|
|
}
|
2005-11-15 02:55:24 +03:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsresult
|
|
|
|
nsGenericHTMLFormElement::BindToTree(nsIDocument* aDocument,
|
|
|
|
nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool aCompileEventHandlers)
|
2005-04-06 03:54:35 +04:00
|
|
|
{
|
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2010-05-19 21:52:17 +04:00
|
|
|
|
|
|
|
// An autofocus event has to be launched if the autofocus attribute is
|
|
|
|
// specified and the element accept the autofocus attribute. In addition,
|
|
|
|
// the document should not be already loaded and the "browser.autofocus"
|
|
|
|
// preference should be 'true'.
|
2011-03-24 18:10:42 +03:00
|
|
|
if (IsAutofocusable() && HasAttr(kNameSpaceID_None, nsGkAtoms::autofocus) &&
|
2017-07-02 09:04:24 +03:00
|
|
|
nsContentUtils::AutoFocusEnabled()) {
|
2010-05-19 21:52:17 +04:00
|
|
|
nsCOMPtr<nsIRunnable> event = new nsAutoFocusEvent(this);
|
|
|
|
rv = NS_DispatchToCurrentThread(event);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
}
|
|
|
|
|
2010-08-26 00:45:43 +04:00
|
|
|
// If @form is set, the element *has* to be in a document, otherwise it
|
|
|
|
// wouldn't be possible to find an element with the corresponding id.
|
|
|
|
// If @form isn't set, the element *has* to have a parent, otherwise it
|
|
|
|
// wouldn't be possible to find a form ancestor.
|
2010-08-26 02:45:35 +04:00
|
|
|
// We should not call UpdateFormOwner if none of these conditions are
|
2010-08-26 00:45:43 +04:00
|
|
|
// fulfilled.
|
2014-10-02 23:07:24 +04:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::form) ? !!GetUncomposedDoc()
|
2010-08-26 00:45:43 +04:00
|
|
|
: !!aParent) {
|
2012-07-30 18:20:58 +04:00
|
|
|
UpdateFormOwner(true, nullptr);
|
2007-07-26 08:26:07 +04:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
// Set parent fieldset which should be used for the disabled state.
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateFieldSet(false);
|
2010-09-19 01:33:16 +04:00
|
|
|
|
2007-07-26 08:26:07 +04:00
|
|
|
return NS_OK;
|
2000-04-19 11:49:07 +04:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLFormElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2000-04-19 11:49:07 +04:00
|
|
|
{
|
2005-05-13 00:53:33 +04:00
|
|
|
// Save state before doing anything
|
|
|
|
SaveState();
|
2017-07-06 15:00:35 +03:00
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
if (mForm) {
|
|
|
|
// Might need to unset mForm
|
|
|
|
if (aNullParent) {
|
|
|
|
// No more parent means no more form
|
2017-05-02 00:10:00 +03:00
|
|
|
ClearForm(true, true);
|
2005-04-06 03:54:35 +04:00
|
|
|
} else {
|
|
|
|
// Recheck whether we should still have an mForm.
|
2010-08-24 05:11:04 +04:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::form) ||
|
|
|
|
!FindAncestorForm(mForm)) {
|
2017-05-02 00:10:00 +03:00
|
|
|
ClearForm(true, true);
|
2007-11-07 20:01:23 +03:00
|
|
|
} else {
|
|
|
|
UnsetFlags(MAYBE_ORPHAN_FORM_ELEMENT);
|
2005-04-06 03:54:35 +04:00
|
|
|
}
|
2001-11-29 17:12:06 +03:00
|
|
|
}
|
2011-06-01 05:46:57 +04:00
|
|
|
|
|
|
|
if (!mForm) {
|
|
|
|
// Our novalidate state might have changed
|
|
|
|
UpdateState(false);
|
|
|
|
}
|
2000-05-17 06:03:10 +04:00
|
|
|
}
|
2000-04-19 11:49:07 +04:00
|
|
|
|
2010-08-24 05:11:04 +04:00
|
|
|
// We have to remove the form id observer if there was one.
|
|
|
|
// We will re-add one later if needed (during bind to tree).
|
|
|
|
if (nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::form)) {
|
|
|
|
RemoveFormIdObserver();
|
|
|
|
}
|
|
|
|
|
2005-04-06 03:54:35 +04:00
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
2010-09-19 01:33:16 +04:00
|
|
|
|
|
|
|
// The element might not have a fieldset anymore.
|
2011-10-17 18:59:28 +04:00
|
|
|
UpdateFieldSet(false);
|
2000-04-19 11:49:07 +04:00
|
|
|
}
|
|
|
|
|
2001-03-22 11:51:52 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLFormElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2012-02-14 06:00:56 +04:00
|
|
|
bool aNotify)
|
2000-05-12 17:46:59 +04:00
|
|
|
{
|
2005-10-28 06:59:38 +04:00
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
2005-08-30 07:31:47 +04:00
|
|
|
nsAutoString tmp;
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
// remove the control from the hashtable as needed
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mForm && (aName == nsGkAtoms::name || aName == nsGkAtoms::id)) {
|
2005-08-30 07:31:47 +04:00
|
|
|
GetAttr(kNameSpaceID_None, aName, tmp);
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2005-08-30 07:31:47 +04:00
|
|
|
if (!tmp.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveElementFromTable(this, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mForm && aName == nsGkAtoms::type) {
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
|
|
|
|
if (!tmp.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveElementFromTable(this, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, tmp);
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2005-08-30 07:31:47 +04:00
|
|
|
if (!tmp.IsEmpty()) {
|
2016-11-21 20:34:02 +03:00
|
|
|
mForm->RemoveElementFromTable(this, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
|
|
|
|
2010-11-11 15:36:42 +03:00
|
|
|
mForm->RemoveElement(this, false);
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
if (aName == nsGkAtoms::form) {
|
|
|
|
// If @form isn't set or set to the empty string, there were no observer
|
|
|
|
// so we don't have to remove it.
|
|
|
|
if (nsContentUtils::HasNonEmptyAttr(this, kNameSpaceID_None,
|
|
|
|
nsGkAtoms::form)) {
|
|
|
|
// The current form id observer is no longer needed.
|
|
|
|
// A new one may be added in AfterSetAttr.
|
|
|
|
RemoveFormIdObserver();
|
|
|
|
}
|
|
|
|
}
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
2000-05-12 17:46:59 +04:00
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName,
|
|
|
|
aValue, aNotify);
|
|
|
|
}
|
2005-08-30 07:31:47 +04:00
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLFormElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aValue,
|
|
|
|
const nsAttrValue* aOldValue, bool aNotify)
|
2005-10-28 06:59:38 +04:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
// add the control to the hashtable as needed
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mForm && (aName == nsGkAtoms::name || aName == nsGkAtoms::id) &&
|
2012-02-14 06:00:56 +04:00
|
|
|
aValue && !aValue->IsEmptyString()) {
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(aValue->Type() == nsAttrValue::eAtom,
|
|
|
|
"Expected atom value for name/id");
|
2012-02-14 06:00:56 +04:00
|
|
|
mForm->AddElementToTable(this,
|
|
|
|
nsDependentAtomString(aValue->GetAtomValue()));
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
2000-05-12 17:46:59 +04:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (mForm && aName == nsGkAtoms::type) {
|
2005-10-28 06:59:38 +04:00
|
|
|
nsAutoString tmp;
|
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, tmp);
|
2000-05-12 17:46:59 +04:00
|
|
|
|
2005-08-30 07:31:47 +04:00
|
|
|
if (!tmp.IsEmpty()) {
|
2006-05-19 14:01:22 +04:00
|
|
|
mForm->AddElementToTable(this, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, tmp);
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2005-08-30 07:31:47 +04:00
|
|
|
if (!tmp.IsEmpty()) {
|
2006-05-19 14:01:22 +04:00
|
|
|
mForm->AddElementToTable(this, tmp);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
|
|
|
|
2010-10-08 17:42:09 +04:00
|
|
|
mForm->AddElement(this, false, aNotify);
|
2001-03-22 11:51:52 +03:00
|
|
|
}
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
if (aName == nsGkAtoms::form) {
|
|
|
|
// We need a new form id observer.
|
2014-10-02 23:07:24 +04:00
|
|
|
//XXXsmaug How should this work in Shadow DOM?
|
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2010-08-24 05:11:04 +04:00
|
|
|
if (doc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
Element* formIdElement = nullptr;
|
2012-02-14 06:00:56 +04:00
|
|
|
if (aValue && !aValue->IsEmptyString()) {
|
2010-08-24 05:11:04 +04:00
|
|
|
formIdElement = AddFormIdObserver();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Because we have a new @form value (or no more @form), we have to
|
|
|
|
// update our form owner.
|
|
|
|
UpdateFormOwner(false, formIdElement);
|
|
|
|
}
|
|
|
|
}
|
2005-10-28 06:59:38 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
2005-10-28 06:59:38 +04:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName,
|
2017-05-19 00:09:01 +03:00
|
|
|
aValue, aOldValue, aNotify);
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
2001-03-22 11:51:52 +03:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
nsresult
|
2016-10-21 05:11:07 +03:00
|
|
|
nsGenericHTMLFormElement::GetEventTargetParent(EventChainPreVisitor& aVisitor)
|
2016-10-21 11:56:58 +03:00
|
|
|
{
|
|
|
|
if (aVisitor.mEvent->IsTrusted() && (aVisitor.mEvent->mMessage == eFocus ||
|
|
|
|
aVisitor.mEvent->mMessage == eBlur)) {
|
|
|
|
// We have to handle focus/blur event to change focus states in
|
|
|
|
// PreHandleEvent to prevent it breaks event target chain creation.
|
|
|
|
aVisitor.mWantsPreHandleEvent = true;
|
|
|
|
}
|
|
|
|
return nsGenericHTMLElement::GetEventTargetParent(aVisitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericHTMLFormElement::PreHandleEvent(EventChainVisitor& aVisitor)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
{
|
2016-03-17 10:01:30 +03:00
|
|
|
if (aVisitor.mEvent->IsTrusted()) {
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aVisitor.mEvent->mMessage) {
|
2015-09-02 09:08:00 +03:00
|
|
|
case eFocus: {
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
// Check to see if focus has bubbled up from a form control's
|
|
|
|
// child textfield or button. If that's the case, don't focus
|
|
|
|
// this parent file control -- leave focus on the child.
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (formControlFrame &&
|
2016-04-18 19:33:23 +03:00
|
|
|
aVisitor.mEvent->mOriginalTarget == static_cast<nsINode*>(this))
|
2011-10-17 18:59:28 +04:00
|
|
|
formControlFrame->SetFocus(true, true);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-09-02 09:08:00 +03:00
|
|
|
case eBlur: {
|
2011-10-17 18:59:28 +04:00
|
|
|
nsIFormControlFrame* formControlFrame = GetFormControlFrame(true);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (formControlFrame)
|
2011-10-17 18:59:28 +04:00
|
|
|
formControlFrame->SetFocus(false, false);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
break;
|
|
|
|
}
|
2015-08-26 15:56:59 +03:00
|
|
|
default:
|
|
|
|
break;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
|
|
|
}
|
2016-10-21 11:56:58 +03:00
|
|
|
return nsGenericHTMLElement::PreHandleEvent(aVisitor);
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
|
|
|
|
2011-09-18 13:22:18 +04:00
|
|
|
/* virtual */
|
|
|
|
bool
|
|
|
|
nsGenericHTMLFormElement::IsDisabled() const
|
|
|
|
{
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
return State().HasState(NS_EVENT_STATE_DISABLED);
|
2011-09-18 13:22:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::ForgetFieldSet(nsIContent* aFieldset)
|
|
|
|
{
|
|
|
|
if (mFieldSet == aFieldset) {
|
2012-07-30 18:20:58 +04:00
|
|
|
mFieldSet = nullptr;
|
2011-09-18 13:22:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2005-09-01 20:49:36 +04:00
|
|
|
nsGenericHTMLFormElement::CanBeDisabled() const
|
2005-08-30 07:31:47 +04:00
|
|
|
{
|
2017-04-01 05:49:00 +03:00
|
|
|
int32_t type = ControlType();
|
2005-09-01 20:49:36 +04:00
|
|
|
// It's easier to test the types that _cannot_ be disabled
|
2005-08-30 07:31:47 +04:00
|
|
|
return
|
2010-04-26 11:42:00 +04:00
|
|
|
type != NS_FORM_OBJECT &&
|
2012-06-07 22:42:45 +04:00
|
|
|
type != NS_FORM_OUTPUT;
|
2005-08-30 07:31:47 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLFormElement::IsHTMLFocusable(bool aWithMouse,
|
|
|
|
bool* aIsFocusable,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t* aTabIndex)
|
2011-01-05 16:23:37 +03:00
|
|
|
{
|
|
|
|
if (nsGenericHTMLElement::IsHTMLFocusable(aWithMouse, aIsFocusable, aTabIndex)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2011-01-05 16:23:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef XP_MACOSX
|
|
|
|
*aIsFocusable =
|
|
|
|
(!aWithMouse || nsFocusManager::sMouseFocusesFormControl) && *aIsFocusable;
|
|
|
|
#endif
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2011-01-05 16:23:37 +03:00
|
|
|
}
|
|
|
|
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates
|
2005-08-30 07:31:47 +04:00
|
|
|
nsGenericHTMLFormElement::IntrinsicState() const
|
|
|
|
{
|
2007-02-09 09:20:47 +03:00
|
|
|
// If you add attribute-dependent states here, you need to add them them to
|
|
|
|
// AfterSetAttr too. And add them to AfterSetAttr for all subclasses that
|
|
|
|
// implement IntrinsicState() and are affected by that attribute.
|
2014-04-03 08:18:36 +04:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2005-08-30 07:31:47 +04:00
|
|
|
|
2009-09-18 22:52:27 +04:00
|
|
|
if (mForm && mForm->IsDefaultSubmitElement(this)) {
|
2006-08-16 07:20:19 +04:00
|
|
|
NS_ASSERTION(IsSubmitControl(),
|
|
|
|
"Default submit element that isn't a submit control.");
|
|
|
|
// We are the default submit element (:default)
|
|
|
|
state |= NS_EVENT_STATE_DEFAULT;
|
|
|
|
}
|
2005-08-30 07:31:47 +04:00
|
|
|
|
2010-11-16 23:45:49 +03:00
|
|
|
// Make the text controls read-write
|
|
|
|
if (!state.HasState(NS_EVENT_STATE_MOZ_READWRITE) &&
|
2016-03-03 01:39:34 +03:00
|
|
|
IsTextOrNumberControl(/*aExcludePassword*/ false)) {
|
2012-10-02 12:24:12 +04:00
|
|
|
bool roState = GetBoolAttr(nsGkAtoms::readonly);
|
2010-11-16 23:45:49 +03:00
|
|
|
|
|
|
|
if (!roState) {
|
|
|
|
state |= NS_EVENT_STATE_MOZ_READWRITE;
|
|
|
|
state &= ~NS_EVENT_STATE_MOZ_READONLY;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-08-30 07:31:47 +04:00
|
|
|
return state;
|
|
|
|
}
|
|
|
|
|
2008-10-07 22:53:23 +04:00
|
|
|
nsGenericHTMLFormElement::FocusTristate
|
|
|
|
nsGenericHTMLFormElement::FocusState()
|
|
|
|
{
|
2014-08-06 03:23:02 +04:00
|
|
|
// We can't be focused if we aren't in a (composed) document
|
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2008-10-07 22:53:23 +04:00
|
|
|
if (!doc)
|
|
|
|
return eUnfocusable;
|
|
|
|
|
|
|
|
// first see if we are disabled or not. If disabled then do nothing.
|
2010-09-19 01:33:16 +04:00
|
|
|
if (IsDisabled()) {
|
2008-10-07 22:53:23 +04:00
|
|
|
return eUnfocusable;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the window is not active, do not allow the focus to bring the
|
|
|
|
// window to the front. We update the focus controller, but do
|
|
|
|
// nothing else.
|
2016-01-30 20:05:36 +03:00
|
|
|
if (nsPIDOMWindowOuter* win = doc->GetWindow()) {
|
|
|
|
nsCOMPtr<nsPIDOMWindowOuter> rootWindow = win->GetPrivateRoot();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIFocusManager> fm = do_GetService(FOCUSMANAGER_CONTRACTID);
|
|
|
|
if (fm && rootWindow) {
|
2016-01-30 20:05:36 +03:00
|
|
|
nsCOMPtr<mozIDOMWindowProxy> activeWindow;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
fm->GetActiveWindow(getter_AddRefs(activeWindow));
|
|
|
|
if (activeWindow == rootWindow) {
|
|
|
|
return eActiveWindow;
|
2008-10-07 22:53:23 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
return eInactiveWindow;
|
2008-10-07 22:53:23 +04:00
|
|
|
}
|
|
|
|
|
2010-08-24 05:11:04 +04:00
|
|
|
Element*
|
|
|
|
nsGenericHTMLFormElement::AddFormIdObserver()
|
|
|
|
{
|
2014-10-02 23:07:24 +04:00
|
|
|
NS_ASSERTION(GetUncomposedDoc(), "When adding a form id observer, "
|
|
|
|
"we should be in a document!");
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
nsAutoString formId;
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
2010-08-24 05:11:04 +04:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::form, formId);
|
|
|
|
NS_ASSERTION(!formId.IsEmpty(),
|
|
|
|
"@form value should not be the empty string!");
|
2017-09-26 01:33:21 +03:00
|
|
|
RefPtr<nsIAtom> atom = NS_Atomize(formId);
|
2010-08-24 05:11:04 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return doc->AddIDTargetObserver(atom, FormIdUpdated, this, false);
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::RemoveFormIdObserver()
|
|
|
|
{
|
|
|
|
/**
|
2011-10-18 14:53:36 +04:00
|
|
|
* We are using OwnerDoc() because we don't really care about having the
|
2010-08-24 05:11:04 +04:00
|
|
|
* element actually being in the tree. If it is not and @form value changes,
|
|
|
|
* this method will be called for nothing but removing an observer which does
|
|
|
|
* not exist doesn't cost so much (no entry in the hash table) so having a
|
2014-10-02 23:07:24 +04:00
|
|
|
* boolean for GetUncomposedDoc()/GetOwnerDoc() would make everything look
|
|
|
|
* more complex for nothing.
|
2010-08-24 05:11:04 +04:00
|
|
|
*/
|
|
|
|
|
2011-10-18 14:53:36 +04:00
|
|
|
nsIDocument* doc = OwnerDoc();
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
// At this point, we may not have a document anymore. In that case, we can't
|
|
|
|
// remove the observer. The document did that for us.
|
|
|
|
if (!doc) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString formId;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::form, formId);
|
|
|
|
NS_ASSERTION(!formId.IsEmpty(),
|
|
|
|
"@form value should not be the empty string!");
|
2017-09-26 01:33:21 +03:00
|
|
|
RefPtr<nsIAtom> atom = NS_Atomize(formId);
|
2010-08-24 05:11:04 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
doc->RemoveIDTargetObserver(atom, FormIdUpdated, this, false);
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* static */
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2010-08-24 05:11:04 +04:00
|
|
|
nsGenericHTMLFormElement::FormIdUpdated(Element* aOldElement,
|
|
|
|
Element* aNewElement,
|
|
|
|
void* aData)
|
|
|
|
{
|
|
|
|
nsGenericHTMLFormElement* element =
|
|
|
|
static_cast<nsGenericHTMLFormElement*>(aData);
|
|
|
|
|
2015-03-03 14:08:59 +03:00
|
|
|
NS_ASSERTION(element->IsHTMLElement(), "aData should be an HTML element");
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
element->UpdateFormOwner(false, aNewElement);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 15:00:35 +03:00
|
|
|
bool
|
2015-08-26 15:56:59 +03:00
|
|
|
nsGenericHTMLFormElement::IsElementDisabledForEvents(EventMessage aMessage,
|
|
|
|
nsIFrame* aFrame)
|
2011-07-19 03:16:44 +04:00
|
|
|
{
|
2015-10-16 21:36:19 +03:00
|
|
|
switch (aMessage) {
|
|
|
|
case eMouseMove:
|
|
|
|
case eMouseOver:
|
|
|
|
case eMouseOut:
|
|
|
|
case eMouseEnter:
|
|
|
|
case eMouseLeave:
|
|
|
|
case ePointerMove:
|
|
|
|
case ePointerOver:
|
|
|
|
case ePointerOut:
|
|
|
|
case ePointerEnter:
|
|
|
|
case ePointerLeave:
|
2016-02-27 00:04:34 +03:00
|
|
|
case eWheel:
|
|
|
|
case eLegacyMouseLineOrPageScroll:
|
|
|
|
case eLegacyMousePixelScroll:
|
2015-10-16 21:36:19 +03:00
|
|
|
return false;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool disabled = IsDisabled();
|
2011-08-04 13:02:49 +04:00
|
|
|
if (!disabled && aFrame) {
|
2013-02-17 01:51:02 +04:00
|
|
|
const nsStyleUserInterface* uiStyle = aFrame->StyleUserInterface();
|
2016-10-23 01:08:18 +03:00
|
|
|
disabled = uiStyle->mUserInput == StyleUserInput::None ||
|
|
|
|
uiStyle->mUserInput == StyleUserInput::Disabled;
|
2011-08-04 13:02:49 +04:00
|
|
|
|
|
|
|
}
|
2015-10-16 21:36:19 +03:00
|
|
|
return disabled;
|
2011-08-04 13:02:49 +04:00
|
|
|
}
|
2011-07-19 03:16:44 +04:00
|
|
|
|
2010-08-24 05:11:04 +04:00
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::UpdateFormOwner(bool aBindToTree,
|
|
|
|
Element* aFormIdElement)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(!aBindToTree || !aFormIdElement,
|
|
|
|
"aFormIdElement shouldn't be set if aBindToTree is true!");
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool needStateUpdate = false;
|
2010-08-24 05:11:04 +04:00
|
|
|
if (!aBindToTree) {
|
2011-06-01 05:46:57 +04:00
|
|
|
needStateUpdate = mForm && mForm->IsDefaultSubmitElement(this);
|
2017-05-02 00:10:00 +03:00
|
|
|
ClearForm(true, false);
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
|
2013-06-19 18:24:37 +04:00
|
|
|
HTMLFormElement *oldForm = mForm;
|
2011-06-01 05:46:57 +04:00
|
|
|
|
2010-08-24 05:11:04 +04:00
|
|
|
if (!mForm) {
|
|
|
|
// If @form is set, we have to use that to find the form.
|
|
|
|
nsAutoString formId;
|
|
|
|
if (GetAttr(kNameSpaceID_None, nsGkAtoms::form, formId)) {
|
|
|
|
if (!formId.IsEmpty()) {
|
2012-07-30 18:20:58 +04:00
|
|
|
Element* element = nullptr;
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
if (aBindToTree) {
|
|
|
|
element = AddFormIdObserver();
|
|
|
|
} else {
|
|
|
|
element = aFormIdElement;
|
|
|
|
}
|
|
|
|
|
2014-10-02 23:07:24 +04:00
|
|
|
NS_ASSERTION(GetUncomposedDoc(), "The element should be in a document "
|
|
|
|
"when UpdateFormOwner is called!");
|
|
|
|
NS_ASSERTION(!GetUncomposedDoc() ||
|
|
|
|
element == GetUncomposedDoc()->GetElementById(formId),
|
2010-08-24 05:11:04 +04:00
|
|
|
"element should be equals to the current element "
|
|
|
|
"associated with the id in @form!");
|
|
|
|
|
2017-10-02 08:10:18 +03:00
|
|
|
if (element &&
|
|
|
|
element->IsHTMLElement(nsGkAtoms::form) &&
|
|
|
|
nsContentUtils::IsInSameAnonymousTree(this, element)) {
|
2017-05-02 00:10:00 +03:00
|
|
|
SetForm(static_cast<HTMLFormElement*>(element), aBindToTree);
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// We now have a parent, so we may have picked up an ancestor form. Search
|
|
|
|
// for it. Note that if mForm is already set we don't want to do this,
|
|
|
|
// because that means someone (probably the content sink) has already set
|
|
|
|
// it to the right value. Also note that even if being bound here didn't
|
|
|
|
// change our parent, we still need to search, since our parent chain
|
|
|
|
// probably changed _somewhere_.
|
2017-05-02 00:10:00 +03:00
|
|
|
SetForm(FindAncestorForm(), aBindToTree);
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mForm && !HasFlag(ADDED_TO_FORM)) {
|
|
|
|
// Now we need to add ourselves to the form
|
|
|
|
nsAutoString nameVal, idVal;
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::name, nameVal);
|
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::id, idVal);
|
|
|
|
|
|
|
|
SetFlags(ADDED_TO_FORM);
|
|
|
|
|
|
|
|
// Notify only if we just found this mForm.
|
2012-07-30 18:20:58 +04:00
|
|
|
mForm->AddElement(this, true, oldForm == nullptr);
|
2010-08-24 05:11:04 +04:00
|
|
|
|
|
|
|
if (!nameVal.IsEmpty()) {
|
|
|
|
mForm->AddElementToTable(this, nameVal);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!idVal.IsEmpty()) {
|
|
|
|
mForm->AddElementToTable(this, idVal);
|
|
|
|
}
|
|
|
|
}
|
2011-06-01 05:46:57 +04:00
|
|
|
|
|
|
|
if (mForm != oldForm || needStateUpdate) {
|
|
|
|
UpdateState(true);
|
|
|
|
}
|
2010-08-24 05:11:04 +04:00
|
|
|
}
|
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLFormElement::UpdateFieldSet(bool aNotify)
|
2010-09-19 01:33:16 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIContent* parent = nullptr;
|
|
|
|
nsIContent* prev = nullptr;
|
2010-09-19 05:47:15 +04:00
|
|
|
|
2017-09-22 22:34:00 +03:00
|
|
|
// Don't walk out of anonymous subtrees. Note the similar code in
|
|
|
|
// nsGenericHTMLElement::FindAncestorForm.
|
|
|
|
nsIContent* bindingParent = GetBindingParent();
|
|
|
|
|
|
|
|
for (parent = GetParent(); parent && parent != bindingParent;
|
2010-09-19 05:47:15 +04:00
|
|
|
prev = parent, parent = parent->GetParent()) {
|
2013-02-08 20:34:47 +04:00
|
|
|
HTMLFieldSetElement* fieldset =
|
|
|
|
HTMLFieldSetElement::FromContent(parent);
|
2011-09-18 13:22:18 +04:00
|
|
|
if (fieldset &&
|
|
|
|
(!prev || fieldset->GetFirstLegend() != prev)) {
|
|
|
|
if (mFieldSet == fieldset) {
|
|
|
|
// We already have the right fieldset;
|
2010-09-19 05:47:15 +04:00
|
|
|
return;
|
|
|
|
}
|
2011-09-18 13:22:18 +04:00
|
|
|
|
|
|
|
if (mFieldSet) {
|
|
|
|
mFieldSet->RemoveElement(this);
|
|
|
|
}
|
|
|
|
mFieldSet = fieldset;
|
|
|
|
fieldset->AddElement(this);
|
|
|
|
|
|
|
|
// The disabled state may have changed
|
|
|
|
FieldSetDisabledChanged(aNotify);
|
|
|
|
return;
|
2010-09-19 01:33:16 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// No fieldset found.
|
2010-11-05 20:15:05 +03:00
|
|
|
if (mFieldSet) {
|
2011-09-18 13:22:18 +04:00
|
|
|
mFieldSet->RemoveElement(this);
|
2012-07-30 18:20:58 +04:00
|
|
|
mFieldSet = nullptr;
|
2011-06-01 05:46:57 +04:00
|
|
|
// The disabled state may have changed
|
|
|
|
FieldSetDisabledChanged(aNotify);
|
2010-11-05 20:15:05 +03:00
|
|
|
}
|
2010-09-19 01:33:16 +04:00
|
|
|
}
|
|
|
|
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
void nsGenericHTMLFormElement::UpdateDisabledState(bool aNotify)
|
|
|
|
{
|
|
|
|
if (!CanBeDisabled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDisabled = HasAttr(kNameSpaceID_None, nsGkAtoms::disabled);
|
|
|
|
|
|
|
|
if (!isDisabled && mFieldSet) {
|
|
|
|
isDisabled = mFieldSet->IsDisabled();
|
|
|
|
}
|
|
|
|
|
|
|
|
EventStates disabledStates;
|
|
|
|
if (isDisabled) {
|
|
|
|
disabledStates |= NS_EVENT_STATE_DISABLED;
|
|
|
|
} else {
|
|
|
|
disabledStates |= NS_EVENT_STATE_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventStates oldDisabledStates = State() & DISABLED_STATES;
|
|
|
|
EventStates changedStates = disabledStates ^ oldDisabledStates;
|
|
|
|
|
2017-08-03 08:27:00 +03:00
|
|
|
if (!changedStates.IsEmpty()) {
|
|
|
|
ToggleStates(changedStates, aNotify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::UpdateRequiredState(bool aIsRequired, bool aNotify)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG
|
|
|
|
int32_t type = ControlType();
|
|
|
|
#endif
|
|
|
|
MOZ_ASSERT((type & NS_FORM_INPUT_ELEMENT) ||
|
|
|
|
type == NS_FORM_SELECT ||
|
|
|
|
type == NS_FORM_TEXTAREA,
|
|
|
|
"This should be called only on types that @required applies");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
HTMLInputElement* input = HTMLInputElement::FromContent(this);
|
|
|
|
if (input) {
|
|
|
|
MOZ_ASSERT(input->DoesRequiredApply(),
|
|
|
|
"This should be called only on input types that @required applies");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
EventStates requiredStates;
|
|
|
|
if (aIsRequired) {
|
|
|
|
requiredStates |= NS_EVENT_STATE_REQUIRED;
|
|
|
|
} else {
|
|
|
|
requiredStates |= NS_EVENT_STATE_OPTIONAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
EventStates oldRequiredStates = State() & REQUIRED_STATES;
|
|
|
|
EventStates changedStates = requiredStates ^ oldRequiredStates;
|
|
|
|
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
if (!changedStates.IsEmpty()) {
|
|
|
|
ToggleStates(changedStates, aNotify);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-19 01:33:16 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLFormElement::FieldSetDisabledChanged(bool aNotify)
|
2010-09-19 01:33:16 +04:00
|
|
|
{
|
Bug 1375599 - Change IsDisabled() to look at NS_EVENT_STATE_DISABLED instead of the "disabled" attribute. r=bz
In order to speed up IsDisabled(), instead of querying for the @disabled
attribute, we're now using the NS_EVENT_STATE_DISABLED flag to know whether an
element is disabled.
It is safe to use the NS_EVENT_STATE_DISABLED flag for the following reasons:
- For form elements, nsGenericHTMLFormElement::IsDisabled() is only called on
form elements that can be disabled; form elements that can't be disabled
overrides IsDisabled() to return false directly.
And, before this patch, NS_EVENT_STATE_DISABLED flag is set by
nsGenericHTMLFormElement::IntrinsicState() if and only if IsDisabled() in all
cases when CanBeDisabled() is true, and when CanBeDisabled() is false then
IsDisabled() is always false and the flag is not set.
- For non form elements, optgroup and option have the flag matching
IsDisabled(). Note that option's IsDisabled() should also refer to optgroup's
(if it exists) disabled state, which was not done before this patch.
For this to work correctly, we need to set NS_EVENT_STATE_DISABLED earlier,
that is, in AfterSetAttr(), before any consumer of IsDisabled().
We also need to update the flag whenever the element's parent (e.g. fieldset or
optgroup) disabled state changes and when moving into/out of a parent
container.
Note that NS_EVENT_STATE_DISABLED/ENABLED is now part of the
EXTERNALLY_MANAGED_STATES.
MozReview-Commit-ID: KSceikeqvvU
2017-07-20 09:15:00 +03:00
|
|
|
UpdateDisabledState(aNotify);
|
2010-09-19 01:33:16 +04:00
|
|
|
}
|
|
|
|
|
2012-06-07 22:41:23 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLFormElement::IsLabelable() const
|
|
|
|
{
|
|
|
|
// TODO: keygen should be in that list, see bug 101019.
|
2017-04-01 05:49:00 +03:00
|
|
|
uint32_t type = ControlType();
|
2014-06-10 05:51:00 +04:00
|
|
|
return (type & NS_FORM_INPUT_ELEMENT && type != NS_FORM_INPUT_HIDDEN) ||
|
2012-06-07 22:41:23 +04:00
|
|
|
type & NS_FORM_BUTTON_ELEMENT ||
|
|
|
|
// type == NS_FORM_KEYGEN ||
|
|
|
|
type == NS_FORM_OUTPUT ||
|
|
|
|
type == NS_FORM_SELECT ||
|
|
|
|
type == NS_FORM_TEXTAREA;
|
|
|
|
}
|
|
|
|
|
2017-07-17 09:17:19 +03:00
|
|
|
void
|
|
|
|
nsGenericHTMLFormElement::GetFormAction(nsString& aValue)
|
|
|
|
{
|
|
|
|
uint32_t type = ControlType();
|
|
|
|
if (!(type & NS_FORM_INPUT_ELEMENT) && !(type & NS_FORM_BUTTON_ELEMENT)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::formaction, aValue) ||
|
|
|
|
aValue.IsEmpty()) {
|
|
|
|
nsIDocument* document = OwnerDoc();
|
|
|
|
nsIURI* docURI = document->GetDocumentURI();
|
|
|
|
if (docURI) {
|
|
|
|
nsAutoCString spec;
|
|
|
|
nsresult rv = docURI->GetSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
CopyUTF8toUTF16(spec, aValue);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
GetURIAttr(nsGkAtoms::formaction, nullptr, aValue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-04-13 02:47:24 +04:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
2012-10-06 11:19:52 +04:00
|
|
|
void
|
2016-11-15 08:18:33 +03:00
|
|
|
nsGenericHTMLElement::Click(CallerType aCallerType)
|
2011-04-11 20:56:37 +04:00
|
|
|
{
|
2013-06-08 12:54:59 +04:00
|
|
|
if (HandlingClick())
|
2012-10-06 11:19:52 +04:00
|
|
|
return;
|
2011-04-11 20:56:37 +04:00
|
|
|
|
|
|
|
// Strong in case the event kills it
|
2014-08-06 03:23:02 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetComposedDoc();
|
2011-04-11 20:56:37 +04:00
|
|
|
|
2011-11-16 11:50:19 +04:00
|
|
|
nsCOMPtr<nsIPresShell> shell;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsPresContext> context;
|
2011-04-11 20:56:37 +04:00
|
|
|
if (doc) {
|
|
|
|
shell = doc->GetShell();
|
|
|
|
if (shell) {
|
|
|
|
context = shell->GetPresContext();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-08 12:54:59 +04:00
|
|
|
SetHandlingClick();
|
2011-04-11 20:56:37 +04:00
|
|
|
|
2016-11-15 08:18:33 +03:00
|
|
|
// Mark this event trusted if Click() is called from system code.
|
|
|
|
WidgetMouseEvent event(aCallerType == CallerType::System,
|
2015-08-29 02:58:32 +03:00
|
|
|
eMouseClick, nullptr, WidgetMouseEvent::eReal);
|
2017-03-23 13:57:44 +03:00
|
|
|
event.mFlags.mIsPositionless = true;
|
2011-08-26 11:43:56 +04:00
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_UNKNOWN;
|
2011-04-11 20:56:37 +04:00
|
|
|
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), context, &event);
|
2011-04-11 20:56:37 +04:00
|
|
|
|
2013-06-08 12:54:59 +04:00
|
|
|
ClearHandlingClick();
|
2011-04-11 20:56:37 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsGenericHTMLElement::IsHTMLFocusable(bool aWithMouse,
|
|
|
|
bool *aIsFocusable,
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t *aTabIndex)
|
2004-07-25 01:12:43 +04:00
|
|
|
{
|
2014-08-06 03:23:02 +04:00
|
|
|
nsIDocument* doc = GetComposedDoc();
|
2008-02-26 17:09:52 +03:00
|
|
|
if (!doc || doc->HasFlag(NODE_IS_EDITABLE)) {
|
|
|
|
// In designMode documents we only allow focusing the document.
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = -1;
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aIsFocusable = false;
|
2008-04-15 22:40:38 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2008-02-26 17:09:52 +03:00
|
|
|
}
|
|
|
|
|
2012-11-11 03:30:15 +04:00
|
|
|
int32_t tabIndex = TabIndex();
|
2016-03-18 08:47:50 +03:00
|
|
|
bool disabled = false;
|
|
|
|
bool disallowOverridingFocusability = true;
|
2004-07-30 17:00:36 +04:00
|
|
|
|
2007-06-28 06:48:16 +04:00
|
|
|
if (IsEditableRoot()) {
|
2008-04-15 22:40:38 +04:00
|
|
|
// Editable roots should always be focusable.
|
2016-03-18 08:47:50 +03:00
|
|
|
disallowOverridingFocusability = true;
|
2008-04-15 22:40:38 +04:00
|
|
|
|
2007-07-13 18:17:35 +04:00
|
|
|
// Ignore the disabled attribute in editable contentEditable/designMode
|
|
|
|
// roots.
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)) {
|
2007-07-13 18:17:35 +04:00
|
|
|
// The default value for tabindex should be 0 for editable
|
|
|
|
// contentEditable roots.
|
2007-06-28 06:48:16 +04:00
|
|
|
tabIndex = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2016-03-18 08:47:50 +03:00
|
|
|
disallowOverridingFocusability = false;
|
2008-04-15 22:40:38 +04:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
// Just check for disabled attribute on form controls
|
2010-09-19 01:33:16 +04:00
|
|
|
disabled = IsDisabled();
|
2007-06-28 06:48:16 +04:00
|
|
|
if (disabled) {
|
|
|
|
tabIndex = -1;
|
|
|
|
}
|
2004-07-25 01:12:43 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (aTabIndex) {
|
|
|
|
*aTabIndex = tabIndex;
|
|
|
|
}
|
2004-07-07 04:58:57 +04:00
|
|
|
|
2004-07-30 17:00:36 +04:00
|
|
|
// If a tabindex is specified at all, or the default tabindex is 0, we're focusable
|
2016-03-18 08:47:50 +03:00
|
|
|
*aIsFocusable =
|
2010-06-21 16:37:34 +04:00
|
|
|
(tabIndex >= 0 || (!disabled && HasAttr(kNameSpaceID_None, nsGkAtoms::tabindex)));
|
2008-04-15 22:40:38 +04:00
|
|
|
|
2016-03-18 08:47:50 +03:00
|
|
|
return disallowOverridingFocusability;
|
2004-07-07 04:58:57 +04:00
|
|
|
}
|
|
|
|
|
2004-04-13 03:30:01 +04:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLElement::RegUnRegAccessKey(bool aDoReg)
|
2002-05-22 04:14:51 +04:00
|
|
|
{
|
|
|
|
// first check to see if we have an access key
|
|
|
|
nsAutoString accessKey;
|
2006-12-26 20:47:52 +03:00
|
|
|
GetAttr(kNameSpaceID_None, nsGkAtoms::accesskey, accessKey);
|
2005-10-28 15:25:24 +04:00
|
|
|
if (accessKey.IsEmpty()) {
|
2004-04-13 03:30:01 +04:00
|
|
|
return;
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
// We have an access key, so get the ESM from the pres context.
|
2014-08-23 00:11:27 +04:00
|
|
|
nsPresContext* presContext = GetPresContext(eForUncomposedDoc);
|
2002-05-22 04:14:51 +04:00
|
|
|
|
2004-04-13 03:30:01 +04:00
|
|
|
if (presContext) {
|
2014-04-01 08:09:23 +04:00
|
|
|
EventStateManager* esm = presContext->EventStateManager();
|
2002-05-22 04:14:51 +04:00
|
|
|
|
2004-04-13 03:30:01 +04:00
|
|
|
// Register or unregister as appropriate.
|
|
|
|
if (aDoReg) {
|
2012-08-22 19:56:38 +04:00
|
|
|
esm->RegisterAccessKey(this, (uint32_t)accessKey.First());
|
2004-04-13 03:30:01 +04:00
|
|
|
} else {
|
2012-08-22 19:56:38 +04:00
|
|
|
esm->UnregisterAccessKey(this, (uint32_t)accessKey.First());
|
2004-04-13 03:30:01 +04:00
|
|
|
}
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-09-18 15:18:42 +03:00
|
|
|
bool
|
2011-09-29 10:19:26 +04:00
|
|
|
nsGenericHTMLElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-02-13 18:02:57 +03:00
|
|
|
{
|
2014-08-23 00:11:27 +04:00
|
|
|
nsPresContext* presContext = GetPresContext(eForUncomposedDoc);
|
2015-09-18 15:18:42 +03:00
|
|
|
if (!presContext) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-13 18:02:57 +03:00
|
|
|
|
|
|
|
// It's hard to say what HTML4 wants us to do in all cases.
|
2015-09-18 15:18:42 +03:00
|
|
|
bool focused = true;
|
|
|
|
nsFocusManager* fm = nsFocusManager::GetFocusManager();
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
if (fm) {
|
2013-08-08 00:23:08 +04:00
|
|
|
fm->SetFocus(this, nsIFocusManager::FLAG_BYKEY);
|
2015-09-18 15:18:42 +03:00
|
|
|
|
|
|
|
// Return true if the element became the current focus within its window.
|
2016-01-30 20:05:36 +03:00
|
|
|
nsPIDOMWindowOuter* window = OwnerDoc()->GetWindow();
|
2015-09-18 15:18:42 +03:00
|
|
|
focused = (window && window->GetFocusedNode());
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 22:00:39 +04:00
|
|
|
}
|
2007-02-13 18:02:57 +03:00
|
|
|
|
|
|
|
if (aKeyCausesActivation) {
|
|
|
|
// Click on it if the users prefs indicate to do so.
|
|
|
|
nsAutoPopupStatePusher popupStatePusher(aIsTrustedEvent ?
|
|
|
|
openAllowed : openAbused);
|
2016-03-19 15:37:09 +03:00
|
|
|
DispatchSimulatedClick(this, aIsTrustedEvent, presContext);
|
2007-02-13 18:02:57 +03:00
|
|
|
}
|
2015-09-18 15:18:42 +03:00
|
|
|
|
|
|
|
return focused;
|
2007-02-13 18:02:57 +03:00
|
|
|
}
|
|
|
|
|
2016-03-19 15:37:09 +03:00
|
|
|
nsresult
|
|
|
|
nsGenericHTMLElement::DispatchSimulatedClick(nsGenericHTMLElement* aElement,
|
|
|
|
bool aIsTrusted,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
{
|
|
|
|
WidgetMouseEvent event(aIsTrusted, eMouseClick, nullptr,
|
|
|
|
WidgetMouseEvent::eReal);
|
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD;
|
2017-03-23 13:57:44 +03:00
|
|
|
event.mFlags.mIsPositionless = true;
|
2016-03-19 15:37:09 +03:00
|
|
|
return EventDispatcher::Dispatch(ToSupports(aElement), aPresContext, &event);
|
|
|
|
}
|
|
|
|
|
2017-08-07 10:53:59 +03:00
|
|
|
already_AddRefed<TextEditor>
|
2006-07-29 04:04:40 +04:00
|
|
|
nsGenericHTMLElement::GetAssociatedEditor()
|
|
|
|
{
|
|
|
|
// If contenteditable is ever implemented, it might need to do something different here?
|
|
|
|
|
2017-06-22 09:21:31 +03:00
|
|
|
RefPtr<TextEditor> textEditor = GetTextEditorInternal();
|
|
|
|
return textEditor.forget();
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2006-07-29 04:04:40 +04:00
|
|
|
nsGenericHTMLElement::IsCurrentBodyElement()
|
|
|
|
{
|
2011-11-16 11:50:19 +04:00
|
|
|
// TODO Bug 698498: Should this handle the case where GetBody returns a
|
|
|
|
// frameset?
|
2015-03-03 14:08:59 +03:00
|
|
|
if (!IsHTMLElement(nsGkAtoms::body)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLDocument> htmlDocument =
|
2014-10-02 23:07:24 +04:00
|
|
|
do_QueryInterface(GetUncomposedDoc());
|
2006-07-29 04:04:40 +04:00
|
|
|
if (!htmlDocument) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDOMHTMLElement> htmlElement;
|
|
|
|
htmlDocument->GetBody(getter_AddRefs(htmlElement));
|
2013-01-13 01:53:01 +04:00
|
|
|
return htmlElement == static_cast<HTMLBodyElement*>(this);
|
2006-07-29 04:04:40 +04:00
|
|
|
}
|
2006-08-25 04:15:14 +04:00
|
|
|
|
|
|
|
// static
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::SyncEditorsOnSubtree(nsIContent* content)
|
|
|
|
{
|
|
|
|
/* Sync this node */
|
|
|
|
nsGenericHTMLElement* element = FromContent(content);
|
|
|
|
if (element) {
|
2017-08-07 10:53:59 +03:00
|
|
|
RefPtr<TextEditor> textEditor = element->GetAssociatedEditor();
|
|
|
|
if (textEditor) {
|
|
|
|
textEditor->SyncRealTimeSpell();
|
2006-08-25 04:15:14 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sync all children */
|
2011-09-27 11:54:58 +04:00
|
|
|
for (nsIContent* child = content->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
|
|
|
SyncEditorsOnSubtree(child);
|
2006-08-25 04:15:14 +04:00
|
|
|
}
|
|
|
|
}
|
2006-10-07 14:27:45 +04:00
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::RecompileScriptEventListeners()
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t i, count = mAttrsAndChildren.AttrCount();
|
2006-10-07 14:27:45 +04:00
|
|
|
for (i = 0; i < count; ++i) {
|
|
|
|
const nsAttrName *name = mAttrsAndChildren.AttrNameAt(i);
|
|
|
|
|
|
|
|
// Eventlistenener-attributes are always in the null namespace
|
|
|
|
if (!name->IsAtom()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom *attr = name->Atom();
|
2013-01-03 00:24:07 +04:00
|
|
|
if (!IsEventAttributeName(attr)) {
|
2006-10-07 14:27:45 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoString value;
|
|
|
|
GetAttr(kNameSpaceID_None, attr, value);
|
2012-08-30 20:25:10 +04:00
|
|
|
SetEventHandler(attr, value, true);
|
2006-10-07 14:27:45 +04:00
|
|
|
}
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2007-06-28 06:48:16 +04:00
|
|
|
nsGenericHTMLElement::IsEditableRoot() const
|
|
|
|
{
|
2014-10-02 23:07:24 +04:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!document) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (document->HasFlag(NODE_IS_EDITABLE)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
2007-07-13 18:17:35 +04:00
|
|
|
if (GetContentEditableValue() != eTrue) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent *parent = GetParent();
|
|
|
|
|
|
|
|
return !parent || !parent->HasFlag(NODE_IS_EDITABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
MakeContentDescendantsEditable(nsIContent *aContent, nsIDocument *aDocument)
|
|
|
|
{
|
2011-06-01 05:46:56 +04:00
|
|
|
// If aContent is not an element, we just need to update its
|
|
|
|
// internal editable state and don't need to notify anyone about
|
|
|
|
// that. For elements, we need to send a ContentStateChanged
|
|
|
|
// notification.
|
|
|
|
if (!aContent->IsElement()) {
|
2011-10-17 18:59:28 +04:00
|
|
|
aContent->UpdateEditableState(false);
|
2011-06-01 05:46:56 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Element *element = aContent->AsElement();
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
element->UpdateEditableState(true);
|
2007-06-28 06:48:16 +04:00
|
|
|
|
2011-06-01 05:46:56 +04:00
|
|
|
for (nsIContent *child = aContent->GetFirstChild();
|
|
|
|
child;
|
|
|
|
child = child->GetNextSibling()) {
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!child->HasAttr(kNameSpaceID_None, nsGkAtoms::contenteditable)) {
|
|
|
|
MakeContentDescendantsEditable(child, aDocument);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-08-22 19:56:38 +04:00
|
|
|
nsGenericHTMLElement::ChangeEditableState(int32_t aChange)
|
2007-06-28 06:48:16 +04:00
|
|
|
{
|
2014-10-02 23:07:24 +04:00
|
|
|
//XXXsmaug Fix this for Shadow DOM, bug 1066965.
|
|
|
|
nsIDocument* document = GetUncomposedDoc();
|
2007-06-28 06:48:16 +04:00
|
|
|
if (!document) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aChange != 0) {
|
|
|
|
nsCOMPtr<nsIHTMLDocument> htmlDocument =
|
|
|
|
do_QueryInterface(document);
|
|
|
|
if (htmlDocument) {
|
|
|
|
htmlDocument->ChangeContentEditableCount(this, aChange);
|
|
|
|
}
|
2015-08-14 20:52:38 +03:00
|
|
|
|
|
|
|
nsIContent* parent = GetParent();
|
|
|
|
while (parent) {
|
|
|
|
parent->ChangeEditableDescendantCount(aChange);
|
|
|
|
parent = parent->GetParent();
|
|
|
|
}
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (document->HasFlag(NODE_IS_EDITABLE)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
document = nullptr;
|
2007-06-28 06:48:16 +04:00
|
|
|
}
|
|
|
|
|
2011-03-29 07:32:11 +04:00
|
|
|
// MakeContentDescendantsEditable is going to call ContentStateChanged for
|
2010-09-08 21:43:28 +04:00
|
|
|
// this element and all descendants if editable state has changed.
|
2011-06-01 01:38:25 +04:00
|
|
|
// We might as well wrap it all in one script blocker.
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
2007-06-28 06:48:16 +04:00
|
|
|
MakeContentDescendantsEditable(this, document);
|
|
|
|
}
|
2012-06-05 03:49:57 +04:00
|
|
|
|
2013-08-02 05:21:31 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsGenericHTMLFormElementWithState::nsGenericHTMLFormElementWithState(
|
2017-04-01 05:49:00 +03:00
|
|
|
already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo, uint8_t aType
|
2013-08-02 05:21:31 +04:00
|
|
|
)
|
2017-04-01 05:49:00 +03:00
|
|
|
: nsGenericHTMLFormElement(aNodeInfo, aType)
|
2013-08-02 05:21:31 +04:00
|
|
|
{
|
|
|
|
mStateKey.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsGenericHTMLFormElementWithState::GenerateStateKey()
|
|
|
|
{
|
|
|
|
// Keep the key if already computed
|
|
|
|
if (!mStateKey.IsVoid()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-08-23 00:11:27 +04:00
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2013-08-02 05:21:31 +04:00
|
|
|
if (!doc) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Generate the state key
|
|
|
|
nsresult rv = nsContentUtils::GenerateStateKey(this, doc, mStateKey);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
mStateKey.SetIsVoid(true);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the state key is blank, this is anonymous content or for whatever
|
|
|
|
// reason we are not supposed to save/restore state: keep it as such.
|
|
|
|
if (!mStateKey.IsEmpty()) {
|
|
|
|
// Add something unique to content so layout doesn't muck us up.
|
|
|
|
mStateKey += "-C";
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresState*
|
|
|
|
nsGenericHTMLFormElementWithState::GetPrimaryPresState()
|
|
|
|
{
|
|
|
|
if (mStateKey.IsEmpty()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> history = GetLayoutHistory(false);
|
|
|
|
|
|
|
|
if (!history) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the pres state for this key, if it doesn't exist, create one.
|
|
|
|
nsPresState* result = history->GetState(mStateKey);
|
|
|
|
if (!result) {
|
|
|
|
result = new nsPresState();
|
|
|
|
history->AddState(mStateKey, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
already_AddRefed<nsILayoutHistoryState>
|
|
|
|
nsGenericHTMLFormElementWithState::GetLayoutHistory(bool aRead)
|
|
|
|
{
|
2014-08-23 00:11:27 +04:00
|
|
|
nsCOMPtr<nsIDocument> doc = GetUncomposedDoc();
|
2013-08-02 05:21:31 +04:00
|
|
|
if (!doc) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Get the history
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> history = doc->GetLayoutHistoryState();
|
|
|
|
if (!history) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (aRead && !history->HasStates()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return history.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
nsGenericHTMLFormElementWithState::RestoreFormControlState()
|
|
|
|
{
|
|
|
|
if (mStateKey.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsILayoutHistoryState> history =
|
|
|
|
GetLayoutHistory(true);
|
|
|
|
if (!history) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsPresState *state;
|
|
|
|
// Get the pres state for this key
|
|
|
|
state = history->GetState(mStateKey);
|
|
|
|
if (state) {
|
|
|
|
bool result = RestoreState(state);
|
|
|
|
history->RemoveState(mStateKey);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-02-23 04:19:04 +03:00
|
|
|
nsGenericHTMLFormElementWithState::NodeInfoChanged(nsIDocument* aOldDoc)
|
2013-08-02 05:21:31 +04:00
|
|
|
{
|
2017-03-25 01:28:19 +03:00
|
|
|
nsGenericHTMLElement::NodeInfoChanged(aOldDoc);
|
2013-08-02 05:21:31 +04:00
|
|
|
mStateKey.SetIsVoid(true);
|
|
|
|
}
|
|
|
|
|
2012-06-27 09:17:31 +04:00
|
|
|
nsSize
|
2015-10-18 08:24:48 +03:00
|
|
|
nsGenericHTMLElement::GetWidthHeightForImage(RefPtr<imgRequestProxy>& aImageRequest)
|
2012-06-27 09:17:31 +04:00
|
|
|
{
|
|
|
|
nsSize size(0,0);
|
|
|
|
|
2017-01-05 10:31:56 +03:00
|
|
|
nsIFrame* frame = GetPrimaryFrame(FlushType::Layout);
|
2012-06-27 09:17:31 +04:00
|
|
|
|
|
|
|
if (frame) {
|
|
|
|
size = frame->GetContentRect().Size();
|
|
|
|
|
|
|
|
size.width = nsPresContext::AppUnitsToIntCSSPixels(size.width);
|
|
|
|
size.height = nsPresContext::AppUnitsToIntCSSPixels(size.height);
|
|
|
|
} else {
|
|
|
|
const nsAttrValue* value;
|
|
|
|
nsCOMPtr<imgIContainer> image;
|
|
|
|
if (aImageRequest) {
|
|
|
|
aImageRequest->GetImage(getter_AddRefs(image));
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = GetParsedAttr(nsGkAtoms::width)) &&
|
|
|
|
value->Type() == nsAttrValue::eInteger) {
|
|
|
|
size.width = value->GetIntegerValue();
|
|
|
|
} else if (image) {
|
|
|
|
image->GetWidth(&size.width);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((value = GetParsedAttr(nsGkAtoms::height)) &&
|
|
|
|
value->Type() == nsAttrValue::eInteger) {
|
|
|
|
size.height = value->GetIntegerValue();
|
|
|
|
} else if (image) {
|
|
|
|
image->GetHeight(&size.height);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_ASSERTION(size.width >= 0, "negative width");
|
|
|
|
NS_ASSERTION(size.height >= 0, "negative height");
|
|
|
|
return size;
|
|
|
|
}
|
2013-01-03 00:24:07 +04:00
|
|
|
|
|
|
|
bool
|
2017-07-04 23:54:30 +03:00
|
|
|
nsGenericHTMLElement::IsEventAttributeNameInternal(nsIAtom *aName)
|
2013-01-03 00:24:07 +04:00
|
|
|
{
|
|
|
|
return nsContentUtils::IsEventAttributeName(aName, EventNameType_HTML);
|
|
|
|
}
|
2013-05-21 20:14:00 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Construct a URI from a string, as an element.src attribute
|
|
|
|
* would be set to. Helper for the media elements.
|
|
|
|
*/
|
|
|
|
nsresult
|
2015-05-22 08:12:13 +03:00
|
|
|
nsGenericHTMLElement::NewURIFromString(const nsAString& aURISpec,
|
2013-05-21 20:14:00 +04:00
|
|
|
nsIURI** aURI)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(aURI);
|
|
|
|
|
|
|
|
*aURI = nullptr;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIDocument> doc = OwnerDoc();
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> baseURI = GetBaseURI();
|
|
|
|
nsresult rv = nsContentUtils::NewURIWithDocumentCharset(aURI, aURISpec,
|
|
|
|
doc, baseURI);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
bool equal;
|
|
|
|
if (aURISpec.IsEmpty() &&
|
|
|
|
doc->GetDocumentURI() &&
|
|
|
|
NS_SUCCEEDED(doc->GetDocumentURI()->Equals(*aURI, &equal)) &&
|
|
|
|
equal) {
|
|
|
|
// Assume an element can't point to a fragment of its embedding
|
|
|
|
// document. Fail here instead of returning the recursive URI
|
|
|
|
// and waiting for the subsequent load to fail.
|
|
|
|
NS_RELEASE(*aURI);
|
|
|
|
return NS_ERROR_DOM_INVALID_STATE_ERR;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-10-30 08:37:03 +03:00
|
|
|
|
2015-11-20 07:14:57 +03:00
|
|
|
static bool
|
|
|
|
IsOrHasAncestorWithDisplayNone(Element* aElement, nsIPresShell* aPresShell)
|
|
|
|
{
|
2017-07-30 05:12:34 +03:00
|
|
|
AutoTArray<Element*, 10> elementsToCheck;
|
2017-07-30 05:14:32 +03:00
|
|
|
// Style and layout work on the flattened tree, so this is what we need to
|
|
|
|
// check in order to figure out whether we're in a display: none subtree.
|
|
|
|
for (Element* e = aElement; e; e = e->GetFlattenedTreeParentElement()) {
|
2015-11-20 07:14:57 +03:00
|
|
|
if (e->GetPrimaryFrame()) {
|
|
|
|
// e definitely isn't display:none and doesn't have a display:none
|
|
|
|
// ancestor.
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
elementsToCheck.AppendElement(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (elementsToCheck.IsEmpty()) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-02-24 10:01:11 +03:00
|
|
|
StyleSetHandle styleSet = aPresShell->StyleSet();
|
2015-11-20 07:14:57 +03:00
|
|
|
RefPtr<nsStyleContext> sc;
|
2017-07-30 05:13:48 +03:00
|
|
|
for (auto* element : Reversed(elementsToCheck)) {
|
2015-11-20 07:14:57 +03:00
|
|
|
if (sc) {
|
2017-08-04 12:26:04 +03:00
|
|
|
if (styleSet->IsGecko()) {
|
|
|
|
sc = styleSet->ResolveStyleFor(element, sc,
|
|
|
|
LazyComputeBehavior::Assert);
|
|
|
|
} else {
|
|
|
|
// Call ResolveStyleLazily to protect against stale element data in
|
|
|
|
// the tree when styled by Servo.
|
|
|
|
sc = styleSet->AsServo()->ResolveStyleLazily(
|
|
|
|
element, CSSPseudoElementType::NotPseudo, nullptr);
|
|
|
|
}
|
2015-11-20 07:14:57 +03:00
|
|
|
} else {
|
2017-07-30 05:13:48 +03:00
|
|
|
sc = nsComputedDOMStyle::GetStyleContextNoFlush(element,
|
2017-04-05 08:39:23 +03:00
|
|
|
nullptr, aPresShell);
|
2015-11-20 07:14:57 +03:00
|
|
|
}
|
2016-09-03 21:46:58 +03:00
|
|
|
if (sc->StyleDisplay()->mDisplay == StyleDisplay::None) {
|
2015-11-20 07:14:57 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-10-30 08:37:03 +03:00
|
|
|
void
|
|
|
|
nsGenericHTMLElement::GetInnerText(mozilla::dom::DOMString& aValue,
|
|
|
|
mozilla::ErrorResult& aError)
|
|
|
|
{
|
2017-01-05 10:31:56 +03:00
|
|
|
if (!GetPrimaryFrame(FlushType::Layout)) {
|
2015-11-20 07:14:57 +03:00
|
|
|
nsIPresShell* presShell = nsComputedDOMStyle::GetPresShellForContent(this);
|
2017-08-05 12:42:08 +03:00
|
|
|
// NOTE(emilio): We need to check the presshell is initialized in order to
|
|
|
|
// ensure the document is styled.
|
2017-08-05 09:55:50 +03:00
|
|
|
if (!presShell || !presShell->DidInitialize() ||
|
|
|
|
IsOrHasAncestorWithDisplayNone(this, presShell)) {
|
2015-10-30 08:37:03 +03:00
|
|
|
GetTextContentInternal(aValue, aError);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsRange::GetInnerTextNoFlush(aValue, aError, this, 0, this, GetChildCount());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsGenericHTMLElement::SetInnerText(const nsAString& aValue)
|
|
|
|
{
|
|
|
|
// Batch possible DOMSubtreeModified events.
|
|
|
|
mozAutoSubtreeModified subtree(OwnerDoc(), nullptr);
|
|
|
|
FireNodeRemovedForChildren();
|
|
|
|
|
|
|
|
// Might as well stick a batch around this since we're performing several
|
|
|
|
// mutations.
|
|
|
|
mozAutoDocUpdate updateBatch(GetComposedDoc(),
|
|
|
|
UPDATE_CONTENT_MODEL, true);
|
|
|
|
nsAutoMutationBatch mb;
|
|
|
|
|
|
|
|
uint32_t childCount = GetChildCount();
|
|
|
|
|
|
|
|
mb.Init(this, true, false);
|
|
|
|
for (uint32_t i = 0; i < childCount; ++i) {
|
|
|
|
RemoveChildAt(0, true);
|
|
|
|
}
|
|
|
|
mb.RemovalDone();
|
|
|
|
|
|
|
|
nsString str;
|
|
|
|
const char16_t* s = aValue.BeginReading();
|
|
|
|
const char16_t* end = aValue.EndReading();
|
|
|
|
while (true) {
|
|
|
|
if (s != end && *s == '\r' && s + 1 != end && s[1] == '\n') {
|
|
|
|
// a \r\n pair should only generate one <br>, so just skip the \r
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
if (s == end || *s == '\r' || *s == '\n') {
|
|
|
|
if (!str.IsEmpty()) {
|
|
|
|
RefPtr<nsTextNode> textContent =
|
|
|
|
new nsTextNode(NodeInfo()->NodeInfoManager());
|
|
|
|
textContent->SetText(str, true);
|
|
|
|
AppendChildTo(textContent, true);
|
|
|
|
}
|
|
|
|
if (s == end) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
str.Truncate();
|
|
|
|
already_AddRefed<mozilla::dom::NodeInfo> ni =
|
|
|
|
NodeInfo()->NodeInfoManager()->GetNodeInfo(nsGkAtoms::br,
|
|
|
|
nullptr, kNameSpaceID_XHTML, nsIDOMNode::ELEMENT_NODE);
|
|
|
|
RefPtr<HTMLBRElement> br = new HTMLBRElement(ni);
|
|
|
|
AppendChildTo(br, true);
|
|
|
|
} else {
|
|
|
|
str.Append(*s);
|
|
|
|
}
|
|
|
|
++s;
|
|
|
|
}
|
|
|
|
|
|
|
|
mb.NodesAdded();
|
|
|
|
}
|