suite/common/fullscreen-video.xhtml
author tbirdbld
Wed, 23 Nov 2011 03:29:45 -0800
branchCOMM90_20111123_RELBRANCH
changeset 9382 c6d7fdf687177d028612abae690e49e32bd955a6
parent 6651 5773513ab09bd6c5e6918478aee8d55d88fe3d4e
child 12286 84ac3c71109811da751f0ef2d72108075938f094
permissions -rw-r--r--
Added tag THUNDERBIRD_9_0b2_BUILD1 for changeset f7ebf70e228c. CLOSED TREE a=release

<?xml version="1.0" encoding="UTF-8"?>

<!-- ***** BEGIN LICENSE BLOCK *****
   - Version: MPL 1.1/GPL 2.0/LGPL 2.1
   -
   - The contents of this file are subject to the Mozilla Public License Version
   - 1.1 (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.mozilla.org/MPL/
   -
   - Software distributed under the License is distributed on an "AS IS" basis,
   - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
   - for the specific language governing rights and limitations under the
   - License.
   -
   - The Original Code is mozilla.org code.
   -
   - The Initial Developer of the Original Code is the Mozilla Foundation.
   - Portions created by the Initial Developer are Copyright (C) 2008
   - the Initial Developer. All Rights Reserved.
   -
   - Contributor(s):
   -   Dao Gottwald <dao@mozilla.com>
   -
   - Alternatively, the contents of this file may be used under the terms of
   - either the GNU General Public License Version 2 or later (the "GPL"), or
   - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
   - in which case the provisions of the GPL or the LGPL are applicable instead
   - of those above. If you wish to allow use of your version of this file only
   - under the terms of either the GPL or the LGPL, and not to allow others to
   - use your version of this file under the terms of the MPL, indicate your
   - decision by deleting the provisions above and replace them with the notice
   - and other provisions required by the GPL or the LGPL. If you do not delete
   - the provisions above, a recipient may use your version of this file under
   - the terms of any one of the MPL, the GPL or the LGPL.
   -
   - ***** END LICENSE BLOCK ***** -->

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" accelerated="11">
<head>
  <link href="chrome://communicator/skin/fullscreen-video.css"
        rel="stylesheet" type="text/css"/>
  <script type="application/javascript"><![CDATA[

var contentVideo = window.arguments[0];
var isPaused = window.arguments[1];
var video;
var closeIcon;

var title = (contentVideo.currentSrc || contentVideo.src).replace(/^.*\//, "");
try {
  title = decodeURI(title);
} catch (e) {}
document.title = title;

window.addEventListener("focus", onFocus, false);
window.addEventListener("unload", onUnload, false);
window.addEventListener("keypress", onKeyPress, false);

function onFocus() {
  window.removeEventListener("focus", onFocus, false);

  window.fullScreen = true;

  window.addEventListener("deactivate", autoClose, false);

  video = document.querySelector("video");
  closeIcon = document.querySelector("div");

  video.addEventListener("loadeddata", onLoadedData, false);

  // Automatically close this window when the playback ended, unless the user
  // interacted with it.
  video.addEventListener("ended", autoClose, false);
  window.addEventListener("click", cancelAutoClose, false);
  window.addEventListener("keypress", cancelAutoClose, false);

  video.addEventListener("playing", hideUI, false);
  video.addEventListener("seeked", hideUI, false);
  video.addEventListener("seeking", showUI, false);
  video.addEventListener("pause", showUI, false);
  video.addEventListener("ended", showUI, false);

  window.addEventListener("mousemove", onMouseMove, false);

  video.mozLoadFrom(contentVideo);
}

function onLoadedData() {
  video.removeEventListener("loadeddata", onLoadedData, false);
  video.volume = contentVideo.volume;
  video.muted = contentVideo.muted;
  video.poster = contentVideo.poster;

  if (contentVideo.currentTime && !contentVideo.ended) {
    video.addEventListener("seeked", playbackStarts, false);

    video.currentTime = contentVideo.currentTime;
  } else {
    playbackStarts();
  }

  video.controls = true;

  if (!isPaused)
    video.play();
}

function onMouseMove() {
  showUI();
  resetIdleTimer();
}

function onUnload() {
  if (video.currentSrc) {
    contentVideo.currentTime = video.currentTime;
    contentVideo.volume = video.volume;
    contentVideo.muted = video.muted;
    if (!video.paused && !video.ended) {
      video.pause();
      contentVideo.play();
    }
  }
}

function onKeyPress(event) {
  if (event.keyCode == event.DOM_VK_ESCAPE) {
    window.close();
    return;
  }

  resetIdleTimer();

  if (!video.controls &&
      String.fromCharCode(event.charCode) == " ")
    video.pause();
}

function playbackStarts() {
  video.removeEventListener("seeked", playbackStarts, false);

  // Loading the data from the content video may take a second or two. We hide
  // the video during that period.
  document.body.style.visibility = "visible";
  video.focus();
}

function autoClose() {
  window.close();
}

function cancelAutoClose() {
  video.removeEventListener("ended", autoClose, false);
  window.removeEventListener("click", cancelAutoClose, false);
  window.removeEventListener("keypress", cancelAutoClose, false);
}

var idleTimer = 0;
function resetIdleTimer() {
  clearTimeout(idleTimer);
  idleTimer = setTimeout(hideUI, 2000);
}

function showUI() {
  if (!video.controls) {
    window.setCursor("auto");
    closeIcon.style.visibility = "visible";
    video.controls = true;
  }
}

function hideUI() {
  if (!video.paused && !video.ended && !video.seeking && !video.error) {
    window.setCursor("none");
    closeIcon.style.visibility = "hidden";
    video.controls = false;
  }
}

  ]]></script>
</head>
<body>
  <div onclick="window.close();"/>
  <video/>
</body>
</html>