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/. */
|
2011-05-25 00:18:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of HTML <label> elements.
|
|
|
|
*/
|
2012-12-21 14:06:50 +00:00
|
|
|
#include "HTMLLabelElement.h"
|
2014-03-18 04:48:21 +00:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-12-21 14:07:28 +00:00
|
|
|
#include "mozilla/dom/HTMLLabelElementBinding.h"
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
#include "nsFocusManager.h"
|
2013-08-23 17:56:20 +00:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2015-04-15 16:47:03 +00:00
|
|
|
#include "nsQueryObject.h"
|
1998-09-03 01:03:33 +00:00
|
|
|
|
1998-10-22 23:00:37 +00:00
|
|
|
// construction, destruction
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2004-05-18 20:58:12 +00:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Label)
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
1998-09-03 01:03:33 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLLabelElement::~HTMLLabelElement()
|
1998-09-03 01:03:33 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-21 14:07:28 +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
|
|
|
HTMLLabelElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-21 14:07:28 +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 HTMLLabelElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-21 14:07:28 +00:00
|
|
|
}
|
|
|
|
|
2013-06-15 02:47:01 +00:00
|
|
|
// nsISupports
|
1998-10-22 23:00:37 +00:00
|
|
|
|
2014-04-27 07:06:00 +00:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLLabelElement, nsGenericHTMLFormElement,
|
|
|
|
nsIDOMHTMLLabelElement)
|
1998-09-03 01:03:33 +00:00
|
|
|
|
2013-07-31 03:32:35 +00:00
|
|
|
// nsIDOMHTMLLabelElement
|
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLLabelElement)
|
1999-07-28 05:26:55 +00:00
|
|
|
|
2013-07-31 03:32:35 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
|
|
|
{
|
|
|
|
return nsGenericHTMLFormElement::GetForm(aForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetControl(nsIDOMHTMLElement** aElement)
|
|
|
|
{
|
2013-08-07 20:23:08 +00:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryObject(GetLabeledElement());
|
2013-07-31 03:32:35 +00:00
|
|
|
element.forget(aElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::SetHtmlFor(const nsAString& aHtmlFor)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
SetHtmlFor(aHtmlFor, rv);
|
2015-04-27 13:18:51 +00:00
|
|
|
return rv.StealNSResult();
|
2013-07-31 03:32:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetHtmlFor(nsAString& aHtmlFor)
|
|
|
|
{
|
|
|
|
nsString htmlFor;
|
|
|
|
GetHtmlFor(htmlFor);
|
|
|
|
aHtmlFor = htmlFor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-06 07:19:52 +00:00
|
|
|
void
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLLabelElement::Focus(ErrorResult& aError)
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
{
|
|
|
|
// retarget the focus method at the for content
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
2013-08-07 20:23:08 +00:00
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryObject(GetLabeledElement());
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
if (elem)
|
|
|
|
fm->SetFocus(elem, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
static bool
|
2015-01-20 20:39:28 +00:00
|
|
|
InInteractiveHTMLContent(nsIContent* aContent, nsIContent* aStop)
|
2002-05-23 00:23:12 +00:00
|
|
|
{
|
2015-01-20 20:39:28 +00:00
|
|
|
nsIContent* content = aContent;
|
|
|
|
while (content && content != aStop) {
|
|
|
|
if (content->IsElement() &&
|
2015-03-17 20:42:14 +00:00
|
|
|
content->AsElement()->IsInteractiveHTMLContent(true)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2002-05-23 00:23:12 +00:00
|
|
|
}
|
2003-07-28 22:32:31 +00:00
|
|
|
content = content->GetParent();
|
2002-05-23 00:23:12 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2002-05-23 00:23:12 +00:00
|
|
|
}
|
|
|
|
|
2004-01-09 23:54:21 +00:00
|
|
|
nsresult
|
2014-03-18 04:48:20 +00:00
|
|
|
HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
1998-09-03 01:03:33 +00:00
|
|
|
{
|
2013-10-28 09:03:19 +00:00
|
|
|
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
|
2002-05-22 00:14:51 +00:00
|
|
|
if (mHandlingEvent ||
|
2013-10-28 09:03:19 +00:00
|
|
|
(!(mouseEvent && mouseEvent->IsLeftClickEvent()) &&
|
2009-03-24 00:55:29 +00:00
|
|
|
aVisitor.mEvent->message != NS_MOUSE_BUTTON_DOWN) ||
|
2006-03-07 17:08:51 +00:00
|
|
|
aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault ||
|
2011-07-19 16:19:32 +00:00
|
|
|
!aVisitor.mPresContext ||
|
|
|
|
// Don't handle the event if it's already been handled by another label
|
2012-12-16 01:26:04 +00:00
|
|
|
aVisitor.mEvent->mFlags.mMultipleActionsPrevented) {
|
2002-05-22 00:14:51 +00:00
|
|
|
return NS_OK;
|
2006-03-07 17:08:51 +00:00
|
|
|
}
|
2000-12-23 10:56:31 +00:00
|
|
|
|
2015-01-20 20:39:28 +00:00
|
|
|
nsCOMPtr<nsIContent> target = do_QueryInterface(aVisitor.mEvent->target);
|
|
|
|
if (InInteractiveHTMLContent(target, this)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-25 00:18:31 +00:00
|
|
|
// Strong ref because event dispatch is going to happen.
|
|
|
|
nsRefPtr<Element> content = GetLabeledElement();
|
2010-05-20 02:28:10 +00:00
|
|
|
|
2015-01-20 20:39:28 +00:00
|
|
|
if (content) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mHandlingEvent = true;
|
2006-03-07 17:08:51 +00:00
|
|
|
switch (aVisitor.mEvent->message) {
|
2009-03-24 00:55:29 +00:00
|
|
|
case NS_MOUSE_BUTTON_DOWN:
|
2013-10-28 09:03:19 +00:00
|
|
|
if (mouseEvent->button == WidgetMouseEvent::eLeftButton) {
|
2009-03-24 00:55:29 +00:00
|
|
|
// We reset the mouse-down point on every event because there is
|
|
|
|
// no guarantee we will reach the NS_MOUSE_CLICK code below.
|
2013-08-02 07:05:16 +00:00
|
|
|
LayoutDeviceIntPoint* curPoint =
|
2013-10-28 09:03:19 +00:00
|
|
|
new LayoutDeviceIntPoint(mouseEvent->refPoint);
|
2009-03-24 00:55:29 +00:00
|
|
|
SetProperty(nsGkAtoms::labelMouseDownPtProperty,
|
2013-08-02 07:05:16 +00:00
|
|
|
static_cast<void*>(curPoint),
|
2014-03-25 13:25:47 +00:00
|
|
|
nsINode::DeleteProperty<LayoutDeviceIntPoint>);
|
2009-03-24 00:55:29 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2006-11-16 21:35:39 +00:00
|
|
|
case NS_MOUSE_CLICK:
|
2013-10-28 09:03:19 +00:00
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
2013-08-02 07:05:16 +00:00
|
|
|
LayoutDeviceIntPoint* mouseDownPoint =
|
|
|
|
static_cast<LayoutDeviceIntPoint*>(
|
|
|
|
GetProperty(nsGkAtoms::labelMouseDownPtProperty));
|
2009-03-24 00:55:29 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool dragSelect = false;
|
2009-03-24 00:55:29 +00:00
|
|
|
if (mouseDownPoint) {
|
2013-08-02 07:05:16 +00:00
|
|
|
LayoutDeviceIntPoint dragDistance = *mouseDownPoint;
|
2009-03-24 00:55:29 +00:00
|
|
|
DeleteProperty(nsGkAtoms::labelMouseDownPtProperty);
|
|
|
|
|
2013-10-22 08:55:20 +00:00
|
|
|
dragDistance -= mouseEvent->refPoint;
|
2009-03-24 00:55:29 +00:00
|
|
|
const int CLICK_DISTANCE = 2;
|
|
|
|
dragSelect = dragDistance.x > CLICK_DISTANCE ||
|
|
|
|
dragDistance.x < -CLICK_DISTANCE ||
|
|
|
|
dragDistance.y > CLICK_DISTANCE ||
|
|
|
|
dragDistance.y < -CLICK_DISTANCE;
|
|
|
|
}
|
|
|
|
// Don't click the for-content if we did drag-select text or if we
|
2013-06-15 02:47:01 +00:00
|
|
|
// have a kbd modifier (which adjusts a selection).
|
2013-10-22 08:55:20 +00:00
|
|
|
if (dragSelect || mouseEvent->IsShift() || mouseEvent->IsControl() ||
|
|
|
|
mouseEvent->IsAlt() || mouseEvent->IsMeta()) {
|
2009-03-24 00:55:29 +00:00
|
|
|
break;
|
|
|
|
}
|
2013-06-15 02:47:01 +00:00
|
|
|
// Only set focus on the first click of multiple clicks to prevent
|
|
|
|
// to prevent immediate de-focus.
|
2013-10-22 08:55:20 +00:00
|
|
|
if (mouseEvent->clickCount <= 1) {
|
2013-06-15 02:47:01 +00:00
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
// Use FLAG_BYMOVEFOCUS here so that the label is scrolled to.
|
|
|
|
// Also, within HTMLInputElement::PostHandleEvent, inputs will
|
|
|
|
// be selected only when focused via a key or when the navigation
|
|
|
|
// flag is used and we want to select the text on label clicks as
|
|
|
|
// well.
|
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(content);
|
|
|
|
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOVEFOCUS);
|
|
|
|
}
|
2005-01-20 16:59:42 +00:00
|
|
|
}
|
|
|
|
// Dispatch a new click event to |content|
|
|
|
|
// (For compatibility with IE, we do only left click. If
|
|
|
|
// we wanted to interpret the HTML spec very narrowly, we
|
|
|
|
// would do nothing. If we wanted to do something
|
|
|
|
// sensible, we might send more events through like
|
|
|
|
// this.) See bug 7554, bug 49897, and bug 96813.
|
2006-03-07 17:08:51 +00:00
|
|
|
nsEventStatus status = aVisitor.mEventStatus;
|
|
|
|
// Ok to use aVisitor.mEvent as parameter because DispatchClickEvent
|
|
|
|
// will actually create a new event.
|
2013-09-14 02:39:41 +00:00
|
|
|
EventFlags eventFlags;
|
2012-12-16 01:26:04 +00:00
|
|
|
eventFlags.mMultipleActionsPrevented = true;
|
2013-10-22 08:55:20 +00:00
|
|
|
DispatchClickEvent(aVisitor.mPresContext, mouseEvent,
|
2012-12-16 01:26:04 +00:00
|
|
|
content, false, &eventFlags, &status);
|
2005-01-20 16:59:42 +00:00
|
|
|
// Do we care about the status this returned? I don't think we do...
|
2011-07-19 16:19:32 +00:00
|
|
|
// Don't run another <label> off of this click
|
2013-10-22 08:55:20 +00:00
|
|
|
mouseEvent->mFlags.mMultipleActionsPrevented = true;
|
2004-11-04 01:36:18 +00:00
|
|
|
}
|
2002-05-22 00:14:51 +00:00
|
|
|
break;
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mHandlingEvent = false;
|
2002-05-22 00:14:51 +00:00
|
|
|
}
|
2006-03-07 17:08:51 +00:00
|
|
|
return NS_OK;
|
1999-11-02 23:38:17 +00:00
|
|
|
}
|
1999-10-07 00:35:04 +00:00
|
|
|
|
2001-11-02 07:40:01 +00:00
|
|
|
nsresult
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLLabelElement::Reset()
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-16 01:19:24 +00:00
|
|
|
NS_IMETHODIMP
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLLabelElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
|
2001-11-02 07:40:01 +00:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-22 00:14:51 +00:00
|
|
|
|
2007-02-13 15:02:57 +00:00
|
|
|
void
|
2012-12-21 14:06:50 +00:00
|
|
|
HTMLLabelElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-02-13 15:02:57 +00:00
|
|
|
{
|
|
|
|
if (!aKeyCausesActivation) {
|
2011-05-25 00:18:31 +00:00
|
|
|
nsRefPtr<Element> element = GetLabeledElement();
|
|
|
|
if (element)
|
|
|
|
element->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
|
2007-02-13 15:02:57 +00:00
|
|
|
} else {
|
2014-08-22 20:11:27 +00:00
|
|
|
nsPresContext *presContext = GetPresContext(eForUncomposedDoc);
|
2007-02-13 15:02:57 +00:00
|
|
|
if (!presContext)
|
|
|
|
return;
|
|
|
|
|
|
|
|
// Click on it if the users prefs indicate to do so.
|
2013-10-02 06:38:27 +00:00
|
|
|
WidgetMouseEvent event(aIsTrustedEvent, NS_MOUSE_CLICK,
|
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
2011-08-26 07:43:56 +00:00
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD;
|
2007-02-13 15:02:57 +00:00
|
|
|
|
|
|
|
nsAutoPopupStatePusher popupStatePusher(aIsTrustedEvent ?
|
|
|
|
openAllowed : openAbused);
|
|
|
|
|
2014-03-18 04:48:21 +00:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
|
|
|
|
&event);
|
2007-02-13 15:02:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-21 14:07:28 +00:00
|
|
|
nsGenericHTMLElement*
|
|
|
|
HTMLLabelElement::GetLabeledElement() const
|
2002-05-22 00:14:51 +00:00
|
|
|
{
|
|
|
|
nsAutoString elementId;
|
2010-05-20 02:28:10 +00:00
|
|
|
|
|
|
|
if (!GetAttr(kNameSpaceID_None, nsGkAtoms::_for, elementId)) {
|
|
|
|
// No @for, so we are a label for our first form control element.
|
|
|
|
// Do a depth-first traversal to look for the first form control element.
|
2012-06-10 23:44:50 +00:00
|
|
|
return GetFirstLabelableDescendant();
|
2003-02-22 13:01:03 +00:00
|
|
|
}
|
2010-05-20 02:28:10 +00:00
|
|
|
|
|
|
|
// We have a @for. The id has to be linked to an element in the same document
|
|
|
|
// and this element should be a labelable form control.
|
2014-10-02 19:07:24 +00:00
|
|
|
//XXXsmaug It is unclear how this should work in case the element is in
|
|
|
|
// Shadow DOM.
|
|
|
|
// See https://www.w3.org/Bugs/Public/show_bug.cgi?id=26365.
|
|
|
|
nsIDocument* doc = GetUncomposedDoc();
|
2010-05-20 02:28:10 +00:00
|
|
|
if (!doc) {
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2010-05-20 02:28:10 +00:00
|
|
|
}
|
|
|
|
|
2011-05-25 00:18:31 +00:00
|
|
|
Element* element = doc->GetElementById(elementId);
|
2012-06-10 23:44:50 +00:00
|
|
|
if (element && element->IsLabelable()) {
|
2012-12-21 14:07:28 +00:00
|
|
|
return static_cast<nsGenericHTMLElement*>(element);
|
2010-05-20 02:28:10 +00:00
|
|
|
}
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2003-02-22 13:01:03 +00:00
|
|
|
}
|
|
|
|
|
2012-12-21 14:07:28 +00:00
|
|
|
nsGenericHTMLElement*
|
|
|
|
HTMLLabelElement::GetFirstLabelableDescendant() const
|
2003-02-22 13:01:03 +00:00
|
|
|
{
|
2012-06-10 23:44:50 +00:00
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur;
|
2011-05-25 00:18:31 +00:00
|
|
|
cur = cur->GetNextNode(this)) {
|
2012-07-30 14:20:58 +00:00
|
|
|
Element* element = cur->IsElement() ? cur->AsElement() : nullptr;
|
2012-06-10 23:44:50 +00:00
|
|
|
if (element && element->IsLabelable()) {
|
2012-12-21 14:07:28 +00:00
|
|
|
return static_cast<nsGenericHTMLElement*>(element);
|
2002-05-22 00:14:51 +00:00
|
|
|
}
|
|
|
|
}
|
2003-02-22 13:01:03 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
return nullptr;
|
2002-05-22 00:14:51 +00:00
|
|
|
}
|
2010-05-20 02:28:10 +00:00
|
|
|
|
2012-12-21 14:06:50 +00:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|