Files
roytam1 7127a02a35 import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1256424. Get rid of ThreadsafeAutoSafeJSContext. r=bholley (445aa7dd4b)
- Bug 1256424 followup to actually address the review comments (d085cf1900)
- Bug 1003432: Expose CustomEvent in Worker. r=smaug (3b143dc6e4)
- Bug 1256414 - Hide MozSettingsEvent from the Web; r=khuey (52fe18e823)
- Bug 1257038: Remove the worker descriptor for WorkerLocation. r=bz (2b9721e4fe)
- Bug 1257039: Remove the worker descriptor for FileReaderSync. r=bz (cc33ce76e6)
- Bug 1257355: Remove the worker descriptor for WorkerNavigator. r=bz (067f1fc9ea)
- Bug 1257480 - null check for GetOrCreateGlobalScope() in WorkerDebuggerGlobalScope, r=khuey (0d3d640fc0)
- Make split-profile run jprof in the directory with the jprof-log. No bug. (58f5060e39)
- Bug 1250333 - do not create accessibles for trailing BRs, r=davidb, roc (d8e1193adc)
- Bug 1251712 - propagate a context flag for alerts, r=davdib (d5ef6167ea)
- Bug 1251752 - logging: add tree specific methods, r=yzen (f974c207ca)
- Bug 1251218 - add special TreeWalker constructor for children creation, r=marcoz (74f939b93e)
- Bug 1251337 - TreeWalker doesn't have to check ARIA owned children for each DOM state, r=yzen (19d83af7e1)
- Bug 1249730 - make TreeWalker bi-directional, r=yzen (a229a591e1)
- Bug 1249730 - make TreeWalker bi-directional, r=yzen (5acc1155b1)
- Bug 1251743 - ARIA owns reallocation may insert a child at wrong index, r=yzen (d95065109b)
- Bug 1249253 - content removal processing can wrongly remove ARIA owned children, r=yzen (45df52f4c9)
- Bug 1254989 - extend TreeWalker::Next to accept a stopper node, r=yzen (c5dfbbdc96)
- Bug 1249730 - make TreeWalker bi-directional, follow up fix, r=yzen (747504b5ec)
- Bug 1196652 - OriginSuffix is shown in about:serviceworker on b2g. r=ferjm (f21d534755)
- Bug 1224570 - [Service Workers Panel] Service Workers panel fails to show registered service workers after restart. r=fabrice (7d7e95db4c)
- Bug 1169674 - Use originNoSuffix for permission event. r=fabrice, f=bholley (8f389cb0c7)
- Bug 1207499 - Part 1: Remove use of expression closure from b2g/. r=sicking (42b96cbfdf)
- Bug 1207499 - Part 2: Remove use of expression closure from chrome/. r=bsmedberg (7abb390349)
- Bug 1207499 - Part 3: Remove use of expression closure from docshell/. r=bz (aee60733a9)
- Bug 1207499 - Part 5: Remove use of expression closure from modules/. r=mwu (6c29c775fe)
- Bug 1147562 - Update remaining callsites of newChannel before landing the shim in netwerk/ (r=jduell) (2d37fab088)
- Bug 1207499 - Part 6: Remove use of expression closure from netwerk/. r=jduell (2881b3450f)
- Bug 1207499 - Part 7: Remove use of expression closure from parser/.  r=jst (2519fb1fff)
- Bug 1207499 - Part 8: Remove use of expression closure from security/. r=keeler (de33d27e8f)
- Bug 1207499 - Part 12: Remove use of expression closure from widget/. r=roc (0e7fd889d9)
- Bug 1207499 - Part 13: Remove use of expression closure from xpcom/. r=froydnj (f95a4eefde)
- Bug 1249219 - Part 1: Define NonOwningAnimationTarget. r=birtles (c13d77b5d9)
- Bug 1249219 - Part 2: Remove struct PseudoElementHashKey. r=birtles (f8ff47d484)
- Bug 1249219 - Part 3: Replace Pair<Element*, CSSPseudoElementType> with NonOwningAnimationTarget. r=birtles (68a1a5e149)
- Bug 1218620 - Allow opacity animation running on compositor even if the frame has any restricted transforms. r=birtles (0f26c81fb0)
- Bug 1254419 - Move GetPropertyState alongside GetFrames; r=hiro (046dbce30e)
- Bug 1246320 part 0 - Whitespace fixes; r=whitespace-only (eda3e8b8ae)
- Bug 1247531 - Annotate intentional switch fallthrough to suppress -Wimplicit-fallthrough warning in dom/animations/. r=dholbert (fbdff98c25)
- Bug 1246320 part 1 - Add AnimationUtils::GetCurrentRealmDocument; r=bz (53c52acbe7)
- Bug 1246320 part 2 - Pass document to ParseEasing; r=hiro (269325c142)
- Bug 1246320 part 3 - Rework KeyframeEffect(ReadOnly) constructor helpers; r=hiro (e0c58fbe49)
- Bug 1246320 part 4 - Pass a document to TimingParams; r=hiro (f9ef7bc956)
- Bug 1246320 part 5 - Simplify KeyframeEffect(ReadOnly) Constructor overloads further; r=hiro (ec932de9a7)
- Bug 1254419 - Rename getPropertyState() to getProperties(); r=heycam, r=bz (4ab86c889d)
- Bug 1254419 - Fix zero-length segment handling; r=heycam (a638e5bbd7)
- Bug 1254419 - Fill in values sequence in getProperties(); r=heycam (c7c233f5ce)
- Bug 1254419 - Return animation property information from getProperties() even if the property is overridden; r=hiro (55537b4445)
- Bug 1254419 - Add values member to AnimationPropertyDetails; r=heycam, r=bz (3ea6c1fb7f)
- Bug 1254419 - Add tests for getProperties(); r=heycam (ff9999286d)
- Bug 1254419 - Make always-set members of AnimationProperty(Value)Details required; r=bz (07ef47d79a)
- Bug 1254419 - Throw if we fail to allocate memory for a values array in getProperties(); r=bz (51ae5d9f99)
2024-03-29 09:22:21 +08:00

