This commit is contained in:
hewitt%netscape.com 2002-05-02 12:08:47 +00:00
Родитель c164b4533c
Коммит a3e21f4672
74 изменённых файлов: 3082 добавлений и 78 удалений

Просмотреть файл

@ -112,6 +112,10 @@ public:
static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild);
static void BookmarkChanged(nsIContent* aItem);
static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild);
static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void DeleteBookmark(nsIDOMElement* aBookmark);
public:
static void GetRootContent(nsIContent** aResult);
@ -131,6 +135,12 @@ public:
static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref);
static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder);
static NSImage* CreateIconForBookmark(nsIDOMElement* aElement);
static void DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent);
static void CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt, nsIDOMElement* aBeforeElt, int aPosition);
public:
// Global counter and pointers to our singletons.
@ -149,6 +159,10 @@ public:
static nsIAtom* gBookmarkAtom;
static nsIDocument* gBookmarks;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;
static int CHInsertBefore;
static int CHInsertAfter;
private:
// There are three kinds of bookmarks data sources:

Просмотреть файл

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#import "CHBrowserView.h"
#include "BookmarksService.h"
#import "BookmarksService.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIAtom.h"
@ -469,6 +469,63 @@
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
- (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
BookmarkItem* beforeItem = nil;
nsCOMPtr<nsIDOMElement> beforeElt;
nsCOMPtr<nsIDOMElement> folderElt;
nsCOMPtr<nsIContent> folderContent;
if (index == NSOutlineViewDropOnItemIndex)
return NO;
// get the folder element
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(folderContent));
else
folderContent = [item contentNode];
folderElt = do_QueryInterface(folderContent);
// get the element to insert before, if there is one
PRInt32 childCount = 0;
folderContent->ChildCount(childCount);
if (index < childCount)
beforeItem = [[outlineView dataSource] outlineView:outlineView child:index ofItem:item];
if (beforeItem)
beforeElt = do_QueryInterface([beforeItem contentNode]);
// insert the dragged stuff into bookmarks
BookmarksService::CompleteBookmarkDrag([info draggingPasteboard], folderElt, beforeElt,
BookmarksService::CHInsertBefore);
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView*)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
NSMutableArray* contentIds = [NSMutableArray array];
for (int i = 0; i < [items count]; ++i) {
nsCOMPtr<nsIContent> content = [[items objectAtIndex:i] contentNode];
PRUint32 contentId;
content->GetContentID(&contentId);
[contentIds addObject:[NSNumber numberWithInt:contentId]];
}
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:outlineView];
[pboard setPropertyList:contentIds forType:@"MozBookmarkType"];
return YES;
}
@end
@implementation BookmarkItem
@ -527,6 +584,10 @@ nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
nsIAtom* BookmarksService::gHrefAtom = nsnull;
nsIAtom* BookmarksService::gNameAtom = nsnull;
nsVoidArray* BookmarksService::gInstances = nsnull;
int BookmarksService::CHInsertNone = 0;
int BookmarksService::CHInsertInto = 1;
int BookmarksService::CHInsertBefore = 2;
int BookmarksService::CHInsertAfter = 3;
BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
{
@ -756,6 +817,74 @@ BookmarksService::RemoveObserver()
}
}
void
BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
// XXX if no folder provided, default to root folder
if (!aFolder) return;
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
nsCOMPtr<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle);
elt->SetAttribute(NS_LITERAL_STRING("href"), aURL);
MoveBookmarkToFolder(elt, aFolder, aBeforeElt);
}
void
BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
if (!aBookmark || !aFolder) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
nsCOMPtr<nsIDOMNode> dummy;
if (oldParent) {
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
}
if (aBeforeElt) {
aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy));
} else {
aFolder->AppendChild(aBookmark, getter_AddRefs(dummy));
}
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(aFolder));
if (oldParent) {
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
BookmarkAdded(parentContent, childContent);
}
void
BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark)
{
if (!aBookmark) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
if (oldParent) {
nsCOMPtr<nsIDOMNode> dummy;
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
}
void
BookmarksService::FlushBookmarks()
{
@ -1202,3 +1331,81 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
[aTabView selectTabViewItemAtIndex: 0];
[[[[aTabView tabViewItemAtIndex: 0] view] getBrowserView] setActive: YES];
}
NSImage*
BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
{
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
content->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom)
return [NSImage imageNamed:@"folder"];
nsAutoString group;
aElement->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty())
return [NSImage imageNamed:@"smallgroup"];
return [NSImage imageNamed:@"groupbookmark"];
}
void
BookmarksService::DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent)
{
NSPasteboard *pboard;
NSString* title;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
PRUint32 contentId;
content->GetContentID(&contentId);
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:aView];
[pboard setPropertyList:[NSArray arrayWithObject:[NSNumber numberWithInt:contentId]] forType:@"MozBookmarkType"];
nsAutoString nameStr;
aElement->GetAttribute(NS_LITERAL_STRING("name"), nameStr);
title = [NSString stringWithCharacters: nameStr.get() length: nsCRT::strlen(nameStr.get())];
[aView dragImage: [MainController createImageForDragging: CreateIconForBookmark(aElement) title:title]
at:NSMakePoint(0,0) offset:NSMakeSize(0,0)
event:aEvent pasteboard:pboard source:aView slideBack:YES];
}
void
BookmarksService::CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt,
nsIDOMElement* aBeforeElt, int aPosition)
{
NSArray* contentIds;
nsCOMPtr<nsIDOMElement> beforeElt = aBeforeElt;
if (aPosition == BookmarksService::CHInsertAfter && aBeforeElt) {
nsCOMPtr<nsIDOMNode> beforeNode;
aBeforeElt->GetNextSibling(getter_AddRefs(beforeNode));
beforeElt = do_QueryInterface(beforeNode);
}
if (aPosition == BookmarksService::CHInsertInto) {
aFolderElt = aBeforeElt;
beforeElt = nsnull;
}
// check for recognized drag types
contentIds = [aPasteboard propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
MoveBookmarkToFolder(bookmarkElt, aFolderElt, beforeElt);
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [aPasteboard propertyListForType: @"MozURLType"];
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
AddBookmarkToFolder(url, title, aFolderElt, beforeElt);
}
}

6
camino/BrowserWindow.nib/classes.nib сгенерированный
Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

16
camino/BrowserWindow.nib/info.nib сгенерированный
Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
camino/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -83,9 +83,8 @@
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
NSMenu* menu = BookmarksService::LocateMenu(content);
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
}
else
[super mouseDown: aEvent];
} else
[super mouseDown:aEvent];
}
-(void)setElement: (nsIDOMElement*)aElt
@ -128,4 +127,17 @@
return mElement;
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void) mouseDragged: (NSEvent*) aEvent
{
// XXX mouseDragged is never called because buttons cancel dragging while you mouse down
// I have to fix this in an ugly way, by doing the "click" stuff myself and never relying
// on the superclass for that. Bah!
BookmarksService::DragBookmark(mElement, self, aEvent);
}
@end

Просмотреть файл

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@implementation CHBookmarksOutlineView
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete) {
NSArray* contentIds = nil;
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
contentIds = [pboard propertyListForType:@"MozBookmarkType"];
if (contentIds) {
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
BookmarksService::DeleteBookmark(bookmarkElt);
}
}
}
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
unsigned int result = [super draggingSourceOperationMaskForLocal:flag];
if (flag == NO)
result &= NSDragOperationDelete;
return result;
}
@end

Просмотреть файл

@ -26,10 +26,13 @@
class nsIDOMElement;
class BookmarksService;
class CHBookmarksButton;
@interface CHBookmarksToolbar : NSView {
BookmarksService* mBookmarks;
NSMutableArray* mButtons;
CHBookmarksButton* mDragInsertionButton;
int mDragInsertionPosition;
}
-(void)initializeToolbar;
@ -45,4 +48,7 @@ class BookmarksService;
-(void)showBookmarksToolbar: (BOOL)aShow;
- (void) setButtonInsertionPoint:(NSPoint)aPoint;
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition;
@end

Просмотреть файл

@ -25,6 +25,7 @@
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
@implementation CHBookmarksToolbar
@ -32,6 +33,9 @@
if ( (self = [super initWithFrame:frame]) ) {
mBookmarks = nsnull;
mButtons = [[NSMutableArray alloc] init];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
return self;
}
@ -70,6 +74,12 @@
// The buttons will paint themselves. Just call our base class method.
[super drawRect: aRect];
// draw a separator at drag n drop insertion point if there is one
if (mDragInsertionPosition) {
[[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set];
NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]);
}
}
-(void)buildButtonList
@ -240,4 +250,100 @@
// [self reflowButtons];
}
- (void)setButtonInsertionPoint:(NSPoint)aPoint
{
int count = [mButtons count];
mDragInsertionButton = nsnull;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
for (int i = 0; i < count; ++i) {
CHBookmarksButton* button = [mButtons objectAtIndex: i];
//NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y);
// XXX origin.y is coming up zero here! Need that to check the row we're dragging in :(
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> contentNode = do_QueryInterface([button element]);
contentNode->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom) {
if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertInto;
return;
}
} else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertBefore;
return;
} else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
return;
}
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
[self setButtonInsertionPoint:[sender draggingLocation]];
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarksService::CompleteBookmarkDrag([sender draggingPasteboard], BookmarksService::gToolbarRoot,
mDragInsertionButton ? [mDragInsertionButton element] : nil,
mDragInsertionPosition);
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return YES;
}
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition
{
if (aPosition == BookmarksService::CHInsertInto) {
return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y,
[aButton frame].size.width, [aButton frame].size.height);
} else if (aPosition == BookmarksService::CHInsertAfter) {
return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y,
2, [aButton frame].size.height);
} else {// if (aPosition == BookmarksService::CHInsertBefore) {
return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y,
2, [aButton frame].size.height);
}
}
@end

