electron/shell/browser/osr/osr_web_contents_view_mac.mm

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.6 KiB
Text
Raw Normal View History

2016-08-04 06:34:29 +00:00
// Copyright (c) 2016 GitHub, Inc.
// Use of this source code is governed by the MIT license that can be
// found in the LICENSE file.
#include "shell/browser/osr/osr_web_contents_view.h"
2016-08-04 06:34:29 +00:00
2016-09-06 08:24:37 +00:00
#import <Cocoa/Cocoa.h>
2016-08-04 06:34:29 +00:00
@interface OffScreenView : NSView
@end
@implementation OffScreenView
- (void)drawRect:(NSRect)dirtyRect {
NSString* str = @"No content under offscreen mode";
NSMutableParagraphStyle* paragraphStyle =
[[[NSParagraphStyle defaultParagraphStyle] mutableCopy] autorelease];
[paragraphStyle setAlignment:NSTextAlignmentCenter];
2018-04-20 18:47:04 +00:00
NSDictionary* attributes =
[NSDictionary dictionaryWithObject:paragraphStyle
forKey:NSParagraphStyleAttributeName];
2016-08-04 06:34:29 +00:00
NSAttributedString* text =
[[[NSAttributedString alloc] initWithString:str
attributes:attributes] autorelease];
2016-08-04 06:34:29 +00:00
NSRect frame = NSMakeRect(0, (self.frame.size.height - text.size.height) / 2,
self.frame.size.width, text.size.height);
[str drawInRect:frame withAttributes:attributes];
}
@end
namespace electron {
gfx::NativeView OffScreenWebContentsView::GetNativeView() const {
return offScreenView_;
}
gfx::NativeView OffScreenWebContentsView::GetContentNativeView() const {
return offScreenView_;
}
gfx::NativeWindow OffScreenWebContentsView::GetTopLevelNativeWindow() const {
return [offScreenView_ window];
}
void OffScreenWebContentsView::PlatformCreate() {
offScreenView_ = [[OffScreenView alloc] init];
}
void OffScreenWebContentsView::PlatformDestroy() {
[offScreenView_ release];
}
} // namespace electron