-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Top autofill * Change AutofillMessagingToChildDelegate passing to WebsiteAutofillUserScript * BSK feedback * Move interface * Bump BSK to 10.0.2
- Loading branch information
1 parent
6a965c7
commit 2f3aeaa
Showing
12 changed files
with
448 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<document type="com.apple.InterfaceBuilder3.Cocoa.Storyboard.XIB" version="3.0" toolsVersion="19529" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES"> | ||
<dependencies> | ||
<deployment identifier="macosx"/> | ||
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="19529"/> | ||
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/> | ||
</dependencies> | ||
<scenes> | ||
<!--Window Controller--> | ||
<scene sceneID="Yd1-AJ-Qv8"> | ||
<objects> | ||
<windowController storyboardIdentifier="ContentOverlayWindowController" id="AYn-l1-ytb" sceneMemberID="viewController"> | ||
<window key="window" title="Window" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" restorable="NO" hasShadow="NO" visibleAtLaunch="NO" appearanceType="aqua" frameAutosaveName="" animationBehavior="default" titlebarAppearsTransparent="YES" titleVisibility="hidden" id="EcH-Hu-Dez"> | ||
<windowStyleMask key="styleMask" fullSizeContentView="YES"/> | ||
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/> | ||
<rect key="contentRect" x="2022" y="350" width="480" height="270"/> | ||
<rect key="screenRect" x="1728" y="37" width="1920" height="1055"/> | ||
<view key="contentView" id="94y-sJ-ZOB"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
</view> | ||
<connections> | ||
<outlet property="delegate" destination="AYn-l1-ytb" id="Rr5-bI-8Mg"/> | ||
</connections> | ||
</window> | ||
<connections> | ||
<segue destination="von-g3-QJ1" kind="relationship" relationship="window.shadowedContentViewController" id="nWM-ud-rJK"/> | ||
</connections> | ||
</windowController> | ||
<customObject id="e7l-sk-SA9" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="-324" y="1"/> | ||
</scene> | ||
<!--Content Overlay View Controller--> | ||
<scene sceneID="ZEN-nM-P55"> | ||
<objects> | ||
<viewController storyboardIdentifier="ContentOverlayViewController" id="von-g3-QJ1" customClass="ContentOverlayViewController" customModule="DuckDuckGo_Privacy_Browser" customModuleProvider="target" sceneMemberID="viewController"> | ||
<view key="view" appearanceType="aqua" id="ct2-uy-dYM"> | ||
<rect key="frame" x="0.0" y="0.0" width="480" height="270"/> | ||
<autoresizingMask key="autoresizingMask"/> | ||
</view> | ||
</viewController> | ||
<customObject id="KjB-z1-VQJ" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/> | ||
</objects> | ||
<point key="canvasLocation" x="409" y="1"/> | ||
</scene> | ||
</scenes> | ||
</document> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// | ||
// ContentOverlayPopover.swift | ||
// | ||
// Copyright © 2022 DuckDuckGo. All rights reserved. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
import Cocoa | ||
import WebKit | ||
import BrowserServicesKit | ||
|
||
public final class ContentOverlayPopover { | ||
|
||
public var zoomFactor: CGFloat? | ||
public weak var currentTabView: NSView? | ||
|
||
public var viewController: ContentOverlayViewController | ||
public var windowController: NSWindowController | ||
|
||
public init(currentTabView: NSView) { | ||
let storyboard = NSStoryboard(name: "ContentOverlay", bundle: Bundle.main) | ||
viewController = storyboard.instantiateController(identifier: "ContentOverlayViewController") | ||
windowController = storyboard.instantiateController(identifier: "ContentOverlayWindowController") | ||
windowController.contentViewController = viewController | ||
windowController.window?.hasShadow = true | ||
windowController.window?.acceptsMouseMovedEvents = true | ||
windowController.window?.ignoresMouseEvents = false | ||
|
||
viewController.view.wantsLayer = true | ||
if let layer = viewController.view.layer { | ||
layer.masksToBounds = true | ||
layer.cornerRadius = 6 | ||
layer.borderWidth = 0.5 | ||
layer.borderColor = CGColor.init(gray: 0, alpha: 0.3) // Looks a little lighter than 0.2 in the CSS | ||
} | ||
viewController.view.window?.backgroundColor = .clear | ||
viewController.view.window?.acceptsMouseMovedEvents = true | ||
viewController.view.window?.ignoresMouseEvents = false | ||
self.currentTabView = currentTabView | ||
} | ||
|
||
public required init?(coder: NSCoder) { | ||
fatalError("ContentOverlayPopover: Bad initializer") | ||
} | ||
} | ||
|
||
// MARK: - WebsiteAutofillUserScriptDelegate | ||
extension ContentOverlayPopover: ContentOverlayUserScriptDelegate { | ||
public func websiteAutofillUserScriptCloseOverlay(_ websiteAutofillUserScript: WebsiteAutofillUserScript?) { | ||
guard let windowController = windowController.window else { | ||
return | ||
} | ||
if !windowController.isVisible { return } | ||
// Reset window size on close to reduce flicker | ||
viewController.requestResizeToSize(CGSize(width: 0, height: 0)) | ||
windowController.parent?.removeChildWindow(windowController) | ||
windowController.orderOut(nil) | ||
} | ||
|
||
public func websiteAutofillUserScript(_ websiteAutofillUserScript: WebsiteAutofillUserScript, | ||
willDisplayOverlayAtClick: NSPoint, | ||
serializedInputContext: String, | ||
inputPosition: CGRect) { | ||
// Combines native click with offset of JS click. | ||
let y = (willDisplayOverlayAtClick.y - (inputPosition.height - inputPosition.minY)) | ||
let x = (willDisplayOverlayAtClick.x - inputPosition.minX) | ||
var rectWidth = inputPosition.width | ||
// If the field is wider we want to left assign the rectangle anchoring | ||
if inputPosition.width > 315 { | ||
rectWidth = 315 | ||
} | ||
let rect = NSRect(x: x, y: y, width: rectWidth, height: inputPosition.height) | ||
|
||
// On open initialize to default size to reduce flicker | ||
viewController.requestResizeToSize(CGSize(width: 0, height: 0)) | ||
viewController.autofillInterfaceToChild = websiteAutofillUserScript | ||
viewController.setType(serializedInputContext: serializedInputContext, zoomFactor: zoomFactor) | ||
if let overlayWindow = windowController.window, let currentTabViewWindow = currentTabView?.window { | ||
currentTabViewWindow.addChildWindow(overlayWindow, ordered: .above) | ||
let outRect = currentTabViewWindow.convertToScreen(rect) | ||
overlayWindow.setFrameTopLeftPoint(NSPoint(x: outRect.minX, y: outRect.minY)) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.