Просмотреть файл

@ -30,4 +30,6 @@
- (BOOL)autoHides;
- (void)setAutoHides:(BOOL)newSetting;
-(void)addTabForURL:(NSString*)aURL;
@end

217
camino/CHExtendedTabView.mm Normal file
Просмотреть файл

@ -0,0 +1,217 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import "CHExtendedTabView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsCRT.h"
//////////////////////////
// NEEDS IMPLEMENTED : Implement drag tracking for moving tabs around.
// Implementation hints : Track drags ;)
// : Change tab controlTint to indicate drag location?
// : Move tab titles around when dragging.
//////////////////////////
@interface CHExtendedTabView (Private)
- (void)showOrHideTabsAsAppropriate;
@end
@implementation CHExtendedTabView
/******************************************/
/*** Initialization ***/
/******************************************/
- (id)initWithFrame:(NSRect)frameRect
{
if ( (self = [super initWithFrame:frameRect]) ) {
autoHides = YES;
}
return self;
}
- (void)awakeFromNib
{
[self showOrHideTabsAsAppropriate];
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
/******************************************/
/*** Overridden Methods ***/
/******************************************/
- (BOOL)isOpaque
{
if ( ([self tabViewType] == NSNoTabsBezelBorder) && (NSAppKitVersionNumber < 633) ) {
return NO;
} else {
return [super isOpaque];
}
}
- (void)addTabViewItem:(NSTabViewItem *)tabViewItem
{
[super addTabViewItem:tabViewItem];
[self showOrHideTabsAsAppropriate];
}
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem
{
[super removeTabViewItem:tabViewItem];
[self showOrHideTabsAsAppropriate];
}
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem atIndex:(int)index
{
[super insertTabViewItem:tabViewItem atIndex:index];
[self showOrHideTabsAsAppropriate];
}
/******************************************/
/*** Accessor Methods ***/
/******************************************/
- (BOOL)autoHides
{
return autoHides;
}
- (void)setAutoHides:(BOOL)newSetting
{
autoHides = newSetting;
}
/******************************************/
/*** Instance Methods ***/
/******************************************/
// 03-03-2002 mlj: Modifies tab view size and type appropriately... Fragile.
// Only to be used with the 2 types of tab view which we use in Chimera.
- (void)showOrHideTabsAsAppropriate
{
// if ( autoHides == YES ) {
if ( [[self tabViewItems] count] < 2) {
if ( [self tabViewType] != NSNoTabsBezelBorder ) {
[self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) + 10 )];
}
[self setTabViewType:NSNoTabsBezelBorder];
} else {
if ( [self tabViewType] != NSTopTabsBezelBorder ) {
[self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) - 10 )];
}
[self setTabViewType:NSTopTabsBezelBorder];
}
[self display];
// }
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSArray* contentIds;
NSTabViewItem* overTabViewItem = nil;
BOOL overContentArea = NO;
// determine if we are over a tab or the content area
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
overTabViewItem = [self tabViewItemAtPoint: localPoint];
overContentArea = NSPointInRect(localPoint, [self contentRect]);
// check for recognized drag types
contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
int i = 0;
// drag type is chimera bookmarks
for (i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: url]
flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI:[NSURL URLWithString: url]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
if (overTabViewItem || overContentArea) {
[[[overTabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: [data objectForKey:@"url"]]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:[data objectForKey:@"url"]];
}
return YES;
}
-(void)addTabForURL:(NSString*)aURL
{
NSTabViewItem* tabViewItem;
CHBrowserWrapper* newView;
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
[tabViewItem setLabel: @"Untitled"];
[tabViewItem setView: newView];
[self addTabViewItem: tabViewItem];
[[[tabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: aURL]
flags: NSLoadFlagsNone];
}
@end

31
camino/CHPageProxyIcon.h Normal file
Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <Cocoa/Cocoa.h>
@interface CHPageProxyIcon : NSImageView
{
}
@end

79
camino/CHPageProxyIcon.mm Normal file
Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHPageProxyIcon.h"
#import "BookmarksService.h"
#import "MainController.h"
@implementation CHPageProxyIcon
- (void) resetCursorRects
{
NSCursor* cursor;
// XXX provide image for drag-hand cursor
cursor = [NSCursor arrowCursor];
[self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor];
[cursor setOnMouseEntered:YES];
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// need to implement this or else mouseDragged isn't called
}
- (void) mouseDragged: (NSEvent*) event
{
NSPasteboard *pboard;
NSDictionary* data;
NSArray* dataVals;
NSArray* dataKeys;
NSString* url;
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
dataVals = [NSArray arrayWithObjects: url, title, nil];
dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil];
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)
event: event pasteboard: pboard source: self slideBack: YES];
}
@end

Просмотреть файл

@ -21,6 +21,7 @@
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
@ -404,6 +405,8 @@
F52D5CD9027D3D5001A80166,
F52F87CF027D75C301A80165,
F52F87D0027D75C301A80165,
2E293A01027F33604B000102,
2EEC3E63028138724B000102,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -500,6 +503,8 @@
F52D5CDA027D3D5001A80166,
F52F87D1027D75C301A80165,
F52F87D2027D75C301A80165,
2E293A02027F33604B000102,
2EEC3E64028138724B000102,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -532,6 +537,67 @@
//292
//293
//294
//2E0
//2E1
//2E2
//2E3
//2E4
2E2939FF027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.mm;
refType = 4;
};
2E293A00027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.h;
refType = 4;
};
2E293A01027F33604B000102 = {
fileRef = 2E293A00027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2E293A02027F33604B000102 = {
fileRef = 2E2939FF027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
refType = 4;
};
2EEC3E62028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.mm;
refType = 4;
};
2EEC3E63028138724B000102 = {
fileRef = 2EEC3E61028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E64028138724B000102 = {
fileRef = 2EEC3E62028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
//2E0
//2E1
//2E2
//2E3
//2E4
//4A0
//4A1
//4A2
@ -917,6 +983,7 @@
F57074B5026BA85F01A80166,
F57074B9026BFD0101A80166,
F57074BD026D80DF01A80166,
2E293A00027F33604B000102,
F5607CB5023944AD01A967DF,
F59E9F3D0237E28401A967DF,
F5137A1102676B9101026D05,
@ -1993,11 +2060,14 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -2636,7 +2706,7 @@
};
F5BF71460231B8BC010001CA = {
isa = PBXFileReference;
path = CHExtendedTabView.m;
path = CHExtendedTabView.mm;
refType = 4;
};
F5BF71510231DC5D010001CA = {

Просмотреть файл

@ -34,7 +34,8 @@ http://chimera.mozdev.org\
\f3\b Patrick Beard\
Ugo Dantas De Santana\
Simon Fraser\
Ben Goodger
Ben Goodger\
Joe Hewitt
\f2\b0 \
\f3\b David Hyatt

6
camino/English.lproj/BrowserWindow.nib/classes.nib сгенерированный
Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

16
camino/English.lproj/BrowserWindow.nib/info.nib сгенерированный
Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
camino/English.lproj/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -121,4 +121,6 @@ class BookmarksService;
- (IBAction)showAboutBox:(id)sender;
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
@end

Просмотреть файл

@ -454,4 +454,34 @@ static PRBool gSetupSmoothTextMenu = PR_FALSE;
//XXX do nothing for now
}
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
{
NSImage* image;
NSSize titleSize, imageSize;
NSRect imageRect;
NSDictionary* stringAttrs;
// get the size of the new image we are creating
titleSize = [aTitle sizeWithAttributes:nil];
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
titleSize.height > [aIcon size].height ?
titleSize.height : [aIcon size].height);
// create the image and lock drawing focus on it
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
[image lockFocus];
// draw the image and title in image with translucency
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
forKey: NSForegroundColorAttributeName];
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
[image unlockFocus];
return image;
}
@end

Просмотреть файл

