Merge m-c to inbound.
[gecko.git] / widget / TextRange.h
blob77e3cbd3bc1bfb51afdbd8928d6ce059e53351fb
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* This Source Code Form is subject to the terms of the Mozilla Public
3 * License, v. 2.0. If a copy of the MPL was not distributed with this
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 #ifndef mozilla_TextRage_h_
7 #define mozilla_TextRage_h_
9 #include <stdint.h>
11 #include "nsColor.h"
12 #include "nsStyleConsts.h"
14 namespace mozilla {
16 /******************************************************************************
17 * mozilla::TextRangeStyle
18 ******************************************************************************/
20 struct TextRangeStyle
22 enum
24 LINESTYLE_NONE = NS_STYLE_TEXT_DECORATION_STYLE_NONE,
25 LINESTYLE_SOLID = NS_STYLE_TEXT_DECORATION_STYLE_SOLID,
26 LINESTYLE_DOTTED = NS_STYLE_TEXT_DECORATION_STYLE_DOTTED,
27 LINESTYLE_DASHED = NS_STYLE_TEXT_DECORATION_STYLE_DASHED,
28 LINESTYLE_DOUBLE = NS_STYLE_TEXT_DECORATION_STYLE_DOUBLE,
29 LINESTYLE_WAVY = NS_STYLE_TEXT_DECORATION_STYLE_WAVY
32 enum
34 DEFINED_NONE = 0x00,
35 DEFINED_LINESTYLE = 0x01,
36 DEFINED_FOREGROUND_COLOR = 0x02,
37 DEFINED_BACKGROUND_COLOR = 0x04,
38 DEFINED_UNDERLINE_COLOR = 0x08
41 // Initialize all members, because TextRange instances may be compared by
42 // memcomp.
43 TextRangeStyle()
45 Clear();
48 void Clear()
50 mDefinedStyles = DEFINED_NONE;
51 mLineStyle = LINESTYLE_NONE;
52 mIsBoldLine = false;
53 mForegroundColor = mBackgroundColor = mUnderlineColor = NS_RGBA(0, 0, 0, 0);
56 bool IsDefined() const { return mDefinedStyles != DEFINED_NONE; }
58 bool IsLineStyleDefined() const
60 return (mDefinedStyles & DEFINED_LINESTYLE) != 0;
63 bool IsForegroundColorDefined() const
65 return (mDefinedStyles & DEFINED_FOREGROUND_COLOR) != 0;
68 bool IsBackgroundColorDefined() const
70 return (mDefinedStyles & DEFINED_BACKGROUND_COLOR) != 0;
73 bool IsUnderlineColorDefined() const
75 return (mDefinedStyles & DEFINED_UNDERLINE_COLOR) != 0;
78 bool IsNoChangeStyle() const
80 return !IsForegroundColorDefined() && !IsBackgroundColorDefined() &&
81 IsLineStyleDefined() && mLineStyle == LINESTYLE_NONE;
84 bool Equals(const TextRangeStyle& aOther)
86 if (mDefinedStyles != aOther.mDefinedStyles)
87 return false;
88 if (IsLineStyleDefined() && (mLineStyle != aOther.mLineStyle ||
89 !mIsBoldLine != !aOther.mIsBoldLine))
90 return false;
91 if (IsForegroundColorDefined() &&
92 (mForegroundColor != aOther.mForegroundColor))
93 return false;
94 if (IsBackgroundColorDefined() &&
95 (mBackgroundColor != aOther.mBackgroundColor))
96 return false;
97 if (IsUnderlineColorDefined() &&
98 (mUnderlineColor != aOther.mUnderlineColor))
99 return false;
100 return true;
103 bool operator !=(const TextRangeStyle &aOther)
105 return !Equals(aOther);
108 bool operator ==(const TextRangeStyle &aOther)
110 return Equals(aOther);
113 uint8_t mDefinedStyles;
114 uint8_t mLineStyle; // DEFINED_LINESTYLE
116 bool mIsBoldLine; // DEFINED_LINESTYLE
118 nscolor mForegroundColor; // DEFINED_FOREGROUND_COLOR
119 nscolor mBackgroundColor; // DEFINED_BACKGROUND_COLOR
120 nscolor mUnderlineColor; // DEFINED_UNDERLINE_COLOR
123 /******************************************************************************
124 * mozilla::TextRange
125 ******************************************************************************/
127 // Sync with nsIPrivateTextRange.h when you change these constants.
128 #define NS_TEXTRANGE_CARETPOSITION 0x01
129 #define NS_TEXTRANGE_RAWINPUT 0x02
130 #define NS_TEXTRANGE_SELECTEDRAWTEXT 0x03
131 #define NS_TEXTRANGE_CONVERTEDTEXT 0x04
132 #define NS_TEXTRANGE_SELECTEDCONVERTEDTEXT 0x05
134 struct TextRange
136 TextRange() :
137 mStartOffset(0), mEndOffset(0), mRangeType(0)
141 uint32_t mStartOffset;
142 // XXX Storing end offset makes the initializing code very complicated.
143 // We should replace it with mLength.
144 uint32_t mEndOffset;
145 uint32_t mRangeType;
147 TextRangeStyle mRangeStyle;
149 uint32_t Length() const { return mEndOffset - mStartOffset; }
152 /******************************************************************************
153 * mozilla::TextRangeArray
155 * XXX This should be replaced with nsTArray<TextRange>.
156 ******************************************************************************/
158 typedef TextRange* TextRangeArray;
160 } // namespace mozilla
162 #endif // mozilla_TextRage_h_