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/. */
|
2011-05-25 04:18:23 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Implementation of HTML <label> elements.
|
|
|
|
*/
|
2012-12-21 18:06:50 +04:00
|
|
|
#include "HTMLLabelElement.h"
|
2014-03-18 08:48:21 +04:00
|
|
|
#include "mozilla/EventDispatcher.h"
|
|
|
|
#include "mozilla/MouseEvents.h"
|
2012-12-21 18:07:28 +04: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 22:00:39 +04:00
|
|
|
#include "nsFocusManager.h"
|
2013-08-23 21:56:20 +04:00
|
|
|
#include "nsIDOMMouseEvent.h"
|
2015-04-15 19:47:03 +03:00
|
|
|
#include "nsQueryObject.h"
|
1998-09-03 05:03:33 +04:00
|
|
|
|
1998-10-23 03:00:37 +04:00
|
|
|
// construction, destruction
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2004-05-19 00:58:12 +04:00
|
|
|
NS_IMPL_NS_NEW_HTML_ELEMENT(Label)
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
HTMLLabelElement::~HTMLLabelElement()
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-12-21 18:07:28 +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
|
|
|
HTMLLabelElement::WrapNode(JSContext *aCx, JS::Handle<JSObject*> aGivenProto)
|
2012-12-21 18:07:28 +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 HTMLLabelElementBinding::Wrap(aCx, this, aGivenProto);
|
2012-12-21 18:07:28 +04:00
|
|
|
}
|
|
|
|
|
2013-06-15 06:47:01 +04:00
|
|
|
// nsISupports
|
1998-10-23 03:00:37 +04:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS_INHERITED(HTMLLabelElement, nsGenericHTMLFormElement,
|
|
|
|
nsIDOMHTMLLabelElement)
|
1998-09-03 05:03:33 +04:00
|
|
|
|
2013-07-31 07:32:35 +04:00
|
|
|
// nsIDOMHTMLLabelElement
|
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
NS_IMPL_ELEMENT_CLONE(HTMLLabelElement)
|
1999-07-28 09:26:55 +04:00
|
|
|
|
2013-07-31 07:32:35 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetForm(nsIDOMHTMLFormElement** aForm)
|
|
|
|
{
|
|
|
|
return nsGenericHTMLFormElement::GetForm(aForm);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetControl(nsIDOMHTMLElement** aElement)
|
|
|
|
{
|
2013-08-08 00:23:08 +04:00
|
|
|
nsCOMPtr<nsIDOMHTMLElement> element = do_QueryObject(GetLabeledElement());
|
2013-07-31 07:32:35 +04:00
|
|
|
element.forget(aElement);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::SetHtmlFor(const nsAString& aHtmlFor)
|
|
|
|
{
|
|
|
|
ErrorResult rv;
|
|
|
|
SetHtmlFor(aHtmlFor, rv);
|
2015-04-27 16:18:51 +03:00
|
|
|
return rv.StealNSResult();
|
2013-07-31 07:32:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
HTMLLabelElement::GetHtmlFor(nsAString& aHtmlFor)
|
|
|
|
{
|
|
|
|
nsString htmlFor;
|
|
|
|
GetHtmlFor(htmlFor);
|
|
|
|
aHtmlFor = htmlFor;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2012-10-06 11:19:52 +04:00
|
|
|
void
|
2012-12-21 18:06:50 +04: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 22:00:39 +04:00
|
|
|
{
|
|
|
|
// retarget the focus method at the for content
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
2013-08-08 00:23:08 +04: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 22:00:39 +04:00
|
|
|
if (elem)
|
|
|
|
fm->SetFocus(elem, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2015-01-20 23:39:28 +03:00
|
|
|
InInteractiveHTMLContent(nsIContent* aContent, nsIContent* aStop)
|
2002-05-23 04:23:12 +04:00
|
|
|
{
|
2015-01-20 23:39:28 +03:00
|
|
|
nsIContent* content = aContent;
|
|
|
|
while (content && content != aStop) {
|
|
|
|
if (content->IsElement() &&
|
2015-03-17 23:42:14 +03:00
|
|
|
content->AsElement()->IsInteractiveHTMLContent(true)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2002-05-23 04:23:12 +04:00
|
|
|
}
|
2003-07-29 02:32:31 +04:00
|
|
|
content = content->GetParent();
|
2002-05-23 04:23:12 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2002-05-23 04:23:12 +04:00
|
|
|
}
|
|
|
|
|
2004-01-10 02:54:21 +03:00
|
|
|
nsresult
|
2014-03-18 08:48:20 +04:00
|
|
|
HTMLLabelElement::PostHandleEvent(EventChainPostVisitor& aVisitor)
|
1998-09-03 05:03:33 +04:00
|
|
|
{
|
2013-10-28 13:03:19 +04:00
|
|
|
WidgetMouseEvent* mouseEvent = aVisitor.mEvent->AsMouseEvent();
|
2002-05-22 04:14:51 +04:00
|
|
|
if (mHandlingEvent ||
|
2013-10-28 13:03:19 +04:00
|
|
|
(!(mouseEvent && mouseEvent->IsLeftClickEvent()) &&
|
2015-08-29 02:58:30 +03:00
|
|
|
aVisitor.mEvent->mMessage != eMouseDown) ||
|
2006-03-07 20:08:51 +03:00
|
|
|
aVisitor.mEventStatus == nsEventStatus_eConsumeNoDefault ||
|
2011-07-19 20:19:32 +04:00
|
|
|
!aVisitor.mPresContext ||
|
|
|
|
// Don't handle the event if it's already been handled by another label
|
2012-12-16 05:26:04 +04:00
|
|
|
aVisitor.mEvent->mFlags.mMultipleActionsPrevented) {
|
2002-05-22 04:14:51 +04:00
|
|
|
return NS_OK;
|
2006-03-07 20:08:51 +03:00
|
|
|
}
|
2000-12-23 13:56:31 +03:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
nsCOMPtr<nsIContent> target = do_QueryInterface(aVisitor.mEvent->target);
|
|
|
|
if (InInteractiveHTMLContent(target, this)) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-25 04:18:31 +04:00
|
|
|
// Strong ref because event dispatch is going to happen.
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Element> content = GetLabeledElement();
|
2010-05-20 06:28:10 +04:00
|
|
|
|
2015-01-20 23:39:28 +03:00
|
|
|
if (content) {
|
2011-10-17 18:59:28 +04:00
|
|
|
mHandlingEvent = true;
|
2015-08-22 04:34:51 +03:00
|
|
|
switch (aVisitor.mEvent->mMessage) {
|
2015-08-29 02:58:30 +03:00
|
|
|
case eMouseDown:
|
2013-10-28 13:03:19 +04:00
|
|
|
if (mouseEvent->button == WidgetMouseEvent::eLeftButton) {
|
2009-03-24 03:55:29 +03:00
|
|
|
// We reset the mouse-down point on every event because there is
|
2015-08-29 02:58:32 +03:00
|
|
|
// no guarantee we will reach the eMouseClick code below.
|
2013-08-02 11:05:16 +04:00
|
|
|
LayoutDeviceIntPoint* curPoint =
|
2013-10-28 13:03:19 +04:00
|
|
|
new LayoutDeviceIntPoint(mouseEvent->refPoint);
|
2009-03-24 03:55:29 +03:00
|
|
|
SetProperty(nsGkAtoms::labelMouseDownPtProperty,
|
2013-08-02 11:05:16 +04:00
|
|
|
static_cast<void*>(curPoint),
|
2014-03-25 17:25:47 +04:00
|
|
|
nsINode::DeleteProperty<LayoutDeviceIntPoint>);
|
2009-03-24 03:55:29 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-08-29 02:58:32 +03:00
|
|
|
case eMouseClick:
|
2013-10-28 13:03:19 +04:00
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
2013-08-02 11:05:16 +04:00
|
|
|
LayoutDeviceIntPoint* mouseDownPoint =
|
|
|
|
static_cast<LayoutDeviceIntPoint*>(
|
|
|
|
GetProperty(nsGkAtoms::labelMouseDownPtProperty));
|
2009-03-24 03:55:29 +03:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool dragSelect = false;
|
2009-03-24 03:55:29 +03:00
|
|
|
if (mouseDownPoint) {
|
2013-08-02 11:05:16 +04:00
|
|
|
LayoutDeviceIntPoint dragDistance = *mouseDownPoint;
|
2009-03-24 03:55:29 +03:00
|
|
|
DeleteProperty(nsGkAtoms::labelMouseDownPtProperty);
|
|
|
|
|
2013-10-22 12:55:20 +04:00
|
|
|
dragDistance -= mouseEvent->refPoint;
|
2009-03-24 03:55:29 +03: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 06:47:01 +04:00
|
|
|
// have a kbd modifier (which adjusts a selection).
|
2013-10-22 12:55:20 +04:00
|
|
|
if (dragSelect || mouseEvent->IsShift() || mouseEvent->IsControl() ||
|
|
|
|
mouseEvent->IsAlt() || mouseEvent->IsMeta()) {
|
2009-03-24 03:55:29 +03:00
|
|
|
break;
|
|
|
|
}
|
2013-06-15 06:47:01 +04:00
|
|
|
// Only set focus on the first click of multiple clicks to prevent
|
|
|
|
// to prevent immediate de-focus.
|
2013-10-22 12:55:20 +04:00
|
|
|
if (mouseEvent->clickCount <= 1) {
|
2013-06-15 06:47:01 +04: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.
|
2015-07-08 07:46:48 +03:00
|
|
|
// If the label has been clicked by the user, we also want to
|
|
|
|
// pass FLAG_BYMOUSE so that we get correct focus ring behavior,
|
|
|
|
// but we don't want to pass FLAG_BYMOUSE if this click event was
|
|
|
|
// caused by the user pressing an accesskey.
|
2013-06-15 06:47:01 +04:00
|
|
|
nsCOMPtr<nsIDOMElement> elem = do_QueryInterface(content);
|
2015-07-08 07:46:48 +03:00
|
|
|
bool byMouse = (mouseEvent->inputSource != nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD);
|
2015-11-12 19:35:20 +03:00
|
|
|
bool byTouch = (mouseEvent->inputSource == nsIDOMMouseEvent::MOZ_SOURCE_TOUCH);
|
2015-07-08 07:46:48 +03:00
|
|
|
fm->SetFocus(elem, nsIFocusManager::FLAG_BYMOVEFOCUS |
|
2015-11-12 19:35:20 +03:00
|
|
|
(byMouse ? nsIFocusManager::FLAG_BYMOUSE : 0) |
|
|
|
|
(byTouch ? nsIFocusManager::FLAG_BYTOUCH : 0));
|
2013-06-15 06:47:01 +04:00
|
|
|
}
|
2005-01-20 19:59:42 +03: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 20:08:51 +03:00
|
|
|
nsEventStatus status = aVisitor.mEventStatus;
|
|
|
|
// Ok to use aVisitor.mEvent as parameter because DispatchClickEvent
|
|
|
|
// will actually create a new event.
|
2013-09-14 06:39:41 +04:00
|
|
|
EventFlags eventFlags;
|
2012-12-16 05:26:04 +04:00
|
|
|
eventFlags.mMultipleActionsPrevented = true;
|
2013-10-22 12:55:20 +04:00
|
|
|
DispatchClickEvent(aVisitor.mPresContext, mouseEvent,
|
2012-12-16 05:26:04 +04:00
|
|
|
content, false, &eventFlags, &status);
|
2005-01-20 19:59:42 +03:00
|
|
|
// Do we care about the status this returned? I don't think we do...
|
2011-07-19 20:19:32 +04:00
|
|
|
// Don't run another <label> off of this click
|
2013-10-22 12:55:20 +04:00
|
|
|
mouseEvent->mFlags.mMultipleActionsPrevented = true;
|
2004-11-04 04:36:18 +03:00
|
|
|
}
|
2002-05-22 04:14:51 +04:00
|
|
|
break;
|
2015-08-26 15:56:59 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
2011-10-17 18:59:28 +04:00
|
|
|
mHandlingEvent = false;
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
2006-03-07 20:08:51 +03:00
|
|
|
return NS_OK;
|
1999-11-03 02:38:17 +03:00
|
|
|
}
|
1999-10-07 04:35:04 +04:00
|
|
|
|
2001-11-02 10:40:01 +03:00
|
|
|
nsresult
|
2012-12-21 18:06:50 +04:00
|
|
|
HTMLLabelElement::Reset()
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-02-16 04:19:24 +03:00
|
|
|
NS_IMETHODIMP
|
2012-12-21 18:06:50 +04:00
|
|
|
HTMLLabelElement::SubmitNamesValues(nsFormSubmission* aFormSubmission)
|
2001-11-02 10:40:01 +03:00
|
|
|
{
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-22 04:14:51 +04:00
|
|
|
|
2015-09-18 15:18:42 +03:00
|
|
|
bool
|
2012-12-21 18:06:50 +04:00
|
|
|
HTMLLabelElement::PerformAccesskey(bool aKeyCausesActivation,
|
|
|
|
bool aIsTrustedEvent)
|
2007-02-13 18:02:57 +03:00
|
|
|
{
|
|
|
|
if (!aKeyCausesActivation) {
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<Element> element = GetLabeledElement();
|
2015-09-18 15:18:42 +03:00
|
|
|
if (element) {
|
|
|
|
return element->PerformAccesskey(aKeyCausesActivation, aIsTrustedEvent);
|
|
|
|
}
|
2007-02-13 18:02:57 +03:00
|
|
|
} else {
|
2014-08-23 00:11:27 +04:00
|
|
|
nsPresContext *presContext = GetPresContext(eForUncomposedDoc);
|
2015-09-18 15:18:42 +03:00
|
|
|
if (!presContext) {
|
|
|
|
return false;
|
|
|
|
}
|
2007-02-13 18:02:57 +03:00
|
|
|
|
|
|
|
// Click on it if the users prefs indicate to do so.
|
2015-08-29 02:58:32 +03:00
|
|
|
WidgetMouseEvent event(aIsTrustedEvent, eMouseClick,
|
2013-10-02 10:38:27 +04:00
|
|
|
nullptr, WidgetMouseEvent::eReal);
|
2011-08-26 11:43:56 +04:00
|
|
|
event.inputSource = nsIDOMMouseEvent::MOZ_SOURCE_KEYBOARD;
|
2007-02-13 18:02:57 +03:00
|
|
|
|
|
|
|
nsAutoPopupStatePusher popupStatePusher(aIsTrustedEvent ?
|
|
|
|
openAllowed : openAbused);
|
|
|
|
|
2014-03-18 08:48:21 +04:00
|
|
|
EventDispatcher::Dispatch(static_cast<nsIContent*>(this), presContext,
|
|
|
|
&event);
|
2007-02-13 18:02:57 +03:00
|
|
|
}
|
2015-09-18 15:18:42 +03:00
|
|
|
|
|
|
|
return aKeyCausesActivation;
|
2007-02-13 18:02:57 +03:00
|
|
|
}
|
|
|
|
|
2012-12-21 18:07:28 +04:00
|
|
|
nsGenericHTMLElement*
|
|
|
|
HTMLLabelElement::GetLabeledElement() const
|
2002-05-22 04:14:51 +04:00
|
|
|
{
|
|
|
|
nsAutoString elementId;
|
2010-05-20 06:28:10 +04: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-11 03:44:50 +04:00
|
|
|
return GetFirstLabelableDescendant();
|
2003-02-22 16:01:03 +03:00
|
|
|
}
|
2010-05-20 06:28:10 +04: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 23:07:24 +04: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 06:28:10 +04:00
|
|
|
if (!doc) {
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2010-05-20 06:28:10 +04:00
|
|
|
}
|
|
|
|
|
2011-05-25 04:18:31 +04:00
|
|
|
Element* element = doc->GetElementById(elementId);
|
2012-06-11 03:44:50 +04:00
|
|
|
if (element && element->IsLabelable()) {
|
2012-12-21 18:07:28 +04:00
|
|
|
return static_cast<nsGenericHTMLElement*>(element);
|
2010-05-20 06:28:10 +04:00
|
|
|
}
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2003-02-22 16:01:03 +03:00
|
|
|
}
|
|
|
|
|
2012-12-21 18:07:28 +04:00
|
|
|
nsGenericHTMLElement*
|
|
|
|
HTMLLabelElement::GetFirstLabelableDescendant() const
|
2003-02-22 16:01:03 +03:00
|
|
|
{
|
2012-06-11 03:44:50 +04:00
|
|
|
for (nsIContent* cur = nsINode::GetFirstChild(); cur;
|
2011-05-25 04:18:31 +04:00
|
|
|
cur = cur->GetNextNode(this)) {
|
2012-07-30 18:20:58 +04:00
|
|
|
Element* element = cur->IsElement() ? cur->AsElement() : nullptr;
|
2012-06-11 03:44:50 +04:00
|
|
|
if (element && element->IsLabelable()) {
|
2012-12-21 18:07:28 +04:00
|
|
|
return static_cast<nsGenericHTMLElement*>(element);
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
|
|
|
}
|
2003-02-22 16:01:03 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
return nullptr;
|
2002-05-22 04:14:51 +04:00
|
|
|
}
|
2010-05-20 06:28:10 +04:00
|
|
|
|
2012-12-21 18:06:50 +04:00
|
|
|
} // namespace dom
|
|
|
|
} // namespace mozilla
|