@@ -1022,8 +1022,8 @@ HTMLInputElement::HTMLInputElement(already_AddRefed<dom::NodeInfo>&& aNodeInfo,
1022
1022
" Keep the size of HTMLInputElement under 512 to avoid "
1023
1023
" performance regression!" );
1024
1024
1025
- // We are in a type=text so we now we currenty need a TextControlState.
1026
- mInputData .mState = TextControlState::Construct ( this ) ;
1025
+ // We are in a type=text but we create TextControlState lazily .
1026
+ mInputData .mState = nullptr ;
1027
1027
1028
1028
void * memory = mInputTypeMem ;
1029
1029
mInputType = InputType::Create (this , mType , memory);
@@ -1053,7 +1053,8 @@ void HTMLInputElement::FreeData() {
1053
1053
if (!IsSingleLineTextControl (false )) {
1054
1054
free (mInputData .mValue );
1055
1055
mInputData .mValue = nullptr ;
1056
- } else {
1056
+ } else if (mInputData .mState ) {
1057
+ // XXX Passing nullptr to UnbindFromFrame doesn't do anything!
1057
1058
UnbindFromFrame (nullptr );
1058
1059
mInputData .mState ->Destroy ();
1059
1060
mInputData .mState = nullptr ;
@@ -1065,11 +1066,22 @@ void HTMLInputElement::FreeData() {
1065
1066
}
1066
1067
}
1067
1068
1069
+ void HTMLInputElement::EnsureEditorState () {
1070
+ MOZ_ASSERT (IsSingleLineTextControl (false ));
1071
+ if (!mInputData .mState ) {
1072
+ mInputData .mState = TextControlState::Construct (this );
1073
+ }
1074
+ }
1075
+
1068
1076
TextControlState* HTMLInputElement::GetEditorState () const {
1069
1077
if (!IsSingleLineTextControl (false )) {
1070
1078
return nullptr ;
1071
1079
}
1072
1080
1081
+ // We've postponed allocating TextControlState, doing that in a const
1082
+ // method is fine.
1083
+ const_cast <HTMLInputElement*>(this )->EnsureEditorState ();
1084
+
1073
1085
MOZ_ASSERT (mInputData .mState ,
1074
1086
" Single line text controls need to have a state"
1075
1087
" associated with them" );
@@ -1085,7 +1097,7 @@ NS_IMPL_CYCLE_COLLECTION_TRAVERSE_BEGIN_INHERITED(HTMLInputElement,
1085
1097
TextControlElement)
1086
1098
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mValidity )
1087
1099
NS_IMPL_CYCLE_COLLECTION_TRAVERSE(mControllers )
1088
- if (tmp->IsSingleLineTextControl (false )) {
1100
+ if (tmp->IsSingleLineTextControl (false ) && tmp->mInputData.mState ) {
1089
1101
tmp->mInputData .mState ->Traverse (cb);
1090
1102
}
1091
1103
@@ -1098,7 +1110,7 @@ NS_IMPL_CYCLE_COLLECTION_UNLINK_BEGIN_INHERITED(HTMLInputElement,
1098
1110
TextControlElement)
1099
1111
NS_IMPL_CYCLE_COLLECTION_UNLINK(mValidity )
1100
1112
NS_IMPL_CYCLE_COLLECTION_UNLINK(mControllers )
1101
- if (tmp->IsSingleLineTextControl (false )) {
1113
+ if (tmp->IsSingleLineTextControl (false ) && tmp->mInputData.mState ) {
1102
1114
tmp->mInputData .mState ->Unlink ();
1103
1115
}
1104
1116
@@ -1578,7 +1590,12 @@ void HTMLInputElement::GetNonFileValueInternal(nsAString& aValue) const {
1578
1590
switch (GetValueMode ()) {
1579
1591
case VALUE_MODE_VALUE:
1580
1592
if (IsSingleLineTextControl (false )) {
1581
- mInputData .mState ->GetValue (aValue, true , /* aForDisplay = */ false );
1593
+ if (mInputData .mState ) {
1594
+ mInputData .mState ->GetValue (aValue, true , /* aForDisplay = */ false );
1595
+ } else {
1596
+ // Value hasn't been set yet.
1597
+ aValue.Truncate ();
1598
+ }
1582
1599
} else if (!aValue.Assign (mInputData .mValue , fallible)) {
1583
1600
aValue.Truncate ();
1584
1601
}
@@ -2702,6 +2719,7 @@ nsresult HTMLInputElement::SetValueInternal(
2702
2719
// of calling this method, you need to maintain SetUserInput() too. FYI:
2703
2720
// After calling SetValue(), the input type might have been
2704
2721
// modified so that mInputData may not store TextControlState.
2722
+ EnsureEditorState ();
2705
2723
if (!mInputData .mState ->SetValue (
2706
2724
value, aOldValue,
2707
2725
forcePreserveUndoHistory
@@ -4455,7 +4473,7 @@ void HTMLInputElement::HandleTypeChange(FormControlType aNewType,
4455
4473
4456
4474
TextControlState::SelectionProperties sp;
4457
4475
4458
- if (GetEditorState () ) {
4476
+ if (IsSingleLineTextControl ( false ) && mInputData . mState ) {
4459
4477
mInputData .mState ->SyncUpSelectionPropertiesBeforeDestruction ();
4460
4478
sp = mInputData .mState ->GetSelectionProperties ();
4461
4479
}
0 commit comments