2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:30:37 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1998-09-09 02:34:40 +04: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/
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1998-09-09 02:34:40 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:30:37 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 06:40:37 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:30:37 +04:00
|
|
|
* 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"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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
|
2004-04-18 18:30:37 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
2006-03-29 22:29:03 +04:00
|
|
|
|
|
|
|
/* rendering object for HTML <br> elements */
|
|
|
|
|
1999-09-10 00:53:18 +04:00
|
|
|
#include "nsCOMPtr.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
2004-08-01 03:15:21 +04:00
|
|
|
#include "nsPresContext.h"
|
1998-09-15 04:19:49 +04:00
|
|
|
#include "nsLineLayout.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsStyleConsts.h"
|
2007-01-30 03:06:41 +03:00
|
|
|
#include "nsGkAtoms.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
#include "nsIFontMetrics.h"
|
|
|
|
#include "nsIRenderingContext.h"
|
2007-05-05 10:09:50 +04:00
|
|
|
#include "nsLayoutUtils.h"
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2006-07-12 17:51:50 +04:00
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIAccessible.h"
|
|
|
|
#include "nsIAccessibilityService.h"
|
|
|
|
#endif
|
|
|
|
|
1999-11-23 23:30:21 +03:00
|
|
|
//FOR SELECTION
|
|
|
|
#include "nsIContent.h"
|
2006-04-26 06:01:07 +04:00
|
|
|
#include "nsFrameSelection.h"
|
1999-11-23 23:30:21 +03:00
|
|
|
//END INCLUDES FOR SELECTION
|
|
|
|
|
1998-10-03 08:28:05 +04:00
|
|
|
class BRFrame : public nsFrame {
|
1998-09-09 02:34:40 +04:00
|
|
|
public:
|
2006-03-27 01:30:36 +04:00
|
|
|
friend nsIFrame* NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
2006-02-27 08:57:37 +03:00
|
|
|
virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint);
|
2005-12-08 02:08:39 +03:00
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
virtual PRBool PeekOffsetNoAmount(PRBool aForward, PRInt32* aOffset);
|
|
|
|
virtual PRBool PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset);
|
|
|
|
virtual PRBool PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsKeyboardSelect,
|
2007-03-23 02:01:14 +03:00
|
|
|
PRInt32* aOffset, PRBool* aSawBeforeType);
|
1998-09-09 02:34:40 +04:00
|
|
|
|
2004-08-01 03:15:21 +04:00
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
1999-11-23 23:30:21 +03:00
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
virtual void AddInlineMinWidth(nsIRenderingContext *aRenderingContext,
|
|
|
|
InlineMinWidthData *aData);
|
|
|
|
virtual void AddInlinePrefWidth(nsIRenderingContext *aRenderingContext,
|
|
|
|
InlinePrefWidthData *aData);
|
|
|
|
virtual nscoord GetMinWidth(nsIRenderingContext *aRenderingContext);
|
|
|
|
virtual nscoord GetPrefWidth(nsIRenderingContext *aRenderingContext);
|
2003-10-31 23:19:18 +03:00
|
|
|
virtual nsIAtom* GetType() const;
|
2007-02-24 21:33:33 +03:00
|
|
|
|
|
|
|
virtual PRBool IsFrameOfType(PRUint32 aFlags) const
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced));
|
2007-02-24 21:33:33 +03:00
|
|
|
}
|
2006-07-12 18:35:43 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2006-07-12 17:51:50 +04:00
|
|
|
NS_IMETHOD GetAccessible(nsIAccessible** aAccessible);
|
2006-07-12 18:35:43 +04:00
|
|
|
#endif
|
2006-07-12 17:51:50 +04:00
|
|
|
|
1998-09-09 02:34:40 +04:00
|
|
|
protected:
|
2006-03-27 01:30:36 +04:00
|
|
|
BRFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
|
1998-09-09 02:34:40 +04:00
|
|
|
virtual ~BRFrame();
|
|
|
|
};
|
|
|
|
|
2005-11-01 23:40:54 +03:00
|
|
|
nsIFrame*
|
2006-03-27 01:30:36 +04:00
|
|
|
NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
2006-03-27 01:30:36 +04:00
|
|
|
return new (aPresShell) BRFrame(aContext);
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
BRFrame::~BRFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2004-08-01 03:15:21 +04:00
|
|
|
BRFrame::Reflow(nsPresContext* aPresContext,
|
1998-10-03 08:28:05 +04:00
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
1998-09-09 02:34:40 +04:00
|
|
|
{
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("BRFrame");
|
2001-11-14 16:40:03 +03:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
2000-02-15 07:26:44 +03:00
|
|
|
aMetrics.height = 0; // BR frames with height 0 are ignored in quirks
|
|
|
|
// mode by nsLineLayout::VerticalAlignFrames .
|
|
|
|
// However, it's not always 0. See below.
|
1998-09-09 02:34:40 +04:00
|
|
|
aMetrics.width = 0;
|
1998-10-03 01:49:47 +04:00
|
|
|
aMetrics.ascent = 0;
|
1998-09-09 02:34:40 +04:00
|
|
|
|
1999-03-26 03:37:22 +03:00
|
|
|
// Only when the BR is operating in a line-layout situation will it
|
|
|
|
// behave like a BR.
|
1999-10-29 18:32:11 +04:00
|
|
|
nsLineLayout* ll = aReflowState.mLineLayout;
|
|
|
|
if (ll) {
|
2002-08-11 22:00:07 +04:00
|
|
|
// Note that the compatibility mode check excludes AlmostStandards
|
|
|
|
// mode, since this is the inline box model. See bug 161691.
|
2003-10-14 01:51:02 +04:00
|
|
|
if ( ll->CanPlaceFloatNow() ||
|
2007-03-23 02:01:14 +03:00
|
|
|
ll->GetCompatMode() == eCompatibility_FullStandards ) {
|
2003-10-14 01:51:02 +04:00
|
|
|
// If we can place a float on the line now it means that the
|
1999-04-03 22:57:30 +04:00
|
|
|
// line is effectively empty (there may be zero sized compressed
|
|
|
|
// white-space frames on the line, but they are to be ignored).
|
|
|
|
//
|
2000-02-15 07:26:44 +03:00
|
|
|
// If this frame is going to terminate the line we know
|
1999-04-03 22:57:30 +04:00
|
|
|
// that nothing else will go on the line. Therefore, in this
|
2000-02-15 07:26:44 +03:00
|
|
|
// case, we provide some height for the BR frame so that it
|
|
|
|
// creates some vertical whitespace. It's necessary to use the
|
|
|
|
// line-height rather than the font size because the
|
|
|
|
// quirks-mode fix that doesn't apply the block's min
|
|
|
|
// line-height makes this necessary to make BR cause a line
|
|
|
|
// of the full line-height
|
|
|
|
|
|
|
|
// We also do this in strict mode because BR should act like a
|
|
|
|
// normal inline frame. That line-height is used is important
|
|
|
|
// here for cases where the line-height is less that 1.
|
2007-05-05 10:09:50 +04:00
|
|
|
nsLayoutUtils::SetFontFromStyle(aReflowState.rendContext, mStyleContext);
|
1999-09-10 00:53:18 +04:00
|
|
|
nsCOMPtr<nsIFontMetrics> fm;
|
|
|
|
aReflowState.rendContext->GetFontMetrics(*getter_AddRefs(fm));
|
|
|
|
if (fm) {
|
2000-02-15 07:26:44 +03:00
|
|
|
nscoord ascent, descent;
|
|
|
|
fm->GetMaxAscent(ascent);
|
|
|
|
fm->GetMaxDescent(descent);
|
|
|
|
nscoord logicalHeight =
|
2007-05-05 09:30:10 +04:00
|
|
|
aReflowState.CalcLineHeight(aReflowState.rendContext, this);
|
2000-02-15 07:26:44 +03:00
|
|
|
nscoord leading = logicalHeight - ascent - descent;
|
|
|
|
aMetrics.height = logicalHeight;
|
|
|
|
aMetrics.ascent = ascent + (leading/2);
|
1999-09-10 00:53:18 +04:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMetrics.ascent = aMetrics.height = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX temporary until I figure out a better solution; see the
|
|
|
|
// code in nsLineLayout::VerticalAlignFrames that zaps minY/maxY
|
|
|
|
// if the width is zero.
|
|
|
|
// XXX This also fixes bug 10036!
|
2003-12-18 09:06:00 +03:00
|
|
|
// Warning: nsTextControlFrame::CalculateSizeStandard depends on
|
|
|
|
// the following line, see bug 228752.
|
1999-09-10 00:53:18 +04:00
|
|
|
aMetrics.width = 1;
|
1999-04-03 22:57:30 +04:00
|
|
|
}
|
1999-03-26 03:37:22 +03:00
|
|
|
|
|
|
|
// Return our reflow status
|
|
|
|
PRUint32 breakType = aReflowState.mStyleDisplay->mBreakType;
|
|
|
|
if (NS_STYLE_CLEAR_NONE == breakType) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LINE;
|
|
|
|
}
|
1998-10-03 08:28:05 +04:00
|
|
|
|
1999-03-26 03:37:22 +03:00
|
|
|
aStatus = NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |
|
|
|
|
NS_INLINE_MAKE_BREAK_TYPE(breakType);
|
1999-10-29 18:32:11 +04:00
|
|
|
ll->SetLineEndsInBR(PR_TRUE);
|
1999-03-26 03:37:22 +03:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
2002-05-29 02:50:43 +04:00
|
|
|
|
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
1998-10-03 08:28:05 +04:00
|
|
|
return NS_OK;
|
1998-09-09 02:34:40 +04:00
|
|
|
}
|
1999-06-20 00:36:44 +04:00
|
|
|
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
/* virtual */ void
|
|
|
|
BRFrame::AddInlineMinWidth(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsIFrame::InlineMinWidthData *aData)
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
aData->Break(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
|
|
|
BRFrame::AddInlinePrefWidth(nsIRenderingContext *aRenderingContext,
|
|
|
|
nsIFrame::InlinePrefWidthData *aData)
|
|
|
|
{
|
2007-03-23 02:01:14 +03:00
|
|
|
aData->Break(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 08:38:33 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
BRFrame::GetMinWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
|
|
|
BRFrame::GetPrefWidth(nsIRenderingContext *aRenderingContext)
|
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2003-10-31 23:19:18 +03:00
|
|
|
nsIAtom*
|
|
|
|
BRFrame::GetType() const
|
2000-02-15 07:26:44 +03:00
|
|
|
{
|
2006-12-26 20:47:52 +03:00
|
|
|
return nsGkAtoms::brFrame;
|
2000-02-15 07:26:44 +03:00
|
|
|
}
|
1999-06-20 00:36:44 +04:00
|
|
|
|
2006-02-27 08:57:37 +03:00
|
|
|
nsIFrame::ContentOffsets BRFrame::CalcContentOffsetsFromFramePoint(nsPoint aPoint)
|
1999-09-30 00:04:05 +04:00
|
|
|
{
|
2006-02-27 08:57:37 +03:00
|
|
|
ContentOffsets offsets;
|
|
|
|
offsets.content = mContent->GetParent();
|
|
|
|
if (offsets.content) {
|
|
|
|
offsets.offset = offsets.content->IndexOf(mContent);
|
|
|
|
offsets.secondaryOffset = offsets.offset;
|
|
|
|
offsets.associateWithNext = PR_TRUE;
|
2005-12-08 02:08:39 +03:00
|
|
|
}
|
2006-02-27 08:57:37 +03:00
|
|
|
return offsets;
|
1999-11-23 23:30:21 +03:00
|
|
|
}
|
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
PRBool
|
|
|
|
BRFrame::PeekOffsetNoAmount(PRBool aForward, PRInt32* aOffset)
|
1999-11-23 23:30:21 +03:00
|
|
|
{
|
2006-09-12 00:43:01 +04:00
|
|
|
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
|
|
|
|
PRInt32 startOffset = *aOffset;
|
|
|
|
// If we hit the end of a BR going backwards, go to its beginning and stay there.
|
|
|
|
if (!aForward && startOffset != 0) {
|
|
|
|
*aOffset = 0;
|
|
|
|
return PR_TRUE;
|
2006-07-12 02:11:02 +04:00
|
|
|
}
|
2006-09-12 00:43:01 +04:00
|
|
|
// Otherwise, stop if we hit the beginning, continue (forward) if we hit the end.
|
|
|
|
return (startOffset == 0);
|
|
|
|
}
|
2005-09-19 09:16:25 +04:00
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
PRBool
|
|
|
|
BRFrame::PeekOffsetCharacter(PRBool aForward, PRInt32* aOffset)
|
|
|
|
{
|
|
|
|
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
|
|
|
|
// Keep going. The actual line jumping will stop us.
|
|
|
|
return PR_FALSE;
|
|
|
|
}
|
1999-11-23 23:30:21 +03:00
|
|
|
|
2006-09-12 00:43:01 +04:00
|
|
|
PRBool
|
|
|
|
BRFrame::PeekOffsetWord(PRBool aForward, PRBool aWordSelectEatSpace, PRBool aIsKeyboardSelect,
|
2007-03-23 02:01:14 +03:00
|
|
|
PRInt32* aOffset, PRBool* aSawBeforeType)
|
2006-09-12 00:43:01 +04:00
|
|
|
{
|
|
|
|
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
|
|
|
|
// Keep going. The actual line jumping will stop us.
|
|
|
|
return PR_FALSE;
|
1999-09-30 00:04:05 +04:00
|
|
|
}
|
2006-07-12 17:51:50 +04:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
NS_IMETHODIMP BRFrame::GetAccessible(nsIAccessible** aAccessible)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIAccessibilityService> accService = do_GetService("@mozilla.org/accessibilityService;1");
|
2007-03-23 02:01:14 +03:00
|
|
|
if (accService) {
|
|
|
|
return accService->CreateHTMLBRAccessible(NS_STATIC_CAST(nsIFrame*, this), aAccessible);
|
2006-07-12 17:51:50 +04:00
|
|
|
}
|
2007-03-23 02:01:14 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2006-07-12 17:51:50 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|