2012-12-21 05:04:50 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
#if !defined(nsMediaFragmentURIParser_h__)
|
|
|
|
# define nsMediaFragmentURIParser_h__
|
|
|
|
|
2013-08-28 02:10:28 +04:00
|
|
|
# include "mozilla/Maybe.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
# include "nsStringFwd.h"
|
2012-12-21 05:04:50 +04:00
|
|
|
# include "nsRect.h"
|
|
|
|
|
2013-09-22 07:04:57 +04:00
|
|
|
class nsIURI;
|
|
|
|
|
2012-12-21 05:04:50 +04:00
|
|
|
// Class to handle parsing of a W3C media fragment URI as per
|
|
|
|
// spec at: http://www.w3.org/TR/media-frags/
|
|
|
|
// Only the temporaral URI portion of the spec is implemented.
|
|
|
|
// To use:
|
|
|
|
// a) Construct an instance with the URI containing the fragment
|
|
|
|
// b) Check for the validity of the values you are interested in
|
|
|
|
// using e.g. HasStartTime().
|
|
|
|
// c) If the values are valid, obtain them using e.g. GetStartTime().
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
|
|
|
enum ClipUnit {
|
|
|
|
eClipUnit_Pixel,
|
|
|
|
eClipUnit_Percent,
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsMediaFragmentURIParser {
|
|
|
|
public:
|
|
|
|
// Create a parser with the provided URI.
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit nsMediaFragmentURIParser(nsIURI* aURI);
|
2012-12-21 05:04:50 +04:00
|
|
|
|
2013-09-28 22:28:42 +04:00
|
|
|
// Create a parser with the provided URI reference portion.
|
2014-08-05 17:20:24 +04:00
|
|
|
explicit nsMediaFragmentURIParser(nsCString& aRef);
|
2013-09-28 22:28:42 +04:00
|
|
|
|
2012-12-21 05:04:50 +04:00
|
|
|
// True if a valid temporal media fragment indicated a start time.
|
2014-08-14 02:42:16 +04:00
|
|
|
bool HasStartTime() const { return mStart.isSome(); }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// If a valid temporal media fragment indicated a start time, returns
|
|
|
|
// it in units of seconds. If not, defaults to 0.
|
2014-08-14 02:42:16 +04:00
|
|
|
double GetStartTime() const { return *mStart; }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// True if a valid temporal media fragment indicated an end time.
|
2014-08-14 02:42:16 +04:00
|
|
|
bool HasEndTime() const { return mEnd.isSome(); }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// If a valid temporal media fragment indicated an end time, returns
|
|
|
|
// it in units of seconds. If not, defaults to -1.
|
2014-08-14 02:42:16 +04:00
|
|
|
double GetEndTime() const { return *mEnd; }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// True if a valid spatial media fragment indicated a clipping region.
|
2014-08-14 02:42:16 +04:00
|
|
|
bool HasClip() const { return mClip.isSome(); }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// If a valid spatial media fragment indicated a clipping region,
|
|
|
|
// returns the region. If not, returns an empty region. The unit
|
|
|
|
// used depends on the value returned by GetClipUnit().
|
2014-08-14 02:42:16 +04:00
|
|
|
nsIntRect GetClip() const { return *mClip; }
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// If a valid spatial media fragment indicated a clipping region,
|
|
|
|
// returns the unit used.
|
|
|
|
ClipUnit GetClipUnit() const { return mClipUnit; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
// Parse the URI ref provided, looking for media fragments. This is
|
|
|
|
// the top-level parser the invokes the others below.
|
|
|
|
void Parse(nsACString& aRef);
|
|
|
|
|
|
|
|
// The following methods parse the fragment as per the media
|
|
|
|
// fragments specification. 'aString' contains the remaining
|
|
|
|
// fragment data to be parsed. The method returns true
|
|
|
|
// if the parse was successful and leaves the remaining unparsed
|
|
|
|
// data in 'aString'. If the parse fails then false is returned
|
|
|
|
// and 'aString' is left as it was when called.
|
|
|
|
bool ParseNPT(nsDependentSubstring aString);
|
|
|
|
bool ParseNPTTime(nsDependentSubstring& aString, double& aTime);
|
|
|
|
bool ParseNPTSec(nsDependentSubstring& aString, double& aSec);
|
|
|
|
bool ParseNPTFraction(nsDependentSubstring& aString, double& aFraction);
|
|
|
|
bool ParseNPTMMSS(nsDependentSubstring& aString, double& aTime);
|
|
|
|
bool ParseNPTHHMMSS(nsDependentSubstring& aString, double& aTime);
|
|
|
|
bool ParseNPTHH(nsDependentSubstring& aString, uint32_t& aHour);
|
|
|
|
bool ParseNPTMM(nsDependentSubstring& aString, uint32_t& aMinute);
|
|
|
|
bool ParseNPTSS(nsDependentSubstring& aString, uint32_t& aSecond);
|
|
|
|
bool ParseXYWH(nsDependentSubstring aString);
|
2013-03-23 03:12:40 +04:00
|
|
|
bool ParseMozResolution(nsDependentSubstring aString);
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
// Media fragment information.
|
|
|
|
Maybe<double> mStart;
|
|
|
|
Maybe<double> mEnd;
|
|
|
|
Maybe<nsIntRect> mClip;
|
|
|
|
ClipUnit mClipUnit;
|
|
|
|
};
|
|
|
|
|
2015-07-13 18:25:42 +03:00
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|
2012-12-21 05:04:50 +04:00
|
|
|
|
|
|
|
#endif
|