<commit_before>/*
 * CPScrollView.j
 * AppKit
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import "CPView.j"
@import "CPClipView.j"
@import "CPScroller.j"

#include "CoreGraphics/CGGeometry.h"


/*!
    @ingroup appkit
    @class CPScrollView

    Used to display views that are too large for the viewing area. the CPScrollView
    places scroll bars on the side of the view to allow the user to scroll and see the entire
    contents of the view.
*/
@implementation CPScrollView : CPView
{
    CPClipView      _contentView;
    CPClipView      _headerClipView;
    CPView          _cornerView;
    CPView          _bottomCornerView;

    BOOL            _hasVerticalScroller;
    BOOL            _hasHorizontalScroller;
    BOOL            _autohidesScrollers;

    CPScroller      _verticalScroller;
    CPScroller      _horizontalScroller;

    int             _recursionCount;

    float           _verticalLineScroll;
    float           _verticalPageScroll;
    float           _horizontalLineScroll;
    float           _horizontalPageScroll;

    CPBorderType    _borderType;
}

+ (CPString)themeClass
{
    return @"scrollview"
}

+ (CPDictionary)themeAttributes
{
    return [CPDictionary dictionaryWithJSObject:{
        @"bottom-corner-color": [CPColor whiteColor],
        @"border-color": [CPColor blackColor]
    }];
}

- (id)initWithFrame:(CGRect)aFrame
{
    self = [super initWithFrame:aFrame];

    if (self)
    {
        _verticalLineScroll = 10.0;
        _verticalPageScroll = 10.0;

        _horizontalLineScroll = 10.0;
        _horizontalPageScroll = 10.0;

        _borderType = CPNoBorder;

        _contentView = [[CPClipView alloc] initWithFrame:[self _insetBounds]];

        [self addSubview:_contentView];

        _headerClipView = [[CPClipView alloc] init];
        [self addSubview:_headerClipView];

        _bottomCornerView = [[CPView alloc] init];
        [self addSubview:_bottomCornerView];

        [self setHasVerticalScroller:YES];
        [self setHasHorizontalScroller:YES];
    }

    return self;
}

// Calculating Layout

+ (CGSize)contentSizeForFrameSize:(CGSize)frameSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
    var bounds = [self _insetBounds:_CGRectMake(0.0, 0.0, frameSize.width, frameSize.height) borderType:borderType],
        scrollerWidth = [CPScroller scrollerWidth];

    if (hFlag)
        bounds.size.height -= scrollerWidth;

    if (vFlag)
        bounds.size.width -= scrollerWidth;

    return bounds.size;
}

+ (CGSize)frameSizeForContentSize:(CGSize)contentSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
    var bounds = [self _insetBounds:_CGRectMake(0.0, 0.0, contentSize.width, contentSize.height) borderType:borderType],
        widthInset = contentSize.width - bounds.size.width,
        heightInset = contentSize.height - bounds.size.height,
        frameSize = _CGSizeMake(contentSize.width + widthInset, contentSize.height + heightInset),
        scrollerWidth = [CPScroller scrollerWidth];

    if (hFlag)
        frameSize.height -= scrollerWidth;

    if (vFlag)
        frameSize.width -= scrollerWidth;

    return frameSize;
}

+ (CGRect)_insetBounds:(CGRect)bounds borderType:(CPBorderType)borderType
{
    switch (borderType)
    {
        case CPLineBorder:
        case CPBezelBorder:
            return _CGRectInset(bounds, 1.0, 1.0);

        case CPGrooveBorder:
            bounds = _CGRectInset(bounds, 2.0, 2.0);
            ++bounds.origin.y;
            --bounds.size.height;

            return bounds;

        case CPNoBorder:
        default:
            return bounds;
    }
}

- (CGRect)_insetBounds
{
    return [[self class] _insetBounds:[self bounds] borderType:_borderType];
}

// Determining component sizes
/*!
    Returns the size of the scroll view's content view.
*/
- (CGRect)contentSize
{
    return [_contentView frame].size;
}

/*!
    Returns the view that is scrolled for the user.
*/
- (id)documentView
{
    return [_contentView documentView];
}
<commit_msg>Fix CPScrollView -contentSize return type.<commit_after>/*
 * CPScrollView.j
 * AppKit
 *
 * Created by <NAME>.
 * Copyright 2008, 280 North, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 */

@import "CPView.j"
@import "CPClipView.j"
@import "CPScroller.j"

