htmlediting.h 8.7 KB
Newer Older
kocienda's avatar
kocienda committed
1
/*
2
 * Copyright (C) 2004, 2006, 2008 Apple Inc. All rights reserved.
kocienda's avatar
kocienda committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 * 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.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``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 COMPUTER, INC. OR
 * 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. 
 */

darin's avatar
darin committed
26 27 28
#ifndef htmlediting_h
#define htmlediting_h

29
#include "EditingBoundary.h"
30
#include "ExceptionCode.h"
31
#include "HTMLNames.h"
32
#include "Position.h"
33
#include "TextDirection.h"
34
#include <wtf/Forward.h>
35
#include <wtf/unicode/CharacterNames.h>
kocienda's avatar
kocienda committed
36

darin's avatar
darin committed
37
namespace WebCore {
kocienda's avatar
kocienda committed
38

darin's avatar
darin committed
39 40
class Document;
class Element;
41
class HTMLElement;
darin's avatar
darin committed
42
class Node;
darin's avatar
darin committed
43
class Position;
44
class Range;
harrison's avatar
harrison committed
45
class VisiblePosition;
46
class VisibleSelection;
justing's avatar
justing committed
47

48 49 50 51 52 53 54 55 56 57 58

// This file contains a set of helper functions used by the editing commands

// -------------------------------------------------------------------------
// Node
// -------------------------------------------------------------------------

// Functions returning Node

Node* highestAncestor(Node*);
Node* highestEditableRoot(const Position&);
59
Node* highestEnclosingNodeOfType(const Position&, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
60 61
Node* lowestEditableAncestor(Node*);   

62
Node* enclosingBlock(Node*, EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
63 64 65 66
Node* enclosingTableCell(const Position&);
Node* enclosingEmptyListItem(const VisiblePosition&);
Node* enclosingAnchorElement(const Position&);
Node* enclosingNodeWithTag(const Position&, const QualifiedName&);
67
Node* enclosingNodeOfType(const Position&, bool (*nodeIsOfType)(const Node*), EditingBoundaryCrossingRule = CannotCrossEditingBoundary);
68 69 70 71 72 73 74

Node* tabSpanNode(const Node*);
Node* isLastPositionBeforeTable(const VisiblePosition&);
Node* isFirstPositionAfterTable(const VisiblePosition&);

// offset functions on Node

eric@webkit.org's avatar
eric@webkit.org committed
75
int lastOffsetForEditing(const Node*);
76 77 78 79 80
int caretMinOffset(const Node*);
int caretMaxOffset(const Node*);

// boolean functions on Node

81 82
bool editingIgnoresContent(const Node*);
bool canHaveChildrenForEditing(const Node*);
83 84 85 86 87 88 89 90
bool isAtomicNode(const Node*);
bool isBlock(const Node*);
bool isSpecialElement(const Node*);
bool isTabSpanNode(const Node*);
bool isTabSpanTextNode(const Node*);
bool isMailBlockquote(const Node*);
bool isTableElement(Node*);
bool isTableCell(const Node*);
91
bool isEmptyTableCell(const Node*);
92 93
bool isTableStructureNode(const Node*);
bool isListElement(Node*);
94
bool isListItem(Node*);
95 96
bool isNodeRendered(const Node*);
bool isNodeVisiblyContainedWithin(Node*, const Range*);
justin.garcia@apple.com's avatar
justin.garcia@apple.com committed
97
bool isRenderedAsNonInlineTableImageOrHR(const Node*);
98
bool isNodeInTextFormControl(Node* node);
99
    
100 101
TextDirection directionOfEnclosingBlock(const Position&);

102 103 104 105 106 107
// -------------------------------------------------------------------------
// Position
// -------------------------------------------------------------------------
    
// Functions returning Position
    
justing's avatar
justing committed
108 109
Position nextCandidate(const Position&);
Position previousCandidate(const Position&);
110 111
    
Position nextVisuallyDistinctCandidate(const Position&);
justing's avatar
justing committed
112
Position previousVisuallyDistinctCandidate(const Position&);
113

114
Position positionOutsideTabSpan(const Position&);
115 116 117
Position positionBeforeContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
Position positionAfterContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
Position positionOutsideContainingSpecialElement(const Position&, Node** containingSpecialElement=0);
118 119 120

inline Position firstPositionInOrBeforeNode(Node* node)
{
121 122
    if (!node)
        return Position();
123
    return editingIgnoresContent(node) ? positionBeforeNode(node) : firstPositionInNode(node);
124 125 126 127
}

inline Position lastPositionInOrAfterNode(Node* node)
{
128 129
    if (!node)
        return Position();
130
    return editingIgnoresContent(node) ? positionAfterNode(node) : lastPositionInNode(node);
131 132
}

133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149
// comparision functions on Position
    
int comparePositions(const Position&, const Position&);

// boolean functions on Position
    
bool isEditablePosition(const Position&);
bool isRichlyEditablePosition(const Position&);
bool isFirstVisiblePositionInSpecialElement(const Position&);
bool isLastVisiblePositionInSpecialElement(const Position&);
bool lineBreakExistsAtPosition(const Position&);
bool isVisiblyAdjacent(const Position& first, const Position& second);
bool isAtUnsplittableElement(const Position&);

// miscellaneous functions on Position

unsigned numEnclosingMailBlockquotes(const Position&);
150

151 152 153 154 155 156 157 158
// -------------------------------------------------------------------------
// VisiblePosition
// -------------------------------------------------------------------------
    
// Functions returning VisiblePosition
    
VisiblePosition firstEditablePositionAfterPositionInRoot(const Position&, Node*);
VisiblePosition lastEditablePositionBeforePositionInRoot(const Position&, Node*);
rniwa@webkit.org's avatar
rniwa@webkit.org committed
159 160
VisiblePosition visiblePositionBeforeNode(Node*);
VisiblePosition visiblePositionAfterNode(Node*);
161 162 163 164 165 166 167 168 169 170 171 172

bool lineBreakExistsAtVisiblePosition(const VisiblePosition&);
    
int comparePositions(const VisiblePosition&, const VisiblePosition&);
int indexForVisiblePosition(const VisiblePosition&);

// -------------------------------------------------------------------------
// Range
// -------------------------------------------------------------------------

// Functions returning Range

173 174
PassRefPtr<Range> createRange(PassRefPtr<Document>, const VisiblePosition& start, const VisiblePosition& end, ExceptionCode&);
PassRefPtr<Range> extendRangeToWrappingNodes(PassRefPtr<Range> rangeToExtend, const Range* maximumRange, const Node* rootNode);
175
PassRefPtr<Range> avoidIntersectionWithNode(const Range*, Node*);
176

177 178 179 180 181 182
// -------------------------------------------------------------------------
// HTMLElement
// -------------------------------------------------------------------------
    
// Functions returning HTMLElement
    
183 184 185 186 187
PassRefPtr<HTMLElement> createDefaultParagraphElement(Document*);
PassRefPtr<HTMLElement> createBreakElement(Document*);
PassRefPtr<HTMLElement> createOrderedListElement(Document*);
PassRefPtr<HTMLElement> createUnorderedListElement(Document*);
PassRefPtr<HTMLElement> createListItemElement(Document*);
eric@webkit.org's avatar
eric@webkit.org committed
188
PassRefPtr<HTMLElement> createHTMLElement(Document*, const QualifiedName&);
189
PassRefPtr<HTMLElement> createHTMLElement(Document*, const AtomicString&);
darin's avatar
darin committed
190

191
HTMLElement* enclosingList(Node*);
192
HTMLElement* outermostEnclosingList(Node*, Node* rootList = 0);
193
Node* enclosingListChild(Node*);
194 195 196 197 198 199 200

// -------------------------------------------------------------------------
// Element
// -------------------------------------------------------------------------
    
// Functions returning Element
    
darin's avatar
darin committed
201 202 203 204
PassRefPtr<Element> createTabSpanElement(Document*);
PassRefPtr<Element> createTabSpanElement(Document*, PassRefPtr<Node> tabTextNode);
PassRefPtr<Element> createTabSpanElement(Document*, const String& tabText);
PassRefPtr<Element> createBlockPlaceholderElement(Document*);
mjs's avatar
mjs committed
205

206 207
Element* editableRootForPosition(const Position&);
Element* unsplittableElementForPosition(const Position&);
harrison's avatar
harrison committed
208

209 210
// Boolean functions on Element
    
bfulgham@webkit.org's avatar
bfulgham@webkit.org committed
211
bool canMergeLists(Element* firstList, Element* secondList);
212 213 214 215
    
// -------------------------------------------------------------------------
// VisibleSelection
// -------------------------------------------------------------------------
justing's avatar
justing committed
216

217
// Functions returning VisibleSelection
218
VisibleSelection avoidIntersectionWithNode(const VisibleSelection&, Node*);
219
VisibleSelection selectionForParagraphIteration(const VisibleSelection&);
220 221
    

222 223 224 225 226
// Miscellaneous functions on Text
inline bool isWhitespace(UChar c)
{
    return c == noBreakSpace || c == ' ' || c == '\n' || c == '\t';
}
227
String stringWithRebalancedWhitespace(const String&, bool startIsStartOfParagraph, bool endIsEndOfParagraph);
228
const String& nonBreakingSpaceString();
justin.garcia@apple.com's avatar
justin.garcia@apple.com committed
229

darin's avatar
darin committed
230
}
kocienda's avatar
kocienda committed
231 232

#endif