adium 2852:7ff6b3f336d6: Instead of inserting a <hr/> when we lo...

commits at adium.im commits at adium.im
Mon Nov 2 23:31:46 UTC 2009


details:	http://hg.adium.im/adium/rev/7ff6b3f336d6
revision:	2852:7ff6b3f336d6
author:		Zachary West <zacw at adium.im>
date:		Mon Nov 02 18:30:22 2009 -0500

Instead of inserting a <hr/> when we lose focus, which ends up breaking more than you'd expect, add a message class for the next message. Fixes #13300.

This removes the "Show Focus Lines" preference (always a good thing), and always inserts the mark in the scrollbar. It will be up to the style to implement the "focus" class to show the location. All previous messages of class "focus" will have "focus" removed when focus is lost again.

diffs (140 lines):

diff -r b7529bc734c5 -r 7ff6b3f336d6 Plugins/Dual Window Interface/AIJumpControlPlugin.h
--- a/Plugins/Dual Window Interface/AIJumpControlPlugin.h	Sun Nov 01 18:31:30 2009 -0500
+++ b/Plugins/Dual Window Interface/AIJumpControlPlugin.h	Mon Nov 02 18:30:22 2009 -0500
@@ -11,8 +11,6 @@
 	NSMenuItem		*menuItem_next;
 	NSMenuItem		*menuItem_focus;
 	NSMenuItem		*menuItem_add;
-	
-	NSMenuItem		*menuItem_focusLine;
 }
 
 @end
diff -r b7529bc734c5 -r 7ff6b3f336d6 Plugins/Dual Window Interface/AIJumpControlPlugin.m
--- a/Plugins/Dual Window Interface/AIJumpControlPlugin.m	Sun Nov 01 18:31:30 2009 -0500
+++ b/Plugins/Dual Window Interface/AIJumpControlPlugin.m	Mon Nov 02 18:30:22 2009 -0500
@@ -53,13 +53,6 @@
 												   keyEquivalent:@""];
 	
 	[adium.menuController addMenuItem:menuItem_add toLocation:LOC_Display_Jump];
-	
-	menuItem_focusLine = [[NSMenuItem alloc] initWithTitle:AILocalizedString(@"Show Focus Lines", "Shows the focus lines inside the chats")
-													target:self
-													action:@selector(showFocusLines:)
-											 keyEquivalent:@""];
-	
-	[adium.menuController addMenuItem:menuItem_focusLine toLocation:LOC_Display_MessageControl];
 }
 
 - (void)uninstallPlugin
@@ -79,8 +72,6 @@
 		return [self.currentController nextMarkExists];
 	} else if (menuItem == menuItem_focus) {
 		return [self.currentController focusMarkExists];
-	} else if (menuItem == menuItem_focusLine) {
-		[menuItem setState:[[adium.preferenceController preferenceForKey:PREF_KEY_FOCUS_LINE group:PREF_GROUP_GENERAL] boolValue]];
 	}
 	
 	return (nil != adium.interfaceController.activeChat);
@@ -111,11 +102,4 @@
 	[self.currentController addMark];
 }
 
-- (void)showFocusLines:(id)sender
-{
-	[adium.preferenceController setPreference:[NSNumber numberWithBool:![sender state]]
-									   forKey:PREF_KEY_FOCUS_LINE 
-									    group:PREF_GROUP_GENERAL];
-}
-
 @end
diff -r b7529bc734c5 -r 7ff6b3f336d6 Plugins/WebKit Message View/AIWebKitMessageViewController.h
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.h	Sun Nov 01 18:31:30 2009 -0500
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.h	Mon Nov 02 18:30:22 2009 -0500
@@ -47,6 +47,9 @@
 	NSImage						*imageMask;
 	NSMutableArray				*objectsWithUserIconsArray;
 	NSMutableDictionary			*objectIconPathDict;
