~mahara-contributors/mahara-adminlang/adminlang-master

« back to all changes in this revision

Viewing changes to htdocs/lib/flowplayer/src/actionscript/org/flowplayer/view/FullscreenManager.as

  • Committer: Ruslan Kabalin
  • Date: 2011-08-03 14:54:09 UTC
  • Revision ID: git-v1:a3409b53a971ec3bad8b5d1329298046d9596381
Revert back to master brach.

The adminlang-master was mistakingly based on the mahara 1.3_STABLE. This is
required for easy merge with the master.

Command used:
for i in `git rev-list
f731cf9b2cf72b61ed6a317acab23a30b9046c8a..afb5850ba246f41b624c162e8d8e6e72c534f239`;
do git revert -n $i; done

Change-Id: I9db8553a66facfaca81492cd978f974c6e7b8892

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*    
 
2
 *    Copyright (c) 2008, 2009 Flowplayer Oy
 
3
 *
 
4
 *    This file is part of Flowplayer.
 
5
 *
 
6
 *    Flowplayer is free software: you can redistribute it and/or modify
 
7
 *    it under the terms of the GNU General Public License as published by
 
8
 *    the Free Software Foundation, either version 3 of the License, or
 
9
 *    (at your option) any later version.
 
10
 *
 
11
 *    Flowplayer is distributed in the hope that it will be useful,
 
12
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *    GNU General Public License for more details.
 
15
 *
 
16
 *    You should have received a copy of the GNU General Public License
 
17
 *    along with Flowplayer.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
package org.flowplayer.view {
 
21
    import flash.display.DisplayObject;
 
22
 
 
23
    import org.flowplayer.model.Clip;
 
24
        import org.flowplayer.model.Cloneable;
 
25
        import org.flowplayer.model.DisplayPluginModel;
 
26
        import org.flowplayer.model.DisplayProperties;
 
27
        import org.flowplayer.model.DisplayPropertiesImpl;
 
28
        import org.flowplayer.model.PlayerEvent;
 
29
        import org.flowplayer.model.Playlist;
 
30
        import org.flowplayer.model.PluginModel;
 
31
        import org.flowplayer.util.Assert;
 
32
        import org.flowplayer.util.Log;
 
33
        
 
34
        import flash.display.Stage;
 
35
        import flash.display.StageDisplayState;
 
36
        import flash.events.FullScreenEvent;
 
37
        import flash.geom.Rectangle;    
 
38
 
 
39
        /**
 
40
         * @author api
 
41
         */
 
42
        internal class FullscreenManager {
 
43
                private var log:Log = new Log(this);
 
44
                private var _stage:Stage;
 
45
                private var _playlist:Playlist;
 
46
                private var _panel:Panel;
 
47
                private var _pluginRegistry:PluginRegistry;
 
48
                private var _animations:AnimationEngine;
 
49
                private var _screen:Screen;
 
50
                private var _screenNormalProperties:DisplayProperties;
 
51
                private var _playerEventDispatcher:PlayerEventDispatcher;
 
52
 
 
53
                public function FullscreenManager(stage:Stage, playlist:Playlist, panel:Panel, pluginRegistry:PluginRegistry, animations:AnimationEngine) {
 
54
                        Assert.notNull(stage, "stage cannot be null");
 
55
                        _stage = stage;
 
56
                        _stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
 
57
                        _playlist = playlist;
 
58
                        _panel = panel;
 
59
                        _pluginRegistry = pluginRegistry;
 
60
                        _screen = (pluginRegistry.getPlugin("screen") as DisplayProperties).getDisplayObject() as Screen;
 
61
                        Assert.notNull(_screen, "got null screen from pluginRegistry");
 
62
                        _screen.fullscreenManager = this;
 
63
                        _animations = animations;
 
64
                }
 
65
                
 
66
                private function getFullscreenProperties():DisplayProperties {
 
67
                        var model:DisplayPluginModel = _pluginRegistry.getPlugin("controls") as DisplayPluginModel;
 
68
            if (! model) return DisplayPropertiesImpl.fullSize("screen");
 
69
 
 
70
            var controls:DisplayObject = model.getDisplayObject();
 
71
                        log.debug("controls.auotoHide " + controls["getAutoHide"]());
 
72
 
 
73
                        if ( controls && ! controls["getAutoHide"]().enabled ) {
 
74
                                log.debug("autoHiding disabled in fullscreen, calculating fullscreen display properties");
 
75
                                var controlsHeight:Number = controls.height;
 
76
                                var props:DisplayProperties = DisplayPropertiesImpl.fullSize("screen");
 
77
                                props.bottom = controlsHeight;
 
78
                                props.height =  ((_stage.stageHeight - controlsHeight) / _stage.stageHeight) * 100 + "%";
 
79
                                return props;
 
80
                        }
 
81
                        return DisplayPropertiesImpl.fullSize("screen");
 
82
                }
 
83
        
 
84
                public function toggleFullscreen():void {
 
85
                        log.debug("toggleFullsreen");
 
86
                        if (isFullscreen) {
 
87
                                exitFullscreen();
 
88
                        } else {
 
89
                                goFullscreen();
 
90
                        }
 
91
                }
 
92
                
 
93
                private function exitFullscreen():void {
 
94
                        log.info("exiting fullscreen");
 
95
                        _stage.displayState = StageDisplayState.NORMAL;
 
96
                }
 
97
 
 
98
                private function goFullscreen():void {
 
99
                        log.info("entering fullscreen");
 
100
                        var clip:Clip = _playlist.current;
 
101
                        initializeHwScaling(clip);
 
102
                        _stage.displayState = StageDisplayState.FULL_SCREEN;
 
103
                }
 
104
 
 
105
                public function get isFullscreen():Boolean {
 
106
                        log.debug("currently in fulscreen? " + (_stage.displayState == StageDisplayState.FULL_SCREEN));
 
107
                        return _stage.displayState == StageDisplayState.FULL_SCREEN;
 
108
                }
 
109
                
 
110
                private function initializeHwScaling(clip:Clip):void {
 
111
            if (! _stage.hasOwnProperty("fullScreenSourceRect")) {
 
112
                log.info("hardware scaling not supported by this Flash version");
 
113
                return;
 
114
            }
 
115
                        if (clip.accelerated) {
 
116
                                _stage.fullScreenSourceRect = new Rectangle(0, 0,clip.originalWidth, clip.originalHeight);
 
117
                                log.info("harware scaled fullscreen initialized with rectangle " + _stage.fullScreenSourceRect);
 
118
                        } else {
 
119
                                _stage.fullScreenSourceRect = null;
 
120
                        }
 
121
                }
 
122
                                
 
123
                private function onFullScreen(event:FullScreenEvent):void {
 
124
                        // store the normal screen properties just prior to entering fullscreen so that the user's screen animations can be restored
 
125
                        if (event.fullScreen) {
 
126
                                _screenNormalProperties = Cloneable(_pluginRegistry.getPlugin("screen")).clone() as DisplayProperties;
 
127
                        }
 
128
                        _animations.animate(_screen, event.fullScreen ? getFullscreenProperties() : _screenNormalProperties, 0, function():void {_playerEventDispatcher.dispatchEvent(event.fullScreen ? PlayerEvent.fullscreen() : PlayerEvent.fullscreenExit());});
 
129
                }
 
130
 
 
131
                public function set playerEventDispatcher(playerEventDispatcher:PlayerEventDispatcher):void {
 
132
                        _playerEventDispatcher = playerEventDispatcher;
 
133
                }
 
134
        }
 
135
}