Skip to content

Commit

Permalink
Merge pull request ViennaRSS#504 from barijaona/bugfixes
Browse files Browse the repository at this point in the history
Smoother Unified layout
  • Loading branch information
josh64x2 committed Aug 29, 2015
2 parents 505cc87 + 0a2acf8 commit 89b298d
Showing 1 changed file with 54 additions and 66 deletions.
120 changes: 54 additions & 66 deletions src/UnifiedDisplayView.m
Original file line number Diff line number Diff line change
Expand Up @@ -294,74 +294,63 @@ - (void)webViewLoadFinished:(NSNotification *)notification
{
ArticleCellView * cell = (ArticleCellView *)objView;
NSUInteger row= [articleList rowForView:objView];
// get the height of the rendered frame.
// I have tested many NSHeight([[ ... ] frame]) tricks, but they were unreliable
// and using DOM to get documentElement scrollHeight and/or offsetHeight was the simplest
// way to get the height with WebKit
// Ref : http://james.padolsey.com/javascript/get-document-height-cross-browser/
//
// this temporary enable Javascript if it is not enabled, then reset to preference
[[sender preferences] setJavaScriptEnabled:YES];
NSString* outputHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"];
NSString* bodyHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
NSString* clientHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.documentElement.clientHeight"];
[[sender preferences] setJavaScriptEnabled:[[Preferences standardPreferences] useJavaScript]];
CGFloat fittingHeight = [outputHeight floatValue];

//get the rect of the current webview frame
NSRect webViewRect = [sender frame];
//calculate the new frame
NSRect newWebViewRect = NSMakeRect(XPOS_IN_CELL,
YPOS_IN_CELL,
NSWidth(webViewRect),
fittingHeight);
//set the new frame to the webview
[sender setFrame:newWebViewRect];
if (row == [cell articleRow] && row < [[articleController allArticles] count]
&& [cell folderId] == [[[articleController allArticles] objectAtIndex:row] folderId])
{ //relevant cell
if ([bodyHeight isEqualToString:outputHeight] && [bodyHeight isEqualToString:clientHeight]) {
if (row < [rowHeightArray count])
[rowHeightArray replaceObjectAtIndex:row withObject:[NSNumber numberWithFloat:fittingHeight]];
else
{ NSInteger toAdd = row - [rowHeightArray count] ;
for (NSInteger i = 0 ; i < toAdd ; i++) {
[rowHeightArray addObject:[NSNumber numberWithFloat:DEFAULT_CELL_HEIGHT]];
}
[rowHeightArray addObject:[NSNumber numberWithFloat:fittingHeight]];
}
[cell setInProgress:NO];
[articleList noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
}
else
{
// something in the dimensions went wrong : force a reload
[self resubmitWebView:sender];
}
}
else { //non relevant cell
[cell setInProgress:NO];
[articleList reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}
NSString* outputHeight;
NSString* bodyHeight;
NSString* clientHeight;
CGFloat fittingHeight;
do // loop until dimensions are OK
{
// get the height of the rendered frame.
// I have tested many NSHeight([[ ... ] frame]) tricks, but they were unreliable
// and using DOM to get documentElement scrollHeight and/or offsetHeight was the simplest
// way to get the height with WebKit
// Ref : http://james.padolsey.com/javascript/get-document-height-cross-browser/
//
// this temporary enable Javascript if it is not enabled, then reset to preference
[[sender preferences] setJavaScriptEnabled:YES];
outputHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.documentElement.scrollHeight"];
bodyHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"];
clientHeight = [sender stringByEvaluatingJavaScriptFromString:@"document.documentElement.clientHeight"];
[[sender preferences] setJavaScriptEnabled:[[Preferences standardPreferences] useJavaScript]];
fittingHeight = [outputHeight floatValue];
//get the rect of the current webview frame
NSRect webViewRect = [sender frame];
//calculate the new frame
NSRect newWebViewRect = NSMakeRect(XPOS_IN_CELL,
YPOS_IN_CELL,
NSWidth(webViewRect),
fittingHeight);
//set the new frame to the webview
[sender setFrame:newWebViewRect];
} while (![bodyHeight isEqualToString:outputHeight] || ![bodyHeight isEqualToString:clientHeight]);

if (row < [rowHeightArray count])
[rowHeightArray replaceObjectAtIndex:row withObject:[NSNumber numberWithFloat:fittingHeight]];
else
{ NSInteger toAdd = row - [rowHeightArray count] ;
for (NSInteger i = 0 ; i < toAdd ; i++)
{
[rowHeightArray addObject:[NSNumber numberWithFloat:DEFAULT_CELL_HEIGHT]];
}
[rowHeightArray addObject:[NSNumber numberWithFloat:fittingHeight]];
}
[cell setInProgress:NO];
[articleList noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
}
else { //non relevant cell
[cell setInProgress:NO];
[articleList reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}
} else {
// not an ArticleCellView anymore
// ???
}
}
}

-(void)resubmitWebView:(WebView *)sender
{
ArticleCellView * cell = (ArticleCellView *)[sender superview];
NSUInteger row = [articleList rowForView:cell];
if (cell != nil)
{
[self webViewLoadFinished:[NSNotification notificationWithName:WebViewProgressFinishedNotification object:sender]];
}
else
[articleList reloadDataForRowIndexes:[NSIndexSet indexSetWithIndex:row] columnIndexes:[NSIndexSet indexSetWithIndex:0]];
}

/* updateAlternateMenuTitle
* Sets the approprate title for the alternate item in the contextual menu
* when user changes preference for opening pages in external browser
Expand Down Expand Up @@ -901,12 +890,6 @@ - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn
{
if (![tableView isEqualTo:articleList])
return nil;
NSArray * allArticles = [articleController allArticles];

Article * theArticle = [allArticles objectAtIndex:row];
NSInteger articleFolderId = [theArticle folderId];
Folder * folder = [[Database sharedManager] folderFromID:articleFolderId];
NSString * feedURL = SafeString([folder feedURL]);

ArticleCellView *cellView = (ArticleCellView*)[tableView makeViewWithIdentifier:LISTVIEW_CELL_IDENTIFIER owner:self];

Expand All @@ -917,12 +900,17 @@ - (NSView *)tableView:(NSTableView *)tableView viewForTableColumn:(NSTableColumn
cellView.identifier = LISTVIEW_CELL_IDENTIFIER;
}

ArticleView * view = [cellView articleView];
NSArray * allArticles = [articleController allArticles];
Article * theArticle = [allArticles objectAtIndex:row];
NSInteger articleFolderId = [theArticle folderId];
Folder * folder = [[Database sharedManager] folderFromID:articleFolderId];
NSString * feedURL = SafeString([folder feedURL]);

[cellView setFolderId:articleFolderId];
[cellView setArticleRow:row];
[cellView setListView:articleList];
ArticleView * view = [cellView articleView];
NSString * htmlText = [view articleTextFromArray:[NSArray arrayWithObject:theArticle]];
[cellView setInProgress:YES];
[view setHTML:htmlText withBase:feedURL];
[cellView addSubview:view];
return cellView;
Expand Down

0 comments on commit 89b298d

Please sign in to comment.