gecko-dev/dom/html/HTMLLabelElement.h
Boris Zbarsky 49a90cb122 Bug 1268852. Change <label> elements to not be form-associated anymore. r=bkelly,hsivonen,surkov
The web platform tests changes are just a cherrypick of
https://github.com/w3c/web-platform-tests/pull/2926 so I don't have to add
failure annotations until the next test uplift.

I've audited our uses of nsIFormControl, and this patch looks to me like it
preserves existing behavior in all but the following cases:

1)  nsXBLPrototypeHandler::DispatchXBLCommand, the case of scrolling when space
is pressed while something inside a <label> is focused.  We used to not scroll
in this situation; I think this is a bug, so I'm changing that behavior to
scroll instead.

2)  In Accessible::RelationByType for the RelationType::DEFAULT_BUTTON case,
when mContent is a <label> we used to return its form's default submit element.
Now we will just return Relation().
2016-05-26 19:39:03 -04:00

87 lines
2.4 KiB
C++

/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* 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/. */
/**
* Declaration of HTML <label> elements.
*/
#ifndef HTMLLabelElement_h
#define HTMLLabelElement_h
#include "mozilla/Attributes.h"
#include "nsGenericHTMLElement.h"
#include "nsIDOMHTMLLabelElement.h"
namespace mozilla {
class EventChainPostVisitor;
namespace dom {
class HTMLLabelElement final : public nsGenericHTMLElement,
public nsIDOMHTMLLabelElement
{
public:
explicit HTMLLabelElement(already_AddRefed<mozilla::dom::NodeInfo>& aNodeInfo)
: nsGenericHTMLElement(aNodeInfo),
mHandlingEvent(false)
{
}
NS_IMPL_FROMCONTENT_HTML_WITH_TAG(HTMLLabelElement, label)
// nsISupports
NS_DECL_ISUPPORTS_INHERITED
// Element
virtual bool IsInteractiveHTMLContent(bool aIgnoreTabindex) const override
{
return true;
}
// nsIDOMHTMLLabelElement
NS_DECL_NSIDOMHTMLLABELELEMENT
HTMLFormElement* GetForm() const;
void GetHtmlFor(nsString& aHtmlFor)
{
GetHTMLAttr(nsGkAtoms::_for, aHtmlFor);
}
void SetHtmlFor(const nsAString& aHtmlFor, ErrorResult& aError)
{
SetHTMLAttr(nsGkAtoms::_for, aHtmlFor, aError);
}
nsGenericHTMLElement* GetControl() const
{
return GetLabeledElement();
}
using nsGenericHTMLElement::Focus;
virtual void Focus(mozilla::ErrorResult& aError) override;
virtual bool IsDisabled() const override { return false; }
// nsIContent
virtual nsresult PostHandleEvent(
EventChainPostVisitor& aVisitor) override;
virtual bool PerformAccesskey(bool aKeyCausesActivation,
bool aIsTrustedEvent) override;
virtual nsresult Clone(mozilla::dom::NodeInfo *aNodeInfo, nsINode **aResult) const override;
nsGenericHTMLElement* GetLabeledElement() const;
protected:
virtual ~HTMLLabelElement();
virtual JSObject* WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto) override;
nsGenericHTMLElement* GetFirstLabelableDescendant() const;
// XXX It would be nice if we could use an event flag instead.
bool mHandlingEvent;
};
} // namespace dom
} // namespace mozilla
#endif /* HTMLLabelElement_h */