#164: browser window fullscreen ; tab reload

This commit is contained in:
Cameron Kaiser 2019-02-14 17:26:06 -08:00
parent d1ed2d7757
commit eb1edd0649
5 changed files with 131 additions and 2 deletions

View File

@ -287,7 +287,14 @@
<property name="index" code="pidx" type="integer" access="r" description="The index of the browser window, ordered front to back.">
<cocoa key="orderedIndex"/>
</property>
<property name="fullscreen" code="pFls" type="boolean" access="rw" description="Whether this browser window is fullscreen.">
<cocoa key="fullscreen"/>
</property>
</class>
<command name="reload" code="104FxRld" description="Reloads an object.">
<cocoa class="NSScriptCommand"/>
<direct-parameter type="specifier" description="the object to reload"/>
</command>
<class name="tab" code="BTab" description="A %MAC_APP_NAME% browser window tab." inherits="item" plural="tabs">
<cocoa class="GeckoTab"/>
<property name="name" code="pnam" type="text" access="r" description="The name of the tab.">
@ -314,6 +321,9 @@
<responds-to name="close">
<cocoa method="handleCloseScriptCommand:"/>
</responds-to>
<responds-to name="reload">
<cocoa method="handleReloadScriptCommand:"/>
</responds-to>
<!--
<responds-to name="print">
<cocoa method="handlePrintScriptCommand:"/>

View File

@ -922,6 +922,16 @@ BrowserGlue.prototype = {
}
return array;
},
getWindowIsFullScreen : function(index) {
let win = this.getWindow(index);
if (win != null)
return win.fullScreen;
},
setWindowIsFullScreen : function(index, fullscreen) {
let win = this.getWindow(index);
if (win != null)
win.fullScreen = (fullscreen) ? true : false;
},
getTabsInWindow : function(index) {
var array = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
let win = this.getWindow(index);
@ -948,6 +958,13 @@ BrowserGlue.prototype = {
win.gBrowser.removeTab(tab);
}
},
reloadTabAtIndexInWindow : function(index, window_index) {
let win = this.getWindow(window_index);
if (win != null) {
var tab = win.gBrowser.tabs[index];
win.gBrowser.reloadTab(tab);
}
},
setCurrentTabInWindow : function(index, window_index) {
let win = this.getWindow(window_index);
if (win != null) {

View File

@ -120,6 +120,28 @@ interface nsIApplescriptService : nsISupports
* @param window_index The window's index.
*/
void closeTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
/**
* Reloads a tab in the window at the given index.
*
* @param index The tab's index.
* @param window_index The window's index.
*/
void reloadTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
/**
* Returns whether the window is fullscreen.
*
* @param index The window's index.
*/
bool getWindowIsFullScreen(in unsigned long index);
/**
* Sets whether the window is fullscreen.
*
* @param index The window's index.
*/
void setWindowIsFullScreen(in unsigned long index, in bool fullscreen);
};
[scriptable, uuid(45f087af-9c24-4fc6-9325-359382196a4e)]
@ -134,16 +156,30 @@ interface nsIApplescriptWindowCallback : nsISupports
/**
* Creates a window.
*
* @param index The tab's index.
* @param index The window's index.
*/
void createWindowAtIndex(in unsigned long index);
/**
* Closes a window (without verification).
*
* @param index The tab's index.
* @param index The window's index.
*/
void closeWindowAtIndex(in unsigned long index);
/**
* Returns whether the window is fullscreen.
*
* @param index The window's index.
*/
bool getWindowIsFullScreen(in unsigned long index);
/**
* Sets whether the window is fullscreen.
*
* @param index The window's index.
*/
void setWindowIsFullScreen(in unsigned long index, in bool fullscreen);
};
[scriptable, uuid(a433c084-ffc7-4264-90fa-82c1e0100b46)]
@ -190,4 +226,12 @@ interface nsIApplescriptTabCallback : nsISupports
* @param window_index The window's index.
*/
void closeTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
/**
* Reloads a tab in the window at the given index.
*
* @param index The tab's index.
* @param window_index The window's index.
*/
void reloadTabAtIndexInWindow(in unsigned long index, in unsigned long window_index);
};

View File

@ -142,6 +142,8 @@ typedef unsigned int NSUInteger;
- (BOOL)isZoomable;
- (BOOL)isZoomed;
- (void)setIsZoomed:(BOOL)zoomed;
- (BOOL)fullscreen;
- (void)setFullscreen:(BOOL)fullscreen;
- (id)handleCloseScriptCommand:(NSCloseCommand*)command;
@ -179,6 +181,7 @@ typedef unsigned int NSUInteger;
- (void)setURL:(NSString*)newURL;
- (id)handleCloseScriptCommand:(NSCloseCommand*)command;
- (id)handleReloadScriptCommand:(NSScriptCommand*)command;
// Helper Methods
- (void)_setWindow:(GeckoWindow*)window;
@ -482,6 +485,26 @@ static BOOL didInit = NO;
}
}
- (BOOL)fullscreen {
NS_WARNING("AppleScript: window fullscreen");
nsCOMPtr<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (applescriptService) {
bool isfs;
if (NS_SUCCEEDED(applescriptService->GetWindowIsFullScreen(mIndex, &isfs))) {
return (isfs) ? YES : NO;
}
}
return NO;
}
- (void)setFullscreen:(BOOL)fullscreen {
NS_WARNING("AppleScript: window setFullscreen");
nsCOMPtr<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (applescriptService) {
applescriptService->SetWindowIsFullScreen(mIndex, (fullscreen == YES));
}
}
- (id)handleCloseScriptCommand:(NSCloseCommand*)command {
NS_WARNING("AppleScript: window handleCloseScriptCommand");
// Try to close with the scripted handler, since it's faster. If not,
@ -852,6 +875,14 @@ static BOOL didInit = NO;
return nil;
}
- (id)handleReloadScriptCommand:(NSScriptCommand*)command {
nsCOMPtr<nsIApplescriptService> applescriptService(do_GetService("@mozilla.org/applescript-service;1"));
if (applescriptService) {
(void)applescriptService->ReloadTabAtIndexInWindow(mIndex, [mWindow orderedIndex]);
}
return nil;
}
@end
#pragma mark -

View File

@ -85,6 +85,25 @@ nsApplescriptService::CloseWindowAtIndex(uint32_t index)
return NS_OK;
}
NS_IMETHODIMP
nsApplescriptService::GetWindowIsFullScreen(uint32_t index, bool *fullscreen)
{
if (windowCallback) {
return windowCallback->GetWindowIsFullScreen(index, fullscreen);
}
*fullscreen = false;
return NS_OK;
}
NS_IMETHODIMP
nsApplescriptService::SetWindowIsFullScreen(uint32_t index, bool fullscreen)
{
if (windowCallback) {
return windowCallback->SetWindowIsFullScreen(index, fullscreen);
}
return NS_OK;
}
NS_IMETHODIMP
nsApplescriptService::GetTabsInWindow(uint32_t index, nsIArray **tabs) {
if (tabCallback) {
@ -130,6 +149,14 @@ nsApplescriptService::CloseTabAtIndexInWindow(uint32_t index, uint32_t window_in
return NS_OK;
}
NS_IMETHODIMP
nsApplescriptService::ReloadTabAtIndexInWindow(uint32_t index, uint32_t window_index) {
if (tabCallback) {
return tabCallback->ReloadTabAtIndexInWindow(index, window_index);
}
return NS_OK;
}
NS_IMETHODIMP
nsApplescriptService::RegisterWindowCallback(nsIApplescriptWindowCallback *callback) {
windowCallback = callback;