Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / widget / src / cocoa / nsChildView.h
blobf6ad2d203587ffda284f08c681a32846f1519415
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
15 * The Original Code is mozilla.org code.
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998
20 * the Initial Developer. All Rights Reserved.
22 * Contributor(s):
23 * Thomas K. Dyas <tdyas@zecador.org>
25 * Alternatively, the contents of this file may be used under the terms of
26 * either the GNU General Public License Version 2 or later (the "GPL"), or
27 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 * in which case the provisions of the GPL or the LGPL are applicable instead
29 * of those above. If you wish to allow use of your version of this file only
30 * under the terms of either the GPL or the LGPL, and not to allow others to
31 * use your version of this file under the terms of the MPL, indicate your
32 * decision by deleting the provisions above and replace them with the notice
33 * and other provisions required by the GPL or the LGPL. If you do not delete
34 * the provisions above, a recipient may use your version of this file under
35 * the terms of any one of the MPL, the GPL or the LGPL.
37 * ***** END LICENSE BLOCK ***** */
39 #ifndef nsChildView_h_
40 #define nsChildView_h_
42 // formal protocols
43 #include "mozView.h"
44 #ifdef ACCESSIBILITY
45 #include "nsIAccessible.h"
46 #include "mozAccessibleProtocol.h"
47 #endif
49 #include "nsAutoPtr.h"
50 #include "nsISupports.h"
51 #include "nsBaseWidget.h"
52 #include "nsIPluginInstanceOwner.h"
53 #include "nsIPluginWidget.h"
54 #include "nsIScrollableView.h"
55 #include "nsWeakPtr.h"
57 #include "nsIWidget.h"
58 #include "nsIAppShell.h"
60 #include "nsIEventListener.h"
61 #include "nsString.h"
62 #include "nsIDragService.h"
64 #include "nsplugindefs.h"
66 #import <Carbon/Carbon.h>
67 #import <Cocoa/Cocoa.h>
69 class gfxASurface;
70 class nsChildView;
71 union nsPluginPort;
73 enum {
74 // Currently focused ChildView (while this TSM document is active).
75 // Transient (only set while TSMProcessRawKeyEvent() is processing a key
76 // event), and the ChildView will be retained and released around the call
77 // to TSMProcessRawKeyEvent() -- so it can be weak.
78 kFocusedChildViewTSMDocPropertyTag = 'GKFV', // type ChildView* [WEAK]
81 // Undocumented HIToolbox function used by WebKit to allow Carbon-based IME
82 // to work in a Cocoa-based browser (like Safari or Cocoa-widgets Firefox).
83 // (Recent WebKit versions actually use a thin wrapper around this function
84 // called WKSendKeyEventToTSM().)
86 // Calling TSMProcessRawKeyEvent() from ChildView's keyDown: and keyUp:
87 // methods (when the ChildView is a plugin view) bypasses Cocoa's IME
88 // infrastructure and (instead) causes Carbon TSM events to be sent on each
89 // NSKeyDown event. We install a Carbon event handler
90 // (PluginKeyEventsHandler()) to catch these events and pass them to Gecko
91 // (which in turn passes them to the plugin).
92 extern "C" long TSMProcessRawKeyEvent(EventRef carbonEvent);
94 @interface NSEvent (Undocumented)
96 // Return Cocoa event's corresponding Carbon event. Not initialized (on
97 // synthetic events) until the OS actually "sends" the event. This method
98 // has been present in the same form since at least OS X 10.2.8.
99 - (EventRef)_eventRef;
101 @end
103 // Needed to support pixel scrolling.
104 // See http://developer.apple.com/qa/qa2005/qa1453.html.
105 // kEventMouseScroll is only defined on 10.5+. Using the moz prefix avoids
106 // potential symbol conflicts.
107 // This should be changed when 10.4 support is dropped.
108 enum {
109 mozkEventMouseScroll = 11
112 // Support for pixel scroll deltas, not part of NSEvent.h
113 // See http://lists.apple.com/archives/cocoa-dev/2007/Feb/msg00050.html
114 @interface NSEvent (DeviceDelta)
115 - (float)deviceDeltaX;
116 - (float)deviceDeltaY;
117 @end
119 @interface ChildView : NSView<
120 #ifdef ACCESSIBILITY
121 mozAccessible,
122 #endif
123 mozView, NSTextInput>
125 @private
126 NSWindow* mWindow; // shortcut to the top window, [WEAK]
128 // the nsChildView that created the view. It retains this NSView, so
129 // the link back to it must be weak.
130 nsChildView* mGeckoChild;
132 // Whether we're a plugin view.
133 BOOL mIsPluginView;
135 // The following variables are only valid during key down event processing.
136 // Their current usage needs to be fixed to avoid problems with nested event
137 // loops that can confuse them. Once a variable is set during key down event
138 // processing, if an event spawns a nested event loop the previously set value
139 // will be wiped out.
140 NSEvent* mCurKeyEvent;
141 PRBool mKeyDownHandled;
142 // While we process key down events we need to keep track of whether or not
143 // we sent a key press event. This helps us make sure we do send one
144 // eventually.
145 BOOL mKeyPressSent;
146 // Valid when mKeyPressSent is true.
147 PRBool mKeyPressHandled;
149 // needed for NSTextInput implementation
150 NSRange mMarkedRange;
152 BOOL mInHandScroll; // true for as long as we are hand scrolling
153 // hand scroll locations
154 NSPoint mHandScrollStartMouseLoc;
155 nscoord mHandScrollStartScrollX, mHandScrollStartScrollY;
157 // when mouseDown: is called, we store its event here (strong)
158 NSEvent* mLastMouseDownEvent;
160 // rects that were invalidated during a draw, so have pending drawing
161 NSMutableArray* mPendingDirtyRects;
162 BOOL mPendingFullDisplay;
164 // All views are always opaque (non-transparent). The only exception is when we're
165 // the content view in a transparent XUL window.
166 BOOL mIsTransparent;
167 PRIntervalTime mLastShadowInvalidation;
168 BOOL mNeedsShadowInvalidation;
170 // Holds our drag service across multiple drag calls. The reference to the
171 // service is obtained when the mouse enters the view and is released when
172 // the mouse exits or there is a drop. This prevents us from having to
173 // re-establish the connection to the service manager many times per second
174 // when handling |draggingUpdated:| messages.
175 nsIDragService* mDragService;
177 // For use with plugins, so that we can support IME in them. We can't use
178 // Cocoa TSM documents (those created and managed by the NSTSMInputContext
179 // class) -- for some reason TSMProcessRawKeyEvent() doesn't work with them.
180 TSMDocumentID mPluginTSMDoc;
182 // Simple gestures support
184 // mGestureState is used to detect when Cocoa has called both
185 // magnifyWithEvent and rotateWithEvent within the same
186 // beginGestureWithEvent and endGestureWithEvent sequence. We
187 // discard the spurious gesture event so as not to confuse Gecko.
189 // mCumulativeMagnification keeps track of the total amount of
190 // magnification peformed during a magnify gesture so that we can
191 // send that value with the final MozMagnifyGesture event.
193 // mCumulativeRotation keeps track of the total amount of rotation
194 // performed during a rotate gesture so we can send that value with
195 // the final MozRotateGesture event.
196 enum {
197 eGestureState_None,
198 eGestureState_StartGesture,
199 eGestureState_MagnifyGesture,
200 eGestureState_RotateGesture
201 } mGestureState;
202 float mCumulativeMagnification;
203 float mCumulativeRotation;
206 // class initialization
207 + (void)initialize;
209 // these are sent to the first responder when the window key status changes
210 - (void)viewsWindowDidBecomeKey;
211 - (void)viewsWindowDidResignKey;
213 // Stop NSView hierarchy being changed during [ChildView drawRect:]
214 - (void)delayedTearDown;
216 - (void)setTransparent:(BOOL)transparent;
218 - (void)sendFocusEvent:(PRUint32)eventType;
220 - (void) processPluginKeyEvent:(EventRef)aKeyEvent;
222 // Simple gestures support
224 // XXX - The swipeWithEvent, beginGestureWithEvent, magnifyWithEvent,
225 // rotateWithEvent, and endGestureWithEvent methods are part of a
226 // PRIVATE interface exported by nsResponder and reverse-engineering
227 // was necessary to obtain the methods' prototypes. Thus, Apple may
228 // change the interface in the future without notice.
230 // The prototypes were obtained from the following link:
231 // http://cocoadex.com/2008/02/nsevent-modifications-swipe-ro.html
232 - (void)swipeWithEvent:(NSEvent *)anEvent;
233 - (void)beginGestureWithEvent:(NSEvent *)anEvent;
234 - (void)magnifyWithEvent:(NSEvent *)anEvent;
235 - (void)rotateWithEvent:(NSEvent *)anEvent;
236 - (void)endGestureWithEvent:(NSEvent *)anEvent;
237 @end
241 //-------------------------------------------------------------------------
243 // nsTSMManager
245 //-------------------------------------------------------------------------
247 class nsTSMManager {
248 public:
249 static PRBool IsComposing() { return sComposingView ? PR_TRUE : PR_FALSE; }
250 static PRBool IsIMEEnabled() { return sIsIMEEnabled; }
251 static PRBool IgnoreCommit() { return sIgnoreCommit; }
253 static void OnDestroyView(NSView<mozView>* aDestroyingView);
255 // Note that we cannot get the actual state in TSM. But we can trust this
256 // value. Because nsIMEStateManager reset this at every focus changing.
257 static PRBool IsRomanKeyboardsOnly() { return sIsRomanKeyboardsOnly; }
259 static PRBool GetIMEOpenState();
261 static void InitTSMDocument(NSView<mozView>* aViewForCaret);
262 static void StartComposing(NSView<mozView>* aComposingView);
263 static void UpdateComposing(NSString* aComposingString);
264 static void EndComposing();
265 static void EnableIME(PRBool aEnable);
266 static void SetIMEOpenState(PRBool aOpen);
267 static void SetRomanKeyboardsOnly(PRBool aRomanOnly);
269 static void CommitIME();
270 static void CancelIME();
271 private:
272 static PRBool sIsIMEEnabled;
273 static PRBool sIsRomanKeyboardsOnly;
274 static PRBool sIgnoreCommit;
275 static NSView<mozView>* sComposingView;
276 static TSMDocumentID sDocumentID;
277 static NSString* sComposingString;
279 static void KillComposing();
282 //-------------------------------------------------------------------------
284 // nsChildView
286 //-------------------------------------------------------------------------
288 class nsChildView : public nsBaseWidget,
289 public nsIPluginWidget
291 private:
292 typedef nsBaseWidget Inherited;
294 public:
295 nsChildView();
296 virtual ~nsChildView();
298 NS_DECL_ISUPPORTS_INHERITED
300 // nsIWidget interface
301 NS_IMETHOD Create(nsIWidget *aParent,
302 const nsRect &aRect,
303 EVENT_CALLBACK aHandleEventFunction,
304 nsIDeviceContext *aContext,
305 nsIAppShell *aAppShell = nsnull,
306 nsIToolkit *aToolkit = nsnull,
307 nsWidgetInitData *aInitData = nsnull);
308 NS_IMETHOD Create(nsNativeWidget aNativeParent,
309 const nsRect &aRect,
310 EVENT_CALLBACK aHandleEventFunction,
311 nsIDeviceContext *aContext,
312 nsIAppShell *aAppShell = nsnull,
313 nsIToolkit *aToolkit = nsnull,
314 nsWidgetInitData *aInitData = nsnull);
316 // Utility method for implementing both Create(nsIWidget ...) and
317 // Create(nsNativeWidget...)
319 virtual nsresult StandardCreate(nsIWidget *aParent,
320 const nsRect &aRect,
321 EVENT_CALLBACK aHandleEventFunction,
322 nsIDeviceContext *aContext,
323 nsIAppShell *aAppShell,
324 nsIToolkit *aToolkit,
325 nsWidgetInitData *aInitData,
326 nsNativeWidget aNativeParent = nsnull);
328 NS_IMETHOD Destroy();
330 NS_IMETHOD Show(PRBool aState);
331 NS_IMETHOD IsVisible(PRBool& outState);
333 NS_IMETHOD SetParent(nsIWidget* aNewParent);
334 virtual nsIWidget* GetParent(void);
336 NS_IMETHOD ModalEventFilter(PRBool aRealEvent, void *aEvent,
337 PRBool *aForWindow);
339 NS_IMETHOD ConstrainPosition(PRBool aAllowSlop,
340 PRInt32 *aX, PRInt32 *aY);
341 NS_IMETHOD Move(PRInt32 aX, PRInt32 aY);
342 NS_IMETHOD Resize(PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
343 NS_IMETHOD Resize(PRInt32 aX, PRInt32 aY,PRInt32 aWidth,PRInt32 aHeight, PRBool aRepaint);
345 NS_IMETHOD Enable(PRBool aState);
346 NS_IMETHOD IsEnabled(PRBool *aState);
347 NS_IMETHOD SetFocus(PRBool aRaise);
348 NS_IMETHOD SetBounds(const nsRect &aRect);
349 NS_IMETHOD GetBounds(nsRect &aRect);
351 NS_IMETHOD Invalidate(PRBool aIsSynchronous);
352 NS_IMETHOD Invalidate(const nsRect &aRect,PRBool aIsSynchronous);
353 NS_IMETHOD InvalidateRegion(const nsIRegion *aRegion, PRBool aIsSynchronous);
354 NS_IMETHOD Validate();
356 virtual void* GetNativeData(PRUint32 aDataType);
357 NS_IMETHOD SetColorMap(nsColorMap *aColorMap);
358 NS_IMETHOD Scroll(PRInt32 aDx, PRInt32 aDy, nsRect *aClipRect);
359 NS_IMETHOD WidgetToScreen(const nsRect& aOldRect, nsRect& aNewRect);
360 NS_IMETHOD ScreenToWidget(const nsRect& aOldRect, nsRect& aNewRect);
361 NS_IMETHOD BeginResizingChildren(void);
362 NS_IMETHOD EndResizingChildren(void);
363 virtual PRBool ShowsResizeIndicator(nsIntRect* aResizerRect);
365 static PRBool ConvertStatus(nsEventStatus aStatus)
366 { return aStatus == nsEventStatus_eConsumeNoDefault; }
367 NS_IMETHOD DispatchEvent(nsGUIEvent* event, nsEventStatus & aStatus);
369 NS_IMETHOD Update();
371 virtual void ConvertToDeviceCoordinates(nscoord &aX, nscoord &aY);
372 void LocalToWindowCoordinate(nsPoint& aPoint) { ConvertToDeviceCoordinates(aPoint.x, aPoint.y); }
373 void LocalToWindowCoordinate(nscoord& aX, nscoord& aY) { ConvertToDeviceCoordinates(aX, aY); }
374 void LocalToWindowCoordinate(nsRect& aRect) { ConvertToDeviceCoordinates(aRect.x, aRect.y); }
376 NS_IMETHOD SetMenuBar(void* aMenuBar);
377 NS_IMETHOD ShowMenuBar(PRBool aShow);
379 NS_IMETHOD GetPreferredSize(PRInt32& aWidth, PRInt32& aHeight);
380 NS_IMETHOD SetPreferredSize(PRInt32 aWidth, PRInt32 aHeight);
382 NS_IMETHOD SetCursor(nsCursor aCursor);
383 NS_IMETHOD SetCursor(imgIContainer* aCursor, PRUint32 aHotspotX, PRUint32 aHotspotY);
385 NS_IMETHOD CaptureRollupEvents(nsIRollupListener * aListener, PRBool aDoCapture, PRBool aConsumeRollupEvent);
386 NS_IMETHOD SetTitle(const nsAString& title);
388 NS_IMETHOD GetAttention(PRInt32 aCycleCount);
390 NS_IMETHOD ActivateNativeMenuItemAt(const nsAString& indexString);
391 NS_IMETHOD ForceUpdateNativeMenuAt(const nsAString& indexString);
393 NS_IMETHOD ResetInputState();
394 NS_IMETHOD SetIMEOpenState(PRBool aState);
395 NS_IMETHOD GetIMEOpenState(PRBool* aState);
396 NS_IMETHOD SetIMEEnabled(PRUint32 aState);
397 NS_IMETHOD GetIMEEnabled(PRUint32* aState);
398 NS_IMETHOD CancelIMEComposition();
399 NS_IMETHOD GetToggledKeyState(PRUint32 aKeyCode,
400 PRBool* aLEDState);
402 // nsIPluginWidget
403 NS_IMETHOD GetPluginClipRect(nsRect& outClipRect, nsPoint& outOrigin, PRBool& outWidgetVisible);
404 NS_IMETHOD StartDrawPlugin();
405 NS_IMETHOD EndDrawPlugin();
406 NS_IMETHOD SetPluginInstanceOwner(nsIPluginInstanceOwner* aInstanceOwner);
408 virtual nsTransparencyMode GetTransparencyMode();
409 virtual void SetTransparencyMode(nsTransparencyMode aMode);
410 NS_IMETHOD SetWindowShadowStyle(PRInt32 aStyle);
412 // Mac specific methods
413 virtual PRBool PointInWidget(Point aThePoint);
415 virtual PRBool DispatchWindowEvent(nsGUIEvent& event);
417 void LiveResizeStarted();
418 void LiveResizeEnded();
420 #ifdef ACCESSIBILITY
421 void GetDocumentAccessible(nsIAccessible** aAccessible);
422 #endif
424 virtual gfxASurface* GetThebesSurface();
426 NS_IMETHOD BeginSecureKeyboardInput();
427 NS_IMETHOD EndSecureKeyboardInput();
429 void HidePlugin();
431 protected:
433 PRBool ReportDestroyEvent();
434 PRBool ReportMoveEvent();
435 PRBool ReportSizeEvent();
437 NS_IMETHOD CalcOffset(PRInt32 &aX,PRInt32 &aY);
439 virtual PRBool OnPaint(nsPaintEvent & aEvent);
441 // override to create different kinds of child views. Autoreleases, so
442 // caller must retain.
443 virtual NSView* CreateCocoaView(NSRect inFrame);
444 void TearDownView();
446 virtual nsresult SynthesizeNativeKeyEvent(PRInt32 aNativeKeyboardLayout,
447 PRInt32 aNativeKeyCode,
448 PRUint32 aModifierFlags,
449 const nsAString& aCharacters,
450 const nsAString& aUnmodifiedCharacters);
452 protected:
454 NSView<mozView>* mView; // my parallel cocoa view (ChildView or NativeScrollbarView), [STRONG]
456 NSView<mozView>* mParentView;
457 nsIWidget* mParentWidget;
459 #ifdef ACCESSIBILITY
460 // weak ref to this childview's associated mozAccessible for speed reasons
461 // (we get queried for it *a lot* but don't want to own it)
462 nsWeakPtr mAccessible;
463 #endif
465 nsRefPtr<gfxASurface> mTempThebesSurface;
467 PRPackedBool mVisible;
468 PRPackedBool mDrawing;
469 PRPackedBool mLiveResizeInProgress;
470 PRPackedBool mIsPluginView; // true if this is a plugin view
471 PRPackedBool mPluginDrawing;
472 PRPackedBool mPluginIsCG; // true if this is a CoreGraphics plugin
474 PRPackedBool mInSetFocus;
476 nsPluginPort mPluginPort;
477 nsIPluginInstanceOwner* mPluginInstanceOwner; // [WEAK]
480 void NS_InstallPluginKeyEventsHandler();
481 void NS_RemovePluginKeyEventsHandler();
483 #endif // nsChildView_h_