| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2012 Apple 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 * 1. Redistributions of source code must retain the above copyright | |
| 8 * notice, this list of conditions and the following disclaimer. | |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | |
| 10 * notice, this list of conditions and the following disclaimer in the | |
| 11 * documentation and/or other materials provided with the distribution. | |
| 12 * | |
| 13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' | |
| 14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, | |
| 15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | |
| 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS | |
| 17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
| 18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
| 19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
| 20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
| 21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
| 22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF | |
| 23 * THE POSSIBILITY OF SUCH DAMAGE. | |
| 24 */ | |
| 25 | |
| 26 #include "config.h" | |
| 27 #include "WebCoreFullScreenWarningView.h" | |
| 28 | |
| 29 #include "LocalizedStrings.h" | |
| 30 #include <wtf/text/WTFString.h> | |
| 31 | |
| 32 static const CGFloat WarningViewTextWhite = 0.9; | |
| 33 static const CGFloat WarningViewTextAlpha = 1; | |
| 34 static const CGFloat WarningViewTextSize = 48; | |
| 35 static const CGFloat WarningViewPadding = 20; | |
| 36 static const CGFloat WarningViewCornerRadius = 10; | |
| 37 static const CGFloat WarningViewBorderWhite = 0.9; | |
| 38 static const CGFloat WarningViewBorderAlpha = 0.2; | |
| 39 static const CGFloat WarningViewBackgroundWhite = 0.1; | |
| 40 static const CGFloat WarningViewBackgroundAlpha = 0.9; | |
| 41 static const CGFloat WarningViewShadowWhite = 0.1; | |
| 42 static const CGFloat WarningViewShadowAlpha = 1; | |
| 43 static const float WarningViewShadowOpacity = 0.25; | |
| 44 static const NSSize WarningViewShadowOffset = {0, -2}; | |
| 45 static const CGFloat WarningViewShadowRadius = 5; | |
| 46 static const NSTimeInterval WarningViewHideDelay = 3; | |
| 47 static const NSTimeInterval WarningViewFadeDuration = 0.5; | |
| 48 | |
| 49 @implementation WebCoreFullScreenWarningView | |
| 50 | |
| 51 - (id)initWithTitle:(NSString*)title | |
| 52 { | |
| 53 self = [super initWithFrame:NSZeroRect]; | |
| 54 if (!self) | |
| 55 return nil; | |
| 56 | |
| 57 [self setAutoresizingMask:(NSViewMinXMargin | NSViewMaxXMargin | NSViewMinYM
argin | NSViewMaxYMargin)]; | |
| 58 [self setBoxType:NSBoxCustom]; | |
| 59 [self setTitlePosition:NSNoTitle]; | |
| 60 | |
| 61 _textField = adoptNS([[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 62 [_textField.get() setEditable:NO]; | |
| 63 [_textField.get() setSelectable:NO]; | |
| 64 [_textField.get() setBordered:NO]; | |
| 65 [_textField.get() setDrawsBackground:NO]; | |
| 66 | |
| 67 NSFont* textFont = [NSFont boldSystemFontOfSize:WarningViewTextSize]; | |
| 68 NSColor* textColor = [NSColor colorWithCalibratedWhite:WarningViewTextWhite
alpha:WarningViewTextAlpha]; | |
| 69 RetainPtr<NSDictionary> attributes = adoptNS([[NSDictionary alloc] initWithO
bjectsAndKeys: | |
| 70 textFont, NSFontAttributeName, | |
| 71 textColor, NSForegroundColorAt
tributeName, | |
| 72 nil]); | |
| 73 RetainPtr<NSAttributedString> text = adoptNS([[NSAttributedString alloc] ini
tWithString:title attributes:attributes.get()]); | |
| 74 [_textField.get() setAttributedStringValue:text.get()]; | |
| 75 [_textField.get() sizeToFit]; | |
| 76 NSRect textFieldFrame = [_textField.get() frame]; | |
| 77 NSSize frameSize = textFieldFrame.size; | |
| 78 frameSize.width += WarningViewPadding * 2; | |
| 79 frameSize.height += WarningViewPadding * 2; | |
| 80 [self setFrameSize:frameSize]; | |
| 81 | |
| 82 textFieldFrame.origin = NSMakePoint( | |
| 83 (frameSize.width - textFieldFrame.size.width) / 2, | |
| 84 (frameSize.height - textFieldFrame.size.height) / 2); | |
| 85 | |
| 86 // Offset the origin by the font's descender, to center the text field about
the baseline: | |
| 87 textFieldFrame.origin.y += [[_textField.get() font] descender]; | |
| 88 | |
| 89 [_textField.get() setFrame:NSIntegralRect(textFieldFrame)]; | |
| 90 [self addSubview:_textField.get()]; | |
| 91 | |
| 92 NSColor* backgroundColor = [NSColor colorWithCalibratedWhite:WarningViewBack
groundWhite alpha:WarningViewBackgroundAlpha]; | |
| 93 [self setFillColor:backgroundColor]; | |
| 94 [self setCornerRadius:WarningViewCornerRadius]; | |
| 95 | |
| 96 NSColor* borderColor = [NSColor colorWithCalibratedWhite:WarningViewBorderWh
ite alpha:WarningViewBorderAlpha]; | |
| 97 [self setBorderColor:borderColor]; | |
| 98 | |
| 99 RetainPtr<NSShadow> shadow = adoptNS([[NSShadow alloc] init]); | |
| 100 RetainPtr<NSColor> shadowColor = [NSColor colorWithCalibratedWhite:WarningVi
ewShadowWhite alpha:WarningViewShadowAlpha]; | |
| 101 [shadow.get() setShadowColor:shadowColor.get()]; | |
| 102 [shadow.get() setShadowOffset:WarningViewShadowOffset]; | |
| 103 [shadow.get() setShadowBlurRadius:WarningViewShadowRadius]; | |
| 104 [self setShadow:shadow.get()]; | |
| 105 | |
| 106 return self; | |
| 107 } | |
| 108 @end | |
| OLD | NEW |