2
* Copyright (c) 2008, 2009 Flowplayer Oy
4
* This file is part of Flowplayer.
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.
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.
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/>.
20
package org.flowplayer.view {
21
import flash.display.DisplayObject;
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;
34
import flash.display.Stage;
35
import flash.display.StageDisplayState;
36
import flash.events.FullScreenEvent;
37
import flash.geom.Rectangle;
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;
53
public function FullscreenManager(stage:Stage, playlist:Playlist, panel:Panel, pluginRegistry:PluginRegistry, animations:AnimationEngine) {
54
Assert.notNull(stage, "stage cannot be null");
56
_stage.addEventListener(FullScreenEvent.FULL_SCREEN, onFullScreen);
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;
66
private function getFullscreenProperties():DisplayProperties {
67
var model:DisplayPluginModel = _pluginRegistry.getPlugin("controls") as DisplayPluginModel;
68
if (! model) return DisplayPropertiesImpl.fullSize("screen");
70
var controls:DisplayObject = model.getDisplayObject();
71
log.debug("controls.auotoHide " + controls["getAutoHide"]());
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 + "%";
81
return DisplayPropertiesImpl.fullSize("screen");
84
public function toggleFullscreen():void {
85
log.debug("toggleFullsreen");
93
private function exitFullscreen():void {
94
log.info("exiting fullscreen");
95
_stage.displayState = StageDisplayState.NORMAL;
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;
105
public function get isFullscreen():Boolean {
106
log.debug("currently in fulscreen? " + (_stage.displayState == StageDisplayState.FULL_SCREEN));
107
return _stage.displayState == StageDisplayState.FULL_SCREEN;
110
private function initializeHwScaling(clip:Clip):void {
111
if (! _stage.hasOwnProperty("fullScreenSourceRect")) {
112
log.info("hardware scaling not supported by this Flash version");
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);
119
_stage.fullScreenSourceRect = null;
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;
128
_animations.animate(_screen, event.fullScreen ? getFullscreenProperties() : _screenNormalProperties, 0, function():void {_playerEventDispatcher.dispatchEvent(event.fullScreen ? PlayerEvent.fullscreen() : PlayerEvent.fullscreenExit());});
131
public function set playerEventDispatcher(playerEventDispatcher:PlayerEventDispatcher):void {
132
_playerEventDispatcher = playerEventDispatcher;