| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/cocoa/tab_contents_controller.h" | 5 #include "chrome/browser/cocoa/tab_contents_controller.h" |
| 6 | 6 |
| 7 #import "base/sys_string_conversions.h" | 7 #import "base/sys_string_conversions.h" |
| 8 #import "chrome/app/chrome_dll_resource.h" | 8 #import "chrome/app/chrome_dll_resource.h" |
| 9 #import "chrome/browser/bookmarks/bookmark_model.h" |
| 9 #import "chrome/browser/command_updater.h" | 10 #import "chrome/browser/command_updater.h" |
| 10 #import "chrome/browser/location_bar.h" | 11 #import "chrome/browser/location_bar.h" |
| 11 #import "chrome/browser/tab_contents/tab_contents.h" | 12 #import "chrome/browser/tab_contents/tab_contents.h" |
| 12 #import "chrome/browser/toolbar_model.h" | 13 #import "chrome/browser/toolbar_model.h" |
| 13 #import "chrome/browser/net/url_fixer_upper.h" | 14 #import "chrome/browser/net/url_fixer_upper.h" |
| 14 | 15 |
| 15 // For now, tab_contents lives here. TODO(port):fix | 16 // For now, tab_contents lives here. TODO(port):fix |
| 16 #include "chrome/common/temp_scaffolding_stubs.h" | 17 #include "chrome/common/temp_scaffolding_stubs.h" |
| 17 | 18 |
| 18 // Names of images in the bundle for the star icon (normal and 'starred'). | 19 // Names of images in the bundle for the star icon (normal and 'starred'). |
| 19 static NSString* const kStarImageName = @"star"; | 20 static NSString* const kStarImageName = @"star"; |
| 20 static NSString* const kStarredImageName = @"starred"; | 21 static NSString* const kStarredImageName = @"starred"; |
| 21 | 22 |
| 22 @interface TabContentsController(CommandUpdates) | 23 @interface TabContentsController(CommandUpdates) |
| 23 - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled; | 24 - (void)enabledStateChangedForCommand:(NSInteger)command enabled:(BOOL)enabled; |
| 24 @end | 25 @end |
| 25 | 26 |
| 26 @interface TabContentsController(LocationBar) | 27 @interface TabContentsController(LocationBar) |
| 27 - (NSString*)locationBarString; | 28 - (NSString*)locationBarString; |
| 28 - (void)focusLocationBar; | 29 - (void)focusLocationBar; |
| 29 @end | 30 @end |
| 30 | 31 |
| 31 @interface TabContentsController(Private) | 32 @interface TabContentsController(Private) |
| 32 - (void)updateToolbarCommandStatus; | 33 - (void)updateToolbarCommandStatus; |
| 34 - (void)applyContentsBoxOffset:(BOOL)apply; |
| 33 @end | 35 @end |
| 34 | 36 |
| 35 // A C++ bridge class that handles listening for updates to commands and | 37 // A C++ bridge class that handles listening for updates to commands and |
| 36 // passing them back to the controller. | 38 // passing them back to the controller. |
| 37 class TabContentsCommandObserver : public CommandUpdater::CommandObserver { | 39 class TabContentsCommandObserver : public CommandUpdater::CommandObserver { |
| 38 public: | 40 public: |
| 39 TabContentsCommandObserver(TabContentsController* controller, | 41 TabContentsCommandObserver(TabContentsController* controller, |
| 40 CommandUpdater* commands); | 42 CommandUpdater* commands); |
| 41 ~TabContentsCommandObserver(); | 43 ~TabContentsCommandObserver(); |
| 42 | 44 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 71 private: | 73 private: |
| 72 TabContentsController* controller_; // weak, owns me | 74 TabContentsController* controller_; // weak, owns me |
| 73 }; | 75 }; |
| 74 | 76 |
| 75 @implementation TabContentsController | 77 @implementation TabContentsController |
| 76 | 78 |
| 77 - (id)initWithNibName:(NSString*)name | 79 - (id)initWithNibName:(NSString*)name |
| 78 bundle:(NSBundle*)bundle | 80 bundle:(NSBundle*)bundle |
| 79 contents:(TabContents*)contents | 81 contents:(TabContents*)contents |
| 80 commands:(CommandUpdater*)commands | 82 commands:(CommandUpdater*)commands |
| 81 toolbarModel:(ToolbarModel*)toolbarModel { | 83 toolbarModel:(ToolbarModel*)toolbarModel |
| 84 bookmarkModel:(BookmarkModel*)bookmarkModel { |
| 82 if ((self = [super initWithNibName:name bundle:bundle])) { | 85 if ((self = [super initWithNibName:name bundle:bundle])) { |
| 83 commands_ = commands; | 86 commands_ = commands; |
| 84 if (commands_) | 87 if (commands_) |
| 85 observer_ = new TabContentsCommandObserver(self, commands); | 88 observer_ = new TabContentsCommandObserver(self, commands); |
| 86 locationBarBridge_ = new LocationBarBridge(self); | 89 locationBarBridge_ = new LocationBarBridge(self); |
| 87 contents_ = contents; | 90 contents_ = contents; |
| 88 toolbarModel_ = toolbarModel; | 91 toolbarModel_ = toolbarModel; |
| 92 bookmarkModel_ = bookmarkModel; |
| 89 } | 93 } |
| 90 return self; | 94 return self; |
| 91 } | 95 } |
| 92 | 96 |
| 93 - (void)dealloc { | 97 - (void)dealloc { |
| 94 // make sure our contents have been removed from the window | 98 // make sure our contents have been removed from the window |
| 95 [[self view] removeFromSuperview]; | 99 [[self view] removeFromSuperview]; |
| 96 delete observer_; | 100 delete observer_; |
| 97 delete locationBarBridge_; | 101 delete locationBarBridge_; |
| 98 [super dealloc]; | 102 [super dealloc]; |
| 99 } | 103 } |
| 100 | 104 |
| 101 - (void)awakeFromNib { | 105 - (void)awakeFromNib { |
| 102 [contentsBox_ setContentView:contents_->GetNativeView()]; | 106 [contentsBox_ setContentView:contents_->GetNativeView()]; |
| 107 [self applyContentsBoxOffset:YES]; |
| 103 | 108 |
| 104 // Provide a starting point since we won't get notifications if the state | 109 // Provide a starting point since we won't get notifications if the state |
| 105 // doesn't change between tabs. | 110 // doesn't change between tabs. |
| 106 [self updateToolbarCommandStatus]; | 111 [self updateToolbarCommandStatus]; |
| 107 | 112 |
| 108 [locationBar_ setStringValue:@"http://dev.chromium.org"]; | 113 [locationBar_ setStringValue:@"http://dev.chromium.org"]; |
| 109 } | 114 } |
| 110 | 115 |
| 111 - (LocationBar*)locationBar { | 116 - (LocationBar*)locationBar { |
| 112 return locationBarBridge_; | 117 return locationBarBridge_; |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 227 return localGrowBox; | 232 return localGrowBox; |
| 228 } | 233 } |
| 229 | 234 |
| 230 - (void)setIsLoading:(BOOL)isLoading { | 235 - (void)setIsLoading:(BOOL)isLoading { |
| 231 NSString* imageName = @"go"; | 236 NSString* imageName = @"go"; |
| 232 if (isLoading) | 237 if (isLoading) |
| 233 imageName = @"stop"; | 238 imageName = @"stop"; |
| 234 [goButton_ setImage:[NSImage imageNamed:imageName]]; | 239 [goButton_ setImage:[NSImage imageNamed:imageName]]; |
| 235 } | 240 } |
| 236 | 241 |
| 242 - (void)toggleBookmarkBar:(BOOL)enable { |
| 243 contentsBoxHasOffset_ = enable; |
| 244 [self applyContentsBoxOffset:enable]; |
| 245 |
| 246 if (enable) { |
| 247 // TODO(jrg): display something useful in the bookmark bar |
| 248 // TODO(jrg): use a BookmarksView, not a ToolbarView |
| 249 // TODO(jrg): don't draw a border around it |
| 250 // TODO(jrg): ... |
| 251 } |
| 252 } |
| 253 |
| 254 // Apply a contents box offset to make (or remove) room for the |
| 255 // bookmark bar. If apply==YES, always make room (the contentsBox_ is |
| 256 // "full size"). If apply==NO we are trying to undo an offset. If no |
| 257 // offset there is nothing to undo. |
| 258 - (void)applyContentsBoxOffset:(BOOL)apply { |
| 259 |
| 260 if (bookmarkView_ == nil) { |
| 261 // We're too early, but awakeFromNib will call me again. |
| 262 return; |
| 263 } |
| 264 if (!contentsBoxHasOffset_ && apply) { |
| 265 // There is no offset to unconditionally apply. |
| 266 return; |
| 267 } |
| 268 |
| 269 int offset = [bookmarkView_ frame].size.height; |
| 270 NSRect frame = [contentsBox_ frame]; |
| 271 if (apply) |
| 272 frame.size.height -= offset; |
| 273 else |
| 274 frame.size.height += offset; |
| 275 |
| 276 // TODO(jrg): animate |
| 277 [contentsBox_ setFrame:frame]; |
| 278 |
| 279 [bookmarkView_ setNeedsDisplay:YES]; |
| 280 [contentsBox_ setNeedsDisplay:YES]; |
| 281 } |
| 282 |
| 237 @end | 283 @end |
| 238 | 284 |
| 239 //-------------------------------------------------------------------------- | 285 //-------------------------------------------------------------------------- |
| 240 | 286 |
| 241 TabContentsCommandObserver::TabContentsCommandObserver( | 287 TabContentsCommandObserver::TabContentsCommandObserver( |
| 242 TabContentsController* controller, CommandUpdater* commands) | 288 TabContentsController* controller, CommandUpdater* commands) |
| 243 : controller_(controller), commands_(commands) { | 289 : controller_(controller), commands_(commands) { |
| 244 DCHECK(controller_ && commands); | 290 DCHECK(controller_ && commands); |
| 245 // Register for notifications about state changes for the toolbar buttons | 291 // Register for notifications about state changes for the toolbar buttons |
| 246 commands_->AddCommandObserver(IDC_BACK, this); | 292 commands_->AddCommandObserver(IDC_BACK, this); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 272 // over. | 318 // over. |
| 273 std::wstring url = base::SysNSStringToWide([controller_ locationBarString]); | 319 std::wstring url = base::SysNSStringToWide([controller_ locationBarString]); |
| 274 | 320 |
| 275 // Try to flesh out the input to make a real URL. | 321 // Try to flesh out the input to make a real URL. |
| 276 return URLFixerUpper::FixupURL(url, std::wstring()); | 322 return URLFixerUpper::FixupURL(url, std::wstring()); |
| 277 } | 323 } |
| 278 | 324 |
| 279 void LocationBarBridge::FocusLocation() { | 325 void LocationBarBridge::FocusLocation() { |
| 280 [controller_ focusLocationBar]; | 326 [controller_ focusLocationBar]; |
| 281 } | 327 } |
| OLD | NEW |