2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
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/. */
|
2000-03-11 10:39:21 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2000-03-31 07:02:06 +00:00
|
|
|
#include "nsButtonBoxFrame.h"
|
2000-03-11 10:39:21 +00:00
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsIDOMNodeList.h"
|
2003-07-14 09:45:54 +00:00
|
|
|
#include "nsIDOMXULButtonElement.h"
|
2006-12-26 17:47:52 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2000-06-29 02:02:43 +00:00
|
|
|
#include "nsIPresShell.h"
|
2001-03-21 09:01:34 +00:00
|
|
|
#include "nsIDOMElement.h"
|
2006-01-26 02:29:17 +00:00
|
|
|
#include "nsDisplayList.h"
|
2009-06-30 07:56:40 +00:00
|
|
|
#include "nsContentUtils.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
#include "mozilla/dom/Element.h"
|
2014-04-01 04:09:23 +00:00
|
|
|
#include "mozilla/EventStateManager.h"
|
2014-04-03 04:18:36 +00:00
|
|
|
#include "mozilla/EventStates.h"
|
2013-10-28 09:03:19 +00:00
|
|
|
#include "mozilla/MouseEvents.h"
|
2013-09-25 11:21:19 +00:00
|
|
|
#include "mozilla/TextEvents.h"
|
2011-07-20 19:18:54 +00:00
|
|
|
|
2013-10-01 07:22:58 +00:00
|
|
|
using namespace mozilla;
|
2000-03-11 10:39:21 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NS_NewXULButtonFrame
|
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
// Creates a new Button frame and returns it
|
2000-03-11 10:39:21 +00:00
|
|
|
//
|
2005-10-26 21:46:39 +00:00
|
|
|
nsIFrame*
|
2006-03-26 21:30:36 +00:00
|
|
|
NS_NewButtonBoxFrame (nsIPresShell* aPresShell, nsStyleContext* aContext)
|
2000-03-11 10:39:21 +00:00
|
|
|
{
|
2006-03-26 21:30:36 +00:00
|
|
|
return new (aPresShell) nsButtonBoxFrame(aPresShell, aContext);
|
2009-09-12 16:49:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsButtonBoxFrame)
|
2000-03-11 10:39:21 +00:00
|
|
|
|
2013-02-14 11:12:27 +00:00
|
|
|
void
|
2006-01-26 02:29:17 +00:00
|
|
|
nsButtonBoxFrame::BuildDisplayListForChildren(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
|
|
|
const nsDisplayListSet& aLists)
|
2000-03-11 10:39:21 +00:00
|
|
|
{
|
2000-03-22 02:43:08 +00:00
|
|
|
// override, since we don't want children to get events
|
2006-01-26 02:29:17 +00:00
|
|
|
if (aBuilder->IsForEventDelivery())
|
2013-02-14 11:12:27 +00:00
|
|
|
return;
|
|
|
|
nsBoxFrame::BuildDisplayListForChildren(aBuilder, aDirtyRect, aLists);
|
2000-03-11 10:39:21 +00:00
|
|
|
}
|
|
|
|
|
2014-02-18 07:47:48 +00:00
|
|
|
nsresult
|
2004-07-31 23:15:21 +00:00
|
|
|
nsButtonBoxFrame::HandleEvent(nsPresContext* aPresContext,
|
2013-10-02 03:46:03 +00:00
|
|
|
WidgetGUIEvent* aEvent,
|
2001-01-09 02:15:55 +00:00
|
|
|
nsEventStatus* aEventStatus)
|
2000-03-14 11:09:46 +00:00
|
|
|
{
|
2009-02-27 10:48:25 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aEventStatus);
|
|
|
|
if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-14 11:09:46 +00:00
|
|
|
switch (aEvent->message) {
|
2013-10-18 06:10:24 +00:00
|
|
|
case NS_KEY_DOWN: {
|
|
|
|
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
|
|
|
|
if (!keyEvent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_VK_SPACE == keyEvent->keyCode) {
|
2014-04-01 04:09:23 +00:00
|
|
|
EventStateManager* esm = aPresContext->EventStateManager();
|
2013-10-18 06:10:24 +00:00
|
|
|
// :hover:active state
|
|
|
|
esm->SetContentState(mContent, NS_EVENT_STATE_HOVER);
|
|
|
|
esm->SetContentState(mContent, NS_EVENT_STATE_ACTIVE);
|
2001-01-09 02:15:55 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-10-18 06:10:24 +00:00
|
|
|
}
|
2001-01-09 02:15:55 +00:00
|
|
|
|
2013-10-18 06:10:24 +00:00
|
|
|
// On mac, Return fires the default button, not the focused one.
|
2005-06-29 14:20:57 +00:00
|
|
|
#ifndef XP_MACOSX
|
2013-10-18 06:10:24 +00:00
|
|
|
case NS_KEY_PRESS: {
|
|
|
|
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
|
|
|
|
if (!keyEvent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_VK_RETURN == keyEvent->keyCode) {
|
|
|
|
nsCOMPtr<nsIDOMXULButtonElement> buttonEl(do_QueryInterface(mContent));
|
|
|
|
if (buttonEl) {
|
|
|
|
MouseClicked(aPresContext, aEvent);
|
|
|
|
*aEventStatus = nsEventStatus_eConsumeNoDefault;
|
2001-01-09 02:15:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-10-18 06:10:24 +00:00
|
|
|
}
|
2005-06-29 14:20:57 +00:00
|
|
|
#endif
|
2001-01-09 02:15:55 +00:00
|
|
|
|
2013-10-18 06:10:24 +00:00
|
|
|
case NS_KEY_UP: {
|
|
|
|
WidgetKeyboardEvent* keyEvent = aEvent->AsKeyboardEvent();
|
|
|
|
if (!keyEvent) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (NS_VK_SPACE == keyEvent->keyCode) {
|
|
|
|
// only activate on keyup if we're already in the :hover:active state
|
|
|
|
NS_ASSERTION(mContent->IsElement(), "How do we have a non-element?");
|
2014-04-03 04:18:36 +00:00
|
|
|
EventStates buttonState = mContent->AsElement()->State();
|
2013-10-18 06:10:24 +00:00
|
|
|
if (buttonState.HasAllStates(NS_EVENT_STATE_ACTIVE |
|
|
|
|
NS_EVENT_STATE_HOVER)) {
|
|
|
|
// return to normal state
|
2014-04-01 04:09:23 +00:00
|
|
|
EventStateManager* esm = aPresContext->EventStateManager();
|
2013-10-18 06:10:24 +00:00
|
|
|
esm->SetContentState(nullptr, NS_EVENT_STATE_ACTIVE);
|
|
|
|
esm->SetContentState(nullptr, NS_EVENT_STATE_HOVER);
|
|
|
|
MouseClicked(aPresContext, aEvent);
|
2000-03-14 11:09:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
2013-10-18 06:10:24 +00:00
|
|
|
}
|
2000-03-14 11:09:46 +00:00
|
|
|
|
2013-10-28 09:03:19 +00:00
|
|
|
case NS_MOUSE_CLICK: {
|
|
|
|
WidgetMouseEvent* mouseEvent = aEvent->AsMouseEvent();
|
|
|
|
if (mouseEvent->IsLeftClickEvent()) {
|
|
|
|
MouseClicked(aPresContext, mouseEvent);
|
2006-11-16 21:35:39 +00:00
|
|
|
}
|
2000-03-14 11:09:46 +00:00
|
|
|
break;
|
2013-10-28 09:03:19 +00:00
|
|
|
}
|
2000-03-14 11:09:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nsBoxFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2013-10-02 03:46:03 +00:00
|
|
|
nsButtonBoxFrame::DoMouseClick(WidgetGUIEvent* aEvent, bool aTrustEvent)
|
2000-03-14 11:09:46 +00:00
|
|
|
{
|
2000-07-30 07:19:58 +00:00
|
|
|
// Don't execute if we're disabled.
|
2006-12-26 17:47:52 +00:00
|
|
|
if (mContent->AttrValueIs(kNameSpaceID_None, nsGkAtoms::disabled,
|
|
|
|
nsGkAtoms::_true, eCaseMatters))
|
2000-07-30 07:19:58 +00:00
|
|
|
return;
|
|
|
|
|
2000-03-14 11:09:46 +00:00
|
|
|
// Execute the oncommand event handler.
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isShift = false;
|
|
|
|
bool isControl = false;
|
|
|
|
bool isAlt = false;
|
|
|
|
bool isMeta = false;
|
2000-08-24 21:28:22 +00:00
|
|
|
if(aEvent) {
|
2013-10-18 06:10:26 +00:00
|
|
|
WidgetInputEvent* inputEvent = aEvent->AsInputEvent();
|
|
|
|
isShift = inputEvent->IsShift();
|
|
|
|
isControl = inputEvent->IsControl();
|
|
|
|
isAlt = inputEvent->IsAlt();
|
|
|
|
isMeta = inputEvent->IsMeta();
|
2000-08-24 21:28:22 +00:00
|
|
|
}
|
2000-06-29 02:02:43 +00:00
|
|
|
|
|
|
|
// Have the content handle the event, propagating it according to normal DOM rules.
|
2007-03-30 21:11:41 +00:00
|
|
|
nsCOMPtr<nsIPresShell> shell = PresContext()->GetPresShell();
|
2003-12-21 05:36:36 +00:00
|
|
|
if (shell) {
|
2009-06-30 07:56:40 +00:00
|
|
|
nsContentUtils::DispatchXULCommand(mContent,
|
|
|
|
aEvent ?
|
2012-12-16 01:26:03 +00:00
|
|
|
aEvent->mFlags.mIsTrusted : aTrustEvent,
|
2012-07-30 14:20:58 +00:00
|
|
|
nullptr, shell,
|
2009-06-30 07:56:40 +00:00
|
|
|
isControl, isAlt, isShift, isMeta);
|
2000-06-29 02:02:43 +00:00
|
|
|
}
|
2000-03-14 11:09:46 +00:00
|
|
|
}
|