Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Public Attributes | Protected Types | Protected Member Functions | Protected Attributes
nsComposerCommandsUpdater Class Reference

#include <nsComposerCommandsUpdater.h>

Inheritance diagram for nsComposerCommandsUpdater:
Inheritance graph
[legend]
Collaboration diagram for nsComposerCommandsUpdater:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 nsComposerCommandsUpdater ()
virtual ~nsComposerCommandsUpdater ()
NS_DECL_ISUPPORTS
NS_DECL_NSISELECTIONLISTENER
NS_DECL_NSIDOCUMENTSTATELISTENER
NS_DECL_NSITIMERCALLBACK
NS_IMETHOD 
WillDo (nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt)
 nsITransactionListener interfaces
NS_IMETHOD DidDo (nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aDoResult)
NS_IMETHOD WillUndo (nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt)
NS_IMETHOD DidUndo (nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aUndoResult)
NS_IMETHOD WillRedo (nsITransactionManager *aManager, nsITransaction *aTransaction, PRBool *aInterrupt)
NS_IMETHOD DidRedo (nsITransactionManager *aManager, nsITransaction *aTransaction, nsresult aRedoResult)
NS_IMETHOD WillBeginBatch (nsITransactionManager *aManager, PRBool *aInterrupt)
NS_IMETHOD DidBeginBatch (nsITransactionManager *aManager, nsresult aResult)
NS_IMETHOD WillEndBatch (nsITransactionManager *aManager, PRBool *aInterrupt)
NS_IMETHOD DidEndBatch (nsITransactionManager *aManager, nsresult aResult)
NS_IMETHOD WillMerge (nsITransactionManager *aManager, nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool *aInterrupt)
NS_IMETHOD DidMerge (nsITransactionManager *aManager, nsITransaction *aTopTransaction, nsITransaction *aTransactionToMerge, PRBool aDidMerge, nsresult aMergeResult)
nsresult Init (nsIDOMWindow *aDOMWindow)
void notifySelectionChanged (in nsIDOMDocument doc, in nsISelection sel, in short reason)
void NotifyDocumentCreated ()
void NotifyDocumentWillBeDestroyed ()
void NotifyDocumentStateChanged (in boolean nowDirty)
boolean willDo (in nsITransactionManager aManager, in nsITransaction aTransaction)
 Called before a transaction manager calls a transaction's doTransaction() method.
void didDo (in nsITransactionManager aManager, in nsITransaction aTransaction, in nsresult aDoResult)
 Called after a transaction manager calls the doTransaction() method of a transaction.
boolean willUndo (in nsITransactionManager aManager, in nsITransaction aTransaction)
 Called before a transaction manager calls the Undo() method of a transaction.
void didUndo (in nsITransactionManager aManager, in nsITransaction aTransaction, in nsresult aUndoResult)
 Called after a transaction manager calls the Undo() method of a transaction.
boolean willRedo (in nsITransactionManager aManager, in nsITransaction aTransaction)
 Called before a transaction manager calls the Redo() method of a transaction.
void didRedo (in nsITransactionManager aManager, in nsITransaction aTransaction, in nsresult aRedoResult)
 Called after a transaction manager calls the Redo() method of a transaction.
boolean willBeginBatch (in nsITransactionManager aManager)
 Called before a transaction manager begins a batch.
void didBeginBatch (in nsITransactionManager aManager, in nsresult aResult)
 Called after a transaction manager begins a batch.
boolean willEndBatch (in nsITransactionManager aManager)
 Called before a transaction manager ends a batch.
void didEndBatch (in nsITransactionManager aManager, in nsresult aResult)
 Called after a transaction manager ends a batch.
boolean willMerge (in nsITransactionManager aManager, in nsITransaction aTopTransaction, in nsITransaction aTransactionToMerge)
 Called before a transaction manager tries to merge a transaction, that was just executed, with the transaction at the top of the undo stack.
void didMerge (in nsITransactionManager aManager, in nsITransaction aTopTransaction, in nsITransaction aTransactionToMerge, in boolean aDidMerge, in nsresult aMergeResult)
 Called after a transaction manager tries to merge a transaction, that was just executed, with the transaction at the top of the undo stack.
void notify (in nsITimer timer)

Public Attributes

const short NO_REASON = 0
const short DRAG_REASON = 1
const short MOUSEDOWN_REASON = 2
const short MOUSEUP_REASON = 4
const short KEYPRESS_REASON = 8
const short SELECTALL_REASON = 16

Protected Types

enum  { eStateUninitialized = -1, eStateOff = PR_FALSE, eStateOn = PR_TRUE }

Protected Member Functions

