/**
 * Generated by Apache Royale Compiler from org\apache\royale\html\beads\controllers\HSliderMouseController.as
 * org.apache.royale.html.beads.controllers.HSliderMouseController
 *
 * @fileoverview
 *
 * @suppress {checkTypes|accessControls}
 */

goog.provide('org.apache.royale.html.beads.controllers.HSliderMouseController');

goog.require('goog.events');
goog.require('goog.events.EventType');
goog.require('org.apache.royale.core.IRangeModel');
goog.require('org.apache.royale.core.IStrand');
goog.require('org.apache.royale.core.UIBase');
goog.require('org.apache.royale.events.BrowserEvent');
goog.require('org.apache.royale.events.MouseEvent');
goog.require('org.apache.royale.events.ValueChangeEvent');
goog.require('org.apache.royale.html.Slider');
goog.require('org.apache.royale.html.beads.ISliderView');
goog.require('org.apache.royale.core.IBead');
goog.require('org.apache.royale.core.IBeadController');
goog.require('org.apache.royale.utils.Language');



/**
 *  constructor.
 *  
 *  @langversion 3.0
 *  @playerversion Flash 10.2
 *  @playerversion AIR 2.6
 *  @productversion Royale 0.0
 * @constructor
 * @implements {org.apache.royale.core.IBead}
 * @implements {org.apache.royale.core.IBeadController}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController = function() {
};


/**
 * Prevent renaming of class. Needed for reflection.
 */
goog.exportSymbol('org.apache.royale.html.beads.controllers.HSliderMouseController', org.apache.royale.html.beads.controllers.HSliderMouseController);


/**
 * @private
 * @type {org.apache.royale.core.IRangeModel}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel;


/**
 * @private
 * @type {org.apache.royale.core.IStrand}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController__strand;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_oldValue;


/**
 * @private
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_track;


/**
 * @private
 * @type {org.apache.royale.core.UIBase}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_thumb;


/**
 * @royaleignorecoercion org.apache.royale.events.BrowserEvent
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_handleTrackClick = function(event) {
  var /** @type {Object} */ bevent = event["wrappedEvent"];
  var /** @type {org.apache.royale.html.Slider} */ host = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, org.apache.royale.html.Slider);
  var /** @type {number} */ xloc = bevent.offsetX;
  var /** @type {number} */ useWidth = parseInt(this.org_apache_royale_html_beads_controllers_HSliderMouseController_track.element.style.width, 10) * 1.0;
  var /** @type {number} */ p = xloc / useWidth;
  var /** @type {number} */ n = p * (this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.maximum - this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.minimum) + this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.minimum;
  var /** @type {org.apache.royale.events.ValueChangeEvent} */ vce = org.apache.royale.events.ValueChangeEvent.createUpdateEvent(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, "value", this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value, n);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value = n;
  host.dispatchEvent(vce);
};


/**
 * @royaleignorecoercion org.apache.royale.events.BrowserEvent
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbDown = function(event) {
  var /** @type {Object} */ bevent = event["wrappedEvent"];
  var /** @type {org.apache.royale.html.Slider} */ host = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, org.apache.royale.html.Slider);
  goog.events.listen(host.element, goog.events.EventType.MOUSEUP, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbUp, this, 'handleThumbUp'), false, this);
  goog.events.listen(host.element, goog.events.EventType.MOUSEMOVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbMove, this, 'handleThumbMove'), false, this);
  goog.events.listen(host.element, goog.events.EventType.MOUSELEAVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbLeave, this, 'handleThumbLeave'), false, this);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_mouseOrigin = bevent.screenX;
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumbOrigin = parseInt(this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumb.element.style.left, 10);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_oldValue = this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value;
};


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_mouseOrigin;


/**
 * @private
 * @type {number}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_thumbOrigin = 0;


/**
 * @royaleignorecoercion org.apache.royale.events.BrowserEvent
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbUp = function(event) {
  var /** @type {Object} */ bevent = event["wrappedEvent"];
  var /** @type {org.apache.royale.html.Slider} */ host = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, org.apache.royale.html.Slider);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSEUP, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbUp, this, 'handleThumbUp'), false, this);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSEMOVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbMove, this, 'handleThumbMove'), false, this);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSELEAVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbLeave, this, 'handleThumbLeave'), false, this);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_calcValFromMousePosition(bevent, false);
  var /** @type {org.apache.royale.events.ValueChangeEvent} */ vce = org.apache.royale.events.ValueChangeEvent.createUpdateEvent(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, "value", this.org_apache_royale_html_beads_controllers_HSliderMouseController_oldValue, this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value);
  host.dispatchEvent(vce);
};