@ -21,6 +21,7 @@
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
@ -404,6 +405,8 @@
F52D5CD9027D3D5001A80166,
F52F87CF027D75C301A80165,
F52F87D0027D75C301A80165,
2E293A01027F33604B000102,
2EEC3E63028138724B000102,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -500,6 +503,8 @@
F52D5CDA027D3D5001A80166,
F52F87D1027D75C301A80165,
F52F87D2027D75C301A80165,
2E293A02027F33604B000102,
2EEC3E64028138724B000102,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -532,6 +537,67 @@
//292
//293
//294
//2E0
//2E1
//2E2
//2E3
//2E4
2E2939FF027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.mm;
refType = 4;
};
2E293A00027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.h;
refType = 4;
};
2E293A01027F33604B000102 = {
fileRef = 2E293A00027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2E293A02027F33604B000102 = {
fileRef = 2E2939FF027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
refType = 4;
};
2EEC3E62028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.mm;
refType = 4;
};
2EEC3E63028138724B000102 = {
fileRef = 2EEC3E61028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E64028138724B000102 = {
fileRef = 2EEC3E62028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
//2E0
//2E1
//2E2
//2E3
//2E4
//4A0
//4A1
//4A2
@ -917,6 +983,7 @@
F57074B5026BA85F01A80166,
F57074B9026BFD0101A80166,
F57074BD026D80DF01A80166,
2E293A00027F33604B000102,
F5607CB5023944AD01A967DF,
F59E9F3D0237E28401A967DF,
F5137A1102676B9101026D05,
@ -1993,11 +2060,14 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -2636,7 +2706,7 @@
};
F5BF71460231B8BC010001CA = {
isa = PBXFileReference;
path = CHExtendedTabView.m;
path = CHExtendedTabView.mm;
refType = 4;
};
F5BF71510231DC5D010001CA = {

Просмотреть файл

@ -34,7 +34,8 @@ http://chimera.mozdev.org\
\f3\b Patrick Beard\
Ugo Dantas De Santana\
Simon Fraser\
Ben Goodger
Ben Goodger\
Joe Hewitt
\f2\b0 \
\f3\b David Hyatt

Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -121,4 +121,6 @@ class BookmarksService;
- (IBAction)showAboutBox:(id)sender;
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
@end

Просмотреть файл

@ -454,4 +454,34 @@ static PRBool gSetupSmoothTextMenu = PR_FALSE;
//XXX do nothing for now
}
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
{
NSImage* image;
NSSize titleSize, imageSize;
NSRect imageRect;
NSDictionary* stringAttrs;
// get the size of the new image we are creating
titleSize = [aTitle sizeWithAttributes:nil];
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
titleSize.height > [aIcon size].height ?
titleSize.height : [aIcon size].height);
// create the image and lock drawing focus on it
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
[image lockFocus];
// draw the image and title in image with translucency
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
forKey: NSForegroundColorAttributeName];
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
[image unlockFocus];
return image;
}
@end

Просмотреть файл

@ -83,9 +83,8 @@
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
NSMenu* menu = BookmarksService::LocateMenu(content);
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
}
else
[super mouseDown: aEvent];
} else
[super mouseDown:aEvent];
}
-(void)setElement: (nsIDOMElement*)aElt
@ -128,4 +127,17 @@
return mElement;
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void) mouseDragged: (NSEvent*) aEvent
{
// XXX mouseDragged is never called because buttons cancel dragging while you mouse down
// I have to fix this in an ugly way, by doing the "click" stuff myself and never relying
// on the superclass for that. Bah!
BookmarksService::DragBookmark(mElement, self, aEvent);
}
@end

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <AppKit/AppKit.h>
#import "CHExtendedOutlineView.h"
@interface CHBookmarksOutlineView : CHExtendedOutlineView {
}
@end

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@implementation CHBookmarksOutlineView
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete) {
NSArray* contentIds = nil;
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
contentIds = [pboard propertyListForType:@"MozBookmarkType"];
if (contentIds) {
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
BookmarksService::DeleteBookmark(bookmarkElt);
}
}
}
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
unsigned int result = [super draggingSourceOperationMaskForLocal:flag];
if (flag == NO)
result &= NSDragOperationDelete;
return result;
}
@end

Просмотреть файл

@ -112,6 +112,10 @@ public:
static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild);
static void BookmarkChanged(nsIContent* aItem);
static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild);
static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void DeleteBookmark(nsIDOMElement* aBookmark);
public:
static void GetRootContent(nsIContent** aResult);
@ -131,6 +135,12 @@ public:
static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref);
static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder);
static NSImage* CreateIconForBookmark(nsIDOMElement* aElement);
static void DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent);
static void CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt, nsIDOMElement* aBeforeElt, int aPosition);
public:
// Global counter and pointers to our singletons.
@ -149,6 +159,10 @@ public:
static nsIAtom* gBookmarkAtom;
static nsIDocument* gBookmarks;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;
static int CHInsertBefore;
static int CHInsertAfter;
private:
// There are three kinds of bookmarks data sources:

Просмотреть файл

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#import "CHBrowserView.h"
#include "BookmarksService.h"
#import "BookmarksService.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIAtom.h"
@ -469,6 +469,63 @@
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
- (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
BookmarkItem* beforeItem = nil;
nsCOMPtr<nsIDOMElement> beforeElt;
nsCOMPtr<nsIDOMElement> folderElt;
nsCOMPtr<nsIContent> folderContent;
if (index == NSOutlineViewDropOnItemIndex)
return NO;
// get the folder element
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(folderContent));
else
folderContent = [item contentNode];
folderElt = do_QueryInterface(folderContent);
// get the element to insert before, if there is one
PRInt32 childCount = 0;
folderContent->ChildCount(childCount);
if (index < childCount)
beforeItem = [[outlineView dataSource] outlineView:outlineView child:index ofItem:item];
if (beforeItem)
beforeElt = do_QueryInterface([beforeItem contentNode]);
// insert the dragged stuff into bookmarks
BookmarksService::CompleteBookmarkDrag([info draggingPasteboard], folderElt, beforeElt,
BookmarksService::CHInsertBefore);
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView*)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
NSMutableArray* contentIds = [NSMutableArray array];
for (int i = 0; i < [items count]; ++i) {
nsCOMPtr<nsIContent> content = [[items objectAtIndex:i] contentNode];
PRUint32 contentId;
content->GetContentID(&contentId);
[contentIds addObject:[NSNumber numberWithInt:contentId]];
}
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:outlineView];
[pboard setPropertyList:contentIds forType:@"MozBookmarkType"];
return YES;
}
@end
@implementation BookmarkItem
@ -527,6 +584,10 @@ nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
nsIAtom* BookmarksService::gHrefAtom = nsnull;
nsIAtom* BookmarksService::gNameAtom = nsnull;
nsVoidArray* BookmarksService::gInstances = nsnull;
int BookmarksService::CHInsertNone = 0;
int BookmarksService::CHInsertInto = 1;
int BookmarksService::CHInsertBefore = 2;
int BookmarksService::CHInsertAfter = 3;
BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
{
@ -756,6 +817,74 @@ BookmarksService::RemoveObserver()
}
}
void
BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
// XXX if no folder provided, default to root folder
if (!aFolder) return;
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
nsCOMPtr<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle);
elt->SetAttribute(NS_LITERAL_STRING("href"), aURL);
MoveBookmarkToFolder(elt, aFolder, aBeforeElt);
}
void
BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
if (!aBookmark || !aFolder) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
nsCOMPtr<nsIDOMNode> dummy;
if (oldParent) {
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
}
if (aBeforeElt) {
aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy));
} else {
aFolder->AppendChild(aBookmark, getter_AddRefs(dummy));
}
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(aFolder));
if (oldParent) {
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
BookmarkAdded(parentContent, childContent);
}
void
BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark)
{
if (!aBookmark) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
if (oldParent) {
nsCOMPtr<nsIDOMNode> dummy;
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
}
void
BookmarksService::FlushBookmarks()
{
@ -1202,3 +1331,81 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
[aTabView selectTabViewItemAtIndex: 0];
[[[[aTabView tabViewItemAtIndex: 0] view] getBrowserView] setActive: YES];
}
NSImage*
BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
{
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
content->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom)
return [NSImage imageNamed:@"folder"];
nsAutoString group;
aElement->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty())
return [NSImage imageNamed:@"smallgroup"];
return [NSImage imageNamed:@"groupbookmark"];
}
void
BookmarksService::DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent)
{
NSPasteboard *pboard;
NSString* title;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
PRUint32 contentId;
content->GetContentID(&contentId);
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:aView];
[pboard setPropertyList:[NSArray arrayWithObject:[NSNumber numberWithInt:contentId]] forType:@"MozBookmarkType"];
nsAutoString nameStr;
aElement->GetAttribute(NS_LITERAL_STRING("name"), nameStr);
title = [NSString stringWithCharacters: nameStr.get() length: nsCRT::strlen(nameStr.get())];
[aView dragImage: [MainController createImageForDragging: CreateIconForBookmark(aElement) title:title]
at:NSMakePoint(0,0) offset:NSMakeSize(0,0)
event:aEvent pasteboard:pboard source:aView slideBack:YES];
}
void
BookmarksService::CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt,
nsIDOMElement* aBeforeElt, int aPosition)
{
NSArray* contentIds;
nsCOMPtr<nsIDOMElement> beforeElt = aBeforeElt;
if (aPosition == BookmarksService::CHInsertAfter && aBeforeElt) {
nsCOMPtr<nsIDOMNode> beforeNode;
aBeforeElt->GetNextSibling(getter_AddRefs(beforeNode));
beforeElt = do_QueryInterface(beforeNode);
}
if (aPosition == BookmarksService::CHInsertInto) {
aFolderElt = aBeforeElt;
beforeElt = nsnull;
}
// check for recognized drag types
contentIds = [aPasteboard propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
MoveBookmarkToFolder(bookmarkElt, aFolderElt, beforeElt);
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [aPasteboard propertyListForType: @"MozURLType"];
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
AddBookmarkToFolder(url, title, aFolderElt, beforeElt);
}
}

Просмотреть файл

@ -26,10 +26,13 @@
class nsIDOMElement;
class BookmarksService;
class CHBookmarksButton;
@interface CHBookmarksToolbar : NSView {
BookmarksService* mBookmarks;
NSMutableArray* mButtons;
CHBookmarksButton* mDragInsertionButton;
int mDragInsertionPosition;
}
-(void)initializeToolbar;
@ -45,4 +48,7 @@ class BookmarksService;
-(void)showBookmarksToolbar: (BOOL)aShow;
- (void) setButtonInsertionPoint:(NSPoint)aPoint;
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition;
@end