PRBool SelectionIsCollapsed ()
nsresult UpdateDirtyState (PRBool aNowDirty)
nsresult UpdateOneCommand (const char *aCommand)
nsresult UpdateCommandGroup (const nsAString &aCommandGroup)
already_AddRefed
< nsPICommandUpdater
GetCommandUpdater ()
nsresult PrimeUpdateTimer ()
void TimerCallback ()

Protected Attributes

nsCOMPtr< nsITimermUpdateTimer
nsIDOMWindowmDOMWindow
nsWeakPtr mDocShell
PRInt8 mDirtyState
PRInt8 mSelectionCollapsed
PRPackedBool mFirstDoOfFirstUndo

Detailed Description

Definition at line 60 of file nsComposerCommandsUpdater.h.


Member Enumeration Documentation

anonymous enum [protected]
Enumerator:
eStateUninitialized 
eStateOff 
eStateOn 

Definition at line 105 of file nsComposerCommandsUpdater.h.


Constructor & Destructor Documentation

Definition at line 65 of file nsComposerCommandsUpdater.cpp.

{
}

Member Function Documentation

Definition at line 197 of file nsComposerCommandsUpdater.cpp.

{
  return NS_OK;
}

Called after a transaction manager begins a batch.

Parameters:
aManagerthe transaction manager that began a batch.
aResultthe nsresult returned after beginning a batch.
void nsITransactionListener::didDo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction,
in nsresult  aDoResult 
) [inherited]

Called after a transaction manager calls the doTransaction() method of a transaction.

Parameters:
aManagerthe transaction manager that did the transaction.
aTransactionthe transaction that was executed.
aDoResultthe nsresult returned after executing the transaction.

Definition at line 131 of file nsComposerCommandsUpdater.cpp.

{
  // only need to update if the status of the Undo menu item changes.
  PRInt32 undoCount;
  aManager->GetNumberOfUndoItems(&undoCount);
  if (undoCount == 1)
  {
    if (mFirstDoOfFirstUndo)
      UpdateCommandGroup(NS_LITERAL_STRING("undo"));
    mFirstDoOfFirstUndo = PR_FALSE;
  }
       
  return NS_OK;
}

Here is the call graph for this function:

Definition at line 212 of file nsComposerCommandsUpdater.cpp.

{
  return NS_OK;
}

Called after a transaction manager ends a batch.

Parameters:
aManagerthe transaction manager ending a batch.
aResultthe nsresult returned after ending a batch.
NS_IMETHODIMP nsComposerCommandsUpdater::DidMerge ( nsITransactionManager aManager,
nsITransaction aTopTransaction,
nsITransaction aTransactionToMerge,
PRBool  aDidMerge,
nsresult  aMergeResult 
)

Definition at line 229 of file nsComposerCommandsUpdater.cpp.

{
  return NS_OK;
}
void nsITransactionListener::didMerge ( in nsITransactionManager  aManager,
in nsITransaction  aTopTransaction,
in nsITransaction  aTransactionToMerge,
in boolean  aDidMerge,
in nsresult  aMergeResult 
) [inherited]

Called after a transaction manager tries to merge a transaction, that was just executed, with the transaction at the top of the undo stack.

Parameters:
aManagerthe transaction manager ending a batch.
aTopTransactionthe transaction at the top of the undo stack.
aTransactionToMergethe transaction to merge.
aDidMergetrue if transaction was merged, else false.
aMergeResultthe nsresult returned after the merge attempt.
aInterruptlisteners should set this to PR_TRUE if they want to interrupt normal control flow, without throwing an error.

Definition at line 180 of file nsComposerCommandsUpdater.cpp.

Here is the call graph for this function:

void nsITransactionListener::didRedo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction,
in nsresult  aRedoResult 
) [inherited]

Called after a transaction manager calls the Redo() method of a transaction.

Parameters:
aManagerthe transaction manager redoing the transaction.
aTransactionthe transaction being redone.
aRedoResultthe nsresult returned after redoing the transaction.

Definition at line 157 of file nsComposerCommandsUpdater.cpp.

{
  PRInt32 undoCount;
  aManager->GetNumberOfUndoItems(&undoCount);
  if (undoCount == 0)
    mFirstDoOfFirstUndo = PR_TRUE;    // reset the state for the next do

  UpdateCommandGroup(NS_LITERAL_STRING("undo"));
  return NS_OK;
}

Here is the call graph for this function:

void nsITransactionListener::didUndo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction,
in nsresult  aUndoResult 
) [inherited]

Called after a transaction manager calls the Undo() method of a transaction.

Parameters:
aManagerthe transaction manager undoing the transaction.
aTransactionthe transaction being undone.
aUndoResultthe nsresult returned after undoing the transaction.

Definition at line 384 of file nsComposerCommandsUpdater.cpp.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 242 of file nsComposerCommandsUpdater.cpp.

