Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- |
michael@0 | 2 | * |
michael@0 | 3 | * This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsBidiPresUtils_h___ |
michael@0 | 8 | #define nsBidiPresUtils_h___ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsBidi.h" |
michael@0 | 11 | #include "nsBidiUtils.h" |
michael@0 | 12 | #include "nsHashKeys.h" |
michael@0 | 13 | #include "nsCoord.h" |
michael@0 | 14 | |
michael@0 | 15 | #ifdef DrawText |
michael@0 | 16 | #undef DrawText |
michael@0 | 17 | #endif |
michael@0 | 18 | |
michael@0 | 19 | struct BidiParagraphData; |
michael@0 | 20 | struct BidiLineData; |
michael@0 | 21 | class nsIFrame; |
michael@0 | 22 | class nsBlockFrame; |
michael@0 | 23 | class nsPresContext; |
michael@0 | 24 | class nsRenderingContext; |
michael@0 | 25 | class nsBlockInFlowLineIterator; |
michael@0 | 26 | class nsStyleContext; |
michael@0 | 27 | template<class T> class nsTHashtable; |
michael@0 | 28 | namespace mozilla { class WritingMode; } |
michael@0 | 29 | |
michael@0 | 30 | /** |
michael@0 | 31 | * A structure representing some continuation state for each frame on the line, |
michael@0 | 32 | * used to determine the first and the last continuation frame for each |
michael@0 | 33 | * continuation chain on the line. |
michael@0 | 34 | */ |
michael@0 | 35 | struct nsFrameContinuationState : public nsVoidPtrHashKey |
michael@0 | 36 | { |
michael@0 | 37 | nsFrameContinuationState(const void *aFrame) : nsVoidPtrHashKey(aFrame) {} |
michael@0 | 38 | |
michael@0 | 39 | /** |
michael@0 | 40 | * The first visual frame in the continuation chain containing this frame, or |
michael@0 | 41 | * nullptr if this frame is the first visual frame in the chain. |
michael@0 | 42 | */ |
michael@0 | 43 | nsIFrame* mFirstVisualFrame; |
michael@0 | 44 | |
michael@0 | 45 | /** |
michael@0 | 46 | * The number of frames in the continuation chain containing this frame, if |
michael@0 | 47 | * this frame is the first visual frame of the chain, or 0 otherwise. |
michael@0 | 48 | */ |
michael@0 | 49 | uint32_t mFrameCount; |
michael@0 | 50 | |
michael@0 | 51 | /** |
michael@0 | 52 | * TRUE if this frame is the first visual frame of its continuation chain on |
michael@0 | 53 | * this line and the chain has some frames on the previous lines. |
michael@0 | 54 | */ |
michael@0 | 55 | bool mHasContOnPrevLines; |
michael@0 | 56 | |
michael@0 | 57 | /** |
michael@0 | 58 | * TRUE if this frame is the first visual frame of its continuation chain on |
michael@0 | 59 | * this line and the chain has some frames left for next lines. |
michael@0 | 60 | */ |
michael@0 | 61 | bool mHasContOnNextLines; |
michael@0 | 62 | }; |
michael@0 | 63 | |
michael@0 | 64 | /* |
michael@0 | 65 | * Following type is used to pass needed hashtable to reordering methods |
michael@0 | 66 | */ |
michael@0 | 67 | typedef nsTHashtable<nsFrameContinuationState> nsContinuationStates; |
michael@0 | 68 | |
michael@0 | 69 | /** |
michael@0 | 70 | * A structure representing a logical position which should be resolved |
michael@0 | 71 | * into its visual position during BiDi processing. |
michael@0 | 72 | */ |
michael@0 | 73 | struct nsBidiPositionResolve |
michael@0 | 74 | { |
michael@0 | 75 | // [in] Logical index within string. |
michael@0 | 76 | int32_t logicalIndex; |
michael@0 | 77 | // [out] Visual index within string. |
michael@0 | 78 | // If the logical position was not found, set to kNotFound. |
michael@0 | 79 | int32_t visualIndex; |
michael@0 | 80 | // [out] Visual position of the character, from the left (on the X axis), in twips. |
michael@0 | 81 | // Eessentially, this is the X position (relative to the rendering context) where the text was drawn + the font metric of the visual string to the left of the given logical position. |
michael@0 | 82 | // If the logical position was not found, set to kNotFound. |
michael@0 | 83 | int32_t visualLeftTwips; |
michael@0 | 84 | // [out] Visual width of the character, in twips. |
michael@0 | 85 | // If the logical position was not found, set to kNotFound. |
michael@0 | 86 | int32_t visualWidth; |
michael@0 | 87 | }; |
michael@0 | 88 | |
michael@0 | 89 | class nsBidiPresUtils { |
michael@0 | 90 | public: |
michael@0 | 91 | nsBidiPresUtils(); |
michael@0 | 92 | ~nsBidiPresUtils(); |
michael@0 | 93 | |
michael@0 | 94 | /** |
michael@0 | 95 | * Interface for the processor used by ProcessText. Used by process text to |
michael@0 | 96 | * collect information about the width of subruns and to notify where each |
michael@0 | 97 | * subrun should be rendered. |
michael@0 | 98 | */ |
michael@0 | 99 | class BidiProcessor { |
michael@0 | 100 | public: |
michael@0 | 101 | virtual ~BidiProcessor() { } |
michael@0 | 102 | |
michael@0 | 103 | /** |
michael@0 | 104 | * Sets the current text with the given length and the given direction. |
michael@0 | 105 | * |
michael@0 | 106 | * @remark The reason that the function gives a string instead of an index |
michael@0 | 107 | * is that ProcessText copies and modifies the string passed to it, so |
michael@0 | 108 | * passing an index would be impossible. |
michael@0 | 109 | * |
michael@0 | 110 | * @param aText The string of text. |
michael@0 | 111 | * @param aLength The length of the string of text. |
michael@0 | 112 | * @param aDirection The direction of the text. The string will never have |
michael@0 | 113 | * mixed direction. |
michael@0 | 114 | */ |
michael@0 | 115 | virtual void SetText(const char16_t* aText, |
michael@0 | 116 | int32_t aLength, |
michael@0 | 117 | nsBidiDirection aDirection) = 0; |
michael@0 | 118 | |
michael@0 | 119 | /** |
michael@0 | 120 | * Returns the measured width of the text given in SetText. If SetText was |
michael@0 | 121 | * not called with valid parameters, the result of this call is undefined. |
michael@0 | 122 | * This call is guaranteed to only be called once between SetText calls. |
michael@0 | 123 | * Will be invoked before DrawText. |
michael@0 | 124 | */ |
michael@0 | 125 | virtual nscoord GetWidth() = 0; |
michael@0 | 126 | |
michael@0 | 127 | /** |
michael@0 | 128 | * Draws the text given in SetText to a rendering context. If SetText was |
michael@0 | 129 | * not called with valid parameters, the result of this call is undefined. |
michael@0 | 130 | * This call is guaranteed to only be called once between SetText calls. |
michael@0 | 131 | * |
michael@0 | 132 | * @param aXOffset The offset of the left side of the substring to be drawn |
michael@0 | 133 | * from the beginning of the overall string passed to ProcessText. |
michael@0 | 134 | * @param aWidth The width returned by GetWidth. |
michael@0 | 135 | */ |
michael@0 | 136 | virtual void DrawText(nscoord aXOffset, |
michael@0 | 137 | nscoord aWidth) = 0; |
michael@0 | 138 | }; |
michael@0 | 139 | |
michael@0 | 140 | /** |
michael@0 | 141 | * Make Bidi engine calculate the embedding levels of the frames that are |
michael@0 | 142 | * descendants of a given block frame. |
michael@0 | 143 | * |
michael@0 | 144 | * @param aBlockFrame The block frame |
michael@0 | 145 | * |
michael@0 | 146 | * @lina 06/18/2000 |
michael@0 | 147 | */ |
michael@0 | 148 | static nsresult Resolve(nsBlockFrame* aBlockFrame); |
michael@0 | 149 | static nsresult ResolveParagraph(nsBlockFrame* aBlockFrame, |
michael@0 | 150 | BidiParagraphData* aBpd); |
michael@0 | 151 | static void ResolveParagraphWithinBlock(nsBlockFrame* aBlockFrame, |
michael@0 | 152 | BidiParagraphData* aBpd); |
michael@0 | 153 | |
michael@0 | 154 | /** |
michael@0 | 155 | * Reorder this line using Bidi engine. |
michael@0 | 156 | * Update frame array, following the new visual sequence. |
michael@0 | 157 | * |
michael@0 | 158 | * @lina 05/02/2000 |
michael@0 | 159 | */ |
michael@0 | 160 | static void ReorderFrames(nsIFrame* aFirstFrameOnLine, |
michael@0 | 161 | int32_t aNumFramesOnLine, |
michael@0 | 162 | mozilla::WritingMode aLineWM, |
michael@0 | 163 | nscoord& aLineWidth); |
michael@0 | 164 | |
michael@0 | 165 | /** |
michael@0 | 166 | * Format Unicode text, taking into account bidi capabilities |
michael@0 | 167 | * of the platform. The formatting includes: reordering, Arabic shaping, |
michael@0 | 168 | * symmetric and numeric swapping, removing control characters. |
michael@0 | 169 | * |
michael@0 | 170 | * @lina 06/18/2000 |
michael@0 | 171 | */ |
michael@0 | 172 | static nsresult FormatUnicodeText(nsPresContext* aPresContext, |
michael@0 | 173 | char16_t* aText, |
michael@0 | 174 | int32_t& aTextLength, |
michael@0 | 175 | nsCharType aCharType, |
michael@0 | 176 | bool aIsOddLevel); |
michael@0 | 177 | |
michael@0 | 178 | /** |
michael@0 | 179 | * Reorder plain text using the Unicode Bidi algorithm and send it to |
michael@0 | 180 | * a rendering context for rendering. |
michael@0 | 181 | * |
michael@0 | 182 | * @param[in] aText the string to be rendered (in logical order) |
michael@0 | 183 | * @param aLength the number of characters in the string |
michael@0 | 184 | * @param aBaseLevel the base embedding level of the string |
michael@0 | 185 | * odd values are right-to-left; even values are left-to-right, plus special |
michael@0 | 186 | * constants as follows (defined in nsBidi.h) |
michael@0 | 187 | * NSBIDI_LTR - left-to-right string |
michael@0 | 188 | * NSBIDI_RTL - right-to-left string |
michael@0 | 189 | * NSBIDI_DEFAULT_LTR - auto direction determined by first strong character, |
michael@0 | 190 | * default is left-to-right |
michael@0 | 191 | * NSBIDI_DEFAULT_RTL - auto direction determined by first strong character, |
michael@0 | 192 | * default is right-to-left |
michael@0 | 193 | * |
michael@0 | 194 | * @param aPresContext the presentation context |
michael@0 | 195 | * @param aRenderingContext the rendering context to render to |
michael@0 | 196 | * @param aTextRunConstructionContext the rendering context to be used to construct the textrun (affects font hinting) |
michael@0 | 197 | * @param aX the x-coordinate to render the string |
michael@0 | 198 | * @param aY the y-coordinate to render the string |
michael@0 | 199 | * @param[in,out] aPosResolve array of logical positions to resolve into visual positions; can be nullptr if this functionality is not required |
michael@0 | 200 | * @param aPosResolveCount number of items in the aPosResolve array |
michael@0 | 201 | */ |
michael@0 | 202 | static nsresult RenderText(const char16_t* aText, |
michael@0 | 203 | int32_t aLength, |
michael@0 | 204 | nsBidiLevel aBaseLevel, |
michael@0 | 205 | nsPresContext* aPresContext, |
michael@0 | 206 | nsRenderingContext& aRenderingContext, |
michael@0 | 207 | nsRenderingContext& aTextRunConstructionContext, |
michael@0 | 208 | nscoord aX, |
michael@0 | 209 | nscoord aY, |
michael@0 | 210 | nsBidiPositionResolve* aPosResolve = nullptr, |
michael@0 | 211 | int32_t aPosResolveCount = 0) |
michael@0 | 212 | { |
michael@0 | 213 | return ProcessTextForRenderingContext(aText, aLength, aBaseLevel, aPresContext, aRenderingContext, |
michael@0 | 214 | aTextRunConstructionContext, MODE_DRAW, aX, aY, aPosResolve, aPosResolveCount, nullptr); |
michael@0 | 215 | } |
michael@0 | 216 | |
michael@0 | 217 | static nscoord MeasureTextWidth(const char16_t* aText, |
michael@0 | 218 | int32_t aLength, |
michael@0 | 219 | nsBidiLevel aBaseLevel, |
michael@0 | 220 | nsPresContext* aPresContext, |
michael@0 | 221 | nsRenderingContext& aRenderingContext) |
michael@0 | 222 | { |
michael@0 | 223 | nscoord length; |
michael@0 | 224 | nsresult rv = ProcessTextForRenderingContext(aText, aLength, aBaseLevel, aPresContext, |
michael@0 | 225 | aRenderingContext, aRenderingContext, |
michael@0 | 226 | MODE_MEASURE, 0, 0, nullptr, 0, &length); |
michael@0 | 227 | return NS_SUCCEEDED(rv) ? length : 0; |
michael@0 | 228 | } |
michael@0 | 229 | |
michael@0 | 230 | /** |
michael@0 | 231 | * Check if a line is reordered, i.e., if the child frames are not |
michael@0 | 232 | * all laid out left-to-right. |
michael@0 | 233 | * @param aFirstFrameOnLine : first frame of the line to be tested |
michael@0 | 234 | * @param aNumFramesOnLine : number of frames on this line |
michael@0 | 235 | * @param[out] aLeftMost : leftmost frame on this line |
michael@0 | 236 | * @param[out] aRightMost : rightmost frame on this line |
michael@0 | 237 | */ |
michael@0 | 238 | static bool CheckLineOrder(nsIFrame* aFirstFrameOnLine, |
michael@0 | 239 | int32_t aNumFramesOnLine, |
michael@0 | 240 | nsIFrame** aLeftmost, |
michael@0 | 241 | nsIFrame** aRightmost); |
michael@0 | 242 | |
michael@0 | 243 | /** |
michael@0 | 244 | * Get the frame to the right of the given frame, on the same line. |
michael@0 | 245 | * @param aFrame : We're looking for the frame to the right of this frame. |
michael@0 | 246 | * If null, return the leftmost frame on the line. |
michael@0 | 247 | * @param aFirstFrameOnLine : first frame of the line to be tested |
michael@0 | 248 | * @param aNumFramesOnLine : number of frames on this line |
michael@0 | 249 | */ |
michael@0 | 250 | static nsIFrame* GetFrameToRightOf(const nsIFrame* aFrame, |
michael@0 | 251 | nsIFrame* aFirstFrameOnLine, |
michael@0 | 252 | int32_t aNumFramesOnLine); |
michael@0 | 253 | |
michael@0 | 254 | /** |
michael@0 | 255 | * Get the frame to the left of the given frame, on the same line. |
michael@0 | 256 | * @param aFrame : We're looking for the frame to the left of this frame. |
michael@0 | 257 | * If null, return the rightmost frame on the line. |
michael@0 | 258 | * @param aFirstFrameOnLine : first frame of the line to be tested |
michael@0 | 259 | * @param aNumFramesOnLine : number of frames on this line |
michael@0 | 260 | */ |
michael@0 | 261 | static nsIFrame* GetFrameToLeftOf(const nsIFrame* aFrame, |
michael@0 | 262 | nsIFrame* aFirstFrameOnLine, |
michael@0 | 263 | int32_t aNumFramesOnLine); |
michael@0 | 264 | |
michael@0 | 265 | static nsIFrame* GetFirstLeaf(nsIFrame* aFrame); |
michael@0 | 266 | |
michael@0 | 267 | /** |
michael@0 | 268 | * Get the bidi embedding level of the given (inline) frame. |
michael@0 | 269 | */ |
michael@0 | 270 | static nsBidiLevel GetFrameEmbeddingLevel(nsIFrame* aFrame); |
michael@0 | 271 | |
michael@0 | 272 | /** |
michael@0 | 273 | * Get the paragraph depth of the given (inline) frame. |
michael@0 | 274 | */ |
michael@0 | 275 | static uint8_t GetParagraphDepth(nsIFrame* aFrame); |
michael@0 | 276 | |
michael@0 | 277 | /** |
michael@0 | 278 | * Get the bidi base level of the given (inline) frame. |
michael@0 | 279 | */ |
michael@0 | 280 | static nsBidiLevel GetFrameBaseLevel(nsIFrame* aFrame); |
michael@0 | 281 | |
michael@0 | 282 | enum Mode { MODE_DRAW, MODE_MEASURE }; |
michael@0 | 283 | |
michael@0 | 284 | /** |
michael@0 | 285 | * Reorder plain text using the Unicode Bidi algorithm and send it to |
michael@0 | 286 | * a processor for rendering or measuring |
michael@0 | 287 | * |
michael@0 | 288 | * @param[in] aText the string to be processed (in logical order) |
michael@0 | 289 | * @param aLength the number of characters in the string |
michael@0 | 290 | * @param aBaseLevel the base embedding level of the string |
michael@0 | 291 | * odd values are right-to-left; even values are left-to-right, plus special |
michael@0 | 292 | * constants as follows (defined in nsBidi.h) |
michael@0 | 293 | * NSBIDI_LTR - left-to-right string |
michael@0 | 294 | * NSBIDI_RTL - right-to-left string |
michael@0 | 295 | * NSBIDI_DEFAULT_LTR - auto direction determined by first strong character, |
michael@0 | 296 | * default is left-to-right |
michael@0 | 297 | * NSBIDI_DEFAULT_RTL - auto direction determined by first strong character, |
michael@0 | 298 | * default is right-to-left |
michael@0 | 299 | * |
michael@0 | 300 | * @param aPresContext the presentation context |
michael@0 | 301 | * @param aprocessor the bidi processor |
michael@0 | 302 | * @param aMode the operation to process |
michael@0 | 303 | * MODE_DRAW - invokes DrawText on the processor for each substring |
michael@0 | 304 | * MODE_MEASURE - does not invoke DrawText on the processor |
michael@0 | 305 | * Note that the string is always measured, regardless of mode |
michael@0 | 306 | * @param[in,out] aPosResolve array of logical positions to resolve into |
michael@0 | 307 | * visual positions; can be nullptr if this functionality is not required |
michael@0 | 308 | * @param aPosResolveCount number of items in the aPosResolve array |
michael@0 | 309 | * @param[out] aWidth Pointer to where the width will be stored (may be null) |
michael@0 | 310 | */ |
michael@0 | 311 | static nsresult ProcessText(const char16_t* aText, |
michael@0 | 312 | int32_t aLength, |
michael@0 | 313 | nsBidiLevel aBaseLevel, |
michael@0 | 314 | nsPresContext* aPresContext, |
michael@0 | 315 | BidiProcessor& aprocessor, |
michael@0 | 316 | Mode aMode, |
michael@0 | 317 | nsBidiPositionResolve* aPosResolve, |
michael@0 | 318 | int32_t aPosResolveCount, |
michael@0 | 319 | nscoord* aWidth, |
michael@0 | 320 | nsBidi* aBidiEngine); |
michael@0 | 321 | |
michael@0 | 322 | /** |
michael@0 | 323 | * Make a copy of a string, converting from logical to visual order |
michael@0 | 324 | * |
michael@0 | 325 | * @param aSource the source string |
michael@0 | 326 | * @param aDest the destination string |
michael@0 | 327 | * @param aBaseDirection the base direction of the string |
michael@0 | 328 | * (NSBIDI_LTR or NSBIDI_RTL to force the base direction; |
michael@0 | 329 | * NSBIDI_DEFAULT_LTR or NSBIDI_DEFAULT_RTL to let the bidi engine |
michael@0 | 330 | * determine the direction from rules P2 and P3 of the bidi algorithm. |
michael@0 | 331 | * @see nsBidi::GetPara |
michael@0 | 332 | * @param aOverride if TRUE, the text has a bidi override, according to |
michael@0 | 333 | * the direction in aDir |
michael@0 | 334 | */ |
michael@0 | 335 | static void CopyLogicalToVisual(const nsAString& aSource, |
michael@0 | 336 | nsAString& aDest, |
michael@0 | 337 | nsBidiLevel aBaseDirection, |
michael@0 | 338 | bool aOverride); |
michael@0 | 339 | |
michael@0 | 340 | /** |
michael@0 | 341 | * Use style attributes to determine the base paragraph level to pass to the |
michael@0 | 342 | * bidi algorithm. |
michael@0 | 343 | * |
michael@0 | 344 | * If |unicode-bidi| is set to "[-moz-]plaintext", returns NSBIDI_DEFAULT_LTR, |
michael@0 | 345 | * in other words the direction is determined from the first strong character |
michael@0 | 346 | * in the text according to rules P2 and P3 of the bidi algorithm, or LTR if |
michael@0 | 347 | * there is no strong character. |
michael@0 | 348 | * |
michael@0 | 349 | * Otherwise returns NSBIDI_LTR or NSBIDI_RTL depending on the value of |
michael@0 | 350 | * |direction| |
michael@0 | 351 | */ |
michael@0 | 352 | static nsBidiLevel BidiLevelFromStyle(nsStyleContext* aStyleContext); |
michael@0 | 353 | |
michael@0 | 354 | private: |
michael@0 | 355 | static nsresult |
michael@0 | 356 | ProcessTextForRenderingContext(const char16_t* aText, |
michael@0 | 357 | int32_t aLength, |
michael@0 | 358 | nsBidiLevel aBaseLevel, |
michael@0 | 359 | nsPresContext* aPresContext, |
michael@0 | 360 | nsRenderingContext& aRenderingContext, |
michael@0 | 361 | nsRenderingContext& aTextRunConstructionContext, |
michael@0 | 362 | Mode aMode, |
michael@0 | 363 | nscoord aX, // DRAW only |
michael@0 | 364 | nscoord aY, // DRAW only |
michael@0 | 365 | nsBidiPositionResolve* aPosResolve, /* may be null */ |
michael@0 | 366 | int32_t aPosResolveCount, |
michael@0 | 367 | nscoord* aWidth /* may be null */); |
michael@0 | 368 | |
michael@0 | 369 | /** |
michael@0 | 370 | * Traverse the child frames of the block element and: |
michael@0 | 371 | * Set up an array of the frames in logical order |
michael@0 | 372 | * Create a string containing the text content of all the frames |
michael@0 | 373 | * If we encounter content that requires us to split the element into more |
michael@0 | 374 | * than one paragraph for bidi resolution, resolve the paragraph up to that |
michael@0 | 375 | * point. |
michael@0 | 376 | */ |
michael@0 | 377 | static void TraverseFrames(nsBlockFrame* aBlockFrame, |
michael@0 | 378 | nsBlockInFlowLineIterator* aLineIter, |
michael@0 | 379 | nsIFrame* aCurrentFrame, |
michael@0 | 380 | BidiParagraphData* aBpd); |
michael@0 | 381 | |
michael@0 | 382 | /* |
michael@0 | 383 | * Position aFrame and its descendants to their visual places. Also if aFrame |
michael@0 | 384 | * is not leaf, resize it to embrace its children. |
michael@0 | 385 | * |
michael@0 | 386 | * @param aFrame The frame which itself and its children are |
michael@0 | 387 | * going to be repositioned |
michael@0 | 388 | * @param aIsEvenLevel TRUE means the embedding level of this frame |
michael@0 | 389 | * is even (LTR) |
michael@0 | 390 | * @param[in,out] aStart IN value is the starting position of aFrame |
michael@0 | 391 | * (without considering its inline-start margin) |
michael@0 | 392 | * OUT value will be the ending position of aFrame |
michael@0 | 393 | * (after adding its inline-end margin) |
michael@0 | 394 | * @param aContinuationStates A map from nsIFrame* to nsFrameContinuationState |
michael@0 | 395 | */ |
michael@0 | 396 | static void RepositionFrame(nsIFrame* aFrame, |
michael@0 | 397 | bool aIsEvenLevel, |
michael@0 | 398 | nscoord& aStart, |
michael@0 | 399 | nsContinuationStates* aContinuationStates, |
michael@0 | 400 | mozilla::WritingMode aLineWM, |
michael@0 | 401 | nscoord& aLineWidth); |
michael@0 | 402 | |
michael@0 | 403 | /* |
michael@0 | 404 | * Initialize the continuation state(nsFrameContinuationState) to |
michael@0 | 405 | * (nullptr, 0) for aFrame and its descendants. |
michael@0 | 406 | * |
michael@0 | 407 | * @param aFrame The frame which itself and its descendants will |
michael@0 | 408 | * be initialized |
michael@0 | 409 | * @param aContinuationStates A map from nsIFrame* to nsFrameContinuationState |
michael@0 | 410 | */ |
michael@0 | 411 | static void InitContinuationStates(nsIFrame* aFrame, |
michael@0 | 412 | nsContinuationStates* aContinuationStates); |
michael@0 | 413 | |
michael@0 | 414 | /* |
michael@0 | 415 | * Determine if aFrame is leftmost or rightmost, and set aIsLeftMost and |
michael@0 | 416 | * aIsRightMost values. Also set continuation states of aContinuationStates. |
michael@0 | 417 | * |
michael@0 | 418 | * A frame is leftmost if it's the first appearance of its continuation chain |
michael@0 | 419 | * on the line and the chain is on its first line if it's LTR or the chain is |
michael@0 | 420 | * on its last line if it's RTL. |
michael@0 | 421 | * A frame is rightmost if it's the last appearance of its continuation chain |
michael@0 | 422 | * on the line and the chain is on its first line if it's RTL or the chain is |
michael@0 | 423 | * on its last line if it's LTR. |
michael@0 | 424 | * |
michael@0 | 425 | * @param aContinuationStates A map from nsIFrame* to nsFrameContinuationState |
michael@0 | 426 | * @param[out] aIsLeftMost TRUE means aFrame is leftmost frame or continuation |
michael@0 | 427 | * @param[out] aIsRightMost TRUE means aFrame is rightmost frame or continuation |
michael@0 | 428 | */ |
michael@0 | 429 | static void IsFirstOrLast(nsIFrame* aFrame, |
michael@0 | 430 | nsContinuationStates* aContinuationStates, |
michael@0 | 431 | bool& aIsFirst /* out */, |
michael@0 | 432 | bool& aIsLast /* out */); |
michael@0 | 433 | |
michael@0 | 434 | /** |
michael@0 | 435 | * Adjust frame positions following their visual order |
michael@0 | 436 | * |
michael@0 | 437 | * @param aFirstChild the first kid |
michael@0 | 438 | * |
michael@0 | 439 | * @lina 04/11/2000 |
michael@0 | 440 | */ |
michael@0 | 441 | static void RepositionInlineFrames(BidiLineData* aBld, |
michael@0 | 442 | nsIFrame* aFirstChild, |
michael@0 | 443 | mozilla::WritingMode aLineWM, |
michael@0 | 444 | nscoord& aLineWidth); |
michael@0 | 445 | |
michael@0 | 446 | /** |
michael@0 | 447 | * Helper method for Resolve() |
michael@0 | 448 | * Truncate a text frame to the end of a single-directional run and possibly |
michael@0 | 449 | * create a continuation frame for the remainder of its content. |
michael@0 | 450 | * |
michael@0 | 451 | * @param aFrame the original frame |
michael@0 | 452 | * @param aNewFrame [OUT] the new frame that was created |
michael@0 | 453 | * @param aFrameIndex [IN/OUT] index of aFrame in mLogicalFrames |
michael@0 | 454 | * @param aStart [IN] the start of the content mapped by aFrame (and |
michael@0 | 455 | * any fluid continuations) |
michael@0 | 456 | * @param aEnd [IN] the offset of the end of the single-directional |
michael@0 | 457 | * text run. |
michael@0 | 458 | * @see Resolve() |
michael@0 | 459 | * @see RemoveBidiContinuation() |
michael@0 | 460 | */ |
michael@0 | 461 | static inline |
michael@0 | 462 | nsresult EnsureBidiContinuation(nsIFrame* aFrame, |
michael@0 | 463 | nsIFrame** aNewFrame, |
michael@0 | 464 | int32_t& aFrameIndex, |
michael@0 | 465 | int32_t aStart, |
michael@0 | 466 | int32_t aEnd); |
michael@0 | 467 | |
michael@0 | 468 | /** |
michael@0 | 469 | * Helper method for Resolve() |
michael@0 | 470 | * Convert one or more bidi continuation frames created in a previous reflow by |
michael@0 | 471 | * EnsureBidiContinuation() into fluid continuations. |
michael@0 | 472 | * @param aFrame the frame whose continuations are to be removed |
michael@0 | 473 | * @param aFirstIndex index of aFrame in mLogicalFrames |
michael@0 | 474 | * @param aLastIndex index of the last frame to be removed |
michael@0 | 475 | * @param aOffset [OUT] count of directional frames removed. Since |
michael@0 | 476 | * directional frames have control characters |
michael@0 | 477 | * corresponding to them in mBuffer, the pointers to |
michael@0 | 478 | * mBuffer in Resolve() will need to be updated after |
michael@0 | 479 | * deleting the frames. |
michael@0 | 480 | * |
michael@0 | 481 | * @see Resolve() |
michael@0 | 482 | * @see EnsureBidiContinuation() |
michael@0 | 483 | */ |
michael@0 | 484 | static void RemoveBidiContinuation(BidiParagraphData* aBpd, |
michael@0 | 485 | nsIFrame* aFrame, |
michael@0 | 486 | int32_t aFirstIndex, |
michael@0 | 487 | int32_t aLastIndex, |
michael@0 | 488 | int32_t& aOffset); |
michael@0 | 489 | static void CalculateCharType(nsBidi* aBidiEngine, |
michael@0 | 490 | const char16_t* aText, |
michael@0 | 491 | int32_t& aOffset, |
michael@0 | 492 | int32_t aCharTypeLimit, |
michael@0 | 493 | int32_t& aRunLimit, |
michael@0 | 494 | int32_t& aRunLength, |
michael@0 | 495 | int32_t& aRunCount, |
michael@0 | 496 | uint8_t& aCharType, |
michael@0 | 497 | uint8_t& aPrevCharType); |
michael@0 | 498 | |
michael@0 | 499 | static void StripBidiControlCharacters(char16_t* aText, |
michael@0 | 500 | int32_t& aTextLength); |
michael@0 | 501 | |
michael@0 | 502 | static bool WriteLogicalToVisual(const char16_t* aSrc, |
michael@0 | 503 | uint32_t aSrcLength, |
michael@0 | 504 | char16_t* aDest, |
michael@0 | 505 | nsBidiLevel aBaseDirection, |
michael@0 | 506 | nsBidi* aBidiEngine); |
michael@0 | 507 | |
michael@0 | 508 | static void WriteReverse(const char16_t* aSrc, |
michael@0 | 509 | uint32_t aSrcLength, |
michael@0 | 510 | char16_t* aDest); |
michael@0 | 511 | }; |
michael@0 | 512 | |
michael@0 | 513 | #endif /* nsBidiPresUtils_h___ */ |