Просмотреть файл

@ -25,6 +25,7 @@
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
@implementation CHBookmarksToolbar
@ -32,6 +33,9 @@
if ( (self = [super initWithFrame:frame]) ) {
mBookmarks = nsnull;
mButtons = [[NSMutableArray alloc] init];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
return self;
}
@ -70,6 +74,12 @@
// The buttons will paint themselves. Just call our base class method.
[super drawRect: aRect];
// draw a separator at drag n drop insertion point if there is one
if (mDragInsertionPosition) {
[[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set];
NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]);
}
}
-(void)buildButtonList
@ -240,4 +250,100 @@
// [self reflowButtons];
}
- (void)setButtonInsertionPoint:(NSPoint)aPoint
{
int count = [mButtons count];
mDragInsertionButton = nsnull;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
for (int i = 0; i < count; ++i) {
CHBookmarksButton* button = [mButtons objectAtIndex: i];
//NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y);
// XXX origin.y is coming up zero here! Need that to check the row we're dragging in :(
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> contentNode = do_QueryInterface([button element]);
contentNode->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom) {
if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertInto;
return;
}
} else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertBefore;
return;
} else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
return;
}
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
[self setButtonInsertionPoint:[sender draggingLocation]];
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarksService::CompleteBookmarkDrag([sender draggingPasteboard], BookmarksService::gToolbarRoot,
mDragInsertionButton ? [mDragInsertionButton element] : nil,
mDragInsertionPosition);
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return YES;
}
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition
{
if (aPosition == BookmarksService::CHInsertInto) {
return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y,
[aButton frame].size.width, [aButton frame].size.height);
} else if (aPosition == BookmarksService::CHInsertAfter) {
return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y,
2, [aButton frame].size.height);
} else {// if (aPosition == BookmarksService::CHInsertBefore) {
return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y,
2, [aButton frame].size.height);
}
}
@end

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <Cocoa/Cocoa.h>
@interface CHPageProxyIcon : NSImageView
{
}
@end

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHPageProxyIcon.h"
#import "BookmarksService.h"
#import "MainController.h"
@implementation CHPageProxyIcon
- (void) resetCursorRects
{
NSCursor* cursor;
// XXX provide image for drag-hand cursor
cursor = [NSCursor arrowCursor];
[self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor];
[cursor setOnMouseEntered:YES];
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// need to implement this or else mouseDragged isn't called
}
- (void) mouseDragged: (NSEvent*) event
{
NSPasteboard *pboard;
NSDictionary* data;
NSArray* dataVals;
NSArray* dataKeys;
NSString* url;
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
dataVals = [NSArray arrayWithObjects: url, title, nil];
dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil];
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)
event: event pasteboard: pboard source: self slideBack: YES];
}
@end

Просмотреть файл

@ -112,6 +112,10 @@ public:
static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild);
static void BookmarkChanged(nsIContent* aItem);
static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild);
static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void DeleteBookmark(nsIDOMElement* aBookmark);
public:
static void GetRootContent(nsIContent** aResult);
@ -131,6 +135,12 @@ public:
static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref);
static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder);
static NSImage* CreateIconForBookmark(nsIDOMElement* aElement);
static void DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent);
static void CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt, nsIDOMElement* aBeforeElt, int aPosition);
public:
// Global counter and pointers to our singletons.
@ -149,6 +159,10 @@ public:
static nsIAtom* gBookmarkAtom;
static nsIDocument* gBookmarks;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;
static int CHInsertBefore;
static int CHInsertAfter;
private:
// There are three kinds of bookmarks data sources:

Просмотреть файл

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#import "CHBrowserView.h"
#include "BookmarksService.h"
#import "BookmarksService.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIAtom.h"
@ -469,6 +469,63 @@
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
- (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
BookmarkItem* beforeItem = nil;
nsCOMPtr<nsIDOMElement> beforeElt;
nsCOMPtr<nsIDOMElement> folderElt;
nsCOMPtr<nsIContent> folderContent;
if (index == NSOutlineViewDropOnItemIndex)
return NO;
// get the folder element
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(folderContent));
else
folderContent = [item contentNode];
folderElt = do_QueryInterface(folderContent);
// get the element to insert before, if there is one
PRInt32 childCount = 0;
folderContent->ChildCount(childCount);
if (index < childCount)
beforeItem = [[outlineView dataSource] outlineView:outlineView child:index ofItem:item];
if (beforeItem)
beforeElt = do_QueryInterface([beforeItem contentNode]);
// insert the dragged stuff into bookmarks
BookmarksService::CompleteBookmarkDrag([info draggingPasteboard], folderElt, beforeElt,
BookmarksService::CHInsertBefore);
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView*)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
NSMutableArray* contentIds = [NSMutableArray array];
for (int i = 0; i < [items count]; ++i) {
nsCOMPtr<nsIContent> content = [[items objectAtIndex:i] contentNode];
PRUint32 contentId;
content->GetContentID(&contentId);
[contentIds addObject:[NSNumber numberWithInt:contentId]];
}
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:outlineView];
[pboard setPropertyList:contentIds forType:@"MozBookmarkType"];
return YES;
}
@end
@implementation BookmarkItem
@ -527,6 +584,10 @@ nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
nsIAtom* BookmarksService::gHrefAtom = nsnull;
nsIAtom* BookmarksService::gNameAtom = nsnull;
nsVoidArray* BookmarksService::gInstances = nsnull;
int BookmarksService::CHInsertNone = 0;
int BookmarksService::CHInsertInto = 1;
int BookmarksService::CHInsertBefore = 2;
int BookmarksService::CHInsertAfter = 3;
BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
{
@ -756,6 +817,74 @@ BookmarksService::RemoveObserver()
}
}
void
BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
// XXX if no folder provided, default to root folder
if (!aFolder) return;
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
nsCOMPtr<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle);
elt->SetAttribute(NS_LITERAL_STRING("href"), aURL);
MoveBookmarkToFolder(elt, aFolder, aBeforeElt);
}
void
BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
if (!aBookmark || !aFolder) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
nsCOMPtr<nsIDOMNode> dummy;
if (oldParent) {
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
}
if (aBeforeElt) {
aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy));
} else {
aFolder->AppendChild(aBookmark, getter_AddRefs(dummy));
}
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(aFolder));
if (oldParent) {
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
BookmarkAdded(parentContent, childContent);
}
void
BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark)
{
if (!aBookmark) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
if (oldParent) {
nsCOMPtr<nsIDOMNode> dummy;
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
}
void
BookmarksService::FlushBookmarks()
{
@ -1202,3 +1331,81 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
[aTabView selectTabViewItemAtIndex: 0];
[[[[aTabView tabViewItemAtIndex: 0] view] getBrowserView] setActive: YES];
}
NSImage*
BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
{
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
content->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom)
return [NSImage imageNamed:@"folder"];
nsAutoString group;
aElement->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty())
return [NSImage imageNamed:@"smallgroup"];
return [NSImage imageNamed:@"groupbookmark"];
}
void
BookmarksService::DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent)
{
NSPasteboard *pboard;
NSString* title;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
PRUint32 contentId;
content->GetContentID(&contentId);
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:aView];
[pboard setPropertyList:[NSArray arrayWithObject:[NSNumber numberWithInt:contentId]] forType:@"MozBookmarkType"];
nsAutoString nameStr;
aElement->GetAttribute(NS_LITERAL_STRING("name"), nameStr);
title = [NSString stringWithCharacters: nameStr.get() length: nsCRT::strlen(nameStr.get())];
[aView dragImage: [MainController createImageForDragging: CreateIconForBookmark(aElement) title:title]
at:NSMakePoint(0,0) offset:NSMakeSize(0,0)
event:aEvent pasteboard:pboard source:aView slideBack:YES];
}
void
BookmarksService::CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt,
nsIDOMElement* aBeforeElt, int aPosition)
{
NSArray* contentIds;
nsCOMPtr<nsIDOMElement> beforeElt = aBeforeElt;
if (aPosition == BookmarksService::CHInsertAfter && aBeforeElt) {
nsCOMPtr<nsIDOMNode> beforeNode;
aBeforeElt->GetNextSibling(getter_AddRefs(beforeNode));
beforeElt = do_QueryInterface(beforeNode);
}
if (aPosition == BookmarksService::CHInsertInto) {
aFolderElt = aBeforeElt;
beforeElt = nsnull;
}
// check for recognized drag types
contentIds = [aPasteboard propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
MoveBookmarkToFolder(bookmarkElt, aFolderElt, beforeElt);
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [aPasteboard propertyListForType: @"MozURLType"];
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
AddBookmarkToFolder(url, title, aFolderElt, beforeElt);
}
}

6
chimera/BrowserWindow.nib/classes.nib сгенерированный
Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

16
chimera/BrowserWindow.nib/info.nib сгенерированный
Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
chimera/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -83,9 +83,8 @@
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
NSMenu* menu = BookmarksService::LocateMenu(content);
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
}
else
[super mouseDown: aEvent];
} else
[super mouseDown:aEvent];
}
-(void)setElement: (nsIDOMElement*)aElt
@ -128,4 +127,17 @@
return mElement;
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void) mouseDragged: (NSEvent*) aEvent
{
// XXX mouseDragged is never called because buttons cancel dragging while you mouse down
// I have to fix this in an ugly way, by doing the "click" stuff myself and never relying
// on the superclass for that. Bah!
BookmarksService::DragBookmark(mElement, self, aEvent);
}
@end

