From a255586f6a65069d21e7b96cd70e3bcb51f51c4a Mon Sep 17 00:00:00 2001 From: "bryner%netscape.com" Date: Fri, 13 Dec 2002 08:43:18 +0000 Subject: [PATCH] Landing changes from CHIMERA_M1_0_1_BRANCH. Not part of the normal build. --- widget/src/cocoa/Makefile.in | 5 +- widget/src/cocoa/mozView.h | 1 + widget/src/cocoa/nsAppShellCocoa.mm | 1 + widget/src/cocoa/nsChildView.h | 96 +- widget/src/cocoa/nsChildView.mm | 1478 +++++++++++++++++----- widget/src/cocoa/nsClipboard.cpp | 28 +- widget/src/cocoa/nsCocoaWindow.h | 1 + widget/src/cocoa/nsCocoaWindow.mm | 9 +- widget/src/cocoa/nsDragHelperService.cpp | 2 - widget/src/cocoa/nsDragService.cpp | 153 ++- widget/src/cocoa/nsDragService.h | 2 +- widget/src/cocoa/nsFilePicker.cpp | 750 ----------- widget/src/cocoa/nsFilePicker.h | 42 +- widget/src/cocoa/nsFilePicker.mm | 511 ++++++++ widget/src/cocoa/nsLookAndFeel.cpp | 11 +- widget/src/cocoa/nsMimeMapper.cpp | 5 +- widget/src/cocoa/nsNativeScrollbar.mm | 20 +- widget/src/cocoa/nsScrollbar.h | 40 +- widget/src/cocoa/nsScrollbar.mm | 241 ++-- widget/src/cocoa/nsSound.cpp | 6 +- widget/src/cocoa/nsToolkit.h | 18 +- widget/src/cocoa/nsToolkit.mm | 273 ++-- 22 files changed, 2189 insertions(+), 1504 deletions(-) delete mode 100644 widget/src/cocoa/nsFilePicker.cpp create mode 100644 widget/src/cocoa/nsFilePicker.mm diff --git a/widget/src/cocoa/Makefile.in b/widget/src/cocoa/Makefile.in index 8d3cc947e5a8..8ea52a18c091 100644 --- a/widget/src/cocoa/Makefile.in +++ b/widget/src/cocoa/Makefile.in @@ -44,7 +44,7 @@ REQUIRES = xpcom \ nkcache \ locale \ pref \ - appshell \ + exthandler \ intl \ mimetype \ unicharutil \ @@ -57,7 +57,6 @@ EXPORTS = \ GFX_LCPPSRCS = \ nsRegionMac.cpp \ nsWatchTask.cpp \ - nsRepeater.cpp \ $(NULL) @@ -67,7 +66,6 @@ CPPSRCS = \ nsDeleteObserver.cpp \ nsDragService.cpp \ nsDragHelperService.cpp \ - nsFilePicker.cpp \ nsLookAndFeel.cpp \ nsMacResources.cpp \ nsMenuX.cpp \ @@ -80,6 +78,7 @@ CPPSRCS = \ $(NULL) CMMSRCS = \ + nsFilePicker.mm \ nsScrollbar.mm \ nsToolkit.mm \ nsAppShellCocoa.mm \ diff --git a/widget/src/cocoa/mozView.h b/widget/src/cocoa/mozView.h index 3da926ff4334..2f2889544f56 100644 --- a/widget/src/cocoa/mozView.h +++ b/widget/src/cocoa/mozView.h @@ -35,6 +35,7 @@ * * ***** END LICENSE BLOCK ***** */ +#undef DARWIN #import class nsIWidget; diff --git a/widget/src/cocoa/nsAppShellCocoa.mm b/widget/src/cocoa/nsAppShellCocoa.mm index f474de5e745e..8fff7b80dbc9 100644 --- a/widget/src/cocoa/nsAppShellCocoa.mm +++ b/widget/src/cocoa/nsAppShellCocoa.mm @@ -44,6 +44,7 @@ // interface may change, so this comment must be updated accordingly.) // +#undef DARWIN #import #include "nsAppShellCocoa.h" diff --git a/widget/src/cocoa/nsChildView.h b/widget/src/cocoa/nsChildView.h index 7633f3c5f318..77b71973425d 100644 --- a/widget/src/cocoa/nsChildView.h +++ b/widget/src/cocoa/nsChildView.h @@ -41,6 +41,7 @@ #include "nsISupports.h" #include "nsBaseWidget.h" +#include "nsIPluginWidget.h" #include "nsDeleteObserver.h" #include "nsIEventSink.h" @@ -62,12 +63,13 @@ struct nsPluginPort; +#undef DARWIN #import class nsChildView; -@interface ChildView : NSQuickDrawView +@interface ChildView : NSQuickDrawView { NSWindow* mWindow; // shortcut to the top window, [WEAK] @@ -83,25 +85,16 @@ class nsChildView; // Whether we're a plugin view. BOOL mIsPluginView; + BOOL mLastKeyEventWasSentToCocoa; + + NSEvent* mCurEvent; // only valid during a keyDown + + // needed for NSTextInput implementation + NSRange mMarkedRange; + NSRange mSelectedRange; + BOOL mInComposition; } - // sets up our view, attaching it to its owning gecko view -- (id) initWithGeckoChild:(nsChildView*)child eventSink:(nsIEventSink*)sink; - - // convert from one event system to the other for event dispatching -- (void) convert:(NSEvent*)inEvent message:(PRInt32)inMsg toGeckoEvent:(nsInputEvent*)outGeckoEvent; - - // create a gecko key event out of a cocoa event -- (void) convert:(NSEvent*)aKeyEvent message:(PRUint32)aMessage - isChar:(PRBool*)outIsChar - toGeckoEvent:(nsKeyEvent*)outGeckoEvent; -- (void) convert:(NSPoint)inPoint message:(PRInt32)inMsg - modifiers:(unsigned int)inMods toGeckoEvent:(nsInputEvent*)outGeckoEvent; - --(NSMenu*)getContextMenu; - --(void)setIsPluginView:(BOOL)aIsPlugin; - @end @@ -112,7 +105,11 @@ class nsChildView; // //------------------------------------------------------------------------- -class nsChildView : public nsBaseWidget, public nsDeleteObserved, public nsIKBStateControl, public nsIEventSink +class nsChildView : public nsBaseWidget, + public nsDeleteObserved, + public nsIPluginWidget, + public nsIKBStateControl, + public nsIEventSink { private: typedef nsBaseWidget Inherited; @@ -178,8 +175,9 @@ public: virtual nsIFontMetrics* GetFont(void); NS_IMETHOD SetFont(const nsFont &aFont); NS_IMETHOD Invalidate(PRBool aIsSynchronous); - NS_IMETHOD Invalidate(const nsRect &aRect,PRBool aIsSynchronous); - NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous); + NS_IMETHOD Invalidate(const nsRect &aRect,PRBool aIsSynchronous); + NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous); + NS_IMETHOD Validate(); virtual void* GetNativeData(PRUint32 aDataType); NS_IMETHOD SetColorMap(nsColorMap *aColorMap); @@ -190,7 +188,7 @@ public: NS_IMETHOD EndResizingChildren(void); static PRBool ConvertStatus(nsEventStatus aStatus); - NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); + NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus); virtual PRBool DispatchMouseEvent(nsMouseEvent &aEvent); virtual void StartDraw(nsIRenderingContext* aRenderingContext = nsnull); @@ -199,9 +197,9 @@ public: virtual void UpdateWidget(nsRect& aRect, nsIRenderingContext* aContext); virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY); - void LocalToWindowCoordinate(nsPoint& aPoint) { ConvertToDeviceCoordinates(aPoint.x, aPoint.y); } - void LocalToWindowCoordinate(nscoord& aX, nscoord& aY) { ConvertToDeviceCoordinates(aX, aY); } - void LocalToWindowCoordinate(nsRect& aRect) { ConvertToDeviceCoordinates(aRect.x, aRect.y); } + void LocalToWindowCoordinate(nsPoint& aPoint) { ConvertToDeviceCoordinates(aPoint.x, aPoint.y); } + void LocalToWindowCoordinate(nscoord& aX, nscoord& aY) { ConvertToDeviceCoordinates(aX, aY); } + void LocalToWindowCoordinate(nsRect& aRect) { ConvertToDeviceCoordinates(aRect.x, aRect.y); } NS_IMETHOD SetMenuBar(nsIMenuBar * aMenuBar); NS_IMETHOD ShowMenuBar(PRBool aShow); @@ -216,17 +214,28 @@ public: NS_IMETHOD GetAttention(); + // nsIPluginWidget + NS_IMETHOD GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigin); + NS_IMETHOD StartDrawPlugin(); + NS_IMETHOD EndDrawPlugin(); + // Mac specific methods virtual void CalcWindowRegions(); - virtual PRBool PointInWidget(Point aThePoint); + virtual PRBool PointInWidget(Point aThePoint); - virtual PRBool DispatchWindowEvent(nsGUIEvent& event); - virtual PRBool DispatchWindowEvent(nsGUIEvent &event,nsEventStatus &aStatus); + virtual PRBool DispatchWindowEvent(nsGUIEvent& event); + virtual PRBool DispatchWindowEvent(nsGUIEvent &event,nsEventStatus &aStatus); virtual void AcceptFocusOnClick(PRBool aBool) { mAcceptFocusOnClick = aBool;}; PRBool AcceptFocusOnClick() { return mAcceptFocusOnClick;}; void Flash(nsPaintEvent &aEvent); + + void RemovedFromWindow(); + void AddedToWindow(); + void LiveResizeStarted(); + void LiveResizeEnded(); + public: // nsIKBStateControl interface NS_IMETHOD ResetInputState(); @@ -260,23 +269,28 @@ public: const char* gInstanceClassName; #endif - id mView; // my parallel cocoa view, [STRONG] + id mView; // my parallel cocoa view, [STRONG] - NSView* mParentView; + NSView* mParentView; + nsIWidget* mParentWidget; - PRBool mDestroyCalled; - PRBool mDestructorCalled; - PRBool mVisible; + nsIFontMetrics* mFontMetrics; + nsIRenderingContext* mTempRenderingContext; - nsIFontMetrics* mFontMetrics; - - PRBool mDrawing; - nsIRenderingContext* mTempRenderingContext; - PRBool mTempRenderingContextMadeHere; + PRPackedBool mDestroyCalled; + PRPackedBool mDestructorCalled; + PRPackedBool mVisible; + PRPackedBool mInWindow; // true if the widget is in a visible tab + + PRPackedBool mDrawing; + PRPackedBool mTempRenderingContextMadeHere; - nsPluginPort* mPluginPort; - - PRBool mAcceptFocusOnClick; + PRPackedBool mAcceptFocusOnClick; + PRPackedBool mLiveResizeInProgress; + PRPackedBool mPluginDrawing; + + nsPluginPort* mPluginPort; + RgnHandle mVisRgn; }; diff --git a/widget/src/cocoa/nsChildView.mm b/widget/src/cocoa/nsChildView.mm index ceeacba56d6b..a7bbb7b24456 100644 --- a/widget/src/cocoa/nsChildView.mm +++ b/widget/src/cocoa/nsChildView.mm @@ -42,6 +42,7 @@ #include "nsToolkit.h" #include "nsIEnumerator.h" #include "prmem.h" +#include "nsCRT.h" #include #include @@ -63,6 +64,42 @@ #include + +@interface ChildView(Private) + +// sends gecko an ime composition event +- (nsRect) sendCompositionEvent:(PRInt32)aEventType; + +// sends gecko an ime text event +- (void) sendTextEvent:(PRUnichar*) aBuffer + attributedString:(NSAttributedString*) aString + selectedRange:(NSRange)selRange + markedRange:(NSRange)markRange + doCommit:(BOOL)doCommit; + + // sets up our view, attaching it to its owning gecko view +- (id) initWithGeckoChild:(nsChildView*)child eventSink:(nsIEventSink*)sink; + + // convert from one event system to the other for event dispatching +- (void) convert:(NSEvent*)inEvent message:(PRInt32)inMsg toGeckoEvent:(nsInputEvent*)outGeckoEvent; + + // create a gecko key event out of a cocoa event +- (void) convert:(NSEvent*)aKeyEvent message:(PRUint32)aMessage + isChar:(PRBool*)outIsChar + toGeckoEvent:(nsKeyEvent*)outGeckoEvent; +- (void) convert:(NSPoint)inPoint message:(PRInt32)inMsg + modifiers:(unsigned int)inMods toGeckoEvent:(nsInputEvent*)outGeckoEvent; + +- (NSMenu*)getContextMenu; + +- (void)setIsPluginView:(BOOL)aIsPlugin; +- (BOOL)getIsPluginView; + +- (BOOL)childViewHasPlugin; + +@end + + //////////////////////////////////////////////////// nsIRollupListener * gRollupListener = nsnull; nsIWidget * gRollupWidget = nsnull; @@ -86,13 +123,11 @@ static void blinkRgn(RgnHandle rgn); #pragma mark - - // // Convenience routines to go from a gecko rect to cocoa NSRects and back // -static void ConvertGeckoToCocoaRect ( const nsRect & inGeckoRect, NSRect & outCocoaRect ); -static void +static inline void ConvertGeckoToCocoaRect ( const nsRect & inGeckoRect, NSRect & outCocoaRect ) { outCocoaRect.origin.x = inGeckoRect.x; @@ -101,8 +136,7 @@ ConvertGeckoToCocoaRect ( const nsRect & inGeckoRect, NSRect & outCocoaRect ) outCocoaRect.size.height = inGeckoRect.height; } -static void ConvertCocoaToGeckoRect ( const NSRect & inCocoaRect, nsRect & outGeckoRect ) ; -static void +static inline void ConvertCocoaToGeckoRect ( const NSRect & inCocoaRect, nsRect & outGeckoRect ) { outGeckoRect.x = NS_STATIC_CAST(nscoord, inCocoaRect.origin.x); @@ -112,8 +146,7 @@ ConvertCocoaToGeckoRect ( const NSRect & inCocoaRect, nsRect & outGeckoRect ) } -static void ConvertGeckoRectToMacRect(const nsRect& aRect, Rect& outMacRect) ; -static void +static inline void ConvertGeckoRectToMacRect(const nsRect& aRect, Rect& outMacRect) { outMacRect.left = aRect.x; @@ -122,6 +155,89 @@ ConvertGeckoRectToMacRect(const nsRect& aRect, Rect& outMacRect) outMacRect.bottom = aRect.y + aRect.height; } +static PRUint32 underlineAttributeToTextRangeType(PRUint32 aUnderlineStyle) +{ +#ifdef DEBUG_IME + NSLog(@"****in underlineAttributeToTextRangeType = %d", aUnderlineStyle); +#endif + + // For more info on the underline attribute, please see: + // http://developer.apple.com/techpubs/macosx/Cocoa/TasksAndConcepts/ProgrammingTopics/AttributedStrings/Tasks/AccessingAttrs.html + // We are not clear where the define for value 2 is right now. + // To see this value in japanese ime, type 'aaaaaaaaa' and hit space to make the + // ime send you some part of text in 1 (NSSingleUnderlineStyle) and some part in 2. + // ftang will ask apple for more details + // + // it probably means show 1-pixel thickness underline vs 2-pixel thickness + + return aUnderlineStyle ? NS_TEXTRANGE_RAWINPUT : NS_TEXTRANGE_CONVERTEDTEXT; +} + +static PRUint32 countRanges(NSAttributedString *aString) +{ + // Iterate through aString for the NSUnderlineStyleAttributeName and count the + // different segments adjusting limitRange as we go. + PRUint32 count = 0; + NSRange effectiveRange; + NSRange limitRange = NSMakeRange(0, [aString length]); + while (limitRange.length > 0) { + [aString attribute:NSUnderlineStyleAttributeName + atIndex:limitRange.location + longestEffectiveRange:&effectiveRange + inRange:limitRange]; + limitRange = NSMakeRange(NSMaxRange(effectiveRange), + NSMaxRange(limitRange) - NSMaxRange(effectiveRange)); + count++; + } + return count; +} + +static void convertAttributeToGeckoRange(NSAttributedString *aString, NSRange markRange, PRUint32 inCount, nsTextRange* aRanges) +{ + // Convert the Cocoa range into the nsTextRange Array used in Gecko. + // Iterate through the attributed string and map the underline attribute to Gecko IME textrange attributes. + // We may need to change the code here if we change the implementation of validAttributesForMarkedText. + PRUint32 i = 0; + NSRange effectiveRange; + NSRange limitRange = NSMakeRange(0, [aString length]); + while ((limitRange.length > 0) && (i < inCount)) { + id attributeValue = [aString attribute:NSUnderlineStyleAttributeName + atIndex:limitRange.location + longestEffectiveRange:&effectiveRange + inRange:limitRange]; + aRanges[i].mStartOffset = effectiveRange.location; + aRanges[i].mEndOffset = NSMaxRange(effectiveRange); + aRanges[i].mRangeType = underlineAttributeToTextRangeType([attributeValue intValue]); + + // reset the range type if the ranges should be selected + if (markRange.length > 0) { + if (effectiveRange.location == markRange.location + && effectiveRange.length >= markRange.length) { + if (aRanges[i].mRangeType == NS_TEXTRANGE_RAWINPUT) + aRanges[i].mRangeType = NS_TEXTRANGE_SELECTEDRAWTEXT; + else + aRanges[i].mRangeType = NS_TEXTRANGE_SELECTEDCONVERTEDTEXT; + } + } + + limitRange = NSMakeRange(NSMaxRange(effectiveRange), + NSMaxRange(limitRange) - NSMaxRange(effectiveRange)); + i++; + } +} + +static void fillTextRangeInTextEvent(nsTextEvent *aTextEvent, NSAttributedString* aString, NSRange markRange) +{ + // Count the number of segments in the attributed string. Allocate the right size of nsTextRange. + // Convert the attributed string into an array of nsTextRange by calling above functions. + PRUint32 count = countRanges(aString); + aTextEvent->rangeArray = new nsTextRange[count]; + if (aTextEvent->rangeArray) + { + aTextEvent->rangeCount = count; + convertAttributeToGeckoRange(aString, markRange, aTextEvent->rangeCount, aTextEvent->rangeArray); + } +} #pragma mark - @@ -131,26 +247,27 @@ ConvertGeckoRectToMacRect(const nsRect& aRect, Rect& outMacRect) // //------------------------------------------------------------------------- nsChildView::nsChildView() : nsBaseWidget() , nsDeleteObserved(this) +, mView(nsnull) +, mParentView(nsnull) +, mParentWidget(nsnull) +, mFontMetrics(nsnull) +, mTempRenderingContext(nsnull) +, mDestroyCalled(PR_FALSE) +, mDestructorCalled(PR_FALSE) +, mVisible(PR_FALSE) +, mInWindow(PR_FALSE) +, mDrawing(PR_FALSE) +, mTempRenderingContextMadeHere(PR_FALSE) +, mAcceptFocusOnClick(PR_TRUE) +, mLiveResizeInProgress(PR_FALSE) +, mPluginDrawing(PR_FALSE) +, mPluginPort(nsnull) +, mVisRgn(nsnull) { WIDGET_SET_CLASSNAME("nsChildView"); - mView = nil; - - mParentView = nil; - - mDestroyCalled = PR_FALSE; - mDestructorCalled = PR_FALSE; - mVisible = PR_FALSE; - mDrawing = PR_FALSE; - mFontMetrics = nsnull; - mTempRenderingContext = nsnull; - SetBackgroundColor(NS_RGB(255, 255, 255)); SetForegroundColor(NS_RGB(0, 0, 0)); - - mPluginPort = nsnull; - - AcceptFocusOnClick(PR_TRUE); } @@ -180,9 +297,15 @@ nsChildView::~nsChildView() NS_IF_RELEASE(mFontMetrics); delete mPluginPort; + + if (mVisRgn) + { + ::DisposeRgn(mVisRgn); + mVisRgn = nsnull; + } } -NS_IMPL_ISUPPORTS_INHERITED2(nsChildView, nsBaseWidget, nsIKBStateControl, nsIEventSink); +NS_IMPL_ISUPPORTS_INHERITED3(nsChildView, nsBaseWidget, nsIPluginWidget, nsIKBStateControl, nsIEventSink); //------------------------------------------------------------------------- // @@ -216,23 +339,41 @@ nsresult nsChildView::StandardCreate(nsIWidget *aParent, // inherit the top-level window. NS_NATIVE_WIDGET is always a NSView // regardless of if we're asking a window or a view (for compatibility // with windows). - mParentView = (NSView*)aParent->GetNativeData(NS_NATIVE_WIDGET); + mParentView = (NSView*)aParent->GetNativeData(NS_NATIVE_WIDGET); + mParentWidget = aParent; } else mParentView = NS_REINTERPRET_CAST(NSView*,aNativeParent); - - NS_ASSERTION(mParentView, "no parent view at all :("); // create our parallel NSView and hook it up to our parent. Recall // that NS_NATIVE_WIDGET is the NSView. NSRect r; ConvertGeckoToCocoaRect(mBounds, r); mView = [CreateCocoaView() retain]; + if (!mView) return NS_ERROR_FAILURE; + [mView setFrame:r]; - NS_ASSERTION(mParentView && mView, "couldn't hook up new NSView in hierarchy"); - if (mParentView && mView ) { - if (![mParentView isKindOfClass: [ChildView class]]) { +#if DEBUG + // if our parent is a popup window, we're most certainly coming from a