DXR will be turned off on Tuesday, December 29th. It will redirect to Searchfox.
See the announcement on Discourse.

DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (882de07e4cbe)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef mozilla_TextControlElement_h
#define mozilla_TextControlElement_h

#include "mozilla/dom/FromParser.h"
#include "mozilla/dom/FromParser.h"
#include "mozilla/dom/NodeInfo.h"
#include "nsGenericHTMLElement.h"

class nsIContent;
class nsISelectionController;
class nsISelectionController;
class nsFrameSelection;
class nsTextControlFrame;

namespace mozilla {


class ErrorResult;
class TextControlState;
class TextEditor;

/**
/**
 * This abstract class is used for the text control frame to get the editor and
 * selection controller objects, and some helper properties.
 */
class TextControlElement : public nsGenericHTMLFormElementWithState {
 public:
  TextControlElement(already_AddRefed<dom::NodeInfo>&& aNodeInfo,
  TextControlElement(already_AddRefed<dom::NodeInfo>&& aNodeInfo,
                     dom::FromParser aFromParser, uint8_t aType)
      : nsGenericHTMLFormElementWithState(std::move(aNodeInfo), aFromParser,
                                          aType){};

  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_ISUPPORTS_INHERITED
  NS_DECL_CYCLE_COLLECTION_CLASS_INHERITED(TextControlElement,
                                           nsGenericHTMLFormElementWithState)

  bool IsTextControlElement() const final { return true; }


  NS_IMPL_FROMNODE_HELPER(TextControlElement, IsTextControlElement())

  /**
   * Tell the control that value has been deliberately changed (or not).
   */
   */
  virtual nsresult SetValueChanged(bool changed) = 0;

  /**
   * Find out whether this is a single line text control.  (text or password)
   * @return whether this is a single line text control
   * @return whether this is a single line text control
   */
  virtual bool IsSingleLineTextControl() const = 0;

  /**
   * Find out whether this control is a textarea.
   * Find out whether this control is a textarea.
   * @return whether this is a textarea text control
   */
  virtual bool IsTextArea() const = 0;
  virtual bool IsTextArea() const = 0;

  /**
   * Find out whether this is a password control (input type=password)
   * @return whether this is a password ontrol
   * @return whether this is a password ontrol
   */
  virtual bool IsPasswordTextControl() const = 0;

  /**
   * Get the cols attribute (if textarea) or a default
   * Get the cols attribute (if textarea) or a default
   * @return the number of columns to use
   */
  virtual int32_t GetCols() = 0;

  /**
  /**
   * Get the column index to wrap at, or -1 if we shouldn't wrap
   */
  virtual int32_t GetWrapCols() = 0;

  /**
  /**
   * Get the rows attribute (if textarea) or a default
   * @return the number of rows to use
   */
  virtual int32_t GetRows() = 0;


  /**
   * Get the default value of the text control
   */
  virtual void GetDefaultValueFromContent(nsAString& aValue) = 0;

  /**
   * Return true if the value of the control has been changed.
   * Return true if the value of the control has been changed.
   */
  virtual bool ValueChanged() const = 0;

  /**
   * Returns the used maxlength attribute value.
   */
  virtual int32_t UsedMaxLength() const = 0;
  virtual int32_t UsedMaxLength() const = 0;

  /**
   * Get the current value of the text editor.
   *
   * @param aValue the buffer to retrieve the value in
   * @param aValue the buffer to retrieve the value in
   * @param aIgnoreWrap whether to ignore the text wrapping behavior specified
   * for the element.
   */
  virtual void GetTextEditorValue(nsAString& aValue,
                                  bool aIgnoreWrap) const = 0;
                                  bool aIgnoreWrap) const = 0;

  /**
   * Get the editor object associated with the text editor.
   * The return value is null if the control does not support an editor
   * (for example, if it is a checkbox.)
   * (for example, if it is a checkbox.)
   * Note that GetTextEditor() creates editor if it hasn't been created yet.
   * If you need editor only when the editor is there, you should use
   * GetTextEditorWithoutCreation().
   */
   */
  MOZ_CAN_RUN_SCRIPT virtual TextEditor* GetTextEditor() = 0;
  virtual TextEditor* GetTextEditorWithoutCreation() = 0;

  /**
   * Get the selection controller object associated with the text editor.
   * Get the selection controller object associated with the text editor.
   * The return value is null if the control does not support an editor
   * (for example, if it is a checkbox.)
   */
  virtual nsISelectionController* GetSelectionController() = 0;