Просмотреть файл

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@implementation CHBookmarksOutlineView
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete) {
NSArray* contentIds = nil;
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
contentIds = [pboard propertyListForType:@"MozBookmarkType"];
if (contentIds) {
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
BookmarksService::DeleteBookmark(bookmarkElt);
}
}
}
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
unsigned int result = [super draggingSourceOperationMaskForLocal:flag];
if (flag == NO)
result &= NSDragOperationDelete;
return result;
}
@end

Просмотреть файл

@ -26,10 +26,13 @@
class nsIDOMElement;
class BookmarksService;
class CHBookmarksButton;
@interface CHBookmarksToolbar : NSView {
BookmarksService* mBookmarks;
NSMutableArray* mButtons;
CHBookmarksButton* mDragInsertionButton;
int mDragInsertionPosition;
}
-(void)initializeToolbar;
@ -45,4 +48,7 @@ class BookmarksService;
-(void)showBookmarksToolbar: (BOOL)aShow;
- (void) setButtonInsertionPoint:(NSPoint)aPoint;
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition;
@end

Просмотреть файл

@ -25,6 +25,7 @@
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
@implementation CHBookmarksToolbar
@ -32,6 +33,9 @@
if ( (self = [super initWithFrame:frame]) ) {
mBookmarks = nsnull;
mButtons = [[NSMutableArray alloc] init];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
return self;
}
@ -70,6 +74,12 @@
// The buttons will paint themselves. Just call our base class method.
[super drawRect: aRect];
// draw a separator at drag n drop insertion point if there is one
if (mDragInsertionPosition) {
[[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set];
NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]);
}
}
-(void)buildButtonList
@ -240,4 +250,100 @@
// [self reflowButtons];
}
- (void)setButtonInsertionPoint:(NSPoint)aPoint
{
int count = [mButtons count];
mDragInsertionButton = nsnull;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
for (int i = 0; i < count; ++i) {
CHBookmarksButton* button = [mButtons objectAtIndex: i];
//NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y);
// XXX origin.y is coming up zero here! Need that to check the row we're dragging in :(
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> contentNode = do_QueryInterface([button element]);
contentNode->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom) {
if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertInto;
return;
}
} else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertBefore;
return;
} else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
return;
}
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
[self setButtonInsertionPoint:[sender draggingLocation]];
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarksService::CompleteBookmarkDrag([sender draggingPasteboard], BookmarksService::gToolbarRoot,
mDragInsertionButton ? [mDragInsertionButton element] : nil,
mDragInsertionPosition);
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return YES;
}
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition
{
if (aPosition == BookmarksService::CHInsertInto) {
return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y,
[aButton frame].size.width, [aButton frame].size.height);
} else if (aPosition == BookmarksService::CHInsertAfter) {
return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y,
2, [aButton frame].size.height);
} else {// if (aPosition == BookmarksService::CHInsertBefore) {
return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y,
2, [aButton frame].size.height);
}
}
@end

Просмотреть файл

@ -30,4 +30,6 @@
- (BOOL)autoHides;
- (void)setAutoHides:(BOOL)newSetting;
-(void)addTabForURL:(NSString*)aURL;
@end

Просмотреть файл

@ -0,0 +1,217 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Matt Judy.
*/
#import "CHExtendedTabView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIAtom.h"
#include "nsString.h"
#include "nsCRT.h"
//////////////////////////
// NEEDS IMPLEMENTED : Implement drag tracking for moving tabs around.
// Implementation hints : Track drags ;)
// : Change tab controlTint to indicate drag location?
// : Move tab titles around when dragging.
//////////////////////////
@interface CHExtendedTabView (Private)
- (void)showOrHideTabsAsAppropriate;
@end
@implementation CHExtendedTabView
/******************************************/
/*** Initialization ***/
/******************************************/
- (id)initWithFrame:(NSRect)frameRect
{
if ( (self = [super initWithFrame:frameRect]) ) {
autoHides = YES;
}
return self;
}
- (void)awakeFromNib
{
[self showOrHideTabsAsAppropriate];
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
/******************************************/
/*** Overridden Methods ***/
/******************************************/
- (BOOL)isOpaque
{
if ( ([self tabViewType] == NSNoTabsBezelBorder) && (NSAppKitVersionNumber < 633) ) {
return NO;
} else {
return [super isOpaque];
}
}
- (void)addTabViewItem:(NSTabViewItem *)tabViewItem
{
[super addTabViewItem:tabViewItem];
[self showOrHideTabsAsAppropriate];
}
- (void)removeTabViewItem:(NSTabViewItem *)tabViewItem
{
[super removeTabViewItem:tabViewItem];
[self showOrHideTabsAsAppropriate];
}
- (void)insertTabViewItem:(NSTabViewItem *)tabViewItem atIndex:(int)index
{
[super insertTabViewItem:tabViewItem atIndex:index];
[self showOrHideTabsAsAppropriate];
}
/******************************************/
/*** Accessor Methods ***/
/******************************************/
- (BOOL)autoHides
{
return autoHides;
}
- (void)setAutoHides:(BOOL)newSetting
{
autoHides = newSetting;
}
/******************************************/
/*** Instance Methods ***/
/******************************************/
// 03-03-2002 mlj: Modifies tab view size and type appropriately... Fragile.
// Only to be used with the 2 types of tab view which we use in Chimera.
- (void)showOrHideTabsAsAppropriate
{
// if ( autoHides == YES ) {
if ( [[self tabViewItems] count] < 2) {
if ( [self tabViewType] != NSNoTabsBezelBorder ) {
[self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) + 10 )];
}
[self setTabViewType:NSNoTabsBezelBorder];
} else {
if ( [self tabViewType] != NSTopTabsBezelBorder ) {
[self setFrameSize:NSMakeSize( NSWidth([self frame]), NSHeight([self frame]) - 10 )];
}
[self setTabViewType:NSTopTabsBezelBorder];
}
[self display];
// }
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
NSArray* contentIds;
NSTabViewItem* overTabViewItem = nil;
BOOL overContentArea = NO;
// determine if we are over a tab or the content area
NSPoint localPoint = [self convertPoint: [sender draggingLocation] fromView: nil];
overTabViewItem = [self tabViewItemAtPoint: localPoint];
overContentArea = NSPointInRect(localPoint, [self contentRect]);
// check for recognized drag types
contentIds = [[sender draggingPasteboard] propertyListForType: @"MozBookmarkType"];
if (contentIds) {
int i = 0;
// drag type is chimera bookmarks
for (i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
nsCOMPtr<nsIAtom> tagName;
[item contentNode]->GetTag(*getter_AddRefs(tagName));
nsAutoString href;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("href"), href);
NSString* url = [NSString stringWithCharacters: href.get() length: nsCRT::strlen(href.get())];
nsAutoString group;
bookmarkElt->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty()) {
BookmarksService::OpenBookmarkGroup(self, bookmarkElt);
} else {
if (overTabViewItem) {
[[[overTabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: url]
flags: NSLoadFlagsNone];
} else if (overContentArea) {
[[[[self selectedTabViewItem] view] getBrowserView] loadURI:[NSURL URLWithString: url]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:url];
}
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [[sender draggingPasteboard] propertyListForType: @"MozURLType"];
if (overTabViewItem || overContentArea) {
[[[overTabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: [data objectForKey:@"url"]]
flags: NSLoadFlagsNone];
} else
[self addTabForURL:[data objectForKey:@"url"]];
}
return YES;
}
-(void)addTabForURL:(NSString*)aURL
{
NSTabViewItem* tabViewItem;
CHBrowserWrapper* newView;
// We need to make a new tab.
tabViewItem = [[[NSTabViewItem alloc] initWithIdentifier: nil] autorelease];
newView = [[[CHBrowserWrapper alloc] initWithTab: tabViewItem andWindow: [self window]] autorelease];
[tabViewItem setLabel: @"Untitled"];
[tabViewItem setView: newView];
[self addTabViewItem: tabViewItem];
[[[tabViewItem view] getBrowserView] loadURI:[NSURL URLWithString: aURL]
flags: NSLoadFlagsNone];
}
@end

31
chimera/CHPageProxyIcon.h Normal file
Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <Cocoa/Cocoa.h>
@interface CHPageProxyIcon : NSImageView
{
}
@end

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHPageProxyIcon.h"
#import "BookmarksService.h"
#import "MainController.h"
@implementation CHPageProxyIcon
- (void) resetCursorRects
{
NSCursor* cursor;
// XXX provide image for drag-hand cursor
cursor = [NSCursor arrowCursor];
[self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor];
[cursor setOnMouseEntered:YES];
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// need to implement this or else mouseDragged isn't called
}
- (void) mouseDragged: (NSEvent*) event
{
NSPasteboard *pboard;
NSDictionary* data;
NSArray* dataVals;
NSArray* dataKeys;
NSString* url;
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
dataVals = [NSArray arrayWithObjects: url, title, nil];
dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil];
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)
event: event pasteboard: pboard source: self slideBack: YES];
}
@end

Просмотреть файл