#include "CoreGraphics/CGGeometry.h"


/*!
    @ingroup appkit
    @class CPScrollView

    Used to display views that are too large for the viewing area. the CPScrollView
    places scroll bars on the side of the view to allow the user to scroll and see the entire
    contents of the view.
*/
@implementation CPScrollView : CPView
{
    CPClipView      _contentView;
    CPClipView      _headerClipView;
    CPView          _cornerView;
    CPView          _bottomCornerView;

    BOOL            _hasVerticalScroller;
    BOOL            _hasHorizontalScroller;
    BOOL            _autohidesScrollers;

    CPScroller      _verticalScroller;
    CPScroller      _horizontalScroller;

    int             _recursionCount;

    float           _verticalLineScroll;
    float           _verticalPageScroll;
    float           _horizontalLineScroll;
    float           _horizontalPageScroll;

    CPBorderType    _borderType;
}

+ (CPString)themeClass
{
    return @"scrollview"
}

+ (CPDictionary)themeAttributes
{
    return [CPDictionary dictionaryWithJSObject:{
        @"bottom-corner-color": [CPColor whiteColor],
        @"border-color": [CPColor blackColor]
    }];
}

- (id)initWithFrame:(CGRect)aFrame
{
    self = [super initWithFrame:aFrame];

    if (self)
    {
        _verticalLineScroll = 10.0;
        _verticalPageScroll = 10.0;

        _horizontalLineScroll = 10.0;
        _horizontalPageScroll = 10.0;

        _borderType = CPNoBorder;

        _contentView = [[CPClipView alloc] initWithFrame:[self _insetBounds]];

        [self addSubview:_contentView];

        _headerClipView = [[CPClipView alloc] init];
        [self addSubview:_headerClipView];

        _bottomCornerView = [[CPView alloc] init];
        [self addSubview:_bottomCornerView];

        [self setHasVerticalScroller:YES];
        [self setHasHorizontalScroller:YES];
    }

    return self;
}

// Calculating Layout

+ (CGSize)contentSizeForFrameSize:(CGSize)frameSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
    var bounds = [self _insetBounds:_CGRectMake(0.0, 0.0, frameSize.width, frameSize.height) borderType:borderType],
        scrollerWidth = [CPScroller scrollerWidth];

    if (hFlag)
        bounds.size.height -= scrollerWidth;

    if (vFlag)
        bounds.size.width -= scrollerWidth;

    return bounds.size;
}

+ (CGSize)frameSizeForContentSize:(CGSize)contentSize hasHorizontalScroller:(BOOL)hFlag hasVerticalScroller:(BOOL)vFlag borderType:(CPBorderType)borderType
{
    var bounds = [self _insetBounds:_CGRectMake(0.0, 0.0, contentSize.width, contentSize.height) borderType:borderType],
        widthInset = contentSize.width - bounds.size.width,
        heightInset = contentSize.height - bounds.size.height,
        frameSize = _CGSizeMake(contentSize.width + widthInset, contentSize.height + heightInset),
        scrollerWidth = [CPScroller scrollerWidth];

    if (hFlag)
        frameSize.height -= scrollerWidth;

    if (vFlag)
        frameSize.width -= scrollerWidth;

    return frameSize;
}

+ (CGRect)_insetBounds:(CGRect)bounds borderType:(CPBorderType)borderType
{
    switch (borderType)
    {
        case CPLineBorder:
        case CPBezelBorder:
            return _CGRectInset(bounds, 1.0, 1.0);

        case CPGrooveBorder:
            bounds = _CGRectInset(bounds, 2.0, 2.0);
            ++bounds.origin.y;
            --bounds.size.height;

            return bounds;

        case CPNoBorder:
        default:
            return bounds;
    }
}

- (CGRect)_insetBounds
{
    return [[self class] _insetBounds:[self bounds] borderType:_borderType];
}

// Determining component sizes
/*!
    Returns the size of the scroll view's content view.
*/
- (CGSize)contentSize
{
    return [_contentView frame].size;
}

/*!
    Returns the view that is scrolled for the user.
*/
- (id)documentView
{
    return [_contentView documentView];
}

{'fraction_non_alphanumeric': 0.08702774649329374, 'fraction_numerical': 0.009829016074536704, 'mean_word_length': 2.9820627802690582, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5070846', 'n_tokens_mistral': 2975, 'n_tokens_neox': 2816, 'n_words': 782}