File indexing completed on 2024-05-05 16:10:20

0001 /*
0002  * Copyright (C) 2007 Apple Inc.  All rights reserved.
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  * 1. Redistributions of source code must retain the above copyright
0008  *    notice, this list of conditions and the following disclaimer.
0009  * 2. Redistributions in binary form must reproduce the above copyright
0010  *    notice, this list of conditions and the following disclaimer in the
0011  *    documentation and/or other materials provided with the distribution.
0012  *
0013  * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
0014  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0015  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0016  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
0017  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0018  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0019  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
0020  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
0021  * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0022  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0023  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0024  */
0025 
0026 #include "TimeRanges.h"
0027 
0028 using namespace khtml;
0029 using namespace DOM;
0030 
0031 TimeRanges::TimeRanges(float start, float end)
0032     : RefCounted<TimeRanges>(0)
0033 {
0034     add(start, end);
0035 }
0036 
0037 float TimeRanges::start(unsigned index, ExceptionCode &ec) const
0038 {
0039     if (index >= length()) {
0040         ec = DOMException::INDEX_SIZE_ERR;
0041         return 0;
0042     }
0043     return m_ranges[index].m_start;
0044 }
0045 
0046 float TimeRanges::end(unsigned index, ExceptionCode &ec) const
0047 {
0048     if (index >= length()) {
0049         ec = DOMException::INDEX_SIZE_ERR;
0050         return 0;
0051     }
0052     return m_ranges[index].m_end;
0053 }
0054 
0055 void TimeRanges::add(float start, float end)
0056 {
0057     m_ranges.append(Range(start, end));
0058     // FIXME normalize
0059 }
0060 
0061 bool TimeRanges::contain(float time) const
0062 {
0063     ExceptionCode unused;
0064     for (unsigned n = 0; n < length(); n++) {
0065         if (time >= start(n, unused) && time <= end(n, unused)) {
0066             return true;
0067         }
0068     }
0069     return false;
0070 }