Bug 426766: Cursor keys behave weirdly in "view source" window. r+sr=roc.
authorUri Bernstein <uriber@gmail.com>
Thu, 09 Oct 2008 12:07:16 +0200
changeset 20199 abd911498db31587f9116891c54af7b5a311b671
parent 20198 335b63a03aba0b7e0a329eea658dd94410e71402
child 20200 729436f1f0d3f929891bc1f9cd5b2b367d5a3713
push idunknown
push userunknown
push dateunknown
bugs426766
milestone1.9.1b2pre
Bug 426766: Cursor keys behave weirdly in "view source" window. r+sr=roc.
layout/generic/nsFrameSelection.h
layout/generic/nsSelection.cpp
--- a/layout/generic/nsFrameSelection.h
+++ b/layout/generic/nsFrameSelection.h
@@ -551,17 +551,18 @@ public:
   nsresult DeleteFromDocument();
 
   nsIPresShell *GetShell()const  { return mShell; }
 
   void DisconnectFromPresShell() { mShell = nsnull; }
 private:
   nsresult TakeFocus(nsIContent *aNewFocus,
                      PRUint32 aContentOffset,
-                     PRUint32 aContentEndOffset, 
+                     PRUint32 aContentEndOffset,
+                     HINT aHint,
                      PRBool aContinueSelection,
                      PRBool aMultipleSelection);
 
   void BidiLevelFromMove(nsIPresShell* aPresShell,
                          nsIContent *aNode,
                          PRUint32 aContentOffset,
                          PRUint32 aKeycode,
                          HINT aHint);
--- a/layout/generic/nsSelection.cpp
+++ b/layout/generic/nsSelection.cpp
@@ -1402,37 +1402,34 @@ nsFrameSelection::MoveCaret(PRUint32    
               || (eSelectLine == aAmount))
           {
             SetCaretBidiLevel(NS_GET_EMBEDDING_LEVEL(theFrame));
           }
           else
             BidiLevelFromMove(mShell, pos.mResultContent, pos.mContentOffset, aKeycode, tHint);
       }
     }
-    result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset, aContinueSelection, PR_FALSE);
+    result = TakeFocus(pos.mResultContent, pos.mContentOffset, pos.mContentOffset,
+                       tHint, aContinueSelection, PR_FALSE);
   } else if (aKeycode == nsIDOMKeyEvent::DOM_VK_RIGHT && !aContinueSelection) {
     // Collapse selection if PeekOffset failed, we either
     //  1. bumped into the BRFrame, bug 207623
     //  2. had select-all in a text input (DIV range), bug 352759.
     weakNodeUsed = mDomSelections[index]->FetchFocusNode();
     offsetused = mDomSelections[index]->FetchFocusOffset();
     PRBool isBRFrame = frame->GetType() == nsGkAtoms::brFrame;
     mDomSelections[index]->Collapse(weakNodeUsed, offsetused);
     // Note: 'frame' might be dead here.
-    if (isBRFrame) {
-      tHint = mHint;    // 1: make the line below restore the original hint
-    }
-    else {
-      tHint = HINTLEFT; // 2: we're now at the end of the frame to the left
+    if (!isBRFrame) {
+      mHint = HINTLEFT; // We're now at the end of the frame to the left.
     }
     result = NS_OK;
   }
   if (NS_SUCCEEDED(result))
   {
-    mHint = tHint; //save the hint parameter now for the next time
     result = mDomSelections[index]->
       ScrollIntoView(nsISelectionController::SELECTION_FOCUS_REGION,
                      PR_FALSE, PR_FALSE);
   }
 
   return result;
 }
 
