layout/forms/nsNumberControlFrame.h

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/layout/forms/nsNumberControlFrame.h	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,242 @@
     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 +
     1.9 +#ifndef nsNumberControlFrame_h__
    1.10 +#define nsNumberControlFrame_h__
    1.11 +
    1.12 +#include "mozilla/Attributes.h"
    1.13 +#include "nsContainerFrame.h"
    1.14 +#include "nsIFormControlFrame.h"
    1.15 +#include "nsITextControlFrame.h"
    1.16 +#include "nsIAnonymousContentCreator.h"
    1.17 +#include "nsCOMPtr.h"
    1.18 +
    1.19 +class nsPresContext;
    1.20 +
    1.21 +namespace mozilla {
    1.22 +class WidgetEvent;
    1.23 +class WidgetGUIEvent;
    1.24 +namespace dom {
    1.25 +class HTMLInputElement;
    1.26 +}
    1.27 +}
    1.28 +
    1.29 +/**
    1.30 + * This frame type is used for <input type=number>.
    1.31 + */
    1.32 +class nsNumberControlFrame MOZ_FINAL : public nsContainerFrame
    1.33 +                                     , public nsIAnonymousContentCreator
    1.34 +                                     , public nsITextControlFrame
    1.35 +{
    1.36 +  friend nsIFrame*
    1.37 +  NS_NewNumberControlFrame(nsIPresShell* aPresShell, nsStyleContext* aContext);
    1.38 +
    1.39 +  typedef mozilla::dom::Element Element;
    1.40 +  typedef mozilla::dom::HTMLInputElement HTMLInputElement;
    1.41 +  typedef mozilla::WidgetEvent WidgetEvent;
    1.42 +  typedef mozilla::WidgetGUIEvent WidgetGUIEvent;
    1.43 +
    1.44 +  nsNumberControlFrame(nsStyleContext* aContext);
    1.45 +
    1.46 +public:
    1.47 +  NS_DECL_QUERYFRAME_TARGET(nsNumberControlFrame)
    1.48 +  NS_DECL_QUERYFRAME
    1.49 +  NS_DECL_FRAMEARENA_HELPERS
    1.50 +
    1.51 +  virtual void DestroyFrom(nsIFrame* aDestructRoot) MOZ_OVERRIDE;
    1.52 +  virtual void ContentStatesChanged(mozilla::EventStates aStates) MOZ_OVERRIDE;
    1.53 +  virtual bool IsLeaf() const MOZ_OVERRIDE { return true; }
    1.54 +
    1.55 +#ifdef ACCESSIBILITY
    1.56 +  virtual mozilla::a11y::AccType AccessibleType() MOZ_OVERRIDE;
    1.57 +#endif
    1.58 +
    1.59 +  virtual nscoord GetMinWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
    1.60 +
    1.61 +  virtual nscoord GetPrefWidth(nsRenderingContext* aRenderingContext) MOZ_OVERRIDE;
    1.62 +
    1.63 +  virtual nsresult Reflow(nsPresContext*           aPresContext,
    1.64 +                          nsHTMLReflowMetrics&     aDesiredSize,
    1.65 +                          const nsHTMLReflowState& aReflowState,
    1.66 +                          nsReflowStatus&          aStatus) MOZ_OVERRIDE;
    1.67 +
    1.68 +  virtual nsresult AttributeChanged(int32_t  aNameSpaceID,
    1.69 +                                    nsIAtom* aAttribute,
    1.70 +                                    int32_t  aModType) MOZ_OVERRIDE;
    1.71 +
    1.72 +  // nsIAnonymousContentCreator
    1.73 +  virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) MOZ_OVERRIDE;
    1.74 +  virtual void AppendAnonymousContentTo(nsBaseContentList& aElements,
    1.75 +                                        uint32_t aFilter) MOZ_OVERRIDE;
    1.76 +
    1.77 +#ifdef DEBUG_FRAME_DUMP
    1.78 +  virtual nsresult GetFrameName(nsAString& aResult) const MOZ_OVERRIDE {
    1.79 +    return MakeFrameName(NS_LITERAL_STRING("NumberControl"), aResult);
    1.80 +  }
    1.81 +#endif
    1.82 +
    1.83 +  virtual nsIAtom* GetType() const MOZ_OVERRIDE;
    1.84 +
    1.85 +  virtual bool IsFrameOfType(uint32_t aFlags) const MOZ_OVERRIDE
    1.86 +  {
    1.87 +    return nsContainerFrame::IsFrameOfType(aFlags &
    1.88 +      ~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
    1.89 +  }
    1.90 +
    1.91 +  // nsITextControlFrame
    1.92 +  NS_IMETHOD    GetEditor(nsIEditor **aEditor) MOZ_OVERRIDE;
    1.93 +
    1.94 +  NS_IMETHOD    SetSelectionStart(int32_t aSelectionStart) MOZ_OVERRIDE;
    1.95 +  NS_IMETHOD    SetSelectionEnd(int32_t aSelectionEnd) MOZ_OVERRIDE;
    1.96 +
    1.97 +  NS_IMETHOD    SetSelectionRange(int32_t aSelectionStart,
    1.98 +                                  int32_t aSelectionEnd,
    1.99 +                                  SelectionDirection aDirection = eNone) MOZ_OVERRIDE;
   1.100 +
   1.101 +  NS_IMETHOD    GetSelectionRange(int32_t* aSelectionStart,
   1.102 +                                  int32_t* aSelectionEnd,
   1.103 +                                  SelectionDirection* aDirection = nullptr) MOZ_OVERRIDE;
   1.104 +
   1.105 +  NS_IMETHOD    GetOwnedSelectionController(nsISelectionController** aSelCon) MOZ_OVERRIDE;
   1.106 +  virtual nsFrameSelection* GetOwnedFrameSelection() MOZ_OVERRIDE;
   1.107 +
   1.108 +  virtual nsresult GetPhonetic(nsAString& aPhonetic) MOZ_OVERRIDE;
   1.109 +
   1.110 +  /**
   1.111 +   * Ensure mEditor is initialized with the proper flags and the default value.
   1.112 +   * @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created
   1.113 +   * @throws various and sundry other things
   1.114 +   */
   1.115 +  virtual nsresult EnsureEditorInitialized() MOZ_OVERRIDE;
   1.116 +
   1.117 +  virtual nsresult ScrollSelectionIntoView() MOZ_OVERRIDE;
   1.118 +
   1.119 +  // nsIFormControlFrame
   1.120 +  virtual void SetFocus(bool aOn, bool aRepaint) MOZ_OVERRIDE;
   1.121 +  virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) MOZ_OVERRIDE;
   1.122 +
   1.123 +  /**
   1.124 +   * This method attempts to localizes aValue and then sets the result as the
   1.125 +   * value of our anonymous text control. It's called when our
   1.126 +   * HTMLInputElement's value changes, when we need to sync up the value
   1.127 +   * displayed in our anonymous text control.
   1.128 +   */
   1.129 +  void SetValueOfAnonTextControl(const nsAString& aValue);
   1.130 +
   1.131 +  /**
   1.132 +   * This method gets the string value of our anonymous text control,
   1.133 +   * attempts to normalizes (de-localizes) it, then sets the outparam aValue to
   1.134 +   * the result. It's called when user input changes the text value of our
   1.135 +   * anonymous text control so that we can sync up the internal value of our
   1.136 +   * HTMLInputElement.
   1.137 +   */
   1.138 +  void GetValueOfAnonTextControl(nsAString& aValue);
   1.139 +
   1.140 +  bool AnonTextControlIsEmpty();
   1.141 +
   1.142 +  /**
   1.143 +   * Called to notify this frame that its HTMLInputElement is currently
   1.144 +   * processing a DOM 'input' event.
   1.145 +   */
   1.146 +  void HandlingInputEvent(bool aHandlingEvent)
   1.147 +  {
   1.148 +    mHandlingInputEvent = aHandlingEvent;
   1.149 +  }
   1.150 +
   1.151 +  HTMLInputElement* GetAnonTextControl();
   1.152 +
   1.153 +  /**
   1.154 +   * If the frame is the frame for an nsNumberControlFrame's anonymous text
   1.155 +   * field, returns the nsNumberControlFrame. Else returns nullptr.
   1.156 +   */
   1.157 +  static nsNumberControlFrame* GetNumberControlFrameForTextField(nsIFrame* aFrame);
   1.158 +
   1.159 +  /**
   1.160 +   * If the frame is the frame for an nsNumberControlFrame's up or down spin
   1.161 +   * button, returns the nsNumberControlFrame. Else returns nullptr.
   1.162 +   */
   1.163 +  static nsNumberControlFrame* GetNumberControlFrameForSpinButton(nsIFrame* aFrame);
   1.164 +
   1.165 +  enum SpinButtonEnum {
   1.166 +    eSpinButtonNone,
   1.167 +    eSpinButtonUp,
   1.168 +    eSpinButtonDown
   1.169 +  };
   1.170 +
   1.171 +  /**
   1.172 +   * Returns one of the SpinButtonEnum values to depending on whether the
   1.173 +   * pointer event is over the spin-up button, the spin-down button, or
   1.174 +   * neither.
   1.175 +   */
   1.176 +  int32_t GetSpinButtonForPointerEvent(WidgetGUIEvent* aEvent) const;
   1.177 +
   1.178 +  void SpinnerStateChanged() const;
   1.179 +
   1.180 +  bool SpinnerUpButtonIsDepressed() const;
   1.181 +  bool SpinnerDownButtonIsDepressed() const;
   1.182 +
   1.183 +  bool IsFocused() const;
   1.184 +
   1.185 +  void HandleFocusEvent(WidgetEvent* aEvent);
   1.186 +
   1.187 +  /**
   1.188 +   * Our element had HTMLInputElement::Select() called on it.
   1.189 +   */
   1.190 +  nsresult HandleSelectCall();
   1.191 +
   1.192 +  virtual Element* GetPseudoElement(nsCSSPseudoElements::Type aType) MOZ_OVERRIDE;
   1.193 +
   1.194 +  bool ShouldUseNativeStyleForSpinner() const;
   1.195 +
   1.196 +private:
   1.197 +
   1.198 +  nsITextControlFrame* GetTextFieldFrame();
   1.199 +  nsresult MakeAnonymousElement(Element** aResult,
   1.200 +                                nsTArray<ContentInfo>& aElements,
   1.201 +                                nsIAtom* aTagName,
   1.202 +                                nsCSSPseudoElements::Type aPseudoType,
   1.203 +                                nsStyleContext* aParentContext);
   1.204 +
   1.205 +  class SyncDisabledStateEvent;
   1.206 +  friend class SyncDisabledStateEvent;
   1.207 +  class SyncDisabledStateEvent : public nsRunnable
   1.208 +  {
   1.209 +  public:
   1.210 +    SyncDisabledStateEvent(nsNumberControlFrame* aFrame)
   1.211 +    : mFrame(aFrame)
   1.212 +    {}
   1.213 +
   1.214 +    NS_IMETHOD Run() MOZ_OVERRIDE
   1.215 +    {
   1.216 +      nsNumberControlFrame* frame =
   1.217 +        static_cast<nsNumberControlFrame*>(mFrame.GetFrame());
   1.218 +      NS_ENSURE_STATE(frame);
   1.219 +
   1.220 +      frame->SyncDisabledState();
   1.221 +      return NS_OK;
   1.222 +    }
   1.223 +
   1.224 +  private:
   1.225 +    nsWeakFrame mFrame;
   1.226 +  };
   1.227 +
   1.228 +  /**
   1.229 +   * Sync the disabled state of the anonymous children up with our content's.
   1.230 +   */
   1.231 +  void SyncDisabledState();
   1.232 +
   1.233 +  /**
   1.234 +   * The text field used to edit and show the number.
   1.235 +   * @see nsNumberControlFrame::CreateAnonymousContent.
   1.236 +   */
   1.237 +  nsCOMPtr<Element> mOuterWrapper;
   1.238 +  nsCOMPtr<Element> mTextField;
   1.239 +  nsCOMPtr<Element> mSpinBox;
   1.240 +  nsCOMPtr<Element> mSpinUp;
   1.241 +  nsCOMPtr<Element> mSpinDown;
   1.242 +  bool mHandlingInputEvent;
   1.243 +};
   1.244 +
   1.245 +#endif // nsNumberControlFrame_h__

mercurial