Prevent infinitely forwarding navigation events. Fixes #13251.
2 * Adium is the legal property of its developers, whose names are listed in the copyright file included
3 * with this source distribution.
5 * This program is free software; you can redistribute it and/or modify it under the terms of the GNU
6 * General Public License as published by the Free Software Foundation; either version 2 of the License,
7 * or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
10 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
11 * Public License for more details.
13 * You should have received a copy of the GNU General Public License along with this program; if not,
14 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 - (void)setDrawsBackground:(BOOL)flag;
21 - (void)setBackgroundColor:(NSColor *)color;
24 @interface NSWindow ()
25 - (void) _setContentHasShadow:(BOOL) shadow;
28 @interface ESWebView ()
29 - (void)forwardSelector:(SEL)selector withObject:(id)object;
32 @implementation ESWebView
34 - (id)initWithFrame:(NSRect)frameRect frameName:(NSString *)frameName groupName:(NSString *)groupName
36 if ((self = [super initWithFrame:frameRect frameName:frameName groupName:groupName])) {
37 draggingDelegate = nil;
38 allowsDragAndDrop = YES;
39 shouldForwardEvents = YES;
40 transparentBackground = NO;
46 #pragma mark Transparency
47 - (void)setTransparent:(BOOL)flag
49 //Private method: this is new in Tiger
50 if( [[self window] respondsToSelector:@selector( _setContentHasShadow: )] )
51 [[self window] _setContentHasShadow:NO];
53 //As of Safari 3.0, we must call setBackgroundColor: to make the webview transparent
54 [self setBackgroundColor:(flag ? [NSColor clearColor] : [NSColor whiteColor])];
56 transparentBackground = flag;
59 - (void)viewDidMoveToWindow
61 NSWindow *win = [self window];
63 [win setOpaque:!transparentBackground];
64 [win _setContentHasShadow:NO];
66 [super viewDidMoveToWindow];
69 //Font Family ----------------------------------------------------------------------------------------------------------
70 #pragma mark Font Family
71 - (void)setFontFamily:(NSString *)familyName
73 [[self preferences] setStandardFontFamily:familyName];
74 [[self preferences] setFixedFontFamily:familyName];
75 [[self preferences] setSerifFontFamily:familyName];
76 [[self preferences] setSansSerifFontFamily:familyName];
79 - (NSString *)fontFamily
81 return [[self preferences] standardFontFamily];
85 #pragma mark Key/Paste Forwarding
86 - (void)setShouldForwardEvents:(BOOL)flag
88 shouldForwardEvents = flag;
91 //When the user attempts to type into the table view, we push the keystroke to the next responder,
92 //and make it key. This isn't required, but convienent behavior since one will never want to type
94 - (void)keyDown:(NSEvent *)theEvent
98 if (shouldForwardEvents) {
99 unichar inChar = [[theEvent charactersIgnoringModifiers] characterAtIndex:0];
101 // Don't forward navigation key events. If we're receiving them, it's because
102 // the frame itself didn't support them.
103 if (inChar != NSUpArrowFunctionKey && inChar != NSDownArrowFunctionKey &&
104 inChar != NSPageUpFunctionKey && inChar != NSPageDownFunctionKey)
106 [self forwardSelector:@selector(keyDown:) withObject:theEvent];
112 [super keyDown:theEvent];
116 - (void)paste:(id)sender
118 [self forwardSelector:@selector(paste:) withObject:sender];
120 - (void)pasteAsPlainText:(id)sender
122 [self forwardSelector:@selector(pasteAsPlainText:) withObject:sender];
124 - (void)pasteAsRichText:(id)sender
126 [self forwardSelector:@selector(pasteAsRichText:) withObject:sender];
129 - (void)forwardSelector:(SEL)selector withObject:(id)object
131 id responder = [self nextResponder];
133 //When walking the responder chain, we want to skip ScrollViews and ClipViews.
134 while (responder && ([responder isKindOfClass:[NSClipView class]] || [responder isKindOfClass:[NSScrollView class]])) {
135 responder = [responder nextResponder];
139 [[self window] makeFirstResponder:responder]; //Make it first responder
140 [responder tryToPerform:selector with:object]; //Pass it this key event
145 //Accepting Drags ------------------------------------------------------------------------------------------------------
146 #pragma mark Accepting Drags
147 - (void)setAllowsDragAndDrop:(BOOL)flag
149 allowsDragAndDrop = flag;
152 - (NSDragOperation)draggingEntered:(id <NSDraggingInfo>)sender
154 NSDragOperation dragOperation;
156 if (allowsDragAndDrop) {
157 if (draggingDelegate && [draggingDelegate respondsToSelector:@selector(webView:draggingEntered:)]) {
158 dragOperation = [draggingDelegate webView:self draggingEntered:sender];
160 dragOperation = [super draggingEntered:sender];
163 dragOperation = NSDragOperationNone;
166 return dragOperation;
169 - (NSDragOperation)draggingUpdated:(id <NSDraggingInfo>)sender
171 NSDragOperation dragOperation;
173 if (allowsDragAndDrop) {
174 if (draggingDelegate && [draggingDelegate respondsToSelector:@selector(webView:draggingUpdated:)]) {
175 dragOperation = [draggingDelegate webView:self draggingUpdated:sender];
177 dragOperation = [super draggingUpdated:sender];
180 dragOperation = NSDragOperationNone;
183 return dragOperation;
186 - (void)draggingExited:(id <NSDraggingInfo>)sender
188 if (draggingDelegate) {
189 if ([draggingDelegate respondsToSelector:@selector(webView:draggingExited:)]) {
190 [draggingDelegate webView:self draggingExited:sender];
193 [super draggingExited:sender];
198 - (void)setDraggingDelegate:(id)inDelegate
200 draggingDelegate = inDelegate;
203 - (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
205 if (draggingDelegate && [draggingDelegate respondsToSelector:@selector(webView:prepareForDragOperation:)]) {
206 return [draggingDelegate webView:self prepareForDragOperation:sender];
208 return [super prepareForDragOperation:sender];
212 - (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
214 if (draggingDelegate && [draggingDelegate respondsToSelector:@selector(webView:performDragOperation:)]) {
215 return [draggingDelegate webView:self performDragOperation:sender];
217 return [super performDragOperation:sender];
221 - (void)concludeDragOperation:(id <NSDraggingInfo>)sender
223 if (draggingDelegate && [draggingDelegate respondsToSelector:@selector(webView:concludeDragOperation:)]) {
224 [draggingDelegate webView:self concludeDragOperation:sender];
226 [super concludeDragOperation:sender];
231 - (id)accessibilityAttributeValue:(NSString *)attribute
233 NSLog(@"%@: Returning %@ for %@", self, [super accessibilityAttributeValue:attribute], attribute);
235 return [super accessibilityAttributeValue:attribute];