@@ -1820,27 +1817,27 @@ nsFrameSelection::HandleClick(nsIContent
 
   if (!aContinueSelection) {
     mMaintainRange = nsnull;
     if (!IsValidSelectionPoint(this, aNewFocus)) {
       mAncestorLimiter = nsnull;
     }
   }
 
-  mHint = HINT(aHint);
   // Don't take focus when dragging off of a table
   if (!mDragSelectingCells)
   {
     BidiLevelFromClick(aNewFocus, aContentOffset);
     PostReason(nsISelectionListener::MOUSEDOWN_REASON + nsISelectionListener::DRAG_REASON);
     if (aContinueSelection &&
         AdjustForMaintainedSelection(aNewFocus, aContentOffset))
       return NS_OK; //shift clicked to maintained selection. rejected.
 
-    return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, aContinueSelection, aMultipleSelection);
+    return TakeFocus(aNewFocus, aContentOffset, aContentEndOffset, HINT(aHint),
+                     aContinueSelection, aMultipleSelection);
   }
   
   return NS_OK;
 }
 
 void
 nsFrameSelection::HandleDrag(nsIFrame *aFrame, nsPoint aPoint)
 {
@@ -1919,16 +1916,17 @@ nsFrameSelection::StopAutoScrollTimer()
 
 /**
 hard to go from nodes to frames, easy the other way!
  */
 nsresult
 nsFrameSelection::TakeFocus(nsIContent *aNewFocus,
                             PRUint32    aContentOffset,
                             PRUint32    aContentEndOffset,
+                            HINT        aHint,
                             PRBool      aContinueSelection,
                             PRBool      aMultipleSelection)
 {
   if (!aNewFocus)
     return NS_ERROR_NULL_POINTER;
 
   NS_ENSURE_STATE(mShell);
 
@@ -1942,20 +1940,22 @@ nsFrameSelection::TakeFocus(nsIContent *
   mEndSelectedCell = nsnull;
   mAppendStartSelectedCell = nsnull;
 
   //HACKHACKHACK
   if (!aNewFocus->GetParent())
     return NS_ERROR_FAILURE;
   //END HACKHACKHACK /checking for root frames/content
 
+  mHint = aHint;
+  
   PRInt8 index = GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
   nsCOMPtr<nsIDOMNode> domNode = do_QueryInterface(aNewFocus);
   //traverse through document and unselect crap here
-  if (!aContinueSelection){ //single click? setting cursor down
+  if (!aContinueSelection) {//single click? setting cursor down
     PRUint32 batching = mBatching;//hack to use the collapse code.
     PRBool changes = mChangesDuringBatching;
     mBatching = 1;
 
     if (aMultipleSelection){
       nsCOMPtr<nsIDOMRange> newRange;
       NS_NewRange(getter_AddRefs(newRange));
 
@@ -2384,17 +2384,17 @@ nsFrameSelection::SelectAll()
     if (!doc)
       return NS_ERROR_FAILURE;
     rootContent = doc->GetRootContent();
     if (!rootContent)
       return NS_ERROR_FAILURE;
   }
   PRInt32 numChildren = rootContent->GetChildCount();
   PostReason(nsISelectionListener::NO_REASON);
-  return TakeFocus(rootContent, 0, numChildren, PR_FALSE, PR_FALSE);
+  return TakeFocus(rootContent, 0, numChildren, HINTLEFT, PR_FALSE, PR_FALSE);
 }
 
 //////////END FRAMESELECTION
 
 void
 nsFrameSelection::StartBatchChanges()
 {
   mBatching++;
@@ -3431,17 +3431,17 @@ nsFrameSelection::SetAncestorLimiter(nsI
   if (mAncestorLimiter != aLimiter) {
     mAncestorLimiter = aLimiter;
     PRInt8 index =
       GetIndexFromSelectionType(nsISelectionController::SELECTION_NORMAL);
     if (!IsValidSelectionPoint(this, mDomSelections[index]->FetchFocusNode())) {
       ClearNormalSelection();
       if (mAncestorLimiter) {
         PostReason(nsISelectionListener::NO_REASON);
-        TakeFocus(mAncestorLimiter, 0, 0, PR_FALSE, PR_FALSE);
+        TakeFocus(mAncestorLimiter, 0, 0, HINTLEFT, PR_FALSE, PR_FALSE);
       }
     }
   }
 }
 
 //END nsFrameSelection methods