Skip to content

Commit 94ad018

Browse files
authored
Merge 044c6fe into bb1cde8
2 parents bb1cde8 + 044c6fe commit 94ad018

1 file changed

Lines changed: 24 additions & 39 deletions

File tree

nvdaHelper/remote/ia2LiveRegions.cpp

Lines changed: 24 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -121,39 +121,32 @@ void CALLBACK winEventProcHook(HWINEVENTHOOK hookID, DWORD eventID, HWND hwnd, l
121121
default:
122122
return;
123123
}
124-
IAccessible* pacc=NULL;
125-
IServiceProvider* pserv=NULL;
126-
IAccessible2* pacc2=NULL;
127-
VARIANT varChild;
124+
CComPtr<IAccessible> pacc;
125+
CComVariant varChild;
128126
//Try getting the IAccessible from the event
129127
if(AccessibleObjectFromEvent(hwnd,objectID,childID,&pacc,&varChild)!=S_OK) {
130128
return;
131129
}
132130
//Retreave the object states, and if its invisible or offscreen ignore the event.
133131
CComVariant varState;
134132
pacc->get_accState(varChild,&varState);
135-
VariantClear(&varChild);
136133
if(varState.vt==VT_I4&&(varState.lVal&STATE_SYSTEM_INVISIBLE)) {
137-
pacc->Release();
138134
return;
139135
}
140136
//Retreave an IAccessible2 via IServiceProvider if it exists.
141-
pacc->QueryInterface(IID_IServiceProvider,(void**)(&pserv));
142-
pacc->Release();
137+
CComQIPtr<IServiceProvider> pserv(pacc);
143138
if(!pserv) return;
144-
pserv->QueryService(IID_IAccessible,IID_IAccessible2,(void**)(&pacc2));
145-
pserv->Release();
139+
CComPtr<IAccessible2> pacc2;
140+
pserv->QueryService(IID_IAccessible, IID_IAccessible2, (void**)(&pacc2));
146141
if(!pacc2) return;
147142
//Retreave the IAccessible2 attributes, and if the object is not a live region then ignore the event.
148143
map<wstring,wstring> attribsMap;
149144
if(!fetchIA2Attributes(pacc2,attribsMap)) {
150-
pacc2->Release();
151145
return;
152146
}
153147
auto i=attribsMap.find(L"container-live");
154148
bool live=(i!=attribsMap.end()&&(i->second.compare(L"polite")==0||i->second.compare(L"assertive")==0||i->second.compare(L"rude")==0));
155149
if(!live) {
156-
pacc2->Release();
157150
return;
158151
}
159152
// #1318: In Firefox, all tabs have the same HWND. Objects in background
@@ -163,14 +156,21 @@ void CALLBACK winEventProcHook(HWINEVENTHOOK hookID, DWORD eventID, HWND hwnd, l
163156
// check.
164157
if (varState.vt==VT_I4 && varState.lVal & STATE_SYSTEM_OFFSCREEN
165158
&& isInBackgroundTab(pacc2, hwnd)) {
166-
pacc2->Release();
159+
return;
160+
}
161+
long ia2States = 0;
162+
pacc2->get_states(&ia2States);
163+
if (ia2States & IA2_STATE_EDITABLE) {
164+
// This is editable text. Editable text should never be a live region, as
165+
// this causes typed characters to be echoed when they shouldn't, etc.
166+
// Nevertheless, some authors misguidedly set aria-live on editable text.
167+
// We explicitly ignore this here.
167168
return;
168169
}
169170
wstring politeness = i->second;
170171
i=attribsMap.find(L"container-busy");
171172
bool busy=(i!=attribsMap.end()&&i->second.compare(L"true")==0);
172173
if(busy) {
173-
pacc2->Release();
174174
return;
175175
}
176176
i=attribsMap.find(L"container-relevant");
@@ -185,33 +185,30 @@ void CALLBACK winEventProcHook(HWINEVENTHOOK hookID, DWORD eventID, HWND hwnd, l
185185
}
186186
// We only support additions or text
187187
if(!allowAdditions&&!allowText) {
188-
pacc2->Release();
189188
return;
190189
}
191190
//Only handle show events if additions are allowed
192191
if(eventID==EVENT_OBJECT_SHOW&&!allowAdditions) {
193-
pacc2->Release();
194192
return;
195193
}
196194
// If this is a show event and this is not the root of the region and there is a text parent,
197195
// We can ignore this event as there will be text events which can handle this better
198196
if(eventID==EVENT_OBJECT_SHOW) {
199197
bool ignoreShowEvent=false;
200-
IDispatch* pdispParent=NULL;
198+
CComPtr<IDispatch> pdispParent;
201199
pacc2->get_accParent(&pdispParent);
202200
if(pdispParent) {
203201
// check for text on parent
204-
IAccessibleText* paccTextParent=NULL;
205-
if(pdispParent->QueryInterface(IID_IAccessibleText,(void**)&paccTextParent)==S_OK&&paccTextParent) {
202+
CComQIPtr<IAccessibleText> paccTextParent(pdispParent);
203+
if (paccTextParent) {
206204
ignoreShowEvent=true;
207-
paccTextParent->Release();
208205
}
209206
if(!ignoreShowEvent) {
210207
// Check for useful container-live on parent, as if missing or off, then child must be the root
211208
// Firstly, we assume we are the root of the region and therefore should ignore the event
212209
ignoreShowEvent=true;
213-
IAccessible2* pacc2Parent=NULL;
214-
if(pdispParent->QueryInterface(IID_IAccessible2,(void**)&pacc2Parent)==S_OK) {
210+
CComQIPtr<IAccessible2> pacc2Parent(pdispParent);
211+
if (pacc2Parent) {
215212
map<wstring,wstring> parentAttribsMap;
216213
if(fetchIA2Attributes(pacc2Parent,parentAttribsMap)) {
217214
i=parentAttribsMap.find(L"container-live");
@@ -220,55 +217,43 @@ void CALLBACK winEventProcHook(HWINEVENTHOOK hookID, DWORD eventID, HWND hwnd, l
220217
ignoreShowEvent=false;
221218
}
222219
}
223-
pacc2Parent->Release();
224220
}
225221
}
226-
pdispParent->Release();
227222
}
228223
if(ignoreShowEvent) {
229-
pacc2->Release();
230224
return;
231225
}
232226
}
233227
// name and description changes can only be announced if relevant is text
234228
if(!allowText&&(eventID==EVENT_OBJECT_NAMECHANGE||eventID==EVENT_OBJECT_DESCRIPTIONCHANGE)) {
235-
pacc2->Release();
236229
return;
237230
}
238231
wstring textBuf;
239232
bool gotText=false;
240-
IAccessible2* pacc2Atomic=findAriaAtomic(pacc2,attribsMap);
233+
CComPtr<IAccessible2> pacc2Atomic = findAriaAtomic(pacc2,attribsMap);
241234
if(pacc2Atomic) {
242235
gotText=getTextFromIAccessible(textBuf,pacc2Atomic);
243-
pacc2Atomic->Release();
244236
} else if(eventID==EVENT_OBJECT_NAMECHANGE) {
245-
BSTR name=NULL;
246-
VARIANT varChild;
247-
varChild.vt=VT_I4;
248-
varChild.lVal=0;
237+
CComBSTR name;
238+
CComVariant varChild(0, VT_I4);
249239
pacc2->get_accName(varChild,&name);
250240
if(name) {
251241
textBuf.append(name);
252242
gotText=true;
253-
SysFreeString(name);
254243
}
255244
} else if(eventID==EVENT_OBJECT_DESCRIPTIONCHANGE) {
256-
BSTR desc=NULL;
257-
VARIANT varChild;
258-
varChild.vt=VT_I4;
259-
varChild.lVal=0;
245+
CComBSTR desc;
246+
CComVariant varChild(0, VT_I4);
260247
pacc2->get_accDescription(varChild,&desc);
261248
if(desc) {
262249
textBuf.append(desc);
263250
gotText=true;
264-
SysFreeString(desc);
265251
}
266252
} else if(eventID==EVENT_OBJECT_SHOW) {
267253
gotText=getTextFromIAccessible(textBuf,pacc2);
268254
} else if(eventID==IA2_EVENT_TEXT_INSERTED||eventID==IA2_EVENT_TEXT_UPDATED) {
269255
gotText=getTextFromIAccessible(textBuf,pacc2,true,allowAdditions,allowText);
270256
}
271-
pacc2->Release();
272257
if (gotText && !textBuf.empty()) {
273258
nvdaControllerInternal_reportLiveRegion(textBuf.c_str(), politeness.c_str());
274259
}

0 commit comments

Comments
 (0)