webengine/wmlengine/src/lmgr/src/LMgrBreakBox.cpp
changeset 74 91031d3aab7d
parent 68 92a765b5b3e7
child 85 e358f2276d3f
equal deleted inserted replaced
68:92a765b5b3e7 74:91031d3aab7d
     1 /*
       
     2 * Copyright (c) 2000 - 2001 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nw_lmgr_breakboxi.h"
       
    20 
       
    21 #include "nw_adt_resizablevector.h"
       
    22 #include "nw_lmgr_cssproperties.h"
       
    23 #include "nw_lmgr_rootbox.h"
       
    24 #include "nw_lmgr_activecontainerbox.h"
       
    25 #include "nw_text_ucs2.h"
       
    26 #include "nwx_settings.h"
       
    27 #include "nw_lmgr_verticaltablecellbox.h"
       
    28 #include "nw_lmgr_containerbox.h"
       
    29 #include "GDIDevicecontext.h"
       
    30 #include "BrsrStatusCodes.h"
       
    31 
       
    32 /* ------------------------------------------------------------------------- *
       
    33    private final methods
       
    34  * ------------------------------------------------------------------------- */
       
    35 
       
    36 /* This method checks if the previous 2 sibling of this break box are also break
       
    37    boxes - If yes we do not want to display this break box 
       
    38    */
       
    39 static
       
    40 NW_Bool
       
    41 NW_LMgr_BreakBox_HandleVerticalLayout(NW_LMgr_Box_t *box)
       
    42 {
       
    43   NW_Bool displayBreak = NW_TRUE;
       
    44   NW_LMgr_Property_t prop;
       
    45   TBrowserStatusCode status = KBrsrSuccess;
       
    46   NW_LMgr_ContainerBox_t* parent = box->parent;
       
    47 
       
    48   if (NW_Object_IsClass(parent, &NW_LMgr_VerticalTableCellBox_Class))
       
    49   {
       
    50     NW_ADT_Vector_Metric_t childIndex = 0;
       
    51   
       
    52     childIndex = NW_LMgr_ContainerBox_GetChildIndex(parent, box);
       
    53     /* If index is zero then we don't want to display the break */
       
    54     if (childIndex == 0)
       
    55     {
       
    56       displayBreak = NW_FALSE;
       
    57     }
       
    58     else
       
    59     {
       
    60       NW_LMgr_Box_t* child = NW_LMgr_ContainerBox_GetChild(parent, (NW_ADT_Vector_Metric_t)(childIndex -1));
       
    61       NW_GDI_Rectangle_t boxBounds = NW_LMgr_Box_GetFormatBounds( child );
       
    62 
       
    63       if (!NW_Object_IsInstanceOf (child, &NW_LMgr_ActiveContainerBox_Class) && 
       
    64           boxBounds.dimension.width == 0 )
       
    65       {
       
    66         child = NW_LMgr_ContainerBox_GetChild(parent, (NW_ADT_Vector_Metric_t)(childIndex -2));
       
    67         if ( child)
       
    68         {
       
    69           if(boxBounds.dimension.width == 0)
       
    70           {
       
    71             displayBreak = NW_FALSE;
       
    72           }
       
    73         }
       
    74         else
       
    75         {
       
    76           displayBreak = NW_FALSE;
       
    77         }
       
    78       }
       
    79     }
       
    80   }
       
    81   else 
       
    82   {
       
    83     status = NW_LMgr_Box_GetProperty(box, NW_CSS_Prop_flags, &prop);
       
    84     if ((status == KBrsrSuccess) && (prop.value.token == NW_CSS_PropValue_flags_thirdBr))
       
    85     {
       
    86       /* do not display this break box since previous 2 siblings were break boxes */
       
    87       displayBreak = NW_FALSE;
       
    88     }
       
    89   }
       
    90 
       
    91   if (!displayBreak)
       
    92   {
       
    93     NW_GDI_Rectangle_t boxBounds = NW_LMgr_Box_GetFormatBounds( box );
       
    94     boxBounds.dimension.height = 0;
       
    95     boxBounds.dimension.width = 0;
       
    96     NW_LMgr_Box_SetFormatBounds( box, boxBounds );
       
    97   }
       
    98 
       
    99   return displayBreak;
       
   100 }
       
   101 
       
   102 
       
   103 /* -------------------------------------------------------------------------
       
   104    The static instance of the Format_Box class object 
       
   105  ------------------------------------------------------------------------- */
       
   106 const
       
   107 NW_LMgr_BreakBox_Class_t  NW_LMgr_BreakBox_Class = {
       
   108   { /* NW_Object_Core            */
       
   109     /* super                     */ &NW_LMgr_Box_Class,
       
   110     /* queryInterface            */ _NW_Object_Base_QueryInterface
       
   111   },
       
   112   { /* NW_Object_Base            */
       
   113     /* interfaceList             */ NULL
       
   114   },
       
   115   { /* NW_Object_Dynamic         */
       
   116     /* instanceSize              */ sizeof (NW_LMgr_BreakBox_t),
       
   117     /* construct                 */ _NW_LMgr_Box_Construct,
       
   118     /* destruct                  */ NULL
       
   119   },
       
   120   { /* NW_LMgr_Box               */
       
   121     /* split                     */ _NW_LMgr_Box_Split,
       
   122     /* resize                    */ _NW_LMgr_BreakBox_Resize,
       
   123     /* postResize                */ _NW_LMgr_Box_PostResize,
       
   124     /* getMinimumContentSize     */ _NW_LMgr_Box_GetMinimumContentSize,
       
   125     /* hasFixedContentSize       */ _NW_LMgr_Box_HasFixedContentSize,
       
   126     /* constrain                 */ _NW_LMgr_BreakBox_Constrain,
       
   127     /* draw                      */ _NW_LMgr_BreakBox_Draw,
       
   128     /* render                    */ _NW_LMgr_Box_Render,
       
   129     /* getBaseline               */ _NW_LMgr_BreakBox_GetBaseline,
       
   130     /* shift                     */ _NW_LMgr_Box_Shift,
       
   131     /* clone                     */ _NW_LMgr_Box_Clone
       
   132   },
       
   133   { /* NW_LMgr_BreakBox          */
       
   134     /* unused                    */ 0
       
   135   }
       
   136 };
       
   137 
       
   138 /* ------------------------------------------------------------------------- */
       
   139 TBrowserStatusCode
       
   140 _NW_LMgr_BreakBox_Resize(NW_LMgr_Box_t *box, NW_LMgr_FormatContext_t* context)
       
   141   {
       
   142   NW_Bool displayBreak = NW_TRUE;
       
   143   NW_REQUIRED_PARAM(context);
       
   144   
       
   145   NW_LMgr_RootBox_t* rootBox = NW_LMgr_Box_GetRootBox( box );
       
   146 
       
   147   /* handle vertical layout for <br/> element */
       
   148   if( NW_LMgr_RootBox_GetSmallScreenOn( rootBox ) )
       
   149     {
       
   150     /* we want to determine if we need to display this break */
       
   151     displayBreak = NW_LMgr_BreakBox_HandleVerticalLayout(box);
       
   152     }
       
   153 
       
   154   if (displayBreak)
       
   155     {
       
   156     CGDIFont *font;
       
   157     /* Set the height to font height */
       
   158     font = NW_LMgr_Box_GetFont (box);
       
   159     if (font != NULL) 
       
   160       {
       
   161       TGDIFontInfo fontInfo;
       
   162 
       
   163       TBrowserStatusCode status = font->GetFontInfo ( &fontInfo);
       
   164       NW_ASSERT (status == KBrsrSuccess);
       
   165 
       
   166       NW_GDI_Rectangle_t boxBounds = NW_LMgr_Box_GetFormatBounds( box );
       
   167       boxBounds.dimension.height = fontInfo.height;
       
   168       boxBounds.dimension.width = 1;
       
   169       NW_LMgr_Box_SetFormatBounds( box, boxBounds );
       
   170       }
       
   171     else 
       
   172       {
       
   173 	    NW_ASSERT(0);
       
   174       }
       
   175     }
       
   176   return KBrsrSuccess;
       
   177   }
       
   178 
       
   179 /* ------------------------------------------------------------------------- */
       
   180 
       
   181 TBrowserStatusCode
       
   182 _NW_LMgr_BreakBox_Constrain(NW_LMgr_Box_t *box,
       
   183                             NW_GDI_Metric_t constraint) {
       
   184 
       
   185   NW_REQUIRED_PARAM(constraint);
       
   186 
       
   187   NW_GDI_Rectangle_t boxBounds = NW_LMgr_Box_GetFormatBounds( box );
       
   188 
       
   189   boxBounds.dimension.width = 0;
       
   190 
       
   191   NW_LMgr_Box_SetFormatBounds( box, boxBounds );
       
   192 
       
   193   return KBrsrSuccess;
       
   194 
       
   195 }
       
   196 
       
   197 /* ------------------------------------------------------------------------- */
       
   198 NW_GDI_Metric_t
       
   199 _NW_LMgr_BreakBox_GetBaseline(NW_LMgr_Box_t* box){
       
   200 
       
   201   CGDIFont *font;
       
   202 
       
   203   /* Set the height to font height */
       
   204   font = NW_LMgr_Box_GetFont (box);
       
   205   if (font != NULL) 
       
   206     {
       
   207     TGDIFontInfo fontInfo;
       
   208 
       
   209     TBrowserStatusCode status = font->GetFontInfo ( &fontInfo);
       
   210     NW_ASSERT (status == KBrsrSuccess);
       
   211 		/* To fix TI compiler warning */
       
   212 		(void) status; 
       
   213 
       
   214     return fontInfo.baseline;
       
   215     }
       
   216   else 
       
   217     {
       
   218 	  NW_ASSERT(0);
       
   219     }
       
   220 
       
   221   return KBrsrSuccess;
       
   222   }
       
   223 
       
   224 /* ------------------------------------------------------------------------- */
       
   225 
       
   226 TBrowserStatusCode
       
   227 _NW_LMgr_BreakBox_Draw (NW_LMgr_Box_t* box,
       
   228                    CGDIDeviceContext* deviceContext,
       
   229                    NW_Uint8 hasFocus) {
       
   230 
       
   231   NW_REQUIRED_PARAM (box);
       
   232   NW_REQUIRED_PARAM (deviceContext);
       
   233   NW_REQUIRED_PARAM (hasFocus);
       
   234 
       
   235   return KBrsrSuccess;
       
   236 }
       
   237 
       
   238 /* -------------------------------------------------------------------------
       
   239   convenience functions
       
   240  * ------------------------------------------------------------------------- */
       
   241 
       
   242 /* ------------------------------------------------------------------------- */
       
   243 NW_LMgr_BreakBox_t*
       
   244 NW_LMgr_BreakBox_New (NW_ADT_Vector_Metric_t numProperties)
       
   245 {
       
   246   return (NW_LMgr_BreakBox_t*)
       
   247     NW_Object_New (&NW_LMgr_BreakBox_Class, numProperties);
       
   248 }
       
   249