Changeset 68252 in webkit


Ignore:
Timestamp:
Sep 24, 2010, 7:38:10 AM (16 years ago)
Author:
[email protected]
Message:

2010-09-24 Hans Wennborg <[email protected]>

Reviewed by Steve Block.

Update DeviceMotionEvent to spec
https://bugs.webkit.org/show_bug.cgi?id=46344

  • fast/dom/DeviceMotion/script-tests/create-event.js:
  • fast/dom/DeviceMotion/create-event-expected.txt: Look for the new attributes.
  • fast/dom/DeviceMotion/script-tests/optional-event-properties.js:
  • fast/dom/DeviceMotion/optional-event-properties-expected.txt: Test the new attributes.
  • fast/dom/script-tests/prototype-inheritance.js: DeviceMotionEvent is not implemented on all platforms, so it should be skipped in this test. This is necessary for platforms that enable the feature to pass the layout tests.

2010-09-24 Hans Wennborg <[email protected]>

Reviewed by Steve Block.

Update DeviceMotionEvent to spec
https://bugs.webkit.org/show_bug.cgi?id=46344

The spec has changed: the DeviceMotionEvent attributes accelerationX,
accelerationY, etc. have been baked into an 'acceleration' attribute
which returns an object with x, y, and z values. Likewise for the
rotation rate. The 'accelerationIncludingGravity' attribute is new.

  • WebCore.exp.in: The DeviceMotionData::create member function has changed. Also export create functions for DeviceMotionData::Acceleration and RotationRate.
  • bindings/js/JSDeviceMotionEventCustom.cpp: (WebCore::JSDeviceMotionEvent::acceleration): (WebCore::JSDeviceMotionEvent::accelerationIncludingGravity): (WebCore::JSDeviceMotionEvent::rotationRate): (WebCore::JSDeviceMotionEvent::initDeviceMotionEvent): Manually create and return objects with the right attributes for acceleration, accelerationIncludingGravity, and rotationRate. When creating the DeviceMotionData object in initDeviceMotionEvent, accept any input objects that have the right attributes.
  • bindings/v8/custom/V8DeviceMotionEventCustom.cpp: (WebCore::V8DeviceMotionEvent::accelerationAccessorGetter): (WebCore::V8DeviceMotionEvent::accelerationIncludingGravityAccessorGetter): (WebCore::V8DeviceMotionEvent::rotationRateAccessorGetter): (WebCore::V8DeviceMotionEvent::initDeviceMotionEventCallback): V8 counterpart to the JSC code above.
  • dom/DeviceMotionData.cpp: (WebCore::DeviceMotionData::Acceleration::create): (WebCore::DeviceMotionData::Acceleration::Acceleration): (WebCore::DeviceMotionData::RotationRate::create): (WebCore::DeviceMotionData::RotationRate::RotationRate): (WebCore::DeviceMotionData::create): (WebCore::DeviceMotionData::DeviceMotionData):
  • dom/DeviceMotionData.h: (WebCore::DeviceMotionData::Acceleration::canProvideX): (WebCore::DeviceMotionData::Acceleration::canProvideY): (WebCore::DeviceMotionData::Acceleration::canProvideZ): (WebCore::DeviceMotionData::Acceleration::x): (WebCore::DeviceMotionData::Acceleration::y): (WebCore::DeviceMotionData::Acceleration::z): (WebCore::DeviceMotionData::RotationRate::canProvideAlpha): (WebCore::DeviceMotionData::RotationRate::canProvideBeta): (WebCore::DeviceMotionData::RotationRate::canProvideGamma): (WebCore::DeviceMotionData::RotationRate::alpha): (WebCore::DeviceMotionData::RotationRate::beta): (WebCore::DeviceMotionData::RotationRate::gamma): (WebCore::DeviceMotionData::acceleration): (WebCore::DeviceMotionData::accelerationIncludingGravity): (WebCore::DeviceMotionData::rotationRate): Add member classes Acceleration and RotationRate to DeviceMotionData.
  • dom/DeviceMotionEvent.idl: Update according to the spec. Acceleration and RotationRate need not be backed by native classes.
Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r68246 r68252  
     12010-09-24  Hans Wennborg  <[email protected]>
     2
     3        Reviewed by Steve Block.
     4
     5        Update DeviceMotionEvent to spec
     6        https://bugs.webkit.org/show_bug.cgi?id=46344
     7
     8        * fast/dom/DeviceMotion/script-tests/create-event.js:
     9        * fast/dom/DeviceMotion/create-event-expected.txt:
     10        Look for the new attributes.
     11
     12        * fast/dom/DeviceMotion/script-tests/optional-event-properties.js:
     13        * fast/dom/DeviceMotion/optional-event-properties-expected.txt:
     14        Test the new attributes.
     15
     16        * fast/dom/script-tests/prototype-inheritance.js:
     17        DeviceMotionEvent is not implemented on all platforms, so it should be
     18        skipped in this test. This is necessary for platforms that enable the
     19        feature to pass the layout tests.
     20
    1212010-09-24  Satish Sampath  <[email protected]>
    222
  • trunk/LayoutTests/fast/dom/DeviceMotion/create-event-expected.txt

    r68241 r68252  
    88PASS 'bubbles' in event is true
    99PASS 'cancelable' in event is true
    10 PASS 'xAcceleration' in event is true
    11 PASS 'yAcceleration' in event is true
    12 PASS 'zAcceleration' in event is true
    13 PASS 'xRotationRate' in event is true
    14 PASS 'yRotationRate' in event is true
    15 PASS 'zRotationRate' in event is true
     10PASS 'acceleration' in event is true
     11PASS 'accelerationIncludingGravity' in event is true
     12PASS 'rotationRate' in event is true
    1613PASS 'interval' in event is true
    1714PASS typeof event.type == 'string' is true
    1815PASS typeof event.bubbles == 'boolean' is true
    1916PASS typeof event.cancelable == 'boolean' is true
    20 PASS typeof event.xAcceleration == 'object' is true
    21 PASS typeof event.yAcceleration == 'object' is true
    22 PASS typeof event.zAcceleration == 'object' is true
    23 PASS typeof event.xRotationRate == 'object' is true
    24 PASS typeof event.yRotationRate == 'object' is true
    25 PASS typeof event.zRotationRate == 'object' is true
     17PASS typeof event.acceleration == 'object' is true
     18PASS typeof event.accelerationIncludingGravity == 'object' is true
     19PASS typeof event.rotationRate == 'object' is true
    2620PASS typeof event.interval == 'object' is true
    2721PASS successfullyParsed is true
  • trunk/LayoutTests/fast/dom/DeviceMotion/optional-event-properties-expected.txt

    r68241 r68252  
    55
    66event = document.createEvent('DeviceMotionEvent')
    7 PASS event.xAcceleration == null is true
    8 PASS event.yAcceleration == null is true
    9 PASS event.zAcceleration == null is true
    10 PASS event.xRotationRate == null is true
    11 PASS event.yRotationRate == null is true
    12 PASS event.zRotationRate == null is true
     7PASS event.acceleration == null is true
     8PASS event.accelerationIncludingGravity == null is true
     9PASS event.rotationRate == null is true
    1310PASS event.interval == null is true
    14 event.initDeviceMotionEvent('', false, false, 0, 1, 2, 3, 4, 5, 6)
    15 PASS event.xAcceleration == 0 is true
    16 PASS event.yAcceleration == 1 is true
    17 PASS event.zAcceleration == 2 is true
    18 PASS event.xRotationRate == 3 is true
    19 PASS event.yRotationRate == 4 is true
    20 PASS event.zRotationRate == 5 is true
    21 PASS event.interval == 6 is true
     11event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)
     12PASS event.acceleration.x == 0 is true
     13PASS event.acceleration.y == 1 is true
     14PASS event.acceleration.z == 2 is true
     15PASS event.accelerationIncludingGravity.x == 3 is true
     16PASS event.accelerationIncludingGravity.y == 4 is true
     17PASS event.accelerationIncludingGravity.z == 5 is true
     18PASS event.rotationRate.alpha == 6 is true
     19PASS event.rotationRate.beta == 7 is true
     20PASS event.rotationRate.gamma == 8 is true
     21PASS event.interval == 9 is true
     22PASS event.initDeviceMotionEvent('', false, false, objectThrowingException, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9) threw exception Error: x getter exception.
     23PASS event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, objectThrowingException, {gamma: 8, beta: 7}, 9) threw exception Error: x getter exception.
     24PASS event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, z: 5}, objectThrowingException, 9) threw exception Error: alpha getter exception.
     25PASS event.initDeviceMotionEvent('', false, false, {x: objectThrowingException, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9) threw exception Error: valueOf threw exception.
     26PASS event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: objectThrowingException, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9) threw exception Error: valueOf threw exception.
     27PASS event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: objectThrowingException}, 9) threw exception Error: valueOf threw exception.
     28event.initDeviceMotionEvent('', false, false, {y: 1, x: 0}, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9)
     29PASS event.acceleration.x == 0 is true
     30PASS event.acceleration.y == 1 is true
     31PASS event.acceleration.z == null is true
     32PASS event.accelerationIncludingGravity.x == 3 is true
     33PASS event.accelerationIncludingGravity.y == null is true
     34PASS event.accelerationIncludingGravity.z == 5 is true
     35PASS event.rotationRate.alpha == null is true
     36PASS event.rotationRate.beta == 7 is true
     37PASS event.rotationRate.gamma == 8 is true
     38PASS event.interval == 9 is true
    2239event.initDeviceMotionEvent()
    23 PASS event.xAcceleration == null is true
    24 PASS event.yAcceleration == null is true
    25 PASS event.zAcceleration == null is true
    26 PASS event.xRotationRate == null is true
    27 PASS event.yRotationRate == null is true
    28 PASS event.zRotationRate == null is true
     40PASS event.acceleration == null is true
     41PASS event.accelerationIncludingGravity == null is true
     42PASS event.rotationRate == null is true
    2943PASS event.interval == null is true
    30 event.initDeviceMotionEvent('', false, false, [], [], [], [], [], [], [])
    31 PASS event.xAcceleration == 0 is true
    32 PASS event.yAcceleration == 0 is true
    33 PASS event.zAcceleration == 0 is true
    34 PASS event.xRotationRate == 0 is true
    35 PASS event.yRotationRate == 0 is true
    36 PASS event.zRotationRate == 0 is true
     44event.initDeviceMotionEvent('', false, false, [], [], [], [])
     45PASS event.acceleration == null is true
     46PASS event.accelerationIncludingGravity == null is true
     47PASS event.rotationRate == null is true
    3748PASS event.interval == 0 is true
    38 event.initDeviceMotionEvent('', false, false, undefined, undefined, undefined, undefined, undefined, undefined, undefined)
    39 PASS event.xAcceleration == null is true
    40 PASS event.yAcceleration == null is true
    41 PASS event.zAcceleration == null is true
    42 PASS event.xRotationRate == null is true
    43 PASS event.yRotationRate == null is true
    44 PASS event.zRotationRate == null is true
     49event.initDeviceMotionEvent('', false, false, undefined, undefined, undefined, undefined)
     50PASS event.acceleration == null is true
     51PASS event.accelerationIncludingGravity == null is true
     52PASS event.rotationRate == null is true
    4553PASS event.interval == null is true
    46 event.initDeviceMotionEvent('', false, false, '', '', '', '', '', '', '')
    47 PASS event.xAcceleration == 0 is true
    48 PASS event.yAcceleration == 0 is true
    49 PASS event.zAcceleration == 0 is true
    50 PASS event.xRotationRate == 0 is true
    51 PASS event.yRotationRate == 0 is true
    52 PASS event.zRotationRate == 0 is true
     54event.initDeviceMotionEvent('', false, false, '', '', '', '')
     55PASS event.acceleration == null is true
     56PASS event.accelerationIncludingGravity == null is true
     57PASS event.rotationRate == null is true
    5358PASS event.interval == 0 is true
    54 event.initDeviceMotionEvent('', false, false, null, null, null, null, null, null, null)
    55 PASS event.xAcceleration == null is true
    56 PASS event.yAcceleration == null is true
    57 PASS event.zAcceleration == null is true
    58 PASS event.xRotationRate == null is true
    59 PASS event.yRotationRate == null is true
    60 PASS event.zRotationRate == null is true
     59event.initDeviceMotionEvent('', false, false, null, null, null, null)
     60PASS event.acceleration == null is true
     61PASS event.accelerationIncludingGravity == null is true
     62PASS event.rotationRate == null is true
     63PASS event.interval == null is true
     64event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: null}, {x: null, y: null, z: null}, {alpha: null, beta: null, gamma: null}, null)
     65PASS event.acceleration == null is true
     66PASS event.accelerationIncludingGravity == null is true
     67PASS event.rotationRate == null is true
     68PASS event.interval == null is true
     69event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: 1}, {x: null, y: null, z: 2}, {alpha: null, beta: null, gamma: 3}, null)
     70PASS event.acceleration.x == null is true
     71PASS event.acceleration.y == null is true
     72PASS event.acceleration.z == 1 is true
     73PASS event.accelerationIncludingGravity.x == null is true
     74PASS event.accelerationIncludingGravity.y == null is true
     75PASS event.accelerationIncludingGravity.z == 2 is true
     76PASS event.rotationRate.alpha == null is true
     77PASS event.rotationRate.beta == null is true
     78PASS event.rotationRate.gamma == 3 is true
     79PASS event.interval == null is true
     80event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: undefined}, {x: undefined, y: undefined, z: undefined}, {alpha: undefined, beta: undefined, gamma: undefined}, undefined)
     81PASS event.acceleration == null is true
     82PASS event.accelerationIncludingGravity == null is true
     83PASS event.rotationRate == null is true
     84PASS event.interval == null is true
     85event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: 1}, {x: undefined, y: undefined, z: 2}, {alpha: undefined, beta: undefined, gamma: 3}, undefined)
     86PASS event.acceleration.x == null is true
     87PASS event.acceleration.y == null is true
     88PASS event.acceleration.z == 1 is true
     89PASS event.accelerationIncludingGravity.x == null is true
     90PASS event.accelerationIncludingGravity.y == null is true
     91PASS event.accelerationIncludingGravity.z == 2 is true
     92PASS event.rotationRate.alpha == null is true
     93PASS event.rotationRate.beta == null is true
     94PASS event.rotationRate.gamma == 3 is true
    6195PASS event.interval == null is true
    6296PASS successfullyParsed is true
  • trunk/LayoutTests/fast/dom/DeviceMotion/script-tests/create-event.js

    r68241 r68252  
    88shouldBeTrue("'bubbles' in event");
    99shouldBeTrue("'cancelable' in event");
    10 shouldBeTrue("'xAcceleration' in event");
    11 shouldBeTrue("'yAcceleration' in event");
    12 shouldBeTrue("'zAcceleration' in event");
    13 shouldBeTrue("'xRotationRate' in event");
    14 shouldBeTrue("'yRotationRate' in event");
    15 shouldBeTrue("'zRotationRate' in event");
     10shouldBeTrue("'acceleration' in event");
     11shouldBeTrue("'accelerationIncludingGravity' in event");
     12shouldBeTrue("'rotationRate' in event");
    1613shouldBeTrue("'interval' in event");
    1714
     
    1916shouldBeTrue("typeof event.bubbles == 'boolean'");
    2017shouldBeTrue("typeof event.cancelable == 'boolean'");
    21 shouldBeTrue("typeof event.xAcceleration == 'object'");
    22 shouldBeTrue("typeof event.yAcceleration == 'object'");
    23 shouldBeTrue("typeof event.zAcceleration == 'object'");
    24 shouldBeTrue("typeof event.xRotationRate == 'object'");
    25 shouldBeTrue("typeof event.yRotationRate == 'object'");
    26 shouldBeTrue("typeof event.zRotationRate == 'object'");
     18shouldBeTrue("typeof event.acceleration == 'object'");
     19shouldBeTrue("typeof event.accelerationIncludingGravity == 'object'");
     20shouldBeTrue("typeof event.rotationRate == 'object'");
    2721shouldBeTrue("typeof event.interval == 'object'");
    2822
  • trunk/LayoutTests/fast/dom/DeviceMotion/script-tests/optional-event-properties.js

    r68241 r68252  
    11description("Tests the optional properties of DeviceMotionEvent. Each property should be null if not set, or set to null or undefined.");
     2
     3function ObjectThrowingException() {};
     4ObjectThrowingException.prototype.valueOf = function() { throw new Error('valueOf threw exception'); }
     5ObjectThrowingException.prototype.__defineGetter__("x", function() { throw new Error('x getter exception'); });
     6ObjectThrowingException.prototype.__defineGetter__("alpha", function() { throw new Error('alpha getter exception'); });
     7var objectThrowingException = new ObjectThrowingException();
     8
     9function testException(expression, expectedException)
     10{
     11    shouldThrow(expression, '(function() { return "' + expectedException + '"; })();');
     12}
    213
    314var event;
    415
    516evalAndLog("event = document.createEvent('DeviceMotionEvent')");
    6 shouldBeTrue("event.xAcceleration == null");
    7 shouldBeTrue("event.yAcceleration == null");
    8 shouldBeTrue("event.zAcceleration == null");
    9 shouldBeTrue("event.xRotationRate == null");
    10 shouldBeTrue("event.yRotationRate == null");
    11 shouldBeTrue("event.zRotationRate == null");
     17shouldBeTrue("event.acceleration == null");
     18shouldBeTrue("event.accelerationIncludingGravity == null");
     19shouldBeTrue("event.rotationRate == null");
    1220shouldBeTrue("event.interval == null");
    1321
    14 evalAndLog("event.initDeviceMotionEvent('', false, false, 0, 1, 2, 3, 4, 5, 6)");
    15 shouldBeTrue("event.xAcceleration == 0");
    16 shouldBeTrue("event.yAcceleration == 1");
    17 shouldBeTrue("event.zAcceleration == 2");
    18 shouldBeTrue("event.xRotationRate == 3");
    19 shouldBeTrue("event.yRotationRate == 4");
    20 shouldBeTrue("event.zRotationRate == 5");
    21 shouldBeTrue("event.interval == 6");
     22evalAndLog("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)");
     23shouldBeTrue("event.acceleration.x == 0");
     24shouldBeTrue("event.acceleration.y == 1");
     25shouldBeTrue("event.acceleration.z == 2");
     26shouldBeTrue("event.accelerationIncludingGravity.x == 3");
     27shouldBeTrue("event.accelerationIncludingGravity.y == 4");
     28shouldBeTrue("event.accelerationIncludingGravity.z == 5");
     29shouldBeTrue("event.rotationRate.alpha == 6");
     30shouldBeTrue("event.rotationRate.beta == 7");
     31shouldBeTrue("event.rotationRate.gamma == 8");
     32shouldBeTrue("event.interval == 9");
     33
     34testException("event.initDeviceMotionEvent('', false, false, objectThrowingException, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9)", "Error: x getter exception");
     35testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, objectThrowingException, {gamma: 8, beta: 7}, 9)", "Error: x getter exception");
     36testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, z: 5}, objectThrowingException, 9)", "Error: alpha getter exception");
     37
     38testException("event.initDeviceMotionEvent('', false, false, {x: objectThrowingException, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)", "Error: valueOf threw exception");
     39testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: objectThrowingException, z: 5}, {alpha: 6, beta: 7, gamma: 8}, 9)", "Error: valueOf threw exception");
     40testException("event.initDeviceMotionEvent('', false, false, {x: 0, y: 1, z: 2}, {x: 3, y: 4, z: 5}, {alpha: 6, beta: 7, gamma: objectThrowingException}, 9)", "Error: valueOf threw exception");
     41
     42evalAndLog("event.initDeviceMotionEvent('', false, false, {y: 1, x: 0}, {x: 3, z: 5}, {gamma: 8, beta: 7}, 9)");
     43shouldBeTrue("event.acceleration.x == 0");
     44shouldBeTrue("event.acceleration.y == 1");
     45shouldBeTrue("event.acceleration.z == null");
     46shouldBeTrue("event.accelerationIncludingGravity.x == 3");
     47shouldBeTrue("event.accelerationIncludingGravity.y == null");
     48shouldBeTrue("event.accelerationIncludingGravity.z == 5");
     49shouldBeTrue("event.rotationRate.alpha == null");
     50shouldBeTrue("event.rotationRate.beta == 7");
     51shouldBeTrue("event.rotationRate.gamma == 8");
     52shouldBeTrue("event.interval == 9");
    2253
    2354evalAndLog("event.initDeviceMotionEvent()");
    24 shouldBeTrue("event.xAcceleration == null");
    25 shouldBeTrue("event.yAcceleration == null");
    26 shouldBeTrue("event.zAcceleration == null");
    27 shouldBeTrue("event.xRotationRate == null");
    28 shouldBeTrue("event.yRotationRate == null");
    29 shouldBeTrue("event.zRotationRate == null");
     55shouldBeTrue("event.acceleration == null");
     56shouldBeTrue("event.accelerationIncludingGravity == null");
     57shouldBeTrue("event.rotationRate == null");
    3058shouldBeTrue("event.interval == null");
    3159
    32 evalAndLog("event.initDeviceMotionEvent('', false, false, [], [], [], [], [], [], [])");
    33 shouldBeTrue("event.xAcceleration == 0");
    34 shouldBeTrue("event.yAcceleration == 0");
    35 shouldBeTrue("event.zAcceleration == 0");
    36 shouldBeTrue("event.xRotationRate == 0");
    37 shouldBeTrue("event.yRotationRate == 0");
    38 shouldBeTrue("event.zRotationRate == 0");
     60evalAndLog("event.initDeviceMotionEvent('', false, false, [], [], [], [])");
     61shouldBeTrue("event.acceleration == null");
     62shouldBeTrue("event.accelerationIncludingGravity == null");
     63shouldBeTrue("event.rotationRate == null");
    3964shouldBeTrue("event.interval == 0");
    4065
    41 evalAndLog("event.initDeviceMotionEvent('', false, false, undefined, undefined, undefined, undefined, undefined, undefined, undefined)");
    42 shouldBeTrue("event.xAcceleration == null");
    43 shouldBeTrue("event.yAcceleration == null");
    44 shouldBeTrue("event.zAcceleration == null");
    45 shouldBeTrue("event.xRotationRate == null");
    46 shouldBeTrue("event.yRotationRate == null");
    47 shouldBeTrue("event.zRotationRate == null");
     66evalAndLog("event.initDeviceMotionEvent('', false, false, undefined, undefined, undefined, undefined)");
     67shouldBeTrue("event.acceleration == null");
     68shouldBeTrue("event.accelerationIncludingGravity == null");
     69shouldBeTrue("event.rotationRate == null");
    4870shouldBeTrue("event.interval == null");
    4971
    50 evalAndLog("event.initDeviceMotionEvent('', false, false, '', '', '', '', '', '', '')");
    51 shouldBeTrue("event.xAcceleration == 0");
    52 shouldBeTrue("event.yAcceleration == 0");
    53 shouldBeTrue("event.zAcceleration == 0");
    54 shouldBeTrue("event.xRotationRate == 0");
    55 shouldBeTrue("event.yRotationRate == 0");
    56 shouldBeTrue("event.zRotationRate == 0");
     72evalAndLog("event.initDeviceMotionEvent('', false, false, '', '', '', '')");
     73shouldBeTrue("event.acceleration == null");
     74shouldBeTrue("event.accelerationIncludingGravity == null");
     75shouldBeTrue("event.rotationRate == null");
    5776shouldBeTrue("event.interval == 0");
    5877
    59 evalAndLog("event.initDeviceMotionEvent('', false, false, null, null, null, null, null, null, null)");
    60 shouldBeTrue("event.xAcceleration == null");
    61 shouldBeTrue("event.yAcceleration == null");
    62 shouldBeTrue("event.zAcceleration == null");
    63 shouldBeTrue("event.xRotationRate == null");
    64 shouldBeTrue("event.yRotationRate == null");
    65 shouldBeTrue("event.zRotationRate == null");
     78evalAndLog("event.initDeviceMotionEvent('', false, false, null, null, null, null)");
     79shouldBeTrue("event.acceleration == null");
     80shouldBeTrue("event.accelerationIncludingGravity == null");
     81shouldBeTrue("event.rotationRate == null");
     82shouldBeTrue("event.interval == null");
     83
     84evalAndLog("event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: null}, {x: null, y: null, z: null}, {alpha: null, beta: null, gamma: null}, null)");
     85shouldBeTrue("event.acceleration == null");
     86shouldBeTrue("event.accelerationIncludingGravity == null");
     87shouldBeTrue("event.rotationRate == null");
     88shouldBeTrue("event.interval == null");
     89
     90evalAndLog("event.initDeviceMotionEvent('', false, false, {x: null, y: null, z: 1}, {x: null, y: null, z: 2}, {alpha: null, beta: null, gamma: 3}, null)");
     91shouldBeTrue("event.acceleration.x == null");
     92shouldBeTrue("event.acceleration.y == null");
     93shouldBeTrue("event.acceleration.z == 1");
     94shouldBeTrue("event.accelerationIncludingGravity.x == null");
     95shouldBeTrue("event.accelerationIncludingGravity.y == null");
     96shouldBeTrue("event.accelerationIncludingGravity.z == 2");
     97shouldBeTrue("event.rotationRate.alpha == null");
     98shouldBeTrue("event.rotationRate.beta == null");
     99shouldBeTrue("event.rotationRate.gamma == 3");
     100shouldBeTrue("event.interval == null");
     101
     102evalAndLog("event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: undefined}, {x: undefined, y: undefined, z: undefined}, {alpha: undefined, beta: undefined, gamma: undefined}, undefined)");
     103shouldBeTrue("event.acceleration == null");
     104shouldBeTrue("event.accelerationIncludingGravity == null");
     105shouldBeTrue("event.rotationRate == null");
     106shouldBeTrue("event.interval == null");
     107
     108evalAndLog("event.initDeviceMotionEvent('', false, false, {x: undefined, y: undefined, z: 1}, {x: undefined, y: undefined, z: 2}, {alpha: undefined, beta: undefined, gamma: 3}, undefined)");
     109shouldBeTrue("event.acceleration.x == null");
     110shouldBeTrue("event.acceleration.y == null");
     111shouldBeTrue("event.acceleration.z == 1");
     112shouldBeTrue("event.accelerationIncludingGravity.x == null");
     113shouldBeTrue("event.accelerationIncludingGravity.y == null");
     114shouldBeTrue("event.accelerationIncludingGravity.z == 2");
     115shouldBeTrue("event.rotationRate.alpha == null");
     116shouldBeTrue("event.rotationRate.beta == null");
     117shouldBeTrue("event.rotationRate.gamma == 3");
    66118shouldBeTrue("event.interval == null");
    67119
  • trunk/LayoutTests/fast/dom/script-tests/prototype-inheritance.js

    r68241 r68252  
    2424    "createBlobURL", "revokeBlobURL",
    2525    "DeviceOrientationEvent",
     26    "DeviceMotionEvent",
    2627    "TEMPORARY", "PERSISTENT",
    2728    "Flags",
  • trunk/WebCore/ChangeLog

    r68251 r68252  
     12010-09-24  Hans Wennborg  <[email protected]>
     2
     3        Reviewed by Steve Block.
     4
     5        Update DeviceMotionEvent to spec
     6        https://bugs.webkit.org/show_bug.cgi?id=46344
     7
     8        The spec has changed: the DeviceMotionEvent attributes accelerationX,
     9        accelerationY, etc. have been baked into an 'acceleration' attribute
     10        which returns an object with x, y, and z values. Likewise for the
     11        rotation rate. The 'accelerationIncludingGravity' attribute is new.
     12
     13        * WebCore.exp.in:
     14        The DeviceMotionData::create member function has changed. Also export
     15        create functions for DeviceMotionData::Acceleration and RotationRate.
     16
     17        * bindings/js/JSDeviceMotionEventCustom.cpp:
     18        (WebCore::JSDeviceMotionEvent::acceleration):
     19        (WebCore::JSDeviceMotionEvent::accelerationIncludingGravity):
     20        (WebCore::JSDeviceMotionEvent::rotationRate):
     21        (WebCore::JSDeviceMotionEvent::initDeviceMotionEvent):
     22        Manually create and return objects with the right attributes for
     23        acceleration, accelerationIncludingGravity, and rotationRate.
     24        When creating the DeviceMotionData object in initDeviceMotionEvent,
     25        accept any input objects that have the right attributes.
     26
     27        * bindings/v8/custom/V8DeviceMotionEventCustom.cpp:
     28        (WebCore::V8DeviceMotionEvent::accelerationAccessorGetter):
     29        (WebCore::V8DeviceMotionEvent::accelerationIncludingGravityAccessorGetter):
     30        (WebCore::V8DeviceMotionEvent::rotationRateAccessorGetter):
     31        (WebCore::V8DeviceMotionEvent::initDeviceMotionEventCallback):
     32        V8 counterpart to the JSC code above.
     33
     34        * dom/DeviceMotionData.cpp:
     35        (WebCore::DeviceMotionData::Acceleration::create):
     36        (WebCore::DeviceMotionData::Acceleration::Acceleration):
     37        (WebCore::DeviceMotionData::RotationRate::create):
     38        (WebCore::DeviceMotionData::RotationRate::RotationRate):
     39        (WebCore::DeviceMotionData::create):
     40        (WebCore::DeviceMotionData::DeviceMotionData):
     41        * dom/DeviceMotionData.h:
     42        (WebCore::DeviceMotionData::Acceleration::canProvideX):
     43        (WebCore::DeviceMotionData::Acceleration::canProvideY):
     44        (WebCore::DeviceMotionData::Acceleration::canProvideZ):
     45        (WebCore::DeviceMotionData::Acceleration::x):
     46        (WebCore::DeviceMotionData::Acceleration::y):
     47        (WebCore::DeviceMotionData::Acceleration::z):
     48        (WebCore::DeviceMotionData::RotationRate::canProvideAlpha):
     49        (WebCore::DeviceMotionData::RotationRate::canProvideBeta):
     50        (WebCore::DeviceMotionData::RotationRate::canProvideGamma):
     51        (WebCore::DeviceMotionData::RotationRate::alpha):
     52        (WebCore::DeviceMotionData::RotationRate::beta):
     53        (WebCore::DeviceMotionData::RotationRate::gamma):
     54        (WebCore::DeviceMotionData::acceleration):
     55        (WebCore::DeviceMotionData::accelerationIncludingGravity):
     56        (WebCore::DeviceMotionData::rotationRate):
     57        Add member classes Acceleration and RotationRate to DeviceMotionData.
     58
     59        * dom/DeviceMotionEvent.idl:
     60        Update according to the spec. Acceleration and RotationRate need not
     61        be backed by native classes.
     62
    1632010-09-24  Romain Pokrzywka  <[email protected]>
    264
  • trunk/WebCore/WebCore.exp.in

    r68241 r68252  
    361361__ZN7WebCore15visitedLinkHashEPKtj
    362362__ZN7WebCore16AbstractDatabase14setIsAvailableEb
    363 __ZN7WebCore16DeviceMotionData6createEbdbdbdbdbdbdbd
     363__ZN7WebCore16DeviceMotionData12Acceleration6createEbdbdbd
     364__ZN7WebCore16DeviceMotionData12RotationRate6createEbdbdbd
     365__ZN7WebCore16DeviceMotionData6createEN3WTF10PassRefPtrINS0_12AccelerationEEES4_NS2_INS0_12RotationRateEEEbd
    364366__ZN7WebCore16FontFallbackList15releaseFontDataEv
    365367__ZN7WebCore16FontPlatformDataC1EP6NSFontbb
  • trunk/WebCore/bindings/js/JSDeviceMotionEventCustom.cpp

    r68241 r68252  
    3636namespace WebCore {
    3737
    38 JSValue JSDeviceMotionEvent::xAcceleration(ExecState* exec) const
     38static PassRefPtr<DeviceMotionData::Acceleration> readAccelerationArgument(JSValue value, ExecState* exec)
     39{
     40    if (value.isUndefinedOrNull())
     41        return 0;
     42
     43    // Given the above test, this will always yield an object.
     44    JSObject* object = value.toObject(exec);
     45
     46    JSValue xValue = object->get(exec, Identifier(exec, "x"));
     47    if (exec->hadException())
     48        return 0;
     49    bool canProvideX = !xValue.isUndefinedOrNull();
     50    double x = xValue.toNumber(exec);
     51    if (exec->hadException())
     52        return 0;
     53
     54    JSValue yValue = object->get(exec, Identifier(exec, "y"));
     55    if (exec->hadException())
     56        return 0;
     57    bool canProvideY = !yValue.isUndefinedOrNull();
     58    double y = yValue.toNumber(exec);
     59    if (exec->hadException())
     60        return 0;
     61
     62    JSValue zValue = object->get(exec, Identifier(exec, "z"));
     63    if (exec->hadException())
     64        return 0;
     65    bool canProvideZ = !zValue.isUndefinedOrNull();
     66    double z = zValue.toNumber(exec);
     67    if (exec->hadException())
     68        return 0;
     69
     70    if (!canProvideX && !canProvideY && !canProvideZ)
     71        return 0;
     72
     73    return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y, canProvideZ, z);
     74}
     75
     76static PassRefPtr<DeviceMotionData::RotationRate> readRotationRateArgument(JSValue value, ExecState* exec)
     77{
     78    if (value.isUndefinedOrNull())
     79        return 0;
     80
     81    // Given the above test, this will always yield an object.
     82    JSObject* object = value.toObject(exec);
     83
     84    JSValue alphaValue = object->get(exec, Identifier(exec, "alpha"));
     85    if (exec->hadException())
     86        return 0;
     87    bool canProvideAlpha = !alphaValue.isUndefinedOrNull();
     88    double alpha = alphaValue.toNumber(exec);
     89    if (exec->hadException())
     90        return 0;
     91
     92    JSValue betaValue = object->get(exec, Identifier(exec, "beta"));
     93    if (exec->hadException())
     94        return 0;
     95    bool canProvideBeta = !betaValue.isUndefinedOrNull();
     96    double beta = betaValue.toNumber(exec);
     97    if (exec->hadException())
     98        return 0;
     99
     100    JSValue gammaValue = object->get(exec, Identifier(exec, "gamma"));
     101    if (exec->hadException())
     102        return 0;
     103    bool canProvideGamma = !gammaValue.isUndefinedOrNull();
     104    double gamma = gammaValue.toNumber(exec);
     105    if (exec->hadException())
     106        return 0;
     107
     108    if (!canProvideAlpha && !canProvideBeta && !canProvideGamma)
     109        return 0;
     110
     111    return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
     112}
     113
     114static JSObject* createAccelerationObject(const DeviceMotionData::Acceleration* acceleration, ExecState* exec)
     115{
     116    JSObject* object = constructEmptyObject(exec);
     117    object->putDirect(Identifier(exec, "x"), acceleration->canProvideX() ? jsNumber(exec, acceleration->x()) : jsNull());
     118    object->putDirect(Identifier(exec, "y"), acceleration->canProvideY() ? jsNumber(exec, acceleration->y()) : jsNull());
     119    object->putDirect(Identifier(exec, "z"), acceleration->canProvideZ() ? jsNumber(exec, acceleration->z()) : jsNull());
     120    return object;
     121}
     122
     123static JSObject* createRotationRateObject(const DeviceMotionData::RotationRate* rotationRate, ExecState* exec)
     124{
     125    JSObject* object = constructEmptyObject(exec);
     126    object->putDirect(Identifier(exec, "alpha"), rotationRate->canProvideAlpha() ? jsNumber(exec, rotationRate->alpha()) : jsNull());
     127    object->putDirect(Identifier(exec, "beta"),  rotationRate->canProvideBeta()  ? jsNumber(exec, rotationRate->beta())  : jsNull());
     128    object->putDirect(Identifier(exec, "gamma"), rotationRate->canProvideGamma() ? jsNumber(exec, rotationRate->gamma()) : jsNull());
     129    return object;
     130}
     131
     132JSValue JSDeviceMotionEvent::acceleration(ExecState* exec) const
    39133{
    40134    DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    41     if (!imp->deviceMotionData()->canProvideXAcceleration())
     135    if (!imp->deviceMotionData()->acceleration())
    42136        return jsNull();
    43     return jsNumber(exec, imp->deviceMotionData()->xAcceleration());
     137    return createAccelerationObject(imp->deviceMotionData()->acceleration(), exec);
    44138}
    45139
    46 JSValue JSDeviceMotionEvent::yAcceleration(ExecState* exec) const
     140JSValue JSDeviceMotionEvent::accelerationIncludingGravity(ExecState* exec) const
    47141{
    48142    DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    49     if (!imp->deviceMotionData()->canProvideYAcceleration())
     143    if (!imp->deviceMotionData()->accelerationIncludingGravity())
    50144        return jsNull();
    51     return jsNumber(exec, imp->deviceMotionData()->yAcceleration());
     145    return createAccelerationObject(imp->deviceMotionData()->accelerationIncludingGravity(), exec);
    52146}
    53147
    54 JSValue JSDeviceMotionEvent::zAcceleration(ExecState* exec) const
     148JSValue JSDeviceMotionEvent::rotationRate(ExecState* exec) const
    55149{
    56150    DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    57     if (!imp->deviceMotionData()->canProvideZAcceleration())
     151    if (!imp->deviceMotionData()->rotationRate())
    58152        return jsNull();
    59     return jsNumber(exec, imp->deviceMotionData()->zAcceleration());
     153    return createRotationRateObject(imp->deviceMotionData()->rotationRate(), exec);
    60154}
    61155
    62 JSValue JSDeviceMotionEvent::xRotationRate(ExecState* exec) const
    63 {
    64     DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    65     if (!imp->deviceMotionData()->canProvideXRotationRate())
    66         return jsNull();
    67     return jsNumber(exec, imp->deviceMotionData()->xRotationRate());
    68 }
    69 
    70 JSValue JSDeviceMotionEvent::yRotationRate(ExecState* exec) const
    71 {
    72     DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    73     if (!imp->deviceMotionData()->canProvideYRotationRate())
    74         return jsNull();
    75     return jsNumber(exec, imp->deviceMotionData()->yRotationRate());
    76 }
    77 
    78 JSValue JSDeviceMotionEvent::zRotationRate(ExecState* exec) const
    79 {
    80     DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    81     if (!imp->deviceMotionData()->canProvideZRotationRate())
    82         return jsNull();
    83     return jsNumber(exec, imp->deviceMotionData()->zRotationRate());
    84 }
    85    
    86156JSValue JSDeviceMotionEvent::interval(ExecState* exec) const
    87157{
     
    91161    return jsNumber(exec, imp->deviceMotionData()->interval());
    92162}
    93    
     163
    94164JSValue JSDeviceMotionEvent::initDeviceMotionEvent(ExecState* exec)
    95165{
     
    97167    bool bubbles = exec->argument(1).toBoolean(exec);
    98168    bool cancelable = exec->argument(2).toBoolean(exec);
     169
    99170    // If any of the parameters are null or undefined, mark them as not provided.
    100171    // Otherwise, use the standard JavaScript conversion.
    101     bool xAccelerationProvided = !exec->argument(3).isUndefinedOrNull();
    102     double xAcceleration = exec->argument(3).toNumber(exec);
    103     bool yAccelerationProvided = !exec->argument(4).isUndefinedOrNull();
    104     double yAcceleration = exec->argument(4).toNumber(exec);
    105     bool zAccelerationProvided = !exec->argument(5).isUndefinedOrNull();
    106     double zAcceleration = exec->argument(5).toNumber(exec);
    107     bool xRotationRateProvided = !exec->argument(6).isUndefinedOrNull();
    108     double xRotationRate = exec->argument(6).toNumber(exec);
    109     bool yRotationRateProvided = !exec->argument(7).isUndefinedOrNull();
    110     double yRotationRate = exec->argument(7).toNumber(exec);
    111     bool zRotationRateProvided = !exec->argument(8).isUndefinedOrNull();
    112     double zRotationRate = exec->argument(8).toNumber(exec);
    113     bool intervalProvided = !exec->argument(9).isUndefinedOrNull();
    114     double interval = exec->argument(9).toNumber(exec);
    115     RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration,
    116                                                                          yAccelerationProvided, yAcceleration,
    117                                                                          zAccelerationProvided, zAcceleration,
    118                                                                          xRotationRateProvided, xRotationRate,
    119                                                                          yRotationRateProvided, yRotationRate,
    120                                                                          zRotationRateProvided, zRotationRate,
    121                                                                          intervalProvided, interval);
     172    RefPtr<DeviceMotionData::Acceleration> acceleration = readAccelerationArgument(exec->argument(3), exec);
     173    if (exec->hadException())
     174        return jsUndefined();
     175
     176    RefPtr<DeviceMotionData::Acceleration> accelerationIncludingGravity = readAccelerationArgument(exec->argument(4), exec);
     177    if (exec->hadException())
     178        return jsUndefined();
     179
     180    RefPtr<DeviceMotionData::RotationRate> rotationRate = readRotationRateArgument(exec->argument(5), exec);
     181    if (exec->hadException())
     182        return jsUndefined();
     183
     184    bool intervalProvided = !exec->argument(6).isUndefinedOrNull();
     185    double interval = exec->argument(6).toNumber(exec);
     186    RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval);
    122187    DeviceMotionEvent* imp = static_cast<DeviceMotionEvent*>(impl());
    123188    imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get());
  • trunk/WebCore/bindings/v8/custom/V8DeviceMotionEventCustom.cpp

    r68241 r68252  
    3838namespace WebCore {
    3939
    40 v8::Handle<v8::Value> V8DeviceMotionEvent::xAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     40namespace {
     41
     42v8::Handle<v8::Value> createAccelerationObject(const DeviceMotionData::Acceleration* acceleration)
    4143{
    42     INC_STATS("DOM.DeviceMotionEvent.xAcceleration._get");
     44    v8::Local<v8::Object> object = v8::Object::New();
     45    object->Set(v8::String::New("x"), acceleration->canProvideX() ? v8::Number::New(acceleration->x()) : v8::Null());
     46    object->Set(v8::String::New("y"), acceleration->canProvideY() ? v8::Number::New(acceleration->y()) : v8::Null());
     47    object->Set(v8::String::New("z"), acceleration->canProvideZ() ? v8::Number::New(acceleration->z()) : v8::Null());
     48    return object;
     49}
     50
     51v8::Handle<v8::Value> createRotationRateObject(const DeviceMotionData::RotationRate* rotationRate)
     52{
     53    v8::Local<v8::Object> object = v8::Object::New();
     54    object->Set(v8::String::New("alpha"), rotationRate->canProvideAlpha() ? v8::Number::New(rotationRate->alpha()) : v8::Null());
     55    object->Set(v8::String::New("beta"),  rotationRate->canProvideBeta()  ? v8::Number::New(rotationRate->beta())  : v8::Null());
     56    object->Set(v8::String::New("gamma"), rotationRate->canProvideGamma() ? v8::Number::New(rotationRate->gamma()) : v8::Null());
     57    return object;
     58}
     59
     60RefPtr<DeviceMotionData::Acceleration> readAccelerationArgument(v8::Local<v8::Value> value)
     61{
     62    if (isUndefinedOrNull(value))
     63        return 0;
     64
     65    // Given the test above, this will always yield an object.
     66    v8::Local<v8::Object> object = value->ToObject();
     67
     68    v8::Local<v8::Value> xValue = object->Get(v8::String::New("x"));
     69    if (xValue.IsEmpty())
     70        return 0;
     71    bool canProvideX = !isUndefinedOrNull(xValue);
     72    double x = static_cast<double>(xValue->NumberValue());
     73
     74    v8::Local<v8::Value> yValue = object->Get(v8::String::New("y"));
     75    if (yValue.IsEmpty())
     76        return 0;
     77    bool canProvideY = !isUndefinedOrNull(yValue);
     78    double y = static_cast<double>(yValue->NumberValue());
     79
     80    v8::Local<v8::Value> zValue = object->Get(v8::String::New("z"));
     81    if (zValue.IsEmpty())
     82        return 0;
     83    bool canProvideZ = !isUndefinedOrNull(zValue);
     84    double z = static_cast<double>(zValue->NumberValue());
     85
     86    if (!canProvideX && !canProvideY && !canProvideZ)
     87        return 0;
     88
     89    return DeviceMotionData::Acceleration::create(canProvideX, x, canProvideY, y, canProvideZ, z);
     90}
     91
     92RefPtr<DeviceMotionData::RotationRate> readRotationRateArgument(v8::Local<v8::Value> value)
     93{
     94    if (isUndefinedOrNull(value))
     95        return 0;
     96
     97    // Given the test above, this will always yield an object.
     98    v8::Local<v8::Object> object = value->ToObject();
     99
     100    v8::Local<v8::Value> alphaValue = object->Get(v8::String::New("alpha"));
     101    if (alphaValue.IsEmpty())
     102        return 0;
     103    bool canProvideAlpha = !isUndefinedOrNull(alphaValue);
     104    double alpha = static_cast<double>(alphaValue->NumberValue());
     105
     106    v8::Local<v8::Value> betaValue = object->Get(v8::String::New("beta"));
     107    if (betaValue.IsEmpty())
     108        return 0;
     109    bool canProvideBeta = !isUndefinedOrNull(betaValue);
     110    double beta = static_cast<double>(betaValue->NumberValue());
     111
     112    v8::Local<v8::Value> gammaValue = object->Get(v8::String::New("gamma"));
     113    if (gammaValue.IsEmpty())
     114        return 0;
     115    bool canProvideGamma = !isUndefinedOrNull(gammaValue);
     116    double gamma = static_cast<double>(gammaValue->NumberValue());
     117
     118    if (!canProvideAlpha && !canProvideBeta && !canProvideGamma)
     119        return 0;
     120
     121    return DeviceMotionData::RotationRate::create(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma);
     122}
     123
     124} // namespace
     125
     126v8::Handle<v8::Value> V8DeviceMotionEvent::accelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     127{
     128    INC_STATS("DOM.DeviceMotionEvent.acceleration._get");
    43129    v8::Handle<v8::Object> holder = info.Holder();
    44130    DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    45     if (!imp->deviceMotionData()->canProvideXAcceleration())
     131    if (!imp->deviceMotionData()->acceleration())
    46132        return v8::Null();
    47     return v8::Number::New(imp->deviceMotionData()->xAcceleration());
     133    return createAccelerationObject(imp->deviceMotionData()->acceleration());
    48134}
    49135
    50 v8::Handle<v8::Value> V8DeviceMotionEvent::yAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     136v8::Handle<v8::Value> V8DeviceMotionEvent::accelerationIncludingGravityAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    51137{
    52     INC_STATS("DOM.DeviceMotionEvent.yAcceleration._get");
     138    INC_STATS("DOM.DeviceMotionEvent.accelerationIncludingGravity._get");
    53139    v8::Handle<v8::Object> holder = info.Holder();
    54140    DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    55     if (!imp->deviceMotionData()->canProvideYAcceleration())
     141    if (!imp->deviceMotionData()->accelerationIncludingGravity())
    56142        return v8::Null();
    57     return v8::Number::New(imp->deviceMotionData()->yAcceleration());
     143    return createAccelerationObject(imp->deviceMotionData()->accelerationIncludingGravity());
    58144}
    59145
    60 v8::Handle<v8::Value> V8DeviceMotionEvent::zAccelerationAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     146v8::Handle<v8::Value> V8DeviceMotionEvent::rotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    61147{
    62     INC_STATS("DOM.DeviceMotionEvent.zAcceleration._get");
     148    INC_STATS("DOM.DeviceMotionEvent.rotationRate._get");
    63149    v8::Handle<v8::Object> holder = info.Holder();
    64150    DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    65     if (!imp->deviceMotionData()->canProvideZAcceleration())
     151    if (!imp->deviceMotionData()->rotationRate())
    66152        return v8::Null();
    67     return v8::Number::New(imp->deviceMotionData()->zAcceleration());
     153    return createRotationRateObject(imp->deviceMotionData()->rotationRate());
    68154}
    69 
    70 v8::Handle<v8::Value> V8DeviceMotionEvent::xRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    71 {
    72     INC_STATS("DOM.DeviceMotionEvent.xRotationRate._get");
    73     v8::Handle<v8::Object> holder = info.Holder();
    74     DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    75     if (!imp->deviceMotionData()->canProvideXRotationRate())
    76         return v8::Null();
    77     return v8::Number::New(imp->deviceMotionData()->xRotationRate());
    78 }
    79 
    80 v8::Handle<v8::Value> V8DeviceMotionEvent::yRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    81 {
    82     INC_STATS("DOM.DeviceMotionEvent.yRotationRate._get");
    83     v8::Handle<v8::Object> holder = info.Holder();
    84     DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    85     if (!imp->deviceMotionData()->canProvideYRotationRate())
    86         return v8::Null();
    87     return v8::Number::New(imp->deviceMotionData()->yRotationRate());
    88 }
    89 
    90 v8::Handle<v8::Value> V8DeviceMotionEvent::zRotationRateAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
    91 {
    92     INC_STATS("DOM.DeviceMotionEvent.zRotationRate._get");
    93     v8::Handle<v8::Object> holder = info.Holder();
    94     DeviceMotionEvent* imp = V8DeviceMotionEvent::toNative(holder);
    95     if (!imp->deviceMotionData()->canProvideZRotationRate())
    96         return v8::Null();
    97     return v8::Number::New(imp->deviceMotionData()->zRotationRate());
    98 }
    99 
    100155
    101156v8::Handle<v8::Value> V8DeviceMotionEvent::intervalAccessorGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info)
     
    115170    bool bubbles = args[1]->BooleanValue();
    116171    bool cancelable = args[2]->BooleanValue();
    117     // If any of the parameters are null or undefined, mark them as not provided.
    118     // Otherwise, use the standard JavaScript conversion.
    119     bool xAccelerationProvided = !isUndefinedOrNull(args[3]);
    120     double xAcceleration = static_cast<double>(args[3]->NumberValue());
    121     bool yAccelerationProvided = !isUndefinedOrNull(args[4]);
    122     double yAcceleration = static_cast<double>(args[4]->NumberValue());
    123     bool zAccelerationProvided = !isUndefinedOrNull(args[5]);
    124     double zAcceleration = static_cast<double>(args[5]->NumberValue());
    125     bool xRotationRateProvided = !isUndefinedOrNull(args[6]);
    126     double xRotationRate = static_cast<double>(args[6]->NumberValue());
    127     bool yRotationRateProvided = !isUndefinedOrNull(args[7]);
    128     double yRotationRate = static_cast<double>(args[7]->NumberValue());
    129     bool zRotationRateProvided = !isUndefinedOrNull(args[8]);
    130     double zRotationRate = static_cast<double>(args[8]->NumberValue());
    131     bool intervalProvided = !isUndefinedOrNull(args[9]);
    132     double interval = static_cast<double>(args[9]->NumberValue());
    133     RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(xAccelerationProvided, xAcceleration, yAccelerationProvided, yAcceleration, zAccelerationProvided, zAcceleration, xRotationRateProvided, xRotationRate, yRotationRateProvided, yRotationRate, zRotationRateProvided, zRotationRate, intervalProvided, interval);
     172    RefPtr<DeviceMotionData::Acceleration> acceleration = readAccelerationArgument(args[3]);
     173    RefPtr<DeviceMotionData::Acceleration> accelerationIncludingGravity = readAccelerationArgument(args[4]);
     174    RefPtr<DeviceMotionData::RotationRate> rotationRate = readRotationRateArgument(args[5]);
     175    bool intervalProvided = !isUndefinedOrNull(args[6]);
     176    double interval = static_cast<double>(args[6]->NumberValue());
     177    RefPtr<DeviceMotionData> deviceMotionData = DeviceMotionData::create(acceleration, accelerationIncludingGravity, rotationRate, intervalProvided, interval);
    134178    imp->initDeviceMotionEvent(type, bubbles, cancelable, deviceMotionData.get());
    135179    return v8::Handle<v8::Value>();
  • trunk/WebCore/dom/DeviceMotionData.cpp

    r68241 r68252  
    2929namespace WebCore {
    3030
     31PassRefPtr<DeviceMotionData::Acceleration> DeviceMotionData::Acceleration::create(bool canProvideX, double x,
     32                                                                                  bool canProvideY, double y,
     33                                                                                  bool canProvideZ, double z)
     34{
     35    return adoptRef(new DeviceMotionData::Acceleration(canProvideX, x, canProvideY, y, canProvideZ, z));
     36}
     37
     38DeviceMotionData::Acceleration::Acceleration(bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z)
     39    : m_x(x)
     40    , m_y(y)
     41    , m_z(z)
     42    , m_canProvideX(canProvideX)
     43    , m_canProvideY(canProvideY)
     44    , m_canProvideZ(canProvideZ)
     45
     46{
     47}
     48
     49PassRefPtr<DeviceMotionData::RotationRate> DeviceMotionData::RotationRate::create(bool canProvideAlpha, double alpha,
     50                                                                                  bool canProvideBeta, double beta,
     51                                                                                  bool canProvideGamma, double gamma)
     52{
     53    return adoptRef(new DeviceMotionData::RotationRate(canProvideAlpha, alpha, canProvideBeta, beta, canProvideGamma, gamma));
     54}
     55
     56DeviceMotionData::RotationRate::RotationRate(bool canProvideAlpha, double alpha, bool canProvideBeta, double beta, bool canProvideGamma, double gamma)
     57    : m_alpha(alpha)
     58    , m_beta(beta)
     59    , m_gamma(gamma)
     60    , m_canProvideAlpha(canProvideAlpha)
     61    , m_canProvideBeta(canProvideBeta)
     62    , m_canProvideGamma(canProvideGamma)
     63{
     64}
     65
    3166PassRefPtr<DeviceMotionData> DeviceMotionData::create()
    3267{
     
    3469}
    3570
    36 PassRefPtr<DeviceMotionData> DeviceMotionData::create(bool canProvideXAcceleration, double xAcceleration,
    37                                                       bool canProvideYAcceleration, double yAcceleration,
    38                                                       bool canProvideZAcceleration, double zAcceleration,
    39                                                       bool canProvideXRotationRate, double xRotationRate,
    40                                                       bool canProvideYRotationRate, double yRotationRate,
    41                                                       bool canProvideZRotationRate, double zRotationRate,
    42                                                       bool canProvideInterval, double interval)
     71PassRefPtr<DeviceMotionData> DeviceMotionData::create(PassRefPtr<Acceleration> acceleration, PassRefPtr<Acceleration> accelerationIncludingGravity,
     72                                                      PassRefPtr<RotationRate> rotationRate, bool canProvideInterval, double interval)
    4373{
    44     return adoptRef(new DeviceMotionData(canProvideXAcceleration, xAcceleration,
    45                                          canProvideYAcceleration, yAcceleration,
    46                                          canProvideZAcceleration, zAcceleration,
    47                                          canProvideXRotationRate, xRotationRate,
    48                                          canProvideYRotationRate, yRotationRate,
    49                                          canProvideZRotationRate, zRotationRate,
    50                                          canProvideInterval, interval));
     74    return adoptRef(new DeviceMotionData(acceleration, accelerationIncludingGravity, rotationRate, canProvideInterval, interval));
    5175}
    5276
    5377DeviceMotionData::DeviceMotionData()
    54     : m_canProvideXAcceleration(false)
    55     , m_canProvideYAcceleration(false)
    56     , m_canProvideZAcceleration(false)
    57     , m_canProvideXRotationRate(false)
    58     , m_canProvideYRotationRate(false)
    59     , m_canProvideZRotationRate(false)
    60     , m_canProvideInterval(false)
     78    : m_canProvideInterval(false)
    6179{
    6280}
    6381
    64 DeviceMotionData::DeviceMotionData(bool canProvideXAcceleration, double xAcceleration,
    65                                    bool canProvideYAcceleration, double yAcceleration,
    66                                    bool canProvideZAcceleration, double zAcceleration,
    67                                    bool canProvideXRotationRate, double xRotationRate,
    68                                    bool canProvideYRotationRate, double yRotationRate,
    69                                    bool canProvideZRotationRate, double zRotationRate,
    70                                    bool canProvideInterval, double interval)
    71     : m_canProvideXAcceleration(canProvideXAcceleration)
    72     , m_canProvideYAcceleration(canProvideYAcceleration)
    73     , m_canProvideZAcceleration(canProvideZAcceleration)
    74     , m_canProvideXRotationRate(canProvideXRotationRate)
    75     , m_canProvideYRotationRate(canProvideYRotationRate)
    76     , m_canProvideZRotationRate(canProvideZRotationRate)
     82DeviceMotionData::DeviceMotionData(PassRefPtr<Acceleration> acceleration, PassRefPtr<Acceleration> accelerationIncludingGravity,
     83                                   PassRefPtr<RotationRate> rotationRate, bool canProvideInterval, double interval)
     84    : m_acceleration(acceleration)
     85    , m_accelerationIncludingGravity(accelerationIncludingGravity)
     86    , m_rotationRate(rotationRate)
    7787    , m_canProvideInterval(canProvideInterval)
    78     , m_xAcceleration(xAcceleration)
    79     , m_yAcceleration(yAcceleration)
    80     , m_zAcceleration(zAcceleration)
    81     , m_xRotationRate(xRotationRate)
    82     , m_yRotationRate(yRotationRate)
    83     , m_zRotationRate(zRotationRate)
    8488    , m_interval(interval)
    8589{
  • trunk/WebCore/dom/DeviceMotionData.h

    r68241 r68252  
    2929#include <wtf/PassRefPtr.h>
    3030#include <wtf/RefCounted.h>
     31#include <wtf/RefPtr.h>
    3132
    3233namespace WebCore {
     
    3435class DeviceMotionData : public RefCounted<DeviceMotionData> {
    3536public:
     37    class Acceleration : public RefCounted<DeviceMotionData::Acceleration> {
     38    public:
     39        static PassRefPtr<Acceleration> create(bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z);
     40
     41        bool canProvideX() const { return m_canProvideX; }
     42        bool canProvideY() const { return m_canProvideY; }
     43        bool canProvideZ() const { return m_canProvideZ; }
     44
     45        double x() const { return m_x; }
     46        double y() const { return m_y; }
     47        double z() const { return m_z; }
     48
     49    private:
     50        Acceleration(bool canProvideX, double x, bool canProvideY, double y, bool canProvideZ, double z);
     51
     52        double m_x;
     53        double m_y;
     54        double m_z;
     55
     56        bool m_canProvideX;
     57        bool m_canProvideY;
     58        bool m_canProvideZ;
     59    };
     60
     61    class RotationRate : public RefCounted<DeviceMotionData::RotationRate> {
     62    public:
     63        static PassRefPtr<RotationRate> create(bool canProvideAlpha, double alpha, bool canProvideBeta,  double beta, bool canProvideGamma, double gamma);
     64
     65        bool canProvideAlpha() const { return m_canProvideAlpha; }
     66        bool canProvideBeta() const { return m_canProvideBeta; }
     67        bool canProvideGamma() const { return m_canProvideGamma; }
     68
     69        double alpha() const { return m_alpha; }
     70        double beta() const { return m_beta; }
     71        double gamma() const { return m_gamma; }
     72
     73    private:
     74        RotationRate(bool canProvideAlpha, double alpha, bool canProvideBeta,  double beta, bool canProvideGamma, double gamma);
     75
     76        double m_alpha;
     77        double m_beta;
     78        double m_gamma;
     79
     80        bool m_canProvideAlpha;
     81        bool m_canProvideBeta;
     82        bool m_canProvideGamma;
     83    };
     84
    3685    static PassRefPtr<DeviceMotionData> create();
    37     static PassRefPtr<DeviceMotionData> create(bool canProvideXAcceleration, double xAcceleration,
    38                                                bool canProvideYAcceleration, double yAcceleration,
    39                                                bool canProvideZAcceleration, double zAcceleration,
    40                                                bool canProvideXRotationRate, double xRotationRate,
    41                                                bool canProvideYRotationRate, double yRotationRate,
    42                                                bool canProvideZRotationRate, double zRotationRate,
    43                                                bool canProvideInterval, double interval);
     86    static PassRefPtr<DeviceMotionData> create(PassRefPtr<Acceleration> acceleration, PassRefPtr<Acceleration> accelerationIncludingGravity,
     87                                               PassRefPtr<RotationRate> rotationRate, bool canProvideInterval, double interval);
    4488
    45     double xAcceleration() const { return m_xAcceleration; }
    46     double yAcceleration() const { return m_yAcceleration; }
    47     double zAcceleration() const { return m_zAcceleration; }
    48     double xRotationRate() const { return m_xRotationRate; }
    49     double yRotationRate() const { return m_yRotationRate; }
    50     double zRotationRate() const { return m_zRotationRate; }
     89    const Acceleration* acceleration() const { return m_acceleration.get(); }
     90    const Acceleration* accelerationIncludingGravity() const { return m_accelerationIncludingGravity.get(); }
     91    const RotationRate* rotationRate() const { return m_rotationRate.get(); }
    5192    double interval() const { return m_interval; }
    52 
    53     bool canProvideXAcceleration() const { return m_canProvideXAcceleration; }
    54     bool canProvideYAcceleration() const { return m_canProvideYAcceleration; }
    55     bool canProvideZAcceleration() const { return m_canProvideZAcceleration; }
    56     bool canProvideXRotationRate() const { return m_canProvideXRotationRate; }
    57     bool canProvideYRotationRate() const { return m_canProvideYRotationRate; }
    58     bool canProvideZRotationRate() const { return m_canProvideZRotationRate; }
    5993    bool canProvideInterval() const { return m_canProvideInterval; }
    6094
    6195private:
    6296    DeviceMotionData();
    63     DeviceMotionData(bool canProvideXAcceleration, double xAcceleration,
    64                      bool canProvideYAcceleration, double yAcceleration,
    65                      bool canProvideZAcceleration, double zAcceleration,
    66                      bool canProvideXRotationRate, double xRotationRate,
    67                      bool canProvideYRotationRate, double yRotationRate,
    68                      bool canProvideZRotationRate, double zRotationRate,
    69                      bool canProvideInterval, double interval);
     97    DeviceMotionData(PassRefPtr<Acceleration> acceleration, PassRefPtr<Acceleration> accelerationIncludingGravity,
     98                     PassRefPtr<RotationRate> rotationRate, bool canProvideInterval, double interval);
    7099
    71     bool m_canProvideXAcceleration;
    72     bool m_canProvideYAcceleration;
    73     bool m_canProvideZAcceleration;
    74     bool m_canProvideXRotationRate;
    75     bool m_canProvideYRotationRate;
    76     bool m_canProvideZRotationRate;
     100    RefPtr<Acceleration> m_acceleration;
     101    RefPtr<Acceleration> m_accelerationIncludingGravity;
     102    RefPtr<RotationRate> m_rotationRate;
    77103    bool m_canProvideInterval;
    78 
    79     double m_xAcceleration;
    80     double m_yAcceleration;
    81     double m_zAcceleration;
    82     double m_xRotationRate;
    83     double m_yRotationRate;
    84     double m_zRotationRate;
    85104    double m_interval;
    86105};
  • trunk/WebCore/dom/DeviceMotionEvent.idl

    r68241 r68252  
    2929        Conditional=DEVICE_ORIENTATION
    3030    ] DeviceMotionEvent : Event {
    31         readonly attribute [Custom] double xAcceleration;
    32         readonly attribute [Custom] double yAcceleration;
    33         readonly attribute [Custom] double zAcceleration;
    34         readonly attribute [Custom] double xRotationRate;
    35         readonly attribute [Custom] double yRotationRate;
    36         readonly attribute [Custom] double zRotationRate;
     31        readonly attribute [Custom] Acceleration acceleration;
     32        readonly attribute [Custom] Acceleration accelerationIncludingGravity;
     33        readonly attribute [Custom] RotationRate rotationRate;
    3734        readonly attribute [Custom] double interval;
    38         [Custom] void initDeviceMotionEvent(in DOMString type, in boolean bubbles, in boolean cancelable, in double xAcceleration, in double yAcceleration, in double zAcceleration, in double xRotationRate, in double yRotationRate, in double zRotationRate, in double interval);
     35        [Custom] void initDeviceMotionEvent(in DOMString type, in boolean bubbles, in boolean cancelable, in Acceleration acceleration, in Acceleration accelerationIncludingGravity, in RotationRate rotationRate, in double interval);
    3936    };
    4037
Note: See TracChangeset for help on using the changeset viewer.