no bug - Bumping Firefox l10n changesets r=release a=l10n-bump DONTBUILD CLOSED TREE
[gecko.git] / accessible / base / nsEventShell.cpp
blobfcdc954919eedde456340680839625459d401aff
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"
9 #include "Logging.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 ////////////////////////////////////////////////////////////////////////////////
19 // nsEventShell
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();
29 if (node) {
30 sEventTargetNode = node;
31 sEventFromUserInput = aEvent->IsFromUserInput();
34 #ifdef A11Y_LOG
35 if (logging::IsEnabled(logging::eEvents)) {
36 logging::MsgBegin("EVENTS", "events fired");
37 nsAutoString type;
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());
44 nsAutoString state;
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());
50 logging::MsgEnd();
52 #endif
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);
67 FireEvent(event);
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;