1635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project/*
28f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian * Copyright (C) 2009 Google Inc. All rights reserved.
38f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
4635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * Redistribution and use in source and binary forms, with or without
5635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * modification, are permitted provided that the following conditions are
6635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * met:
78f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
8635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions of source code must retain the above copyright
9635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * notice, this list of conditions and the following disclaimer.
10635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Redistributions in binary form must reproduce the above
11635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * copyright notice, this list of conditions and the following disclaimer
12635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * in the documentation and/or other materials provided with the
13635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * distribution.
14635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project *     * Neither the name of Google Inc. nor the names of its
15635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * contributors may be used to endorse or promote products derived from
16635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * this software without specific prior written permission.
178f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian *
18635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project */
30635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
31643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#ifndef WebRange_h
32643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#define WebRange_h
33635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
34643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#include "WebCommon.h"
35635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
36643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#if WEBKIT_IMPLEMENTATION
37643ca7872b450ea4efacab6188849e5aac2ba161Steve Blocknamespace WebCore { class Range; }
38643ca7872b450ea4efacab6188849e5aac2ba161Steve Blocknamespace WTF { template <typename T> class PassRefPtr; }
39643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#endif
40773979f92560dd1aead375c82fd75b584a141e5dJohn Recknamespace WebCore { class Node; }
41635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
42643ca7872b450ea4efacab6188849e5aac2ba161Steve Blocknamespace WebKit {
438f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
44643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockclass WebRangePrivate;
45643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockclass WebString;
46635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
47643ca7872b450ea4efacab6188849e5aac2ba161Steve Block// Provides readonly access to some properties of a DOM range.
48643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockclass WebRange {
49643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockpublic:
50643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    ~WebRange() { reset(); }
51643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
52643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRange() : m_private(0) { }
53643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRange(const WebRange& r) : m_private(0) { assign(r); }
54643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRange& operator=(const WebRange& r)
55643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    {
56643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        assign(r);
57643ca7872b450ea4efacab6188849e5aac2ba161Steve Block        return *this;
58643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    }
59643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
60643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API void reset();
61643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API void assign(const WebRange&);
62643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
63643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    bool isNull() const { return !m_private; }
64643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
65643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API int startOffset() const;
66643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API int endOffset() const;
67773979f92560dd1aead375c82fd75b584a141e5dJohn Reck    WEBKIT_API WebCore::Node* startContainer(int& exceptionCode) const;
68773979f92560dd1aead375c82fd75b584a141e5dJohn Reck    WEBKIT_API WebCore::Node* endContainer(int& exceptionCode) const;
69643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
70643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API WebString toHTMLText() const;
71643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WEBKIT_API WebString toPlainText() const;
72643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
73643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#if WEBKIT_IMPLEMENTATION
74643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRange(const WTF::PassRefPtr<WebCore::Range>&);
75643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRange& operator=(const WTF::PassRefPtr<WebCore::Range>&);
76643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    operator WTF::PassRefPtr<WebCore::Range>() const;
775f1ab04193ad0130ca8204aadaceae083aca9881Feng Qian#endif
788f72e70a9fd78eec56623b3a62e68f16b7b27e28Feng Qian
79643ca7872b450ea4efacab6188849e5aac2ba161Steve Blockprivate:
80643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    void assign(WebRangePrivate*);
81643ca7872b450ea4efacab6188849e5aac2ba161Steve Block    WebRangePrivate* m_private;
82643ca7872b450ea4efacab6188849e5aac2ba161Steve Block};
83635860845790a19bf50bbc51ba8fb66a96dde068The Android Open Source Project
84643ca7872b450ea4efacab6188849e5aac2ba161Steve Block} // namespace WebKit
85643ca7872b450ea4efacab6188849e5aac2ba161Steve Block
86643ca7872b450ea4efacab6188849e5aac2ba161Steve Block#endif
87