Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move core extensions that exist for usage with Core to core.rb

  • Loading branch information...
commit e27a32989b109c36a17711e66411b0a047cd6101 1 parent 1a47e27
@ferrous26 ferrous26 authored
View
49 lib/accessibility/core.rb
@@ -23,8 +23,8 @@
end
-require 'ax_elements/version'
-require 'ax_elements/macruby_extensions'
+require 'ax_elements/version'
+require 'ax_elements/macruby_extensions'
##
# @todo I feel a bit weird having to instantiate a new pointer every
@@ -862,6 +862,51 @@ def handle_not_enough_precision
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
##
# Added for backwards compatability with Snow Leopard.
View
50 lib/ax_elements/macruby_extensions.rb
@@ -1,4 +1,3 @@
-require 'accessibility/core'
require 'accessibility/translator'
##
@@ -107,41 +106,10 @@ class NSString
##
-# Extensions to `NSObject`.
-class NSObject
- # @return [Object]
- alias_method :to_axvalue, :self
-end
-
-
-##
# Extensions to `Boxed` objects. `Boxed` is the superclass for all structs
# that MacRuby brings over using its BridgeSupport.
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
-
##
# Return the height of the main screen.
#
@@ -155,8 +123,6 @@ def screen_height
##
# Extensions to `CGPoint`.
class CGPoint
- @ax_value = KAXValueCGPointType
-
##
# Find the center of a rectangle, treating `self` as the origin and
# the given `size` as the size of the rectangle.
@@ -185,17 +151,8 @@ def flip!
##
-# Extensions to `CGSize`.
-class CGSize
- @ax_value = KAXValueCGSizeType
-end
-
-
-##
# Extensions to `CGRect`.
class CGRect
- @ax_value = KAXValueCGRectType
-
##
# Treats the rect as belonging to the flipped co-ordinate system
# and then flips it to be using the Cartesian co-ordinate system.
@@ -209,13 +166,6 @@ def flip!
##
-# Extensions to `CFRange`.
-class CFRange
- @ax_value = KAXValueCFRangeType
-end
-
-
-##
# Extensions to `NilClass`.
class NilClass
##
View
41 test/unit/accessibility/test_core.rb
@@ -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
# there are no tests to check what happens when they do not exist;
@@ -664,3 +655,35 @@ def test_not_enough_precision
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
View
26 test/unit/test_macruby_extensions.rb
@@ -69,12 +69,6 @@ def test_blank?
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
# being used is new enough
def test_inspecting
@@ -88,26 +82,6 @@ def test_inspecting
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
SCREENS = NSScreen.screens
Please sign in to comment.
Something went wrong with that request. Please try again.