Skip to content

Commit

Permalink
Move core extensions that exist for usage with Core to core.rb
Browse files Browse the repository at this point in the history
  • Loading branch information
ferrous26 committed Mar 16, 2012
1 parent 1a47e27 commit e27a329
Show file tree
Hide file tree
Showing 4 changed files with 79 additions and 87 deletions.
49 changes: 47 additions & 2 deletions lib/accessibility/core.rb
Expand Up @@ -23,8 +23,8 @@
end end




require 'ax_elements/version' require 'ax_elements/version'
require 'ax_elements/macruby_extensions' require 'ax_elements/macruby_extensions'


## ##
# @todo I feel a bit weird having to instantiate a new pointer every # @todo I feel a bit weird having to instantiate a new pointer every
Expand Down Expand Up @@ -862,6 +862,51 @@ def handle_not_enough_precision


end end



##
# AXElements extensions to the `Boxed` class. The `Boxed` class is
# simply an abstract base class for structs that MacRuby can use
# via bridge support.
class Boxed
include Accessibility::Core

##
# Returns the number that AXAPI uses in order to know how to wrap
# a struct.
#
# @return [Number]
def ax_value
raise NotImplementedError, "#{self.class} cannot be wraped"
end

##
# Create an `AXValue` from the `Boxed` instance. This will only
# work if for a few boxed types, you will need to check the AXAPI
# documentation for an up to date list.
#
# @return [AXValueRef]
def to_axvalue
wrap self
end
end

# AXElements extensions for `CGPoint`.
class CGPoint; def ax_value; KAXValueCGPointType end end
# AXElements extensions for `CGSize`.
class CGSize; def ax_value; KAXValueCGSizeType; end end
# AXElements extensions for `CGRect`.
class CGRect; def ax_value; KAXValueCGRectType; end end
# AXElements extensions for `CFRange`.
class CFRange; def ax_value; KAXValueCFRangeType; end end

##
# AXElements extensions for `NSObject`.
class NSObject
# @return [Object]
alias_method :to_axvalue, :self
end


unless Object.const_defined? :KAXIdentifierAttribute unless Object.const_defined? :KAXIdentifierAttribute
## ##
# Added for backwards compatability with Snow Leopard. # Added for backwards compatability with Snow Leopard.
Expand Down
50 changes: 0 additions & 50 deletions lib/ax_elements/macruby_extensions.rb
@@ -1,4 +1,3 @@
require 'accessibility/core'
require 'accessibility/translator' require 'accessibility/translator'


## ##
Expand Down Expand Up @@ -106,42 +105,11 @@ class NSString
end end




##
# Extensions to `NSObject`.
class NSObject
# @return [Object]
alias_method :to_axvalue, :self
end


## ##
# Extensions to `Boxed` objects. `Boxed` is the superclass for all structs # Extensions to `Boxed` objects. `Boxed` is the superclass for all structs
# that MacRuby brings over using its BridgeSupport. # that MacRuby brings over using its BridgeSupport.
class Boxed class Boxed
include Accessibility::Core

class << self
##
# The `AXValue` constant for the struct type. Not all structs
# have a value.
#
# @return [AXValueType]
attr_reader :ax_value
end

##
# Create an `AXValue` from the `Boxed` instance. This will only
# work if for a few boxed types, you will need to check the AXAPI
# documentation for an up to date list.
#
# @return [AXValueRef]
def to_axvalue
wrap self
end


private private

## ##
# Return the height of the main screen. # Return the height of the main screen.
# #
Expand All @@ -155,8 +123,6 @@ def screen_height
## ##
# Extensions to `CGPoint`. # Extensions to `CGPoint`.
class CGPoint class CGPoint
@ax_value = KAXValueCGPointType

## ##
# Find the center of a rectangle, treating `self` as the origin and # Find the center of a rectangle, treating `self` as the origin and
# the given `size` as the size of the rectangle. # the given `size` as the size of the rectangle.
Expand Down Expand Up @@ -184,18 +150,9 @@ def flip!
end end




