2015-05-03 19:32:37 +00: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 11:12:37 +00: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/. */
|
2013-02-08 16:34:48 +00:00
|
|
|
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-02-08 16:34:48 +00:00
|
|
|
#include "mozilla/dom/HTMLOptGroupElement.h"
|
2013-02-08 16:34:48 +00:00
|
|
|
#include "mozilla/dom/HTMLOptGroupElementBinding.h"
|
2013-04-04 07:03:33 +00:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h" // SafeOptionListMutation
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-03 01:03:33 +00:00
|
|
|
#include "nsStyleConsts.h"
|
2000-08-08 23:38:00 +00:00
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
1998-09-03 01:03:33 +00:00
|
|
|
|
2013-02-08 16:34:48 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(OptGroup)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2012-11-14 22:10:08 +00:00
|
|
|
|
2002-08-06 04:59:15 +00:00
|
|
|
/**
|
|
|
|
* The implementation of <optgroup>
|
|
|
|
*/
|
2000-05-10 13:13:39 +00:00
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
|
|
|
|
2014-06-20 02:01:40 +00:00
|
|
|
HTMLOptGroupElement::HTMLOptGroupElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2004-05-18 20:58:12 +00:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
1998-09-03 01:03:33 +00:00
|
|
|
{
|
2011-06-01 01:46:57 +00:00
|
|
|
// We start off enabled
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED);
|
1998-09-03 01:03:33 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::~HTMLOptGroupElement()
|
1998-09-03 01:03:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLOptGroupElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLOptGroupElement)
|
1998-09-03 01:03:33 +00:00
|
|
|
|
2013-02-08 16:34:48 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOptGroupElement)
|
1999-07-07 01:24:40 +00:00
|
|
|
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2013-02-08 16:34:48 +00:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLOptGroupElement, Disabled, disabled)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLOptGroupElement, Label, label)
|
1998-09-03 01:03:33 +00:00
|
|
|
|
1998-09-05 04:00:06 +00:00
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2014-03-18 04:48:19 +00:00
|
|
|
HTMLOptGroupElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
1998-09-03 01:03:33 +00:00
|
|
|
{
|
2011-10-17 14:59:28 +00:00
|
|
|
aVisitor.mCanHandle = false;
|
1999-12-04 02:22:21 +00:00
|
|
|
// Do not process any DOM events if the element is disabled
|
2006-03-07 17:08:51 +00:00
|
|
|
// XXXsmaug This is not the right thing to do. But what is?
|
2010-09-18 21:33:16 +00:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
|
|
|
return NS_OK;
|
1999-12-04 02:22:21 +00:00
|
|
|
}
|
|
|
|
|
2006-06-12 16:14:31 +00:00
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
2005-02-05 04:13:29 +00:00
|
|
|
if (frame) {
|
2013-02-16 21:51:02 +00:00
|
|
|
const nsStyleUserInterface* uiStyle = frame->StyleUserInterface();
|
2000-08-08 23:38:00 +00:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
2001-12-12 07:31:15 +00:00
|
|
|
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
|
2000-08-08 23:38:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-03-07 17:08:51 +00:00
|
|
|
return nsGenericHTMLElement::PreHandleEvent(aVisitor);
|
1998-09-03 01:03:33 +00:00
|
|
|
}
|
1998-12-10 23:52:46 +00:00
|
|
|
|
2006-07-27 21:06:27 +00:00
|
|
|
nsIContent*
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::GetSelect()
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
2006-07-27 21:06:27 +00:00
|
|
|
nsIContent* parent = this;
|
2015-03-03 11:08:59 +00:00
|
|
|
while ((parent = parent->GetParent()) && parent->IsHTMLElement()) {
|
2015-03-03 11:09:00 +00:00
|
|
|
if (parent->IsHTMLElement(nsGkAtoms::select)) {
|
2006-07-27 21:06:27 +00:00
|
|
|
return parent;
|
|
|
|
}
|
2015-03-03 11:09:00 +00:00
|
|
|
if (!parent->IsHTMLElement(nsGkAtoms::optgroup)) {
|
2001-11-02 07:40:01 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2006-07-27 21:06:27 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2001-11-02 07:40:01 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::InsertChildAt(nsIContent* aKid,
|
|
|
|
uint32_t aIndex,
|
|
|
|
bool aNotify)
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
2013-04-04 07:03:33 +00:00
|
|
|
SafeOptionListMutation safeMutation(GetSelect(), this, aKid, aIndex, aNotify);
|
2007-08-28 07:09:32 +00:00
|
|
|
nsresult rv = nsGenericHTMLElement::InsertChildAt(aKid, aIndex, aNotify);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
safeMutation.MutationFailed();
|
2006-03-24 22:43:23 +00:00
|
|
|
}
|
2007-08-28 07:09:32 +00:00
|
|
|
return rv;
|
2006-03-24 22:43:23 +00:00
|
|
|
}
|
|
|
|
|
2012-03-29 21:09:07 +00:00
|
|
|
void
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2006-03-24 22:43:23 +00:00
|
|
|
{
|
2013-04-04 07:03:33 +00:00
|
|
|
SafeOptionListMutation safeMutation(GetSelect(), this, nullptr, aIndex,
|
|
|
|
aNotify);
|
2012-03-29 21:09:07 +00:00
|
|
|
nsGenericHTMLElement::RemoveChildAt(aIndex, aNotify);
|
2001-11-02 07:40:01 +00:00
|
|
|
}
|
2005-09-28 08:32:40 +00:00
|
|
|
|
2012-06-01 09:46:43 +00:00
|
|
|
nsresult
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2012-06-01 09:46:43 +00:00
|
|
|
{
|
|
|
|
if (aNameSpaceID == kNameSpaceID_None && aName == nsGkAtoms::disabled) {
|
|
|
|
// All our children <option> have their :disabled state depending on our
|
|
|
|
// disabled attribute. We should make sure their state is updated.
|
|
|
|
for (nsIContent* child = nsINode::GetFirstChild(); child;
|
|
|
|
child = child->GetNextSibling()) {
|
2015-03-03 11:08:59 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::option)) {
|
2012-06-01 09:46:43 +00:00
|
|
|
// No need to call |IsElement()| because it's an HTML element.
|
|
|
|
child->AsElement()->UpdateState(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::AfterSetAttr(aNameSpaceID, aName, aValue,
|
|
|
|
aNotify);
|
|
|
|
}
|
|
|
|
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates
|
2013-02-08 16:34:48 +00:00
|
|
|
HTMLOptGroupElement::IntrinsicState() const
|
2005-09-28 08:32:40 +00:00
|
|
|
{
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2010-09-18 21:33:16 +00:00
|
|
|
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
2005-09-28 08:32:40 +00:00
|
|
|
state |= NS_EVENT_STATE_DISABLED;
|
|
|
|
state &= ~NS_EVENT_STATE_ENABLED;
|
|
|
|
} else {
|
|
|
|
state &= ~NS_EVENT_STATE_DISABLED;
|
|
|
|
state |= NS_EVENT_STATE_ENABLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return state;
|
|
|
|
}
|
2013-02-08 16:34:48 +00:00
|
|
|
|
2013-02-08 16:34:48 +00: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 14:13:33 +00:00
|
|
|
HTMLOptGroupElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-08 16:34:48 +00: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 14:13:33 +00:00
|
|
|
return HTMLOptGroupElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 16:34:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-08 16:34:48 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|