1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/layout/forms/nsImageControlFrame.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,206 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.6 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.8 +#include "nsImageFrame.h" 1.9 +#include "nsIFormControlFrame.h" 1.10 +#include "nsPresContext.h" 1.11 +#include "nsGkAtoms.h" 1.12 +#include "nsStyleConsts.h" 1.13 +#include "nsFormControlFrame.h" 1.14 +#include "nsLayoutUtils.h" 1.15 +#include "mozilla/MouseEvents.h" 1.16 + 1.17 +using namespace mozilla; 1.18 + 1.19 +typedef nsImageFrame nsImageControlFrameSuper; 1.20 +class nsImageControlFrame : public nsImageControlFrameSuper, 1.21 + public nsIFormControlFrame 1.22 +{ 1.23 +public: 1.24 + nsImageControlFrame(nsStyleContext* aContext); 1.25 + ~nsImageControlFrame(); 1.26 + 1.27 + virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; 1.28 + virtual void Init(nsIContent* aContent, 1.29 + nsIFrame* aParent, 1.30 + nsIFrame* aPrevInFlow) MOZ_OVERRIDE; 1.31 + 1.32 + NS_DECL_QUERYFRAME 1.33 + NS_DECL_FRAMEARENA_HELPERS 1.34 + 1.35 + virtual nsresult Reflow(nsPresContext* aPresContext, 1.36 + nsHTMLReflowMetrics& aDesiredSize, 1.37 + const nsHTMLReflowState& aReflowState, 1.38 + nsReflowStatus& aStatus) MOZ_OVERRIDE; 1.39 + 1.40 + virtual nsresult HandleEvent(nsPresContext* aPresContext, 1.41 + WidgetGUIEvent* aEvent, 1.42 + nsEventStatus* aEventStatus) MOZ_OVERRIDE; 1.43 + 1.44 + virtual nsIAtom* GetType() const MOZ_OVERRIDE; 1.45 + 1.46 +#ifdef ACCESSIBILITY 1.47 + virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; 1.48 +#endif 1.49 + 1.50 +#ifdef DEBUG_FRAME_DUMP 1.51 + virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { 1.52 + return MakeFrameName(NS_LITERAL_STRING("ImageControl"), aResult); 1.53 + } 1.54 +#endif 1.55 + 1.56 + virtual nsresult GetCursor(const nsPoint& aPoint, 1.57 + nsIFrame::Cursor& aCursor) MOZ_OVERRIDE; 1.58 + // nsIFormContromFrame 1.59 + virtual void SetFocus(bool aOn, bool aRepaint) MOZ_OVERRIDE; 1.60 + virtual nsresult SetFormProperty(nsIAtom* aName, 1.61 + const nsAString& aValue) MOZ_OVERRIDE; 1.62 +}; 1.63 + 1.64 + 1.65 +nsImageControlFrame::nsImageControlFrame(nsStyleContext* aContext): 1.66 + nsImageControlFrameSuper(aContext) 1.67 +{ 1.68 +} 1.69 + 1.70 +nsImageControlFrame::~nsImageControlFrame() 1.71 +{ 1.72 +} 1.73 + 1.74 +void 1.75 +nsImageControlFrame::DestroyFrom(nsIFrame* aDestructRoot) 1.76 +{ 1.77 + if (!GetPrevInFlow()) { 1.78 + nsFormControlFrame::RegUnRegAccessKey(this, false); 1.79 + } 1.80 + nsImageControlFrameSuper::DestroyFrom(aDestructRoot); 1.81 +} 1.82 + 1.83 +nsIFrame* 1.84 +NS_NewImageControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext) 1.85 +{ 1.86 + return new (aPresShell) nsImageControlFrame(aContext); 1.87 +} 1.88 + 1.89 +NS_IMPL_FRAMEARENA_HELPERS(nsImageControlFrame) 1.90 + 1.91 +void 1.92 +nsImageControlFrame::Init(nsIContent* aContent, 1.93 + nsIFrame* aParent, 1.94 + nsIFrame* aPrevInFlow) 1.95 +{ 1.96 + nsImageControlFrameSuper::Init(aContent, aParent, aPrevInFlow); 1.97 + 1.98 + if (aPrevInFlow) { 1.99 + return; 1.100 + } 1.101 + 1.102 + mContent->SetProperty(nsGkAtoms::imageClickedPoint, 1.103 + new nsIntPoint(0, 0), 1.104 + nsINode::DeleteProperty<nsIntPoint>); 1.105 +} 1.106 + 1.107 +NS_QUERYFRAME_HEAD(nsImageControlFrame) 1.108 + NS_QUERYFRAME_ENTRY(nsIFormControlFrame) 1.109 +NS_QUERYFRAME_TAIL_INHERITING(nsImageControlFrameSuper) 1.110 + 1.111 +#ifdef ACCESSIBILITY 1.112 +a11y::AccType 1.113 +nsImageControlFrame::AccessibleType() 1.114 +{ 1.115 + if (mContent->Tag() == nsGkAtoms::button || 1.116 + mContent->Tag() == nsGkAtoms::input) { 1.117 + return a11y::eHTMLButtonType; 1.118 + } 1.119 + 1.120 + return a11y::eNoType; 1.121 +} 1.122 +#endif 1.123 + 1.124 +nsIAtom* 1.125 +nsImageControlFrame::GetType() const 1.126 +{ 1.127 + return nsGkAtoms::imageControlFrame; 1.128 +} 1.129 + 1.130 +nsresult 1.131 +nsImageControlFrame::Reflow(nsPresContext* aPresContext, 1.132 + nsHTMLReflowMetrics& aDesiredSize, 1.133 + const nsHTMLReflowState& aReflowState, 1.134 + nsReflowStatus& aStatus) 1.135 +{ 1.136 + DO_GLOBAL_REFLOW_COUNT("nsImageControlFrame"); 1.137 + DISPLAY_REFLOW(aPresContext, this, aReflowState, aDesiredSize, aStatus); 1.138 + if (!GetPrevInFlow() && (mState & NS_FRAME_FIRST_REFLOW)) { 1.139 + nsFormControlFrame::RegUnRegAccessKey(this, true); 1.140 + } 1.141 + return nsImageControlFrameSuper::Reflow(aPresContext, aDesiredSize, aReflowState, aStatus); 1.142 +} 1.143 + 1.144 +nsresult 1.145 +nsImageControlFrame::HandleEvent(nsPresContext* aPresContext, 1.146 + WidgetGUIEvent* aEvent, 1.147 + nsEventStatus* aEventStatus) 1.148 +{ 1.149 + NS_ENSURE_ARG_POINTER(aEventStatus); 1.150 + 1.151 + // Don't do anything if the event has already been handled by someone 1.152 + if (nsEventStatus_eConsumeNoDefault == *aEventStatus) { 1.153 + return NS_OK; 1.154 + } 1.155 + 1.156 + // do we have user-input style? 1.157 + const nsStyleUserInterface* uiStyle = StyleUserInterface(); 1.158 + if (uiStyle->mUserInput == NS_STYLE_USER_INPUT_NONE || uiStyle->mUserInput == NS_STYLE_USER_INPUT_DISABLED) 1.159 + return nsFrame::HandleEvent(aPresContext, aEvent, aEventStatus); 1.160 + 1.161 + if (mContent->HasAttr(kNameSpaceID_None, nsGkAtoms::disabled)) { // XXX cache disabled 1.162 + return NS_OK; 1.163 + } 1.164 + 1.165 + *aEventStatus = nsEventStatus_eIgnore; 1.166 + 1.167 + if (aEvent->message == NS_MOUSE_BUTTON_UP && 1.168 + aEvent->AsMouseEvent()->button == WidgetMouseEvent::eLeftButton) { 1.169 + // Store click point for HTMLInputElement::SubmitNamesValues 1.170 + // Do this on MouseUp because the specs don't say and that's what IE does 1.171 + nsIntPoint* lastClickPoint = 1.172 + static_cast<nsIntPoint*> 1.173 + (mContent->GetProperty(nsGkAtoms::imageClickedPoint)); 1.174 + if (lastClickPoint) { 1.175 + // normally lastClickedPoint is not null, as it's allocated in Init() 1.176 + nsPoint pt = nsLayoutUtils::GetEventCoordinatesRelativeTo(aEvent, this); 1.177 + TranslateEventCoords(pt, *lastClickPoint); 1.178 + } 1.179 + } 1.180 + return nsImageControlFrameSuper::HandleEvent(aPresContext, aEvent, 1.181 + aEventStatus); 1.182 +} 1.183 + 1.184 +void 1.185 +nsImageControlFrame::SetFocus(bool aOn, bool aRepaint) 1.186 +{ 1.187 +} 1.188 + 1.189 +nsresult 1.190 +nsImageControlFrame::GetCursor(const nsPoint& aPoint, 1.191 + nsIFrame::Cursor& aCursor) 1.192 +{ 1.193 + // Use style defined cursor if one is provided, otherwise when 1.194 + // the cursor style is "auto" we use the pointer cursor. 1.195 + FillCursorInformationFromStyle(StyleUserInterface(), aCursor); 1.196 + 1.197 + if (NS_STYLE_CURSOR_AUTO == aCursor.mCursor) { 1.198 + aCursor.mCursor = NS_STYLE_CURSOR_POINTER; 1.199 + } 1.200 + 1.201 + return NS_OK; 1.202 +} 1.203 + 1.204 +nsresult 1.205 +nsImageControlFrame::SetFormProperty(nsIAtom* aName, 1.206 + const nsAString& aValue) 1.207 +{ 1.208 + return NS_OK; 1.209 +}