Adium

Ticket #131: transparentWebview.3.diff

File transparentWebview.3.diff, 9.0 kB (added by poisonousinsect, 3 years ago)

Improved version, detailed comments in a second since this text field is tiny.

  • Plugins/WebKit

    old new  
    2020        id              draggingDelegate; 
    2121        BOOL    allowsDragAndDrop; 
    2222        BOOL    shouldForwardEvents; 
     23        BOOL    transparentBackground; 
    2324} 
    2425 
     26- (void)setDrawsBackground:(BOOL)flag; 
     27- (BOOL)drawsBackground; 
     28 
    2529- (void)setFontFamily:(NSString *)familyName; 
    2630- (NSString *)fontFamily; 
    2731- (void)setDraggingDelegate:(id)inDelegate; 
  • Plugins/WebKit

    old new  
    107107 
    108108        //Observe preference changes and set our initial preferences 
    109109        [[adium preferenceController] registerPreferenceObserver:self forGroup:PREF_GROUP_WEBKIT_MESSAGE_DISPLAY]; 
     110         
     111        //Allow the alpha component to be set for our background color 
     112        [[NSColorPanel sharedColorPanel] setShowsAlpha:YES]; 
    110113} 
    111114 
    112115/*! 
     
    114117 */ 
    115118- (void)viewWillClose 
    116119{ 
     120        //Hide the alpha component 
     121        [[NSColorPanel sharedColorPanel] setShowsAlpha:NO]; 
     122         
    117123        [[adium notificationCenter] removeObserver:self]; 
    118124        [[adium preferenceController] unregisterPreferenceObserver:self]; 
    119125        [previewListObjectsDict release]; previewListObjectsDict = nil; 
  • Plugins/WebKit

    old new  
    1616 
    1717#import "ESWebView.h" 
    1818 
     19@interface WebView (PRIVATE) 
     20- (void)setDrawsBackground:(BOOL)flag; 
     21- (BOOL)drawsBackground; 
     22@end 
     23 
    1924@interface ESWebView (PRIVATE) 
    2025- (void)forwardSelector:(SEL)selector withObject:(id)object; 
    2126@end 
     
    2934        draggingDelegate = nil; 
    3035        allowsDragAndDrop = YES; 
    3136        shouldForwardEvents = YES; 
     37        transparentBackground = (![self drawsBackground]); 
    3238 
    3339        return self; 
    3440} 
     41 
     42- (void)drawRect:(NSRect)rect 
     43{ 
     44        [super drawRect:rect]; 
     45         
     46        //Only reset the shadow if we're transparent 
     47        if (transparentBackground) { 
     48                //This happens after the next run loop to ensure that we invalidate the shadow after all of our subviews have drawn 
     49                [[self window] performSelector:@selector(invalidateShadow) 
     50                                                        withObject:nil 
     51                                                        afterDelay:0 
     52                                                           inModes:[NSArray arrayWithObjects:NSDefaultRunLoopMode, NSEventTrackingRunLoopMode, nil]]; 
     53        } 
     54} 
     55 
     56//Background Drawing --------------------------------------------------------------------------------------------------- 
     57#pragma mark Background Drawing 
     58- (void)setDrawsBackground:(BOOL)flag 
     59{ 
     60        if ([super respondsToSelector:@selector(setDrawsBackground:)]) { 
     61                [super setDrawsBackground:flag]; 
     62                transparentBackground = !flag; 
     63        } 
     64} 
     65- (BOOL)drawsBackground 
     66{ 
     67        BOOL flag = YES; 
     68        if ([super respondsToSelector:@selector(drawsBackground)]) flag = [super drawsBackground]; 
     69        return flag; 
     70} 
     71 
    3572//Font Family ---------------------------------------------------------------------------------------------------------- 
    3673#pragma mark Font Family 
    3774- (void)setFontFamily:(NSString *)familyName 
     
    182219} 
    183220 
    184221@end 
     222 
     223@implementation WebDynamicScrollBarsView (ScrollBarHack) 
     224/* 
     225 * This is a heck of a lot of effort just to get it to always show the vertical scroll bar. 
     226 * Unfortunately, just calling -setAutohidesScrollers: and -setHasVerticalScroller: doesn't work 
     227 * because the WebView resets them. Not only that, but an always visible vertical scroller might 
     228 * not be an improvement anyway, although most Apple apps imply that it's correct (for example, Mail). 
     229 *  
     230 * Ultimately, the code is here, but feel free to remove it. 
     231 */ 
     232- (void)tile 
     233{ 
     234        [super tile]; 
     235        [[self verticalScroller] setHidden:NO]; 
     236 
     237        float scrollerWidth = NSWidth([[self verticalScroller] frame]); 
     238        [[self verticalScroller] setFrame:NSMakeRect(NSWidth([self bounds]) - scrollerWidth, 0, scrollerWidth, NSHeight([self bounds]))]; 
     239 
     240        NSRect clipViewFrame = [[self contentView] frame]; 
     241        clipViewFrame.size.width = NSMinX([[self verticalScroller] frame]); 
     242        [[self contentView] setFrame:clipViewFrame]; 
     243} 
     244@end 
  • Plugins/WebKit

    old new  
    335335        [webView setUIDelegate:self]; 
    336336        [webView setDraggingDelegate:self]; 
    337337        [webView setMaintainsBackForwardList:NO]; 
    338          
     338 
    339339        if (!draggedTypes) { 
    340340                draggedTypes = [[NSArray alloc] initWithObjects: 
    341341                        NSFilenamesPboardType, 
     
    424424        } else { 
    425425                [messageStyle setCustomBackgroundColor:nil]; 
    426426        } 
    427          
     427        [webView setDrawsBackground:![[self messageStyle] isBackgroundTransparent]]; 
     428 
    428429        //Update webview font settings 
    429430        NSString        *fontFamily = [prefDict objectForKey:[plugin styleSpecificKey:@"FontFamily" forStyle:activeStyle]]; 
    430431        [webView setFontFamily:(fontFamily ? fontFamily : [messageStyle defaultFontFamily])]; 
  • Plugins/WebKit

    old new  
    5757 
    5858        //Style settings 
    5959        BOOL                            allowsCustomBackground; 
     60        BOOL                            transparentDefaultBackground; 
    6061        BOOL                            allowsUserIcons; 
    6162        BOOL                            usingCustomBaseHTML; 
    6263 
     
    8889 
    8990//Settings 
    9091- (BOOL)allowsCustomBackground; 
     92- (BOOL)isBackgroundTransparent; 
    9193- (NSString *)defaultFontFamily; 
    9294- (NSNumber *)defaultFontSize; 
    9395- (BOOL)hasHeader; 
  • Plugins/WebKit

    old new  
    9191 
    9292                //Style flags 
    9393                allowsCustomBackground = ![[styleBundle objectForInfoDictionaryKey:@"DisableCustomBackground"] boolValue]; 
     94                transparentDefaultBackground = [[styleBundle objectForInfoDictionaryKey:@"DefaultBackgroundIsTransparent"] boolValue]; 
     95 
    9496                combineConsecutive = ![[styleBundle objectForInfoDictionaryKey:@"DisableCombineConsecutive"] boolValue]; 
    9597 
    9698                NSNumber *tmpNum = [styleBundle objectForInfoDictionaryKey:@"ShowsUserIcons"]; 
     
    158160} 
    159161 
    160162/*! 
     163 * @breif Style has a transparent background 
     164 */ 
     165- (BOOL)isBackgroundTransparent 
     166{ 
     167        //Our custom background is only transparent if the user has set a custom color with an alpha component less than 1.0 
     168        return ((!customBackgroundColor && transparentDefaultBackground) || 
     169                   (customBackgroundColor && [customBackgroundColor alphaComponent] < 0.99)); 
     170} 
     171 
     172/*! 
    161173 * @brief Style supports user icons 
    162174 */ 
    163175- (BOOL)allowsUserIcons 
     
    10231035                                        } 
    10241036                                } 
    10251037                                if (customBackgroundColor) { 
    1026                                         [bodyTag appendString:[NSString stringWithFormat:@"background-color: #%@; ", [customBackgroundColor hexString]]]; 
     1038                                        float red, green, blue, alpha; 
     1039                                        [customBackgroundColor getRed:&red green:&green blue:&blue alpha:&alpha]; 
     1040                                        [bodyTag appendString:[NSString stringWithFormat:@"background-color: rgba(%i, %i, %i, %f); ", (int)(red * 255.0), (int)(green * 255.0), (int)(blue * 255.0), alpha]]; 
    10271041                                } 
    10281042                        } 
    10291043                         
  • Plugins/Dual

    old new  
    8888                 
    8989                //Load our window 
    9090                myWindow = [self window]; 
    91                  
     91 
     92                //Disable the optimization for opaque windows since ours might not be 
     93                [myWindow setOpaque:NO]; 
     94 
    9295                //Tab hiding suppression (used to force tab bars visible when a drag is occuring) 
    9396                tabBarIsVisible = YES; 
    9497                supressHiding = NO; 
     
    297300        } 
    298301         
    299302        [inTabViewItem setContainer:self]; 
    300  
     303         
    301304        if (!silent) [[adium interfaceController] chatDidOpen:[inTabViewItem chat]]; 
    302305} 
    303306 
  • Plugins/Dual

    old new  
    272272        //scrollView_messages is originally a placeholder; replace it with controllerView_messages 
    273273        [controllerView_messages setFrame:[scrollView_messages documentVisibleRect]]; 
    274274        [[customView_messages superview] replaceSubview:customView_messages with:controllerView_messages]; 
     275 
     276        //This is what draws our transparent background 
     277        //Technically, it could be set in MessageView.nib, too 
     278        [scrollView_messages setBackgroundColor:[NSColor clearColor]]; 
     279 
    275280        [controllerView_messages setNextResponder:textView_outgoing]; 
    276281} 
    277282