Tue, 06 Jan 2015 21:39:09 +0100
Conditionally force memory storage according to privacy.thirdparty.isolate;
This solves Tor bug #9701, complying with disk avoidance documented in
https://www.torproject.org/projects/torbrowser/design/#disk-avoidance.
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 nsNumberControlFrame_h__ |
michael@0 | 7 | #define nsNumberControlFrame_h__ |
michael@0 | 8 | |
michael@0 | 9 | #include "mozilla/Attributes.h" |
michael@0 | 10 | #include "nsContainerFrame.h" |
michael@0 | 11 | #include "nsIFormControlFrame.h" |
michael@0 | 12 | #include "nsITextControlFrame.h" |
michael@0 | 13 | #include "nsIAnonymousContentCreator.h" |
michael@0 | 14 | #include "nsCOMPtr.h" |
michael@0 | 15 | |
michael@0 | 16 | class nsPresContext; |
michael@0 | 17 | |
michael@0 | 18 | namespace mozilla { |
michael@0 | 19 | class WidgetEvent; |
michael@0 | 20 | class WidgetGUIEvent; |
michael@0 | 21 | namespace dom { |
michael@0 | 22 | class HTMLInputElement; |
michael@0 | 23 | } |
michael@0 | 24 | } |
michael@0 | 25 | |
michael@0 | 26 | /** |
michael@0 | 27 | * This frame type is used for <input type=number>. |
michael@0 | 28 | */ |
michael@0 | 29 | class nsNumberControlFrame MOZ_FINAL : public nsContainerFrame |
michael@0 | 30 | , public nsIAnonymousContentCreator |
michael@0 | 31 | , public nsITextControlFrame |
michael@0 | 32 | { |
michael@0 | 33 | friend nsIFrame* |
michael@0 | 34 | NS_NewNumberControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext); |
michael@0 | 35 | |
michael@0 | 36 | typedef mozilla::dom::Element Element; |
michael@0 | 37 | typedef mozilla::dom::HTMLInputElement HTMLInputElement; |
michael@0 | 38 | typedef mozilla::WidgetEvent WidgetEvent; |
michael@0 | 39 | typedef mozilla::WidgetGUIEvent WidgetGUIEvent; |
michael@0 | 40 | |
michael@0 | 41 | nsNumberControlFrame(nsStyleContext* aContext); |
michael@0 | 42 | |
michael@0 | 43 | public: |
michael@0 | 44 | NS_DECL_QUERYFRAME_TARGET(nsNumberControlFrame) |
michael@0 | 45 | NS_DECL_QUERYFRAME |
michael@0 | 46 | NS_DECL_FRAMEARENA_HELPERS |
michael@0 | 47 | |
michael@0 | 48 | virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE; |
michael@0 | 49 | virtual void ContentStatesChanged(mozilla::EventStates aStates) MOZ_OVERRIDE; |
michael@0 | 50 | virtual bool IsLeaf() const MOZ_OVERRIDE { return true; } |
michael@0 | 51 | |
michael@0 | 52 | #ifdef ACCESSIBILITY |
michael@0 | 53 | virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE; |
michael@0 | 54 | #endif |
michael@0 | 55 | |
michael@0 | 56 | virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE; |
michael@0 | 57 | |
michael@0 | 58 | virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE; |
michael@0 | 59 | |
michael@0 | 60 | virtual nsresult Reflow(nsPresContext* aPresContext, |
michael@0 | 61 | nsHTMLReflowMetrics& aDesiredSize, |
michael@0 | 62 | const nsHTMLReflowState& aReflowState, |
michael@0 | 63 | nsReflowStatus& aStatus) MOZ_OVERRIDE; |
michael@0 | 64 | |
michael@0 | 65 | virtual nsresult AttributeChanged(int32_t aNameSpaceID, |
michael@0 | 66 | nsIAtom* aAttribute, |
michael@0 | 67 | int32_t aModType) MOZ_OVERRIDE; |
michael@0 | 68 | |
michael@0 | 69 | // nsIAnonymousContentCreator |
michael@0 | 70 | virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE; |
michael@0 | 71 | virtual void AppendAnonymousContentTo(nsBaseContentList& aElements, |
michael@0 | 72 | uint32_t aFilter) MOZ_OVERRIDE; |
michael@0 | 73 | |
michael@0 | 74 | #ifdef DEBUG_FRAME_DUMP |
michael@0 | 75 | virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE { |
michael@0 | 76 | return MakeFrameName(NS_LITERAL_STRING("NumberControl"), aResult); |
michael@0 | 77 | } |
michael@0 | 78 | #endif |
michael@0 | 79 | |
michael@0 | 80 | virtual nsIAtom* GetType() const MOZ_OVERRIDE; |
michael@0 | 81 | |
michael@0 | 82 | virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE |
michael@0 | 83 | { |
michael@0 | 84 | return nsContainerFrame::IsFrameOfType(aFlags & |
michael@0 | 85 | ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock)); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | // nsITextControlFrame |
michael@0 | 89 | NS_IMETHOD GetEditor(nsIEditor **aEditor) MOZ_OVERRIDE; |
michael@0 | 90 | |
michael@0 | 91 | NS_IMETHOD SetSelectionStart(int32_t aSelectionStart) MOZ_OVERRIDE; |
michael@0 | 92 | NS_IMETHOD SetSelectionEnd(int32_t aSelectionEnd) MOZ_OVERRIDE; |
michael@0 | 93 | |
michael@0 | 94 | NS_IMETHOD SetSelectionRange(int32_t aSelectionStart, |
michael@0 | 95 | int32_t aSelectionEnd, |
michael@0 | 96 | SelectionDirection aDirection = eNone) MOZ_OVERRIDE; |
michael@0 | 97 | |
michael@0 | 98 | NS_IMETHOD GetSelectionRange(int32_t* aSelectionStart, |
michael@0 | 99 | int32_t* aSelectionEnd, |
michael@0 | 100 | SelectionDirection* aDirection = nullptr) MOZ_OVERRIDE; |
michael@0 | 101 | |
michael@0 | 102 | NS_IMETHOD GetOwnedSelectionController(nsISelectionController** aSelCon) MOZ_OVERRIDE; |
michael@0 | 103 | virtual nsFrameSelection* GetOwnedFrameSelection() MOZ_OVERRIDE; |
michael@0 | 104 | |
michael@0 | 105 | virtual nsresult GetPhonetic(nsAString& aPhonetic) MOZ_OVERRIDE; |
michael@0 | 106 | |
michael@0 | 107 | /** |
michael@0 | 108 | * Ensure mEditor is initialized with the proper flags and the default value. |
michael@0 | 109 | * @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created |
michael@0 | 110 | * @throws various and sundry other things |
michael@0 | 111 | */ |
michael@0 | 112 | virtual nsresult EnsureEditorInitialized() MOZ_OVERRIDE; |
michael@0 | 113 | |
michael@0 | 114 | virtual nsresult ScrollSelectionIntoView() MOZ_OVERRIDE; |
michael@0 | 115 | |
michael@0 | 116 | // nsIFormControlFrame |
michael@0 | 117 | virtual void SetFocus(bool aOn, bool aRepaint) MOZ_OVERRIDE; |
michael@0 | 118 | virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE; |
michael@0 | 119 | |
michael@0 | 120 | /** |
michael@0 | 121 | * This method attempts to localizes aValue and then sets the result as the |
michael@0 | 122 | * value of our anonymous text control. It's called when our |
michael@0 | 123 | * HTMLInputElement's value changes, when we need to sync up the value |
michael@0 | 124 | * displayed in our anonymous text control. |
michael@0 | 125 | */ |
michael@0 | 126 | void SetValueOfAnonTextControl(const nsAString& aValue); |
michael@0 | 127 | |
michael@0 | 128 | /** |
michael@0 | 129 | * This method gets the string value of our anonymous text control, |
michael@0 | 130 | * attempts to normalizes (de-localizes) it, then sets the outparam aValue to |
michael@0 | 131 | * the result. It's called when user input changes the text value of our |
michael@0 | 132 | * anonymous text control so that we can sync up the internal value of our |
michael@0 | 133 | * HTMLInputElement. |
michael@0 | 134 | */ |
michael@0 | 135 | void GetValueOfAnonTextControl(nsAString& aValue); |
michael@0 | 136 | |
michael@0 | 137 | bool AnonTextControlIsEmpty(); |
michael@0 | 138 | |
michael@0 | 139 | /** |
michael@0 | 140 | * Called to notify this frame that its HTMLInputElement is currently |
michael@0 | 141 | * processing a DOM 'input' event. |
michael@0 | 142 | */ |
michael@0 | 143 | void HandlingInputEvent(bool aHandlingEvent) |
michael@0 | 144 | { |
michael@0 | 145 | mHandlingInputEvent = aHandlingEvent; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | HTMLInputElement* GetAnonTextControl(); |
michael@0 | 149 | |
michael@0 | 150 | /** |
michael@0 | 151 | * If the frame is the frame for an nsNumberControlFrame's anonymous text |
michael@0 | 152 | * field, returns the nsNumberControlFrame. Else returns nullptr. |
michael@0 | 153 | */ |
michael@0 | 154 | static nsNumberControlFrame* GetNumberControlFrameForTextField(nsIFrame* aFrame); |
michael@0 | 155 | |
michael@0 | 156 | /** |
michael@0 | 157 | * If the frame is the frame for an nsNumberControlFrame's up or down spin |
michael@0 | 158 | * button, returns the nsNumberControlFrame. Else returns nullptr. |
michael@0 | 159 | */ |
michael@0 | 160 | static nsNumberControlFrame* GetNumberControlFrameForSpinButton(nsIFrame* aFrame); |
michael@0 | 161 | |
michael@0 | 162 | enum SpinButtonEnum { |
michael@0 | 163 | eSpinButtonNone, |
michael@0 | 164 | eSpinButtonUp, |
michael@0 | 165 | eSpinButtonDown |
michael@0 | 166 | }; |
michael@0 | 167 | |
michael@0 | 168 | /** |
michael@0 | 169 | * Returns one of the SpinButtonEnum values to depending on whether the |
michael@0 | 170 | * pointer event is over the spin-up button, the spin-down button, or |
michael@0 | 171 | * neither. |
michael@0 | 172 | */ |
michael@0 | 173 | int32_t GetSpinButtonForPointerEvent(WidgetGUIEvent* aEvent) const; |
michael@0 | 174 | |
michael@0 | 175 | void SpinnerStateChanged() const; |
michael@0 | 176 | |
michael@0 | 177 | bool SpinnerUpButtonIsDepressed() const; |
michael@0 | 178 | bool SpinnerDownButtonIsDepressed() const; |
michael@0 | 179 | |
michael@0 | 180 | bool IsFocused() const; |
michael@0 | 181 | |
michael@0 | 182 | void HandleFocusEvent(WidgetEvent* aEvent); |
michael@0 | 183 | |
michael@0 | 184 | /** |
michael@0 | 185 | * Our element had HTMLInputElement::Select() called on it. |
michael@0 | 186 | */ |
michael@0 | 187 | nsresult HandleSelectCall(); |
michael@0 | 188 | |
michael@0 | 189 | virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE; |
michael@0 | 190 | |
michael@0 | 191 | bool ShouldUseNativeStyleForSpinner() const; |
michael@0 | 192 | |
michael@0 | 193 | private: |
michael@0 | 194 | |
michael@0 | 195 | nsITextControlFrame* GetTextFieldFrame(); |
michael@0 | 196 | nsresult MakeAnonymousElement(Element** aResult, |
michael@0 | 197 | nsTArray<ContentInfo>& aElements, |
michael@0 | 198 | nsIAtom* aTagName, |
michael@0 | 199 | nsCSSPseudoElements::Type aPseudoType, |
michael@0 | 200 | nsStyleContext* aParentContext); |
michael@0 | 201 | |
michael@0 | 202 | class SyncDisabledStateEvent; |
michael@0 | 203 | friend class SyncDisabledStateEvent; |
michael@0 | 204 | class SyncDisabledStateEvent : public nsRunnable |
michael@0 | 205 | { |
michael@0 | 206 | public: |
michael@0 | 207 | SyncDisabledStateEvent(nsNumberControlFrame* aFrame) |
michael@0 | 208 | : mFrame(aFrame) |
michael@0 | 209 | {} |
michael@0 | 210 | |
michael@0 | 211 | NS_IMETHOD Run() MOZ_OVERRIDE |
michael@0 | 212 | { |
michael@0 | 213 | nsNumberControlFrame* frame = |
michael@0 | 214 | static_cast<nsNumberControlFrame*>(mFrame.GetFrame()); |
michael@0 | 215 | NS_ENSURE_STATE(frame); |
michael@0 | 216 | |
michael@0 | 217 | frame->SyncDisabledState(); |
michael@0 | 218 | return NS_OK; |
michael@0 | 219 | } |
michael@0 | 220 | |
michael@0 | 221 | private: |
michael@0 | 222 | nsWeakFrame mFrame; |
michael@0 | 223 | }; |
michael@0 | 224 | |
michael@0 | 225 | /** |
michael@0 | 226 | * Sync the disabled state of the anonymous children up with our content's. |
michael@0 | 227 | */ |
michael@0 | 228 | void SyncDisabledState(); |
michael@0 | 229 | |
michael@0 | 230 | /** |
michael@0 | 231 | * The text field used to edit and show the number. |
michael@0 | 232 | * @see nsNumberControlFrame::CreateAnonymousContent. |
michael@0 | 233 | */ |
michael@0 | 234 | nsCOMPtr<Element> mOuterWrapper; |
michael@0 | 235 | nsCOMPtr<Element> mTextField; |
michael@0 | 236 | nsCOMPtr<Element> mSpinBox; |
michael@0 | 237 | nsCOMPtr<Element> mSpinUp; |
michael@0 | 238 | nsCOMPtr<Element> mSpinDown; |
michael@0 | 239 | bool mHandlingInputEvent; |
michael@0 | 240 | }; |
michael@0 | 241 | |
michael@0 | 242 | #endif // nsNumberControlFrame_h__ |