mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Mac-specific: Implement scanning in Safari (issue #129)
This commit is contained in:
parent
4199ea20a8
commit
dd0a4fc896
|
@ -130,6 +130,7 @@ void MacMouseOver::handlePosition()
|
||||||
|
|
||||||
QString strToTranslate;
|
QString strToTranslate;
|
||||||
CGPoint pt = carbonScreenPointFromCocoaScreenPoint( [NSEvent mouseLocation] );
|
CGPoint pt = carbonScreenPointFromCocoaScreenPoint( [NSEvent mouseLocation] );
|
||||||
|
CFArrayRef names = 0;
|
||||||
|
|
||||||
AXUIElementRef elem = 0;
|
AXUIElementRef elem = 0;
|
||||||
AXError err = AXUIElementCopyElementAtPosition( elementSystemWide, pt.x, pt.y, &elem );
|
AXError err = AXUIElementCopyElementAtPosition( elementSystemWide, pt.x, pt.y, &elem );
|
||||||
|
@ -141,8 +142,16 @@ void MacMouseOver::handlePosition()
|
||||||
{
|
{
|
||||||
CFTypeRef parameter = AXValueCreate( kAXValueCGPointType, &pt );
|
CFTypeRef parameter = AXValueCreate( kAXValueCGPointType, &pt );
|
||||||
CFTypeRef rangeValue;
|
CFTypeRef rangeValue;
|
||||||
|
err = AXUIElementCopyParameterizedAttributeNames( elem, &names );
|
||||||
|
if( err != kAXErrorSuccess )
|
||||||
|
break;
|
||||||
|
|
||||||
|
int numOfAttributes = CFArrayGetCount( names );
|
||||||
|
if( CFArrayContainsValue( names, CFRangeMake( 0, numOfAttributes ), CFSTR( "AXRangeForPosition" ) ) )
|
||||||
|
{
|
||||||
|
// Standard interface
|
||||||
err = AXUIElementCopyParameterizedAttributeValue( elem, kAXRangeForPositionParameterizedAttribute,
|
err = AXUIElementCopyParameterizedAttributeValue( elem, kAXRangeForPositionParameterizedAttribute,
|
||||||
parameter, &rangeValue );
|
parameter, ( CFTypeRef * )&rangeValue );
|
||||||
CFRelease( parameter );
|
CFRelease( parameter );
|
||||||
if( err != kAXErrorSuccess )
|
if( err != kAXErrorSuccess )
|
||||||
break;
|
break;
|
||||||
|
@ -193,11 +202,40 @@ void MacMouseOver::handlePosition()
|
||||||
|
|
||||||
handleRetrievedString( strToTranslate, wordPos );
|
handleRetrievedString( strToTranslate, wordPos );
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
else if( CFArrayContainsValue( names, CFRangeMake( 0, numOfAttributes ), CFSTR( "AXTextMarkerForPosition" ) ) )
|
||||||
|
{
|
||||||
|
// Safari interface
|
||||||
|
CFTypeRef marker, range;
|
||||||
|
CFStringRef str;
|
||||||
|
err = AXUIElementCopyParameterizedAttributeValue( elem, CFSTR( "AXTextMarkerForPosition" ),
|
||||||
|
parameter, ( CFTypeRef * )&marker );
|
||||||
|
CFRelease( parameter );
|
||||||
|
if( err != kAXErrorSuccess )
|
||||||
|
break;
|
||||||
|
|
||||||
|
err = AXUIElementCopyParameterizedAttributeValue( elem, CFSTR( "AXLeftWordTextMarkerRangeForTextMarker" ),
|
||||||
|
marker, ( CFTypeRef * )&range );
|
||||||
|
CFRelease( marker );
|
||||||
|
if( err != kAXErrorSuccess )
|
||||||
|
break;
|
||||||
|
|
||||||
|
err = AXUIElementCopyParameterizedAttributeValue( elem, CFSTR( "AXStringForTextMarkerRange" ),
|
||||||
|
range, ( CFTypeRef * )&str );
|
||||||
|
CFRelease( range );
|
||||||
|
if( err == kAXErrorSuccess )
|
||||||
|
{
|
||||||
|
strToTranslate = CFStringRefToQString( str );
|
||||||
|
CFRelease( str );
|
||||||
|
handleRetrievedString( strToTranslate, 0 );
|
||||||
|
}
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if( elem )
|
if( elem )
|
||||||
CFRelease( elem );
|
CFRelease( elem );
|
||||||
|
if( names )
|
||||||
|
CFRelease( names );
|
||||||
}
|
}
|
||||||
|
|
||||||
void MacMouseOver::handleRetrievedString( QString & wordSeq, int wordSeqPos )
|
void MacMouseOver::handleRetrievedString( QString & wordSeq, int wordSeqPos )
|
||||||
|
|
Loading…
Reference in a new issue