##
# Extensions to `CGSize`.
class CGSize
@ax_value = KAXValueCGSizeType
end


## ##
# Extensions to `CGRect`. # Extensions to `CGRect`.
class CGRect class CGRect
@ax_value = KAXValueCGRectType

## ##
# Treats the rect as belonging to the flipped co-ordinate system # Treats the rect as belonging to the flipped co-ordinate system
# and then flips it to be using the Cartesian co-ordinate system. # and then flips it to be using the Cartesian co-ordinate system.
Expand All @@ -208,13 +165,6 @@ def flip!
end end




##
# Extensions to `CFRange`.
class CFRange
@ax_value = KAXValueCFRangeType
end


## ##
# Extensions to `NilClass`. # Extensions to `NilClass`.
class NilClass class NilClass
Expand Down
41 changes: 32 additions & 9 deletions test/unit/accessibility/test_core.rb
Expand Up @@ -42,15 +42,6 @@ def web_area







# trivial but important for backwards compat with Snow Leopard
def test_identifier_const
assert Object.const_defined? :KAXIdentifierAttribute
assert_equal 'AXIdentifier', KAXIdentifierAttribute
end



## ##
# AFAICT every accessibility object **MUST** have attributes, so # AFAICT every accessibility object **MUST** have attributes, so
# there are no tests to check what happens when they do not exist; # there are no tests to check what happens when they do not exist;
Expand Down Expand Up @@ -664,3 +655,35 @@ def test_not_enough_precision
end end


end end


class TestCoreExtensionsForCore < MiniTest::Unit::TestCase
include Accessibility::Core

def test_to_axvalue_calls_back
point = CGPointMake(1, 2)
assert_equal wrap(point), point.to_axvalue

size = CGSizeMake(2, 5)
assert_equal wrap(size), size.to_axvalue

rect = CGRectMake(5, 9, 8, 4)
assert_equal wrap(rect), rect.to_axvalue

range = CFRange.new(5, 4)
assert_equal wrap(range), range.to_axvalue
end

def test_to_axvalue_alias
obj = Object.new
assert_respond_to obj, :to_axvalue
assert_equal obj.method(:self), obj.method(:to_axvalue)
end

# trivial but important for backwards compat with Snow Leopard
def test_identifier_const
assert Object.const_defined? :KAXIdentifierAttribute
assert_equal 'AXIdentifier', KAXIdentifierAttribute
end

end
26 changes: 0 additions & 26 deletions test/unit/test_macruby_extensions.rb
Expand Up @@ -69,12 +69,6 @@ def test_blank?


class TestNSObjectExtensions < MiniTest::Unit::TestCase class TestNSObjectExtensions < MiniTest::Unit::TestCase


def test_to_axvalue_alias
obj = Object.new
assert_respond_to obj, :to_axvalue
assert_equal obj.method(:self), obj.method(:to_axvalue)
end

# keeping this test just to make sure the version of MacRuby # keeping this test just to make sure the version of MacRuby
# being used is new enough # being used is new enough
def test_inspecting def test_inspecting
Expand All @@ -88,26 +82,6 @@ def test_inspecting
end end




class TestBoxedExtensions < MiniTest::Unit::TestCase
include Accessibility::Core

def test_to_axvalue_calls_back
point = CGPointMake(1, 2)
assert_equal wrap(point), point.to_axvalue

size = CGSizeMake(2, 5)
assert_equal wrap(size), size.to_axvalue

rect = CGRectMake(5, 9, 8, 4)
assert_equal wrap(rect), rect.to_axvalue

range = CFRange.new(5, 4)
assert_equal wrap(range), range.to_axvalue
end

end


class TestCGPointExtensions < MiniTest::Unit::TestCase class TestCGPointExtensions < MiniTest::Unit::TestCase


SCREENS = NSScreen.screens SCREENS = NSScreen.screens
Expand Down

0 comments on commit e27a329

Please sign in to comment.