Back to index

lightning-sunbird  0.9+nobinonly
mozXMLTermListeners.cpp
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is XMLterm.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Ramalingam Saravanan.
00018  * Portions created by the Initial Developer are Copyright (C) 1999
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Pierre Phaneuf <pp@ludusdesign.com>
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 // mozXMLTermListeners.cpp: implementation of classes in mozXMLTermListeners.h
00039 
00040 #include "nsIServiceManager.h"
00041 
00042 #include "mozXMLT.h"
00043 #include "mozXMLTermUtils.h"
00044 #include "mozXMLTermListeners.h"
00045 
00046 #include "nsIDOMKeyEvent.h"
00047 #include "nsIDOMMouseEvent.h"
00048 #include "nsIDOMNSUIEvent.h"
00049 #include "nsIPrivateTextEvent.h"
00050 #include "nsIPresShell.h"
00051 #include "nsISelectionController.h"
00052 
00054 // mozXMLTermKeyListener factory
00056 
00057 nsresult 
00058 NS_NewXMLTermKeyListener(nsIDOMEventListener ** aInstancePtrResult, 
00059                          mozIXMLTerminal *aXMLTerminal)
00060 {
00061   mozXMLTermKeyListener* listener = new mozXMLTermKeyListener();
00062   if (listener == nsnull) {
00063     return NS_ERROR_OUT_OF_MEMORY;
00064   }
00065 
00066   // Save non-owning reference to embedding XMLTerminal object
00067   listener->SetXMLTerminal(aXMLTerminal);
00068 
00069   return listener->QueryInterface(NS_GET_IID(nsIDOMEventListener),
00070                                   (void **) aInstancePtrResult);
00071 }
00072 
00073 nsresult 
00074 NS_NewXMLTermTextListener(nsIDOMEventListener ** aInstancePtrResult, 
00075                          mozIXMLTerminal *aXMLTerminal)
00076 {
00077   mozXMLTermTextListener* listener = new mozXMLTermTextListener();
00078   if (listener == nsnull) {
00079     return NS_ERROR_OUT_OF_MEMORY;
00080   }
00081 
00082   // Save non-owning reference to embedding XMLTerminal object
00083   listener->SetXMLTerminal(aXMLTerminal);
00084 
00085   return listener->QueryInterface(NS_GET_IID(nsIDOMEventListener),
00086                                   (void **) aInstancePtrResult);
00087 }
00088 
00089 nsresult 
00090 NS_NewXMLTermMouseListener(nsIDOMEventListener ** aInstancePtrResult, 
00091                          mozIXMLTerminal *aXMLTerminal)
00092 {
00093   mozXMLTermMouseListener* listener = new mozXMLTermMouseListener();
00094   if (listener == nsnull) {
00095     return NS_ERROR_OUT_OF_MEMORY;
00096   }
00097 
00098   // Save non-owning reference to embedding XMLTerminal object
00099   listener->SetXMLTerminal(aXMLTerminal);
00100 
00101   return listener->QueryInterface(NS_GET_IID(nsIDOMEventListener),
00102                                   (void **) aInstancePtrResult);
00103 }
00104 
00105 nsresult 
00106 NS_NewXMLTermDragListener(nsIDOMEventListener ** aInstancePtrResult, 
00107                          mozIXMLTerminal *aXMLTerminal)
00108 {
00109   mozXMLTermDragListener* listener = new mozXMLTermDragListener();
00110   if (listener == nsnull) {
00111     return NS_ERROR_OUT_OF_MEMORY;
00112   }
00113 
00114   // Save non-owning reference to embedding XMLTerminal object
00115   listener->SetXMLTerminal(aXMLTerminal);
00116 
00117   return listener->QueryInterface(NS_GET_IID(nsIDOMEventListener),
00118                                   (void **) aInstancePtrResult);
00119 }
00120 
00122 // mozXMLTermKeyListener implementation
00124 
00125 mozXMLTermKeyListener::mozXMLTermKeyListener() :
00126   mXMLTerminal(nsnull),
00127   mSuspend(PR_FALSE)
00128 {
00129 }
00130 
00131 
00132 mozXMLTermKeyListener::~mozXMLTermKeyListener() 
00133 {
00134 }
00135 
00136 
00137 NS_IMPL_ADDREF(mozXMLTermKeyListener)
00138 
00139 NS_IMPL_RELEASE(mozXMLTermKeyListener)
00140 
00141 
00142 NS_IMETHODIMP
00143 mozXMLTermKeyListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
00144 {
00145   if (aInstancePtr == NULL) {
00146     return NS_ERROR_NULL_POINTER;
00147   }
00148 
00149   // Always NULL result, in case of failure
00150   *aInstancePtr = NULL;
00151 
00152   if (aIID.Equals(NS_GET_IID(nsISupports))) {
00153     *aInstancePtr = NS_STATIC_CAST(nsISupports*,
00154                                    NS_STATIC_CAST(nsIDOMKeyListener*,this));
00155 
00156   } else if (aIID.Equals(NS_GET_IID(nsIDOMEventListener))) {
00157     *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
00158 
00159   } else if (aIID.Equals(NS_GET_IID(nsIDOMKeyListener))) {
00160     *aInstancePtr = NS_STATIC_CAST(nsIDOMKeyListener*,this);
00161 
00162   } else if (aIID.Equals(NS_GET_IID(mozIXMLTermSuspend))) {
00163     *aInstancePtr = NS_STATIC_CAST(mozIXMLTermSuspend*,this);
00164 
00165   } else {
00166     return NS_ERROR_NO_INTERFACE;
00167   }
00168 
00169   NS_ADDREF_THIS();
00170 
00171   return NS_OK;
00172 }
00173 
00174 
00175 NS_IMETHODIMP mozXMLTermKeyListener::GetSuspend(PRBool* aSuspend)
00176 {
00177   if (!*aSuspend)
00178     return NS_ERROR_NULL_POINTER;
00179   *aSuspend = mSuspend;
00180   return NS_OK;
00181 }
00182 
00183 
00184 NS_IMETHODIMP mozXMLTermKeyListener::SetSuspend(const PRBool aSuspend)
00185 {
00186   XMLT_LOG(mozXMLTermKeyListener::SetSuspend,50,("aSuspend=0x%x\n",
00187                                                  aSuspend));
00188   mSuspend = aSuspend;
00189   return NS_OK;
00190 }
00191 
00192 // Individual key handlers return NS_OK to indicate NOT consumed
00193 // by default, an error is returned indicating event is consumed
00194 
00195 NS_IMETHODIMP
00196 mozXMLTermKeyListener::HandleEvent(nsIDOMEvent* aEvent)
00197 {
00198   return NS_OK;
00199 }
00200 
00201 
00202 // Process KeyDown events (handles control/alt modified key events)
00203 NS_IMETHODIMP
00204 mozXMLTermKeyListener::KeyDown(nsIDOMEvent* aKeyEvent)
00205 {
00206   nsCOMPtr<nsIDOMKeyEvent> keyEvent;
00207   keyEvent = do_QueryInterface(aKeyEvent);
00208   if (!keyEvent) {
00209     // Non-key event passed to keydown, do not consume it
00210     return NS_OK;
00211   }
00212 
00213   PRBool shiftKey, ctrlKey, altKey;
00214   PRUint32 keyCode;
00215 
00216   XMLT_LOG(mozXMLTermKeyListener::KeyDown,50,("mSuspend=0x%x\n",
00217                                                mSuspend));
00218 
00219   if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) && 
00220       NS_SUCCEEDED(keyEvent->GetShiftKey(&shiftKey)) &&
00221       NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
00222       NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {
00223 
00224     XMLT_LOG(mozXMLTermKeyListener::KeyDown,52,
00225           ("code=0x%x, shift=%d, ctrl=%d, alt=%d\n",
00226            keyCode, shiftKey, ctrlKey, altKey));
00227   }
00228 
00229   // Consume key down event
00230   return NS_ERROR_BASE;
00231 }
00232 
00233 
00234 NS_IMETHODIMP
00235 mozXMLTermKeyListener::KeyUp(nsIDOMEvent* aKeyEvent)
00236 {
00237   return NS_OK;
00238 }
00239 
00240 
00241 // Handle KeyPress events (non control/alt modified key events)
00242 NS_IMETHODIMP
00243 mozXMLTermKeyListener::KeyPress(nsIDOMEvent* aKeyEvent)
00244 {
00245   nsresult result;
00246 
00247   XMLT_LOG(mozXMLTermKeyListener::KeyPress,50,("mSuspend=0x%x\n",
00248                                                mSuspend));
00249 
00250   nsCOMPtr<nsIDOMKeyEvent> keyEvent;
00251   keyEvent = do_QueryInterface(aKeyEvent);
00252   if (!keyEvent) {
00253     // Non-key event passed to keydown, do not consume it
00254     return NS_OK;
00255   }
00256 
00257 #if 0  // Debugging
00258   nsCOMPtr<nsIPresShell> presShell;
00259   result = mXMLTerminal->GetPresShell(getter_AddRefs(presShell));
00260   if (NS_SUCCEEDED(result) && presShell) {
00261     nsCOMPtr<nsISelection> selection;
00262     result = presShell->GetSelection(SELECTION_NORMAL,
00263                                      getter_AddRefs(selection));
00264     if (NS_SUCCEEDED(result) && selection) {
00265       nsCOMPtr<nsIDOMNode> childNode, parentNode;
00266       result = selection->GetFocusNode(getter_AddRefs(childNode));
00267       if (NS_SUCCEEDED(result) && childNode) {
00268         PRInt32 j;
00269         nsAutoString nodeName;
00270         for (j=0; (j<6) && childNode; j++) {
00271           result = childNode->GetParentNode(getter_AddRefs(parentNode));
00272           if (NS_SUCCEEDED(result) && parentNode) {
00273             result = parentNode->GetNodeName(nodeName);
00274             if (NS_SUCCEEDED(result)) {
00275               NS_ConvertUTF16toUTF8 CNodeName(nodeName);
00276               XMLT_LOG(mozXMLTermKeyListener::KeyPress,58,("nodeName=%s\n",
00277                                               CNodeName.get()));
00278             }
00279             childNode = parentNode;
00280           } else {
00281             childNode = nsnull;
00282           }
00283         }
00284       }
00285     }
00286   }
00287 #endif
00288 
00289   PRUint32 keyCode;
00290   PRBool shiftKey, ctrlKey, altKey;
00291   if (NS_SUCCEEDED(keyEvent->GetKeyCode(&keyCode)) && 
00292       NS_SUCCEEDED(keyEvent->GetShiftKey(&shiftKey)) &&
00293       NS_SUCCEEDED(keyEvent->GetCtrlKey(&ctrlKey)) &&
00294       NS_SUCCEEDED(keyEvent->GetAltKey(&altKey)) ) {
00295 
00296     PRUint32 keyChar = 0;
00297     PRUint32 escPrefix = 0;
00298     nsAutoString JSCommand; JSCommand.SetLength(0);
00299 
00300     PRBool screenMode = 0;
00301     result = mXMLTerminal->GetScreenMode(&screenMode);
00302 
00303     result = keyEvent->GetCharCode(&keyChar);
00304 
00305     XMLT_LOG(mozXMLTermKeyListener::KeyPress,52,
00306           ("code=0x%x, char=0x%x, shift=%d, ctrl=%d, alt=%d, screenMode=%d\n",
00307            keyCode, keyChar, shiftKey, ctrlKey, altKey, screenMode));
00308 
00309     if (keyChar == 0) {
00310       // Key that hasn't been mapped to a character code
00311 
00312       switch (keyCode) {
00313       case nsIDOMKeyEvent::DOM_VK_SHIFT:
00314       case nsIDOMKeyEvent::DOM_VK_CONTROL:
00315       case nsIDOMKeyEvent::DOM_VK_ALT:
00316         break;                         // ignore modifier key event
00317       case nsIDOMKeyEvent::DOM_VK_BACK_SPACE:
00318         keyChar = U_BACKSPACE;
00319         break;
00320       case nsIDOMKeyEvent::DOM_VK_DELETE:
00321         keyChar = U_DEL;
00322         break;
00323       case nsIDOMKeyEvent::DOM_VK_TAB:
00324         keyChar = U_TAB;
00325         break;
00326       case nsIDOMKeyEvent::DOM_VK_RETURN:
00327         keyChar = U_CRETURN;
00328         break;
00329       case nsIDOMKeyEvent::DOM_VK_UP:
00330         escPrefix = 1;
00331         keyChar = U_A_CHAR;
00332         break;
00333       case nsIDOMKeyEvent::DOM_VK_DOWN:
00334         escPrefix = 1;
00335         keyChar = U_B_CHAR;
00336         break;
00337       case nsIDOMKeyEvent::DOM_VK_RIGHT:
00338         escPrefix = 1;
00339         keyChar = U_C_CHAR;
00340         break;
00341       case nsIDOMKeyEvent::DOM_VK_LEFT:
00342         escPrefix = 1;
00343         keyChar = U_D_CHAR;
00344         break;
00345       case nsIDOMKeyEvent::DOM_VK_ESCAPE:
00346         keyChar = U_ESCAPE;
00347         break;
00348       case nsIDOMKeyEvent::DOM_VK_HOME:
00349         JSCommand.AssignLiteral("ScrollHomeKey");
00350         break;
00351       case nsIDOMKeyEvent::DOM_VK_END:
00352         JSCommand.AssignLiteral("ScrollEndKey");
00353         break;
00354       case nsIDOMKeyEvent::DOM_VK_PAGE_UP:
00355         JSCommand.AssignLiteral("ScrollPageUpKey");
00356         break;
00357       case nsIDOMKeyEvent::DOM_VK_PAGE_DOWN:
00358         JSCommand.AssignLiteral("ScrollPageDownKey");
00359         break;
00360       case nsIDOMKeyEvent::DOM_VK_F1:
00361         JSCommand.AssignLiteral("F1Key");
00362         break;
00363       case nsIDOMKeyEvent::DOM_VK_F2:
00364         JSCommand.AssignLiteral("F2Key");
00365         break;
00366       case nsIDOMKeyEvent::DOM_VK_F3:
00367         JSCommand.AssignLiteral("F3Key");
00368         break;
00369       case nsIDOMKeyEvent::DOM_VK_F4:
00370         JSCommand.AssignLiteral("F4Key");
00371         break;
00372       case nsIDOMKeyEvent::DOM_VK_F5:
00373         JSCommand.AssignLiteral("F5Key");
00374         break;
00375       case nsIDOMKeyEvent::DOM_VK_F6:
00376         JSCommand.AssignLiteral("F6Key");
00377         break;
00378       case nsIDOMKeyEvent::DOM_VK_F7:
00379         JSCommand.AssignLiteral("F7Key");
00380         break;
00381       case nsIDOMKeyEvent::DOM_VK_F8:
00382         JSCommand.AssignLiteral("F8Key");
00383         break;
00384       case nsIDOMKeyEvent::DOM_VK_F9:
00385         JSCommand.AssignLiteral("F9Key");
00386         break;
00387       default: 
00388         if ( (ctrlKey && (keyCode ==nsIDOMKeyEvent::DOM_VK_SPACE)) ||
00389              (ctrlKey && shiftKey && (keyCode ==nsIDOMKeyEvent::DOM_VK_2)) ) {
00390           // Hack to handle input of NUL characters in NUL-terminated strings
00391           // See also: mozLineTerm::Write
00392           keyChar = U_PRIVATE0;
00393         } else {
00394           // ignore event without consuming
00395           return NS_OK;
00396         }
00397       }
00398 
00399     } else if ((ctrlKey == PR_TRUE) && (altKey == PR_FALSE) &&
00400                (keyChar >= 0x40U) && (keyChar < 0x80U)) {
00401       // Control character, without Alt; adjust character code
00402       // Is this portable?
00403       keyChar = (keyChar >= 0x60U) ? keyChar-0x60U : keyChar-0x40U;
00404     }
00405 
00406     XMLT_LOG(mozXMLTermKeyListener::KeyPress,53,
00407              ("escPrefix=%d, keyChar=0x%x, \n", escPrefix, keyChar));
00408 
00409     if (!JSCommand.IsEmpty()) {
00410       // Execute JS command
00411       nsCOMPtr<nsIDOMDocument> domDocument;
00412       result = mXMLTerminal->GetDocument(getter_AddRefs(domDocument));
00413 
00414       if (NS_SUCCEEDED(result) && domDocument) {
00415         nsAutoString JSInput = JSCommand;
00416         nsAutoString JSOutput; JSOutput.SetLength(0);
00417         JSInput.AppendLiteral("(");
00418         JSInput.AppendInt(shiftKey,10);
00419         JSInput.AppendLiteral(",");
00420         JSInput.AppendInt(ctrlKey,10);
00421         JSInput.Append(NS_LITERAL_STRING(");"));
00422         result = mozXMLTermUtils::ExecuteScript(domDocument,
00423                                                 JSInput,
00424                                                 JSOutput);
00425       }
00426     }
00427 
00428     if (!mSuspend && (keyChar > 0) && (keyChar <= 0xFFFDU)) {
00429       // Transmit valid non-null Unicode character
00430       nsAutoString keyString; keyString.SetLength(0);
00431       if (escPrefix) {
00432         keyString.Append((PRUnichar) U_ESCAPE);
00433         keyString.Append((PRUnichar) U_LBRACKET);
00434       }
00435 
00436       keyString.Append((PRUnichar) keyChar);
00437 
00438       result = mXMLTerminal->SendTextAux(keyString.get());
00439     }
00440   }
00441 
00442   // Consume key press event
00443   return NS_ERROR_BASE;
00444 }
00445 
00446 
00448 // mozXMLTermTextListener implementation
00450 
00451 mozXMLTermTextListener::mozXMLTermTextListener()
00452 {
00453 }
00454 
00455 
00456 mozXMLTermTextListener::~mozXMLTermTextListener() 
00457 {
00458 }
00459 
00460 
00461 NS_IMPL_ADDREF(mozXMLTermTextListener)
00462 
00463 NS_IMPL_RELEASE(mozXMLTermTextListener)
00464 
00465 
00466 NS_IMETHODIMP
00467 mozXMLTermTextListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
00468 {
00469   if (aInstancePtr == NULL) {
00470     return NS_ERROR_NULL_POINTER;
00471   }
00472 
00473   // Always NULL result, in case of failure
00474   *aInstancePtr = NULL;
00475 
00476   if (aIID.Equals(NS_GET_IID(nsISupports))) {
00477     *aInstancePtr = NS_STATIC_CAST(nsISupports*,
00478                                    NS_STATIC_CAST(nsIDOMTextListener*,this));
00479 
00480   } else if (aIID.Equals(NS_GET_IID(nsIDOMEventListener))) {
00481     *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
00482 
00483   } else if (aIID.Equals(NS_GET_IID(nsIDOMTextListener))) {
00484     *aInstancePtr = NS_STATIC_CAST(nsIDOMTextListener*,this);
00485 
00486   } else {
00487     return NS_ERROR_NO_INTERFACE;
00488   }
00489 
00490   NS_ADDREF_THIS();
00491 
00492   return NS_OK;
00493 }
00494 
00495 
00496 NS_IMETHODIMP
00497 mozXMLTermTextListener::HandleEvent(nsIDOMEvent* aEvent)
00498 {
00499   return NS_OK;
00500 }
00501 
00502 
00503 NS_IMETHODIMP
00504 mozXMLTermTextListener::HandleText(nsIDOMEvent* aTextEvent)
00505 {
00506   nsCOMPtr<nsIPrivateTextEvent> textEvent (do_QueryInterface(aTextEvent));
00507   if (!textEvent) {
00508     // Soft failure
00509     return NS_OK;
00510   }
00511 
00512   XMLT_LOG(mozXMLTermTextListener::HandleText,50,("\n"));
00513 
00514   nsAutoString textStr;
00515   textEvent->GetText(textStr);
00516 
00517   // Transmit text to terminal
00518   mXMLTerminal->SendTextAux(textStr.get());
00519 
00520   return NS_OK;
00521 }
00522 
00523 
00525 // mozXMLTermMouseListener implementation
00527 
00528 mozXMLTermMouseListener::mozXMLTermMouseListener()
00529 {
00530 }
00531 
00532 
00533 mozXMLTermMouseListener::~mozXMLTermMouseListener() 
00534 {
00535 }
00536 
00537 
00538 NS_IMPL_ADDREF(mozXMLTermMouseListener)
00539 
00540 NS_IMPL_RELEASE(mozXMLTermMouseListener)
00541 
00542 
00543 NS_IMETHODIMP
00544 mozXMLTermMouseListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
00545 {
00546   if (aInstancePtr == NULL) {
00547     return NS_ERROR_NULL_POINTER;
00548   }
00549 
00550   // Always NULL result, in case of failure
00551   *aInstancePtr = NULL;
00552 
00553   if (aIID.Equals(NS_GET_IID(nsISupports))) {
00554     *aInstancePtr = NS_STATIC_CAST(nsISupports*,
00555                                    NS_STATIC_CAST(nsIDOMMouseListener*,this));
00556 
00557   } else if (aIID.Equals(NS_GET_IID(nsIDOMEventListener))) {
00558     *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
00559 
00560   } else if (aIID.Equals(NS_GET_IID(nsIDOMMouseListener))) {
00561     *aInstancePtr = NS_STATIC_CAST(nsIDOMMouseListener*,this);
00562 
00563   } else {
00564     return NS_ERROR_NO_INTERFACE;
00565   }
00566 
00567   NS_ADDREF_THIS();
00568 
00569   return NS_OK;
00570 }
00571 
00572 
00573 NS_IMETHODIMP
00574 mozXMLTermMouseListener::HandleEvent(nsIDOMEvent* aEvent)
00575 {
00576   return NS_OK;
00577 }
00578 
00579 
00580 NS_IMETHODIMP
00581 mozXMLTermMouseListener::MouseDown(nsIDOMEvent* aMouseEvent)
00582 {
00583   if (!aMouseEvent)
00584     return NS_OK;
00585 
00586   nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
00587   mouseEvent = do_QueryInterface(aMouseEvent);
00588   if (!mouseEvent) {
00589     // Non-mouse event passed; do not consume it
00590     return NS_OK;
00591   }
00592 
00593   PRUint16 buttonCode = (PRUint16)-1;
00594   mouseEvent->GetButton(&buttonCode);
00595 
00596   XMLT_LOG(mozXMLTermMouseListener::MouseDown,50,("buttonCode=%d\n",
00597                                                   buttonCode));
00598 
00599   if (buttonCode == 1) {
00600     // Middle-mouse button pressed; initiate paste
00601     mXMLTerminal->Paste();
00602   }
00603 
00604   return NS_OK;
00605 }
00606 
00607 
00608 NS_IMETHODIMP
00609 mozXMLTermMouseListener::MouseUp(nsIDOMEvent* aMouseEvent)
00610 {
00611   return NS_OK;
00612 }
00613 
00614 
00615 NS_IMETHODIMP
00616 mozXMLTermMouseListener::MouseClick(nsIDOMEvent* aMouseEvent)
00617 {
00618   nsresult result;
00619 
00620   if (!aMouseEvent)
00621     return NS_OK;
00622 
00623   nsCOMPtr<nsIDOMMouseEvent> mouseEvent;
00624   mouseEvent = do_QueryInterface(aMouseEvent);
00625   if (!mouseEvent) {
00626     // Non-mouse event passed; do not consume it
00627     return NS_OK;
00628   }
00629 
00630   PRUint16 buttonCode = (PRUint16)-1;
00631   mouseEvent->GetButton(&buttonCode);
00632 
00633   PRInt32 screenX, screenY;
00634   result = mouseEvent->GetScreenX(&screenX);
00635   result = mouseEvent->GetScreenY(&screenY);
00636 
00637   XMLT_LOG(mozXMLTermMouseListener::MouseClick,50, ("buttonCode=%d\n",
00638                                                     buttonCode));
00639 
00640 #if 0
00641   // NO MORE NEED FOR THIS WORKAROUND!
00642   // Without this workaround, clicking on the xmlterm window to give it
00643   // focus fails position the cursor at the end of the last line
00644   // (For some reason, the MouseDown event causes the cursor to be positioned
00645   // in the line above the location of the mouse click
00646 
00647   // Get selection
00648   nsCOMPtr<nsIPresShell> presShell;
00649   result = mXMLTerminal->GetPresShell(getter_AddRefs(presShell));
00650   if (NS_FAILED(result) || !presShell)
00651     return NS_OK; // Do not consume mouse event
00652   nsCOMPtr<nsISelectionController> selCon;
00653   selCon = do_QueryInterface(presShell);
00654   if (!selCon)
00655     return NS_ERROR_FAILURE;
00656   nsCOMPtr<nsISelection> selection;
00657   result = selCon->GetSelection(nsISelectionController::SELECTION_NORMAL,
00658                                      getter_AddRefs(selection));
00659 
00660   if (NS_FAILED(result) || !selection)
00661     return NS_OK; // Do not consume mouse event
00662 
00663   PRBool isCollapsed;
00664   result = selection->GetIsCollapsed(&isCollapsed);
00665   if (NS_FAILED(result))
00666     return NS_OK; // Do not consume mouse event
00667 
00668   XMLT_LOG(mozXMLTermMouseListener::MouseClick,50, ("isCollapsed=%d\n",
00669                                                     isCollapsed));
00670 
00671   // If non-collapsed selection, do not collapse it
00672   if (!isCollapsed)
00673     return NS_OK;
00674 
00675   // Locate selection range
00676   nsCOMPtr<nsIDOMNSUIEvent> uiEvent (do_QueryInterface(mouseEvent));
00677   if (!uiEvent)
00678     return NS_OK; // Do not consume mouse event
00679 
00680   nsCOMPtr<nsIDOMNode> parentNode;
00681   result = uiEvent->GetRangeParent(getter_AddRefs(parentNode));
00682   if (NS_FAILED(result) || !parentNode)
00683     return NS_OK; // Do not consume mouse event
00684 
00685   PRInt32 offset = 0;
00686   result = uiEvent->GetRangeOffset(&offset);
00687   if (NS_FAILED(result))
00688     return NS_OK; // Do not consume mouse event
00689 
00690   (void)selection->Collapse(parentNode, offset);
00691 #endif
00692 
00693   return NS_OK; // Do not consume mouse event
00694 }
00695 
00696 
00697 NS_IMETHODIMP
00698 mozXMLTermMouseListener::MouseDblClick(nsIDOMEvent* aMouseEvent)
00699 {
00700   return NS_OK;
00701 }
00702 
00703 
00704 NS_IMETHODIMP
00705 mozXMLTermMouseListener::MouseOver(nsIDOMEvent* aMouseEvent)
00706 {
00707   return NS_OK;
00708 }
00709 
00710 
00711 NS_IMETHODIMP
00712 mozXMLTermMouseListener::MouseOut(nsIDOMEvent* aMouseEvent)
00713 {
00714   return NS_OK;
00715 }
00716 
00717 
00719 // mozXMLTermDragListener implementation
00721 
00722 mozXMLTermDragListener::mozXMLTermDragListener()
00723 {
00724 }
00725 
00726 
00727 mozXMLTermDragListener::~mozXMLTermDragListener() 
00728 {
00729 }
00730 
00731 
00732 NS_IMPL_ADDREF(mozXMLTermDragListener)
00733 
00734 NS_IMPL_RELEASE(mozXMLTermDragListener)
00735 
00736 
00737 NS_IMETHODIMP
00738 mozXMLTermDragListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
00739 {
00740   if (aInstancePtr == NULL) {
00741     return NS_ERROR_NULL_POINTER;
00742   }
00743 
00744   // Always NULL result, in case of failure
00745   *aInstancePtr = NULL;
00746 
00747   if (aIID.Equals(NS_GET_IID(nsISupports))) {
00748     *aInstancePtr = NS_STATIC_CAST(nsISupports*,
00749                                    NS_STATIC_CAST(nsIDOMDragListener*,this));
00750 
00751   } else if (aIID.Equals(NS_GET_IID(nsIDOMEventListener))) {
00752     *aInstancePtr = NS_STATIC_CAST(nsIDOMEventListener*,this);
00753 
00754   } else if (aIID.Equals(NS_GET_IID(nsIDOMDragListener))) {
00755     *aInstancePtr = NS_STATIC_CAST(nsIDOMDragListener*,this);
00756 
00757   } else {
00758     return NS_ERROR_NO_INTERFACE;
00759   }
00760 
00761   NS_ADDREF_THIS();
00762 
00763   return NS_OK;
00764 }
00765 
00766 
00767 NS_IMETHODIMP
00768 mozXMLTermDragListener::HandleEvent(nsIDOMEvent* aEvent)
00769 {
00770   return NS_OK;
00771 }
00772 
00773 
00774 NS_IMETHODIMP
00775 mozXMLTermDragListener::DragEnter(nsIDOMEvent* aDragEvent)
00776 {
00777   return NS_OK;
00778 }
00779 
00780 
00781 NS_IMETHODIMP
00782 mozXMLTermDragListener::DragOver(nsIDOMEvent* aDragEvent)
00783 {
00784   return NS_OK;
00785 }
00786 
00787 
00788 NS_IMETHODIMP
00789 mozXMLTermDragListener::DragExit(nsIDOMEvent* aDragEvent)
00790 {
00791   return NS_OK;
00792 }
00793 
00794 
00795 NS_IMETHODIMP
00796 mozXMLTermDragListener::DragDrop(nsIDOMEvent* aDragEvent)
00797 {
00798   return NS_OK;
00799 }
00800 
00801 
00802 NS_IMETHODIMP
00803 mozXMLTermDragListener::DragGesture(nsIDOMEvent* aDragEvent)
00804 {
00805   return NS_OK;
00806 }