{
  NS_ENSURE_ARG(aDOMWindow);
  mDOMWindow = aDOMWindow;

  nsCOMPtr<nsIScriptGlobalObject> scriptObject(do_QueryInterface(aDOMWindow));
  if (scriptObject)
  {
    mDocShell = do_GetWeakReference(scriptObject->GetDocShell());
  }
  return NS_OK;
}

Here is the call graph for this function:

void nsITimerCallback::notify ( in nsITimer  timer) [inherited]
Parameters:
aTimerthe timer which has expired
void nsISelectionListener::notifySelectionChanged ( in nsIDOMDocument  doc,
in nsISelection  sel,
in short  reason 
) [inherited]

Definition at line 256 of file nsComposerCommandsUpdater.cpp.

{
  if (!mUpdateTimer)
  {
    nsresult rv = NS_OK;
    mUpdateTimer = do_CreateInstance("@mozilla.org/timer;1", &rv);
    if (NS_FAILED(rv)) return rv;
  }

  const PRUint32 kUpdateTimerDelay = 150;
  return mUpdateTimer->InitWithCallback(NS_STATIC_CAST(nsITimerCallback*, this),
                                        kUpdateTimerDelay,
                                        nsITimer::TYPE_ONE_SHOT);
}

Here is the call graph for this function:

Definition at line 366 of file nsComposerCommandsUpdater.cpp.

{
  if (!mDOMWindow) return PR_TRUE;

  nsCOMPtr<nsISelection> domSelection;
  if (NS_SUCCEEDED(mDOMWindow->GetSelection(getter_AddRefs(domSelection))) && domSelection)
  {
    PRBool selectionCollapsed = PR_FALSE;
    domSelection->GetIsCollapsed(&selectionCollapsed);
    return selectionCollapsed;
  }

  NS_WARNING("nsComposerCommandsUpdater::SelectionIsCollapsed - no domSelection");

  return PR_FALSE;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 272 of file nsComposerCommandsUpdater.cpp.

{
  // if the selection state has changed, update stuff
  PRBool isCollapsed = SelectionIsCollapsed();
  if (isCollapsed != mSelectionCollapsed)
  {
    UpdateCommandGroup(NS_LITERAL_STRING("select"));
    mSelectionCollapsed = isCollapsed;
  }
  
  // isn't this redundant with the UpdateCommandGroup above?
  // can we just nuke the above call? or create a meta command group?
  UpdateCommandGroup(NS_LITERAL_STRING("style"));
}

Here is the call graph for this function:

nsresult nsComposerCommandsUpdater::UpdateCommandGroup ( const nsAString &  aCommandGroup) [protected]

Definition at line 301 of file nsComposerCommandsUpdater.cpp.

{
  nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
  if (!commandUpdater) return NS_ERROR_FAILURE;

  
  // This hardcoded list of commands is temporary.
  // This code should use nsIControllerCommandGroup.
  if (aCommandGroup.EqualsLiteral("undo"))
  {
    commandUpdater->CommandStatusChanged("cmd_undo");
    commandUpdater->CommandStatusChanged("cmd_redo");
  }
  else if (aCommandGroup.EqualsLiteral("select") ||
           aCommandGroup.EqualsLiteral("style"))
  {
    commandUpdater->CommandStatusChanged("cmd_bold");
    commandUpdater->CommandStatusChanged("cmd_italic");
    commandUpdater->CommandStatusChanged("cmd_underline");
    commandUpdater->CommandStatusChanged("cmd_tt");

    commandUpdater->CommandStatusChanged("cmd_strikethrough");
    commandUpdater->CommandStatusChanged("cmd_superscript");
    commandUpdater->CommandStatusChanged("cmd_subscript");
    commandUpdater->CommandStatusChanged("cmd_nobreak");

    commandUpdater->CommandStatusChanged("cmd_em");
    commandUpdater->CommandStatusChanged("cmd_strong");
    commandUpdater->CommandStatusChanged("cmd_cite");
    commandUpdater->CommandStatusChanged("cmd_abbr");
    commandUpdater->CommandStatusChanged("cmd_acronym");
    commandUpdater->CommandStatusChanged("cmd_code");
    commandUpdater->CommandStatusChanged("cmd_samp");
    commandUpdater->CommandStatusChanged("cmd_var");
   
    commandUpdater->CommandStatusChanged("cmd_increaseFont");
    commandUpdater->CommandStatusChanged("cmd_decreaseFont");

    commandUpdater->CommandStatusChanged("cmd_paragraphState");
    commandUpdater->CommandStatusChanged("cmd_fontFace");
    commandUpdater->CommandStatusChanged("cmd_fontColor");
    commandUpdater->CommandStatusChanged("cmd_backgroundColor");
    commandUpdater->CommandStatusChanged("cmd_highlight");
  }  
  else if (aCommandGroup.EqualsLiteral("save"))
  {
    // save commands (most are not in C++)
    commandUpdater->CommandStatusChanged("cmd_setDocumentModified");
    commandUpdater->CommandStatusChanged("cmd_save");
  }
  return NS_OK;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 288 of file nsComposerCommandsUpdater.cpp.

{
  if (mDirtyState != aNowDirty)
  {
    UpdateCommandGroup(NS_LITERAL_STRING("save"));
    UpdateCommandGroup(NS_LITERAL_STRING("undo"));
    mDirtyState = aNowDirty;
  }
  
  return NS_OK;  
}

Here is the call graph for this function:

Definition at line 355 of file nsComposerCommandsUpdater.cpp.

{
  nsCOMPtr<nsPICommandUpdater> commandUpdater = GetCommandUpdater();
  if (!commandUpdater) return NS_ERROR_FAILURE;

  commandUpdater->CommandStatusChanged(aCommand);

  return NS_OK;  
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 189 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}

Called before a transaction manager begins a batch.

Parameters:
aManagerthe transaction manager beginning a batch.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error. Note that listeners can also interrupt normal control flow by throwing an nsresult that indicates an error.
boolean nsITransactionListener::willDo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction 
) [inherited]

Called before a transaction manager calls a transaction's doTransaction() method.

Parameters:
aManagerthe transaction manager doing the transaction.
aTransactionthe transaction being executed.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error.
NS_IMETHODIMP nsComposerCommandsUpdater::WillDo ( nsITransactionManager aManager,
nsITransaction aTransaction,
PRBool aInterrupt 
)

nsITransactionListener interfaces

Definition at line 123 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}

