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