forked from ZenBrowserMirrors/zen-desktop
feat: Completed API for cocoa, b=(no-bug), c=common
This commit is contained in:
parent
0b34cc3033
commit
3566289cb5
8 changed files with 92 additions and 34 deletions
|
@ -451,17 +451,7 @@ var gZenUIManager = {
|
|||
const [toast, reused] = this._createToastElement(messageId, options);
|
||||
this._toastContainer.removeAttribute('hidden');
|
||||
this._toastContainer.appendChild(toast);
|
||||
if (reused) {
|
||||
await this.motion.animate(toast, { scale: 0.2 }, { duration: 0.1, bounce: 0 });
|
||||
}
|
||||
if (!toast.style.hasOwnProperty('transform')) {
|
||||
toast.style.transform = 'scale(0)';
|
||||
}
|
||||
await this.motion.animate(toast, { scale: 1 }, { type: 'spring', bounce: 0.2, duration: 0.5 });
|
||||
if (this._toastTimeouts[messageId]) {
|
||||
clearTimeout(this._toastTimeouts[messageId]);
|
||||
}
|
||||
this._toastTimeouts[messageId] = setTimeout(() => {
|
||||
const timeoutFunction = () => {
|
||||
this.motion
|
||||
.animate(toast, { opacity: [1, 0], scale: [1, 0.5] }, { duration: 0.2, bounce: 0 })
|
||||
.then(() => {
|
||||
|
@ -470,7 +460,30 @@ var gZenUIManager = {
|
|||
this._toastContainer.setAttribute('hidden', true);
|
||||
}
|
||||
});
|
||||
}, options.timeout || 2000);
|
||||
};
|
||||
if (reused) {
|
||||
await this.motion.animate(toast, { scale: 0.2 }, { duration: 0.1, bounce: 0 });
|
||||
} else {
|
||||
toast.addEventListener('mouseover', () => {
|
||||
if (this._toastTimeouts[messageId]) {
|
||||
clearTimeout(this._toastTimeouts[messageId]);
|
||||
}
|
||||
});
|
||||
toast.addEventListener('mouseout', () => {
|
||||
if (this._toastTimeouts[messageId]) {
|
||||
clearTimeout(this._toastTimeouts[messageId]);
|
||||
}
|
||||
this._toastTimeouts[messageId] = setTimeout(timeoutFunction, options.timeout || 2000);
|
||||
});
|
||||
}
|
||||
if (!toast.style.hasOwnProperty('transform')) {
|
||||
toast.style.transform = 'scale(0)';
|
||||
}
|
||||
await this.motion.animate(toast, { scale: 1 }, { type: 'spring', bounce: 0.2, duration: 0.5 });
|
||||
if (this._toastTimeouts[messageId]) {
|
||||
clearTimeout(this._toastTimeouts[messageId]);
|
||||
}
|
||||
this._toastTimeouts[messageId] = setTimeout(timeoutFunction, options.timeout || 2000);
|
||||
},
|
||||
|
||||
get panelUIPosition() {
|
||||
|
|
|
@ -363,6 +363,7 @@ menuitem {
|
|||
translate: 100%;
|
||||
}
|
||||
|
||||
gap: 10px;
|
||||
z-index: 1000;
|
||||
padding: 10px;
|
||||
border-radius: 12px;
|
||||
|
@ -387,10 +388,16 @@ menuitem {
|
|||
font-size: smaller;
|
||||
}
|
||||
|
||||
& label {
|
||||
margin-top: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
& button {
|
||||
width: min-content;
|
||||
padding: 0 12px !important;
|
||||
min-width: unset !important;
|
||||
margin: 0px !important;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -82,16 +82,17 @@ ZenCommonUtils::Share(nsIURI* url, const nsACString& title,
|
|||
if (!IsSharingSupported()) {
|
||||
return NS_OK; // We don't want to throw an error here
|
||||
}
|
||||
ShareInternal(aWindow, url, title, text, aX, aY);
|
||||
return NS_OK;
|
||||
return ShareInternal(aWindow, url, title, text, aX, aY);
|
||||
}
|
||||
|
||||
void ZenCommonUtils::ShareInternal(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* url,
|
||||
nsresult ZenCommonUtils::ShareInternal(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* url,
|
||||
const nsACString& title, const nsACString& text, uint32_t aX, uint32_t aY) {
|
||||
// We shoud've had done pointer checks before, so we can assume
|
||||
// aWindow is valid.
|
||||
#ifdef ZEN_CAN_SHARE_NATIVE
|
||||
::nsZenNativeShareInternal(aWindow, url, title, text, aX, aY);
|
||||
#ifdef NS_ZEN_CAN_SHARE_NATIVE
|
||||
return ::nsZenNativeShareInternal::ShowNativeDialog(aWindow, url, title, text, aX, aY);
|
||||
#else
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -102,7 +103,7 @@ auto ZenCommonUtils::IsSharingSupported() -> bool {
|
|||
#elif defined(NS_ZEN_CAN_SHARE_NATIVE)
|
||||
return NS_ZEN_CAN_SHARE_NATIVE;
|
||||
#else
|
||||
return true;
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
|
|
@ -41,7 +41,7 @@ class ZenCommonUtils final : public nsIZenCommonUtils {
|
|||
*/
|
||||
static auto ShareInternal(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* url,
|
||||
const nsACString& title, const nsACString& text, uint32_t aX, uint32_t aY)
|
||||
-> void;
|
||||
-> nsresult;
|
||||
};
|
||||
|
||||
} // namespace zen
|
||||
|
|
|
@ -28,10 +28,9 @@ class nsZenNativeShareInternal final {
|
|||
* @param aText The text to share.
|
||||
* @returns void
|
||||
*/
|
||||
auto ShowNativeDialog(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
|
||||
const nsACString& aTitle, const nsACString& aText,
|
||||
uint32_t aX = 0, uint32_t aY = 0) const
|
||||
-> void;
|
||||
static auto ShowNativeDialog(nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
|
||||
const nsACString& aTitle, const nsACString& aText, uint32_t aX = 0, uint32_t aY = 0)
|
||||
-> nsresult;
|
||||
|
||||
nsZenNativeShareInternal() = default;
|
||||
~nsZenNativeShareInternal() = default;
|
||||
|
|
|
@ -5,18 +5,44 @@
|
|||
#include "ZenShareInternal.h"
|
||||
#include "nsCocoaUtils.h"
|
||||
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "WidgetUtils.h"
|
||||
#include "nsIWidget.h"
|
||||
|
||||
extern mozilla::LazyLogModule gCocoaUtilsLog;
|
||||
#undef LOG
|
||||
#define LOG(...) MOZ_LOG(gCocoaUtilsLog, mozilla::LogLevel::Debug, (__VA_ARGS__))
|
||||
#define LOG(...) MOZ_LOG(gCocoaUtilsLog, mozilla::LogLevel::Info, (__VA_ARGS__))
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
auto nsZenNativeShareInternal::ShowNativeDialog(
|
||||
nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
|
||||
const nsACString& aTitle, const nsACString& aText,
|
||||
uint32_t aX, uint32_t aY) const
|
||||
-> void {
|
||||
namespace zen {
|
||||
using ::mozilla::widget::WidgetUtils;
|
||||
|
||||
/**
|
||||
* Get the native NSWindow pointer from a DOM window.
|
||||
*
|
||||
* @param a_window The DOM window to get the native window from.
|
||||
* @param a_nativeWindow The pointer to the native NSWindow.
|
||||
* @return NS_OK on success, or an error code on failure.
|
||||
*/
|
||||
static nsresult GetNativeWindowPointerFromDOMWindow(mozIDOMWindowProxy* a_window,
|
||||
NSWindow** a_nativeWindow) {
|
||||
*a_nativeWindow = nil;
|
||||
if (!a_window) return NS_ERROR_INVALID_ARG;
|
||||
nsPIDOMWindowOuter* win = nsPIDOMWindowOuter::From(a_window);
|
||||
nsCOMPtr<nsIWidget> widget = WidgetUtils::DOMWindowToWidget(win);
|
||||
if (!widget) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
*a_nativeWindow = (NSWindow*)widget->GetNativeData(NS_NATIVE_WINDOW);
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
auto nsZenNativeShareInternal::ShowNativeDialog(nsCOMPtr<mozIDOMWindowProxy>& aWindow,
|
||||
nsIURI* aUrl, const nsACString& aTitle, const nsACString& aText, uint32_t aX, uint32_t aY)
|
||||
-> nsresult {
|
||||
// Just use the URL since apple doesn't support sharing text
|
||||
// and title in the share dialog
|
||||
nsAutoCString pageUrlAsStringTemp;
|
||||
|
@ -30,14 +56,22 @@ auto nsZenNativeShareInternal::ShowNativeDialog(
|
|||
NSURL* pageUrl = nsCocoaUtils::ToNSURL(
|
||||
NS_ConvertUTF8toUTF16(pageUrlAsStringTemp)
|
||||
);
|
||||
LOG("pageUrl: %s", pageUrlAsStringTemp.get());
|
||||
if (!pageUrl || (![pageUrl.scheme isEqualToString:@"https"] &&
|
||||
![pageUrl.scheme isEqualToString:@"http"])) {
|
||||
return;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NSSharingServicePicker* sharingPicker =
|
||||
[[NSSharingServicePicker alloc] initWithItems:@[ pageUrl ]];
|
||||
NSWindow* cocoaMru = nil;
|
||||
zen::GetNativeWindowPointerFromDOMWindow(aWindow, &cocoaMru);
|
||||
if (!cocoaMru) {
|
||||
LOG("ERROR: failed to get native window pointer");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
// Create a rect for the sharing picker
|
||||
NSRect rect = NSMakeRect(aX, aY, 0, 0);
|
||||
[sharingPicker showRelativeToRect:rect];
|
||||
[sharingPicker showRelativeToRect:rect
|
||||
ofView:cocoaMru.contentView
|
||||
preferredEdge:NSMinYEdge];
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
|
@ -6,4 +6,7 @@ SOURCES += [
|
|||
|
||||
LOCAL_INCLUDES += [
|
||||
"../",
|
||||
"/widget",
|
||||
"/widget/cocoa",
|
||||
"/xpcom/base",
|
||||
]
|
|
@ -9,7 +9,7 @@ auto nsZenNativeShareInternal::ShowNativeDialog(
|
|||
nsCOMPtr<mozIDOMWindowProxy>& aWindow, nsIURI* aUrl,
|
||||
const nsACString& aTitle, const nsACString& aText,
|
||||
uint32_t aX, uint32_t aY) const
|
||||
-> void {
|
||||
-> nsresult {
|
||||
nsAutoCString urlString;
|
||||
if (aUrl) {
|
||||
nsresult rv = aUrl->GetSpec(urlString);
|
||||
|
@ -21,4 +21,5 @@ auto nsZenNativeShareInternal::ShowNativeDialog(
|
|||
(void)WindowsUIUtils::Share(NS_ConvertUTF8toUTF16_MaybeVoid(aTitle),
|
||||
NS_ConvertUTF8toUTF16_MaybeVoid(aText),
|
||||
NS_ConvertUTF8toUTF16_MaybeVoid(urlString));
|
||||
return NS_OK;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue