netwerk/base/src/nsMediaFragmentURIParser.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/netwerk/base/src/nsMediaFragmentURIParser.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,112 @@
     1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim:set ts=2 sw=2 sts=2 et cindent: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +#if !defined(nsMediaFragmentURIParser_h__)
    1.10 +#define nsMediaFragmentURIParser_h__
    1.11 +
    1.12 +#include "mozilla/Maybe.h"
    1.13 +#include "nsStringFwd.h"
    1.14 +#include "nsRect.h"
    1.15 +
    1.16 +class nsIURI;
    1.17 +
    1.18 +// Class to handle parsing of a W3C media fragment URI as per
    1.19 +// spec at: http://www.w3.org/TR/media-frags/
    1.20 +// Only the temporaral URI portion of the spec is implemented.
    1.21 +// To use:
    1.22 +// a) Construct an instance with the URI containing the fragment
    1.23 +// b) Check for the validity of the values you are interested in
    1.24 +//    using e.g. HasStartTime().
    1.25 +// c) If the values are valid, obtain them using e.g. GetStartTime().
    1.26 +
    1.27 +namespace mozilla { namespace net {
    1.28 +
    1.29 +enum ClipUnit
    1.30 +{
    1.31 +  eClipUnit_Pixel,
    1.32 +  eClipUnit_Percent,
    1.33 +};
    1.34 +
    1.35 +class nsMediaFragmentURIParser
    1.36 +{
    1.37 +public:
    1.38 +  // Create a parser with the provided URI.
    1.39 +  nsMediaFragmentURIParser(nsIURI* aURI);
    1.40 +
    1.41 +  // Create a parser with the provided URI reference portion.
    1.42 +  nsMediaFragmentURIParser(nsCString& aRef);
    1.43 +
    1.44 +  // True if a valid temporal media fragment indicated a start time.
    1.45 +  bool HasStartTime() const { return !mStart.empty(); }
    1.46 +
    1.47 +  // If a valid temporal media fragment indicated a start time, returns
    1.48 +  // it in units of seconds. If not, defaults to 0.
    1.49 +  double GetStartTime() const { return mStart.ref(); }
    1.50 +
    1.51 +  // True if a valid temporal media fragment indicated an end time.
    1.52 +  bool HasEndTime() const { return !mEnd.empty(); }
    1.53 +
    1.54 +  // If a valid temporal media fragment indicated an end time, returns
    1.55 +  // it in units of seconds. If not, defaults to -1.
    1.56 +  double GetEndTime() const { return mEnd.ref(); }
    1.57 +
    1.58 +  // True if a valid spatial media fragment indicated a clipping region.
    1.59 +  bool HasClip() const { return !mClip.empty(); }
    1.60 +
    1.61 +  // True if a valid spatial media fragment indicated a resolution.
    1.62 +  bool HasResolution() const { return !mResolution.empty(); }
    1.63 +
    1.64 +  // True if a valid spatial media fragment indicated a resolution.
    1.65 +  nsIntSize GetResolution() const { return mResolution.ref(); }
    1.66 +
    1.67 +  // If a valid spatial media fragment indicated a clipping region,
    1.68 +  // returns the region. If not, returns an empty region. The unit
    1.69 +  // used depends on the value returned by GetClipUnit().
    1.70 +  nsIntRect GetClip() const { return mClip.ref(); }
    1.71 +
    1.72 +  // If a valid spatial media fragment indicated a clipping region,
    1.73 +  // returns the unit used.
    1.74 +  ClipUnit GetClipUnit() const { return mClipUnit; }
    1.75 +
    1.76 +  bool HasSampleSize() const { return !mSampleSize.empty(); }
    1.77 +
    1.78 +  int GetSampleSize() const { return mSampleSize.ref(); }
    1.79 +
    1.80 +private:
    1.81 +  // Parse the URI ref provided, looking for media fragments. This is
    1.82 +  // the top-level parser the invokes the others below.
    1.83 +  void Parse(nsACString& aRef);
    1.84 +
    1.85 +  // The following methods parse the fragment as per the media
    1.86 +  // fragments specification. 'aString' contains the remaining
    1.87 +  // fragment data to be parsed. The method returns true
    1.88 +  // if the parse was successful and leaves the remaining unparsed
    1.89 +  // data in 'aString'. If the parse fails then false is returned
    1.90 +  // and 'aString' is left as it was when called.
    1.91 +  bool ParseNPT(nsDependentSubstring aString);
    1.92 +  bool ParseNPTTime(nsDependentSubstring& aString, double& aTime);
    1.93 +  bool ParseNPTSec(nsDependentSubstring& aString, double& aSec);
    1.94 +  bool ParseNPTFraction(nsDependentSubstring& aString, double& aFraction);
    1.95 +  bool ParseNPTMMSS(nsDependentSubstring& aString, double& aTime);
    1.96 +  bool ParseNPTHHMMSS(nsDependentSubstring& aString, double& aTime);
    1.97 +  bool ParseNPTHH(nsDependentSubstring& aString, uint32_t& aHour);
    1.98 +  bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute);
    1.99 +  bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond);
   1.100 +  bool ParseXYWH(nsDependentSubstring aString);
   1.101 +  bool ParseMozResolution(nsDependentSubstring aString);
   1.102 +  bool ParseMozSampleSize(nsDependentSubstring aString);
   1.103 +
   1.104 +  // Media fragment information.
   1.105 +  Maybe<double>    mStart;
   1.106 +  Maybe<double>    mEnd;
   1.107 +  Maybe<nsIntRect> mClip;
   1.108 +  ClipUnit         mClipUnit;
   1.109 +  Maybe<nsIntSize> mResolution;
   1.110 +  Maybe<int>       mSampleSize;
   1.111 +};
   1.112 +
   1.113 +}} // namespace mozilla::net
   1.114 +
   1.115 +#endif

mercurial