netwerk/base/src/nsMediaFragmentURIParser.h

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
michael@0 2 /* vim:set ts=2 sw=2 sts=2 et cindent: */
michael@0 3 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6 #if !defined(nsMediaFragmentURIParser_h__)
michael@0 7 #define nsMediaFragmentURIParser_h__
michael@0 8
michael@0 9 #include "mozilla/Maybe.h"
michael@0 10 #include "nsStringFwd.h"
michael@0 11 #include "nsRect.h"
michael@0 12
michael@0 13 class nsIURI;
michael@0 14
michael@0 15 // Class to handle parsing of a W3C media fragment URI as per
michael@0 16 // spec at: http://www.w3.org/TR/media-frags/
michael@0 17 // Only the temporaral URI portion of the spec is implemented.
michael@0 18 // To use:
michael@0 19 // a) Construct an instance with the URI containing the fragment
michael@0 20 // b) Check for the validity of the values you are interested in
michael@0 21 // using e.g. HasStartTime().
michael@0 22 // c) If the values are valid, obtain them using e.g. GetStartTime().
michael@0 23
michael@0 24 namespace mozilla { namespace net {
michael@0 25
michael@0 26 enum ClipUnit
michael@0 27 {
michael@0 28 eClipUnit_Pixel,
michael@0 29 eClipUnit_Percent,
michael@0 30 };
michael@0 31
michael@0 32 class nsMediaFragmentURIParser
michael@0 33 {
michael@0 34 public:
michael@0 35 // Create a parser with the provided URI.
michael@0 36 nsMediaFragmentURIParser(nsIURI* aURI);
michael@0 37
michael@0 38 // Create a parser with the provided URI reference portion.
michael@0 39 nsMediaFragmentURIParser(nsCString& aRef);
michael@0 40
michael@0 41 // True if a valid temporal media fragment indicated a start time.
michael@0 42 bool HasStartTime() const { return !mStart.empty(); }
michael@0 43
michael@0 44 // If a valid temporal media fragment indicated a start time, returns
michael@0 45 // it in units of seconds. If not, defaults to 0.
michael@0 46 double GetStartTime() const { return mStart.ref(); }
michael@0 47
michael@0 48 // True if a valid temporal media fragment indicated an end time.
michael@0 49 bool HasEndTime() const { return !mEnd.empty(); }
michael@0 50
michael@0 51 // If a valid temporal media fragment indicated an end time, returns
michael@0 52 // it in units of seconds. If not, defaults to -1.
michael@0 53 double GetEndTime() const { return mEnd.ref(); }
michael@0 54
michael@0 55 // True if a valid spatial media fragment indicated a clipping region.
michael@0 56 bool HasClip() const { return !mClip.empty(); }
michael@0 57
michael@0 58 // True if a valid spatial media fragment indicated a resolution.
michael@0 59 bool HasResolution() const { return !mResolution.empty(); }
michael@0 60
michael@0 61 // True if a valid spatial media fragment indicated a resolution.
michael@0 62 nsIntSize GetResolution() const { return mResolution.ref(); }
michael@0 63
michael@0 64 // If a valid spatial media fragment indicated a clipping region,
michael@0 65 // returns the region. If not, returns an empty region. The unit
michael@0 66 // used depends on the value returned by GetClipUnit().
michael@0 67 nsIntRect GetClip() const { return mClip.ref(); }
michael@0 68
michael@0 69 // If a valid spatial media fragment indicated a clipping region,
michael@0 70 // returns the unit used.
michael@0 71 ClipUnit GetClipUnit() const { return mClipUnit; }
michael@0 72
michael@0 73 bool HasSampleSize() const { return !mSampleSize.empty(); }
michael@0 74
michael@0 75 int GetSampleSize() const { return mSampleSize.ref(); }
michael@0 76
michael@0 77 private:
michael@0 78 // Parse the URI ref provided, looking for media fragments. This is
michael@0 79 // the top-level parser the invokes the others below.
michael@0 80 void Parse(nsACString& aRef);
michael@0 81
michael@0 82 // The following methods parse the fragment as per the media
michael@0 83 // fragments specification. 'aString' contains the remaining
michael@0 84 // fragment data to be parsed. The method returns true
michael@0 85 // if the parse was successful and leaves the remaining unparsed
michael@0 86 // data in 'aString'. If the parse fails then false is returned
michael@0 87 // and 'aString' is left as it was when called.
michael@0 88 bool ParseNPT(nsDependentSubstring aString);
michael@0 89 bool ParseNPTTime(nsDependentSubstring& aString, double& aTime);
michael@0 90 bool ParseNPTSec(nsDependentSubstring& aString, double& aSec);
michael@0 91 bool ParseNPTFraction(nsDependentSubstring& aString, double& aFraction);
michael@0 92 bool ParseNPTMMSS(nsDependentSubstring& aString, double& aTime);
michael@0 93 bool ParseNPTHHMMSS(nsDependentSubstring& aString, double& aTime);
michael@0 94 bool ParseNPTHH(nsDependentSubstring& aString, uint32_t& aHour);
michael@0 95 bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute);
michael@0 96 bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond);
michael@0 97 bool ParseXYWH(nsDependentSubstring aString);
michael@0 98 bool ParseMozResolution(nsDependentSubstring aString);
michael@0 99 bool ParseMozSampleSize(nsDependentSubstring aString);
michael@0 100
michael@0 101 // Media fragment information.
michael@0 102 Maybe<double> mStart;
michael@0 103 Maybe<double> mEnd;
michael@0 104 Maybe<nsIntRect> mClip;
michael@0 105 ClipUnit mClipUnit;
michael@0 106 Maybe<nsIntSize> mResolution;
michael@0 107 Maybe<int> mSampleSize;
michael@0 108 };
michael@0 109
michael@0 110 }} // namespace mozilla::net
michael@0 111
michael@0 112 #endif

mercurial