2017-10-27 17:33:53 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
2012-05-21 11:12:37 +00: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/. */
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2012-12-14 23:58:45 +00:00
|
|
|
#include "mozilla/DebugOnly.h"
|
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
#include "gfxContext.h"
|
2002-07-26 17:17:00 +00:00
|
|
|
#include "nsCOMPtr.h"
|
2014-10-24 15:28:14 +00:00
|
|
|
#include "nsFontMetrics.h"
|
2002-07-26 20:57:24 +00:00
|
|
|
#include "nsTextControlFrame.h"
|
2002-07-26 17:17:00 +00:00
|
|
|
#include "nsIPlaintextEditor.h"
|
2008-07-16 10:52:01 +00:00
|
|
|
#include "nsCaret.h"
|
2016-02-17 20:37:00 +00:00
|
|
|
#include "nsCSSPseudoElements.h"
|
2005-01-12 19:45:38 +00:00
|
|
|
#include "nsGenericHTMLElement.h"
|
2013-08-28 19:06:00 +00:00
|
|
|
#include "nsIEditor.h"
|
2012-07-01 23:45:59 +00:00
|
|
|
#include "nsTextFragment.h"
|
2014-02-27 23:04:46 +00:00
|
|
|
#include "nsNameSpaceManager.h"
|
2017-09-27 12:12:00 +00:00
|
|
|
#include "nsCheckboxRadioFrame.h" //for registering accesskeys
|
2002-07-26 17:17:00 +00:00
|
|
|
|
|
|
|
#include "nsIContent.h"
|
2004-07-31 23:15:21 +00:00
|
|
|
#include "nsPresContext.h"
|
2007-01-30 00:06:41 +00:00
|
|
|
#include "nsGkAtoms.h"
|
2006-07-06 10:43:51 +00:00
|
|
|
#include "nsLayoutUtils.h"
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2013-01-15 12:22:03 +00:00
|
|
|
#include <algorithm>
|
2018-03-27 04:35:22 +00:00
|
|
|
#include "nsRange.h" //for selection setting helper func
|
2018-01-30 04:10:53 +00:00
|
|
|
#include "nsINode.h"
|
2005-11-28 23:56:44 +00:00
|
|
|
#include "nsPIDOMWindow.h" //needed for notify selection changed to update the menus ect.
|
2018-03-27 04:35:22 +00:00
|
|
|
#include "nsQueryObject.h"
|
2018-03-02 18:18:35 +00:00
|
|
|
#include "nsILayoutHistoryState.h"
|
2002-07-26 17:17:00 +00:00
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
#include "nsFocusManager.h"
|
2019-04-03 12:40:26 +00:00
|
|
|
#include "mozilla/PresShell.h"
|
2018-03-02 18:18:35 +00:00
|
|
|
#include "mozilla/PresState.h"
|
2012-09-30 16:40:24 +00:00
|
|
|
#include "nsAttrValueInlines.h"
|
2014-04-10 16:09:40 +00:00
|
|
|
#include "mozilla/dom/Selection.h"
|
2016-07-09 02:34:41 +00:00
|
|
|
#include "mozilla/TextEditRules.h"
|
2013-01-23 19:37:17 +00:00
|
|
|
#include "nsContentUtils.h"
|
2013-04-04 12:01:08 +00:00
|
|
|
#include "nsTextNode.h"
|
2016-08-15 23:05:31 +00:00
|
|
|
#include "mozilla/dom/HTMLInputElement.h"
|
|
|
|
#include "mozilla/dom/HTMLTextAreaElement.h"
|
2013-12-12 01:51:58 +00:00
|
|
|
#include "mozilla/dom/ScriptSettings.h"
|
2018-03-19 19:15:39 +00:00
|
|
|
#include "mozilla/dom/Text.h"
|
2014-01-16 01:37:41 +00:00
|
|
|
#include "mozilla/MathAlgorithms.h"
|
2015-09-02 17:39:39 +00:00
|
|
|
#include "nsFrameSelection.h"
|
2010-05-19 23:22:19 +00:00
|
|
|
|
2002-07-26 17:17:00 +00:00
|
|
|
#define DEFAULT_COLUMN_WIDTH 20
|
|
|
|
|
2012-06-10 23:44:50 +00:00
|
|
|
using namespace mozilla;
|
2017-09-22 00:18:30 +00:00
|
|
|
using namespace mozilla::dom;
|
2012-06-10 23:44:50 +00:00
|
|
|
|
2019-04-16 07:24:49 +00:00
|
|
|
nsIFrame* NS_NewTextControlFrame(PresShell* aPresShell, ComputedStyle* aStyle) {
|
2019-02-05 16:45:54 +00:00
|
|
|
return new (aPresShell)
|
|
|
|
nsTextControlFrame(aStyle, aPresShell->GetPresContext());
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2009-09-12 16:49:24 +00:00
|
|
|
NS_IMPL_FRAMEARENA_HELPERS(nsTextControlFrame)
|
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
NS_QUERYFRAME_HEAD(nsTextControlFrame)
|
2018-12-07 20:00:18 +00:00
|
|
|
NS_QUERYFRAME_ENTRY(nsIFormControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIAnonymousContentCreator)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsITextControlFrame)
|
|
|
|
NS_QUERYFRAME_ENTRY(nsIStatefulFrame)
|
2012-06-23 11:11:00 +00:00
|
|
|
NS_QUERYFRAME_TAIL_INHERITING(nsContainerFrame)
|
2002-07-26 17:17:00 +00:00
|
|
|
|
|
|
|
#ifdef ACCESSIBILITY
|
2012-09-28 21:53:44 +00:00
|
|
|
a11y::AccType nsTextControlFrame::AccessibleType() {
|
2012-12-18 01:25:52 +00:00
|
|
|
return a11y::eHTMLTextFieldType;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-02-10 01:29:11 +00:00
|
|
|
#ifdef DEBUG
|
|
|
|
class EditorInitializerEntryTracker {
|
|
|
|
public:
|
|
|
|
explicit EditorInitializerEntryTracker(nsTextControlFrame& frame)
|
2011-10-17 14:59:28 +00:00
|
|
|
: mFrame(frame), mFirstEntry(false) {
|
2010-02-10 01:29:11 +00:00
|
|
|
if (!mFrame.mInEditorInitialization) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mFrame.mInEditorInitialization = true;
|
|
|
|
mFirstEntry = true;
|
2010-02-10 01:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
~EditorInitializerEntryTracker() {
|
|
|
|
if (mFirstEntry) {
|
2011-10-17 14:59:28 +00:00
|
|
|
mFrame.mInEditorInitialization = false;
|
2010-02-10 01:29:11 +00:00
|
|
|
}
|
|
|
|
}
|
2011-09-29 06:19:26 +00:00
|
|
|
bool EnteredMoreThanOnce() const { return !mFirstEntry; }
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2010-02-10 01:29:11 +00:00
|
|
|
private:
|
|
|
|
nsTextControlFrame& mFrame;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool mFirstEntry;
|
2010-02-10 01:29:11 +00:00
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
class nsTextControlFrame::nsAnonDivObserver final
|
|
|
|
: public nsStubMutationObserver {
|
|
|
|
public:
|
|
|
|
explicit nsAnonDivObserver(nsTextControlFrame& aFrame) : mFrame(aFrame) {}
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CHARACTERDATACHANGED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTAPPENDED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTINSERTED
|
|
|
|
NS_DECL_NSIMUTATIONOBSERVER_CONTENTREMOVED
|
|
|
|
|
|
|
|
private:
|
|
|
|
~nsAnonDivObserver() {}
|
|
|
|
nsTextControlFrame& mFrame;
|
|
|
|
};
|
|
|
|
|
2019-02-05 16:45:54 +00:00
|
|
|
nsTextControlFrame::nsTextControlFrame(ComputedStyle* aStyle,
|
|
|
|
nsPresContext* aPresContext)
|
|
|
|
: nsContainerFrame(aStyle, aPresContext, kClassID),
|
2019-05-03 17:34:36 +00:00
|
|
|
mFirstBaseline(NS_INTRINSIC_ISIZE_UNKNOWN),
|
2013-10-16 13:43:03 +00:00
|
|
|
mEditorHasBeenInitialized(false),
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsProcessing(false)
|
2010-02-10 01:29:11 +00:00
|
|
|
#ifdef DEBUG
|
2011-10-17 14:59:28 +00:00
|
|
|
,
|
|
|
|
mInEditorInitialization(false)
|
2010-02-10 01:29:11 +00:00
|
|
|
#endif
|
2007-01-05 16:31:07 +00:00
|
|
|
{
|
2017-09-22 00:18:30 +00:00
|
|
|
ClearCachedValue();
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2002-07-26 20:57:24 +00:00
|
|
|
nsTextControlFrame::~nsTextControlFrame() {}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-11-07 00:20:33 +00:00
|
|
|
void nsTextControlFrame::DestroyFrom(nsIFrame* aDestructRoot,
|
|
|
|
PostDestroyData& aPostDestroyData) {
|
2010-05-06 22:12:21 +00:00
|
|
|
mScrollEvent.Revoke();
|
2006-02-21 00:49:04 +00:00
|
|
|
|
2017-05-28 10:22:29 +00:00
|
|
|
DeleteProperty(TextControlInitializer());
|
2011-05-21 08:25:27 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
// Unbind the text editor state object from the frame. The editor will live
|
|
|
|
// on, but things like controllers will be released.
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
txtCtrl->UnbindFromFrame(this);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-09-27 12:12:00 +00:00
|
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(static_cast<nsIFrame*>(this), false);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
if (mMutationObserver) {
|
|
|
|
mRootNode->RemoveMutationObserver(mMutationObserver);
|
|
|
|
mMutationObserver = nullptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME(emilio, bug 1400618): Do this after the child frames are destroyed.
|
2017-11-07 00:20:33 +00:00
|
|
|
aPostDestroyData.AddAnonymousContent(mRootNode.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mPlaceholderDiv.forget());
|
|
|
|
aPostDestroyData.AddAnonymousContent(mPreviewDiv.forget());
|
2017-09-22 00:18:30 +00:00
|
|
|
|
2017-11-07 00:20:33 +00:00
|
|
|
nsContainerFrame::DestroyFrom(aDestructRoot, aPostDestroyData);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
LogicalSize nsTextControlFrame::CalcIntrinsicSize(
|
|
|
|
gfxContext* aRenderingContext, WritingMode aWM,
|
2016-11-18 18:08:32 +00:00
|
|
|
float aFontSizeInflation) const {
|
|
|
|
LogicalSize intrinsicSize(aWM);
|
2017-07-06 12:00:35 +00:00
|
|
|
// Get leading and the Average/MaxAdvance char width
|
2004-10-10 18:30:28 +00:00
|
|
|
nscoord lineHeight = 0;
|
2002-09-23 19:43:48 +00:00
|
|
|
nscoord charWidth = 0;
|
|
|
|
nscoord charMaxAdvance = 0;
|
|
|
|
|
2016-03-17 05:55:48 +00:00
|
|
|
RefPtr<nsFontMetrics> fontMet =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, aFontSizeInflation);
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2018-04-06 12:52:12 +00:00
|
|
|
lineHeight = ReflowInput::CalcLineHeight(GetContent(), Style(), PresContext(),
|
|
|
|
NS_AUTOHEIGHT, aFontSizeInflation);
|
2011-04-08 04:18:43 +00:00
|
|
|
charWidth = fontMet->AveCharWidth();
|
|
|
|
charMaxAdvance = fontMet->MaxAdvance();
|
2002-09-16 06:23:52 +00:00
|
|
|
|
|
|
|
// Set the width equal to the width in characters
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t cols = GetCols();
|
2016-11-18 18:08:32 +00:00
|
|
|
intrinsicSize.ISize(aWM) = cols * charWidth;
|
2003-11-10 23:42:43 +00:00
|
|
|
|
|
|
|
// To better match IE, take the maximum character width(in twips) and remove
|
|
|
|
// 4 pixels add this on as additional padding(internalPadding). But only do
|
2014-01-16 01:37:41 +00:00
|
|
|
// this if we think we have a fixed-width font.
|
2014-01-17 15:03:44 +00:00
|
|
|
if (mozilla::Abs(charWidth - charMaxAdvance) >
|
|
|
|
(unsigned)nsPresContext::CSSPixelsToAppUnits(1)) {
|
2014-01-16 01:37:41 +00:00
|
|
|
nscoord internalPadding =
|
|
|
|
std::max(0, charMaxAdvance - nsPresContext::CSSPixelsToAppUnits(4));
|
2017-07-06 12:00:35 +00:00
|
|
|
nscoord t = nsPresContext::CSSPixelsToAppUnits(1);
|
2007-02-07 07:46:44 +00:00
|
|
|
// Round to a multiple of t
|
2017-07-06 12:00:35 +00:00
|
|
|
nscoord rest = internalPadding % t;
|
2003-11-10 23:42:43 +00:00
|
|
|
if (rest < t - rest) {
|
|
|
|
internalPadding -= rest;
|
|
|
|
} else {
|
|
|
|
internalPadding += t - rest;
|
|
|
|
}
|
|
|
|
// Now add the extra padding on (so that small input sizes work well)
|
2016-11-18 18:08:32 +00:00
|
|
|
intrinsicSize.ISize(aWM) += internalPadding;
|
2014-05-22 22:10:20 +00:00
|
|
|
} else {
|
|
|
|
// This is to account for the anonymous <br> having a 1 twip width
|
|
|
|
// in Full Standards mode, see BRFrame::Reflow and bug 228752.
|
|
|
|
if (PresContext()->CompatibilityMode() == eCompatibility_FullStandards) {
|
2016-11-18 18:08:32 +00:00
|
|
|
intrinsicSize.ISize(aWM) += 1;
|
2014-05-22 22:10:20 +00:00
|
|
|
}
|
2003-11-10 23:42:43 +00:00
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2004-08-07 22:04:27 +00:00
|
|
|
// Increment width with cols * letter-spacing.
|
|
|
|
{
|
2019-03-04 18:19:40 +00:00
|
|
|
const StyleLength& letterSpacing = StyleText()->mLetterSpacing;
|
|
|
|
if (!letterSpacing.IsZero()) {
|
|
|
|
intrinsicSize.ISize(aWM) += cols * letterSpacing.ToAppUnits();
|
2004-08-07 22:04:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-09-16 06:23:52 +00:00
|
|
|
// Set the height equal to total number of rows (times the height of each
|
|
|
|
// line, of course)
|
2016-11-18 18:08:32 +00:00
|
|
|
intrinsicSize.BSize(aWM) = lineHeight * GetRows();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
|
|
|
|
// Add in the size of the scrollbars for textarea
|
|
|
|
if (IsTextArea()) {
|
2016-01-29 14:42:14 +00:00
|
|
|
nsIFrame* first = PrincipalChildList().FirstChild();
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2009-01-12 19:20:59 +00:00
|
|
|
nsIScrollableFrame* scrollableFrame = do_QueryFrame(first);
|
2006-12-19 15:08:34 +00:00
|
|
|
NS_ASSERTION(scrollableFrame, "Child must be scrollable");
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
|
2010-08-25 05:44:18 +00:00
|
|
|
if (scrollableFrame) {
|
2015-07-07 13:20:09 +00:00
|
|
|
LogicalMargin scrollbarSizes(
|
|
|
|
aWM, scrollableFrame->GetDesiredScrollbarSizes(PresContext(),
|
|
|
|
aRenderingContext));
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
|
2016-11-18 18:08:32 +00:00
|
|
|
intrinsicSize.ISize(aWM) += scrollbarSizes.IStartEnd(aWM);
|
|
|
|
intrinsicSize.BSize(aWM) += scrollbarSizes.BStartEnd(aWM);
|
2010-08-25 05:44:18 +00:00
|
|
|
}
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
}
|
2016-11-18 18:08:32 +00:00
|
|
|
return intrinsicSize;
|
2002-09-23 19:43:48 +00:00
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2010-02-02 04:00:06 +00:00
|
|
|
nsresult nsTextControlFrame::EnsureEditorInitialized() {
|
2009-01-29 19:46:17 +00:00
|
|
|
// This method initializes our editor, if needed.
|
2010-02-02 04:00:06 +00:00
|
|
|
|
2009-01-29 19:46:17 +00:00
|
|
|
// This code used to be called from CreateAnonymousContent(), but
|
|
|
|
// when the editor set the initial string, it would trigger a
|
|
|
|
// PresShell listener which called FlushPendingNotifications()
|
|
|
|
// during frame construction. This was causing other form controls
|
2010-02-02 04:00:06 +00:00
|
|
|
// to display wrong values. Additionally, calling this every time
|
|
|
|
// a text frame control is instantiated means that we're effectively
|
|
|
|
// instantiating the editor for all text fields, even if they
|
2010-02-02 15:49:55 +00:00
|
|
|
// never get used. So, now this method is being called lazily only
|
|
|
|
// when we actually need an editor.
|
2006-05-15 19:35:12 +00:00
|
|
|
|
2013-10-16 13:43:03 +00:00
|
|
|
if (mEditorHasBeenInitialized) return NS_OK;
|
2006-05-15 19:35:12 +00:00
|
|
|
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = mContent->GetComposedDoc();
|
2010-02-02 04:00:06 +00:00
|
|
|
NS_ENSURE_TRUE(doc, NS_ERROR_FAILURE);
|
|
|
|
|
2017-03-01 17:03:14 +00:00
|
|
|
AutoWeakFrame weakFrame(this);
|
2010-02-02 04:00:06 +00:00
|
|
|
|
|
|
|
// Flush out content on our document. Have to do this, because script
|
|
|
|
// blockers don't prevent the sink flushing out content and notifying in the
|
|
|
|
// process, which can destroy frames.
|
2017-01-05 07:31:56 +00:00
|
|
|
doc->FlushPendingNotifications(FlushType::ContentAndNotify);
|
2010-02-02 04:00:06 +00:00
|
|
|
NS_ENSURE_TRUE(weakFrame.IsAlive(), NS_ERROR_FAILURE);
|
|
|
|
|
|
|
|
// Make sure that editor init doesn't do things that would kill us off
|
|
|
|
// (especially off the script blockers it'll create for its DOM mutations).
|
2012-10-20 18:48:34 +00:00
|
|
|
{
|
2015-09-02 17:39:39 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
|
|
|
|
|
|
|
// Hide selection changes during the initialization, as webpages should not
|
|
|
|
// be aware of these initializations
|
|
|
|
AutoHideSelectionChanges hideSelectionChanges(
|
|
|
|
txtCtrl->GetConstFrameSelection());
|
|
|
|
|
2012-10-20 18:48:34 +00:00
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
|
|
|
// Time to mess with our security context... See comments in GetValue()
|
|
|
|
// for why this is needed.
|
2014-04-15 03:27:00 +00:00
|
|
|
mozilla::dom::AutoNoJSAPI nojsapi;
|
2012-10-20 18:48:34 +00:00
|
|
|
|
|
|
|
// Make sure that we try to focus the content even if the method fails
|
|
|
|
class EnsureSetFocus {
|
|
|
|
public:
|
|
|
|
explicit EnsureSetFocus(nsTextControlFrame* aFrame) : mFrame(aFrame) {}
|
|
|
|
~EnsureSetFocus() {
|
|
|
|
if (nsContentUtils::IsFocusedContent(mFrame->GetContent()))
|
|
|
|
mFrame->SetFocus(true, false);
|
|
|
|
}
|
2018-11-30 10:46:48 +00:00
|
|
|
|
2012-10-20 18:48:34 +00:00
|
|
|
private:
|
|
|
|
nsTextControlFrame* mFrame;
|
|
|
|
};
|
|
|
|
EnsureSetFocus makeSureSetFocusHappens(this);
|
2010-02-02 04:00:06 +00:00
|
|
|
|
2010-02-10 01:29:11 +00:00
|
|
|
#ifdef DEBUG
|
2012-10-20 18:48:34 +00:00
|
|
|
// Make sure we are not being called again until we're finished.
|
|
|
|
// If reentrancy happens, just pretend that we don't have an editor.
|
|
|
|
const EditorInitializerEntryTracker tracker(*this);
|
|
|
|
NS_ASSERTION(!tracker.EnteredMoreThanOnce(),
|
|
|
|
"EnsureEditorInitialized has been called while a previous "
|
|
|
|
"call was in progress");
|
2010-02-10 01:29:11 +00:00
|
|
|
#endif
|
|
|
|
|
2012-10-20 18:48:34 +00:00
|
|
|
// Create an editor for the frame, if one doesn't already exist
|
|
|
|
nsresult rv = txtCtrl->CreateEditor();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
2009-01-29 19:46:17 +00:00
|
|
|
|
2013-10-16 13:43:03 +00:00
|
|
|
// Set mEditorHasBeenInitialized so that subsequent calls will use the
|
2012-10-20 18:48:34 +00:00
|
|
|
// editor.
|
2013-10-16 13:43:03 +00:00
|
|
|
mEditorHasBeenInitialized = true;
|
2009-11-18 23:38:11 +00:00
|
|
|
|
2012-10-20 18:48:34 +00:00
|
|
|
if (weakFrame.IsAlive()) {
|
2017-03-09 19:44:45 +00:00
|
|
|
uint32_t position = 0;
|
2017-02-28 17:08:06 +00:00
|
|
|
|
|
|
|
// Set the selection to the end of the text field (bug 1287655),
|
|
|
|
// but only if the contents has changed (bug 1337392).
|
|
|
|
if (txtCtrl->ValueChanged()) {
|
|
|
|
nsAutoString val;
|
|
|
|
txtCtrl->GetTextEditorValue(val, true);
|
|
|
|
position = val.Length();
|
|
|
|
}
|
|
|
|
|
|
|
|
SetSelectionEndPoints(position, position);
|
2012-10-20 18:48:34 +00:00
|
|
|
}
|
2011-09-20 03:14:47 +00:00
|
|
|
}
|
2012-10-20 18:48:34 +00:00
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
2002-07-26 17:17:00 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
static already_AddRefed<Element> CreateEmptyDiv(
|
|
|
|
const nsTextControlFrame& aOwnerFrame) {
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = aOwnerFrame.PresContext()->Document();
|
2017-09-22 00:18:30 +00:00
|
|
|
RefPtr<mozilla::dom::NodeInfo> nodeInfo = doc->NodeInfoManager()->GetNodeInfo(
|
2018-01-30 04:10:53 +00:00
|
|
|
nsGkAtoms::div, nullptr, kNameSpaceID_XHTML, nsINode::ELEMENT_NODE);
|
2017-09-22 00:18:30 +00:00
|
|
|
|
|
|
|
RefPtr<Element> element = NS_NewHTMLDivElement(nodeInfo.forget());
|
|
|
|
return element.forget();
|
|
|
|
}
|
|
|
|
|
|
|
|
static already_AddRefed<Element> CreateEmptyDivWithTextNode(
|
|
|
|
const nsTextControlFrame& aOwnerFrame) {
|
|
|
|
RefPtr<Element> element = CreateEmptyDiv(aOwnerFrame);
|
|
|
|
|
|
|
|
// Create the text node for DIV
|
|
|
|
RefPtr<nsTextNode> textNode =
|
|
|
|
new nsTextNode(element->OwnerDoc()->NodeInfoManager());
|
|
|
|
textNode->MarkAsMaybeModifiedFrequently();
|
|
|
|
|
|
|
|
element->AppendChildTo(textNode, false);
|
|
|
|
|
|
|
|
return element.forget();
|
|
|
|
}
|
|
|
|
|
2011-05-06 20:04:44 +00:00
|
|
|
nsresult nsTextControlFrame::CreateAnonymousContent(
|
|
|
|
nsTArray<ContentInfo>& aElements) {
|
2017-09-22 00:18:30 +00:00
|
|
|
MOZ_ASSERT(mContent, "We should have a content!");
|
2010-10-19 13:11:07 +00:00
|
|
|
|
2017-08-24 11:09:42 +00:00
|
|
|
AddStateBits(NS_FRAME_INDEPENDENT_SELECTION);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
2017-09-22 00:18:30 +00:00
|
|
|
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
nsresult rv = CreateRootNode();
|
2007-02-18 17:34:09 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
// Bind the frame to its text control
|
|
|
|
rv = txtCtrl->BindToFrame(this);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2014-10-28 13:44:26 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
aElements.AppendElement(mRootNode);
|
|
|
|
CreatePlaceholderIfNeeded();
|
|
|
|
if (mPlaceholderDiv) {
|
2014-10-28 13:44:26 +00:00
|
|
|
if (!IsSingleLineTextControl()) {
|
|
|
|
// For textareas, UpdateValueDisplay doesn't initialize the visibility
|
|
|
|
// status of the placeholder because it returns early, so we have to
|
|
|
|
// do that manually here.
|
2017-03-30 09:38:59 +00:00
|
|
|
txtCtrl->UpdateOverlayTextVisibility(true);
|
2014-10-28 13:44:26 +00:00
|
|
|
}
|
2017-09-22 00:18:30 +00:00
|
|
|
aElements.AppendElement(mPlaceholderDiv);
|
2010-10-19 13:11:07 +00:00
|
|
|
}
|
2017-09-22 00:18:30 +00:00
|
|
|
CreatePreviewIfNeeded();
|
|
|
|
if (mPreviewDiv) {
|
|
|
|
aElements.AppendElement(mPreviewDiv);
|
2017-03-22 08:55:56 +00:00
|
|
|
}
|
2017-03-20 03:53:40 +00:00
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
rv = UpdateValueDisplay(false);
|
2010-04-21 20:17:41 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2009-01-29 19:46:17 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
InitializeEagerlyIfNeeded();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool nsTextControlFrame::ShouldInitializeEagerly() const {
|
|
|
|
// textareas are eagerly initialized.
|
|
|
|
if (!IsSingleLineTextControl()) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Also, input elements which have a cached selection should get eager
|
|
|
|
// editor initialization.
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
if (txtCtrl->HasCachedSelection()) {
|
|
|
|
return true;
|
2011-07-29 21:31:57 +00:00
|
|
|
}
|
2017-09-22 00:18:30 +00:00
|
|
|
|
|
|
|
// So do input text controls with spellcheck=true
|
2018-03-21 21:39:04 +00:00
|
|
|
if (auto* htmlElement = nsGenericHTMLElement::FromNode(mContent)) {
|
2017-09-22 00:18:30 +00:00
|
|
|
if (htmlElement->Spellcheck()) {
|
|
|
|
return true;
|
2010-06-03 02:39:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::InitializeEagerlyIfNeeded() {
|
|
|
|
MOZ_ASSERT(!nsContentUtils::IsSafeToRunScript(),
|
|
|
|
"Someone forgot a script blocker?");
|
|
|
|
if (!ShouldInitializeEagerly()) {
|
|
|
|
return;
|
2009-01-29 19:46:17 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
EditorInitializer* initializer = new EditorInitializer(this);
|
|
|
|
SetProperty(TextControlInitializer(), initializer);
|
|
|
|
nsContentUtils::AddScriptRunner(initializer);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsTextControlFrame::CreateRootNode() {
|
|
|
|
MOZ_ASSERT(!mRootNode);
|
|
|
|
|
|
|
|
mRootNode = CreateEmptyDiv(*this);
|
2018-05-14 15:52:09 +00:00
|
|
|
mRootNode->SetIsNativeAnonymousRoot();
|
2017-09-22 00:18:30 +00:00
|
|
|
|
|
|
|
mMutationObserver = new nsAnonDivObserver(*this);
|
|
|
|
mRootNode->AddMutationObserver(mMutationObserver);
|
|
|
|
|
|
|
|
// Make our root node editable
|
|
|
|
mRootNode->SetFlags(NODE_IS_EDITABLE);
|
|
|
|
|
|
|
|
// Set the necessary classes on the text control. We use class values instead
|
|
|
|
// of a 'style' attribute so that the style comes from a user-agent style
|
|
|
|
// sheet and is still applied even if author styles are disabled.
|
|
|
|
nsAutoString classValue;
|
|
|
|
classValue.AppendLiteral("anonymous-div");
|
|
|
|
|
|
|
|
if (!IsSingleLineTextControl()) {
|
|
|
|
// We can't just inherit the overflow because setting visible overflow will
|
|
|
|
// crash when the number of lines exceeds the height of the textarea and
|
2018-12-11 00:50:32 +00:00
|
|
|
// setting -moz-hidden-unscrollable overflow doesn't paint the caret for
|
|
|
|
// some reason.
|
2017-09-22 00:18:30 +00:00
|
|
|
const nsStyleDisplay* disp = StyleDisplay();
|
2018-12-11 00:50:32 +00:00
|
|
|
if (disp->mOverflowX != StyleOverflow::Visible &&
|
|
|
|
disp->mOverflowX != StyleOverflow::MozHiddenUnscrollable) {
|
2017-09-22 00:18:30 +00:00
|
|
|
classValue.AppendLiteral(" inherit-overflow");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nsresult rv = mRootNode->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
classValue, false);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2017-09-22 12:48:02 +00:00
|
|
|
return NS_OK;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
void nsTextControlFrame::CreatePlaceholderIfNeeded() {
|
|
|
|
MOZ_ASSERT(!mPlaceholderDiv);
|
|
|
|
|
|
|
|
// Do we need a placeholder node?
|
|
|
|
nsAutoString placeholderTxt;
|
2017-12-07 18:13:50 +00:00
|
|
|
mContent->AsElement()->GetAttr(kNameSpaceID_None, nsGkAtoms::placeholder,
|
|
|
|
placeholderTxt);
|
2017-12-02 00:11:39 +00:00
|
|
|
if (IsTextArea()) { // <textarea>s preserve newlines...
|
|
|
|
nsContentUtils::PlatformToDOMLineBreaks(placeholderTxt);
|
|
|
|
} else { // ...<input>s don't
|
|
|
|
nsContentUtils::RemoveNewlines(placeholderTxt);
|
|
|
|
}
|
2017-09-22 05:33:41 +00:00
|
|
|
|
|
|
|
if (placeholderTxt.IsEmpty()) {
|
|
|
|
return;
|
2016-08-15 23:05:31 +00:00
|
|
|
}
|
2017-09-22 05:33:41 +00:00
|
|
|
|
|
|
|
mPlaceholderDiv = CreateEmptyDivWithTextNode(*this);
|
|
|
|
// Associate ::placeholder pseudo-element with the placeholder node.
|
2019-02-19 13:44:33 +00:00
|
|
|
mPlaceholderDiv->SetPseudoElementType(PseudoStyleType::placeholder);
|
2018-03-28 22:01:46 +00:00
|
|
|
mPlaceholderDiv->GetFirstChild()->AsText()->SetText(placeholderTxt, false);
|
2017-09-22 00:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::CreatePreviewIfNeeded() {
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
2017-09-22 05:33:41 +00:00
|
|
|
if (!txtCtrl->IsPreviewEnabled()) {
|
|
|
|
return;
|
2014-07-16 18:41:57 +00:00
|
|
|
}
|
2017-09-22 05:33:41 +00:00
|
|
|
|
|
|
|
mPreviewDiv = CreateEmptyDivWithTextNode(*this);
|
|
|
|
mPreviewDiv->SetAttr(kNameSpaceID_None, nsGkAtoms::_class,
|
|
|
|
NS_LITERAL_STRING("preview-div"), false);
|
2017-09-22 00:18:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::AppendAnonymousContentTo(
|
|
|
|
nsTArray<nsIContent*>& aElements, uint32_t aFilter) {
|
|
|
|
aElements.AppendElement(mRootNode);
|
2014-07-16 18:41:57 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
if (mPlaceholderDiv && !(aFilter & nsIContent::eSkipPlaceholderContent)) {
|
|
|
|
aElements.AppendElement(mPlaceholderDiv);
|
2017-03-20 03:53:40 +00:00
|
|
|
}
|
2016-07-21 18:52:49 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
if (mPreviewDiv) {
|
|
|
|
aElements.AppendElement(mPreviewDiv);
|
2017-03-20 03:53:40 +00:00
|
|
|
}
|
2012-06-23 11:11:00 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
nscoord nsTextControlFrame::GetPrefISize(gfxContext* aRenderingContext) {
|
2016-11-18 18:08:32 +00:00
|
|
|
nscoord result = 0;
|
2018-09-12 12:35:47 +00:00
|
|
|
DISPLAY_PREF_INLINE_SIZE(this, result);
|
2016-11-18 18:08:32 +00:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
|
|
|
WritingMode wm = GetWritingMode();
|
|
|
|
result = CalcIntrinsicSize(aRenderingContext, wm, inflation).ISize(wm);
|
|
|
|
return result;
|
2010-02-11 17:34:01 +00:00
|
|
|
}
|
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
nscoord nsTextControlFrame::GetMinISize(gfxContext* aRenderingContext) {
|
2018-09-12 12:35:47 +00:00
|
|
|
// Our min inline size is just our preferred width if we have auto inline size
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
nscoord result;
|
2018-09-12 12:35:47 +00:00
|
|
|
DISPLAY_MIN_INLINE_SIZE(this, result);
|
2014-07-24 17:03:25 +00:00
|
|
|
result = GetPrefISize(aRenderingContext);
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2017-06-09 19:14:53 +00:00
|
|
|
LogicalSize nsTextControlFrame::ComputeAutoSize(
|
|
|
|
gfxContext* aRenderingContext, WritingMode aWM, const LogicalSize& aCBSize,
|
2016-11-05 01:57:06 +00:00
|
|
|
nscoord aAvailableISize, const LogicalSize& aMargin,
|
|
|
|
const LogicalSize& aBorder, const LogicalSize& aPadding,
|
|
|
|
ComputeSizeFlags aFlags) {
|
2012-05-21 05:18:28 +00:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
2016-11-18 18:08:32 +00:00
|
|
|
LogicalSize autoSize = CalcIntrinsicSize(aRenderingContext, aWM, inflation);
|
2016-11-18 18:08:32 +00:00
|
|
|
|
|
|
|
// Note: nsContainerFrame::ComputeAutoSize only computes the inline-size (and
|
|
|
|
// only for 'auto'), the block-size it returns is always NS_UNCONSTRAINEDSIZE.
|
2019-02-10 12:55:16 +00:00
|
|
|
const auto& iSizeCoord = StylePosition()->ISize(aWM);
|
|
|
|
if (iSizeCoord.IsAuto()) {
|
2016-11-18 18:08:32 +00:00
|
|
|
if (aFlags & ComputeSizeFlags::eIClampMarginBoxMinSize) {
|
|
|
|
// CalcIntrinsicSize isn't aware of grid-item margin-box clamping, so we
|
|
|
|
// fall back to nsContainerFrame's ComputeAutoSize to handle that.
|
|
|
|
// XXX maybe a font-inflation issue here? (per the assertion below).
|
|
|
|
autoSize.ISize(aWM) =
|
|
|
|
nsContainerFrame::ComputeAutoSize(aRenderingContext, aWM, aCBSize,
|
|
|
|
aAvailableISize, aMargin, aBorder,
|
|
|
|
aPadding, aFlags)
|
|
|
|
.ISize(aWM);
|
|
|
|
}
|
2007-08-22 03:07:25 +00:00
|
|
|
#ifdef DEBUG
|
2016-11-18 18:08:32 +00:00
|
|
|
else {
|
2014-11-04 14:45:00 +00:00
|
|
|
LogicalSize ancestorAutoSize = nsContainerFrame::ComputeAutoSize(
|
|
|
|
aRenderingContext, aWM, aCBSize, aAvailableISize, aMargin, aBorder,
|
2016-11-05 01:57:06 +00:00
|
|
|
aPadding, aFlags);
|
2016-04-21 04:28:31 +00:00
|
|
|
// Disabled when there's inflation; see comment in GetXULPrefSize.
|
2014-11-04 14:45:00 +00:00
|
|
|
MOZ_ASSERT(inflation != 1.0f ||
|
|
|
|
ancestorAutoSize.ISize(aWM) == autoSize.ISize(aWM),
|
2007-08-22 03:07:25 +00:00
|
|
|
"Incorrect size computed by ComputeAutoSize?");
|
2014-11-04 14:45:00 +00:00
|
|
|
}
|
2007-08-22 03:07:25 +00:00
|
|
|
#endif
|
2016-11-18 18:08:32 +00:00
|
|
|
}
|
2014-11-04 14:45:00 +00:00
|
|
|
return autoSize;
|
2007-08-22 03:07:25 +00:00
|
|
|
}
|
|
|
|
|
2004-07-31 23:15:21 +00:00
|
|
|
void nsTextControlFrame::Reflow(nsPresContext* aPresContext,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aDesiredSize,
|
2016-07-21 10:36:39 +00:00
|
|
|
const ReflowInput& aReflowInput,
|
2007-01-22 04:27:31 +00:00
|
|
|
nsReflowStatus& aStatus) {
|
2015-03-29 22:38:40 +00:00
|
|
|
MarkInReflow();
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
DO_GLOBAL_REFLOW_COUNT("nsTextControlFrame");
|
2016-07-21 10:36:39 +00:00
|
|
|
DISPLAY_REFLOW(aPresContext, this, aReflowInput, aDesiredSize, aStatus);
|
2017-09-13 10:00:25 +00:00
|
|
|
MOZ_ASSERT(aStatus.IsEmpty(), "Caller should pass a fresh reflow status!");
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2012-06-23 11:11:00 +00:00
|
|
|
// make sure that the form registers itself on the initial/first reflow
|
2002-07-26 17:17:00 +00:00
|
|
|
if (mState & NS_FRAME_FIRST_REFLOW) {
|
2017-09-27 12:12:00 +00:00
|
|
|
nsCheckboxRadioFrame::RegUnRegAccessKey(this, true);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 11:11:00 +00:00
|
|
|
// set values of reflow's out parameters
|
2016-07-21 10:36:39 +00:00
|
|
|
WritingMode wm = aReflowInput.GetWritingMode();
|
2014-07-24 08:30:07 +00:00
|
|
|
LogicalSize finalSize(
|
|
|
|
wm,
|
2016-07-21 10:36:39 +00:00
|
|
|
aReflowInput.ComputedISize() +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().IStartEnd(wm),
|
|
|
|
aReflowInput.ComputedBSize() +
|
|
|
|
aReflowInput.ComputedLogicalBorderPadding().BStartEnd(wm));
|
2014-07-24 08:30:07 +00:00
|
|
|
aDesiredSize.SetSize(wm, finalSize);
|
2010-03-18 19:58:12 +00:00
|
|
|
|
2017-01-28 01:34:13 +00:00
|
|
|
// Calculate the baseline and store it in mFirstBaseline.
|
2016-07-21 10:36:39 +00:00
|
|
|
nscoord lineHeight = aReflowInput.ComputedBSize();
|
2012-06-23 11:11:00 +00:00
|
|
|
float inflation = nsLayoutUtils::FontSizeInflationFor(this);
|
|
|
|
if (!IsSingleLineTextControl()) {
|
2018-04-06 12:52:12 +00:00
|
|
|
lineHeight = ReflowInput::CalcLineHeight(
|
|
|
|
GetContent(), Style(), PresContext(), NS_AUTOHEIGHT, inflation);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
2016-03-17 05:55:48 +00:00
|
|
|
RefPtr<nsFontMetrics> fontMet =
|
|
|
|
nsLayoutUtils::GetFontMetricsForFrame(this, inflation);
|
2014-11-13 08:58:06 +00:00
|
|
|
mFirstBaseline = nsLayoutUtils::GetCenteredFontBaseline(fontMet, lineHeight,
|
|
|
|
wm.IsLineInverted()) +
|
2017-01-28 01:34:13 +00:00
|
|
|
aReflowInput.ComputedLogicalBorderPadding().BStart(wm);
|
|
|
|
aDesiredSize.SetBlockStartAscent(mFirstBaseline);
|
2012-06-23 11:11:00 +00:00
|
|
|
|
|
|
|
// overflow handling
|
|
|
|
aDesiredSize.SetOverflowAreasToDesiredBounds();
|
|
|
|
// perform reflow on all kids
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
|
|
|
while (kid) {
|
2016-07-21 10:36:39 +00:00
|
|
|
ReflowTextControlChild(kid, aPresContext, aReflowInput, aStatus,
|
|
|
|
aDesiredSize);
|
2012-06-23 11:11:00 +00:00
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
2012-08-29 05:14:46 +00:00
|
|
|
|
2012-06-23 11:11:00 +00:00
|
|
|
// take into account css properties that affect overflow handling
|
|
|
|
FinishAndStoreOverflow(&aDesiredSize);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-09-13 10:00:25 +00:00
|
|
|
aStatus.Reset(); // This type of frame can't be split.
|
2016-07-21 10:36:39 +00:00
|
|
|
NS_FRAME_SET_TRUNCATION(aStatus, aReflowInput, aDesiredSize);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2012-06-23 11:11:00 +00:00
|
|
|
void nsTextControlFrame::ReflowTextControlChild(
|
|
|
|
nsIFrame* aKid, nsPresContext* aPresContext,
|
2016-07-21 10:36:39 +00:00
|
|
|
const ReflowInput& aReflowInput, nsReflowStatus& aStatus,
|
2016-07-21 10:36:38 +00:00
|
|
|
ReflowOutput& aParentDesiredSize) {
|
2012-06-23 11:11:00 +00:00
|
|
|
// compute available size and frame offsets for child
|
2014-07-24 08:28:46 +00:00
|
|
|
WritingMode wm = aKid->GetWritingMode();
|
2016-07-21 10:36:39 +00:00
|
|
|
LogicalSize availSize = aReflowInput.ComputedSizeWithPadding(wm);
|
2014-07-24 08:28:46 +00:00
|
|
|
availSize.BSize(wm) = NS_UNCONSTRAINEDSIZE;
|
2014-01-13 13:13:10 +00:00
|
|
|
|
2017-07-06 12:00:35 +00:00
|
|
|
ReflowInput kidReflowInput(aPresContext, aReflowInput, aKid, availSize,
|
2019-04-24 17:35:31 +00:00
|
|
|
Nothing(), ReflowInput::CALLER_WILL_INIT);
|
2014-01-13 13:13:10 +00:00
|
|
|
// Override padding with our computed padding in case we got it from theming
|
|
|
|
// or percentage
|
2019-04-24 17:35:31 +00:00
|
|
|
kidReflowInput.Init(aPresContext, Nothing(), nullptr,
|
2016-07-21 10:36:39 +00:00
|
|
|
&aReflowInput.ComputedPhysicalPadding());
|
2012-06-23 11:11:00 +00:00
|
|
|
|
|
|
|
// Set computed width and computed height for the child
|
2016-07-21 10:36:39 +00:00
|
|
|
kidReflowInput.SetComputedWidth(aReflowInput.ComputedWidth());
|
|
|
|
kidReflowInput.SetComputedHeight(aReflowInput.ComputedHeight());
|
2014-01-13 13:13:10 +00:00
|
|
|
|
|
|
|
// Offset the frame by the size of the parent's border
|
2016-07-21 10:36:39 +00:00
|
|
|
nscoord xOffset = aReflowInput.ComputedPhysicalBorderPadding().left -
|
|
|
|
aReflowInput.ComputedPhysicalPadding().left;
|
|
|
|
nscoord yOffset = aReflowInput.ComputedPhysicalBorderPadding().top -
|
|
|
|
aReflowInput.ComputedPhysicalPadding().top;
|
2012-06-23 11:11:00 +00:00
|
|
|
|
|
|
|
// reflow the child
|
2016-07-21 10:36:39 +00:00
|
|
|
ReflowOutput desiredSize(aReflowInput);
|
2017-07-06 12:00:35 +00:00
|
|
|
ReflowChild(aKid, aPresContext, desiredSize, kidReflowInput, xOffset, yOffset,
|
2012-06-23 11:11:00 +00:00
|
|
|
0, aStatus);
|
|
|
|
|
|
|
|
// place the child
|
2014-01-17 01:34:44 +00:00
|
|
|
FinishReflowChild(aKid, aPresContext, desiredSize, &kidReflowInput, xOffset,
|
2016-07-21 10:36:39 +00:00
|
|
|
yOffset, 0);
|
2012-06-23 11:11:00 +00:00
|
|
|
|
|
|
|
// consider the overflow
|
|
|
|
aParentDesiredSize.mOverflowAreas.UnionWith(desiredSize.mOverflowAreas);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:31 +00:00
|
|
|
nsSize nsTextControlFrame::GetXULMinSize(nsBoxLayoutState& aState) {
|
Bug 300030: Move intrinsic width computation out of nsIFrame::Reflow and into its own methods on nsIFrame. Replace reflow reasons, types, and commands with dirty bits/notifications. Thanks to bzbarsky for almost all of the HTML form controls (mozilla/layout/forms) changes, and many others for help testing and patching. For detailed commit logs, see REFLOW_YYYYMMDD_BRANCH, where YYYYMMDD is one of 20061031, 20060830, 20060603, 20060302, 20060119, 20051011, 20050804, 20050429, 20050315, 20050111, and 20041213.
2006-12-08 05:38:33 +00:00
|
|
|
// XXXbz why? Why not the nsBoxFrame sizes?
|
2016-04-21 04:28:31 +00:00
|
|
|
return nsBox::GetXULMinSize(aState);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2016-04-21 04:28:32 +00:00
|
|
|
bool nsTextControlFrame::IsXULCollapsed() {
|
2007-01-22 04:27:31 +00:00
|
|
|
// We're never collapsed in the box sense.
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2007-01-22 04:27:31 +00:00
|
|
|
}
|
|
|
|
|
2010-05-06 22:12:21 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::ScrollOnFocusEvent::Run() {
|
2010-04-21 20:17:41 +00:00
|
|
|
if (mFrame) {
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl =
|
|
|
|
do_QueryInterface(mFrame->GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
|
|
|
if (selCon) {
|
|
|
|
mFrame->mScrollEvent.Forget();
|
|
|
|
selCon->ScrollSelectionIntoView(
|
|
|
|
nsISelectionController::SELECTION_NORMAL,
|
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION,
|
2010-10-21 20:56:20 +00:00
|
|
|
nsISelectionController::SCROLL_SYNCHRONOUS);
|
2010-04-21 20:17:41 +00:00
|
|
|
}
|
2010-05-06 22:12:21 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-12-12 23:53:06 +00:00
|
|
|
// IMPLEMENTING NS_IFORMCONTROLFRAME
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsTextControlFrame::SetFocus(bool aOn, bool aRepaint) {
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
|
2010-05-06 22:12:21 +00:00
|
|
|
// Revoke the previous scroll event if one exists
|
|
|
|
mScrollEvent.Revoke();
|
|
|
|
|
2012-11-09 10:32:58 +00:00
|
|
|
// If 'dom.placeholeder.show_on_focus' preference is 'false', focusing or
|
|
|
|
// blurring the frame can have an impact on the placeholder visibility.
|
2017-09-22 05:33:41 +00:00
|
|
|
if (mPlaceholderDiv) {
|
2017-03-30 09:38:59 +00:00
|
|
|
txtCtrl->UpdateOverlayTextVisibility(true);
|
2012-11-09 10:32:58 +00:00
|
|
|
}
|
|
|
|
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
if (!aOn) {
|
2004-04-15 19:45:46 +00:00
|
|
|
return;
|
Bug 178324, refactor focus by moving all focus handling into one place and simplifying it, add many tests, fixes many other bugs too numerous to mention in this small checkin comment, r=josh,smichaud,ere,dbaron,marco,neil,gavin,smaug,sr=smaug (CLOSED TREE)
2009-06-10 18:00:39 +00:00
|
|
|
}
|
2004-05-05 22:48:51 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
2018-05-08 17:52:36 +00:00
|
|
|
if (!selCon) {
|
2004-05-05 22:48:51 +00:00
|
|
|
return;
|
2018-05-08 17:52:36 +00:00
|
|
|
}
|
2004-05-05 22:48:51 +00:00
|
|
|
|
2018-05-08 17:52:36 +00:00
|
|
|
RefPtr<Selection> ourSel =
|
|
|
|
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL);
|
|
|
|
if (!ourSel) {
|
|
|
|
return;
|
|
|
|
}
|
2004-04-15 19:45:46 +00:00
|
|
|
|
2019-04-03 12:40:26 +00:00
|
|
|
mozilla::PresShell* presShell = PresContext()->GetPresShell();
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsCaret> caret = presShell->GetCaret();
|
2018-05-08 17:52:36 +00:00
|
|
|
if (!caret) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-06 23:19:35 +00:00
|
|
|
|
|
|
|
// Scroll the current selection into view
|
2018-05-08 17:52:42 +00:00
|
|
|
Selection* caretSelection = caret->GetSelection();
|
2011-09-29 06:19:26 +00:00
|
|
|
const bool isFocusedRightNow = ourSel == caretSelection;
|
2010-05-06 23:19:35 +00:00
|
|
|
if (!isFocusedRightNow) {
|
2010-09-20 23:30:07 +00:00
|
|
|
// Don't scroll the current selection if we've been focused using the mouse.
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t lastFocusMethod = 0;
|
2019-01-02 13:05:23 +00:00
|
|
|
Document* doc = GetContent()->GetComposedDoc();
|
2010-09-20 23:30:07 +00:00
|
|
|
if (doc) {
|
|
|
|
nsIFocusManager* fm = nsFocusManager::GetFocusManager();
|
|
|
|
if (fm) {
|
|
|
|
fm->GetLastFocusMethod(doc->GetWindow(), &lastFocusMethod);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!(lastFocusMethod & nsIFocusManager::FLAG_BYMOUSE)) {
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<ScrollOnFocusEvent> event = new ScrollOnFocusEvent(this);
|
2017-07-26 08:13:35 +00:00
|
|
|
nsresult rv =
|
|
|
|
mContent->OwnerDoc()->Dispatch(TaskCategory::Other, do_AddRef(event));
|
2010-09-20 23:30:07 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2018-05-30 19:15:35 +00:00
|
|
|
mScrollEvent = std::move(event);
|
2010-09-20 23:30:07 +00:00
|
|
|
}
|
2010-05-06 23:19:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// tell the caret to use our selection
|
2014-08-06 05:19:27 +00:00
|
|
|
caret->SetSelection(ourSel);
|
2004-04-15 19:45:46 +00:00
|
|
|
|
|
|
|
// mutual-exclusion: the selection is either controlled by the
|
|
|
|
// document or by the text input/area. Clear any selection in the
|
|
|
|
// document since the focus is now on our independent selection.
|
|
|
|
|
2018-03-27 04:35:23 +00:00
|
|
|
RefPtr<Selection> docSel =
|
2019-04-03 12:40:26 +00:00
|
|
|
presShell->GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2018-03-27 04:35:23 +00:00
|
|
|
if (!docSel) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!docSel->IsCollapsed()) {
|
|
|
|
docSel->RemoveAllRanges(IgnoreErrors());
|
|
|
|
}
|
2004-04-15 19:45:46 +00:00
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-10-02 22:05:19 +00:00
|
|
|
nsresult nsTextControlFrame::SetFormProperty(nsAtom* aName,
|
|
|
|
const nsAString& aValue) {
|
2018-12-05 18:44:05 +00:00
|
|
|
if (!mIsProcessing) { // some kind of lock.
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsProcessing = true;
|
2010-04-21 20:17:41 +00:00
|
|
|
if (nsGkAtoms::select == aName) {
|
2003-01-21 15:17:32 +00:00
|
|
|
// Select all the text.
|
|
|
|
//
|
2010-04-21 20:17:41 +00:00
|
|
|
// XXX: This is lame, we can't call editor's SelectAll method
|
2003-01-21 15:17:32 +00:00
|
|
|
// because that triggers AutoCopies in unix builds.
|
|
|
|
// Instead, we have to call our own homegrown version
|
|
|
|
// of select all which merely builds a range that selects
|
|
|
|
// all of the content and adds that to the selection.
|
|
|
|
|
2017-03-01 17:03:14 +00:00
|
|
|
AutoWeakFrame weakThis = this;
|
2011-10-17 14:59:28 +00:00
|
|
|
SelectAllOrCollapseToEndOfText(true); // NOTE: can destroy the world
|
2011-01-18 17:40:38 +00:00
|
|
|
if (!weakThis.IsAlive()) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
mIsProcessing = false;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
return NS_OK;
|
2010-02-02 04:00:12 +00:00
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2017-06-19 14:47:02 +00:00
|
|
|
NS_IMETHODIMP_(already_AddRefed<TextEditor>)
|
|
|
|
nsTextControlFrame::GetTextEditor() {
|
|
|
|
if (NS_WARN_IF(NS_FAILED(EnsureEditorInitialized()))) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2010-02-02 04:00:12 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
2017-06-19 14:47:02 +00:00
|
|
|
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
|
|
|
RefPtr<TextEditor> textEditor = txtCtrl->GetTextEditor();
|
|
|
|
return textEditor.forget();
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2018-01-30 04:10:51 +00:00
|
|
|
nsresult nsTextControlFrame::SetSelectionInternal(
|
2017-03-09 19:44:45 +00:00
|
|
|
nsINode* aStartNode, uint32_t aStartOffset, nsINode* aEndNode,
|
2011-07-28 17:51:22 +00:00
|
|
|
uint32_t aEndOffset, nsITextControlFrame::SelectionDirection aDirection) {
|
2003-01-21 15:17:32 +00:00
|
|
|
// Create a new range to represent the new selection.
|
|
|
|
// Note that we use a new range to avoid having to do
|
|
|
|
// isIncreasing checks to avoid possible errors.
|
|
|
|
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsRange> range = new nsRange(mContent);
|
2016-11-16 22:34:43 +00:00
|
|
|
// Be careful to use internal nsRange methods which do not check to make sure
|
|
|
|
// we have access to the node.
|
2017-05-30 04:18:25 +00:00
|
|
|
// XXXbz nsRange::SetStartAndEnd takes int32_t (and ranges generally work on
|
|
|
|
// int32_t), but we're passing uint32_t. The good news is that at this point
|
|
|
|
// our endpoints should really be within our length, so not really that big.
|
|
|
|
// And if they _are_ that big, SetStartAndEnd() will simply error out, which
|
|
|
|
// is not too bad for a case we don't expect to happen.
|
2018-01-30 04:10:51 +00:00
|
|
|
nsresult rv =
|
|
|
|
range->SetStartAndEnd(aStartNode, aStartOffset, aEndNode, aEndOffset);
|
2003-01-21 15:17:32 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Get the selection, clear it and add the new range to it!
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
|
|
|
NS_ENSURE_TRUE(selCon, NS_ERROR_FAILURE);
|
2003-01-21 15:17:32 +00:00
|
|
|
|
2018-03-27 04:35:22 +00:00
|
|
|
RefPtr<Selection> selection =
|
2018-05-08 17:52:36 +00:00
|
|
|
selCon->GetSelection(nsISelectionController::SELECTION_NORMAL);
|
2003-01-21 15:17:32 +00:00
|
|
|
NS_ENSURE_TRUE(selection, NS_ERROR_FAILURE);
|
|
|
|
|
2011-07-28 17:51:22 +00:00
|
|
|
nsDirection direction;
|
|
|
|
if (aDirection == eNone) {
|
|
|
|
// Preserve the direction
|
2018-05-08 17:52:38 +00:00
|
|
|
direction = selection->GetDirection();
|
2011-07-28 17:51:22 +00:00
|
|
|
} else {
|
|
|
|
direction = (aDirection == eBackward) ? eDirPrevious : eDirNext;
|
|
|
|
}
|
|
|
|
|
2018-03-27 04:35:22 +00:00
|
|
|
ErrorResult err;
|
2018-03-27 04:35:23 +00:00
|
|
|
selection->RemoveAllRanges(err);
|
|
|
|
if (NS_WARN_IF(err.Failed())) {
|
|
|
|
return err.StealNSResult();
|
|
|
|
}
|
|
|
|
|
2018-03-27 04:35:22 +00:00
|
|
|
selection->AddRange(*range, err); // NOTE: can destroy the world
|
|
|
|
if (NS_WARN_IF(err.Failed())) {
|
|
|
|
return err.StealNSResult();
|
|
|
|
}
|
2011-07-28 17:51:22 +00:00
|
|
|
|
2018-05-08 17:52:38 +00:00
|
|
|
selection->SetDirection(direction);
|
2011-02-05 00:29:29 +00:00
|
|
|
return rv;
|
|
|
|
}
|
2010-03-18 16:14:08 +00:00
|
|
|
|
2011-02-05 00:29:29 +00:00
|
|
|
nsresult nsTextControlFrame::ScrollSelectionIntoView() {
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
|
|
|
if (selCon) {
|
|
|
|
// Scroll the selection into view (see bug 231389).
|
|
|
|
return selCon->ScrollSelectionIntoView(
|
|
|
|
nsISelectionController::SELECTION_NORMAL,
|
|
|
|
nsISelectionController::SELECTION_FOCUS_REGION,
|
|
|
|
nsISelectionController::SCROLL_FIRST_ANCESTOR_ONLY);
|
2011-01-18 17:40:38 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 00:29:29 +00:00
|
|
|
return NS_ERROR_FAILURE;
|
2003-01-21 15:17:32 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult nsTextControlFrame::SelectAllOrCollapseToEndOfText(bool aSelect) {
|
2018-04-24 06:17:17 +00:00
|
|
|
nsresult rv = EnsureEditorInitialized();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-01-21 15:17:32 +00:00
|
|
|
|
2018-01-30 04:10:51 +00:00
|
|
|
nsCOMPtr<nsINode> rootNode;
|
2018-04-24 06:17:17 +00:00
|
|
|
rootNode = mRootNode;
|
2010-11-22 08:12:56 +00:00
|
|
|
|
2018-04-24 06:17:17 +00:00
|
|
|
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
|
2010-11-22 08:12:56 +00:00
|
|
|
|
2018-04-24 06:17:17 +00:00
|
|
|
int32_t numChildren = mRootNode->GetChildCount();
|
2003-01-21 15:17:32 +00:00
|
|
|
|
|
|
|
if (numChildren > 0) {
|
|
|
|
// We never want to place the selection after the last
|
|
|
|
// br under the root node!
|
2018-04-24 06:17:17 +00:00
|
|
|
nsIContent* child = mRootNode->GetLastChild();
|
2003-09-27 04:18:26 +00:00
|
|
|
if (child) {
|
2018-01-03 15:29:44 +00:00
|
|
|
if (child->IsHTMLElement(nsGkAtoms::br)) {
|
|
|
|
child = child->GetPreviousSibling();
|
2003-01-21 15:17:32 +00:00
|
|
|
--numChildren;
|
2018-04-12 22:41:00 +00:00
|
|
|
} else if (child->IsText() && !child->Length()) {
|
2018-01-11 09:39:12 +00:00
|
|
|
// Editor won't remove text node when empty value.
|
|
|
|
--numChildren;
|
2018-01-03 15:29:44 +00:00
|
|
|
}
|
2003-01-21 15:17:32 +00:00
|
|
|
}
|
2010-02-07 19:44:32 +00:00
|
|
|
if (!aSelect && numChildren) {
|
2018-01-03 15:29:44 +00:00
|
|
|
child = child->GetPreviousSibling();
|
2018-04-12 22:41:00 +00:00
|
|
|
if (child && child->IsText()) {
|
2018-01-30 04:10:51 +00:00
|
|
|
rootNode = child;
|
2010-02-07 19:44:32 +00:00
|
|
|
const nsTextFragment* fragment = child->GetText();
|
|
|
|
numChildren = fragment ? fragment->GetLength() : 0;
|
|
|
|
}
|
|
|
|
}
|
2003-01-21 15:17:32 +00:00
|
|
|
}
|
|
|
|
|
2011-02-05 00:29:29 +00:00
|
|
|
rv = SetSelectionInternal(rootNode, aSelect ? 0 : numChildren, rootNode,
|
|
|
|
numChildren);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
return ScrollSelectionIntoView();
|
2003-01-21 15:17:32 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:44:45 +00:00
|
|
|
nsresult nsTextControlFrame::SetSelectionEndPoints(
|
|
|
|
uint32_t aSelStart, uint32_t aSelEnd,
|
2011-07-28 17:51:22 +00:00
|
|
|
nsITextControlFrame::SelectionDirection aDirection) {
|
2003-01-09 06:06:17 +00:00
|
|
|
NS_ASSERTION(aSelStart <= aSelEnd, "Invalid selection offsets!");
|
|
|
|
|
2002-07-26 17:17:00 +00:00
|
|
|
if (aSelStart > aSelEnd) return NS_ERROR_FAILURE;
|
|
|
|
|
2018-01-30 04:10:51 +00:00
|
|
|
nsCOMPtr<nsINode> startNode, endNode;
|
2017-03-09 19:44:45 +00:00
|
|
|
uint32_t startOffset, endOffset;
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2003-01-09 06:06:17 +00:00
|
|
|
// Calculate the selection start point.
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2003-01-09 06:06:17 +00:00
|
|
|
nsresult rv =
|
|
|
|
OffsetToDOMPoint(aSelStart, getter_AddRefs(startNode), &startOffset);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2003-01-09 06:06:17 +00:00
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 17:17:00 +00:00
|
|
|
|
2003-01-09 06:06:17 +00:00
|
|
|
if (aSelStart == aSelEnd) {
|
|
|
|
// Collapsed selection, so start and end are the same!
|
|
|
|
endNode = startNode;
|
|
|
|
endOffset = startOffset;
|
|
|
|
} else {
|
|
|
|
// Selection isn't collapsed so we have to calculate
|
|
|
|
// the end point too.
|
|
|
|
|
|
|
|
rv = OffsetToDOMPoint(aSelEnd, getter_AddRefs(endNode), &endOffset);
|
|
|
|
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2011-07-28 17:51:22 +00:00
|
|
|
return SetSelectionInternal(startNode, startOffset, endNode, endOffset,
|
|
|
|
aDirection);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2017-03-09 19:44:45 +00:00
|
|
|
nsTextControlFrame::SetSelectionRange(
|
|
|
|
uint32_t aSelStart, uint32_t aSelEnd,
|
2011-07-28 17:51:22 +00:00
|
|
|
nsITextControlFrame::SelectionDirection aDirection) {
|
2010-02-02 04:00:12 +00:00
|
|
|
nsresult rv = EnsureEditorInitialized();
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2003-01-09 06:06:17 +00:00
|
|
|
if (aSelStart > aSelEnd) {
|
|
|
|
// Simulate what we'd see SetSelectionStart() was called, followed
|
|
|
|
// by a SetSelectionEnd().
|
|
|
|
|
|
|
|
aSelStart = aSelEnd;
|
|
|
|
}
|
|
|
|
|
2011-07-28 17:51:22 +00:00
|
|
|
return SetSelectionEndPoints(aSelStart, aSelEnd, aDirection);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2017-03-09 19:44:45 +00:00
|
|
|
nsresult nsTextControlFrame::OffsetToDOMPoint(uint32_t aOffset,
|
2018-01-30 04:10:51 +00:00
|
|
|
nsINode** aResult,
|
2017-03-09 19:44:45 +00:00
|
|
|
uint32_t* aPosition) {
|
2003-01-09 06:06:17 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aResult && aPosition);
|
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
*aResult = nullptr;
|
2003-01-09 06:06:17 +00:00
|
|
|
*aPosition = 0;
|
|
|
|
|
2018-04-24 06:17:17 +00:00
|
|
|
nsresult rv = EnsureEditorInitialized();
|
|
|
|
if (NS_WARN_IF(NS_FAILED(rv))) {
|
|
|
|
return rv;
|
|
|
|
}
|
2003-01-09 06:06:17 +00:00
|
|
|
|
2018-04-24 06:17:17 +00:00
|
|
|
RefPtr<Element> rootNode = mRootNode;
|
2003-01-09 06:06:17 +00:00
|
|
|
NS_ENSURE_TRUE(rootNode, NS_ERROR_FAILURE);
|
|
|
|
|
2018-01-30 04:10:51 +00:00
|
|
|
nsCOMPtr<nsINodeList> nodeList = rootNode->ChildNodes();
|
|
|
|
uint32_t length = nodeList->Length();
|
2003-01-09 06:06:17 +00:00
|
|
|
|
2010-07-20 12:47:28 +00:00
|
|
|
NS_ASSERTION(length <= 2,
|
|
|
|
"We should have one text node and one mozBR at most");
|
2010-09-02 23:54:23 +00:00
|
|
|
|
2018-01-30 04:10:51 +00:00
|
|
|
nsCOMPtr<nsINode> firstNode = nodeList->Item(0);
|
2018-03-19 19:15:39 +00:00
|
|
|
Text* textNode = firstNode ? firstNode->GetAsText() : nullptr;
|
2010-09-02 23:54:23 +00:00
|
|
|
|
2017-03-09 19:44:45 +00:00
|
|
|
if (length == 0) {
|
2018-04-24 06:17:17 +00:00
|
|
|
rootNode.forget(aResult);
|
2010-07-20 12:47:28 +00:00
|
|
|
*aPosition = 0;
|
|
|
|
} else if (textNode) {
|
2018-03-19 19:15:39 +00:00
|
|
|
uint32_t textLength = textNode->Length();
|
2017-03-09 19:44:45 +00:00
|
|
|
if (length == 2 && aOffset == textLength) {
|
2010-12-07 06:30:05 +00:00
|
|
|
// If we're at the end of the text node and we have a trailing BR node,
|
|
|
|
// set the selection on the BR node.
|
2018-03-19 19:15:39 +00:00
|
|
|
rootNode.forget(aResult);
|
2010-12-07 06:30:05 +00:00
|
|
|
*aPosition = 1;
|
|
|
|
} else {
|
|
|
|
// Otherwise, set the selection on the textnode itself.
|
2018-03-19 19:15:39 +00:00
|
|
|
firstNode.forget(aResult);
|
2017-03-09 19:44:45 +00:00
|
|
|
*aPosition = std::min(aOffset, textLength);
|
2010-12-07 06:30:05 +00:00
|
|
|
}
|
2010-07-20 12:47:28 +00:00
|
|
|
} else {
|
2018-03-19 19:15:39 +00:00
|
|
|
rootNode.forget(aResult);
|
2010-07-20 12:47:28 +00:00
|
|
|
*aPosition = 0;
|
2003-01-09 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2010-07-20 12:47:28 +00:00
|
|
|
return NS_OK;
|
2003-01-09 06:06:17 +00:00
|
|
|
}
|
|
|
|
|
2002-07-26 17:17:00 +00:00
|
|
|
/////END INTERFACE IMPLEMENTATIONS
|
|
|
|
|
|
|
|
////NSIFRAME
|
2012-08-22 15:56:38 +00:00
|
|
|
nsresult nsTextControlFrame::AttributeChanged(int32_t aNameSpaceID,
|
2017-10-02 22:05:19 +00:00
|
|
|
nsAtom* aAttribute,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t aModType) {
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
nsISelectionController* selCon = txtCtrl->GetSelectionController();
|
2011-09-29 06:19:26 +00:00
|
|
|
const bool needEditor =
|
|
|
|
nsGkAtoms::maxlength == aAttribute || nsGkAtoms::readonly == aAttribute ||
|
2010-06-28 18:04:37 +00:00
|
|
|
nsGkAtoms::disabled == aAttribute || nsGkAtoms::spellcheck == aAttribute;
|
2017-06-19 14:47:02 +00:00
|
|
|
RefPtr<TextEditor> textEditor = needEditor ? GetTextEditor() : nullptr;
|
|
|
|
if ((needEditor && !textEditor) || !selCon) {
|
2012-06-23 11:11:00 +00:00
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute,
|
|
|
|
aModType);
|
2013-07-24 23:03:39 +00:00
|
|
|
}
|
2009-01-29 19:46:17 +00:00
|
|
|
|
2013-07-24 23:03:39 +00:00
|
|
|
if (nsGkAtoms::maxlength == aAttribute) {
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t maxLength;
|
2011-09-29 06:19:26 +00:00
|
|
|
bool maxDefined = GetMaxLength(&maxLength);
|
2013-07-24 23:03:39 +00:00
|
|
|
if (textEditor) {
|
|
|
|
if (maxDefined) { // set the maxLength attribute
|
|
|
|
textEditor->SetMaxTextLength(maxLength);
|
2002-07-26 17:17:00 +00:00
|
|
|
// if maxLength>docLength, we need to truncate the doc content
|
2013-07-24 23:03:39 +00:00
|
|
|
} else { // unset the maxLength attribute
|
|
|
|
textEditor->SetMaxTextLength(-1);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-24 23:03:39 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nsGkAtoms::readonly == aAttribute) {
|
|
|
|
if (AttributeExists(nsGkAtoms::readonly)) { // set readonly
|
|
|
|
if (nsContentUtils::IsFocusedContent(mContent)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
selCon->SetCaretEnabled(false);
|
2013-07-24 23:03:39 +00:00
|
|
|
}
|
2017-08-08 03:36:29 +00:00
|
|
|
textEditor->AddFlags(nsIPlaintextEditor::eEditorReadonlyMask);
|
2013-07-24 23:03:39 +00:00
|
|
|
} else { // unset readonly
|
2017-06-19 14:47:02 +00:00
|
|
|
if (!textEditor->IsDisabled() &&
|
2013-07-24 23:03:39 +00:00
|
|
|
nsContentUtils::IsFocusedContent(mContent)) {
|
2011-10-17 14:59:28 +00:00
|
|
|
selCon->SetCaretEnabled(true);
|
2013-07-24 23:03:39 +00:00
|
|
|
}
|
2017-08-08 03:36:29 +00:00
|
|
|
textEditor->RemoveFlags(nsIPlaintextEditor::eEditorReadonlyMask);
|
2010-02-02 04:00:06 +00:00
|
|
|
}
|
2013-07-24 23:03:39 +00:00
|
|
|
return NS_OK;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
2013-07-24 23:03:39 +00:00
|
|
|
|
|
|
|
if (nsGkAtoms::disabled == aAttribute) {
|
|
|
|
int16_t displaySelection = nsISelectionController::SELECTION_OFF;
|
|
|
|
const bool focused = nsContentUtils::IsFocusedContent(mContent);
|
|
|
|
const bool hasAttr = AttributeExists(nsGkAtoms::disabled);
|
2017-08-08 03:36:29 +00:00
|
|
|
bool disable;
|
2013-07-24 23:03:39 +00:00
|
|
|
if (hasAttr) { // set disabled
|
2017-08-08 03:36:29 +00:00
|
|
|
disable = true;
|
2013-07-24 23:03:39 +00:00
|
|
|
} else { // unset disabled
|
2017-08-08 03:36:29 +00:00
|
|
|
disable = false;
|
2013-07-24 23:03:39 +00:00
|
|
|
displaySelection = focused ? nsISelectionController::SELECTION_ON
|
|
|
|
: nsISelectionController::SELECTION_HIDDEN;
|
|
|
|
}
|
|
|
|
selCon->SetDisplaySelection(displaySelection);
|
|
|
|
if (focused) {
|
|
|
|
selCon->SetCaretEnabled(!hasAttr);
|
2010-02-02 15:49:55 +00:00
|
|
|
}
|
2017-08-08 03:36:29 +00:00
|
|
|
if (disable) {
|
|
|
|
textEditor->AddFlags(nsIPlaintextEditor::eEditorDisabledMask);
|
|
|
|
} else {
|
|
|
|
textEditor->RemoveFlags(nsIPlaintextEditor::eEditorDisabledMask);
|
|
|
|
}
|
2013-07-24 23:03:39 +00:00
|
|
|
return NS_OK;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
2013-07-24 23:03:39 +00:00
|
|
|
|
2013-10-16 13:43:03 +00:00
|
|
|
if (!mEditorHasBeenInitialized && nsGkAtoms::value == aAttribute) {
|
2011-10-17 14:59:28 +00:00
|
|
|
UpdateValueDisplay(true);
|
2013-07-24 23:03:39 +00:00
|
|
|
return NS_OK;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2013-07-24 23:03:39 +00:00
|
|
|
// Allow the base class to handle common attributes supported by all form
|
|
|
|
// elements...
|
|
|
|
return nsContainerFrame::AttributeChanged(aNameSpaceID, aAttribute, aModType);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2010-02-07 19:44:32 +00:00
|
|
|
void nsTextControlFrame::GetText(nsString& aText) {
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
2002-09-16 06:23:52 +00:00
|
|
|
if (IsSingleLineTextControl()) {
|
2010-07-21 00:11:19 +00:00
|
|
|
// There will be no line breaks so we can ignore the wrap property.
|
2011-10-17 14:59:28 +00:00
|
|
|
txtCtrl->GetTextEditorValue(aText, true);
|
2002-07-26 17:17:00 +00:00
|
|
|
} else {
|
2018-03-21 21:39:04 +00:00
|
|
|
HTMLTextAreaElement* textArea = HTMLTextAreaElement::FromNode(mContent);
|
2002-07-26 17:17:00 +00:00
|
|
|
if (textArea) {
|
2017-10-30 23:14:51 +00:00
|
|
|
textArea->GetValue(aText);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// END NSIFRAME OVERLOADS
|
|
|
|
/////BEGIN PROTECTED METHODS
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
bool nsTextControlFrame::GetMaxLength(int32_t* aSize) {
|
2002-07-26 17:17:00 +00:00
|
|
|
*aSize = -1;
|
|
|
|
|
2018-03-21 21:39:04 +00:00
|
|
|
nsGenericHTMLElement* content = nsGenericHTMLElement::FromNode(mContent);
|
2002-07-26 17:17:00 +00:00
|
|
|
if (content) {
|
2006-12-26 17:47:52 +00:00
|
|
|
const nsAttrValue* attr = content->GetParsedAttr(nsGkAtoms::maxlength);
|
2005-01-25 00:02:58 +00:00
|
|
|
if (attr && attr->Type() == nsAttrValue::eInteger) {
|
|
|
|
*aSize = attr->GetIntegerValue();
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
}
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// END IMPLEMENTING NS_IFORMCONTROLFRAME
|
|
|
|
|
2011-08-24 20:54:30 +00:00
|
|
|
void nsTextControlFrame::SetInitialChildList(ChildListID aListID,
|
2009-07-28 12:53:20 +00:00
|
|
|
nsFrameList& aChildList) {
|
2014-05-28 19:36:58 +00:00
|
|
|
nsContainerFrame::SetInitialChildList(aListID, aChildList);
|
2016-01-27 23:11:00 +00:00
|
|
|
if (aListID != kPrincipalList) {
|
|
|
|
return;
|
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
|
|
|
|
// Mark the scroll frame as being a reflow root. This will allow
|
|
|
|
// incremental reflows to be initiated at the scroll frame, rather
|
|
|
|
// than descending from the root frame of the frame hierarchy.
|
2016-01-29 14:42:14 +00:00
|
|
|
if (nsIFrame* first = PrincipalChildList().FirstChild()) {
|
2010-08-05 02:13:57 +00:00
|
|
|
first->AddStateBits(NS_FRAME_REFLOW_ROOT);
|
2010-09-14 17:34:50 +00:00
|
|
|
|
2010-09-24 19:09:25 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
|
|
|
txtCtrl->InitializeKeyboardEventListeners();
|
2011-02-04 23:28:38 +00:00
|
|
|
|
2017-05-27 11:36:00 +00:00
|
|
|
nsPoint* contentScrollPos = GetProperty(ContentScrollPos());
|
2011-02-04 23:28:38 +00:00
|
|
|
if (contentScrollPos) {
|
|
|
|
// If we have a scroll pos stored to be passed to our anonymous
|
|
|
|
// div, do it here!
|
|
|
|
nsIStatefulFrame* statefulFrame = do_QueryFrame(first);
|
|
|
|
NS_ASSERTION(statefulFrame,
|
|
|
|
"unexpected type of frame for the anonymous div");
|
2018-03-02 18:18:35 +00:00
|
|
|
UniquePtr<PresState> fakePresState = NewPresState();
|
|
|
|
fakePresState->scrollState() = *contentScrollPos;
|
|
|
|
statefulFrame->RestoreState(fakePresState.get());
|
2017-05-27 11:36:00 +00:00
|
|
|
RemoveProperty(ContentScrollPos());
|
2011-02-04 23:28:38 +00:00
|
|
|
delete contentScrollPos;
|
|
|
|
}
|
2010-09-24 19:09:25 +00:00
|
|
|
}
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
void nsTextControlFrame::SetValueChanged(bool aValueChanged) {
|
2018-03-28 22:01:47 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl =
|
|
|
|
HTMLInputElement::FromNode(GetContent());
|
|
|
|
if (!txtCtrl) {
|
|
|
|
txtCtrl = HTMLTextAreaElement::FromNode(GetContent());
|
|
|
|
}
|
2017-09-08 13:07:22 +00:00
|
|
|
MOZ_ASSERT(txtCtrl, "Content not a text control element");
|
2011-01-28 01:19:04 +00:00
|
|
|
|
2017-09-22 05:33:41 +00:00
|
|
|
if (mPlaceholderDiv) {
|
2017-03-01 17:03:14 +00:00
|
|
|
AutoWeakFrame weakFrame(this);
|
2017-03-30 09:38:59 +00:00
|
|
|
txtCtrl->UpdateOverlayTextVisibility(true);
|
2011-01-28 01:19:04 +00:00
|
|
|
if (!weakFrame.IsAlive()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
txtCtrl->SetValueChanged(aValueChanged);
|
2002-07-26 17:17:00 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
nsresult nsTextControlFrame::UpdateValueDisplay(bool aNotify,
|
|
|
|
bool aBeforeEditorInit,
|
2010-02-02 15:49:55 +00:00
|
|
|
const nsAString* aValue) {
|
|
|
|
if (!IsSingleLineTextControl()) // textareas don't use this
|
|
|
|
return NS_OK;
|
|
|
|
|
2018-04-28 19:50:58 +00:00
|
|
|
MOZ_ASSERT(mRootNode, "Must have a div content\n");
|
|
|
|
MOZ_ASSERT(!mEditorHasBeenInitialized,
|
|
|
|
"Do not call this after editor has been initialized");
|
2010-02-02 15:49:55 +00:00
|
|
|
|
2018-03-28 22:01:46 +00:00
|
|
|
nsIContent* childContent = mRootNode->GetFirstChild();
|
|
|
|
Text* textContent;
|
|
|
|
if (!childContent) {
|
2010-04-16 01:25:40 +00:00
|
|
|
// Set up a textnode with our value
|
2015-10-18 05:24:48 +00:00
|
|
|
RefPtr<nsTextNode> textNode =
|
2013-04-04 12:01:08 +00:00
|
|
|
new nsTextNode(mContent->NodeInfo()->NodeInfoManager());
|
2017-08-18 07:05:16 +00:00
|
|
|
textNode->MarkAsMaybeModifiedFrequently();
|
2010-02-02 15:49:55 +00:00
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
mRootNode->AppendChildTo(textNode, aNotify);
|
2010-04-16 01:25:40 +00:00
|
|
|
textContent = textNode;
|
2018-03-28 22:01:46 +00:00
|
|
|
} else {
|
2018-09-11 10:10:08 +00:00
|
|
|
textContent = childContent->GetAsText();
|
2010-02-02 15:49:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-16 01:25:40 +00:00
|
|
|
NS_ENSURE_TRUE(textContent, NS_ERROR_UNEXPECTED);
|
|
|
|
|
2017-09-22 00:18:30 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
MOZ_ASSERT(txtCtrl);
|
|
|
|
|
2010-02-02 15:49:55 +00:00
|
|
|
// Get the current value of the textfield from the content.
|
|
|
|
nsAutoString value;
|
|
|
|
if (aValue) {
|
|
|
|
value = *aValue;
|
|
|
|
} else {
|
2011-10-17 14:59:28 +00:00
|
|
|
txtCtrl->GetTextEditorValue(value, true);
|
2010-02-02 15:49:55 +00:00
|
|
|
}
|
|
|
|
|
2017-03-30 09:38:59 +00:00
|
|
|
// Update the display of the placeholder value and preview text if needed.
|
|
|
|
// We don't need to do this if we're about to initialize the editor, since
|
|
|
|
// EnsureEditorInitialized takes care of this.
|
2017-09-22 05:33:41 +00:00
|
|
|
if ((mPlaceholderDiv || mPreviewDiv) && !aBeforeEditorInit) {
|
2017-03-01 17:03:14 +00:00
|
|
|
AutoWeakFrame weakFrame(this);
|
2017-03-30 09:38:59 +00:00
|
|
|
txtCtrl->UpdateOverlayTextVisibility(aNotify);
|
2010-04-06 20:43:39 +00:00
|
|
|
NS_ENSURE_STATE(weakFrame.IsAlive());
|
|
|
|
}
|
|
|
|
|
2010-02-02 15:49:55 +00:00
|
|
|
if (aBeforeEditorInit && value.IsEmpty()) {
|
2018-01-16 13:17:10 +00:00
|
|
|
nsIContent* node = mRootNode->GetFirstChild();
|
|
|
|
if (node) {
|
|
|
|
mRootNode->RemoveChildNode(node, true);
|
|
|
|
}
|
2010-02-02 15:49:55 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-16 01:25:40 +00:00
|
|
|
if (!value.IsEmpty() && IsPasswordTextControl()) {
|
2016-07-09 02:34:41 +00:00
|
|
|
TextEditRules::FillBufWithPWChars(&value, value.Length());
|
2010-02-02 15:49:55 +00:00
|
|
|
}
|
2010-04-16 01:25:40 +00:00
|
|
|
return textContent->SetText(value, aNotify);
|
2010-02-02 15:49:55 +00:00
|
|
|
}
|
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::GetOwnedSelectionController(
|
|
|
|
nsISelectionController** aSelCon) {
|
|
|
|
NS_ENSURE_ARG_POINTER(aSelCon);
|
2010-02-26 18:47:38 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
2010-02-26 18:47:38 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
*aSelCon = txtCtrl->GetSelectionController();
|
|
|
|
NS_IF_ADDREF(*aSelCon);
|
2010-02-26 18:47:38 +00:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
nsFrameSelection* nsTextControlFrame::GetOwnedFrameSelection() {
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element");
|
2010-02-07 19:44:32 +00:00
|
|
|
|
2010-04-21 20:17:41 +00:00
|
|
|
return txtCtrl->GetConstFrameSelection();
|
2010-02-07 19:44:32 +00:00
|
|
|
}
|
|
|
|
|
2018-03-02 18:18:35 +00:00
|
|
|
UniquePtr<PresState> nsTextControlFrame::SaveState() {
|
2018-04-24 06:17:17 +00:00
|
|
|
if (mRootNode) {
|
2011-02-04 23:28:38 +00:00
|
|
|
// Query the nsIStatefulFrame from the HTMLScrollFrame
|
2018-04-24 06:17:17 +00:00
|
|
|
nsIStatefulFrame* scrollStateFrame =
|
|
|
|
do_QueryFrame(mRootNode->GetPrimaryFrame());
|
2011-02-04 23:28:38 +00:00
|
|
|
if (scrollStateFrame) {
|
2018-03-02 18:18:35 +00:00
|
|
|
return scrollStateFrame->SaveState();
|
2011-02-04 23:28:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-02 18:18:35 +00:00
|
|
|
return nullptr;
|
2011-02-04 23:28:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2018-03-02 18:18:35 +00:00
|
|
|
nsTextControlFrame::RestoreState(PresState* aState) {
|
2011-02-04 23:28:38 +00:00
|
|
|
NS_ENSURE_ARG_POINTER(aState);
|
|
|
|
|
2018-04-24 06:17:17 +00:00
|
|
|
if (mRootNode) {
|
2011-02-04 23:28:38 +00:00
|
|
|
// Query the nsIStatefulFrame from the HTMLScrollFrame
|
2018-04-24 06:17:17 +00:00
|
|
|
nsIStatefulFrame* scrollStateFrame =
|
|
|
|
do_QueryFrame(mRootNode->GetPrimaryFrame());
|
2011-02-04 23:28:38 +00:00
|
|
|
if (scrollStateFrame) {
|
|
|
|
return scrollStateFrame->RestoreState(aState);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Most likely, we don't have our anonymous content constructed yet, which
|
|
|
|
// would cause us to end up here. In this case, we'll just store the scroll
|
|
|
|
// pos ourselves, and forward it to the scroll frame later when it's created.
|
2018-03-02 18:18:35 +00:00
|
|
|
SetProperty(ContentScrollPos(), new nsPoint(aState->scrollState()));
|
2011-02-04 23:28:38 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-06-19 23:31:03 +00:00
|
|
|
|
|
|
|
nsresult nsTextControlFrame::PeekOffset(nsPeekOffsetStruct* aPos) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-11-09 10:22:29 +00:00
|
|
|
void nsTextControlFrame::BuildDisplayList(nsDisplayListBuilder* aBuilder,
|
|
|
|
const nsDisplayListSet& aLists) {
|
|
|
|
/*
|
|
|
|
* The implementation of this method is equivalent as:
|
|
|
|
* nsContainerFrame::BuildDisplayList()
|
|
|
|
* with the difference that we filter-out the placeholder frame when it
|
|
|
|
* should not be visible.
|
|
|
|
*/
|
|
|
|
DO_GLOBAL_REFLOW_COUNT_DSP("nsTextControlFrame");
|
|
|
|
|
|
|
|
nsCOMPtr<nsITextControlElement> txtCtrl = do_QueryInterface(GetContent());
|
|
|
|
NS_ASSERTION(txtCtrl, "Content not a text control element!");
|
|
|
|
|
2013-02-14 11:08:08 +00:00
|
|
|
DisplayBorderBackgroundOutline(aBuilder, aLists);
|
2012-11-09 10:22:29 +00:00
|
|
|
|
|
|
|
nsIFrame* kid = mFrames.FirstChild();
|
2013-03-07 05:13:13 +00:00
|
|
|
// Redirect all lists to the Content list so that nothing can escape, ie
|
|
|
|
// opacity creating stacking contexts that then get sorted with stacking
|
|
|
|
// contexts external to us.
|
|
|
|
nsDisplayList* content = aLists.Content();
|
|
|
|
nsDisplayListSet set(content, content, content, content, content, content);
|
2012-11-09 10:22:29 +00:00
|
|
|
|
|
|
|
while (kid) {
|
2017-03-30 09:38:59 +00:00
|
|
|
// If the frame is the placeholder or preview frame, we should only show
|
|
|
|
// it if it has to be visible.
|
2018-04-24 06:17:17 +00:00
|
|
|
if (!((kid->GetContent() == mPlaceholderDiv &&
|
2017-03-30 09:38:59 +00:00
|
|
|
!txtCtrl->GetPlaceholderVisibility()) ||
|
2018-04-24 06:17:18 +00:00
|
|
|
(kid->GetContent() == mPreviewDiv &&
|
2017-03-30 09:38:59 +00:00
|
|
|
!txtCtrl->GetPreviewVisibility()))) {
|
2017-08-07 02:23:35 +00:00
|
|
|
BuildDisplayListForChild(aBuilder, kid, set, 0);
|
2012-11-09 10:22:29 +00:00
|
|
|
}
|
|
|
|
kid = kid->GetNextSibling();
|
|
|
|
}
|
|
|
|
}
|
2013-01-23 19:37:17 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsTextControlFrame::EditorInitializer::Run() {
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Need to block script to avoid bug 669767.
|
|
|
|
nsAutoScriptBlocker scriptBlocker;
|
|
|
|
|
2019-04-16 07:25:10 +00:00
|
|
|
RefPtr<mozilla::PresShell> presShell = mFrame->PresShell();
|
|
|
|
bool observes = presShell->ObservesNativeAnonMutationsForPrint();
|
|
|
|
presShell->ObserveNativeAnonMutationsForPrint(true);
|
2013-01-23 19:37:17 +00:00
|
|
|
// This can cause the frame to be destroyed (and call Revoke()).
|
|
|
|
mFrame->EnsureEditorInitialized();
|
2019-04-16 07:25:10 +00:00
|
|
|
presShell->ObserveNativeAnonMutationsForPrint(observes);
|
2013-01-23 19:37:17 +00:00
|
|
|
|
|
|
|
// The frame can *still* be destroyed even though we have a scriptblocker,
|
|
|
|
// bug 682684.
|
|
|
|
if (!mFrame) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mFrame->FinishedInitializer();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2017-09-22 00:18:30 +00:00
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS(nsTextControlFrame::nsAnonDivObserver, nsIMutationObserver)
|
|
|
|
|
|
|
|
void nsTextControlFrame::nsAnonDivObserver::CharacterDataChanged(
|
2018-02-27 14:30:27 +00:00
|
|
|
nsIContent* aContent, const CharacterDataChangeInfo&) {
|
2017-09-22 00:18:30 +00:00
|
|
|
mFrame.ClearCachedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::nsAnonDivObserver::ContentAppended(
|
2017-07-27 13:49:52 +00:00
|
|
|
nsIContent* aFirstNewContent) {
|
2017-09-22 00:18:30 +00:00
|
|
|
mFrame.ClearCachedValue();
|
|
|
|
}
|
|
|
|
|
2018-03-01 11:36:58 +00:00
|
|
|
void nsTextControlFrame::nsAnonDivObserver::ContentInserted(
|
|
|
|
nsIContent* aChild) {
|
2017-09-22 00:18:30 +00:00
|
|
|
mFrame.ClearCachedValue();
|
|
|
|
}
|
|
|
|
|
|
|
|
void nsTextControlFrame::nsAnonDivObserver::ContentRemoved(
|
|
|
|
nsIContent* aChild, nsIContent* aPreviousSibling) {
|
|
|
|
mFrame.ClearCachedValue();
|
|
|
|
}
|