| 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 #import "chrome/browser/cocoa/toolbar_controller.h" | 5 #import "chrome/browser/cocoa/toolbar_controller.h" |
| 6 | 6 |
| 7 #include "app/l10n_util_mac.h" | 7 #include "app/l10n_util_mac.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/nsimage_cache_mac.h" | 9 #include "base/nsimage_cache_mac.h" |
| 10 #include "base/sys_string_conversions.h" | 10 #include "base/sys_string_conversions.h" |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 resizeDelegate:(id<ViewResizer>)resizeDelegate { | 142 resizeDelegate:(id<ViewResizer>)resizeDelegate { |
| 143 DCHECK(model && commands && profile); | 143 DCHECK(model && commands && profile); |
| 144 if ((self = [super initWithNibName:@"Toolbar" | 144 if ((self = [super initWithNibName:@"Toolbar" |
| 145 bundle:mac_util::MainAppBundle()])) { | 145 bundle:mac_util::MainAppBundle()])) { |
| 146 toolbarModel_ = model; | 146 toolbarModel_ = model; |
| 147 commands_ = commands; | 147 commands_ = commands; |
| 148 profile_ = profile; | 148 profile_ = profile; |
| 149 browser_ = browser; | 149 browser_ = browser; |
| 150 resizeDelegate_ = resizeDelegate; | 150 resizeDelegate_ = resizeDelegate; |
| 151 hasToolbar_ = YES; | 151 hasToolbar_ = YES; |
| 152 hasLocationBar_ = YES; |
| 152 | 153 |
| 153 // Register for notifications about state changes for the toolbar buttons | 154 // Register for notifications about state changes for the toolbar buttons |
| 154 commandObserver_.reset(new CommandObserverBridge(self, commands)); | 155 commandObserver_.reset(new CommandObserverBridge(self, commands)); |
| 155 commandObserver_->ObserveCommand(IDC_BACK); | 156 commandObserver_->ObserveCommand(IDC_BACK); |
| 156 commandObserver_->ObserveCommand(IDC_FORWARD); | 157 commandObserver_->ObserveCommand(IDC_FORWARD); |
| 157 commandObserver_->ObserveCommand(IDC_RELOAD); | 158 commandObserver_->ObserveCommand(IDC_RELOAD); |
| 158 commandObserver_->ObserveCommand(IDC_HOME); | 159 commandObserver_->ObserveCommand(IDC_HOME); |
| 159 commandObserver_->ObserveCommand(IDC_BOOKMARK_PAGE); | 160 commandObserver_->ObserveCommand(IDC_BOOKMARK_PAGE); |
| 160 } | 161 } |
| 161 return self; | 162 return self; |
| 162 } | 163 } |
| 163 | 164 |
| 164 - (void)dealloc { | 165 - (void)dealloc { |
| 165 // Make sure any code in the base class which assumes [self view] is | 166 // Make sure any code in the base class which assumes [self view] is |
| 166 // the "parent" view continues to work. | 167 // the "parent" view continues to work. |
| 167 hasToolbar_ = YES; | 168 hasToolbar_ = YES; |
| 169 hasLocationBar_ = YES; |
| 168 | 170 |
| 169 [[NSNotificationCenter defaultCenter] removeObserver:self]; | 171 [[NSNotificationCenter defaultCenter] removeObserver:self]; |
| 170 | 172 |
| 171 if (trackingArea_.get()) | 173 if (trackingArea_.get()) |
| 172 [[self view] removeTrackingArea:trackingArea_.get()]; | 174 [[self view] removeTrackingArea:trackingArea_.get()]; |
| 173 [super dealloc]; | 175 [super dealloc]; |
| 174 } | 176 } |
| 175 | 177 |
| 176 // Called after the view is done loading and the outlets have been hooked up. | 178 // Called after the view is done loading and the outlets have been hooked up. |
| 177 // Now we can hook up bridges that rely on UI objects such as the location | 179 // Now we can hook up bridges that rely on UI objects such as the location |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 286 [[targetView cell] setMouseInside:YES animate:YES]; | 288 [[targetView cell] setMouseInside:YES animate:YES]; |
| 287 [hoveredButton_ release]; | 289 [hoveredButton_ release]; |
| 288 hoveredButton_ = [targetView retain]; | 290 hoveredButton_ = [targetView retain]; |
| 289 } | 291 } |
| 290 } | 292 } |
| 291 | 293 |
| 292 - (void)mouseEntered:(NSEvent*)event { | 294 - (void)mouseEntered:(NSEvent*)event { |
| 293 [self mouseMoved:event]; | 295 [self mouseMoved:event]; |
| 294 } | 296 } |
| 295 | 297 |
| 296 - (LocationBar*)locationBar { | 298 - (LocationBar*)locationBarBridge { |
| 297 return locationBarView_.get(); | 299 return locationBarView_.get(); |
| 298 } | 300 } |
| 299 | 301 |
| 300 - (void)focusLocationBar { | 302 - (void)focusLocationBar { |
| 301 if (locationBarView_.get()) { | 303 if (locationBarView_.get()) { |
| 302 locationBarView_->FocusLocation(); | 304 locationBarView_->FocusLocation(); |
| 303 } | 305 } |
| 304 } | 306 } |
| 305 | 307 |
| 306 // Called when the state for a command changes to |enabled|. Update the | 308 // Called when the state for a command changes to |enabled|. Update the |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 NSInteger tag = IDC_GO; | 372 NSInteger tag = IDC_GO; |
| 371 if (isLoading) { | 373 if (isLoading) { |
| 372 imageName = kGoButtonStopImageName; | 374 imageName = kGoButtonStopImageName; |
| 373 tag = IDC_STOP; | 375 tag = IDC_STOP; |
| 374 } | 376 } |
| 375 NSImage* stopStartImage = nsimage_cache::ImageNamed(imageName); | 377 NSImage* stopStartImage = nsimage_cache::ImageNamed(imageName); |
| 376 [goButton_ setImage:stopStartImage]; | 378 [goButton_ setImage:stopStartImage]; |
| 377 [goButton_ setTag:tag]; | 379 [goButton_ setTag:tag]; |
| 378 } | 380 } |
| 379 | 381 |
| 380 - (void)setHasToolbar:(BOOL)toolbar { | 382 - (void)setHasToolbar:(BOOL)toolbar hasLocationBar:(BOOL)locBar { |
| 381 [self view]; // force nib loading | 383 [self view]; // Force nib loading. |
| 384 |
| 382 hasToolbar_ = toolbar; | 385 hasToolbar_ = toolbar; |
| 383 | 386 |
| 384 // App mode allows turning off the location bar as well. | 387 // If there's a toolbar, there must be a location bar. |
| 385 // TODO(???): add more code here when implementing app mode to allow | 388 DCHECK((toolbar && locBar) || !toolbar); |
| 386 // turning off both toolbar AND location bar. | 389 hasLocationBar_ = toolbar ? YES : locBar; |
| 390 |
| 391 // Decide whether to hide/show based on whether there's a location bar. |
| 392 [[self view] setHidden:!hasLocationBar_]; |
| 387 | 393 |
| 388 // Make location bar not editable when in a pop-up. | 394 // Make location bar not editable when in a pop-up. |
| 395 // TODO(viettrungluu): is this right (all the time)? |
| 389 [locationBar_ setEditable:toolbar]; | 396 [locationBar_ setEditable:toolbar]; |
| 390 } | 397 } |
| 391 | 398 |
| 392 - (NSView*)view { | 399 - (NSView*)view { |
| 393 if (hasToolbar_) | 400 if (hasToolbar_) |
| 394 return [super view]; | 401 return [super view]; |
| 395 return locationBar_; | 402 return locationBar_; |
| 396 } | 403 } |
| 397 | 404 |
| 398 // (Private) Returns the backdrop to the toolbar. | 405 // (Private) Returns the backdrop to the toolbar. |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 575 locationFrame.size.width += dX; | 582 locationFrame.size.width += dX; |
| 576 [locationBar_ setFrame:locationFrame]; | 583 [locationBar_ setFrame:locationFrame]; |
| 577 } | 584 } |
| 578 | 585 |
| 579 - (NSRect)starButtonInWindowCoordinates { | 586 - (NSRect)starButtonInWindowCoordinates { |
| 580 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds] | 587 return [[[starButton_ window] contentView] convertRect:[starButton_ bounds] |
| 581 fromView:starButton_]; | 588 fromView:starButton_]; |
| 582 } | 589 } |
| 583 | 590 |
| 584 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { | 591 - (CGFloat)desiredHeightForCompression:(CGFloat)compressByHeight { |
| 585 return kBaseToolbarHeight - compressByHeight; | 592 // With no toolbar, just ignore the compression. |
| 593 return hasToolbar_ ? kBaseToolbarHeight - compressByHeight : |
| 594 NSHeight([locationBar_ frame]); |
| 586 } | 595 } |
| 587 | 596 |
| 588 - (void)setDividerOpacity:(CGFloat)opacity { | 597 - (void)setDividerOpacity:(CGFloat)opacity { |
| 589 BackgroundGradientView* view = [self backgroundGradientView]; | 598 BackgroundGradientView* view = [self backgroundGradientView]; |
| 590 [view setShowsDivider:(opacity > 0 ? YES : NO)]; | 599 [view setShowsDivider:(opacity > 0 ? YES : NO)]; |
| 591 | 600 |
| 592 // We may not have a toolbar view (e.g., popup windows only have a location | 601 // We may not have a toolbar view (e.g., popup windows only have a location |
| 593 // bar). | 602 // bar). |
| 594 if ([view isKindOfClass:[ToolbarView class]]) { | 603 if ([view isKindOfClass:[ToolbarView class]]) { |
| 595 ToolbarView* toolbarView = (ToolbarView*)view; | 604 ToolbarView* toolbarView = (ToolbarView*)view; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 606 // Following chrome/browser/views/go_button.cc: GoButton::GetTooltipText() | 615 // Following chrome/browser/views/go_button.cc: GoButton::GetTooltipText() |
| 607 | 616 |
| 608 // Is it currently 'stop'? | 617 // Is it currently 'stop'? |
| 609 if ([goButton_ tag] == IDC_STOP) { | 618 if ([goButton_ tag] == IDC_STOP) { |
| 610 return l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP); | 619 return l10n_util::GetNSStringWithFixup(IDS_TOOLTIP_STOP); |
| 611 } | 620 } |
| 612 | 621 |
| 613 // It is 'go', so see what it would do... | 622 // It is 'go', so see what it would do... |
| 614 | 623 |
| 615 // Fetch the EditView and EditModel | 624 // Fetch the EditView and EditModel |
| 616 LocationBar* locationBar = [self locationBar]; | 625 LocationBar* locationBar = [self locationBarBridge]; |
| 617 DCHECK(locationBar); | 626 DCHECK(locationBar); |
| 618 AutocompleteEditView* editView = locationBar->location_entry(); | 627 AutocompleteEditView* editView = locationBar->location_entry(); |
| 619 DCHECK(editView); | 628 DCHECK(editView); |
| 620 AutocompleteEditModel* editModel = editView->model(); | 629 AutocompleteEditModel* editModel = editView->model(); |
| 621 DCHECK(editModel); | 630 DCHECK(editModel); |
| 622 | 631 |
| 623 std::wstring currentText(editView->GetText()); | 632 std::wstring currentText(editView->GetText()); |
| 624 if (currentText.empty()) { | 633 if (currentText.empty()) { |
| 625 return nil; | 634 return nil; |
| 626 } | 635 } |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 665 | 674 |
| 666 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, | 675 NSRect r = NSMakeRect(minX, NSMinY(locationFrame), maxX - minX, |
| 667 NSHeight(locationFrame)); | 676 NSHeight(locationFrame)); |
| 668 gfx::Rect stack_bounds( | 677 gfx::Rect stack_bounds( |
| 669 NSRectToCGRect([[self view] convertRect:r toView:nil])); | 678 NSRectToCGRect([[self view] convertRect:r toView:nil])); |
| 670 // Inset the bounds to just inside the visible edges (see comment above). | 679 // Inset the bounds to just inside the visible edges (see comment above). |
| 671 stack_bounds.Inset(kLocationStackEdgeWidth, 0); | 680 stack_bounds.Inset(kLocationStackEdgeWidth, 0); |
| 672 return stack_bounds; | 681 return stack_bounds; |
| 673 } | 682 } |
| 674 @end | 683 @end |
| OLD | NEW |