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
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
#include "mozilla/dom/HTMLTableElement.h"
|
2017-01-27 03:51:01 +03:00
|
|
|
#include "mozilla/GenericSpecifiedValuesInlines.h"
|
2012-09-30 20:40:24 +04:00
|
|
|
#include "nsAttrValueInlines.h"
|
2011-08-20 14:18:50 +04:00
|
|
|
#include "nsHTMLStyleSheet.h"
|
2013-02-14 19:33:16 +04:00
|
|
|
#include "nsMappedAttributes.h"
|
2012-12-29 12:08:15 +04:00
|
|
|
#include "mozilla/dom/HTMLCollectionBinding.h"
|
|
|
|
#include "mozilla/dom/HTMLTableElementBinding.h"
|
2013-02-01 03:11:49 +04:00
|
|
|
#include "nsContentUtils.h"
|
2014-04-16 06:58:44 +04:00
|
|
|
#include "jsfriendapi.h"
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Table)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2011-10-11 09:50:08 +04:00
|
|
|
|
1998-11-17 02:31:24 +03:00
|
|
|
/* ------------------------------ TableRowsCollection -------------------------------- */
|
|
|
|
/**
|
|
|
|
* This class provides a late-bound collection of rows in a table.
|
|
|
|
* mParent is NOT ref-counted to avoid circular references
|
|
|
|
*/
|
2017-07-06 23:58:06 +03:00
|
|
|
class TableRowsCollection final : public nsIHTMLCollection
|
|
|
|
, public nsStubMutationObserver
|
|
|
|
, public nsWrapperCache
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
|
|
|
public:
|
2014-09-02 04:49:25 +04:00
|
|
|
explicit TableRowsCollection(HTMLTableElement* aParent);
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTING_ISUPPORTS
|
|
|
|
NS_DECL_NSIDOMHTMLCOLLECTION
|
1998-11-17 02:31:24 +03:00
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_NODEWILLBEDESTROYED
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual Element* GetElementAt(uint32_t aIndex) override;
|
|
|
|
virtual nsINode* GetParentObject() override
|
2011-06-01 01:47:59 +04:00
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
virtual Element*
|
2015-03-21 19:28:04 +03:00
|
|
|
GetFirstNamedElement(const nsAString& aName, bool& aFound) override;
|
2016-05-10 05:25:40 +03:00
|
|
|
virtual void GetSupportedNames(nsTArray<nsString>& aNames) override;
|
2012-09-06 00:49:53 +04:00
|
|
|
|
1998-11-17 02:31:24 +03:00
|
|
|
NS_IMETHOD ParentDestroyed();
|
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_CLASS_AMBIGUOUS(TableRowsCollection, nsIHTMLCollection)
|
2011-06-01 01:47:17 +04:00
|
|
|
|
|
|
|
// nsWrapperCache
|
2013-11-12 19:22:22 +04:00
|
|
|
using nsWrapperCache::GetWrapperPreserveColor;
|
2017-05-17 07:52:53 +03:00
|
|
|
using nsWrapperCache::PreserveWrapper;
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto) override;
|
2013-11-12 19:22:22 +04:00
|
|
|
protected:
|
2017-07-06 23:58:06 +03:00
|
|
|
// Unregister ourselves as a mutation observer, and clear our internal state.
|
|
|
|
void CleanUp();
|
|
|
|
void LastRelease()
|
|
|
|
{
|
|
|
|
CleanUp();
|
|
|
|
}
|
|
|
|
virtual ~TableRowsCollection()
|
|
|
|
{
|
|
|
|
// we do NOT have a ref-counted reference to mParent, so do NOT
|
|
|
|
// release it! this is to avoid circular references. The
|
|
|
|
// instantiator who provided mParent is responsible for managing our
|
|
|
|
// reference for us.
|
|
|
|
CleanUp();
|
|
|
|
}
|
2014-06-25 06:09:15 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
virtual JSObject* GetWrapperPreserveColorInternal() override
|
2011-06-01 01:47:17 +04:00
|
|
|
{
|
2013-11-12 19:22:22 +04:00
|
|
|
return nsWrapperCache::GetWrapperPreserveColor();
|
2011-06-01 01:47:17 +04:00
|
|
|
}
|
2017-05-17 07:52:53 +03:00
|
|
|
virtual void PreserveWrapperInternal(nsISupports* aScriptObjectHolder) override
|
|
|
|
{
|
|
|
|
nsWrapperCache::PreserveWrapper(aScriptObjectHolder);
|
|
|
|
}
|
2007-03-08 14:17:16 +03:00
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
// Ensure that HTMLTableElement is in a valid state. This must be called
|
|
|
|
// before inspecting the mRows object.
|
|
|
|
void EnsureInitialized();
|
|
|
|
|
|
|
|
// Checks if the passed-in container is interesting for the purposes of
|
|
|
|
// invalidation due to a mutation observer.
|
|
|
|
bool InterestingContainer(nsIContent* aContainer);
|
|
|
|
|
|
|
|
// Check if the passed-in nsIContent is a <tr> within the section defined by
|
|
|
|
// `aSection`. The root of the table is considered to be part of the `<tbody>`
|
|
|
|
// section.
|
|
|
|
bool IsAppropriateRow(nsIAtom* aSection, nsIContent* aContent);
|
|
|
|
|
|
|
|
// Scan backwards starting from `aCurrent` in the table, looking for the
|
|
|
|
// previous row in the table which is within the section `aSection`.
|
|
|
|
nsIContent* PreviousRow(nsIAtom* aSection, nsIContent* aCurrent);
|
|
|
|
|
|
|
|
// Handle the insertion of the child `aChild` into the container `aContainer`
|
|
|
|
// within the tree. The container must be an `InterestingContainer`. This
|
|
|
|
// method updates the mRows, mBodyStart, and mFootStart member variables.
|
|
|
|
//
|
|
|
|
// HandleInsert returns an integer which can be passed to the next call of the
|
|
|
|
// method in a loop inserting children into the same container. This will
|
|
|
|
// optimize subsequent insertions to require less work. This can either be -1,
|
|
|
|
// in which case we don't know where to insert the next row, and When passed
|
|
|
|
// to HandleInsert, it will use `PreviousRow` to locate the index to insert.
|
|
|
|
// Or, it can be an index to insert the next <tr> in the same container at.
|
|
|
|
int32_t HandleInsert(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexGuess = -1);
|
|
|
|
|
|
|
|
// The HTMLTableElement which this TableRowsCollection tracks the rows for.
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement* mParent;
|
2017-07-06 23:58:06 +03:00
|
|
|
|
|
|
|
// The current state of the TableRowsCollection. mBodyStart and mFootStart are
|
|
|
|
// indices into mRows which represent the location of the first row in the
|
|
|
|
// body or foot section. If there are no rows in a section, the index points
|
|
|
|
// at the location where the first element in that section would be inserted.
|
|
|
|
nsTArray<nsCOMPtr<nsIContent>> mRows;
|
|
|
|
uint32_t mBodyStart;
|
|
|
|
uint32_t mFootStart;
|
|
|
|
bool mInitialized;
|
1998-11-17 02:31:24 +03:00
|
|
|
};
|
|
|
|
|
1999-10-07 04:35:04 +04:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
TableRowsCollection::TableRowsCollection(HTMLTableElement *aParent)
|
2007-03-08 14:17:16 +03:00
|
|
|
: mParent(aParent)
|
2017-07-06 23:58:06 +03:00
|
|
|
, mBodyStart(0)
|
|
|
|
, mFootStart(0)
|
|
|
|
, mInitialized(false)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
MOZ_ASSERT(mParent);
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
void
|
|
|
|
TableRowsCollection::EnsureInitialized()
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
if (mInitialized) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
mInitialized = true;
|
|
|
|
|
|
|
|
// Initialize mRows as the TableRowsCollection is created. The mutation
|
|
|
|
// observer should keep it up to date.
|
|
|
|
//
|
|
|
|
// It should be extremely unlikely that anyone creates a TableRowsCollection
|
|
|
|
// without calling a method on it, so lazily performing this initialization
|
|
|
|
// seems unnecessary.
|
|
|
|
AutoTArray<nsCOMPtr<nsIContent>, 32> body;
|
|
|
|
AutoTArray<nsCOMPtr<nsIContent>, 32> foot;
|
|
|
|
mRows.Clear();
|
|
|
|
|
|
|
|
auto addRowChildren = [&] (nsTArray<nsCOMPtr<nsIContent>>& aArray, nsIContent* aNode) {
|
|
|
|
for (nsIContent* inner = aNode->nsINode::GetFirstChild();
|
|
|
|
inner; inner = inner->GetNextSibling()) {
|
|
|
|
if (inner->IsHTMLElement(nsGkAtoms::tr)) {
|
|
|
|
aArray.AppendElement(inner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (nsIContent* node = mParent->nsINode::GetFirstChild();
|
|
|
|
node; node = node->GetNextSibling()) {
|
|
|
|
if (node->IsHTMLElement(nsGkAtoms::thead)) {
|
|
|
|
addRowChildren(mRows, node);
|
|
|
|
} else if (node->IsHTMLElement(nsGkAtoms::tbody)) {
|
|
|
|
addRowChildren(body, node);
|
|
|
|
} else if (node->IsHTMLElement(nsGkAtoms::tfoot)) {
|
|
|
|
addRowChildren(foot, node);
|
|
|
|
} else if (node->IsHTMLElement(nsGkAtoms::tr)) {
|
|
|
|
body.AppendElement(node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
mBodyStart = mRows.Length();
|
|
|
|
mRows.AppendElements(Move(body));
|
|
|
|
mFootStart = mRows.Length();
|
|
|
|
mRows.AppendElements(Move(foot));
|
|
|
|
|
|
|
|
mParent->AddMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TableRowsCollection::CleanUp()
|
|
|
|
{
|
|
|
|
// Unregister ourselves as a mutation observer.
|
|
|
|
if (mInitialized && mParent) {
|
|
|
|
mParent->RemoveMutationObserver(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Clean up all of our internal state and make it empty in case someone looks
|
|
|
|
// at us.
|
|
|
|
mRows.Clear();
|
|
|
|
mBodyStart = 0;
|
|
|
|
mFootStart = 0;
|
|
|
|
|
|
|
|
// We set mInitialized to true in case someone still has a reference to us, as
|
|
|
|
// we don't need to try to initialize first.
|
|
|
|
mInitialized = true;
|
|
|
|
mParent = nullptr;
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
2013-11-12 19:22:22 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
TableRowsCollection::WrapObject(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-11-12 19:22:22 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return HTMLCollectionBinding::Wrap(aCx, this, aGivenProto);
|
2013-11-12 19:22:22 +04:00
|
|
|
}
|
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_WRAPPERCACHE(TableRowsCollection, mRows)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_ADDREF(TableRowsCollection)
|
2017-07-06 23:58:06 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTING_RELEASE_WITH_LAST_RELEASE(TableRowsCollection,
|
|
|
|
LastRelease())
|
2007-03-08 14:17:16 +03:00
|
|
|
|
2007-08-21 02:55:06 +04:00
|
|
|
NS_INTERFACE_TABLE_HEAD(TableRowsCollection)
|
2014-08-26 03:21:35 +04:00
|
|
|
NS_WRAPPERCACHE_INTERFACE_TABLE_ENTRY
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_INTERFACE_TABLE(TableRowsCollection, nsIHTMLCollection,
|
2017-07-06 23:58:06 +03:00
|
|
|
nsIDOMHTMLCollection, nsIMutationObserver)
|
2007-08-21 02:55:06 +04:00
|
|
|
NS_INTERFACE_TABLE_TO_MAP_SEGUE_CYCLE_COLLECTION(TableRowsCollection)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2016-05-17 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TableRowsCollection::GetLength(uint32_t* aLength)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
EnsureInitialized();
|
|
|
|
*aLength = mRows.Length();
|
2011-04-25 21:46:51 +04:00
|
|
|
return NS_OK;
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
2012-11-15 02:10:08 +04:00
|
|
|
Element*
|
2012-09-05 19:42:58 +04:00
|
|
|
TableRowsCollection::GetElementAt(uint32_t aIndex)
|
1998-11-17 02:31:24 +03:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
EnsureInitialized();
|
|
|
|
if (aIndex < mRows.Length()) {
|
|
|
|
return mRows[aIndex]->AsElement();
|
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
2016-05-17 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
TableRowsCollection::Item(uint32_t aIndex, nsIDOMNode** aReturn)
|
2008-10-22 18:31:14 +04:00
|
|
|
{
|
2012-09-05 19:42:58 +04:00
|
|
|
nsISupports* node = GetElementAt(aIndex);
|
2008-10-22 18:31:14 +04:00
|
|
|
if (!node) {
|
2012-07-30 18:20:58 +04:00
|
|
|
*aReturn = nullptr;
|
2008-10-22 18:31:14 +04:00
|
|
|
|
2011-04-25 21:46:57 +04:00
|
|
|
return NS_OK;
|
2008-10-22 18:31:14 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
2005-08-15 06:34:21 +04:00
|
|
|
}
|
2004-04-14 08:26:00 +04:00
|
|
|
|
2013-11-11 11:55:41 +04:00
|
|
|
Element*
|
|
|
|
TableRowsCollection::GetFirstNamedElement(const nsAString& aName, bool& aFound)
|
2012-09-06 00:49:53 +04:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
EnsureInitialized();
|
2013-11-11 11:55:41 +04:00
|
|
|
aFound = false;
|
2016-05-17 10:08:00 +03:00
|
|
|
nsCOMPtr<nsIAtom> nameAtom = NS_Atomize(aName);
|
|
|
|
NS_ENSURE_TRUE(nameAtom, nullptr);
|
2017-07-06 23:58:06 +03:00
|
|
|
|
|
|
|
for (auto& node : mRows) {
|
|
|
|
if (node->AttrValueIs(kNameSpaceID_None, nsGkAtoms::name,
|
|
|
|
nameAtom, eCaseMatters) ||
|
|
|
|
node->AttrValueIs(kNameSpaceID_None, nsGkAtoms::id,
|
|
|
|
nameAtom, eCaseMatters)) {
|
2016-05-17 10:08:00 +03:00
|
|
|
aFound = true;
|
2017-07-06 23:58:06 +03:00
|
|
|
return node->AsElement();
|
2016-05-17 10:08:00 +03:00
|
|
|
}
|
2017-07-06 23:58:06 +03:00
|
|
|
}
|
2016-05-17 10:08:00 +03:00
|
|
|
|
2012-09-06 00:49:53 +04:00
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
|
2012-11-05 20:58:03 +04:00
|
|
|
void
|
2016-05-10 05:25:40 +03:00
|
|
|
TableRowsCollection::GetSupportedNames(nsTArray<nsString>& aNames)
|
2012-11-05 20:58:03 +04:00
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
EnsureInitialized();
|
|
|
|
for (auto& node : mRows) {
|
|
|
|
if (node->HasID()) {
|
|
|
|
nsIAtom* idAtom = node->GetID();
|
2016-05-17 10:08:00 +03:00
|
|
|
MOZ_ASSERT(idAtom != nsGkAtoms::_empty,
|
|
|
|
"Empty ids don't get atomized");
|
|
|
|
nsDependentAtomString idStr(idAtom);
|
|
|
|
if (!aNames.Contains(idStr)) {
|
|
|
|
aNames.AppendElement(idStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
nsGenericHTMLElement* el = nsGenericHTMLElement::FromContent(node);
|
2016-05-17 10:08:00 +03:00
|
|
|
if (el) {
|
|
|
|
const nsAttrValue* val = el->GetParsedAttr(nsGkAtoms::name);
|
|
|
|
if (val && val->Type() == nsAttrValue::eAtom) {
|
|
|
|
nsIAtom* nameAtom = val->GetAtomValue();
|
|
|
|
MOZ_ASSERT(nameAtom != nsGkAtoms::_empty,
|
|
|
|
"Empty names don't get atomized");
|
|
|
|
nsDependentAtomString nameStr(nameAtom);
|
|
|
|
if (!aNames.Contains(nameStr)) {
|
|
|
|
aNames.AppendElement(nameStr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-07-06 23:58:06 +03:00
|
|
|
}
|
2012-11-05 20:58:03 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-05-17 09:54:00 +03:00
|
|
|
NS_IMETHODIMP
|
2008-11-01 00:40:35 +03:00
|
|
|
TableRowsCollection::NamedItem(const nsAString& aName,
|
|
|
|
nsIDOMNode** aReturn)
|
|
|
|
{
|
2016-05-17 10:08:00 +03:00
|
|
|
bool found;
|
|
|
|
nsISupports* node = GetFirstNamedElement(aName, found);
|
|
|
|
if (!node) {
|
|
|
|
*aReturn = nullptr;
|
2008-11-01 00:40:35 +03:00
|
|
|
|
2016-05-17 10:08:00 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
return CallQueryInterface(node, aReturn);
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TableRowsCollection::ParentDestroyed()
|
|
|
|
{
|
2017-07-06 23:58:06 +03:00
|
|
|
CleanUp();
|
1998-11-17 02:31:24 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-07-06 23:58:06 +03:00
|
|
|
bool
|
|
|
|
TableRowsCollection::InterestingContainer(nsIContent* aContainer)
|
|
|
|
{
|
|
|
|
return mParent && aContainer &&
|
|
|
|
(aContainer == mParent ||
|
|
|
|
(aContainer->GetParent() == mParent &&
|
|
|
|
aContainer->IsAnyOfHTMLElements(nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tfoot)));
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
TableRowsCollection::IsAppropriateRow(nsIAtom* aSection, nsIContent* aContent)
|
|
|
|
{
|
|
|
|
if (!aContent->IsHTMLElement(nsGkAtoms::tr)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// If it's in the root, then we consider it to be in a tbody.
|
|
|
|
nsIContent* parent = aContent->GetParent();
|
|
|
|
if (aSection == nsGkAtoms::tbody && parent == mParent) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return parent->IsHTMLElement(aSection);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
|
|
|
TableRowsCollection::PreviousRow(nsIAtom* aSection, nsIContent* aCurrent)
|
|
|
|
{
|
|
|
|
// Keep going backwards until we've found a `tr` element. We want to always
|
|
|
|
// run at least once, as we don't want to find ourselves.
|
|
|
|
//
|
|
|
|
// Each spin of the loop we step backwards one element. If we're at the top of
|
|
|
|
// a section, we step out of it into the root, and if we step onto a section
|
|
|
|
// matching `aSection`, we step into it. We keep spinning the loop until
|
|
|
|
// either we reach the first element in mParent, or find a <tr> in an
|
|
|
|
// appropriate section.
|
|
|
|
nsIContent* prev = aCurrent;
|
|
|
|
do {
|
|
|
|
nsIContent* parent = prev->GetParent();
|
|
|
|
prev = prev->GetPreviousSibling();
|
|
|
|
|
|
|
|
// Ascend out of any sections we're currently in, if we've run out of
|
|
|
|
// elements.
|
|
|
|
if (!prev && parent != mParent) {
|
|
|
|
prev = parent->GetPreviousSibling();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Descend into a section if we stepped onto one.
|
|
|
|
if (prev && prev->GetParent() == mParent && prev->IsHTMLElement(aSection)) {
|
|
|
|
prev = prev->GetLastChild();
|
|
|
|
}
|
|
|
|
} while (prev && !IsAppropriateRow(aSection, prev));
|
|
|
|
return prev;
|
|
|
|
}
|
|
|
|
|
|
|
|
int32_t
|
|
|
|
TableRowsCollection::HandleInsert(nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexGuess)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsInSameAnonymousTree(mParent, aChild)) {
|
|
|
|
return aIndexGuess; // Nothing inserted, guess hasn't changed.
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're adding a section to the root, add each of the rows in that section
|
|
|
|
// individually.
|
|
|
|
if (aContainer == mParent &&
|
|
|
|
aChild->IsAnyOfHTMLElements(nsGkAtoms::thead,
|
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tfoot)) {
|
|
|
|
// If we're entering a tbody, we can persist the index guess we were passed,
|
|
|
|
// as the newly added items are in the same section as us, however, if we're
|
|
|
|
// entering thead or tfoot we will have to re-scan.
|
|
|
|
bool isTBody = aChild->IsHTMLElement(nsGkAtoms::tbody);
|
|
|
|
int32_t indexGuess = isTBody ? aIndexGuess : -1;
|
|
|
|
|
|
|
|
for (nsIContent* inner = aChild->GetFirstChild();
|
|
|
|
inner; inner = inner->GetNextSibling()) {
|
|
|
|
indexGuess = HandleInsert(aChild, inner, indexGuess);
|
|
|
|
}
|
|
|
|
|
|
|
|
return isTBody ? indexGuess : -1;
|
|
|
|
}
|
|
|
|
if (!aChild->IsHTMLElement(nsGkAtoms::tr)) {
|
|
|
|
return aIndexGuess; // Nothing inserted, guess hasn't changed.
|
|
|
|
}
|
|
|
|
|
|
|
|
// We should have only been passed an insertion from an interesting container,
|
|
|
|
// so we can get the container we're inserting to fairly easily.
|
|
|
|
nsIAtom* section = aContainer == mParent
|
|
|
|
? nsGkAtoms::tbody
|
|
|
|
: aContainer->NodeInfo()->NameAtom();
|
|
|
|
|
|
|
|
// Determine the default index we would to insert after if we don't find any
|
|
|
|
// previous row, and offset our section boundaries based on the section we're
|
|
|
|
// planning to insert into.
|
|
|
|
size_t index = 0;
|
|
|
|
if (section == nsGkAtoms::thead) {
|
|
|
|
mBodyStart++;
|
|
|
|
mFootStart++;
|
|
|
|
} else if (section == nsGkAtoms::tbody) {
|
|
|
|
index = mBodyStart;
|
|
|
|
mFootStart++;
|
|
|
|
} else if (section == nsGkAtoms::tfoot) {
|
|
|
|
index = mFootStart;
|
|
|
|
} else {
|
|
|
|
MOZ_ASSERT(false, "section should be one of thead, tbody, or tfoot");
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we already have an index guess, we can skip scanning for the previous row.
|
|
|
|
if (aIndexGuess >= 0) {
|
|
|
|
index = aIndexGuess;
|
|
|
|
} else {
|
|
|
|
// Find the previous row in the section we're inserting into. If we find it,
|
|
|
|
// we can use it to override our insertion index. We don't need to modify
|
|
|
|
// mBodyStart or mFootStart anymore, as they have already been correctly
|
|
|
|
// updated based only on section.
|
|
|
|
nsIContent* insertAfter = PreviousRow(section, aChild);
|
|
|
|
if (insertAfter) {
|
|
|
|
// NOTE: We want to ensure that appending elements is quick, so we search
|
|
|
|
// from the end rather than from the beginning.
|
|
|
|
index = mRows.LastIndexOf(insertAfter) + 1;
|
|
|
|
MOZ_ASSERT(index != nsTArray<nsCOMPtr<nsIContent>>::NoIndex);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
|
|
|
// Assert that we're inserting into the correct section.
|
|
|
|
if (section == nsGkAtoms::thead) {
|
|
|
|
MOZ_ASSERT(index < mBodyStart);
|
|
|
|
} else if (section == nsGkAtoms::tbody) {
|
|
|
|
MOZ_ASSERT(index >= mBodyStart);
|
|
|
|
MOZ_ASSERT(index < mFootStart);
|
|
|
|
} else if (section == nsGkAtoms::tfoot) {
|
|
|
|
MOZ_ASSERT(index >= mFootStart);
|
|
|
|
MOZ_ASSERT(index <= mRows.Length());
|
|
|
|
}
|
|
|
|
|
|
|
|
MOZ_ASSERT(mBodyStart <= mFootStart);
|
|
|
|
MOZ_ASSERT(mFootStart <= mRows.Length() + 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
mRows.InsertElementAt(index, aChild);
|
|
|
|
return index + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIMutationObserver
|
|
|
|
|
|
|
|
void
|
|
|
|
TableRowsCollection::ContentAppended(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aFirstNewContent,
|
|
|
|
int32_t aNewIndexInContainer)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsInSameAnonymousTree(mParent, aFirstNewContent) ||
|
|
|
|
!InterestingContainer(aContainer)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We usually can't guess where we need to start inserting, unless we're
|
|
|
|
// appending into mParent, in which case we can provide the guess that we
|
|
|
|
// should insert at the end of the body, which can help us avoid potentially
|
|
|
|
// expensive work in the common case.
|
|
|
|
int32_t indexGuess = mParent == aContainer ? mFootStart : -1;
|
|
|
|
|
|
|
|
// Insert each of the newly added content one at a time. The indexGuess should
|
|
|
|
// make insertions of a large number of elements cheaper.
|
|
|
|
for (nsIContent* content = aFirstNewContent;
|
|
|
|
content; content = content->GetNextSibling()) {
|
|
|
|
indexGuess = HandleInsert(aContainer, content, indexGuess);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TableRowsCollection::ContentInserted(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsInSameAnonymousTree(mParent, aChild) ||
|
|
|
|
!InterestingContainer(aContainer)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
HandleInsert(aContainer, aChild);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TableRowsCollection::ContentRemoved(nsIDocument* aDocument,
|
|
|
|
nsIContent* aContainer,
|
|
|
|
nsIContent* aChild,
|
|
|
|
int32_t aIndexInContainer,
|
|
|
|
nsIContent* aPreviousSibling)
|
|
|
|
{
|
|
|
|
if (!nsContentUtils::IsInSameAnonymousTree(mParent, aChild) ||
|
|
|
|
!InterestingContainer(aContainer)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the element being removed is a `tr`, we can just remove it from our
|
|
|
|
// list. It shouldn't change the order of anything.
|
|
|
|
if (aChild->IsHTMLElement(nsGkAtoms::tr)) {
|
|
|
|
size_t index = mRows.IndexOf(aChild);
|
|
|
|
if (index != nsTArray<nsCOMPtr<nsIContent>>::NoIndex) {
|
|
|
|
mRows.RemoveElementAt(index);
|
|
|
|
if (mBodyStart > index) {
|
|
|
|
mBodyStart--;
|
|
|
|
}
|
|
|
|
if (mFootStart > index) {
|
|
|
|
mFootStart--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If the element being removed is a `thead`, `tbody`, or `tfoot`, we can
|
|
|
|
// remove any `tr`s in our list which have that element as its parent node. In
|
|
|
|
// any other situation, the removal won't affect us, so we can ignore it.
|
|
|
|
if (!aChild->IsAnyOfHTMLElements(nsGkAtoms::thead, nsGkAtoms::tbody, nsGkAtoms::tfoot)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t beforeLength = mRows.Length();
|
|
|
|
mRows.RemoveElementsBy([&] (nsIContent* element) {
|
|
|
|
return element->GetParent() == aChild;
|
|
|
|
});
|
|
|
|
size_t removed = beforeLength - mRows.Length();
|
|
|
|
if (aChild->IsHTMLElement(nsGkAtoms::thead)) {
|
|
|
|
// NOTE: Need to move both tbody and tfoot, as we removed from head.
|
|
|
|
mBodyStart -= removed;
|
|
|
|
mFootStart -= removed;
|
|
|
|
} else if (aChild->IsHTMLElement(nsGkAtoms::tbody)) {
|
|
|
|
// NOTE: Need to move tfoot, as we removed from body.
|
|
|
|
mFootStart -= removed;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
TableRowsCollection::NodeWillBeDestroyed(const nsINode* aNode)
|
|
|
|
{
|
|
|
|
// Set mInitialized to false so CleanUp doesn't try to remove our mutation
|
|
|
|
// observer, as we're going away. CleanUp() will reset mInitialized to true as
|
|
|
|
// it returns.
|
|
|
|
mInitialized = false;
|
|
|
|
CleanUp();
|
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
/* --------------------------- HTMLTableElement ---------------------------- */
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2014-06-20 06:01:40 +04:00
|
|
|
HTMLTableElement::HTMLTableElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2011-08-20 14:18:50 +04:00
|
|
|
: nsGenericHTMLElement(aNodeInfo),
|
2017-03-26 23:53:34 +03:00
|
|
|
mTableInheritedAttributes(nullptr)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2013-12-17 17:58:32 +04:00
|
|
|
SetHasWeirdParserInsertionMode();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::~HTMLTableElement()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (mRows) {
|
1998-11-17 02:31:24 +03:00
|
|
|
mRows->ParentDestroyed();
|
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
ReleaseInheritedAttributes();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
JSObject*
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
HTMLTableElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-29 12:08:15 +04:00
|
|
|
{
|
Bug 1117172 part 3. Change the wrappercached WrapObject methods to allow passing in aGivenProto. r=peterv
The only manual changes here are to BindingUtils.h, BindingUtils.cpp,
Codegen.py, Element.cpp, IDBFileRequest.cpp, IDBObjectStore.cpp,
dom/workers/Navigator.cpp, WorkerPrivate.cpp, DeviceStorageRequestChild.cpp,
Notification.cpp, nsGlobalWindow.cpp, MessagePort.cpp, nsJSEnvironment.cpp,
Sandbox.cpp, XPCConvert.cpp, ExportHelpers.cpp, and DataStoreService.cpp. The
rest of this diff was generated by running the following commands:
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObjectInternal\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapNode\((?:aCx|cx|aContext|aCtx|js))\)/\1, aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(WrapObject\(JSContext *\* *(?:aCx|cx|aContext|aCtx|js))\)/\1, JS::Handle<JSObject*> aGivenProto)/g'
find . -name "*.h" -o -name "*.cpp" | xargs perl -pi -e 'BEGIN { $/ = undef } s/(Binding(?:_workers)?::Wrap\((?:aCx|cx|aContext|aCtx|js), [^,)]+)\)/\1, aGivenProto)/g'
2015-03-19 17:13:33 +03:00
|
|
|
return HTMLTableElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-29 12:08:15 +04:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2013-08-02 05:29:05 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_CLASS(HTMLTableElement)
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLTableElement, nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mTBodies)
|
2012-01-08 03:37:43 +04:00
|
|
|
if (tmp->mRows) {
|
|
|
|
tmp->mRows->ParentDestroyed();
|
|
|
|
}
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK(mRows)
|
2012-01-08 03:37:43 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_UNLINK_END
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLTableElement,
|
2007-03-08 14:17:16 +03:00
|
|
|
nsGenericHTMLElement)
|
2012-11-15 11:32:40 +04:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mTBodies)
|
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mRows)
|
2007-03-08 14:17:16 +03:00
|
|
|
NS_IMPL_CYCLE_COLLECTION_TRAVERSE_END
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ADDREF_INHERITED(HTMLTableElement, Element)
|
|
|
|
NS_IMPL_RELEASE_INHERITED(HTMLTableElement, Element)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
// QueryInterface implementation for HTMLTableElement
|
2015-04-25 17:23:54 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN_CYCLE_COLLECTION_INHERITED(HTMLTableElement)
|
|
|
|
NS_INTERFACE_MAP_END_INHERITING(nsGenericHTMLElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
|
|
|
|
2012-12-28 06:45:57 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLTableElement)
|
1998-09-02 04:56:01 +04:00
|
|
|
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
// the DOM spec says border, cellpadding, cellSpacing are all "wstring"
|
2000-12-23 13:56:31 +03:00
|
|
|
// in fact, they are integers or they are meaningless. so we store them
|
|
|
|
// here as ints.
|
1998-09-15 21:58:24 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection*
|
|
|
|
HTMLTableElement::Rows()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (!mRows) {
|
1998-11-17 02:31:24 +03:00
|
|
|
mRows = new TableRowsCollection(this);
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return mRows;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection*
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::TBodies()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2000-12-23 13:56:31 +03:00
|
|
|
if (!mTBodies) {
|
2004-04-14 08:26:00 +04:00
|
|
|
// Not using NS_GetContentList because this should not be cached
|
2006-07-02 11:23:10 +04:00
|
|
|
mTBodies = new nsContentList(this,
|
2011-11-16 11:50:19 +04:00
|
|
|
kNameSpaceID_XHTML,
|
2010-09-01 06:47:00 +04:00
|
|
|
nsGkAtoms::tbody,
|
|
|
|
nsGkAtoms::tbody,
|
2011-10-17 18:59:28 +04:00
|
|
|
false);
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2011-04-25 21:46:51 +04:00
|
|
|
return mTBodies;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTHead()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> head = GetTHead();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!head) {
|
|
|
|
// Create a new head rowgroup.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::thead,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
head = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!head) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2017-02-21 06:43:00 +03:00
|
|
|
nsCOMPtr<nsIContent> refNode = nullptr;
|
|
|
|
for (refNode = nsINode::GetFirstChild();
|
|
|
|
refNode;
|
|
|
|
refNode = refNode->GetNextSibling()) {
|
|
|
|
|
|
|
|
if (refNode->IsHTMLElement() &&
|
|
|
|
!refNode->IsHTMLElement(nsGkAtoms::caption) &&
|
|
|
|
!refNode->IsHTMLElement(nsGkAtoms::colgroup)) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
IgnoredErrorResult rv;
|
2016-10-14 15:33:42 +03:00
|
|
|
nsINode::InsertBefore(*head, refNode, rv);
|
2011-11-16 11:50:19 +04:00
|
|
|
}
|
2012-12-29 12:08:15 +04:00
|
|
|
return head.forget();
|
|
|
|
}
|
2002-12-17 16:29:39 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteTHead()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* tHead = GetTHead();
|
|
|
|
if (tHead) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tHead, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTFoot()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> foot = GetTFoot();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!foot) {
|
|
|
|
// create a new foot rowgroup
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tfoot,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
foot = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (!foot) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
AppendChildTo(foot, true);
|
1998-11-18 02:09:59 +03:00
|
|
|
}
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return foot.forget();
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteTFoot()
|
1998-11-18 09:06:37 +03:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* tFoot = GetTFoot();
|
|
|
|
if (tFoot) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*tFoot, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateCaption()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> caption = GetCaption();
|
2012-12-29 12:08:15 +04:00
|
|
|
if (!caption) {
|
|
|
|
// Create a new caption.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::caption,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
caption = NS_NewHTMLTableCaptionElement(nodeInfo.forget());
|
|
|
|
if (!caption) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
|
2017-02-21 06:43:00 +03:00
|
|
|
IgnoredErrorResult rv;
|
|
|
|
nsCOMPtr<nsINode> firsChild = nsINode::GetFirstChild();
|
|
|
|
nsINode::InsertBefore(*caption, firsChild, rv);
|
1998-11-18 02:09:59 +03:00
|
|
|
}
|
2012-12-29 12:08:15 +04:00
|
|
|
return caption.forget();
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2013-08-02 02:24:21 +04:00
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::DeleteCaption()
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableCaptionElement* caption = GetCaption();
|
|
|
|
if (caption) {
|
|
|
|
mozilla::ErrorResult rv;
|
|
|
|
nsINode::RemoveChild(*caption, rv);
|
|
|
|
MOZ_ASSERT(!rv.Failed());
|
1998-11-17 02:31:24 +03:00
|
|
|
}
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-04 09:04:30 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::CreateTBody()
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo =
|
2012-12-04 09:04:30 +04:00
|
|
|
OwnerDoc()->NodeInfoManager()->GetNodeInfo(nsGkAtoms::tbody, nullptr,
|
|
|
|
kNameSpaceID_XHTML,
|
|
|
|
nsIDOMNode::ELEMENT_NODE);
|
|
|
|
MOZ_ASSERT(nodeInfo);
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> newBody =
|
2012-12-04 09:04:30 +04:00
|
|
|
NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
MOZ_ASSERT(newBody);
|
|
|
|
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsIContent> referenceNode = nullptr;
|
2012-12-04 09:04:30 +04:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
|
|
|
child;
|
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-04 09:04:30 +04:00
|
|
|
referenceNode = child->GetNextSibling();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-21 06:43:00 +03:00
|
|
|
IgnoredErrorResult rv;
|
2012-12-04 09:04:30 +04:00
|
|
|
nsINode::InsertBefore(*newBody, referenceNode, rv);
|
|
|
|
|
|
|
|
return newBody.forget();
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
already_AddRefed<nsGenericHTMLElement>
|
|
|
|
HTMLTableElement::InsertRow(int32_t aIndex, ErrorResult& aError)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
1998-12-10 02:30:06 +03:00
|
|
|
/* get the ref row at aIndex
|
2013-08-02 02:24:21 +04:00
|
|
|
if there is one,
|
2009-01-23 12:02:09 +03:00
|
|
|
get its parent
|
1998-12-10 02:30:06 +03:00
|
|
|
insert the new row just before the ref row
|
1998-11-18 09:06:37 +03:00
|
|
|
else
|
|
|
|
get the first row group
|
|
|
|
insert the new row as its first child
|
|
|
|
*/
|
2002-12-17 16:29:39 +03:00
|
|
|
if (aIndex < -1) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 09:49:10 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
|
|
|
uint32_t rowCount = rows->Length();
|
2012-08-22 19:56:38 +04:00
|
|
|
if ((uint32_t)aIndex > rowCount && aIndex != -1) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return nullptr;
|
2002-01-03 09:49:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// use local variable refIndex so we can remember original aIndex
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t refIndex = (uint32_t)aIndex;
|
2002-01-03 09:49:10 +03:00
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsGenericHTMLElement> newRow;
|
2002-01-03 09:49:10 +03:00
|
|
|
if (rowCount > 0) {
|
2002-12-17 16:29:39 +03:00
|
|
|
if (refIndex == rowCount || aIndex == -1) {
|
2000-12-23 13:56:31 +03:00
|
|
|
// we set refIndex to the last row so we can get the last row's
|
|
|
|
// parent we then do an AppendChild below if (rowCount<aIndex)
|
|
|
|
|
2002-01-03 09:49:10 +03:00
|
|
|
refIndex = rowCount - 1;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2016-02-24 03:23:43 +03:00
|
|
|
RefPtr<Element> refRow = rows->Item(refIndex);
|
|
|
|
nsCOMPtr<nsINode> parent = refRow->GetParentNode();
|
2000-12-23 13:56:31 +03:00
|
|
|
|
1998-11-18 09:06:37 +03:00
|
|
|
// create the row
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2004-06-06 06:38:32 +04:00
|
|
|
if (newRow) {
|
2012-12-29 12:08:15 +04:00
|
|
|
// If aIndex is -1 or equal to the number of rows, the new row
|
2003-01-12 00:33:00 +03:00
|
|
|
// is appended.
|
2012-08-22 19:56:38 +04:00
|
|
|
if (aIndex == -1 || uint32_t(aIndex) == rowCount) {
|
2012-12-29 12:08:15 +04:00
|
|
|
parent->AppendChild(*newRow, aError);
|
|
|
|
} else {
|
2000-12-23 13:56:31 +03:00
|
|
|
// insert the new row before the reference row we found above
|
2012-12-29 12:08:15 +04:00
|
|
|
parent->InsertBefore(*newRow, refRow, aError);
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
2000-12-23 13:56:31 +03:00
|
|
|
}
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
2011-11-16 11:50:19 +04:00
|
|
|
} else {
|
2016-05-17 09:54:00 +03:00
|
|
|
// the row count was 0, so
|
2014-05-02 05:29:23 +04:00
|
|
|
// find the last row group and insert there as first child
|
2012-12-29 12:08:15 +04:00
|
|
|
nsCOMPtr<nsIContent> rowGroup;
|
2014-05-02 05:29:23 +04:00
|
|
|
for (nsIContent* child = nsINode::GetLastChild();
|
2011-09-27 11:54:58 +04:00
|
|
|
child;
|
2014-05-02 05:29:23 +04:00
|
|
|
child = child->GetPreviousSibling()) {
|
2015-03-03 14:08:59 +03:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::tbody)) {
|
2012-12-29 12:08:15 +04:00
|
|
|
rowGroup = child;
|
2004-04-14 08:26:00 +04:00
|
|
|
break;
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
|
|
|
if (!rowGroup) { // need to create a TBODY
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tbody,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-05-10 17:13:39 +04:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
rowGroup = NS_NewHTMLTableSectionElement(nodeInfo.forget());
|
|
|
|
if (rowGroup) {
|
|
|
|
aError = AppendChildTo(rowGroup, true);
|
|
|
|
if (aError.Failed()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
|
|
|
if (rowGroup) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo;
|
2017-02-21 06:44:00 +03:00
|
|
|
nsContentUtils::QNameChanged(mNodeInfo, nsGkAtoms::tr,
|
|
|
|
getter_AddRefs(nodeInfo));
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
newRow = NS_NewHTMLTableRowElement(nodeInfo.forget());
|
2004-04-14 08:26:00 +04:00
|
|
|
if (newRow) {
|
2012-12-29 12:08:15 +04:00
|
|
|
HTMLTableSectionElement* section =
|
|
|
|
static_cast<HTMLTableSectionElement*>(rowGroup.get());
|
2012-12-29 18:07:48 +04:00
|
|
|
nsIHTMLCollection* rows = section->Rows();
|
2016-10-14 15:33:42 +03:00
|
|
|
nsCOMPtr<nsINode> refNode = rows->Item(0);
|
|
|
|
rowGroup->InsertBefore(*newRow, refNode, aError);
|
1998-11-18 09:06:37 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
return newRow.forget();
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::DeleteRow(int32_t aIndex, ErrorResult& aError)
|
|
|
|
{
|
|
|
|
if (aIndex < -1) {
|
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsIHTMLCollection* rows = Rows();
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t refIndex;
|
2012-12-29 12:08:15 +04:00
|
|
|
if (aIndex == -1) {
|
|
|
|
refIndex = rows->Length();
|
2002-12-17 16:29:39 +03:00
|
|
|
if (refIndex == 0) {
|
2012-12-29 12:08:15 +04:00
|
|
|
return;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
--refIndex;
|
2012-12-29 12:08:15 +04:00
|
|
|
} else {
|
|
|
|
refIndex = (uint32_t)aIndex;
|
2002-12-17 16:29:39 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
nsCOMPtr<nsIContent> row = rows->Item(refIndex);
|
2001-12-11 13:20:57 +03:00
|
|
|
if (!row) {
|
2012-12-29 12:08:15 +04:00
|
|
|
aError.Throw(NS_ERROR_DOM_INDEX_SIZE_ERR);
|
|
|
|
return;
|
2001-12-11 13:20:57 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-29 12:08:15 +04:00
|
|
|
row->RemoveFromParent();
|
|
|
|
}
|
2001-12-11 13:20:57 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::ParseAttribute(int32_t aNamespaceID,
|
|
|
|
nsIAtom* aAttribute,
|
|
|
|
const nsAString& aValue,
|
|
|
|
nsAttrValue& aResult)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
1998-09-15 21:58:24 +04:00
|
|
|
/* ignore summary, just a string */
|
2005-11-29 19:37:15 +03:00
|
|
|
if (aNamespaceID == kNameSpaceID_None) {
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::cellspacing ||
|
2013-02-07 12:08:57 +04:00
|
|
|
aAttribute == nsGkAtoms::cellpadding ||
|
|
|
|
aAttribute == nsGkAtoms::border) {
|
2012-02-21 13:34:01 +04:00
|
|
|
return aResult.ParseNonNegativeIntValue(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::height) {
|
2011-02-04 22:46:16 +03:00
|
|
|
return aResult.ParseSpecialIntValue(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::width) {
|
2011-02-04 22:46:16 +03:00
|
|
|
if (aResult.ParseSpecialIntValue(aValue)) {
|
2005-11-29 19:37:15 +03:00
|
|
|
// treat 0 width as auto
|
|
|
|
nsAttrValue::ValueType type = aResult.Type();
|
2011-07-11 14:56:00 +04:00
|
|
|
return !((type == nsAttrValue::eInteger &&
|
|
|
|
aResult.GetIntegerValue() == 0) ||
|
|
|
|
(type == nsAttrValue::ePercent &&
|
|
|
|
aResult.GetPercentValue() == 0.0f));
|
2001-08-22 08:21:05 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::align) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return ParseTableHAlignValue(aValue, aResult);
|
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::bgcolor ||
|
|
|
|
aAttribute == nsGkAtoms::bordercolor) {
|
2010-07-17 12:09:14 +04:00
|
|
|
return aResult.ParseColor(aValue);
|
2005-11-29 19:37:15 +03:00
|
|
|
}
|
2006-12-26 20:47:52 +03:00
|
|
|
if (aAttribute == nsGkAtoms::hspace ||
|
|
|
|
aAttribute == nsGkAtoms::vspace) {
|
2005-11-29 19:37:15 +03:00
|
|
|
return aResult.ParseIntWithBounds(aValue, 0);
|
1999-07-24 23:55:35 +04:00
|
|
|
}
|
2000-06-14 04:59:29 +04:00
|
|
|
}
|
1998-09-15 21:58:24 +04:00
|
|
|
|
2012-08-24 21:50:49 +04:00
|
|
|
return nsGenericHTMLElement::ParseBackgroundAttribute(aNamespaceID,
|
|
|
|
aAttribute, aValue,
|
|
|
|
aResult) ||
|
|
|
|
nsGenericHTMLElement::ParseAttribute(aNamespaceID, aAttribute, aValue,
|
2005-11-29 19:37:15 +03:00
|
|
|
aResult);
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
|
|
|
|
2005-09-23 09:02:42 +04:00
|
|
|
|
1998-09-15 21:58:24 +04:00
|
|
|
|
2013-11-19 23:21:29 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::MapAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
1998-09-02 04:56:01 +04:00
|
|
|
{
|
2003-07-12 01:16:12 +04:00
|
|
|
// XXX Bug 211636: This function is used by a single style rule
|
|
|
|
// that's used to match two different type of elements -- tables, and
|
|
|
|
// table cells. (nsHTMLTableCellElement overrides
|
|
|
|
// WalkContentStyleRules so that this happens.) This violates the
|
|
|
|
// nsIStyleRule contract, since it's the same style rule object doing
|
|
|
|
// the mapping in two different ways. It's also incorrect since it's
|
|
|
|
// testing the display type of the style context rather than checking
|
|
|
|
// which *element* it's matching (style rules should not stop matching
|
|
|
|
// when the display type is changed).
|
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
nsPresContext* presContext = aData->PresContext();
|
2007-11-16 06:46:42 +03:00
|
|
|
nsCompatibility mode = presContext->CompatibilityMode();
|
2001-10-25 04:24:08 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(TableBorder))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
// cellspacing
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellspacing);
|
2012-02-21 13:34:01 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger &&
|
2017-01-27 03:51:01 +03:00
|
|
|
!aData->PropertyIsSet(eCSSProperty_border_spacing)) {
|
|
|
|
aData->SetPixelValue(eCSSProperty_border_spacing, float(value->GetIntegerValue()));
|
1998-09-15 21:58:24 +04:00
|
|
|
}
|
2010-08-19 23:33:44 +04:00
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Margin))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
// align; Check for enumerated type (it may be another type if
|
|
|
|
// illegal)
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::align);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eEnum) {
|
|
|
|
if (value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_CENTER ||
|
|
|
|
value->GetEnumValue() == NS_STYLE_TEXT_ALIGN_MOZ_CENTER) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_left);
|
|
|
|
aData->SetAutoValueIfUnset(eCSSProperty_margin_right);
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
1999-05-27 03:48:19 +04:00
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
// hspace is mapped into left and right margin,
|
|
|
|
// vspace is mapped into top and bottom margins
|
|
|
|
// - *** Quirks Mode only ***
|
|
|
|
if (eCompatibility_NavQuirks == mode) {
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::hspace);
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_left, (float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_right, (float)value->GetIntegerValue());
|
1999-05-27 03:48:19 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
value = aAttributes->GetAttr(nsGkAtoms::vspace);
|
|
|
|
|
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_top, (float)value->GetIntegerValue());
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_margin_bottom, (float)value->GetIntegerValue());
|
2000-02-12 03:58:38 +03:00
|
|
|
}
|
2001-06-01 02:19:43 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Border))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
// bordercolor
|
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::bordercolor);
|
|
|
|
nscolor color;
|
|
|
|
if (value && presContext->UseDocumentColors() &&
|
|
|
|
value->GetColorValue(color)) {
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_top_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_left_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_bottom_color, color);
|
|
|
|
aData->SetColorValueIfUnset(eCSSProperty_border_right_color, color);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2000-06-14 04:59:29 +04:00
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
// border
|
|
|
|
const nsAttrValue* borderValue = aAttributes->GetAttr(nsGkAtoms::border);
|
|
|
|
if (borderValue) {
|
|
|
|
// border = 1 pixel default
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t borderThickness = 1;
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
if (borderValue->Type() == nsAttrValue::eInteger)
|
|
|
|
borderThickness = borderValue->GetIntegerValue();
|
|
|
|
|
|
|
|
// by default, set all border sides to the specified width
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_top_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_left_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_bottom_width, (float)borderThickness);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_border_right_width, (float)borderThickness);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
|
|
|
}
|
2017-01-27 03:51:01 +03:00
|
|
|
nsGenericHTMLElement::MapImageSizeAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapBackgroundAttributesInto(aAttributes, aData);
|
|
|
|
nsGenericHTMLElement::MapCommonAttributesInto(aAttributes, aData);
|
1999-07-07 05:24:40 +04:00
|
|
|
}
|
1998-11-11 22:56:02 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
NS_IMETHODIMP_(bool)
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::IsAttributeMapped(const nsIAtom* aAttribute) const
|
1999-07-07 05:24:40 +04:00
|
|
|
{
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry attributes[] = {
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::cellpadding },
|
|
|
|
{ &nsGkAtoms::cellspacing },
|
|
|
|
{ &nsGkAtoms::border },
|
|
|
|
{ &nsGkAtoms::width },
|
|
|
|
{ &nsGkAtoms::height },
|
|
|
|
{ &nsGkAtoms::hspace },
|
|
|
|
{ &nsGkAtoms::vspace },
|
2016-05-17 09:54:00 +03:00
|
|
|
|
2006-12-26 20:47:52 +03:00
|
|
|
{ &nsGkAtoms::bordercolor },
|
2016-05-17 09:54:00 +03:00
|
|
|
|
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
|
|
|
};
|
|
|
|
|
2004-02-26 00:04:50 +03:00
|
|
|
static const MappedAttributeEntry* const map[] = {
|
2003-04-17 00:54:20 +04:00
|
|
|
attributes,
|
|
|
|
sCommonAttributeMap,
|
|
|
|
sBackgroundAttributeMap,
|
|
|
|
};
|
|
|
|
|
2011-12-18 14:09:27 +04:00
|
|
|
return FindAttributeDependence(aAttribute, map);
|
1998-09-05 08:00:06 +04:00
|
|
|
}
|
|
|
|
|
2005-01-12 22:45:38 +03:00
|
|
|
nsMapRuleToAttributesFunc
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::GetAttributeMappingFunction() const
|
1998-09-05 08:00:06 +04:00
|
|
|
{
|
2005-01-12 22:45:38 +03:00
|
|
|
return &MapAttributesIntoRule;
|
1998-09-02 04:56:01 +04:00
|
|
|
}
|
2011-08-20 14:18:50 +04:00
|
|
|
|
|
|
|
static void
|
|
|
|
MapInheritedTableAttributesIntoRule(const nsMappedAttributes* aAttributes,
|
2017-01-27 03:51:01 +03:00
|
|
|
GenericSpecifiedValues* aData)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2017-01-27 03:51:01 +03:00
|
|
|
if (aData->ShouldComputeStyleStruct(NS_STYLE_INHERIT_BIT(Padding))) {
|
2011-08-20 14:18:50 +04:00
|
|
|
const nsAttrValue* value = aAttributes->GetAttr(nsGkAtoms::cellpadding);
|
2012-02-21 13:34:01 +04:00
|
|
|
if (value && value->Type() == nsAttrValue::eInteger) {
|
|
|
|
// We have cellpadding. This will override our padding values if we
|
|
|
|
// don't have any set.
|
2017-01-27 03:51:01 +03:00
|
|
|
float pad = float(value->GetIntegerValue());
|
2012-02-21 13:34:01 +04:00
|
|
|
|
2017-01-27 03:51:01 +03:00
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_top, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_right, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_bottom, pad);
|
|
|
|
aData->SetPixelValueIfUnset(eCSSProperty_padding_left, pad);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMappedAttributes*
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::GetAttributesMappedForCell()
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2017-03-26 23:53:34 +03:00
|
|
|
return mTableInheritedAttributes;
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BuildInheritedAttributes()
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2017-03-26 23:53:34 +03:00
|
|
|
NS_ASSERTION(!mTableInheritedAttributes,
|
2011-08-20 14:18:50 +04:00
|
|
|
"potential leak, plus waste of work");
|
2017-03-26 23:53:34 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2014-10-02 23:07:24 +04:00
|
|
|
nsIDocument *document = GetComposedDoc();
|
2011-08-20 14:18:50 +04:00
|
|
|
nsHTMLStyleSheet* sheet = document ?
|
2012-07-30 18:20:58 +04:00
|
|
|
document->GetAttributeStyleSheet() : nullptr;
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMappedAttributes> newAttrs;
|
2011-08-20 14:18:50 +04:00
|
|
|
if (sheet) {
|
|
|
|
const nsAttrValue* value = mAttrsAndChildren.GetAttr(nsGkAtoms::cellpadding);
|
|
|
|
if (value) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsMappedAttributes> modifiableMapped = new
|
2011-08-20 14:18:50 +04:00
|
|
|
nsMappedAttributes(sheet, MapInheritedTableAttributesIntoRule);
|
|
|
|
|
|
|
|
if (modifiableMapped) {
|
|
|
|
nsAttrValue val(*value);
|
2017-05-19 00:09:01 +03:00
|
|
|
bool oldValueSet;
|
|
|
|
modifiableMapped->SetAndSwapAttr(nsGkAtoms::cellpadding, val,
|
|
|
|
&oldValueSet);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
newAttrs = sheet->UniqueMappedAttributes(modifiableMapped);
|
|
|
|
NS_ASSERTION(newAttrs, "out of memory, but handling gracefully");
|
|
|
|
|
|
|
|
if (newAttrs != modifiableMapped) {
|
|
|
|
// Reset the stylesheet of modifiableMapped so that it doesn't
|
|
|
|
// spend time trying to remove itself from the hash. There is no
|
|
|
|
// risk that modifiableMapped is in the hash since we created
|
|
|
|
// it ourselves and it didn't come from the stylesheet (in which
|
|
|
|
// case it would not have been modifiable).
|
|
|
|
modifiableMapped->DropStyleSheetReference();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
mTableInheritedAttributes = newAttrs;
|
|
|
|
NS_IF_ADDREF(mTableInheritedAttributes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-14 19:33:16 +04:00
|
|
|
void
|
|
|
|
HTMLTableElement::ReleaseInheritedAttributes()
|
|
|
|
{
|
2017-03-26 23:53:34 +03:00
|
|
|
NS_IF_RELEASE(mTableInheritedAttributes);
|
2013-02-14 19:33:16 +04:00
|
|
|
}
|
|
|
|
|
2011-08-20 14:18:50 +04:00
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BindToTree(nsIDocument* aDocument, nsIContent* aParent,
|
|
|
|
nsIContent* aBindingParent,
|
|
|
|
bool aCompileEventHandlers)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
2017-03-26 23:53:34 +03:00
|
|
|
nsresult rv = nsGenericHTMLElement::BindToTree(aDocument, aParent,
|
|
|
|
aBindingParent,
|
|
|
|
aCompileEventHandlers);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
BuildInheritedAttributes();
|
|
|
|
return NS_OK;
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::UnbindFromTree(bool aDeep, bool aNullParent)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
nsGenericHTMLElement::UnbindFromTree(aDeep, aNullParent);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::BeforeSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
2017-03-16 21:50:41 +03:00
|
|
|
const nsAttrValueOrString* aValue,
|
2012-12-28 06:45:57 +04:00
|
|
|
bool aNotify)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2011-08-28 14:59:34 +04:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
2011-08-20 14:18:50 +04:00
|
|
|
ReleaseInheritedAttributes();
|
|
|
|
}
|
2011-08-28 14:59:34 +04:00
|
|
|
return nsGenericHTMLElement::BeforeSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-12-28 06:45:57 +04:00
|
|
|
HTMLTableElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue,
|
2017-05-19 00:09:01 +03:00
|
|
|
const nsAttrValue* aOldValue, bool aNotify)
|
2011-08-20 14:18:50 +04:00
|
|
|
{
|
2011-08-28 14:59:34 +04:00
|
|
|
if (aName == nsGkAtoms::cellpadding && aNameSpaceID == kNameSpaceID_None) {
|
|
|
|
BuildInheritedAttributes();
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2011-08-28 14:59:34 +04:00
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
2017-05-19 00:09:01 +03:00
|
|
|
aOldValue, aNotify);
|
2011-08-20 14:18:50 +04:00
|
|
|
}
|
2012-12-28 06:45:57 +04:00
|
|
|
|
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|