1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2
/* ***** BEGIN LICENSE BLOCK *****
3
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
5
* The contents of this file are subject to the Netscape Public License
6
* Version 1.1 (the "License"); you may not use this file except in
7
* compliance with the License. You may obtain a copy of the License at
8
* http://www.mozilla.org/NPL/
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
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.
24
* Alternatively, the contents of this file may be used under the terms of
25
* either the GNU General Public License Version 2 or later (the "GPL"), or
26
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27
* in which case the provisions of the GPL or the LGPL are applicable instead
28
* of those above. If you wish to allow use of your version of this file only
29
* under the terms of either the GPL or the LGPL, and not to allow others to
30
* use your version of this file under the terms of the NPL, indicate your
31
* decision by deleting the provisions above and replace them with the notice
32
* and other provisions required by the GPL or the LGPL. If you do not delete
33
* the provisions above, a recipient may use your version of this file under
34
* the terms of any one of the NPL, the GPL or the LGPL.
36
* ***** END LICENSE BLOCK ***** */
38
#import "NSString+Utils.h"
39
#import "CHClickListener.h"
41
#include "nsCWebBrowser.h"
42
#include "nsIBaseWindow.h"
43
#include "nsIWebNavigation.h"
44
#include "nsComponentManagerUtils.h"
47
#include "nsIDOMWindow.h"
48
#include "nsPIDOMWindow.h"
49
#include "nsIChromeEventHandler.h"
50
#include "nsIDOMEventReceiver.h"
51
#include "nsIWidget.h"
54
#include "nsIWebBrowserPrint.h"
55
//#include "nsIPrintSettings.h"
57
// Saving of links/images/docs
58
#include "nsIWebBrowserFocus.h"
59
#include "nsIDOMNSDocument.h"
60
#include "nsIDOMLocation.h"
61
#include "nsIWebBrowserPersist.h"
62
#include "nsIProperties.h"
63
//#include "nsIRequest.h"
64
//#include "nsIPrefService.h"
65
#include "nsISHistory.h"
66
#include "nsIHistoryEntry.h"
67
#include "nsISHEntry.h"
68
#include "nsNetUtil.h"
69
#include "SaveHeaderSniffer.h"
70
#include "nsIWebBrowserFind.h"
72
#import "CHBrowserView.h"
74
#import "CHBrowserService.h"
75
#import "CHBrowserListener.h"
79
typedef unsigned int DragReference;
80
#include "nsIDragHelperService.h"
83
#include "nsIClipboardCommands.h"
84
#include "nsIInterfaceRequestorUtils.h"
87
#include "nsICommandManager.h"
88
#include "nsICommandParams.h"
91
const char kPersistContractID[] = "@mozilla.org/embedding/browser/nsWebBrowserPersist;1";
92
const char kDirServiceContractID[] = "@mozilla.org/file/directory_service;1";
94
@implementation CHBrowserView
96
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow
99
return [self initWithFrame:frame];
102
- (id)initWithFrame:(NSRect)frame
104
if ( (self = [super initWithFrame:frame]) )
106
nsresult rv = CHBrowserService::InitEmbedding();
111
_listener = new CHBrowserListener(self);
112
NS_ADDREF(_listener);
114
// Create the web browser instance
115
nsCOMPtr<nsIWebBrowser> browser = do_CreateInstance(NS_WEBBROWSER_CONTRACTID, &rv);
120
_webBrowser = browser;
121
NS_ADDREF(_webBrowser);
123
// Set the container nsIWebBrowserChrome
124
_webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *, _listener));
126
// Register as a listener for web progress
127
nsCOMPtr<nsIWeakReference> weak = do_GetWeakReference(NS_STATIC_CAST(nsIWebProgressListener*, _listener));
128
_webBrowser->AddWebBrowserListener(weak, NS_GET_IID(nsIWebProgressListener));
130
// Hook up the widget hierarchy with us as the parent
131
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
132
baseWin->InitWindow((NSView*)self, nsnull, 0, 0,
133
frame.size.width, frame.size.height);
136
// register the view as a drop site for text, files, and urls.
137
[self registerForDraggedTypes: [NSArray arrayWithObjects:
138
@"MozURLType", NSStringPboardType, NSURLPboardType, NSFilenamesPboardType, nil]];
140
// hookup the listener for creating our own native menus on <SELECTS>
141
CHClickListener* clickListener = new CHClickListener();
145
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([self getContentWindow]);
146
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
147
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
148
piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
149
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
151
rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
156
- (void)destroyWebBrowser
158
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
160
// clean up here rather than in the dtor so that if anyone tries to get our
161
// web browser, it won't get a garbage object that's past its prime. As a result,
162
// this routine MUST be called otherwise we will leak.
164
NS_RELEASE(_webBrowser);
170
NS_RELEASE(_listener);
172
// it is imperative that |destroyWebBrowser()| be called before we get here, otherwise
173
// we will leak the webBrowser.
174
NS_ASSERTION(!_webBrowser, "BrowserView going away, destroyWebBrowser not called; leaking webBrowser!");
176
CHBrowserService::BrowserClosed();
179
NSLog(@"CHBrowserView died.");
185
- (void)setFrame:(NSRect)frameRect
187
[super setFrame:frameRect];
189
nsCOMPtr<nsIBaseWindow> window = do_QueryInterface(_webBrowser);
190
window->SetSize((PRInt32)frameRect.size.width,
191
(PRInt32)frameRect.size.height,
196
- (void)addListener:(id <CHBrowserListener>)listener
198
_listener->AddListener(listener);
201
- (void)removeListener:(id <CHBrowserListener>)listener
203
_listener->RemoveListener(listener);
206
- (void)setContainer:(id <CHBrowserContainer>)container
208
_listener->SetContainer(container);
211
- (nsIDOMWindow*)getContentWindow
213
nsIDOMWindow* window = nsnull;
216
_webBrowser->GetContentDOMWindow(&window);
221
- (void)loadURI:(NSString *)urlSpec referrer:(NSString*)referrer flags:(unsigned int)flags
223
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
225
int length = [urlSpec length];
226
PRUnichar* specStr = nsMemory::Alloc((length+1) * sizeof(PRUnichar));
227
[urlSpec getCharacters:specStr];
228
specStr[length] = PRUnichar(0);
230
nsCOMPtr<nsIURI> referrerURI;
232
NS_NewURI(getter_AddRefs(referrerURI), [referrer UTF8String]);
234
PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
235
if (flags & NSLoadFlagsDontPutInHistory) {
236
navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_HISTORY;
238
if (flags & NSLoadFlagsReplaceHistoryEntry) {
239
navFlags |= nsIWebNavigation::LOAD_FLAGS_REPLACE_HISTORY;
241
if (flags & NSLoadFlagsBypassCacheAndProxy) {
242
navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE |
243
nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
246
nsresult rv = nav->LoadURI(specStr, navFlags, referrerURI, nsnull, nsnull);
251
nsMemory::Free(specStr);
254
- (void)reload:(unsigned int)flags
256
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
260
PRUint32 navFlags = nsIWebNavigation::LOAD_FLAGS_NONE;
261
if (flags & NSLoadFlagsBypassCacheAndProxy) {
262
navFlags |= nsIWebNavigation::LOAD_FLAGS_BYPASS_CACHE |
263
nsIWebNavigation::LOAD_FLAGS_BYPASS_PROXY;
266
nsresult rv = nav->Reload(navFlags);
274
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
279
nav->GetCanGoBack(&can);
281
return can ? YES : NO;
286
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
291
nav->GetCanGoForward(&can);
293
return can ? YES : NO;
298
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
302
nsresult rv = nav->GoBack();
310
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
314
nsresult rv = nav->GoForward();
320
- (void)gotoIndex:(int)index
322
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
326
nsresult rv = nav->GotoIndex(index);
332
- (void)stop:(unsigned int)flags
334
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
338
nsresult rv = nav->Stop(flags);
344
// XXXbryner This isn't used anywhere. how is it different from getCurrentURLSpec?
345
- (NSString*)getCurrentURI
347
nsCOMPtr<nsIURI> uri;
348
nsCOMPtr<nsIWebNavigation> nav = do_QueryInterface(_webBrowser);
352
nav->GetCurrentURI(getter_AddRefs(uri));
360
const char* cstr = spec.get();
361
NSString* str = [NSString stringWithCString:cstr];
366
- (CHBrowserListener*)getCocoaBrowserListener
371
- (nsIWebBrowser*)getWebBrowser
373
NS_IF_ADDREF(_webBrowser);
377
- (void)setWebBrowser:(nsIWebBrowser*)browser
379
NS_IF_ADDREF(browser); // prevents destroying |browser| if |browser| == |_webBrowser|
380
NS_IF_RELEASE(_webBrowser);
381
_webBrowser = browser;
384
// Set the container nsIWebBrowserChrome
385
_webBrowser->SetContainerWindow(NS_STATIC_CAST(nsIWebBrowserChrome *,
388
NSRect frame = [self frame];
390
// Hook up the widget hierarchy with us as the parent
391
nsCOMPtr<nsIBaseWindow> baseWin = do_QueryInterface(_webBrowser);
392
baseWin->InitWindow((NSView*)self, nsnull, 0, 0,
393
frame.size.width, frame.size.height);
399
-(void) saveInternal: (nsIURI*)aURI
400
withDocument: (nsIDOMDocument*)aDocument
401
suggestedFilename: (const char*)aFilename
402
bypassCache: (BOOL)aBypassCache
403
filterView: (NSView*)aFilterView
404
filterList: (NSPopUpButton*)aFilterList
406
// Create our web browser persist object. This is the object that knows
407
// how to actually perform the saving of the page (and of the images
409
nsCOMPtr<nsIWebBrowserPersist> webPersist(do_CreateInstance(kPersistContractID));
413
// Make a temporary file object that we can save to.
414
nsCOMPtr<nsIProperties> dirService(do_GetService(kDirServiceContractID));
417
nsCOMPtr<nsIFile> tmpFile;
418
dirService->Get("TmpD", NS_GET_IID(nsIFile), getter_AddRefs(tmpFile));
419
static short unsigned int tmpRandom = 0;
420
nsAutoString tmpNo; tmpNo.AppendInt(tmpRandom++);
421
nsAutoString saveFile(NS_LITERAL_STRING("-sav"));
423
saveFile += NS_LITERAL_STRING("tmp");
424
tmpFile->Append(saveFile);
426
// Get the post data if we're an HTML doc.
427
nsCOMPtr<nsIInputStream> postData;
429
nsCOMPtr<nsIWebNavigation> webNav(do_QueryInterface(_webBrowser));
431
nsCOMPtr<nsISHistory> sessionHistory;
432
webNav->GetSessionHistory(getter_AddRefs(sessionHistory));
433
nsCOMPtr<nsIHistoryEntry> entry;
435
sessionHistory->GetIndex(&sindex);
436
sessionHistory->GetEntryAtIndex(sindex, PR_FALSE, getter_AddRefs(entry));
437
nsCOMPtr<nsISHEntry> shEntry(do_QueryInterface(entry));
439
shEntry->GetPostData(getter_AddRefs(postData));
443
// when saving, we first fire off a save with a nsHeaderSniffer as a progress
444
// listener. This allows us to look for the content-disposition header, which
445
// can supply a filename, and maybe has something to do with CGI-generated
447
nsCAutoString fileName(aFilename);
448
nsHeaderSniffer* sniffer = new nsHeaderSniffer(webPersist, tmpFile, aURI,
449
aDocument, postData, fileName, aBypassCache,
450
aFilterView, aFilterList);
453
webPersist->SetProgressListener(sniffer); // owned
454
webPersist->SaveURI(aURI, nsnull, nsnull, nsnull, nsnull, tmpFile);
461
nsCOMPtr<nsIDOMWindow> domWindow;
462
_webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
463
nsCOMPtr<nsIInterfaceRequestor> ir(do_QueryInterface(domWindow));
464
nsCOMPtr<nsIWebBrowserPrint> print;
465
ir->GetInterface(NS_GET_IID(nsIWebBrowserPrint), getter_AddRefs(print));
466
print->Print(nsnull, nsnull);
469
- (BOOL)findInPageWithPattern:(NSString*)inText caseSensitive:(BOOL)inCaseSensitive
470
wrap:(BOOL)inWrap backwards:(BOOL)inBackwards
474
PRBool found = PR_FALSE;
476
nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
477
nsCOMPtr<nsIDOMWindow> rootWindow;
478
nsCOMPtr<nsIDOMWindow> focusedWindow;
479
_webBrowser->GetContentDOMWindow(getter_AddRefs(rootWindow));
480
wbf->GetFocusedWindow(getter_AddRefs(focusedWindow));
482
focusedWindow = rootWindow;
483
nsCOMPtr<nsIWebBrowserFind> webFind(do_GetInterface(_webBrowser));
485
nsCOMPtr<nsIWebBrowserFindInFrames> framesFind(do_QueryInterface(webFind));
486
framesFind->SetRootSearchFrame(rootWindow);
487
framesFind->SetCurrentSearchFrame(focusedWindow);
489
webFind->SetMatchCase(inCaseSensitive ? PR_TRUE : PR_FALSE);
490
webFind->SetWrapFind(inWrap ? PR_TRUE : PR_FALSE);
491
webFind->SetFindBackwards(inBackwards ? PR_TRUE : PR_FALSE);
493
PRUnichar* text = (PRUnichar*)nsMemory::Alloc(([inText length]+1)*sizeof(PRUnichar));
495
[inText getCharacters:text];
496
text[[inText length]] = 0;
497
webFind->SetSearchString(text);
498
webFind->FindNext(&found);
499
nsMemory::Free(text);
505
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
506
url: (NSString*)aURLSpec suggestedFilename: (NSString*)aFilename
508
nsCOMPtr<nsIURI> url;
509
nsresult rv = NS_NewURI(getter_AddRefs(url), [aURLSpec UTF8String]);
513
[self saveInternal: url.get()
515
suggestedFilename: (([aFilename length] > 0) ? [aFilename fileSystemRepresentation] : "")
517
filterView: aFilterView
518
filterList: aFilterList];
521
-(NSString*)getFocusedURLString
525
nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
526
nsCOMPtr<nsIDOMWindow> domWindow;
527
wbf->GetFocusedWindow(getter_AddRefs(domWindow));
529
_webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
533
nsCOMPtr<nsIDOMDocument> domDocument;
534
domWindow->GetDocument(getter_AddRefs(domDocument));
537
nsCOMPtr<nsIDOMNSDocument> nsDoc(do_QueryInterface(domDocument));
540
nsCOMPtr<nsIDOMLocation> location;
541
nsDoc->GetLocation(getter_AddRefs(location));
545
location->GetHref(urlStr);
546
return [NSString stringWith_nsAString: urlStr];
549
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
553
nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
554
nsCOMPtr<nsIDOMWindow> domWindow;
555
wbf->GetFocusedWindow(getter_AddRefs(domWindow));
557
_webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
561
nsCOMPtr<nsIDOMDocument> domDocument;
562
domWindow->GetDocument(getter_AddRefs(domDocument));
565
nsCOMPtr<nsIDOMNSDocument> nsDoc(do_QueryInterface(domDocument));
568
nsCOMPtr<nsIDOMLocation> location;
569
nsDoc->GetLocation(getter_AddRefs(location));
573
location->GetHref(urlStr);
575
nsCAutoString urlCStr; urlCStr.AssignWithConversion(urlStr);
576
nsCOMPtr<nsIURI> url;
577
nsresult rv = NS_NewURI(getter_AddRefs(url), urlCStr.get());
581
[self saveInternal: url.get()
582
withDocument: domDocument
583
suggestedFilename: ""
585
filterView: aFilterView
586
filterList: aFilterList];
589
-(void)doCommand:(const char*)commandName
591
nsCOMPtr<nsICommandManager> commandMgr(do_GetInterface(_webBrowser));
593
nsresult rv = commandMgr->DoCommand(commandName, nsnull, nsnull);
596
NSLog(@"DoCommand failed");
601
NSLog(@"No command manager");
606
-(BOOL)isCommandEnabled:(const char*)commandName
608
PRBool isEnabled = PR_FALSE;
609
nsCOMPtr<nsICommandManager> commandMgr(do_GetInterface(_webBrowser));
611
nsresult rv = commandMgr->IsCommandEnabled(commandName, nsnull, &isEnabled);
614
NSLog(@"IsCommandEnabled failed");
619
NSLog(@"No command manager");
623
return (isEnabled) ? YES : NO;
627
-(IBAction)cut:(id)aSender
629
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
631
clipboard->CutSelection();
636
PRBool canCut = PR_FALSE;
637
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
639
clipboard->CanCutSelection(&canCut);
643
-(IBAction)copy:(id)aSender
645
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
647
clipboard->CopySelection();
652
PRBool canCut = PR_FALSE;
653
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
655
clipboard->CanCopySelection(&canCut);
659
-(IBAction)paste:(id)aSender
661
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
668
PRBool canCut = PR_FALSE;
669
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
671
clipboard->CanPaste(&canCut);
675
-(IBAction)delete:(id)aSender
677
[self doCommand: "cmd_delete"];
682
return [self isCommandEnabled: "cmd_delete"];
685
-(IBAction)selectAll:(id)aSender
687
nsCOMPtr<nsIClipboardCommands> clipboard(do_GetInterface(_webBrowser));
689
clipboard->SelectAll();
692
-(IBAction)undo:(id)aSender
694
[self doCommand: "cmd_undo"];
697
-(IBAction)redo:(id)aSender
699
[self doCommand: "cmd_redo"];
704
return [self isCommandEnabled: "cmd_undo"];
709
return [self isCommandEnabled: "cmd_redo"];
712
-(NSString*)getCurrentURLSpec
714
NSString* empty = @"";
717
nsCOMPtr<nsIDOMWindow> domWindow;
718
_webBrowser->GetContentDOMWindow(getter_AddRefs(domWindow));
722
nsCOMPtr<nsIDOMDocument> domDocument;
723
domWindow->GetDocument(getter_AddRefs(domDocument));
727
nsCOMPtr<nsIDOMNSDocument> nsDoc(do_QueryInterface(domDocument));
731
nsCOMPtr<nsIDOMLocation> location;
732
nsDoc->GetLocation(getter_AddRefs(location));
737
location->GetHref(urlStr);
738
return [NSString stringWith_nsAString: urlStr];
741
- (void)setActive: (BOOL)aIsActive
743
nsCOMPtr<nsIWebBrowserFocus> wbf(do_QueryInterface(_webBrowser));
752
-(NSMenu*)getContextMenu
754
if ([[self superview] conformsToProtocol:@protocol(CHBrowserContainer)])
756
id<CHBrowserContainer> browserContainer = [self superview];
757
return [browserContainer getContextMenu];
763
-(NSWindow*)getNativeWindow
765
NSWindow* window = [self window];
767
return window; // We're visible. Just hand the window back.
769
// We're invisible. It's likely that we're in a Cocoa tab view.
770
// First see if we have a cached window.
774
// Finally, see if our parent responds to the getNativeWindow selector,
775
// and if they do, let them handle it.
776
if ([[self superview] conformsToProtocol:@protocol(CHBrowserContainer)])
778
id<CHBrowserContainer> browserContainer = [self superview];
779
return [browserContainer getNativeWindow];
787
// -findEventSink:forPoint:inWindow:
789
// Given a point in window coordinates, find the Gecko event sink of the ChildView
790
// the point is over. This involves first converting the point to this view's
791
// coordinate system and using hitTest: to get the subview. Then we get
792
// that view's widget and QI it to an event sink
794
- (void) findEventSink:(nsIEventSink**)outSink forPoint:(NSPoint)inPoint inWindow:(NSWindow*)inWind
796
NSPoint localPoint = [self convertPoint:inPoint fromView:[inWind contentView]];
797
NSView<mozView>* hitView = [self hitTest:localPoint];
798
if ( [hitView conformsToProtocol:@protocol(mozView)] ) {
799
nsCOMPtr<nsIEventSink> sink (do_QueryInterface([hitView widget]));
800
*outSink = sink.get();
801
NS_IF_ADDREF(*outSink);
807
- (BOOL)shouldAcceptDrag:(id <NSDraggingInfo>)sender
809
if ([[self superview] conformsToProtocol:@protocol(CHBrowserContainer)])
811
id<CHBrowserContainer> browserContainer = [self superview];
812
return [browserContainer shouldAcceptDragFromSource:[sender draggingSource]];
817
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
819
if (![self shouldAcceptDrag:sender])
820
return NSDragOperationNone;
822
// NSLog(@"draggingEntered");
823
nsCOMPtr<nsIDragHelperService> helper(do_GetService("@mozilla.org/widget/draghelperservice;1"));
824
mDragHelper = helper.get();
825
NS_IF_ADDREF(mDragHelper);
826
NS_ASSERTION ( mDragHelper, "Couldn't get a drag service, we're in big trouble" );
829
mLastTrackedLocation = [sender draggingLocation];
830
mLastTrackedWindow = [sender draggingDestinationWindow];
831
nsCOMPtr<nsIEventSink> sink;
832
[self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow];
834
mDragHelper->Enter ( [sender draggingSequenceNumber], sink );
837
return NSDragOperationCopy;
840
- (void)draggingExited:(id <NSDraggingInfo>)sender
842
// NSLog(@"draggingExited");
844
nsCOMPtr<nsIEventSink> sink;
846
[self findEventSink:getter_AddRefs(sink)
847
forPoint:mLastTrackedLocation /* [sender draggingLocation] */
848
inWindow:mLastTrackedWindow /* [sender draggingDestinationWindow] */
851
mDragHelper->Leave( [sender draggingSequenceNumber], sink );
852
NS_RELEASE(mDragHelper);
856
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
858
if (![self shouldAcceptDrag:sender])
859
return NSDragOperationNone;
861
// NSLog(@"draggingUpdated");
862
PRBool dropAllowed = PR_FALSE;
864
mLastTrackedLocation = [sender draggingLocation];
865
mLastTrackedWindow = [sender draggingDestinationWindow];
866
nsCOMPtr<nsIEventSink> sink;
867
[self findEventSink:getter_AddRefs(sink) forPoint:mLastTrackedLocation inWindow:mLastTrackedWindow];
869
mDragHelper->Tracking([sender draggingSequenceNumber], sink, &dropAllowed);
872
return dropAllowed ? NSDragOperationCopy : NSDragOperationNone;
875
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
880
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
882
if (![self shouldAcceptDrag:sender])
885
PRBool dragAccepted = PR_FALSE;
888
nsCOMPtr<nsIEventSink> sink;
889
[self findEventSink:getter_AddRefs(sink) forPoint:[sender draggingLocation]
890
inWindow:[sender draggingDestinationWindow]];
892
mDragHelper->Drop([sender draggingSequenceNumber], sink, &dragAccepted);
895
return dragAccepted ? YES : NO;
900
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem
902
// update first responder items based on the selection
903
SEL action = [aMenuItem action];
904
if (action == @selector(cut:))
905
return [self canCut];
906
else if (action == @selector(copy:))
907
return [self canCopy];
908
else if (action == @selector(paste:))
909
return [self canPaste];
910
else if (action == @selector(delete:))
911
return [self canDelete];
912
else if (action == @selector(undo:))
913
return [self canUndo];
914
else if (action == @selector(redo:))
915
return [self canRedo];
916
else if (action == @selector(selectAll:))