Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/src/windows/native/sun/bridge/AccessBridgeEventHandler.cpp
32287 views
/*1* Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425/*26* A class to manage firing Accessibility events to Windows AT27*/2829#include "AccessBridgeDebug.h"30#include "AccessBridgeEventHandler.h"31#include "AccessBridgePackages.h"32#include "WinAccessBridge.h"3334DEBUG_CODE(extern HWND theDialogWindow);35extern "C" {36DEBUG_CODE(void AppendToCallInfo(char *s));37}383940// -----------------------------4142/**43* Initialization. Set all callbacks to null44*/45AccessBridgeEventHandler::AccessBridgeEventHandler() {46javaEventMask = 0;47accessibilityEventMask = 0;4849propertyChangeFP = (AccessBridge_PropertyChangeFP) NULL;50javaShutdownFP = (AccessBridge_JavaShutdownFP) NULL;51focusGainedFP = (AccessBridge_FocusGainedFP) NULL;52focusLostFP = (AccessBridge_FocusLostFP) NULL;53caretUpdateFP = (AccessBridge_CaretUpdateFP) NULL;54mouseClickedFP = (AccessBridge_MouseClickedFP) NULL;55mouseEnteredFP = (AccessBridge_MouseEnteredFP) NULL;56mouseExitedFP = (AccessBridge_MouseExitedFP) NULL;57mousePressedFP = (AccessBridge_MousePressedFP) NULL;58mouseReleasedFP = (AccessBridge_MouseReleasedFP) NULL;59menuCanceledFP = (AccessBridge_MenuCanceledFP) NULL;60menuDeselectedFP = (AccessBridge_MenuDeselectedFP) NULL;61menuSelectedFP = (AccessBridge_MenuSelectedFP) NULL;62popupMenuCanceledFP = (AccessBridge_PopupMenuCanceledFP) NULL;63popupMenuWillBecomeInvisibleFP = (AccessBridge_PopupMenuWillBecomeInvisibleFP) NULL;64popupMenuWillBecomeVisibleFP = (AccessBridge_PopupMenuWillBecomeVisibleFP) NULL;6566propertyNameChangeFP = (AccessBridge_PropertyNameChangeFP) NULL;67propertyDescriptionChangeFP = (AccessBridge_PropertyDescriptionChangeFP) NULL;68propertyStateChangeFP = (AccessBridge_PropertyStateChangeFP) NULL;69propertyValueChangeFP = (AccessBridge_PropertyValueChangeFP) NULL;70propertySelectionChangeFP = (AccessBridge_PropertySelectionChangeFP) NULL;71propertyTextChangeFP = (AccessBridge_PropertyTextChangeFP) NULL;72propertyCaretChangeFP = (AccessBridge_PropertyCaretChangeFP) NULL;73propertyVisibleDataChangeFP = (AccessBridge_PropertyVisibleDataChangeFP) NULL;74propertyChildChangeFP = (AccessBridge_PropertyChildChangeFP) NULL;75propertyActiveDescendentChangeFP = (AccessBridge_PropertyActiveDescendentChangeFP) NULL;7677propertyTableModelChangeFP = (AccessBridge_PropertyTableModelChangeFP) NULL;7879}8081/**82* Destruction.83*/84AccessBridgeEventHandler::~AccessBridgeEventHandler() {85}868788// ------------ Event handling methods8990#define SET_JAVA_EVENT_FP(function, eventFP, callbackFP, eventConstant) \91void AccessBridgeEventHandler::function(eventFP fp, WinAccessBridge *wab) { \92callbackFP = fp; \93if (fp != (eventFP) 0) { \94javaEventMask |= eventConstant; \95wab->addJavaEventNotification(eventConstant); \96} else { \97javaEventMask &= (0xFFFFFFFF - eventConstant); \98wab->removeJavaEventNotification(eventConstant); \99} \100}101102SET_JAVA_EVENT_FP(setPropertyChangeFP, AccessBridge_PropertyChangeFP, propertyChangeFP, cPropertyChangeEvent)103SET_JAVA_EVENT_FP(setJavaShutdownFP, AccessBridge_JavaShutdownFP, javaShutdownFP, cJavaShutdownEvent)104SET_JAVA_EVENT_FP(setFocusGainedFP, AccessBridge_FocusGainedFP, focusGainedFP, cFocusGainedEvent)105SET_JAVA_EVENT_FP(setFocusLostFP, AccessBridge_FocusLostFP, focusLostFP, cFocusLostEvent)106SET_JAVA_EVENT_FP(setCaretUpdateFP, AccessBridge_CaretUpdateFP, caretUpdateFP, cCaretUpdateEvent)107SET_JAVA_EVENT_FP(setMouseClickedFP, AccessBridge_MouseClickedFP, mouseClickedFP, cMouseClickedEvent)108SET_JAVA_EVENT_FP(setMouseEnteredFP, AccessBridge_MouseEnteredFP, mouseEnteredFP, cMouseEnteredEvent)109SET_JAVA_EVENT_FP(setMouseExitedFP, AccessBridge_MouseExitedFP, mouseExitedFP, cMouseExitedEvent)110SET_JAVA_EVENT_FP(setMousePressedFP, AccessBridge_MousePressedFP, mousePressedFP, cMousePressedEvent)111SET_JAVA_EVENT_FP(setMouseReleasedFP, AccessBridge_MouseReleasedFP, mouseReleasedFP, cMouseReleasedEvent)112SET_JAVA_EVENT_FP(setMenuCanceledFP, AccessBridge_MenuCanceledFP, menuCanceledFP, cMenuCanceledEvent)113SET_JAVA_EVENT_FP(setMenuDeselectedFP, AccessBridge_MenuDeselectedFP, menuDeselectedFP, cMenuDeselectedEvent)114SET_JAVA_EVENT_FP(setMenuSelectedFP, AccessBridge_MenuSelectedFP, menuSelectedFP, cMenuSelectedEvent)115SET_JAVA_EVENT_FP(setPopupMenuCanceledFP, AccessBridge_PopupMenuCanceledFP, popupMenuCanceledFP, cPopupMenuCanceledEvent)116SET_JAVA_EVENT_FP(setPopupMenuWillBecomeInvisibleFP, AccessBridge_PopupMenuWillBecomeInvisibleFP, popupMenuWillBecomeInvisibleFP, cPopupMenuWillBecomeInvisibleEvent)117SET_JAVA_EVENT_FP(setPopupMenuWillBecomeVisibleFP, AccessBridge_PopupMenuWillBecomeVisibleFP, popupMenuWillBecomeVisibleFP, cPopupMenuWillBecomeVisibleEvent)118119#define SET_ACCESSIBILITY_EVENT_FP(function, eventFP, callbackFP, eventConstant) \120void AccessBridgeEventHandler::function(eventFP fp, WinAccessBridge *wab) { \121callbackFP = fp; \122if (fp != (eventFP) 0) { \123accessibilityEventMask |= eventConstant; \124wab->addAccessibilityEventNotification(eventConstant); \125} else { \126accessibilityEventMask &= (0xFFFFFFFF - eventConstant); \127wab->removeAccessibilityEventNotification(eventConstant); \128} \129}130131132SET_ACCESSIBILITY_EVENT_FP(setPropertyNameChangeFP, AccessBridge_PropertyNameChangeFP, propertyNameChangeFP, cPropertyNameChangeEvent)133SET_ACCESSIBILITY_EVENT_FP(setPropertyDescriptionChangeFP, AccessBridge_PropertyDescriptionChangeFP, propertyDescriptionChangeFP, cPropertyDescriptionChangeEvent)134SET_ACCESSIBILITY_EVENT_FP(setPropertyStateChangeFP, AccessBridge_PropertyStateChangeFP, propertyStateChangeFP, cPropertyStateChangeEvent)135SET_ACCESSIBILITY_EVENT_FP(setPropertyValueChangeFP, AccessBridge_PropertyValueChangeFP, propertyValueChangeFP, cPropertyValueChangeEvent)136SET_ACCESSIBILITY_EVENT_FP(setPropertySelectionChangeFP, AccessBridge_PropertySelectionChangeFP, propertySelectionChangeFP, cPropertySelectionChangeEvent)137SET_ACCESSIBILITY_EVENT_FP(setPropertyTextChangeFP, AccessBridge_PropertyTextChangeFP, propertyTextChangeFP, cPropertyTextChangeEvent)138SET_ACCESSIBILITY_EVENT_FP(setPropertyCaretChangeFP, AccessBridge_PropertyCaretChangeFP, propertyCaretChangeFP, cPropertyCaretChangeEvent)139SET_ACCESSIBILITY_EVENT_FP(setPropertyVisibleDataChangeFP, AccessBridge_PropertyVisibleDataChangeFP, propertyVisibleDataChangeFP, cPropertyVisibleDataChangeEvent)140SET_ACCESSIBILITY_EVENT_FP(setPropertyChildChangeFP, AccessBridge_PropertyChildChangeFP, propertyChildChangeFP, cPropertyChildChangeEvent)141SET_ACCESSIBILITY_EVENT_FP(setPropertyActiveDescendentChangeFP, AccessBridge_PropertyActiveDescendentChangeFP, propertyActiveDescendentChangeFP, cPropertyActiveDescendentChangeEvent)142143SET_ACCESSIBILITY_EVENT_FP(setPropertyTableModelChangeFP, AccessBridge_PropertyTableModelChangeFP, propertyTableModelChangeFP, cPropertyTableModelChangeEvent)144145146/**147* propertyChange - extends the Java method call to Windows:148* propertyChange(PropertyChangeEvent e, )149*150* Note: PropertyChangeEvent object passed in is a globalReference;151* It is critical that releaseJavaObject() be called152* on the PropertyChangeEvent once it is no longer needed,153* otherwise the JavaVM/JNI will suffer memory leaks154*155*/156void157AccessBridgeEventHandler::firePropertyChange(long vmID,158JOBJECT64 event, JOBJECT64 source,159wchar_t *property, wchar_t *oldName,160wchar_t *newName) {161DEBUG_CODE(char debugBuf[255]);162#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)163DEBUG_CODE(sprintf(debugBuf, "\r\nCalling firePropertyChange(%p, %p):\r\n", event, source));164#else // JOBJECT64 is jlong (64 bit)165DEBUG_CODE(sprintf(debugBuf, "\r\nCalling firePropertyChange(%016I64X, %016I64X):\r\n", event, source));166#endif167DEBUG_CODE(AppendToCallInfo(debugBuf));168169if (propertyChangeFP != (AccessBridge_PropertyChangeFP) 0) {170propertyChangeFP(vmID, event, source, property, oldName, newName);171} else {172DEBUG_CODE(AppendToCallInfo("[ERROR]: propertyChangeFP == 0"));173}174}175176177/**178* FIRE_EVENT - macro for all fireXXX methods (which179* all are basically identical to one another...)180*181* Note: the event and source objects passed in are globalReferences;182* It is critical that releaseJavaObject() be called183* on them once they are no longer needed, otherwise184* the JavaVM/JNI will suffer memory leaks185*186*/187#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)188const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%p, %p); vmID = %X\r\n";189#else // JOBJECT64 is jlong (64 bit)190const char fireEventDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s(%016I64X, %016I64X); vmID = %X\r\n";191#endif192193#define FIRE_EVENT(method, FPprototype, eventFP) \194void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source) { \195DEBUG_CODE(char debugBuf[255]); \196DEBUG_CODE(sprintf(debugBuf, fireEventDebugString, #method, event, source, vmID)); \197DEBUG_CODE(AppendToCallInfo(debugBuf)); \198if (eventFP != (FPprototype) 0) { \199eventFP(vmID, event, source); \200} else { \201DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0")); \202} \203}204205void AccessBridgeEventHandler::fireJavaShutdown(long vmID) {206DEBUG_CODE(char debugBuf[255]);207DEBUG_CODE(sprintf(debugBuf, "[INFO]: Calling fireJavaShutdown; vmID = %X\r\n", vmID));208DEBUG_CODE(AppendToCallInfo(debugBuf));209if (javaShutdownFP != (AccessBridge_JavaShutdownFP) 0) {210javaShutdownFP(vmID);211} else {212DEBUG_CODE(AppendToCallInfo("[ERROR]: javaShutdownFP == 0"));213}214}215216FIRE_EVENT(fireFocusGained, AccessBridge_FocusGainedFP, focusGainedFP)217FIRE_EVENT(fireFocusLost, AccessBridge_FocusLostFP, focusLostFP)218FIRE_EVENT(fireCaretUpdate, AccessBridge_CaretUpdateFP, caretUpdateFP)219FIRE_EVENT(fireMouseClicked, AccessBridge_MouseClickedFP, mouseClickedFP)220FIRE_EVENT(fireMouseEntered, AccessBridge_MouseEnteredFP, mouseEnteredFP)221FIRE_EVENT(fireMouseExited, AccessBridge_MouseExitedFP, mouseExitedFP)222FIRE_EVENT(fireMousePressed, AccessBridge_MousePressedFP, mousePressedFP)223FIRE_EVENT(fireMouseReleased, AccessBridge_MouseReleasedFP, mouseReleasedFP)224FIRE_EVENT(fireMenuCanceled, AccessBridge_MenuCanceledFP, menuCanceledFP)225FIRE_EVENT(fireMenuDeselected, AccessBridge_MenuDeselectedFP, menuDeselectedFP)226FIRE_EVENT(fireMenuSelected, AccessBridge_MenuSelectedFP, menuSelectedFP)227FIRE_EVENT(firePopupMenuCanceled, AccessBridge_PopupMenuCanceledFP, popupMenuCanceledFP)228FIRE_EVENT(firePopupMenuWillBecomeInvisible, AccessBridge_PopupMenuWillBecomeInvisibleFP, popupMenuWillBecomeInvisibleFP)229FIRE_EVENT(firePopupMenuWillBecomeVisible, AccessBridge_PopupMenuWillBecomeVisibleFP, popupMenuWillBecomeVisibleFP)230231232/**233* FIRE_PROPERTY_CHANGE - macro for all fireXXX methods (which234* all are basically identical to one another...235*236* Note: the event and source objects passed in are globalReferences;237* It is critical that releaseJavaObject() be called238* on them once they are no longer needed, otherwise239* the JavaVM/JNI will suffer memory leaks240*241*/242#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)243const char firePropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a no-param property change (%p, %p):\r\n";244#else // JOBJECT64 is jlong (64 bit)245const char firePropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a no-param property change (%016I64X, %016I64X):\r\n";246#endif247248#define FIRE_PROPERTY_CHANGE(method, FPprototype, eventFP) \249void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source) { \250DEBUG_CODE(char debugBuf[255]); \251DEBUG_CODE(sprintf(debugBuf, firePropertyChangeDebugString, #method, event, source)); \252DEBUG_CODE(AppendToCallInfo(debugBuf)); \253if (eventFP != (FPprototype) 0) { \254eventFP(vmID, event, source); \255} else { \256DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0")); \257} \258}259260/**261* FIRE_STRING_PROPERTY_CHANGE - macro for all firePropertyXXXChange methods262* that have strings as the old/new values263264* Note: the event and source objects passed in are globalReferences;265* It is critical that releaseJavaObject() be called266* on them once they are no longer needed, otherwise267* the JavaVM/JNI will suffer memory leaks268*269*/270#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)271const char fireStringPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a string property change (%p, %p, %ls, %ls):\r\n";272#else // JOBJECT64 is jlong (64 bit)273const char fireStringPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing a string property change (%016I64X, %016I64X, %ls, %ls):\r\n";274#endif275276#define FIRE_STRING_PROPERTY_CHANGE(method, FPprototype, eventFP, oldValue, newValue) \277void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \278wchar_t *oldValue, wchar_t *newValue) { \279DEBUG_CODE(char debugBuf[255]); \280DEBUG_CODE(sprintf(debugBuf, fireStringPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \281DEBUG_CODE(AppendToCallInfo(debugBuf)); \282if (eventFP != (FPprototype) 0) { \283eventFP(vmID, event, source, oldValue, newValue); \284} else { \285DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \286} \287}288289/**290* FIRE_INT_PROPERTY_CHANGE - macro for all firePropertyXXXChange methods291* that have ints as the old/new values292*293* Note: the event and source objects passed in are globalReferences;294* It is critical that releaseJavaObject() be called295* on them once they are no longer needed, otherwise296* the JavaVM/JNI will suffer memory leaks297*298*/299#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)300const char fireIntPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an int property change (%p, %p, %d, %d):\r\n";301#else // JOBJECT64 is jlong (64 bit)302const char fireIntPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an int property change (%016I64X, %016I64X, %d, %d):\r\n";303#endif304305#define FIRE_INT_PROPERTY_CHANGE(method, FPprototype, eventFP) \306void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \307int oldValue, int newValue) { \308DEBUG_CODE(char debugBuf[255]); \309DEBUG_CODE(sprintf(debugBuf, fireIntPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \310DEBUG_CODE(AppendToCallInfo(debugBuf)); \311if (eventFP != (FPprototype) 0) { \312eventFP(vmID, event, source, oldValue, newValue); \313} else { \314DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \315} \316}317318/**319* FIRE_AC_PROPERTY_CHANGE - macro for all firePropertyXXXChange methods320* that have jobjects (AccessibleContexts) as the old/new values321*322* Note: the event and source objects passed in are globalReferences;323* It is critical that releaseJavaObject() be called324* on them once they are no longer needed, otherwise325* the JavaVM/JNI will suffer memory leaks326*327*/328#ifdef ACCESSBRIDGE_ARCH_LEGACY // JOBJECT64 is jobject (32 bit pointer)329const char fireACPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an AC property change (%p, %p, %p, %p):\r\n";330#else // JOBJECT64 is jlong (64 bit)331const char fireACPropertyChangeDebugString[] = "[INFO]: In AccessBridgeEventHandler::%s, Firing an AC property change (%016I64X, %016I64X, %016I64X, %016I64X):\r\n";332#endif333334#define FIRE_AC_PROPERTY_CHANGE(method, FPprototype, eventFP) \335void AccessBridgeEventHandler::method(long vmID, JOBJECT64 event, JOBJECT64 source, \336JOBJECT64 oldValue, JOBJECT64 newValue) { \337DEBUG_CODE(char debugBuf[255]); \338DEBUG_CODE(sprintf(debugBuf, fireACPropertyChangeDebugString, #method, event, source, oldValue, newValue)); \339DEBUG_CODE(AppendToCallInfo(debugBuf)); \340if (eventFP != (FPprototype) 0) { \341eventFP(vmID, event, source, oldValue, newValue); \342} else { \343DEBUG_CODE(AppendToCallInfo("[ERROR]: eventFP == 0\r\n")); \344} \345}346347FIRE_STRING_PROPERTY_CHANGE(firePropertyNameChange,348AccessBridge_PropertyNameChangeFP,349propertyNameChangeFP, oldName, newName)350FIRE_STRING_PROPERTY_CHANGE(firePropertyDescriptionChange,351AccessBridge_PropertyDescriptionChangeFP,352propertyDescriptionChangeFP,353oldDescription, newDescription)354FIRE_STRING_PROPERTY_CHANGE(firePropertyStateChange,355AccessBridge_PropertyStateChangeFP,356propertyStateChangeFP, oldState, newState)357FIRE_STRING_PROPERTY_CHANGE(firePropertyValueChange,358AccessBridge_PropertyValueChangeFP,359propertyValueChangeFP, oldValue, newValue)360FIRE_PROPERTY_CHANGE(firePropertySelectionChange,361AccessBridge_PropertySelectionChangeFP,362propertySelectionChangeFP)363FIRE_PROPERTY_CHANGE(firePropertyTextChange,364AccessBridge_PropertyTextChangeFP,365propertyTextChangeFP);366FIRE_INT_PROPERTY_CHANGE(firePropertyCaretChange,367AccessBridge_PropertyCaretChangeFP,368propertyCaretChangeFP)369FIRE_PROPERTY_CHANGE(firePropertyVisibleDataChange,370AccessBridge_PropertyVisibleDataChangeFP,371propertyVisibleDataChangeFP)372FIRE_AC_PROPERTY_CHANGE(firePropertyChildChange,373AccessBridge_PropertyChildChangeFP,374propertyChildChangeFP)375FIRE_AC_PROPERTY_CHANGE(firePropertyActiveDescendentChange,376AccessBridge_PropertyActiveDescendentChangeFP,377propertyActiveDescendentChangeFP)378379FIRE_STRING_PROPERTY_CHANGE(firePropertyTableModelChange,380AccessBridge_PropertyTableModelChangeFP,381propertyTableModelChangeFP, oldValue, newValue)382383384