/*
 * Copyright (C) 2020 Igalia S.L. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
 * THE POSSIBILITY OF SUCH DAMAGE.
 */

[
    Conditional=WEBXR,
    EnabledBySetting=WebXREnabled,
    InterfaceName=FakeXRInputController,
    LegacyNoInterfaceObject
] interface WebFakeXRInputController {
    // Indicates that the handedness of the device has changed.
    undefined setHandedness(XRHandedness handedness);

    // Indicates that the target ray mode of the device has changed.
    undefined setTargetRayMode(XRTargetRayMode targetRayMode);

    // Indicates that the list of profiles representing the device has changed.
    undefined setProfiles(sequence<DOMString> profiles);

    // Sets or clears the position of the controller.  If not set, the controller is assumed to
    // not be tracked.
    undefined setGripOrigin(FakeXRRigidTransformInit gripOrigin, optional boolean emulatedPosition = false);
    undefined clearGripOrigin();

    // Sets the pointer origin for the controller.
    undefined setPointerOrigin(FakeXRRigidTransformInit pointerOrigin, optional boolean emulatedPosition = false);

    // Temporarily disconnect the input device
    undefined disconnect();

    // Reconnect a disconnected input device
    undefined reconnect();

    // Start a selection for the current frame with the primary input
    // If a gamepad is supported, should update the state of the primary button accordingly.
    undefined startSelection();

    // End selection for the current frame with the primary input
    // If a gamepad is supported, should update the state of the primary button accordingly.
    undefined endSelection();

    // Simulates a start/endSelection for the current frame with the primary input
    // If a gamepad is supported, should update the state of the primary button accordingly.
    undefined simulateSelect();

    // Updates the set of supported buttons, including any initial state.
    // Note that this method should not be generally used to update the state of the
    // buttons, as the UA may treat this as re-creating the Gamepad.
    // Note that if any FakeXRButtonType is repeated the behavior is undefined.
    undefined setSupportedButtons(sequence<FakeXRButtonStateInit> supportedButtons);

    // Used to update the state of a button currently supported by the input source
    // Will not add support for that button if it is not currently supported.
    undefined updateButtonState(FakeXRButtonStateInit buttonState);
    
    [Conditional=WEBXR_HANDS] undefined updateHandJoints(sequence<FakeXRJointStateInit> handJoints);
};
