• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (C) 2005 Apple Computer, Inc.  All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 *
8 * 1.  Redistributions of source code must retain the above copyright
9 *     notice, this list of conditions and the following disclaimer.
10 * 2.  Redistributions in binary form must reproduce the above copyright
11 *     notice, this list of conditions and the following disclaimer in the
12 *     documentation and/or other materials provided with the distribution.
13 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
14 *     its contributors may be used to endorse or promote products derived
15 *     from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
18 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29#import "WebClipView.h"
30
31#import <WebKit/WebHTMLView.h>
32#import <WebKit/WebNSViewExtras.h>
33#import <WebKit/WebViewPrivate.h>
34#import <wtf/Assertions.h>
35
36// WebClipView's entire reason for existing is to set the clip used by focus ring redrawing.
37// There's no easy way to prevent the focus ring from drawing outside the passed-in clip rectangle
38// because it expects to have to draw outside the bounds of the view it's being drawn for.
39// But it looks for the enclosing clip view, which gives us a hook we can use to control it.
40// The "additional clip" is a clip for focus ring redrawing.
41
42// FIXME: Change terminology from "additional clip" to "focus ring clip".
43
44@interface NSView (WebViewMethod)
45- (WebView *)_webView;
46@end
47
48@implementation WebClipView
49
50- (id)initWithFrame:(NSRect)frame
51{
52    self = [super initWithFrame:frame];
53    if (!self)
54        return nil;
55
56    // In WebHTMLView, we set a clip. This is not typical to do in an
57    // NSView, and while correct for any one invocation of drawRect:,
58    // it causes some bad problems if that clip is cached between calls.
59    // The cached graphics state, which clip views keep around, does
60    // cache the clip in this undesirable way. Consequently, we want to
61    // release the GState for all clip views for all views contained in
62    // a WebHTMLView. Here we do it for subframes, which use WebClipView.
63    // See these bugs for more information:
64    // <rdar://problem/3409315>: REGRESSSION (7B58-7B60)?: Safari draws blank frames on macosx.apple.com perf page
65    [self releaseGState];
66
67    return self;
68}
69
70- (void)resetAdditionalClip
71{
72    ASSERT(_haveAdditionalClip);
73    _haveAdditionalClip = NO;
74}
75
76- (void)setAdditionalClip:(NSRect)additionalClip
77{
78    ASSERT(!_haveAdditionalClip);
79    _haveAdditionalClip = YES;
80    _additionalClip = additionalClip;
81}
82
83- (BOOL)hasAdditionalClip
84{
85    return _haveAdditionalClip;
86}
87
88- (NSRect)additionalClip
89{
90    ASSERT(_haveAdditionalClip);
91    return _additionalClip;
92}
93
94- (NSRect)_focusRingVisibleRect
95{
96    NSRect rect = [self visibleRect];
97    if (_haveAdditionalClip) {
98        rect = NSIntersectionRect(rect, _additionalClip);
99    }
100    return rect;
101}
102
103- (void)scrollWheel:(NSEvent *)event
104{
105    NSView *docView = [self documentView];
106    if ([docView respondsToSelector:@selector(_webView)]) {
107#if ENABLE(DASHBOARD_SUPPORT)
108        WebView *wv = [docView _webView];
109        if ([wv _dashboardBehavior:WebDashboardBehaviorAllowWheelScrolling]) {
110            [super scrollWheel:event];
111        }
112#endif
113        return;
114    }
115    [super scrollWheel:event];
116}
117
118@end
119