Back to index

lightning-sunbird  0.9+nobinonly
nsCaret.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either of the GNU General Public License Version 2 or later (the "GPL"),
00027  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  * ***** END LICENSE BLOCK ***** */
00038 
00039 
00040 #include "nsCoord.h"
00041 #include "nsISelectionListener.h"
00042 #include "nsIRenderingContext.h"
00043 #include "nsITimer.h"
00044 #include "nsICaret.h"
00045 #include "nsWeakPtr.h"
00046 #ifdef IBMBIDI
00047 #include "nsIBidiKeyboard.h"
00048 #endif
00049 
00050 class nsIView;
00051 
00052 //-----------------------------------------------------------------------------
00053 
00054 class nsCaret : public nsICaret,
00055                 public nsISelectionListener
00056 {
00057   public:
00058 
00059                   nsCaret();
00060     virtual       ~nsCaret();
00061         
00062     NS_DECL_ISUPPORTS
00063 
00064   public:
00065   
00066     // nsICaret interface
00067     NS_IMETHOD    Init(nsIPresShell *inPresShell);
00068     NS_IMETHOD    Terminate();
00069 
00070     NS_IMETHOD    GetCaretDOMSelection(nsISelection **outDOMSel);
00071     NS_IMETHOD    SetCaretDOMSelection(nsISelection *inDOMSel);
00072     NS_IMETHOD    GetCaretVisible(PRBool *outMakeVisible);
00073     NS_IMETHOD    SetCaretVisible(PRBool intMakeVisible);
00074     NS_IMETHOD    SetCaretReadOnly(PRBool inMakeReadonly);
00075     NS_IMETHOD    GetCaretCoordinates(EViewCoordinates aRelativeToType, nsISelection *inDOMSel, nsRect* outCoordinates, PRBool* outIsCollapsed, nsIView **outView);
00076     NS_IMETHOD    EraseCaret();
00077 
00078     NS_IMETHOD    SetVisibilityDuringSelection(PRBool aVisibility);
00079     NS_IMETHOD    DrawAtPosition(nsIDOMNode* aNode, PRInt32 aOffset);
00080 
00081     //nsISelectionListener interface
00082     NS_DECL_NSISELECTIONLISTENER
00083                               
00084     static void   CaretBlinkCallback(nsITimer *aTimer, void *aClosure);
00085   
00086     NS_IMETHOD    GetCaretFrameForNodeOffset (nsIContent* aContentNode, PRInt32 aOffset, nsIFrameSelection::HINT aFrameHint, PRUint8 aBidiLevel,
00087                                               nsIFrame** aReturnFrame, PRInt32* aReturnOffset);
00088   protected:
00089 
00090     void          KillTimer();
00091     nsresult      PrimeTimer();
00092     
00093     nsresult      StartBlinking();
00094     nsresult      StopBlinking();
00095     
00096     void          GetViewForRendering(nsIFrame *caretFrame, EViewCoordinates coordType, nsPoint &viewOffset, nsRect& outClipRect, nsIView **outRenderingView, nsIView **outRelativeView);
00097     PRBool        DrawAtPositionWithHint(nsIDOMNode* aNode, PRInt32 aOffset, nsIFrameSelection::HINT aFrameHint, PRUint8 aBidiLevel);
00098     PRBool        MustDrawCaret();
00099     void          DrawCaret();
00100     void          GetCaretRectAndInvert(nsIFrame* aFrame, PRInt32 aFrameOffset);
00101     void          ToggleDrawnStatus() {   mDrawn = !mDrawn; }
00102 
00103 protected:
00104 
00105     nsWeakPtr             mPresShell;
00106     nsWeakPtr             mDomSelectionWeak;
00107 
00108     nsCOMPtr<nsITimer>              mBlinkTimer;
00109     nsCOMPtr<nsIRenderingContext>   mRendContext;
00110 
00111     PRUint32              mBlinkRate;         // time for one cyle (off then on), in milliseconds
00112 
00113     nscoord               mCaretTwipsWidth;   // caret width in twips. this gets calculated laziiy
00114     nscoord               mBidiIndicatorTwipsSize;   // width and height of bidi indicator
00115 
00116     PRPackedBool          mVisible;           // is the caret blinking
00117     PRPackedBool          mDrawn;             // this should be mutable
00118     PRPackedBool          mReadOnly;          // it the caret in readonly state (draws differently)      
00119     PRPackedBool          mShowDuringSelection; // show when text is selected
00120 
00121     nsRect                mCaretRect;         // the last caret rect
00122     nsIView*              mLastCaretView;     // last view that we used for drawing. Cached so we can tell when we need to make a new RC
00123     nsCOMPtr<nsIContent>  mLastContent;       // store the content the caret was last requested to be drawn in (by DrawAtPosition()/DrawCaret()),
00124                                               // note that this can be different than where it was actually drawn (anon <BR> in text control)
00125     PRInt32               mLastContentOffset; // the offset for the last request
00126     nsIFrameSelection::HINT mLastHint;        // the hint associated with the last request, see also mLastBidiLevel below
00127 #ifdef IBMBIDI
00128     nsRect                mHookRect;          // directional hook on the caret
00129     nsCOMPtr<nsIBidiKeyboard> mBidiKeyboard;  // Bidi keyboard object to set and query keyboard language
00130     PRUint8               mLastBidiLevel;     // saved bidi level of the last draw request, to use when we erase
00131     PRPackedBool          mKeyboardRTL;       // is the keyboard language right-to-left
00132 #endif
00133 };
00134