1 | /* |
2 | * Copyright (C) 2010, 2011 Apple Inc. All rights reserved. |
3 | * |
4 | * Redistribution and use in source and binary forms, with or without |
5 | * modification, are permitted provided that the following conditions |
6 | * are met: |
7 | * 1. Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. |
9 | * 2. Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. |
12 | * |
13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' |
14 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, |
15 | * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS |
17 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
18 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
19 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
20 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
21 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
22 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF |
23 | * THE POSSIBILITY OF SUCH DAMAGE. |
24 | */ |
25 | |
26 | #pragma once |
27 | |
28 | #include "ArgumentCoders.h" |
29 | #include <WebCore/Color.h> |
30 | #include <WebCore/FontAttributes.h> |
31 | #include <WebCore/IntRect.h> |
32 | #include <WebCore/WritingDirection.h> |
33 | #include <wtf/text/WTFString.h> |
34 | |
35 | #if PLATFORM(IOS_FAMILY) |
36 | #include <WebCore/SelectionRect.h> |
37 | #endif |
38 | |
39 | namespace WTF { |
40 | class TextStream; |
41 | }; |
42 | |
43 | namespace WebKit { |
44 | |
45 | enum TypingAttributes { |
46 | AttributeNone = 0, |
47 | AttributeBold = 1, |
48 | AttributeItalics = 2, |
49 | AttributeUnderline = 4, |
50 | AttributeStrikeThrough = 8 |
51 | }; |
52 | |
53 | enum TextAlignment { |
54 | NoAlignment = 0, |
55 | LeftAlignment = 1, |
56 | RightAlignment = 2, |
57 | CenterAlignment = 3, |
58 | JustifiedAlignment = 4, |
59 | }; |
60 | |
61 | enum ListType { |
62 | NoList = 0, |
63 | OrderedList, |
64 | UnorderedList |
65 | }; |
66 | |
67 | struct EditorState { |
68 | bool shouldIgnoreSelectionChanges { false }; |
69 | |
70 | bool selectionIsNone { true }; // This will be false when there is a caret selection. |
71 | bool selectionIsRange { false }; |
72 | bool isContentEditable { false }; |
73 | bool isContentRichlyEditable { false }; |
74 | bool isInPasswordField { false }; |
75 | bool isInPlugin { false }; |
76 | bool hasComposition { false }; |
77 | bool isMissingPostLayoutData { false }; |
78 | |
79 | #if PLATFORM(IOS_FAMILY) |
80 | WebCore::IntRect firstMarkedRect; |
81 | WebCore::IntRect lastMarkedRect; |
82 | String markedText; |
83 | #endif |
84 | |
85 | String originIdentifierForPasteboard; |
86 | |
87 | struct PostLayoutData { |
88 | uint32_t typingAttributes { AttributeNone }; |
89 | #if PLATFORM(IOS_FAMILY) || PLATFORM(GTK) |
90 | WebCore::IntRect caretRectAtStart; |
91 | #endif |
92 | #if PLATFORM(COCOA) |
93 | WebCore::IntRect focusedElementRect; |
94 | uint64_t selectedTextLength { 0 }; |
95 | uint32_t textAlignment { NoAlignment }; |
96 | WebCore::Color textColor { WebCore::Color::black }; |
97 | uint32_t enclosingListType { NoList }; |
98 | WebCore::WritingDirection baseWritingDirection { WebCore::WritingDirection::Natural }; |
99 | #endif |
100 | #if PLATFORM(IOS_FAMILY) |
101 | WebCore::IntRect caretRectAtEnd; |
102 | Vector<WebCore::SelectionRect> selectionRects; |
103 | String wordAtSelection; |
104 | UChar32 characterAfterSelection { 0 }; |
105 | UChar32 characterBeforeSelection { 0 }; |
106 | UChar32 twoCharacterBeforeSelection { 0 }; |
107 | bool isReplaceAllowed { false }; |
108 | bool hasContent { false }; |
109 | bool isStableStateUpdate { false }; |
110 | bool insideFixedPosition { false }; |
111 | bool hasPlainText { false }; |
112 | bool editableRootIsTransparentOrFullyClipped { false }; |
113 | WebCore::Color caretColor; |
114 | bool atStartOfSentence { false }; |
115 | #endif |
116 | #if PLATFORM(MAC) |
117 | uint64_t candidateRequestStartPosition { 0 }; |
118 | String paragraphContextForCandidateRequest; |
119 | String stringForCandidateRequest; |
120 | #endif |
121 | |
122 | Optional<WebCore::FontAttributes> fontAttributes; |
123 | |
124 | bool canCut { false }; |
125 | bool canCopy { false }; |
126 | bool canPaste { false }; |
127 | |
128 | void encode(IPC::Encoder&) const; |
129 | static bool decode(IPC::Decoder&, PostLayoutData&); |
130 | }; |
131 | |
132 | const PostLayoutData& postLayoutData() const; |
133 | PostLayoutData& postLayoutData(); |
134 | |
135 | void encode(IPC::Encoder&) const; |
136 | static bool decode(IPC::Decoder&, EditorState&); |
137 | |
138 | private: |
139 | PostLayoutData m_postLayoutData; |
140 | }; |
141 | |
142 | inline auto EditorState::postLayoutData() -> PostLayoutData& |
143 | { |
144 | ASSERT_WITH_MESSAGE(!isMissingPostLayoutData, "Attempt to access post layout data before receiving it" ); |
145 | return m_postLayoutData; |
146 | } |
147 | |
148 | inline auto EditorState::postLayoutData() const -> const PostLayoutData& |
149 | { |
150 | ASSERT_WITH_MESSAGE(!isMissingPostLayoutData, "Attempt to access post layout data before receiving it" ); |
151 | return m_postLayoutData; |
152 | } |
153 | |
154 | WTF::TextStream& operator<<(WTF::TextStream&, const EditorState&); |
155 | |
156 | } // namespace WebKit |
157 | |