Definition at line 204 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}

Called before a transaction manager ends a batch.

Parameters:
aManagerthe transaction manager ending a batch.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error. Note that listeners can also interrupt normal control flow by throwing an nsresult that indicates an error.
NS_IMETHODIMP nsComposerCommandsUpdater::WillMerge ( nsITransactionManager aManager,
nsITransaction aTopTransaction,
nsITransaction aTransactionToMerge,
PRBool aInterrupt 
)

Definition at line 219 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}
boolean nsITransactionListener::willMerge ( in nsITransactionManager  aManager,
in nsITransaction  aTopTransaction,
in nsITransaction  aTransactionToMerge 
) [inherited]

Called before a transaction manager tries to merge a transaction, that was just executed, with the transaction at the top of the undo stack.

Parameters:
aManagerthe transaction manager ending a batch.
aTopTransactionthe transaction at the top of the undo stack.
aTransactionToMergethe transaction to merge.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error. Note that listeners can also interrupt normal control flow by throwing an nsresult that indicates an error.

Definition at line 171 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}
boolean nsITransactionListener::willRedo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction 
) [inherited]

Called before a transaction manager calls the Redo() method of a transaction.

Parameters:
aManagerthe transaction manager redoing the transaction.
aTransactionthe transaction being redone.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error. Note that listeners can also interrupt normal control flow by throwing an nsresult that indicates an error.

Definition at line 148 of file nsComposerCommandsUpdater.cpp.

{
  *aInterrupt = PR_FALSE;
  return NS_OK;
}
boolean nsITransactionListener::willUndo ( in nsITransactionManager  aManager,
in nsITransaction  aTransaction 
) [inherited]

Called before a transaction manager calls the Undo() method of a transaction.

Parameters:
aManagerthe transaction manager undoing the transaction.
aTransactionthe transaction being undone.
Returns:
boolean value returned by listener which indicates it's desire to interrupt normal control flow. Listeners should return true if they want to interrupt normal control flow, without throwing an error. Note that listeners can also interrupt normal control flow by throwing an nsresult that indicates an error.

Member Data Documentation

Definition at line 47 of file nsISelectionListener.idl.

Definition at line 50 of file nsISelectionListener.idl.

Definition at line 124 of file nsComposerCommandsUpdater.h.

Definition at line 123 of file nsComposerCommandsUpdater.h.

Definition at line 122 of file nsComposerCommandsUpdater.h.

Definition at line 126 of file nsComposerCommandsUpdater.h.

Definition at line 48 of file nsISelectionListener.idl.

Definition at line 49 of file nsISelectionListener.idl.

Definition at line 125 of file nsComposerCommandsUpdater.h.

Definition at line 120 of file nsComposerCommandsUpdater.h.

const short nsISelectionListener::NO_REASON = 0 [inherited]

Definition at line 46 of file nsISelectionListener.idl.

Definition at line 51 of file nsISelectionListener.idl.


The documentation for this class was generated from the following files: