⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 scrollbarthememac.mm

📁 linux下开源浏览器WebKit的源码,市面上的很多商用浏览器都是移植自WebKit
💻 MM
📖 第 1 页 / 共 2 页
字号:
/* * Copyright (C) 2008 Apple Inc. All Rights Reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in the *    documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  */#include "config.h"#include "ScrollbarThemeMac.h"#include "GraphicsContext.h"#include "ImageBuffer.h"#include "IntRect.h"#include "Page.h"#include "PlatformMouseEvent.h"#include "Scrollbar.h"#include "ScrollbarClient.h"#include "Settings.h"#include <Carbon/Carbon.h>#include <wtf/StdLibExtras.h>#include <wtf/UnusedParam.h>// FIXME: There are repainting problems due to Aqua scroll bar buttons' visual overflow.using namespace std;using namespace WebCore;static HashSet<Scrollbar*>* gScrollbars;@interface ScrollbarPrefsObserver : NSObject{}+ (void)registerAsObserver;+ (void)appearancePrefsChanged:(NSNotification*)theNotification;+ (void)behaviorPrefsChanged:(NSNotification*)theNotification;@end@implementation ScrollbarPrefsObserver+ (void)appearancePrefsChanged:(NSNotification*)unusedNotification{    UNUSED_PARAM(unusedNotification);    static_cast<ScrollbarThemeMac*>(ScrollbarTheme::nativeTheme())->preferencesChanged();    if (!gScrollbars)        return;    HashSet<Scrollbar*>::iterator end = gScrollbars->end();    for (HashSet<Scrollbar*>::iterator it = gScrollbars->begin(); it != end; ++it) {        (*it)->styleChanged();        (*it)->invalidate();    }}+ (void)behaviorPrefsChanged:(NSNotification*)unusedNotification{    UNUSED_PARAM(unusedNotification);    static_cast<ScrollbarThemeMac*>(ScrollbarTheme::nativeTheme())->preferencesChanged();}+ (void)registerAsObserver{    [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(appearancePrefsChanged:) name:@"AppleAquaScrollBarVariantChanged" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorDeliverImmediately];    [[NSDistributedNotificationCenter defaultCenter] addObserver:self selector:@selector(behaviorPrefsChanged:) name:@"AppleNoRedisplayAppearancePreferenceChanged" object:nil suspensionBehavior:NSNotificationSuspensionBehaviorCoalesce];}@endnamespace WebCore {ScrollbarTheme* ScrollbarTheme::nativeTheme(){    DEFINE_STATIC_LOCAL(ScrollbarThemeMac, theme, ());    return &theme;}// FIXME: Get these numbers from CoreUI.static int cScrollbarThickness[] = { 15, 11 };static int cRealButtonLength[] = { 28, 21 };static int cButtonInset[] = { 14, 11 };static int cButtonHitInset[] = { 3, 2 };// cRealButtonLength - cButtonInsetstatic int cButtonLength[] = { 14, 10 };static int cThumbMinLength[] = { 26, 20 };static int cOuterButtonLength[] = { 16, 14 }; // The outer button in a double button pair is a bit bigger.static int cOuterButtonOverlap = 2;static float gInitialButtonDelay = 0.5f;static float gAutoscrollButtonDelay = 0.05f;static bool gJumpOnTrackClick = false;static ScrollbarButtonsPlacement gButtonPlacement = ScrollbarButtonsDoubleEnd;static void updateArrowPlacement(){    NSString *buttonPlacement = [[NSUserDefaults standardUserDefaults] objectForKey:@"AppleScrollBarVariant"];    if ([buttonPlacement isEqualToString:@"Single"])        gButtonPlacement = ScrollbarButtonsSingle;    else if ([buttonPlacement isEqualToString:@"DoubleMin"])        gButtonPlacement = ScrollbarButtonsDoubleStart;    else if ([buttonPlacement isEqualToString:@"DoubleBoth"])        gButtonPlacement = ScrollbarButtonsDoubleBoth;    else        gButtonPlacement = ScrollbarButtonsDoubleEnd; // The default is ScrollbarButtonsDoubleEnd.}void ScrollbarThemeMac::registerScrollbar(Scrollbar* scrollbar){    if (!gScrollbars)        gScrollbars = new HashSet<Scrollbar*>;    gScrollbars->add(scrollbar);}void ScrollbarThemeMac::unregisterScrollbar(Scrollbar* scrollbar){    gScrollbars->remove(scrollbar);    if (gScrollbars->isEmpty()) {        delete gScrollbars;        gScrollbars = 0;    }}ScrollbarThemeMac::ScrollbarThemeMac(){    static bool initialized;    if (!initialized) {        initialized = true;        [ScrollbarPrefsObserver registerAsObserver];        preferencesChanged();    }}ScrollbarThemeMac::~ScrollbarThemeMac(){}void ScrollbarThemeMac::preferencesChanged(){    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];    [defaults synchronize];    updateArrowPlacement();    gInitialButtonDelay = [defaults floatForKey:@"NSScrollerButtonDelay"];    gAutoscrollButtonDelay = [defaults floatForKey:@"NSScrollerButtonPeriod"];    gJumpOnTrackClick = [defaults boolForKey:@"AppleScrollerPagingBehavior"];}int ScrollbarThemeMac::scrollbarThickness(ScrollbarControlSize controlSize){    return cScrollbarThickness[controlSize];}double ScrollbarThemeMac::initialAutoscrollTimerDelay(){    return gInitialButtonDelay;}double ScrollbarThemeMac::autoscrollTimerDelay(){    return gAutoscrollButtonDelay;}    ScrollbarButtonsPlacement ScrollbarThemeMac::buttonsPlacement() const{    return gButtonPlacement;}bool ScrollbarThemeMac::hasButtons(Scrollbar* scrollbar){    return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ?              scrollbar->width() :              scrollbar->height()) >= 2 * (cRealButtonLength[scrollbar->controlSize()] - cButtonHitInset[scrollbar->controlSize()]);}bool ScrollbarThemeMac::hasThumb(Scrollbar* scrollbar){    return scrollbar->enabled() && (scrollbar->orientation() == HorizontalScrollbar ?              scrollbar->width() :              scrollbar->height()) >= 2 * cButtonInset[scrollbar->controlSize()] + cThumbMinLength[scrollbar->controlSize()] + 1;}static IntRect buttonRepaintRect(const IntRect& buttonRect, ScrollbarOrientation orientation, ScrollbarControlSize controlSize, bool start){    IntRect paintRect(buttonRect);    if (orientation == HorizontalScrollbar) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -