Back to index

lightning-sunbird  0.9+nobinonly
Public Member Functions | Protected Member Functions | Private Member Functions
CTextInputEventHandler Class Reference

#include <CTextInputEventHandler.h>

List of all members.

Public Member Functions

 CTextInputEventHandler ()
virtual ~CTextInputEventHandler ()
virtual OSStatus HandleAll (EventHandlerCallRef inHandlerCallRef, EventRef inEvent)

Protected Member Functions

virtual OSStatus HandleUnicodeForKeyEvent (CBrowserShell *aBrwoserShell, EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
virtual OSStatus HandleUpdateActiveInputArea (CBrowserShell *sink, EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
virtual OSStatus HandleOffsetToPos (CBrowserShell *aBrwoserShell, EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
virtual OSStatus HandlePosToOffset (CBrowserShell *aBrwoserShell, EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
virtual OSStatus HandleGetSelectedText (CBrowserShell *aBrwoserShell, EventHandlerCallRef inHandlerCallRef, EventRef inEvent)
virtual CBrowserShellGetGeckoTarget ()

Private Member Functions

OSStatus GetText (EventRef inEvent, nsString &outString)
OSStatus GetScriptLang (EventRef inEvent, ScriptLanguageRecord &outSlr)

Detailed Description

Definition at line 50 of file CTextInputEventHandler.h.


Constructor & Destructor Documentation

Definition at line 53 of file CTextInputEventHandler.h.

{};
virtual CTextInputEventHandler::~CTextInputEventHandler ( ) [inline, virtual]

Definition at line 54 of file CTextInputEventHandler.h.

{};

Member Function Documentation

Definition at line 59 of file CTextInputEventHandling.cpp.

{
  return dynamic_cast<CBrowserShell*> (LCommander::GetTarget());  
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::GetScriptLang ( EventRef  inEvent,
ScriptLanguageRecord &  outSlr 
) [private]

Definition at line 69 of file CTextInputEventHandling.cpp.

{
  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendSLRec, typeIntlWritingCode, NULL, 
                          sizeof(outSlr), NULL, &outSlr);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::GetText ( EventRef  inEvent,
nsString outString 
) [private]

Definition at line 79 of file CTextInputEventHandling.cpp.

{
  UInt32 neededSize;
  outString.Truncate(0);
  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendText, typeUnicodeText, NULL, 0, &neededSize, NULL);
  if (noErr != err)
    return err;
    
  if (neededSize > 0) 
  {
    nsAutoBuffer<PRUnichar, 256> buf;
    if (! buf.EnsureElemCapacity(neededSize/sizeof(PRUnichar)))
      return eventParameterNotFoundErr;

    err = ::GetEventParameter(inEvent, kEventParamTextInputSendText, typeUnicodeText, NULL, 
                            neededSize, &neededSize, buf.get());
                            
    if (noErr == err) 
       outString.Assign(buf.get(), neededSize/sizeof(PRUnichar));
  }
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandleAll ( EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [virtual]

Definition at line 292 of file CTextInputEventHandling.cpp.

{
  CBrowserShell* aBrowserShell = GetGeckoTarget();
  // if this is not an event for Gecko, just return eventNotHandledErr and let 
  // OS to fallback to class event handling 
  if (!aBrowserShell)
    return eventNotHandledErr;
  
  UInt32 eventClass = ::GetEventClass(inEvent);
  if (eventClass != kEventClassTextInput)
    return eventNotHandledErr;

  UInt32 eventKind = ::GetEventKind(inEvent);
  if ((kEventTextInputUpdateActiveInputArea != eventKind) &&
                  (kEventTextInputUnicodeForKeyEvent!= eventKind) &&
                  (kEventTextInputOffsetToPos != eventKind) &&
                  (kEventTextInputPosToOffset != eventKind) &&
                  (kEventTextInputGetSelectedText != eventKind))
    return eventNotHandledErr;
    
  switch(eventKind)
  {
    case kEventTextInputUpdateActiveInputArea:
      return HandleUpdateActiveInputArea(aBrowserShell, inHandlerCallRef, inEvent);
    case kEventTextInputUnicodeForKeyEvent:
      return HandleUnicodeForKeyEvent(aBrowserShell, inHandlerCallRef, inEvent);
    case kEventTextInputOffsetToPos:
      return HandleOffsetToPos(aBrowserShell, inHandlerCallRef, inEvent);
    case kEventTextInputPosToOffset:
      return HandlePosToOffset(aBrowserShell, inHandlerCallRef, inEvent);
    case kEventTextInputGetSelectedText:
      return HandleGetSelectedText(aBrowserShell, inHandlerCallRef, inEvent);
  }
  return eventNotHandledErr;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandleGetSelectedText ( CBrowserShell aBrwoserShell,
EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [protected, virtual]

Definition at line 208 of file CTextInputEventHandling.cpp.

{
  NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);

  nsAutoString outString;
  OSStatus err = aBrowserShell->HandleGetSelectedText(outString);   
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  err = ::SetEventParameter(inEvent, kEventParamTextInputReplyText, typeUnicodeText,
                          outString.Length()*sizeof(PRUnichar), outString.get());
  return err; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandleOffsetToPos ( CBrowserShell aBrwoserShell,
EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [protected, virtual]

Definition at line 229 of file CTextInputEventHandling.cpp.

{
  NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
  PRUint32 offset;
  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendTextOffset, typeLongInteger, NULL, 
                          sizeof(offset), NULL, &offset);
  if (noErr != err)
    return eventParameterNotFoundErr;

  Point thePoint;
  // printf("call HandleOffsetToPos offset = %d\n", offset);
  err = aBrowserShell->HandleOffsetToPos(offset, &thePoint.h, &thePoint.v);   
  // printf("return %d, %d\n", thePoint.v, thePoint.h);                          
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  err = ::SetEventParameter(inEvent, kEventParamTextInputReplyPoint, typeQDPoint,
                          sizeof(thePoint), &thePoint);
  return err; 
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandlePosToOffset ( CBrowserShell aBrwoserShell,
EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [protected, virtual]

Definition at line 257 of file CTextInputEventHandling.cpp.

{
  NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
  PRInt32 offset;
  Point thePoint;
  short regionClass;

  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendCurrentPoint, typeQDPoint, NULL, 
                                   sizeof(thePoint), NULL, &thePoint);
  if (noErr != err)
    return eventParameterNotFoundErr;

  // printf("call HandlePosToOffset Point = %d, %d\n", thePoint.h, thePoint.v);
  err = aBrowserShell->HandlePosToOffset(thePoint.h, thePoint.v, &offset, &regionClass);
  // printf("return offset = %d, region = %d\n", offset, regionClass);                          
  if (noErr != err)
    return eventParameterNotFoundErr;

  err = ::SetEventParameter(inEvent, kEventParamTextInputReplyRegionClass, typeShortInteger,
                          sizeof(regionClass), &regionClass);
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  err = ::SetEventParameter(inEvent, kEventParamTextInputReplyTextOffset, typeLongInteger,
                          sizeof(offset), &offset);
  return err;   
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandleUnicodeForKeyEvent ( CBrowserShell aBrwoserShell,
EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [protected, virtual]

Definition at line 108 of file CTextInputEventHandling.cpp.

{
  NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
  EventRef keyboardEvent;
  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendKeyboardEvent, typeEventRef, NULL, 
                          sizeof(keyboardEvent), NULL, &keyboardEvent);
  
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  // Check first to see if the key event is a cmd-key or control-key.
  // If so, return eventNotHandledErr, and the keydown event will end
  // up being handled by LEventDispatcher::EventKeyDown() which is the
  // standard PowerPlant handling.
  UInt32 keyModifiers;  
  err = ::GetEventParameter(keyboardEvent, kEventParamKeyModifiers, typeUInt32,
        NULL, sizeof(UInt32), NULL, &keyModifiers);
  if ((noErr == err) && (keyModifiers & (cmdKey | controlKey)))
    return eventNotHandledErr;
    
  EventRecord eventRecord;                        
                       
  if (! ::ConvertEventRefToEventRecord(keyboardEvent, &eventRecord))
    return eventParameterNotFoundErr;
  // printf("uk1- %d %d %d %d %d\n", eventRecord.what, eventRecord.message, eventRecord.when, eventRecord.where, eventRecord.modifiers);

  ScriptLanguageRecord slr;
  err = GetScriptLang(inEvent, slr);
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  nsAutoString text;
  err = GetText(inEvent, text);
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  // printf("call HandleUnicodeForKeyEvent textlength = %d script=%d language=%d\n",  text.Length(), slr.fScript, slr.fLanguage);
  err = aBrowserShell->HandleUnicodeForKeyEvent(text, slr.fScript, slr.fLanguage, &eventRecord);
  // printf("err = %d\n", err);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:

OSStatus CTextInputEventHandler::HandleUpdateActiveInputArea ( CBrowserShell sink,
EventHandlerCallRef  inHandlerCallRef,
EventRef  inEvent 
) [protected, virtual]

Definition at line 157 of file CTextInputEventHandling.cpp.

{
  NS_ENSURE_TRUE(aBrowserShell, eventNotHandledErr);
  PRUint32 fixLength;
  OSStatus err = ::GetEventParameter(inEvent, kEventParamTextInputSendFixLen, typeLongInteger, NULL, 
                          sizeof(fixLength), NULL, &fixLength);
  if (noErr != err)
    return eventParameterNotFoundErr;

  ScriptLanguageRecord slr;
  err = GetScriptLang(inEvent, slr);
  if (noErr != err)
    return eventParameterNotFoundErr;
  
  nsAutoString text;
  err = GetText(inEvent, text);
   if (noErr != err)
    return eventParameterNotFoundErr;

  // kEventParamTextInputSendHiliteRng is optional parameter, don't return if we cannot get it.
  
  TextRangeArray* hiliteRng = nsnull;                        
  UInt32 rngSize=0;   
  err = ::GetEventParameter(inEvent, kEventParamTextInputSendHiliteRng, typeTextRangeArray, NULL, 
                          0, NULL, &rngSize);
  if (noErr == err)  
  {
    TextRangeArray* pt = (TextRangeArray*)::malloc(rngSize);
    NS_WARN_IF_FALSE( (pt), "Cannot malloc for hiliteRng") ; 
    if (pt)
    { 
      hiliteRng = pt;
      err = ::GetEventParameter(inEvent, kEventParamTextInputSendHiliteRng, typeTextRangeArray, NULL, 
                              rngSize, &rngSize, hiliteRng);
      NS_WARN_IF_FALSE( (noErr == err), "Cannot get hiliteRng") ; 
    }                          
  }                     
  // printf("call HandleUpdateActiveInputArea textlength = %d ",text.Length());
  // printf("script=%d language=%d fixlen=%d\n", slr.fScript, slr.fLanguage, fixLength / 2);
  err = aBrowserShell->HandleUpdateActiveInputArea(text, slr.fScript, slr.fLanguage,
                                          fixLength / sizeof(PRUnichar), hiliteRng);
  if (hiliteRng)
     ::free(hiliteRng);
  return err;
}

Here is the call graph for this function:

Here is the caller graph for this function:


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