Zooming in and out in WebView

  • Hi!

    I am having trouble to zoom in and out in WebView. I have a subclass
    of WebView with the following zoom code:

    - (void)zoomByFactor:(CGFloat)factor {
        WebFrameView *frameView = self.mainFrame.frameView;
        NSView <WebDocumentView> *const docView = frameView.documentView;
        NSScrollView *scrollView = docView.enclosingScrollView;
        NSClipView *clipView = scrollView.contentView;

        NSView *viewToScale = docView;

        NSSize oldScale = [viewToScale convertSize:UNIT_SIZE toView:nil];
        NSSize newScale = NSMakeSize(oldScale.width * factor,
    oldScale.height * factor);

        [viewToScale scaleUnitSquareToSize:[viewToScale
    convertSize:UNIT_SIZE fromView:nil]];
        [docView scaleUnitSquareToSize:newScale];
        [docView setFrameSize:[docView convertSize:[docView bounds].size
    toView:nil]];

        [docView setNeedsLayout:YES];
        [self setNeedsDisplay:YES];
    }

    where UNIT_SIZE = NSMakeSize(1, 1).

    Zooming out seems to work, however, zooming in does not work. The web
    page gets zoomed in, however, the page gets clipped on the right side.
    There is a white strip. Zooming in further makes that white strip
    wider. Am I missing some convenient method? If not, how can I properly
    zoom a WebView?

    Thanks in advance,
    Tae
previous month may 2012 next month
MTWTFSS
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      
Go to today