WebKit/mac/WebView/WebClipView.mm
changeset 0 4f2f89ce4247
equal deleted inserted replaced
-1:000000000000 0:4f2f89ce4247
       
     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 "WebFrameInternal.h"
       
    32 #import "WebFrameView.h"
       
    33 #import "WebViewPrivate.h"
       
    34 #import <WebCore/FrameView.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 using namespace WebCore;
       
    45 
       
    46 @interface NSView (WebViewMethod)
       
    47 - (WebView *)_webView;
       
    48 @end
       
    49 
       
    50 @interface NSClipView (WebNSClipViewDetails)
       
    51 - (void)_immediateScrollToPoint:(NSPoint)newOrigin;
       
    52 @end
       
    53 
       
    54 @implementation WebClipView
       
    55 
       
    56 - (id)initWithFrame:(NSRect)frame
       
    57 {
       
    58     self = [super initWithFrame:frame];
       
    59     if (!self)
       
    60         return nil;
       
    61     
       
    62     // In WebHTMLView, we set a clip. This is not typical to do in an
       
    63     // NSView, and while correct for any one invocation of drawRect:,
       
    64     // it causes some bad problems if that clip is cached between calls.
       
    65     // The cached graphics state, which clip views keep around, does
       
    66     // cache the clip in this undesirable way. Consequently, we want to 
       
    67     // release the GState for all clip views for all views contained in 
       
    68     // a WebHTMLView. Here we do it for subframes, which use WebClipView.
       
    69     // See these bugs for more information:
       
    70     // <rdar://problem/3409315>: REGRESSSION (7B58-7B60)?: Safari draws blank frames on macosx.apple.com perf page
       
    71     [self releaseGState];
       
    72     
       
    73     return self;
       
    74 }
       
    75 
       
    76 #if USE(ACCELERATED_COMPOSITING)
       
    77 - (NSRect)visibleRect
       
    78 {
       
    79     if (!_isScrolling)
       
    80         return [super visibleRect];
       
    81 
       
    82     WebFrameView *webFrameView = (WebFrameView *)[[self superview] superview];
       
    83     if (![webFrameView isKindOfClass:[WebFrameView class]])
       
    84         return [super visibleRect];
       
    85 
       
    86     if (Frame* coreFrame = core([webFrameView webFrame])) {
       
    87         if (FrameView* frameView = coreFrame->view()) {
       
    88             if (frameView->isEnclosedInCompositingLayer())
       
    89                 return [self bounds];
       
    90         }
       
    91     }
       
    92 
       
    93     return [super visibleRect];
       
    94 }
       
    95 
       
    96 - (void)_immediateScrollToPoint:(NSPoint)newOrigin
       
    97 {
       
    98     _isScrolling = YES;
       
    99     [super _immediateScrollToPoint:newOrigin];
       
   100     _isScrolling = NO;
       
   101 }
       
   102 #endif
       
   103 
       
   104 - (void)resetAdditionalClip
       
   105 {
       
   106     ASSERT(_haveAdditionalClip);
       
   107     _haveAdditionalClip = NO;
       
   108 }
       
   109 
       
   110 - (void)setAdditionalClip:(NSRect)additionalClip
       
   111 {
       
   112     ASSERT(!_haveAdditionalClip);
       
   113     _haveAdditionalClip = YES;
       
   114     _additionalClip = additionalClip;
       
   115 }
       
   116 
       
   117 - (BOOL)hasAdditionalClip
       
   118 {
       
   119     return _haveAdditionalClip;
       
   120 }
       
   121 
       
   122 - (NSRect)additionalClip
       
   123 {
       
   124     ASSERT(_haveAdditionalClip);
       
   125     return _additionalClip;
       
   126 }
       
   127 
       
   128 - (NSRect)_focusRingVisibleRect
       
   129 {
       
   130     NSRect rect = [self visibleRect];
       
   131     if (_haveAdditionalClip) {
       
   132         rect = NSIntersectionRect(rect, _additionalClip);
       
   133     }
       
   134     return rect;
       
   135 }
       
   136 
       
   137 - (void)scrollWheel:(NSEvent *)event
       
   138 {
       
   139     NSView *docView = [self documentView];
       
   140     if ([docView respondsToSelector:@selector(_webView)]) {
       
   141 #if ENABLE(DASHBOARD_SUPPORT)
       
   142         WebView *wv = [docView _webView];
       
   143         if ([wv _dashboardBehavior:WebDashboardBehaviorAllowWheelScrolling]) {
       
   144             [super scrollWheel:event];
       
   145         }
       
   146 #endif
       
   147         return;
       
   148     }
       
   149     [super scrollWheel:event];
       
   150 }
       
   151 
       
   152 @end