Re: Window title change notification in Apple Safari
Re: Window title change notification in Apple Safari
- Subject: Re: Window title change notification in Apple Safari
- From: email@hidden
- Date: Wed, 02 Mar 2011 00:32:30 +0100
Although notifications about tab switches work well, I believe observing the window title itself will be more suitable for me because:
- loading a new page in the same tab doesn't fire a notification
- there may be a tabless window in Safari
I'd appreciate it if somebody could take a look at the code why I'm not getting notified about title changes in a Safari window.
Regards,
Jake
---------------------------------------------------------------------------------------------
// some mandatory stuff
AXObserverCreate(safari_pid, safari_callback, &observer);
CFRunLoopAddSource(CFRunLoopGetCurrent(), \
AXObserverGetRunLoopSource(observer), \
kCFRunLoopDefaultMode);
element = AXUIElementCreateApplication(safari_pid);
// focused window
CFTypeRef window;
AXUIElementCopyAttributeValue(element, kAXFocusedWindowAttribute,
&window);
// window's children
CFArrayRef children;
AXUIElementCopyAttributeValues(window,
kAXChildrenAttribute,0,10, &children); // 10 should be enough
// search for AXStaticText in children
CFTypeRef staticText;
for(int i=0, count = CFArrayGetCount(children); i<count; ++i){
CFTypeRef role;
AXUIElementCopyAttributeValue(
CFArrayGetValueAtIndex(children, i),
kAXRoleAttribute, &role);
if(CFStringCompare(role, kAXStaticTextRole, 0) == 0){
// found static text
staticText = CFArrayGetValueAtIndex(children, i);
CFRelease(children);
break;
}
}
// get top level UIElement for observing
CFTypeRef topLevel;
AXUIElementCopyAttributeValue(staticText, kAXTopLevelUIElementAttribute,
&topLevel);
// add notification
AXObserverAddNotification(observer, topLevel,
kAXValueChangedNotification, data);
-------------------------------------------------------------------------------------------------------------------------------
On Mar 1, 2011, at 6:31 PM, email@hidden wrote:
> Thank you for taking the time to answer my question, James.
> It was really helpful.
>
> Jake
>
> On Feb 28, 2011, at 10:27 PM, James Dempsey wrote:
>
>>
>> On Feb 28, 2011, at 12:08 PM, email@hidden wrote:
>>
>>> Hello,
>>>
>>> I tried to implement the below-mentioned suggestion to get notified about tab switches in Safari. But adding the notification to observer doesn't return kAXErrorSuccess.
>>> Unfortunately I'm not that familiar with accessibility to see my error. Could someone help me to get this right?
>>>
>>> AXUIElementRef app;
>>> CFTypeRef window;
>>> CFTypeRef tabs;
>>>
>>> // get safari app
>>> app = AXUIElementCreateApplication(safari_pid);
>>>
>>> // get window
>>> AXUIElementCopyAttributeValue(app, kAXFocusedWindowAttribute, &window);
>>>
>>> // get tabs
>>> AXUIElementCopyAttributeValue(window, kAXTabGroupRole, &tabs);
>>
>> The window does not have a 'tab group role' attribute. You would ask for its kAXChildrenAttribute value and go through that array to find the element whose kAXRoleAttribute is kAXTabGroupRole
>>
>>>
>>> // register for changes in tabs
>>> AXObserverAddNotification(observer, tabs, kAXValueChangedNotification, self);
>>
>>
>> There is more information in the reference docs at:
>> http://developer.apple.com/library/mac/#documentation/Accessibility/Reference/AccessibilityLowlevel/AXUIElement_h/CompositePage.html
>>
>> Specifically to use an AXObserver you will need to
>> 1. Create one and provide it a callback method (as defined in the header or in the docs above).
>> 2. Create a runloop observer and add it to a running runloop. AXObserverGetRunLoopSource() documentation has a brief snippet that shows this.
>> 3. Add notifications to the observer as needed.
>>
>> -James
>>
>>
>>>
>>> If there are other possibilities to receive notifications about tab changes (maybe Carbon events or s.th. like that) I'd be glad to hear about them, too.
>>> best regards,
>>> jake
>>>
>>>
>>>
>>>> When the selected tab of a tab group changes, AXValueChangedNotification is fired off for the AXTabGroup. Then you can examine the AXValue of this AXTabGroup and fetch the AXTitle of the AXRadioButton.
>>>>
>>>> Patti Hoa
>>>>
>>>> On Jun 17, 2010, at 8:38 AM, Peter wrote:
>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I am trying to keep track of window title changes in the user's launched applications. With exception of Apple Safari, everything seems to work fine. I got some useful help during the WWDC10.
>>>>>>
>>>>>> I noticed that Safari uses some AXTabGroup items and a change of the current tab doesn't seem to fire a title change notification.
>>>>>>
>>>>>> VoiceOver receives an event of a 'html content' change that would be useful for this case but I cannot find something related in the documentation.
>>>>>>
>>>>>> What solution exists to get a notification if the frontmost tab changed that also changed the window title?
>>>>>>
>>>>>> Thanks for any input,
>>>>>> Peter
>>> _______________________________________________
>>> Do not post admin requests to the list. They will be ignored.
>>> Accessibility-dev mailing list (email@hidden)
>>> Help/Unsubscribe/Update your Subscription:
>>>
>>> This email sent to email@hidden
>>
>> --------------------------------------------------
>> James Dempsey
>> AppKit Engineering
>> Apple
>> email@hidden
>>
>>
>>
>>
>
> _______________________________________________
> Do not post admin requests to the list. They will be ignored.
> Accessibility-dev mailing list (email@hidden)
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Accessibility-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden