DOMSelection.h 4.3 KB
Newer Older
weinig's avatar
weinig committed
1 2
/*
 * Copyright (C) 2007 Apple Inc.  All rights reserved.
3
 * Copyright (C) 2012 Google Inc.  All rights reserved.
weinig's avatar
weinig committed
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1.  Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer. 
 * 2.  Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in the
 *     documentation and/or other materials provided with the distribution. 
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */


#ifndef DOMSelection_h
#define DOMSelection_h

34
#include "DOMWindowProperty.h"
weinig's avatar
weinig committed
35 36
#include <wtf/Forward.h>
#include <wtf/PassRefPtr.h>
37
#include <wtf/RefCounted.h>
weinig's avatar
weinig committed
38 39 40 41

namespace WebCore {

    class Frame;
42
    class Node;
43
    class Position;
44 45
    class Range;
    class TreeScope;
eric@webkit.org's avatar
eric@webkit.org committed
46
    class VisibleSelection;
weinig's avatar
weinig committed
47 48 49

    typedef int ExceptionCode;

50
    class DOMSelection : public RefCounted<DOMSelection>, public DOMWindowProperty {
weinig's avatar
weinig committed
51
    public:
52 53 54
        static PassRefPtr<DOMSelection> create(const TreeScope* treeScope) { return adoptRef(new DOMSelection(treeScope)); }

        void clearTreeScope();
weinig's avatar
weinig committed
55

eric@webkit.org's avatar
eric@webkit.org committed
56
        // Safari Selection Object API
ap@webkit.org's avatar
ap@webkit.org committed
57
        // These methods return the valid equivalents of internal editing positions.
weinig's avatar
weinig committed
58
        Node* baseNode() const;
ap@webkit.org's avatar
ap@webkit.org committed
59
        Node* extentNode() const;
weinig's avatar
weinig committed
60
        int baseOffset() const;
ap@webkit.org's avatar
ap@webkit.org committed
61 62 63 64 65 66
        int extentOffset() const;
        String type() const;
        void setBaseAndExtent(Node* baseNode, int baseOffset, Node* extentNode, int extentOffset, ExceptionCode&);
        void setPosition(Node*, int offset, ExceptionCode&);
        void modify(const String& alter, const String& direction, const String& granularity);

eric@webkit.org's avatar
eric@webkit.org committed
67
        // Mozilla Selection Object API
ap@webkit.org's avatar
ap@webkit.org committed
68 69 70 71 72 73 74
        // In Firefox, anchor/focus are the equal to the start/end of the selection,
        // but reflect the direction in which the selection was made by the user.  That does
        // not mean that they are base/extent, since the base/extent don't reflect
        // expansion.
        // These methods return the valid equivalents of internal editing positions.
        Node* anchorNode() const;
        int anchorOffset() const;
weinig's avatar
weinig committed
75 76 77 78 79
        Node* focusNode() const;
        int focusOffset() const;
        bool isCollapsed() const;
        int rangeCount() const;
        void collapse(Node*, int offset, ExceptionCode&);
80 81
        void collapseToEnd(ExceptionCode&);
        void collapseToStart(ExceptionCode&);
ap@webkit.org's avatar
ap@webkit.org committed
82
        void extend(Node*, int offset, ExceptionCode&);
weinig's avatar
weinig committed
83 84 85
        PassRefPtr<Range> getRangeAt(int, ExceptionCode&);
        void removeAllRanges();
        void addRange(Range*);
ap@webkit.org's avatar
ap@webkit.org committed
86
        void deleteFromDocument();
87
        bool containsNode(Node*, bool partlyContained) const;
ap@webkit.org's avatar
ap@webkit.org committed
88
        void selectAllChildren(Node*, ExceptionCode&);
weinig's avatar
weinig committed
89 90 91

        String toString();

eric@webkit.org's avatar
eric@webkit.org committed
92
        // Microsoft Selection Object API
ap@webkit.org's avatar
ap@webkit.org committed
93 94
        void empty();

weinig's avatar
weinig committed
95
    private:
96 97 98
        const TreeScope* m_treeScope;

        explicit DOMSelection(const TreeScope*);
eric@webkit.org's avatar
eric@webkit.org committed
99 100 101 102

        // Convenience method for accessors, does not NULL check m_frame.
        const VisibleSelection& visibleSelection() const;

103 104 105
        Node* shadowAdjustedNode(const Position&) const;
        int shadowAdjustedOffset(const Position&) const;

106
        bool isValidForPosition(Node*) const;
weinig's avatar
weinig committed
107 108 109 110 111
    };

} // namespace WebCore

#endif // DOMSelection_h