15c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)/*
2f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles) * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
35c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
45c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * Redistribution and use in source and binary forms, with or without
55c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * modification, are permitted provided that the following conditions
65c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * are met:
75c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 1. Redistributions of source code must retain the above copyright
85c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer.
95c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * 2. Redistributions in binary form must reproduce the above copyright
105c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    notice, this list of conditions and the following disclaimer in the
115c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *    documentation and/or other materials provided with the distribution.
125c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) *
135c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
145c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
155c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
165c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
175c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
185c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
195c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
205c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
215c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
225c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
245c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles) */
255c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
26f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#ifndef PlainTextRange_h
27f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#define PlainTextRange_h
285c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
29a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch#include "platform/heap/Handle.h"
30f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#include "wtf/NotFound.h"
317757ec2eadfa2dd8ac2aeed0a4399e9b07ec38cbBen Murdoch#include "wtf/PassRefPtr.h"
325c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
33c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)namespace blink {
345c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
35f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)class ContainerNode;
36f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)class Range;
375c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
38f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)class PlainTextRange {
395c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)public:
40f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    PlainTextRange();
41f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    PlainTextRange(const PlainTextRange&);
42f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    explicit PlainTextRange(int location);
43f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    PlainTextRange(int start, int end);
445c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
45f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    size_t end() const { ASSERT(!isNull()); return m_end; }
46f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    size_t start() const { ASSERT(!isNull()); return m_start; }
47f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isNull() const { return m_start == kNotFound; }
48f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    bool isNotNull() const { return m_start != kNotFound; }
49f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    size_t length() const { ASSERT(!isNull()); return m_end - m_start; }
505c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
51a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    PassRefPtrWillBeRawPtr<Range> createRange(const ContainerNode& scope) const;
52a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    PassRefPtrWillBeRawPtr<Range> createRangeForSelection(const ContainerNode& scope) const;
5302772c6a72f1ee0b226341a4f4439970c29fc861Ben Murdoch
54c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)    static PlainTextRange create(const ContainerNode& scope, const Range&);
555c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
56f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)private:
57f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    PlainTextRange& operator=(const PlainTextRange&)  WTF_DELETED_FUNCTION;
58f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)
59197021e6b966cfb06891637935ef33fff06433d1Ben Murdoch    enum GetRangeFor { ForGeneric, ForSelection };
60a9984bf9ddc3cf73fdae3f29134a2bab379e7029Ben Murdoch    PassRefPtrWillBeRawPtr<Range> createRangeFor(const ContainerNode& scope, GetRangeFor) const;
615c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
62f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    const size_t m_start;
63f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)    const size_t m_end;
645c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)};
655c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
66c1847b1379d12d0e05df27436bf19a9b1bf12deaTorne (Richard Coles)} // namespace blink
675c87bf8b86a7c82ef50fb7a89697d8e02e2553beTorne (Richard Coles)
68f79f16f17ddc4f842d7b7a38603e280e94be826aTorne (Richard Coles)#endif // PlainTextRange_h
69