├── .gitignore ├── LICENSE ├── LICENSE-chromium ├── README.md ├── chromium-tabs.xcodeproj └── project.pbxproj ├── examples ├── prefix.pch └── simple-app │ ├── AppDelegate.h │ ├── AppDelegate.m │ ├── English.lproj │ ├── InfoPlist.strings │ └── MainMenu.xib │ ├── Info.plist │ ├── MyBrowser.h │ ├── MyBrowser.m │ ├── MyTabContents.h │ ├── MyTabContents.m │ └── main.m ├── ownership-and-relations.txt ├── resources ├── BrowserWindow.xib ├── ChromiumTabs-Info.plist ├── English.lproj │ └── Localizable.strings ├── TabContents.xib ├── TabView.xib ├── Toolbar_bak.xib └── gfx │ ├── default-icon.pdf │ ├── newtab.png │ ├── newtab_h.png │ ├── newtab_p.png │ ├── sadfavicon.png │ ├── throbber.png │ └── throbber_waiting.png ├── src ├── Browser Window │ ├── CTBrowser.h │ ├── CTBrowser.m │ ├── CTBrowserCommand.h │ ├── CTBrowserFrameView.h │ ├── CTBrowserFrameView.m │ ├── CTBrowserWindow.h │ ├── CTBrowserWindow.m │ ├── CTBrowserWindowController.h │ ├── CTBrowserWindowController.m │ ├── CTPresentationModeController.h │ ├── CTPresentationModeController.m │ ├── CTTabWindowController.h │ └── CTTabWindowController.m ├── Buttons │ ├── HoverButton.h │ ├── HoverButton.m │ ├── HoverCloseButton.h │ ├── HoverCloseButton.m │ ├── NewTabButton.h │ ├── NewTabButton.m │ ├── ToolbarButton.h │ └── ToolbarButton.m ├── ChromiumTabs.h ├── Tab Strip │ ├── CTTabStripController.h │ ├── CTTabStripController.m │ ├── CTTabStripDragController.h │ ├── CTTabStripDragController.m │ ├── CTTabStripModel.h │ ├── CTTabStripModel.m │ ├── CTTabStripModelDelegate.h │ ├── CTTabStripModelOrderController.h │ ├── CTTabStripModelOrderController.m │ ├── CTTabStripView.h │ └── CTTabStripView.m ├── Tab │ ├── CTTabContents.h │ ├── CTTabContents.m │ ├── CTTabContentsController.h │ ├── CTTabContentsController.m │ ├── CTTabController.h │ ├── CTTabController.m │ ├── CTTabControllerTarget.h │ ├── CTTabView.h │ └── CTTabView.m ├── Toolbar │ ├── CTToolbarController.h │ ├── CTToolbarController.m │ ├── CTToolbarView.h │ └── CTToolbarView.m ├── Utils │ ├── CTPageTransition.c │ ├── CTPageTransition.h │ ├── CTUtil.h │ ├── CTUtil.m │ ├── NSImage+CTAdditions.h │ ├── NSImage+CTAdditions.m │ ├── NSWindow+CTThemed.h │ ├── NSWindow+CTThemed.m │ ├── URLDropTarget.h │ └── URLDropTarget.m ├── Views │ ├── BackgroundGradientView.h │ ├── BackgroundGradientView.m │ ├── CTFloatingBarBackingView.h │ ├── CTFloatingBarBackingView.m │ ├── FastResizeView.h │ ├── FastResizeView.m │ ├── ThrobberView.h │ └── ThrobberView.m ├── build_config.h ├── common.c ├── common.h ├── common.m ├── prefix.pch └── third_party │ ├── .gclient │ ├── gtm-subset │ ├── COPYING │ ├── GTMDefines.h │ ├── GTMNSAnimation+Duration.h │ ├── GTMNSAnimation+Duration.m │ ├── GTMNSColor+Luminance.h │ └── GTMNSColor+Luminance.m │ ├── molokocacao │ ├── LICENSE │ ├── NSBezierPath+MCAdditions.h │ ├── NSBezierPath+MCAdditions.m │ └── README.chromium │ └── mozilla │ ├── LICENSE │ ├── NSPasteboard+Utils.h │ ├── NSPasteboard+Utils.m │ ├── NSString+Utils.h │ ├── NSString+Utils.m │ ├── NSURL+Utils.h │ ├── NSURL+Utils.m │ └── README.chromium └── todo.taskpaper /.gitignore: -------------------------------------------------------------------------------- 1 | /build/ 2 | /chromium/.gclient 3 | /chromium/.gclient_entries 4 | /chromium/README-archive 5 | /chromium/src/ 6 | *xcodeproj/project.xcworkspace 7 | *xcodeproj/xcuserdata 8 | /examples/simple-app/test.* 9 | *CTTab*Object.* 10 | 11 | .DS_Store 12 | 13 | chromium-tabs.xcodeproj/KOed.mode1v3 14 | 15 | chromium-tabs.xcodeproj/KOed.pbxuser 16 | 17 | chromium-tabs.tmproj 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | This license applies to all parts of Chromium Tabs that are not externally 2 | created by (origins from) a third party. The third party material used by 3 | Chromium Tabs are: 4 | 5 | - Chromium, located under src/chrome and src/base, copyright Google, Inc. BSD 6 | license. See LICENSE-chromium. 7 | 8 | - Google Toolbox for Mac, located under src/third_party/gtm-subset, copyright 9 | by Google, Inc. Apache 2.0 license. 10 | 11 | - MolokoCacao, located under src/third_party/molokocacao, copyright Sean 12 | Patrick O'Brien. BSD license. 13 | 14 | - Cocoa extension code from Camino, located under src/third_party/mozilla, 15 | copyright Netscape Communications Corporation and mozilla.org. MPL 1.1 16 | license. 17 | 18 | 19 | Chromium Tabs's license follows: 20 | 21 | Copyright 2010 Rasmus Andersson. All rights reserved. 22 | 23 | Permission is hereby granted, free of charge, to any person obtaining a copy 24 | of this software and associated documentation files (the "Software"), to 25 | deal in the Software without restriction, including without limitation the 26 | rights to use, copy, modify, merge, publish, distribute, sublicense, and/or 27 | sell copies of the Software, and to permit persons to whom the Software is 28 | furnished to do so, subject to the following conditions: 29 | 30 | The above copyright notice and this permission notice shall be included in 31 | all copies or substantial portions of the Software. 32 | 33 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 36 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 37 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 38 | FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 39 | IN THE SOFTWARE. 40 | -------------------------------------------------------------------------------- /LICENSE-chromium: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Google Inc. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Chromium Tabs 2 | 3 | Chromium Tabs is a [Cocoa](http://developer.apple.com/cocoa/) framework for building applications that works like [Chromium](http://www.chromium.org/)'s window system. 4 | 5 | - An *application* has multiple *windows* 6 | - Each *window* represents a unit of *tabs* 7 | - Each *tab* represents a stateful view 8 | - Each *tab* can be freely dragged between *windows* 9 | 10 | > **Important:** This is currently work in progress and the framework API will change often. 11 | 12 | Requirements: OS X 10.5 or later. 13 | 14 | ## Usage 15 | 16 | The framework is distributed with an [`@rpath`](http://www.codeshorts.ca/2007/nov/01/leopard-linking-making-relocatable-libraries-movin) which means it should be embedded into your applications' Contents/Frameworks directory. In Xcode you can add a new "Copy Files" action with the "Frameworks" destination to your target. 17 | 18 | As an alternative, with Xcode4, you can create a new workspace which includes your project and `chromium-tabs.xcodeproj`. Once this is done, `ChromiumTabs.framework` will be available for linking like any other built-in library. 19 | 20 | Then you need to do at least two things: 21 | 22 | 1. `#import ` 23 | 2. `[[CTBrowser browser] newWindow]` when your application has started (e.g. in the application delegates' `applicationDidFinishLaunching:`) 24 | 25 | The example application (in `examples/simple-app/`) illustrates basic usage and likes to be inspected while you drink coffee. It looks like this: 26 | 27 | [A slightly boring screenshot of the example application](http://github.com/downloads/rsms/chromium-tabs/Chromium%20Tabs.app.zip) 28 | 29 | When building a "real" application you will need to sublcass at least the `CTBrowser` class which factorises tabs and their content. The example application do this at a very basic level (provides custom tab content). 30 | 31 | ## Download 32 | 33 | Visit the [download section on GitHub](http://github.com/rsms/chromium-tabs/downloads) to download the latest release of the framework and the example application. 34 | 35 | ## Building 36 | 37 | 1. Check out (or download) the source code 38 | 2. Open `chromium-tabs.xcodeproj` in [Xcode](http://developer.apple.com/tools/xcode/) 39 | 3. Choose your target and hit "Build" 40 | 41 | There is also an optional example application in the Xcode project. You build it by selecting the "Chromium Tabs" target. 42 | 43 | ## License 44 | 45 | See the LICENSE file for details. 46 | -------------------------------------------------------------------------------- /examples/prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | #import 3 | #endif 4 | -------------------------------------------------------------------------------- /examples/simple-app/AppDelegate.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface AppDelegate : NSObject { 4 | } 5 | 6 | - (void)commandDispatch:(id)sender; 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /examples/simple-app/AppDelegate.m: -------------------------------------------------------------------------------- 1 | #import "AppDelegate.h" 2 | #import "MyBrowser.h" 3 | 4 | @implementation AppDelegate 5 | 6 | - (void)applicationDidFinishLaunching:(NSNotification *)notification { 7 | // Create a new browser & window when we start 8 | MyBrowser* browser = (MyBrowser *)[MyBrowser browser]; 9 | browser.windowController = [[CTBrowserWindowController alloc] initWithBrowser:browser]; 10 | [browser addBlankTabInForeground:YES]; 11 | [browser.windowController showWindow:self]; 12 | } 13 | 14 | // When there are no windows in our application, this class (AppDelegate) will 15 | // become the first responder. We forward the command to the browser class. 16 | - (void)commandDispatch:(id)sender { 17 | NSLog(@"commandDispatch %d", (int)[sender tag]); 18 | [MyBrowser executeCommand:[sender tag]]; 19 | } 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /examples/simple-app/English.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /examples/simple-app/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIconFile 10 | 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1 25 | LSMinimumSystemVersion 26 | ${MACOSX_DEPLOYMENT_TARGET} 27 | NSMainNibFile 28 | MainMenu 29 | NSPrincipalClass 30 | NSApplication 31 | 32 | 33 | -------------------------------------------------------------------------------- /examples/simple-app/MyBrowser.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | // We provide our own CTBrowser subclass so we can create our own, custom tabs. 4 | // See the implementation file for details. 5 | 6 | @interface MyBrowser : CTBrowser { 7 | } 8 | @end 9 | -------------------------------------------------------------------------------- /examples/simple-app/MyBrowser.m: -------------------------------------------------------------------------------- 1 | #import "MyBrowser.h" 2 | #import "MyTabContents.h" 3 | 4 | @implementation MyBrowser 5 | 6 | // This method is called when a new tab is being created. We need to return a 7 | // new CTTabContents object which will represent the contents of the new tab. 8 | -(CTTabContents*)createBlankTabBasedOn:(CTTabContents*)baseContents { 9 | // Create a new instance of our tab type 10 | return [[MyTabContents alloc] 11 | initWithBaseTabContents:baseContents]; 12 | } 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /examples/simple-app/MyTabContents.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | // This class represents a tab. In this example application a tab contains a 4 | // simple scrollable text area. 5 | @interface MyTabContents : CTTabContents { 6 | } 7 | 8 | @end 9 | -------------------------------------------------------------------------------- /examples/simple-app/MyTabContents.m: -------------------------------------------------------------------------------- 1 | #import "MyTabContents.h" 2 | 3 | @implementation MyTabContents 4 | 5 | -(id)initWithBaseTabContents:(CTTabContents*)baseContents { 6 | if (!(self = [super initWithBaseTabContents:baseContents])) return nil; 7 | 8 | // Setup our contents -- a scrolling text view 9 | 10 | // Create a simple NSTextView 11 | NSTextView* tv = [[NSTextView alloc] initWithFrame:NSZeroRect]; 12 | [tv setFont:[NSFont userFixedPitchFontOfSize:13.0]]; 13 | [tv setAutoresizingMask: NSViewMaxYMargin| 14 | NSViewMinXMargin|NSViewWidthSizable|NSViewMaxXMargin| 15 | NSViewHeightSizable| 16 | NSViewMinYMargin]; 17 | 18 | // Create a NSScrollView to which we add the NSTextView 19 | NSScrollView *sv = [[NSScrollView alloc] initWithFrame:NSZeroRect]; 20 | [sv setDocumentView:tv]; 21 | [sv setHasVerticalScroller:YES]; 22 | 23 | // Set the NSScrollView as our view 24 | self.view = sv; 25 | 26 | return self; 27 | } 28 | 29 | -(void)viewFrameDidChange:(NSRect)newFrame { 30 | // We need to recalculate the frame of the NSTextView when the frame changes. 31 | // This happens when a tab is created and when it's moved between windows. 32 | [super viewFrameDidChange:newFrame]; 33 | NSClipView* clipView = [[view_ subviews] objectAtIndex:0]; 34 | NSTextView* tv = [[clipView subviews] objectAtIndex:0]; 35 | NSRect frame = NSZeroRect; 36 | frame.size = [(NSScrollView*)(view_) contentSize]; 37 | [tv setFrame:frame]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /examples/simple-app/main.m: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | int main(int argc, char *argv[]) { 4 | return NSApplicationMain(argc, (const char **) argv); 5 | } 6 | -------------------------------------------------------------------------------- /ownership-and-relations.txt: -------------------------------------------------------------------------------- 1 | 2 | CTBrowserWindowController 3 | CTTabStripController 4 | CTTabStripView 5 | TabContentsController[] # NSViewController for the contents of a tab 6 | weak:CTTabContents contents_ 7 | TabController[] # NSViewController for a tab in the tab strip 8 | weak:id target_ 9 | GTMWindowSheetController sheetController_ 10 | weak:CTTabContents currentTab_ 11 | weak:CTBrowser browser_ 12 | weak:CTTabStripModel tabStripModel_ 13 | CTTabStripModelObserverBridge 14 | weak:id controller_ # owns this 15 | weak:CTTabStripModel model_ 16 | CTToolbarController 17 | weak:CTBrowser browser_ 18 | CTBrowser browser_ 19 | CTTabStripModel 20 | TabContentsData[] 21 | CTTabContents 22 | NSView view_ 23 | weak: CTBrowser browser_ 24 | weak: CTTabContents parentOpener_ 25 | CTTabStripModelOrderController 26 | weak:CTTabStripModel tabStripModel_ 27 | CTTabStripModelObserver[] 28 | weak:NSObject delegate_ 29 | weak:CTBrowserWindowController *windowController_ 30 | 31 | -------------------------------------------------------------------------------- /resources/BrowserWindow.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /resources/ChromiumTabs-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | FMWK 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 0.0.4 21 | 22 | 23 | -------------------------------------------------------------------------------- /resources/English.lproj/Localizable.strings: -------------------------------------------------------------------------------- 1 | /* 2 | Strings are used by the framework through the L10n function in util.h 3 | */ 4 | 5 | /* Default title of an empty tab */ 6 | "New Tab" = "New Tab"; 7 | 8 | -------------------------------------------------------------------------------- /resources/TabContents.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /resources/TabView.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | -------------------------------------------------------------------------------- /resources/gfx/default-icon.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/default-icon.pdf -------------------------------------------------------------------------------- /resources/gfx/newtab.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/newtab.png -------------------------------------------------------------------------------- /resources/gfx/newtab_h.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/newtab_h.png -------------------------------------------------------------------------------- /resources/gfx/newtab_p.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/newtab_p.png -------------------------------------------------------------------------------- /resources/gfx/sadfavicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/sadfavicon.png -------------------------------------------------------------------------------- /resources/gfx/throbber.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/throbber.png -------------------------------------------------------------------------------- /resources/gfx/throbber_waiting.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/typcn/chromium-tabs/42c3d1a43bf2cfd385da0c99f01724063004773d/resources/gfx/throbber_waiting.png -------------------------------------------------------------------------------- /src/Browser Window/CTBrowser.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #import 3 | #import "CTTabStripModelDelegate.h" 4 | 5 | typedef enum { 6 | CTWindowOpenDispositionCurrentTab, 7 | CTWindowOpenDispositionNewForegroundTab, 8 | CTWindowOpenDispositionNewBackgroundTab, 9 | } CTWindowOpenDisposition; 10 | 11 | @class CTTabStripModel; 12 | @class CTBrowserWindowController; 13 | @class CTTabContentsController; 14 | @class CTToolbarController; 15 | 16 | // There is one CTBrowser instance per percieved window. 17 | // A CTBrowser instance has one TabStripModel. 18 | 19 | @interface CTBrowser : NSObject 20 | 21 | // The tab strip model 22 | @property(retain, readonly, nonatomic) CTTabStripModel* tabStripModel; 23 | 24 | // The window controller 25 | @property(strong, retain, readwrite, nonatomic) CTBrowserWindowController* windowController; 26 | 27 | // The window. Convenience for [windowController window] 28 | @property(strong, readonly, nonatomic) NSWindow* window; 29 | 30 | // Create a new browser with a window. 31 | // @autoreleased 32 | + (CTBrowser*)browser; 33 | 34 | // init 35 | - (id)init; 36 | 37 | // Create a new toolbar controller. The default implementation will create a 38 | // controller loaded with a nib called "Toolbar". If the nib can't be found in 39 | // the main bundle, a fallback nib will be loaded from the framework. 40 | // Returning nil means there is no toolbar. 41 | // @autoreleased 42 | - (CTToolbarController *)createToolbarController; 43 | 44 | // Create a new tab contents controller. Override this to provide a custom 45 | // CTTabContentsController subclass. 46 | // @autoreleased 47 | - (CTTabContentsController*)createTabContentsControllerWithContents: 48 | (CTTabContents*)contents; 49 | 50 | // Create a new default/blank CTTabContents. 51 | // |baseContents| represents the CTTabContents which is currently in the 52 | // foreground. It might be nil. 53 | // Subclasses could override this to provide a custom CTTabContents type. 54 | // @autoreleased 55 | - (CTTabContents*)createBlankTabBasedOn:(CTTabContents*)baseContents; 56 | 57 | // Add blank tab 58 | - (CTTabContents*)addBlankTabAtIndex:(int)index 59 | inForeground:(BOOL)foreground; 60 | - (CTTabContents*)addBlankTabInForeground:(BOOL)foreground; 61 | - (CTTabContents*)addBlankTab; // inForeground:YES 62 | 63 | // Add tab with contents 64 | - (CTTabContents*)addTabContents:(CTTabContents*)contents 65 | atIndex:(int)index 66 | inForeground:(BOOL)foreground; 67 | - (CTTabContents*)addTabContents:(CTTabContents*)contents 68 | inForeground:(BOOL)foreground; 69 | - (CTTabContents*)addTabContents:(CTTabContents*)contents; // inForeground:YES 70 | 71 | // Commands -- TODO: move to CTBrowserWindowController 72 | - (void)newWindow; 73 | - (void)closeWindow; 74 | - (void)closeTab; 75 | - (void)selectNextTab; 76 | - (void)selectPreviousTab; 77 | - (void)moveTabNext; 78 | - (void)moveTabPrevious; 79 | - (void)selectTabAtIndex:(int)index; 80 | - (void)selectLastTab; 81 | - (void)duplicateTab; 82 | 83 | - (void)executeCommand:(int)cmd 84 | withDisposition:(CTWindowOpenDisposition)disposition; 85 | - (void)executeCommand:(int)cmd; 86 | 87 | // Execute a command which does not need to have a valid browser. This can be 88 | // used in application delegates or other non-chromium-tabs windows which are 89 | // first responders. Like this: 90 | // 91 | // - (void)commandDispatch:(id)sender { 92 | // [MyBrowser executeCommand:[sender tag]]; 93 | // } 94 | // 95 | + (void)executeCommand:(int)cmd; 96 | 97 | // callbacks 98 | - (void)loadingStateDidChange:(CTTabContents*)contents; 99 | - (void)windowDidBeginToClose; 100 | 101 | // Convenience helpers (proxy for TabStripModel) 102 | - (int)tabCount; 103 | - (int)activeTabIndex; 104 | - (CTTabContents*)activeTabContents; 105 | - (CTTabContents*)tabContentsAtIndex:(int)index; 106 | - (NSArray*)allTabContents; 107 | - (int)indexOfTabContents:(CTTabContents*)contents; // -1 if not found 108 | - (void)selectTabContentsAtIndex:(int)index userGesture:(BOOL)userGesture; 109 | - (void)updateTabStateAtIndex:(int)index; 110 | - (void)updateTabStateForContent:(CTTabContents*)contents; 111 | - (void)replaceTabContentsAtIndex:(int)index 112 | withTabContents:(CTTabContents*)contents; 113 | - (void)closeTabAtIndex:(int)index makeHistory:(BOOL)makeHistory; 114 | - (void)closeAllTabs; 115 | 116 | @end 117 | -------------------------------------------------------------------------------- /src/Browser Window/CTBrowserCommand.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // NOTE: Within each of the following sections, the IDs are ordered roughly by 4 | // how they appear in the GUI/menus (left to right, top to bottom, etc.). 5 | 6 | // NOTE: MainMenu.xib use these constants so if you change something here you 7 | // also need to update the corresponding "tag" in MainMenu.xib 8 | 9 | typedef enum { 10 | // Window management commands 11 | CTBrowserCommandNewWindow = 34000, 12 | //CTBrowserCommandNewIncognitoWindow = 34001, 13 | CTBrowserCommandCloseWindow = 34012, 14 | //CTBrowserCommandAlwaysOnTop = 34013, 15 | CTBrowserCommandNewTab = 34014, 16 | CTBrowserCommandCloseTab = 34015, 17 | CTBrowserCommandSelectNextTab = 34016, 18 | CTBrowserCommandSelectPreviousTab = 34017, 19 | CTBrowserCommandSelectTab0 = 34018, 20 | CTBrowserCommandSelectTab1 = 34019, 21 | CTBrowserCommandSelectTab2 = 34020, 22 | CTBrowserCommandSelectTab3 = 34021, 23 | CTBrowserCommandSelectTab4 = 34022, 24 | CTBrowserCommandSelectTab5 = 34023, 25 | CTBrowserCommandSelectTab6 = 34024, 26 | CTBrowserCommandSelectTab7 = 34025, 27 | CTBrowserCommandSelectLastTab = 34026, 28 | CTBrowserCommandDuplicateTab = 34027, 29 | CTBrowserCommandRestoreTab = 34028, 30 | CTBrowserCommandShowAsTab = 34029, 31 | CTBrowserCommandFullscreen = 34030, 32 | CTBrowserCommandExit = 34031, 33 | CTBrowserCommandMoveTabNext = 34032, 34 | CTBrowserCommandMoveTabPrevious = 34033, 35 | //CTBrowserCommandSearch = 34035, 36 | //CTBrowserCommandTabpose = 34036, 37 | } CTBrowserCommand; 38 | -------------------------------------------------------------------------------- /src/Browser Window/CTBrowserFrameView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import 6 | 7 | // CTBrowserFrameView is a class whose methods we swizzle into NSGrayFrame 8 | // (an AppKit framework class) so that we can support custom frame drawing, and 9 | // have the ability to move our window widgets (close, zoom, miniaturize) where 10 | // we want them. 11 | // This class is never to be instantiated on its own. 12 | // We explored a variety of ways to support custom frame drawing and custom 13 | // window widgets. 14 | // Our requirements were: 15 | // a) that we could fall back on standard system drawing at any time for the 16 | // "default theme" 17 | // b) We needed to be able to draw both a background pattern, and an overlay 18 | // graphic, and we need to be able to set the pattern phase of our background 19 | // window. 20 | // c) We had to be able to support "transparent" themes, so that you could see 21 | // through to the underlying windows in places without the system theme 22 | // getting in the way. 23 | // d) We had to support having the custom window controls moved down by a couple 24 | // of pixels and rollovers, accessibility, etc. all had to work. 25 | // 26 | // Since we want "A" we couldn't just do a transparent borderless window. At 27 | // least I couldn't find the right combination of HITheme calls to make it draw 28 | // nicely, and I don't trust that the HITheme calls are going to exist in future 29 | // system versions. 30 | // "C" precluded us from inserting a view between the system frame and the 31 | // the content frame in Z order. To get the transparency we actually need to 32 | // replace the drawing of the system frame. 33 | // "D" required us to override _mouseInGroup to get our custom widget rollovers 34 | // drawing correctly. The widgets call _mouseInGroup on their superview to 35 | // decide whether they should draw in highlight mode or not. 36 | // "B" precluded us from just setting a background color on the window. 37 | // 38 | // Originally we tried overriding the private API +frameViewForStyleMask: to 39 | // add our own subclass of NSGrayView to our window. Turns out that if you 40 | // subclass NSGrayView it does not draw correctly when you call NSGrayView's 41 | // drawRect. It appears that NSGrayView's drawRect: method (and that of its 42 | // superclasses) do lots of "isMemberOfClass/isKindOfClass" calls, and if your 43 | // class is NOT an instance of NSGrayView (as opposed to a subclass of 44 | // NSGrayView) then the system drawing will not work correctly. 45 | // 46 | // Given all of the above, we found swizzling drawRect, and adding an 47 | // implementation of _mouseInGroup and updateTrackingAreas, in _load to be the 48 | // easiest and safest method of achieving our goals. We do the best we can to 49 | // check that everything is safe, and attempt to fallback gracefully if it is 50 | // not. 51 | @interface CTBrowserFrameView : NSView 52 | @end 53 | -------------------------------------------------------------------------------- /src/Browser Window/CTBrowserFrameView.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import "CTBrowserFrameView.h" 6 | 7 | #import 8 | 9 | #import "CTBrowserWindow.h" 10 | #import "common.h" 11 | 12 | static const CGFloat kBrowserFrameViewPaintHeight = 60.0; 13 | //static const NSPoint kBrowserFrameViewPatternPhaseOffset = { -5, 3 }; 14 | 15 | static BOOL gCanDrawTitle = NO; 16 | static BOOL gCanGetCornerRadius = NO; 17 | 18 | @interface NSView (Swizzles) 19 | - (void)drawRectOriginal:(NSRect)rect; 20 | - (BOOL)_mouseInGroup:(NSButton*)widget; 21 | - (void)updateTrackingAreas; 22 | @end 23 | 24 | // Undocumented APIs. They are really on NSGrayFrame rather than 25 | // CTBrowserFrameView, but we call them from methods swizzled onto NSGrayFrame. 26 | @interface CTBrowserFrameView (UndocumentedAPI) 27 | 28 | - (float)roundedCornerRadius; 29 | - (CGRect)_titlebarTitleRect; 30 | - (void)_drawTitleStringIn:(struct CGRect)arg1 withColor:(id)color; 31 | 32 | @end 33 | 34 | @implementation CTBrowserFrameView 35 | 36 | + (void)load { 37 | // This is where we swizzle drawRect, and add in two methods that we 38 | // need. If any of these fail it shouldn't affect the functionality of the 39 | // others. If they all fail, we will lose window frame theming and 40 | // roll overs for our close widgets, but things should still function 41 | // correctly. 42 | // ScopedNSAutoreleasePool pool; 43 | Class grayFrameClass = NSClassFromString(@"NSGrayFrame"); 44 | DCHECK(grayFrameClass); 45 | if (!grayFrameClass) return; 46 | 47 | // Exchange draw rect 48 | Method m0 = class_getInstanceMethod([self class], @selector(drawRect:)); 49 | DCHECK(m0); 50 | if (m0) { 51 | BOOL didAdd = class_addMethod(grayFrameClass, 52 | @selector(drawRectOriginal:), 53 | method_getImplementation(m0), 54 | method_getTypeEncoding(m0)); 55 | DCHECK(didAdd); 56 | if (didAdd) { 57 | Method m1 = class_getInstanceMethod(grayFrameClass, @selector(drawRect:)); 58 | Method m2 = class_getInstanceMethod(grayFrameClass, 59 | @selector(drawRectOriginal:)); 60 | DCHECK(m1 && m2); 61 | if (m1 && m2) { 62 | method_exchangeImplementations(m1, m2); 63 | } 64 | } 65 | } 66 | 67 | gCanDrawTitle = 68 | [grayFrameClass 69 | instancesRespondToSelector:@selector(_titlebarTitleRect)] && 70 | [grayFrameClass 71 | instancesRespondToSelector:@selector(_drawTitleStringIn:withColor:)]; 72 | gCanGetCornerRadius = 73 | [grayFrameClass 74 | instancesRespondToSelector:@selector(roundedCornerRadius)]; 75 | } 76 | 77 | /*- (id)initWithFrame:(NSRect)frame { 78 | // This class is not for instantiating. 79 | [self doesNotRecognizeSelector:_cmd]; 80 | return nil; 81 | } 82 | 83 | - (id)initWithCoder:(NSCoder*)coder { 84 | // This class is not for instantiating. 85 | [self doesNotRecognizeSelector:_cmd]; 86 | return nil; 87 | }*/ 88 | 89 | // Here is our custom drawing for our frame. 90 | - (void)drawRect:(NSRect)rect { 91 | // If this isn't the window class we expect, then pass it on to the 92 | // original implementation. 93 | if (![[self window] isKindOfClass:[CTBrowserWindow class]]) { 94 | [self drawRectOriginal:rect]; 95 | return; 96 | } 97 | 98 | // WARNING: There is an obvious optimization opportunity here that you DO NOT 99 | // want to take. To save painting cycles, you might think it would be a good 100 | // idea to call out to -drawRectOriginal: only if no theme were drawn. In 101 | // reality, however, if you fail to call -drawRectOriginal:, or if you call it 102 | // after a clipping path is set, the rounded corners at the top of the window 103 | // will not draw properly. Do not try to be smart here. 104 | 105 | // Only paint the top of the window. 106 | NSWindow* window = [self window]; 107 | NSRect windowRect = [self convertRect:[window frame] fromView:nil]; 108 | windowRect.origin = NSMakePoint(0, 0); 109 | 110 | NSRect paintRect = windowRect; 111 | paintRect.origin.y = NSMaxY(paintRect) - kBrowserFrameViewPaintHeight; 112 | paintRect.size.height = kBrowserFrameViewPaintHeight; 113 | rect = NSIntersectionRect(paintRect, rect); 114 | [self drawRectOriginal:rect]; 115 | 116 | // Set up our clip. 117 | float cornerRadius = 4.0; 118 | if (gCanGetCornerRadius) 119 | cornerRadius = [self roundedCornerRadius]; 120 | [[NSBezierPath bezierPathWithRoundedRect:windowRect 121 | xRadius:cornerRadius 122 | yRadius:cornerRadius] addClip]; 123 | [[NSBezierPath bezierPathWithRect:rect] addClip]; 124 | 125 | // Draw a fancy gradient at the top of the window, like "Incognito mode" 126 | /* 127 | NSGradient* gradient = [[NSGradient alloc] initWithStartingColor:[NSColor yellowColor] 128 | endingColor:[NSColor redColor]]; 129 | NSPoint startPoint = NSMakePoint(NSMinX(windowRect), NSMaxY(windowRect)); 130 | NSPoint endPoint = startPoint; 131 | endPoint.y -= kBrowserFrameViewPaintHeight; 132 | [gradient drawFromPoint:startPoint toPoint:endPoint options:0]; 133 | */ 134 | 135 | // -- removed: themed window drawing routines -- 136 | } 137 | 138 | @end 139 | -------------------------------------------------------------------------------- /src/Browser Window/CTBrowserWindow.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #pragma once 6 | #import 7 | // Cocoa class representing a Chrome browser window. 8 | // We need to override NSWindow with our own class since we need access to all 9 | // unhandled keyboard events and subclassing NSWindow is the only method to do 10 | // this. We also handle our own window controls and custom window frame drawing. 11 | @interface CTBrowserWindow : NSWindow 12 | @property (readonly, nonatomic) CGFloat windowButtonsInterButtonSpacing; 13 | 14 | // Tells the window to suppress title drawing. 15 | - (void)setShouldHideTitle:(BOOL)flag; 16 | @end 17 | 18 | @interface NSWindow (UndocumentedAPI) 19 | 20 | // Undocumented Cocoa API to suppress drawing of the window's title. 21 | // -setTitle: still works, but the title set only applies to the 22 | // miniwindow and menus (and, importantly, Expose). Overridden to 23 | // return |shouldHideTitle_|. 24 | -(BOOL)_isTitleHidden; 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /src/Browser Window/CTBrowserWindowController.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "CTTabWindowController.h" 3 | 4 | @class CTBrowser; 5 | @class CTTabStripController; 6 | @class CTToolbarController; 7 | @class CTTabContents; 8 | @class CTPresentationModeController; 9 | 10 | @interface NSDocumentController (CTBrowserWindowControllerAdditions) 11 | - (id)openUntitledDocumentWithWindowController:(NSWindowController*)windowController 12 | display:(BOOL)display 13 | error:(NSError **)outError; 14 | @end 15 | 16 | @interface CTBrowserWindowController : CTTabWindowController { 17 | __weak CTBrowser* browser_; // we own the browser 18 | CTTabStripController *tabStripController_; 19 | CTToolbarController *toolbarController_; 20 | @private 21 | BOOL initializing_; // YES if the instance is initializing 22 | 23 | // The view that shows the presentation mode toggle when in Lion fullscreen 24 | // mode. Nil if not in fullscreen mode or not on Lion. 25 | NSButton* presentationModeToggleButton_; 26 | 27 | // Tracks whether presentation mode was entered from fullscreen mode or 28 | // directly from normal windowed mode. Used to determine what to do when 29 | // exiting presentation mode. 30 | BOOL enteredPresentationModeFromFullscreen_; 31 | 32 | // True between -windowWillEnterFullScreen and -windowDidEnterFullScreen. 33 | // Only used on Lion. 34 | BOOL enteringFullscreen_; 35 | 36 | CTPresentationModeController* presentationModeController_; 37 | 38 | // Lazily created view which draws the background for the floating set of bars 39 | // in presentation mode (for window types having a floating bar; it remains 40 | // nil for those which don't). 41 | NSView* floatingBarBackingView_; 42 | 43 | // The proportion of the floating bar which is shown (in presentation mode). 44 | CGFloat floatingBarShownFraction_; 45 | 46 | // Various UI elements/events may want to ensure that the floating bar is 47 | // visible (in presentation mode), e.g., because of where the mouse is or 48 | // where keyboard focus is. Whenever an object requires bar visibility, it has 49 | // itself added to |barVisibilityLocks_|. When it no longer requires bar 50 | // visibility, it has itself removed. 51 | NSMutableSet* barVisibilityLocks_; 52 | 53 | // Bar visibility locks and releases only result (when appropriate) in changes 54 | // in visible state when the following is |YES|. 55 | BOOL barVisibilityUpdatesEnabled_; 56 | 57 | BOOL shouldUsePresentationModeWhenEnteringFullscreen_; 58 | } 59 | 60 | @property(strong, readonly, nonatomic) CTTabStripController *tabStripController; 61 | @property(strong, readonly, nonatomic) CTToolbarController *toolbarController; 62 | @property(weak, readonly, nonatomic) CTBrowser *browser; 63 | 64 | // Called to check whether or not this window has a toolbar. By default returns 65 | // YES if toolbarController_ is not nil. 66 | @property(readonly, nonatomic) BOOL hasToolbar; 67 | 68 | // Ensure that the new tab button is never shown if set. 69 | @property(nonatomic, assign) BOOL disableNewTabButton; 70 | 71 | @property(readwrite, nonatomic, assign) BOOL shouldUsePresentationModeWhenEnteringFullscreen; 72 | 73 | //@property(readonly, nonatomic) BOOL shouldShowPresentationModeToggle; 74 | 75 | // Returns the current "main" CTBrowserWindowController, or nil if none. "main" 76 | // means the window controller's window is the main window. Useful when there's 77 | // a need to e.g. add contents to the "best window from the users perspective". 78 | + (CTBrowserWindowController*)mainBrowserWindowController; 79 | 80 | // Returns the window controller for |window| or nil if none found 81 | + (CTBrowserWindowController*)browserWindowControllerForWindow:(NSWindow*)window; 82 | 83 | // Returns the window controller for |view| or nil if none found 84 | + (CTBrowserWindowController*)browserWindowControllerForView:(NSView*)view; 85 | 86 | // alias for [[[isa alloc] init] autorelease] 87 | + (CTBrowserWindowController*)browserWindowController; 88 | 89 | - (id)initWithWindowNibPath:(NSString *)windowNibPath 90 | browser:(CTBrowser*)browser; 91 | - (id)initWithBrowser:(CTBrowser *)browser; 92 | - (id)init; 93 | 94 | // Gets the pattern phase for the window. 95 | - (NSPoint)themePatternPhase; 96 | 97 | - (IBAction)saveAllDocuments:(id)sender; 98 | - (IBAction)openDocument:(id)sender; 99 | - (IBAction)newDocument:(id)sender; 100 | 101 | // Returns the active tab, or nil if there are no tabs. 102 | - (CTTabContents*)activeTabContents; 103 | 104 | // Returns the index of the active tab, or -1 if there are no tabs. 105 | - (int)activeTabIndex; 106 | 107 | // Updates the toolbar with the states of the specified |contents|. 108 | // If |shouldRestore| is YES, we're switching (back?) to this tab and should 109 | // restore any previous state (such as user editing a text field) as well. 110 | - (void)updateToolbarWithContents:(CTTabContents*)tab 111 | shouldRestoreState:(BOOL)shouldRestore; 112 | 113 | // Brings this controller's window to the front. 114 | - (void)activate; 115 | 116 | // Make the (currently-active) tab contents the first responder, if possible. 117 | - (void)focusTabContents; 118 | 119 | // Lays out the tab content area in the given frame. If the height changes, 120 | // sends a message to the renderer to resize. 121 | - (void)layoutTabContentArea:(NSRect)frame; 122 | @end 123 | 124 | // Methods having to do with fullscreen and presentation mode. 125 | @interface CTBrowserWindowController(Fullscreen) 126 | @property(nonatomic, readonly) BOOL isFullscreen; // fullscreen or not 127 | @property(nonatomic, readonly) BOOL inPresentationMode; 128 | 129 | // Returns fullscreen state. This method is safe to call on all OS versions. 130 | - (BOOL)isFullscreen; 131 | 132 | // Whether to show the presentation mode toggle button in the UI. Returns YES 133 | // if in fullscreen mode on Lion or later. This method is safe to call on all 134 | // OS versions. 135 | // Subclasses can overwrite this to decide whether or not show presentation 136 | // mode toggle button. 137 | - (BOOL)shouldShowPresentationModeToggle; 138 | 139 | // Resizes the fullscreen window to fit the screen it's currently on. Called by 140 | // the PresentationModeController when there is a change in monitor placement or 141 | // resolution. 142 | - (void)resizeFullscreenWindow; 143 | 144 | // Gets or sets the fraction of the floating bar (presentation mode overlay) 145 | // that is shown. 0 is completely hidden, 1 is fully shown. 146 | - (CGFloat)floatingBarShownFraction; 147 | - (void)setFloatingBarShownFraction:(CGFloat)fraction; 148 | 149 | // Query/lock/release the requirement that the tab strip/toolbar/attached 150 | // bookmark bar bar cluster is visible (e.g., when one of its elements has 151 | // focus). This is required for the floating bar in presentation mode, but 152 | // should also be called when not in presentation mode; see the comments for 153 | // |barVisibilityLocks_| for more details. Double locks/releases by the same 154 | // owner are ignored. If |animate:| is YES, then an animation may be performed, 155 | // possibly after a small delay if |delay:| is YES. If |animate:| is NO, 156 | // |delay:| will be ignored. In the case of multiple calls, later calls have 157 | // precedence with the rule that |animate:NO| has precedence over |animate:YES|, 158 | // and |delay:NO| has precedence over |delay:YES|. 159 | - (BOOL)isBarVisibilityLockedForOwner:(id)owner; 160 | - (void)lockBarVisibilityForOwner:(id)owner 161 | withAnimation:(BOOL)animate 162 | delay:(BOOL)delay; 163 | - (void)releaseBarVisibilityForOwner:(id)owner 164 | withAnimation:(BOOL)animate 165 | delay:(BOOL)delay; 166 | @end // @interface BrowserWindowController(Fullscreen) 167 | -------------------------------------------------------------------------------- /src/Browser Window/CTPresentationModeController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CTPresentationModeController.h 3 | // chromium-tabs 4 | // 5 | // Created by KOed on 12-4-19. 6 | // Copyright (c) 2012年 __MyCompanyName__. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @class CTBrowserWindowController; 13 | @class DropdownAnimation; 14 | 15 | // Provides a controller to manage presentation mode for a single browser 16 | // window. This class handles running animations, showing and hiding the 17 | // floating dropdown bar, and managing the tracking area associated with the 18 | // dropdown. This class does not directly manage any views -- the 19 | // BrowserWindowController is responsible for positioning and z-ordering views. 20 | // 21 | // Tracking areas are disabled while animations are running. If 22 | // |overlayFrameChanged:| is called while an animation is running, the 23 | // controller saves the new frame and installs the appropriate tracking area 24 | // when the animation finishes. This is largely done for ease of 25 | // implementation; it is easier to check the mouse location at each animation 26 | // step than it is to manage a constantly-changing tracking area. 27 | @interface CTPresentationModeController : NSObject 28 | 29 | @property(readonly, nonatomic) BOOL inPresentationMode; 30 | 31 | // Designated initializer. 32 | - (id)initWithBrowserController:(CTBrowserWindowController*)controller; 33 | 34 | // Informs the controller that the browser has entered or exited presentation 35 | // mode. |-enterPresentationModeForContentView:showDropdown:| should be called 36 | // after the window is setup, just before it is shown. |-exitPresentationMode| 37 | // should be called before any views are moved back to the non-fullscreen 38 | // window. If |-enterPresentationModeForContentView:showDropdown:| is called, 39 | // it must be balanced with a call to |-exitPresentationMode| before the 40 | // controller is released. 41 | - (void)enterPresentationModeForContentView:(NSView*)contentView 42 | showDropdown:(BOOL)showDropdown; 43 | - (void)exitPresentationMode; 44 | 45 | // Returns the amount by which the floating bar should be offset downwards (to 46 | // avoid the menu) and by which the overlay view should be enlarged vertically. 47 | // Generally, this is > 0 when the window is on the primary screen and 0 48 | // otherwise. 49 | - (CGFloat)floatingBarVerticalOffset; 50 | 51 | // Informs the controller that the overlay's frame has changed. The controller 52 | // uses this information to update its tracking areas. 53 | - (void)overlayFrameChanged:(NSRect)frame; 54 | 55 | // Informs the controller that the overlay should be shown/hidden, possibly with 56 | // animation, possibly after a delay (only applicable for the animated case). 57 | - (void)ensureOverlayShownWithAnimation:(BOOL)animate delay:(BOOL)delay; 58 | - (void)ensureOverlayHiddenWithAnimation:(BOOL)animate delay:(BOOL)delay; 59 | 60 | // Cancels any running animation and timers. 61 | - (void)cancelAnimationAndTimers; 62 | 63 | // Gets the current floating bar shown fraction. 64 | - (CGFloat)floatingBarShownFraction; 65 | 66 | // Sets a new current floating bar shown fraction. NOTE: This function has side 67 | // effects, such as modifying the system fullscreen mode (menu bar shown state). 68 | - (void)changeFloatingBarShownFraction:(CGFloat)fraction; 69 | 70 | @end 71 | 72 | // Notification posted when we're about to enter or leave fullscreen. 73 | extern NSString* const kWillEnterFullscreenNotification; 74 | extern NSString* const kWillLeaveFullscreenNotification; -------------------------------------------------------------------------------- /src/Browser Window/CTTabWindowController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | // A class acting as the Objective-C window controller for a window that has 8 | // tabs which can be dragged around. Tabs can be re-arranged within the same 9 | // window or dragged into other CTTabWindowController windows. This class doesn't 10 | // know anything about the actual tab implementation or model, as that is fairly 11 | // application-specific. It only provides an API to be overridden by subclasses 12 | // to fill in the details. 13 | // 14 | // This assumes that there will be a view in the nib, connected to 15 | // |tabContentArea_|, that indicates the content that it switched when switching 16 | // between tabs. It needs to be a regular NSView, not something like an NSBox 17 | // because the CTTabStripController makes certain assumptions about how it can 18 | // swap out subviews. 19 | // 20 | // The tab strip is placed outside the window's content area, overlapping the 21 | // title area and window controls and will be stretched to fill the width 22 | // of the window. 23 | 24 | #import 25 | 26 | @class CTTabStripView; 27 | @class CTTabView; 28 | 29 | @interface CTTabWindowController : NSWindowController 30 | 31 | @property(readonly, nonatomic) CTTabStripView* tabStripView; 32 | @property(readonly, nonatomic) NSView* tabContentArea; 33 | 34 | // Used during tab dragging to turn on/off the overlay window when a tab 35 | // is torn off. If -deferPerformClose (below) is used, -removeOverlay will 36 | // cause the controller to be autoreleased before returning. 37 | - (void)showOverlay; 38 | - (void)removeOverlay; 39 | - (NSWindow*)overlayWindow; 40 | 41 | // Returns YES if it is ok to constrain the window's frame to fit the screen. 42 | - (BOOL)shouldConstrainFrameRect; 43 | 44 | // A collection of methods, stubbed out in this base class, that provide 45 | // the implementation of tab dragging based on whatever model is most 46 | // appropriate. 47 | 48 | // Layout the tabs based on the current ordering of the model. 49 | - (void)layoutTabs; 50 | 51 | // Creates a new window by pulling the given tab out and placing it in 52 | // the new window. Returns the controller for the new window. The size of the 53 | // new window will be the same size as this window. 54 | - (CTTabWindowController*)detachTabToNewWindow:(CTTabView*)tabView; 55 | 56 | // Make room in the tab strip for |tab| at the given x coordinate. Will hide the 57 | // new tab button while there's a placeholder. Subclasses need to call the 58 | // superclass implementation. 59 | - (void)insertPlaceholderForTab:(CTTabView*)tab 60 | frame:(NSRect)frame; 61 | 62 | // Removes the placeholder installed by |-insertPlaceholderForTab:atLocation:| 63 | // and restores the new tab button. Subclasses need to call the superclass 64 | // implementation. 65 | - (void)removePlaceholder; 66 | 67 | // The follow return YES if tab dragging/tab tearing (off the tab strip)/window 68 | // movement is currently allowed. Any number of things can choose to disable it, 69 | // such as pending animations. The default implementations always return YES. 70 | // Subclasses should override as appropriate. 71 | - (BOOL)tabDraggingAllowed; 72 | - (BOOL)tabTearingAllowed; 73 | - (BOOL)windowMovementAllowed; 74 | 75 | // Called when dragging of teared tab in an overlay window occurs 76 | -(void)willStartTearingTab; 77 | -(void)willEndTearingTab; 78 | -(void)didEndTearingTab; 79 | 80 | // Show or hide the new tab button. The button is hidden immediately, but 81 | // waits until the next call to |-layoutTabs| to show it again. 82 | @property(nonatomic, assign) BOOL showsNewTabButton; 83 | 84 | // Enables the content views to be transparent, showing the desktop behind the 85 | // window if set. Also controls how the CTTabStripView draws itself (so that it 86 | // will NOT draw transparently) 87 | @property(nonatomic, assign) BOOL enableTransparentContent; 88 | 89 | // Returns whether or not |tab| can still be fully seen in the tab strip or if 90 | // its current position would cause it be obscured by things such as the edge 91 | // of the window or the window decorations. Returns YES only if the entire tab 92 | // is visible. The default implementation always returns YES. 93 | - (BOOL)isTabFullyVisible:(CTTabView*)tab; 94 | 95 | // Called to check if the receiver can receive dragged tabs from 96 | // source. Return YES if so. The default implementation returns NO. 97 | - (BOOL)canReceiveFrom:(CTTabWindowController*)source; 98 | 99 | // Move a given tab view to the location of the current placeholder. If there is 100 | // no placeholder, it will go at the end. |controller| is the window controller 101 | // of a tab being dropped from a different window. It will be nil if the drag is 102 | // within the window, otherwise the tab is removed from that window before being 103 | // placed into this one. The implementation will call |-removePlaceholder| since 104 | // the drag is now complete. This also calls |-layoutTabs| internally so 105 | // clients do not need to call it again. 106 | - (void)moveTabView:(NSView*)view 107 | fromController:(CTTabWindowController*)controller; 108 | 109 | // Number of tabs in the tab strip. Useful, for example, to know if we're 110 | // dragging the only tab in the window. This includes pinned tabs (both live 111 | // and not). 112 | - (NSInteger)numberOfTabs; 113 | 114 | // YES if there are tabs in the tab strip which have content, allowing for 115 | // the notion of tabs in the tab strip that are placeholders, but 116 | // currently have no content. 117 | - (BOOL)hasLiveTabs; 118 | 119 | // Return the view of the active tab. 120 | - (NSView *)activeTabView; 121 | 122 | // The title of the active tab. 123 | - (NSString*)activeTabTitle; 124 | 125 | // Called to check whether or not this controller's window has a tab strip (YES 126 | // if it does, NO otherwise). The default implementation returns YES. 127 | - (BOOL)hasTabStrip; 128 | 129 | // Get/set whether a particular tab is draggable between windows. 130 | - (BOOL)isTabDraggable:(NSView*)tabView; 131 | - (void)setTab:(NSView*)tabView isDraggable:(BOOL)draggable; 132 | 133 | // Tell the window that it needs to call performClose: as soon as the current 134 | // drag is complete. This prevents a window (and its overlay) from going away 135 | // during a drag. 136 | - (void)deferPerformClose; 137 | 138 | @end 139 | 140 | @interface CTTabWindowController(ProtectedMethods) 141 | // Tells the tab strip to forget about this tab in preparation for it being 142 | // put into a different tab strip, such as during a drop on another window. 143 | - (void)detachTabView:(NSView*)view; 144 | 145 | // Called when the size of the window content area has changed. Override to 146 | // position specific views. Base class implementation does nothing. 147 | - (void)layoutSubviews; 148 | @end 149 | -------------------------------------------------------------------------------- /src/Buttons/HoverButton.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import 6 | 7 | typedef enum { 8 | kHoverStateNone = 0, 9 | kHoverStateMouseOver = 1, 10 | kHoverStateMouseDown = 2 11 | } HoverState; 12 | 13 | // A button that changes when you hover over it and click it. 14 | @interface HoverButton : NSButton { 15 | @protected 16 | // Enumeration of the hover states that the close button can be in at any one 17 | // time. The button cannot be in more than one hover state at a time. 18 | HoverState hoverState_; 19 | } 20 | 21 | // Enables or disables the |NSTrackingRect|s for the button. 22 | - (void)setTrackingEnabled:(BOOL)enabled; 23 | 24 | // Checks to see whether the mouse is in the button's bounds and update 25 | // the image in case it gets out of sync. This occurs to the close button 26 | // when you close a tab so the tab to the left of it takes its place, and 27 | // drag the button without moving the mouse before you press the button down. 28 | - (void)checkImageState; 29 | @end 30 | -------------------------------------------------------------------------------- /src/Buttons/HoverButton.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import "HoverButton.h" 6 | 7 | 8 | @implementation HoverButton { 9 | @private 10 | // Tracking area for button mouseover states. 11 | NSTrackingArea* trackingArea_; 12 | } 13 | 14 | - (id)initWithFrame:(NSRect)frameRect { 15 | if ((self = [super initWithFrame:frameRect])) { 16 | [self setTrackingEnabled:YES]; 17 | hoverState_ = kHoverStateNone; 18 | [self updateTrackingAreas]; 19 | } 20 | return self; 21 | } 22 | 23 | - (void)awakeFromNib { 24 | [self setTrackingEnabled:YES]; 25 | hoverState_ = kHoverStateNone; 26 | [self updateTrackingAreas]; 27 | } 28 | 29 | - (void)dealloc { 30 | [self setTrackingEnabled:NO]; 31 | } 32 | 33 | - (void)mouseEntered:(NSEvent*)theEvent { 34 | hoverState_ = kHoverStateMouseOver; 35 | [self setNeedsDisplay:YES]; 36 | } 37 | 38 | - (void)mouseExited:(NSEvent*)theEvent { 39 | hoverState_ = kHoverStateNone; 40 | [self setNeedsDisplay:YES]; 41 | } 42 | 43 | - (void)mouseDown:(NSEvent*)theEvent { 44 | hoverState_ = kHoverStateMouseDown; 45 | [self setNeedsDisplay:YES]; 46 | // The hover button needs to hold onto itself here for a bit. Otherwise, 47 | // it can be freed while |super mouseDown:| is in it's loop, and the 48 | // |checkImageState| call will crash. 49 | // http://crbug.com/28220 50 | // scoped_nsobject myself([self retain]); 51 | if([super respondsToSelector:@selector(mouseDown:)]){ 52 | [super mouseDown:theEvent]; 53 | }else{ 54 | return; 55 | } 56 | 57 | // We need to check the image state after the mouseDown event loop finishes. 58 | // It's possible that we won't get a mouseExited event if the button was 59 | // moved under the mouse during tab resize, instead of the mouse moving over 60 | // the button. 61 | // http://crbug.com/31279 62 | [self checkImageState]; 63 | } 64 | 65 | - (void)setTrackingEnabled:(BOOL)enabled { 66 | if (enabled) { 67 | trackingArea_ = [[NSTrackingArea alloc] initWithRect:[self bounds] 68 | options:NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways 69 | owner:self 70 | userInfo:nil]; 71 | [self addTrackingArea:trackingArea_]; 72 | 73 | // If you have a separate window that overlaps the close button, and you 74 | // move the mouse directly over the close button without entering another 75 | // part of the tab strip, we don't get any mouseEntered event since the 76 | // tracking area was disabled when we entered. 77 | [self checkImageState]; 78 | } else if (trackingArea_) { 79 | [self removeTrackingArea:trackingArea_]; 80 | trackingArea_ = nil; 81 | } 82 | } 83 | 84 | 85 | - (void)updateTrackingAreas { 86 | [super updateTrackingAreas]; 87 | [self checkImageState]; 88 | } 89 | 90 | - (void)checkImageState { 91 | if (!trackingArea_) 92 | return; 93 | 94 | // Update the button's state if the button has moved. 95 | NSPoint mouseLoc = [[self window] mouseLocationOutsideOfEventStream]; 96 | mouseLoc = [self convertPoint:mouseLoc fromView:nil]; 97 | hoverState_ = NSPointInRect(mouseLoc, [self bounds]) ? 98 | kHoverStateMouseOver : kHoverStateNone; 99 | [self setNeedsDisplay:YES]; 100 | } 101 | 102 | @end 103 | -------------------------------------------------------------------------------- /src/Buttons/HoverCloseButton.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import 6 | 7 | #import "HoverButton.h" 8 | 9 | // The standard close button for our Mac UI which is the "x" that changes to a 10 | // dark circle with the "x" when you hover over it. At this time it is used by 11 | // the popup blocker, download bar, info bar and tabs. 12 | @interface HoverCloseButton : HoverButton 13 | // Sets up the button's tracking areas and accessibility info when instantiated 14 | // via initWithFrame or awakeFromNib. 15 | - (void)commonInit; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /src/Buttons/HoverCloseButton.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "HoverCloseButton.h" 6 | //#import "scoped_nsobject.h" 7 | #import "NSBezierPath+MCAdditions.h" 8 | 9 | // Convenience function to return the middle point of the given |rect|. 10 | static NSPoint MidRect(NSRect rect) { 11 | return NSMakePoint(NSMidX(rect), NSMidY(rect)); 12 | } 13 | 14 | const CGFloat kCircleRadiusPercentage = 0.415; 15 | const CGFloat kCircleHoverWhite = 0.565; 16 | const CGFloat kCircleClickWhite = 0.396; 17 | const CGFloat kXShadowAlpha = 0.75; 18 | const CGFloat kXShadowCircleAlpha = 0.1; 19 | 20 | @interface HoverCloseButton(Private) 21 | - (void)setUpDrawingPaths; 22 | @end 23 | 24 | @implementation HoverCloseButton { 25 | // Bezier path for drawing the 'x' within the button. 26 | NSBezierPath* xPath_; 27 | 28 | // Bezier path for drawing the hover state circle behind the 'x'. 29 | NSBezierPath* circlePath_; 30 | } 31 | 32 | - (id)initWithFrame:(NSRect)frameRect { 33 | if ((self = [super initWithFrame:frameRect])) { 34 | [self commonInit]; 35 | } 36 | return self; 37 | } 38 | 39 | - (void)awakeFromNib { 40 | [super awakeFromNib]; 41 | [self commonInit]; 42 | } 43 | 44 | - (void)drawRect:(NSRect)rect { 45 | if (!circlePath_ || !xPath_) 46 | [self setUpDrawingPaths]; 47 | 48 | // If the user is hovering over the button, a light/dark gray circle is drawn 49 | // behind the 'x'. 50 | if (hoverState_ != kHoverStateNone) { 51 | // Adjust the color of the circle depending on whether it is being 52 | // clicked. 53 | CGFloat white = (hoverState_ == kHoverStateMouseOver) ? 54 | kCircleHoverWhite : kCircleClickWhite; 55 | if(white == kCircleHoverWhite){ 56 | [[NSColor colorWithRed:0.82 green:0.50 blue:0.48 alpha:1.0] set]; 57 | }else if(white == kCircleClickWhite){ 58 | [[NSColor colorWithRed:0.77 green:0.46 blue:0.47 alpha:1.0] set]; 59 | } 60 | [circlePath_ fill]; 61 | } 62 | 63 | [[NSColor whiteColor] set]; 64 | [xPath_ fill]; 65 | 66 | // Give the 'x' an inner shadow for depth. If the button is in a hover state 67 | // (circle behind it), then adjust the shadow accordingly (not as harsh). 68 | NSShadow* shadow = [[NSShadow alloc] init]; 69 | CGFloat alpha = (hoverState_ != kHoverStateNone) ? 70 | kXShadowCircleAlpha : kXShadowAlpha; 71 | [shadow setShadowColor:[NSColor colorWithCalibratedWhite:0.15 72 | alpha:alpha]]; 73 | [shadow setShadowOffset:NSMakeSize(0.0, 0.0)]; 74 | [shadow setShadowBlurRadius:2.5]; 75 | [xPath_ fillWithInnerShadow:shadow]; 76 | } 77 | 78 | - (void)commonInit { 79 | // Set accessibility description. 80 | NSString* description = @"Close"; 81 | [[self cell] 82 | accessibilitySetOverrideValue:description 83 | forAttribute:NSAccessibilityDescriptionAttribute]; 84 | } 85 | 86 | - (void)setUpDrawingPaths { 87 | NSPoint viewCenter = MidRect([self bounds]); 88 | 89 | circlePath_ = [NSBezierPath bezierPath]; 90 | [circlePath_ moveToPoint:viewCenter]; 91 | CGFloat radius = kCircleRadiusPercentage * NSWidth([self bounds]); 92 | [circlePath_ appendBezierPathWithArcWithCenter:viewCenter 93 | radius:radius 94 | startAngle:0.0 95 | endAngle:365.0]; 96 | 97 | // Construct an 'x' by drawing two intersecting rectangles in the shape of a 98 | // cross and then rotating the path by 45 degrees. 99 | xPath_ = [NSBezierPath bezierPath]; 100 | [xPath_ appendBezierPathWithRect:NSMakeRect(3.5, 7.0, 9.0, 2.0)]; 101 | [xPath_ appendBezierPathWithRect:NSMakeRect(7.0, 3.5, 2.0, 9.0)]; 102 | 103 | NSPoint pathCenter = MidRect([xPath_ bounds]); 104 | 105 | NSAffineTransform* transform = [NSAffineTransform transform]; 106 | [transform translateXBy:viewCenter.x yBy:viewCenter.y]; 107 | [transform rotateByDegrees:45.0]; 108 | [transform translateXBy:-pathCenter.x yBy:-pathCenter.y]; 109 | 110 | [xPath_ transformUsingAffineTransform:transform]; 111 | } 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /src/Buttons/NewTabButton.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | #pragma once 5 | 6 | #import 7 | 8 | //#import "scoped_nsobject.h" 9 | 10 | // Overrides hit-test behavior to only accept clicks inside the image of the 11 | // button, not just inside the bounding box. This could be abstracted to general 12 | // use, but no other buttons are so irregularly shaped with respect to their 13 | // bounding box. 14 | 15 | @interface NewTabButton : NSButton 16 | // Returns YES if the given point is over the button. |point| is in the 17 | // superview's coordinate system. 18 | - (BOOL)pointIsOverButton:(NSPoint)point; 19 | @end 20 | -------------------------------------------------------------------------------- /src/Buttons/NewTabButton.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "NewTabButton.h" 6 | 7 | @implementation NewTabButton { 8 | NSBezierPath* imagePath_; 9 | } 10 | 11 | // Approximate the shape. It doesn't need to be perfect. This will need to be 12 | // updated if the size or shape of the icon ever changes. 13 | // TODO(pinkerton): use a click mask image instead of hard-coding points. 14 | - (NSBezierPath*)pathForButton { 15 | if (imagePath_) 16 | return imagePath_; 17 | 18 | // Cache the path as it doesn't change (the coordinates are local to this 19 | // view). There's not much point making constants for these, as they are 20 | // custom. 21 | imagePath_ = [NSBezierPath bezierPath]; 22 | [imagePath_ moveToPoint:NSMakePoint(9, 7)]; 23 | [imagePath_ lineToPoint:NSMakePoint(26, 7)]; 24 | [imagePath_ lineToPoint:NSMakePoint(33, 23)]; 25 | [imagePath_ lineToPoint:NSMakePoint(14, 23)]; 26 | [imagePath_ lineToPoint:NSMakePoint(9, 7)]; 27 | return imagePath_; 28 | } 29 | 30 | - (BOOL)pointIsOverButton:(NSPoint)point { 31 | NSPoint localPoint = [self convertPoint:point fromView:[self superview]]; 32 | NSBezierPath* buttonPath = [self pathForButton]; 33 | return [buttonPath containsPoint:localPoint]; 34 | } 35 | 36 | // Override to only accept clicks within the bounds of the defined path, not 37 | // the entire bounding box. |aPoint| is in the superview's coordinate system. 38 | - (NSView*)hitTest:(NSPoint)aPoint { 39 | if ([self pointIsOverButton:aPoint]) 40 | return [super hitTest:aPoint]; 41 | return nil; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /src/Buttons/ToolbarButton.h: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import "HoverButton.h" 4 | // A button that changes images when you hover over it and click it. 5 | 6 | @interface ToolbarButton : HoverButton 7 | 8 | 9 | @end -------------------------------------------------------------------------------- /src/Buttons/ToolbarButton.m: -------------------------------------------------------------------------------- 1 | // 2 | // hover_image_button.m 3 | // chromium-tabs 4 | // 5 | // Created by TYPCN on 2015/9/4. 6 | // 7 | // 8 | 9 | #import "ToolbarButton.h" 10 | 11 | @implementation ToolbarButton 12 | 13 | - (BOOL)wantsUpdateLayer{ 14 | return YES; 15 | } 16 | 17 | - (void)updateLayer{ 18 | CALayer *layer = [super layer]; 19 | 20 | if (hoverState_ == kHoverStateMouseDown) { 21 | [layer setBackgroundColor:[NSColor colorWithRed:0.74 green:0.74 blue:0.74 alpha:1.0].CGColor]; 22 | [layer setBorderColor:[NSColor colorWithRed:0.62 green:0.62 blue:0.62 alpha:1.0].CGColor]; 23 | [layer setBorderWidth:2.0]; 24 | } else if (hoverState_ == kHoverStateMouseOver) { 25 | [layer setBackgroundColor:nil]; 26 | [layer setBorderColor:[NSColor colorWithRed:0.72 green:0.72 blue:0.72 alpha:1.0].CGColor]; 27 | [layer setBorderWidth:2.0]; 28 | 29 | } else { 30 | [layer setBorderWidth:0.0]; 31 | [layer setBackgroundColor:nil]; 32 | } 33 | 34 | [layer setCornerRadius:4.0]; 35 | 36 | } 37 | 38 | - (void)drawRect:(NSRect)rect { 39 | [super setWantsLayer:YES]; 40 | } 41 | @end -------------------------------------------------------------------------------- /src/ChromiumTabs.h: -------------------------------------------------------------------------------- 1 | // ChromiumTabs 2 | 3 | // Describes the |CTBrowser| class which represents one set of tabs (a window). 4 | #import 5 | 6 | // Describes the |CTBrowserWindowController| class which represents a window with 7 | // tabs. It also manages one |CTBrowser| instance (owns the reference). 8 | #import 9 | 10 | // Describes the |CTTabContents| class which represents the contents of a tab, 11 | // including icon, title and state (loading, crashed, etc). 12 | #import 13 | 14 | // Toolbar view and view controller 15 | #import 16 | #import 17 | 18 | // Utilities 19 | #import 20 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | #pragma once 5 | 6 | #import 7 | 8 | #import "CTTabControllerTarget.h" 9 | #import "URLDropTarget.h" 10 | 11 | @class NewTabButton; 12 | @class CTTabContentsController; 13 | @class CTTabView; 14 | @class CTTabStripView; 15 | 16 | @class CTTabContents; 17 | @class CTBrowser; 18 | 19 | @class CTTabStripModel; 20 | 21 | // A class that handles managing the tab strip in a browser window. It uses 22 | // a supporting C++ bridge object to register for notifications from the 23 | // TabStripModel. The Obj-C part of this class handles drag and drop and all 24 | // the other Cocoa-y aspects. 25 | // 26 | // For a full description of the design, see 27 | // http://www.chromium.org/developers/design-documents/tab-strip-mac 28 | @interface CTTabStripController : NSObject 29 | 30 | @property(nonatomic) CGFloat indentForControls; 31 | 32 | // Show or hide the new tab button. The button is hidden immediately, but 33 | // waits until the next call to |-layoutTabs| to show it again. 34 | @property(nonatomic, assign) BOOL showsNewTabButton; 35 | 36 | // Ensure that the new tab button is never shown if set. 37 | @property(nonatomic, assign) BOOL disableNewTabButton; 38 | 39 | // Initialize the controller with a view and browser that contains 40 | // everything else we'll need. |switchView| is the view whose contents get 41 | // "switched" every time the user switches tabs. The children of this view 42 | // will be released, so if you want them to stay around, make sure 43 | // you have retained them. 44 | - (id)initWithView:(CTTabStripView*)view 45 | switchView:(NSView*)switchView 46 | browser:(CTBrowser*)browser; 47 | 48 | // Return the view for the currently active tab. 49 | - (NSView*)activeTabView; 50 | 51 | // Set the frame of the active tab, also updates the internal frame dict. 52 | - (void)setFrameOfActiveTab:(NSRect)frame; 53 | 54 | // Move the given tab at index |from| in this window to the location of the 55 | // current placeholder. 56 | - (void)moveTabFromIndex:(NSInteger)from; 57 | 58 | // Drop a given CTTabContents at the location of the current placeholder. If there 59 | // is no placeholder, it will go at the end. Used when dragging from another 60 | // window when we don't have access to the CTTabContents as part of our strip. 61 | // |frame| is in the coordinate system of the tab strip view and represents 62 | // where the user dropped the new tab so it can be animated into its correct 63 | // location when the tab is added to the model. If the tab was pinned in its 64 | // previous window, setting |pinned| to YES will propagate that state to the 65 | // new window. Mini-tabs are either app or pinned tabs; the app state is stored 66 | // by the |contents|, but the |pinned| state is the caller's responsibility. 67 | - (void)dropTabContents:(CTTabContents*)contents 68 | withFrame:(NSRect)frame 69 | asPinnedTab:(BOOL)pinned; 70 | 71 | // Returns the index of the subview |view|. Returns -1 if not present. Takes 72 | // closing tabs into account such that this index will correctly match the tab 73 | // model. If |view| is in the process of closing, returns -1, as closing tabs 74 | // are no longer in the model. 75 | - (NSInteger)modelIndexForTabView:(NSView*)view; 76 | 77 | // Return the view at a given index. 78 | - (NSView*)viewAtIndex:(NSUInteger)index; 79 | 80 | // Return the number of tab views in the tab strip. It's same as number of tabs 81 | // in the model, except when a tab is closing, which will be counted in views 82 | // count, but no longer in the model. 83 | - (NSUInteger)viewsCount; 84 | 85 | // Set the placeholder for a dragged tab, allowing the |frame| and |strechiness| 86 | // to be specified. This causes this tab to be rendered in an arbitrary position 87 | - (void)insertPlaceholderForTab:(CTTabView*)tab 88 | frame:(NSRect)frame; 89 | 90 | // Returns whether or not |tab| can still be fully seen in the tab strip or if 91 | // its current position would cause it be obscured by things such as the edge 92 | // of the window or the window decorations. Returns YES only if the entire tab 93 | // is visible. 94 | - (BOOL)isTabFullyVisible:(CTTabView*)tab; 95 | 96 | // Force the tabs to rearrange themselves to reflect the current model. 97 | - (void)layoutTabs; 98 | - (void)layoutTabsWithoutAnimation; 99 | 100 | // Are we in rapid (tab) closure mode? I.e., is a full layout deferred (while 101 | // the user closes tabs)? Needed to overcome missing clicks during rapid tab 102 | // closure. 103 | - (BOOL)inRapidClosureMode; 104 | 105 | // Returns YES if the user is allowed to drag tabs on the strip at this moment. 106 | // For example, this returns NO if there are any pending tab close animtations. 107 | - (BOOL)tabDraggingAllowed; 108 | 109 | // Default height for tabs. 110 | + (CGFloat)defaultTabHeight; 111 | 112 | // Default indentation for tabs (see |indentForControls_|). 113 | + (CGFloat)defaultIndentForControls; 114 | 115 | // Returns the (lazily created) window sheet controller of this window. Used 116 | // for the per-tab sheets. 117 | //- (GTMWindowSheetController*)sheetController; 118 | 119 | // Destroys the window sheet controller of this window, if it exists. The sheet 120 | // controller can be recreated by a subsequent call to |-sheetController|. Must 121 | // not be called if any sheets are currently open. 122 | // TODO(viettrungluu): This is temporary code needed to allow sheets to work 123 | // (read: not crash) in fullscreen mode. Once GTMWindowSheetController is 124 | // modified to support moving sheets between windows, this code can go away. 125 | // http://crbug.com/19093. 126 | //- (void)destroySheetController; 127 | 128 | // Returns the currently active CTTabContentsController. 129 | - (CTTabContentsController*)activeTabContentsController; 130 | 131 | // See comments in browser_window_controller.h for documentation about these 132 | // functions. 133 | //- (void)attachConstrainedWindow:(ConstrainedWindowMac*)window; 134 | //- (void)removeConstrainedWindow:(ConstrainedWindowMac*)window; 135 | //- (void)updateDevToolsForContents:(CTTabContents*)contents; 136 | 137 | -(CTTabContentsController*)tabContentsControllerForTabContents:(CTTabContents*)contents; 138 | 139 | @end 140 | 141 | // Notification sent when the number of tabs changes. The object will be this 142 | // controller. 143 | extern NSString* const kTabStripNumberOfTabsChanged; 144 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripDragController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2011 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | @class CTTabController; 10 | @class CTTabStripController; 11 | @class CTTabWindowController; 12 | 13 | //////////////////////////////////////////////////////////////////////////////// 14 | 15 | // This protocol is used to carry mouse events to the TabStripDragController, 16 | // which manages the logic for actually dragging tabs. 17 | @protocol TabDraggingEventTarget 18 | 19 | // Returns YES if the tab represented by the controller can be dragged. 20 | - (BOOL)tabCanBeDragged:(CTTabController*)tab; 21 | 22 | // Initiates a dragging session with a mouseDown event. The tab controller 23 | // passed here is the one used for the rest of the dragging session. 24 | - (void)maybeStartDrag:(NSEvent*)event forTab:(CTTabController*)tab; 25 | 26 | @end 27 | 28 | //////////////////////////////////////////////////////////////////////////////// 29 | 30 | // This controller is owned by the TabStripController and is used to delegate 31 | // all the logic for tab dragging from the TabView's events. 32 | @interface CTTabStripDragController : NSObject { 33 | @private 34 | __weak CTTabStripController* tabStrip_; // Weak; owns this. 35 | 36 | // These are released on mouseUp: 37 | BOOL moveWindowOnDrag_; // Set if the only tab of a window is dragged. 38 | BOOL tabWasDragged_; // Has the tab been dragged? 39 | BOOL draggingWithinTabStrip_; // Did drag stay in the current tab strip? 40 | BOOL chromeIsVisible_; 41 | 42 | NSTimeInterval tearTime_; // Time since tear happened 43 | NSPoint tearOrigin_; // Origin of the tear rect 44 | NSPoint dragOrigin_; // Origin point of the drag 45 | 46 | __weak CTTabWindowController* sourceController_; // weak. controller starting the drag 47 | __weak NSWindow* sourceWindow_; // Weak. The window starting the drag. 48 | NSRect sourceWindowFrame_; 49 | NSRect sourceTabFrame_; 50 | 51 | __weak CTTabController* draggedTab_; // Weak. The tab controller being dragged. 52 | 53 | __weak CTTabWindowController* draggedController_; // Weak. Controller being dragged. 54 | __weak NSWindow* dragWindow_; // Weak. The window being dragged 55 | __weak NSWindow* dragOverlay_; // Weak. The overlay being dragged 56 | 57 | __weak CTTabWindowController* targetController_; // weak. Controller being targeted 58 | } 59 | 60 | // Designated initializer. 61 | - (id)initWithTabStripController:(CTTabStripController*)controller; 62 | 63 | // TabDraggingEventTarget methods are also implemented. 64 | 65 | @end 66 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripModelDelegate.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | @class CTBrowser; 4 | @class CTTabContents; 5 | 6 | // 7 | // CTTabStripModelDelegate 8 | // 9 | // A delegate interface that the CTTabStripModel uses to perform work that it 10 | // can't do itself, such as obtain a container for creating new CTTabContents, 11 | // creating new TabStripModels for detached tabs, etc. 12 | // 13 | // This interface is typically implemented by the controller that instantiates 14 | // the CTTabStripModel (the CTBrowser object). 15 | // 16 | @protocol CTTabStripModelDelegate 17 | // Adds what the delegate considers to be a blank tab to the model. 18 | -(CTTabContents*)addBlankTabInForeground:(BOOL)foreground; 19 | -(CTTabContents*)addBlankTabAtIndex:(int)index inForeground:(BOOL)foreground; 20 | 21 | // Asks for a new TabStripModel to be created and the given tab contents to 22 | // be added to it. Its size and position are reflected in |window_bounds|. 23 | // If |dock_info|'s type is other than NONE, the newly created window should 24 | // be docked as identified by |dock_info|. Returns the CTBrowser object 25 | // representing the newly created window and tab strip. This does not 26 | // show the window, it's up to the caller to do so. 27 | -(CTBrowser*)createNewStripWithContents:(CTTabContents*)contents; 28 | 29 | // Creates a new CTBrowser object and window containing the specified 30 | // |contents|, and continues a drag operation that began within the source 31 | // window's tab strip. |window_bounds| are the bounds of the source window in 32 | // screen coordinates, used to place the new window, and |tab_bounds| are the 33 | // bounds of the dragged Tab view in the source window, in screen coordinates, 34 | // used to place the new Tab in the new window. 35 | -(void)continueDraggingDetachedTab:(CTTabContents*)contents 36 | windowBounds:(const NSRect)windowBounds 37 | tabBounds:(const NSRect)tabBounds; 38 | 39 | // Returns whether some contents can be duplicated. 40 | -(BOOL)canDuplicateContentsAt:(int)index; 41 | 42 | // Duplicates the contents at the provided index and places it into its own 43 | // window. 44 | -(void)duplicateContentsAt:(int)index; 45 | 46 | // Called when a drag session has completed and the frame that initiated the 47 | // the session should be closed. 48 | -(void)closeFrameAfterDragSession; 49 | 50 | // Creates an entry in the historical tab database for the specified 51 | // CTTabContents. 52 | -(void)createHistoricalTab:(CTTabContents*)contents; 53 | 54 | // Runs any unload listeners associated with the specified CTTabContents before 55 | // it is closed. If there are unload listeners that need to be run, this 56 | // function returns true and the TabStripModel will wait before closing the 57 | // CTTabContents. If it returns false, there are no unload listeners and the 58 | // TabStripModel can close the CTTabContents immediately. 59 | -(BOOL)runUnloadListenerBeforeClosing:(CTTabContents*)contents; 60 | 61 | // Returns true if a tab can be restored. 62 | -(BOOL)canRestoreTab; 63 | 64 | // Restores the last closed tab if CanRestoreTab would return true. 65 | -(void)restoreTab; 66 | 67 | // Returns whether some contents can be closed. 68 | -(BOOL)canCloseContentsAt:(int)index; 69 | 70 | // Returns true if any of the tabs can be closed. 71 | -(BOOL)canCloseTab; 72 | 73 | @end // @protocol CTTabStripModelDelegate 74 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripModelOrderController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CTTabStripModelOrderController.h 3 | // chromium-tabs 4 | // 5 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style license that can be 7 | // found in the LICENSE-chromium file. 8 | // 9 | 10 | #import 11 | #import "CTTabStripModel.h" 12 | 13 | @class CTTabContents; 14 | /////////////////////////////////////////////////////////////////////////////// 15 | // CTTabStripModelOrderController 16 | // 17 | // An object that allows different types of ordering and reselection to be 18 | // heuristics plugged into a TabStripModel. 19 | // 20 | @interface CTTabStripModelOrderController : NSObject 21 | 22 | // The insertion policy. Default is INSERT_AFTER. 23 | @property (readwrite, assign) InsertionPolicy insertionPolicy; 24 | 25 | - (id)initWithTabStripModel:(CTTabStripModel *)tabStripModel; 26 | 27 | // Determine where to place a newly opened tab by using the supplied 28 | // transition and foreground flag to figure out how it was opened. 29 | - (int)determineInsertionIndexWithContents:(CTTabContents *)newContents 30 | transition:(CTPageTransition)transition 31 | inForeground:(BOOL)foreground; 32 | 33 | // Returns the index to append tabs at. 34 | - (int)determineInsertionIndexForAppending; 35 | 36 | // Determine where to shift selection after a tab is closed. 37 | - (int)determineNewSelectedIndexAfterClose:(int)removedIndex; 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripModelOrderController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CTTabStripModelOrderController.m 3 | // chromium-tabs 4 | // 5 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 6 | // Use of this source code is governed by a BSD-style license that can be 7 | // found in the LICENSE-chromium file. 8 | // 9 | 10 | #import "CTTabStripModelOrderController.h" 11 | #import "CTTabContents.h" 12 | 13 | @interface CTTabStripModelOrderController (PrivateMethods) 14 | // Returns a valid index to be active after the tab at |removingIndex| is 15 | // closed. If |index| is after |removingIndex|, |index| is adjusted to 16 | // reflect the fact that |removingIndex| is going away. 17 | - (int)getValidIndex:(int)index 18 | afterRemove:(int)removingIndex; 19 | @end 20 | 21 | @implementation CTTabStripModelOrderController { 22 | __weak CTTabStripModel *tabStripModel_; 23 | 24 | InsertionPolicy insertionPolicy_; 25 | } 26 | @synthesize insertionPolicy = insertionPolicy_; 27 | 28 | - (id)initWithTabStripModel:(CTTabStripModel *)tabStripModel { 29 | self = [super init]; 30 | if (self) { 31 | tabStripModel_ = tabStripModel; 32 | insertionPolicy_ = INSERT_AFTER; 33 | } 34 | 35 | return self; 36 | } 37 | 38 | - (void)dealloc { 39 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 40 | } 41 | 42 | - (int)determineInsertionIndexWithContents:(CTTabContents *)newContents 43 | transition:(CTPageTransition)transition 44 | inForeground:(BOOL)foreground { 45 | int tab_count = [tabStripModel_ count]; 46 | if (!tab_count) 47 | return 0; 48 | 49 | // NOTE: TabStripModel enforces that all non-mini-tabs occur after mini-tabs, 50 | // so we don't have to check here too. 51 | if (transition == CTPageTransitionLink && 52 | [tabStripModel_ activeIndex] != -1) { 53 | int delta = (insertionPolicy_ == INSERT_AFTER) ? 1 : 0; 54 | if (foreground) { 55 | // If the page was opened in the foreground by a link click in another 56 | // tab, insert it adjacent to the tab that opened that link. 57 | return [tabStripModel_ activeIndex] + delta; 58 | } 59 | 60 | // Otherwise insert adjacent to opener... 61 | return [tabStripModel_ activeIndex] + delta; 62 | } 63 | // In other cases, such as Ctrl+T, open at the end of the strip. 64 | return [self determineInsertionIndexForAppending]; 65 | } 66 | 67 | - (int)determineInsertionIndexForAppending { 68 | return (insertionPolicy_ == INSERT_AFTER) ? 69 | [tabStripModel_ count] : 0; 70 | } 71 | 72 | - (int)determineNewSelectedIndexAfterClose:(int)removedIndex { 73 | int tab_count = [tabStripModel_ count]; 74 | assert(removedIndex >= 0 && removedIndex < tab_count); 75 | 76 | // if the closing tab has a valid parentOpener tab, return its index 77 | CTTabContents* parentOpener = 78 | [tabStripModel_ tabContentsAtIndex:removedIndex].parentOpener; 79 | if (parentOpener) { 80 | int index = [tabStripModel_ indexOfTabContents:parentOpener]; 81 | if (index != kNoTab) 82 | return [self getValidIndex:index 83 | afterRemove:removedIndex]; 84 | } 85 | 86 | // No opener set, fall through to the default handler... 87 | int activeIndex = [tabStripModel_ activeIndex]; 88 | if (activeIndex >= (tab_count - 1)) 89 | return activeIndex - 1; 90 | return activeIndex; 91 | 92 | // Chromium legacy code keept for documentation purposes 93 | /*NavigationController* parent_opener = 94 | tabStripModel_->GetOpenerOfTabContentsAt(removing_index); 95 | // First see if the index being removed has any "child" tabs. If it does, we 96 | // want to select the first in that child group, not the next tab in the same 97 | // group of the removed tab. 98 | NavigationController* removed_controller = 99 | &tabStripModel_->GetTabContentsAt(removing_index)->controller(); 100 | int index = tabStripModel_->GetIndexOfNextTabContentsOpenedBy( 101 | removed_controller, removing_index, false); 102 | if (index != TabStripModel::kNoTab) 103 | return GetValidIndex(index, removing_index, is_remove); 104 | 105 | if (parent_opener) { 106 | // If the tab was in a group, shift selection to the next tab in the group. 107 | int index = tabStripModel_->GetIndexOfNextTabContentsOpenedBy( 108 | parent_opener, removing_index, false); 109 | if (index != TabStripModel::kNoTab) 110 | return GetValidIndex(index, removing_index, is_remove); 111 | 112 | // If we can't find a subsequent group member, just fall back to the 113 | // parent_opener itself. Note that we use "group" here since opener is 114 | // reset by select operations.. 115 | index = tabStripModel_->GetIndexOfController(parent_opener); 116 | if (index != TabStripModel::kNoTab) 117 | return GetValidIndex(index, removing_index, is_remove); 118 | }*/ 119 | } 120 | 121 | #pragma mark private 122 | /////////////////////////////////////////////////////////////////////////////// 123 | // CTTabStripModelOrderController, private: 124 | 125 | - (int)getValidIndex:(int)index 126 | afterRemove:(int)removingIndex { 127 | if (removingIndex < index) 128 | index = MAX(0, index - 1); 129 | return index; 130 | } 131 | @end 132 | -------------------------------------------------------------------------------- /src/Tab Strip/CTTabStripView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | #import "BackgroundGradientView.h" 10 | #import "URLDropTarget.h" 11 | 12 | @class NewTabButton; 13 | @class URLDropTargetHandler; 14 | 15 | // A view class that handles rendering the tab strip and drops of URLS with 16 | // a positioning locator for drop feedback. 17 | 18 | @interface CTTabStripView : BackgroundGradientView 19 | 20 | @property(weak, nonatomic) IBOutlet NewTabButton* addTabButton; 21 | @property(assign, nonatomic) BOOL dropArrowShown; 22 | @property(assign, nonatomic) NSPoint dropArrowPosition; 23 | @property(assign, nonatomic) BOOL allowGradient; 24 | 25 | @end 26 | 27 | // Protected methods subclasses can override to alter behavior. Clients should 28 | // not call these directly. 29 | @interface CTTabStripView(Protected) 30 | - (void)drawBottomBorder:(NSRect)bounds; 31 | - (BOOL)doubleClickMinimizesWindow; 32 | @end 33 | -------------------------------------------------------------------------------- /src/Tab/CTTabContents.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #import 3 | 4 | @class CTTabStripModel; 5 | @class CTBrowser; 6 | 7 | extern NSString *const CTTabContentsDidCloseNotification; 8 | 9 | // 10 | // Visibility states: 11 | // 12 | // - isVisible: if the tab is visible (on screen). You may implement the 13 | // callbacks in order to enable/disable "background" tasks like 14 | // animations. 15 | // Callbacks: 16 | // - tabDidBecomeVisible 17 | // - tabDidResignVisible 18 | // 19 | // - isActive: if the tab is the active tab in its window. Note that a tab 20 | // can be active withouth being visible (i.e. the window is 21 | // minimized or the app is hidden). If your tabs contain 22 | // user-interactive components, you should save and restore focus 23 | // by sublcassing the callbacks. 24 | // Callbacks: 25 | // - tabDidBecomeActive 26 | // - tabDidResignActive 27 | // 28 | // - isKey: if the tab has the users focus. Only one tab in the application 29 | // can be key at a given time. (Note that the OS will automatically 30 | // restore any focus to user-interactive components.) 31 | // Callbacks: 32 | // - tabDidBecomeKey 33 | // - tabDidResignKey 34 | // 35 | 36 | @interface CTTabContents : NSDocument { 37 | BOOL isApp_; 38 | BOOL isLoading_; 39 | BOOL isWaitingForResponse_; 40 | BOOL isCrashed_; 41 | BOOL isVisible_; 42 | BOOL isActive_; 43 | BOOL isTeared_; // YES while being "teared" (dragged between windows) 44 | BOOL isPinned_; 45 | BOOL isBlocked_; 46 | id delegate_; 47 | unsigned int closedByUserGesture_; // TabStripModel::CloseTypes 48 | NSView *view_; // the actual content 49 | NSString *title_; // title of this tab 50 | NSImage *icon_; // tab icon (nil means no or default icon) 51 | CTBrowser *browser_; 52 | CTTabContents* parentOpener_; // the tab which opened this tab (unless nil) 53 | } 54 | 55 | @property(assign, nonatomic) BOOL isApp; 56 | @property(assign, nonatomic) BOOL isLoading; 57 | @property(assign, nonatomic) BOOL isCrashed; 58 | @property(assign, nonatomic) BOOL isWaitingForResponse; 59 | @property(assign, nonatomic, setter = setVisible:) BOOL isVisible; 60 | @property(assign, nonatomic, setter = setActive:) BOOL isActive; 61 | @property(assign, nonatomic, setter = setTeared:) BOOL isTeared; 62 | @property(retain, nonatomic) id delegate; 63 | @property(assign, nonatomic) unsigned int closedByUserGesture; 64 | @property(retain, nonatomic) IBOutlet NSView *view; 65 | @property(retain, nonatomic) NSString *title; 66 | @property(retain, nonatomic) NSImage *icon; 67 | @property(retain, nonatomic) CTBrowser *browser; 68 | @property(strong, nonatomic) CTTabContents* parentOpener; 69 | 70 | // If this returns YES, special icons like throbbers and "crashed" is 71 | // displayed, even if |icon| is nil. By default this returns YES. 72 | @property(readonly, nonatomic) BOOL hasIcon; 73 | 74 | // Initialize a new CTTabContents object. 75 | // The default implementation does nothing with |baseContents| but subclasses 76 | // can use |baseContents| (the active CTTabContents, if any) to perform 77 | // customized initialization. 78 | -(id)initWithBaseTabContents:(CTTabContents*)baseContents; 79 | 80 | // Called when the tab should be destroyed (involves some finalization). 81 | //-(void)destroy:(CTTabStripModel *)sender; 82 | 83 | #pragma mark Action 84 | 85 | // Selects the tab in it's window and brings the window to front 86 | - (void)makeKeyAndOrderFront:(id)sender; 87 | 88 | // Give first-responder status to view_ if isVisible 89 | - (BOOL)becomeFirstResponder; 90 | 91 | 92 | #pragma mark - 93 | #pragma mark Callbacks 94 | 95 | // Called when this tab may be closing (unless CTBrowser respond no to 96 | // canCloseTab). 97 | -(void)closingOfTabDidStart:(CTTabStripModel *)model; 98 | 99 | // The following three callbacks are meant to be implemented by subclasses: 100 | // Called when this tab was inserted into a browser 101 | - (void)tabDidInsertIntoBrowser:(CTBrowser*)browser 102 | atIndex:(NSInteger)index 103 | inForeground:(BOOL)foreground; 104 | // Called when this tab replaced another tab 105 | - (void)tabReplaced:(CTTabContents*)oldContents 106 | inBrowser:(CTBrowser*)browser 107 | atIndex:(NSInteger)index; 108 | // Called when this tab is about to close 109 | - (void)tabWillCloseInBrowser:(CTBrowser*)browser atIndex:(NSInteger)index; 110 | // Called when this tab was removed from a browser 111 | - (void)tabDidDetachFromBrowser:(CTBrowser*)browser atIndex:(NSInteger)index; 112 | 113 | // The following callbacks called when the tab's visible state changes. If you 114 | // override, be sure and invoke super's implementation. See "Visibility states" 115 | // in the header of this file for details. 116 | 117 | // Called when this tab become visible on screen. This is a good place to resume 118 | // animations. 119 | -(void)tabDidBecomeVisible; 120 | 121 | // Called when this tab is no longer visible on screen. This is a good place to 122 | // pause animations. 123 | -(void)tabDidResignVisible; 124 | 125 | // Called when this tab is about to become the active tab. Followed by a call 126 | // to |tabDidBecomeActive| 127 | -(void)tabWillBecomeActive; 128 | 129 | // Called when this tab is about to resign as the active tab. Followed by a 130 | // call to |tabDidResignActive| 131 | -(void)tabWillResignActive; 132 | 133 | // Called when this tab became the active tab in its window. This does 134 | // neccessarily not mean it's visible (app might be hidden or window might be 135 | // minimized). The default implementation makes our view the first responder, if 136 | // visible. 137 | -(void)tabDidBecomeActive; 138 | 139 | // Called when another tab in our window "stole" the selection. 140 | -(void)tabDidResignActive; 141 | 142 | // Called when this tab is about to being "teared" (when dragging a tab from one 143 | // window to another). 144 | -(void)tabWillBecomeTeared; 145 | 146 | // Called when this tab is teared and is about to "land" into a window. 147 | -(void)tabWillResignTeared; 148 | 149 | // Called when this tab was teared and just landed in a window. The default 150 | // implementation makes our view the first responder, restoring focus. 151 | -(void)tabDidResignTeared; 152 | 153 | // Called when the frame has changed, which isn't too often. 154 | // There are at least two cases when it's called: 155 | // - When the tab's view is first inserted into the view hiearchy 156 | // - When a torn off tab is moves into a window with other dimensions than the 157 | // initial window. 158 | -(void)viewFrameDidChange:(NSRect)newFrame; 159 | 160 | @end 161 | 162 | @protocol TabContentsDelegate 163 | -(BOOL)canReloadContents:(CTTabContents*)contents; 164 | -(BOOL)reload; // should set contents->isLoading_ = YES 165 | @end 166 | 167 | -------------------------------------------------------------------------------- /src/Tab/CTTabContents.m: -------------------------------------------------------------------------------- 1 | #import "CTTabContents.h" 2 | #import "CTTabStripModel.h" 3 | #import "CTBrowser.h" 4 | //#import "KVOChangeScope.hh" 5 | 6 | NSString *const CTTabContentsDidCloseNotification = @"CTTabContentsDidCloseNotification"; 7 | 8 | @implementation CTTabContents 9 | 10 | // Custom @synthesize which invokes [browser_ updateTabStateForContent:self] 11 | // when setting values. 12 | #define _synthRetain(T, setname, getname) \ 13 | - (T)getname { return getname##_; } \ 14 | - (void)set##setname :(T)v { \ 15 | getname##_ = v; \ 16 | if (browser_) [browser_ updateTabStateForContent:self]; \ 17 | } 18 | #define _synthAssign(T, setname, getname) \ 19 | - (T)getname { return getname##_; } \ 20 | - (void)set##setname :(T)v { \ 21 | getname##_ = v; \ 22 | if (browser_) [browser_ updateTabStateForContent:self]; \ 23 | } 24 | 25 | // changing any of these implies [browser_ updateTabStateForContent:self] 26 | 27 | _synthAssign(BOOL, IsLoading, isLoading); 28 | _synthAssign(BOOL, IsWaitingForResponse, isWaitingForResponse); 29 | _synthAssign(BOOL, IsCrashed, isCrashed); 30 | 31 | _synthRetain(NSString*, Title, title); 32 | _synthRetain(NSImage*, Icon, icon); 33 | 34 | //@synthesize isLoading = isLoading_; 35 | //@synthesize isWaitingForResponse = isWaitingForResponse_; 36 | //@synthesize isCrashed = isCrashed_; 37 | //@synthesize title = title_; 38 | //@synthesize icon = icon_; 39 | 40 | @synthesize delegate = delegate_; 41 | @synthesize closedByUserGesture = closedByUserGesture_; 42 | @synthesize view = view_; 43 | @synthesize browser = browser_; 44 | @synthesize isApp = isApp_; 45 | @synthesize isActive = isActive_; 46 | @synthesize isTeared = isTeared_; 47 | @synthesize isVisible = isVisible_; 48 | 49 | #undef _synth 50 | 51 | 52 | // KVO support 53 | + (BOOL)automaticallyNotifiesObserversForKey:(NSString*)key { 54 | if ([key isEqualToString:@"isLoading"] || 55 | [key isEqualToString:@"isWaitingForResponse"] || 56 | [key isEqualToString:@"isCrashed"] || 57 | [key isEqualToString:@"isVisible"] || 58 | [key isEqualToString:@"title"] || 59 | [key isEqualToString:@"icon"] || 60 | [key isEqualToString:@"parentOpener"] || 61 | [key isEqualToString:@"isActive"] || 62 | [key isEqualToString:@"isTeared"]) { 63 | return YES; 64 | } 65 | return [super automaticallyNotifiesObserversForKey:key]; 66 | } 67 | 68 | 69 | -(id)initWithBaseTabContents:(CTTabContents*)baseContents { 70 | // subclasses should probably override this 71 | self.parentOpener = baseContents; 72 | return [super init]; 73 | } 74 | 75 | #pragma mark Properties impl. 76 | 77 | -(BOOL)hasIcon { 78 | return YES; 79 | } 80 | 81 | - (CTTabContents*)parentOpener { 82 | return parentOpener_; 83 | } 84 | 85 | - (void)setParentOpener:(CTTabContents*)parentOpener { 86 | NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 87 | if (parentOpener_) { 88 | [nc removeObserver:self 89 | name:CTTabContentsDidCloseNotification 90 | object:parentOpener_]; 91 | } 92 | [self willChangeValueForKey:@"parentOpener"]; 93 | parentOpener_ = parentOpener; 94 | [self didChangeValueForKey:@"parentOpener"]; 95 | if (parentOpener_) { 96 | [nc addObserver:self 97 | selector:@selector(tabContentsDidClose:) 98 | name:CTTabContentsDidCloseNotification 99 | object:parentOpener_]; 100 | } 101 | } 102 | 103 | - (void)tabContentsDidClose:(NSNotification*)notification { 104 | // detach (NULLify) our parentOpener_ when it closes 105 | CTTabContents* tabContents = [notification object]; 106 | if (tabContents == parentOpener_) { 107 | parentOpener_ = nil; 108 | } 109 | } 110 | 111 | - (void)setVisible:(BOOL)visible { 112 | if (isVisible_ != visible && !isTeared_) { 113 | isVisible_ = visible; 114 | if (isVisible_) { 115 | [self tabDidBecomeVisible]; 116 | } else { 117 | [self tabDidResignVisible]; 118 | } 119 | } 120 | } 121 | 122 | - (void)setActive:(BOOL)active { 123 | if (isActive_ != active && !isTeared_) { 124 | isActive_ = active; 125 | if (isActive_) { 126 | [self tabDidBecomeActive]; 127 | } else { 128 | [self tabDidResignActive]; 129 | } 130 | } 131 | } 132 | 133 | - (void)setTeared:(BOOL)teared { 134 | if (isTeared_ != teared) { 135 | isTeared_ = teared; 136 | if (isTeared_) { 137 | [self tabWillBecomeTeared]; 138 | } else { 139 | [self tabWillResignTeared]; 140 | [self tabDidBecomeActive]; 141 | } 142 | } 143 | } 144 | 145 | #pragma mark Actions 146 | 147 | - (void)makeKeyAndOrderFront:(id)sender { 148 | if (browser_) { 149 | NSWindow *window = browser_.window; 150 | if (window) 151 | [window makeKeyAndOrderFront:sender]; 152 | int index = [browser_ indexOfTabContents:self]; 153 | assert(index > -1); // we should exist in browser 154 | [browser_ selectTabAtIndex:index]; 155 | } 156 | } 157 | 158 | 159 | - (BOOL)becomeFirstResponder { 160 | if (isVisible_) { 161 | return [[view_ window] makeFirstResponder:view_]; 162 | } 163 | return NO; 164 | } 165 | 166 | 167 | #pragma mark Callbacks 168 | 169 | -(void)closingOfTabDidStart:(CTTabStripModel *)closeInitiatedByTabStripModel { 170 | NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; 171 | [nc postNotificationName:CTTabContentsDidCloseNotification object:self]; 172 | } 173 | 174 | // Called when this tab was inserted into a browser 175 | - (void)tabDidInsertIntoBrowser:(CTBrowser*)browser 176 | atIndex:(NSInteger)index 177 | inForeground:(BOOL)foreground { 178 | self.browser = browser; 179 | } 180 | 181 | // Called when this tab replaced another tab 182 | - (void)tabReplaced:(CTTabContents*)oldContents 183 | inBrowser:(CTBrowser*)browser 184 | atIndex:(NSInteger)index { 185 | 186 | // If there's only one, then make sure we assign 187 | // that same browser before nilling it out in 188 | // the other tab so no GC will kick in 189 | self.browser = browser; 190 | oldContents.browser = nil; 191 | } 192 | 193 | // Called when this tab is about to close 194 | - (void)tabWillCloseInBrowser:(CTBrowser*)browser atIndex:(NSInteger)index { 195 | self.browser = nil; 196 | } 197 | 198 | // Called when this tab was removed from a browser. Will be followed by a 199 | // |tabDidInsertIntoBrowser:atIndex:inForeground:|. 200 | - (void)tabDidDetachFromBrowser:(CTBrowser*)browser atIndex:(NSInteger)index { 201 | self.browser = nil; 202 | } 203 | 204 | -(void)tabWillBecomeActive {} 205 | -(void)tabWillResignActive {} 206 | 207 | -(void)tabDidBecomeActive { 208 | [self becomeFirstResponder]; 209 | } 210 | 211 | -(void)tabDidResignActive {} 212 | -(void)tabDidBecomeVisible {} 213 | -(void)tabDidResignVisible {} 214 | 215 | -(void)tabWillBecomeTeared { 216 | // Teared tabs should always be visible and active since tearing is invoked 217 | // by the user selecting the tab on screen. 218 | assert(isVisible_); 219 | assert(isActive_); 220 | } 221 | 222 | -(void)tabWillResignTeared { 223 | assert(isVisible_); 224 | assert(isActive_); 225 | } 226 | 227 | // Unlike the above callbacks, this one is explicitly called by 228 | // CTBrowserWindowController 229 | -(void)tabDidResignTeared { 230 | [[view_ window] makeFirstResponder:view_]; 231 | } 232 | 233 | -(void)viewFrameDidChange:(NSRect)newFrame { 234 | [view_ setFrame:newFrame]; 235 | } 236 | 237 | @end 238 | -------------------------------------------------------------------------------- /src/Tab/CTTabContentsController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | @class CTTabContents; 10 | 11 | // A class that controls the contents of a tab. It manages displaying the native 12 | // view for a given CTTabContents in |contentsContainer_|. 13 | // Note that just creating the class does not display the view in 14 | // |contentsContainer_|. We defer inserting it until the box is the correct size 15 | // to avoid multiple resize messages to the renderer. You must call 16 | // |-ensureContentsVisible| to display the render widget host view. 17 | 18 | @interface CTTabContentsController : NSViewController 19 | 20 | // Create the contents of a tab represented by |contents| and loaded from the 21 | // nib given by |name|. 22 | - (id)initWithNibName:(NSString*)name 23 | bundle:(NSBundle*)bundle 24 | contents:(CTTabContents*)contents; 25 | 26 | // Create the contents of a tab represented by |contents| and loaded from a nib 27 | // called "TabContents". 28 | // 29 | // Will first try to find a nib named "TabContents" in the main bundle. If the 30 | // "TabContents" nib could not be found in the main bulde it is loaded from the 31 | // framework bundle. 32 | // 33 | // If you use a nib with another name you should override the implementation in 34 | // your subclass and delegate the internal initialization to 35 | // initWithNibName:bundle:contents 36 | - (id)initWithContents:(CTTabContents*)contents; 37 | 38 | // Returns YES if the tab represented by this controller is the front-most. 39 | - (BOOL)isCurrentTab; 40 | 41 | // Called when the tab contents is the currently active tab and is about to be 42 | // removed from the view hierarchy. 43 | - (void)willResignActiveTab; 44 | 45 | // Called when the tab contents is about to be put into the view hierarchy as 46 | // the active tab. Handles things such as ensuring the toolbar is correctly 47 | // enabled. 48 | - (void)willBecomeActiveTab; 49 | 50 | // Call when the tab view is properly sized and the render widget host view 51 | // should be put into the view hierarchy. 52 | - (void)ensureContentsVisible; 53 | 54 | // Called when the tab contents is updated in some non-descript way (the 55 | // notification from the model isn't specific). |updatedContents| could reflect 56 | // an entirely new tab contents object. 57 | - (void)tabDidChange:(CTTabContents*)updatedContents; 58 | 59 | // Shows |devToolsContents| in a split view, or removes the bottom view in the 60 | // split viewif |devToolsContents| is NULL. 61 | // TODO(thakis): Either move this to tab_window or move infobar handling to here 62 | // too -- http://crbug.com/31633 . 63 | //- (void)showDevToolsContents:(CTTabContents*)devToolsContents; 64 | 65 | // Returns the height required by devtools and divider, or 0 if no devtools are 66 | // docked to the tab. 67 | //- (CGFloat)devToolsHeight; 68 | 69 | -(BOOL)isControllerForTabContents:(CTTabContents*)contents; 70 | 71 | @end 72 | -------------------------------------------------------------------------------- /src/Tab/CTTabContentsController.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "CTTabContentsController.h" 6 | #import "CTTabContents.h" 7 | #import "CTUtil.h" 8 | 9 | @implementation CTTabContentsController { 10 | __weak CTTabContents* contents_; // weak 11 | 12 | IBOutlet NSSplitView* contentsContainer_; 13 | } 14 | 15 | - (id)initWithContents:(CTTabContents*)contents { 16 | // subclasses might override this to load a different nib 17 | NSBundle *bundle = [CTUtil bundleForResource:@"TabContents" ofType:@"nib"]; 18 | return [self initWithNibName:@"TabContents" bundle:bundle contents:contents]; 19 | } 20 | 21 | - (id)initWithNibName:(NSString*)name 22 | bundle:(NSBundle*)bundle 23 | contents:(CTTabContents*)contents { 24 | if ((self = [super initWithNibName:name bundle:bundle])) { 25 | contents_ = contents; 26 | } 27 | return self; 28 | } 29 | 30 | - (void)dealloc { 31 | // make sure our contents have been removed from the window 32 | [[self view] removeFromSuperview]; 33 | // [super dealloc]; 34 | } 35 | 36 | -(BOOL)isControllerForTabContents:(CTTabContents*)contents 37 | { 38 | return [contents isEqual:contents_]; 39 | } 40 | 41 | // Call when the tab view is properly sized and the render widget host view 42 | // should be put into the view hierarchy. 43 | - (void)ensureContentsVisible { 44 | NSArray* subviews = [contentsContainer_ subviews]; 45 | if ([subviews count] == 0) { 46 | [contentsContainer_ addSubview:contents_.view]; 47 | [contents_ viewFrameDidChange:[contentsContainer_ bounds]]; 48 | } else if ([subviews objectAtIndex:0] != contents_.view) { 49 | NSView *subview = [subviews objectAtIndex:0]; 50 | [contentsContainer_ replaceSubview:subview 51 | with:contents_.view]; 52 | [contents_ viewFrameDidChange:[subview bounds]]; 53 | } 54 | } 55 | 56 | // Returns YES if the tab represented by this controller is the front-most. 57 | - (BOOL)isCurrentTab { 58 | // We're the current tab if we're in the view hierarchy, otherwise some other 59 | // tab is. 60 | return [[self view] superview] ? YES : NO; 61 | } 62 | 63 | - (void)willBecomeActiveTab { 64 | [contents_ tabWillBecomeActive]; 65 | } 66 | 67 | - (void)willResignActiveTab { 68 | [contents_ tabWillResignActive]; 69 | } 70 | 71 | - (void)tabDidChange:(CTTabContents*)updatedContents { 72 | // Calling setContentView: here removes any first responder status 73 | // the view may have, so avoid changing the view hierarchy unless 74 | // the view is different. 75 | if (contents_ != updatedContents) { 76 | updatedContents.isActive = contents_.isActive; 77 | updatedContents.isVisible = contents_.isVisible; 78 | //updatedContents.isKey = contents_.isKey; 79 | contents_ = updatedContents; 80 | [self ensureContentsVisible]; 81 | } 82 | } 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /src/Tab/CTTabController.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #ifndef CHROME_BROWSER_COCOA_TAB_CONTROLLER_H_ 6 | #define CHROME_BROWSER_COCOA_TAB_CONTROLLER_H_ 7 | #pragma once 8 | 9 | #import 10 | #import "CTTabStripDragController.h" 11 | 12 | // The loading/waiting state of the tab. 13 | typedef enum { 14 | CTTabLoadingStateDone, 15 | CTTabLoadingStateLoading, 16 | CTTabLoadingStateWaiting, 17 | CTTabLoadingStateCrashed, 18 | } CTTabLoadingState; 19 | 20 | @class CTTabView; 21 | @protocol CTTabControllerTarget; 22 | 23 | // A class that manages a single tab in the tab strip. Set its target/action 24 | // to be sent a message when the tab is selected by the user clicking. Setting 25 | // the |loading| property to YES visually indicates that this tab is currently 26 | // loading content via a spinner. 27 | // 28 | // The tab has the notion of an "icon view" which can be used to display 29 | // identifying characteristics such as a favicon, or since it's a full-fledged 30 | // view, something with state and animation such as a throbber for illustrating 31 | // progress. The default in the nib is an image view so nothing special is 32 | // required if that's all you need. 33 | 34 | @interface CTTabController : NSViewController 35 | 36 | @property(assign, nonatomic) CTTabLoadingState loadingState; 37 | 38 | @property(assign, nonatomic) SEL action; 39 | @property(assign, nonatomic, setter = setApp:) BOOL isApp; 40 | @property(assign, nonatomic, setter = setMini:) BOOL isMini; 41 | @property(assign, nonatomic, setter = setPinned:) BOOL isPinned; 42 | @property(assign, nonatomic, setter = setActive:) BOOL isActive; 43 | @property(weak, nonatomic) id target; 44 | 45 | // Minimum and maximum allowable tab width. The minimum width does not show 46 | // the icon or the close button. The active tab always has at least a close 47 | // button so it has a different minimum width. 48 | + (CGFloat)minTabWidth; 49 | + (CGFloat)maxTabWidth; 50 | + (CGFloat)minActiveTabWidth; 51 | + (CGFloat)miniTabWidth; 52 | + (CGFloat)appTabWidth; 53 | 54 | // Initialize a new controller. The default implementation will locate a nib 55 | // called "TabView" in the app bundle and if not found there, will use the 56 | // default nib from the framework bundle. If you need to rename the nib or load 57 | // if from somepleace else, you should override this method and then call 58 | // initWithNibName:bundle:. 59 | - (id)init; 60 | 61 | // Does the actual initialization work 62 | - (id)initWithNibName:(NSString*)nibName bundle:(NSBundle*)bundle; 63 | 64 | // The view associated with this controller, pre-casted as a CTTabView 65 | - (CTTabView*)tabView; 66 | 67 | // Closes the associated CTTabView by relaying the message to |target_| to 68 | // perform the close. 69 | - (IBAction)closeTab:(id)sender; 70 | 71 | // Replace the current icon view with the given view. |iconView| will be 72 | // resized to the size of the current icon view. 73 | - (void)setIconView:(NSView*)iconView; 74 | - (NSView*)iconView; 75 | 76 | // Called by the tabs to determine whether we are in rapid (tab) closure mode. 77 | // In this mode, we handle clicks slightly differently due to animation. 78 | // Ideally, tabs would know about their own animation and wouldn't need this. 79 | - (BOOL)inRapidClosureMode; 80 | 81 | // Updates the visibility of certain subviews, such as the icon and close 82 | // button, based on criteria such as the tab's active state and its current 83 | // width. 84 | - (void)updateVisibility; 85 | 86 | // Update the title color to match the tabs current state. 87 | - (void)updateTitleColor; 88 | @end 89 | 90 | @interface CTTabController(TestingAPI) 91 | - (NSString*)toolTip; 92 | - (CGFloat)iconCapacity; 93 | - (BOOL)shouldShowIcon; 94 | - (BOOL)shouldShowCloseButton; 95 | @end // CTTabController(TestingAPI) 96 | 97 | #endif // CHROME_BROWSER_COCOA_TAB_CONTROLLER_H_ 98 | -------------------------------------------------------------------------------- /src/Tab/CTTabControllerTarget.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | @protocol TabDraggingEventTarget; 8 | 9 | // A protocol to be implemented by a CTTabController's target. 10 | @protocol CTTabControllerTarget 11 | - (void)selectTab:(id)sender; 12 | - (void)closeTab:(id)sender; 13 | 14 | // Dispatch context menu commands for the given tab controller. 15 | //- (void)commandDispatch:(TabStripModel::ContextMenuCommand)command 16 | // forController:(CTTabController*)controller; 17 | // Returns YES if the specificed command should be enabled for the given 18 | // controller. 19 | //- (BOOL)isCommandEnabled:(TabStripModel::ContextMenuCommand)command 20 | // forController:(CTTabController*)controller; 21 | 22 | // Returns a weak reference to the controller that manages dragging of tabs. 23 | - (id)dragController; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /src/Tab/CTTabView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #ifndef CHROME_BROWSER_COCOA_TAB_VIEW_H_ 6 | #define CHROME_BROWSER_COCOA_TAB_VIEW_H_ 7 | #pragma once 8 | 9 | #import 10 | #import 11 | 12 | //#import 13 | 14 | //#import "scoped_nsobject.h" 15 | #import "BackgroundGradientView.h" 16 | 17 | // Nomenclature: 18 | // Tabs _glow_ under two different circumstances, when they are _hovered_ (by 19 | // the mouse) and when they are _alerted_ (to show that the tab's title has 20 | // changed). 21 | 22 | // The state of alerting (to show a title change on an inactive, pinned tab). 23 | // This is more complicated than a simple on/off since we want to allow the 24 | // alert glow to go through a full rise-hold-fall cycle to avoid flickering (or 25 | // always holding). 26 | typedef enum { 27 | kAlertNone = 0, // Obj-C initializes to this. 28 | kAlertRising, 29 | kAlertHolding, 30 | kAlertFalling 31 | } AlertState; 32 | 33 | @class CTTabController; 34 | 35 | // A view that handles the event tracking (clicking and dragging) for a tab 36 | // on the tab strip. Relies on an associated CTTabController to provide a 37 | // target/action for selecting the tab. 38 | 39 | @interface CTTabView : BackgroundGradientView 40 | 41 | @property(assign, nonatomic) NSCellStateValue state; 42 | @property(assign, nonatomic) CGFloat hoverAlpha; 43 | @property(assign, nonatomic) CGFloat alertAlpha; 44 | 45 | // Determines if the tab is in the process of animating closed. It may still 46 | // be visible on-screen, but should not respond to/initiate any events. Upon 47 | // setting to NO, clears the target/action of the close button to prevent 48 | // clicks inside it from sending messages. 49 | @property(assign, nonatomic, setter = setClosing:) BOOL isClosing; 50 | 51 | // Returns the inset multiplier used to compute the inset of the top of the tab. 52 | + (CGFloat)insetMultiplier; 53 | 54 | // Enables/Disables tracking regions for the tab. 55 | - (void)setTrackingEnabled:(BOOL)enabled; 56 | 57 | // Begin showing an "alert" glow (shown to call attention to an inactive 58 | // pinned tab whose title changed). 59 | - (void)startAlert; 60 | 61 | // Stop showing the "alert" glow; this won't immediately wipe out any glow, but 62 | // will make it fade away. 63 | - (void)cancelAlert; 64 | 65 | @end 66 | 67 | // The CTTabController |tabController_| is not the only owner of this view. If the 68 | // controller is released before this view, then we could be hanging onto a 69 | // garbage pointer. To prevent this, the CTTabController uses this interface to 70 | // clear the |tabController_| pointer when it is dying. 71 | @interface CTTabView (TabControllerInterface) 72 | - (void)setController:(CTTabController*)controller; 73 | - (CTTabController*)controller; 74 | @end 75 | 76 | #endif // CHROME_BROWSER_COCOA_TAB_VIEW_H_ 77 | -------------------------------------------------------------------------------- /src/Toolbar/CTToolbarController.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "URLDropTarget.h" 3 | 4 | @class CTBrowser; 5 | @class CTTabContents; 6 | 7 | // A controller for the toolbar in the browser window. 8 | // 9 | // This class is meant to be subclassed -- the default implementation will load 10 | // a placeholder/dummy nib. You need to do two things: 11 | // 12 | // 1. Create a new subclass of CTToolbarController. 13 | // 14 | // 2. Copy the Toolbar.xib into your project (or create a new) and modify it as 15 | // needed (add buttons etc). Make sure the "files owner" type matches your 16 | // CTToolbarController subclass. 17 | // 18 | // 3. Implement createToolbarController in your CTBrowser subclass to initialize 19 | // and return a CTToolbarController based on your nib. 20 | // 21 | @interface CTToolbarController : NSViewController 22 | 23 | @property (weak, nonatomic, readonly) CTBrowser *browser; 24 | 25 | - (id)initWithNibName:(NSString*)nibName 26 | bundle:(NSBundle*)bundle 27 | browser:(CTBrowser*)browser; 28 | 29 | // Set the opacity of the divider (the line at the bottom) *if* we have a 30 | // |ToolbarView| (0 means don't show it); no-op otherwise. 31 | - (void)setDividerOpacity:(CGFloat)opacity; 32 | 33 | // Called when the current tab is changing. Subclasses should implement this to 34 | // update the toolbar's state. 35 | - (void)updateToolbarWithContents:(CTTabContents*)contents 36 | shouldRestoreState:(BOOL)shouldRestore; 37 | 38 | // Called by the Window delegate so we can provide a custom field editor if 39 | // needed. 40 | // Note that this may be called for objects unrelated to the toolbar. 41 | // returns nil if we don't want to override the custom field editor for |obj|. 42 | // The default implementation returns nil 43 | - (id)customFieldEditorForObject:(id)obj; 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /src/Toolbar/CTToolbarController.m: -------------------------------------------------------------------------------- 1 | #import "CTToolbarController.h" 2 | #import "CTBrowser.h" 3 | #import "CTToolbarView.h" 4 | #import "CTTabContents.h" 5 | #import "BackgroundGradientView.h" 6 | #import "common.h" 7 | 8 | @interface CTToolbarController (Private) 9 | - (BackgroundGradientView*)backgroundGradientView; 10 | - (void)toolbarFrameChanged; 11 | @end 12 | 13 | @implementation CTToolbarController { 14 | __weak CTBrowser* browser_; // weak, one per window 15 | } 16 | 17 | @synthesize browser = browser_; 18 | 19 | - (id)initWithNibName:(NSString*)nibName 20 | bundle:(NSBundle*)bundle 21 | browser:(CTBrowser*)browser { 22 | self = [self initWithNibName:nibName bundle:bundle]; 23 | assert(self); 24 | browser_ = browser; // weak 25 | return self; 26 | } 27 | 28 | 29 | - (void)updateToolbarWithContents:(CTTabContents*)contents 30 | shouldRestoreState:(BOOL)shouldRestore { 31 | // subclasses should implement this 32 | } 33 | 34 | 35 | - (void)setDividerOpacity:(CGFloat)opacity { 36 | BackgroundGradientView* view = [self backgroundGradientView]; 37 | [view setShowsDivider:(opacity > 0 ? YES : NO)]; 38 | if ([view isKindOfClass:[CTToolbarView class]]) { 39 | CTToolbarView* toolbarView = (CTToolbarView*)view; 40 | [toolbarView setDividerOpacity:opacity]; 41 | } 42 | } 43 | 44 | 45 | // Called after the view is done loading and the outlets have been hooked up. 46 | - (void)awakeFromNib { 47 | } 48 | 49 | #pragma mark - 50 | #pragma mark URLDropTargetController protocol impl 51 | 52 | - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point { 53 | // subclasses should implement this 54 | NOTIMPLEMENTED(); 55 | } 56 | 57 | 58 | - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point { 59 | // Do nothing. 60 | } 61 | 62 | 63 | - (void)hideDropURLsIndicatorInView:(NSView*)view { 64 | // Do nothing. 65 | } 66 | 67 | 68 | - (id)customFieldEditorForObject:(id)obj { 69 | return nil; 70 | } 71 | 72 | 73 | #pragma mark - 74 | #pragma mark Private 75 | 76 | // (Private) Returns the backdrop to the toolbar. 77 | - (BackgroundGradientView*)backgroundGradientView { 78 | // We really do mean |[super view]| see our override of |-view|. 79 | assert([[super view] isKindOfClass:[BackgroundGradientView class]]); 80 | return (BackgroundGradientView*)[super view]; 81 | } 82 | 83 | 84 | @end 85 | -------------------------------------------------------------------------------- /src/Toolbar/CTToolbarView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #pragma once 6 | 7 | #import 8 | #import "BackgroundGradientView.h" 9 | 10 | // A view that handles any special rendering of the toolbar bar. At this time it 11 | // simply draws a gradient and an optional divider at the bottom. 12 | 13 | @interface CTToolbarView : BackgroundGradientView 14 | @property(assign, nonatomic) CGFloat dividerOpacity; 15 | @end 16 | -------------------------------------------------------------------------------- /src/Toolbar/CTToolbarView.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import "CTToolbarView.h" 6 | #import "NSWindow+CTThemed.h" 7 | 8 | @implementation CTToolbarView { 9 | // The opacity of the divider line (at the bottom of the toolbar); used when 10 | // the detached bookmark bar is morphing to the normal bar and vice versa. 11 | CGFloat dividerOpacity_; 12 | } 13 | 14 | @synthesize dividerOpacity = dividerOpacity_; 15 | 16 | // Prevent mouse down events from moving the parent window around. 17 | - (BOOL)mouseDownCanMoveWindow { 18 | return NO; 19 | } 20 | 21 | - (void)drawRect:(NSRect)rect { 22 | // The toolbar's background pattern is phased relative to the tab strip view's 23 | // background pattern. 24 | NSPoint phase = [[self window] themePatternPhase]; 25 | [[NSGraphicsContext currentContext] setPatternPhase:phase]; 26 | [self drawBackground]; 27 | } 28 | 29 | // Override of |-[BackgroundGradientView strokeColor]|; make it respect opacity. 30 | - (NSColor*)strokeColor { 31 | return [[super strokeColor] colorWithAlphaComponent:[self dividerOpacity]]; 32 | } 33 | 34 | - (BOOL)accessibilityIsIgnored { 35 | return NO; 36 | } 37 | 38 | - (id)accessibilityAttributeValue:(NSString*)attribute { 39 | if ([attribute isEqual:NSAccessibilityRoleAttribute]) 40 | return NSAccessibilityToolbarRole; 41 | return [super accessibilityAttributeValue:attribute]; 42 | } 43 | 44 | @end 45 | -------------------------------------------------------------------------------- /src/Utils/CTPageTransition.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "CTPageTransition.h" 6 | #import 7 | 8 | const char* CTPageTransitionCoreString(CTPageTransition type) { 9 | switch (type & CTPageTransitionCoreMask) { 10 | case 0: return "link"; 11 | case 1: return "typed"; 12 | case 2: return "auto_bookmark"; 13 | case 3: return "auto_subframe"; 14 | case 4: return "manual_subframe"; 15 | case 5: return "generated"; 16 | case 6: return "start_page"; 17 | case 7: return "form_submit"; 18 | case 8: return "reload"; 19 | case 9: return "keyword"; 20 | case 10: return "keyword_generated"; 21 | } 22 | return NULL; 23 | } 24 | -------------------------------------------------------------------------------- /src/Utils/CTPageTransition.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #ifndef CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ 6 | #define CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ 7 | #pragma once 8 | 9 | #import 10 | 11 | // Types of transitions between pages. These are stored in the history 12 | // database to separate visits, and are reported by the renderer for page 13 | // navigations. 14 | // 15 | // WARNING: don't change these numbers. They are written directly into the 16 | // history database, so future versions will need the same values to match 17 | // the enums. 18 | // 19 | // A type is made of a core value and a set of qualifiers. A type has one 20 | // core value and 0 or or more qualifiers. 21 | typedef enum { 22 | // User got to this page by clicking a link on another page. 23 | CTPageTransitionLink = 0, 24 | 25 | // User got this page by typing the URL in the URL bar. This should not be 26 | // used for cases where the user selected a choice that didn't look at all 27 | // like a URL; see Generated below. 28 | // 29 | // We also use this for other "explicit" navigation actions. 30 | CTPageTransitionTyped = 1, 31 | 32 | // User got to this page through a suggestion in the UI, for example, 33 | // through the destinations page. 34 | CTPageTransitionAutoBookmark = 2, 35 | 36 | // This is a subframe navigation. This is any content that is automatically 37 | // loaded in a non-toplevel frame. For example, if a page consists of 38 | // several frames containing ads, those ad URLs will have this transition 39 | // type. The user may not even realize the content in these pages is a 40 | // separate frame, so may not care about the URL (see Manual below). 41 | CTPageTransitionAutoSubframe = 3, 42 | 43 | // For subframe navigations that are explicitly requested by the user and 44 | // generate new navigation entries in the back/forward list. These are 45 | // probably more important than frames that were automatically loaded in 46 | // the background because the user probably cares about the fact that this 47 | // link was loaded. 48 | CTPageTransitionManualSubframe = 4, 49 | 50 | // User got to this page by typing in the URL bar and selecting an entry 51 | // that did not look like a URL. For example, a match might have the URL 52 | // of a Google search result page, but appear like "Search Google for ...". 53 | // These are not quite the same as Typed navigations because the user 54 | // didn't type or see the destination URL. 55 | // See also Keyword. 56 | CTPageTransitionGenerated = 5, 57 | 58 | // The page was specified in the command line or is the start page. 59 | CTPageTransitionStartPage = 6, 60 | 61 | // The user filled out values in a form and submitted it. NOTE that in 62 | // some situations submitting a form does not result in this transition 63 | // type. This can happen if the form uses script to submit the contents. 64 | CTPageTransitionFormSubmit = 7, 65 | 66 | // The user "reloaded" the page, either by hitting the reload button or by 67 | // hitting enter in the address bar. NOTE: This is distinct from the 68 | // concept of whether a particular load uses "reload semantics" (i.e. 69 | // bypasses cached data). For this reason, lots of code needs to pass 70 | // around the concept of whether a load should be treated as a "reload" 71 | // separately from their tracking of this transition type, which is mainly 72 | // used for proper scoring for consumers who care about how frequently a 73 | // user typed/visited a particular URL. 74 | // 75 | // SessionRestore and undo tab close use this transition type too. 76 | CTPageTransitionReload = 8, 77 | 78 | // The url was generated from a replaceable keyword other than the default 79 | // search provider. If the user types a keyword (which also applies to 80 | // tab-to-search) in the omnibox this qualifier is applied to the transition 81 | // type of the generated url. TemplateURLModel then may generate an 82 | // additional visit with a transition type of KeywordGenerated against the 83 | // url 'http://' + keyword. For example, if you do a tab-to-search against 84 | // wikipedia the generated url has a transition qualifer of Keyword, and 85 | // TemplateURLModel generates a visit for 'wikipedia.org' with a transition 86 | // type of KeywordGenerated. 87 | CTPageTransitionKeyword = 9, 88 | 89 | // Corresponds to a visit generated for a keyword. See description of 90 | // KEYWORD for more details. 91 | CTPageTransitionKeywordGenerated = 10, 92 | 93 | // ADDING NEW CORE VALUE? Be sure to update the LastCore and CoreMask 94 | // values below. Also update CoreTransitionString(). 95 | CTPageTransitionLastCore = CTPageTransitionKeywordGenerated, 96 | CTPageTransitionCoreMask = 0xFF, 97 | 98 | // Qualifiers 99 | // Any of the core values above can be augmented by one or more qualifiers. 100 | // These qualifiers further define the transition. 101 | 102 | // The beginning of a navigation chain. 103 | CTPageTransitionChainStart = 0x10000000, 104 | 105 | // The last transition in a redirect chain. 106 | CTPageTransitionChainEnd = 0x20000000, 107 | 108 | // Redirects caused by JavaScript or a meta refresh tag on the page. 109 | CTPageTransitionClientRedirect = 0x40000000, 110 | 111 | // Redirects sent from the server by HTTP headers. It might be nice to 112 | // break this out into 2 types in the future, permanent or temporary, if we 113 | // can get that information from WebKit. 114 | CTPageTransitionServerRedirect = 0x80000000, 115 | 116 | // Used to test whether a transition involves a redirect. 117 | CTPageTransitionIsRedirectMask = 0xC0000000, 118 | 119 | // General mask defining the bits used for the qualifiers. 120 | CTPageTransitionQualifierMask = 0xFFFFFF00 121 | 122 | } CTPageTransition; 123 | 124 | 125 | // Simplifies the provided transition by removing any qualifier 126 | inline CTPageTransition CTPageTransitionStripQualifier(CTPageTransition type) { 127 | return (CTPageTransition)(type & ~CTPageTransitionQualifierMask); 128 | } 129 | 130 | inline int CTPageTransitionValidType(CTPageTransition type) { 131 | CTPageTransition t = CTPageTransitionStripQualifier(type); 132 | return !!(t <= CTPageTransitionLastCore); // Boolean 133 | } 134 | 135 | // Returns true if the given transition is a top-level frame transition, or 136 | // false if the transition was for a subframe. Boolean. 137 | inline int CTPageTransitionIsMainFrame(CTPageTransition type) { 138 | CTPageTransition t = CTPageTransitionStripQualifier(type); 139 | return !!(t != CTPageTransitionAutoSubframe && 140 | t != CTPageTransitionManualSubframe); 141 | } 142 | 143 | // Returns whether a transition involves a redirection. Boolean. 144 | inline int CTPageTransitionIsRedirect(CTPageTransition type) { 145 | return (type & CTPageTransitionIsRedirectMask) != 0; 146 | } 147 | 148 | // Return the qualifier 149 | inline int CTPageTransitionGetQualifier(CTPageTransition type) { 150 | return type & CTPageTransitionQualifierMask; 151 | } 152 | 153 | inline CTPageTransition CTPageTransitionFromInt(CTPageTransition type) { 154 | if (!CTPageTransitionValidType(type)) { 155 | // Return a safe default so we don't have corrupt data 156 | return CTPageTransitionLink; 157 | } 158 | return (CTPageTransition)(type); 159 | } 160 | 161 | // Return a string version of the core type values. 162 | const char* CTPageTransitionCoreString(CTPageTransition type); 163 | 164 | 165 | #endif // CHROME_COMMON_PAGE_TRANSITION_TYPES_H__ 166 | -------------------------------------------------------------------------------- /src/Utils/CTUtil.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | // Framework-local utilities 4 | 5 | extern NSBundle *CTFrameworkBundle; 6 | extern NSBundle *CTHostBundle; // main bundle -- the hosts' bundle 7 | 8 | NSString *L10n(NSString *key); 9 | 10 | @interface CTUtil : NSObject 11 | 12 | +(NSBundle *)bundleForResource:(NSString *)name ofType:(NSString *)ext; 13 | +(NSBundle *)bundleForResource:(NSString *)name; // ofType:nil 14 | +(NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /src/Utils/CTUtil.m: -------------------------------------------------------------------------------- 1 | #import "CTUtil.h" 2 | 3 | NSBundle *CTFrameworkBundle = nil; 4 | NSBundle *CTHostBundle = nil; 5 | 6 | NSString *L10n(NSString *key) { 7 | assert(CTFrameworkBundle); 8 | return [CTFrameworkBundle localizedStringForKey:key value:nil table:nil]; 9 | } 10 | 11 | @implementation CTUtil 12 | 13 | + (void)load { 14 | // NSAutoreleasePool* pool = [NSAutoreleasePool new]; 15 | CTFrameworkBundle = [NSBundle bundleForClass:self]; 16 | assert(CTFrameworkBundle); 17 | CTHostBundle = [NSBundle mainBundle]; 18 | assert(CTHostBundle); 19 | // [pool drain]; 20 | } 21 | 22 | +(NSBundle *)bundleForResource:(NSString *)name { 23 | return [self bundleForResource:name ofType:nil]; 24 | } 25 | 26 | +(NSBundle *)bundleForResource:(NSString *)name ofType:(NSString *)ext { 27 | if ([CTHostBundle pathForResource:name ofType:ext]) 28 | return CTHostBundle; 29 | assert([CTFrameworkBundle pathForResource:name ofType:ext]); 30 | return CTFrameworkBundle; 31 | } 32 | 33 | +(NSString *)pathForResource:(NSString *)name ofType:(NSString *)ext { 34 | NSString *path = [CTHostBundle pathForResource:name ofType:ext]; 35 | if (path) 36 | return path; 37 | return [CTFrameworkBundle pathForResource:name ofType:ext]; 38 | } 39 | 40 | @end 41 | -------------------------------------------------------------------------------- /src/Utils/NSImage+CTAdditions.h: -------------------------------------------------------------------------------- 1 | #import 2 | 3 | @interface NSImage (CTAdditions) 4 | +(NSImage*)imageWithPath:(NSString *)path; 5 | +(NSImage*)imageInAppOrCTFrameworkNamed:(NSString*)name; 6 | +(NSImage*)imageInFrameworkNamed:(NSString*)name; 7 | @end 8 | -------------------------------------------------------------------------------- /src/Utils/NSImage+CTAdditions.m: -------------------------------------------------------------------------------- 1 | #import "NSImage+CTAdditions.h" 2 | #import "CTUtil.h" 3 | 4 | @implementation NSImage (CTAdditions) 5 | 6 | +(NSImage*)imageWithPath:(NSString *)path { 7 | return [[NSImage alloc] initWithContentsOfFile:path]; 8 | } 9 | 10 | +(NSImage*)imageInAppOrCTFrameworkNamed:(NSString *)name { 11 | NSBundle *bundle = CTHostBundle; 12 | if (bundle == nil) bundle = [NSBundle mainBundle]; 13 | NSString *path = [bundle pathForImageResource:name]; 14 | if (!path) { 15 | NSBundle *bundle = CTFrameworkBundle; 16 | if (bundle == nil) bundle = [NSBundle bundleForClass:self]; 17 | path = [bundle pathForImageResource:name]; 18 | } 19 | return [self imageWithPath:path]; 20 | } 21 | 22 | +(NSImage*)imageInFrameworkNamed:(NSString *)name { 23 | return [self imageWithPath:[CTFrameworkBundle pathForImageResource:name]]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /src/Utils/NSWindow+CTThemed.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | #pragma once 5 | 6 | #import 7 | 8 | @interface NSWindow (CTThemed) 9 | - (NSPoint)themePatternPhase; 10 | @end 11 | -------------------------------------------------------------------------------- /src/Utils/NSWindow+CTThemed.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import "NSWindow+CTThemed.h" 6 | 7 | @implementation NSWindow (CTThemed) 8 | 9 | - (NSPoint)themePatternPhase { 10 | return NSZeroPoint; 11 | } 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /src/Utils/URLDropTarget.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | #import 8 | #import 9 | 10 | // Protocol for the controller which handles the actual drop data/drop updates. 11 | @protocol URLDropTargetController 12 | 13 | // The given URLs (an |NSArray| of |NSString|s) were dropped in the given view 14 | // at the given point (in that view's coordinates). 15 | - (void)dropURLs:(NSArray*)urls inView:(NSView*)view at:(NSPoint)point; 16 | 17 | // Dragging is in progress over the owner view (at the given point, in view 18 | // coordinates) and any indicator of location -- e.g., an arrow -- should be 19 | // updated/shown. 20 | - (void)indicateDropURLsInView:(NSView*)view at:(NSPoint)point; 21 | 22 | // Dragging is over, and any indicator should be hidden. 23 | - (void)hideDropURLsIndicatorInView:(NSView*)view; 24 | 25 | @end // @protocol URLDropTargetController 26 | 27 | 28 | // Protocol which views that are URL drop targets and use |URLDropTargetHandler| 29 | // must implement. 30 | @protocol URLDropTarget 31 | 32 | // Returns the controller which handles the drop. 33 | - (id)urlDropController; 34 | 35 | // The following, which come from |NSDraggingDestination|, must be implemented 36 | // by calling the |URLDropTargetHandler|'s implementations. 37 | - (NSDragOperation)draggingEntered:(id)sender; 38 | - (NSDragOperation)draggingUpdated:(id)sender; 39 | - (void)draggingExited:(id)sender; 40 | - (BOOL)performDragOperation:(id)sender; 41 | 42 | @end // @protocol URLDropTarget 43 | 44 | // Object which coordinates the dropping of URLs on a given view, sending data 45 | // and updates to a controller. 46 | @interface URLDropTargetHandler : NSObject 47 | // Initialize the given view, which must implement the |URLDropTarget| (below), 48 | // to accept drops of URLs. 49 | - (id)initWithView:(NSView*)view; 50 | 51 | // The owner view should implement the following methods by calling the 52 | // |URLDropTargetHandler|'s version, and leave the others to the default 53 | // implementation provided by |NSView|/|NSWindow|. 54 | - (NSDragOperation)draggingEntered:(id)sender; 55 | - (NSDragOperation)draggingUpdated:(id)sender; 56 | - (void)draggingExited:(id)sender; 57 | - (BOOL)performDragOperation:(id)sender; 58 | 59 | @end // @interface URLDropTargetHandler 60 | -------------------------------------------------------------------------------- /src/Utils/URLDropTarget.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "URLDropTarget.h" 6 | #import "NSPasteboard+Utils.h" 7 | 8 | @interface URLDropTargetHandler(Private) 9 | 10 | // Gets the appropriate drag operation given the |NSDraggingInfo|. 11 | - (NSDragOperation)getDragOperation:(id)sender; 12 | 13 | // Tell the window controller to hide the drop indicator. 14 | - (void)hideIndicator; 15 | 16 | @end // @interface URLDropTargetHandler(Private) 17 | 18 | @implementation URLDropTargetHandler { 19 | __weak NSView* view_; // weak 20 | } 21 | 22 | - (id)initWithView:(NSView*)view { 23 | if ((self = [super init])) { 24 | view_ = view; 25 | [view_ registerForDraggedTypes: 26 | [NSArray arrayWithObjects:kWebURLsWithTitlesPboardType, 27 | NSURLPboardType, 28 | NSStringPboardType, 29 | NSFilenamesPboardType, 30 | nil]]; 31 | } 32 | return self; 33 | } 34 | 35 | // The following four methods implement parts of the |NSDraggingDestination| 36 | // protocol, which the owner should "forward" to its |URLDropTargetHandler| 37 | // (us). 38 | 39 | - (NSDragOperation)draggingEntered:(id)sender { 40 | return [self getDragOperation:sender]; 41 | } 42 | 43 | - (NSDragOperation)draggingUpdated:(id)sender { 44 | NSDragOperation dragOp = [self getDragOperation:sender]; 45 | if (dragOp == NSDragOperationCopy) { 46 | // Just tell the window controller to update the indicator. 47 | NSPoint hoverPoint = [view_ convertPoint:[sender draggingLocation] 48 | fromView:nil]; 49 | [[view_ urlDropController] indicateDropURLsInView:view_ at:hoverPoint]; 50 | } 51 | return dragOp; 52 | } 53 | 54 | - (void)draggingExited:(id)sender { 55 | [self hideIndicator]; 56 | } 57 | 58 | - (BOOL)performDragOperation:(id)sender { 59 | [self hideIndicator]; 60 | 61 | NSPasteboard* pboard = [sender draggingPasteboard]; 62 | if ([pboard containsURLData]) { 63 | NSArray* urls = nil; 64 | NSArray* titles; // discarded 65 | [pboard getURLs:&urls andTitles:&titles convertingFilenames:YES]; 66 | 67 | if ([urls count]) { 68 | // Tell the window controller about the dropped URL(s). 69 | NSPoint dropPoint = 70 | [view_ convertPoint:[sender draggingLocation] fromView:nil]; 71 | [[view_ urlDropController] dropURLs:urls inView:view_ at:dropPoint]; 72 | return YES; 73 | } 74 | } 75 | 76 | return NO; 77 | } 78 | 79 | @end // @implementation URLDropTargetHandler 80 | 81 | @implementation URLDropTargetHandler(Private) 82 | 83 | - (NSDragOperation)getDragOperation:(id)sender { 84 | if (![[sender draggingPasteboard] containsURLData]) 85 | return NSDragOperationNone; 86 | 87 | // Only allow the copy operation. 88 | return [sender draggingSourceOperationMask] & NSDragOperationCopy; 89 | } 90 | 91 | - (void)hideIndicator { 92 | [[view_ urlDropController] hideDropURLsIndicatorInView:view_]; 93 | } 94 | 95 | @end // @implementation URLDropTargetHandler(Private) 96 | -------------------------------------------------------------------------------- /src/Views/BackgroundGradientView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | // A custom view that draws a 'standard' background gradient. 10 | // Base class for other Chromium views. 11 | @interface BackgroundGradientView : NSView 12 | // The color used for the bottom stroke. Public so subclasses can use. 13 | - (NSColor *)strokeColor; 14 | 15 | // Draws the background for this view. Make sure that your patternphase 16 | // is set up correctly in your graphics context before calling. 17 | - (void)drawBackground; 18 | 19 | // Controls whether the bar draws a dividing line at the bottom. 20 | @property(nonatomic, assign) BOOL showsDivider; 21 | @end 22 | -------------------------------------------------------------------------------- /src/Views/BackgroundGradientView.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import "BackgroundGradientView.h" 6 | //#import "chrome/browser/browser_theme_provider.h" 7 | //#import "themed_window.h" 8 | #import "GTMNSColor+Luminance.h" 9 | 10 | #define kToolbarTopOffset 12 11 | #define kToolbarMaxHeight 100 12 | 13 | static NSGradient *_mkGradient(BOOL faded) { 14 | NSColor* base_color = [NSColor colorWithCalibratedWhite:0.2 alpha:1.0]; 15 | NSColor* start_color = 16 | [base_color gtm_colorAdjustedFor:GTMColorationLightHighlight 17 | faded:faded]; 18 | NSColor* mid_color = 19 | [base_color gtm_colorAdjustedFor:GTMColorationLightMidtone 20 | faded:faded]; 21 | NSColor* end_color = 22 | [base_color gtm_colorAdjustedFor:GTMColorationLightShadow 23 | faded:faded]; 24 | NSColor* glow_color = 25 | [base_color gtm_colorAdjustedFor:GTMColorationLightPenumbra 26 | faded:faded]; 27 | return [[NSGradient alloc] initWithColorsAndLocations:start_color, 0.0, 28 | mid_color, 0.5, 29 | end_color, 0.5, 30 | glow_color, 0.5, 31 | nil]; 32 | } 33 | 34 | @implementation BackgroundGradientView { 35 | BOOL showsDivider_; 36 | } 37 | 38 | @synthesize showsDivider = showsDivider_; 39 | 40 | static NSGradient *_gradientFaded = nil; 41 | static NSGradient *_gradientNotFaded = nil; 42 | static NSColor* kDefaultColorToolbarStroke = nil; 43 | static NSColor* kDefaultColorToolbarStrokeInactive = nil; 44 | 45 | + (void)load { 46 | // NSAutoreleasePool* pool = [NSAutoreleasePool new]; 47 | _gradientFaded = _mkGradient(YES); 48 | _gradientNotFaded = _mkGradient(NO); 49 | kDefaultColorToolbarStroke = 50 | [NSColor colorWithCalibratedWhite: 0x67 / 0xff alpha:1.0]; 51 | kDefaultColorToolbarStrokeInactive = 52 | [NSColor colorWithCalibratedWhite: 0x7b / 0xff alpha:1.0]; 53 | // [pool drain]; 54 | } 55 | 56 | - (id)initWithFrame:(NSRect)frameRect { 57 | self = [super initWithFrame:frameRect]; 58 | if (self != nil) { 59 | showsDivider_ = YES; 60 | } 61 | return self; 62 | } 63 | 64 | - (void)awakeFromNib { 65 | showsDivider_ = YES; 66 | } 67 | 68 | - (void)setShowsDivider:(BOOL)show { 69 | showsDivider_ = show; 70 | [self setNeedsDisplay:YES]; 71 | } 72 | 73 | - (void)drawBackground { 74 | NSGradient *gradient = [[self window] isKeyWindow] ? _gradientNotFaded : 75 | _gradientFaded; 76 | CGFloat winHeight = NSHeight([[self window] frame]); 77 | NSPoint startPoint = 78 | [self convertPoint:NSMakePoint(0, winHeight - kToolbarTopOffset) 79 | fromView:nil]; 80 | NSPoint endPoint = 81 | NSMakePoint(0, winHeight - kToolbarTopOffset - kToolbarMaxHeight); 82 | endPoint = [self convertPoint:endPoint fromView:nil]; 83 | 84 | [gradient drawFromPoint:startPoint 85 | toPoint:endPoint 86 | options:(NSGradientDrawsBeforeStartingLocation | 87 | NSGradientDrawsAfterEndingLocation)]; 88 | 89 | if (showsDivider_) { 90 | // Draw bottom stroke 91 | [[self strokeColor] set]; 92 | NSRect borderRect, contentRect; 93 | NSDivideRect([self bounds], &borderRect, &contentRect, 1, NSMinYEdge); 94 | NSRectFillUsingOperation(borderRect, NSCompositeSourceOver); 95 | } 96 | } 97 | 98 | - (NSColor*)strokeColor { 99 | return [[self window] isKeyWindow] ? kDefaultColorToolbarStroke : 100 | kDefaultColorToolbarStrokeInactive; 101 | } 102 | 103 | @end 104 | -------------------------------------------------------------------------------- /src/Views/CTFloatingBarBackingView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | // A custom view that draws the tab strip background for fullscreen windows. 10 | @interface CTFloatingBarBackingView : NSView 11 | @end 12 | -------------------------------------------------------------------------------- /src/Views/CTFloatingBarBackingView.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2010 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #import "CTFloatingBarBackingView.h" 6 | 7 | #import "CTBrowserFrameView.h" 8 | 9 | @implementation CTFloatingBarBackingView 10 | 11 | - (void)drawRect:(NSRect)rect { 12 | NSWindow* window = [self window]; 13 | BOOL isMainWindow = [window isMainWindow]; 14 | 15 | if (isMainWindow) 16 | [[NSColor windowFrameColor] set]; 17 | else 18 | [[NSColor windowBackgroundColor] set]; 19 | NSRectFill(rect); 20 | 21 | // TODO(rohitrao): Don't assume -22 here. 22 | // [CTBrowserFrameView drawWindowThemeInDirtyRect:rect 23 | // forView:self 24 | // bounds:[self bounds] 25 | // offset:NSMakePoint(0, -22) 26 | // forceBlackBackground:YES]; 27 | 28 | } 29 | 30 | // Eat all mouse events (and do *not* pass them on to the next responder!). 31 | - (void)mouseDown:(NSEvent*)event {} 32 | - (void)rightMouseDown:(NSEvent*)event {} 33 | - (void)otherMouseDown:(NSEvent*)event {} 34 | - (void)rightMouseUp:(NSEvent*)event {} 35 | - (void)otherMouseUp:(NSEvent*)event {} 36 | - (void)mouseMoved:(NSEvent*)event {} 37 | - (void)mouseDragged:(NSEvent*)event {} 38 | - (void)rightMouseDragged:(NSEvent*)event {} 39 | - (void)otherMouseDragged:(NSEvent*)event {} 40 | 41 | // Eat this too, except that ... 42 | - (void)mouseUp:(NSEvent*)event { 43 | // a double-click in the blank area should try to minimize, to be consistent 44 | // with double-clicks on the contiguous tab strip area. (It'll fail and beep.) 45 | if ([event clickCount] == 2 && 46 | (![NSWindow respondsToSelector:@selector(_shouldMiniaturizeOnDoubleClick)] || 47 | [NSWindow performSelector:@selector(_shouldMiniaturizeOnDoubleClick)])) 48 | [[self window] performMiniaturize:self]; 49 | } 50 | 51 | @end // @implementation FloatingBarBackingView 52 | -------------------------------------------------------------------------------- /src/Views/FastResizeView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | #pragma once 5 | 6 | #import 7 | 8 | // A Cocoa view that supports an alternate resizing mode, normally used when 9 | // animations are in progress. In normal resizing mode, subviews are sized to 10 | // completely fill this view's bounds. In fast resizing mode, the subviews' 11 | // size is not changed and the subview is clipped to fit, if necessary. Fast 12 | // resize mode is useful when animating a view that normally takes a significant 13 | // amount of time to relayout and redraw when its size is changed. 14 | @interface FastResizeView : NSView 15 | // Turns fast resizing mode on or off, which determines how this view resizes 16 | // its subviews. Turning fast resizing mode off has the effect of immediately 17 | // resizing subviews to fit; callers do not need to explictly call |setFrame:| 18 | // to trigger a resize. 19 | - (void)setFastResizeMode:(BOOL)fastResizeMode; 20 | @end 21 | -------------------------------------------------------------------------------- /src/Views/FastResizeView.m: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #import 6 | #import "FastResizeView.h" 7 | 8 | @interface FastResizeView (PrivateMethods) 9 | // Lays out this views subviews. If fast resize mode is on, does not resize any 10 | // subviews and instead pegs them to the top left. If fast resize mode is off, 11 | // sets the subviews' frame to be equal to this view's bounds. 12 | - (void)layoutSubviews; 13 | @end 14 | 15 | @implementation FastResizeView { 16 | BOOL fastResizeMode_; 17 | } 18 | 19 | - (void)setFastResizeMode:(BOOL)fastResizeMode { 20 | fastResizeMode_ = fastResizeMode; 21 | 22 | // Force a relayout when coming out of fast resize mode. 23 | if (!fastResizeMode_) 24 | [self layoutSubviews]; 25 | } 26 | 27 | - (void)resizeSubviewsWithOldSize:(NSSize)oldSize { 28 | [self layoutSubviews]; 29 | } 30 | 31 | - (void)drawRect:(NSRect)dirtyRect { 32 | // If we are in fast resize mode, our subviews may not completely cover our 33 | // bounds, so we fill with white. If we are not in fast resize mode, we do 34 | // not need to draw anything. 35 | if (fastResizeMode_) { 36 | [[NSColor whiteColor] set]; 37 | NSRectFill(dirtyRect); 38 | } 39 | } 40 | 41 | 42 | @end 43 | 44 | @implementation FastResizeView (PrivateMethods) 45 | - (void)layoutSubviews { 46 | // There should never be more than one subview. There can be zero, if we are 47 | // in the process of switching tabs or closing the window. In those cases, no 48 | // layout is needed. 49 | NSArray* subviews = [self subviews]; 50 | assert([subviews count] <= 1); 51 | if ([subviews count] < 1) 52 | return; 53 | 54 | NSView* subview = [subviews objectAtIndex:0]; 55 | NSRect bounds = [self bounds]; 56 | 57 | if (fastResizeMode_) { 58 | NSRect frame = [subview frame]; 59 | frame.origin.x = 0; 60 | frame.origin.y = NSHeight(bounds) - NSHeight(frame); 61 | [subview setFrame:frame]; 62 | } else { 63 | [subview setFrame:bounds]; 64 | } 65 | } 66 | @end 67 | -------------------------------------------------------------------------------- /src/Views/ThrobberView.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2009 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE-chromium file. 4 | 5 | #pragma once 6 | 7 | #import 8 | 9 | @protocol ThrobberDataDelegate; 10 | 11 | // A class that knows how to draw an animated state to indicate progress. 12 | // Creating the class starts the animation, destroying it stops it. There are 13 | // two types: 14 | // 15 | // - Filmstrip: Draws via a sequence of frames in an image. There is no state 16 | // where the class is frozen on an image and not animating. The image needs to 17 | // be made of squares such that the height divides evenly into the width. 18 | // 19 | // - Toast: Draws an image animating down to the bottom and then another image 20 | // animating up from the bottom. Stops once the animation is complete. 21 | 22 | @interface ThrobberView : NSView 23 | 24 | // Creates a filmstrip view with |frame| and image |image|. 25 | + (id)filmstripThrobberViewWithFrame:(NSRect)frame 26 | image:(NSImage*)image; 27 | 28 | // Creates a toast view with |frame| and specified images. 29 | + (id)toastThrobberViewWithFrame:(NSRect)frame 30 | beforeImage:(NSImage*)beforeImage 31 | afterImage:(NSImage*)afterImage; 32 | 33 | @end 34 | -------------------------------------------------------------------------------- /src/build_config.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the src/chrome/LICENSE file. 4 | 5 | // This file adds defines about the platform we're currently building on. 6 | // Operating System: 7 | // OS_WIN / OS_MACOSX / OS_LINUX / OS_POSIX (MACOSX or LINUX) 8 | // Compiler: 9 | // COMPILER_MSVC / COMPILER_GCC 10 | // Processor: 11 | // ARCH_CPU_X86 / ARCH_CPU_X86_64 / ARCH_CPU_X86_FAMILY (X86 or X86_64) 12 | // ARCH_CPU_32_BITS / ARCH_CPU_64_BITS 13 | 14 | #ifndef BUILD_BUILD_CONFIG_H_ 15 | #define BUILD_BUILD_CONFIG_H_ 16 | 17 | // A set of macros to use for platform detection. 18 | #if defined(__APPLE__) 19 | #define OS_MACOSX 1 20 | #elif defined(__linux__) 21 | #define OS_LINUX 1 22 | // Use TOOLKIT_GTK on linux if TOOLKIT_VIEWS isn't defined. 23 | #if !defined(TOOLKIT_VIEWS) 24 | #define TOOLKIT_GTK 25 | #endif 26 | #elif defined(_WIN32) 27 | #define OS_WIN 1 28 | #define TOOLKIT_VIEWS 1 29 | #elif defined(__FreeBSD__) 30 | #define OS_FREEBSD 1 31 | #define TOOLKIT_GTK 32 | #elif defined(__OpenBSD__) 33 | #define OS_OPENBSD 1 34 | #define TOOLKIT_GTK 35 | #elif defined(__sun) 36 | #define OS_SOLARIS 1 37 | #define TOOLKIT_GTK 38 | #else 39 | #error Please add support for your platform in build/build_config.h 40 | #endif 41 | 42 | // A flag derived from the above flags, used to cover GTK code in 43 | // both TOOLKIT_GTK and TOOLKIT_VIEWS. 44 | #if defined(TOOLKIT_GTK) || (defined(TOOLKIT_VIEWS) && !defined(OS_WIN)) 45 | #define TOOLKIT_USES_GTK 1 46 | #endif 47 | 48 | #if defined(OS_LINUX) || defined(OS_FREEBSD) || defined(OS_OPENBSD) || \ 49 | defined(OS_SOLARIS) 50 | #define USE_NSS 1 // Use NSS for crypto. 51 | #define USE_X11 1 // Use X for graphics. 52 | #endif 53 | 54 | // For access to standard POSIXish features, use OS_POSIX instead of a 55 | // more specific macro. 56 | #if defined(OS_MACOSX) || defined(OS_LINUX) || defined(OS_FREEBSD) || \ 57 | defined(OS_OPENBSD) || defined(OS_SOLARIS) 58 | #define OS_POSIX 1 59 | // Use base::DataPack for name/value pairs. 60 | #define USE_BASE_DATA_PACK 1 61 | #endif 62 | 63 | // Use tcmalloc 64 | #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(NO_TCMALLOC) 65 | #define USE_TCMALLOC 1 66 | #endif 67 | 68 | // Use heapchecker. 69 | #if (defined(OS_WIN) || defined(OS_LINUX)) && !defined(NO_HEAPCHECKER) 70 | #define USE_HEAPCHECKER 1 71 | #endif 72 | 73 | // Compiler detection. 74 | #if defined(__GNUC__) 75 | #define COMPILER_GCC 1 76 | #elif defined(_MSC_VER) 77 | #define COMPILER_MSVC 1 78 | #else 79 | #error Please add support for your compiler in build/build_config.h 80 | #endif 81 | 82 | // Processor architecture detection. For more info on what's defined, see: 83 | // http://msdn.microsoft.com/en-us/library/b0084kay.aspx 84 | // http://www.agner.org/optimize/calling_conventions.pdf 85 | // or with gcc, run: "echo | gcc -E -dM -" 86 | #if defined(_M_X64) || defined(__x86_64__) 87 | #define ARCH_CPU_X86_FAMILY 1 88 | #define ARCH_CPU_X86_64 1 89 | #define ARCH_CPU_64_BITS 1 90 | #elif defined(_M_IX86) || defined(__i386__) 91 | #define ARCH_CPU_X86_FAMILY 1 92 | #define ARCH_CPU_X86 1 93 | #define ARCH_CPU_32_BITS 1 94 | #elif defined(__ARMEL__) 95 | #define ARCH_CPU_ARM_FAMILY 1 96 | #define ARCH_CPU_ARMEL 1 97 | #define ARCH_CPU_32_BITS 1 98 | #define WCHAR_T_IS_UNSIGNED 1 99 | #else 100 | #error Please add support for your architecture in build/build_config.h 101 | #endif 102 | 103 | // Type detection for wchar_t. 104 | #if defined(OS_WIN) 105 | #define WCHAR_T_IS_UTF16 106 | #elif defined(OS_POSIX) && defined(COMPILER_GCC) && \ 107 | defined(__WCHAR_MAX__) && \ 108 | (__WCHAR_MAX__ == 0x7fffffff || __WCHAR_MAX__ == 0xffffffff) 109 | #define WCHAR_T_IS_UTF32 110 | #elif defined(OS_POSIX) && defined(COMPILER_GCC) && \ 111 | defined(__WCHAR_MAX__) && \ 112 | (__WCHAR_MAX__ == 0x7fff || __WCHAR_MAX__ == 0xffff) 113 | // On Posix, we'll detect short wchar_t, but projects aren't guaranteed to 114 | // compile in this mode (in particular, Chrome doesn't). This is intended for 115 | // other projects using base who manage their own dependencies and make sure 116 | // short wchar works for them. 117 | #define WCHAR_T_IS_UTF16 118 | #else 119 | #error Please add support for your compiler in build/build_config.h 120 | #endif 121 | 122 | #endif // BUILD_BUILD_CONFIG_H_ 123 | -------------------------------------------------------------------------------- /src/common.c: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | #import 4 | 5 | /* 6 | * find the last occurrance of find in string 7 | * 8 | * Copyright 1998-2002 University of Illinois Board of Trustees 9 | * Copyright 1998-2002 Mark D. Roth 10 | * All rights reserved. 11 | * 12 | * strrstr.c - strrstr() function for compatibility library 13 | * 14 | * Mark D. Roth 15 | * Campus Information Technologies and Educational Services 16 | * University of Illinois at Urbana-Champaign 17 | */ 18 | const char *common_strrstr(const char *string, const char *find) { 19 | size_t stringlen, findlen; 20 | char *cp; 21 | findlen = strlen(find); 22 | stringlen = strlen(string); 23 | if (findlen > stringlen) 24 | return NULL; 25 | for (cp = (char*)string + stringlen - findlen; cp >= string; cp--) 26 | if (strncmp(cp, find, findlen) == 0) 27 | return cp; 28 | return NULL; 29 | } 30 | // TODO: check if the system have strrstr and use that instead 31 | -------------------------------------------------------------------------------- /src/common.h: -------------------------------------------------------------------------------- 1 | #ifndef COMMON_H_ 2 | #define COMMON_H_ 3 | 4 | // Foundation is nice to have 5 | #ifdef __OBJC__ 6 | #import 7 | #endif 8 | 9 | // Filename macro 10 | #ifndef __FILENAME__ 11 | #define __FILENAME__ ((strrchr(__FILE__, '/') ?: __FILE__ - 1) + 1) 12 | #endif 13 | #define __SRC_FILENAME__ \ 14 | ((common_strrstr(__FILE__, "/src/") ?: __FILE__ - 1) + 1) 15 | 16 | // log info, warning and error message 17 | // DLOG(format[, ...]) -- log a debug message 18 | #if defined(__OBJC__) 19 | #define _LOG(prefixch, fmt, ...) \ 20 | NSLog((NSString*)(CFSTR("%c [%s:%d] " fmt)), prefixch, \ 21 | __SRC_FILENAME__, __LINE__, ##__VA_ARGS__) 22 | #else 23 | #define _LOG(prefixch, fmt, ...) \ 24 | fprintf(stderr, "%c [%s:%d] " fmt, prefixch, \ 25 | __SRC_FILENAME__, __LINE__, ##__VA_ARGS__) 26 | #endif 27 | #ifdef LOG_SILENT 28 | #define ILOG(...) do{}while(0) 29 | #else 30 | #define ILOG(...) _LOG('I', __VA_ARGS__) 31 | #endif 32 | #define WLOG(...) _LOG('W', __VA_ARGS__) 33 | #define ELOG(...) _LOG('E', __VA_ARGS__) 34 | 35 | // Debug/development utilities 36 | #if !defined(NDEBUG) 37 | #ifndef _DEBUG 38 | #define _DEBUG 1 39 | #endif 40 | // shorthand to include and evaluate only for debug builds 41 | #define IFDEBUG(x) do{ x }while(0) 42 | #define DLOG(...) _LOG('D', __VA_ARGS__) 43 | #define DLOG_TRACE() _LOG('T', "%s", __func__) 44 | // log an expression 45 | #ifdef __OBJC__ 46 | // trace " selector" 47 | #define DLOG_TRACE_M() \ 48 | _LOG('T', "%@ %@", self, NSStringFromSelector(_cmd)); 49 | 50 | NSString *VTPG_DDToStringFromTypeAndValue(const char *tc, void *v); 51 | #define DLOG_EXPR(_X_) do{\ 52 | __typeof__(_X_) _Y_ = (_X_);\ 53 | const char * _TYPE_CODE_ = @encode(__typeof__(_X_));\ 54 | NSString *_STR_ = VTPG_DDToStringFromTypeAndValue(_TYPE_CODE_, &_Y_);\ 55 | if(_STR_){\ 56 | NSLog(@"X [%s:%d] %s = %@", __SRC_FILENAME__, __LINE__, #_X_, _STR_);\ 57 | }else{\ 58 | NSLog(@"Unknown _TYPE_CODE_: %s for expression %s in function %s, file %s, line %d",\ 59 | _TYPE_CODE_, #_X_, __func__, __SRC_FILENAME__, __LINE__);\ 60 | }}while(0) 61 | #else // __OBJC__ 62 | #define DLOG_EXPR(_X_) fprintf(stderr, "%s [%d] X [%s:%d] %s = %s\n",\ 63 | __FILENAME__, getpid(), __SRC_FILENAME__, __LINE__, \ 64 | #_X_, "") 65 | // TODO eval expression ---------------^ 66 | #endif // __OBJC__ 67 | #else // !defined(NDEBUG) 68 | #define IFDEBUG(x) do{}while(0) 69 | #define DLOG(...) do{}while(0) 70 | #define DLOG_TRACE() do{}while(0) 71 | #define DLOG_EXPR(...) do{}while(0) 72 | #endif // !defined(NDEBUG) 73 | 74 | // libbase compatible assertion macros 75 | #define DCHECK assert 76 | #define DCHECK_OP(op, val1, val2) assert((val1) op (val2)) 77 | #define DCHECK_EQ(val1, val2) DCHECK_OP(==, val1, val2) 78 | #define DCHECK_NE(val1, val2) DCHECK_OP(!=, val1, val2) 79 | #define DCHECK_LE(val1, val2) DCHECK_OP(<=, val1, val2) 80 | #define DCHECK_LT(val1, val2) DCHECK_OP(< , val1, val2) 81 | #define DCHECK_GE(val1, val2) DCHECK_OP(>=, val1, val2) 82 | #define DCHECK_GT(val1, val2) DCHECK_OP(> , val1, val2) 83 | 84 | // log an error and exit when reaching unimplemented parts 85 | #import 86 | #define NOTIMPLEMENTED() errx(4, "[not implemented] %s (%s:%d)", \ 87 | __PRETTY_FUNCTION__, __SRC_FILENAME__, __LINE__) 88 | 89 | #define NOTREACHED() assert(NO && "Should not have been reached") 90 | 91 | // strrstr 92 | #ifdef __cplusplus 93 | extern "C" { 94 | #endif 95 | const char *common_strrstr(const char *string, const char *find); 96 | #ifdef __cplusplus 97 | } 98 | #endif 99 | 100 | #endif // COMMON_H_ 101 | -------------------------------------------------------------------------------- /src/common.m: -------------------------------------------------------------------------------- 1 | #import "common.h" 2 | // Copyright (c) 2008-2010, Vincent Gable. 3 | // http://vincentgable.com 4 | // 5 | // Use of this code permitted by copyright holder in this statement: 6 | // http://vgable.com/blog/2010/08/19/the-most-useful-objective-c-code-ive- 7 | // ever-written/ 8 | // 9 | // based off 10 | // http://www.dribin.org/dave/blog/archives/2008/09/22/convert_to_nsstring/ 11 | // 12 | static BOOL TypeCodeIsCharArray(const char *typeCode){ 13 | size_t lastCharOffset = strlen(typeCode) - 1; 14 | size_t secondToLastCharOffset = lastCharOffset - 1 ; 15 | 16 | BOOL isCharArray = typeCode[0] == '[' && 17 | typeCode[secondToLastCharOffset] == 'c' && typeCode[lastCharOffset] == ']'; 18 | for(int i = 1; i < secondToLastCharOffset; i++) 19 | isCharArray = isCharArray && isdigit(typeCode[i]); 20 | return isCharArray; 21 | } 22 | 23 | //since BOOL is #defined as a signed char, we treat the value as 24 | //a BOOL if it is exactly YES or NO, and a char otherwise. 25 | static NSString* VTPGStringFromBoolOrCharValue(BOOL boolOrCharvalue) { 26 | if(boolOrCharvalue == YES) 27 | return @"YES"; 28 | if(boolOrCharvalue == NO) 29 | return @"NO"; 30 | return [NSString stringWithFormat:@"'%c'", boolOrCharvalue]; 31 | } 32 | 33 | static NSString *VTPGStringFromFourCharCodeOrUnsignedInt32(FourCharCode fourcc) { 34 | return [NSString stringWithFormat:@"%u ('%c%c%c%c')", 35 | fourcc, 36 | (fourcc >> 24) & 0xFF, 37 | (fourcc >> 16) & 0xFF, 38 | (fourcc >> 8) & 0xFF, 39 | fourcc & 0xFF]; 40 | } 41 | 42 | static NSString *StringFromNSDecimalWithCurrentLocal(NSDecimal dcm) { 43 | return NSDecimalString(&dcm, [NSLocale currentLocale]); 44 | } 45 | 46 | NSString * VTPG_DDToStringFromTypeAndValue(const char * typeCode, void * value) { 47 | #define IF_TYPE_MATCHES_INTERPRET_WITH(typeToMatch,func) \ 48 | if (strcmp(typeCode, @encode(typeToMatch)) == 0) \ 49 | return (func)(*(typeToMatch*)value) 50 | 51 | #if TARGET_OS_IPHONE 52 | IF_TYPE_MATCHES_INTERPRET_WITH(CGPoint,NSStringFromCGPoint); 53 | IF_TYPE_MATCHES_INTERPRET_WITH(CGSize,NSStringFromCGSize); 54 | IF_TYPE_MATCHES_INTERPRET_WITH(CGRect,NSStringFromCGRect); 55 | #else 56 | IF_TYPE_MATCHES_INTERPRET_WITH(NSPoint,NSStringFromPoint); 57 | IF_TYPE_MATCHES_INTERPRET_WITH(NSSize,NSStringFromSize); 58 | IF_TYPE_MATCHES_INTERPRET_WITH(NSRect,NSStringFromRect); 59 | #endif 60 | IF_TYPE_MATCHES_INTERPRET_WITH(NSRange,NSStringFromRange); 61 | IF_TYPE_MATCHES_INTERPRET_WITH(Class,NSStringFromClass); 62 | IF_TYPE_MATCHES_INTERPRET_WITH(SEL,NSStringFromSelector); 63 | IF_TYPE_MATCHES_INTERPRET_WITH(BOOL,VTPGStringFromBoolOrCharValue); 64 | IF_TYPE_MATCHES_INTERPRET_WITH(NSDecimal,StringFromNSDecimalWithCurrentLocal); 65 | 66 | #define IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(typeToMatch,formatString) \ 67 | if (strcmp(typeCode, @encode(typeToMatch)) == 0) \ 68 | return [NSString stringWithFormat:(formatString), (*(typeToMatch*)value)] 69 | 70 | 71 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(CFStringRef,@"%@"); //CFStringRef is toll-free bridged to NSString* 72 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(CFArrayRef,@"%@"); //CFArrayRef is toll-free bridged to NSArray* 73 | IF_TYPE_MATCHES_INTERPRET_WITH(FourCharCode, VTPGStringFromFourCharCodeOrUnsignedInt32); 74 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(long long,@"%lld"); 75 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(unsigned long long,@"%llu"); 76 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(float,@"%f"); 77 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(double,@"%f"); 78 | // IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(id,@"%@"); 79 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(short,@"%hi"); 80 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(unsigned short,@"%hu"); 81 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(int,@"%i"); 82 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(unsigned, @"%u"); 83 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(long,@"%li"); 84 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(long double,@"%Lf"); //WARNING on older versions of OS X, @encode(long double) == @encode(double) 85 | 86 | //C-strings 87 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(char*, @"%s"); 88 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(const char*, @"%s"); 89 | if(TypeCodeIsCharArray(typeCode)) 90 | return [NSString stringWithFormat:@"%s", (char*)value]; 91 | 92 | IF_TYPE_MATCHES_INTERPRET_WITH_FORMAT(void*,@"(void*)%p"); 93 | 94 | //This is a hack to print out CLLocationCoordinate2D, without needing to #import 95 | //A CLLocationCoordinate2D is a struct made up of 2 doubles. 96 | //We detect it by hard-coding the result of @encode(CLLocationCoordinate2D). 97 | //We get at the fields by treating it like an array of doubles, which it is identical to in memory. 98 | if(strcmp(typeCode, "{?=dd}")==0)//@encode(CLLocationCoordinate2D) 99 | return [NSString stringWithFormat:@"{latitude=%g,longitude=%g}",((double*)value)[0],((double*)value)[1]]; 100 | 101 | //we don't know how to convert this typecode into an NSString 102 | return nil; 103 | } -------------------------------------------------------------------------------- /src/prefix.pch: -------------------------------------------------------------------------------- 1 | #ifdef __OBJC__ 2 | //#import 3 | #endif 4 | #import "common.h" 5 | -------------------------------------------------------------------------------- /src/third_party/.gclient: -------------------------------------------------------------------------------- 1 | solutions = [ 2 | { "name" : "chromium-trunk-src", 3 | "url" : "http://src.chromium.org/svn/trunk/src", 4 | "safesync_url": "http://build.chromium.org/buildbot/continuous/mac/LATEST/REVISION", 5 | "custom_deps" : { 6 | "src/app": None, 7 | "src/breakpad": None, 8 | "src/build": None, 9 | "src/chrome": None, 10 | "src/chrome_frame": None, 11 | "src/courgette": None, 12 | "src/gears": None, 13 | "src/gfx": None, 14 | "src/google_update": None, 15 | "src/googleurl": None, 16 | "src/gpu": None, 17 | "src/ipc": None, 18 | "src/jingle": None, 19 | "src/media": None, 20 | "src/native_client": None, 21 | "src/net": None, 22 | "src/o3d": None, 23 | "src/printing": None, 24 | "src/remoting": None, 25 | "src/rlz": None, 26 | "src/sandbox": None, 27 | "src/sdch": None, 28 | "src/site_scons": None, 29 | "src/skia": None, 30 | "src/testing": None, 31 | "src/third_party": None, 32 | "src/tools": None, 33 | "src/v8": None, 34 | "src/views": None, 35 | "src/webkit": None, 36 | "src/xcodebuild": None 37 | }, 38 | }, 39 | ] 40 | -------------------------------------------------------------------------------- /src/third_party/gtm-subset/GTMNSAnimation+Duration.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMNSAnimation+Duration.h 3 | // 4 | // Copyright 2009 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | 20 | #import 21 | 22 | // Given a "normal" duration for an animation, return what it should be based 23 | // on the current system state. For example, holding down the shift and/or 24 | // control keys modifies the normal duration for an animation making it slower. 25 | // Currently only modifies the duration if the current event is masked by 26 | // eventMask and only the control and/or shift modifiers are down. 27 | // The shift modifier is ignored if it is applied to a Tab key down. 28 | // Tab and shift-tab are often used for navigating around UI elements, 29 | // and in the majority of cases slowing down the animations while navigating 30 | // around UI elements is not desired. 31 | NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration, 32 | NSUInteger eventMask); 33 | 34 | // The standard eventmask that you want for the methods in this file. Some apps 35 | // (eg Chrome) may not want to have animations fire on key strokes, so will use 36 | // just NSLeftMouseUpMask instead. 37 | extern const NSUInteger kGTMLeftMouseUpAndKeyDownMask; 38 | 39 | // Categories for changing the duration of an animation based on the current 40 | // event. Right now they track the state of the shift and control keys to slow 41 | // down animations similar to how minimize window animations occur. 42 | @interface NSAnimation (GTMNSAnimationDurationAdditions) 43 | 44 | // Note that using this initializer will set the duration of the animation 45 | // based on the current event when the animation is created. If the animation 46 | // is to be reused, the duration for the event should be reset with 47 | // gtm_setDuration each time the animation is started. 48 | // See notes for GTMModifyDurationBasedOnCurrentState for more info. 49 | - (id)gtm_initWithDuration:(NSTimeInterval)duration 50 | eventMask:(NSUInteger)eventMask 51 | animationCurve:(NSAnimationCurve)animationCurve; 52 | 53 | // Sets the duration by taking the duration passed in and calling 54 | // GTMModifyDurationBasedOnCurrentState to calculate the real duration. 55 | // See notes for GTMModifyDurationBasedOnCurrentState for more info. 56 | - (void)gtm_setDuration:(NSTimeInterval)duration 57 | eventMask:(NSUInteger)eventMask; 58 | @end 59 | 60 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 61 | 62 | #import 63 | 64 | @interface NSAnimationContext (GTMNSAnimationDurationAdditions) 65 | 66 | // Sets the duration by taking the duration passed in and calling 67 | // GTMModifyDurationBasedOnCurrentState to calculate the real duration. 68 | // See notes for GTMModifyDurationBasedOnCurrentState for more info. 69 | - (void)gtm_setDuration:(NSTimeInterval)duration 70 | eventMask:(NSUInteger)eventMask; 71 | @end 72 | 73 | @interface CAAnimation (GTMCAAnimationDurationAdditions) 74 | 75 | // Sets the duration by taking the duration passed in and calling 76 | // GTMModifyDurationBasedOnCurrentState to calculate the real duration. 77 | // See notes for GTMModifyDurationBasedOnCurrentState for more info. 78 | - (void)gtm_setDuration:(CFTimeInterval)duration 79 | eventMask:(NSUInteger)events; 80 | @end 81 | 82 | #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 83 | -------------------------------------------------------------------------------- /src/third_party/gtm-subset/GTMNSAnimation+Duration.m: -------------------------------------------------------------------------------- 1 | // 2 | // GTMNSAnimation+Duration.m 3 | // 4 | // Copyright 2009 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #import "GTMNSAnimation+Duration.h" 20 | 21 | const NSUInteger kGTMLeftMouseUpAndKeyDownMask 22 | = NSLeftMouseUpMask | NSKeyDownMask; 23 | 24 | NSTimeInterval GTMModifyDurationBasedOnCurrentState(NSTimeInterval duration, 25 | NSUInteger eventMask) { 26 | NSEvent *currentEvent = [NSApp currentEvent]; 27 | NSUInteger currentEventMask = NSEventMaskFromType([currentEvent type]); 28 | if (eventMask & currentEventMask) { 29 | NSUInteger modifiers = [currentEvent modifierFlags]; 30 | if (!(modifiers & (NSAlternateKeyMask | 31 | NSCommandKeyMask))) { 32 | if (modifiers & NSShiftKeyMask) { 33 | // 25 is the ascii code generated for a shift-tab (End-of-message) 34 | // The shift modifier is ignored if it is applied to a Tab key down/up. 35 | // Tab and shift-tab are often used for navigating around UI elements, 36 | // and in the majority of cases slowing down the animations while 37 | // navigating around UI elements is not desired. 38 | if ((currentEventMask & (NSKeyDownMask | NSKeyUpMask)) 39 | && !(modifiers & NSControlKeyMask) 40 | && ([[currentEvent characters] length] == 1) 41 | && ([[currentEvent characters] characterAtIndex:0] == 25)) { 42 | duration = duration; 43 | } else { 44 | duration *= 5.0; 45 | } 46 | } 47 | // These are additive, so shift+control returns 10 * duration. 48 | if (modifiers & NSControlKeyMask) { 49 | duration *= 2.0; 50 | } 51 | } 52 | } 53 | return duration; 54 | } 55 | 56 | @implementation NSAnimation (GTMNSAnimationDurationAdditions) 57 | 58 | - (id)gtm_initWithDuration:(NSTimeInterval)duration 59 | eventMask:(NSUInteger)eventMask 60 | animationCurve:(NSAnimationCurve)animationCurve { 61 | return [self initWithDuration:GTMModifyDurationBasedOnCurrentState(duration, 62 | eventMask) 63 | animationCurve:animationCurve]; 64 | } 65 | 66 | - (void)gtm_setDuration:(NSTimeInterval)duration 67 | eventMask:(NSUInteger)eventMask { 68 | [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, 69 | eventMask)]; 70 | } 71 | 72 | @end 73 | 74 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 75 | 76 | @implementation NSAnimationContext (GTMNSAnimationDurationAdditions) 77 | 78 | - (void)gtm_setDuration:(NSTimeInterval)duration 79 | eventMask:(NSUInteger)eventMask { 80 | [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, 81 | eventMask)]; 82 | } 83 | 84 | @end 85 | 86 | @implementation CAAnimation (GTMCAAnimationDurationAdditions) 87 | 88 | - (void)gtm_setDuration:(CFTimeInterval)duration 89 | eventMask:(NSUInteger)eventMask { 90 | [self setDuration:GTMModifyDurationBasedOnCurrentState(duration, 91 | eventMask)]; 92 | } 93 | 94 | @end 95 | 96 | #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 97 | -------------------------------------------------------------------------------- /src/third_party/gtm-subset/GTMNSColor+Luminance.h: -------------------------------------------------------------------------------- 1 | // 2 | // GTMNSColor+Luminance.h 3 | // 4 | // Copyright 2009 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #import 20 | 21 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 22 | 23 | enum { 24 | GTMColorationBaseHighlight, 25 | GTMColorationBaseMidtone, 26 | GTMColorationBaseShadow, 27 | GTMColorationBasePenumbra, 28 | GTMColorationLightHighlight, 29 | GTMColorationLightMidtone, 30 | GTMColorationLightShadow, 31 | GTMColorationLightPenumbra, 32 | GTMColorationDarkHighlight, 33 | GTMColorationDarkMidtone, 34 | GTMColorationDarkShadow, 35 | GTMColorationDarkPenumbra 36 | }; 37 | typedef NSUInteger GTMColorationUse; 38 | 39 | @interface NSColorSpace (GTMNSColorSpaceLuminanceHelpers) 40 | + (NSColorSpace *)gtm_labColorSpace; 41 | @end 42 | 43 | @interface NSColor (GTMLuminanceAdditions) 44 | - (CGFloat)gtm_luminance; 45 | 46 | // Create a color modified by lightening or darkening it (-1.0 to 1.0) 47 | - (NSColor *)gtm_colorByAdjustingLuminance:(CGFloat)luminance; 48 | 49 | // Create a color modified by lightening or darkening it (-1.0 to 1.0) 50 | - (NSColor *)gtm_colorByAdjustingLuminance:(CGFloat)luminance 51 | saturation:(CGFloat)saturation; 52 | 53 | // Returns a color adjusted for a specific usage 54 | - (NSColor *)gtm_colorAdjustedFor:(GTMColorationUse)use; 55 | - (NSColor *)gtm_colorAdjustedFor:(GTMColorationUse)use faded:(BOOL)fade; 56 | 57 | // Returns whether the color is in the dark half of the spectrum 58 | - (BOOL)gtm_isDarkColor; 59 | 60 | // Returns a color that is legible on this color. (Nothing to do with textColor) 61 | - (NSColor *)gtm_legibleTextColor; 62 | @end 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/third_party/gtm-subset/GTMNSColor+Luminance.m: -------------------------------------------------------------------------------- 1 | // 2 | // GTMNSColor+Luminance.m 3 | // 4 | // Copyright 2009 Google Inc. 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 7 | // use this file except in compliance with the License. You may obtain a copy 8 | // of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 14 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 15 | // License for the specific language governing permissions and limitations under 16 | // the License. 17 | // 18 | 19 | #if MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 20 | 21 | #import "GTMNSColor+Luminance.h" 22 | 23 | static const CGFloat kGTMLuminanceDarkCutoff = 0.6; 24 | 25 | @implementation NSColorSpace (GTMNSColorSpaceLuminanceHelpers) 26 | 27 | // TODO(alcor): we may want to keep one of these around for performance reasons 28 | + (NSColorSpace *)gtm_labColorSpace { 29 | // Observer= 2°, Illuminant= D65 30 | // TODO(alcor): these should come from ColorSync 31 | CGFloat whitePoint[3] = {0.95047, 1.0, 1.08883}; 32 | CGFloat blackPoint[3] = {0, 0, 0}; 33 | CGFloat range[4] = {-127, 127, -127, 127}; 34 | CGColorSpaceRef cs = CGColorSpaceCreateLab(whitePoint, blackPoint, range); 35 | NSColorSpace *space = nil; 36 | if (cs) { 37 | space = [[NSColorSpace alloc] initWithCGColorSpace:cs]; 38 | CGColorSpaceRelease(cs); 39 | } 40 | return space; 41 | } 42 | @end 43 | 44 | @implementation NSColor (GTMLuminance) 45 | 46 | - (NSColor *)labColor { 47 | return [self colorUsingColorSpace:[NSColorSpace gtm_labColorSpace]]; 48 | } 49 | 50 | - (CGFloat)gtm_luminance { 51 | CGFloat lab[4]; 52 | lab[0] = 0.0; 53 | [[self labColor] getComponents:lab]; 54 | return lab[0] / 100.0; 55 | } 56 | 57 | - (NSColor *)gtm_colorByAdjustingLuminance:(CGFloat)luminance 58 | saturation:(CGFloat)saturation { 59 | CGFloat lab[4]; 60 | [[self labColor] getComponents:lab]; 61 | lab[0] *= 1.0 + luminance; 62 | // If luminance is greater than 100, we desaturate it so that we don't get 63 | // wild colors coming out of the forumula 64 | if (lab[0] > 100) { 65 | CGFloat clipping = lab[0] - 100; 66 | CGFloat desaturation = (50.0 - clipping) / 50.0; 67 | saturation = MIN(saturation, desaturation); 68 | } 69 | lab[1] *= saturation; 70 | lab[2] *= saturation; 71 | return [NSColor colorWithColorSpace:[NSColorSpace gtm_labColorSpace] 72 | components:lab 73 | count:sizeof(lab) / sizeof(lab[0])]; 74 | } 75 | 76 | - (NSColor *)gtm_colorByAdjustingLuminance:(CGFloat)luminance { 77 | return [self gtm_colorByAdjustingLuminance:luminance saturation:1.0]; 78 | } 79 | 80 | // TODO(alcor): these constants are largely made up, come up with a consistent 81 | // set of values or at least guidelines 82 | - (NSColor *)gtm_colorAdjustedFor:(GTMColorationUse)use { 83 | NSColor *color = nil; 84 | switch (use) { 85 | case GTMColorationBaseHighlight: 86 | color = [self gtm_colorByAdjustingLuminance:0.15]; 87 | break; 88 | case GTMColorationBaseMidtone: 89 | color = self; 90 | break; 91 | case GTMColorationBaseShadow: 92 | color = [self gtm_colorByAdjustingLuminance:-0.15]; 93 | break; 94 | case GTMColorationBasePenumbra: 95 | color = [self gtm_colorByAdjustingLuminance:-0.10]; 96 | break; 97 | case GTMColorationLightHighlight: 98 | color = [self gtm_colorByAdjustingLuminance:0.25]; 99 | color = [color blendedColorWithFraction:0.9 ofColor:[NSColor whiteColor]]; 100 | break; 101 | case GTMColorationLightMidtone: 102 | color = [self blendedColorWithFraction:0.8 ofColor:[NSColor whiteColor]]; 103 | break; 104 | case GTMColorationLightShadow: 105 | color = [self blendedColorWithFraction:0.7 ofColor:[NSColor whiteColor]]; 106 | color = [color gtm_colorByAdjustingLuminance:-0.02]; 107 | break; 108 | case GTMColorationLightPenumbra: 109 | color = [self blendedColorWithFraction:0.8 ofColor:[NSColor whiteColor]]; 110 | color = [color gtm_colorByAdjustingLuminance:-0.01]; 111 | break; 112 | case GTMColorationDarkHighlight: 113 | color = [self gtm_colorByAdjustingLuminance:-0.20]; 114 | break; 115 | case GTMColorationDarkMidtone: 116 | color = [self gtm_colorByAdjustingLuminance:-0.25]; 117 | break; 118 | case GTMColorationDarkShadow: 119 | color = [self gtm_colorByAdjustingLuminance:-0.30 saturation:1.4]; 120 | break; 121 | case GTMColorationDarkPenumbra: 122 | color = [self gtm_colorByAdjustingLuminance:-0.25]; 123 | break; 124 | default: 125 | NSLog(@"%s: Invalid Coloration Use %lld", __FILE__, (long long)use); 126 | color = self; 127 | break; 128 | } 129 | return color; 130 | } 131 | const CGFloat kDefaultFade = 0.3; 132 | 133 | - (NSColor *)gtm_colorAdjustedFor:(GTMColorationUse)use faded:(BOOL)fade { 134 | NSColor *color = [self gtm_colorAdjustedFor:use]; 135 | if (fade) { 136 | CGFloat luminance = [color gtm_luminance]; 137 | color = [color gtm_colorByAdjustingLuminance: 138 | kDefaultFade * (1.0 - luminance) 139 | saturation:kDefaultFade]; 140 | } 141 | return color; 142 | } 143 | 144 | - (BOOL)gtm_isDarkColor { 145 | return [self gtm_luminance] < kGTMLuminanceDarkCutoff; 146 | } 147 | 148 | - (NSColor *)gtm_legibleTextColor { 149 | return [self gtm_isDarkColor] ? [NSColor whiteColor] : [NSColor blackColor]; 150 | } 151 | 152 | @end 153 | #endif // MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_5 154 | -------------------------------------------------------------------------------- /src/third_party/molokocacao/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2008 MolokoCacao 2 | All rights reserved 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted providing that the following conditions 6 | are met: 7 | 1. Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | 2. Redistributions in binary form must reproduce the above copyright 10 | notice, this list of conditions and the following disclaimer in the 11 | documentation and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 14 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 17 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 21 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 22 | IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 23 | POSSIBILITY OF SUCH DAMAGE. 24 | -------------------------------------------------------------------------------- /src/third_party/molokocacao/NSBezierPath+MCAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSBezierPath+MCAdditions.h 3 | // 4 | // Created by Sean Patrick O'Brien on 4/1/08. 5 | // Copyright 2008 MolokoCacao. All rights reserved. 6 | // 7 | #import 8 | 9 | @interface NSBezierPath (MCAdditions) 10 | 11 | + (NSBezierPath*)bezierPathWithCGPath:(CGPathRef)pathRef; 12 | 13 | - (void)fillWithInnerShadow:(NSShadow*)shadow; 14 | - (void)drawBlurWithColor:(NSColor*)color radius:(CGFloat)radius; 15 | 16 | - (void)strokeInside; 17 | - (void)strokeInsideWithinRect:(NSRect)clipRect; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /src/third_party/molokocacao/NSBezierPath+MCAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSBezierPath+MCAdditions.m 3 | // 4 | // Created by Sean Patrick O'Brien on 4/1/08. 5 | // Copyright 2008 MolokoCacao. All rights reserved. 6 | // 7 | 8 | #import "NSBezierPath+MCAdditions.h" 9 | 10 | // remove/comment out this line of you don't want to use undocumented functions 11 | #define MCBEZIER_USE_PRIVATE_FUNCTION 12 | 13 | #ifdef MCBEZIER_USE_PRIVATE_FUNCTION 14 | extern CGPathRef CGContextCopyPath(CGContextRef context); 15 | #endif 16 | 17 | static void CGPathCallback(void *info, const CGPathElement *element) { 18 | NSBezierPath *path = (__bridge_transfer NSBezierPath *)info; 19 | CGPoint *points = element->points; 20 | 21 | switch (element->type) { 22 | case kCGPathElementMoveToPoint: 23 | { 24 | [path moveToPoint:NSMakePoint(points[0].x, points[0].y)]; 25 | break; 26 | } 27 | case kCGPathElementAddLineToPoint: 28 | { 29 | [path lineToPoint:NSMakePoint(points[0].x, points[0].y)]; 30 | break; 31 | } 32 | case kCGPathElementAddQuadCurveToPoint: 33 | { 34 | // NOTE: This is untested. 35 | NSPoint currentPoint = [path currentPoint]; 36 | NSPoint interpolatedPoint = NSMakePoint((currentPoint.x + 2*points[0].x) / 3, (currentPoint.y + 2*points[0].y) / 3); 37 | [path curveToPoint:NSMakePoint(points[1].x, points[1].y) controlPoint1:interpolatedPoint controlPoint2:interpolatedPoint]; 38 | break; 39 | } 40 | case kCGPathElementAddCurveToPoint: 41 | { 42 | [path curveToPoint:NSMakePoint(points[2].x, points[2].y) controlPoint1:NSMakePoint(points[0].x, points[0].y) controlPoint2:NSMakePoint(points[1].x, points[1].y)]; 43 | break; 44 | } 45 | case kCGPathElementCloseSubpath: 46 | { 47 | [path closePath]; 48 | break; 49 | } 50 | } 51 | } 52 | 53 | @implementation NSBezierPath (MCAdditions) 54 | 55 | + (NSBezierPath *)bezierPathWithCGPath:(CGPathRef)pathRef { 56 | NSBezierPath *path = [NSBezierPath bezierPath]; 57 | CGPathApply(pathRef, (__bridge void*)path, CGPathCallback); 58 | 59 | return path; 60 | } 61 | 62 | - (void)fillWithInnerShadow:(NSShadow *)shadow { 63 | [NSGraphicsContext saveGraphicsState]; 64 | 65 | NSSize offset = shadow.shadowOffset; 66 | NSSize originalOffset = offset; 67 | CGFloat radius = shadow.shadowBlurRadius; 68 | NSRect bounds = NSInsetRect(self.bounds, -(ABS(offset.width) + radius), -(ABS(offset.height) + radius)); 69 | offset.height += bounds.size.height; 70 | shadow.shadowOffset = offset; 71 | NSAffineTransform *transform = [NSAffineTransform transform]; 72 | if ([[NSGraphicsContext currentContext] isFlipped]) 73 | [transform translateXBy:0 yBy:bounds.size.height]; 74 | else 75 | [transform translateXBy:0 yBy:-bounds.size.height]; 76 | 77 | NSBezierPath *drawingPath = [NSBezierPath bezierPathWithRect:bounds]; 78 | [drawingPath setWindingRule:NSEvenOddWindingRule]; 79 | [drawingPath appendBezierPath:self]; 80 | [drawingPath transformUsingAffineTransform:transform]; 81 | 82 | [self addClip]; 83 | [shadow set]; 84 | [[NSColor blackColor] set]; 85 | [drawingPath fill]; 86 | 87 | shadow.shadowOffset = originalOffset; 88 | 89 | [NSGraphicsContext restoreGraphicsState]; 90 | } 91 | 92 | - (void)drawBlurWithColor:(NSColor *)color radius:(CGFloat)radius { 93 | NSRect bounds = NSInsetRect(self.bounds, -radius, -radius); 94 | NSShadow *shadow = [[NSShadow alloc] init]; 95 | shadow.shadowOffset = NSMakeSize(0, bounds.size.height); 96 | shadow.shadowBlurRadius = radius; 97 | shadow.shadowColor = color; 98 | NSBezierPath *path = [self copy]; 99 | NSAffineTransform *transform = [NSAffineTransform transform]; 100 | if ([[NSGraphicsContext currentContext] isFlipped]) 101 | [transform translateXBy:0 yBy:bounds.size.height]; 102 | else 103 | [transform translateXBy:0 yBy:-bounds.size.height]; 104 | [path transformUsingAffineTransform:transform]; 105 | 106 | [NSGraphicsContext saveGraphicsState]; 107 | 108 | [shadow set]; 109 | [[NSColor blackColor] set]; 110 | NSRectClip(bounds); 111 | [path fill]; 112 | 113 | [NSGraphicsContext restoreGraphicsState]; 114 | 115 | } 116 | 117 | // Credit for the next two methods goes to Matt Gemmell 118 | - (void)strokeInside { 119 | /* Stroke within path using no additional clipping rectangle. */ 120 | [self strokeInsideWithinRect:NSZeroRect]; 121 | } 122 | 123 | - (void)strokeInsideWithinRect:(NSRect)clipRect { 124 | NSGraphicsContext *thisContext = [NSGraphicsContext currentContext]; 125 | float lineWidth = [self lineWidth]; 126 | 127 | /* Save the current graphics context. */ 128 | [thisContext saveGraphicsState]; 129 | 130 | /* Double the stroke width, since -stroke centers strokes on paths. */ 131 | [self setLineWidth:(lineWidth * 2.0)]; 132 | 133 | /* Clip drawing to this path; draw nothing outwith the path. */ 134 | [self setClip]; 135 | 136 | /* Further clip drawing to clipRect, usually the view's frame. */ 137 | if (clipRect.size.width > 0.0 && clipRect.size.height > 0.0) { 138 | [NSBezierPath clipRect:clipRect]; 139 | } 140 | 141 | /* Stroke the path. */ 142 | [self stroke]; 143 | 144 | /* Restore the previous graphics context. */ 145 | [thisContext restoreGraphicsState]; 146 | [self setLineWidth:lineWidth]; 147 | } 148 | 149 | @end 150 | -------------------------------------------------------------------------------- /src/third_party/molokocacao/README.chromium: -------------------------------------------------------------------------------- 1 | Name: NSBezierPath additions from Sean Patrick O'Brien 2 | URL: http://www.seanpatrickobrien.com/journal/posts/3 3 | Source URL: http://www.seanpatrickobrien.com/downloads/track/?path=%2Ftutorials%2F1%2FExampleButton.zip 4 | Version: 1.0 5 | License: BSD 6 | 7 | Description: 8 | Additions to NSBezierPath to make certain operations more convenient (inner 9 | shadows on paths, for example). 10 | 11 | Local Modifications: 12 | - Added LICENSE file based on email correspondence with Sean. 13 | - Added header guards. 14 | -------------------------------------------------------------------------------- /src/third_party/mozilla/LICENSE: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Mozilla Public License Version 5 | * 1.1 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * http://www.mozilla.org/MPL/ 8 | * 9 | * Software distributed under the License is distributed on an "AS IS" basis, 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 | * for the specific language governing rights and limitations under the 12 | * License. 13 | * 14 | * The Original Code is mozilla.org code. 15 | * 16 | * The Initial Developer of the Original Code is 17 | * Netscape Communications Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2002 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * 23 | * Alternatively, the contents of this file may be used under the terms of 24 | * either the GNU General Public License Version 2 or later (the "GPL"), or 25 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 26 | * in which case the provisions of the GPL or the LGPL are applicable instead 27 | * of those above. If you wish to allow use of your version of this file only 28 | * under the terms of either the GPL or the LGPL, and not to allow others to 29 | * use your version of this file under the terms of the MPL, indicate your 30 | * decision by deleting the provisions above and replace them with the notice 31 | * and other provisions required by the GPL or the LGPL. If you do not delete 32 | * the provisions above, a recipient may use your version of this file under 33 | * the terms of any one of the MPL, the GPL or the LGPL. 34 | * 35 | * ***** END LICENSE BLOCK ***** */ 36 | -------------------------------------------------------------------------------- /src/third_party/mozilla/NSPasteboard+Utils.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Mozilla Public License Version 5 | * 1.1 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * http://www.mozilla.org/MPL/ 8 | * 9 | * Software distributed under the License is distributed on an "AS IS" basis, 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 | * for the specific language governing rights and limitations under the 12 | * License. 13 | * 14 | * The Original Code is Chimera code. 15 | * 16 | * The Initial Developer of the Original Code is 17 | * Netscape Communications Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2002 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * Simon Fraser 23 | * Bruce Davidson 24 | * 25 | * Alternatively, the contents of this file may be used under the terms of 26 | * either the GNU General Public License Version 2 or later (the "GPL"), or 27 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 28 | * in which case the provisions of the GPL or the LGPL are applicable instead 29 | * of those above. If you wish to allow use of your version of this file only 30 | * under the terms of either the GPL or the LGPL, and not to allow others to 31 | * use your version of this file under the terms of the MPL, indicate your 32 | * decision by deleting the provisions above and replace them with the notice 33 | * and other provisions required by the GPL or the LGPL. If you do not delete 34 | * the provisions above, a recipient may use your version of this file under 35 | * the terms of any one of the MPL, the GPL or the LGPL. 36 | * 37 | * ***** END LICENSE BLOCK ***** */ 38 | 39 | #import 40 | 41 | extern NSString* const kCorePasteboardFlavorType_url; 42 | extern NSString* const kCorePasteboardFlavorType_urln; 43 | extern NSString* const kCorePasteboardFlavorType_urld; 44 | 45 | extern NSString* const kCaminoBookmarkListPBoardType; 46 | extern NSString* const kWebURLsWithTitlesPboardType; 47 | 48 | @interface NSPasteboard(ChimeraPasteboardURLUtils) 49 | 50 | - (int)declareURLPasteboardWithAdditionalTypes:(NSArray*)additionalTypes 51 | owner:(id)newOwner; 52 | - (void)setDataForURL:(NSString*)url title:(NSString*)title; 53 | 54 | - (void)setURLs:(NSArray*)inUrls withTitles:(NSArray*)inTitles; 55 | - (void)getURLs:(NSArray**)outUrls 56 | andTitles:(NSArray**)outTitles 57 | convertingFilenames:(BOOL)convertFilenames; 58 | - (BOOL)containsURLData; 59 | 60 | @end 61 | 62 | @interface NSPasteboard(ChromiumHTMLUtils) 63 | 64 | // Returns the HTML converted from RTF data on the pasteboard. If there is 65 | // none, returns an empty string. 66 | - (NSString*)htmlFromRtf; 67 | 68 | @end 69 | -------------------------------------------------------------------------------- /src/third_party/mozilla/NSString+Utils.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Mozilla Public License Version 5 | * 1.1 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * http://www.mozilla.org/MPL/ 8 | * 9 | * Software distributed under the License is distributed on an "AS IS" basis, 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 | * for the specific language governing rights and limitations under the 12 | * License. 13 | * 14 | * The Original Code is Chimera code. 15 | * 16 | * The Initial Developer of the Original Code is 17 | * Netscape Communications Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2002 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * Simon Fraser 23 | * 24 | * Alternatively, the contents of this file may be used under the terms of 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 | * in which case the provisions of the GPL or the LGPL are applicable instead 28 | * of those above. If you wish to allow use of your version of this file only 29 | * under the terms of either the GPL or the LGPL, and not to allow others to 30 | * use your version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the notice 32 | * and other provisions required by the GPL or the LGPL. If you do not delete 33 | * the provisions above, a recipient may use your version of this file under 34 | * the terms of any one of the MPL, the GPL or the LGPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** */ 37 | 38 | #import 39 | 40 | typedef enum 41 | { 42 | kTruncateAtStart, 43 | kTruncateAtMiddle, 44 | kTruncateAtEnd 45 | } ETruncationType; 46 | 47 | 48 | // a category to extend NSString 49 | @interface NSString (ChimeraStringUtils) 50 | 51 | + (id)ellipsisString; 52 | 53 | - (BOOL)isEqualToStringIgnoringCase:(NSString*)inString; 54 | - (BOOL)hasCaseInsensitivePrefix:(NSString*)inString; 55 | 56 | // Some URIs can contain spaces and still work, even though they aren't strictly valid 57 | // per RFC2396. This method allows us to account for those URIs. 58 | - (BOOL)isLooselyValidatedURI; 59 | 60 | // Utility method to identify URIs that can be run in the context of the current page. 61 | // These URIs could be used as attack vectors via AppleScript, for example. 62 | - (BOOL)isPotentiallyDangerousURI; 63 | 64 | // Utility method to ensure validity of URI strings. NSURL is used to validate 65 | // most of them, but the NSURL test may fail for |javascript:| and |data:| URIs 66 | // because they often contain invalid (per RFC2396) characters such as spaces. 67 | - (BOOL)isValidURI; 68 | 69 | - (NSString *)stringByRemovingCharactersInSet:(NSCharacterSet*)characterSet; 70 | - (NSString *)stringByReplacingCharactersInSet:(NSCharacterSet*)characterSet withString:(NSString*)string; 71 | - (NSString *)stringByTruncatingTo:(unsigned int)maxCharacters at:(ETruncationType)truncationType; 72 | - (NSString *)stringByTruncatingToWidth:(float)inWidth at:(ETruncationType)truncationType withAttributes:(NSDictionary *)attributes; 73 | - (NSString *)stringByTrimmingWhitespace; 74 | - (NSString *)stringByRemovingAmpEscapes; 75 | - (NSString *)stringByAddingAmpEscapes; 76 | 77 | @end 78 | 79 | @interface NSMutableString (ChimeraMutableStringUtils) 80 | 81 | - (void)truncateTo:(unsigned)maxCharacters 82 | at:(ETruncationType)truncationType; 83 | - (void)truncateToWidth:(float)maxWidth 84 | at:(ETruncationType)truncationType 85 | withAttributes:(NSDictionary *)attributes; 86 | 87 | @end 88 | 89 | -------------------------------------------------------------------------------- /src/third_party/mozilla/NSURL+Utils.h: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Mozilla Public License Version 5 | * 1.1 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * http://www.mozilla.org/MPL/ 8 | * 9 | * Software distributed under the License is distributed on an "AS IS" basis, 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 | * for the specific language governing rights and limitations under the 12 | * License. 13 | * 14 | * The Original Code is Camino code. 15 | * 16 | * The Initial Developer of the Original Code is 17 | * Netscape Communications Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2002 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * Nate Weaver (Wevah) - wevah@derailer.org 23 | * 24 | * Alternatively, the contents of this file may be used under the terms of 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 | * in which case the provisions of the GPL or the LGPL are applicable instead 28 | * of those above. If you wish to allow use of your version of this file only 29 | * under the terms of either the GPL or the LGPL, and not to allow others to 30 | * use your version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the notice 32 | * and other provisions required by the GPL or the LGPL. If you do not delete 33 | * the provisions above, a recipient may use your version of this file under 34 | * the terms of any one of the MPL, the GPL or the LGPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** */ 37 | 38 | #import 39 | 40 | 41 | @interface NSURL (CaminoExtensions) 42 | 43 | // This takes an NSURL to a local file, and if that file is a file that 44 | // represents a URL, returns the URL it contains. Otherwise, returns the 45 | // passed URL. Supports .url, .webloc and .ftploc files. 46 | + (NSURL*)decodeLocalFileURL:(NSURL*)url; 47 | 48 | + (NSURL*)URLFromInetloc:(NSString*)inFile; 49 | + (NSURL*)URLFromIEURLFile:(NSString*)inFile; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /src/third_party/mozilla/NSURL+Utils.m: -------------------------------------------------------------------------------- 1 | /* ***** BEGIN LICENSE BLOCK ***** 2 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1 3 | * 4 | * The contents of this file are subject to the Mozilla Public License Version 5 | * 1.1 (the "License"); you may not use this file except in compliance with 6 | * the License. You may obtain a copy of the License at 7 | * http://www.mozilla.org/MPL/ 8 | * 9 | * Software distributed under the License is distributed on an "AS IS" basis, 10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 11 | * for the specific language governing rights and limitations under the 12 | * License. 13 | * 14 | * The Original Code is Camino code. 15 | * 16 | * The Initial Developer of the Original Code is 17 | * Netscape Communications Corporation. 18 | * Portions created by the Initial Developer are Copyright (C) 2002 19 | * the Initial Developer. All Rights Reserved. 20 | * 21 | * Contributor(s): 22 | * Nate Weaver (Wevah) - wevah@derailer.org 23 | * 24 | * Alternatively, the contents of this file may be used under the terms of 25 | * either the GNU General Public License Version 2 or later (the "GPL"), or 26 | * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), 27 | * in which case the provisions of the GPL or the LGPL are applicable instead 28 | * of those above. If you wish to allow use of your version of this file only 29 | * under the terms of either the GPL or the LGPL, and not to allow others to 30 | * use your version of this file under the terms of the MPL, indicate your 31 | * decision by deleting the provisions above and replace them with the notice 32 | * and other provisions required by the GPL or the LGPL. If you do not delete 33 | * the provisions above, a recipient may use your version of this file under 34 | * the terms of any one of the MPL, the GPL or the LGPL. 35 | * 36 | * ***** END LICENSE BLOCK ***** */ 37 | 38 | #import "NSURL+Utils.h" 39 | 40 | 41 | @implementation NSURL (CaminoExtensions) 42 | 43 | + (NSURL*)decodeLocalFileURL:(NSURL*)url 44 | { 45 | NSString* urlPathString = [url path]; 46 | NSString* ext = [[urlPathString pathExtension] lowercaseString]; 47 | OSType fileType = NSHFSTypeCodeFromFileType(NSHFSTypeOfFile(urlPathString)); 48 | 49 | if ([ext isEqualToString:@"url"] || fileType == 'LINK') { 50 | url = [NSURL URLFromIEURLFile:urlPathString]; 51 | } 52 | else if ([ext isEqualToString:@"webloc"] || [ext isEqualToString:@"ftploc"] || 53 | fileType == 'ilht' || fileType == 'ilft') 54 | { 55 | url = [NSURL URLFromInetloc:urlPathString]; 56 | } 57 | 58 | return url; 59 | } 60 | 61 | // 62 | // Reads the URL from a .webloc/.ftploc file. 63 | // Returns the URL, or nil on failure. 64 | // 65 | +(NSURL*)URLFromInetloc:(NSString*)inFile 66 | { 67 | NSURL *ret = nil; 68 | // 69 | // if (inFile && FSPathMakeRef((UInt8 *)[inFile fileSystemRepresentation], &ref, NULL) == noErr) { 70 | // short resRef; 71 | // 72 | // resRef = FSOpenResFile(&ref, fsRdPerm); 73 | // 74 | // if (resRef != -1) { // Has resouce fork. 75 | // Handle urlResHandle; 76 | // 77 | // if ((urlResHandle = Get1Resource('url ', 256))) { // Has 'url ' resource with ID 256. 78 | // long size; 79 | // 80 | // size = GetMaxResourceSize(urlResHandle); 81 | // // Begin Google Modified 82 | // // ret = [NSURL URLWithString:[NSString stringWithCString:(char *)*urlResHandle length:size]]; 83 | // NSString *urlString = [[NSString alloc] initWithBytes:(void *)*urlResHandle 84 | // length:size 85 | // encoding:NSMacOSRomanStringEncoding]; // best guess here 86 | // ret = [NSURL URLWithString:urlString]; 87 | // // End Google Modified 88 | // } 89 | // 90 | // CloseResFile(resRef); 91 | // } 92 | // 93 | // if (!ret) { // Look for valid plist data. 94 | // NSDictionary *plist; 95 | // if ((plist = [[NSDictionary alloc] initWithContentsOfFile:inFile])) { 96 | // ret = [NSURL URLWithString:[plist objectForKey:@"URL"]]; 97 | // // [plist release]; 98 | // } 99 | // } 100 | // } 101 | // 102 | return ret; 103 | } 104 | 105 | // 106 | // Reads the URL from a .url file. 107 | // Returns the URL or nil on failure. 108 | // 109 | +(NSURL*)URLFromIEURLFile:(NSString*)inFile 110 | { 111 | NSURL *ret = nil; 112 | 113 | // Is this really an IE .url file? 114 | if (inFile) { 115 | NSCharacterSet *newlines = [NSCharacterSet characterSetWithCharactersInString:@"\r\n"]; 116 | // Begin Google Modified 117 | // NSScanner *scanner = [NSScanner scannerWithString:[NSString stringWithContentsOfFile:inFile]]; 118 | NSString *fileString = [NSString stringWithContentsOfFile:inFile 119 | encoding:NSWindowsCP1252StringEncoding // best guess here 120 | error:nil]; 121 | NSScanner *scanner = [NSScanner scannerWithString:fileString]; 122 | // End Google Modified 123 | [scanner scanUpToString:@"[InternetShortcut]" intoString:nil]; 124 | 125 | if ([scanner scanString:@"[InternetShortcut]" intoString:nil]) { 126 | // Scan each non-empty line in this section. We don't need to explicitly scan the newlines or 127 | // whitespace because NSScanner ignores these by default. 128 | NSString *line; 129 | 130 | while ([scanner scanUpToCharactersFromSet:newlines intoString:&line]) { 131 | if ([line hasPrefix:@"URL="]) { 132 | ret = [NSURL URLWithString:[line substringFromIndex:4]]; 133 | break; 134 | } 135 | else if ([line hasPrefix:@"["]) { 136 | // This is the start of a new section, so if we haven't found an URL yet, we should bail. 137 | break; 138 | } 139 | } 140 | } 141 | } 142 | 143 | return ret; 144 | } 145 | 146 | @end 147 | -------------------------------------------------------------------------------- /src/third_party/mozilla/README.chromium: -------------------------------------------------------------------------------- 1 | Name: Cocoa extension code from Camino 2 | URL: http://caminobrowser.org/ 3 | 4 | Description: 5 | This directory contains the following files come from (Mozilla) Camino 6 | (src/camino/src/extensions): 7 | 8 | NSPasteboard+Utils.h/mm 9 | NSScreen+Utils.h/m 10 | NSString+Utils.h/m 11 | NSURL+Utils.h/m 12 | NSWorkspace+Utils.h/m 13 | 14 | Local modifications: 15 | - NSURL+Utils.m was modified to use non-deprecated Cocoa APIs to allow 16 | compilation on future versions of Mac OS X. 17 | - NSString+Utils.m was renamed to NSString+Utils.mm and modified to use GURL 18 | for validation in -[NSString isValidURI]. 19 | - NSPasteboard+Utils.mm was modified to add an argument to 20 | -[NSPasteboard getURLs:andTitles:] to determine whether or not filenames in 21 | the drag should be converted to file URLs. 22 | -[NSPasteboard htmlFromRtf] added to do rtf->html conversion. 23 | -------------------------------------------------------------------------------- /todo.taskpaper: -------------------------------------------------------------------------------- 1 | Features: 2 | - Save and restore window bounds @done using NS autosave for BrowserWindow.xib with key "browserWindow" 3 | - Toolbar support (optional, controlled by CTBrowserWindowController) @done 4 | Bugs: 5 | - We are leaking like an old umbrella somewhere with CTBrowser and CTBrowserWindowController I think. @done (well, at least it seems to be fixed) 6 | - The top of the window gets darker when "enough" tabs are in it. Why? @done (fixed by CTBrowserWindow and friends) 7 | 8 | --------------------------------------------------------------------------------