+	
+	//Focus tracking
+	BOOL						nextMessageFocus;
 }
 
 /*!
diff -r b7529bc734c5 -r 7ff6b3f336d6 Plugins/WebKit Message View/AIWebKitMessageViewController.m
--- a/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Sun Nov 01 18:31:30 2009 -0500
+++ b/Plugins/WebKit Message View/AIWebKitMessageViewController.m	Mon Nov 02 18:30:22 2009 -0500
@@ -94,6 +94,7 @@
 
 @interface DOMDocument (FutureWebKitPublicMethodsIKnow)
 - (DOMNodeList *)getElementsByClassName:(NSString *)className;
+- (DOMNodeList *)querySelectorAll:(NSString *)selectors; // We require 10.5.8/Safari 4, all is well!
 @end
 
 static NSArray *draggedTypes = nil;
@@ -472,6 +473,7 @@
 	[self.markedScroller removeAllMarks];
 	[previousContent release];
 	previousContent = nil;
+	nextMessageFocus = NO;
 	[chat clearUnviewedContentCount];
 }
 
@@ -679,6 +681,12 @@
 			[self markCurrentLocation];
 		}
 		
+		// Set it as a focus if appropriate.
+		if (nextMessageFocus && [content.type isEqualToString:CONTENT_MESSAGE_TYPE]) {
+			[content addDisplayClass:@"focus"];
+			nextMessageFocus = NO;
+		}
+		
 		//Add the content object
 		[self _appendContent:content 
 					 similar:similar
@@ -1451,18 +1459,23 @@
 	[scroller removeMarkWithIdentifier:@"focus"];
 	[scroller addMarkAt:[self.currentOffsetHeight integerValue] withIdentifier:@"focus" withColor:[NSColor redColor]];	
 	
-	DOMElement *element = (DOMElement *)[webView.mainFrameDocument getElementById:@"focus"];
-	if (element) {
-		[element.parentNode removeChild:element];
+	nextMessageFocus = YES;
+	
+	DOMNodeList *nodeList = [webView.mainFrameDocument querySelectorAll:@".focus"];
+	DOMHTMLElement *node = nil; NSMutableArray *classes = nil;
+	for (NSUInteger i = 0; i < nodeList.length; i++)
+	{
+		node = (DOMHTMLElement *)[nodeList item:i];
+		classes = [[node.className componentsSeparatedByString:@" "] mutableCopy];
+		
+		[classes removeObject:@"focus"];
+		
+		node.className = [classes componentsJoinedByString:@" "];
+		
+		[classes release];
 	}
 	
-	if ([[adium.preferenceController preferenceForKey:PREF_KEY_FOCUS_LINE group:PREF_GROUP_GENERAL] boolValue]) {
-		element = [webView.mainFrameDocument createElement:@"hr"];
-		[element setAttribute:@"id" value:@"focus"];
-
-		[element setAttribute:@"style" value:[NSString stringWithFormat:@"position: absolute; top: %dpx;", self.currentOffsetHeight.integerValue - 1]];
-		[[(DOMHTMLDocument *)webView.mainFrameDocument body] appendChild:element];
-	}
+	nextMessageFocus = YES;
 }
 
 - (void)addMark
diff -r b7529bc734c5 -r 7ff6b3f336d6 Plugins/WebKit Message View/Template.html
--- a/Plugins/WebKit Message View/Template.html	Sun Nov 01 18:31:30 2009 -0500
+++ b/Plugins/WebKit Message View/Template.html	Mon Nov 02 18:30:22 2009 -0500
@@ -319,7 +319,6 @@
 		.actionMessageUserName { display:none; }
 		.actionMessageBody:before { content:"*"; }
 		.actionMessageBody:after { content:"*"; }
-		hr#focus { border: 0; border-bottom: 1px solid red; width: 25%%; margin: 0 auto 0 auto; }
 		* { word-wrap:break-word; }
 		img.scaledToFitImage { height: auto; max-width: 100%%; }
 	</style>




More information about the commits mailing list