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