2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2012-05-21 04:12:37 -07:00
|
|
|
/* 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/. */
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifndef nsTextControlFrame_h___
|
|
|
|
#define nsTextControlFrame_h___
|
|
|
|
|
2012-09-14 09:10:08 -07:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-06-23 04:11:00 -07:00
|
|
|
#include "nsContainerFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsIAnonymousContentCreator.h"
|
2014-08-18 07:44:50 -07:00
|
|
|
#include "nsIContent.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
#include "nsITextControlFrame.h"
|
2010-04-21 13:17:41 -07:00
|
|
|
#include "nsITextControlElement.h"
|
2011-02-04 15:28:38 -08:00
|
|
|
#include "nsIStatefulFrame.h"
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
class nsISelectionController;
|
2010-02-09 17:29:11 -08:00
|
|
|
class EditorInitializerEntryTracker;
|
2010-04-21 13:17:41 -07:00
|
|
|
class nsTextEditorState;
|
2013-08-28 12:06:00 -07:00
|
|
|
class nsIEditor;
|
2012-06-10 16:44:50 -07:00
|
|
|
namespace mozilla {
|
|
|
|
namespace dom {
|
|
|
|
class Element;
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
class nsTextControlFrame final : public nsContainerFrame,
|
2015-03-27 11:52:19 -07:00
|
|
|
public nsIAnonymousContentCreator,
|
|
|
|
public nsITextControlFrame,
|
|
|
|
public nsIStatefulFrame
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
public:
|
2009-09-12 09:49:24 -07:00
|
|
|
NS_DECL_FRAMEARENA_HELPERS
|
|
|
|
|
2015-02-04 15:22:27 -08:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(ContentScrollPos, DeleteValue<nsPoint>)
|
2011-02-04 15:28:38 -08:00
|
|
|
|
2015-01-06 01:27:56 -08:00
|
|
|
explicit nsTextControlFrame(nsStyleContext* aContext);
|
2007-03-22 10:30:00 -07:00
|
|
|
virtual ~nsTextControlFrame();
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void DestroyFrom(nsIFrame* aDestructRoot) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIScrollableFrame* GetScrollTargetFrame() override {
|
2011-08-24 13:54:30 -07:00
|
|
|
return do_QueryFrame(GetFirstPrincipalChild());
|
2009-09-01 04:22:31 -07:00
|
|
|
}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nscoord GetMinISize(nsRenderingContext* aRenderingContext) override;
|
|
|
|
virtual nscoord GetPrefISize(nsRenderingContext* aRenderingContext) override;
|
2012-06-23 04:11:00 -07:00
|
|
|
|
2014-08-24 07:34:51 -07:00
|
|
|
virtual mozilla::LogicalSize
|
|
|
|
ComputeAutoSize(nsRenderingContext *aRenderingContext,
|
|
|
|
mozilla::WritingMode aWritingMode,
|
|
|
|
const mozilla::LogicalSize& aCBSize,
|
|
|
|
nscoord aAvailableISize,
|
|
|
|
const mozilla::LogicalSize& aMargin,
|
|
|
|
const mozilla::LogicalSize& aBorder,
|
|
|
|
const mozilla::LogicalSize& aPadding,
|
2015-03-21 09:28:04 -07:00
|
|
|
bool aShrinkWrap) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-12 17:47:52 -07:00
|
|
|
virtual void Reflow(nsPresContext* aPresContext,
|
|
|
|
nsHTMLReflowMetrics& aDesiredSize,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsReflowStatus& aStatus) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsSize GetMinSize(nsBoxLayoutState& aBoxLayoutState) override;
|
|
|
|
virtual bool IsCollapsed() override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool IsLeaf() const override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual mozilla::a11y::AccType AccessibleType() override;
|
2007-03-22 10:30:00 -07:00
|
|
|
#endif
|
|
|
|
|
2014-01-05 15:31:14 -08:00
|
|
|
#ifdef DEBUG_FRAME_DUMP
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult GetFrameName(nsAString& aResult) const override
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
aResult.AssignLiteral("nsTextControlFrame");
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual bool IsFrameOfType(uint32_t aFlags) const override
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
// nsStackFrame is already both of these, but that's somewhat bogus,
|
|
|
|
// and we really mean it.
|
2012-06-23 04:11:00 -07:00
|
|
|
return nsContainerFrame::IsFrameOfType(aFlags &
|
2007-03-22 10:30:00 -07:00
|
|
|
~(nsIFrame::eReplaced | nsIFrame::eReplacedContainsBlock));
|
|
|
|
}
|
|
|
|
|
|
|
|
// nsIAnonymousContentCreator
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult CreateAnonymousContent(nsTArray<ContentInfo>& aElements) override;
|
2014-07-16 11:41:57 -07:00
|
|
|
virtual void AppendAnonymousContentTo(nsTArray<nsIContent*>& aElements,
|
2015-03-21 09:28:04 -07:00
|
|
|
uint32_t aFilter) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2014-05-28 12:36:58 -07:00
|
|
|
virtual void SetInitialChildList(ChildListID aListID,
|
2015-03-21 09:28:04 -07:00
|
|
|
nsFrameList& aChildList) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2013-02-14 03:12:27 -08:00
|
|
|
virtual void BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsRect& aDirtyRect,
|
2015-03-21 09:28:04 -07:00
|
|
|
const nsDisplayListSet& aLists) override;
|
2012-11-09 02:22:29 -08:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual mozilla::dom::Element* GetPseudoElement(nsCSSPseudoElements::Type aType) override;
|
2013-12-02 15:57:50 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//==== BEGIN NSIFORMCONTROLFRAME
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual void SetFocus(bool aOn , bool aRepaint) override;
|
|
|
|
virtual nsresult SetFormProperty(nsIAtom* aName, const nsAString& aValue) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//==== END NSIFORMCONTROLFRAME
|
|
|
|
|
2009-01-29 11:46:17 -08:00
|
|
|
//==== NSITEXTCONTROLFRAME
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD GetEditor(nsIEditor **aEditor) override;
|
|
|
|
NS_IMETHOD SetSelectionStart(int32_t aSelectionStart) override;
|
|
|
|
NS_IMETHOD SetSelectionEnd(int32_t aSelectionEnd) override;
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD SetSelectionRange(int32_t aSelectionStart,
|
|
|
|
int32_t aSelectionEnd,
|
2015-03-21 09:28:04 -07:00
|
|
|
SelectionDirection aDirection = eNone) override;
|
2012-08-22 08:56:38 -07:00
|
|
|
NS_IMETHOD GetSelectionRange(int32_t* aSelectionStart,
|
|
|
|
int32_t* aSelectionEnd,
|
2015-03-21 09:28:04 -07:00
|
|
|
SelectionDirection* aDirection = nullptr) override;
|
|
|
|
NS_IMETHOD GetOwnedSelectionController(nsISelectionController** aSelCon) override;
|
|
|
|
virtual nsFrameSelection* GetOwnedFrameSelection() override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
nsresult GetPhonetic(nsAString& aPhonetic) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-01 20:00:06 -08:00
|
|
|
/**
|
|
|
|
* Ensure mEditor is initialized with the proper flags and the default value.
|
|
|
|
* @throws NS_ERROR_NOT_INITIALIZED if mEditor has not been created
|
|
|
|
* @throws various and sundry other things
|
|
|
|
*/
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult EnsureEditorInitialized() override;
|
2010-02-01 20:00:06 -08:00
|
|
|
|
2009-01-29 11:46:17 -08:00
|
|
|
//==== END NSITEXTCONTROLFRAME
|
2011-02-04 15:28:38 -08:00
|
|
|
|
|
|
|
//==== NSISTATEFULFRAME
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD SaveState(nsPresState** aState) override;
|
|
|
|
NS_IMETHOD RestoreState(nsPresState* aState) override;
|
2011-02-04 15:28:38 -08:00
|
|
|
|
|
|
|
//=== END NSISTATEFULFRAME
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//==== OVERLOAD of nsIFrame
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsIAtom* GetType() const override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
/** handler for attribute changes to mContent */
|
2014-02-17 23:47:48 -08:00
|
|
|
virtual nsresult AttributeChanged(int32_t aNameSpaceID,
|
2014-02-18 00:36:33 -08:00
|
|
|
nsIAtom* aAttribute,
|
2015-03-21 09:28:04 -07:00
|
|
|
int32_t aModType) override;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-07 11:44:32 -08:00
|
|
|
nsresult GetText(nsString& aText);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
virtual nsresult PeekOffset(nsPeekOffsetStruct *aPos) override;
|
2012-06-19 16:31:03 -07:00
|
|
|
|
2009-01-12 11:20:59 -08:00
|
|
|
NS_DECL_QUERYFRAME
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2011-05-21 01:25:27 -07:00
|
|
|
// Temp reference to scriptrunner
|
|
|
|
// We could make these auto-Revoking via the "delete" entry for safety
|
2012-07-30 07:20:58 -07:00
|
|
|
NS_DECLARE_FRAME_PROPERTY(TextControlInitializer, nullptr)
|
2011-05-21 01:25:27 -07:00
|
|
|
|
2012-06-23 04:11:00 -07:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Launch the reflow on the child frames - see nsTextControlFrame::Reflow()
|
|
|
|
*/
|
|
|
|
void ReflowTextControlChild(nsIFrame* aFrame,
|
|
|
|
nsPresContext* aPresContext,
|
|
|
|
const nsHTMLReflowState& aReflowState,
|
|
|
|
nsReflowStatus& aStatus,
|
|
|
|
nsHTMLReflowMetrics& aParentDesiredSize);
|
2011-05-21 01:25:27 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
public: //for methods who access nsTextControlFrame directly
|
2011-09-28 23:19:26 -07:00
|
|
|
void SetValueChanged(bool aValueChanged);
|
2012-05-07 09:27:24 -07:00
|
|
|
|
2007-09-27 09:01:32 -07:00
|
|
|
// called by the focus listener
|
|
|
|
nsresult MaybeBeginSecureKeyboardInput();
|
|
|
|
void MaybeEndSecureKeyboardInput();
|
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
#define DEFINE_TEXTCTRL_FORWARDER(type, name) \
|
|
|
|
type name() { \
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element"); \
|
|
|
|
return txtCtrl->name(); \
|
|
|
|
}
|
|
|
|
#define DEFINE_TEXTCTRL_CONST_FORWARDER(type, name) \
|
|
|
|
type name() const { \
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent()); \
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element"); \
|
|
|
|
return txtCtrl->name(); \
|
|
|
|
}
|
|
|
|
|
2011-09-28 23:19:26 -07:00
|
|
|
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsSingleLineTextControl)
|
|
|
|
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsTextArea)
|
|
|
|
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPlainTextControl)
|
|
|
|
DEFINE_TEXTCTRL_CONST_FORWARDER(bool, IsPasswordTextControl)
|
2012-08-22 08:56:38 -07:00
|
|
|
DEFINE_TEXTCTRL_FORWARDER(int32_t, GetCols)
|
|
|
|
DEFINE_TEXTCTRL_FORWARDER(int32_t, GetWrapCols)
|
|
|
|
DEFINE_TEXTCTRL_FORWARDER(int32_t, GetRows)
|
2010-04-21 13:17:41 -07:00
|
|
|
|
|
|
|
#undef DEFINE_TEXTCTRL_CONST_FORWARDER
|
|
|
|
#undef DEFINE_TEXTCTRL_FORWARDER
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
protected:
|
2009-01-29 11:46:17 -08:00
|
|
|
class EditorInitializer;
|
|
|
|
friend class EditorInitializer;
|
2010-04-21 13:17:41 -07:00
|
|
|
friend class nsTextEditorState; // needs access to UpdateValueDisplay
|
2009-01-29 11:46:17 -08:00
|
|
|
|
|
|
|
class EditorInitializer : public nsRunnable {
|
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit EditorInitializer(nsTextControlFrame* aFrame) :
|
2009-01-29 11:46:17 -08:00
|
|
|
mFrame(aFrame) {}
|
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
NS_IMETHOD Run() override;
|
2009-01-29 11:46:17 -08:00
|
|
|
|
2011-05-21 01:25:27 -07:00
|
|
|
// avoids use of nsWeakFrame
|
|
|
|
void Revoke() {
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame = nullptr;
|
2011-05-21 01:25:27 -07:00
|
|
|
}
|
|
|
|
|
2009-01-29 11:46:17 -08:00
|
|
|
private:
|
|
|
|
nsTextControlFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2010-05-06 15:12:21 -07:00
|
|
|
class ScrollOnFocusEvent;
|
|
|
|
friend class ScrollOnFocusEvent;
|
|
|
|
|
|
|
|
class ScrollOnFocusEvent : public nsRunnable {
|
|
|
|
public:
|
2014-08-31 20:36:37 -07:00
|
|
|
explicit ScrollOnFocusEvent(nsTextControlFrame* aFrame) :
|
2010-05-06 15:12:21 -07:00
|
|
|
mFrame(aFrame) {}
|
|
|
|
|
|
|
|
NS_DECL_NSIRUNNABLE
|
|
|
|
|
|
|
|
void Revoke() {
|
2012-07-30 07:20:58 -07:00
|
|
|
mFrame = nullptr;
|
2010-05-06 15:12:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
nsTextControlFrame* mFrame;
|
|
|
|
};
|
|
|
|
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult OffsetToDOMPoint(int32_t aOffset, nsIDOMNode** aResult, int32_t* aPosition);
|
2009-01-29 11:46:17 -08:00
|
|
|
|
2010-02-02 07:49:55 -08:00
|
|
|
/**
|
|
|
|
* Update the textnode under our anonymous div to show the new
|
|
|
|
* value. This should only be called when we have no editor yet.
|
|
|
|
* @throws NS_ERROR_UNEXPECTED if the div has no text content
|
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult UpdateValueDisplay(bool aNotify,
|
|
|
|
bool aBeforeEditorInit = false,
|
2012-07-30 07:20:58 -07:00
|
|
|
const nsAString *aValue = nullptr);
|
2010-02-02 07:49:55 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Get the maxlength attribute
|
|
|
|
* @param aMaxLength the value of the max length attr
|
2011-10-17 07:59:28 -07:00
|
|
|
* @returns false if attr not defined
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2012-08-22 08:56:38 -07:00
|
|
|
bool GetMaxLength(int32_t* aMaxLength);
|
2010-02-02 07:49:55 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Find out whether an attribute exists on the content or not.
|
|
|
|
* @param aAtt the attribute to determine the existence of
|
2011-10-17 07:59:28 -07:00
|
|
|
* @returns false if it does not exist
|
2007-03-22 10:30:00 -07:00
|
|
|
*/
|
2011-09-28 23:19:26 -07:00
|
|
|
bool AttributeExists(nsIAtom *aAtt) const
|
2007-03-22 10:30:00 -07:00
|
|
|
{ return mContent && mContent->HasAttr(kNameSpaceID_None, aAtt); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* We call this when we are being destroyed or removed from the PFM.
|
|
|
|
* @param aPresContext the current pres context
|
|
|
|
*/
|
|
|
|
void PreDestroy();
|
|
|
|
|
|
|
|
// Compute our intrinsic size. This does not include any borders, paddings,
|
|
|
|
// etc. Just the size of our actual area for the text (and the scrollbars,
|
|
|
|
// for <textarea>).
|
2011-04-07 18:04:40 -07:00
|
|
|
nsresult CalcIntrinsicSize(nsRenderingContext* aRenderingContext,
|
2014-11-04 06:45:00 -08:00
|
|
|
mozilla::WritingMode aWM,
|
|
|
|
mozilla::LogicalSize& aIntrinsicSize,
|
|
|
|
float aFontSizeInflation);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2015-03-21 09:28:04 -07:00
|
|
|
nsresult ScrollSelectionIntoView() override;
|
2011-02-04 16:29:29 -08:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
//helper methods
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetSelectionInternal(nsIDOMNode *aStartNode, int32_t aStartOffset,
|
|
|
|
nsIDOMNode *aEndNode, int32_t aEndOffset,
|
2011-07-28 10:51:22 -07:00
|
|
|
SelectionDirection aDirection = eNone);
|
2011-09-28 23:19:26 -07:00
|
|
|
nsresult SelectAllOrCollapseToEndOfText(bool aSelect);
|
2012-08-22 08:56:38 -07:00
|
|
|
nsresult SetSelectionEndPoints(int32_t aSelStart, int32_t aSelEnd,
|
2011-07-28 10:51:22 -07:00
|
|
|
SelectionDirection aDirection = eNone);
|
2010-02-26 10:47:38 -08:00
|
|
|
|
2010-04-21 13:17:41 -07:00
|
|
|
/**
|
|
|
|
* Return the root DOM element, and implicitly initialize the editor if needed.
|
|
|
|
*/
|
2012-06-10 16:44:50 -07:00
|
|
|
mozilla::dom::Element* GetRootNodeAndInitializeEditor();
|
2010-04-21 13:17:41 -07:00
|
|
|
nsresult GetRootNodeAndInitializeEditor(nsIDOMElement **aRootElement);
|
2010-04-06 13:44:46 -07:00
|
|
|
|
2011-05-21 01:25:27 -07:00
|
|
|
void FinishedInitializer() {
|
|
|
|
Properties().Delete(TextControlInitializer());
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
private:
|
|
|
|
// these packed bools could instead use the high order bits on mState, saving 4 bytes
|
2013-10-16 06:43:03 -07:00
|
|
|
bool mEditorHasBeenInitialized;
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mIsProcessing;
|
2010-10-19 06:11:07 -07:00
|
|
|
// Keep track if we have asked a placeholder node creation.
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mUsePlaceholder;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2010-02-09 17:29:11 -08:00
|
|
|
#ifdef DEBUG
|
2011-09-28 23:19:26 -07:00
|
|
|
bool mInEditorInitialization;
|
2010-02-09 17:29:11 -08:00
|
|
|
friend class EditorInitializerEntryTracker;
|
|
|
|
#endif
|
|
|
|
|
2010-05-06 15:12:21 -07:00
|
|
|
nsRevocableEventPtr<ScrollOnFocusEvent> mScrollEvent;
|
2007-03-22 10:30:00 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|