Bug 1057256 - Part 2 - Add null pointer check for touch and selection carets. r=roc
authorTing-Yu Lin <tlin@mozilla.com>
Mon, 25 Aug 2014 02:50:00 +0200
changeset 201633 da880002e2afbd6b4d8be36948301a00045802ba
parent 201632 53719d03f70afee27a56b2e2288aaabe0b26bca6
child 201634 6d59613b92df36a8f53fd642294b8107903f176c
push id27375
push userryanvm@gmail.com
push dateTue, 26 Aug 2014 19:56:59 +0000
treeherdermozilla-central@f9bfe115fee5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc
bugs1057256
milestone34.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 1057256 - Part 2 - Add null pointer check for touch and selection carets. r=roc TouchCaret::IsDisplayable() contains more null pointer check. It covers what's original there in TouchCaret::HandleEvent().
layout/base/SelectionCarets.cpp
layout/base/TouchCaret.cpp
--- a/layout/base/SelectionCarets.cpp
+++ b/layout/base/SelectionCarets.cpp
@@ -534,16 +534,20 @@ SelectionCarets::SelectWord()
   if (!ptFrame) {
     return NS_OK;
   }
 
   nsPoint ptInFrame = mDownPoint;
   nsLayoutUtils::TransformPoint(canvasFrame, ptFrame, ptInFrame);
 
   nsIFrame* caretFocusFrame = GetCaretFocusFrame();
+  if (!caretFocusFrame) {
+    return NS_OK;
+  }
+
   SetSelectionDragState(true);
   nsFrame* frame = static_cast<nsFrame*>(ptFrame);
   nsresult rs = frame->SelectByTypeAtPoint(mPresShell->GetPresContext(), ptInFrame,
                                            eSelectWord, eSelectWord, 0);
   SetSelectionDragState(false);
 
   // Clear maintain selection otherwise we cannot select less than a word
   nsRefPtr<nsFrameSelection> fs = caretFocusFrame->GetFrameSelection();
@@ -632,16 +636,20 @@ SelectionCarets::DragSelection(const nsP
   // Find out which content we point to
   nsIFrame *ptFrame = nsLayoutUtils::GetFrameForPoint(canvasFrame, movePoint,
     nsLayoutUtils::IGNORE_PAINT_SUPPRESSION | nsLayoutUtils::IGNORE_CROSS_DOC);
   if (!ptFrame) {
     return nsEventStatus_eConsumeNoDefault;
   }
 
   nsIFrame* caretFocusFrame = GetCaretFocusFrame();
+  if (!caretFocusFrame) {
+    return nsEventStatus_eConsumeNoDefault;
+  }
+
   nsRefPtr<nsFrameSelection> fs = caretFocusFrame->GetFrameSelection();
 
   nsresult result;
   nsIFrame *newFrame = nullptr;
   nsPoint newPoint;
   nsPoint ptInFrame = movePoint;
   nsLayoutUtils::TransformPoint(canvasFrame, ptFrame, ptInFrame);
   result = fs->ConstrainFrameAndPointToAnchorSubtree(ptFrame, ptInFrame, &newFrame, newPoint);
@@ -730,16 +738,20 @@ SelectionCarets::GetCaretYCenterPosition
   nsLayoutUtils::TransformRect(theFrame, canvasFrame, frameRect);
   return frameRect.Center().y;
 }
 
 void
 SelectionCarets::SetSelectionDragState(bool aState)
 {
   nsIFrame* caretFocusFrame = GetCaretFocusFrame();
+  if (!caretFocusFrame) {
+    return;
+  }
+
   nsRefPtr<nsFrameSelection> fs = caretFocusFrame->GetFrameSelection();
   fs->SetDragState(aState);
 }
 
 void
 SelectionCarets::SetSelectionDirection(bool aForward)
 {
   nsISelection* caretSelection = GetSelection();
--- a/layout/base/TouchCaret.cpp
+++ b/layout/base/TouchCaret.cpp
@@ -538,23 +538,17 @@ TouchCaret::SetSelectionDragState(bool a
   nsRefPtr<nsFrameSelection> fs = caretFocusFrame->GetFrameSelection();
   fs->SetDragState(aState);
 }
 
 nsEventStatus
 TouchCaret::HandleEvent(WidgetEvent* aEvent)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  nsCOMPtr<nsIPresShell> presShell = do_QueryReferent(mPresShell);
-  if (!presShell) {
-    return nsEventStatus_eIgnore;
-  }
-
-  mozilla::dom::Element* touchCaretElement = presShell->GetTouchCaretElement();
-  if (!touchCaretElement) {
+  if (!IsDisplayable()) {
     return nsEventStatus_eIgnore;
   }
 
   nsEventStatus status = nsEventStatus_eIgnore;
 
   switch (aEvent->message) {
     case NS_TOUCH_START:
       status = HandleTouchDownEvent(aEvent->AsTouchEvent());