| 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 "base/mac_util.h" | 7 #include "base/mac_util.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #import "chrome/browser/cocoa/location_bar_view_mac.h" | 10 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
| 11 #include "chrome/browser/toolbar_model.h" | 11 #include "chrome/browser/toolbar_model.h" |
| 12 | 12 |
| 13 // Names of images in the bundle for the star icon (normal and 'starred'). | 13 // Names of images in the bundle for the star icon (normal and 'starred'). |
| 14 static NSString* const kStarImageName = @"star"; | 14 static NSString* const kStarImageName = @"star"; |
| 15 static NSString* const kStarredImageName = @"starred"; | 15 static NSString* const kStarredImageName = @"starred"; |
| 16 | 16 |
| 17 @implementation LocationBarFieldEditor |
| 18 - (void)copy:(id)sender { |
| 19 NSPasteboard* pb = [NSPasteboard generalPasteboard]; |
| 20 [self performCopy:pb]; |
| 21 } |
| 22 |
| 23 - (void)cut:(id)sender { |
| 24 NSPasteboard* pb = [NSPasteboard generalPasteboard]; |
| 25 [self performCut:pb]; |
| 26 } |
| 27 |
| 28 - (void)performCopy:(NSPasteboard*)pb { |
| 29 [pb declareTypes:[NSArray array] owner:nil]; |
| 30 [self writeSelectionToPasteboard:pb types: |
| 31 [NSArray arrayWithObject:NSStringPboardType]]; |
| 32 } |
| 33 |
| 34 - (void)performCut:(NSPasteboard*)pb { |
| 35 [self performCopy:pb]; |
| 36 [self delete:nil]; |
| 37 } |
| 38 |
| 39 @end |
| 40 |
| 17 @interface ToolbarController(Private) | 41 @interface ToolbarController(Private) |
| 18 - (void)initCommandStatus:(CommandUpdater*)commands; | 42 - (void)initCommandStatus:(CommandUpdater*)commands; |
| 19 @end | 43 @end |
| 20 | 44 |
| 21 @implementation ToolbarController | 45 @implementation ToolbarController |
| 22 | 46 |
| 23 - (id)initWithModel:(ToolbarModel*)model | 47 - (id)initWithModel:(ToolbarModel*)model |
| 24 commands:(CommandUpdater*)commands | 48 commands:(CommandUpdater*)commands |
| 25 profile:(Profile*)profile { | 49 profile:(Profile*)profile { |
| 26 DCHECK(model && commands && profile); | 50 DCHECK(model && commands && profile); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 44 // Called after the view is done loading and the outlets have been hooked up. | 68 // Called after the view is done loading and the outlets have been hooked up. |
| 45 // Now we can hook up bridges that rely on UI objects such as the location | 69 // Now we can hook up bridges that rely on UI objects such as the location |
| 46 // bar and button state. | 70 // bar and button state. |
| 47 - (void)awakeFromNib { | 71 - (void)awakeFromNib { |
| 48 [self initCommandStatus:commands_]; | 72 [self initCommandStatus:commands_]; |
| 49 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, | 73 locationBarView_.reset(new LocationBarViewMac(locationBar_, commands_, |
| 50 toolbarModel_, profile_)); | 74 toolbarModel_, profile_)); |
| 51 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 75 [locationBar_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 52 } | 76 } |
| 53 | 77 |
| 54 - (void)dealloc { | |
| 55 [super dealloc]; | |
| 56 } | |
| 57 | |
| 58 - (LocationBar*)locationBar { | 78 - (LocationBar*)locationBar { |
| 59 return locationBarView_.get(); | 79 return locationBarView_.get(); |
| 60 } | 80 } |
| 61 | 81 |
| 62 - (void)focusLocationBar { | 82 - (void)focusLocationBar { |
| 63 if (locationBarView_.get()) { | 83 if (locationBarView_.get()) { |
| 64 locationBarView_->FocusLocation(); | 84 locationBarView_->FocusLocation(); |
| 65 } | 85 } |
| 66 } | 86 } |
| 67 | 87 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 NSString* imageName = @"go"; | 134 NSString* imageName = @"go"; |
| 115 NSInteger tag = IDC_GO; | 135 NSInteger tag = IDC_GO; |
| 116 if (isLoading) { | 136 if (isLoading) { |
| 117 imageName = @"stop"; | 137 imageName = @"stop"; |
| 118 tag = IDC_STOP; | 138 tag = IDC_STOP; |
| 119 } | 139 } |
| 120 [goButton_ setImage:[NSImage imageNamed:imageName]]; | 140 [goButton_ setImage:[NSImage imageNamed:imageName]]; |
| 121 [goButton_ setTag:tag]; | 141 [goButton_ setTag:tag]; |
| 122 } | 142 } |
| 123 | 143 |
| 144 - (id)customFieldEditorForObject:(id)obj { |
| 145 if (obj == locationBar_) { |
| 146 // Lazilly construct Field editor, Cocoa UI code always runs on the |
| 147 // same thread, so there shoudn't be a race condition here. |
| 148 if (locationBarFieldEditor_.get() == nil) { |
| 149 locationBarFieldEditor_.reset([[LocationBarFieldEditor alloc] init]); |
| 150 } |
| 151 |
| 152 // This needs to be called every time, otherwise notifications |
| 153 // aren't sent correctly. |
| 154 DCHECK(locationBarFieldEditor_.get()); |
| 155 [locationBarFieldEditor_.get() setFieldEditor:YES]; |
| 156 return locationBarFieldEditor_.get(); |
| 157 } |
| 158 return nil; |
| 159 } |
| 160 |
| 124 // Returns an array of views in the order of the outlets above. | 161 // Returns an array of views in the order of the outlets above. |
| 125 - (NSArray*)toolbarViews { | 162 - (NSArray*)toolbarViews { |
| 126 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, | 163 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, |
| 127 starButton_, goButton_, locationBar_, nil]; | 164 starButton_, goButton_, locationBar_, nil]; |
| 128 } | 165 } |
| 129 | 166 |
| 130 @end | 167 @end |
| OLD | NEW |