diff --git a/SBrowser/Browser View/BrowserView.swift b/SBrowser/Browser View/BrowserView.swift index 4b092aa..48666c3 100644 --- a/SBrowser/Browser View/BrowserView.swift +++ b/SBrowser/Browser View/BrowserView.swift @@ -67,33 +67,41 @@ class BrowserView: UIView super.layoutSubviews() webView?.frame = bounds - if let toolbarView = toolbarView { - var toolbarSize = toolbarView.sizeThatFits(bounds.size) - - var bottomOffset: CGFloat = 0.0 - if keyboardLayoutOffset == 0 { - toolbarSize.height += safeAreaInsets.bottom - } else if toolbarView.urlBar?.textField.isFirstResponder ?? false { - bottomOffset = keyboardLayoutOffset - } - - toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize) - toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - bottomOffset) - } + var webViewContentInset = UIEdgeInsets() bringSubviewToFront(titlebarView) var titlebarHeight: CGFloat = 24.0 titlebarHeight += safeAreaInsets.top - titlebarView.frame = CGRect(origin: .zero, size: CGSize(width: bounds.width, height: titlebarHeight)) + webViewContentInset.top += titlebarView.frame.height + + if let toolbarView = toolbarView { + var toolbarSize = toolbarView.sizeThatFits(bounds.size) + + // Compact: toolbar is at the bottom + if traitCollection.horizontalSizeClass == .compact { + var bottomOffset: CGFloat = 0.0 + if keyboardLayoutOffset == 0 { + toolbarSize.height += safeAreaInsets.bottom + } else if toolbarView.urlBar?.textField.isFirstResponder ?? false { + bottomOffset = keyboardLayoutOffset + } + + toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize) + toolbarView.center = CGPoint(x: bounds.center.x, y: bounds.maxY - (toolbarView.bounds.height / 2) - bottomOffset) + webViewContentInset.bottom += toolbarView.frame.height + } else { + // Regular: toolbar is at the top + toolbarView.bounds = CGRect(origin: .zero, size: toolbarSize) + toolbarView.center = CGPoint(x: bounds.center.x, y: titlebarView.center.y + titlebarView.frame.height) + webViewContentInset.top += toolbarView.frame.height + } + } // Fix web view content insets webView?.scrollView.automaticallyAdjustsScrollIndicatorInsets = false - var webViewContentInset = UIEdgeInsets() - webViewContentInset.top = titlebarView.frame.height - webViewContentInset.bottom = toolbarView?.frame.height ?? 0 webView?.scrollView.contentInset = webViewContentInset.subtracting(safeAreaInsets) webView?.scrollView.scrollIndicatorInsets = webViewContentInset } diff --git a/SBrowser/Browser View/BrowserViewController.swift b/SBrowser/Browser View/BrowserViewController.swift index 70cdd97..77b208b 100644 --- a/SBrowser/Browser View/BrowserViewController.swift +++ b/SBrowser/Browser View/BrowserViewController.swift @@ -62,6 +62,9 @@ class BrowserViewController: UIViewController, scriptViewController.allowScriptsForTab = self.javaScriptEnabledForTab let navController = UINavigationController(rootViewController: scriptViewController) + navController.modalPresentationStyle = .popover + navController.popoverPresentationController?.sourceView = self.toolbarController.scriptControllerIconView + self.present(navController, animated: true, completion: nil) }), for: .touchUpInside) diff --git a/SBrowser/Browser View/ToolbarViewController.swift b/SBrowser/Browser View/ToolbarViewController.swift index 8846497..720cadf 100644 --- a/SBrowser/Browser View/ToolbarViewController.swift +++ b/SBrowser/Browser View/ToolbarViewController.swift @@ -82,12 +82,12 @@ class ToolbarView: UIView // Cancel button let urlBarPadding: CGFloat = 8.0 let cancelButtonSize = cancelButton.sizeThatFits(containerView.bounds.size) - cancelButton.frame = CGRect(origin: CGPoint(x: (urlBar?.frame.maxX ?? 0) + urlBarPadding, y: 0), + cancelButton.frame = CGRect(origin: CGPoint(x: (containerView.bounds.maxX - cancelButtonSize.width), y: 0), size: CGSize(width: cancelButtonSize.width, height: containerView.bounds.height)) // Toolbar buttons - let toolbarSize = buttonsView.sizeThatFits(containerView.bounds.size) - buttonsView.frame = CGRect(origin: CGPoint(x: (urlBar?.frame.maxX ?? 0) + urlBarPadding, y: 0), size: toolbarSize) + let buttonContainerSize = buttonsView.sizeThatFits(containerView.bounds.size) + buttonsView.frame = CGRect(origin: CGPoint(x: (containerView.bounds.maxX - buttonContainerSize.width) + urlBarPadding, y: 0), size: buttonContainerSize) var avoidingSize: CGSize = .zero if cancelButtonVisible { @@ -99,7 +99,7 @@ class ToolbarView: UIView cancelButton.alpha = 0.0 buttonsView.alpha = 1.0 - avoidingSize = toolbarSize + avoidingSize = buttonContainerSize } if let urlBar = urlBar {