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