2011-01-12 23:21:17 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2011 Sven Weidauer <sven.weidauer@gmail.com>
|
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#import <Cocoa/Cocoa.h>
|
|
|
|
|
2011-01-26 22:17:27 +03:00
|
|
|
#import "cocoa/gui.h"
|
2011-01-27 14:43:48 +03:00
|
|
|
#import "cocoa/plotter.h"
|
2011-01-31 22:12:00 +03:00
|
|
|
#import "cocoa/BrowserView.h"
|
|
|
|
#import "cocoa/BrowserViewController.h"
|
|
|
|
#import "cocoa/BrowserWindowController.h"
|
|
|
|
#import "cocoa/FormSelectMenu.h"
|
2014-01-23 03:19:57 +04:00
|
|
|
#import "cocoa/fetch.h"
|
2014-03-08 18:13:27 +04:00
|
|
|
#import "cocoa/schedule.h"
|
2011-01-12 23:21:17 +03:00
|
|
|
|
2013-05-26 01:46:27 +04:00
|
|
|
#import "utils/nsoption.h"
|
2011-01-17 19:18:14 +03:00
|
|
|
#import "utils/utils.h"
|
2014-01-05 21:33:08 +04:00
|
|
|
#import "utils/log.h"
|
2014-10-17 01:30:38 +04:00
|
|
|
#import "desktop/mouse.h"
|
|
|
|
#import "desktop/gui_window.h"
|
|
|
|
#import "desktop/gui_misc.h"
|
|
|
|
#import "desktop/browser_private.h"
|
|
|
|
#import "desktop/textinput.h"
|
2011-01-25 20:16:17 +03:00
|
|
|
#import "image/ico.h"
|
2011-02-24 01:27:55 +03:00
|
|
|
#import "content/fetchers/resource.h"
|
2014-02-03 22:12:44 +04:00
|
|
|
#import "content/hlcache.h"
|
|
|
|
#import "content/content.h"
|
2011-01-25 20:16:17 +03:00
|
|
|
|
2011-01-26 22:17:27 +03:00
|
|
|
NSString * const kCookiesFileOption = @"CookiesFile";
|
|
|
|
NSString * const kURLsFileOption = @"URLsFile";
|
|
|
|
NSString * const kHotlistFileOption = @"Hotlist";
|
|
|
|
NSString * const kHomepageURLOption = @"HomepageURL";
|
2011-01-27 12:01:16 +03:00
|
|
|
NSString * const kOptionsFileOption = @"ClassicOptionsFile";
|
2011-01-29 13:24:54 +03:00
|
|
|
NSString * const kAlwaysCancelDownload = @"AlwaysCancelDownload";
|
2011-01-31 11:07:22 +03:00
|
|
|
NSString * const kAlwaysCloseMultipleTabs = @"AlwaysCloseMultipleTabs";
|
2011-01-26 22:17:27 +03:00
|
|
|
|
2011-01-12 23:21:17 +03:00
|
|
|
#define UNIMPL() NSLog( @"Function '%s' unimplemented", __func__ )
|
|
|
|
|
|
|
|
struct browser_window;
|
|
|
|
|
2014-10-13 02:35:09 +04:00
|
|
|
static struct gui_window *
|
|
|
|
gui_window_create(struct browser_window *bw,
|
|
|
|
struct gui_window *existing,
|
|
|
|
gui_window_create_flags flags)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
BrowserWindowController *window = nil;
|
|
|
|
|
2014-02-09 17:07:39 +04:00
|
|
|
if (existing != NULL) {
|
2014-02-09 17:36:52 +04:00
|
|
|
bw->scale = (float) nsoption_int(scale) / 100;
|
2014-02-09 17:07:39 +04:00
|
|
|
window = [(BrowserViewController *)(existing) windowController];
|
2011-01-19 23:19:43 +03:00
|
|
|
} else {
|
2012-03-22 13:34:34 +04:00
|
|
|
bw->scale = (float) nsoption_int(scale) / 100;
|
2011-01-19 23:19:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
BrowserViewController *result = [[BrowserViewController alloc] initWithBrowser: bw];
|
|
|
|
|
2014-02-09 17:07:39 +04:00
|
|
|
if (!(flags & GW_CREATE_TAB) || nil == window) {
|
2011-09-05 16:38:56 +04:00
|
|
|
window = [[[BrowserWindowController alloc] init] autorelease];
|
|
|
|
[[window window] makeKeyAndOrderFront: nil];
|
2011-01-28 17:08:42 +03:00
|
|
|
}
|
2011-09-05 16:38:56 +04:00
|
|
|
[window addTab: result];
|
2011-01-28 17:08:42 +03:00
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
return (struct gui_window *)result;
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 02:34:12 +04:00
|
|
|
static void gui_window_destroy(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-28 17:08:42 +03:00
|
|
|
BrowserViewController *vc = (BrowserViewController *)g;
|
|
|
|
|
|
|
|
if ([vc browser]->parent != NULL) [[vc view] removeFromSuperview];
|
|
|
|
[vc release];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 14:27:41 +04:00
|
|
|
static void gui_window_set_title(struct gui_window *g, const char *title)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
[(BrowserViewController *)g setTitle: [NSString stringWithUTF8String: title]];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 03:50:54 +04:00
|
|
|
static void gui_window_redraw_window(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
[[(BrowserViewController *)g browserView] setNeedsDisplay: YES];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 03:50:54 +04:00
|
|
|
static void gui_window_update_box(struct gui_window *g, const struct rect *rect)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-08-31 15:52:08 +04:00
|
|
|
const NSRect nsrect = cocoa_scaled_rect_wh( [(BrowserViewController *)g browser]->scale,
|
2011-07-06 16:48:45 +04:00
|
|
|
rect->x0, rect->y0,
|
|
|
|
rect->x1 - rect->x0, rect->y1 - rect->y0 );
|
2011-08-31 15:52:08 +04:00
|
|
|
[[(BrowserViewController *)g browserView] setNeedsDisplayInRect: nsrect];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 05:08:15 +04:00
|
|
|
static bool gui_window_get_scroll(struct gui_window *g, int *sx, int *sy)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
|
|
|
NSCParameterAssert( g != NULL && sx != NULL && sy != NULL );
|
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
NSRect visible = [[(BrowserViewController *)g browserView] visibleRect];
|
2011-01-27 14:43:48 +03:00
|
|
|
*sx = cocoa_pt_to_px( NSMinX( visible ) );
|
|
|
|
*sy = cocoa_pt_to_px( NSMinY( visible ) );
|
2011-01-12 23:21:17 +03:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2014-01-13 05:08:15 +04:00
|
|
|
static void gui_window_set_scroll(struct gui_window *g, int sx, int sy)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-27 14:43:48 +03:00
|
|
|
[[(BrowserViewController *)g browserView] scrollPoint: cocoa_point( sx, sy )];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-06-30 19:40:56 +04:00
|
|
|
/**
|
|
|
|
* callback from core to reformat a window.
|
|
|
|
*/
|
|
|
|
static void cocoa_window_reformat(struct gui_window *gw)
|
|
|
|
{
|
|
|
|
if (gw != NULL) {
|
2014-07-06 14:01:39 +04:00
|
|
|
[[(BrowserViewController *)gw browserView] reformat ];
|
2014-06-30 19:40:56 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void gui_window_get_dimensions(struct gui_window *g,
|
|
|
|
int *width, int *height,
|
|
|
|
bool scaled)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
|
|
|
NSCParameterAssert( width != NULL && height != NULL );
|
|
|
|
|
2011-01-19 23:19:43 +03:00
|
|
|
NSRect frame = [[[(BrowserViewController *)g browserView] superview] frame];
|
2011-01-17 18:00:18 +03:00
|
|
|
if (scaled) {
|
2011-01-19 23:19:43 +03:00
|
|
|
const CGFloat scale = [(BrowserViewController *)g browser]->scale;
|
2011-01-17 18:00:18 +03:00
|
|
|
frame.size.width /= scale;
|
|
|
|
frame.size.height /= scale;
|
|
|
|
}
|
2011-01-27 14:43:48 +03:00
|
|
|
*width = cocoa_pt_to_px( NSWidth( frame ) );
|
|
|
|
*height = cocoa_pt_to_px( NSHeight( frame ) );
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 15:38:35 +04:00
|
|
|
static void gui_window_update_extent(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
BrowserViewController * const window = (BrowserViewController *)g;
|
2011-01-27 14:43:48 +03:00
|
|
|
|
|
|
|
struct browser_window *browser = [window browser];
|
|
|
|
int width = content_get_width( browser->current_content );
|
|
|
|
int height = content_get_height( browser->current_content );
|
2011-01-19 23:19:43 +03:00
|
|
|
|
2011-01-27 14:43:48 +03:00
|
|
|
[[window browserView] setMinimumSize: cocoa_scaled_size( browser->scale, width, height )];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void gui_window_set_status(struct gui_window *g, const char *text)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
[(BrowserViewController *)g setStatus: [NSString stringWithUTF8String: text]];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void gui_window_set_pointer(struct gui_window *g, gui_pointer_shape shape)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
|
|
|
switch (shape) {
|
|
|
|
case GUI_POINTER_DEFAULT:
|
|
|
|
case GUI_POINTER_WAIT:
|
|
|
|
case GUI_POINTER_PROGRESS:
|
|
|
|
[[NSCursor arrowCursor] set];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_POINTER_CROSS:
|
|
|
|
[[NSCursor crosshairCursor] set];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_POINTER_POINT:
|
2011-01-25 18:09:06 +03:00
|
|
|
case GUI_POINTER_MENU:
|
2011-01-12 23:21:17 +03:00
|
|
|
[[NSCursor pointingHandCursor] set];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GUI_POINTER_CARET:
|
|
|
|
[[NSCursor IBeamCursor] set];
|
|
|
|
break;
|
2011-02-01 10:12:47 +03:00
|
|
|
|
|
|
|
case GUI_POINTER_MOVE:
|
|
|
|
[[NSCursor closedHandCursor] set];
|
|
|
|
break;
|
2011-01-12 23:21:17 +03:00
|
|
|
|
|
|
|
default:
|
|
|
|
NSLog( @"Other cursor %d requested", shape );
|
|
|
|
[[NSCursor arrowCursor] set];
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-12 14:27:41 +04:00
|
|
|
static void gui_window_set_url(struct gui_window *g, const char *url)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
[(BrowserViewController *)g setUrl: [NSString stringWithUTF8String: url]];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 14:27:41 +04:00
|
|
|
static void gui_window_start_throbber(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-20 16:22:39 +03:00
|
|
|
[(BrowserViewController *)g setIsProcessing: YES];
|
2011-01-26 16:35:07 +03:00
|
|
|
[(BrowserViewController *)g updateBackForward];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 14:27:41 +04:00
|
|
|
static void gui_window_stop_throbber(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-20 16:22:39 +03:00
|
|
|
[(BrowserViewController *)g setIsProcessing: NO];
|
2011-01-26 16:35:07 +03:00
|
|
|
[(BrowserViewController *)g updateBackForward];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-12 21:07:34 +04:00
|
|
|
static void gui_window_set_icon(struct gui_window *g, hlcache_handle *icon)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-25 20:16:17 +03:00
|
|
|
NSBitmapImageRep *bmp = icon != NULL ? (NSBitmapImageRep *)content_get_bitmap( icon ) : NULL;
|
|
|
|
|
|
|
|
NSImage *image = nil;
|
|
|
|
if (bmp != nil) {
|
|
|
|
image = [[NSImage alloc] initWithSize: NSMakeSize( 32, 32 )];
|
|
|
|
[image addRepresentation: bmp];
|
|
|
|
} else {
|
2011-01-26 16:58:35 +03:00
|
|
|
image = [[NSImage imageNamed: @"NetSurf"] copy];
|
2011-01-25 20:16:17 +03:00
|
|
|
}
|
2011-01-26 16:58:35 +03:00
|
|
|
[image setFlipped: YES];
|
|
|
|
|
2011-01-25 20:16:17 +03:00
|
|
|
[(BrowserViewController *)g setFavicon: image];
|
|
|
|
[image release];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void gui_window_place_caret(struct gui_window *g, int x, int y, int height,
|
2013-03-06 02:53:33 +04:00
|
|
|
const struct rect *clip)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-27 14:43:48 +03:00
|
|
|
[[(BrowserViewController *)g browserView] addCaretAt: cocoa_point( x, y )
|
|
|
|
height: cocoa_px_to_pt( height )];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 18:51:27 +04:00
|
|
|
static void gui_window_remove_caret(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-19 23:19:43 +03:00
|
|
|
[[(BrowserViewController *)g browserView] removeCaret];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-01-13 02:55:26 +04:00
|
|
|
static void gui_window_new_content(struct gui_window *g)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2011-01-26 16:35:07 +03:00
|
|
|
[(BrowserViewController *)g contentUpdated];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-10-16 15:39:31 +04:00
|
|
|
static void gui_create_form_select_menu(struct gui_window *g,
|
2011-01-12 23:21:17 +03:00
|
|
|
struct form_control *control)
|
|
|
|
{
|
2014-10-16 17:45:26 +04:00
|
|
|
BrowserViewController * const window = (BrowserViewController *)g;
|
2014-10-16 17:51:24 +04:00
|
|
|
FormSelectMenu *menu = [[FormSelectMenu alloc] initWithControl: control forWindow: window->browser];
|
2014-10-16 17:45:26 +04:00
|
|
|
[menu runInView: [window browserView]];
|
2011-01-25 18:09:06 +03:00
|
|
|
[menu release];
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
2014-05-28 02:52:35 +04:00
|
|
|
static nserror gui_launch_url(nsurl *url)
|
2011-01-12 23:21:17 +03:00
|
|
|
{
|
2014-05-28 02:52:35 +04:00
|
|
|
[[NSWorkspace sharedWorkspace] openURL: [NSURL URLWithString: [NSString stringWithUTF8String: nsurl_access(url)]]];
|
2014-10-13 02:35:09 +04:00
|
|
|
return NSERROR_OK;
|
2011-01-12 23:21:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct ssl_cert_info;
|
|
|
|
|
2014-01-15 16:28:55 +04:00
|
|
|
static void gui_cert_verify(nsurl *url, const struct ssl_cert_info *certs,
|
2011-01-12 23:21:17 +03:00
|
|
|
unsigned long num, nserror (*cb)(bool proceed, void *pw),
|
|
|
|
void *cbpw)
|
|
|
|
{
|
|
|
|
cb( false, cbpw );
|
|
|
|
}
|
|
|
|
|
2014-01-05 20:01:03 +04:00
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_window_table window_table = {
|
2014-01-12 21:07:34 +04:00
|
|
|
.create = gui_window_create,
|
|
|
|
.destroy = gui_window_destroy,
|
2014-01-13 03:50:54 +04:00
|
|
|
.redraw = gui_window_redraw_window,
|
|
|
|
.update = gui_window_update_box,
|
2014-01-13 05:08:15 +04:00
|
|
|
.get_scroll = gui_window_get_scroll,
|
|
|
|
.set_scroll = gui_window_set_scroll,
|
2014-01-13 15:38:35 +04:00
|
|
|
.get_dimensions = gui_window_get_dimensions,
|
|
|
|
.update_extent = gui_window_update_extent,
|
2014-10-13 02:35:09 +04:00
|
|
|
.reformat = cocoa_window_reformat,
|
2014-01-12 21:07:34 +04:00
|
|
|
|
|
|
|
.set_title = gui_window_set_title,
|
|
|
|
.set_url = gui_window_set_url,
|
|
|
|
.set_icon = gui_window_set_icon,
|
2014-01-13 18:51:27 +04:00
|
|
|
.set_status = gui_window_set_status,
|
|
|
|
.set_pointer = gui_window_set_pointer,
|
|
|
|
.place_caret = gui_window_place_caret,
|
|
|
|
.remove_caret = gui_window_remove_caret,
|
2014-10-13 02:35:09 +04:00
|
|
|
.new_content = gui_window_new_content,
|
2014-01-12 21:07:34 +04:00
|
|
|
.start_throbber = gui_window_start_throbber,
|
|
|
|
.stop_throbber = gui_window_stop_throbber,
|
|
|
|
};
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_window_table *cocoa_window_table = &window_table;
|
|
|
|
|
2014-01-23 03:19:57 +04:00
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
static struct gui_browser_table browser_table = {
|
2014-10-13 02:35:09 +04:00
|
|
|
.schedule = cocoa_schedule,
|
2014-01-23 03:19:57 +04:00
|
|
|
|
2014-01-15 16:28:55 +04:00
|
|
|
.launch_url = gui_launch_url,
|
|
|
|
.create_form_select_menu = gui_create_form_select_menu,
|
|
|
|
.cert_verify = gui_cert_verify,
|
2014-01-11 18:20:30 +04:00
|
|
|
};
|
|
|
|
|
2014-01-15 23:37:05 +04:00
|
|
|
struct gui_browser_table *cocoa_browser_table = &browser_table;
|