2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/* rendering object for HTML <br> elements */
|
|
|
|
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsFrame.h"
|
|
|
|
#include "nsHTMLParts.h"
|
|
|
|
#include "nsPresContext.h"
|
|
|
|
#include "nsLineLayout.h"
|
|
|
|
#include "nsStyleConsts.h"
|
|
|
|
#include "nsGkAtoms.h"
|
2011-04-07 18:04:40 -07:00
|
|
|
#include "nsRenderingContext.h"
|
2007-05-04 23:09:50 -07:00
|
|
|
#include "nsLayoutUtils.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
|
|
|
#include "nsIServiceManager.h"
|
2011-01-27 20:38:14 -08:00
|
|
|
#include "nsAccessibilityService.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//FOR SELECTION
|
|
|
|
#include "nsIContent.h"
|
|
|
|
#include "nsFrameSelection.h"
|
|
|
|
//END INCLUDES FOR SELECTION
|
|
|
|
|
|
|
|
class BRFrame : public nsFrame {
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
friend nsIFrame* NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
|
|
|
|
|
|
|
|
virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint);
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool PeekOffsetNoAmount(bool aForward, PRInt32* aOffset);
|
|
|
|
virtual bool PeekOffsetCharacter(bool aForward, PRInt32* aOffset,
|
|
|
|
bool aRespectClusters = true);
|
|
|
|
virtual bool PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
|
2007-08-29 20:10:19 -07:00
|
|
|
PRInt32* aOffset, PeekWordState* aState);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
NS_IMETHOD Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus);
|
2011-04-07 18:04:40 -07:00
|
|
|
virtual void AddInlineMinWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
InlineMinWidthData *aData);
|
2011-04-07 18:04:40 -07:00
|
|
|
virtual void AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
InlinePrefWidthData *aData);
|
2011-04-07 18:04:40 -07:00
|
|
|
virtual nscoord GetMinWidth(nsRenderingContext *aRenderingContext);
|
|
|
|
virtual nscoord GetPrefWidth(nsRenderingContext *aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual nsIAtom* GetType() const;
|
2010-08-31 11:54:44 -07:00
|
|
|
virtual nscoord GetBaseline() const;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
virtual bool IsFrameOfType(PRUint32 aFlags) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-05-17 23:04:04 -07:00
|
|
|
return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced |
|
|
|
|
nsIFrame::eLineParticipant));
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-06-28 05:02:03 -07:00
|
|
|
#ifdef ACCESSIBILITY
|
2012-05-28 18:18:45 -07:00
|
|
|
virtual already_AddRefed<Accessible> CreateAccessible();
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
BRFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
|
|
|
|
virtual ~BRFrame();
|
2011-11-23 18:48:23 -08:00
|
|
|
|
|
|
|
nscoord mAscent;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
nsIFrame*
|
|
|
|
NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
|
|
|
|
{
|
|
|
|
return new (aPresShell) BRFrame(aContext);
|
|
|
|
}
|
|
|
|
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(BRFrame)
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
BRFrame::~BRFrame()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
BRFrame::Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aMetrics,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus)
|
|
|
|
{
|
|
|
|
DO_GLOBAL_REFLOW_COUNT("BRFrame");
|
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
|
|
|
|
aMetrics.height = 0; // BR frames with height 0 are ignored in quirks
|
|
|
|
// mode by nsLineLayout::VerticalAlignFrames .
|
|
|
|
// However, it's not always 0. See below.
|
|
|
|
aMetrics.width = 0;
|
|
|
|
aMetrics.ascent = 0;
|
|
|
|
|
|
|
|
// Only when the BR is operating in a line-layout situation will it
|
|
|
|
// behave like a BR.
|
|
|
|
nsLineLayout* ll = aReflowState.mLineLayout;
|
|
|
|
if (ll) {
|
|
|
|
// Note that the compatibility mode check excludes AlmostStandards
|
|
|
|
// mode, since this is the inline box model. See bug 161691.
|
2008-06-14 01:28:07 -07:00
|
|
|
if ( ll->LineIsEmpty() ||
|
2007-10-01 19:36:26 -07:00
|
|
|
aPresContext->CompatibilityMode() == eCompatibility_FullStandards ) {
|
2008-06-14 01:28:07 -07:00
|
|
|
// The line is logically empty; any whitespace is trimmed away.
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// If this frame is going to terminate the line we know
|
|
|
|
// that nothing else will go on the line. Therefore, in this
|
|
|
|
// 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
|
2009-04-22 10:13:48 -07:00
|
|
|
// here for cases where the line-height is less than 1.
|
2011-08-14 10:08:04 -07:00
|
|
|
nsRefPtr<nsFontMetrics> fm;
|
2011-11-23 18:48:23 -08:00
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fm),
|
2012-05-20 22:18:28 -07:00
|
|
|
nsLayoutUtils::FontSizeInflationFor(this));
|
2011-08-14 10:08:04 -07:00
|
|
|
aReflowState.rendContext->SetFont(fm); // FIXME: maybe not needed?
|
2007-03-22 10:30:00 -07:00
|
|
|
if (fm) {
|
2009-05-18 15:13:12 -07:00
|
|
|
nscoord logicalHeight = aReflowState.CalcLineHeight();
|
2007-03-22 10:30:00 -07:00
|
|
|
aMetrics.height = logicalHeight;
|
2009-05-18 15:13:12 -07:00
|
|
|
aMetrics.ascent =
|
|
|
|
nsLayoutUtils::GetCenteredFontBaseline(fm, logicalHeight);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aMetrics.ascent = aMetrics.height = 0;
|
|
|
|
}
|
2008-06-16 15:39:30 -07:00
|
|
|
|
|
|
|
// 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!
|
|
|
|
// Warning: nsTextControlFrame::CalculateSizeStandard depends on
|
|
|
|
// the following line, see bug 228752.
|
|
|
|
aMetrics.width = 1;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
// Return our reflow status
|
|
|
|
PRUint32 breakType = aReflowState.mStyleDisplay->mBreakType;
|
|
|
|
if (NS_STYLE_CLEAR_NONE == breakType) {
|
|
|
|
breakType = NS_STYLE_CLEAR_LINE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aStatus = NS_INLINE_BREAK | NS_INLINE_BREAK_AFTER |
|
|
|
|
NS_INLINE_MAKE_BREAK_TYPE(breakType);
|
2011-10-17 07:59:28 -07:00
|
|
|
ll->SetLineEndsInBR(true);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
aStatus = NS_FRAME_COMPLETE;
|
|
|
|
}
|
2010-10-06 21:25:46 -07:00
|
|
|
|
|
|
|
aMetrics.SetOverflowAreasToDesiredBounds();
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-11-23 18:48:23 -08:00
|
|
|
mAscent = aMetrics.ascent;
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
BRFrame::AddInlineMinWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlineMinWidthData *aData)
|
|
|
|
{
|
2007-06-21 15:32:47 -07:00
|
|
|
aData->ForceBreak(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ void
|
2011-04-07 18:04:40 -07:00
|
|
|
BRFrame::AddInlinePrefWidth(nsRenderingContext *aRenderingContext,
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::InlinePrefWidthData *aData)
|
|
|
|
{
|
2007-06-21 15:32:47 -07:00
|
|
|
aData->ForceBreak(aRenderingContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
BRFrame::GetMinWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_MIN_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* virtual */ nscoord
|
2011-04-07 18:04:40 -07:00
|
|
|
BRFrame::GetPrefWidth(nsRenderingContext *aRenderingContext)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
nscoord result = 0;
|
|
|
|
DISPLAY_PREF_WIDTH(this, result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIAtom*
|
|
|
|
BRFrame::GetType() const
|
|
|
|
{
|
|
|
|
return nsGkAtoms::brFrame;
|
|
|
|
}
|
|
|
|
|
2010-08-31 11:54:44 -07:00
|
|
|
nscoord
|
|
|
|
BRFrame::GetBaseline() const
|
|
|
|
{
|
2011-11-23 18:48:23 -08:00
|
|
|
return mAscent;
|
2010-08-31 11:54:44 -07:00
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
nsIFrame::ContentOffsets BRFrame::CalcContentOffsetsFromFramePoint(nsPoint aPoint)
|
|
|
|
{
|
|
|
|
ContentOffsets offsets;
|
|
|
|
offsets.content = mContent->GetParent();
|
|
|
|
if (offsets.content) {
|
|
|
|
offsets.offset = offsets.content->IndexOf(mContent);
|
|
|
|
offsets.secondaryOffset = offsets.offset;
|
2011-10-17 07:59:28 -07:00
|
|
|
offsets.associateWithNext = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
return offsets;
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
BRFrame::PeekOffsetNoAmount(bool aForward, PRInt32* aOffset)
|
2007-03-22 10:30:00 -07: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;
|
2011-10-17 07:59:28 -07:00
|
|
|
return true;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
// Otherwise, stop if we hit the beginning, continue (forward) if we hit the end.
|
|
|
|
return (startOffset == 0);
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
BRFrame::PeekOffsetCharacter(bool aForward, PRInt32* aOffset,
|
|
|
|
bool aRespectClusters)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
|
|
|
|
// Keep going. The actual line jumping will stop us.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
bool
|
|
|
|
BRFrame::PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
|
2007-08-29 20:10:19 -07:00
|
|
|
PRInt32* aOffset, PeekWordState* aState)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
|
|
|
|
// Keep going. The actual line jumping will stop us.
|
2011-10-17 07:59:28 -07:00
|
|
|
return false;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-05-28 18:18:45 -07:00
|
|
|
already_AddRefed<Accessible>
|
2010-06-28 05:02:03 -07:00
|
|
|
BRFrame::CreateAccessible()
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2011-01-27 20:38:14 -08:00
|
|
|
nsAccessibilityService* accService = nsIPresShell::AccService();
|
2010-06-28 05:02:03 -07:00
|
|
|
if (!accService) {
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2010-06-28 05:02:03 -07:00
|
|
|
}
|
2008-07-22 21:50:20 -07:00
|
|
|
nsIContent *parent = mContent->GetParent();
|
|
|
|
if (parent &&
|
|
|
|
parent->IsRootOfNativeAnonymousSubtree() &&
|
|
|
|
parent->GetChildCount() == 1) {
|
2008-01-14 06:34:40 -08:00
|
|
|
// This <br> is the only node in a text control, therefore it is the hacky
|
|
|
|
// "bogus node" used when there is no text in the control
|
2012-07-30 07:20:58 -07:00
|
|
|
return nullptr;
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
2010-06-28 05:02:03 -07:00
|
|
|
return accService->CreateHTMLBRAccessible(mContent,
|
|
|
|
PresContext()->PresShell());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|