Coverage Report

Created: 2018-09-25 14:53

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