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/autocomplete_text_field.h" |
| 11 #import "chrome/browser/cocoa/autocomplete_text_field_editor.h" |
10 #import "chrome/browser/cocoa/location_bar_view_mac.h" | 12 #import "chrome/browser/cocoa/location_bar_view_mac.h" |
11 #include "chrome/browser/cocoa/nsimage_cache.h" | 13 #include "chrome/browser/cocoa/nsimage_cache.h" |
12 #include "chrome/browser/profile.h" | 14 #include "chrome/browser/profile.h" |
13 #include "chrome/browser/toolbar_model.h" | 15 #include "chrome/browser/toolbar_model.h" |
14 #include "chrome/common/notification_details.h" | 16 #include "chrome/common/notification_details.h" |
15 #include "chrome/common/notification_observer.h" | 17 #include "chrome/common/notification_observer.h" |
16 #include "chrome/common/notification_type.h" | 18 #include "chrome/common/notification_type.h" |
17 #include "chrome/common/pref_names.h" | 19 #include "chrome/common/pref_names.h" |
18 #include "chrome/common/pref_service.h" | 20 #include "chrome/common/pref_service.h" |
19 | 21 |
20 // Names of images in the bundle for the star icon (normal and 'starred'). | 22 // Names of images in the bundle for the star icon (normal and 'starred'). |
21 static NSString* const kStarImageName = @"star_Template.pdf"; | 23 static NSString* const kStarImageName = @"star_Template.pdf"; |
22 static NSString* const kStarredImageName = @"starred.pdf"; | 24 static NSString* const kStarredImageName = @"starred.pdf"; |
23 | 25 |
24 @implementation LocationBarFieldEditor | |
25 - (void)copy:(id)sender { | |
26 NSPasteboard* pb = [NSPasteboard generalPasteboard]; | |
27 [self performCopy:pb]; | |
28 } | |
29 | |
30 - (void)cut:(id)sender { | |
31 NSPasteboard* pb = [NSPasteboard generalPasteboard]; | |
32 [self performCut:pb]; | |
33 } | |
34 | |
35 - (void)performCopy:(NSPasteboard*)pb { | |
36 [pb declareTypes:[NSArray array] owner:nil]; | |
37 [self writeSelectionToPasteboard:pb types: | |
38 [NSArray arrayWithObject:NSStringPboardType]]; | |
39 } | |
40 | |
41 - (void)performCut:(NSPasteboard*)pb { | |
42 [self performCopy:pb]; | |
43 [self delete:nil]; | |
44 } | |
45 | |
46 @end | |
47 | |
48 @interface ToolbarController(Private) | 26 @interface ToolbarController(Private) |
49 - (void)initCommandStatus:(CommandUpdater*)commands; | 27 - (void)initCommandStatus:(CommandUpdater*)commands; |
50 - (void)prefChanged:(std::wstring*)prefName; | 28 - (void)prefChanged:(std::wstring*)prefName; |
51 @end | 29 @end |
52 | 30 |
53 namespace ToolbarControllerInternal { | 31 namespace ToolbarControllerInternal { |
54 | 32 |
55 // A C++ class registered for changes in preferences. Bridges the | 33 // A C++ class registered for changes in preferences. Bridges the |
56 // notification back to the ToolbarController. | 34 // notification back to the ToolbarController. |
57 class PrefObserverBridge : public NotificationObserver { | 35 class PrefObserverBridge : public NotificationObserver { |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
238 // TODO(jrg): investigate non-Mac Chrome behavior and possibly expand this. | 216 // TODO(jrg): investigate non-Mac Chrome behavior and possibly expand this. |
239 if (hasToolbar_ == NO) | 217 if (hasToolbar_ == NO) |
240 return nil; | 218 return nil; |
241 return bookmarkBarController_.get(); | 219 return bookmarkBarController_.get(); |
242 } | 220 } |
243 | 221 |
244 - (id)customFieldEditorForObject:(id)obj { | 222 - (id)customFieldEditorForObject:(id)obj { |
245 if (obj == locationBar_) { | 223 if (obj == locationBar_) { |
246 // Lazilly construct Field editor, Cocoa UI code always runs on the | 224 // Lazilly construct Field editor, Cocoa UI code always runs on the |
247 // same thread, so there shoudn't be a race condition here. | 225 // same thread, so there shoudn't be a race condition here. |
248 if (locationBarFieldEditor_.get() == nil) { | 226 if (autocompleteTextFieldEditor_.get() == nil) { |
249 locationBarFieldEditor_.reset([[LocationBarFieldEditor alloc] init]); | 227 autocompleteTextFieldEditor_.reset( |
| 228 [[AutocompleteTextFieldEditor alloc] init]); |
250 } | 229 } |
251 | 230 |
252 // This needs to be called every time, otherwise notifications | 231 // This needs to be called every time, otherwise notifications |
253 // aren't sent correctly. | 232 // aren't sent correctly. |
254 DCHECK(locationBarFieldEditor_.get()); | 233 DCHECK(autocompleteTextFieldEditor_.get()); |
255 [locationBarFieldEditor_.get() setFieldEditor:YES]; | 234 [autocompleteTextFieldEditor_.get() setFieldEditor:YES]; |
256 return locationBarFieldEditor_.get(); | 235 return autocompleteTextFieldEditor_.get(); |
257 } | 236 } |
258 return nil; | 237 return nil; |
259 } | 238 } |
260 | 239 |
261 // Returns an array of views in the order of the outlets above. | 240 // Returns an array of views in the order of the outlets above. |
262 - (NSArray*)toolbarViews { | 241 - (NSArray*)toolbarViews { |
263 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, | 242 return [NSArray arrayWithObjects:backButton_, forwardButton_, reloadButton_, |
264 homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, | 243 homeButton_, starButton_, goButton_, pageButton_, wrenchButton_, |
265 locationBar_, nil]; | 244 locationBar_, nil]; |
266 } | 245 } |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
343 forView:pageButton_]; | 322 forView:pageButton_]; |
344 } | 323 } |
345 | 324 |
346 - (IBAction)showWrenchMenu:(id)sender { | 325 - (IBAction)showWrenchMenu:(id)sender { |
347 [NSMenu popUpContextMenu:wrenchMenu_ | 326 [NSMenu popUpContextMenu:wrenchMenu_ |
348 withEvent:[NSApp currentEvent] | 327 withEvent:[NSApp currentEvent] |
349 forView:wrenchButton_]; | 328 forView:wrenchButton_]; |
350 } | 329 } |
351 | 330 |
352 @end | 331 @end |
OLD | NEW |