@ -21,6 +21,7 @@
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
@ -404,6 +405,8 @@
F52D5CD9027D3D5001A80166,
F52F87CF027D75C301A80165,
F52F87D0027D75C301A80165,
2E293A01027F33604B000102,
2EEC3E63028138724B000102,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -500,6 +503,8 @@
F52D5CDA027D3D5001A80166,
F52F87D1027D75C301A80165,
F52F87D2027D75C301A80165,
2E293A02027F33604B000102,
2EEC3E64028138724B000102,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -532,6 +537,67 @@
//292
//293
//294
//2E0
//2E1
//2E2
//2E3
//2E4
2E2939FF027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.mm;
refType = 4;
};
2E293A00027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.h;
refType = 4;
};
2E293A01027F33604B000102 = {
fileRef = 2E293A00027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2E293A02027F33604B000102 = {
fileRef = 2E2939FF027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
refType = 4;
};
2EEC3E62028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.mm;
refType = 4;
};
2EEC3E63028138724B000102 = {
fileRef = 2EEC3E61028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E64028138724B000102 = {
fileRef = 2EEC3E62028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
//2E0
//2E1
//2E2
//2E3
//2E4
//4A0
//4A1
//4A2
@ -917,6 +983,7 @@
F57074B5026BA85F01A80166,
F57074B9026BFD0101A80166,
F57074BD026D80DF01A80166,
2E293A00027F33604B000102,
F5607CB5023944AD01A967DF,
F59E9F3D0237E28401A967DF,
F5137A1102676B9101026D05,
@ -1993,11 +2060,14 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -2636,7 +2706,7 @@
};
F5BF71460231B8BC010001CA = {
isa = PBXFileReference;
path = CHExtendedTabView.m;
path = CHExtendedTabView.mm;
refType = 4;
};
F5BF71510231DC5D010001CA = {

Просмотреть файл

@ -34,7 +34,8 @@ http://chimera.mozdev.org\
\f3\b Patrick Beard\
Ugo Dantas De Santana\
Simon Fraser\
Ben Goodger
Ben Goodger\
Joe Hewitt
\f2\b0 \
\f3\b David Hyatt

6
chimera/English.lproj/BrowserWindow.nib/classes.nib сгенерированный
Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

16
chimera/English.lproj/BrowserWindow.nib/info.nib сгенерированный
Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
chimera/English.lproj/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -121,4 +121,6 @@ class BookmarksService;
- (IBAction)showAboutBox:(id)sender;
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
@end

Просмотреть файл

@ -454,4 +454,34 @@ static PRBool gSetupSmoothTextMenu = PR_FALSE;
//XXX do nothing for now
}
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
{
NSImage* image;
NSSize titleSize, imageSize;
NSRect imageRect;
NSDictionary* stringAttrs;
// get the size of the new image we are creating
titleSize = [aTitle sizeWithAttributes:nil];
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
titleSize.height > [aIcon size].height ?
titleSize.height : [aIcon size].height);
// create the image and lock drawing focus on it
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
[image lockFocus];
// draw the image and title in image with translucency
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
forKey: NSForegroundColorAttributeName];
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
[image unlockFocus];
return image;
}
@end

Просмотреть файл

@ -21,6 +21,7 @@
F57074B6026BA85F01A80166,
F57074BA026BFD0101A80166,
F57074BE026D80DF01A80166,
2E2939FF027F33604B000102,
F59E9F3F0237E43401A967DF,
F52D5CD0027A887001A80166,
F52D5CD4027A88C601A80166,
@ -404,6 +405,8 @@
F52D5CD9027D3D5001A80166,
F52F87CF027D75C301A80165,
F52F87D0027D75C301A80165,
2E293A01027F33604B000102,
2EEC3E63028138724B000102,
);
isa = PBXHeadersBuildPhase;
name = Headers;
@ -500,6 +503,8 @@
F52D5CDA027D3D5001A80166,
F52F87D1027D75C301A80165,
F52F87D2027D75C301A80165,
2E293A02027F33604B000102,
2EEC3E64028138724B000102,
);
isa = PBXSourcesBuildPhase;
name = Sources;
@ -532,6 +537,67 @@
//292
//293
//294
//2E0
//2E1
//2E2
//2E3
//2E4
2E2939FF027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.mm;
refType = 4;
};
2E293A00027F33604B000102 = {
isa = PBXFileReference;
path = CHPageProxyIcon.h;
refType = 4;
};
2E293A01027F33604B000102 = {
fileRef = 2E293A00027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2E293A02027F33604B000102 = {
fileRef = 2E2939FF027F33604B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E6002810B184B000102 = {
indentWidth = 2;
isa = PBXFileReference;
path = CHExtendedTabView.m;
refType = 4;
usesTabs = 0;
};
2EEC3E61028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.h;
refType = 4;
};
2EEC3E62028138714B000102 = {
isa = PBXFileReference;
path = CHBookmarksOutlineView.mm;
refType = 4;
};
2EEC3E63028138724B000102 = {
fileRef = 2EEC3E61028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
2EEC3E64028138724B000102 = {
fileRef = 2EEC3E62028138714B000102;
isa = PBXBuildFile;
settings = {
};
};
//2E0
//2E1
//2E2
//2E3
//2E4
//4A0
//4A1
//4A2
@ -917,6 +983,7 @@
F57074B5026BA85F01A80166,
F57074B9026BFD0101A80166,
F57074BD026D80DF01A80166,
2E293A00027F33604B000102,
F5607CB5023944AD01A967DF,
F59E9F3D0237E28401A967DF,
F5137A1102676B9101026D05,
@ -1993,11 +2060,14 @@
F5571935022B401B010001CA = {
children = (
F5BF71450231B8BC010001CA,
2EEC3E6002810B184B000102,
F5BF71460231B8BC010001CA,
F5648739023C3857010001CA,
F564873A023C3857010001CA,
F5C3AB810270072A01A80166,
F5C3AB820270072A01A80166,
2EEC3E61028138714B000102,
2EEC3E62028138714B000102,
F541495A02711A8301A80166,
F541495B02711A8301A80166,
F541495E02711B0001A80166,
@ -2636,7 +2706,7 @@
};
F5BF71460231B8BC010001CA = {
isa = PBXFileReference;
path = CHExtendedTabView.m;
path = CHExtendedTabView.mm;
refType = 4;
};
F5BF71510231DC5D010001CA = {

Просмотреть файл

@ -34,7 +34,8 @@ http://chimera.mozdev.org\
\f3\b Patrick Beard\
Ugo Dantas De Santana\
Simon Fraser\
Ben Goodger
Ben Goodger\
Joe Hewitt
\f2\b0 \
\f3\b David Hyatt

Просмотреть файл

@ -73,6 +73,11 @@
SUPERCLASS = NSTableView;
},
{CLASS = CHAutoCompleteTextField; LANGUAGE = ObjC; SUPERCLASS = NSTextField; },
{
CLASS = CHBookmarksOutlineView;
LANGUAGE = ObjC;
SUPERCLASS = CHExtendedOutlineView;
},
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
@ -82,6 +87,7 @@
SUPERCLASS = CHRDFOutlineViewDataSource;
},
{CLASS = CHLocationBar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
{CLASS = CHPageProxyIcon; LANGUAGE = ObjC; SUPERCLASS = NSImageView; },
{
CLASS = CHRDFOutlineViewDataSource;
LANGUAGE = ObjC;

Просмотреть файл

@ -3,17 +3,17 @@
<plist version="0.9">
<dict>
<key>IBDocumentLocation</key>
<string>91 273 480 309 0 0 1280 1002 </string>
<string>41 39 480 309 0 0 1152 746 </string>
<key>IBEditorPositions</key>
<dict>
<key>124</key>
<string>431 537 170 180 0 0 1152 746 </string>
<key>160</key>
<string>572 326 195 666 0 0 1280 1002 </string>
<string>454 70 195 666 0 0 1152 746 </string>
<key>28</key>
<string>478 279 195 457 0 0 1152 746 </string>
<string>454 268 195 457 0 0 1152 746 </string>
<key>297</key>
<string>79 163 198 210 0 0 1280 1002 </string>
<string>70 110 198 210 0 0 1152 746 </string>
<key>314</key>
<string>271 139 198 180 0 0 1152 746 </string>
<key>336</key>
@ -23,9 +23,9 @@
<key>463</key>
<string>7 444 200 252 0 0 1152 746 </string>
<key>475</key>
<string>609 597 120 142 0 0 1280 1002 </string>
<string>493 338 207 230 0 0 1152 746 </string>
<key>56</key>
<string>498 634 343 68 0 0 1280 1002 </string>
<string>380 463 343 68 0 0 1152 746 </string>
</dict>
<key>IBFramework Version</key>
<string>248.0</string>
@ -45,12 +45,10 @@
</array>
<key>IBOpenObjects</key>
<array>
<integer>475</integer>
<integer>297</integer>
<integer>160</integer>
<integer>56</integer>
</array>
<key>IBSystem Version</key>
<string>5L21</string>
<string>5Q125</string>
</dict>
</plist>

Двоичные данные
chimera/resources/localized/English.lproj/BrowserWindow.nib/objects.nib сгенерированный

Двоичный файл не отображается.

Просмотреть файл

@ -121,4 +121,6 @@ class BookmarksService;
- (IBAction)showAboutBox:(id)sender;
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle;
@end

Просмотреть файл

@ -454,4 +454,34 @@ static PRBool gSetupSmoothTextMenu = PR_FALSE;
//XXX do nothing for now
}
+ (NSImage*)createImageForDragging:(NSImage*)aIcon title:(NSString*)aTitle
{
NSImage* image;
NSSize titleSize, imageSize;
NSRect imageRect;
NSDictionary* stringAttrs;
// get the size of the new image we are creating
titleSize = [aTitle sizeWithAttributes:nil];
imageSize = NSMakeSize(titleSize.width + [aIcon size].width,
titleSize.height > [aIcon size].height ?
titleSize.height : [aIcon size].height);
// create the image and lock drawing focus on it
image = [[[NSImage alloc] initWithSize:imageSize] autorelease];
[image lockFocus];
// draw the image and title in image with translucency
imageRect = NSMakeRect(0,0, [aIcon size].width, [aIcon size].height);
[aIcon drawAtPoint: NSMakePoint(0,0) fromRect: imageRect operation:NSCompositeCopy fraction:0.8];
stringAttrs = [NSDictionary dictionaryWithObject: [[NSColor textColor] colorWithAlphaComponent:0.8]
forKey: NSForegroundColorAttributeName];
[aTitle drawAtPoint: NSMakePoint([aIcon size].width, 0) withAttributes: stringAttrs];
[image unlockFocus];
return image;
}
@end

Просмотреть файл

@ -83,9 +83,8 @@
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
NSMenu* menu = BookmarksService::LocateMenu(content);
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
}
else
[super mouseDown: aEvent];
} else
[super mouseDown:aEvent];
}
-(void)setElement: (nsIDOMElement*)aElt
@ -128,4 +127,17 @@
return mElement;
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void) mouseDragged: (NSEvent*) aEvent
{
// XXX mouseDragged is never called because buttons cancel dragging while you mouse down
// I have to fix this in an ugly way, by doing the "click" stuff myself and never relying
// on the superclass for that. Bah!
BookmarksService::DragBookmark(mElement, self, aEvent);
}
@end

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <AppKit/AppKit.h>
#import "CHExtendedOutlineView.h"
@interface CHBookmarksOutlineView : CHExtendedOutlineView {
}
@end

