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

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

Issue 159250: [Mac] Omnibox keyword, keyword hint, and search hint support. (Closed)
Patch Set: Get rid of funky cells and other comment responses. 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
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 "app/gfx/font.h" 7 #include "app/gfx/font.h"
8 #include "app/resource_bundle.h" 8 #include "app/resource_bundle.h"
9 #include "base/clipboard.h" 9 #include "base/clipboard.h"
10 #include "base/string_util.h" 10 #include "base/string_util.h"
(...skipping 272 matching lines...) Expand 10 before | Expand all | Expand 10 after
283 void AutocompleteEditViewMac::SetUserText(const std::wstring& text, 283 void AutocompleteEditViewMac::SetUserText(const std::wstring& text,
284 const std::wstring& display_text, 284 const std::wstring& display_text,
285 bool update_popup) { 285 bool update_popup) {
286 model_->SetUserText(text); 286 model_->SetUserText(text);
287 // TODO(shess): TODO below from gtk. 287 // TODO(shess): TODO below from gtk.
288 // TODO(deanm): something about selection / focus change here. 288 // TODO(deanm): something about selection / focus change here.
289 SetText(display_text); 289 SetText(display_text);
290 if (update_popup) { 290 if (update_popup) {
291 UpdatePopup(); 291 UpdatePopup();
292 } 292 }
293 controller_->OnChanged();
293 } 294 }
294 295
295 NSRange AutocompleteEditViewMac::GetSelectedRange() const { 296 NSRange AutocompleteEditViewMac::GetSelectedRange() const {
296 DCHECK([field_ currentEditor]); 297 DCHECK([field_ currentEditor]);
297 return [[field_ currentEditor] selectedRange]; 298 return [[field_ currentEditor] selectedRange];
298 } 299 }
299 300
300 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) { 301 void AutocompleteEditViewMac::SetSelectedRange(const NSRange range) {
301 // This can be called when we don't have focus. For instance, when 302 // This can be called when we don't have focus. For instance, when
302 // the user clicks the "Go" button. 303 // the user clicks the "Go" button.
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
406 if (scheme_security_level == ToolbarModel::SECURE) { 407 if (scheme_security_level == ToolbarModel::SECURE) {
407 color = SecureSchemeColor(); 408 color = SecureSchemeColor();
408 } else { 409 } else {
409 color = InsecureSchemeColor(); 410 color = InsecureSchemeColor();
410 } 411 }
411 [as addAttribute:NSForegroundColorAttributeName value:color 412 [as addAttribute:NSForegroundColorAttributeName value:color
412 range:ComponentToNSRange(parts.scheme)]; 413 range:ComponentToNSRange(parts.scheme)];
413 } 414 }
414 415
415 [field_ setObjectValue:as]; 416 [field_ setObjectValue:as];
417
418 // TODO(shess): This may be an appropriate place to call:
419 // controller_->OnChanged();
420 // In the current implementation, this tells LocationBarViewMac to
421 // mess around with |model_| and update |field_|. Unfortunately,
422 // when I look at our peer implementations, it's not entirely clear
423 // to me if this is safe. SetText() is sort of an utility method,
424 // and different callers sometimes have different needs. Research
425 // this issue so that it can be added safely.
426
427 // TODO(shess): Also, consider whether this code couldn't just
428 // manage things directly. Windows uses a series of overlaid view
429 // objects to accomplish the hinting stuff that OnChanged() does, so
430 // it makes sense to have it in the controller that lays those
431 // things out. Mac instead pushes the support into a custom
432 // text-field implementation.
416 } 433 }
417 434
418 void AutocompleteEditViewMac::SetTextAndSelectedRange( 435 void AutocompleteEditViewMac::SetTextAndSelectedRange(
419 const std::wstring& display_text, const NSRange range) { 436 const std::wstring& display_text, const NSRange range) {
420 SetText(display_text); 437 SetText(display_text);
421 SetSelectedRange(range); 438 SetSelectedRange(range);
422 } 439 }
423 440
424 void AutocompleteEditViewMac::EmphasizeURLComponents() { 441 void AutocompleteEditViewMac::EmphasizeURLComponents() {
425 if ([field_ currentEditor]) { 442 if ([field_ currentEditor]) {
426 SetTextAndSelectedRange(GetText(), GetSelectedRange()); 443 SetTextAndSelectedRange(GetText(), GetSelectedRange());
427 } else { 444 } else {
428 SetText(GetText()); 445 SetText(GetText());
429 } 446 }
430 } 447 }
431 448
432 void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged( 449 void AutocompleteEditViewMac::OnTemporaryTextMaybeChanged(
433 const std::wstring& display_text, bool save_original_selection) { 450 const std::wstring& display_text, bool save_original_selection) {
434 // TODO(shess): I believe this is for when the user arrows around 451 // TODO(shess): I believe this is for when the user arrows around
435 // the popup, will be restored if they hit escape. Figure out if 452 // the popup, will be restored if they hit escape. Figure out if
436 // that is for certain it. 453 // that is for certain it.
437 if (save_original_selection) { 454 if (save_original_selection) {
438 saved_temporary_selection_ = GetSelectedRange(); 455 saved_temporary_selection_ = GetSelectedRange();
439 saved_temporary_text_ = GetText(); 456 saved_temporary_text_ = GetText();
440 } 457 }
441 458
442 SetWindowTextAndCaretPos(display_text, display_text.size()); 459 SetWindowTextAndCaretPos(display_text, display_text.size());
460 controller_->OnChanged();
443 } 461 }
444 462
445 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged( 463 bool AutocompleteEditViewMac::OnInlineAutocompleteTextMaybeChanged(
446 const std::wstring& display_text, size_t user_text_length) { 464 const std::wstring& display_text, size_t user_text_length) {
447 // TODO(shess): Make sure that this actually works. The round trip 465 // TODO(shess): Make sure that this actually works. The round trip
448 // to native form and back may mean that it's the same but not the 466 // to native form and back may mean that it's the same but not the
449 // same. 467 // same.
450 if (display_text == GetText()) { 468 if (display_text == GetText()) {
451 return false; 469 return false;
452 } 470 }
453 471
454 DCHECK_LE(user_text_length, display_text.size()); 472 DCHECK_LE(user_text_length, display_text.size());
455 const NSRange range = NSMakeRange(user_text_length, display_text.size()); 473 const NSRange range = NSMakeRange(user_text_length, display_text.size());
456 SetTextAndSelectedRange(display_text, range); 474 SetTextAndSelectedRange(display_text, range);
475 controller_->OnChanged();
457 476
458 return true; 477 return true;
459 } 478 }
460 479
461 void AutocompleteEditViewMac::OnRevertTemporaryText() { 480 void AutocompleteEditViewMac::OnRevertTemporaryText() {
462 SetTextAndSelectedRange(saved_temporary_text_, saved_temporary_selection_); 481 SetTextAndSelectedRange(saved_temporary_text_, saved_temporary_selection_);
463 saved_temporary_text_.clear(); 482 saved_temporary_text_.clear();
464 } 483 }
465 484
466 bool AutocompleteEditViewMac::IsFirstResponder() const { 485 bool AutocompleteEditViewMac::IsFirstResponder() const {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
504 523
505 const bool something_changed = model_->OnAfterPossibleChange(new_text, 524 const bool something_changed = model_->OnAfterPossibleChange(new_text,
506 selection_differs, text_differs, just_deleted_text, at_end_of_edit); 525 selection_differs, text_differs, just_deleted_text, at_end_of_edit);
507 526
508 // Restyle in case the user changed something. 527 // Restyle in case the user changed something.
509 // TODO(shess): I believe there are multiple-redraw cases, here. 528 // TODO(shess): I believe there are multiple-redraw cases, here.
510 // Linux watches for something_changed && text_differs, but that 529 // Linux watches for something_changed && text_differs, but that
511 // fails for us in case you copy the URL and paste the identical URL 530 // fails for us in case you copy the URL and paste the identical URL
512 // back (we'll lose the styling). 531 // back (we'll lose the styling).
513 EmphasizeURLComponents(); 532 EmphasizeURLComponents();
533 controller_->OnChanged();
514 534
515 return something_changed; 535 return something_changed;
516 } 536 }
517 537
518 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const { 538 gfx::NativeView AutocompleteEditViewMac::GetNativeView() const {
519 return field_; 539 return field_;
520 } 540 }
521 541
522 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) { 542 void AutocompleteEditViewMac::OnUpOrDownKeyPressed(bool up, bool by_page) {
523 // We should only arrive here when the field is focussed. 543 // We should only arrive here when the field is focussed.
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
593 613
594 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) { 614 void AutocompleteEditViewMac::OnControlKeyChanged(bool pressed) {
595 model_->OnControlKeyChanged(pressed); 615 model_->OnControlKeyChanged(pressed);
596 } 616 }
597 617
598 void AutocompleteEditViewMac::AcceptInput( 618 void AutocompleteEditViewMac::AcceptInput(
599 WindowOpenDisposition disposition, bool for_drop) { 619 WindowOpenDisposition disposition, bool for_drop) {
600 model_->AcceptInput(disposition, for_drop); 620 model_->AcceptInput(disposition, for_drop);
601 } 621 }
602 622
623 void AutocompleteEditViewMac::AcceptKeyword() {
624 model_->AcceptKeyword();
625 }
626
603 void AutocompleteEditViewMac::FocusLocation() { 627 void AutocompleteEditViewMac::FocusLocation() {
604 [[field_ window] makeFirstResponder:field_]; 628 [[field_ window] makeFirstResponder:field_];
605 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]); 629 DCHECK_EQ([field_ currentEditor], [[field_ window] firstResponder]);
606 } 630 }
607 631
608 // TODO(shess): Copied from autocomplete_edit_view_win.cc. Could this 632 // TODO(shess): Copied from autocomplete_edit_view_win.cc. Could this
609 // be pushed into the model? 633 // be pushed into the model?
610 std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) { 634 std::wstring AutocompleteEditViewMac::GetClipboardText(Clipboard* clipboard) {
611 // autocomplete_edit_view_win.cc assumes this can never happen, we 635 // autocomplete_edit_view_win.cc assumes this can never happen, we
612 // will too. 636 // will too.
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
678 if (cmd == @selector(scrollPageUp:)) { 702 if (cmd == @selector(scrollPageUp:)) {
679 edit_view_->OnUpOrDownKeyPressed(true, true); 703 edit_view_->OnUpOrDownKeyPressed(true, true);
680 return YES; 704 return YES;
681 } 705 }
682 706
683 if (cmd == @selector(cancelOperation:)) { 707 if (cmd == @selector(cancelOperation:)) {
684 edit_view_->OnEscapeKeyPressed(); 708 edit_view_->OnEscapeKeyPressed();
685 return YES; 709 return YES;
686 } 710 }
687 711
712 if (cmd == @selector(insertTab:)) {
713 edit_view_->AcceptKeyword();
714 return YES;
715 }
716
688 if (cmd == @selector(insertNewline:)) { 717 if (cmd == @selector(insertNewline:)) {
689 edit_view_->AcceptInput(CURRENT_TAB, false); 718 edit_view_->AcceptInput(CURRENT_TAB, false);
690 return YES; 719 return YES;
691 } 720 }
692 721
693 // When the user does Control-Enter, the existing content has "www." 722 // When the user does Control-Enter, the existing content has "www."
694 // prepended and ".com" appended. |model_| should already have 723 // prepended and ".com" appended. |model_| should already have
695 // received notification when the Control key was depressed, but it 724 // received notification when the Control key was depressed, but it
696 // is safe to tell it twice. 725 // is safe to tell it twice.
697 if (cmd == @selector(insertLineBreak:)) { 726 if (cmd == @selector(insertLineBreak:)) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 // prepended and ".com" appended. This calls down to 778 // prepended and ".com" appended. This calls down to
750 // AutocompleteEditModel::OnControlKeyChanged() so that it can change 779 // AutocompleteEditModel::OnControlKeyChanged() so that it can change
751 // the popup to reflect this. See autocomplete_edit.cc 780 // the popup to reflect this. See autocomplete_edit.cc
752 // OnControlKeyChanged() and OnAfterPossibleChange(). 781 // OnControlKeyChanged() and OnAfterPossibleChange().
753 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent { 782 - (void)control:(NSControl*)control flagsChanged:(NSEvent*)theEvent {
754 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0; 783 BOOL controlFlag = ([theEvent modifierFlags]&NSControlKeyMask) != 0;
755 edit_view_->OnControlKeyChanged(controlFlag); 784 edit_view_->OnControlKeyChanged(controlFlag);
756 } 785 }
757 786
758 @end 787 @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