/**
 * @royaleignorecoercion org.apache.royale.events.BrowserEvent
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbMove = function(event) {
  var /** @type {Object} */ bevent = event["wrappedEvent"];
  var /** @type {org.apache.royale.html.Slider} */ host = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, org.apache.royale.html.Slider);
  var /** @type {number} */ lastValue = this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value;
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_calcValFromMousePosition(bevent, false);
  var /** @type {org.apache.royale.events.ValueChangeEvent} */ vce = org.apache.royale.events.ValueChangeEvent.createUpdateEvent(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, "value", lastValue, this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value);
  host.dispatchEvent(vce);
};


/**
 * @private
 * @param {org.apache.royale.events.MouseEvent} event
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbLeave = function(event) {
  var /** @type {org.apache.royale.html.Slider} */ host = org.apache.royale.utils.Language.as(this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand, org.apache.royale.html.Slider);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSEUP, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbUp, this, 'handleThumbUp'), false, this);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSEMOVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbMove, this, 'handleThumbMove'), false, this);
  goog.events.unlisten(host.element, goog.events.EventType.MOUSELEAVE, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbLeave, this, 'handleThumbLeave'), false, this);
};


/**
 * @private
 * @param {org.apache.royale.events.BrowserEvent} event
 * @param {boolean} useOffset
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.org_apache_royale_html_beads_controllers_HSliderMouseController_calcValFromMousePosition = function(event, useOffset) {
  var /** @type {number} */ deltaX = event.screenX - this.org_apache_royale_html_beads_controllers_HSliderMouseController_mouseOrigin;
  if (deltaX == 0)
    return;
  var /** @type {number} */ thumbW = parseInt(this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumb.element.style.width, 10) / 2;
  var /** @type {number} */ newPointX = this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumbOrigin + deltaX;
  var /** @type {number} */ useWidth = parseInt(this.org_apache_royale_html_beads_controllers_HSliderMouseController_track.element.style.width, 10) * 1.0;
  var /** @type {number} */ p = newPointX / useWidth;
  var /** @type {number} */ n = p * (this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.maximum - this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.minimum) + this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.minimum;
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel.value = n;
};


org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.set__strand = function(value) {
  this.org_apache_royale_html_beads_controllers_HSliderMouseController__strand = value;
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_rangeModel = org.apache.royale.utils.Language.as(org.apache.royale.utils.Language.as(value, org.apache.royale.core.UIBase, true).model, org.apache.royale.core.IRangeModel);
  
  var /** @type {org.apache.royale.html.beads.ISliderView} */ sliderView = org.apache.royale.utils.Language.as(value.getBeadByType(org.apache.royale.html.beads.ISliderView), org.apache.royale.html.beads.ISliderView);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_track = org.apache.royale.utils.Language.as(sliderView.track, org.apache.royale.core.UIBase);
  this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumb = org.apache.royale.utils.Language.as(sliderView.thumb, org.apache.royale.core.UIBase);
  goog.events.listen(this.org_apache_royale_html_beads_controllers_HSliderMouseController_track.element, goog.events.EventType.CLICK, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleTrackClick, this, 'handleTrackClick'), false, this);
  goog.events.listen(this.org_apache_royale_html_beads_controllers_HSliderMouseController_thumb.element, goog.events.EventType.MOUSEDOWN, org.apache.royale.utils.Language.closure(this.org_apache_royale_html_beads_controllers_HSliderMouseController_handleThumbDown, this, 'handleThumbDown'), false, this);
};


Object.defineProperties(org.apache.royale.html.beads.controllers.HSliderMouseController.prototype, /** @lends {org.apache.royale.html.beads.controllers.HSliderMouseController.prototype} */ {
/**
  * @export
  * @type {org.apache.royale.core.IStrand} */
strand: {
set: org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.set__strand}}
);


/**
 * Metadata
 *
 * @type {Object.<string, Array.<Object>>}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.ROYALE_CLASS_INFO = { names: [{ name: 'HSliderMouseController', qName: 'org.apache.royale.html.beads.controllers.HSliderMouseController', kind: 'class' }], interfaces: [org.apache.royale.core.IBead, org.apache.royale.core.IBeadController] };



/**
 * Reflection
 *
 * @return {Object.<string, Function>}
 */
org.apache.royale.html.beads.controllers.HSliderMouseController.prototype.ROYALE_REFLECTION_INFO = function () {
  return {
    variables: function () {return {};},
    accessors: function () {
      return {
        'strand': { type: 'org.apache.royale.core.IStrand', access: 'writeonly', declaredBy: 'org.apache.royale.html.beads.controllers.HSliderMouseController'}
      };
    },
    methods: function () {
      return {
        'HSliderMouseController': { type: '', declaredBy: 'org.apache.royale.html.beads.controllers.HSliderMouseController'}
      };
    }
  };
};