Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(161)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit_view_mac.mm

Issue 173194: [Mac] Omnibox keyword, keyword hint, and search hint support.... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 11 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/autocomplete/autocomplete_edit_view_mac.h" 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_mac.h"
6 6
7 #include <Carbon/Carbon.h> // kVK_Return 7 #include <Carbon/Carbon.h> // kVK_Return
8 #include "app/gfx/font.h" 8 #include "app/gfx/font.h"
9 #include "app/resource_bundle.h" 9 #include "app/resource_bundle.h"
10 #include "base/clipboard.h" 10 #include "base/clipboard.h"
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
285 void AutocompleteEditViewMac::SetUserText(const std::wstring& text, 285 void AutocompleteEditViewMac::SetUserText(const std::wstring& text,
286 const std::wstring& display_text, 286 const std::wstring& display_text,
287 bool update_popup) { 287 bool update_popup) {
288 model_->SetUserText(text); 288 model_->SetUserText(text);
289 // TODO(shess): TODO below from gtk. 289 // TODO(shess): TODO below from gtk.
290 // TODO(deanm): something about selection / focus change here. 290 // TODO(deanm): something about selection / focus change here.
291 SetText(display_text); 291 SetText(display_text);
292 if (update_popup) { 292 if (update_popup) {
293 UpdatePopup(); 293 UpdatePopup();
294 } 294 }
295 controller_->OnChanged();
295 } 296 }
296 297
297 NSRange AutocompleteEditViewMac::GetSelectedRange() const { 298 NSRange AutocompleteEditViewMac::GetSelectedRange() const {
298 DCHECK([field_ currentEditor]); 299 DCHECK([field_ currentEditor]);
299 return [[field_ currentEditor] selectedRange]; 300 return [[field_ currentEditor] selectedRange];
300 } 301 }
301 302
302 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { 303 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) {
303 // This can be called when we don't have focus. For instance, when 304 // This can be called when we don't have focus. For instance, when
304 // the user clicks the "Go" button. 305 // the user clicks the "Go" button.
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 if (scheme_security_level == ToolbarModel::SECURE) { 421 if (scheme_security_level == ToolbarModel::SECURE) {
421 color = SecureSchemeColor(); 422 color = SecureSchemeColor();
422 } else { 423 } else {
423 color = InsecureSchemeColor(); 424 color = InsecureSchemeColor();
424 } 425 }
425 [as addAttribute:NSForegroundColorAttributeName value:color 426 [as addAttribute:NSForegroundColorAttributeName value:color
426 range:ComponentToNSRange(parts.scheme)]; 427 range:ComponentToNSRange(parts.scheme)];
427 } 428 }
428 429
429 [field_ setObjectValue:as]; 430 [field_ setObjectValue:as];
431
432 // TODO(shess): This may be an appropriate place to call:
433 // controller_->OnChanged();
434 // In the current implementation, this tells LocationBarViewMac to
435 // mess around with |model_| and update |field_|. Unfortunately,
436 // when I look at our peer implementations, it's not entirely clear
437 // to me if this is safe. SetText() is sort of an utility method,
438 // and different callers sometimes have different needs. Research
439 // this issue so that it can be added safely.
440
441 // TODO(shess): Also, consider whether this code couldn't just
442 // manage things directly. Windows uses a series of overlaid view
443 // objects to accomplish the hinting stuff that OnChanged() does, so
444 // it makes sense to have it in the controller that lays those
445 // things out. Mac instead pushes the support into a custom
446 // text-field implementation.
430 } 447 }
431 448
432 void AutocompleteEditViewMac::SetTextAndSelectedRange( 449 void AutocompleteEditViewMac::SetTextAndSelectedRange(
433 const std::wstring& display_text, const NSRange range) { 450 const std::wstring& display_text, const NSRange range) {
434 SetText(display_text); 451 SetText(display_text);
435 SetSelectedRange(range); 452 SetSelectedRange(range);
436 } 453 }
437 454
438 void AutocompleteEditViewMac::EmphasizeURLComponents() { 455 void AutocompleteEditViewMac::EmphasizeURLComponents() {
439 if ([field_ currentEditor]) { 456 if ([field_ currentEditor]) {
440 SetTextAndSelectedRange(GetText(), GetSelectedRange()); 457 SetTextAndSelectedRange(GetText(), GetSelectedRange());
441 } else { 458 } else {
442 SetText(GetText()); 459 SetText(GetText());
443 } 460 }
444 } 461 }
445 462
446 void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged( 463 void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged(
447 const std::wstring& display_text, bool save_original_selection) { 464 const std::wstring& display_text, bool save_original_selection) {
448 // TODO(shess): I believe this is for when the user arrows around 465 // TODO(shess): I believe this is for when the user arrows around
449 // the popup, will be restored if they hit escape. Figure out if 466 // the popup, will be restored if they hit escape. Figure out if
450 // that is for certain it. 467 // that is for certain it.
451 if (save_original_selection) { 468 if (save_original_selection) {
452 saved_temporary_selection_ = GetSelectedRange(); 469 saved_temporary_selection_ = GetSelectedRange();
453 saved_temporary_text_ = GetText(); 470 saved_temporary_text_ = GetText();
454 } 471 }
455 472
456 SetWindowTextAndCaretPos(display_text, display_text.size()); 473 SetWindowTextAndCaretPos(display_text, display_text.size());
474 controller_->OnChanged();
457 } 475 }
458 476
459 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( 477 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged(
460 const std::wstring& display_text, size_t user_text_length) { 478 const std::wstring& display_text, size_t user_text_length) {
461 // TODO(shess): Make sure that this actually works. The round trip 479 // TODO(shess): Make sure that this actually works. The round trip
462 // to native form and back may mean that it's the same but not the 480 // to native form and back may mean that it's the same but not the
463 // same. 481 // same.
464 if (display_text == GetText()) { 482 if (display_text == GetText()) {
465 return false; 483 return false;
466 } 484 }
467 485
468 DCHECK_LE(user_text_length, display_text.size()); 486 DCHECK_LE(user_text_length, display_text.size());
469 const NSRange range = NSMakeRange(user_text_length, display_text.size()); 487 const NSRange range = NSMakeRange(user_text_length, display_text.size());
470 SetTextAndSelectedRange(display_text, range); 488 SetTextAndSelectedRange(display_text, range);
489 controller_->OnChanged();
471 490
472 return true; 491 return true;
473 } 492 }
474 493
475 void AutocompleteEditViewMac::OnRevertTemporaryText() { 494 void AutocompleteEditViewMac::OnRevertTemporaryText() {
476 SetTextAndSelectedRange(saved_temporary_text_, saved_temporary_selection_); 495 SetTextAndSelectedRange(saved_temporary_text_, saved_temporary_selection_);
477 saved_temporary_text_.clear(); 496 saved_temporary_text_.clear();
478 } 497 }
479 498
480 bool AutocompleteEditViewMac::IsFirstResponder() const { 499 bool AutocompleteEditViewMac::IsFirstResponder() const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
518 537
519 const bool something_changed = model_->OnAfterPossibleChange(new_text, 538 const bool something_changed = model_->OnAfterPossibleChange(new_text,
520 selection_differs, text_differs, just_deleted_text, at_end_of_edit); 539 selection_differs, text_differs, just_deleted_text, at_end_of_edit);
521 540
522 // Restyle in case the user changed something. 541 // Restyle in case the user changed something.
523 // TODO(shess): I believe there are multiple-redraw cases, here. 542 // TODO(shess): I believe there are multiple-redraw cases, here.
524 // Linux watches for something_changed && text_differs, but that 543 // Linux watches for something_changed && text_differs, but that
525 // fails for us in case you copy the URL and paste the identical URL 544 // fails for us in case you copy the URL and paste the identical URL
526 // back (we'll lose the styling). 545 // back (we'll lose the styling).
527 EmphasizeURLComponents(); 546 EmphasizeURLComponents();
547 controller_->OnChanged();
528 548
529 return something_changed; 549 return something_changed;
530 } 550 }
531 551
532 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const { 552 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const {
533 return field_; 553 return field_;
534 } 554 }
535 555
536 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) { 556 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) {
537 // We should only arrive here when the field is focussed. 557 // We should only arrive here when the field is focussed.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
607 627
608 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) { 628 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) {
609 model_->OnControlKeyChanged(pressed); 629 model_->OnControlKeyChanged(pressed);
610 } 630 }
611 631
612 void AutocompleteEditViewMac::AcceptInput( 632 void AutocompleteEditViewMac::AcceptInput(
613 WindowOpenDisposition disposition, bool for_drop) { 633 WindowOpenDisposition disposition, bool for_drop) {
614 model_->AcceptInput(disposition, for_drop); 634 model_->AcceptInput(disposition, for_drop);
615 } 635 }
616 636
637 void AutocompleteEditViewMac::AcceptKeyword() {
638 model_->AcceptKeyword();
639 }
640
617 void AutocompleteEditViewMac::FocusLocation() { 641 void AutocompleteEditViewMac::FocusLocation() {
618 [[field_ window] makeFirstResponder:field_]; 642 [[field_ window] makeFirstResponder:field_];
619 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); 643 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]);
620 } 644 }
621 645
622 // TODO(shess): Copied from autocomplete_edit_view_win.cc. Could this 646 // TODO(shess): Copied from autocomplete_edit_view_win.cc. Could this
623 // be pushed into the model? 647 // be pushed into the model?
624 std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) { 648 std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
625 // autocomplete_edit_view_win.cc assumes this can never happen, we 649 // autocomplete_edit_view_win.cc assumes this can never happen, we
626 // will too. 650 // will too.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
692 if (cmd == @selector(scrollPageUp:)) { 716 if (cmd == @selector(scrollPageUp:)) {
693 edit_view_->OnUpOrDownKeyPressed(true, true); 717 edit_view_->OnUpOrDownKeyPressed(true, true);
694 return YES; 718 return YES;
695 } 719 }
696 720
697 if (cmd == @selector(cancelOperation:)) { 721 if (cmd == @selector(cancelOperation:)) {
698 edit_view_->OnEscapeKeyPressed(); 722 edit_view_->OnEscapeKeyPressed();
699 return YES; 723 return YES;
700 } 724 }
701 725
726 if (cmd == @selector(insertTab:)) {
727 edit_view_->AcceptKeyword();
728 return YES;
729 }
730
702 // |-noop:| is sent when the user presses Cmd+Return. Override the no-op 731 // |-noop:| is sent when the user presses Cmd+Return. Override the no-op
703 // behavior with the proper WindowOpenDisposition. 732 // behavior with the proper WindowOpenDisposition.
704 NSEvent* event = [NSApp currentEvent]; 733 NSEvent* event = [NSApp currentEvent];
705 if (cmd == @selector(insertNewline:) || 734 if (cmd == @selector(insertNewline:) ||
706 (cmd == @selector(noop:) && [event keyCode] == kVK_Return)) { 735 (cmd == @selector(noop:) && [event keyCode] == kVK_Return)) {
707 WindowOpenDisposition disposition = 736 WindowOpenDisposition disposition =
708 event_utils::WindowOpenDispositionFromNSEvent(event); 737 event_utils::WindowOpenDispositionFromNSEvent(event);
709 edit_view_->AcceptInput(disposition, false); 738 edit_view_->AcceptInput(disposition, false);
710 return YES; 739 return YES;
711 } 740 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
771 // prepended and ".com" appended. This calls down to 800 // prepended and ".com" appended. This calls down to
772 // AutocompleteEditModel::OnControlKeyChanged() so that it can change 801 // AutocompleteEditModel::OnControlKeyChanged() so that it can change
773 // the popup to reflect this. See autocomplete_edit.cc 802 // the popup to reflect this. See autocomplete_edit.cc
774 // OnControlKeyChanged() and OnAfterPossibleChange(). 803 // OnControlKeyChanged() and OnAfterPossibleChange().
775 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { 804 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent {
776 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; 805 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0;
777 edit_view_->OnControlKeyChanged(controlFlag); 806 edit_view_->OnControlKeyChanged(controlFlag);
778 } 807 }
779 808
780 @end 809 @end
OLDNEW
« no previous file with comments | « chrome/browser/autocomplete/autocomplete_edit_view_mac.h ('k') | chrome/browser/cocoa/autocomplete_text_field.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698