Files
palemoon27/layout/forms/nsMeterFrame.cpp
T
roytam1 89d38b5d7a import changes from `dev' branch of rmottola/Arctic-Fox:
- Bug 1173364 - support ARIA table and cell roles, r=marcoz (c6f9fc891e)
- Bug 1205318 - make aria-owns loop alg more sophisticated, r=yzen (d287b1e41c)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList(), r=smaug (bf920abdd3)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList(), part3, r=davidb (675c3a0ee2)
- Bug 1205476 - crash in mozilla::a11y::DocAccessible::ProcessInvalidationList, part2, r=davidb (a7cd835169)
- Bug 1186786 - Replace nsBaseHashtable::EnumerateRead() calls in accessible/ with iterators. r=tbsaunde. (172fcbe18f)
- Bug 1219299 - rework aria-owns implementation, r=yzen (c297a84b41)
- Bug 1219744 - no child_of/parent_of relations for aria-owns, r=yzen (38ea8be268)
- Bug 1205341 - get rid of aria-owns provided relations, part1: remove ARIA combobox special support (bug 819273 backout), r=yzen (0ca03a27bd)
- Bug 1219743 - remove special ARIA owns support for ARIA menus, r=yzen (64468fdfd1)
- Bug 1200595 - Introduce TextureData and implement it for X11. r=mattwoodrow, Bas, sotaro (2e6bc3f02c)
- Bug 1200595 - Buffer TextureData implementation. r=mattwoodrow (1cb3ffd937)
- Bug 1227415 - Fix copy buffer size r=jolin (344130daec)
- Bug 1200595 - Gralloc TextureData implementation. r=sotaro (a0726233ca)
- Bug 1205725 - Add basic SidebandStream handling to HwcComposer2D r=mwu,nical (42bea59a5f)
- namespace (ab69730d53)
- Bug 1194775 - Paper over a crash in ContentClient. r=Bas (998051cee4)
- minor (c24c0b069d)
- Bug 1197315 - remove PR_snprintf calls in gfx/; r=froydnj (f153fed9c8)
- Bug 1157664 - Initialize mozilla::layers::FPSCOUNTER::mIteratorIndex. r=nical (cf5d2203ee)
- Bug 1157663 - Init mMap in the constructor to avoid half initialized structures. r=nical (d972306493)
- Bug 1167370: Check for Map() call failing. r=bas (707eda52ff)
- Bug 1221276 - Don't crash if we don't have a surface. r=nical (c53141ea3d)
- Bug 1219230 - Use the valid region for determining buffer size instead of the visible region. r=mstange (f2d4783eef)
- Pass the correct moz2d backend in CanvasClients. (bug 1212499, r=mattwoodrow) (c16688afbb)
- Bug 1179987 - Simplify unlocking of tiled texture hosts. r=nical (781200f702)
- Bug 1170189 - Fix tiling crash on Linux. r=jrmuizel (879bbfb506)
- Bug 1170189 - fix a comment in the tiling code. r=BenWa (62b47f1bbd)
- Bug 1179987 - Make tiled TextureSource recycling based on pointer comparisons rather than trying to do it geometrically. r=nical (7bde534929)
- Bug 1189710 - Use correct offset for LayerRenderState in TiledContentHost. r=jrmuizel (cb93c2f98a)
- Bug 1215050 - Make layerscope support TiledPaintedLayer when using HWC. r=mattwoodrow, r=cjku (6bffac30f8)
- Bug 1186208 - Fix crash when tiling is enabled on linux. r=mattwoodrow (b2f2c85734)
- Bug 1197713 - Add missing gfxPrefs.h include to TiledContentHost.cpp. r=nical (22bce4e071)
- Bug 1143575. Async image invalidation does not necessarily need to invalidate the layer; LayerTreeInvalidation will do that for us. r=mattwoodrow (a6144b7127)
- Bug 1219529 - Don't attempt to deallocate shmems after the ipdl protocol is shut down. r=sotaro (3bb89ef36e)
- Bug 1143575. Add assertion for diagnostic purposes. r=nical (e4944dd72f)
- Bug 1202175 - Guard GLX-specific call in SurfaceDescriptorX11. r=jgilbert (167a4aa49b)
- Bug 1132528 - Handle non existent key r=nical (6c12df1446)
- Bug 1137151: Marked destructor of |GrallocReporter| as protected, r=jmuizelaar (57605c4472)
- Bug 1145389 - Add gralloc allocation requet size check r=nical (47c6065148)
- Bug 1181197 - Fix null dereference in SharedPlanarYCbCrImage destructor. r=jgilbert (3f8c390a6f)
- Bug 1195110 - Check if GLContext is destroyed before freeing resources in CompositingRenderTargetOGL. r=jrmuizel (8eac603d84)
- bug 1178956 - Specify precision in OGLShaderProgram.cpp to fix compositor on iOS. r=kip (daa6d9db20)
- Bug 1186725 - InitTextures should check if LockRect() returns an error, r=mattwoodrow (bc87f908a7)
- Bug 1170143 - Add some error checks around the creation of dxgi ycbcrvideo frames. r=Bas (c96e4d9e79)
- Bug 1170143 - Build fix. r=me (a9d0064bc3)
- Bug 1202700 - Use d3d9 device to upload YCbCr surfaces on the client side if possible. r=Bas (3ccd0c68f5)
- Bug 1199361 - Add texture memory reporters for YCbCr TextureClients. r=jrmuizel (723e9d4b10)
- bug 1183967 - fixup correct case of mfidl.h (e9abd04709)
- Bug 1133007 - followup - make CreateServerSocketRunnable's constructor explicit; r=bustage (5de0ec7900)
- Bug 1195653 - Part1.1: Dump SecondaryEffects (EffectTypes::MASK) on Layerscope viewer. r=dglastonbury (v2, carry r+) (a6736ad381)
- Bug 1195653 - Part1.2: Use sSentTextureIds instead of sTextureIdList and move HasTextureIdBeenSent into SendTextureSource. r=dglastonbury (v3, carry r+) (7e0b14bca6)
- Bug 1195653 - Part1.3: Add isMask attribute field to LayerScopePacket.proto. r=dglastonbury (v2, carry r+) (510e50e09a)
- Bug 1195653 - Part1.4: Generated file diffs from patched LayerScopePacket.proto. r=dglastonbury (v1, carry r+) (f1824afcb3)
- Bug 1195653 - Part1.5: Send isMask info to LayerScope viewer by TexturePacket. r=dglastonbury (v3) (1722e5e6fe)
- Bug 1205521 - Part1: (v3) Add texture/mask attribute fields in LayerScopePacket.proto. r=dglastonbury (0cca15f8f5)
- Bug 1205521 - Part2: (v3) Generated file diffs from patched LayerScopePacket.proto. r=dglastonbury (6253724bcf)
- Bug 1205521 - Part3: (v3) Dump texture/mask attributes on layerscope viewer. r=dglastonbury (31d346bad1)
- Bug 1205521 - Part4: (v2) Align LayerScopePacket to fit changes in Bug 1211324. r=dglastonbury (712da0fe9c)
- Bug 1177023 - Log the IsRootContent flag when dumping framemetrics. r=botond (9bea51f318)
- Bug 1153724 - Only assert if the size was reasonable to start. r=mchang (c3d61bbee1)
- namespace (edcce0a0b3)
- Bug 1195857: Make nsPresContext::HasAuthorSpecifiedRules()'s arg 'const', to remove need for const_cast in callers. r=jwatt (274fe66dca)
- Bug 1182414, part 1 - Fix printing crash with range input controls. r=dholbert (352a408a83)
- Bug 1182414, part 2 - Add printing crash test. r=dholbert (0fc9bd4529)
- Bug 1099103 - Prevent numbers input using a grouping separator from being mis-processed as if the separator was a decimal separator. r=dholbert (90276c2f6b)
- Bug 1157142 - Support logical (inline/block) in addition to physical orientation for the <input type=range> element; make inline the default behavior so that range sliders respect writing mode. r=jwatt (2ec37cbba8)
2023-01-30 12:47:09 +08:00

298 lines
9.7 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/. */
#include "nsMeterFrame.h"
#include "nsIContent.h"
#include "nsPresContext.h"
#include "nsGkAtoms.h"
#include "nsNameSpaceManager.h"
#include "nsIDocument.h"
#include "nsIPresShell.h"
#include "nsNodeInfoManager.h"
#include "nsContentCreatorFunctions.h"
#include "nsContentUtils.h"
#include "nsFormControlFrame.h"
#include "nsFontMetrics.h"
#include "mozilla/dom/Element.h"
#include "mozilla/dom/HTMLMeterElement.h"
#include "nsContentList.h"
#include "nsStyleSet.h"
#include "nsThemeConstants.h"
#include <algorithm>
using namespace mozilla;
using mozilla::dom::Element;
using mozilla::dom::HTMLMeterElement;
nsIFrame*
NS_NewMeterFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
{
return new (aPresShell) nsMeterFrame(aContext);
}
NS_IMPL_FRAMEARENA_HELPERS(nsMeterFrame)
nsMeterFrame::nsMeterFrame(nsStyleContext* aContext)
: nsContainerFrame(aContext)
, mBarDiv(nullptr)
{
}
nsMeterFrame::~nsMeterFrame()
{
}
void
nsMeterFrame::DestroyFrom(nsIFrame* aDestructRoot)
{
NS_ASSERTION(!GetPrevContinuation(),
"nsMeterFrame should not have continuations; if it does we "
"need to call RegUnregAccessKey only for the first.");
nsFormControlFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
nsContentUtils::DestroyAnonymousContent(&mBarDiv);
nsContainerFrame::DestroyFrom(aDestructRoot);
}
nsIAtom*
nsMeterFrame::GetType() const
{
return nsGkAtoms::meterFrame;
}
nsresult
nsMeterFrame::CreateAnonymousContent(nsTArray<ContentInfo>& aElements)
{
// Get the NodeInfoManager and tag necessary to create the meter bar div.
nsCOMPtr<nsIDocument> doc = mContent->GetComposedDoc();
// Create the div.
mBarDiv = doc->CreateHTMLElement(nsGkAtoms::div);
// Associate ::-moz-meter-bar pseudo-element to the anonymous child.
nsCSSPseudoElements::Type pseudoType = nsCSSPseudoElements::ePseudo_mozMeterBar;
RefPtr<nsStyleContext> newStyleContext = PresContext()->StyleSet()->
ResolvePseudoElementStyle(mContent->AsElement(), pseudoType,
StyleContext(), mBarDiv->AsElement());
if (!aElements.AppendElement(ContentInfo(mBarDiv, newStyleContext))) {
return NS_ERROR_OUT_OF_MEMORY;
}
return NS_OK;
}
void
nsMeterFrame::AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
uint32_t aFilter)
{
if (mBarDiv) {
aElements.AppendElement(mBarDiv);
}
}
NS_QUERYFRAME_HEAD(nsMeterFrame)
NS_QUERYFRAME_ENTRY(nsMeterFrame)
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
void
nsMeterFrame::Reflow(nsPresContext* aPresContext,
nsHTMLReflowMetrics& aDesiredSize,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
MarkInReflow();
DO_GLOBAL_REFLOW_COUNT("nsMeterFrame");
DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus);
NS_ASSERTION(mBarDiv, "Meter bar div must exist!");
NS_ASSERTION(!GetPrevContinuation(),
"nsMeterFrame should not have continuations; if it does we "
"need to call RegUnregAccessKey only for the first.");
if (mState & NS_FRAME_FIRST_REFLOW) {
nsFormControlFrame::RegUnRegAccessKey(this, true);
}
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
NS_ASSERTION(barFrame, "The meter frame should have a child with a frame!");
ReflowBarFrame(barFrame, aPresContext, aReflowState, aStatus);
aDesiredSize.SetSize(aReflowState.GetWritingMode(),
aReflowState.ComputedSizeWithBorderPadding());
aDesiredSize.SetOverflowAreasToDesiredBounds();
ConsiderChildOverflow(aDesiredSize.mOverflowAreas, barFrame);
FinishAndStoreOverflow(&aDesiredSize);
aStatus = NS_FRAME_COMPLETE;
NS_FRAME_SET_TRUNCATION(aStatus, aReflowState, aDesiredSize);
}
void
nsMeterFrame::ReflowBarFrame(nsIFrame* aBarFrame,
nsPresContext* aPresContext,
const nsHTMLReflowState& aReflowState,
nsReflowStatus& aStatus)
{
bool vertical = ResolvedOrientationIsVertical();
WritingMode wm = aBarFrame->GetWritingMode();
LogicalSize availSize = aReflowState.ComputedSize(wm);
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
nsHTMLReflowState reflowState(aPresContext, aReflowState,
aBarFrame, availSize);
nscoord size = vertical ? aReflowState.ComputedHeight()
: aReflowState.ComputedWidth();
nscoord xoffset = aReflowState.ComputedPhysicalBorderPadding().left;
nscoord yoffset = aReflowState.ComputedPhysicalBorderPadding().top;
// NOTE: Introduce a new function getPosition in the content part ?
HTMLMeterElement* meterElement = static_cast<HTMLMeterElement*>(mContent);
double max = meterElement->Max();
double min = meterElement->Min();
double value = meterElement->Value();
double position = max - min;
position = position != 0 ? (value - min) / position : 1;
size = NSToCoordRound(size * position);
if (!vertical && (wm.IsVertical() ? wm.IsVerticalRL() : !wm.IsBidiLTR())) {
xoffset += aReflowState.ComputedWidth() - size;
}
// The bar position is *always* constrained.
if (vertical) {
// We want the bar to begin at the bottom.
yoffset += aReflowState.ComputedHeight() - size;
size -= reflowState.ComputedPhysicalMargin().TopBottom() +
reflowState.ComputedPhysicalBorderPadding().TopBottom();
size = std::max(size, 0);
reflowState.SetComputedHeight(size);
} else {
size -= reflowState.ComputedPhysicalMargin().LeftRight() +
reflowState.ComputedPhysicalBorderPadding().LeftRight();
size = std::max(size, 0);
reflowState.SetComputedWidth(size);
}
xoffset += reflowState.ComputedPhysicalMargin().left;
yoffset += reflowState.ComputedPhysicalMargin().top;
nsHTMLReflowMetrics barDesiredSize(reflowState);
ReflowChild(aBarFrame, aPresContext, barDesiredSize, reflowState, xoffset,
yoffset, 0, aStatus);
FinishReflowChild(aBarFrame, aPresContext, barDesiredSize, &reflowState,
xoffset, yoffset, 0);
}
nsresult
nsMeterFrame::AttributeChanged(int32_t aNameSpaceID,
nsIAtom* aAttribute,
int32_t aModType)
{
NS_ASSERTION(mBarDiv, "Meter bar div must exist!");
if (aNameSpaceID == kNameSpaceID_None &&
(aAttribute == nsGkAtoms::value ||
aAttribute == nsGkAtoms::max ||
aAttribute == nsGkAtoms::min )) {
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
NS_ASSERTION(barFrame, "The meter frame should have a child with a frame!");
PresContext()->PresShell()->FrameNeedsReflow(barFrame,
nsIPresShell::eResize,
NS_FRAME_IS_DIRTY);
InvalidateFrame();
}
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
aModType);
}
LogicalSize
nsMeterFrame::ComputeAutoSize(nsRenderingContext *aRenderingContext,
WritingMode aWM,
const LogicalSize& aCBSize,
nscoord aAvailableISize,
const LogicalSize& aMargin,
const LogicalSize& aBorder,
const LogicalSize& aPadding,
bool aShrinkWrap)
{
RefPtr<nsFontMetrics> fontMet;
NS_ENSURE_SUCCESS(nsLayoutUtils::GetFontMetricsForFrame(this,
getter_AddRefs(fontMet)),
LogicalSize(aWM));
const WritingMode wm = GetWritingMode();
LogicalSize autoSize(wm);
autoSize.BSize(wm) = autoSize.ISize(wm) = fontMet->Font().size; // 1em
if (ResolvedOrientationIsVertical() == wm.IsVertical()) {
autoSize.ISize(wm) *= 5; // 5em
} else {
autoSize.BSize(wm) *= 5; // 5em
}
return autoSize.ConvertTo(aWM, wm);
}
nscoord
nsMeterFrame::GetMinISize(nsRenderingContext *aRenderingContext)
{
RefPtr<nsFontMetrics> fontMet;
NS_ENSURE_SUCCESS(
nsLayoutUtils::GetFontMetricsForFrame(this, getter_AddRefs(fontMet)), 0);
nscoord minISize = fontMet->Font().size; // 1em
if (ResolvedOrientationIsVertical() == GetWritingMode().IsVertical()) {
// The orientation is inline
minISize *= 5; // 5em
}
return minISize;
}
nscoord
nsMeterFrame::GetPrefISize(nsRenderingContext *aRenderingContext)
{
return GetMinISize(aRenderingContext);
}
bool
nsMeterFrame::ShouldUseNativeStyle() const
{
nsIFrame* barFrame = mBarDiv->GetPrimaryFrame();
// Use the native style if these conditions are satisfied:
// - both frames use the native appearance;
// - neither frame has author specified rules setting the border or the
// background.
return StyleDisplay()->mAppearance == NS_THEME_METERBAR &&
!PresContext()->HasAuthorSpecifiedRules(this,
NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND) &&
barFrame &&
barFrame->StyleDisplay()->mAppearance == NS_THEME_METERBAR_CHUNK &&
!PresContext()->HasAuthorSpecifiedRules(barFrame,
NS_AUTHOR_SPECIFIED_BORDER | NS_AUTHOR_SPECIFIED_BACKGROUND);
}
Element*
nsMeterFrame::GetPseudoElement(nsCSSPseudoElements::Type aType)
{
if (aType == nsCSSPseudoElements::ePseudo_mozMeterBar) {
return mBarDiv;
}
return nsContainerFrame::GetPseudoElement(aType);
}