Bug 1753131 - Dispatch devicechange events even without an actively capturing MediaSt...
[gecko.git] / layout / forms / nsCheckboxRadioFrame.cpp
blob797761f20a8959e77f01f7ee89b4d1803182dd06
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* vim: set ts=8 sts=2 et sw=2 tw=80: */
3 /* This Source Code Form is subject to the terms of the Mozilla Public
4 * License, v. 2.0. If a copy of the MPL was not distributed with this
5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
7 #include "nsCheckboxRadioFrame.h"
9 #include "nsGkAtoms.h"
10 #include "nsLayoutUtils.h"
11 #include "mozilla/dom/HTMLInputElement.h"
12 #include "mozilla/PresShell.h"
13 #include "nsIContent.h"
14 #include "nsStyleConsts.h"
16 using namespace mozilla;
17 using mozilla::dom::HTMLInputElement;
19 //#define FCF_NOISY
21 nsCheckboxRadioFrame* NS_NewCheckboxRadioFrame(PresShell* aPresShell,
22 ComputedStyle* aStyle) {
23 return new (aPresShell)
24 nsCheckboxRadioFrame(aStyle, aPresShell->GetPresContext());
27 nsCheckboxRadioFrame::nsCheckboxRadioFrame(ComputedStyle* aStyle,
28 nsPresContext* aPresContext)
29 : nsAtomicContainerFrame(aStyle, aPresContext, kClassID) {}
31 nsCheckboxRadioFrame::~nsCheckboxRadioFrame() = default;
33 NS_IMPL_FRAMEARENA_HELPERS(nsCheckboxRadioFrame)
35 NS_QUERYFRAME_HEAD(nsCheckboxRadioFrame)
36 NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
37 NS_QUERYFRAME_TAIL_INHERITING(nsAtomicContainerFrame)
39 nscoord nsCheckboxRadioFrame::DefaultSize() {
40 if (StyleDisplay()->HasAppearance()) {
41 return PresContext()->Theme()->GetCheckboxRadioPrefSize();
43 return CSSPixel::ToAppUnits(9);
46 /* virtual */
47 void nsCheckboxRadioFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
48 const nsDisplayListSet& aLists) {
49 DO_GLOBAL_REFLOW_COUNT_DSP("nsCheckboxRadioFrame");
50 DisplayBorderBackgroundOutline(aBuilder, aLists);
53 /* virtual */
54 nscoord nsCheckboxRadioFrame::GetMinISize(gfxContext* aRenderingContext) {
55 nscoord result;
56 DISPLAY_MIN_INLINE_SIZE(this, result);
57 result = StyleDisplay()->HasAppearance() ? DefaultSize() : 0;
58 return result;
61 /* virtual */
62 nscoord nsCheckboxRadioFrame::GetPrefISize(gfxContext* aRenderingContext) {
63 nscoord result;
64 DISPLAY_PREF_INLINE_SIZE(this, result);
65 result = StyleDisplay()->HasAppearance() ? DefaultSize() : 0;
66 return result;
69 /* virtual */
70 LogicalSize nsCheckboxRadioFrame::ComputeAutoSize(
71 gfxContext* aRC, WritingMode aWM, const LogicalSize& aCBSize,
72 nscoord aAvailableISize, const LogicalSize& aMargin,
73 const LogicalSize& aBorderPadding, const StyleSizeOverrides& aSizeOverrides,
74 ComputeSizeFlags aFlags) {
75 LogicalSize size(aWM, 0, 0);
76 if (!StyleDisplay()->HasAppearance()) {
77 return size;
80 // Note: this call always set the BSize to NS_UNCONSTRAINEDSIZE.
81 size = nsAtomicContainerFrame::ComputeAutoSize(
82 aRC, aWM, aCBSize, aAvailableISize, aMargin, aBorderPadding,
83 aSizeOverrides, aFlags);
84 size.BSize(aWM) = DefaultSize();
85 return size;
88 nscoord nsCheckboxRadioFrame::GetLogicalBaseline(
89 WritingMode aWritingMode) const {
90 NS_ASSERTION(!IsSubtreeDirty(), "frame must not be dirty");
92 // For appearance:none we use a standard CSS baseline, i.e. synthesized from
93 // our margin-box.
94 if (!StyleDisplay()->HasAppearance()) {
95 return nsAtomicContainerFrame::GetLogicalBaseline(aWritingMode);
98 // This is for compatibility with Chrome, Safari and Edge (Dec 2016).
99 // Treat radio buttons and checkboxes as having an intrinsic baseline
100 // at the block-end of the control (use the block-end content edge rather
101 // than the margin edge).
102 // For "inverted" lines (typically in writing-mode:vertical-lr), use the
103 // block-start end instead.
104 return aWritingMode.IsLineInverted()
105 ? GetLogicalUsedBorderAndPadding(aWritingMode).BStart(aWritingMode)
106 : BSize(aWritingMode) -
107 GetLogicalUsedBorderAndPadding(aWritingMode)
108 .BEnd(aWritingMode);
111 void nsCheckboxRadioFrame::Reflow(nsPresContext* aPresContext,
112 ReflowOutput& aDesiredSize,
113 const ReflowInput& aReflowInput,
114 nsReflowStatus& aStatus) {
115 MarkInReflow();
116 DO_GLOBAL_REFLOW_COUNT("nsCheckboxRadioFrame");
117 DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
118 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
119 NS_FRAME_TRACE(
120 NS_FRAME_TRACE_CALLS,
121 ("enter nsCheckboxRadioFrame::Reflow: aMaxSize=%d,%d",
122 aReflowInput.AvailableWidth(), aReflowInput.AvailableHeight()));
124 const auto wm = aReflowInput.GetWritingMode();
125 aDesiredSize.SetSize(wm, aReflowInput.ComputedSizeWithBorderPadding(wm));
127 if (nsLayoutUtils::FontSizeInflationEnabled(aPresContext)) {
128 float inflation = nsLayoutUtils::FontSizeInflationFor(this);
129 aDesiredSize.Width() *= inflation;
130 aDesiredSize.Height() *= inflation;
133 NS_FRAME_TRACE(NS_FRAME_TRACE_CALLS,
134 ("exit nsCheckboxRadioFrame::Reflow: size=%d,%d",
135 aDesiredSize.Width(), aDesiredSize.Height()));
136 NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
138 aDesiredSize.SetOverflowAreasToDesiredBounds();
139 FinishAndStoreOverflow(&aDesiredSize);
142 void nsCheckboxRadioFrame::SetFocus(bool aOn, bool aRepaint) {}
144 nsresult nsCheckboxRadioFrame::HandleEvent(nsPresContext* aPresContext,
145 WidgetGUIEvent* aEvent,
146 nsEventStatus* aEventStatus) {
147 // Check for disabled content so that selection works properly (?).
148 if (IsContentDisabled()) {
149 return nsIFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
151 return NS_OK;
154 void nsCheckboxRadioFrame::GetCurrentCheckState(bool* aState) {
155 HTMLInputElement* inputElement = HTMLInputElement::FromNode(mContent);
156 if (inputElement) {
157 *aState = inputElement->Checked();
161 nsresult nsCheckboxRadioFrame::SetFormProperty(nsAtom* aName,
162 const nsAString& aValue) {
163 return NS_OK;