2001-03-09 04:12:39 +03:00
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
2004-04-18 18:30:37 +04:00
* * * * * * BEGIN LICENSE BLOCK * * * * *
* Version : MPL 1.1 / GPL 2.0 / LGPL 2.1
2001-03-09 04:12:39 +03:00
*
2004-04-18 18:30:37 +04:00
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 ( the " License " ) ; you may not use this file except in compliance with
* the License . You may obtain a copy of the License at
* http : //www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an " AS IS " basis ,
* WITHOUT WARRANTY OF ANY KIND , either express or implied . See the License
* for the specific language governing rights and limitations under the
* License .
2001-03-09 04:12:39 +03:00
*
* The Original Code is mozilla . org code .
*
* The Initial Developer of the Original Code is
2004-04-18 18:30:37 +04:00
* IBM Corporation .
* Portions created by the Initial Developer are Copyright ( C ) 2000
* the Initial Developer . All Rights Reserved .
*
* Contributor ( s ) :
* IBM Corporation
2001-03-09 04:12:39 +03:00
*
2004-04-18 18:30:37 +04:00
* Alternatively , the contents of this file may be used under the terms of
* either of the GNU General Public License Version 2 or later ( the " GPL " ) ,
* or the GNU Lesser General Public License Version 2.1 or later ( the " LGPL " ) ,
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above . If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL , and not to allow others to
* use your version of this file under the terms of the MPL , indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL . If you do not delete
* the provisions above , a recipient may use your version of this file under
* the terms of any one of the MPL , the GPL or the LGPL .
2001-03-09 04:12:39 +03:00
*
2004-04-18 18:30:37 +04:00
* * * * * * END LICENSE BLOCK * * * * * */
2001-03-09 04:12:39 +03:00
# ifdef IBMBIDI
# ifndef nsBidiPresUtils_h___
# define nsBidiPresUtils_h___
# include "nsVoidArray.h"
# include "nsIFrame.h"
2002-02-19 23:41:32 +03:00
# include "nsBidi.h"
# include "nsBidiUtils.h"
2001-05-15 15:57:22 +04:00
# include "nsCOMPtr.h"
2003-07-24 22:33:50 +04:00
# include "nsDataHashtable.h"
2006-03-15 23:52:02 +03:00
# include "nsBlockFrame.h"
2001-03-09 04:12:39 +03:00
2004-10-29 16:28:19 +04:00
/**
* A structure representing a logical position which should be resolved
* into its visual position during BiDi processing .
*/
struct nsBidiPositionResolve
{
// [in] Logical index within string.
PRInt32 logicalIndex ;
// [out] Visual index within string.
// If the logical position was not found, set to kNotFound.
PRInt32 visualIndex ;
// [out] Visual position of the character, from the left (on the X axis), in twips.
// 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.
// If the logical position was not found, set to kNotFound.
PRInt32 visualLeftTwips ;
} ;
2001-03-09 04:12:39 +03:00
class nsBidiPresUtils {
public :
nsBidiPresUtils ( ) ;
~ nsBidiPresUtils ( ) ;
PRBool IsSuccessful ( void ) const ;
/**
2003-07-24 22:33:50 +04:00
* Make Bidi engine calculate the embedding levels of the frames that are
* descendants of a given block frame .
*
* @ param aPresContext The presContext
* @ param aBlockFrame The block frame
* @ param aFirstChild The first child frame of aBlockFrame
* @ param aIsVisualFormControl [ IN ] Set if we are in a form control on a
* visual page .
* @ see nsHTMLReflowState : : IsBidiFormControl
2001-03-09 04:12:39 +03:00
*
* @ lina 06 / 18 / 2000
*/
2004-08-01 03:15:21 +04:00
nsresult Resolve ( nsPresContext * aPresContext ,
2006-03-15 23:52:02 +03:00
nsBlockFrame * aBlockFrame ,
2001-03-09 04:12:39 +03:00
nsIFrame * aFirstChild ,
2002-07-10 04:52:17 +04:00
PRBool aIsVisualFormControl ) ;
2001-03-09 04:12:39 +03:00
/**
* Reorder this line using Bidi engine .
* Update frame array , following the new visual sequence .
*
* @ lina 05 / 02 / 2000
*/
2004-08-01 03:15:21 +04:00
void ReorderFrames ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
nsIRenderingContext * aRendContext ,
2006-03-12 12:49:48 +03:00
nsIFrame * aFirstFrameOnLine ,
PRInt32 aNumFramesOnLine ) ;
2001-03-09 04:12:39 +03:00
/**
* Format Unicode text , taking into account bidi capabilities
* of the platform . The formatting includes : reordering , Arabic shaping ,
* symmetric and numeric swapping , removing control characters .
*
* @ lina 06 / 18 / 2000
*/
2004-08-01 03:15:21 +04:00
nsresult FormatUnicodeText ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
PRUnichar * aText ,
PRInt32 & aTextLength ,
nsCharType aCharType ,
PRBool aIsOddLevel ,
PRBool aIsBidiSystem ) ;
2002-06-12 01:00:20 +04:00
/**
* Reorder Unicode text , taking into account bidi capabilities of the
* platform . The reordering includes symmetric swapping and removing
* control characters .
*/
nsresult ReorderUnicodeText ( PRUnichar * aText ,
PRInt32 & aTextLength ,
nsCharType aCharType ,
PRBool aIsOddLevel ,
PRBool aIsBidiSystem ) ;
2001-03-09 04:12:39 +03:00
/**
2002-02-19 23:41:32 +03:00
* Return our nsBidi object ( bidi reordering engine )
2001-03-09 04:12:39 +03:00
*/
2002-02-19 23:41:32 +03:00
nsresult GetBidiEngine ( nsBidi * * aBidiEngine ) ;
2001-03-09 04:12:39 +03:00
2001-11-12 23:51:48 +03:00
/**
* Reorder plain text using the Unicode Bidi algorithm and send it to
* a rendering context for rendering .
*
2004-10-29 16:28:19 +04:00
* @ param [ in ] aText the string to be rendered ( in logical order )
2001-11-12 23:51:48 +03:00
* @ param aLength the number of characters in the string
* @ param aBaseDirection the base direction of the string
* NSBIDI_LTR - left - to - right string
* NSBIDI_RTL - right - to - left string
* @ param aPresContext the presentation context
* @ param aRenderingContext the rendering context
2004-10-29 16:28:19 +04:00
* @ param aX the x - coordinate to render the string
* @ param aY the y - coordinate to render the string
* @ param [ in , out ] aPosResolve array of logical positions to resolve into visual positions ; can be nsnull if this functionality is not required
* @ param aPosResolveCount number of items in the aPosResolve array
2001-11-12 23:51:48 +03:00
*/
2004-10-29 16:28:19 +04:00
nsresult RenderText ( const PRUnichar * aText ,
2001-11-13 00:40:03 +03:00
PRInt32 aLength ,
nsBidiDirection aBaseDirection ,
2004-08-01 03:15:21 +04:00
nsPresContext * aPresContext ,
2001-11-13 00:40:03 +03:00
nsIRenderingContext & aRenderingContext ,
nscoord aX ,
2004-10-29 16:28:19 +04:00
nscoord aY ,
nsBidiPositionResolve * aPosResolve = nsnull ,
PRInt32 aPosResolveCount = 0 ) ;
2001-11-12 23:51:48 +03:00
2006-03-12 12:49:48 +03:00
/**
* Check if a line is reordered , i . e . , if the child frames are not
* all laid out left - to - right .
* @ param aFirstFrameOnLine : first frame of the line to be tested
* @ param aNumFramesOnLine : number of frames on this line
* @ param [ out ] aLeftMost : leftmost frame on this line
* @ param [ out ] aRightMost : rightmost frame on this line
*/
PRBool CheckLineOrder ( nsIFrame * aFirstFrameOnLine ,
PRInt32 aNumFramesOnLine ,
nsIFrame * * aLeftmost ,
nsIFrame * * aRightmost ) ;
/**
* Get the frame to the right of the given frame , on the same line .
* @ param aFrame : We ' re looking for the frame to the right of this frame .
* If null , return the leftmost frame on the line .
* @ param aFirstFrameOnLine : first frame of the line to be tested
* @ param aNumFramesOnLine : number of frames on this line
*/
nsIFrame * GetFrameToRightOf ( const nsIFrame * aFrame ,
nsIFrame * aFirstFrameOnLine ,
PRInt32 aNumFramesOnLine ) ;
/**
* Get the frame to the left of the given frame , on the same line .
* @ param aFrame : We ' re looking for the frame to the left of this frame .
* If null , return the rightmost frame on the line .
* @ param aFirstFrameOnLine : first frame of the line to be tested
* @ param aNumFramesOnLine : number of frames on this line
*/
nsIFrame * GetFrameToLeftOf ( const nsIFrame * aFrame ,
nsIFrame * aFirstFrameOnLine ,
PRInt32 aNumFramesOnLine ) ;
/**
* Get the bidi embedding level of the given ( inline ) frame .
*/
static nsBidiLevel GetFrameEmbeddingLevel ( nsIFrame * aFrame ) ;
/**
* Get the bidi base level of the given ( inline ) frame .
*/
static nsBidiLevel GetFrameBaseLevel ( nsIFrame * aFrame ) ;
2001-03-09 04:12:39 +03:00
private :
/**
* Create a string containing entire text content of this block .
*
* @ lina 05 / 02 / 2000
*/
2004-08-01 03:15:21 +04:00
void CreateBlockBuffer ( nsPresContext * aPresContext ) ;
2001-03-09 04:12:39 +03:00
/**
* Set up an array of the frames after splitting frames so that each frame has
* consistent directionality . At this point the frames are still in logical
* order
*/
2004-08-01 03:15:21 +04:00
nsresult InitLogicalArray ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
nsIFrame * aCurrentFrame ,
nsIFrame * aNextInFlow ,
PRBool aAddMarkers = PR_FALSE ) ;
2006-03-12 12:49:48 +03:00
/**
* Initialize the logically - ordered array of frames
* using the top - level frames of a single line
*/
void InitLogicalArrayFromLine ( nsIFrame * aFirstFrameOnLine ,
PRInt32 aNumFramesOnLine ) ;
2001-03-09 04:12:39 +03:00
/**
* Reorder the frame array from logical to visual order
2006-02-22 00:33:47 +03:00
*
* @ param aReordered TRUE on return if the visual order is different from
* the logical order
2006-03-12 12:49:48 +03:00
* @ param aHasRTLFrames TRUE on return if at least one of the frames is RTL
* ( and therefore might have reordered descendents )
2001-03-09 04:12:39 +03:00
*/
2006-03-12 12:49:48 +03:00
nsresult Reorder ( PRBool & aReordered , PRBool & aHasRTLFrames ) ;
2001-03-09 04:12:39 +03:00
/**
* Adjust frame positions following their visual order
*
2004-08-01 03:15:21 +04:00
* @ param < code > nsPresContext * < / code > , the first kid
2001-03-09 04:12:39 +03:00
*
* @ lina 04 / 11 / 2000
*/
2004-08-01 03:15:21 +04:00
void RepositionInlineFrames ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
nsIRenderingContext * aRendContext ,
nsIFrame * aFirstChild ,
2006-02-22 00:33:47 +03:00
PRBool aReordered ) const ;
2001-03-09 04:12:39 +03:00
2004-08-01 03:15:21 +04:00
void RepositionContainerFrame ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
nsIFrame * aContainer ,
PRInt32 & aMinX ,
PRInt32 & aMaxX ) const ;
2003-07-24 22:33:50 +04:00
/**
* Helper method for Resolve ( )
* Truncate a text frame and possibly create a continuation frame with the
* remainder of its content .
*
* @ param aPresContext the pres context
* @ param aFrame the original frame
* @ param aNewFrame [ OUT ] the new frame that was created
* @ param aFrameIndex [ IN / OUT ] index of aFrame in mLogicalFrames
*
* If there is already a bidi continuation for this frame in mLogicalFrames ,
* no new frame will be created . On exit aNewFrame will point to the existing
* bidi continuation and aFrameIndex will contain its index .
* @ see Resolve ( )
* @ see RemoveBidiContinuation ( )
*/
2004-08-01 03:15:21 +04:00
PRBool EnsureBidiContinuation ( nsPresContext * aPresContext ,
2001-03-09 04:12:39 +03:00
nsIFrame * aFrame ,
nsIFrame * * aNewFrame ,
PRInt32 & aFrameIndex ) ;
2003-07-24 22:33:50 +04:00
/**
* Helper method for Resolve ( )
2006-03-08 12:02:42 +03:00
* Convert one or more bidi continuation frames created in a previous reflow by
* EnsureBidiContinuation ( ) into fluid continuations .
2003-07-24 22:33:50 +04:00
* @ param aPresContext the pres context
* @ param aFrame the frame whose continuations are to be removed
* @ param aFirstIndex index of aFrame in mLogicalFrames
* @ param aLastIndex index of the last frame to be removed
* @ param aOffset [ OUT ] count of directional frames removed . Since
* directional frames have control characters
* corresponding to them in mBuffer , the pointers to
* mBuffer in Resolve ( ) will need to be updated after
* deleting the frames .
*
* @ see Resolve ( )
* @ see EnsureBidiContinuation ( )
*/
2004-08-01 03:15:21 +04:00
void RemoveBidiContinuation ( nsPresContext * aPresContext ,
2003-07-24 22:33:50 +04:00
nsIFrame * aFrame ,
PRInt32 aFirstIndex ,
PRInt32 aLastIndex ,
PRInt32 & aOffset ) const ;
2001-06-29 07:15:58 +04:00
void CalculateCharType ( PRInt32 & aOffset ,
PRInt32 aCharTypeLimit ,
PRInt32 & aRunLimit ,
PRInt32 & aRunLength ,
PRInt32 & aRunCount ,
2001-03-09 04:12:39 +03:00
PRUint8 & aCharType ,
PRUint8 & aPrevCharType ) const ;
2002-04-24 03:50:17 +04:00
void StripBidiControlCharacters ( PRUnichar * aText ,
PRInt32 & aTextLength ) const ;
2001-03-09 04:12:39 +03:00
nsAutoString mBuffer ;
nsVoidArray mLogicalFrames ;
nsVoidArray mVisualFrames ;
2003-07-24 22:33:50 +04:00
nsDataHashtable < nsISupportsHashKey , PRInt32 > mContentToFrameIndex ;
2001-03-09 04:12:39 +03:00
PRInt32 mArraySize ;
PRInt32 * mIndexMap ;
PRUint8 * mLevels ;
nsresult mSuccess ;
2002-02-19 23:41:32 +03:00
nsBidi * mBidiEngine ;
2001-03-09 04:12:39 +03:00
} ;
# endif /* nsBidiPresUtils_h___ */
# endif // IBMBIDI