LCOV - code coverage report
Current view: directory - layout/generic - nsBRFrame.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 85 0 0.0 %
Date: 2012-06-02 Functions: 19 0 0.0 %

       1                 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      26                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : /* rendering object for HTML <br> elements */
      39                 : 
      40                 : #include "nsCOMPtr.h"
      41                 : #include "nsFrame.h"
      42                 : #include "nsHTMLParts.h"
      43                 : #include "nsPresContext.h"
      44                 : #include "nsLineLayout.h"
      45                 : #include "nsStyleConsts.h"
      46                 : #include "nsGkAtoms.h"
      47                 : #include "nsRenderingContext.h"
      48                 : #include "nsLayoutUtils.h"
      49                 : 
      50                 : #ifdef ACCESSIBILITY
      51                 : #include "nsIServiceManager.h"
      52                 : #include "nsAccessibilityService.h"
      53                 : #endif
      54                 : 
      55                 : //FOR SELECTION
      56                 : #include "nsIContent.h"
      57                 : #include "nsFrameSelection.h"
      58                 : //END INCLUDES FOR SELECTION
      59                 : 
      60                 : class BRFrame : public nsFrame {
      61                 : public:
      62                 :   NS_DECL_FRAMEARENA_HELPERS
      63                 : 
      64                 :   friend nsIFrame* NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
      65                 : 
      66                 :   virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint);
      67                 : 
      68                 :   virtual bool PeekOffsetNoAmount(bool aForward, PRInt32* aOffset);
      69                 :   virtual bool PeekOffsetCharacter(bool aForward, PRInt32* aOffset,
      70                 :                                      bool aRespectClusters = true);
      71                 :   virtual bool PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
      72                 :                                 PRInt32* aOffset, PeekWordState* aState);
      73                 : 
      74                 :   NS_IMETHOD Reflow(nsPresContext* aPresContext,
      75                 :                     nsHTMLReflowMetrics& aDesiredSize,
      76                 :                     const nsHTMLReflowState& aReflowState,
      77                 :                     nsReflowStatus& aStatus);
      78                 :   virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext,
      79                 :                                  InlineMinWidthData *aData);
      80                 :   virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
      81                 :                                   InlinePrefWidthData *aData);
      82                 :   virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
      83                 :   virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
      84                 :   virtual nsIAtom* GetType() const;
      85                 :   virtual nscoord GetBaseline() const;
      86                 : 
      87               0 :   virtual bool IsFrameOfType(PRUint32 aFlags) const
      88                 :   {
      89                 :     return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced |
      90               0 :                                              nsIFrame::eLineParticipant));
      91                 :   }
      92                 : 
      93                 : #ifdef ACCESSIBILITY
      94                 :   virtual already_AddRefed<nsAccessible> CreateAccessible();
      95                 : #endif
      96                 : 
      97                 : protected:
      98               0 :   BRFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
      99                 :   virtual ~BRFrame();
     100                 : 
     101                 :   nscoord mAscent;
     102                 : };
     103                 : 
     104                 : nsIFrame*
     105               0 : NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
     106                 : {
     107               0 :   return new (aPresShell) BRFrame(aContext);
     108                 : }
     109                 : 
     110               0 : NS_IMPL_FRAMEARENA_HELPERS(BRFrame)
     111                 : 
     112               0 : BRFrame::~BRFrame()
     113                 : {
     114               0 : }
     115                 : 
     116                 : NS_IMETHODIMP
     117               0 : BRFrame::Reflow(nsPresContext* aPresContext,
     118                 :                 nsHTMLReflowMetrics& aMetrics,
     119                 :                 const nsHTMLReflowState& aReflowState,
     120                 :                 nsReflowStatus& aStatus)
     121                 : {
     122               0 :   DO_GLOBAL_REFLOW_COUNT("BRFrame");
     123               0 :   DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
     124               0 :   aMetrics.height = 0; // BR frames with height 0 are ignored in quirks
     125                 :                        // mode by nsLineLayout::VerticalAlignFrames .
     126                 :                        // However, it's not always 0.  See below.
     127               0 :   aMetrics.width = 0;
     128               0 :   aMetrics.ascent = 0;
     129                 : 
     130                 :   // Only when the BR is operating in a line-layout situation will it
     131                 :   // behave like a BR.
     132               0 :   nsLineLayout* ll = aReflowState.mLineLayout;
     133               0 :   if (ll) {
     134                 :     // Note that the compatibility mode check excludes AlmostStandards
     135                 :     // mode, since this is the inline box model.  See bug 161691.
     136               0 :     if ( ll->LineIsEmpty() ||
     137               0 :          aPresContext->CompatibilityMode() == eCompatibility_FullStandards ) {
     138                 :       // The line is logically empty; any whitespace is trimmed away.
     139                 :       //
     140                 :       // If this frame is going to terminate the line we know
     141                 :       // that nothing else will go on the line. Therefore, in this
     142                 :       // case, we provide some height for the BR frame so that it
     143                 :       // creates some vertical whitespace.  It's necessary to use the
     144                 :       // line-height rather than the font size because the
     145                 :       // quirks-mode fix that doesn't apply the block's min
     146                 :       // line-height makes this necessary to make BR cause a line
     147                 :       // of the full line-height
     148                 : 
     149                 :       // We also do this in strict mode because BR should act like a
     150                 :       // normal inline frame.  That line-height is used is important
     151                 :       // here for cases where the line-height is less than 1.
     152               0 :       nsRefPtr<nsFontMetrics> fm;
     153                 :       nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
     154               0 :         nsLayoutUtils::FontSizeInflationFor(this, nsLayoutUtils::eInReflow));
     155               0 :       aReflowState.rendContext->SetFont(fm); // FIXME: maybe not needed?
     156               0 :       if (fm) {
     157               0 :         nscoord logicalHeight = aReflowState.CalcLineHeight();
     158               0 :         aMetrics.height = logicalHeight;
     159                 :         aMetrics.ascent =
     160               0 :           nsLayoutUtils::GetCenteredFontBaseline(fm, logicalHeight);
     161                 :       }
     162                 :       else {
     163               0 :         aMetrics.ascent = aMetrics.height = 0;
     164                 :       }
     165                 : 
     166                 :       // XXX temporary until I figure out a better solution; see the
     167                 :       // code in nsLineLayout::VerticalAlignFrames that zaps minY/maxY
     168                 :       // if the width is zero.
     169                 :       // XXX This also fixes bug 10036!
     170                 :       // Warning: nsTextControlFrame::CalculateSizeStandard depends on
     171                 :       // the following line, see bug 228752.
     172               0 :       aMetrics.width = 1;
     173                 :     }
     174                 : 
     175                 :     // Return our reflow status
     176               0 :     PRUint32 breakType = aReflowState.mStyleDisplay->mBreakType;
     177               0 :     if (NS_STYLE_CLEAR_NONE == breakType) {
     178               0 :       breakType = NS_STYLE_CLEAR_LINE;
     179                 :     }
     180                 : 
     181                 :     aStatus = NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |
     182               0 :       NS_INLINE_MAKE_BREAK_TYPE(breakType);
     183               0 :     ll->SetLineEndsInBR(true);
     184                 :   }
     185                 :   else {
     186               0 :     aStatus = NS_FRAME_COMPLETE;
     187                 :   }
     188                 : 
     189               0 :   aMetrics.SetOverflowAreasToDesiredBounds();
     190                 : 
     191               0 :   mAscent = aMetrics.ascent;
     192                 : 
     193               0 :   NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
     194               0 :   return NS_OK;
     195                 : }
     196                 : 
     197                 : /* virtual */ void
     198               0 : BRFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext,
     199                 :                            nsIFrame::InlineMinWidthData *aData)
     200                 : {
     201               0 :   aData->ForceBreak(aRenderingContext);
     202               0 : }
     203                 : 
     204                 : /* virtual */ void
     205               0 : BRFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
     206                 :                             nsIFrame::InlinePrefWidthData *aData)
     207                 : {
     208               0 :   aData->ForceBreak(aRenderingContext);
     209               0 : }
     210                 : 
     211                 : /* virtual */ nscoord
     212               0 : BRFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
     213                 : {
     214               0 :   nscoord result = 0;
     215               0 :   DISPLAY_MIN_WIDTH(this, result);
     216               0 :   return result;
     217                 : }
     218                 : 
     219                 : /* virtual */ nscoord
     220               0 : BRFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
     221                 : {
     222               0 :   nscoord result = 0;
     223               0 :   DISPLAY_PREF_WIDTH(this, result);
     224               0 :   return result;
     225                 : }
     226                 : 
     227                 : nsIAtom*
     228               0 : BRFrame::GetType() const
     229                 : {
     230               0 :   return nsGkAtoms::brFrame;
     231                 : }
     232                 : 
     233                 : nscoord
     234               0 : BRFrame::GetBaseline() const
     235                 : {
     236               0 :   return mAscent;
     237                 : }
     238                 : 
     239               0 : nsIFrame::ContentOffsets BRFrame::CalcContentOffsetsFromFramePoint(nsPoint aPoint)
     240                 : {
     241               0 :   ContentOffsets offsets;
     242               0 :   offsets.content = mContent->GetParent();
     243               0 :   if (offsets.content) {
     244               0 :     offsets.offset = offsets.content->IndexOf(mContent);
     245               0 :     offsets.secondaryOffset = offsets.offset;
     246               0 :     offsets.associateWithNext = true;
     247                 :   }
     248                 :   return offsets;
     249                 : }
     250                 : 
     251                 : bool
     252               0 : BRFrame::PeekOffsetNoAmount(bool aForward, PRInt32* aOffset)
     253                 : {
     254               0 :   NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
     255               0 :   PRInt32 startOffset = *aOffset;
     256                 :   // If we hit the end of a BR going backwards, go to its beginning and stay there.
     257               0 :   if (!aForward && startOffset != 0) {
     258               0 :     *aOffset = 0;
     259               0 :     return true;
     260                 :   }
     261                 :   // Otherwise, stop if we hit the beginning, continue (forward) if we hit the end.
     262               0 :   return (startOffset == 0);
     263                 : }
     264                 : 
     265                 : bool
     266               0 : BRFrame::PeekOffsetCharacter(bool aForward, PRInt32* aOffset,
     267                 :                              bool aRespectClusters)
     268                 : {
     269               0 :   NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
     270                 :   // Keep going. The actual line jumping will stop us.
     271               0 :   return false;
     272                 : }
     273                 : 
     274                 : bool
     275               0 : BRFrame::PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
     276                 :                         PRInt32* aOffset, PeekWordState* aState)
     277                 : {
     278               0 :   NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
     279                 :   // Keep going. The actual line jumping will stop us.
     280               0 :   return false;
     281                 : }
     282                 : 
     283                 : #ifdef ACCESSIBILITY
     284                 : already_AddRefed<nsAccessible>
     285               0 : BRFrame::CreateAccessible()
     286                 : {
     287               0 :   nsAccessibilityService* accService = nsIPresShell::AccService();
     288               0 :   if (!accService) {
     289               0 :     return nsnull;
     290                 :   }
     291               0 :   nsIContent *parent = mContent->GetParent();
     292               0 :   if (parent &&
     293               0 :       parent->IsRootOfNativeAnonymousSubtree() &&
     294               0 :       parent->GetChildCount() == 1) {
     295                 :     // This <br> is the only node in a text control, therefore it is the hacky
     296                 :     // "bogus node" used when there is no text in the control
     297               0 :     return nsnull;
     298                 :   }
     299                 :   return accService->CreateHTMLBRAccessible(mContent,
     300               0 :                                             PresContext()->PresShell());
     301                 : }
     302                 : #endif
     303                 : 

Generated by: LCOV version 1.7