Bug 1343037 part 4. Fix type changes on an input to properly grab the selection offsets from the old editor before we ask the editor state for them. r=ehsan
authorBoris Zbarsky <bzbarsky@mit.edu>
Thu, 09 Mar 2017 14:44:04 -0500
changeset 346889 08db504dc8e4d9387b4b48626150b6f846df0558
parent 346888 3512debaa707969651b661c4bad61a04f4bf2c55
child 346890 5118456a4b9d08df8919e8ed3a5558b912bbc7ca
push id87912
push userbzbarsky@mozilla.com
push dateFri, 10 Mar 2017 06:56:16 +0000
treeherdermozilla-inbound@f8c3eb6aa697 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs1343037
milestone55.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1343037 part 4. Fix type changes on an input to properly grab the selection offsets from the old editor before we ask the editor state for them. r=ehsan MozReview-Commit-ID: IDdt0qedJpT
dom/html/HTMLInputElement.cpp
dom/html/nsTextEditorState.cpp
dom/html/nsTextEditorState.h
--- a/dom/html/HTMLInputElement.cpp
+++ b/dom/html/HTMLInputElement.cpp
@@ -5131,16 +5131,17 @@ HTMLInputElement::HandleTypeChange(uint8
     // Doesn't matter what caller type we pass here, since we know we're not a
     // file input anyway.
     GetValue(aOldValue, CallerType::NonSystem);
   }
 
   nsTextEditorState::SelectionProperties sp;
 
   if (GetEditorState()) {
+    mInputData.mState->SyncUpSelectionPropertiesBeforeDestruction();
     sp = mInputData.mState->GetSelectionProperties();
   }
 
   // We already have a copy of the value, lets free it and changes the type.
   FreeData();
   mType = aNewType;
 
   if (IsSingleLineTextControl()) {
--- a/dom/html/nsTextEditorState.cpp
+++ b/dom/html/nsTextEditorState.cpp
@@ -1533,16 +1533,24 @@ nsTextEditorState::GetSelectionPropertie
     if (number) {
       return number->GetSelectionProperties();
     }
   }
   return mSelectionProperties;
 }
 
 void
+nsTextEditorState::SyncUpSelectionPropertiesBeforeDestruction()
+{
+  if (mBoundFrame) {
+    UnbindFromFrame(mBoundFrame);
+  }
+}
+
+void
 nsTextEditorState::SetSelectionProperties(nsTextEditorState::SelectionProperties& aProps)
 {
   if (mBoundFrame) {
     mBoundFrame->SetSelectionRange(aProps.GetStart(),
                                    aProps.GetEnd(),
                                    aProps.GetDirection());
   } else {
     mSelectionProperties = aProps;
--- a/dom/html/nsTextEditorState.h
+++ b/dom/html/nsTextEditorState.h
@@ -256,16 +256,20 @@ public:
       nsITextControlFrame::SelectionDirection mDirection;
   };
 
   bool IsSelectionCached() const;
   SelectionProperties& GetSelectionProperties();
   void SetSelectionProperties(SelectionProperties& aProps);
   void WillInitEagerly() { mSelectionRestoreEagerInit = true; }
   bool HasNeverInitializedBefore() const { return !mEverInited; }
+  // Sync up our selection properties with our editor prior to being destroyed.
+  // This will invoke UnbindFromFrame() to ensure that we grab whatever
+  // selection state may be at the moment.
+  void SyncUpSelectionPropertiesBeforeDestruction();
 
   // Get the selection range start and end points in our text.
   nsresult GetSelectionRange(int32_t* aSelectionStart, int32_t* aSelectionEnd);
 
   // Get the selection direction
   nsresult GetSelectionDirection(nsITextControlFrame::SelectionDirection* aDirection);
 
   void UpdateEditableState(bool aNotify) {