Bug 748307 part 3 - Clean up WillDoAction; r=ehsan
authorAryeh Gregor <ayg@aryeh.name>
Tue, 22 May 2012 12:37:17 +0300
changeset 94962 d3d137c04d726655b9eaf01e2f6144883982e6d1
parent 94961 f45e87248f24d87e840186ab33dc528d1f5248e0
child 94963 d216ddd1d2ed71e4822e40c52f9fa03b713cc964
push id22770
push userryanvm@gmail.com
push dateSat, 26 May 2012 12:07:39 +0000
treeherdermozilla-central@cd62c4b8f500 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersehsan
bugs748307
milestone15.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 748307 part 3 - Clean up WillDoAction; r=ehsan
editor/libeditor/html/nsHTMLEditRules.cpp
editor/libeditor/text/nsTextEditRules.cpp
--- a/editor/libeditor/html/nsHTMLEditRules.cpp
+++ b/editor/libeditor/html/nsHTMLEditRules.cpp
@@ -509,128 +509,105 @@ nsHTMLEditRules::AfterEditInner(nsEditor
   {
     res = CheckInterlinePosition(selection);
   }
   
   return res;
 }
 
 
-NS_IMETHODIMP 
-nsHTMLEditRules::WillDoAction(nsTypedSelection *aSelection,
-                              nsRulesInfo *aInfo, 
-                              bool *aCancel, 
-                              bool *aHandled)
-{
-  NS_ENSURE_TRUE(aInfo && aCancel && aHandled, NS_ERROR_NULL_POINTER);
-#if defined(DEBUG_ftang)
-  printf("nsHTMLEditRules::WillDoAction action = %d\n", aInfo->action);
-#endif
+NS_IMETHODIMP
+nsHTMLEditRules::WillDoAction(nsTypedSelection* aSelection,
+                              nsRulesInfo* aInfo,
+                              bool* aCancel,
+                              bool* aHandled)
+{
+  MOZ_ASSERT(aInfo && aCancel && aHandled);
 
   *aCancel = false;
   *aHandled = false;
-    
+
   // my kingdom for dynamic cast
   nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
 
   // Deal with actions for which we don't need to check whether the selection is
   // editable.
   if (info->action == nsEditor::kOpOutputText ||
       info->action == nsEditor::kOpUndo ||
       info->action == nsEditor::kOpRedo) {
     return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
   }
 
-  nsCOMPtr<nsIDOMRange> domRange;
-  nsresult rv = aSelection->GetRangeAt(0, getter_AddRefs(domRange));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  nsCOMPtr<nsIDOMNode> selStartNode;
-  rv = domRange->GetStartContainer(getter_AddRefs(selStartNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (!mHTMLEditor->IsModifiableNode(selStartNode))
-  {
+  nsRefPtr<nsRange> range = aSelection->GetRangeAt(0);
+  nsCOMPtr<nsINode> selStartNode = range->GetStartParent();
+
+  if (!mHTMLEditor->IsModifiableNode(selStartNode)) {
     *aCancel = true;
-
     return NS_OK;
   }
 
-  nsCOMPtr<nsIDOMNode> selEndNode;
-  rv = domRange->GetEndContainer(getter_AddRefs(selEndNode));
-  NS_ENSURE_SUCCESS(rv, rv);
-
-  if (selStartNode != selEndNode)
-  {
-    if (!mHTMLEditor->IsModifiableNode(selEndNode))
-    {
+  nsCOMPtr<nsINode> selEndNode = range->GetEndParent();
+
+  if (selStartNode != selEndNode) {
+    if (!mHTMLEditor->IsModifiableNode(selEndNode)) {
       *aCancel = true;
-
       return NS_OK;
     }
 
-    nsRange* range = static_cast<nsRange*>(domRange.get());
-    nsCOMPtr<nsIDOMNode> ancestor =
-      do_QueryInterface(range->GetCommonAncestor());
-    if (!mHTMLEditor->IsModifiableNode(ancestor))
-    {
+    if (!mHTMLEditor->IsModifiableNode(range->GetCommonAncestor())) {
       *aCancel = true;
-
       return NS_OK;
     }
   }
 
-  switch (info->action)
-  {
+  switch (info->action) {
     case nsEditor::kOpInsertText:
     case nsEditor::kOpInsertIMEText:
-      return WillInsertText(info->action,
-                            aSelection, 
-                            aCancel, 
-                            aHandled,
-                            info->inString,
-                            info->outString,
-                            info->maxLength);
+      return WillInsertText(info->action, aSelection, aCancel, aHandled,
+                            info->inString, info->outString, info->maxLength);
     case nsEditor::kOpLoadHTML:
       return WillLoadHTML(aSelection, aCancel);
     case nsEditor::kOpInsertBreak:
       return WillInsertBreak(aSelection, aCancel, aHandled);
     case nsEditor::kOpDeleteSelection:
       return WillDeleteSelection(aSelection, info->collapsedAction,
                                  info->stripWrappers, aCancel, aHandled);
     case nsEditor::kOpMakeList:
-      return WillMakeList(aSelection, info->blockType, info->entireList, info->bulletType, aCancel, aHandled);
+      return WillMakeList(aSelection, info->blockType, info->entireList,
+                          info->bulletType, aCancel, aHandled);
     case nsEditor::kOpIndent:
       return WillIndent(aSelection, aCancel, aHandled);
     case nsEditor::kOpOutdent:
       return WillOutdent(aSelection, aCancel, aHandled);
     case nsEditor::kOpSetAbsolutePosition:
       return WillAbsolutePosition(aSelection, aCancel, aHandled);
     case nsEditor::kOpRemoveAbsolutePosition:
       return WillRemoveAbsolutePosition(aSelection, aCancel, aHandled);
     case nsEditor::kOpAlign:
       return WillAlign(aSelection, info->alignType, aCancel, aHandled);
     case nsEditor::kOpMakeBasicBlock:
       return WillMakeBasicBlock(aSelection, info->blockType, aCancel, aHandled);
     case nsEditor::kOpRemoveList:
       return WillRemoveList(aSelection, info->bOrdered, aCancel, aHandled);
     case nsEditor::kOpMakeDefListItem:
-      return WillMakeDefListItem(aSelection, info->blockType, info->entireList, aCancel, aHandled);
+      return WillMakeDefListItem(aSelection, info->blockType, info->entireList,
+                                 aCancel, aHandled);
     case nsEditor::kOpInsertElement:
       return WillInsert(aSelection, aCancel);
     case nsEditor::kOpDecreaseZIndex:
       return WillRelativeChangeZIndex(aSelection, -1, aCancel, aHandled);
     case nsEditor::kOpIncreaseZIndex:
       return WillRelativeChangeZIndex(aSelection, 1, aCancel, aHandled);
     default:
-      return nsTextEditRules::WillDoAction(aSelection, aInfo, aCancel, aHandled);
-  }
-}
-  
-  
+      return nsTextEditRules::WillDoAction(aSelection, aInfo,
+                                           aCancel, aHandled);
+  }
+}
+
+
 NS_IMETHODIMP 
 nsHTMLEditRules::DidDoAction(nsISelection *aSelection,
                              nsRulesInfo *aInfo, nsresult aResult)
 {
   nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
   switch (info->action)
   {
     case nsEditor::kOpInsertBreak:
--- a/editor/libeditor/text/nsTextEditRules.cpp
+++ b/editor/libeditor/text/nsTextEditRules.cpp
@@ -203,72 +203,61 @@ nsTextEditRules::AfterEdit(nsEditor::Ope
 
     // collapse the selection to the trailing BR if it's at the end of our text node
     CollapseSelectionToTrailingBRIfNeeded(selection);
   }
   return res;
 }
 
 
-NS_IMETHODIMP 
+NS_IMETHODIMP
 nsTextEditRules::WillDoAction(nsTypedSelection* aSelection,
-                              nsRulesInfo *aInfo, 
-                              bool *aCancel, 
-                              bool *aHandled)
+                              nsRulesInfo* aInfo,
+                              bool* aCancel,
+                              bool* aHandled)
 {
   // null selection is legal
-  if (!aInfo || !aCancel || !aHandled) { return NS_ERROR_NULL_POINTER; }
-#if defined(DEBUG_ftang)
-  printf("nsTextEditRules::WillDoAction action= %d", aInfo->action);
-#endif
+  MOZ_ASSERT(aInfo && aCancel && aHandled);
 
   *aCancel = false;
   *aHandled = false;
 
   // my kingdom for dynamic cast
   nsTextRulesInfo *info = static_cast<nsTextRulesInfo*>(aInfo);
-    
-  switch (info->action)
-  {
+
+  switch (info->action) {
     case nsEditor::kOpInsertBreak:
       return WillInsertBreak(aSelection, aCancel, aHandled, info->maxLength);
     case nsEditor::kOpInsertText:
     case nsEditor::kOpInsertIMEText:
-      return WillInsertText(info->action,
-                            aSelection, 
-                            aCancel,
-                            aHandled, 
-                            info->inString,
-                            info->outString,
-                            info->maxLength);
+      return WillInsertText(info->action, aSelection, aCancel, aHandled,
+                            info->inString, info->outString, info->maxLength);
     case nsEditor::kOpDeleteSelection:
-      return WillDeleteSelection(aSelection, info->collapsedAction, aCancel, aHandled);
+      return WillDeleteSelection(aSelection, info->collapsedAction,
+                                 aCancel, aHandled);
     case nsEditor::kOpUndo:
       return WillUndo(aSelection, aCancel, aHandled);
     case nsEditor::kOpRedo:
       return WillRedo(aSelection, aCancel, aHandled);
     case nsEditor::kOpSetTextProperty:
       return WillSetTextProperty(aSelection, aCancel, aHandled);
     case nsEditor::kOpRemoveTextProperty:
       return WillRemoveTextProperty(aSelection, aCancel, aHandled);
     case nsEditor::kOpOutputText:
-      return WillOutputText(aSelection, 
-                            info->outputFormat,
-                            info->outString,                            
-                            aCancel,
-                            aHandled);
+      return WillOutputText(aSelection, info->outputFormat, info->outString,
+                            aCancel, aHandled);
     case nsEditor::kOpInsertElement:
       // i had thought this would be html rules only.  but we put pre elements
       // into plaintext mail when doing quoting for reply!  doh!
       return WillInsert(aSelection, aCancel);
     default:
       return NS_ERROR_FAILURE;
   }
 }
-  
+
 NS_IMETHODIMP 
 nsTextEditRules::DidDoAction(nsISelection *aSelection,
                              nsRulesInfo *aInfo, nsresult aResult)
 {
   // don't let any txns in here move the selection around behind our back.
   // Note that this won't prevent explicit selection setting from working.
   nsAutoTxnsConserveSelection dontSpazMySelection(mEditor);