Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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/ui/cocoa/location_bar/autocomplete_text_field_editor.h" | 5 #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" |
| 6 | 6 |
| 7 #include "base/mac/sdk_forward_declarations.h" | 7 #include "base/mac/sdk_forward_declarations.h" |
| 8 #include "base/strings/string_util.h" | 8 #include "base/strings/string_util.h" |
| 9 #include "base/strings/sys_string_conversions.h" | 9 #include "base/strings/sys_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" // IDC_* | 10 #include "chrome/app/chrome_command_ids.h" // IDC_* |
| (...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 DCHECK(observer); | 161 DCHECK(observer); |
| 162 if (observer && observer->CanCopy()) | 162 if (observer && observer->CanCopy()) |
| 163 observer->CopyToPasteboard([NSPasteboard generalPasteboard]); | 163 observer->CopyToPasteboard([NSPasteboard generalPasteboard]); |
| 164 } | 164 } |
| 165 | 165 |
| 166 - (void)cut:(id)sender { | 166 - (void)cut:(id)sender { |
| 167 [self copy:sender]; | 167 [self copy:sender]; |
| 168 [self delete:nil]; | 168 [self delete:nil]; |
| 169 } | 169 } |
| 170 | 170 |
| 171 - (void)showURL:(id)sender { | |
| 172 AutocompleteTextFieldObserver* observer = [self observer]; | |
| 173 DCHECK(observer); | |
| 174 observer->ShowURL(); | |
| 175 } | |
| 176 | |
| 177 // This class assumes that the delegate is an AutocompleteTextField. | 171 // This class assumes that the delegate is an AutocompleteTextField. |
| 178 // Enforce that assumption. | 172 // Enforce that assumption. |
| 179 - (AutocompleteTextField*)delegate { | 173 - (AutocompleteTextField*)delegate { |
| 180 AutocompleteTextField* delegate = | 174 AutocompleteTextField* delegate = |
| 181 static_cast<AutocompleteTextField*>([super delegate]); | 175 static_cast<AutocompleteTextField*>([super delegate]); |
| 182 DCHECK(delegate == nil || | 176 DCHECK(delegate == nil || |
| 183 [delegate isKindOfClass:[AutocompleteTextField class]]); | 177 [delegate isKindOfClass:[AutocompleteTextField class]]); |
| 184 return delegate; | 178 return delegate; |
| 185 } | 179 } |
| 186 | 180 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 301 NSString* pasteAndGoLabel = | 295 NSString* pasteAndGoLabel = |
| 302 l10n_util::GetNSStringWithFixup(observer->GetPasteActionStringId()); | 296 l10n_util::GetNSStringWithFixup(observer->GetPasteActionStringId()); |
| 303 DCHECK([pasteAndGoLabel length]); | 297 DCHECK([pasteAndGoLabel length]); |
| 304 [menu addItemWithTitle:pasteAndGoLabel | 298 [menu addItemWithTitle:pasteAndGoLabel |
| 305 action:@selector(pasteAndGo:) | 299 action:@selector(pasteAndGo:) |
| 306 keyEquivalent:@""]; | 300 keyEquivalent:@""]; |
| 307 } | 301 } |
| 308 | 302 |
| 309 [menu addItem:[NSMenuItem separatorItem]]; | 303 [menu addItem:[NSMenuItem separatorItem]]; |
| 310 | 304 |
| 311 // Display a "Show URL" option if search term replacement is active. | |
| 312 if (observer->ShouldEnableShowURL()) { | |
| 313 NSString* showURLLabel = | |
| 314 l10n_util::GetNSStringWithFixup(IDS_SHOW_URL_MAC); | |
|
Peter Kasting
2016/08/13 05:03:44
This was the only use of this string, so it should
Marc Treib
2016/08/16 12:00:17
Done. (I have a follow-up CL almost ready that'll
| |
| 315 DCHECK([showURLLabel length]); | |
| 316 [menu addItemWithTitle:showURLLabel | |
| 317 action:@selector(showURL:) | |
| 318 keyEquivalent:@""]; | |
| 319 } | |
| 320 | |
| 321 NSString* searchEngineLabel = | 305 NSString* searchEngineLabel = |
| 322 l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES); | 306 l10n_util::GetNSStringWithFixup(IDS_EDIT_SEARCH_ENGINES); |
| 323 DCHECK([searchEngineLabel length]); | 307 DCHECK([searchEngineLabel length]); |
| 324 NSMenuItem* item = [menu addItemWithTitle:searchEngineLabel | 308 NSMenuItem* item = [menu addItemWithTitle:searchEngineLabel |
| 325 action:@selector(commandDispatch:) | 309 action:@selector(commandDispatch:) |
| 326 keyEquivalent:@""]; | 310 keyEquivalent:@""]; |
| 327 [item setTag:IDC_EDIT_SEARCH_ENGINES]; | 311 [item setTag:IDC_EDIT_SEARCH_ENGINES]; |
| 328 } | 312 } |
| 329 | 313 |
| 330 return menu; | 314 return menu; |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 579 - (BOOL)validateMenuItem:(NSMenuItem*)item { | 563 - (BOOL)validateMenuItem:(NSMenuItem*)item { |
| 580 if ([item action] == @selector(copyToFindPboard:)) | 564 if ([item action] == @selector(copyToFindPboard:)) |
| 581 return [self selectedRange].length > 0; | 565 return [self selectedRange].length > 0; |
| 582 if ([item action] == @selector(pasteAndGo:)) { | 566 if ([item action] == @selector(pasteAndGo:)) { |
| 583 // TODO(rohitrao): If the clipboard is empty, should we show a | 567 // TODO(rohitrao): If the clipboard is empty, should we show a |
| 584 // greyed-out "Paste and Go" or nothing at all? | 568 // greyed-out "Paste and Go" or nothing at all? |
| 585 AutocompleteTextFieldObserver* observer = [self observer]; | 569 AutocompleteTextFieldObserver* observer = [self observer]; |
| 586 DCHECK(observer); | 570 DCHECK(observer); |
| 587 return observer->CanPasteAndGo(); | 571 return observer->CanPasteAndGo(); |
| 588 } | 572 } |
| 589 if ([item action] == @selector(showURL:)) { | |
| 590 AutocompleteTextFieldObserver* observer = [self observer]; | |
| 591 DCHECK(observer); | |
| 592 return observer->ShouldEnableShowURL(); | |
| 593 } | |
| 594 return [super validateMenuItem:item]; | 573 return [super validateMenuItem:item]; |
| 595 } | 574 } |
| 596 | 575 |
| 597 - (void)copyToFindPboard:(id)sender { | 576 - (void)copyToFindPboard:(id)sender { |
| 598 NSRange selectedRange = [self selectedRange]; | 577 NSRange selectedRange = [self selectedRange]; |
| 599 if (selectedRange.length == 0) | 578 if (selectedRange.length == 0) |
| 600 return; | 579 return; |
| 601 NSAttributedString* selection = | 580 NSAttributedString* selection = |
| 602 [self attributedSubstringForProposedRange:selectedRange | 581 [self attributedSubstringForProposedRange:selectedRange |
| 603 actualRange:NULL]; | 582 actualRange:NULL]; |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 626 if (!ui::MaterialDesignController::IsModeMaterial()) { | 605 if (!ui::MaterialDesignController::IsModeMaterial()) { |
| 627 return; | 606 return; |
| 628 } | 607 } |
| 629 [self updateColorsToMatchTheme]; | 608 [self updateColorsToMatchTheme]; |
| 630 } | 609 } |
| 631 | 610 |
| 632 - (void)windowDidChangeActive { | 611 - (void)windowDidChangeActive { |
| 633 } | 612 } |
| 634 | 613 |
| 635 @end | 614 @end |
| OLD | NEW |