  virtual nsFrameSelection* GetConstFrameSelection() = 0;

  virtual TextControlState* GetTextControlState() const = 0;


  /**
   * Binds a frame to the text control.  This is performed when a frame
   * is created for the content node.
   * Be aware, this must be called with script blocker.
   */
   */
  virtual nsresult BindToFrame(nsTextControlFrame* aFrame) = 0;

  /**
   * Unbinds a frame from the text control.  This is performed when a frame
   * belonging to a content node is destroyed.
   * belonging to a content node is destroyed.
   */
  MOZ_CAN_RUN_SCRIPT virtual void UnbindFromFrame(
      nsTextControlFrame* aFrame) = 0;

  /**
  /**
   * Creates an editor for the text control.  This should happen when
   * a frame has been created for the text control element, but the created
   * editor may outlive the frame itself.
   * editor may outlive the frame itself.
   */
  MOZ_CAN_RUN_SCRIPT virtual nsresult CreateEditor() = 0;

  /**
   * Update preview value for the text control.
   */
  virtual void SetPreviewValue(const nsAString& aValue) = 0;

  /**
   * Get the current preview value for text control.
   * Get the current preview value for text control.
   */
  virtual void GetPreviewValue(nsAString& aValue) = 0;

  /**
   * Enable preview for text control.
   * Enable preview for text control.
   */
  virtual void EnablePreview() = 0;

  /**
   * Find out whether this control enables preview for form autofoll.
   * Find out whether this control enables preview for form autofoll.
   */
  virtual bool IsPreviewEnabled() = 0;

  /**
   * Initialize the keyboard event listeners.
   * Initialize the keyboard event listeners.
   */
  virtual void InitializeKeyboardEventListeners() = 0;


  /**
   * Update the visibility of both the placholder and preview text based on the
   * element's state.
   */
  virtual void UpdateOverlayTextVisibility(bool aNotify) = 0;
  virtual void UpdateOverlayTextVisibility(bool aNotify) = 0;

  /**
   * Returns the current expected placeholder visibility state.
   */
  virtual bool GetPlaceholderVisibility() = 0;
  virtual bool GetPlaceholderVisibility() = 0;

  /**
   * Returns the current expected preview visibility state.
   */
  virtual bool GetPreviewVisibility() = 0;

  enum class ValueChangeKind {
    Internal,
    Script,
    Script,
    UserInteraction,
  };

  /**
   * Callback called whenever the value is changed.
   * Callback called whenever the value is changed.
   */
  virtual void OnValueChanged(ValueChangeKind) = 0;

  /**
   * Helpers for value manipulation from SetRangeText.
   * Helpers for value manipulation from SetRangeText.
   */
  virtual void GetValueFromSetRangeText(nsAString& aValue) = 0;
  MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
  MOZ_CAN_RUN_SCRIPT virtual nsresult SetValueFromSetRangeText(
      const nsAString& aValue) = 0;

  static const int32_t DEFAULT_COLS = 20;
  static const int32_t DEFAULT_ROWS = 1;
  static const int32_t DEFAULT_ROWS_TEXTAREA = 2;
  static const int32_t DEFAULT_ROWS_TEXTAREA = 2;
  static const int32_t DEFAULT_UNDO_CAP = 1000;

  // wrap can be one of these three values.
  typedef enum {
    eHTMLTextWrap_Off = 1,   // "off"
    eHTMLTextWrap_Off = 1,   // "off"
    eHTMLTextWrap_Hard = 2,  // "hard"
    eHTMLTextWrap_Soft = 3   // the default
  } nsHTMLTextWrap;

  static bool GetWrapPropertyEnum(nsIContent* aContent,
  static bool GetWrapPropertyEnum(nsIContent* aContent,
                                  nsHTMLTextWrap& aWrapProp);

  /**
   * Does the editor have a selection cache?
   *
   *
   * Note that this function has the side effect of making the editor for input
   * elements be initialized eagerly.
   */
   */
  virtual bool HasCachedSelection() = 0;
  virtual bool HasCachedSelection() = 0;

  static already_AddRefed<TextControlElement>
  GetTextControlElementFromEditingHost(nsIContent* aHost);
  GetTextControlElementFromEditingHost(nsIContent* aHost);


 protected:
  virtual ~TextControlElement() = default;
};

}  // namespace mozilla
}  // namespace mozilla

#endif  // mozilla_TextControlElement_h