File: WebKitView.m

package info (click to toggle)
mediainfo 25.04-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,124 kB
  • sloc: cpp: 18,542; objc: 3,089; sh: 1,417; xml: 1,268; python: 319; makefile: 214; perl: 207
file content (54 lines) | stat: -rw-r--r-- 2,055 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//
//  WebKitView.m
//  MediaInfo
//
//  Created by Maxime Gervais on 20/04/2021.
//  Copyright © 2021 MediaArea.net SARL. All rights reserved.
//

#import "WebKitView.h"

@implementation WebKitView

-(void)initialize {
    WKWebViewConfiguration *configuration=[[WKWebViewConfiguration alloc] init];

    webView = [[WKWebView alloc] initWithFrame:CGRectZero configuration:configuration];
    [self addSubview:webView];

    webView.UIDelegate = self;

    // Fix bug with WKWebKit on macOS < 12 where background color
    // doesn't follows the system theme
    if (@available(macOS 12, *)) {}
    else if (@available(macOS 10.14, *)) { // First macOS version that support dark theme
        [webView setValue:@(NO) forKey:@"drawsBackground"];
        [self setValue: NSColor.controlBackgroundColor forKey:@"backgroundColor"];
    }

    [webView setTranslatesAutoresizingMaskIntoConstraints:false];
    [NSLayoutConstraint constraintWithItem:self attribute: NSLayoutAttributeTop relatedBy: NSLayoutRelationEqual toItem:webView attribute:NSLayoutAttributeTop multiplier:1.0 constant:0.0].active = true;
    [NSLayoutConstraint constraintWithItem:self attribute: NSLayoutAttributeBottom relatedBy: NSLayoutRelationEqual toItem:webView attribute:NSLayoutAttributeBottom multiplier:1.0 constant:0.0].active = true;
    [NSLayoutConstraint constraintWithItem:self attribute: NSLayoutAttributeLeading relatedBy: NSLayoutRelationEqual toItem:webView attribute:NSLayoutAttributeLeading multiplier:1.0 constant:0.0].active = true;
    [NSLayoutConstraint constraintWithItem:self attribute: NSLayoutAttributeTrailing relatedBy: NSLayoutRelationEqual toItem:webView attribute:NSLayoutAttributeTrailing multiplier:1.0 constant:0.0].active = true;
}

-(void)dealloc {
    [webView release];
    [super dealloc];
}

-(instancetype)initWithCoder:(NSCoder *)coder {
    self = [super initWithCoder:coder];

    if (self)
        [self initialize];

    return self;
}

-(void)setContent:(NSString *)content {
    [webView loadHTMLString:content baseURL:nil];
}

@end