http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ItemRendererMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ItemRendererMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ItemRendererMouseController.as new file mode 100644 index 0000000..ca06c77 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ItemRendererMouseController.as @@ -0,0 +1,203 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.ISelectableItemRenderer; + import org.apache.flex.core.IStrand; +COMPILE::AS3 { + import org.apache.flex.events.Event; + import org.apache.flex.events.MouseEvent; +} +COMPILE::JS { + import org.apache.flex.core.UIBase; + import org.apache.flex.core.WrappedHTMLElement; + import org.apache.flex.events.BrowserEvent; + import goog.events.Event; + import goog.events.EventType; + import goog.events; +} + + /** + * The ItemRendererMouseController class bead handles mouse events in itemRenderers. This + * includes roll-overs, mouse down, and mouse up. These platform-specific events are then + * re-dispatched as FlexJS events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + * @flexjsignoreimport goog.events.Event + */ + public class ItemRendererMouseController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ItemRendererMouseController() + { + } + + private var renderer:ISelectableItemRenderer; + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + renderer = value as ISelectableItemRenderer; + + COMPILE::AS3 { + renderer.addEventListener(MouseEvent.ROLL_OVER, rollOverHandler); + renderer.addEventListener(MouseEvent.ROLL_OUT, rollOutHandler); + renderer.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler); + } + + COMPILE::JS { + var element:WrappedHTMLElement = (_strand as UIBase).element; + + goog.events.listen(element, goog.events.EventType.MOUSEOVER, this.handleMouseOver); + goog.events.listen(element, goog.events.EventType.MOUSEOUT, this.handleMouseOut); + goog.events.listen(element, goog.events.EventType.MOUSEDOWN, this.handleMouseDown); + goog.events.listen(element, goog.events.EventType.MOUSEUP, this.handleMouseUp); + } + } + + /** + * @private + */ + COMPILE::AS3 + protected function rollOverHandler(event:MouseEvent):void + { + var target:ISelectableItemRenderer = event.target as ISelectableItemRenderer; + if (target) + { + target.hovered = true; + target.dispatchEvent(new Event("itemRendererRollOver",true)); + } + } + + COMPILE::JS + protected function handleMouseOver(event:BrowserEvent):void + { + var target:ISelectableItemRenderer = event.target as ISelectableItemRenderer; + if (target) { + target.hovered = true; + target.dispatchEvent(new Event("itemRendererRollOver",true)); + } + } + + /** + * @private + */ + COMPILE::AS3 + protected function rollOutHandler(event:MouseEvent):void + { + var target:ISelectableItemRenderer = event.target as ISelectableItemRenderer; + if (target) + { + target.hovered = false; + target.down = false; + target.dispatchEvent(new Event("itemRendererRollOut",true)); + } + } + + COMPILE::JS + protected function handleMouseOut(event:BrowserEvent):void + { + var target:ISelectableItemRenderer = event.target as ISelectableItemRenderer; + if (target) + { + target.hovered = false; + target.down = false; + target.dispatchEvent(new Event("itemRendererRollOut",true)); + } + } + + /** + * @private + */ + COMPILE::AS3 + protected function mouseDownHandler(event:MouseEvent):void + { + var target:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; + if (target) + { + target.down = true; + target.addEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); + } + } + + /** + * @private + */ + COMPILE::JS + protected function handleMouseDown(event:BrowserEvent):void + { + var target:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; + if (target) + { + target.down = true; + target.hovered = false; + } + } + + /** + * @private + */ + COMPILE::AS3 + protected function mouseUpHandler(event:MouseEvent):void + { + var target:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; + if (target) + { + target.removeEventListener(MouseEvent.MOUSE_UP, mouseUpHandler); + target.selected = true; + target.dispatchEvent(new Event("selected")); + } + } + + /** + * @private + */ + COMPILE::JS + protected function handleMouseUp(event:BrowserEvent):void + { + var target:ISelectableItemRenderer = event.currentTarget as ISelectableItemRenderer; + if (target) + { + target.selected = true; + target.dispatchEvent(new Event("selected")); + } + } + + } +}
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as new file mode 100644 index 0000000..9760591 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ListSingleSelectionMouseController.as @@ -0,0 +1,127 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IItemRendererParent; + import org.apache.flex.core.IRollOverModel; + import org.apache.flex.core.ISelectableItemRenderer; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.html.beads.IListView; + + /** + * The ListSingleSelectionMouseController class is a controller for + * org.apache.flex.html.List. Controllers + * watch for events from the interactive portions of a View and + * update the data model or dispatch a semantic event. + * This controller watches for events from the item renderers + * and updates an ISelectionModel (which only supports single + * selection). Other controller/model pairs would support + * various kinds of multiple selection. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ListSingleSelectionMouseController implements IBeadController + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ListSingleSelectionMouseController() + { + } + + /** + * The model. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var listModel:ISelectionModel; + + /** + * The view. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var listView:IListView; + + /** + * The parent of the item renderers. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var dataGroup:IItemRendererParent; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + listModel = value.getBeadByType(ISelectionModel) as ISelectionModel; + listView = value.getBeadByType(IListView) as IListView; + dataGroup = listView.dataGroup; + dataGroup.addEventListener("selected", selectedHandler, true); + IEventDispatcher(_strand).addEventListener(MouseEvent.ROLL_OVER, rolloverHandler); + } + + private function selectedHandler(event:Event):void + { + listModel.selectedIndex = ISelectableItemRenderer(event.target).index; + listView.host.dispatchEvent(new Event("change")); + } + + private function rolloverHandler(event:Event):void + { + var renderer:ISelectableItemRenderer = event.target as ISelectableItemRenderer; + if (renderer) { + //trace("ListSingleSelectionMouseController.ROLL_OVER"); + IRollOverModel(listModel).rollOverIndex = renderer.index; + } + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ScrollBarMouseControllerBase.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ScrollBarMouseControllerBase.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ScrollBarMouseControllerBase.as new file mode 100644 index 0000000..8d9d27b --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/ScrollBarMouseControllerBase.as @@ -0,0 +1,184 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IScrollBarModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.html.beads.IScrollBarView; + + /** + * The ScrollBarMouseControllerBase class is the base class + * for ScrollBarMouseControllers such as VScrollBarMouseController. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ScrollBarMouseControllerBase implements IBeadController + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ScrollBarMouseControllerBase() + { + } + + /** + * The data model + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var sbModel:IScrollBarModel; + + /** + * The view + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected var sbView:IScrollBarView; + + private var _strand:IStrand; + + /** + * @private + */ + public function get strand():IStrand + { + return _strand; + } + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + sbModel = value.getBeadByType(IScrollBarModel) as IScrollBarModel; + sbView = value.getBeadByType(IScrollBarView) as IScrollBarView; + sbView.decrement.addEventListener(MouseEvent.CLICK, decrementClickHandler); + sbView.increment.addEventListener(MouseEvent.CLICK, incrementClickHandler); + sbView.decrement.addEventListener("buttonRepeat", decrementClickHandler); + sbView.increment.addEventListener("buttonRepeat", incrementClickHandler); + sbView.track.addEventListener(MouseEvent.CLICK, trackClickHandler); + sbView.thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbMouseDownHandler); + } + + /** + * Force the input number to be "snapped" to the snapInterval. + * + * @param value The input number. + * @return The input number "snapped" to the snapInterval. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function snap(value:Number):Number + { + var si:Number = sbModel.snapInterval; + var n:Number = Math.round((value - sbModel.minimum) / si) * si + sbModel.minimum; + if (value > 0) + { + if (value - n < n + si - value) + return n; + return n + si; + + } + if (value - n > n + si - value) + return n + si; + return n; + } + + /** + * Updates the model when the decrement button is clicked. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function decrementClickHandler(event:Event):void + { + sbModel.value = snap(Math.max(sbModel.minimum, sbModel.value - sbModel.stepSize)); + IEventDispatcher(_strand).dispatchEvent(new Event("scroll")); + } + + /** + * Updates the model when the increment button is clicked. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function incrementClickHandler(event:Event):void + { + sbModel.value = snap(Math.min(sbModel.maximum - sbModel.pageSize, sbModel.value + sbModel.stepSize)); + IEventDispatcher(_strand).dispatchEvent(new Event("scroll")); + } + + /** + * Handles a click in the track. Must be overridden. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function trackClickHandler(event:MouseEvent):void + { + } + + /** + * Handles a mouse down on the thumb. Must be overridden. + * Subclasses process the mouseMove and mouseUp events. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + protected function thumbMouseDownHandler(event:MouseEvent):void + { + } + + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SliderMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SliderMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SliderMouseController.as new file mode 100644 index 0000000..6469fd0 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SliderMouseController.as @@ -0,0 +1,286 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBead; + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IRangeModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.geom.Point; + import org.apache.flex.html.beads.ISliderView; + import org.apache.flex.html.beads.SliderTrackView; + + COMPILE::JS + { + import goog.events; + import goog.events.EventType; + import org.apache.flex.events.BrowserEvent; + import org.apache.flex.html.Slider; + import org.apache.flex.html.beads.SliderThumbView; + import org.apache.flex.html.beads.SliderTrackView; + } + + /** + * The SliderMouseController class bead handles mouse events on the + * org.apache.flex.html.Slider's component parts (thumb and track) and + * dispatches change events on behalf of the Slider (as well as co-ordinating visual + * changes (such as moving the thumb when the track has been tapped or clicked). + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class SliderMouseController implements IBead, IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function SliderMouseController() + { + } + + private var rangeModel:IRangeModel; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + rangeModel = UIBase(value).model as IRangeModel; + + COMPILE::AS3 + { + var sliderView:ISliderView = value.getBeadByType(ISliderView) as ISliderView; + sliderView.thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDownHandler); + + // add handler to detect click on track + sliderView.track.addEventListener(MouseEvent.CLICK, trackClickHandler, false, 99999); + + } + COMPILE::JS + { + track = value.getBeadByType( + SliderTrackView) as SliderTrackView; + thumb = value.getBeadByType( + SliderThumbView) as SliderThumbView; + + goog.events.listen(track.element, goog.events.EventType.CLICK, + handleTrackClick, false, this); + + goog.events.listen(thumb.element, goog.events.EventType.MOUSEDOWN, + handleThumbDown, false, this); + + } + } + + COMPILE::JS + private var track:SliderTrackView; + + COMPILE::JS + private var thumb:SliderThumbView; + + /** + * @private + */ + COMPILE::AS3 + private function thumbDownHandler( event:MouseEvent ) : void + { + UIBase(_strand).topMostEventDispatcher.addEventListener(MouseEvent.MOUSE_MOVE, thumbMoveHandler); + UIBase(_strand).topMostEventDispatcher.addEventListener(MouseEvent.MOUSE_UP, thumbUpHandler); + + var sliderView:ISliderView = _strand.getBeadByType(ISliderView) as ISliderView; + + origin = new Point(event.screenX, event.screenY); + thumb = new Point(sliderView.thumb.x,sliderView.thumb.y); + } + + /** + * @private + */ + COMPILE::AS3 + private function thumbUpHandler( event:MouseEvent ) : void + { + UIBase(_strand).topMostEventDispatcher.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMoveHandler); + UIBase(_strand).topMostEventDispatcher.removeEventListener(MouseEvent.MOUSE_UP, thumbUpHandler); + + IEventDispatcher(_strand).dispatchEvent(new Event("valueChange")); + } + + COMPILE::AS3 + private var origin:Point; + COMPILE::AS3 + private var thumb:Point; + + /** + * @private + */ + COMPILE::AS3 + private function thumbMoveHandler( event:MouseEvent ) : void + { + var sliderView:ISliderView = _strand.getBeadByType(ISliderView) as ISliderView; + + var deltaX:Number = event.screenX - origin.x; + var thumbW:Number = sliderView.thumb.width/2; + var newX:Number = thumb.x + deltaX; + + var p:Number = newX/UIBase(_strand).width; + var n:Number = p*(rangeModel.maximum - rangeModel.minimum) + rangeModel.minimum; + + rangeModel.value = n; + + IEventDispatcher(_strand).dispatchEvent(new Event("valueChange")); + } + + /** + * @private + */ + COMPILE::AS3 + private function trackClickHandler( event:MouseEvent ) : void + { + event.stopImmediatePropagation(); + + var sliderView:ISliderView = _strand.getBeadByType(ISliderView) as ISliderView; + + var xloc:Number = event.localX; + var p:Number = xloc/UIBase(_strand).width; + var n:Number = p*(rangeModel.maximum - rangeModel.minimum) + rangeModel.minimum; + + rangeModel.value = n; + + IEventDispatcher(_strand).dispatchEvent(new Event("valueChange")); + } + + /** + */ + COMPILE::JS + private function handleTrackClick(event:BrowserEvent):void + { + var host:Slider = _strand as Slider; + var xloc:Number = event.clientX; + var p:Number = Math.min(1, xloc / parseInt(track.element.style.width, 10)); + var n:Number = p * (host.maximum - host.minimum) + + host.minimum; + + host.value = n; + + origin = parseInt(thumb.element.style.left, 10); + position = parseInt(thumb.element.style.left, 10); + + calcValFromMousePosition(event, true); + + host.dispatchEvent(new org.apache.flex.events.Event('valueChange')); + } + + + /** + */ + COMPILE::JS + private function handleThumbDown(event:BrowserEvent):void + { + var host:Slider = _strand as Slider; + goog.events.listen(host.element, goog.events.EventType.MOUSEUP, + handleThumbUp, false, this); + goog.events.listen(host.element, goog.events.EventType.MOUSEMOVE, + handleThumbMove, false, this); + + origin = event.clientX; + position = parseInt(thumb.element.style.left, 10); + } + + COMPILE::JS + private var origin:Number; + COMPILE::JS + private var position:int; + + /** + */ + COMPILE::JS + private function handleThumbUp(event:BrowserEvent):void + { + var host:Slider = _strand as Slider; + goog.events.unlisten(host.element, goog.events.EventType.MOUSEUP, + handleThumbUp, false, this); + goog.events.unlisten(host.element, goog.events.EventType.MOUSEMOVE, + handleThumbMove, false, this); + + calcValFromMousePosition(event, false); + + host.dispatchEvent(new org.apache.flex.events.Event('valueChange')); + } + + + /** + */ + COMPILE::JS + private function handleThumbMove(event:BrowserEvent):void + { + var host:Slider = _strand as Slider; + calcValFromMousePosition(event, false); + + host.dispatchEvent(new org.apache.flex.events.Event('valueChange')); + } + + + /** + */ + COMPILE::JS + private function calcValFromMousePosition(event:BrowserEvent, useOffset:Boolean):void + { + var host:Slider = _strand as Slider; + var deltaX:Number = (useOffset ? event.offsetX : event.clientX) - origin; + var thumbW:int = parseInt(thumb.element.style.width, 10) / 2; + var newX:Number = position + deltaX; + + var p:Number = newX / parseInt(track.element.style.width, 10); + var n:Number = p * (host.maximum - host.minimum) + + host.minimum; + n = host.snap(n); + if (n < host.minimum) n = host.minimum; + else if (n > host.maximum) n = host.maximum; + + p = (n - host.minimum) / (host.maximum - + host.minimum); + newX = p * parseInt(track.element.style.width, 10); + + thumb.element.style.left = String(newX - + parseInt(thumb.element.style.width, 10) / 2) + 'px'; + + host.value = n; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SpinnerMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SpinnerMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SpinnerMouseController.as new file mode 100644 index 0000000..53309df --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/SpinnerMouseController.as @@ -0,0 +1,125 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import org.apache.flex.core.IBeadController; + import org.apache.flex.core.IRangeModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.html.TextButton; + import org.apache.flex.html.beads.ISpinnerView; + COMPILE::JS + { + import org.apache.flex.html.Spinner; + import goog.events; + import goog.events.EventType; + } + + /** + * The SpinnerMouseController class bead handles mouse events on the + * org.apache.flex.html.Spinner's component buttons, changing the + * value of the Spinner. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class SpinnerMouseController implements IBeadController + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function SpinnerMouseController() + { + } + + private var rangeModel:IRangeModel; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @flexjsignorecoercion org.apache.flex.html.Spinner + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + + rangeModel = UIBase(value).model as IRangeModel; + + COMPILE::AS3 + { + var spinnerBead:ISpinnerView = value.getBeadByType(ISpinnerView) as ISpinnerView; + spinnerBead.decrement.addEventListener(MouseEvent.CLICK, decrementClickHandler); + spinnerBead.decrement.addEventListener("buttonRepeat", decrementClickHandler); + spinnerBead.increment.addEventListener(MouseEvent.CLICK, incrementClickHandler); + spinnerBead.increment.addEventListener("buttonRepeat", incrementClickHandler); + } + + COMPILE::JS + { + var host:Spinner = value as Spinner; + incrementButton = host.incrementButton; + decrementButton = host.decrementButton; + + goog.events.listen(incrementButton.element, goog.events.EventType.CLICK, + incrementClickHandler); + + goog.events.listen(decrementButton.element, goog.events.EventType.CLICK, + decrementClickHandler); + + } + } + + private var incrementButton:TextButton; + private var decrementButton:TextButton; + + /** + * @private + */ + private function decrementClickHandler( event:Event ) : void + { + rangeModel.value = Math.max(rangeModel.minimum, rangeModel.value - rangeModel.stepSize); + IEventDispatcher(_strand).dispatchEvent(new Event("valueChange")); + } + + /** + * @private + */ + private function incrementClickHandler( event:Event ) : void + { + rangeModel.value = Math.min(rangeModel.maximum, rangeModel.value + rangeModel.stepSize); + IEventDispatcher(_strand).dispatchEvent(new Event("valueChange")); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/VScrollBarMouseController.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/VScrollBarMouseController.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/VScrollBarMouseController.as new file mode 100644 index 0000000..611f6dd --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/controllers/VScrollBarMouseController.as @@ -0,0 +1,101 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.controllers +{ + import flash.display.DisplayObject; + + import org.apache.flex.events.Event; + import org.apache.flex.events.MouseEvent; + import org.apache.flex.events.IEventDispatcher; + + /** + * The VScrollBarMouseController class is the controller for + * org.apache.flex.html.supportClasses.ScrollBar + * that acts as the Vertical ScrollBar. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class VScrollBarMouseController extends ScrollBarMouseControllerBase + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function VScrollBarMouseController() + { + } + + /** + * @private + */ + override protected function trackClickHandler(event:MouseEvent):void + { + if (sbView.thumb.visible) + { + if (event.localY < sbView.thumb.y) + { + sbModel.value = snap(Math.max(sbModel.minimum, sbModel.value - sbModel.pageStepSize)); + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + else + { + sbModel.value = snap(Math.min(sbModel.maximum - sbModel.pageSize, sbModel.value + sbModel.pageStepSize)); + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + } + } + + private var thumbDownY:Number; + private var lastThumbY:Number; + + /** + * @private + */ + override protected function thumbMouseDownHandler(event:MouseEvent):void + { + sbView.thumb.stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMouseMoveHandler); + sbView.thumb.stage.addEventListener(MouseEvent.MOUSE_UP, thumbMouseUpHandler); + thumbDownY = event.screenY; + lastThumbY = sbView.thumb.y; + } + + private function thumbMouseMoveHandler(event:MouseEvent):void + { + var thumb:DisplayObject = sbView.thumb; + var track:DisplayObject = sbView.track; + thumb.y = Math.max(track.y, Math.min(lastThumbY + (event.screenY - thumbDownY), track.y + track.height - thumb.height)); + var newValue:Number = snap((thumb.y - track.y) / (track.height - thumb.height) * (sbModel.maximum - sbModel.minimum - sbModel.pageSize)); + sbModel.value = newValue; + IEventDispatcher(strand).dispatchEvent(new Event("scroll")); + } + + private function thumbMouseUpHandler(event:MouseEvent):void + { + sbView.thumb.stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMouseMoveHandler); + sbView.thumb.stage.removeEventListener(MouseEvent.MOUSE_UP, thumbMouseUpHandler); + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as new file mode 100644 index 0000000..8a8c0d7 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/BasicLayout.as @@ -0,0 +1,445 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.layouts +{ + + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ILayoutChild; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.utils.CSSUtils; + //import org.apache.flex.utils.dbg.DOMPathUtil; + + /** + * The BasicLayout class is a simple layout + * bead. It takes the set of children and lays them out + * as specified by CSS properties like left, right, top + * and bottom. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class BasicLayout implements IBeadLayout + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function BasicLayout() + { + } + + // the strand/host container is also an ILayoutChild because + // can have its size dictated by the host's parent which is + // important to know for layout optimization + private var host:ILayoutChild; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + host = value as ILayoutChild; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + * @flexjsignorecoercion org.apache.flex.core.ILayoutHost + * @flexjsignorecoercion org.apache.flex.core.UIBase + */ + public function layout():Boolean + { + COMPILE::AS3 + { + //trace(DOMPathUtil.getPath(host), event ? event.type : "fixed size"); + var layoutParent:ILayoutHost = host.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent ? layoutParent.contentView : IParentIUIBase(host); + + var gotMargin:Boolean; + var marginLeft:Object; + var marginRight:Object; + var marginTop:Object; + var marginBottom:Object; + var margin:Object; + var ml:Number; + var mr:Number; + var mt:Number; + var mb:Number; + var hostWidthSizedToContent:Boolean = host.isWidthSizedToContent(); + var hostHeightSizedToContent:Boolean = host.isHeightSizedToContent(); + var w:Number = hostWidthSizedToContent ? 0 : contentView.width; + var h:Number = hostHeightSizedToContent ? 0 : contentView.height; + var n:int = contentView.numElements; + var maxWidth:Number = 0; + var maxHeight:Number = 0; + var childData:Array = []; + for (var i:int = 0; i < n; i++) + { + var child:IUIBase = contentView.getElementAt(i) as IUIBase; + var left:Number = ValuesManager.valuesImpl.getValue(child, "left"); + var right:Number = ValuesManager.valuesImpl.getValue(child, "right"); + var top:Number = ValuesManager.valuesImpl.getValue(child, "top"); + var bottom:Number = ValuesManager.valuesImpl.getValue(child, "bottom"); + var ww:Number = w; + var hh:Number = h; + + var ilc:ILayoutChild = child as ILayoutChild; + if (!isNaN(left)) + { + if (ilc) + ilc.setX(left); + else + child.x = left; + ww -= left; + } + if (!isNaN(top)) + { + if (ilc) + ilc.setY(top); + else + child.y = top; + hh -= top; + } + if (ilc) + { + if (!hostWidthSizedToContent) + { + if (!isNaN(ilc.percentWidth)) + ilc.setWidth((ww - (isNaN(right) ? 0 : right)) * ilc.percentWidth / 100, true); + } + else + childData[i] = { bottom: bottom, right: right, ww: ww, ilc: ilc, child: child }; + } + if (!isNaN(right)) + { + if (!hostWidthSizedToContent) + { + if (!isNaN(left)) + { + if (ilc) + ilc.setWidth(ww - right, true); + else + child.width = ww - right; + } + else + { + if (ilc) + ilc.setX( w - right - child.width); + else + child.x = w - right - child.width; + } + } + else + childData[i] = { ww: ww, left: left, right: right, ilc: ilc, child: child }; + } + + if (isNaN(right) && isNaN(left)) + { + margin = ValuesManager.valuesImpl.getValue(child, "margin"); + gotMargin = true; + marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); + marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); + var horizontalCenter:Boolean = + (marginLeft == "auto" && marginRight == "auto") || + (margin is String && margin == "auto") || + (margin is Array && + ((margin.length < 4 && margin[1] == "auto") || + (margin.length == 4 && margin[1] == "auto" && margin[3] == "auto"))); + if (!hostWidthSizedToContent) + { + if (!horizontalCenter) + { + mr = CSSUtils.getRightValue(marginRight, margin, ww); + ml = CSSUtils.getLeftValue(marginLeft, margin, ww); + if (ilc) + ilc.setX(ml); + else + child.x = ml; + if (ilc && isNaN(ilc.percentWidth) && isNaN(ilc.explicitWidth)) + child.width = ww - child.x - mr; + } + else + { + if (ilc) + ilc.setX((ww - child.width) / 2); + else + child.x = (ww - child.width) / 2; + } + } + else + { + if (!horizontalCenter) + { + mr = CSSUtils.getRightValue(marginRight, margin, ww); + ml = CSSUtils.getLeftValue(marginLeft, margin, ww); + if (ilc) + ilc.setX(ml); + else + child.x = ml; + if (ilc && isNaN(ilc.percentWidth) && isNaN(ilc.explicitWidth)) + childData[i] = { ww: ww, left: ml, right: mr, ilc: ilc, child: child }; + } + else + { + childData[i] = { ww: ww, center: true, ilc: ilc, child: child }; + } + } + + } + if (isNaN(top) && isNaN(bottom)) + { + if (!gotMargin) + margin = ValuesManager.valuesImpl.getValue(child, "margin"); + marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); + marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); + mt = CSSUtils.getTopValue(marginTop, margin, hh); + mb = CSSUtils.getBottomValue(marginBottom, margin, hh); + if (ilc) + ilc.setY(mt); + else + child.y = mt; + /* browsers don't use margin-bottom to stretch things vertically + if (!hostHeightSizedToContent) + { + if (ilc && isNaN(ilc.percentHeight) && isNaN(ilc.explicitHeight)) + child.height = hh - child.y - mb; + } + else + { + if (!childData[i]) + childData[i] = { hh: hh, bottom: mb, ilc: ilc, child: child }; + else + { + childData[i].hh = hh; + childData[i].bottom = mb; + } + } + */ + } + + if (ilc) + { + if (!hostHeightSizedToContent) + { + if (!isNaN(ilc.percentHeight)) + ilc.setHeight((hh - (isNaN(bottom) ? 0 : bottom)) * ilc.percentHeight / 100, true); + } + else + { + if (!childData[i]) + childData[i] = { hh: hh, bottom: bottom, ilc: ilc, child: child }; + else + { + childData[i].hh = hh; + childData[i].bottom = bottom; + } + } + } + if (!isNaN(bottom)) + { + if (!hostHeightSizedToContent) + { + if (!isNaN(top)) + { + if (ilc) + ilc.setHeight(hh - bottom, true); + else + child.height = hh - bottom; + } + else + { + if (ilc) + ilc.setY(h - bottom - child.height); + else + child.y = h - bottom - child.height; + } + } + else + { + if (!childData[i]) + childData[i] = { top: top, bottom: bottom, hh:hh, ilc: ilc, child: child }; + else + { + childData[i].top = top; + childData[i].bottom = bottom; + childData[i].hh = hh; + } + } + } + if (!childData[i]) + child.dispatchEvent(new Event("sizeChanged")); + maxWidth = Math.max(maxWidth, child.x + child.width); + maxHeight = Math.max(maxHeight, child.y + child.height); + } + if (hostHeightSizedToContent || hostWidthSizedToContent) + { + for (i = 0; i < n; i++) + { + var data:Object = childData[i]; + if (data) + { + if (hostWidthSizedToContent) + { + if (data.ilc && !isNaN(data.ilc.percentWidth)) + data.ilc.setWidth((data.ww - (isNaN(data.right) ? 0 : data.right)) * data.ilc.percentWidth / 100, true); + if (data.center) + { + if (data.ilc) + data.ilc.setX((data.ww - data.child.width) / 2); + else + data.child.x = (data.ww - data.child.width) / 2; + } + else if (!isNaN(data.right)) + { + if (!isNaN(data.left)) + { + if (data.ilc) + data.ilc.setWidth(data.ww - data.right, true); + else + data.child.width = data.ww - data.right; + } + else + { + if (data.ilc) + data.ilc.setX(maxWidth - data.right - data.child.width); + else + data.child.x = maxWidth - data.right - data.child.width; + } + } + } + if (hostHeightSizedToContent) + { + if (data.ilc && !isNaN(data.ilc.percentHeight)) + data.ilc.setHeight((data.hh - (isNaN(data.bottom) ? 0 : data.bottom)) * data.ilc.percentHeight / 100, true); + if (!isNaN(data.bottom)) + { + if (!isNaN(data.top)) + { + if (data.ilc) + data.ilc.setHeight(data.hh - data.bottom, true); + else + data.child.height = data.hh - data.bottom; + } + else + { + if (data.ilc) + data.ilc.setY(maxHeight - data.bottom - data.child.height); + else + data.child.y = maxHeight - data.bottom - data.child.height; + } + } + } + child.dispatchEvent(new Event("sizeChanged")); + } + } + } + + host.dispatchEvent( new Event("layoutComplete") ); + + return true; + + } + COMPILE::JS + { + var i:int + var n:int; + var h:Number; + var w:Number; + + var viewBead:ILayoutHost = host.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = viewBead.contentView; + w = contentView.width; + var hasWidth:Boolean = !host.isWidthSizedToContent(); + h = contentView.height; + var hasHeight:Boolean = !host.isHeightSizedToContent(); + var maxHeight:Number = 0; + var maxWidth:Number = 0; + n = contentView.numElements; + for (i = 0; i < n; i++) { + var child:UIBase = contentView.getElementAt(i) as UIBase; + child.setDisplayStyleForLayout('block'); + var left:Number = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'left'); + var right:Number = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'right'); + var top:Number = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'top'); + var bottom:Number = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'bottom'); + var margin:String = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'margin'); + var marginLeft:String = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'margin-left'); + var marginRight:String = org.apache.flex.core.ValuesManager.valuesImpl.getValue(child, 'margin-right'); + var horizontalCenter:Boolean = + (marginLeft == 'auto' && marginRight == 'auto') || + (typeof(margin) === 'string' && margin == 'auto') || + (margin && margin.hasOwnProperty('length') && + ((margin.length < 4 && margin[1] == 'auto') || + (margin.length == 4 && margin[1] == 'auto' && margin[3] == 'auto'))); + + if (!isNaN(left)) { + child.positioner.style.position = 'absolute'; + child.positioner.style.left = left.toString() + 'px'; + } + if (!isNaN(top)) { + child.positioner.style.position = 'absolute'; + child.positioner.style.top = top.toString() + 'px'; + } + if (!isNaN(right)) { + child.positioner.style.position = 'absolute'; + child.positioner.style.right = right.toString() + 'px'; + } + if (!isNaN(bottom)) { + child.positioner.style.position = 'absolute'; + child.positioner.style.bottom = bottom.toString() + 'px'; + } + if (horizontalCenter) + { + child.positioner.style.position = 'absolute'; + child.positioner.style.left = ((w - child.width) / 2).toString() + 'px'; + } + child.dispatchEvent('sizeChanged'); + maxWidth = Math.max(maxWidth, child.positioner.offsetLeft + child.positioner.offsetWidth); + maxHeight = Math.max(maxHeight, child.positioner.offsetTop + child.positioner.offsetHeight); + } + // if there are children and maxHeight is ok, use it. + // maxHeight can be NaN if the child hasn't been rendered yet. + if (!hasWidth && n > 0 && !isNaN(maxWidth)) { + contentView.width = maxWidth; + } + if (!hasHeight && n > 0 && !isNaN(maxHeight)) { + contentView.height = maxHeight; + } + return true; + } + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as new file mode 100644 index 0000000..5bd1159 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/ButtonBarLayout.as @@ -0,0 +1,143 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.layouts +{ + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.IItemRendererClassFactory; + import org.apache.flex.core.IItemRendererParent; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.ISelectableItemRenderer; + import org.apache.flex.core.ISelectionModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.IViewportModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.List; + import org.apache.flex.html.beads.ButtonBarView; + + /** + * The ButtonBarLayout class bead sizes and positions the org.apache.flex.html.Button + * elements that make up a org.apache.flex.html.ButtonBar. This bead arranges the Buttons + * horizontally and makes them all the same width unless the buttonWidths property has been set in which case + * the values stored in that array are used. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class ButtonBarLayout implements IBeadLayout + { + /** + * constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function ButtonBarLayout() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + } + + private var _buttonWidths:Array = null; + + /** + * An array of widths (Number), one per button. These values supersede the + * default of equally-sized buttons. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get buttonWidths():Array + { + return _buttonWidths; + } + public function set buttonWidths(value:Array):void + { + _buttonWidths = value; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + */ + public function layout():Boolean + { + var layoutParent:ILayoutHost = _strand.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent.contentView as IParentIUIBase; + var itemRendererParent:IItemRendererParent = contentView as IItemRendererParent; + var viewportModel:IViewportModel = (layoutParent as ButtonBarView).viewportModel; + + var n:int = contentView.numElements; + var realN:int = n; + + for (var j:int=0; j < n; j++) + { + var child:IUIBase = itemRendererParent.getElementAt(j) as IUIBase; + if (child == null || !child.visible) realN--; + } + + var xpos:Number = 0; + var useWidth:Number = contentView.width / realN; + var useHeight:Number = contentView.height; + + for (var i:int=0; i < n; i++) + { + var ir:ISelectableItemRenderer = itemRendererParent.getElementAt(i) as ISelectableItemRenderer; + if (ir == null || !UIBase(ir).visible) continue; + UIBase(ir).y = 0; + UIBase(ir).x = xpos; + if (!isNaN(useHeight) && useHeight > 0) { + UIBase(ir).height = useHeight; + } + + if (buttonWidths) UIBase(ir).width = Number(buttonWidths[i]); + else if (!isNaN(useWidth) && useWidth > 0) { + UIBase(ir).width = useWidth; + } + xpos += UIBase(ir).width; + } + + IEventDispatcher(_strand).dispatchEvent( new Event("layoutComplete") ); + + return true; + } + } +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/DataGridLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/DataGridLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/DataGridLayout.as new file mode 100644 index 0000000..33399c3 --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/DataGridLayout.as @@ -0,0 +1,156 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.layouts +{ + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.IDataGridModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.UIBase; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.html.ButtonBar; + import org.apache.flex.html.supportClasses.DataGridColumn; + + /** + * DataGridLayout is a class that handles the size and positioning of the + * elements of a DataGrid. This includes the ButtonBar used for the column + * headers and the Lists that are the columns. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class DataGridLayout implements IBeadLayout + { + /** + * constructor + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function DataGridLayout() + { + } + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + } + + private var _header:UIBase; + + /** + * The element that is the header for the DataGrid + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get header():IUIBase + { + return _header; + } + public function set header(value:IUIBase):void + { + _header = UIBase(value); + } + + private var _columns:Array; + + /** + * The array of column elements. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get columns():Array + { + return _columns; + } + public function set columns(value:Array):void + { + _columns = value; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + */ + public function layout():Boolean + { + var sw:Number = UIBase(_strand).width; + var sh:Number = UIBase(_strand).height; + + var columnHeight:Number = Math.floor(sh - header.height); + var columnWidth:Number = Math.floor(sw / columns.length); + + var xpos:Number = 0; + var ypos:Number = Math.floor(header.height); + + // TODO: change the layout so that the model's DataGridColumn.columnWidth + // isn't used blindly, but is considered in the overall width. In other words, + // right now the width could exceed the strand's width. + var model:IDataGridModel = _strand.getBeadByType(IDataGridModel) as IDataGridModel; + + var buttonWidths:Array = new Array(); + + for(var i:int=0; i < columns.length; i++) { + var column:UIBase = columns[i] as UIBase; + column.x = xpos; + column.y = ypos; + column.height = columnHeight; + + var dgc:DataGridColumn = model.columns[i]; + if (!isNaN(dgc.columnWidth)) column.width = dgc.columnWidth; + else column.width = columnWidth; + + xpos += column.width; + + buttonWidths.push(column.width); + } + + var bar:ButtonBar = header as ButtonBar; + var barLayout:ButtonBarLayout = bar.getBeadByType(ButtonBarLayout) as ButtonBarLayout; + barLayout.buttonWidths = buttonWidths; + + header.x = 0; + header.y = 0; + header.width = sw; + header.dispatchEvent(new Event("layoutNeeded")); + + return true; + } + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as new file mode 100644 index 0000000..4198fea --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/FlexibleFirstChildHorizontalLayout.as @@ -0,0 +1,244 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.layouts +{ + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.ILayoutChild; + import org.apache.flex.core.ILayoutHost; + import org.apache.flex.core.IParentIUIBase; + import org.apache.flex.core.IStrand; + import org.apache.flex.core.IUIBase; + import org.apache.flex.core.IViewport; + import org.apache.flex.core.IViewportModel; + import org.apache.flex.core.UIBase; + import org.apache.flex.core.ValuesManager; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.geom.Rectangle; + import org.apache.flex.html.supportClasses.Viewport; + import org.apache.flex.utils.CSSContainerUtils; + + /** + * The FlexibleFirstChildHorizontalLayout class is a simple layout + * bead. It takes the set of children and lays them out + * horizontally in one row, separating them according to + * CSS layout rules for margin and padding styles. But it + * will size the first child to take up as much or little + * room as possible. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class FlexibleFirstChildHorizontalLayout implements IBeadLayout + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function FlexibleFirstChildHorizontalLayout() + { + } + + // the strand/host container is also an ILayoutChild because + // can have its size dictated by the host's parent which is + // important to know for layout optimization + private var host:ILayoutChild; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + host = value as ILayoutChild; + } + + private var _maxWidth:Number; + + /** + * @copy org.apache.flex.core.IBead#maxWidth + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get maxWidth():Number + { + return _maxWidth; + } + + /** + * @private + */ + public function set maxWidth(value:Number):void + { + _maxWidth = value; + } + + private var _maxHeight:Number; + + /** + * @copy org.apache.flex.core.IBead#maxHeight + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function get maxHeight():Number + { + return _maxHeight; + } + + /** + * @private + */ + public function set maxHeight(value:Number):void + { + _maxHeight = value; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + */ + public function layout():Boolean + { + var layoutParent:ILayoutHost = host.getBeadByType(ILayoutHost) as ILayoutHost; + var contentView:IParentIUIBase = layoutParent.contentView as IParentIUIBase; + var padding:Rectangle = CSSContainerUtils.getPaddingMetrics(host); + var hostSizedToContent:Boolean = host.isHeightSizedToContent(); + + var n:int = contentView.numElements; + var marginLeft:Object; + var marginRight:Object; + var marginTop:Object; + var marginBottom:Object; + var margin:Object; + maxHeight = 0; + var verticalMargins:Array = []; + + var xx:Number = contentView.width; + if (isNaN(xx) || xx <= 0) + return true; + xx -= padding.right + 1; // some browsers won't layout to the edge + + for (var i:int = n - 1; i >= 0; i--) + { + var child:IUIBase = contentView.getElementAt(i) as IUIBase; + margin = ValuesManager.valuesImpl.getValue(child, "margin"); + if (margin is Array) + { + if (margin.length == 1) + marginLeft = marginTop = marginRight = marginBottom = margin[0]; + else if (margin.length <= 3) + { + marginLeft = marginRight = margin[1]; + marginTop = marginBottom = margin[0]; + } + else if (margin.length == 4) + { + marginLeft = margin[3]; + marginBottom = margin[2]; + marginRight = margin[1]; + marginTop = margin[0]; + } + } + else if (margin == null) + { + marginLeft = ValuesManager.valuesImpl.getValue(child, "margin-left"); + marginTop = ValuesManager.valuesImpl.getValue(child, "margin-top"); + marginRight = ValuesManager.valuesImpl.getValue(child, "margin-right"); + marginBottom = ValuesManager.valuesImpl.getValue(child, "margin-bottom"); + } + else + { + marginLeft = marginTop = marginBottom = marginRight = margin; + } + var ml:Number; + var mr:Number; + var mt:Number; + var mb:Number; + var lastmr:Number; + mt = Number(marginTop); + if (isNaN(mt)) + mt = 0; + mb = Number(marginBottom); + if (isNaN(mb)) + mb = 0; + if (marginLeft == "auto") + ml = 0; + else + { + ml = Number(marginLeft); + if (isNaN(ml)) + ml = 0; + } + if (marginRight == "auto") + mr = 0; + else + { + mr = Number(marginRight); + if (isNaN(mr)) + mr = 0; + } + child.y = mt + padding.top; + if (i == 0) + { + child.x = ml + padding.left; + child.width = xx - mr - child.x; + } + else + child.x = xx - child.width - mr; + maxHeight = Math.max(maxHeight, mt + child.height + mb); + xx -= child.width + mr + ml; + lastmr = mr; + var valign:Object = ValuesManager.valuesImpl.getValue(child, "vertical-align"); + verticalMargins.push({ marginTop: mt, marginBottom: mb, valign: valign }); + } + for (i = 0; i < n; i++) + { + var obj:Object = verticalMargins[0] + child = contentView.getElementAt(i) as IUIBase; + if (obj.valign == "middle") + child.y = (maxHeight - child.height) / 2; + else if (valign == "bottom") + child.y = maxHeight - child.height - obj.marginBottom; + else + child.y = obj.marginTop; + } + if (hostSizedToContent) + ILayoutChild(contentView).setHeight(maxHeight + padding.top + padding.bottom, true); + + return true; + } + + } + +} http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/7853ef15/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HScrollBarLayout.as ---------------------------------------------------------------------- diff --git a/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HScrollBarLayout.as b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HScrollBarLayout.as new file mode 100644 index 0000000..38b97ec --- /dev/null +++ b/frameworks/projects/HTML/src/main/flex/org/apache/flex/html/beads/layouts/HScrollBarLayout.as @@ -0,0 +1,121 @@ +//////////////////////////////////////////////////////////////////////////////// +// +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////////// +package org.apache.flex.html.beads.layouts +{ + import flash.display.DisplayObject; + + import org.apache.flex.core.IBeadLayout; + import org.apache.flex.core.IScrollBarModel; + import org.apache.flex.core.IStrand; + import org.apache.flex.events.Event; + import org.apache.flex.events.IEventDispatcher; + import org.apache.flex.geom.Rectangle; + import org.apache.flex.html.beads.IScrollBarView; + import org.apache.flex.utils.CSSContainerUtils; + + /** + * The HScrollBarLayout class is a layout + * bead that displays lays out the pieces of a + * horizontal ScrollBar like the thumb, track + * and arrow buttons. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public class HScrollBarLayout implements IBeadLayout + { + /** + * Constructor. + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function HScrollBarLayout() + { + } + + private var sbModel:IScrollBarModel; + private var sbView:IScrollBarView; + + private var _strand:IStrand; + + /** + * @copy org.apache.flex.core.IBead#strand + * + * @langversion 3.0 + * @playerversion Flash 10.2 + * @playerversion AIR 2.6 + * @productversion FlexJS 0.0 + */ + public function set strand(value:IStrand):void + { + _strand = value; + sbView = _strand.getBeadByType(IScrollBarView) as IScrollBarView; + } + + /** + * @copy org.apache.flex.core.IBeadLayout#layout + */ + public function layout():Boolean + { + if (!sbModel) + sbModel = _strand.getBeadByType(IScrollBarModel) as IScrollBarModel + + var metrics:Rectangle = CSSContainerUtils.getBorderAndPaddingMetrics(_strand); + + var w:Number = DisplayObject(_strand).width + metrics.left + metrics.right; + var increment:DisplayObject = sbView.increment; + var decrement:DisplayObject = sbView.decrement; + var track:DisplayObject = sbView.track; + var thumb:DisplayObject = sbView.thumb; + + decrement.x = 0; + decrement.y = 0; + decrement.height = DisplayObject(_strand).height; + decrement.width = DisplayObject(_strand).height; + + increment.height = DisplayObject(_strand).height; + increment.width = DisplayObject(_strand).height; + increment.x = w - increment.width - 1; + increment.y = 0; + + track.x = decrement.width; + track.y = 0; + track.height = DisplayObject(_strand).height; + track.width = increment.x - decrement.width; + thumb.width = sbModel.pageSize / (sbModel.maximum - sbModel.minimum) * track.width; + if (track.width > thumb.width) + { + thumb.visible = true; + thumb.x = (sbModel.value / (sbModel.maximum - sbModel.minimum - sbModel.pageSize) * (track.width - thumb.width)) + track.x; + } + else + { + thumb.visible = false; + } + + return true; + } + + } +}
