Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 | |
michael@0 | 6 | #ifndef nsTextControlFrame_h___ |
michael@0 | 7 | #define nsTextControlFrame_h___ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsContainerFrame.h" |
michael@0 | 11 | #include "nsIAnonymousContentCreator.h" |
michael@0 | 12 | #include "nsITextControlFrame.h" |
michael@0 | 13 | #include "nsITextControlElement.h" |
michael@0 | 14 | #include "nsIStatefulFrame.h" |
michael@0 | 15 | |
michael@0 | 16 | class nsISelectionController; |
michael@0 | 17 | class EditorInitializerEntryTracker; |
michael@0 | 18 | class nsTextEditorState; |
michael@0 | 19 | class nsIEditor; |
michael@0 | 20 | namespace mozilla { |
michael@0 | 21 | namespace dom { |
michael@0 | 22 | class Element; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | class nsTextControlFrame : public nsContainerFrame, |
michael@0 | 27 | public nsIAnonymousContentCreator, |
michael@0 | 28 | public nsITextControlFrame, |
michael@0 | 29 | public nsIStatefulFrame |
michael@0 | 30 | { |
michael@0 | 31 | public: |
michael@0 | 32 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 33 | |
michael@0 | 34 | NS_DECLARE_FRAME_PROPERTY(ContentScrollPos, DestroyPoint) |
michael@0 | 35 | |
michael@0 | 36 | nsTextControlFrame(nsIPresShell* aShell, nsStyleContext* aContext); |
michael@0 | 37 | virtual ~nsTextControlFrame(); |
michael@0 | 38 | |
michael@0 | 39 | virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
michael@0 | 40 | |
michael@0 | 41 | virtual nsIScrollableFrame* GetScrollTargetFrame() MOZ_OVERRIDE { |
michael@0 | 42 | return do_QueryFrame(GetFirstPrincipalChild()); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE; |
michael@0 | 46 | virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE; |
michael@0 | 47 | |
michael@0 | 48 | virtual nsSize ComputeAutoSize(nsRenderingContext *aRenderingContext, |
michael@0 | 49 | nsSize aCBSize, nscoord aAvailableWidth, |
michael@0 | 50 | nsSize aMargin, nsSize aBorder, |
michael@0 | 51 | nsSize aPadding, bool aShrinkWrap) MOZ_OVERRIDE; |
michael@0 | 52 | |
michael@0 | 53 | virtual nsresult Reflow(nsPresContext* aPresContext, |
michael@0 | 54 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 55 | const nsHTMLReflowState& aReflowState, |
michael@0 | 56 | nsReflowStatus& aStatus) MOZ_OVERRIDE; |
michael@0 | 57 | |
michael@0 | 58 | virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) MOZ_OVERRIDE; |
michael@0 | 59 | virtual bool IsCollapsed() MOZ_OVERRIDE; |
michael@0 | 60 | |
michael@0 | 61 | virtual bool IsLeaf() const MOZ_OVERRIDE; |
michael@0 | 62 | |
michael@0 | 63 | #ifdef ACCESSIBILITY |
michael@0 | 64 | virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
michael@0 | 65 | #endif |
michael@0 | 66 | |
michael@0 | 67 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 68 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE |
michael@0 | 69 | { |
michael@0 | 70 | aResult.AssignLiteral("nsTextControlFrame"); |
michael@0 | 71 | return NS_OK; |
michael@0 | 72 | } |
michael@0 | 73 | #endif |
michael@0 | 74 | |
michael@0 | 75 | virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
michael@0 | 76 | { |
michael@0 | 77 | // nsStackFrame is already both of these, but that's somewhat bogus, |
michael@0 | 78 | // and we really mean it. |
michael@0 | 79 | return nsContainerFrame::IsFrameOfType(aFlags & |
michael@0 | 80 | ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | // nsIAnonymousContentCreator |
michael@0 | 84 | virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE; |
michael@0 | 85 | virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, |
michael@0 | 86 | uint32_t aFilter) MOZ_OVERRIDE; |
michael@0 | 87 | |
michael@0 | 88 | // Utility methods to set current widget state |
michael@0 | 89 | |
michael@0 | 90 | virtual nsresult SetInitialChildList(ChildListID aListID, |
michael@0 | 91 | nsFrameList& aChildList) MOZ_OVERRIDE; |
michael@0 | 92 | |
michael@0 | 93 | virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder, |
michael@0 | 94 | const nsRect& aDirtyRect, |
michael@0 | 95 | const nsDisplayListSet& aLists) MOZ_OVERRIDE; |
michael@0 | 96 | |
michael@0 | 97 | virtual mozilla::dom::Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE; |
michael@0 | 98 | |
michael@0 | 99 | //==== BEGIN NSIFORMCONTROLFRAME |
michael@0 | 100 | virtual void SetFocus(bool aOn , bool aRepaint) MOZ_OVERRIDE; |
michael@0 | 101 | virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE; |
michael@0 | 102 | |
michael@0 | 103 | //==== END NSIFORMCONTROLFRAME |
michael@0 | 104 | |
michael@0 | 105 | //==== NSITEXTCONTROLFRAME |
michael@0 | 106 | |
michael@0 | 107 | NS_IMETHOD GetEditor(nsIEditor **aEditor) MOZ_OVERRIDE; |
michael@0 | 108 | NS_IMETHOD SetSelectionStart(int32_t aSelectionStart) MOZ_OVERRIDE; |
michael@0 | 109 | NS_IMETHOD SetSelectionEnd(int32_t aSelectionEnd) MOZ_OVERRIDE; |
michael@0 | 110 | NS_IMETHOD SetSelectionRange(int32_t aSelectionStart, |
michael@0 | 111 | int32_t aSelectionEnd, |
michael@0 | 112 | SelectionDirection aDirection = eNone) MOZ_OVERRIDE; |
michael@0 | 113 | NS_IMETHOD GetSelectionRange(int32_t* aSelectionStart, |
michael@0 | 114 | int32_t* aSelectionEnd, |
michael@0 | 115 | SelectionDirection* aDirection = nullptr) MOZ_OVERRIDE; |
michael@0 | 116 | NS_IMETHOD GetOwnedSelectionController(nsISelectionController** aSelCon) MOZ_OVERRIDE; |
michael@0 | 117 | virtual nsFrameSelection* GetOwnedFrameSelection() MOZ_OVERRIDE; |
michael@0 | 118 | |
michael@0 | 119 | nsresult GetPhonetic(nsAString& aPhonetic) MOZ_OVERRIDE; |
michael@0 | 120 | |
michael@0 | 121 | /** |
michael@0 | 122 | * Ensure mEditor is initialized with the proper flags and the default value. |
michael@0 | 123 | * @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created |
michael@0 | 124 | * @throws various and sundry other things |
michael@0 | 125 | */ |
michael@0 | 126 | virtual nsresult EnsureEditorInitialized() MOZ_OVERRIDE; |
michael@0 | 127 | |
michael@0 | 128 | //==== END NSITEXTCONTROLFRAME |
michael@0 | 129 | |
michael@0 | 130 | //==== NSISTATEFULFRAME |
michael@0 | 131 | |
michael@0 | 132 | NS_IMETHOD SaveState(nsPresState** aState) MOZ_OVERRIDE; |
michael@0 | 133 | NS_IMETHOD RestoreState(nsPresState* aState) MOZ_OVERRIDE; |
michael@0 | 134 | |
michael@0 | 135 | //=== END NSISTATEFULFRAME |
michael@0 | 136 | |
michael@0 | 137 | //==== OVERLOAD of nsIFrame |
michael@0 | 138 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 139 | |
michael@0 | 140 | /** handler for attribute changes to mContent */ |
michael@0 | 141 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 142 | nsIAtom* aAttribute, |
michael@0 | 143 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 144 | |
michael@0 | 145 | nsresult GetText(nsString& aText); |
michael@0 | 146 | |
michael@0 | 147 | virtual nsresult PeekOffset(nsPeekOffsetStruct *aPos) MOZ_OVERRIDE; |
michael@0 | 148 | |
michael@0 | 149 | NS_DECL_QUERYFRAME |
michael@0 | 150 | |
michael@0 | 151 | // Temp reference to scriptrunner |
michael@0 | 152 | // We could make these auto-Revoking via the "delete" entry for safety |
michael@0 | 153 | NS_DECLARE_FRAME_PROPERTY(TextControlInitializer, nullptr) |
michael@0 | 154 | |
michael@0 | 155 | protected: |
michael@0 | 156 | /** |
michael@0 | 157 | * Launch the reflow on the child frames - see nsTextControlFrame::Reflow() |
michael@0 | 158 | */ |
michael@0 | 159 | void ReflowTextControlChild(nsIFrame* aFrame, |
michael@0 | 160 | nsPresContext* aPresContext, |
michael@0 | 161 | const nsHTMLReflowState& aReflowState, |
michael@0 | 162 | nsReflowStatus& aStatus, |
michael@0 | 163 | nsHTMLReflowMetrics& aParentDesiredSize); |
michael@0 | 164 | |
michael@0 | 165 | public: //for methods who access nsTextControlFrame directly |
michael@0 | 166 | void SetValueChanged(bool aValueChanged); |
michael@0 | 167 | |
michael@0 | 168 | // called by the focus listener |
michael@0 | 169 | nsresult MaybeBeginSecureKeyboardInput(); |
michael@0 | 170 | void MaybeEndSecureKeyboardInput(); |
michael@0 | 171 | |
michael@0 | 172 | #define DEFINE_TEXTCTRL_FORWARDER(type, name) \ |
michael@0 | 173 | type name() { \ |
michael@0 | 174 | nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \ |
michael@0 | 175 | NS_ASSERTION(txtCtrl, "Content not a text control element"); \ |
michael@0 | 176 | return txtCtrl->name(); \ |
michael@0 | 177 | } |
michael@0 | 178 | #define DEFINE_TEXTCTRL_CONST_FORWARDER(type, name) \ |
michael@0 | 179 | type name() const { \ |
michael@0 | 180 | nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \ |
michael@0 | 181 | NS_ASSERTION(txtCtrl, "Content not a text control element"); \ |
michael@0 | 182 | return txtCtrl->name(); \ |
michael@0 | 183 | } |
michael@0 | 184 | |
michael@0 | 185 | DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsSingleLineTextControl) |
michael@0 | 186 | DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsTextArea) |
michael@0 | 187 | DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPlainTextControl) |
michael@0 | 188 | DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPasswordTextControl) |
michael@0 | 189 | DEFINE_TEXTCTRL_FORWARDER(int32_t, GetCols) |
michael@0 | 190 | DEFINE_TEXTCTRL_FORWARDER(int32_t, GetWrapCols) |
michael@0 | 191 | DEFINE_TEXTCTRL_FORWARDER(int32_t, GetRows) |
michael@0 | 192 | |
michael@0 | 193 | #undef DEFINE_TEXTCTRL_CONST_FORWARDER |
michael@0 | 194 | #undef DEFINE_TEXTCTRL_FORWARDER |
michael@0 | 195 | |
michael@0 | 196 | protected: |
michael@0 | 197 | class EditorInitializer; |
michael@0 | 198 | friend class EditorInitializer; |
michael@0 | 199 | friend class nsTextEditorState; // needs access to UpdateValueDisplay |
michael@0 | 200 | |
michael@0 | 201 | class EditorInitializer : public nsRunnable { |
michael@0 | 202 | public: |
michael@0 | 203 | EditorInitializer(nsTextControlFrame* aFrame) : |
michael@0 | 204 | mFrame(aFrame) {} |
michael@0 | 205 | |
michael@0 | 206 | NS_IMETHOD Run() MOZ_OVERRIDE; |
michael@0 | 207 | |
michael@0 | 208 | // avoids use of nsWeakFrame |
michael@0 | 209 | void Revoke() { |
michael@0 | 210 | mFrame = nullptr; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | private: |
michael@0 | 214 | nsTextControlFrame* mFrame; |
michael@0 | 215 | }; |
michael@0 | 216 | |
michael@0 | 217 | class ScrollOnFocusEvent; |
michael@0 | 218 | friend class ScrollOnFocusEvent; |
michael@0 | 219 | |
michael@0 | 220 | class ScrollOnFocusEvent : public nsRunnable { |
michael@0 | 221 | public: |
michael@0 | 222 | ScrollOnFocusEvent(nsTextControlFrame* aFrame) : |
michael@0 | 223 | mFrame(aFrame) {} |
michael@0 | 224 | |
michael@0 | 225 | NS_DECL_NSIRUNNABLE |
michael@0 | 226 | |
michael@0 | 227 | void Revoke() { |
michael@0 | 228 | mFrame = nullptr; |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | private: |
michael@0 | 232 | nsTextControlFrame* mFrame; |
michael@0 | 233 | }; |
michael@0 | 234 | |
michael@0 | 235 | nsresult OffsetToDOMPoint(int32_t aOffset, nsIDOMNode** aResult, int32_t* aPosition); |
michael@0 | 236 | |
michael@0 | 237 | /** |
michael@0 | 238 | * Update the textnode under our anonymous div to show the new |
michael@0 | 239 | * value. This should only be called when we have no editor yet. |
michael@0 | 240 | * @throws NS_ERROR_UNEXPECTED if the div has no text content |
michael@0 | 241 | */ |
michael@0 | 242 | nsresult UpdateValueDisplay(bool aNotify, |
michael@0 | 243 | bool aBeforeEditorInit = false, |
michael@0 | 244 | const nsAString *aValue = nullptr); |
michael@0 | 245 | |
michael@0 | 246 | /** |
michael@0 | 247 | * Get the maxlength attribute |
michael@0 | 248 | * @param aMaxLength the value of the max length attr |
michael@0 | 249 | * @returns false if attr not defined |
michael@0 | 250 | */ |
michael@0 | 251 | bool GetMaxLength(int32_t* aMaxLength); |
michael@0 | 252 | |
michael@0 | 253 | /** |
michael@0 | 254 | * Find out whether an attribute exists on the content or not. |
michael@0 | 255 | * @param aAtt the attribute to determine the existence of |
michael@0 | 256 | * @returns false if it does not exist |
michael@0 | 257 | */ |
michael@0 | 258 | bool AttributeExists(nsIAtom *aAtt) const |
michael@0 | 259 | { return mContent && mContent->HasAttr(kNameSpaceID_None, aAtt); } |
michael@0 | 260 | |
michael@0 | 261 | /** |
michael@0 | 262 | * We call this when we are being destroyed or removed from the PFM. |
michael@0 | 263 | * @param aPresContext the current pres context |
michael@0 | 264 | */ |
michael@0 | 265 | void PreDestroy(); |
michael@0 | 266 | |
michael@0 | 267 | // Compute our intrinsic size. This does not include any borders, paddings, |
michael@0 | 268 | // etc. Just the size of our actual area for the text (and the scrollbars, |
michael@0 | 269 | // for <textarea>). |
michael@0 | 270 | nsresult CalcIntrinsicSize(nsRenderingContext* aRenderingContext, |
michael@0 | 271 | nsSize& aIntrinsicSize, |
michael@0 | 272 | float aFontSizeInflation); |
michael@0 | 273 | |
michael@0 | 274 | nsresult ScrollSelectionIntoView() MOZ_OVERRIDE; |
michael@0 | 275 | |
michael@0 | 276 | private: |
michael@0 | 277 | //helper methods |
michael@0 | 278 | nsresult SetSelectionInternal(nsIDOMNode *aStartNode, int32_t aStartOffset, |
michael@0 | 279 | nsIDOMNode *aEndNode, int32_t aEndOffset, |
michael@0 | 280 | SelectionDirection aDirection = eNone); |
michael@0 | 281 | nsresult SelectAllOrCollapseToEndOfText(bool aSelect); |
michael@0 | 282 | nsresult SetSelectionEndPoints(int32_t aSelStart, int32_t aSelEnd, |
michael@0 | 283 | SelectionDirection aDirection = eNone); |
michael@0 | 284 | |
michael@0 | 285 | /** |
michael@0 | 286 | * Return the root DOM element, and implicitly initialize the editor if needed. |
michael@0 | 287 | */ |
michael@0 | 288 | mozilla::dom::Element* GetRootNodeAndInitializeEditor(); |
michael@0 | 289 | nsresult GetRootNodeAndInitializeEditor(nsIDOMElement **aRootElement); |
michael@0 | 290 | |
michael@0 | 291 | void FinishedInitializer() { |
michael@0 | 292 | Properties().Delete(TextControlInitializer()); |
michael@0 | 293 | } |
michael@0 | 294 | |
michael@0 | 295 | private: |
michael@0 | 296 | // these packed bools could instead use the high order bits on mState, saving 4 bytes |
michael@0 | 297 | bool mEditorHasBeenInitialized; |
michael@0 | 298 | bool mIsProcessing; |
michael@0 | 299 | // Keep track if we have asked a placeholder node creation. |
michael@0 | 300 | bool mUsePlaceholder; |
michael@0 | 301 | |
michael@0 | 302 | #ifdef DEBUG |
michael@0 | 303 | bool mInEditorInitialization; |
michael@0 | 304 | friend class EditorInitializerEntryTracker; |
michael@0 | 305 | #endif |
michael@0 | 306 | |
michael@0 | 307 | nsRevocableEventPtr<ScrollOnFocusEvent> mScrollEvent; |
michael@0 | 308 | }; |
michael@0 | 309 | |
michael@0 | 310 | #endif |
michael@0 | 311 | |
michael@0 | 312 |