2015-05-03 12:32:37 -07: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 04:12:37 -07: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 08:34:48 -08:00
|
|
|
|
2014-03-17 21:48:21 -07:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
2014-04-02 21:18:36 -07:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-02-08 08:34:48 -08:00
|
|
|
#include "mozilla/dom/HTMLOptGroupElement.h"
|
2013-02-08 08:34:48 -08:00
|
|
|
#include "mozilla/dom/HTMLOptGroupElementBinding.h"
|
2013-04-04 00:03:33 -07:00
|
|
|
#include "mozilla/dom/HTMLSelectElement.h" // SafeOptionListMutation
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsGkAtoms.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsIFrame.h"
|
|
|
|
#include "nsIFormControlFrame.h"
|
|
|
|
|
2013-02-08 08:34:48 -08:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(OptGroup)
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
2012-11-14 14:10:08 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* The implementation of <optgroup>
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-06-19 19:01:40 -07:00
|
|
|
HTMLOptGroupElement::HTMLOptGroupElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
|
2007-03-22 10:30:00 -07:00
|
|
|
: nsGenericHTMLElement(aNodeInfo)
|
|
|
|
{
|
2011-05-31 18:46:57 -07:00
|
|
|
// We start off enabled
|
|
|
|
AddStatesSilently(NS_EVENT_STATE_ENABLED);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::~HTMLOptGroupElement()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-27 00:06:00 -07:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLOptGroupElement, nsGenericHTMLElement,
|
|
|
|
nsIDOMHTMLOptGroupElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-08 08:34:48 -08:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLOptGroupElement)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
2013-02-08 08:34:48 -08:00
|
|
|
NS_IMPL_BOOL_ATTR(HTMLOptGroupElement, Disabled, disabled)
|
|
|
|
NS_IMPL_STRING_ATTR(HTMLOptGroupElement, Label, label)
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
2014-03-17 21:48:19 -07:00
|
|
|
HTMLOptGroupElement::PreHandleEvent(EventChainPreVisitor& aVisitor)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-10-17 07:59:28 -07:00
|
|
|
aVisitor.mCanHandle = false;
|
2007-03-22 10:30:00 -07:00
|
|
|
// Do not process any DOM events if the element is disabled
|
|
|
|
// XXXsmaug This is not the right thing to do. But what is?
|
2010-09-18 14:33:16 -07:00
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
|
|
|
return NS_OK;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsIFrame* frame = GetPrimaryFrame();
|
|
|
|
if (frame) {
|
2013-02-16 13:51:02 -08:00
|
|
|
const nsStyleUserInterface* uiStyle = frame->StyleUserInterface();
|
2007-03-22 10:30:00 -07:00
|
|
|
if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE ||
|
|
|
|
uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return nsGenericHTMLElement::PreHandleEvent(aVisitor);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIContent*
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::GetSelect()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nsIContent* parent = this;
|
2015-03-03 03:08:59 -08:00
|
|
|
while ((parent = parent->GetParent()) && parent->IsHTMLElement()) {
|
2015-03-03 03:09:00 -08:00
|
|
|
if (parent->IsHTMLElement(nsGkAtoms::select)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
return parent;
|
|
|
|
}
|
2015-03-03 03:09:00 -08:00
|
|
|
if (!parent->IsHTMLElement(nsGkAtoms::optgroup)) {
|
2007-03-22 10:30:00 -07:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::InsertChildAt(nsIContent* aKid,
|
|
|
|
uint32_t aIndex,
|
|
|
|
bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-04 00:03:33 -07:00
|
|
|
SafeOptionListMutation safeMutation(GetSelect(), this, aKid, aIndex, aNotify);
|
2007-08-28 00:09:32 -07:00
|
|
|
nsresult rv = nsGenericHTMLElement::InsertChildAt(aKid, aIndex, aNotify);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
safeMutation.MutationFailed();
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2007-08-28 00:09:32 -07:00
|
|
|
return rv;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-03-29 14:09:07 -07:00
|
|
|
void
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::RemoveChildAt(uint32_t aIndex, bool aNotify)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2013-04-04 00:03:33 -07:00
|
|
|
SafeOptionListMutation safeMutation(GetSelect(), this, nullptr, aIndex,
|
|
|
|
aNotify);
|
2012-03-29 14:09:07 -07:00
|
|
|
nsGenericHTMLElement::RemoveChildAt(aIndex, aNotify);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2012-06-01 02:46:43 -07:00
|
|
|
nsresult
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::AfterSetAttr(int32_t aNameSpaceID, nsIAtom* aName,
|
|
|
|
const nsAttrValue* aValue, bool aNotify)
|
2012-06-01 02:46:43 -07: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 03:08:59 -08:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::option)) {
|
2012-06-01 02:46:43 -07: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-02 21:18:36 -07:00
|
|
|
EventStates
|
2013-02-08 08:34:48 -08:00
|
|
|
HTMLOptGroupElement::IntrinsicState() const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2014-04-02 21:18:36 -07:00
|
|
|
EventStates state = nsGenericHTMLElement::IntrinsicState();
|
2010-09-18 14:33:16 -07:00
|
|
|
|
|
|
|
if (HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) {
|
2007-03-22 10:30:00 -07: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 08:34:48 -08:00
|
|
|
|
2013-02-08 08:34:48 -08: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 07:13:33 -07:00
|
|
|
HTMLOptGroupElement::WrapNode(JSContext* aCx, JS::Handle<JSObject*> aGivenProto)
|
2013-02-08 08:34:48 -08: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 07:13:33 -07:00
|
|
|
return HTMLOptGroupElementBinding::Wrap(aCx, this, aGivenProto);
|
2013-02-08 08:34:48 -08:00
|
|
|
}
|
|
|
|
|
2013-02-08 08:34:48 -08:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|