Просмотреть файл

@ -0,0 +1,62 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHBookmarksOutlineView.h"
#import "BookmarksService.h"
#include "nsCOMPtr.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
#include "nsIDOMNode.h"
@implementation CHBookmarksOutlineView
- (void)awakeFromNib
{
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
- (void)draggedImage:(NSImage *)anImage endedAt:(NSPoint)aPoint operation:(NSDragOperation)operation
{
if (operation == NSDragOperationDelete) {
NSArray* contentIds = nil;
NSPasteboard* pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
contentIds = [pboard propertyListForType:@"MozBookmarkType"];
if (contentIds) {
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [BookmarksService::gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
BookmarksService::DeleteBookmark(bookmarkElt);
}
}
}
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
unsigned int result = [super draggingSourceOperationMaskForLocal:flag];
if (flag == NO)
result &= NSDragOperationDelete;
return result;
}
@end

Просмотреть файл

@ -112,6 +112,10 @@ public:
static void BookmarkAdded(nsIContent* aContainer, nsIContent* aChild);
static void BookmarkChanged(nsIContent* aItem);
static void BookmarkRemoved(nsIContent* aContainer, nsIContent* aChild);
static void AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt);
static void DeleteBookmark(nsIDOMElement* aBookmark);
public:
static void GetRootContent(nsIContent** aResult);
@ -131,6 +135,12 @@ public:
static void GetTitleAndHrefForBrowserView(id aBrowserView, nsString& aTitle, nsString& aHref);
static void OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder);
static NSImage* CreateIconForBookmark(nsIDOMElement* aElement);
static void DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent);
static void CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt, nsIDOMElement* aBeforeElt, int aPosition);
public:
// Global counter and pointers to our singletons.
@ -149,6 +159,10 @@ public:
static nsIAtom* gBookmarkAtom;
static nsIDocument* gBookmarks;
static nsVoidArray* gInstances;
static int CHInsertNone;
static int CHInsertInto;
static int CHInsertBefore;
static int CHInsertAfter;
private:
// There are three kinds of bookmarks data sources:

Просмотреть файл

@ -36,7 +36,7 @@
* ***** END LICENSE BLOCK ***** */
#import "CHBrowserView.h"
#include "BookmarksService.h"
#import "BookmarksService.h"
#include "nsIDocument.h"
#include "nsIContent.h"
#include "nsIAtom.h"
@ -469,6 +469,63 @@
[mOutlineView reloadItem: item reloadChildren: aReloadChildren];
}
- (BOOL)outlineView:(NSOutlineView*)outlineView acceptDrop:(id <NSDraggingInfo>)info item:(id)item childIndex:(int)index
{
BookmarkItem* beforeItem = nil;
nsCOMPtr<nsIDOMElement> beforeElt;
nsCOMPtr<nsIDOMElement> folderElt;
nsCOMPtr<nsIContent> folderContent;
if (index == NSOutlineViewDropOnItemIndex)
return NO;
// get the folder element
if (!item)
mBookmarks->GetRootContent(getter_AddRefs(folderContent));
else
folderContent = [item contentNode];
folderElt = do_QueryInterface(folderContent);
// get the element to insert before, if there is one
PRInt32 childCount = 0;
folderContent->ChildCount(childCount);
if (index < childCount)
beforeItem = [[outlineView dataSource] outlineView:outlineView child:index ofItem:item];
if (beforeItem)
beforeElt = do_QueryInterface([beforeItem contentNode]);
// insert the dragged stuff into bookmarks
BookmarksService::CompleteBookmarkDrag([info draggingPasteboard], folderElt, beforeElt,
BookmarksService::CHInsertBefore);
return YES;
}
- (NSDragOperation)outlineView:(NSOutlineView*)outlineView validateDrop:(id <NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(int)index
{
if (index == NSOutlineViewDropOnItemIndex)
return NSDragOperationNone;
return NSDragOperationGeneric;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard
{
NSMutableArray* contentIds = [NSMutableArray array];
for (int i = 0; i < [items count]; ++i) {
nsCOMPtr<nsIContent> content = [[items objectAtIndex:i] contentNode];
PRUint32 contentId;
content->GetContentID(&contentId);
[contentIds addObject:[NSNumber numberWithInt:contentId]];
}
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:outlineView];
[pboard setPropertyList:contentIds forType:@"MozBookmarkType"];
return YES;
}
@end
@implementation BookmarkItem
@ -527,6 +584,10 @@ nsIAtom* BookmarksService::gBookmarkAtom = nsnull;
nsIAtom* BookmarksService::gHrefAtom = nsnull;
nsIAtom* BookmarksService::gNameAtom = nsnull;
nsVoidArray* BookmarksService::gInstances = nsnull;
int BookmarksService::CHInsertNone = 0;
int BookmarksService::CHInsertInto = 1;
int BookmarksService::CHInsertBefore = 2;
int BookmarksService::CHInsertAfter = 3;
BookmarksService::BookmarksService(BookmarksDataSource* aDataSource)
{
@ -756,6 +817,74 @@ BookmarksService::RemoveObserver()
}
}
void
BookmarksService::AddBookmarkToFolder(nsString& aURL, nsString& aTitle, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
// XXX if no folder provided, default to root folder
if (!aFolder) return;
nsCOMPtr<nsIDOMDocument> domDoc(do_QueryInterface(gBookmarks));
nsCOMPtr<nsIDOMElement> elt;
domDoc->CreateElementNS(NS_LITERAL_STRING("http://chimera.mozdev.org/bookmarks/"),
NS_LITERAL_STRING("bookmark"),
getter_AddRefs(elt));
elt->SetAttribute(NS_LITERAL_STRING("name"), aTitle);
elt->SetAttribute(NS_LITERAL_STRING("href"), aURL);
MoveBookmarkToFolder(elt, aFolder, aBeforeElt);
}
void
BookmarksService::MoveBookmarkToFolder(nsIDOMElement* aBookmark, nsIDOMElement* aFolder, nsIDOMElement* aBeforeElt)
{
if (!aBookmark || !aFolder) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
nsCOMPtr<nsIDOMNode> dummy;
if (oldParent) {
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
}
if (aBeforeElt) {
aFolder->InsertBefore(aBookmark, aBeforeElt, getter_AddRefs(dummy));
} else {
aFolder->AppendChild(aBookmark, getter_AddRefs(dummy));
}
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> parentContent(do_QueryInterface(aFolder));
if (oldParent) {
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
BookmarkAdded(parentContent, childContent);
}
void
BookmarksService::DeleteBookmark(nsIDOMElement* aBookmark)
{
if (!aBookmark) return;
nsCOMPtr<nsIDOMNode> oldParent;
aBookmark->GetParentNode(getter_AddRefs(oldParent));
if (oldParent) {
nsCOMPtr<nsIDOMNode> dummy;
nsCOMPtr<nsIDOMNode> bookmarkNode = do_QueryInterface(aBookmark);
oldParent->RemoveChild(bookmarkNode, getter_AddRefs(dummy));
nsCOMPtr<nsIContent> childContent(do_QueryInterface(aBookmark));
nsCOMPtr<nsIContent> oldParentContent(do_QueryInterface(oldParent));
BookmarkRemoved(oldParentContent, childContent);
}
}
void
BookmarksService::FlushBookmarks()
{
@ -1202,3 +1331,81 @@ BookmarksService::OpenBookmarkGroup(id aTabView, nsIDOMElement* aFolder)
[aTabView selectTabViewItemAtIndex: 0];
[[[[aTabView tabViewItemAtIndex: 0] view] getBrowserView] setActive: YES];
}
NSImage*
BookmarksService::CreateIconForBookmark(nsIDOMElement* aElement)
{
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
content->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom)
return [NSImage imageNamed:@"folder"];
nsAutoString group;
aElement->GetAttribute(NS_LITERAL_STRING("group"), group);
if (!group.IsEmpty())
return [NSImage imageNamed:@"smallgroup"];
return [NSImage imageNamed:@"groupbookmark"];
}
void
BookmarksService::DragBookmark(nsIDOMElement* aElement, NSView* aView, NSEvent* aEvent)
{
NSPasteboard *pboard;
NSString* title;
nsCOMPtr<nsIContent> content = do_QueryInterface(aElement);
PRUint32 contentId;
content->GetContentID(&contentId);
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozBookmarkType"] owner:aView];
[pboard setPropertyList:[NSArray arrayWithObject:[NSNumber numberWithInt:contentId]] forType:@"MozBookmarkType"];
nsAutoString nameStr;
aElement->GetAttribute(NS_LITERAL_STRING("name"), nameStr);
title = [NSString stringWithCharacters: nameStr.get() length: nsCRT::strlen(nameStr.get())];
[aView dragImage: [MainController createImageForDragging: CreateIconForBookmark(aElement) title:title]
at:NSMakePoint(0,0) offset:NSMakeSize(0,0)
event:aEvent pasteboard:pboard source:aView slideBack:YES];
}
void
BookmarksService::CompleteBookmarkDrag(NSPasteboard* aPasteboard, nsIDOMElement* aFolderElt,
nsIDOMElement* aBeforeElt, int aPosition)
{
NSArray* contentIds;
nsCOMPtr<nsIDOMElement> beforeElt = aBeforeElt;
if (aPosition == BookmarksService::CHInsertAfter && aBeforeElt) {
nsCOMPtr<nsIDOMNode> beforeNode;
aBeforeElt->GetNextSibling(getter_AddRefs(beforeNode));
beforeElt = do_QueryInterface(beforeNode);
}
if (aPosition == BookmarksService::CHInsertInto) {
aFolderElt = aBeforeElt;
beforeElt = nsnull;
}
// check for recognized drag types
contentIds = [aPasteboard propertyListForType: @"MozBookmarkType"];
if (contentIds) {
// drag type is chimera bookmarks
for (int i = 0; i < [contentIds count]; ++i) {
BookmarkItem* item = [gDictionary objectForKey: [contentIds objectAtIndex:i]];
nsCOMPtr<nsIDOMElement> bookmarkElt = do_QueryInterface([item contentNode]);
MoveBookmarkToFolder(bookmarkElt, aFolderElt, beforeElt);
}
} else {
// add bookmark for chimera url type
NSDictionary* data = [aPasteboard propertyListForType: @"MozURLType"];
nsAutoString url; url.AssignWithConversion([[data objectForKey:@"url"] cString]);
nsAutoString title; title.AssignWithConversion([[data objectForKey:@"title"] cString]);
AddBookmarkToFolder(url, title, aFolderElt, beforeElt);
}
}

