Bug 1568151 - Replace `target.getInspector()` by `target.getFront("inspector")`....
[gecko.git] / accessible / base / nsEventShell.cpp
blobde49b5bac1f736a85d7bde8ab920391357a7013b
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"
11 #include "mozilla/StaticPtr.h"
13 using namespace mozilla;
14 using namespace mozilla::a11y;
16 ////////////////////////////////////////////////////////////////////////////////
17 // nsEventShell
18 ////////////////////////////////////////////////////////////////////////////////
20 void nsEventShell::FireEvent(AccEvent* aEvent) {
21 if (!aEvent || aEvent->mEventRule == AccEvent::eDoNotEmit) return;
23 Accessible* accessible = aEvent->GetAccessible();
24 NS_ENSURE_TRUE_VOID(accessible);
26 nsINode* node = accessible->GetNode();
27 if (node) {
28 sEventTargetNode = node;
29 sEventFromUserInput = aEvent->IsFromUserInput();
32 #ifdef A11Y_LOG
33 if (logging::IsEnabled(logging::eEvents)) {
34 logging::MsgBegin("EVENTS", "events fired");
35 nsAutoString type;
36 GetAccService()->GetStringEventType(aEvent->GetEventType(), type);
37 logging::MsgEntry("type: %s", NS_ConvertUTF16toUTF8(type).get());
38 logging::AccessibleInfo("target", aEvent->GetAccessible());
39 logging::MsgEnd();
41 #endif
43 accessible->HandleAccEvent(aEvent);
44 aEvent->mEventRule = AccEvent::eDoNotEmit;
46 sEventTargetNode = nullptr;
49 void nsEventShell::FireEvent(uint32_t aEventType, Accessible* aAccessible,
50 EIsFromUserInput aIsFromUserInput) {
51 NS_ENSURE_TRUE_VOID(aAccessible);
53 RefPtr<AccEvent> event =
54 new AccEvent(aEventType, aAccessible, aIsFromUserInput);
56 FireEvent(event);
59 void nsEventShell::GetEventAttributes(nsINode* aNode,
60 nsIPersistentProperties* aAttributes) {
61 if (aNode != sEventTargetNode) return;
63 nsAccUtils::SetAccAttr(aAttributes, nsGkAtoms::eventFromInput,
64 sEventFromUserInput ? NS_LITERAL_STRING("true")
65 : NS_LITERAL_STRING("false"));
68 ////////////////////////////////////////////////////////////////////////////////
69 // nsEventShell: private
71 bool nsEventShell::sEventFromUserInput = false;
72 StaticRefPtr<nsINode> nsEventShell::sEventTargetNode;