From c9e838ffaf88eb6a639039e0f8f6ebb302b6e69b Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Mon, 29 Jan 2018 22:08:30 +0000 Subject: [PATCH 01/12] [Cocoa] Add `window_frame` kwarg to remove the window frame. --- webview/__init__.py | 4 +-- webview/cocoa.py | 70 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 64 insertions(+), 10 deletions(-) diff --git a/webview/__init__.py b/webview/__init__.py index f11dc47e..55f3eb9a 100755 --- a/webview/__init__.py +++ b/webview/__init__.py @@ -175,7 +175,7 @@ def load_html(content, base_uri=""): def create_window(title, url=None, js_api=None, width=800, height=600, resizable=True, fullscreen=False, min_size=(200, 100), strings={}, confirm_quit=False, - background_color='#FFFFFF', debug=False): + background_color='#FFFFFF', debug=False, window_frame=True): """ Create a web view window using a native GUI. The execution blocks after this function is invoked, so other program logic must be executed in a separate thread. @@ -199,7 +199,7 @@ def create_window(title, url=None, js_api=None, width=800, height=600, localization.update(strings) gui.create_window(_make_unicode(title), _transform_url(url), width, height, resizable, fullscreen, min_size, confirm_quit, - background_color, debug, js_api, _webview_ready) + background_color, debug, js_api, _webview_ready, window_frame) def set_title(title): """ diff --git a/webview/cocoa.py b/webview/cocoa.py index b9165b84..f8346428 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -24,6 +24,42 @@ info['NSAppTransportSecurity'] = {'NSAllowsArbitraryLoads': Foundation.YES} +class DragBar(AppKit.NSView): + def mouseDragged_(self, theEvent): + screenFrame = AppKit.NSScreen.mainScreen().frame() + if screenFrame is None: + sys.stderr.write('failed to obtain screen\n') + raise RuntimeError + + window = self.window() + windowFrame = window.frame() + if windowFrame is None: + sys.stderr.write('failed to obtain frame\n') + raise RuntimeError + + currentLocation = window.convertBaseToScreen_(window.mouseLocationOutsideOfEventStream()) + newOrigin = AppKit.NSMakePoint((currentLocation.x - self.initialLocation.x), + (currentLocation.y - self.initialLocation.y)) + if (newOrigin.y + windowFrame.size.height) > \ + (screenFrame.origin.y + screenFrame.size.height): + newOrigin.y = screenFrame.origin.y + \ + (screenFrame.size.height + windowFrame.size.height) + window.setFrameOrigin_(newOrigin) + + def mouseDown_(self, theEvent): + window = self.window() + + windowFrame = window.frame() + if windowFrame is None: + sys.stderr.write('failed to obtain frame\n') + raise RuntimeError + + self.initialLocation = \ + window.convertBaseToScreen_(theEvent.locationInWindow()) + self.initialLocation.x -= windowFrame.origin.x + self.initialLocation.y -= windowFrame.origin.y + + class BrowserView: instance = None app = AppKit.NSApplication.sharedApplication() @@ -146,7 +182,7 @@ def printView(frameview): def webView_decidePolicyForNavigationAction_request_frame_decisionListener_(self, webview, action, request, frame, listener): # The event that might have triggered the navigation event = AppKit.NSApp.currentEvent() - action_type = action['WebActionNavigationTypeKey'] + action_type = action['WebActionNavigationTypeKey'] """ Disable back navigation on pressing the Delete key: """ # Check if the requested navigation action is Back/Forward @@ -166,7 +202,14 @@ def webView_didFinishLoadForFrame_(self, webview, frame): if not webview.window(): BrowserView.instance.window.setContentView_(webview) BrowserView.instance.window.makeFirstResponder_(webview) - + + frame_size = BrowserView.instance.window.frame().size + drag_bar_height = 24 + + rect = AppKit.NSMakeRect(0, frame_size.height - drag_bar_height, frame_size.width, drag_bar_height) + drag_bar = DragBar.alloc().initWithFrame_(rect) + BrowserView.instance.window.contentView().addSubview_(drag_bar) + BrowserView.load_event.set() if BrowserView.instance.js_bridge: BrowserView.instance._set_js_api() @@ -224,7 +267,7 @@ def performKeyEquivalent_(self, theEvent): return handled - def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready): + def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, window_frame): BrowserView.instance = self BrowserView.debug = debug @@ -244,15 +287,26 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b if resizable: window_mask = window_mask | AppKit.NSResizableWindowMask + if window_frame is False: + window_mask = window_mask | AppKit.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask + self.window = AppKit.NSWindow.alloc().\ initWithContentRect_styleMask_backing_defer_(rect, window_mask, AppKit.NSBackingStoreBuffered, False) self.window.setTitle_(title) self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color)) self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1])) - # Set the titlebar color (so that it does not change with the window color) - self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) - self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect) + if window_frame is False: + self.window.setTitlebarAppearsTransparent_(True) + self.window.setMovableByWindowBackground_(True) + self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) + webkit_rect = AppKit.NSMakeRect(0, -12, width, height - 12) + else: + # Set the titlebar color (so that it does not change with the window color) + self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) + webkit_rect = rect + + self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(webkit_rect) self._browserDelegate = BrowserView.BrowserDelegate.alloc().init() self._windowDelegate = BrowserView.WindowDelegate.alloc().init() @@ -535,11 +589,11 @@ def _set_debugging(): def create_window(title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready): + confirm_quit, background_color, debug, js_api, webview_ready, window_frame): global _confirm_quit _confirm_quit = confirm_quit - browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready) + browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, window_frame) browser.show() From bf14753dd646a1d7d8a5f3837f02bc196095c74a Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Tue, 30 Jan 2018 10:41:56 +0000 Subject: [PATCH 02/12] Make the drag bar stick to the top and autoresize to the width of the view. --- webview/cocoa.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index f8346428..63b04bfa 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -206,8 +206,12 @@ def webView_didFinishLoadForFrame_(self, webview, frame): frame_size = BrowserView.instance.window.frame().size drag_bar_height = 24 - rect = AppKit.NSMakeRect(0, frame_size.height - drag_bar_height, frame_size.width, drag_bar_height) + # Flip the webview so our bar is position from the top, not bottom + webview.setFlipped_(True) + + rect = AppKit.NSMakeRect(0, 0, frame_size.width, drag_bar_height) drag_bar = DragBar.alloc().initWithFrame_(rect) + drag_bar.setAutoresizingMask_(AppKit.NSViewWidthSizable) BrowserView.instance.window.contentView().addSubview_(drag_bar) BrowserView.load_event.set() From d5a05ebd411d3f7ad3b45681afd5a1e9e09b483b Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 14 Feb 2018 13:28:23 +0000 Subject: [PATCH 03/12] Rename `window_frame` kwarg to `frameless`. --- webview/__init__.py | 5 +++-- webview/cocoa.py | 11 +++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/webview/__init__.py b/webview/__init__.py index 55f3eb9a..3f41d54a 100755 --- a/webview/__init__.py +++ b/webview/__init__.py @@ -175,7 +175,7 @@ def load_html(content, base_uri=""): def create_window(title, url=None, js_api=None, width=800, height=600, resizable=True, fullscreen=False, min_size=(200, 100), strings={}, confirm_quit=False, - background_color='#FFFFFF', debug=False, window_frame=True): + background_color='#FFFFFF', debug=False, frameless=False): """ Create a web view window using a native GUI. The execution blocks after this function is invoked, so other program logic must be executed in a separate thread. @@ -189,6 +189,7 @@ def create_window(title, url=None, js_api=None, width=800, height=600, :param strings: a dictionary with localized strings :param confirm_quit: Display a quit confirmation dialog. Default is False :param background_color: Background color as a hex string that is displayed before the content of webview is loaded. Default is white. + :param frameless: Whether the window should havea frame. :return: """ valid_color = r'^#(?:[0-9a-fA-F]{3}){1,2}$' @@ -199,7 +200,7 @@ def create_window(title, url=None, js_api=None, width=800, height=600, localization.update(strings) gui.create_window(_make_unicode(title), _transform_url(url), width, height, resizable, fullscreen, min_size, confirm_quit, - background_color, debug, js_api, _webview_ready, window_frame) + background_color, debug, js_api, _webview_ready, frameless) def set_title(title): """ diff --git a/webview/cocoa.py b/webview/cocoa.py index 63b04bfa..1e2ef860 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -271,7 +271,7 @@ def performKeyEquivalent_(self, theEvent): return handled - def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, window_frame): + def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless): BrowserView.instance = self BrowserView.debug = debug @@ -291,7 +291,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b if resizable: window_mask = window_mask | AppKit.NSResizableWindowMask - if window_frame is False: + if frameless is True: window_mask = window_mask | AppKit.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask self.window = AppKit.NSWindow.alloc().\ @@ -300,9 +300,8 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color)) self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1])) - if window_frame is False: + if frameless is True: self.window.setTitlebarAppearsTransparent_(True) - self.window.setMovableByWindowBackground_(True) self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) webkit_rect = AppKit.NSMakeRect(0, -12, width, height - 12) else: @@ -593,11 +592,11 @@ def _set_debugging(): def create_window(title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready, window_frame): + confirm_quit, background_color, debug, js_api, webview_ready, frameless): global _confirm_quit _confirm_quit = confirm_quit - browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, window_frame) + browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless) browser.show() From 1f3686f724a80d077853b18be023cfa124cbc6e9 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 23 Feb 2018 09:09:38 +0000 Subject: [PATCH 04/12] Correct typo. --- webview/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/webview/__init__.py b/webview/__init__.py index 3f41d54a..7f0f89f8 100755 --- a/webview/__init__.py +++ b/webview/__init__.py @@ -189,7 +189,7 @@ def create_window(title, url=None, js_api=None, width=800, height=600, :param strings: a dictionary with localized strings :param confirm_quit: Display a quit confirmation dialog. Default is False :param background_color: Background color as a hex string that is displayed before the content of webview is loaded. Default is white. - :param frameless: Whether the window should havea frame. + :param frameless: Whether the window should have a frame. :return: """ valid_color = r'^#(?:[0-9a-fA-F]{3}){1,2}$' From da9cb1a9f4ba3c522b0d6b955127e5d0ce45ece5 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 23 Feb 2018 09:09:51 +0000 Subject: [PATCH 05/12] Raise with message, rather than writing/raising. --- webview/cocoa.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index 1e2ef860..2f082bf6 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -51,8 +51,7 @@ def mouseDown_(self, theEvent): windowFrame = window.frame() if windowFrame is None: - sys.stderr.write('failed to obtain frame\n') - raise RuntimeError + raise RuntimeError('Failed to obtain screen') self.initialLocation = \ window.convertBaseToScreen_(theEvent.locationInWindow()) From 30f40e5a5a80ad1f101783a2fba31c70ed984814 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 23 Feb 2018 09:10:12 +0000 Subject: [PATCH 06/12] Remove pointless `is True` when checking if `frameless`. --- webview/cocoa.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index 2f082bf6..3273d6ab 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -290,7 +290,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b if resizable: window_mask = window_mask | AppKit.NSResizableWindowMask - if frameless is True: + if frameless: window_mask = window_mask | AppKit.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask self.window = AppKit.NSWindow.alloc().\ @@ -299,7 +299,7 @@ def __init__(self, title, url, width, height, resizable, fullscreen, min_size, b self.window.setBackgroundColor_(BrowserView.nscolor_from_hex(background_color)) self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1])) - if frameless is True: + if frameless: self.window.setTitlebarAppearsTransparent_(True) self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) webkit_rect = AppKit.NSMakeRect(0, -12, width, height - 12) From a793339abe5e7d2272c559ed968beaf27d6d13c3 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Fri, 23 Feb 2018 09:11:02 +0000 Subject: [PATCH 07/12] Switch `webview_ready` to be the final argument. --- webview/__init__.py | 2 +- webview/cocoa.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webview/__init__.py b/webview/__init__.py index 7f0f89f8..b90424ef 100755 --- a/webview/__init__.py +++ b/webview/__init__.py @@ -200,7 +200,7 @@ def create_window(title, url=None, js_api=None, width=800, height=600, localization.update(strings) gui.create_window(_make_unicode(title), _transform_url(url), width, height, resizable, fullscreen, min_size, confirm_quit, - background_color, debug, js_api, _webview_ready, frameless) + background_color, debug, js_api, frameless, _webview_ready) def set_title(title): """ diff --git a/webview/cocoa.py b/webview/cocoa.py index 3273d6ab..0469cde0 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -270,7 +270,7 @@ def performKeyEquivalent_(self, theEvent): return handled - def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless): + def __init__(self, title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, frameless, webview_ready): BrowserView.instance = self BrowserView.debug = debug @@ -591,11 +591,11 @@ def _set_debugging(): def create_window(title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready, frameless): + confirm_quit, background_color, debug, js_api, frameless, webview_ready): global _confirm_quit _confirm_quit = confirm_quit - browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, webview_ready, frameless) + browser = BrowserView(title, url, width, height, resizable, fullscreen, min_size, background_color, debug, js_api, frameless, webview_ready) browser.show() From 841ca88e5f0ab76002ef9ca7f9e16d36d75b2b80 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 7 Mar 2018 21:36:46 +0000 Subject: [PATCH 08/12] Create the frameless drag bar on init. --- webview/cocoa.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index 7f983002..c3ceadc6 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -212,20 +212,8 @@ def webView_didFinishLoadForFrame_(self, webview, frame): if i is not None: if not webview.window(): - i.window.setContentView_(webview) i.window.makeFirstResponder_(webview) - frame_size = i.window.frame().size - drag_bar_height = 24 - - # Flip the webview so our bar is position from the top, not bottom - webview.setFlipped_(True) - - rect = AppKit.NSMakeRect(0, 0, frame_size.width, drag_bar_height) - drag_bar = DragBar.alloc().initWithFrame_(rect) - drag_bar.setAutoresizingMask_(AppKit.NSViewWidthSizable) - i.window.contentView().addSubview_(drag_bar) - if i.js_bridge: i._set_js_api() @@ -325,11 +313,9 @@ def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_si if frameless: self.window.setTitlebarAppearsTransparent_(True) self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) - webkit_rect = AppKit.NSMakeRect(0, -12, width, height - 12) else: # Set the titlebar color (so that it does not change with the window color) self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) - webkit_rect = rect self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect).retain() @@ -342,6 +328,20 @@ def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_si self.window.setDelegate_(self._windowDelegate) BrowserView.app.setDelegate_(self._appDelegate) + self.window.setContentView_(self.webkit) + + if frameless: + frame_size = self.window.frame().size + drag_bar_height = 24 + + # Flip the webview so our bar is position from the top, not bottom + self.webkit.setFlipped_(True) + + rect = AppKit.NSMakeRect(0, 0, frame_size.width, drag_bar_height) + drag_bar = DragBar.alloc().initWithFrame_(rect) + drag_bar.setAutoresizingMask_(AppKit.NSViewWidthSizable) + self.window.contentView().addSubview_(drag_bar) + if url: self.url = url self.load_url(url) From 83cd92bac075921baa77b108cd32adc2621c2a27 Mon Sep 17 00:00:00 2001 From: Nick Barrett Date: Wed, 7 Mar 2018 21:41:21 +0000 Subject: [PATCH 09/12] Make `RuntimeError`s consistent. --- webview/cocoa.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index c3ceadc6..f862c166 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -28,14 +28,12 @@ class DragBar(AppKit.NSView): def mouseDragged_(self, theEvent): screenFrame = AppKit.NSScreen.mainScreen().frame() if screenFrame is None: - sys.stderr.write('failed to obtain screen\n') - raise RuntimeError + raise RuntimeError('Failed to obtain screen') window = self.window() windowFrame = window.frame() if windowFrame is None: - sys.stderr.write('failed to obtain frame\n') - raise RuntimeError + raise RuntimeError('Failed to obtain frame') currentLocation = window.convertBaseToScreen_(window.mouseLocationOutsideOfEventStream()) newOrigin = AppKit.NSMakePoint((currentLocation.x - self.initialLocation.x), From 3e116194ee62fe0e5c4203c1517383bdb0e3a103 Mon Sep 17 00:00:00 2001 From: Shiva Prasad Date: Sat, 24 Mar 2018 15:55:31 +0530 Subject: [PATCH 10/12] [Cocoa] Fix compatibility issues + refactor I have also made some small changes and bug fixes: * Default title bar height is 22; changed to it from 24. * We cannot not set content view of window in __init__, should be done in the load-finish delegate. Originally this was to support background color, but now a couple of other things depend on it as well. --- webview/cocoa.py | 107 +++++++++++++++++++++++++---------------------- 1 file changed, 57 insertions(+), 50 deletions(-) diff --git a/webview/cocoa.py b/webview/cocoa.py index f862c166..a1621b98 100644 --- a/webview/cocoa.py +++ b/webview/cocoa.py @@ -24,39 +24,6 @@ info['NSAppTransportSecurity'] = {'NSAllowsArbitraryLoads': Foundation.YES} -class DragBar(AppKit.NSView): - def mouseDragged_(self, theEvent): - screenFrame = AppKit.NSScreen.mainScreen().frame() - if screenFrame is None: - raise RuntimeError('Failed to obtain screen') - - window = self.window() - windowFrame = window.frame() - if windowFrame is None: - raise RuntimeError('Failed to obtain frame') - - currentLocation = window.convertBaseToScreen_(window.mouseLocationOutsideOfEventStream()) - newOrigin = AppKit.NSMakePoint((currentLocation.x - self.initialLocation.x), - (currentLocation.y - self.initialLocation.y)) - if (newOrigin.y + windowFrame.size.height) > \ - (screenFrame.origin.y + screenFrame.size.height): - newOrigin.y = screenFrame.origin.y + \ - (screenFrame.size.height + windowFrame.size.height) - window.setFrameOrigin_(newOrigin) - - def mouseDown_(self, theEvent): - window = self.window() - - windowFrame = window.frame() - if windowFrame is None: - raise RuntimeError('Failed to obtain screen') - - self.initialLocation = \ - window.convertBaseToScreen_(theEvent.locationInWindow()) - self.initialLocation.x -= windowFrame.origin.x - self.initialLocation.y -= windowFrame.origin.y - - class BrowserView: instances = {} app = AppKit.NSApplication.sharedApplication() @@ -210,6 +177,7 @@ def webView_didFinishLoadForFrame_(self, webview, frame): if i is not None: if not webview.window(): + i.window.setContentView_(webview) i.window.makeFirstResponder_(webview) if i.js_bridge: @@ -231,6 +199,49 @@ def onChange_(self, sender): option = sender.indexOfSelectedItem() self.window().setAllowedFileTypes_(self.filter[option][1]) + class DragBar(AppKit.NSView): + default_height = 22 + # Fallbacks, in case these constants are not wrapped by PyObjC + try: + NSFullSizeContentViewWindowMask = AppKit.NSFullSizeContentViewWindowMask + except AttributeError: + NSFullSizeContentViewWindowMask = 1 << 15 + try: + NSWindowTitleHidden = AppKit.NSWindowTitleHidden + except AttributeError: + NSWindowTitleHidden = 1 + + def mouseDragged_(self, theEvent): + screenFrame = AppKit.NSScreen.mainScreen().frame() + if screenFrame is None: + raise RuntimeError('Failed to obtain screen') + + window = self.window() + windowFrame = window.frame() + if windowFrame is None: + raise RuntimeError('Failed to obtain frame') + + currentLocation = window.convertBaseToScreen_(window.mouseLocationOutsideOfEventStream()) + newOrigin = AppKit.NSMakePoint((currentLocation.x - self.initialLocation.x), + (currentLocation.y - self.initialLocation.y)) + if (newOrigin.y + windowFrame.size.height) > \ + (screenFrame.origin.y + screenFrame.size.height): + newOrigin.y = screenFrame.origin.y + \ + (screenFrame.size.height + windowFrame.size.height) + window.setFrameOrigin_(newOrigin) + + def mouseDown_(self, theEvent): + window = self.window() + + windowFrame = window.frame() + if windowFrame is None: + raise RuntimeError('Failed to obtain screen') + + self.initialLocation = \ + window.convertBaseToScreen_(theEvent.locationInWindow()) + self.initialLocation.x -= windowFrame.origin.x + self.initialLocation.y -= windowFrame.origin.y + class WebKitHost(WebKit.WebView): def performKeyEquivalent_(self, theEvent): """ @@ -296,9 +307,6 @@ def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_si if resizable: window_mask = window_mask | AppKit.NSResizableWindowMask - if frameless: - window_mask = window_mask | AppKit.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask - # The allocated resources are retained because we would explicitly delete # this instance when its window is closed self.window = AppKit.NSWindow.alloc().\ @@ -308,13 +316,6 @@ def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_si self.window.setMinSize_(AppKit.NSSize(min_size[0], min_size[1])) BrowserView.cascade_loc = self.window.cascadeTopLeftFromPoint_(BrowserView.cascade_loc) - if frameless: - self.window.setTitlebarAppearsTransparent_(True) - self.window.setTitleVisibility_(AppKit.NSWindowTitleHidden) - else: - # Set the titlebar color (so that it does not change with the window color) - self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) - self.webkit = BrowserView.WebKitHost.alloc().initWithFrame_(rect).retain() self._browserDelegate = BrowserView.BrowserDelegate.alloc().init().retain() @@ -326,19 +327,25 @@ def __init__(self, uid, title, url, width, height, resizable, fullscreen, min_si self.window.setDelegate_(self._windowDelegate) BrowserView.app.setDelegate_(self._appDelegate) - self.window.setContentView_(self.webkit) - if frameless: - frame_size = self.window.frame().size - drag_bar_height = 24 + # Make content full size and titlebar transparent + window_mask = window_mask | BrowserView.DragBar.NSFullSizeContentViewWindowMask | AppKit.NSTexturedBackgroundWindowMask + self.window.setStyleMask_(window_mask) + self.window.setTitlebarAppearsTransparent_(True) + self.window.setTitleVisibility_(BrowserView.DragBar.NSWindowTitleHidden) # Flip the webview so our bar is position from the top, not bottom self.webkit.setFlipped_(True) - rect = AppKit.NSMakeRect(0, 0, frame_size.width, drag_bar_height) - drag_bar = DragBar.alloc().initWithFrame_(rect) + rect = AppKit.NSMakeRect(0, 0, width, BrowserView.DragBar.default_height) + drag_bar = BrowserView.DragBar.alloc().initWithFrame_(rect) drag_bar.setAutoresizingMask_(AppKit.NSViewWidthSizable) - self.window.contentView().addSubview_(drag_bar) + + # Add DragBar on top of the webview + self.webkit.addSubview_(drag_bar) + else: + # Set the titlebar color (so that it does not change with the window color) + self.window.contentView().superview().subviews().lastObject().setBackgroundColor_(AppKit.NSColor.windowBackgroundColor()) if url: self.url = url From e76b3f9698a195e9f246e1488acc0198034103f3 Mon Sep 17 00:00:00 2001 From: Shiva Prasad Date: Sat, 24 Mar 2018 16:10:36 +0530 Subject: [PATCH 11/12] [All] Add skeleton for frameless parameter --- webview/gtk.py | 2 +- webview/qt.py | 2 +- webview/win32.py | 2 +- webview/winforms.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/webview/gtk.py b/webview/gtk.py index 664677bc..408b16db 100755 --- a/webview/gtk.py +++ b/webview/gtk.py @@ -291,7 +291,7 @@ def create_bridge(): def create_window(uid, title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready): + confirm_quit, background_color, debug, js_api, frameless, webview_ready): def create(): browser = BrowserView(uid, title, url, width, height, resizable, fullscreen, min_size, confirm_quit, background_color, debug, js_api, webview_ready) diff --git a/webview/qt.py b/webview/qt.py index 58db6698..c0ad5e3a 100755 --- a/webview/qt.py +++ b/webview/qt.py @@ -343,7 +343,7 @@ def create_window(uid, title, url, width, height, resizable, fullscreen, min_siz def _create(): browser = BrowserView(uid, title, url, width, height, resizable, fullscreen, min_size, confirm_quit, background_color, debug, js_api, - webview_ready) + frameless, webview_ready) browser.show() if uid == 'master': diff --git a/webview/win32.py b/webview/win32.py index d5cb7524..1b741327 100644 --- a/webview/win32.py +++ b/webview/win32.py @@ -290,7 +290,7 @@ def DocumentComplete(self, *args): def create_window(uid, title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready): + confirm_quit, background_color, debug, js_api, frameless, webview_ready): set_ie_mode() browser_view = BrowserView(title, url, width, height, resizable, fullscreen, min_size, webview_ready) browser_view.show() diff --git a/webview/winforms.py b/webview/winforms.py index 74a57f3d..128543b9 100644 --- a/webview/winforms.py +++ b/webview/winforms.py @@ -204,7 +204,7 @@ def toggle_fullscreen(self): def create_window(uid, title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready): + confirm_quit, background_color, debug, js_api, frameless, webview_ready): def create(): window = BrowserView.BrowserForm(uid, title, url, width, height, resizable, fullscreen, min_size, confirm_quit, background_color, debug, js_api, webview_ready) From c109c8a28423fc3fbd4d6c74642cc283514ebbca Mon Sep 17 00:00:00 2001 From: Shiva Prasad Date: Tue, 27 Mar 2018 23:39:20 +0530 Subject: [PATCH 12/12] [Qt] Correct frameless parameter position --- webview/qt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/webview/qt.py b/webview/qt.py index c0ad5e3a..92073f21 100755 --- a/webview/qt.py +++ b/webview/qt.py @@ -337,13 +337,13 @@ def on_create_window(func): def create_window(uid, title, url, width, height, resizable, fullscreen, min_size, - confirm_quit, background_color, debug, js_api, webview_ready): + confirm_quit, background_color, debug, js_api, frameless, webview_ready): app = QApplication.instance() or QApplication([]) def _create(): browser = BrowserView(uid, title, url, width, height, resizable, fullscreen, min_size, confirm_quit, background_color, debug, js_api, - frameless, webview_ready) + webview_ready) browser.show() if uid == 'master':