зеркало из https://github.com/mozilla/pjs.git
Initial commits of a bunch of files. Chimera. NPOB.
This commit is contained in:
Родитель
2265de9de5
Коммит
ae69eb8174
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичный файл не отображается.
|
@ -0,0 +1,40 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
@interface CHBookmarksButton : NSButton {
|
||||
|
||||
nsIDOMElement* mElement;
|
||||
BOOL mIsFolder;
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt;
|
||||
-(nsIDOMElement*)element;
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender;
|
||||
|
||||
@end
|
|
@ -0,0 +1,127 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsString.h"
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation CHBookmarksButton
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mElement = nsnull;
|
||||
[self setBezelStyle: NSRegularSquareBezelStyle];
|
||||
[self setBordered: NO];
|
||||
[self setImagePosition: NSImageLeft];
|
||||
[self setRefusesFirstResponder: YES];
|
||||
[self setFont: [NSFont labelFontOfSize: 11.0]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender
|
||||
{
|
||||
// See if we're a group.
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
if (!group.IsEmpty()) {
|
||||
BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the href attribute. This is the URL we want to load.
|
||||
nsAutoString href;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCAutoString cref; cref.AssignWithConversion(href);
|
||||
if (cref.IsEmpty())
|
||||
return;
|
||||
|
||||
NSString* url = [NSString stringWithCString: cref.get()];
|
||||
|
||||
// Now load the URL in the window.
|
||||
[[[self window] windowController] loadURL:[NSURL URLWithString: url]];
|
||||
|
||||
// Focus and activate our content area.
|
||||
[[[[[self window] windowController] getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)aRect
|
||||
{
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
|
||||
{
|
||||
return [[self superview] menu];
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent*)aEvent
|
||||
{
|
||||
if (mIsFolder) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
|
||||
NSMenu* menu = BookmarksService::LocateMenu(content);
|
||||
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
|
||||
}
|
||||
else
|
||||
[super mouseDown: aEvent];
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt
|
||||
{
|
||||
mElement = aElt;
|
||||
nsAutoString tag;
|
||||
mElement->GetLocalName(tag);
|
||||
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
|
||||
if (!group.IsEmpty()) {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
else if (tag.Equals(NS_LITERAL_STRING("folder"))) {
|
||||
[self setImage: [NSImage imageNamed: @"folder"]];
|
||||
mIsFolder = YES;
|
||||
}
|
||||
else {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
[self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
|
||||
}
|
||||
|
||||
-(nsIDOMElement*)element
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface CHBookmarksToolbar : NSView {
|
||||
BookmarksService* mBookmarks;
|
||||
NSMutableArray* mButtons;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar;
|
||||
|
||||
// Called to construct the initial set of personal toolbar buttons.
|
||||
-(void)buildButtonList;
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex;
|
||||
-(void)removeButton: (nsIDOMElement*)aElt;
|
||||
|
||||
// Called to lay out the buttons on the toolbar.
|
||||
-(void)reflowButtons;
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex;
|
||||
|
||||
@end
|
|
@ -0,0 +1,227 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "BookmarksService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
@implementation CHBookmarksToolbar
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mButtons = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar
|
||||
{
|
||||
// Initialization code here.
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
mBookmarks->EnsureToolbarRoot();
|
||||
[self buildButtonList];
|
||||
}
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
[mButtons autorelease];
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)aRect {
|
||||
// Fill the background with our background color.
|
||||
//[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set];
|
||||
//NSRectFill(aRect);
|
||||
|
||||
//printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
|
||||
|
||||
if (aRect.origin.y + aRect.size.height ==
|
||||
[self bounds].size.height) {
|
||||
// The personal toolbar is 21 pixels tall. The bottom two pixels
|
||||
// are a separator.
|
||||
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
|
||||
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
|
||||
}
|
||||
|
||||
// The buttons will paint themselves. Just call our base class method.
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(void)buildButtonList
|
||||
{
|
||||
// Build the buttons, and then lay them all out.
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
|
||||
if (childElt) {
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: childElt];
|
||||
[self addSubview: button];
|
||||
[mButtons addObject: button];
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
|
||||
[self reflowButtons];
|
||||
}
|
||||
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
|
||||
{
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: aElt];
|
||||
[self addSubview: button];
|
||||
[mButtons insertObject: button atIndex: aIndex];
|
||||
[self reflowButtonsStartingAtIndex: aIndex];
|
||||
}
|
||||
|
||||
-(void)removeButton: (nsIDOMElement*)aElt
|
||||
{
|
||||
int count = [mButtons count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
if ([button element] == aElt) {
|
||||
[mButtons removeObjectAtIndex: i];
|
||||
[button removeFromSuperview];
|
||||
if (count > i)
|
||||
[self reflowButtonsStartingAtIndex: i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
-(void)reflowButtons
|
||||
{
|
||||
[self reflowButtonsStartingAtIndex: 0];
|
||||
}
|
||||
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex
|
||||
{
|
||||
float oldHeight = [self frame].size.height;
|
||||
float computedHeight = 18;
|
||||
int count = [mButtons count];
|
||||
float currY = 1.0;
|
||||
float prevX = 2.0;
|
||||
if (aIndex > 0) {
|
||||
CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)];
|
||||
prevX += [prevButton frame].origin.x + [prevButton frame].size.width;
|
||||
currY = [prevButton frame].origin.y;
|
||||
}
|
||||
for (int i = aIndex; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
[button sizeToFit];
|
||||
float width = [button frame].size.width;
|
||||
float height = [button frame].size.height;
|
||||
if (width > 150)
|
||||
width = 150;
|
||||
if (height < 16)
|
||||
height = 16; // Our folder tiff is only 15 pixels for some reason.
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
|
||||
prevX += [button frame].size.width + 2;
|
||||
|
||||
if ([self bounds].size.width < prevX) {
|
||||
// The previous button didn't fit. We need to make a new row.
|
||||
currY += 18;
|
||||
computedHeight += 18;
|
||||
if (computedHeight > oldHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y+(oldHeight-computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
prevX = 2;
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
prevX += [button frame].size.width + 2;
|
||||
}
|
||||
|
||||
[button setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float currentHeight = [self frame].size.height;
|
||||
if (computedHeight != currentHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (currentHeight - computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float sizeChange = computedHeight - oldHeight;
|
||||
if (sizeChange != 0) {
|
||||
// We need to adjust the content area.
|
||||
NSView* view = [[[self window] windowController] getTabBrowser];
|
||||
[view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y,
|
||||
[view frame].size.width, [view frame].size.height - sizeChange)];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped
|
||||
{
|
||||
return YES; // Use flipped coords, so we can layout out from top row to bottom row.
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)aRect
|
||||
{
|
||||
NSRect oldFrame = [self frame];
|
||||
[super setFrame:aRect];
|
||||
|
||||
if (oldFrame.size.width == aRect.size.width)
|
||||
return;
|
||||
|
||||
int count = [mButtons count];
|
||||
if (count <= 2)
|
||||
return; // We have too few buttons to care.
|
||||
|
||||
// Do some optimizations when we have only one row.
|
||||
if (aRect.size.height < 25) // We have only one row.
|
||||
{
|
||||
if (oldFrame.size.width < aRect.size.width)
|
||||
// We got bigger. If we already only have one row, just bail.
|
||||
// This will optimize for a common resizing case.
|
||||
return;
|
||||
else {
|
||||
// We got smaller. Just go to the last button and see if it is outside
|
||||
// our bounds.
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)];
|
||||
if ([button frame].origin.x + [button frame].size.width >
|
||||
[self bounds].size.width - 2) {
|
||||
// The button doesn't fit any more. Reflow starting at this index.
|
||||
[self reflowButtonsStartingAtIndex:(count-1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we got bigger or smaller. We could gain or lose a row.
|
||||
[self reflowButtons];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,158 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsCocoaBrowserView_h__
|
||||
#define __nsCocoaBrowserView_h__
|
||||
|
||||
#undef DARWIN
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class CHBrowserView;
|
||||
class nsCocoaBrowserListener;
|
||||
class nsIDOMWindow;
|
||||
class nsIWebBrowser;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMEvent;
|
||||
class nsIWebBrowserFind;
|
||||
|
||||
// Protocol implemented by anyone interested in progress
|
||||
// related to a BrowserView. A listener should explicitly
|
||||
// register itself with the view using the addListener
|
||||
// method.
|
||||
@protocol NSBrowserListener
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
// Invoked regularly as data associated with a page streams
|
||||
// in. If the total number of bytes expected is unknown,
|
||||
// maxBytes is -1.
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
|
||||
@end
|
||||
|
||||
typedef enum {
|
||||
NSStatusTypeScript = 0x0001,
|
||||
NSStatusTypeScriptDefault = 0x0002,
|
||||
NSStatusTypeLink = 0x0003,
|
||||
} NSStatusType;
|
||||
|
||||
@protocol NSBrowserContainer
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
// Set the dimensions of our NSView. The container might need to do
|
||||
// some adjustment, so the view doesn't do it directly.
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
// Create a new browser container window and return the contained view.
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
@end
|
||||
|
||||
enum {
|
||||
NSLoadFlagsNone = 0x0000,
|
||||
NSLoadFlagsDontPutInHistory = 0x0010,
|
||||
NSLoadFlagsReplaceHistoryEntry = 0x0020,
|
||||
NSLoadFlagsBypassCacheAndProxy = 0x0040
|
||||
};
|
||||
|
||||
enum {
|
||||
NSStopLoadNetwork = 0x01,
|
||||
NSStopLoadContent = 0x02,
|
||||
NSStopLoadAll = 0x03
|
||||
};
|
||||
|
||||
@interface CHBrowserView : NSView
|
||||
{
|
||||
nsIWebBrowser* _webBrowser;
|
||||
nsCocoaBrowserListener* _listener;
|
||||
NSWindow* mWindow;
|
||||
}
|
||||
|
||||
// NSView overrides
|
||||
- (id)initWithFrame:(NSRect)frame;
|
||||
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow;
|
||||
|
||||
- (void)dealloc;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// nsIWebBrowser methods
|
||||
- (void)addListener:(id <NSBrowserListener>)listener;
|
||||
- (void)removeListener:(id <NSBrowserListener>)listener;
|
||||
- (void)setContainer:(id <NSBrowserContainer>)container;
|
||||
- (nsIDOMWindow*)getContentWindow;
|
||||
|
||||
// nsIWebNavigation methods
|
||||
- (void)loadURI:(NSURL *)url flags:(unsigned int)flags;
|
||||
- (void)reload:(unsigned int)flags;
|
||||
- (BOOL)canGoBack;
|
||||
- (BOOL)canGoForward;
|
||||
- (void)goBack;
|
||||
- (void)goForward;
|
||||
- (void)gotoIndex:(int)index;
|
||||
- (void)stop:(unsigned int)flags;
|
||||
- (NSURL*)getCurrentURI;
|
||||
|
||||
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
|
||||
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
|
||||
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
|
||||
|
||||
- (void)printDocument;
|
||||
|
||||
- (BOOL)findInPage:(NSString*)inText;
|
||||
|
||||
-(IBAction)cut:(id)aSender;
|
||||
-(IBAction)copy:(id)aSender;
|
||||
-(IBAction)paste:(id)aSender;
|
||||
-(IBAction)clear:(id)aSender;
|
||||
-(IBAction)selectAll:(id)aSender;
|
||||
-(IBAction)undo:(id)aSender;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
- (void)setActive: (BOOL)aIsActive;
|
||||
|
||||
- (NSMenu*)getContextMenu;
|
||||
- (NSWindow*)getNativeWindow;
|
||||
|
||||
- (void)destroyWebBrowser;
|
||||
- (nsIWebBrowser*)getWebBrowser;
|
||||
- (nsCocoaBrowserListener*)getCocoaBrowserListener;
|
||||
- (void)setWebBrowser:(nsIWebBrowser*)browser;
|
||||
@end
|
||||
|
||||
#endif // __nsCocoaBrowserView_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "CHBrowserView.h"
|
||||
|
||||
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
|
||||
{
|
||||
id urlbar;
|
||||
id status;
|
||||
id progress;
|
||||
id progressSuper;
|
||||
id mWindowController;
|
||||
NSTabViewItem* mTab;
|
||||
NSWindow* mWindow;
|
||||
|
||||
CHBrowserView* mBrowserView;
|
||||
NSString* defaultStatus;
|
||||
NSString* loadingStatus;
|
||||
|
||||
BOOL mIsPrimary;
|
||||
BOOL mIsBusy;
|
||||
BOOL mOffline;
|
||||
BOOL mListenersAttached; // We hook up our click and context menu listeners lazily.
|
||||
// If we never become the primary view, we don't bother creating the listeners.
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender;
|
||||
- (void)awakeFromNib;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
- (CHBrowserView*)getBrowserView;
|
||||
- (BOOL)isBusy;
|
||||
- (void)windowClosed;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: (id)aWindowController;
|
||||
-(void)disconnectView;
|
||||
-(void)setTab: (NSTabViewItem*)tab;
|
||||
|
||||
-(NSWindow*)getNativeWindow;
|
||||
|
||||
-(NSMenu*)getContextMenu;
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow;
|
||||
|
||||
// NSBrowserListener messages
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
|
||||
// NSBrowserContainer messages
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
|
||||
@end
|
|
@ -0,0 +1,429 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "CHBrowserWrapper.h"
|
||||
#import "BrowserWindowController.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "ContentClickListener.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCocoaBrowserService.h"
|
||||
|
||||
#define DOCUMENT_DONE_STRING @"Document: Done"
|
||||
#define LOADING_STRING @"Loading..."
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation CHBrowserWrapper
|
||||
|
||||
-(void)windowClosed
|
||||
{
|
||||
// Break the cycle.
|
||||
[mBrowserView destroyWebBrowser];
|
||||
[mBrowserView setContainer: nil];
|
||||
[mBrowserView removeListener: self];
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
printf("The browser wrapper died.\n");
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
[defaultStatus release];
|
||||
[loadingStatus release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender
|
||||
{
|
||||
[mBrowserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
|
||||
}
|
||||
|
||||
-(void)disconnectView
|
||||
{
|
||||
urlbar = nil;
|
||||
status = nil;
|
||||
progress = nil;
|
||||
progressSuper = nil;
|
||||
mIsPrimary = NO;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[mBrowserView setActive: NO];
|
||||
}
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow: (NSWindow*)aWindow
|
||||
{
|
||||
mTab = aTab;
|
||||
mWindow = aWindow;
|
||||
return [self initWithFrame: NSZeroRect];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ( (self = [super initWithFrame: frameRect]) ) {
|
||||
mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease];
|
||||
[self addSubview: mBrowserView];
|
||||
[mBrowserView setContainer:self];
|
||||
[mBrowserView addListener:self];
|
||||
mIsBusy = NO;
|
||||
mListenersAttached = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTab: (NSTabViewItem*)tab
|
||||
{
|
||||
mTab = tab;
|
||||
}
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: aWindowController
|
||||
{
|
||||
urlbar = aUrlbar;
|
||||
status = aStatus;
|
||||
progress = aProgress;
|
||||
progressSuper = [aProgress superview];
|
||||
mWindowController = aWindowController;
|
||||
|
||||
if (!mIsBusy)
|
||||
[progress removeFromSuperview];
|
||||
|
||||
defaultStatus = NULL;
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsPrimary = YES;
|
||||
|
||||
if ([[self window] isKeyWindow])
|
||||
[mBrowserView setActive: YES];
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mWindowController) // Only register if we're the content area.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(offlineModeChanged:)
|
||||
name:@"offlineModeChanged"
|
||||
object:nil];
|
||||
|
||||
// Update the URL bar.
|
||||
[mWindowController updateLocationFields:[self getCurrentURLSpec]];
|
||||
|
||||
if (mWindowController && !mListenersAttached) {
|
||||
mListenersAttached = YES;
|
||||
|
||||
// We need to hook up our click and context menu listeners.
|
||||
ContentClickListener* clickListener = new ContentClickListener(mWindowController);
|
||||
if (!clickListener)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
|
||||
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
|
||||
piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
|
||||
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
|
||||
rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*)getCurrentURLSpec
|
||||
{
|
||||
return [mBrowserView getCurrentURLSpec];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
NSRect bounds = [self bounds];
|
||||
[mBrowserView setFrame:bounds];
|
||||
}
|
||||
|
||||
-(BOOL)isBusy
|
||||
{
|
||||
return mIsBusy;
|
||||
}
|
||||
|
||||
- (void)onLoadingStarted
|
||||
{
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
defaultStatus = NULL;
|
||||
}
|
||||
|
||||
[progressSuper addSubview:progress];
|
||||
[progress setIndeterminate:YES];
|
||||
[progress startAnimation:self];
|
||||
|
||||
loadingStatus = LOADING_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsBusy = YES;
|
||||
[mTab setLabel: LOADING_STRING];
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
else {
|
||||
printf("background load.\n");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded
|
||||
{
|
||||
[progress setIndeterminate:YES];
|
||||
[progress stopAnimation:self];
|
||||
[progress removeFromSuperview];
|
||||
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
mIsBusy = NO;
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
}
|
||||
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes
|
||||
{
|
||||
if (maxBytes > 0) {
|
||||
BOOL isIndeterminate = [progress isIndeterminate];
|
||||
if (isIndeterminate) {
|
||||
[progress setIndeterminate:NO];
|
||||
}
|
||||
double val = ((double)currentBytes / (double)maxBytes) * 100.0;
|
||||
[progress setDoubleValue:val];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocationChange:(NSURL*)url
|
||||
{
|
||||
NSString* spec = [url absoluteString];
|
||||
[mWindowController updateLocationFields:spec];
|
||||
}
|
||||
|
||||
- (void)onStatusChange:(NSString*)aStatusString
|
||||
{
|
||||
[status setStringValue: aStatusString];
|
||||
}
|
||||
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type
|
||||
{
|
||||
if (type == NSStatusTypeScriptDefault) {
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
}
|
||||
defaultStatus = statusString;
|
||||
if (defaultStatus) {
|
||||
[defaultStatus retain];
|
||||
}
|
||||
}
|
||||
else if (!statusString) {
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[status setStringValue:statusString];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return [[mWindowController window] title];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
// We must be the primary content area.
|
||||
if (mIsPrimary && mWindowController) {
|
||||
if (mOffline) {
|
||||
NSString* newTitle;
|
||||
if (title && ![title isEqualToString:@""])
|
||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
||||
else
|
||||
newTitle = @"Untitled [Working Offline]";
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[[mWindowController window] setTitle:title];
|
||||
else
|
||||
[[mWindowController window] setTitle:@"Untitled"];
|
||||
}
|
||||
}
|
||||
|
||||
// Always set the tab.
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[mTab setLabel:title];
|
||||
else
|
||||
[mTab setLabel:@"Untitled"];
|
||||
}
|
||||
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
|
||||
{
|
||||
[mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode];
|
||||
}
|
||||
|
||||
-(NSMenu*)getContextMenu
|
||||
{
|
||||
return [mWindowController getContextMenu];
|
||||
}
|
||||
|
||||
-(NSWindow*)getNativeWindow
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
if (window)
|
||||
return window;
|
||||
|
||||
if (mWindow)
|
||||
return mWindow;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)offlineModeChanged: (NSNotification*)aNotification
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mOffline) {
|
||||
NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
float dx = dimensions.width - bounds.size.width;
|
||||
float dy = dimensions.height - bounds.size.height;
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
frame.size.width += dx;
|
||||
frame.size.height += dy;
|
||||
|
||||
[[self window] setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
#define NS_POPUP_BLOCK @"This Web site is attempting to open an unrequested popup window. Navigator can \
|
||||
automatically prevent Web sites from opening popup advertisements. Click OK to prevent all \
|
||||
unrequested popups (including this one) from opening."
|
||||
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return NS_OK; // Something bad happened if we can't get prefs.
|
||||
|
||||
PRBool showBlocker;
|
||||
pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
|
||||
|
||||
if (showBlocker) {
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(domWindow));
|
||||
PRBool isUnrequested;
|
||||
piWindow->IsLoadingOrRunningTimeout(&isUnrequested);
|
||||
if (isUnrequested) {
|
||||
// A popup is being opened while the page is currently loading. Offer to block the
|
||||
// popup.
|
||||
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
|
||||
BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected"
|
||||
text: NS_POPUP_BLOCK];
|
||||
|
||||
// This is a one-time dialog.
|
||||
pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
|
||||
|
||||
if (confirm) {
|
||||
pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
|
||||
pref->SetIntPref("dom.disable_open_click_delay", 1000);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
|
||||
prefService->SavePrefFile(nsnull);
|
||||
|
||||
if (confirm)
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
[controller setChromeMask: aMask];
|
||||
[controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
|
||||
[controller enterModalSession];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return [[controller getBrowserWrapper] getBrowserView];
|
||||
}
|
||||
|
||||
- (CHBrowserView*)getBrowserView
|
||||
{
|
||||
return mBrowserView;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- 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):
|
||||
* Mike Pinkerton <pinkerton@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//
|
||||
// protocol CHFind
|
||||
//
|
||||
// Any window who wants to be able to work with the Find dialog should implement
|
||||
// this protocol.
|
||||
//
|
||||
|
||||
@protocol CHFind
|
||||
|
||||
- (BOOL)findInPage:(NSString*)text;
|
||||
|
||||
@end
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
- (id)performDefaultImplementation {
|
||||
id controller = [[NSApp delegate] openBrowserWindowWithURLString: [self directParameter]];
|
||||
[[[controller getMyBrowserView] getBrowserView] setActive: YES];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -388,6 +388,8 @@
|
|||
F57074BF026D80DF01A80166,
|
||||
F51B70B8026EC98B01A80166,
|
||||
F5C3AB830270072A01A80166,
|
||||
F541495C02711A8301A80166,
|
||||
F541496002711B0101A80166,
|
||||
);
|
||||
isa = PBXHeadersBuildPhase;
|
||||
name = Headers;
|
||||
|
@ -474,6 +476,8 @@
|
|||
F57074C0026D80DF01A80166,
|
||||
F51B70B9026EC98B01A80166,
|
||||
F5C3AB840270072A01A80166,
|
||||
F541495D02711A8301A80166,
|
||||
F541496102711B0101A80166,
|
||||
);
|
||||
isa = PBXSourcesBuildPhase;
|
||||
name = Sources;
|
||||
|
@ -798,7 +802,7 @@
|
|||
};
|
||||
F5125A110202064D01FAFD9F = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.h;
|
||||
path = CHBrowserWrapper.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5125A140202064D01FAFD9F = {
|
||||
|
@ -809,7 +813,7 @@
|
|||
};
|
||||
F5137A1102676B9101026D05 = {
|
||||
isa = PBXFileReference;
|
||||
path = Find.h;
|
||||
path = CHFind.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5137A1202676B9101026D05 = {
|
||||
|
@ -1591,6 +1595,50 @@
|
|||
settings = {
|
||||
};
|
||||
};
|
||||
F541495A02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.h;
|
||||
refType = 4;
|
||||
};
|
||||
F541495B02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.m;
|
||||
refType = 4;
|
||||
};
|
||||
F541495C02711A8301A80166 = {
|
||||
fileRef = F541495A02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495D02711A8301A80166 = {
|
||||
fileRef = F541495B02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495E02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.h;
|
||||
refType = 2;
|
||||
};
|
||||
F541495F02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.m;
|
||||
refType = 2;
|
||||
};
|
||||
F541496002711B0101A80166 = {
|
||||
fileRef = F541495E02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541496102711B0101A80166 = {
|
||||
fileRef = F541495F02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F54EF7ED022A2F9C01A80165 = {
|
||||
isa = PBXFileReference;
|
||||
name = pipnss.jar;
|
||||
|
@ -1755,6 +1803,10 @@
|
|||
F564873A023C3857010001CA,
|
||||
F5C3AB810270072A01A80166,
|
||||
F5C3AB820270072A01A80166,
|
||||
F541495A02711A8301A80166,
|
||||
F541495B02711A8301A80166,
|
||||
F541495E02711B0001A80166,
|
||||
F541495F02711B0001A80166,
|
||||
);
|
||||
isa = PBXGroup;
|
||||
name = "Categories and Extensions";
|
||||
|
@ -1798,7 +1850,7 @@
|
|||
};
|
||||
F5607CB5023944AD01A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = GeckoUtils.h;
|
||||
path = CHGeckoUtils.h;
|
||||
refType = 2;
|
||||
};
|
||||
F5607CB6023944AE01A967DF = {
|
||||
|
@ -1949,12 +2001,12 @@
|
|||
};
|
||||
F57074B5026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.h;
|
||||
path = CHBookmarksToolbar.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B6026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.mm;
|
||||
path = CHBookmarksToolbar.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B7026BA85F01A80166 = {
|
||||
|
@ -1971,12 +2023,12 @@
|
|||
};
|
||||
F57074B9026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.h;
|
||||
path = CHBookmarksButton.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BA026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.mm;
|
||||
path = CHBookmarksButton.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BB026BFD0201A80166 = {
|
||||
|
@ -2497,7 +2549,7 @@
|
|||
};
|
||||
F5DE10E70209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.h;
|
||||
path = CHBrowserView.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10E80209DC0601A967DF = {
|
||||
|
@ -2512,7 +2564,7 @@
|
|||
};
|
||||
F5DE10EA0209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.mm;
|
||||
path = CHBrowserView.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10EB0209DC0601A967DF = {
|
||||
|
@ -2742,7 +2794,7 @@
|
|||
};
|
||||
F6BA6D4E01B2F8A601A962F7 = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.mm;
|
||||
path = CHBrowserWrapper.mm;
|
||||
refType = 2;
|
||||
};
|
||||
F6BA6D4F01B2F8A601A962F7 = {
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичный файл не отображается.
|
@ -388,6 +388,8 @@
|
|||
F57074BF026D80DF01A80166,
|
||||
F51B70B8026EC98B01A80166,
|
||||
F5C3AB830270072A01A80166,
|
||||
F541495C02711A8301A80166,
|
||||
F541496002711B0101A80166,
|
||||
);
|
||||
isa = PBXHeadersBuildPhase;
|
||||
name = Headers;
|
||||
|
@ -474,6 +476,8 @@
|
|||
F57074C0026D80DF01A80166,
|
||||
F51B70B9026EC98B01A80166,
|
||||
F5C3AB840270072A01A80166,
|
||||
F541495D02711A8301A80166,
|
||||
F541496102711B0101A80166,
|
||||
);
|
||||
isa = PBXSourcesBuildPhase;
|
||||
name = Sources;
|
||||
|
@ -798,7 +802,7 @@
|
|||
};
|
||||
F5125A110202064D01FAFD9F = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.h;
|
||||
path = CHBrowserWrapper.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5125A140202064D01FAFD9F = {
|
||||
|
@ -809,7 +813,7 @@
|
|||
};
|
||||
F5137A1102676B9101026D05 = {
|
||||
isa = PBXFileReference;
|
||||
path = Find.h;
|
||||
path = CHFind.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5137A1202676B9101026D05 = {
|
||||
|
@ -1591,6 +1595,50 @@
|
|||
settings = {
|
||||
};
|
||||
};
|
||||
F541495A02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.h;
|
||||
refType = 4;
|
||||
};
|
||||
F541495B02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.m;
|
||||
refType = 4;
|
||||
};
|
||||
F541495C02711A8301A80166 = {
|
||||
fileRef = F541495A02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495D02711A8301A80166 = {
|
||||
fileRef = F541495B02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495E02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.h;
|
||||
refType = 2;
|
||||
};
|
||||
F541495F02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.m;
|
||||
refType = 2;
|
||||
};
|
||||
F541496002711B0101A80166 = {
|
||||
fileRef = F541495E02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541496102711B0101A80166 = {
|
||||
fileRef = F541495F02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F54EF7ED022A2F9C01A80165 = {
|
||||
isa = PBXFileReference;
|
||||
name = pipnss.jar;
|
||||
|
@ -1755,6 +1803,10 @@
|
|||
F564873A023C3857010001CA,
|
||||
F5C3AB810270072A01A80166,
|
||||
F5C3AB820270072A01A80166,
|
||||
F541495A02711A8301A80166,
|
||||
F541495B02711A8301A80166,
|
||||
F541495E02711B0001A80166,
|
||||
F541495F02711B0001A80166,
|
||||
);
|
||||
isa = PBXGroup;
|
||||
name = "Categories and Extensions";
|
||||
|
@ -1798,7 +1850,7 @@
|
|||
};
|
||||
F5607CB5023944AD01A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = GeckoUtils.h;
|
||||
path = CHGeckoUtils.h;
|
||||
refType = 2;
|
||||
};
|
||||
F5607CB6023944AE01A967DF = {
|
||||
|
@ -1949,12 +2001,12 @@
|
|||
};
|
||||
F57074B5026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.h;
|
||||
path = CHBookmarksToolbar.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B6026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.mm;
|
||||
path = CHBookmarksToolbar.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B7026BA85F01A80166 = {
|
||||
|
@ -1971,12 +2023,12 @@
|
|||
};
|
||||
F57074B9026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.h;
|
||||
path = CHBookmarksButton.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BA026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.mm;
|
||||
path = CHBookmarksButton.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BB026BFD0201A80166 = {
|
||||
|
@ -2497,7 +2549,7 @@
|
|||
};
|
||||
F5DE10E70209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.h;
|
||||
path = CHBrowserView.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10E80209DC0601A967DF = {
|
||||
|
@ -2512,7 +2564,7 @@
|
|||
};
|
||||
F5DE10EA0209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.mm;
|
||||
path = CHBrowserView.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10EB0209DC0601A967DF = {
|
||||
|
@ -2742,7 +2794,7 @@
|
|||
};
|
||||
F6BA6D4E01B2F8A601A962F7 = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.mm;
|
||||
path = CHBrowserWrapper.mm;
|
||||
refType = 2;
|
||||
};
|
||||
F6BA6D4F01B2F8A601A962F7 = {
|
||||
|
|
Двоичный файл не отображается.
Двоичный файл не отображается.
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичные данные
camino/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичный файл не отображается.
|
@ -28,7 +28,7 @@
|
|||
|
||||
- (id)performDefaultImplementation {
|
||||
id controller = [[NSApp delegate] openBrowserWindowWithURLString: [self directParameter]];
|
||||
[[[controller getMyBrowserView] getBrowserView] setActive: YES];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
@interface CHBookmarksButton : NSButton {
|
||||
|
||||
nsIDOMElement* mElement;
|
||||
BOOL mIsFolder;
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt;
|
||||
-(nsIDOMElement*)element;
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender;
|
||||
|
||||
@end
|
|
@ -0,0 +1,127 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsString.h"
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation CHBookmarksButton
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mElement = nsnull;
|
||||
[self setBezelStyle: NSRegularSquareBezelStyle];
|
||||
[self setBordered: NO];
|
||||
[self setImagePosition: NSImageLeft];
|
||||
[self setRefusesFirstResponder: YES];
|
||||
[self setFont: [NSFont labelFontOfSize: 11.0]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender
|
||||
{
|
||||
// See if we're a group.
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
if (!group.IsEmpty()) {
|
||||
BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the href attribute. This is the URL we want to load.
|
||||
nsAutoString href;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCAutoString cref; cref.AssignWithConversion(href);
|
||||
if (cref.IsEmpty())
|
||||
return;
|
||||
|
||||
NSString* url = [NSString stringWithCString: cref.get()];
|
||||
|
||||
// Now load the URL in the window.
|
||||
[[[self window] windowController] loadURL:[NSURL URLWithString: url]];
|
||||
|
||||
// Focus and activate our content area.
|
||||
[[[[[self window] windowController] getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)aRect
|
||||
{
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
|
||||
{
|
||||
return [[self superview] menu];
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent*)aEvent
|
||||
{
|
||||
if (mIsFolder) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
|
||||
NSMenu* menu = BookmarksService::LocateMenu(content);
|
||||
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
|
||||
}
|
||||
else
|
||||
[super mouseDown: aEvent];
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt
|
||||
{
|
||||
mElement = aElt;
|
||||
nsAutoString tag;
|
||||
mElement->GetLocalName(tag);
|
||||
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
|
||||
if (!group.IsEmpty()) {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
else if (tag.Equals(NS_LITERAL_STRING("folder"))) {
|
||||
[self setImage: [NSImage imageNamed: @"folder"]];
|
||||
mIsFolder = YES;
|
||||
}
|
||||
else {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
[self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
|
||||
}
|
||||
|
||||
-(nsIDOMElement*)element
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface CHBookmarksToolbar : NSView {
|
||||
BookmarksService* mBookmarks;
|
||||
NSMutableArray* mButtons;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar;
|
||||
|
||||
// Called to construct the initial set of personal toolbar buttons.
|
||||
-(void)buildButtonList;
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex;
|
||||
-(void)removeButton: (nsIDOMElement*)aElt;
|
||||
|
||||
// Called to lay out the buttons on the toolbar.
|
||||
-(void)reflowButtons;
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex;
|
||||
|
||||
@end
|
|
@ -0,0 +1,227 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "BookmarksService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
@implementation CHBookmarksToolbar
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mButtons = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar
|
||||
{
|
||||
// Initialization code here.
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
mBookmarks->EnsureToolbarRoot();
|
||||
[self buildButtonList];
|
||||
}
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
[mButtons autorelease];
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)aRect {
|
||||
// Fill the background with our background color.
|
||||
//[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set];
|
||||
//NSRectFill(aRect);
|
||||
|
||||
//printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
|
||||
|
||||
if (aRect.origin.y + aRect.size.height ==
|
||||
[self bounds].size.height) {
|
||||
// The personal toolbar is 21 pixels tall. The bottom two pixels
|
||||
// are a separator.
|
||||
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
|
||||
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
|
||||
}
|
||||
|
||||
// The buttons will paint themselves. Just call our base class method.
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(void)buildButtonList
|
||||
{
|
||||
// Build the buttons, and then lay them all out.
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
|
||||
if (childElt) {
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: childElt];
|
||||
[self addSubview: button];
|
||||
[mButtons addObject: button];
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
|
||||
[self reflowButtons];
|
||||
}
|
||||
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
|
||||
{
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: aElt];
|
||||
[self addSubview: button];
|
||||
[mButtons insertObject: button atIndex: aIndex];
|
||||
[self reflowButtonsStartingAtIndex: aIndex];
|
||||
}
|
||||
|
||||
-(void)removeButton: (nsIDOMElement*)aElt
|
||||
{
|
||||
int count = [mButtons count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
if ([button element] == aElt) {
|
||||
[mButtons removeObjectAtIndex: i];
|
||||
[button removeFromSuperview];
|
||||
if (count > i)
|
||||
[self reflowButtonsStartingAtIndex: i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
-(void)reflowButtons
|
||||
{
|
||||
[self reflowButtonsStartingAtIndex: 0];
|
||||
}
|
||||
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex
|
||||
{
|
||||
float oldHeight = [self frame].size.height;
|
||||
float computedHeight = 18;
|
||||
int count = [mButtons count];
|
||||
float currY = 1.0;
|
||||
float prevX = 2.0;
|
||||
if (aIndex > 0) {
|
||||
CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)];
|
||||
prevX += [prevButton frame].origin.x + [prevButton frame].size.width;
|
||||
currY = [prevButton frame].origin.y;
|
||||
}
|
||||
for (int i = aIndex; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
[button sizeToFit];
|
||||
float width = [button frame].size.width;
|
||||
float height = [button frame].size.height;
|
||||
if (width > 150)
|
||||
width = 150;
|
||||
if (height < 16)
|
||||
height = 16; // Our folder tiff is only 15 pixels for some reason.
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
|
||||
prevX += [button frame].size.width + 2;
|
||||
|
||||
if ([self bounds].size.width < prevX) {
|
||||
// The previous button didn't fit. We need to make a new row.
|
||||
currY += 18;
|
||||
computedHeight += 18;
|
||||
if (computedHeight > oldHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y+(oldHeight-computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
prevX = 2;
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
prevX += [button frame].size.width + 2;
|
||||
}
|
||||
|
||||
[button setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float currentHeight = [self frame].size.height;
|
||||
if (computedHeight != currentHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (currentHeight - computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float sizeChange = computedHeight - oldHeight;
|
||||
if (sizeChange != 0) {
|
||||
// We need to adjust the content area.
|
||||
NSView* view = [[[self window] windowController] getTabBrowser];
|
||||
[view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y,
|
||||
[view frame].size.width, [view frame].size.height - sizeChange)];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped
|
||||
{
|
||||
return YES; // Use flipped coords, so we can layout out from top row to bottom row.
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)aRect
|
||||
{
|
||||
NSRect oldFrame = [self frame];
|
||||
[super setFrame:aRect];
|
||||
|
||||
if (oldFrame.size.width == aRect.size.width)
|
||||
return;
|
||||
|
||||
int count = [mButtons count];
|
||||
if (count <= 2)
|
||||
return; // We have too few buttons to care.
|
||||
|
||||
// Do some optimizations when we have only one row.
|
||||
if (aRect.size.height < 25) // We have only one row.
|
||||
{
|
||||
if (oldFrame.size.width < aRect.size.width)
|
||||
// We got bigger. If we already only have one row, just bail.
|
||||
// This will optimize for a common resizing case.
|
||||
return;
|
||||
else {
|
||||
// We got smaller. Just go to the last button and see if it is outside
|
||||
// our bounds.
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)];
|
||||
if ([button frame].origin.x + [button frame].size.width >
|
||||
[self bounds].size.width - 2) {
|
||||
// The button doesn't fit any more. Reflow starting at this index.
|
||||
[self reflowButtonsStartingAtIndex:(count-1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we got bigger or smaller. We could gain or lose a row.
|
||||
[self reflowButtons];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "CHBrowserView.h"
|
||||
|
||||
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
|
||||
{
|
||||
id urlbar;
|
||||
id status;
|
||||
id progress;
|
||||
id progressSuper;
|
||||
id mWindowController;
|
||||
NSTabViewItem* mTab;
|
||||
NSWindow* mWindow;
|
||||
|
||||
CHBrowserView* mBrowserView;
|
||||
NSString* defaultStatus;
|
||||
NSString* loadingStatus;
|
||||
|
||||
BOOL mIsPrimary;
|
||||
BOOL mIsBusy;
|
||||
BOOL mOffline;
|
||||
BOOL mListenersAttached; // We hook up our click and context menu listeners lazily.
|
||||
// If we never become the primary view, we don't bother creating the listeners.
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender;
|
||||
- (void)awakeFromNib;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
- (CHBrowserView*)getBrowserView;
|
||||
- (BOOL)isBusy;
|
||||
- (void)windowClosed;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: (id)aWindowController;
|
||||
-(void)disconnectView;
|
||||
-(void)setTab: (NSTabViewItem*)tab;
|
||||
|
||||
-(NSWindow*)getNativeWindow;
|
||||
|
||||
-(NSMenu*)getContextMenu;
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow;
|
||||
|
||||
// NSBrowserListener messages
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
|
||||
// NSBrowserContainer messages
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
|
||||
@end
|
|
@ -0,0 +1,429 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "CHBrowserWrapper.h"
|
||||
#import "BrowserWindowController.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "ContentClickListener.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCocoaBrowserService.h"
|
||||
|
||||
#define DOCUMENT_DONE_STRING @"Document: Done"
|
||||
#define LOADING_STRING @"Loading..."
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation CHBrowserWrapper
|
||||
|
||||
-(void)windowClosed
|
||||
{
|
||||
// Break the cycle.
|
||||
[mBrowserView destroyWebBrowser];
|
||||
[mBrowserView setContainer: nil];
|
||||
[mBrowserView removeListener: self];
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
printf("The browser wrapper died.\n");
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
[defaultStatus release];
|
||||
[loadingStatus release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender
|
||||
{
|
||||
[mBrowserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
|
||||
}
|
||||
|
||||
-(void)disconnectView
|
||||
{
|
||||
urlbar = nil;
|
||||
status = nil;
|
||||
progress = nil;
|
||||
progressSuper = nil;
|
||||
mIsPrimary = NO;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[mBrowserView setActive: NO];
|
||||
}
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow: (NSWindow*)aWindow
|
||||
{
|
||||
mTab = aTab;
|
||||
mWindow = aWindow;
|
||||
return [self initWithFrame: NSZeroRect];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ( (self = [super initWithFrame: frameRect]) ) {
|
||||
mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease];
|
||||
[self addSubview: mBrowserView];
|
||||
[mBrowserView setContainer:self];
|
||||
[mBrowserView addListener:self];
|
||||
mIsBusy = NO;
|
||||
mListenersAttached = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTab: (NSTabViewItem*)tab
|
||||
{
|
||||
mTab = tab;
|
||||
}
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: aWindowController
|
||||
{
|
||||
urlbar = aUrlbar;
|
||||
status = aStatus;
|
||||
progress = aProgress;
|
||||
progressSuper = [aProgress superview];
|
||||
mWindowController = aWindowController;
|
||||
|
||||
if (!mIsBusy)
|
||||
[progress removeFromSuperview];
|
||||
|
||||
defaultStatus = NULL;
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsPrimary = YES;
|
||||
|
||||
if ([[self window] isKeyWindow])
|
||||
[mBrowserView setActive: YES];
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mWindowController) // Only register if we're the content area.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(offlineModeChanged:)
|
||||
name:@"offlineModeChanged"
|
||||
object:nil];
|
||||
|
||||
// Update the URL bar.
|
||||
[mWindowController updateLocationFields:[self getCurrentURLSpec]];
|
||||
|
||||
if (mWindowController && !mListenersAttached) {
|
||||
mListenersAttached = YES;
|
||||
|
||||
// We need to hook up our click and context menu listeners.
|
||||
ContentClickListener* clickListener = new ContentClickListener(mWindowController);
|
||||
if (!clickListener)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
|
||||
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
|
||||
piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
|
||||
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
|
||||
rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*)getCurrentURLSpec
|
||||
{
|
||||
return [mBrowserView getCurrentURLSpec];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
NSRect bounds = [self bounds];
|
||||
[mBrowserView setFrame:bounds];
|
||||
}
|
||||
|
||||
-(BOOL)isBusy
|
||||
{
|
||||
return mIsBusy;
|
||||
}
|
||||
|
||||
- (void)onLoadingStarted
|
||||
{
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
defaultStatus = NULL;
|
||||
}
|
||||
|
||||
[progressSuper addSubview:progress];
|
||||
[progress setIndeterminate:YES];
|
||||
[progress startAnimation:self];
|
||||
|
||||
loadingStatus = LOADING_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsBusy = YES;
|
||||
[mTab setLabel: LOADING_STRING];
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
else {
|
||||
printf("background load.\n");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded
|
||||
{
|
||||
[progress setIndeterminate:YES];
|
||||
[progress stopAnimation:self];
|
||||
[progress removeFromSuperview];
|
||||
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
mIsBusy = NO;
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
}
|
||||
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes
|
||||
{
|
||||
if (maxBytes > 0) {
|
||||
BOOL isIndeterminate = [progress isIndeterminate];
|
||||
if (isIndeterminate) {
|
||||
[progress setIndeterminate:NO];
|
||||
}
|
||||
double val = ((double)currentBytes / (double)maxBytes) * 100.0;
|
||||
[progress setDoubleValue:val];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocationChange:(NSURL*)url
|
||||
{
|
||||
NSString* spec = [url absoluteString];
|
||||
[mWindowController updateLocationFields:spec];
|
||||
}
|
||||
|
||||
- (void)onStatusChange:(NSString*)aStatusString
|
||||
{
|
||||
[status setStringValue: aStatusString];
|
||||
}
|
||||
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type
|
||||
{
|
||||
if (type == NSStatusTypeScriptDefault) {
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
}
|
||||
defaultStatus = statusString;
|
||||
if (defaultStatus) {
|
||||
[defaultStatus retain];
|
||||
}
|
||||
}
|
||||
else if (!statusString) {
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[status setStringValue:statusString];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return [[mWindowController window] title];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
// We must be the primary content area.
|
||||
if (mIsPrimary && mWindowController) {
|
||||
if (mOffline) {
|
||||
NSString* newTitle;
|
||||
if (title && ![title isEqualToString:@""])
|
||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
||||
else
|
||||
newTitle = @"Untitled [Working Offline]";
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[[mWindowController window] setTitle:title];
|
||||
else
|
||||
[[mWindowController window] setTitle:@"Untitled"];
|
||||
}
|
||||
}
|
||||
|
||||
// Always set the tab.
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[mTab setLabel:title];
|
||||
else
|
||||
[mTab setLabel:@"Untitled"];
|
||||
}
|
||||
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
|
||||
{
|
||||
[mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode];
|
||||
}
|
||||
|
||||
-(NSMenu*)getContextMenu
|
||||
{
|
||||
return [mWindowController getContextMenu];
|
||||
}
|
||||
|
||||
-(NSWindow*)getNativeWindow
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
if (window)
|
||||
return window;
|
||||
|
||||
if (mWindow)
|
||||
return mWindow;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)offlineModeChanged: (NSNotification*)aNotification
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mOffline) {
|
||||
NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
float dx = dimensions.width - bounds.size.width;
|
||||
float dy = dimensions.height - bounds.size.height;
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
frame.size.width += dx;
|
||||
frame.size.height += dy;
|
||||
|
||||
[[self window] setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
#define NS_POPUP_BLOCK @"This Web site is attempting to open an unrequested popup window. Navigator can \
|
||||
automatically prevent Web sites from opening popup advertisements. Click OK to prevent all \
|
||||
unrequested popups (including this one) from opening."
|
||||
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return NS_OK; // Something bad happened if we can't get prefs.
|
||||
|
||||
PRBool showBlocker;
|
||||
pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
|
||||
|
||||
if (showBlocker) {
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(domWindow));
|
||||
PRBool isUnrequested;
|
||||
piWindow->IsLoadingOrRunningTimeout(&isUnrequested);
|
||||
if (isUnrequested) {
|
||||
// A popup is being opened while the page is currently loading. Offer to block the
|
||||
// popup.
|
||||
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
|
||||
BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected"
|
||||
text: NS_POPUP_BLOCK];
|
||||
|
||||
// This is a one-time dialog.
|
||||
pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
|
||||
|
||||
if (confirm) {
|
||||
pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
|
||||
pref->SetIntPref("dom.disable_open_click_delay", 1000);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
|
||||
prefService->SavePrefFile(nsnull);
|
||||
|
||||
if (confirm)
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
[controller setChromeMask: aMask];
|
||||
[controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
|
||||
[controller enterModalSession];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return [[controller getBrowserWrapper] getBrowserView];
|
||||
}
|
||||
|
||||
- (CHBrowserView*)getBrowserView
|
||||
{
|
||||
return mBrowserView;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,158 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsCocoaBrowserView_h__
|
||||
#define __nsCocoaBrowserView_h__
|
||||
|
||||
#undef DARWIN
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class CHBrowserView;
|
||||
class nsCocoaBrowserListener;
|
||||
class nsIDOMWindow;
|
||||
class nsIWebBrowser;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMEvent;
|
||||
class nsIWebBrowserFind;
|
||||
|
||||
// Protocol implemented by anyone interested in progress
|
||||
// related to a BrowserView. A listener should explicitly
|
||||
// register itself with the view using the addListener
|
||||
// method.
|
||||
@protocol NSBrowserListener
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
// Invoked regularly as data associated with a page streams
|
||||
// in. If the total number of bytes expected is unknown,
|
||||
// maxBytes is -1.
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
|
||||
@end
|
||||
|
||||
typedef enum {
|
||||
NSStatusTypeScript = 0x0001,
|
||||
NSStatusTypeScriptDefault = 0x0002,
|
||||
NSStatusTypeLink = 0x0003,
|
||||
} NSStatusType;
|
||||
|
||||
@protocol NSBrowserContainer
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
// Set the dimensions of our NSView. The container might need to do
|
||||
// some adjustment, so the view doesn't do it directly.
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
// Create a new browser container window and return the contained view.
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
@end
|
||||
|
||||
enum {
|
||||
NSLoadFlagsNone = 0x0000,
|
||||
NSLoadFlagsDontPutInHistory = 0x0010,
|
||||
NSLoadFlagsReplaceHistoryEntry = 0x0020,
|
||||
NSLoadFlagsBypassCacheAndProxy = 0x0040
|
||||
};
|
||||
|
||||
enum {
|
||||
NSStopLoadNetwork = 0x01,
|
||||
NSStopLoadContent = 0x02,
|
||||
NSStopLoadAll = 0x03
|
||||
};
|
||||
|
||||
@interface CHBrowserView : NSView
|
||||
{
|
||||
nsIWebBrowser* _webBrowser;
|
||||
nsCocoaBrowserListener* _listener;
|
||||
NSWindow* mWindow;
|
||||
}
|
||||
|
||||
// NSView overrides
|
||||
- (id)initWithFrame:(NSRect)frame;
|
||||
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow;
|
||||
|
||||
- (void)dealloc;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// nsIWebBrowser methods
|
||||
- (void)addListener:(id <NSBrowserListener>)listener;
|
||||
- (void)removeListener:(id <NSBrowserListener>)listener;
|
||||
- (void)setContainer:(id <NSBrowserContainer>)container;
|
||||
- (nsIDOMWindow*)getContentWindow;
|
||||
|
||||
// nsIWebNavigation methods
|
||||
- (void)loadURI:(NSURL *)url flags:(unsigned int)flags;
|
||||
- (void)reload:(unsigned int)flags;
|
||||
- (BOOL)canGoBack;
|
||||
- (BOOL)canGoForward;
|
||||
- (void)goBack;
|
||||
- (void)goForward;
|
||||
- (void)gotoIndex:(int)index;
|
||||
- (void)stop:(unsigned int)flags;
|
||||
- (NSURL*)getCurrentURI;
|
||||
|
||||
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
|
||||
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
|
||||
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
|
||||
|
||||
- (void)printDocument;
|
||||
|
||||
- (BOOL)findInPage:(NSString*)inText;
|
||||
|
||||
-(IBAction)cut:(id)aSender;
|
||||
-(IBAction)copy:(id)aSender;
|
||||
-(IBAction)paste:(id)aSender;
|
||||
-(IBAction)clear:(id)aSender;
|
||||
-(IBAction)selectAll:(id)aSender;
|
||||
-(IBAction)undo:(id)aSender;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
- (void)setActive: (BOOL)aIsActive;
|
||||
|
||||
- (NSMenu*)getContextMenu;
|
||||
- (NSWindow*)getNativeWindow;
|
||||
|
||||
- (void)destroyWebBrowser;
|
||||
- (nsIWebBrowser*)getWebBrowser;
|
||||
- (nsCocoaBrowserListener*)getCocoaBrowserListener;
|
||||
- (void)setWebBrowser:(nsIWebBrowser*)browser;
|
||||
@end
|
||||
|
||||
#endif // __nsCocoaBrowserView_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,179 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __GeckoUtils_h__
|
||||
#define __GeckoUtils_h__
|
||||
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIDOMHTMLAreaElement.h"
|
||||
#include "nsIDOMHTMLLinkElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
class CHGeckoUtils
|
||||
{
|
||||
public:
|
||||
static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult) {
|
||||
nsAutoString text;
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
aNode->GetFirstChild(getter_AddRefs(node));
|
||||
PRUint32 depth = 1;
|
||||
while (node && depth) {
|
||||
nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node));
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (charData && nodeType == nsIDOMNode::TEXT_NODE) {
|
||||
// Add this text to our collection.
|
||||
text += NS_LITERAL_STRING(" ");
|
||||
nsAutoString data;
|
||||
charData->GetData(data);
|
||||
text += data;
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node));
|
||||
if (img) {
|
||||
nsAutoString altText;
|
||||
img->GetAlt(altText);
|
||||
if (!altText.IsEmpty()) {
|
||||
text = altText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the next node to test.
|
||||
PRBool hasChildNodes;
|
||||
node->HasChildNodes(&hasChildNodes);
|
||||
if (hasChildNodes) {
|
||||
nsCOMPtr<nsIDOMNode> temp = node;
|
||||
temp->GetFirstChild(getter_AddRefs(node));
|
||||
depth++;
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> nextSibling;
|
||||
node->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
if (nextSibling)
|
||||
node = nextSibling;
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
node->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (!parentNode)
|
||||
node = nsnull;
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> nextSibling;
|
||||
parentNode->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
node = nextSibling;
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text.CompressWhitespace();
|
||||
aResult = text;
|
||||
};
|
||||
|
||||
static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> content(do_QueryInterface(aNode));
|
||||
nsAutoString localName;
|
||||
if (content)
|
||||
content->GetLocalName(localName);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> linkContent;
|
||||
ToLowerCase(localName);
|
||||
nsAutoString href;
|
||||
if (localName.Equals(NS_LITERAL_STRING("a")) ||
|
||||
localName.Equals(NS_LITERAL_STRING("area")) ||
|
||||
localName.Equals(NS_LITERAL_STRING("link"))) {
|
||||
PRBool hasAttr;
|
||||
content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
|
||||
if (hasAttr) {
|
||||
linkContent = content;
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
|
||||
if (anchor)
|
||||
anchor->GetHref(href);
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(linkContent));
|
||||
if (area)
|
||||
area->GetHref(href);
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLLinkElement> link(do_QueryInterface(linkContent));
|
||||
if (link)
|
||||
link->GetHref(href);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> curr = aNode;
|
||||
nsCOMPtr<nsIDOMNode> temp = curr;
|
||||
temp->GetParentNode(getter_AddRefs(curr));
|
||||
while (curr) {
|
||||
content = do_QueryInterface(curr);
|
||||
if (!content)
|
||||
break;
|
||||
content->GetLocalName(localName);
|
||||
ToLowerCase(localName);
|
||||
if (localName.Equals(NS_LITERAL_STRING("a"))) {
|
||||
PRBool hasAttr;
|
||||
content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
|
||||
if (hasAttr) {
|
||||
linkContent = content;
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
|
||||
if (anchor)
|
||||
anchor->GetHref(href);
|
||||
}
|
||||
else
|
||||
linkContent = nsnull; // Links can't be nested.
|
||||
break;
|
||||
}
|
||||
|
||||
temp = curr;
|
||||
temp->GetParentNode(getter_AddRefs(curr));
|
||||
}
|
||||
}
|
||||
|
||||
*aLinkContent = linkContent;
|
||||
NS_IF_ADDREF(*aLinkContent);
|
||||
|
||||
aHref = href;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
#import <AppKit/NSImage.h>
|
||||
|
||||
@interface NSImage (CHImageAdditions)
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta;
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op;
|
||||
- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale;
|
||||
@end
|
|
@ -0,0 +1,36 @@
|
|||
#import "CHImageAdditions.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@implementation NSImage (CHImageAdditions)
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta {
|
||||
CGContextRef context;
|
||||
|
||||
context = [[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextSaveGState( context ); {
|
||||
CGContextTranslateCTM( context, 0, NSMaxY( rect ) );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
|
||||
rect.origin.y = 0;
|
||||
[self drawInRect:rect fromRect:NSZeroRect operation:op fraction:delta];
|
||||
} CGContextRestoreGState( context );
|
||||
}
|
||||
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op {
|
||||
[self drawFlippedInRect:rect operation:op fraction:1.0];
|
||||
}
|
||||
|
||||
- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale
|
||||
{
|
||||
if (!badge)
|
||||
return;
|
||||
|
||||
[badge setScalesWhenResized:YES];
|
||||
[badge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)];
|
||||
|
||||
[self lockFocus];
|
||||
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
|
||||
[badge dissolveToPoint:NSMakePoint([self size].width - [badge size].width,0) fraction:alpha];
|
||||
[self unlockFocus];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,12 @@
|
|||
#import <AppKit/NSToolbar.h>
|
||||
|
||||
@interface NSToolbar (CHToolbarCustomizableAdditions)
|
||||
- (BOOL) alwaysCustomizableByDrag;
|
||||
- (void) setAlwaysCustomizableByDrag:(BOOL) flag;
|
||||
|
||||
- (BOOL) showsContextMenu;
|
||||
- (void) setShowsContextMenu:(BOOL) flag;
|
||||
|
||||
- (unsigned int) indexOfFirstMovableItem;
|
||||
- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex;
|
||||
@end
|
|
@ -0,0 +1,28 @@
|
|||
#import "CHToolbarAdditions.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@implementation NSToolbar (CHToolbarCustomizableAdditions)
|
||||
- (BOOL) alwaysCustomizableByDrag {
|
||||
return (BOOL) _tbFlags.clickAndDragPerformsCustomization;
|
||||
}
|
||||
|
||||
- (void) setAlwaysCustomizableByDrag:(BOOL) flag {
|
||||
_tbFlags.clickAndDragPerformsCustomization = (unsigned int) flag & 1;
|
||||
}
|
||||
|
||||
- (BOOL) showsContextMenu {
|
||||
return (BOOL) ! _tbFlags.showsNoContextMenu;
|
||||
}
|
||||
|
||||
- (void) setShowsContextMenu:(BOOL) flag {
|
||||
_tbFlags.showsNoContextMenu = (unsigned int) ! flag & 1;
|
||||
}
|
||||
|
||||
- (unsigned int) indexOfFirstMovableItem {
|
||||
return (unsigned int) _tbFlags.firstMoveableItemIndex;
|
||||
}
|
||||
|
||||
- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex {
|
||||
_tbFlags.firstMoveableItemIndex = (unsigned int) anIndex & 0x3F;
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- 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):
|
||||
* Mike Pinkerton <pinkerton@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//
|
||||
// protocol CHFind
|
||||
//
|
||||
// Any window who wants to be able to work with the Find dialog should implement
|
||||
// this protocol.
|
||||
//
|
||||
|
||||
@protocol CHFind
|
||||
|
||||
- (BOOL)findInPage:(NSString*)text;
|
||||
|
||||
@end
|
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичный файл не отображается.
|
@ -0,0 +1,40 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
@interface CHBookmarksButton : NSButton {
|
||||
|
||||
nsIDOMElement* mElement;
|
||||
BOOL mIsFolder;
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt;
|
||||
-(nsIDOMElement*)element;
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender;
|
||||
|
||||
@end
|
|
@ -0,0 +1,127 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsString.h"
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation CHBookmarksButton
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mElement = nsnull;
|
||||
[self setBezelStyle: NSRegularSquareBezelStyle];
|
||||
[self setBordered: NO];
|
||||
[self setImagePosition: NSImageLeft];
|
||||
[self setRefusesFirstResponder: YES];
|
||||
[self setFont: [NSFont labelFontOfSize: 11.0]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender
|
||||
{
|
||||
// See if we're a group.
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
if (!group.IsEmpty()) {
|
||||
BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the href attribute. This is the URL we want to load.
|
||||
nsAutoString href;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCAutoString cref; cref.AssignWithConversion(href);
|
||||
if (cref.IsEmpty())
|
||||
return;
|
||||
|
||||
NSString* url = [NSString stringWithCString: cref.get()];
|
||||
|
||||
// Now load the URL in the window.
|
||||
[[[self window] windowController] loadURL:[NSURL URLWithString: url]];
|
||||
|
||||
// Focus and activate our content area.
|
||||
[[[[[self window] windowController] getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)aRect
|
||||
{
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
|
||||
{
|
||||
return [[self superview] menu];
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent*)aEvent
|
||||
{
|
||||
if (mIsFolder) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
|
||||
NSMenu* menu = BookmarksService::LocateMenu(content);
|
||||
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
|
||||
}
|
||||
else
|
||||
[super mouseDown: aEvent];
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt
|
||||
{
|
||||
mElement = aElt;
|
||||
nsAutoString tag;
|
||||
mElement->GetLocalName(tag);
|
||||
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
|
||||
if (!group.IsEmpty()) {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
else if (tag.Equals(NS_LITERAL_STRING("folder"))) {
|
||||
[self setImage: [NSImage imageNamed: @"folder"]];
|
||||
mIsFolder = YES;
|
||||
}
|
||||
else {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
[self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
|
||||
}
|
||||
|
||||
-(nsIDOMElement*)element
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface CHBookmarksToolbar : NSView {
|
||||
BookmarksService* mBookmarks;
|
||||
NSMutableArray* mButtons;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar;
|
||||
|
||||
// Called to construct the initial set of personal toolbar buttons.
|
||||
-(void)buildButtonList;
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex;
|
||||
-(void)removeButton: (nsIDOMElement*)aElt;
|
||||
|
||||
// Called to lay out the buttons on the toolbar.
|
||||
-(void)reflowButtons;
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex;
|
||||
|
||||
@end
|
|
@ -0,0 +1,227 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "BookmarksService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
@implementation CHBookmarksToolbar
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mButtons = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar
|
||||
{
|
||||
// Initialization code here.
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
mBookmarks->EnsureToolbarRoot();
|
||||
[self buildButtonList];
|
||||
}
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
[mButtons autorelease];
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)aRect {
|
||||
// Fill the background with our background color.
|
||||
//[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set];
|
||||
//NSRectFill(aRect);
|
||||
|
||||
//printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
|
||||
|
||||
if (aRect.origin.y + aRect.size.height ==
|
||||
[self bounds].size.height) {
|
||||
// The personal toolbar is 21 pixels tall. The bottom two pixels
|
||||
// are a separator.
|
||||
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
|
||||
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
|
||||
}
|
||||
|
||||
// The buttons will paint themselves. Just call our base class method.
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(void)buildButtonList
|
||||
{
|
||||
// Build the buttons, and then lay them all out.
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
|
||||
if (childElt) {
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: childElt];
|
||||
[self addSubview: button];
|
||||
[mButtons addObject: button];
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
|
||||
[self reflowButtons];
|
||||
}
|
||||
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
|
||||
{
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: aElt];
|
||||
[self addSubview: button];
|
||||
[mButtons insertObject: button atIndex: aIndex];
|
||||
[self reflowButtonsStartingAtIndex: aIndex];
|
||||
}
|
||||
|
||||
-(void)removeButton: (nsIDOMElement*)aElt
|
||||
{
|
||||
int count = [mButtons count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
if ([button element] == aElt) {
|
||||
[mButtons removeObjectAtIndex: i];
|
||||
[button removeFromSuperview];
|
||||
if (count > i)
|
||||
[self reflowButtonsStartingAtIndex: i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
-(void)reflowButtons
|
||||
{
|
||||
[self reflowButtonsStartingAtIndex: 0];
|
||||
}
|
||||
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex
|
||||
{
|
||||
float oldHeight = [self frame].size.height;
|
||||
float computedHeight = 18;
|
||||
int count = [mButtons count];
|
||||
float currY = 1.0;
|
||||
float prevX = 2.0;
|
||||
if (aIndex > 0) {
|
||||
CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)];
|
||||
prevX += [prevButton frame].origin.x + [prevButton frame].size.width;
|
||||
currY = [prevButton frame].origin.y;
|
||||
}
|
||||
for (int i = aIndex; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
[button sizeToFit];
|
||||
float width = [button frame].size.width;
|
||||
float height = [button frame].size.height;
|
||||
if (width > 150)
|
||||
width = 150;
|
||||
if (height < 16)
|
||||
height = 16; // Our folder tiff is only 15 pixels for some reason.
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
|
||||
prevX += [button frame].size.width + 2;
|
||||
|
||||
if ([self bounds].size.width < prevX) {
|
||||
// The previous button didn't fit. We need to make a new row.
|
||||
currY += 18;
|
||||
computedHeight += 18;
|
||||
if (computedHeight > oldHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y+(oldHeight-computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
prevX = 2;
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
prevX += [button frame].size.width + 2;
|
||||
}
|
||||
|
||||
[button setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float currentHeight = [self frame].size.height;
|
||||
if (computedHeight != currentHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (currentHeight - computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float sizeChange = computedHeight - oldHeight;
|
||||
if (sizeChange != 0) {
|
||||
// We need to adjust the content area.
|
||||
NSView* view = [[[self window] windowController] getTabBrowser];
|
||||
[view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y,
|
||||
[view frame].size.width, [view frame].size.height - sizeChange)];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped
|
||||
{
|
||||
return YES; // Use flipped coords, so we can layout out from top row to bottom row.
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)aRect
|
||||
{
|
||||
NSRect oldFrame = [self frame];
|
||||
[super setFrame:aRect];
|
||||
|
||||
if (oldFrame.size.width == aRect.size.width)
|
||||
return;
|
||||
|
||||
int count = [mButtons count];
|
||||
if (count <= 2)
|
||||
return; // We have too few buttons to care.
|
||||
|
||||
// Do some optimizations when we have only one row.
|
||||
if (aRect.size.height < 25) // We have only one row.
|
||||
{
|
||||
if (oldFrame.size.width < aRect.size.width)
|
||||
// We got bigger. If we already only have one row, just bail.
|
||||
// This will optimize for a common resizing case.
|
||||
return;
|
||||
else {
|
||||
// We got smaller. Just go to the last button and see if it is outside
|
||||
// our bounds.
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)];
|
||||
if ([button frame].origin.x + [button frame].size.width >
|
||||
[self bounds].size.width - 2) {
|
||||
// The button doesn't fit any more. Reflow starting at this index.
|
||||
[self reflowButtonsStartingAtIndex:(count-1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we got bigger or smaller. We could gain or lose a row.
|
||||
[self reflowButtons];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,158 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsCocoaBrowserView_h__
|
||||
#define __nsCocoaBrowserView_h__
|
||||
|
||||
#undef DARWIN
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class CHBrowserView;
|
||||
class nsCocoaBrowserListener;
|
||||
class nsIDOMWindow;
|
||||
class nsIWebBrowser;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMEvent;
|
||||
class nsIWebBrowserFind;
|
||||
|
||||
// Protocol implemented by anyone interested in progress
|
||||
// related to a BrowserView. A listener should explicitly
|
||||
// register itself with the view using the addListener
|
||||
// method.
|
||||
@protocol NSBrowserListener
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
// Invoked regularly as data associated with a page streams
|
||||
// in. If the total number of bytes expected is unknown,
|
||||
// maxBytes is -1.
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
|
||||
@end
|
||||
|
||||
typedef enum {
|
||||
NSStatusTypeScript = 0x0001,
|
||||
NSStatusTypeScriptDefault = 0x0002,
|
||||
NSStatusTypeLink = 0x0003,
|
||||
} NSStatusType;
|
||||
|
||||
@protocol NSBrowserContainer
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
// Set the dimensions of our NSView. The container might need to do
|
||||
// some adjustment, so the view doesn't do it directly.
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
// Create a new browser container window and return the contained view.
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
@end
|
||||
|
||||
enum {
|
||||
NSLoadFlagsNone = 0x0000,
|
||||
NSLoadFlagsDontPutInHistory = 0x0010,
|
||||
NSLoadFlagsReplaceHistoryEntry = 0x0020,
|
||||
NSLoadFlagsBypassCacheAndProxy = 0x0040
|
||||
};
|
||||
|
||||
enum {
|
||||
NSStopLoadNetwork = 0x01,
|
||||
NSStopLoadContent = 0x02,
|
||||
NSStopLoadAll = 0x03
|
||||
};
|
||||
|
||||
@interface CHBrowserView : NSView
|
||||
{
|
||||
nsIWebBrowser* _webBrowser;
|
||||
nsCocoaBrowserListener* _listener;
|
||||
NSWindow* mWindow;
|
||||
}
|
||||
|
||||
// NSView overrides
|
||||
- (id)initWithFrame:(NSRect)frame;
|
||||
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow;
|
||||
|
||||
- (void)dealloc;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// nsIWebBrowser methods
|
||||
- (void)addListener:(id <NSBrowserListener>)listener;
|
||||
- (void)removeListener:(id <NSBrowserListener>)listener;
|
||||
- (void)setContainer:(id <NSBrowserContainer>)container;
|
||||
- (nsIDOMWindow*)getContentWindow;
|
||||
|
||||
// nsIWebNavigation methods
|
||||
- (void)loadURI:(NSURL *)url flags:(unsigned int)flags;
|
||||
- (void)reload:(unsigned int)flags;
|
||||
- (BOOL)canGoBack;
|
||||
- (BOOL)canGoForward;
|
||||
- (void)goBack;
|
||||
- (void)goForward;
|
||||
- (void)gotoIndex:(int)index;
|
||||
- (void)stop:(unsigned int)flags;
|
||||
- (NSURL*)getCurrentURI;
|
||||
|
||||
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
|
||||
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
|
||||
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
|
||||
|
||||
- (void)printDocument;
|
||||
|
||||
- (BOOL)findInPage:(NSString*)inText;
|
||||
|
||||
-(IBAction)cut:(id)aSender;
|
||||
-(IBAction)copy:(id)aSender;
|
||||
-(IBAction)paste:(id)aSender;
|
||||
-(IBAction)clear:(id)aSender;
|
||||
-(IBAction)selectAll:(id)aSender;
|
||||
-(IBAction)undo:(id)aSender;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
- (void)setActive: (BOOL)aIsActive;
|
||||
|
||||
- (NSMenu*)getContextMenu;
|
||||
- (NSWindow*)getNativeWindow;
|
||||
|
||||
- (void)destroyWebBrowser;
|
||||
- (nsIWebBrowser*)getWebBrowser;
|
||||
- (nsCocoaBrowserListener*)getCocoaBrowserListener;
|
||||
- (void)setWebBrowser:(nsIWebBrowser*)browser;
|
||||
@end
|
||||
|
||||
#endif // __nsCocoaBrowserView_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "CHBrowserView.h"
|
||||
|
||||
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
|
||||
{
|
||||
id urlbar;
|
||||
id status;
|
||||
id progress;
|
||||
id progressSuper;
|
||||
id mWindowController;
|
||||
NSTabViewItem* mTab;
|
||||
NSWindow* mWindow;
|
||||
|
||||
CHBrowserView* mBrowserView;
|
||||
NSString* defaultStatus;
|
||||
NSString* loadingStatus;
|
||||
|
||||
BOOL mIsPrimary;
|
||||
BOOL mIsBusy;
|
||||
BOOL mOffline;
|
||||
BOOL mListenersAttached; // We hook up our click and context menu listeners lazily.
|
||||
// If we never become the primary view, we don't bother creating the listeners.
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender;
|
||||
- (void)awakeFromNib;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
- (CHBrowserView*)getBrowserView;
|
||||
- (BOOL)isBusy;
|
||||
- (void)windowClosed;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: (id)aWindowController;
|
||||
-(void)disconnectView;
|
||||
-(void)setTab: (NSTabViewItem*)tab;
|
||||
|
||||
-(NSWindow*)getNativeWindow;
|
||||
|
||||
-(NSMenu*)getContextMenu;
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow;
|
||||
|
||||
// NSBrowserListener messages
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
|
||||
// NSBrowserContainer messages
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
|
||||
@end
|
|
@ -0,0 +1,429 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "CHBrowserWrapper.h"
|
||||
#import "BrowserWindowController.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "ContentClickListener.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCocoaBrowserService.h"
|
||||
|
||||
#define DOCUMENT_DONE_STRING @"Document: Done"
|
||||
#define LOADING_STRING @"Loading..."
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation CHBrowserWrapper
|
||||
|
||||
-(void)windowClosed
|
||||
{
|
||||
// Break the cycle.
|
||||
[mBrowserView destroyWebBrowser];
|
||||
[mBrowserView setContainer: nil];
|
||||
[mBrowserView removeListener: self];
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
printf("The browser wrapper died.\n");
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
[defaultStatus release];
|
||||
[loadingStatus release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender
|
||||
{
|
||||
[mBrowserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
|
||||
}
|
||||
|
||||
-(void)disconnectView
|
||||
{
|
||||
urlbar = nil;
|
||||
status = nil;
|
||||
progress = nil;
|
||||
progressSuper = nil;
|
||||
mIsPrimary = NO;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[mBrowserView setActive: NO];
|
||||
}
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow: (NSWindow*)aWindow
|
||||
{
|
||||
mTab = aTab;
|
||||
mWindow = aWindow;
|
||||
return [self initWithFrame: NSZeroRect];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ( (self = [super initWithFrame: frameRect]) ) {
|
||||
mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease];
|
||||
[self addSubview: mBrowserView];
|
||||
[mBrowserView setContainer:self];
|
||||
[mBrowserView addListener:self];
|
||||
mIsBusy = NO;
|
||||
mListenersAttached = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTab: (NSTabViewItem*)tab
|
||||
{
|
||||
mTab = tab;
|
||||
}
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: aWindowController
|
||||
{
|
||||
urlbar = aUrlbar;
|
||||
status = aStatus;
|
||||
progress = aProgress;
|
||||
progressSuper = [aProgress superview];
|
||||
mWindowController = aWindowController;
|
||||
|
||||
if (!mIsBusy)
|
||||
[progress removeFromSuperview];
|
||||
|
||||
defaultStatus = NULL;
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsPrimary = YES;
|
||||
|
||||
if ([[self window] isKeyWindow])
|
||||
[mBrowserView setActive: YES];
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mWindowController) // Only register if we're the content area.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(offlineModeChanged:)
|
||||
name:@"offlineModeChanged"
|
||||
object:nil];
|
||||
|
||||
// Update the URL bar.
|
||||
[mWindowController updateLocationFields:[self getCurrentURLSpec]];
|
||||
|
||||
if (mWindowController && !mListenersAttached) {
|
||||
mListenersAttached = YES;
|
||||
|
||||
// We need to hook up our click and context menu listeners.
|
||||
ContentClickListener* clickListener = new ContentClickListener(mWindowController);
|
||||
if (!clickListener)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
|
||||
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
|
||||
piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
|
||||
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
|
||||
rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*)getCurrentURLSpec
|
||||
{
|
||||
return [mBrowserView getCurrentURLSpec];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
NSRect bounds = [self bounds];
|
||||
[mBrowserView setFrame:bounds];
|
||||
}
|
||||
|
||||
-(BOOL)isBusy
|
||||
{
|
||||
return mIsBusy;
|
||||
}
|
||||
|
||||
- (void)onLoadingStarted
|
||||
{
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
defaultStatus = NULL;
|
||||
}
|
||||
|
||||
[progressSuper addSubview:progress];
|
||||
[progress setIndeterminate:YES];
|
||||
[progress startAnimation:self];
|
||||
|
||||
loadingStatus = LOADING_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsBusy = YES;
|
||||
[mTab setLabel: LOADING_STRING];
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
else {
|
||||
printf("background load.\n");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded
|
||||
{
|
||||
[progress setIndeterminate:YES];
|
||||
[progress stopAnimation:self];
|
||||
[progress removeFromSuperview];
|
||||
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
mIsBusy = NO;
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
}
|
||||
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes
|
||||
{
|
||||
if (maxBytes > 0) {
|
||||
BOOL isIndeterminate = [progress isIndeterminate];
|
||||
if (isIndeterminate) {
|
||||
[progress setIndeterminate:NO];
|
||||
}
|
||||
double val = ((double)currentBytes / (double)maxBytes) * 100.0;
|
||||
[progress setDoubleValue:val];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocationChange:(NSURL*)url
|
||||
{
|
||||
NSString* spec = [url absoluteString];
|
||||
[mWindowController updateLocationFields:spec];
|
||||
}
|
||||
|
||||
- (void)onStatusChange:(NSString*)aStatusString
|
||||
{
|
||||
[status setStringValue: aStatusString];
|
||||
}
|
||||
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type
|
||||
{
|
||||
if (type == NSStatusTypeScriptDefault) {
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
}
|
||||
defaultStatus = statusString;
|
||||
if (defaultStatus) {
|
||||
[defaultStatus retain];
|
||||
}
|
||||
}
|
||||
else if (!statusString) {
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[status setStringValue:statusString];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return [[mWindowController window] title];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
// We must be the primary content area.
|
||||
if (mIsPrimary && mWindowController) {
|
||||
if (mOffline) {
|
||||
NSString* newTitle;
|
||||
if (title && ![title isEqualToString:@""])
|
||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
||||
else
|
||||
newTitle = @"Untitled [Working Offline]";
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[[mWindowController window] setTitle:title];
|
||||
else
|
||||
[[mWindowController window] setTitle:@"Untitled"];
|
||||
}
|
||||
}
|
||||
|
||||
// Always set the tab.
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[mTab setLabel:title];
|
||||
else
|
||||
[mTab setLabel:@"Untitled"];
|
||||
}
|
||||
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
|
||||
{
|
||||
[mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode];
|
||||
}
|
||||
|
||||
-(NSMenu*)getContextMenu
|
||||
{
|
||||
return [mWindowController getContextMenu];
|
||||
}
|
||||
|
||||
-(NSWindow*)getNativeWindow
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
if (window)
|
||||
return window;
|
||||
|
||||
if (mWindow)
|
||||
return mWindow;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)offlineModeChanged: (NSNotification*)aNotification
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mOffline) {
|
||||
NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
float dx = dimensions.width - bounds.size.width;
|
||||
float dy = dimensions.height - bounds.size.height;
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
frame.size.width += dx;
|
||||
frame.size.height += dy;
|
||||
|
||||
[[self window] setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
#define NS_POPUP_BLOCK @"This Web site is attempting to open an unrequested popup window. Navigator can \
|
||||
automatically prevent Web sites from opening popup advertisements. Click OK to prevent all \
|
||||
unrequested popups (including this one) from opening."
|
||||
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return NS_OK; // Something bad happened if we can't get prefs.
|
||||
|
||||
PRBool showBlocker;
|
||||
pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
|
||||
|
||||
if (showBlocker) {
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(domWindow));
|
||||
PRBool isUnrequested;
|
||||
piWindow->IsLoadingOrRunningTimeout(&isUnrequested);
|
||||
if (isUnrequested) {
|
||||
// A popup is being opened while the page is currently loading. Offer to block the
|
||||
// popup.
|
||||
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
|
||||
BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected"
|
||||
text: NS_POPUP_BLOCK];
|
||||
|
||||
// This is a one-time dialog.
|
||||
pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
|
||||
|
||||
if (confirm) {
|
||||
pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
|
||||
pref->SetIntPref("dom.disable_open_click_delay", 1000);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
|
||||
prefService->SavePrefFile(nsnull);
|
||||
|
||||
if (confirm)
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
[controller setChromeMask: aMask];
|
||||
[controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
|
||||
[controller enterModalSession];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return [[controller getBrowserWrapper] getBrowserView];
|
||||
}
|
||||
|
||||
- (CHBrowserView*)getBrowserView
|
||||
{
|
||||
return mBrowserView;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- 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):
|
||||
* Mike Pinkerton <pinkerton@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//
|
||||
// protocol CHFind
|
||||
//
|
||||
// Any window who wants to be able to work with the Find dialog should implement
|
||||
// this protocol.
|
||||
//
|
||||
|
||||
@protocol CHFind
|
||||
|
||||
- (BOOL)findInPage:(NSString*)text;
|
||||
|
||||
@end
|
|
@ -28,7 +28,7 @@
|
|||
|
||||
- (id)performDefaultImplementation {
|
||||
id controller = [[NSApp delegate] openBrowserWindowWithURLString: [self directParameter]];
|
||||
[[[controller getMyBrowserView] getBrowserView] setActive: YES];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -388,6 +388,8 @@
|
|||
F57074BF026D80DF01A80166,
|
||||
F51B70B8026EC98B01A80166,
|
||||
F5C3AB830270072A01A80166,
|
||||
F541495C02711A8301A80166,
|
||||
F541496002711B0101A80166,
|
||||
);
|
||||
isa = PBXHeadersBuildPhase;
|
||||
name = Headers;
|
||||
|
@ -474,6 +476,8 @@
|
|||
F57074C0026D80DF01A80166,
|
||||
F51B70B9026EC98B01A80166,
|
||||
F5C3AB840270072A01A80166,
|
||||
F541495D02711A8301A80166,
|
||||
F541496102711B0101A80166,
|
||||
);
|
||||
isa = PBXSourcesBuildPhase;
|
||||
name = Sources;
|
||||
|
@ -798,7 +802,7 @@
|
|||
};
|
||||
F5125A110202064D01FAFD9F = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.h;
|
||||
path = CHBrowserWrapper.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5125A140202064D01FAFD9F = {
|
||||
|
@ -809,7 +813,7 @@
|
|||
};
|
||||
F5137A1102676B9101026D05 = {
|
||||
isa = PBXFileReference;
|
||||
path = Find.h;
|
||||
path = CHFind.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5137A1202676B9101026D05 = {
|
||||
|
@ -1591,6 +1595,50 @@
|
|||
settings = {
|
||||
};
|
||||
};
|
||||
F541495A02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.h;
|
||||
refType = 4;
|
||||
};
|
||||
F541495B02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.m;
|
||||
refType = 4;
|
||||
};
|
||||
F541495C02711A8301A80166 = {
|
||||
fileRef = F541495A02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495D02711A8301A80166 = {
|
||||
fileRef = F541495B02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495E02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.h;
|
||||
refType = 2;
|
||||
};
|
||||
F541495F02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.m;
|
||||
refType = 2;
|
||||
};
|
||||
F541496002711B0101A80166 = {
|
||||
fileRef = F541495E02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541496102711B0101A80166 = {
|
||||
fileRef = F541495F02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F54EF7ED022A2F9C01A80165 = {
|
||||
isa = PBXFileReference;
|
||||
name = pipnss.jar;
|
||||
|
@ -1755,6 +1803,10 @@
|
|||
F564873A023C3857010001CA,
|
||||
F5C3AB810270072A01A80166,
|
||||
F5C3AB820270072A01A80166,
|
||||
F541495A02711A8301A80166,
|
||||
F541495B02711A8301A80166,
|
||||
F541495E02711B0001A80166,
|
||||
F541495F02711B0001A80166,
|
||||
);
|
||||
isa = PBXGroup;
|
||||
name = "Categories and Extensions";
|
||||
|
@ -1798,7 +1850,7 @@
|
|||
};
|
||||
F5607CB5023944AD01A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = GeckoUtils.h;
|
||||
path = CHGeckoUtils.h;
|
||||
refType = 2;
|
||||
};
|
||||
F5607CB6023944AE01A967DF = {
|
||||
|
@ -1949,12 +2001,12 @@
|
|||
};
|
||||
F57074B5026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.h;
|
||||
path = CHBookmarksToolbar.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B6026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.mm;
|
||||
path = CHBookmarksToolbar.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B7026BA85F01A80166 = {
|
||||
|
@ -1971,12 +2023,12 @@
|
|||
};
|
||||
F57074B9026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.h;
|
||||
path = CHBookmarksButton.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BA026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.mm;
|
||||
path = CHBookmarksButton.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BB026BFD0201A80166 = {
|
||||
|
@ -2497,7 +2549,7 @@
|
|||
};
|
||||
F5DE10E70209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.h;
|
||||
path = CHBrowserView.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10E80209DC0601A967DF = {
|
||||
|
@ -2512,7 +2564,7 @@
|
|||
};
|
||||
F5DE10EA0209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.mm;
|
||||
path = CHBrowserView.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10EB0209DC0601A967DF = {
|
||||
|
@ -2742,7 +2794,7 @@
|
|||
};
|
||||
F6BA6D4E01B2F8A601A962F7 = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.mm;
|
||||
path = CHBrowserWrapper.mm;
|
||||
refType = 2;
|
||||
};
|
||||
F6BA6D4F01B2F8A601A962F7 = {
|
||||
|
|
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичный файл не отображается.
|
@ -388,6 +388,8 @@
|
|||
F57074BF026D80DF01A80166,
|
||||
F51B70B8026EC98B01A80166,
|
||||
F5C3AB830270072A01A80166,
|
||||
F541495C02711A8301A80166,
|
||||
F541496002711B0101A80166,
|
||||
);
|
||||
isa = PBXHeadersBuildPhase;
|
||||
name = Headers;
|
||||
|
@ -474,6 +476,8 @@
|
|||
F57074C0026D80DF01A80166,
|
||||
F51B70B9026EC98B01A80166,
|
||||
F5C3AB840270072A01A80166,
|
||||
F541495D02711A8301A80166,
|
||||
F541496102711B0101A80166,
|
||||
);
|
||||
isa = PBXSourcesBuildPhase;
|
||||
name = Sources;
|
||||
|
@ -798,7 +802,7 @@
|
|||
};
|
||||
F5125A110202064D01FAFD9F = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.h;
|
||||
path = CHBrowserWrapper.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5125A140202064D01FAFD9F = {
|
||||
|
@ -809,7 +813,7 @@
|
|||
};
|
||||
F5137A1102676B9101026D05 = {
|
||||
isa = PBXFileReference;
|
||||
path = Find.h;
|
||||
path = CHFind.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5137A1202676B9101026D05 = {
|
||||
|
@ -1591,6 +1595,50 @@
|
|||
settings = {
|
||||
};
|
||||
};
|
||||
F541495A02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.h;
|
||||
refType = 4;
|
||||
};
|
||||
F541495B02711A8301A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHToolbarAdditions.m;
|
||||
refType = 4;
|
||||
};
|
||||
F541495C02711A8301A80166 = {
|
||||
fileRef = F541495A02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495D02711A8301A80166 = {
|
||||
fileRef = F541495B02711A8301A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541495E02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.h;
|
||||
refType = 2;
|
||||
};
|
||||
F541495F02711B0001A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = CHImageAdditions.m;
|
||||
refType = 2;
|
||||
};
|
||||
F541496002711B0101A80166 = {
|
||||
fileRef = F541495E02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F541496102711B0101A80166 = {
|
||||
fileRef = F541495F02711B0001A80166;
|
||||
isa = PBXBuildFile;
|
||||
settings = {
|
||||
};
|
||||
};
|
||||
F54EF7ED022A2F9C01A80165 = {
|
||||
isa = PBXFileReference;
|
||||
name = pipnss.jar;
|
||||
|
@ -1755,6 +1803,10 @@
|
|||
F564873A023C3857010001CA,
|
||||
F5C3AB810270072A01A80166,
|
||||
F5C3AB820270072A01A80166,
|
||||
F541495A02711A8301A80166,
|
||||
F541495B02711A8301A80166,
|
||||
F541495E02711B0001A80166,
|
||||
F541495F02711B0001A80166,
|
||||
);
|
||||
isa = PBXGroup;
|
||||
name = "Categories and Extensions";
|
||||
|
@ -1798,7 +1850,7 @@
|
|||
};
|
||||
F5607CB5023944AD01A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = GeckoUtils.h;
|
||||
path = CHGeckoUtils.h;
|
||||
refType = 2;
|
||||
};
|
||||
F5607CB6023944AE01A967DF = {
|
||||
|
@ -1949,12 +2001,12 @@
|
|||
};
|
||||
F57074B5026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.h;
|
||||
path = CHBookmarksToolbar.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B6026BA85F01A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksToolbar.mm;
|
||||
path = CHBookmarksToolbar.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074B7026BA85F01A80166 = {
|
||||
|
@ -1971,12 +2023,12 @@
|
|||
};
|
||||
F57074B9026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.h;
|
||||
path = CHBookmarksButton.h;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BA026BFD0101A80166 = {
|
||||
isa = PBXFileReference;
|
||||
path = BookmarksButton.mm;
|
||||
path = CHBookmarksButton.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F57074BB026BFD0201A80166 = {
|
||||
|
@ -2497,7 +2549,7 @@
|
|||
};
|
||||
F5DE10E70209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.h;
|
||||
path = CHBrowserView.h;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10E80209DC0601A967DF = {
|
||||
|
@ -2512,7 +2564,7 @@
|
|||
};
|
||||
F5DE10EA0209DC0601A967DF = {
|
||||
isa = PBXFileReference;
|
||||
path = NSBrowserView.mm;
|
||||
path = CHBrowserView.mm;
|
||||
refType = 4;
|
||||
};
|
||||
F5DE10EB0209DC0601A967DF = {
|
||||
|
@ -2742,7 +2794,7 @@
|
|||
};
|
||||
F6BA6D4E01B2F8A601A962F7 = {
|
||||
isa = PBXFileReference;
|
||||
path = MyBrowserView.mm;
|
||||
path = CHBrowserWrapper.mm;
|
||||
refType = 2;
|
||||
};
|
||||
F6BA6D4F01B2F8A601A962F7 = {
|
||||
|
|
Двоичный файл не отображается.
|
@ -64,6 +64,7 @@
|
|||
};
|
||||
SUPERCLASS = NSWindowController;
|
||||
},
|
||||
{CLASS = CHBookmarksToolbar; LANGUAGE = ObjC; SUPERCLASS = NSView; },
|
||||
{CLASS = CHExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
{CLASS = CHExtendedTabView; LANGUAGE = ObjC; SUPERCLASS = NSTabView; },
|
||||
{CLASS = ExtendedOutlineView; LANGUAGE = ObjC; SUPERCLASS = NSOutlineView; },
|
||||
|
|
|
@ -45,9 +45,9 @@
|
|||
</array>
|
||||
<key>IBOpenObjects</key>
|
||||
<array>
|
||||
<integer>10</integer>
|
||||
<integer>394</integer>
|
||||
<integer>160</integer>
|
||||
<integer>394</integer>
|
||||
<integer>10</integer>
|
||||
</array>
|
||||
<key>IBSystem Version</key>
|
||||
<string>5Q125</string>
|
||||
|
|
Двоичные данные
chimera/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичные данные
chimera/resources/localized/English.lproj/BrowserWindow.nib/objects.nib
сгенерированный
Двоичный файл не отображается.
|
@ -28,7 +28,7 @@
|
|||
|
||||
- (id)performDefaultImplementation {
|
||||
id controller = [[NSApp delegate] openBrowserWindowWithURLString: [self directParameter]];
|
||||
[[[controller getMyBrowserView] getBrowserView] setActive: YES];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return nil;
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -0,0 +1,40 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Appkit/Appkit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
@interface CHBookmarksButton : NSButton {
|
||||
|
||||
nsIDOMElement* mElement;
|
||||
BOOL mIsFolder;
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt;
|
||||
-(nsIDOMElement*)element;
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender;
|
||||
|
||||
@end
|
|
@ -0,0 +1,127 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsString.h"
|
||||
#import "BookmarksService.h"
|
||||
|
||||
@implementation CHBookmarksButton
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mElement = nsnull;
|
||||
[self setBezelStyle: NSRegularSquareBezelStyle];
|
||||
[self setBordered: NO];
|
||||
[self setImagePosition: NSImageLeft];
|
||||
[self setRefusesFirstResponder: YES];
|
||||
[self setFont: [NSFont labelFontOfSize: 11.0]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(IBAction)openBookmark:(id)aSender
|
||||
{
|
||||
// See if we're a group.
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
if (!group.IsEmpty()) {
|
||||
BookmarksService::OpenBookmarkGroup([[[self window] windowController] getTabBrowser], mElement);
|
||||
return;
|
||||
}
|
||||
|
||||
// Get the href attribute. This is the URL we want to load.
|
||||
nsAutoString href;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("href"), href);
|
||||
nsCAutoString cref; cref.AssignWithConversion(href);
|
||||
if (cref.IsEmpty())
|
||||
return;
|
||||
|
||||
NSString* url = [NSString stringWithCString: cref.get()];
|
||||
|
||||
// Now load the URL in the window.
|
||||
[[[self window] windowController] loadURL:[NSURL URLWithString: url]];
|
||||
|
||||
// Focus and activate our content area.
|
||||
[[[[[self window] windowController] getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
}
|
||||
|
||||
-(void)drawRect:(NSRect)aRect
|
||||
{
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(NSMenu*)menuForEvent:(NSEvent*)aEvent
|
||||
{
|
||||
return [[self superview] menu];
|
||||
}
|
||||
|
||||
-(void)mouseDown:(NSEvent*)aEvent
|
||||
{
|
||||
if (mIsFolder) {
|
||||
nsCOMPtr<nsIContent> content(do_QueryInterface(mElement));
|
||||
NSMenu* menu = BookmarksService::LocateMenu(content);
|
||||
[NSMenu popUpContextMenu: menu withEvent: aEvent forView: self];
|
||||
}
|
||||
else
|
||||
[super mouseDown: aEvent];
|
||||
}
|
||||
|
||||
-(void)setElement: (nsIDOMElement*)aElt
|
||||
{
|
||||
mElement = aElt;
|
||||
nsAutoString tag;
|
||||
mElement->GetLocalName(tag);
|
||||
|
||||
nsAutoString group;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("group"), group);
|
||||
|
||||
if (!group.IsEmpty()) {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
else if (tag.Equals(NS_LITERAL_STRING("folder"))) {
|
||||
[self setImage: [NSImage imageNamed: @"folder"]];
|
||||
mIsFolder = YES;
|
||||
}
|
||||
else {
|
||||
mIsFolder = NO;
|
||||
[self setImage: [NSImage imageNamed: @"smallbookmark"]];
|
||||
[self setAction: @selector(openBookmark:)];
|
||||
[self setTarget: self];
|
||||
}
|
||||
|
||||
nsAutoString name;
|
||||
mElement->GetAttribute(NS_LITERAL_STRING("name"), name);
|
||||
[self setTitle: [NSString stringWithCharacters: name.get() length: nsCRT::strlen(name.get())]];
|
||||
}
|
||||
|
||||
-(nsIDOMElement*)element
|
||||
{
|
||||
return mElement;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,46 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <AppKit/AppKit.h>
|
||||
|
||||
class nsIDOMElement;
|
||||
|
||||
class BookmarksService;
|
||||
|
||||
@interface CHBookmarksToolbar : NSView {
|
||||
BookmarksService* mBookmarks;
|
||||
NSMutableArray* mButtons;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar;
|
||||
|
||||
// Called to construct the initial set of personal toolbar buttons.
|
||||
-(void)buildButtonList;
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex;
|
||||
-(void)removeButton: (nsIDOMElement*)aElt;
|
||||
|
||||
// Called to lay out the buttons on the toolbar.
|
||||
-(void)reflowButtons;
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex;
|
||||
|
||||
@end
|
|
@ -0,0 +1,227 @@
|
|||
/* -*- 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):
|
||||
* David Hyatt <hyatt@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import "CHBookmarksButton.h"
|
||||
#import "CHBookmarksToolbar.h"
|
||||
#import "BookmarksService.h"
|
||||
#include "nsIDOMElement.h"
|
||||
|
||||
@implementation CHBookmarksToolbar
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame {
|
||||
if ( (self = [super initWithFrame:frame]) ) {
|
||||
mBookmarks = nsnull;
|
||||
mButtons = [[NSMutableArray alloc] init];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)initializeToolbar
|
||||
{
|
||||
// Initialization code here.
|
||||
mBookmarks = new BookmarksService(self);
|
||||
mBookmarks->AddObserver();
|
||||
mBookmarks->EnsureToolbarRoot();
|
||||
[self buildButtonList];
|
||||
}
|
||||
|
||||
-(void) dealloc
|
||||
{
|
||||
[mButtons autorelease];
|
||||
mBookmarks->RemoveObserver();
|
||||
delete mBookmarks;
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void)drawRect:(NSRect)aRect {
|
||||
// Fill the background with our background color.
|
||||
//[[NSColor colorWithCalibratedWhite: 0.98 alpha: 1.0] set];
|
||||
//NSRectFill(aRect);
|
||||
|
||||
//printf("The rect is: %f %f %f %f\n", aRect.origin.x, aRect.origin.y, aRect.size.width, aRect.size.height);
|
||||
|
||||
if (aRect.origin.y + aRect.size.height ==
|
||||
[self bounds].size.height) {
|
||||
// The personal toolbar is 21 pixels tall. The bottom two pixels
|
||||
// are a separator.
|
||||
[[NSColor colorWithCalibratedWhite: 0.90 alpha: 1.0] set];
|
||||
NSRectFill(NSMakeRect(aRect.origin.x, [self bounds].size.height-2, aRect.size.width, [self bounds].size.height));
|
||||
}
|
||||
|
||||
// The buttons will paint themselves. Just call our base class method.
|
||||
[super drawRect: aRect];
|
||||
}
|
||||
|
||||
-(void)buildButtonList
|
||||
{
|
||||
// Build the buttons, and then lay them all out.
|
||||
nsCOMPtr<nsIDOMNode> child;
|
||||
BookmarksService::gToolbarRoot->GetFirstChild(getter_AddRefs(child));
|
||||
while (child) {
|
||||
nsCOMPtr<nsIDOMElement> childElt(do_QueryInterface(child));
|
||||
if (childElt) {
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: childElt];
|
||||
[self addSubview: button];
|
||||
[mButtons addObject: button];
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMNode> temp = child;
|
||||
temp->GetNextSibling(getter_AddRefs(child));
|
||||
}
|
||||
|
||||
[self reflowButtons];
|
||||
}
|
||||
|
||||
-(void)addButton: (nsIDOMElement*)aElt atIndex: (int)aIndex
|
||||
{
|
||||
CHBookmarksButton* button = [[[CHBookmarksButton alloc] initWithFrame: NSMakeRect(2, 1, 100, 17)] autorelease];
|
||||
[button setElement: aElt];
|
||||
[self addSubview: button];
|
||||
[mButtons insertObject: button atIndex: aIndex];
|
||||
[self reflowButtonsStartingAtIndex: aIndex];
|
||||
}
|
||||
|
||||
-(void)removeButton: (nsIDOMElement*)aElt
|
||||
{
|
||||
int count = [mButtons count];
|
||||
for (int i = 0; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
if ([button element] == aElt) {
|
||||
[mButtons removeObjectAtIndex: i];
|
||||
[button removeFromSuperview];
|
||||
if (count > i)
|
||||
[self reflowButtonsStartingAtIndex: i];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
-(void)reflowButtons
|
||||
{
|
||||
[self reflowButtonsStartingAtIndex: 0];
|
||||
}
|
||||
|
||||
-(void)reflowButtonsStartingAtIndex: (int)aIndex
|
||||
{
|
||||
float oldHeight = [self frame].size.height;
|
||||
float computedHeight = 18;
|
||||
int count = [mButtons count];
|
||||
float currY = 1.0;
|
||||
float prevX = 2.0;
|
||||
if (aIndex > 0) {
|
||||
CHBookmarksButton* prevButton = [mButtons objectAtIndex: (aIndex-1)];
|
||||
prevX += [prevButton frame].origin.x + [prevButton frame].size.width;
|
||||
currY = [prevButton frame].origin.y;
|
||||
}
|
||||
for (int i = aIndex; i < count; i++) {
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex: i];
|
||||
[button sizeToFit];
|
||||
float width = [button frame].size.width;
|
||||
float height = [button frame].size.height;
|
||||
if (width > 150)
|
||||
width = 150;
|
||||
if (height < 16)
|
||||
height = 16; // Our folder tiff is only 15 pixels for some reason.
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
|
||||
prevX += [button frame].size.width + 2;
|
||||
|
||||
if ([self bounds].size.width < prevX) {
|
||||
// The previous button didn't fit. We need to make a new row.
|
||||
currY += 18;
|
||||
computedHeight += 18;
|
||||
if (computedHeight > oldHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y+(oldHeight-computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
prevX = 2;
|
||||
[button setFrame: NSMakeRect(prevX, currY, width, height)];
|
||||
prevX += [button frame].size.width + 2;
|
||||
}
|
||||
|
||||
[button setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float currentHeight = [self frame].size.height;
|
||||
if (computedHeight != currentHeight) {
|
||||
[self setFrame: NSMakeRect([self frame].origin.x, [self frame].origin.y + (currentHeight - computedHeight),
|
||||
[self frame].size.width, computedHeight)];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
||||
float sizeChange = computedHeight - oldHeight;
|
||||
if (sizeChange != 0) {
|
||||
// We need to adjust the content area.
|
||||
NSView* view = [[[self window] windowController] getTabBrowser];
|
||||
[view setFrame: NSMakeRect([view frame].origin.x, [view frame].origin.y,
|
||||
[view frame].size.width, [view frame].size.height - sizeChange)];
|
||||
}
|
||||
}
|
||||
|
||||
-(BOOL)isFlipped
|
||||
{
|
||||
return YES; // Use flipped coords, so we can layout out from top row to bottom row.
|
||||
}
|
||||
|
||||
-(void)setFrame:(NSRect)aRect
|
||||
{
|
||||
NSRect oldFrame = [self frame];
|
||||
[super setFrame:aRect];
|
||||
|
||||
if (oldFrame.size.width == aRect.size.width)
|
||||
return;
|
||||
|
||||
int count = [mButtons count];
|
||||
if (count <= 2)
|
||||
return; // We have too few buttons to care.
|
||||
|
||||
// Do some optimizations when we have only one row.
|
||||
if (aRect.size.height < 25) // We have only one row.
|
||||
{
|
||||
if (oldFrame.size.width < aRect.size.width)
|
||||
// We got bigger. If we already only have one row, just bail.
|
||||
// This will optimize for a common resizing case.
|
||||
return;
|
||||
else {
|
||||
// We got smaller. Just go to the last button and see if it is outside
|
||||
// our bounds.
|
||||
CHBookmarksButton* button = [mButtons objectAtIndex:(count-1)];
|
||||
if ([button frame].origin.x + [button frame].size.width >
|
||||
[self bounds].size.width - 2) {
|
||||
// The button doesn't fit any more. Reflow starting at this index.
|
||||
[self reflowButtonsStartingAtIndex:(count-1)];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// See if we got bigger or smaller. We could gain or lose a row.
|
||||
[self reflowButtons];
|
||||
}
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,96 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
#import "CHBrowserView.h"
|
||||
|
||||
@interface CHBrowserWrapper : NSView <NSBrowserListener, NSBrowserContainer>
|
||||
{
|
||||
id urlbar;
|
||||
id status;
|
||||
id progress;
|
||||
id progressSuper;
|
||||
id mWindowController;
|
||||
NSTabViewItem* mTab;
|
||||
NSWindow* mWindow;
|
||||
|
||||
CHBrowserView* mBrowserView;
|
||||
NSString* defaultStatus;
|
||||
NSString* loadingStatus;
|
||||
|
||||
BOOL mIsPrimary;
|
||||
BOOL mIsBusy;
|
||||
BOOL mOffline;
|
||||
BOOL mListenersAttached; // We hook up our click and context menu listeners lazily.
|
||||
// If we never become the primary view, we don't bother creating the listeners.
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender;
|
||||
- (void)awakeFromNib;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
- (CHBrowserView*)getBrowserView;
|
||||
- (BOOL)isBusy;
|
||||
- (void)windowClosed;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: (id)aWindowController;
|
||||
-(void)disconnectView;
|
||||
-(void)setTab: (NSTabViewItem*)tab;
|
||||
|
||||
-(NSWindow*)getNativeWindow;
|
||||
|
||||
-(NSMenu*)getContextMenu;
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow:(NSWindow*)aWindow;
|
||||
|
||||
// NSBrowserListener messages
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
|
||||
// NSBrowserContainer messages
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
|
||||
@end
|
|
@ -0,0 +1,429 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#import "CHBrowserWrapper.h"
|
||||
#import "BrowserWindowController.h"
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "ContentClickListener.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIChromeEventHandler.h"
|
||||
#include "nsPIDOMWindow.h"
|
||||
#include "nsIDOMEventReceiver.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsCocoaBrowserService.h"
|
||||
|
||||
#define DOCUMENT_DONE_STRING @"Document: Done"
|
||||
#define LOADING_STRING @"Loading..."
|
||||
|
||||
static const char* ioServiceContractID = "@mozilla.org/network/io-service;1";
|
||||
|
||||
@implementation CHBrowserWrapper
|
||||
|
||||
-(void)windowClosed
|
||||
{
|
||||
// Break the cycle.
|
||||
[mBrowserView destroyWebBrowser];
|
||||
[mBrowserView setContainer: nil];
|
||||
[mBrowserView removeListener: self];
|
||||
}
|
||||
|
||||
-(void)dealloc
|
||||
{
|
||||
printf("The browser wrapper died.\n");
|
||||
|
||||
[[NSNotificationCenter defaultCenter] removeObserver: self];
|
||||
|
||||
[defaultStatus release];
|
||||
[loadingStatus release];
|
||||
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (IBAction)load:(id)sender
|
||||
{
|
||||
[mBrowserView loadURI:[NSURL URLWithString:[urlbar stringValue]] flags:NSLoadFlagsNone];
|
||||
}
|
||||
|
||||
-(void)disconnectView
|
||||
{
|
||||
urlbar = nil;
|
||||
status = nil;
|
||||
progress = nil;
|
||||
progressSuper = nil;
|
||||
mIsPrimary = NO;
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
|
||||
[mBrowserView setActive: NO];
|
||||
}
|
||||
|
||||
-(id)initWithTab:(id)aTab andWindow: (NSWindow*)aWindow
|
||||
{
|
||||
mTab = aTab;
|
||||
mWindow = aWindow;
|
||||
return [self initWithFrame: NSZeroRect];
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frameRect
|
||||
{
|
||||
if ( (self = [super initWithFrame: frameRect]) ) {
|
||||
mBrowserView = [[[CHBrowserView alloc] initWithFrame:[self bounds] andWindow: [self getNativeWindow]] autorelease];
|
||||
[self addSubview: mBrowserView];
|
||||
[mBrowserView setContainer:self];
|
||||
[mBrowserView addListener:self];
|
||||
mIsBusy = NO;
|
||||
mListenersAttached = NO;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
-(void)setTab: (NSTabViewItem*)tab
|
||||
{
|
||||
mTab = tab;
|
||||
}
|
||||
|
||||
-(void)makePrimaryBrowserView: (id)aUrlbar status: (id)aStatus
|
||||
progress: (id)aProgress windowController: aWindowController
|
||||
{
|
||||
urlbar = aUrlbar;
|
||||
status = aStatus;
|
||||
progress = aProgress;
|
||||
progressSuper = [aProgress superview];
|
||||
mWindowController = aWindowController;
|
||||
|
||||
if (!mIsBusy)
|
||||
[progress removeFromSuperview];
|
||||
|
||||
defaultStatus = NULL;
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsPrimary = YES;
|
||||
|
||||
if ([[self window] isKeyWindow])
|
||||
[mBrowserView setActive: YES];
|
||||
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mWindowController) // Only register if we're the content area.
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||
selector:@selector(offlineModeChanged:)
|
||||
name:@"offlineModeChanged"
|
||||
object:nil];
|
||||
|
||||
// Update the URL bar.
|
||||
[mWindowController updateLocationFields:[self getCurrentURLSpec]];
|
||||
|
||||
if (mWindowController && !mListenersAttached) {
|
||||
mListenersAttached = YES;
|
||||
|
||||
// We need to hook up our click and context menu listeners.
|
||||
ContentClickListener* clickListener = new ContentClickListener(mWindowController);
|
||||
if (!clickListener)
|
||||
return;
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> contentWindow = getter_AddRefs([[self getBrowserView] getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(contentWindow));
|
||||
nsCOMPtr<nsIChromeEventHandler> chromeHandler;
|
||||
piWindow->GetChromeEventHandler(getter_AddRefs(chromeHandler));
|
||||
nsCOMPtr<nsIDOMEventReceiver> rec(do_QueryInterface(chromeHandler));
|
||||
rec->AddEventListenerByIID(clickListener, NS_GET_IID(nsIDOMMouseListener));
|
||||
}
|
||||
}
|
||||
|
||||
-(NSString*)getCurrentURLSpec
|
||||
{
|
||||
return [mBrowserView getCurrentURLSpec];
|
||||
}
|
||||
|
||||
- (void)awakeFromNib
|
||||
{
|
||||
}
|
||||
|
||||
- (void)setFrame:(NSRect)frameRect
|
||||
{
|
||||
[super setFrame:frameRect];
|
||||
NSRect bounds = [self bounds];
|
||||
[mBrowserView setFrame:bounds];
|
||||
}
|
||||
|
||||
-(BOOL)isBusy
|
||||
{
|
||||
return mIsBusy;
|
||||
}
|
||||
|
||||
- (void)onLoadingStarted
|
||||
{
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
defaultStatus = NULL;
|
||||
}
|
||||
|
||||
[progressSuper addSubview:progress];
|
||||
[progress setIndeterminate:YES];
|
||||
[progress startAnimation:self];
|
||||
|
||||
loadingStatus = LOADING_STRING;
|
||||
[status setStringValue:loadingStatus];
|
||||
|
||||
mIsBusy = YES;
|
||||
[mTab setLabel: LOADING_STRING];
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
else {
|
||||
printf("background load.\n");
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded
|
||||
{
|
||||
[progress setIndeterminate:YES];
|
||||
[progress stopAnimation:self];
|
||||
[progress removeFromSuperview];
|
||||
|
||||
loadingStatus = DOCUMENT_DONE_STRING;
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
|
||||
mIsBusy = NO;
|
||||
|
||||
if (mWindowController)
|
||||
[mWindowController updateToolbarItems];
|
||||
}
|
||||
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes
|
||||
{
|
||||
if (maxBytes > 0) {
|
||||
BOOL isIndeterminate = [progress isIndeterminate];
|
||||
if (isIndeterminate) {
|
||||
[progress setIndeterminate:NO];
|
||||
}
|
||||
double val = ((double)currentBytes / (double)maxBytes) * 100.0;
|
||||
[progress setDoubleValue:val];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)onLocationChange:(NSURL*)url
|
||||
{
|
||||
NSString* spec = [url absoluteString];
|
||||
[mWindowController updateLocationFields:spec];
|
||||
}
|
||||
|
||||
- (void)onStatusChange:(NSString*)aStatusString
|
||||
{
|
||||
[status setStringValue: aStatusString];
|
||||
}
|
||||
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type
|
||||
{
|
||||
if (type == NSStatusTypeScriptDefault) {
|
||||
if (defaultStatus) {
|
||||
[defaultStatus release];
|
||||
}
|
||||
defaultStatus = statusString;
|
||||
if (defaultStatus) {
|
||||
[defaultStatus retain];
|
||||
}
|
||||
}
|
||||
else if (!statusString) {
|
||||
if (defaultStatus) {
|
||||
[status setStringValue:defaultStatus];
|
||||
}
|
||||
else {
|
||||
[status setStringValue:loadingStatus];
|
||||
}
|
||||
}
|
||||
else {
|
||||
[status setStringValue:statusString];
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)title
|
||||
{
|
||||
return [[mWindowController window] title];
|
||||
}
|
||||
|
||||
- (void)setTitle:(NSString *)title
|
||||
{
|
||||
// We must be the primary content area.
|
||||
if (mIsPrimary && mWindowController) {
|
||||
if (mOffline) {
|
||||
NSString* newTitle;
|
||||
if (title && ![title isEqualToString:@""])
|
||||
newTitle = [title stringByAppendingString: @" [Working Offline]"];
|
||||
else
|
||||
newTitle = @"Untitled [Working Offline]";
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[[mWindowController window] setTitle:title];
|
||||
else
|
||||
[[mWindowController window] setTitle:@"Untitled"];
|
||||
}
|
||||
}
|
||||
|
||||
// Always set the tab.
|
||||
if (title && ![title isEqualToString:@""])
|
||||
[mTab setLabel:title];
|
||||
else
|
||||
[mTab setLabel:@"Untitled"];
|
||||
}
|
||||
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode
|
||||
{
|
||||
[mWindowController onShowContextMenu: flags domEvent: aEvent domNode: aNode];
|
||||
}
|
||||
|
||||
-(NSMenu*)getContextMenu
|
||||
{
|
||||
return [mWindowController getContextMenu];
|
||||
}
|
||||
|
||||
-(NSWindow*)getNativeWindow
|
||||
{
|
||||
NSWindow* window = [self window];
|
||||
if (window)
|
||||
return window;
|
||||
|
||||
if (mWindow)
|
||||
return mWindow;
|
||||
|
||||
return nil;
|
||||
}
|
||||
|
||||
- (void)offlineModeChanged: (NSNotification*)aNotification
|
||||
{
|
||||
nsCOMPtr<nsIIOService> ioService(do_GetService(ioServiceContractID));
|
||||
if (!ioService)
|
||||
return;
|
||||
PRBool offline = PR_FALSE;
|
||||
ioService->GetOffline(&offline);
|
||||
mOffline = offline;
|
||||
|
||||
if (mOffline) {
|
||||
NSString* newTitle = [[[mWindowController window] title] stringByAppendingString: @" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: newTitle];
|
||||
}
|
||||
else {
|
||||
NSArray* titleItems = [[[mWindowController window] title] componentsSeparatedByString:@" [Working Offline]"];
|
||||
[[mWindowController window] setTitle: [titleItems objectAtIndex: 0]];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions
|
||||
{
|
||||
NSRect bounds = [self bounds];
|
||||
float dx = dimensions.width - bounds.size.width;
|
||||
float dy = dimensions.height - bounds.size.height;
|
||||
|
||||
NSRect frame = [[self window] frame];
|
||||
frame.size.width += dx;
|
||||
frame.size.height += dy;
|
||||
|
||||
[[self window] setFrame:frame display:YES];
|
||||
}
|
||||
|
||||
#define NS_POPUP_BLOCK @"This Web site is attempting to open an unrequested popup window. Navigator can \
|
||||
automatically prevent Web sites from opening popup advertisements. Click OK to prevent all \
|
||||
unrequested popups (including this one) from opening."
|
||||
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)aMask
|
||||
{
|
||||
nsCOMPtr<nsIPrefBranch> pref(do_GetService("@mozilla.org/preferences-service;1"));
|
||||
if (!pref)
|
||||
return NS_OK; // Something bad happened if we can't get prefs.
|
||||
|
||||
PRBool showBlocker;
|
||||
pref->GetBoolPref("browser.popups.showPopupBlocker", &showBlocker);
|
||||
|
||||
if (showBlocker) {
|
||||
nsCOMPtr<nsIDOMWindow> domWindow = getter_AddRefs([mBrowserView getContentWindow]);
|
||||
nsCOMPtr<nsPIDOMWindow> piWindow(do_QueryInterface(domWindow));
|
||||
PRBool isUnrequested;
|
||||
piWindow->IsLoadingOrRunningTimeout(&isUnrequested);
|
||||
if (isUnrequested) {
|
||||
// A popup is being opened while the page is currently loading. Offer to block the
|
||||
// popup.
|
||||
nsAlertController* controller = nsCocoaBrowserService::GetAlertController();
|
||||
BOOL confirm = [controller confirm: [self window] title: @"Unrequested Popup Detected"
|
||||
text: NS_POPUP_BLOCK];
|
||||
|
||||
// This is a one-time dialog.
|
||||
pref->SetBoolPref("browser.popups.showPopupBlocker", PR_FALSE);
|
||||
|
||||
if (confirm) {
|
||||
pref->SetBoolPref("dom.disable_open_during_load", PR_TRUE);
|
||||
pref->SetIntPref("dom.disable_open_click_delay", 1000);
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIPrefService> prefService(do_QueryInterface(pref));
|
||||
prefService->SavePrefFile(nsnull);
|
||||
|
||||
if (confirm)
|
||||
return nil;
|
||||
}
|
||||
}
|
||||
|
||||
BrowserWindowController* controller = [[BrowserWindowController alloc] initWithWindowNibName: @"BrowserWindow"];
|
||||
[controller setChromeMask: aMask];
|
||||
[controller disableAutosave]; // The Web page opened this window, so we don't ever use its settings.
|
||||
[controller enterModalSession];
|
||||
[[[controller getBrowserWrapper] getBrowserView] setActive: YES];
|
||||
return [[controller getBrowserWrapper] getBrowserView];
|
||||
}
|
||||
|
||||
- (CHBrowserView*)getBrowserView
|
||||
{
|
||||
return mBrowserView;
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,158 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 1998
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __nsCocoaBrowserView_h__
|
||||
#define __nsCocoaBrowserView_h__
|
||||
|
||||
#undef DARWIN
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@class CHBrowserView;
|
||||
class nsCocoaBrowserListener;
|
||||
class nsIDOMWindow;
|
||||
class nsIWebBrowser;
|
||||
class nsIDOMNode;
|
||||
class nsIDOMEvent;
|
||||
class nsIWebBrowserFind;
|
||||
|
||||
// Protocol implemented by anyone interested in progress
|
||||
// related to a BrowserView. A listener should explicitly
|
||||
// register itself with the view using the addListener
|
||||
// method.
|
||||
@protocol NSBrowserListener
|
||||
- (void)onLoadingStarted;
|
||||
- (void)onLoadingCompleted:(BOOL)succeeded;
|
||||
// Invoked regularly as data associated with a page streams
|
||||
// in. If the total number of bytes expected is unknown,
|
||||
// maxBytes is -1.
|
||||
- (void)onProgressChange:(int)currentBytes outOf:(int)maxBytes;
|
||||
- (void)onLocationChange:(NSURL*)url;
|
||||
- (void)onStatusChange:(NSString*)aMessage;
|
||||
// Called when a context menu should be shown.
|
||||
- (void)onShowContextMenu:(int)flags domEvent:(nsIDOMEvent*)aEvent domNode:(nsIDOMNode*)aNode;
|
||||
@end
|
||||
|
||||
typedef enum {
|
||||
NSStatusTypeScript = 0x0001,
|
||||
NSStatusTypeScriptDefault = 0x0002,
|
||||
NSStatusTypeLink = 0x0003,
|
||||
} NSStatusType;
|
||||
|
||||
@protocol NSBrowserContainer
|
||||
- (void)setStatus:(NSString *)statusString ofType:(NSStatusType)type;
|
||||
- (NSString *)title;
|
||||
- (void)setTitle:(NSString *)title;
|
||||
// Set the dimensions of our NSView. The container might need to do
|
||||
// some adjustment, so the view doesn't do it directly.
|
||||
- (void)sizeBrowserTo:(NSSize)dimensions;
|
||||
// Create a new browser container window and return the contained view.
|
||||
- (CHBrowserView*)createBrowserWindow:(unsigned int)mask;
|
||||
@end
|
||||
|
||||
enum {
|
||||
NSLoadFlagsNone = 0x0000,
|
||||
NSLoadFlagsDontPutInHistory = 0x0010,
|
||||
NSLoadFlagsReplaceHistoryEntry = 0x0020,
|
||||
NSLoadFlagsBypassCacheAndProxy = 0x0040
|
||||
};
|
||||
|
||||
enum {
|
||||
NSStopLoadNetwork = 0x01,
|
||||
NSStopLoadContent = 0x02,
|
||||
NSStopLoadAll = 0x03
|
||||
};
|
||||
|
||||
@interface CHBrowserView : NSView
|
||||
{
|
||||
nsIWebBrowser* _webBrowser;
|
||||
nsCocoaBrowserListener* _listener;
|
||||
NSWindow* mWindow;
|
||||
}
|
||||
|
||||
// NSView overrides
|
||||
- (id)initWithFrame:(NSRect)frame;
|
||||
- (id)initWithFrame:(NSRect)frame andWindow:(NSWindow*)aWindow;
|
||||
|
||||
- (void)dealloc;
|
||||
- (void)setFrame:(NSRect)frameRect;
|
||||
|
||||
// nsIWebBrowser methods
|
||||
- (void)addListener:(id <NSBrowserListener>)listener;
|
||||
- (void)removeListener:(id <NSBrowserListener>)listener;
|
||||
- (void)setContainer:(id <NSBrowserContainer>)container;
|
||||
- (nsIDOMWindow*)getContentWindow;
|
||||
|
||||
// nsIWebNavigation methods
|
||||
- (void)loadURI:(NSURL *)url flags:(unsigned int)flags;
|
||||
- (void)reload:(unsigned int)flags;
|
||||
- (BOOL)canGoBack;
|
||||
- (BOOL)canGoForward;
|
||||
- (void)goBack;
|
||||
- (void)goForward;
|
||||
- (void)gotoIndex:(int)index;
|
||||
- (void)stop:(unsigned int)flags;
|
||||
- (NSURL*)getCurrentURI;
|
||||
|
||||
- (void)saveDocument: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList;
|
||||
- (void)saveURL: (NSView*)aFilterView filterList: (NSPopUpButton*)aFilterList
|
||||
url: (NSURL*)aURL suggestedFilename: (NSString*)aFilename;
|
||||
|
||||
- (void)printDocument;
|
||||
|
||||
- (BOOL)findInPage:(NSString*)inText;
|
||||
|
||||
-(IBAction)cut:(id)aSender;
|
||||
-(IBAction)copy:(id)aSender;
|
||||
-(IBAction)paste:(id)aSender;
|
||||
-(IBAction)clear:(id)aSender;
|
||||
-(IBAction)selectAll:(id)aSender;
|
||||
-(IBAction)undo:(id)aSender;
|
||||
|
||||
-(NSString*)getCurrentURLSpec;
|
||||
|
||||
- (void)setActive: (BOOL)aIsActive;
|
||||
|
||||
- (NSMenu*)getContextMenu;
|
||||
- (NSWindow*)getNativeWindow;
|
||||
|
||||
- (void)destroyWebBrowser;
|
||||
- (nsIWebBrowser*)getWebBrowser;
|
||||
- (nsCocoaBrowserListener*)getCocoaBrowserListener;
|
||||
- (void)setWebBrowser:(nsIWebBrowser*)browser;
|
||||
@end
|
||||
|
||||
#endif // __nsCocoaBrowserView_h__
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -0,0 +1,179 @@
|
|||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* The contents of this file are subject to the Netscape 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/NPL/
|
||||
*
|
||||
* 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 mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the NPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the NPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef __GeckoUtils_h__
|
||||
#define __GeckoUtils_h__
|
||||
|
||||
#include "nsIDOMHTMLAnchorElement.h"
|
||||
#include "nsIDOMHTMLAreaElement.h"
|
||||
#include "nsIDOMHTMLLinkElement.h"
|
||||
#include "nsIDOMHTMLImageElement.h"
|
||||
#include "nsIDOMCharacterData.h"
|
||||
|
||||
class CHGeckoUtils
|
||||
{
|
||||
public:
|
||||
static void GatherTextUnder(nsIDOMNode* aNode, nsString& aResult) {
|
||||
nsAutoString text;
|
||||
nsCOMPtr<nsIDOMNode> node;
|
||||
aNode->GetFirstChild(getter_AddRefs(node));
|
||||
PRUint32 depth = 1;
|
||||
while (node && depth) {
|
||||
nsCOMPtr<nsIDOMCharacterData> charData(do_QueryInterface(node));
|
||||
PRUint16 nodeType;
|
||||
node->GetNodeType(&nodeType);
|
||||
if (charData && nodeType == nsIDOMNode::TEXT_NODE) {
|
||||
// Add this text to our collection.
|
||||
text += NS_LITERAL_STRING(" ");
|
||||
nsAutoString data;
|
||||
charData->GetData(data);
|
||||
text += data;
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLImageElement> img(do_QueryInterface(node));
|
||||
if (img) {
|
||||
nsAutoString altText;
|
||||
img->GetAlt(altText);
|
||||
if (!altText.IsEmpty()) {
|
||||
text = altText;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Find the next node to test.
|
||||
PRBool hasChildNodes;
|
||||
node->HasChildNodes(&hasChildNodes);
|
||||
if (hasChildNodes) {
|
||||
nsCOMPtr<nsIDOMNode> temp = node;
|
||||
temp->GetFirstChild(getter_AddRefs(node));
|
||||
depth++;
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> nextSibling;
|
||||
node->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
if (nextSibling)
|
||||
node = nextSibling;
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> parentNode;
|
||||
node->GetParentNode(getter_AddRefs(parentNode));
|
||||
if (!parentNode)
|
||||
node = nsnull;
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> nextSibling;
|
||||
parentNode->GetNextSibling(getter_AddRefs(nextSibling));
|
||||
node = nextSibling;
|
||||
depth--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
text.CompressWhitespace();
|
||||
aResult = text;
|
||||
};
|
||||
|
||||
static void GetEnclosingLinkElementAndHref(nsIDOMNode* aNode, nsIDOMElement** aLinkContent, nsString& aHref)
|
||||
{
|
||||
nsCOMPtr<nsIDOMElement> content(do_QueryInterface(aNode));
|
||||
nsAutoString localName;
|
||||
if (content)
|
||||
content->GetLocalName(localName);
|
||||
|
||||
nsCOMPtr<nsIDOMElement> linkContent;
|
||||
ToLowerCase(localName);
|
||||
nsAutoString href;
|
||||
if (localName.Equals(NS_LITERAL_STRING("a")) ||
|
||||
localName.Equals(NS_LITERAL_STRING("area")) ||
|
||||
localName.Equals(NS_LITERAL_STRING("link"))) {
|
||||
PRBool hasAttr;
|
||||
content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
|
||||
if (hasAttr) {
|
||||
linkContent = content;
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
|
||||
if (anchor)
|
||||
anchor->GetHref(href);
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLAreaElement> area(do_QueryInterface(linkContent));
|
||||
if (area)
|
||||
area->GetHref(href);
|
||||
else {
|
||||
nsCOMPtr<nsIDOMHTMLLinkElement> link(do_QueryInterface(linkContent));
|
||||
if (link)
|
||||
link->GetHref(href);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
nsCOMPtr<nsIDOMNode> curr = aNode;
|
||||
nsCOMPtr<nsIDOMNode> temp = curr;
|
||||
temp->GetParentNode(getter_AddRefs(curr));
|
||||
while (curr) {
|
||||
content = do_QueryInterface(curr);
|
||||
if (!content)
|
||||
break;
|
||||
content->GetLocalName(localName);
|
||||
ToLowerCase(localName);
|
||||
if (localName.Equals(NS_LITERAL_STRING("a"))) {
|
||||
PRBool hasAttr;
|
||||
content->HasAttribute(NS_LITERAL_STRING("href"), &hasAttr);
|
||||
if (hasAttr) {
|
||||
linkContent = content;
|
||||
nsCOMPtr<nsIDOMHTMLAnchorElement> anchor(do_QueryInterface(linkContent));
|
||||
if (anchor)
|
||||
anchor->GetHref(href);
|
||||
}
|
||||
else
|
||||
linkContent = nsnull; // Links can't be nested.
|
||||
break;
|
||||
}
|
||||
|
||||
temp = curr;
|
||||
temp->GetParentNode(getter_AddRefs(curr));
|
||||
}
|
||||
}
|
||||
|
||||
*aLinkContent = linkContent;
|
||||
NS_IF_ADDREF(*aLinkContent);
|
||||
|
||||
aHref = href;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,7 @@
|
|||
#import <AppKit/NSImage.h>
|
||||
|
||||
@interface NSImage (CHImageAdditions)
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta;
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op;
|
||||
- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale;
|
||||
@end
|
|
@ -0,0 +1,36 @@
|
|||
#import "CHImageAdditions.h"
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@implementation NSImage (CHImageAdditions)
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op fraction:(float) delta {
|
||||
CGContextRef context;
|
||||
|
||||
context = [[NSGraphicsContext currentContext] graphicsPort];
|
||||
CGContextSaveGState( context ); {
|
||||
CGContextTranslateCTM( context, 0, NSMaxY( rect ) );
|
||||
CGContextScaleCTM( context, 1, -1 );
|
||||
|
||||
rect.origin.y = 0;
|
||||
[self drawInRect:rect fromRect:NSZeroRect operation:op fraction:delta];
|
||||
} CGContextRestoreGState( context );
|
||||
}
|
||||
|
||||
- (void) drawFlippedInRect:(NSRect) rect operation:(NSCompositingOperation) op {
|
||||
[self drawFlippedInRect:rect operation:op fraction:1.0];
|
||||
}
|
||||
|
||||
- (void)applyBadge:(NSImage*)badge withAlpha:(float)alpha scale:(float)scale
|
||||
{
|
||||
if (!badge)
|
||||
return;
|
||||
|
||||
[badge setScalesWhenResized:YES];
|
||||
[badge setSize:NSMakeSize([self size].width * scale,[self size].height * scale)];
|
||||
|
||||
[self lockFocus];
|
||||
[[NSGraphicsContext currentContext] setImageInterpolation:NSImageInterpolationHigh];
|
||||
[badge dissolveToPoint:NSMakePoint([self size].width - [badge size].width,0) fraction:alpha];
|
||||
[self unlockFocus];
|
||||
}
|
||||
|
||||
@end
|
|
@ -0,0 +1,12 @@
|
|||
#import <AppKit/NSToolbar.h>
|
||||
|
||||
@interface NSToolbar (CHToolbarCustomizableAdditions)
|
||||
- (BOOL) alwaysCustomizableByDrag;
|
||||
- (void) setAlwaysCustomizableByDrag:(BOOL) flag;
|
||||
|
||||
- (BOOL) showsContextMenu;
|
||||
- (void) setShowsContextMenu:(BOOL) flag;
|
||||
|
||||
- (unsigned int) indexOfFirstMovableItem;
|
||||
- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex;
|
||||
@end
|
|
@ -0,0 +1,28 @@
|
|||
#import "CHToolbarAdditions.h"
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@implementation NSToolbar (CHToolbarCustomizableAdditions)
|
||||
- (BOOL) alwaysCustomizableByDrag {
|
||||
return (BOOL) _tbFlags.clickAndDragPerformsCustomization;
|
||||
}
|
||||
|
||||
- (void) setAlwaysCustomizableByDrag:(BOOL) flag {
|
||||
_tbFlags.clickAndDragPerformsCustomization = (unsigned int) flag & 1;
|
||||
}
|
||||
|
||||
- (BOOL) showsContextMenu {
|
||||
return (BOOL) ! _tbFlags.showsNoContextMenu;
|
||||
}
|
||||
|
||||
- (void) setShowsContextMenu:(BOOL) flag {
|
||||
_tbFlags.showsNoContextMenu = (unsigned int) ! flag & 1;
|
||||
}
|
||||
|
||||
- (unsigned int) indexOfFirstMovableItem {
|
||||
return (unsigned int) _tbFlags.firstMoveableItemIndex;
|
||||
}
|
||||
|
||||
- (void) setIndexOfFirstMovableItem:(unsigned int) anIndex {
|
||||
_tbFlags.firstMoveableItemIndex = (unsigned int) anIndex & 0x3F;
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,37 @@
|
|||
/* -*- 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):
|
||||
* Mike Pinkerton <pinkerton@netscape.com> (Original Author)
|
||||
*/
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
//
|
||||
// protocol CHFind
|
||||
//
|
||||
// Any window who wants to be able to work with the Find dialog should implement
|
||||
// this protocol.
|
||||
//
|
||||
|
||||
@protocol CHFind
|
||||
|
||||
- (BOOL)findInPage:(NSString*)text;
|
||||
|
||||
@end
|
Загрузка…
Ссылка в новой задаче