home *** CD-ROM | disk | FTP | other *** search
/ Computer Active 2010 August / CA08.iso / Multimedija / shufflr.air / ShufflrClient.swf / scripts / mx / controls / HTML.as < prev    next >
Encoding:
Text File  |  2010-06-23  |  14.6 KB  |  513 lines

  1. package mx.controls
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.HTMLUncaughtScriptExceptionEvent;
  5.    import flash.events.MouseEvent;
  6.    import flash.html.HTMLHistoryItem;
  7.    import flash.html.HTMLHost;
  8.    import flash.html.HTMLLoader;
  9.    import flash.net.URLRequest;
  10.    import flash.system.ApplicationDomain;
  11.    import mx.controls.listClasses.BaseListData;
  12.    import mx.controls.listClasses.IDropInListItemRenderer;
  13.    import mx.controls.listClasses.IListItemRenderer;
  14.    import mx.core.ClassFactory;
  15.    import mx.core.EdgeMetrics;
  16.    import mx.core.FlexHTMLLoader;
  17.    import mx.core.IDataRenderer;
  18.    import mx.core.IFactory;
  19.    import mx.core.ScrollControlBase;
  20.    import mx.core.ScrollPolicy;
  21.    import mx.core.mx_internal;
  22.    import mx.events.FlexEvent;
  23.    import mx.managers.IFocusManagerComponent;
  24.    
  25.    use namespace mx_internal;
  26.    
  27.    public class HTML extends ScrollControlBase implements IDataRenderer, IDropInListItemRenderer, IListItemRenderer, IFocusManagerComponent
  28.    {
  29.       mx_internal static const VERSION:String = "3.5.0.12683";
  30.       
  31.       private static const MAX_HTML_WIDTH:Number = 2880;
  32.       
  33.       private static const MAX_HTML_HEIGHT:Number = 2880;
  34.       
  35.       private var _data:Object;
  36.       
  37.       private var _userAgent:String;
  38.       
  39.       private var _htmlLoaderFactory:IFactory = new ClassFactory(FlexHTMLLoader);
  40.       
  41.       private var _location:String;
  42.       
  43.       private var _runtimeApplicationDomain:ApplicationDomain;
  44.       
  45.       private var htmlTextChanged:Boolean = false;
  46.       
  47.       public var htmlLoader:HTMLLoader;
  48.       
  49.       private var _paintsDefaultBackground:Boolean;
  50.       
  51.       private var locationChanged:Boolean = false;
  52.       
  53.       private var htmlHostChanged:Boolean = false;
  54.       
  55.       private var _listData:BaseListData;
  56.       
  57.       private var _htmlText:String;
  58.       
  59.       private var _htmlHost:HTMLHost;
  60.       
  61.       private var paintsDefaultBackgroundChanged:Boolean = false;
  62.       
  63.       private var userAgentChanged:Boolean = false;
  64.       
  65.       private var runtimeApplicationDomainChanged:Boolean = false;
  66.       
  67.       private var textSet:Boolean;
  68.       
  69.       public function HTML()
  70.       {
  71.          super();
  72.          mx_internal::_horizontalScrollPolicy = ScrollPolicy.AUTO;
  73.          mx_internal::_verticalScrollPolicy = ScrollPolicy.AUTO;
  74.          tabEnabled = false;
  75.          tabChildren = true;
  76.       }
  77.       
  78.       public static function get pdfCapability() : int
  79.       {
  80.          return HTMLLoader.pdfCapability;
  81.       }
  82.       
  83.       public function get contentHeight() : Number
  84.       {
  85.          if(!htmlLoader)
  86.          {
  87.             return 0;
  88.          }
  89.          return htmlLoader.contentHeight;
  90.       }
  91.       
  92.       public function get userAgent() : String
  93.       {
  94.          return _userAgent;
  95.       }
  96.       
  97.       public function set userAgent(param1:String) : void
  98.       {
  99.          _userAgent = param1;
  100.          userAgentChanged = true;
  101.          invalidateProperties();
  102.       }
  103.       
  104.       public function get loaded() : Boolean
  105.       {
  106.          if(!htmlLoader || locationChanged || htmlTextChanged)
  107.          {
  108.             return false;
  109.          }
  110.          return htmlLoader.loaded;
  111.       }
  112.       
  113.       public function cancelLoad() : void
  114.       {
  115.          if(htmlLoader)
  116.          {
  117.             htmlLoader.cancelLoad();
  118.          }
  119.       }
  120.       
  121.       private function htmlLoader_htmlRenderHandler(param1:Event) : void
  122.       {
  123.          dispatchEvent(param1);
  124.          adjustScrollBars();
  125.       }
  126.       
  127.       [Bindable("htmlLoaderFactoryChanged")]
  128.       public function get htmlLoaderFactory() : IFactory
  129.       {
  130.          return _htmlLoaderFactory;
  131.       }
  132.       
  133.       public function historyForward() : void
  134.       {
  135.          if(htmlLoader)
  136.          {
  137.             htmlLoader.historyForward();
  138.          }
  139.       }
  140.       
  141.       public function set htmlLoaderFactory(param1:IFactory) : void
  142.       {
  143.          _htmlLoaderFactory = param1;
  144.          dispatchEvent(new Event("htmlLoaderFactoryChanged"));
  145.       }
  146.       
  147.       public function get historyLength() : int
  148.       {
  149.          if(!htmlLoader)
  150.          {
  151.             return 0;
  152.          }
  153.          return htmlLoader.historyLength;
  154.       }
  155.       
  156.       public function reload() : void
  157.       {
  158.          if(htmlLoader)
  159.          {
  160.             htmlLoader.reload();
  161.          }
  162.       }
  163.       
  164.       override protected function createChildren() : void
  165.       {
  166.          super.createChildren();
  167.          if(!htmlLoader)
  168.          {
  169.             htmlLoader = htmlLoaderFactory.newInstance();
  170.             htmlLoader.addEventListener(Event.HTML_DOM_INITIALIZE,htmlLoader_domInitialize);
  171.             htmlLoader.addEventListener(Event.COMPLETE,htmlLoader_completeHandler);
  172.             htmlLoader.addEventListener(Event.HTML_RENDER,htmlLoader_htmlRenderHandler);
  173.             htmlLoader.addEventListener(Event.LOCATION_CHANGE,htmlLoader_locationChangeHandler);
  174.             htmlLoader.addEventListener(Event.HTML_BOUNDS_CHANGE,htmlLoader_htmlBoundsChangeHandler);
  175.             htmlLoader.addEventListener(Event.SCROLL,htmlLoader_scrollHandler);
  176.             htmlLoader.addEventListener(HTMLUncaughtScriptExceptionEvent.UNCAUGHT_SCRIPT_EXCEPTION,htmlLoader_uncaughtScriptExceptionHandler);
  177.             addChild(htmlLoader);
  178.          }
  179.       }
  180.       
  181.       public function historyGo(param1:int) : void
  182.       {
  183.          if(htmlLoader)
  184.          {
  185.             htmlLoader.historyGo(param1);
  186.          }
  187.       }
  188.       
  189.       private function htmlLoader_domInitialize(param1:Event) : void
  190.       {
  191.          dispatchEvent(param1);
  192.       }
  193.       
  194.       private function adjustScrollBars() : void
  195.       {
  196.          setScrollBarProperties(htmlLoader.contentWidth,htmlLoader.width,htmlLoader.contentHeight,htmlLoader.height);
  197.          if(verticalScrollBar)
  198.          {
  199.             verticalScrollBar.lineScrollSize = 20;
  200.          }
  201.          if(horizontalScrollBar)
  202.          {
  203.             horizontalScrollBar.lineScrollSize = 20;
  204.          }
  205.       }
  206.       
  207.       [Bindable("dataChange")]
  208.       public function get data() : Object
  209.       {
  210.          return _data;
  211.       }
  212.       
  213.       [Bindable("locationChange")]
  214.       public function get location() : String
  215.       {
  216.          return _location;
  217.       }
  218.       
  219.       private function htmlLoader_completeHandler(param1:Event) : void
  220.       {
  221.          invalidateSize();
  222.          dispatchEvent(param1);
  223.       }
  224.       
  225.       public function set historyPosition(param1:int) : void
  226.       {
  227.          if(htmlLoader)
  228.          {
  229.             htmlLoader.historyPosition = param1;
  230.          }
  231.       }
  232.       
  233.       public function getHistoryAt(param1:int) : HTMLHistoryItem
  234.       {
  235.          if(!htmlLoader)
  236.          {
  237.             return null;
  238.          }
  239.          return htmlLoader.getHistoryAt(param1);
  240.       }
  241.       
  242.       public function get runtimeApplicationDomain() : ApplicationDomain
  243.       {
  244.          return _runtimeApplicationDomain;
  245.       }
  246.       
  247.       override protected function scrollHandler(param1:Event) : void
  248.       {
  249.          super.scrollHandler(param1);
  250.          htmlLoader.scrollH = horizontalScrollPosition;
  251.          htmlLoader.scrollV = verticalScrollPosition;
  252.       }
  253.       
  254.       public function historyBack() : void
  255.       {
  256.          if(htmlLoader)
  257.          {
  258.             htmlLoader.historyBack();
  259.          }
  260.       }
  261.       
  262.       override protected function commitProperties() : void
  263.       {
  264.          super.commitProperties();
  265.          if(htmlHostChanged)
  266.          {
  267.             htmlLoader.htmlHost = _htmlHost;
  268.             htmlHostChanged = false;
  269.          }
  270.          if(paintsDefaultBackgroundChanged)
  271.          {
  272.             htmlLoader.paintsDefaultBackground = _paintsDefaultBackground;
  273.             paintsDefaultBackgroundChanged = false;
  274.          }
  275.          if(runtimeApplicationDomainChanged)
  276.          {
  277.             htmlLoader.runtimeApplicationDomain = _runtimeApplicationDomain;
  278.             runtimeApplicationDomainChanged = false;
  279.          }
  280.          if(userAgentChanged)
  281.          {
  282.             htmlLoader.userAgent = _userAgent;
  283.             userAgentChanged = false;
  284.          }
  285.          if(locationChanged)
  286.          {
  287.             htmlLoader.load(new URLRequest(_location));
  288.             locationChanged = false;
  289.          }
  290.          if(htmlTextChanged)
  291.          {
  292.             htmlLoader.loadString(_htmlText);
  293.             htmlTextChanged = false;
  294.          }
  295.       }
  296.       
  297.       public function get contentWidth() : Number
  298.       {
  299.          if(!htmlLoader)
  300.          {
  301.             return 0;
  302.          }
  303.          return htmlLoader.contentWidth;
  304.       }
  305.       
  306.       public function get domWindow() : Object
  307.       {
  308.          if(!htmlLoader)
  309.          {
  310.             return null;
  311.          }
  312.          return htmlLoader.window;
  313.       }
  314.       
  315.       override protected function mouseWheelHandler(param1:MouseEvent) : void
  316.       {
  317.          if(param1.target != this)
  318.          {
  319.             return;
  320.          }
  321.          param1.delta *= 6;
  322.          super.mouseWheelHandler(param1);
  323.       }
  324.       
  325.       override public function set verticalScrollPosition(param1:Number) : void
  326.       {
  327.          param1 = Math.max(param1,0);
  328.          if(Boolean(htmlLoader) && htmlLoader.contentHeight > htmlLoader.height)
  329.          {
  330.             param1 = Math.min(param1,htmlLoader.contentHeight - htmlLoader.height);
  331.          }
  332.          super.verticalScrollPosition = param1;
  333.          if(htmlLoader)
  334.          {
  335.             htmlLoader.scrollV = param1;
  336.          }
  337.          else
  338.          {
  339.             invalidateProperties();
  340.          }
  341.       }
  342.       
  343.       public function set data(param1:Object) : void
  344.       {
  345.          var _loc2_:* = undefined;
  346.          _data = param1;
  347.          if(_listData)
  348.          {
  349.             _loc2_ = _listData.label;
  350.          }
  351.          else if(_data != null)
  352.          {
  353.             if(_data is String)
  354.             {
  355.                _loc2_ = String(_data);
  356.             }
  357.             else
  358.             {
  359.                _loc2_ = _data.toString();
  360.             }
  361.          }
  362.          if(_loc2_ !== undefined && !textSet)
  363.          {
  364.             htmlText = _loc2_;
  365.             textSet = false;
  366.          }
  367.          dispatchEvent(new FlexEvent(FlexEvent.DATA_CHANGE));
  368.       }
  369.       
  370.       private function htmlLoader_scrollHandler(param1:Event) : void
  371.       {
  372.          horizontalScrollPosition = htmlLoader.scrollH;
  373.          verticalScrollPosition = htmlLoader.scrollV;
  374.       }
  375.       
  376.       public function get historyPosition() : int
  377.       {
  378.          if(!htmlLoader)
  379.          {
  380.             return 0;
  381.          }
  382.          return htmlLoader.historyPosition;
  383.       }
  384.       
  385.       override protected function measure() : void
  386.       {
  387.          super.measure();
  388.          var _loc1_:EdgeMetrics = viewMetrics;
  389.          _loc1_.left += getStyle("paddingLeft");
  390.          _loc1_.top += getStyle("paddingTop");
  391.          _loc1_.right += getStyle("paddingRight");
  392.          _loc1_.bottom += getStyle("paddingBottom");
  393.          measuredWidth = Math.min(htmlLoader.contentWidth + _loc1_.left + _loc1_.right,MAX_HTML_WIDTH);
  394.          measuredHeight = Math.min(htmlLoader.contentHeight + _loc1_.top + _loc1_.bottom,MAX_HTML_HEIGHT);
  395.       }
  396.       
  397.       public function set listData(param1:BaseListData) : void
  398.       {
  399.          _listData = param1;
  400.       }
  401.       
  402.       private function htmlLoader_uncaughtScriptExceptionHandler(param1:HTMLUncaughtScriptExceptionEvent) : void
  403.       {
  404.          var _loc2_:Event = param1.clone();
  405.          dispatchEvent(_loc2_);
  406.          if(_loc2_.isDefaultPrevented())
  407.          {
  408.             param1.preventDefault();
  409.          }
  410.       }
  411.       
  412.       private function htmlLoader_locationChangeHandler(param1:Event) : void
  413.       {
  414.          var _loc2_:* = _location != htmlLoader.location;
  415.          _location = htmlLoader.location;
  416.          if(_loc2_)
  417.          {
  418.             dispatchEvent(param1);
  419.          }
  420.       }
  421.       
  422.       public function set htmlHost(param1:HTMLHost) : void
  423.       {
  424.          _htmlHost = param1;
  425.          htmlHostChanged = true;
  426.          invalidateProperties();
  427.       }
  428.       
  429.       [Bindable("dataChange")]
  430.       public function get listData() : BaseListData
  431.       {
  432.          return _listData;
  433.       }
  434.       
  435.       public function set htmlText(param1:String) : void
  436.       {
  437.          _htmlText = param1;
  438.          htmlTextChanged = true;
  439.          _location = null;
  440.          locationChanged = false;
  441.          invalidateProperties();
  442.          invalidateSize();
  443.          invalidateDisplayList();
  444.          dispatchEvent(new Event("htmlTextChanged"));
  445.       }
  446.       
  447.       public function set location(param1:String) : void
  448.       {
  449.          _location = param1;
  450.          locationChanged = true;
  451.          _htmlText = null;
  452.          htmlTextChanged = false;
  453.          invalidateProperties();
  454.          invalidateSize();
  455.          invalidateDisplayList();
  456.          dispatchEvent(new Event("locationChange"));
  457.       }
  458.       
  459.       public function get htmlHost() : HTMLHost
  460.       {
  461.          return _htmlHost;
  462.       }
  463.       
  464.       override protected function updateDisplayList(param1:Number, param2:Number) : void
  465.       {
  466.          super.updateDisplayList(param1,param2);
  467.          var _loc3_:EdgeMetrics = viewMetrics;
  468.          _loc3_.left += getStyle("paddingLeft");
  469.          _loc3_.top += getStyle("paddingTop");
  470.          _loc3_.right += getStyle("paddingRight");
  471.          _loc3_.bottom += getStyle("paddingBottom");
  472.          htmlLoader.x = _loc3_.left;
  473.          htmlLoader.y = _loc3_.top;
  474.          var _loc4_:Number = Math.max(param1 - _loc3_.left - _loc3_.right,1);
  475.          var _loc5_:Number = Math.max(param2 - _loc3_.top - _loc3_.bottom,1);
  476.          htmlLoader.width = _loc4_;
  477.          htmlLoader.height = _loc5_;
  478.       }
  479.       
  480.       [Bindable("htmlTextChanged")]
  481.       public function get htmlText() : String
  482.       {
  483.          return _htmlText;
  484.       }
  485.       
  486.       private function htmlLoader_htmlBoundsChangeHandler(param1:Event) : void
  487.       {
  488.          invalidateSize();
  489.          adjustScrollBars();
  490.       }
  491.       
  492.       public function get paintsDefaultBackground() : Boolean
  493.       {
  494.          return _paintsDefaultBackground;
  495.       }
  496.       
  497.       public function set paintsDefaultBackground(param1:Boolean) : void
  498.       {
  499.          _paintsDefaultBackground = param1;
  500.          paintsDefaultBackgroundChanged = true;
  501.          invalidateProperties();
  502.       }
  503.       
  504.       public function set runtimeApplicationDomain(param1:ApplicationDomain) : void
  505.       {
  506.          _runtimeApplicationDomain = param1;
  507.          runtimeApplicationDomainChanged = true;
  508.          invalidateProperties();
  509.       }
  510.    }
  511. }
  512.  
  513.