Bug 1867190 - Initialise the PHC allocate delay later r=glandium
[gecko.git] / layout / forms / nsImageControlFrame.cpp
blob898d890e04c1ab12d42c45b52063b491892a6062
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 "nsImageFrame.h"
9 #include "mozilla/MouseEvents.h"
10 #include "mozilla/PresShell.h"
11 #include "nsIFormControlFrame.h"
12 #include "nsPresContext.h"
13 #include "nsGkAtoms.h"
14 #include "nsStyleConsts.h"
15 #include "nsLayoutUtils.h"
16 #include "nsIContent.h"
18 using namespace mozilla;
20 class nsImageControlFrame final : public nsImageFrame,
21 public nsIFormControlFrame {
22 public:
23 explicit nsImageControlFrame(ComputedStyle* aStyle,
24 nsPresContext* aPresContext);
25 ~nsImageControlFrame() final;
27 void Init(nsIContent* aContent, nsContainerFrame* aParent,
28 nsIFrame* aPrevInFlow) final;
30 NS_DECL_QUERYFRAME
31 NS_DECL_FRAMEARENA_HELPERS(nsImageControlFrame)
33 void Reflow(nsPresContext*, ReflowOutput&, const ReflowInput&,
34 nsReflowStatus&) final;
36 nsresult HandleEvent(nsPresContext*, WidgetGUIEvent*, nsEventStatus*) final;
38 #ifdef ACCESSIBILITY
39 mozilla::a11y::AccType AccessibleType() final;
40 #endif
42 #ifdef DEBUG_FRAME_DUMP
43 nsresult GetFrameName(nsAString& aResult) const final {
44 return MakeFrameName(u"ImageControl"_ns, aResult);
46 #endif
48 Maybe<Cursor> GetCursor(const nsPoint&) final;
50 // nsIFormContromFrame
51 void SetFocus(bool aOn, bool aRepaint) final;
52 nsresult SetFormProperty(nsAtom* aName, const nsAString& aValue) final;
55 nsImageControlFrame::nsImageControlFrame(ComputedStyle* aStyle,
56 nsPresContext* aPresContext)
57 : nsImageFrame(aStyle, aPresContext, kClassID) {}
59 nsImageControlFrame::~nsImageControlFrame() = default;
61 nsIFrame* NS_NewImageControlFrame(PresShell* aPresShell,
62 ComputedStyle* aStyle) {
63 return new (aPresShell)
64 nsImageControlFrame(aStyle, aPresShell->GetPresContext());
67 NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)
69 void nsImageControlFrame::Init(nsIContent* aContent, nsContainerFrame* aParent,
70 nsIFrame* aPrevInFlow) {
71 nsImageFrame::Init(aContent, aParent, aPrevInFlow);
73 if (aPrevInFlow) {
74 return;
77 mContent->SetProperty(nsGkAtoms::imageClickedPoint, new CSSIntPoint(0, 0),
78 nsINode::DeleteProperty<CSSIntPoint>);
81 NS_QUERYFRAME_HEAD(nsImageControlFrame)
82 NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
83 NS_QUERYFRAME_TAIL_INHERITING(nsImageFrame)
85 #ifdef ACCESSIBILITY
86 a11y::AccType nsImageControlFrame::AccessibleType() {
87 if (mContent->IsAnyOfHTMLElements(nsGkAtoms::button, nsGkAtoms::input)) {
88 return a11y::eHTMLButtonType;
91 return a11y::eNoType;
93 #endif
95 void nsImageControlFrame::Reflow(nsPresContext* aPresContext,
96 ReflowOutput& aDesiredSize,
97 const ReflowInput& aReflowInput,
98 nsReflowStatus& aStatus) {
99 DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame");
100 DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
101 MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
102 return nsImageFrame::Reflow(aPresContext, aDesiredSize, aReflowInput,
103 aStatus);
106 nsresult nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
107 WidgetGUIEvent* aEvent,
108 nsEventStatus* aEventStatus) {
109 NS_ENSURE_ARG_POINTER(aEventStatus);
111 // Don't do anything if the event has already been handled by someone
112 if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
113 return NS_OK;
116 if (IsContentDisabled()) {
117 return nsIFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
120 *aEventStatus = nsEventStatus_eIgnore;
122 if (aEvent->mMessage == eMouseUp &&
123 aEvent->AsMouseEvent()->mButton == MouseButton::ePrimary) {
124 // Store click point for HTMLInputElement::SubmitNamesValues
125 // Do this on MouseUp because the specs don't say and that's what IE does
126 auto* lastClickedPoint = static_cast<CSSIntPoint*>(
127 mContent->GetProperty(nsGkAtoms::imageClickedPoint));
128 if (lastClickedPoint) {
129 // normally lastClickedPoint is not null, as it's allocated in Init()
130 nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(
131 aEvent, RelativeTo{this});
132 *lastClickedPoint = TranslateEventCoords(pt);
135 return nsImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
138 void nsImageControlFrame::SetFocus(bool aOn, bool aRepaint) {}
140 Maybe<nsIFrame::Cursor> nsImageControlFrame::GetCursor(const nsPoint&) {
141 StyleCursorKind kind = StyleUI()->Cursor().keyword;
142 if (kind == StyleCursorKind::Auto) {
143 kind = StyleCursorKind::Pointer;
145 return Some(Cursor{kind, AllowCustomCursorImage::Yes});
148 nsresult nsImageControlFrame::SetFormProperty(nsAtom* aName,
149 const nsAString& aValue) {
150 return NS_OK;