50 #include "../NativeWindowFromNode.h"
53 #include <sbFileUtils.h>
57 #include <nsICategoryManager.h>
58 #include <nsIDOMDocument.h>
59 #include <nsIDOMElement.h>
60 #include <nsIDOMWindow.h>
61 #include <nsIWindowWatcher.h>
62 #include <nsNetUtil.h>
63 #include <nsServiceManagerUtils.h>
64 #include <nsStringGlue.h>
67 #include <objc/objc-runtime.h>
89 const nsAString& aAttributeName,
90 nsAString& aAttributeValue);
93 const nsAString& aAttributeName,
97 const nsAString& aAttributeName,
102 static PRBool
SBParseColor(
const nsAString& aColorString,
153 const char* aLoaderStr,
155 const nsModuleComponentInfo* aInfo)
160 nsCOMPtr<nsICategoryManager> categoryManager =
161 do_GetService(NS_CATEGORYMANAGER_CONTRACTID,
163 NS_ENSURE_SUCCESS(rv, rv);
166 rv = categoryManager->AddCategoryEntry
173 NS_ENSURE_SUCCESS(rv, rv);
183 const char* aLoaderStr,
184 const nsModuleComponentInfo* aInfo)
189 nsCOMPtr<nsICategoryManager> categoryManager =
190 do_GetService(NS_CATEGORYMANAGER_CONTRACTID,
192 NS_ENSURE_SUCCESS(rv, rv);
195 rv = categoryManager->DeleteCategoryEntry
199 NS_ENSURE_SUCCESS(rv, rv);
219 Method origMethod = class_getInstanceMethod([
NSGrayFrame class],
220 @selector(drawRect:));
221 Method sbMethod = class_getInstanceMethod([
NSGrayFrame class],
222 @selector(_sbDrawRect:));
223 Method origPlaceholderMethod =
224 class_getInstanceMethod([
NSGrayFrame class],
@selector(_sbOrigDrawRect:));
228 origPlaceholderMethod->method_imp = origMethod->method_imp;
229 origMethod->method_imp = sbMethod->method_imp;
252 Method origMethod = class_getInstanceMethod([
NSGrayFrame class],
253 @selector(drawRect:));
254 Method origPlaceholderMethod = class_getInstanceMethod
256 @selector(_sbOrigDrawRect:));
259 origMethod->method_imp = origPlaceholderMethod->method_imp;
274 - (void)_sbDrawRect:(NSRect)aDirtyRect
281 NSColor* titlebarColor = nil;
285 NSRectFillUsingOperation([
self titlebarRect], NSCompositeSourceIn);
292 NSImage* titlebarImage = nil;
296 NSGraphicsContext* currentContext = [NSGraphicsContext currentContext];
299 [currentContext saveGraphicsState];
300 [currentContext setPatternPhase: NSMakePoint(0, titlebarTop)];
303 [[NSColor colorWithPatternImage: titlebarImage] set];
304 NSRectFillUsingOperation([
self titlebarRect], NSCompositeSourceAtop);
307 [currentContext restoreGraphicsState];
311 NSColor* textColor = nil;
317 NSFont *titleFont = [NSFont titleBarFontOfSize:0];
320 NSMutableParagraphStyle
321 *paraStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
322 [paraStyle setParagraphStyle:[NSParagraphStyle defaultParagraphStyle]];
323 [paraStyle setAlignment:NSCenterTextAlignment];
324 [paraStyle setLineBreakMode:NSLineBreakByTruncatingTail];
327 NSMutableDictionary *titleAttrs =
328 [NSMutableDictionary dictionaryWithObjectsAndKeys:
329 titleFont, NSFontAttributeName,
330 textColor, NSForegroundColorAttributeName,
331 [[paraStyle copy] autorelease], NSParagraphStyleAttributeName,
336 withAttributes: titleAttrs];
340 - (void)_sbOrigDrawRect:(NSRect)aDirtyRect
370 NS_ENSURE_ARG_POINTER(aDOMWindow);
376 nsCOMPtr<nsISimpleEnumerator> windowEnumerator;
377 nsCOMPtr<nsIWindowWatcher>
378 windowWatcher = do_GetService(
"@mozilla.org/embedcomp/window-watcher;1",
380 NS_ENSURE_SUCCESS(rv, rv);
381 rv = windowWatcher->GetWindowEnumerator(getter_AddRefs(windowEnumerator));
382 NS_ENSURE_SUCCESS(rv, rv);
387 nsCOMPtr<nsISupports> domWindow;
389 rv = windowEnumerator->HasMoreElements(&hasMoreElements);
390 NS_ENSURE_SUCCESS(rv, rv);
391 if (!hasMoreElements)
393 rv = windowEnumerator->GetNext(getter_AddRefs(domWindow));
394 NS_ENSURE_SUCCESS(rv, rv);
401 if (nativeWindow == aNativeWindow) {
402 rv = CallQueryInterface(domWindow, aDOMWindow);
403 NS_ENSURE_SUCCESS(rv, rv);
408 return NS_ERROR_NOT_AVAILABLE;
426 NS_ENSURE_ARG_POINTER(aWindow);
427 NS_ENSURE_ARG_POINTER(aColor);
433 if ([aWindow isKeyWindow]) {
435 NS_LITERAL_STRING(
"activetitlebarcolor"),
437 NS_ENSURE_SUCCESS(rv, rv);
441 NS_LITERAL_STRING(
"inactivetitlebarcolor"),
443 NS_ENSURE_SUCCESS(rv, rv);
464 NS_ENSURE_ARG_POINTER(aWindow);
465 NS_ENSURE_ARG_POINTER(aImage);
471 if ([aWindow isKeyWindow]) {
473 NS_LITERAL_STRING(
"activetitlebarimage"),
475 NS_ENSURE_SUCCESS(rv, rv);
479 NS_LITERAL_STRING(
"inactivetitlebarimage"),
481 NS_ENSURE_SUCCESS(rv, rv);
502 NS_ENSURE_ARG_POINTER(aWindow);
503 NS_ENSURE_ARG_POINTER(aColor);
509 if ([aWindow isKeyWindow]) {
511 NS_LITERAL_STRING(
"activetitlebartextcolor"),
513 NS_ENSURE_SUCCESS(rv, rv);
517 NS_LITERAL_STRING(
"inactivetitlebartextcolor"),
519 NS_ENSURE_SUCCESS(rv, rv);
537 const nsAString& aAttributeName,
538 nsAString& aAttributeValue)
541 NS_ENSURE_ARG_POINTER(aWindow);
547 aAttributeValue.Truncate();
551 nsCOMPtr<nsIDOMWindow> domWindow;
553 if (rv == NS_ERROR_NOT_AVAILABLE)
555 NS_ENSURE_SUCCESS(rv, rv);
558 nsCOMPtr<nsIDOMElement> documentElement;
559 nsCOMPtr<nsIDOMDocument> document;
560 rv = domWindow->GetDocument(getter_AddRefs(document));
561 NS_ENSURE_SUCCESS(rv, rv);
562 rv = document->GetDocumentElement(getter_AddRefs(documentElement));
563 NS_ENSURE_SUCCESS(rv, rv);
566 rv = documentElement->GetAttribute(aAttributeName, aAttributeValue);
567 NS_ENSURE_SUCCESS(rv, rv);
584 const nsAString& aAttributeName,
588 NS_ENSURE_ARG_POINTER(aWindow);
589 NS_ENSURE_ARG_POINTER(aColor);
598 nsAutoString colorString;
600 NS_ENSURE_SUCCESS(rv, rv);
601 if (colorString.IsEmpty())
610 *aColor = [NSColor colorWithDeviceRed:NS_GET_R(color)/255.0
611 green:NS_GET_G(color)/255.0
612 blue:NS_GET_B(color)/255.0
613 alpha:NS_GET_A(color)/255.0];
630 const nsAString& aAttributeName,
634 NS_ENSURE_ARG_POINTER(aWindow);
635 NS_ENSURE_ARG_POINTER(aImage);
644 nsAutoString imageURL;
646 NS_ENSURE_SUCCESS(rv, rv);
647 if (imageURL.IsEmpty())
671 nsCOMPtr<nsIURI> imageURI;
672 rv = NS_NewURI(getter_AddRefs(imageURI), aImageURL);
673 NS_ENSURE_SUCCESS(rv, nil);
676 nsCOMPtr<nsIInputStream> sourceStream;
677 rv = NS_OpenURI(getter_AddRefs(sourceStream), imageURI);
678 NS_ENSURE_SUCCESS(rv, nil);
679 sbAutoInputStream autoSourceStream(sourceStream);
684 NS_ENSURE_SUCCESS(rv, nil);
687 NSData *dataWrapper = [NSData dataWithBytes:data.BeginReading()
688 length:data.Length()];
689 NSImage *image = [[[NSImage alloc] initWithData:dataWrapper] autorelease];
710 NS_ENSURE_ARG_POINTER(aColor);
716 nsAutoString colorString(aColorString);
717 colorString.Trim(
"#", PR_TRUE, PR_FALSE);
720 PRUint32 color32 = colorString.ToInteger(&rv, 16);
725 *aColor = NS_RGBA((color32 >> 16) & 0xFF,
726 (color32 >> 8) & 0xFF,
static nsresult GetWindowAttribute(NSWindow *aWindow, const nsAString &aAttributeName, nsAString &aAttributeValue)
void _sbOrigDrawRect:(NSRect aDirtyRect)
static nsresult GetSBTitlebarImage(NSWindow *aWindow, NSImage **aImage)
static PRBool SBParseColor(const nsAString &aColorString, nscolor *aColor)
static NS_METHOD UnregisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const nsModuleComponentInfo *aInfo)
static nsresult GetSBTitlebarColor(NSWindow *aWindow, NSColor **aColor)
static NS_METHOD RegisterSelf(nsIComponentManager *aCompMgr, nsIFile *aPath, const char *aLoaderStr, const char *aType, const nsModuleComponentInfo *aInfo)
static NSImage * GetImageFromURL(const nsAString &aImageURL)
nsresult sbConsumeStream(nsIInputStream *stream, PRUint32 maxCount, nsACString &result)
#define SB_MAC_WINDOW_TITLEBAR_SERVICE_CLASSNAME
static void * get(nsISupports *window)
#define SB_MAC_WINDOW_TITLEBAR_SERVICE_CONTRACTID
SimpleArrayEnumerator prototype hasMoreElements
static nsresult GetDOMWindowFromNativeWindow(void *aNativeWindow, nsIDOMWindow **aDOMWindow)
static nsresult GetSBTitlebarTextColor(NSWindow *aWindow, NSColor **aColor)
Songbird Mac Window Titlebar Service Definitions.
NSRect _titlebarTitleRect()
virtual ~sbMacWindowTitlebarService()