1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #include "nsEventShell.h"
8 #include "nsAccUtils.h"
10 #include "AccAttributes.h"
12 #include "mozilla/StaticPtr.h"
13 #include "mozilla/dom/DOMStringList.h"
15 using namespace mozilla
;
16 using namespace mozilla::a11y
;
18 ////////////////////////////////////////////////////////////////////////////////
20 ////////////////////////////////////////////////////////////////////////////////
22 void nsEventShell::FireEvent(AccEvent
* aEvent
) {
23 if (!aEvent
|| aEvent
->mEventRule
== AccEvent::eDoNotEmit
) return;
25 LocalAccessible
* accessible
= aEvent
->GetAccessible();
26 NS_ENSURE_TRUE_VOID(accessible
);
28 nsINode
* node
= accessible
->GetNode();
30 sEventTargetNode
= node
;
31 sEventFromUserInput
= aEvent
->IsFromUserInput();
35 if (logging::IsEnabled(logging::eEvents
)) {
36 logging::MsgBegin("EVENTS", "events fired");
38 GetAccService()->GetStringEventType(aEvent
->GetEventType(), type
);
39 logging::MsgEntry("type: %s", NS_ConvertUTF16toUTF8(type
).get());
40 if (aEvent
->GetEventType() == nsIAccessibleEvent::EVENT_STATE_CHANGE
) {
41 AccStateChangeEvent
* event
= downcast_accEvent(aEvent
);
42 RefPtr
<dom::DOMStringList
> stringStates
=
43 GetAccService()->GetStringStates(event
->GetState());
45 stringStates
->Item(0, state
);
46 logging::MsgEntry("state: %s = %s", NS_ConvertUTF16toUTF8(state
).get(),
47 event
->IsStateEnabled() ? "true" : "false");
49 logging::AccessibleInfo("target", aEvent
->GetAccessible());
54 accessible
->HandleAccEvent(aEvent
);
55 aEvent
->mEventRule
= AccEvent::eDoNotEmit
;
57 sEventTargetNode
= nullptr;
60 void nsEventShell::FireEvent(uint32_t aEventType
, LocalAccessible
* aAccessible
,
61 EIsFromUserInput aIsFromUserInput
) {
62 NS_ENSURE_TRUE_VOID(aAccessible
);
64 RefPtr
<AccEvent
> event
=
65 new AccEvent(aEventType
, aAccessible
, aIsFromUserInput
);
70 void nsEventShell::GetEventAttributes(nsINode
* aNode
,
71 AccAttributes
* aAttributes
) {
72 if (aNode
!= sEventTargetNode
) return;
74 aAttributes
->SetAttribute(nsGkAtoms::eventFromInput
, sEventFromUserInput
);
77 ////////////////////////////////////////////////////////////////////////////////
78 // nsEventShell: private
80 bool nsEventShell::sEventFromUserInput
= false;
81 StaticRefPtr
<nsINode
> nsEventShell::sEventTargetNode
;