Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* This Source Code Form is subject to the terms of the Mozilla Public
3 : * License, v. 2.0. If a copy of the MPL was not distributed with this
4 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 :
6 : #include "nsImageFrame.h"
7 : #include "nsIFormControlFrame.h"
8 : #include "nsPresContext.h"
9 : #include "nsGkAtoms.h"
10 : #include "nsStyleConsts.h"
11 : #include "nsFormControlFrame.h"
12 : #include "nsLayoutUtils.h"
13 : #include "mozilla/MouseEvents.h"
14 : #include "nsIContent.h"
15 :
16 : using namespace mozilla;
17 :
18 : class nsImageControlFrame : public nsImageFrame,
19 : public nsIFormControlFrame
20 : {
21 : public:
22 : explicit nsImageControlFrame(nsStyleContext* aContext);
23 : ~nsImageControlFrame();
24 :
25 : virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
26 : virtual void Init(nsIContent* aContent,
27 : nsContainerFrame* aParent,
28 : nsIFrame* aPrevInFlow) override;
29 :
30 : NS_DECL_QUERYFRAME
31 0 : NS_DECL_FRAMEARENA_HELPERS(nsImageControlFrame)
32 :
33 : virtual void Reflow(nsPresContext* aPresContext,
34 : ReflowOutput& aDesiredSize,
35 : const ReflowInput& aReflowInput,
36 : nsReflowStatus& aStatus) override;
37 :
38 : virtual nsresult HandleEvent(nsPresContext* aPresContext,
39 : WidgetGUIEvent* aEvent,
40 : nsEventStatus* aEventStatus) override;
41 :
42 : #ifdef ACCESSIBILITY
43 : virtual mozilla::a11y::AccType AccessibleType() override;
44 : #endif
45 :
46 : #ifdef DEBUG_FRAME_DUMP
47 0 : virtual nsresult GetFrameName(nsAString& aResult) const override {
48 0 : return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult);
49 : }
50 : #endif
51 :
52 : virtual nsresult GetCursor(const nsPoint& aPoint,
53 : nsIFrame::Cursor& aCursor) override;
54 : // nsIFormContromFrame
55 : virtual void SetFocus(bool aOn, bool aRepaint) override;
56 : virtual nsresult SetFormProperty(nsIAtom* aName,
57 : const nsAString& aValue) override;
58 : };
59 :
60 0 : nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext)
61 0 : : nsImageFrame(aContext, kClassID)
62 : {
63 0 : }
64 :
65 0 : nsImageControlFrame::~nsImageControlFrame()
66 : {
67 0 : }
68 :
69 : void
70 0 : nsImageControlFrame::DestroyFrom(nsIFrame* aDestructRoot)
71 : {
72 0 : if (!GetPrevInFlow()) {
73 0 : nsFormControlFrame::RegUnRegAccessKey(this, false);
74 : }
75 0 : nsImageFrame::DestroyFrom(aDestructRoot);
76 0 : }
77 :
78 : nsIFrame*
79 0 : NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext)
80 : {
81 0 : return new (aPresShell) nsImageControlFrame(aContext);
82 : }
83 :
84 0 : NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame)
85 :
86 : void
87 0 : nsImageControlFrame::Init(nsIContent* aContent,
88 : nsContainerFrame* aParent,
89 : nsIFrame* aPrevInFlow)
90 : {
91 0 : nsImageFrame::Init(aContent, aParent, aPrevInFlow);
92 :
93 0 : if (aPrevInFlow) {
94 0 : return;
95 : }
96 :
97 0 : mContent->SetProperty(nsGkAtoms::imageClickedPoint,
98 0 : new nsIntPoint(0, 0),
99 0 : nsINode::DeleteProperty<nsIntPoint>);
100 : }
101 :
102 0 : NS_QUERYFRAME_HEAD(nsImageControlFrame)
103 0 : NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
104 0 : NS_QUERYFRAME_TAIL_INHERITING(nsImageFrame)
105 :
106 : #ifdef ACCESSIBILITY
107 : a11y::AccType
108 0 : nsImageControlFrame::AccessibleType()
109 : {
110 0 : if (mContent->IsAnyOfHTMLElements(nsGkAtoms::button, nsGkAtoms::input)) {
111 0 : return a11y::eHTMLButtonType;
112 : }
113 :
114 0 : return a11y::eNoType;
115 : }
116 : #endif
117 :
118 : void
119 0 : nsImageControlFrame::Reflow(nsPresContext* aPresContext,
120 : ReflowOutput& aDesiredSize,
121 : const ReflowInput& aReflowInput,
122 : nsReflowStatus& aStatus)
123 : {
124 0 : DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame");
125 0 : DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
126 0 : if (!GetPrevInFlow() && (mState & NS_FRAME_FIRST_REFLOW)) {
127 0 : nsFormControlFrame::RegUnRegAccessKey(this, true);
128 : }
129 0 : return nsImageFrame::Reflow(aPresContext, aDesiredSize, aReflowInput, aStatus);
130 : }
131 :
132 : nsresult
133 0 : nsImageControlFrame::HandleEvent(nsPresContext* aPresContext,
134 : WidgetGUIEvent* aEvent,
135 : nsEventStatus* aEventStatus)
136 : {
137 0 : NS_ENSURE_ARG_POINTER(aEventStatus);
138 :
139 : // Don't do anything if the event has already been handled by someone
140 0 : if (nsEventStatus_eConsumeNoDefault == *aEventStatus) {
141 0 : return NS_OK;
142 : }
143 :
144 : // do we have user-input style?
145 0 : const nsStyleUserInterface* uiStyle = StyleUserInterface();
146 0 : if (uiStyle->mUserInput == StyleUserInput::None ||
147 0 : uiStyle->mUserInput == StyleUserInput::Disabled) {
148 0 : return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
149 : }
150 0 : if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { // XXX cache disabled
151 0 : return NS_OK;
152 : }
153 :
154 0 : *aEventStatus = nsEventStatus_eIgnore;
155 :
156 0 : if (aEvent->mMessage == eMouseUp &&
157 0 : aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) {
158 : // Store click point for HTMLInputElement::SubmitNamesValues
159 : // Do this on MouseUp because the specs don't say and that's what IE does
160 : nsIntPoint* lastClickPoint =
161 : static_cast<nsIntPoint*>
162 0 : (mContent->GetProperty(nsGkAtoms::imageClickedPoint));
163 0 : if (lastClickPoint) {
164 : // normally lastClickedPoint is not null, as it's allocated in Init()
165 0 : nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this);
166 0 : TranslateEventCoords(pt, *lastClickPoint);
167 : }
168 : }
169 0 : return nsImageFrame::HandleEvent(aPresContext, aEvent, aEventStatus);
170 : }
171 :
172 : void
173 0 : nsImageControlFrame::SetFocus(bool aOn, bool aRepaint)
174 : {
175 0 : }
176 :
177 : nsresult
178 0 : nsImageControlFrame::GetCursor(const nsPoint& aPoint,
179 : nsIFrame::Cursor& aCursor)
180 : {
181 : // Use style defined cursor if one is provided, otherwise when
182 : // the cursor style is "auto" we use the pointer cursor.
183 0 : FillCursorInformationFromStyle(StyleUserInterface(), aCursor);
184 :
185 0 : if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) {
186 0 : aCursor.mCursor = NS_STYLE_CURSOR_POINTER;
187 : }
188 :
189 0 : return NS_OK;
190 : }
191 :
192 : nsresult
193 0 : nsImageControlFrame::SetFormProperty(nsIAtom* aName,
194 : const nsAString& aValue)
195 : {
196 0 : return NS_OK;
197 : }
|