280 lines
9.3 KiB
C++

/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* 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/. */
/* rendering object for HTML <br> elements */
#include "nsCOMPtr.h"
#include "nsFontMetrics.h"
#include "nsFrame.h"
#include "nsPresContext.h"
#include "nsLineLayout.h"
#include "nsStyleConsts.h"
#include "nsGkAtoms.h"
#include "nsRenderingContext.h"
#include "nsLayoutUtils.h"
//FOR SELECTION
#include "nsIContent.h"
//END INCLUDES FOR SELECTION
using namespace mozilla;
class BRFrame : public nsFrame {
public:
NS_DECL_FRAMEARENA_HELPERS
friend nsIFrame* NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
virtual ContentOffsets CalcContentOffsetsFromFramePoint(nsPoint aPoint) override;
virtual FrameSearchResult PeekOffsetNoAmount(bool aForward, int32_t* aOffset) override;
virtual FrameSearchResult PeekOffsetCharacter(bool aForward, int32_t* aOffset,
bool aRespectClusters = true) override;
virtual FrameSearchResult PeekOffsetWord(bool aForward, bool aWordSelectEatSpace,
bool aIsKeyboardSelect, int32_t* aOffset,
PeekWordState* aState) override;
virtual void Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus) override;
virtual void AddInlineMinISize(nsRenderingContext *aRenderingContext,
InlineMinISizeData *aData) override;
virtual void AddInlinePrefISize(nsRenderingContext *aRenderingContext,
InlinePrefISizeData *aData) override;
virtual nscoord GetMinISize(nsRenderingContext *aRenderingContext) override;
virtual nscoord GetPrefISize(nsRenderingContext *aRenderingContext) override;
virtual nsIAtom* GetType() const override;
virtual nscoord GetLogicalBaseline(mozilla::WritingMode aWritingMode) const override;
virtual bool IsFrameOfType(uint32_t aFlags) const override
{
return nsFrame::IsFrameOfType(aFlags & ~(nsIFrame::eReplaced |
nsIFrame::eLineParticipant));
}
#ifdef ACCESSIBILITY
virtual mozilla::a11y::AccType AccessibleType() override;
#endif
protected:
explicit BRFrame(nsStyleContext* aContext) : nsFrame(aContext) {}
virtual ~BRFrame();
nscoord mAscent;
};
nsIFrame*
NS_NewBRFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) BRFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(BRFrame)
BRFrame::~BRFrame()
{
}
void
BRFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aMetrics,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
MarkInReflow();
DO_GLOBAL_REFLOW_COUNT("BRFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowState, aMetrics, aStatus);
WritingMode wm = aReflowState.GetWritingMode();
LogicalSize finalSize(wm);
finalSize.BSize(wm) = 0; // BR frames with block size 0 are ignored in quirks
// mode by nsLineLayout::VerticalAlignFrames .
// However, it's not always 0. See below.
finalSize.ISize(wm) = 0;
aMetrics.SetBlockStartAscent(0);
// Only when the BR is operating in a line-layout situation will it
// behave like a BR. Additionally, we suppress breaks from BR inside
// of ruby frames. To determine if we're inside ruby, we have to rely
// on the *parent's* ShouldSuppressLineBreak() method, instead of our
// own, because we may have custom "display" value that makes our
// ShouldSuppressLineBreak() return false.
nsLineLayout* ll = aReflowState.mLineLayout;
if (ll && !GetParent()->StyleContext()->ShouldSuppressLineBreak()) {
// Note that the compatibility mode check excludes AlmostStandards
// mode, since this is the inline box model. See bug 161691.
if ( ll->LineIsEmpty() ||
aPresContext->CompatibilityMode() == eCompatibility_FullStandards ) {
// The line is logically empty; any whitespace is trimmed away.
//
// 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
// here for cases where the line-height is less than 1.
RefPtr<nsFontMetrics> fm =
nsLayoutUtils::GetInflatedFontMetricsForFrame(this);
if (fm) {
nscoord logicalHeight = aReflowState.CalcLineHeight();
finalSize.BSize(wm) = logicalHeight;
aMetrics.SetBlockStartAscent(nsLayoutUtils::GetCenteredFontBaseline(
fm, logicalHeight, wm.IsLineInverted()));
}
else {
aMetrics.SetBlockStartAscent(aMetrics.BSize(wm) = 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!
// Warning: nsTextControlFrame::CalculateSizeStandard depends on
// the following line, see bug 228752.
finalSize.ISize(wm) = 1;
}
// Return our reflow status
uint32_t breakType = aReflowState.mStyleDisplay->PhysicalBreakType(wm);
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);
ll->SetLineEndsInBR(true);
}
else {
aStatus = NS_FRAME_COMPLETE;
}
aMetrics.SetSize(wm, finalSize);
aMetrics.SetOverflowAreasToDesiredBounds();
mAscent = aMetrics.BlockStartAscent();
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aMetrics);
}
/* virtual */ void
BRFrame::AddInlineMinISize(nsRenderingContext *aRenderingContext,
nsIFrame::InlineMinISizeData *aData)
{
if (!GetParent()->StyleContext()->ShouldSuppressLineBreak()) {
aData->ForceBreak();
}
}
/* virtual */ void
BRFrame::AddInlinePrefISize(nsRenderingContext *aRenderingContext,
nsIFrame::InlinePrefISizeData *aData)
{
if (!GetParent()->StyleContext()->ShouldSuppressLineBreak()) {
aData->ForceBreak();
}
}
/* virtual */ nscoord
BRFrame::GetMinISize(nsRenderingContext *aRenderingContext)
{
nscoord result = 0;
DISPLAY_MIN_WIDTH(this, result);
return result;
}
/* virtual */ nscoord
BRFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
{
nscoord result = 0;
DISPLAY_PREF_WIDTH(this, result);
return result;
}
nsIAtom*
BRFrame::GetType() const
{
return nsGkAtoms::brFrame;
}
nscoord
BRFrame::GetLogicalBaseline(mozilla::WritingMode aWritingMode) const
{
return mAscent;
}
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;
offsets.associate = CARET_ASSOCIATE_AFTER;
}
return offsets;
}
nsIFrame::FrameSearchResult
BRFrame::PeekOffsetNoAmount(bool aForward, int32_t* aOffset)
{
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
int32_t 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 FOUND;
}
// Otherwise, stop if we hit the beginning, continue (forward) if we hit the end.
return (startOffset == 0) ? FOUND : CONTINUE;
}
nsIFrame::FrameSearchResult
BRFrame::PeekOffsetCharacter(bool aForward, int32_t* aOffset,
bool aRespectClusters)
{
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
// Keep going. The actual line jumping will stop us.
return CONTINUE;
}
nsIFrame::FrameSearchResult
BRFrame::PeekOffsetWord(bool aForward, bool aWordSelectEatSpace, bool aIsKeyboardSelect,
int32_t* aOffset, PeekWordState* aState)
{
NS_ASSERTION (aOffset && *aOffset <= 1, "aOffset out of range");
// Keep going. The actual line jumping will stop us.
return CONTINUE;
}
#ifdef ACCESSIBILITY
a11y::AccType
BRFrame::AccessibleType()
{
nsIContent *parent = mContent->GetParent();
if (parent && parent->IsRootOfNativeAnonymousSubtree() &&
parent->GetChildCount() == 1) {
// 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
return a11y::eNoType;
}
// Trailing HTML br element don't play any difference. We don't need to expose
// it to AT (see bug https://bugzilla.mozilla.org/show_bug.cgi?id=899433#c16
// for details).
if (!mContent->GetNextSibling() && !GetNextSibling()) {
return a11y::eNoType;
}
return a11y::eHTMLBRType;
}
#endif