Add data backing for dev view in prefs; WIP displaying them

This commit is contained in:
anthony 2021-03-16 20:03:47 +00:00
parent 7fad95dd07
commit 9f15aa694f
6 changed files with 83 additions and 14 deletions

View File

@ -46,6 +46,7 @@ id preferencesWindowController;
-(void)showPreferencesWindow: (id)sender;
-(NSURL*)requestDownloadDestination;
-(void)openWebsite: (Website*)aWebsite;
-(void)openDeveloperFileAtPath: (NSString*)path;
-(NSString*)currentUrl;
-(BrowserWindowController*)activeBrowserWindow;
@end

View File

@ -223,7 +223,24 @@ static NSMenuItem *menuItemForItem(id item) {
return [[self activeBrowserWindow] visibleUrl];
}
-(void)openDeveloperFileAtPath: (NSString*)path {
NSString *app;
switch ([[Preferences defaultPreferences] developerViewLocation]) {
case ViewLocationTab:
case ViewLocationWindow:
case ViewLocationEditor:
app = [[NSWorkspace sharedWorkspace] getBestAppInRole: @"Viewer"
forExtension: @"txt"];
if (app == nil) {
NSLog(@"No app found to show content");
} else {
[[NSWorkspace sharedWorkspace] openFile: path withApplication: app];
}
default:
break;
}
}
@end

View File

@ -716,9 +716,6 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) {
[pb setString: [sender representedObject] forType: NSStringPboardType];
}
-(void)pageSource: (id)sender {
NSLog(@"Show page source");
}
-(void)debugRendering: (id)sender {
NSLog(@"Toggle debug rendering");
@ -726,29 +723,59 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) {
[self setNeedsDisplay: YES];
}
-(void)debugBoxTree: (id)sender {
NSLog(@"debug box tree");
char *fname = tempnam("/tmp", "netsurf_boxtree");
-(void)openDump: (NSString*)path {
NSLog(@"open result at %@", path);
[[NSApp delegate] openDeveloperFileAtPath: path];
}
-(NSString*)dumpContentType: (enum content_debug)type {
char *fname = tempnam("/tmp", "netsurf");
if (fname == NULL) {
NSLog(@"tmpnam error");
return;
return nil;
}
FILE *f = fopen(fname, "w+");
if (f == NULL) {
NSLog(@"fopen error");
return;
return nil;
}
nserror err = browser_window_debug_dump(browser, f, CONTENT_DEBUG_RENDER);
nserror err = browser_window_debug_dump(browser, f, type);
if (err != NSERROR_OK) {
NSLog(@"browser_window_debug_dump error");
}
fclose(f);
return [NSString stringWithCString: fname];
}
-(void)debugBoxTree: (id)sender {
NSLog(@"debug box tree");
[self openDump: [self dumpContentType: CONTENT_DEBUG_RENDER]];
}
-(void)debugDomTree: (id)sender {
NSLog(@"debug box tree");
char *fname = tempnam("/tmp", "netsurf_domtree");
[self openDump: [self dumpContentType: CONTENT_DEBUG_DOM]];
}
-(void)pageSource: (id)sender {
NSLog(@"Show page source");
struct hlcache_handle *hlcontent = browser_window_get_content(browser);
if (hlcontent == NULL) {
NSLog(@"get_content error");
return;
}
if (content_get_type(hlcontent) != CONTENT_HTML) {
NSLog(@"content type not html");
return;
}
size_t sz;
const uint8_t *data = content_get_source_data(hlcontent, &sz);
if (data == NULL) {
NSLog(@"get source data failed");
return;
}
char *fname = tempnam("/tmp", "netsurf");
if (fname == NULL) {
NSLog(@"tmpnam error");
return;
@ -758,11 +785,13 @@ static browser_mouse_state cocoa_mouse_flags_for_event( NSEvent *evt ) {
NSLog(@"fopen error");
return;
}
nserror err = browser_window_debug_dump(browser, f, CONTENT_DEBUG_DOM);
if (err != NSERROR_OK) {
NSLog(@"browser_window_debug_dump error");
size_t written;
if ((written = fwrite(data, sz, 1, f)) != 1) {
NSLog(@"fwrite error");
}
fclose(f);
[self openDump: [NSString stringWithCString: fname]];
}
@end

View File

@ -56,5 +56,8 @@ typedef NS_ENUM(NSInteger, PreferenceType) {
-(TabLocation)tabLocation;
-(void)setTabLocation: (TabLocation)value;
-(ViewLocation)developerViewLocation;
-(void)setDeveloperViewLocation: (ViewLocation)value;
+(Preferences*)defaultPreferences;
@end

View File

@ -12,6 +12,7 @@
#define KEY_BLANK_NEW_TABS @"blank_new_tabs"
#define KEY_ALWAYS_SHOW_TABS @"always_show_tabs"
#define KEY_TAB_LOCATION @"tab_location"
#define KEY_DEVELOPER_VIEW_LOCATION @"developer_view_location"
@interface Preferences (Private)
@ -157,6 +158,20 @@
[self notifyPreferenceUpdated: PreferenceTypeTabLocation];
}
-(ViewLocation)developerViewLocation {
if ([defaults objectForKey: KEY_DEVELOPER_VIEW_LOCATION] != nil) {
return (ViewLocation)[defaults integerForKey:
KEY_DEVELOPER_VIEW_LOCATION];
} else {
return ViewLocationWindow;
}
}
-(void)setDeveloperViewLocation: (ViewLocation)value {
[defaults setInteger: (NSInteger)value forKey:
KEY_DEVELOPER_VIEW_LOCATION];
}
+(Preferences*)defaultPreferences {
static Preferences *prefs;
if (prefs == nil) {

View File

@ -207,10 +207,14 @@
NSOnState : NSOffState];
TabLocation location = [[Preferences defaultPreferences] tabLocation];
[tabPositionButton selectItemAtIndex: (NSInteger)location];
ViewLocation viewLocation = [[Preferences defaultPreferences] developerViewLocation];
[developerViewsButton selectItemAtIndex: (NSInteger)viewLocation];
}
-(void)didPickDeveloperViews: (id)sender {
NSLog(@"didPickDeveloperViews");
ViewLocation location = (ViewLocation)[sender indexOfItem: [sender selectedItem]];
[[Preferences defaultPreferences] setDeveloperViewLocation: location];
}
-(void)didPickTabPosition: (id)sender {