summaryrefslogtreecommitdiffstats
path: root/WebCore/html/TimeRanges.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'WebCore/html/TimeRanges.cpp')
-rw-r--r--WebCore/html/TimeRanges.cpp22
1 files changed, 21 insertions, 1 deletions
diff --git a/WebCore/html/TimeRanges.cpp b/WebCore/html/TimeRanges.cpp
index e5b070d..1e18306 100644
--- a/WebCore/html/TimeRanges.cpp
+++ b/WebCore/html/TimeRanges.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
+ * Copyright (C) 2007, 2009, 2010 Apple Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -27,6 +27,8 @@
#include "TimeRanges.h"
+#include <math.h>
+
using namespace WebCore;
TimeRanges::TimeRanges(float start, float end)
@@ -115,3 +117,21 @@ bool TimeRanges::contain(float time) const
}
return false;
}
+
+float TimeRanges::nearest(float time) const
+{
+ ExceptionCode unused;
+ float closest = 0;
+ unsigned count = length();
+ for (unsigned ndx = 0; ndx < count; ndx++) {
+ float startTime = start(ndx, unused);
+ float endTime = end(ndx, unused);
+ if (time >= startTime && time <= endTime)
+ return time;
+ if (fabs(startTime - time) < closest)
+ closest = fabsf(startTime - time);
+ else if (fabs(endTime - time) < closest)
+ closest = fabsf(endTime - time);
+ }
+ return closest;
+}