Просмотреть файл

@ -26,10 +26,13 @@
class nsIDOMElement;
class BookmarksService;
class CHBookmarksButton;
@interface CHBookmarksToolbar : NSView {
BookmarksService* mBookmarks;
NSMutableArray* mButtons;
CHBookmarksButton* mDragInsertionButton;
int mDragInsertionPosition;
}
-(void)initializeToolbar;
@ -45,4 +48,7 @@ class BookmarksService;
-(void)showBookmarksToolbar: (BOOL)aShow;
- (void) setButtonInsertionPoint:(NSPoint)aPoint;
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int)aPosition;
@end

Просмотреть файл

@ -25,6 +25,7 @@
#import "CHBookmarksToolbar.h"
#import "BookmarksService.h"
#include "nsIDOMElement.h"
#include "nsIContent.h"
@implementation CHBookmarksToolbar
@ -32,6 +33,9 @@
if ( (self = [super initWithFrame:frame]) ) {
mBookmarks = nsnull;
mButtons = [[NSMutableArray alloc] init];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self registerForDraggedTypes:[NSArray arrayWithObjects:@"MozURLType", @"MozBookmarkType", nil]];
}
return self;
}
@ -70,6 +74,12 @@
// The buttons will paint themselves. Just call our base class method.
[super drawRect: aRect];
// draw a separator at drag n drop insertion point if there is one
if (mDragInsertionPosition) {
[[[NSColor controlShadowColor] colorWithAlphaComponent:0.6] set];
NSRectFill([self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]);
}
}
-(void)buildButtonList
@ -240,4 +250,100 @@
// [self reflowButtons];
}
- (void)setButtonInsertionPoint:(NSPoint)aPoint
{
int count = [mButtons count];
mDragInsertionButton = nsnull;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
for (int i = 0; i < count; ++i) {
CHBookmarksButton* button = [mButtons objectAtIndex: i];
//NSLog(@"check %d - %d,%d %d,%d\n", i, [button frame].origin.x, [button frame].origin.y, aPoint.x, aPoint.y);
// XXX origin.y is coming up zero here! Need that to check the row we're dragging in :(
nsCOMPtr<nsIAtom> tagName;
nsCOMPtr<nsIContent> contentNode = do_QueryInterface([button element]);
contentNode->GetTag(*getter_AddRefs(tagName));
if (tagName == BookmarksService::gFolderAtom) {
if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertInto;
return;
}
} else if (([button frame].origin.x+([button frame].size.width/2) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertBefore;
return;
} else if (([button frame].origin.x+([button frame].size.width) > aPoint.x)) {
mDragInsertionButton = button;
mDragInsertionPosition = BookmarksService::CHInsertAfter;
return;
}
}
}
// NSDraggingDestination ///////////
- (unsigned int)draggingEntered:(id <NSDraggingInfo>)sender
{
return NSDragOperationGeneric;
}
- (void)draggingExited:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
}
- (unsigned int)draggingUpdated:(id <NSDraggingInfo>)sender
{
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
[self setButtonInsertionPoint:[sender draggingLocation]];
if (mDragInsertionPosition)
[self setNeedsDisplayInRect:[self insertionRectForButton:mDragInsertionButton position:mDragInsertionPosition]];
return NSDragOperationGeneric;
}
- (BOOL)prepareForDragOperation:(id <NSDraggingInfo>)sender
{
return YES;
}
- (BOOL)performDragOperation:(id <NSDraggingInfo>)sender
{
BookmarksService::CompleteBookmarkDrag([sender draggingPasteboard], BookmarksService::gToolbarRoot,
mDragInsertionButton ? [mDragInsertionButton element] : nil,
mDragInsertionPosition);
mDragInsertionButton = nil;
mDragInsertionPosition = BookmarksService::CHInsertNone;
[self setNeedsDisplay:YES];
return YES;
}
- (NSRect)insertionRectForButton:(NSView*)aButton position:(int) aPosition
{
if (aPosition == BookmarksService::CHInsertInto) {
return NSMakeRect([aButton frame].origin.x, [aButton frame].origin.y,
[aButton frame].size.width, [aButton frame].size.height);
} else if (aPosition == BookmarksService::CHInsertAfter) {
return NSMakeRect([aButton frame].origin.x+[aButton frame].size.width, [aButton frame].origin.y,
2, [aButton frame].size.height);
} else {// if (aPosition == BookmarksService::CHInsertBefore) {
return NSMakeRect([aButton frame].origin.x - 2, [aButton frame].origin.y,
2, [aButton frame].size.height);
}
}
@end

Просмотреть файл

@ -0,0 +1,31 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import <Cocoa/Cocoa.h>
@interface CHPageProxyIcon : NSImageView
{
}
@end

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 2002 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
* Joe Hewitt <hewitt@netscape.com> (Original Author)
*/
#import "CHPageProxyIcon.h"
#import "BookmarksService.h"
#import "MainController.h"
@implementation CHPageProxyIcon
- (void) resetCursorRects
{
NSCursor* cursor;
// XXX provide image for drag-hand cursor
cursor = [NSCursor arrowCursor];
[self addCursorRect:NSMakeRect(0,0,[self frame].size.width,[self frame].size.height) cursor:cursor];
[cursor setOnMouseEntered:YES];
}
- (unsigned int)draggingSourceOperationMaskForLocal:(BOOL)flag
{
return NSDragOperationGeneric;
}
- (void)mouseDown:(NSEvent *)theEvent
{
// need to implement this or else mouseDragged isn't called
}
- (void) mouseDragged: (NSEvent*) event
{
NSPasteboard *pboard;
NSDictionary* data;
NSArray* dataVals;
NSArray* dataKeys;
NSString* url;
NSString* title;
nsAutoString hrefStr, titleStr;
BookmarksService::GetTitleAndHrefForBrowserView([[[[self window] windowController] getBrowserWrapper] getBrowserView],
titleStr, hrefStr);
url = [NSString stringWithCharacters: hrefStr.get() length: nsCRT::strlen(hrefStr.get())];
title = [NSString stringWithCharacters: titleStr.get() length: nsCRT::strlen(titleStr.get())];
dataVals = [NSArray arrayWithObjects: url, title, nil];
dataKeys = [NSArray arrayWithObjects: @"url", @"title", nil];
data = [NSDictionary dictionaryWithObjects:dataVals forKeys:dataKeys];
pboard = [NSPasteboard pasteboardWithName:NSDragPboard];
[pboard declareTypes:[NSArray arrayWithObject:@"MozURLType"] owner:self];
[pboard setPropertyList:data forType: @"MozURLType"];
[self dragImage: [MainController createImageForDragging:[self image] title:title]
at: NSMakePoint(0,0) offset: NSMakeSize(0,0)
event: event pasteboard: pboard source: self slideBack: YES];
}
@end