| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/omnibox/omnibox_view_win.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_win.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <locale> | 8 #include <locale> |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 432 | 432 |
| 433 } // namespace | 433 } // namespace |
| 434 | 434 |
| 435 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, | 435 OmniboxViewWin::OmniboxViewWin(OmniboxEditController* controller, |
| 436 ToolbarModel* toolbar_model, | 436 ToolbarModel* toolbar_model, |
| 437 LocationBarView* parent_view, | 437 LocationBarView* parent_view, |
| 438 CommandUpdater* command_updater, | 438 CommandUpdater* command_updater, |
| 439 bool popup_window_mode, | 439 bool popup_window_mode, |
| 440 views::View* location_bar, | 440 views::View* location_bar, |
| 441 views::View* popup_parent_view) | 441 views::View* popup_parent_view) |
| 442 : model_(new OmniboxEditModel(this, controller, parent_view->profile())), | 442 : OmniboxView(parent_view->profile(), controller, toolbar_model, |
| 443 command_updater), |
| 443 popup_view_(OmniboxPopupContentsView::Create( | 444 popup_view_(OmniboxPopupContentsView::Create( |
| 444 parent_view->font(), this, model_.get(), location_bar, | 445 parent_view->font(), this, model(), location_bar, |
| 445 popup_parent_view)), | 446 popup_parent_view)), |
| 446 controller_(controller), | |
| 447 parent_view_(parent_view), | 447 parent_view_(parent_view), |
| 448 toolbar_model_(toolbar_model), | |
| 449 command_updater_(command_updater), | |
| 450 popup_window_mode_(popup_window_mode), | 448 popup_window_mode_(popup_window_mode), |
| 451 force_hidden_(false), | 449 force_hidden_(false), |
| 452 tracking_click_(), | 450 tracking_click_(), |
| 453 tracking_double_click_(false), | 451 tracking_double_click_(false), |
| 454 double_click_time_(0), | 452 double_click_time_(0), |
| 455 can_discard_mousemove_(false), | 453 can_discard_mousemove_(false), |
| 456 ignore_ime_messages_(false), | 454 ignore_ime_messages_(false), |
| 457 delete_at_end_pressed_(false), | 455 delete_at_end_pressed_(false), |
| 458 font_(parent_view->font()), | 456 font_(parent_view->font()), |
| 459 possible_drag_(false), | 457 possible_drag_(false), |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 539 g_paint_patcher.Pointer()->DerefPatch(); | 537 g_paint_patcher.Pointer()->DerefPatch(); |
| 540 } | 538 } |
| 541 | 539 |
| 542 views::View* OmniboxViewWin::parent_view() const { | 540 views::View* OmniboxViewWin::parent_view() const { |
| 543 return parent_view_; | 541 return parent_view_; |
| 544 } | 542 } |
| 545 | 543 |
| 546 void OmniboxViewWin::SaveStateToTab(WebContents* tab) { | 544 void OmniboxViewWin::SaveStateToTab(WebContents* tab) { |
| 547 DCHECK(tab); | 545 DCHECK(tab); |
| 548 | 546 |
| 549 const OmniboxEditModel::State model_state(model_->GetStateForTabSwitch()); | 547 const OmniboxEditModel::State model_state(model()->GetStateForTabSwitch()); |
| 550 | 548 |
| 551 CHARRANGE selection; | 549 CHARRANGE selection; |
| 552 GetSelection(selection); | 550 GetSelection(selection); |
| 553 GetStateAccessor()->SetProperty(tab->GetPropertyBag(), | 551 GetStateAccessor()->SetProperty(tab->GetPropertyBag(), |
| 554 AutocompleteEditState( | 552 AutocompleteEditState( |
| 555 model_state, | 553 model_state, |
| 556 State(selection, saved_selection_for_focus_change_))); | 554 State(selection, saved_selection_for_focus_change_))); |
| 557 } | 555 } |
| 558 | 556 |
| 559 void OmniboxViewWin::Update(const WebContents* tab_for_state_restoring) { | 557 void OmniboxViewWin::Update(const WebContents* tab_for_state_restoring) { |
| 560 const bool visibly_changed_permanent_text = | 558 const bool visibly_changed_permanent_text = |
| 561 model_->UpdatePermanentText(toolbar_model_->GetText()); | 559 model()->UpdatePermanentText(toolbar_model()->GetText()); |
| 562 | 560 |
| 563 const ToolbarModel::SecurityLevel security_level = | 561 const ToolbarModel::SecurityLevel security_level = |
| 564 toolbar_model_->GetSecurityLevel(); | 562 toolbar_model()->GetSecurityLevel(); |
| 565 const bool changed_security_level = (security_level != security_level_); | 563 const bool changed_security_level = (security_level != security_level_); |
| 566 | 564 |
| 567 // Bail early when no visible state will actually change (prevents an | 565 // Bail early when no visible state will actually change (prevents an |
| 568 // unnecessary ScopedFreeze, and thus UpdateWindow()). | 566 // unnecessary ScopedFreeze, and thus UpdateWindow()). |
| 569 if (!changed_security_level && !visibly_changed_permanent_text && | 567 if (!changed_security_level && !visibly_changed_permanent_text && |
| 570 !tab_for_state_restoring) | 568 !tab_for_state_restoring) |
| 571 return; | 569 return; |
| 572 | 570 |
| 573 // Update our local state as desired. We set security_level_ here so it will | 571 // Update our local state as desired. We set security_level_ here so it will |
| 574 // already be correct before we get to any RevertAll()s below and use it. | 572 // already be correct before we get to any RevertAll()s below and use it. |
| 575 security_level_ = security_level; | 573 security_level_ = security_level; |
| 576 | 574 |
| 577 // When we're switching to a new tab, restore its state, if any. | 575 // When we're switching to a new tab, restore its state, if any. |
| 578 ScopedFreeze freeze(this, GetTextObjectModel()); | 576 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 579 if (tab_for_state_restoring) { | 577 if (tab_for_state_restoring) { |
| 580 // Make sure we reset our own state first. The new tab may not have any | 578 // Make sure we reset our own state first. The new tab may not have any |
| 581 // saved state, or it may not have had input in progress, in which case we | 579 // saved state, or it may not have had input in progress, in which case we |
| 582 // won't overwrite all our local state. | 580 // won't overwrite all our local state. |
| 583 RevertAll(); | 581 RevertAll(); |
| 584 | 582 |
| 585 const AutocompleteEditState* state = GetStateAccessor()->GetProperty( | 583 const AutocompleteEditState* state = GetStateAccessor()->GetProperty( |
| 586 tab_for_state_restoring->GetPropertyBag()); | 584 tab_for_state_restoring->GetPropertyBag()); |
| 587 if (state) { | 585 if (state) { |
| 588 model_->RestoreState(state->model_state); | 586 model()->RestoreState(state->model_state); |
| 589 | 587 |
| 590 // Restore user's selection. We do this after restoring the user_text | 588 // Restore user's selection. We do this after restoring the user_text |
| 591 // above so we're selecting in the correct string. | 589 // above so we're selecting in the correct string. |
| 592 SetSelectionRange(state->view_state.selection); | 590 SetSelectionRange(state->view_state.selection); |
| 593 saved_selection_for_focus_change_ = | 591 saved_selection_for_focus_change_ = |
| 594 state->view_state.saved_selection_for_focus_change; | 592 state->view_state.saved_selection_for_focus_change; |
| 595 } | 593 } |
| 596 } else if (visibly_changed_permanent_text) { | 594 } else if (visibly_changed_permanent_text) { |
| 597 // Not switching tabs, just updating the permanent text. (In the case where | 595 // Not switching tabs, just updating the permanent text. (In the case where |
| 598 // we _were_ switching tabs, the RevertAll() above already drew the new | 596 // we _were_ switching tabs, the RevertAll() above already drew the new |
| (...skipping 22 matching lines...) Expand all Loading... |
| 621 } else if (changed_security_level) { | 619 } else if (changed_security_level) { |
| 622 // Only the security style changed, nothing else. Redraw our text using it. | 620 // Only the security style changed, nothing else. Redraw our text using it. |
| 623 EmphasizeURLComponents(); | 621 EmphasizeURLComponents(); |
| 624 } | 622 } |
| 625 } | 623 } |
| 626 | 624 |
| 627 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, | 625 void OmniboxViewWin::OpenMatch(const AutocompleteMatch& match, |
| 628 WindowOpenDisposition disposition, | 626 WindowOpenDisposition disposition, |
| 629 const GURL& alternate_nav_url, | 627 const GURL& alternate_nav_url, |
| 630 size_t selected_line) { | 628 size_t selected_line) { |
| 631 if (!match.destination_url.is_valid()) | |
| 632 return; | |
| 633 | |
| 634 // When we navigate, we first revert to the unedited state, then if necessary | 629 // When we navigate, we first revert to the unedited state, then if necessary |
| 635 // synchronously change the permanent text to the new URL. If we don't freeze | 630 // synchronously change the permanent text to the new URL. If we don't freeze |
| 636 // here, the user could potentially see a flicker of the current URL before | 631 // here, the user could potentially see a flicker of the current URL before |
| 637 // the new one reappears, which would look glitchy. | 632 // the new one reappears, which would look glitchy. |
| 638 ScopedFreeze freeze(this, GetTextObjectModel()); | 633 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 639 model_->OpenMatch(match, disposition, alternate_nav_url, selected_line); | 634 OmniboxView::OpenMatch(match, disposition, alternate_nav_url, selected_line); |
| 640 } | 635 } |
| 641 | 636 |
| 642 string16 OmniboxViewWin::GetText() const { | 637 string16 OmniboxViewWin::GetText() const { |
| 643 const int len = GetTextLength() + 1; | 638 const int len = GetTextLength() + 1; |
| 644 string16 str; | 639 string16 str; |
| 645 if (len > 1) | 640 if (len > 1) |
| 646 GetWindowText(WriteInto(&str, len), len); | 641 GetWindowText(WriteInto(&str, len), len); |
| 647 return str; | 642 return str; |
| 648 } | 643 } |
| 649 | 644 |
| 650 bool OmniboxViewWin::IsEditingOrEmpty() const { | |
| 651 return model_->user_input_in_progress() || (GetTextLength() == 0); | |
| 652 } | |
| 653 | |
| 654 int OmniboxViewWin::GetIcon() const { | |
| 655 return IsEditingOrEmpty() ? | |
| 656 AutocompleteMatch::TypeToIcon(model_->CurrentTextType()) : | |
| 657 toolbar_model_->GetIcon(); | |
| 658 } | |
| 659 | |
| 660 void OmniboxViewWin::SetUserText(const string16& text) { | |
| 661 SetUserText(text, text, true); | |
| 662 } | |
| 663 | |
| 664 void OmniboxViewWin::SetUserText(const string16& text, | 645 void OmniboxViewWin::SetUserText(const string16& text, |
| 665 const string16& display_text, | 646 const string16& display_text, |
| 666 bool update_popup) { | 647 bool update_popup) { |
| 667 ScopedFreeze freeze(this, GetTextObjectModel()); | 648 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 668 model_->SetUserText(text); | |
| 669 saved_selection_for_focus_change_.cpMin = -1; | 649 saved_selection_for_focus_change_.cpMin = -1; |
| 670 SetWindowTextAndCaretPos(display_text, display_text.length(), update_popup, | 650 OmniboxView::SetUserText(text, display_text, update_popup); |
| 671 true); | |
| 672 } | 651 } |
| 673 | 652 |
| 674 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, | 653 void OmniboxViewWin::SetWindowTextAndCaretPos(const string16& text, |
| 675 size_t caret_pos, | 654 size_t caret_pos, |
| 676 bool update_popup, | 655 bool update_popup, |
| 677 bool notify_text_changed) { | 656 bool notify_text_changed) { |
| 678 SetWindowText(text.c_str()); | 657 SetWindowText(text.c_str()); |
| 679 PlaceCaretAt(caret_pos); | 658 PlaceCaretAt(caret_pos); |
| 680 | 659 |
| 681 if (update_popup) | 660 if (update_popup) |
| 682 UpdatePopup(); | 661 UpdatePopup(); |
| 683 | 662 |
| 684 if (notify_text_changed) | 663 if (notify_text_changed) |
| 685 TextChanged(); | 664 TextChanged(); |
| 686 } | 665 } |
| 687 | 666 |
| 688 void OmniboxViewWin::SetForcedQuery() { | 667 void OmniboxViewWin::SetForcedQuery() { |
| 689 const string16 current_text(GetText()); | 668 const string16 current_text(GetText()); |
| 690 const size_t start = current_text.find_first_not_of(kWhitespaceWide); | 669 const size_t start = current_text.find_first_not_of(kWhitespaceWide); |
| 691 if (start == string16::npos || (current_text[start] != '?')) | 670 if (start == string16::npos || (current_text[start] != '?')) |
| 692 SetUserText(L"?"); | 671 OmniboxView::SetUserText(L"?"); |
| 693 else | 672 else |
| 694 SetSelection(current_text.length(), start + 1); | 673 SetSelection(current_text.length(), start + 1); |
| 695 } | 674 } |
| 696 | 675 |
| 697 bool OmniboxViewWin::IsSelectAll() const { | 676 bool OmniboxViewWin::IsSelectAll() const { |
| 698 CHARRANGE selection; | 677 CHARRANGE selection; |
| 699 GetSel(selection); | 678 GetSel(selection); |
| 700 return IsSelectAllForRange(selection); | 679 return IsSelectAllForRange(selection); |
| 701 } | 680 } |
| 702 | 681 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 714 | 693 |
| 715 void OmniboxViewWin::SelectAll(bool reversed) { | 694 void OmniboxViewWin::SelectAll(bool reversed) { |
| 716 if (reversed) | 695 if (reversed) |
| 717 SetSelection(GetTextLength(), 0); | 696 SetSelection(GetTextLength(), 0); |
| 718 else | 697 else |
| 719 SetSelection(0, GetTextLength()); | 698 SetSelection(0, GetTextLength()); |
| 720 } | 699 } |
| 721 | 700 |
| 722 void OmniboxViewWin::RevertAll() { | 701 void OmniboxViewWin::RevertAll() { |
| 723 ScopedFreeze freeze(this, GetTextObjectModel()); | 702 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 724 ClosePopup(); | |
| 725 saved_selection_for_focus_change_.cpMin = -1; | 703 saved_selection_for_focus_change_.cpMin = -1; |
| 726 model_->Revert(); | 704 OmniboxView::RevertAll(); |
| 727 } | 705 } |
| 728 | 706 |
| 729 void OmniboxViewWin::UpdatePopup() { | 707 void OmniboxViewWin::UpdatePopup() { |
| 730 ScopedFreeze freeze(this, GetTextObjectModel()); | 708 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 731 model_->SetInputInProgress(true); | 709 model()->SetInputInProgress(true); |
| 732 | 710 |
| 733 // Don't allow the popup to open while the candidate window is open, so | 711 // Don't allow the popup to open while the candidate window is open, so |
| 734 // they don't overlap. | 712 // they don't overlap. |
| 735 if (ime_candidate_window_open_) | 713 if (ime_candidate_window_open_) |
| 736 return; | 714 return; |
| 737 | 715 |
| 738 if (!model_->has_focus()) { | 716 if (!model()->has_focus()) { |
| 739 // When we're in the midst of losing focus, don't rerun autocomplete. This | 717 // When we're in the midst of losing focus, don't rerun autocomplete. This |
| 740 // can happen when losing focus causes the IME to cancel/finalize a | 718 // can happen when losing focus causes the IME to cancel/finalize a |
| 741 // composition. We still want to note that user input is in progress, we | 719 // composition. We still want to note that user input is in progress, we |
| 742 // just don't want to do anything else. | 720 // just don't want to do anything else. |
| 743 // | 721 // |
| 744 // Note that in this case the ScopedFreeze above was unnecessary; however, | 722 // Note that in this case the ScopedFreeze above was unnecessary; however, |
| 745 // we're inside the callstack of OnKillFocus(), which has already frozen the | 723 // we're inside the callstack of OnKillFocus(), which has already frozen the |
| 746 // edit, so this will never result in an unnecessary UpdateWindow() call. | 724 // edit, so this will never result in an unnecessary UpdateWindow() call. |
| 747 return; | 725 return; |
| 748 } | 726 } |
| 749 | 727 |
| 750 // Don't inline autocomplete when: | 728 // Don't inline autocomplete when: |
| 751 // * The user is deleting text | 729 // * The user is deleting text |
| 752 // * The caret/selection isn't at the end of the text | 730 // * The caret/selection isn't at the end of the text |
| 753 // * The user has just pasted in something that replaced all the text | 731 // * The user has just pasted in something that replaced all the text |
| 754 // * The user is trying to compose something in an IME | 732 // * The user is trying to compose something in an IME |
| 755 CHARRANGE sel; | 733 CHARRANGE sel; |
| 756 GetSel(sel); | 734 GetSel(sel); |
| 757 model_->StartAutocomplete(sel.cpMax != sel.cpMin, | 735 model()->StartAutocomplete(sel.cpMax != sel.cpMin, |
| 758 (sel.cpMax < GetTextLength()) || IsImeComposing()); | 736 (sel.cpMax < GetTextLength()) || IsImeComposing()); |
| 759 } | 737 } |
| 760 | 738 |
| 761 void OmniboxViewWin::ClosePopup() { | |
| 762 model_->StopAutocomplete(); | |
| 763 } | |
| 764 | |
| 765 void OmniboxViewWin::SetFocus() { | 739 void OmniboxViewWin::SetFocus() { |
| 766 ::SetFocus(m_hWnd); | 740 ::SetFocus(m_hWnd); |
| 767 } | 741 } |
| 768 | 742 |
| 769 void OmniboxViewWin::SetDropHighlightPosition(int position) { | 743 void OmniboxViewWin::SetDropHighlightPosition(int position) { |
| 770 if (drop_highlight_position_ != position) { | 744 if (drop_highlight_position_ != position) { |
| 771 RepaintDropHighlight(drop_highlight_position_); | 745 RepaintDropHighlight(drop_highlight_position_); |
| 772 drop_highlight_position_ = position; | 746 drop_highlight_position_ = position; |
| 773 RepaintDropHighlight(drop_highlight_position_); | 747 RepaintDropHighlight(drop_highlight_position_); |
| 774 } | 748 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 885 // When the user has deleted text, we don't allow inline autocomplete. Make | 859 // When the user has deleted text, we don't allow inline autocomplete. Make |
| 886 // sure to not flag cases like selecting part of the text and then pasting | 860 // sure to not flag cases like selecting part of the text and then pasting |
| 887 // (or typing) the prefix of that selection. (We detect these by making | 861 // (or typing) the prefix of that selection. (We detect these by making |
| 888 // sure the caret, which should be after any insertion, hasn't moved | 862 // sure the caret, which should be after any insertion, hasn't moved |
| 889 // forward of the old selection start.) | 863 // forward of the old selection start.) |
| 890 const bool just_deleted_text = | 864 const bool just_deleted_text = |
| 891 (text_before_change_.length() > new_text.length()) && | 865 (text_before_change_.length() > new_text.length()) && |
| 892 (new_sel.cpMin <= std::min(sel_before_change_.cpMin, | 866 (new_sel.cpMin <= std::min(sel_before_change_.cpMin, |
| 893 sel_before_change_.cpMax)); | 867 sel_before_change_.cpMax)); |
| 894 | 868 |
| 895 const bool something_changed = model_->OnAfterPossibleChange( | 869 const bool something_changed = model()->OnAfterPossibleChange( |
| 896 text_before_change_, new_text, new_sel.cpMin, new_sel.cpMax, | 870 text_before_change_, new_text, new_sel.cpMin, new_sel.cpMax, |
| 897 selection_differs, text_differs, just_deleted_text, !IsImeComposing()); | 871 selection_differs, text_differs, just_deleted_text, !IsImeComposing()); |
| 898 | 872 |
| 899 if (selection_differs) | 873 if (selection_differs) |
| 900 controller_->OnSelectionBoundsChanged(); | 874 controller()->OnSelectionBoundsChanged(); |
| 901 | 875 |
| 902 if (something_changed && text_differs) | 876 if (something_changed && text_differs) |
| 903 TextChanged(); | 877 TextChanged(); |
| 904 | 878 |
| 905 if (text_differs) { | 879 if (text_differs) { |
| 906 // Note that a TEXT_CHANGED event implies that the cursor/selection | 880 // Note that a TEXT_CHANGED event implies that the cursor/selection |
| 907 // probably changed too, so we don't need to send both. | 881 // probably changed too, so we don't need to send both. |
| 908 native_view_host_->GetWidget()->NotifyAccessibilityEvent( | 882 native_view_host_->GetWidget()->NotifyAccessibilityEvent( |
| 909 native_view_host_, ui::AccessibilityTypes::EVENT_TEXT_CHANGED, true); | 883 native_view_host_, ui::AccessibilityTypes::EVENT_TEXT_CHANGED, true); |
| 910 } else if (selection_differs) { | 884 } else if (selection_differs) { |
| 911 // Notify assistive technology that the cursor or selection changed. | 885 // Notify assistive technology that the cursor or selection changed. |
| 912 native_view_host_->GetWidget()->NotifyAccessibilityEvent( | 886 native_view_host_->GetWidget()->NotifyAccessibilityEvent( |
| 913 native_view_host_, | 887 native_view_host_, |
| 914 ui::AccessibilityTypes::EVENT_SELECTION_CHANGED, | 888 ui::AccessibilityTypes::EVENT_SELECTION_CHANGED, |
| 915 true); | 889 true); |
| 916 } else if (delete_at_end_pressed_) { | 890 } else if (delete_at_end_pressed_) { |
| 917 model_->OnChanged(); | 891 model()->OnChanged(); |
| 918 } | 892 } |
| 919 | 893 |
| 920 return something_changed; | 894 return something_changed; |
| 921 } | 895 } |
| 922 | 896 |
| 923 gfx::NativeView OmniboxViewWin::GetNativeView() const { | 897 gfx::NativeView OmniboxViewWin::GetNativeView() const { |
| 924 return m_hWnd; | 898 return m_hWnd; |
| 925 } | 899 } |
| 926 | 900 |
| 927 // static | 901 // static |
| 928 gfx::NativeView OmniboxViewWin::GetRelativeWindowForNativeView( | 902 gfx::NativeView OmniboxViewWin::GetRelativeWindowForNativeView( |
| 929 gfx::NativeView edit_native_view) { | 903 gfx::NativeView edit_native_view) { |
| 930 // When an IME is attached to the rich-edit control, retrieve its window | 904 // When an IME is attached to the rich-edit control, retrieve its window |
| 931 // handle, and the popup window of OmniboxPopupView will be shown under the | 905 // handle, and the popup window of OmniboxPopupView will be shown under the |
| 932 // IME windows. | 906 // IME windows. |
| 933 // Otherwise, the popup window will be shown under top-most windows. | 907 // Otherwise, the popup window will be shown under top-most windows. |
| 934 // TODO(hbono): http://b/1111369 if we exclude this popup window from the | 908 // TODO(hbono): http://b/1111369 if we exclude this popup window from the |
| 935 // display area of IME windows, this workaround becomes unnecessary. | 909 // display area of IME windows, this workaround becomes unnecessary. |
| 936 HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); | 910 HWND ime_window = ImmGetDefaultIMEWnd(edit_native_view); |
| 937 return ime_window ? ime_window : HWND_NOTOPMOST; | 911 return ime_window ? ime_window : HWND_NOTOPMOST; |
| 938 } | 912 } |
| 939 | 913 |
| 940 gfx::NativeView OmniboxViewWin::GetRelativeWindowForPopup() const { | 914 gfx::NativeView OmniboxViewWin::GetRelativeWindowForPopup() const { |
| 941 return GetRelativeWindowForNativeView(GetNativeView()); | 915 return GetRelativeWindowForNativeView(GetNativeView()); |
| 942 } | 916 } |
| 943 | 917 |
| 944 CommandUpdater* OmniboxViewWin::GetCommandUpdater() { | |
| 945 return command_updater_; | |
| 946 } | |
| 947 | |
| 948 void OmniboxViewWin::SetInstantSuggestion(const string16& suggestion, | 918 void OmniboxViewWin::SetInstantSuggestion(const string16& suggestion, |
| 949 bool animate_to_complete) { | 919 bool animate_to_complete) { |
| 950 parent_view_->SetInstantSuggestion(suggestion, animate_to_complete); | 920 parent_view_->SetInstantSuggestion(suggestion, animate_to_complete); |
| 951 } | 921 } |
| 952 | 922 |
| 953 int OmniboxViewWin::TextWidth() const { | 923 int OmniboxViewWin::TextWidth() const { |
| 954 return WidthNeededToDisplay(GetText()); | 924 return WidthNeededToDisplay(GetText()); |
| 955 } | 925 } |
| 956 | 926 |
| 957 string16 OmniboxViewWin::GetInstantSuggestion() const { | 927 string16 OmniboxViewWin::GetInstantSuggestion() const { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1003 | 973 |
| 1004 int OmniboxViewWin::OnPerformDropImpl(const views::DropTargetEvent& event, | 974 int OmniboxViewWin::OnPerformDropImpl(const views::DropTargetEvent& event, |
| 1005 bool in_drag) { | 975 bool in_drag) { |
| 1006 const ui::OSExchangeData& data = event.data(); | 976 const ui::OSExchangeData& data = event.data(); |
| 1007 | 977 |
| 1008 if (data.HasURL()) { | 978 if (data.HasURL()) { |
| 1009 GURL url; | 979 GURL url; |
| 1010 string16 title; | 980 string16 title; |
| 1011 if (data.GetURLAndTitle(&url, &title)) { | 981 if (data.GetURLAndTitle(&url, &title)) { |
| 1012 string16 text(StripJavascriptSchemas(UTF8ToUTF16(url.spec()))); | 982 string16 text(StripJavascriptSchemas(UTF8ToUTF16(url.spec()))); |
| 1013 SetUserText(text); | 983 OmniboxView::SetUserText(text); |
| 1014 model()->AcceptInput(CURRENT_TAB, true); | 984 model()->AcceptInput(CURRENT_TAB, true); |
| 1015 return CopyOrLinkDragOperation(event.source_operations()); | 985 return CopyOrLinkDragOperation(event.source_operations()); |
| 1016 } | 986 } |
| 1017 } else if (data.HasString()) { | 987 } else if (data.HasString()) { |
| 1018 int string_drop_position = drop_highlight_position(); | 988 int string_drop_position = drop_highlight_position(); |
| 1019 string16 text; | 989 string16 text; |
| 1020 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) { | 990 if ((string_drop_position != -1 || !in_drag) && data.GetString(&text)) { |
| 1021 DCHECK(string_drop_position == -1 || | 991 DCHECK(string_drop_position == -1 || |
| 1022 ((string_drop_position >= 0) && | 992 ((string_drop_position >= 0) && |
| 1023 (string_drop_position <= GetTextLength()))); | 993 (string_drop_position <= GetTextLength()))); |
| 1024 if (in_drag) { | 994 if (in_drag) { |
| 1025 if (event.source_operations()== ui::DragDropTypes::DRAG_MOVE) | 995 if (event.source_operations()== ui::DragDropTypes::DRAG_MOVE) |
| 1026 MoveSelectedText(string_drop_position); | 996 MoveSelectedText(string_drop_position); |
| 1027 else | 997 else |
| 1028 InsertText(string_drop_position, text); | 998 InsertText(string_drop_position, text); |
| 1029 } else { | 999 } else { |
| 1030 string16 collapsed_text(CollapseWhitespace(text, true)); | 1000 string16 collapsed_text(CollapseWhitespace(text, true)); |
| 1031 if (model_->CanPasteAndGo(collapsed_text)) | 1001 if (model()->CanPasteAndGo(collapsed_text)) |
| 1032 model_->PasteAndGo(collapsed_text); | 1002 model()->PasteAndGo(collapsed_text); |
| 1033 } | 1003 } |
| 1034 return CopyOrLinkDragOperation(event.source_operations()); | 1004 return CopyOrLinkDragOperation(event.source_operations()); |
| 1035 } | 1005 } |
| 1036 } | 1006 } |
| 1037 | 1007 |
| 1038 return ui::DragDropTypes::DRAG_NONE; | 1008 return ui::DragDropTypes::DRAG_NONE; |
| 1039 } | 1009 } |
| 1040 | 1010 |
| 1041 bool OmniboxViewWin::SkipDefaultKeyEventProcessing( | 1011 bool OmniboxViewWin::SkipDefaultKeyEventProcessing( |
| 1042 const views::KeyEvent& event) { | 1012 const views::KeyEvent& event) { |
| 1043 ui::KeyboardCode key = event.key_code(); | 1013 ui::KeyboardCode key = event.key_code(); |
| 1044 // We don't process ALT + numpad digit as accelerators, they are used for | 1014 // We don't process ALT + numpad digit as accelerators, they are used for |
| 1045 // entering special characters. We do translate alt-home. | 1015 // entering special characters. We do translate alt-home. |
| 1046 if (event.IsAltDown() && (key != ui::VKEY_HOME) && | 1016 if (event.IsAltDown() && (key != ui::VKEY_HOME) && |
| 1047 views::NativeTextfieldWin::IsNumPadDigit(key, | 1017 views::NativeTextfieldWin::IsNumPadDigit(key, |
| 1048 (event.flags() & ui::EF_EXTENDED) != 0)) | 1018 (event.flags() & ui::EF_EXTENDED) != 0)) |
| 1049 return true; | 1019 return true; |
| 1050 | 1020 |
| 1051 // Skip accelerators for key combinations omnibox wants to crack. This list | 1021 // Skip accelerators for key combinations omnibox wants to crack. This list |
| 1052 // should be synced with OnKeyDownOnlyWritable() (but for tab which is dealt | 1022 // should be synced with OnKeyDownOnlyWritable() (but for tab which is dealt |
| 1053 // with above in LocationBarView::SkipDefaultKeyEventProcessing). | 1023 // with above in LocationBarView::SkipDefaultKeyEventProcessing). |
| 1054 // | 1024 // |
| 1055 // We cannot return true for all keys because we still need to handle some | 1025 // We cannot return true for all keys because we still need to handle some |
| 1056 // accelerators (e.g., F5 for reload the page should work even when the | 1026 // accelerators (e.g., F5 for reload the page should work even when the |
| 1057 // Omnibox gets focused). | 1027 // Omnibox gets focused). |
| 1058 switch (key) { | 1028 switch (key) { |
| 1059 case ui::VKEY_ESCAPE: { | 1029 case ui::VKEY_ESCAPE: { |
| 1060 ScopedFreeze freeze(this, GetTextObjectModel()); | 1030 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1061 return model_->OnEscapeKeyPressed(); | 1031 return model()->OnEscapeKeyPressed(); |
| 1062 } | 1032 } |
| 1063 | 1033 |
| 1064 case ui::VKEY_RETURN: | 1034 case ui::VKEY_RETURN: |
| 1065 return true; | 1035 return true; |
| 1066 | 1036 |
| 1067 case ui::VKEY_UP: | 1037 case ui::VKEY_UP: |
| 1068 case ui::VKEY_DOWN: | 1038 case ui::VKEY_DOWN: |
| 1069 return !event.IsAltDown(); | 1039 return !event.IsAltDown(); |
| 1070 | 1040 |
| 1071 case ui::VKEY_DELETE: | 1041 case ui::VKEY_DELETE: |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1102 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { | 1072 bool OmniboxViewWin::IsCommandIdChecked(int command_id) const { |
| 1103 return false; | 1073 return false; |
| 1104 } | 1074 } |
| 1105 | 1075 |
| 1106 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { | 1076 bool OmniboxViewWin::IsCommandIdEnabled(int command_id) const { |
| 1107 switch (command_id) { | 1077 switch (command_id) { |
| 1108 case IDS_UNDO: return !!CanUndo(); | 1078 case IDS_UNDO: return !!CanUndo(); |
| 1109 case IDC_CUT: return !!CanCut(); | 1079 case IDC_CUT: return !!CanCut(); |
| 1110 case IDC_COPY: return !!CanCopy(); | 1080 case IDC_COPY: return !!CanCopy(); |
| 1111 case IDC_PASTE: return !!CanPaste(); | 1081 case IDC_PASTE: return !!CanPaste(); |
| 1112 case IDS_PASTE_AND_GO: return model_->CanPasteAndGo(GetClipboardText()); | 1082 case IDS_PASTE_AND_GO: return model()->CanPasteAndGo(GetClipboardText()); |
| 1113 case IDS_SELECT_ALL: return !!CanSelectAll(); | 1083 case IDS_SELECT_ALL: return !!CanSelectAll(); |
| 1114 case IDS_EDIT_SEARCH_ENGINES: | 1084 case IDS_EDIT_SEARCH_ENGINES: |
| 1115 return command_updater_->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); | 1085 return command_updater()->IsCommandEnabled(IDC_EDIT_SEARCH_ENGINES); |
| 1116 default: | 1086 default: |
| 1117 NOTREACHED(); | 1087 NOTREACHED(); |
| 1118 return false; | 1088 return false; |
| 1119 } | 1089 } |
| 1120 } | 1090 } |
| 1121 | 1091 |
| 1122 bool OmniboxViewWin::GetAcceleratorForCommandId( | 1092 bool OmniboxViewWin::GetAcceleratorForCommandId( |
| 1123 int command_id, | 1093 int command_id, |
| 1124 ui::Accelerator* accelerator) { | 1094 ui::Accelerator* accelerator) { |
| 1125 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); | 1095 return parent_view_->GetWidget()->GetAccelerator(command_id, accelerator); |
| 1126 } | 1096 } |
| 1127 | 1097 |
| 1128 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const { | 1098 bool OmniboxViewWin::IsItemForCommandIdDynamic(int command_id) const { |
| 1129 // No need to change the default IDS_PASTE_AND_GO label unless this is a | 1099 // No need to change the default IDS_PASTE_AND_GO label unless this is a |
| 1130 // search. | 1100 // search. |
| 1131 return command_id == IDS_PASTE_AND_GO; | 1101 return command_id == IDS_PASTE_AND_GO; |
| 1132 } | 1102 } |
| 1133 | 1103 |
| 1134 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const { | 1104 string16 OmniboxViewWin::GetLabelForCommandId(int command_id) const { |
| 1135 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); | 1105 DCHECK_EQ(IDS_PASTE_AND_GO, command_id); |
| 1136 return l10n_util::GetStringUTF16( | 1106 return l10n_util::GetStringUTF16( |
| 1137 model_->IsPasteAndSearch(GetClipboardText()) ? | 1107 model()->IsPasteAndSearch(GetClipboardText()) ? |
| 1138 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); | 1108 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); |
| 1139 } | 1109 } |
| 1140 | 1110 |
| 1141 void OmniboxViewWin::ExecuteCommand(int command_id) { | 1111 void OmniboxViewWin::ExecuteCommand(int command_id) { |
| 1142 ScopedFreeze freeze(this, GetTextObjectModel()); | 1112 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1143 if (command_id == IDS_PASTE_AND_GO) { | 1113 if (command_id == IDS_PASTE_AND_GO) { |
| 1144 // This case is separate from the switch() below since we don't want to wrap | 1114 // This case is separate from the switch() below since we don't want to wrap |
| 1145 // it in OnBefore/AfterPossibleChange() calls. | 1115 // it in OnBefore/AfterPossibleChange() calls. |
| 1146 model_->PasteAndGo(GetClipboardText()); | 1116 model()->PasteAndGo(GetClipboardText()); |
| 1147 return; | 1117 return; |
| 1148 } | 1118 } |
| 1149 | 1119 |
| 1150 OnBeforePossibleChange(); | 1120 OnBeforePossibleChange(); |
| 1151 switch (command_id) { | 1121 switch (command_id) { |
| 1152 case IDS_UNDO: | 1122 case IDS_UNDO: |
| 1153 Undo(); | 1123 Undo(); |
| 1154 break; | 1124 break; |
| 1155 | 1125 |
| 1156 case IDC_CUT: | 1126 case IDC_CUT: |
| 1157 Cut(); | 1127 Cut(); |
| 1158 break; | 1128 break; |
| 1159 | 1129 |
| 1160 case IDC_COPY: | 1130 case IDC_COPY: |
| 1161 Copy(); | 1131 Copy(); |
| 1162 break; | 1132 break; |
| 1163 | 1133 |
| 1164 case IDC_PASTE: | 1134 case IDC_PASTE: |
| 1165 Paste(); | 1135 Paste(); |
| 1166 break; | 1136 break; |
| 1167 | 1137 |
| 1168 case IDS_SELECT_ALL: | 1138 case IDS_SELECT_ALL: |
| 1169 SelectAll(false); | 1139 SelectAll(false); |
| 1170 break; | 1140 break; |
| 1171 | 1141 |
| 1172 case IDS_EDIT_SEARCH_ENGINES: | 1142 case IDS_EDIT_SEARCH_ENGINES: |
| 1173 command_updater_->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); | 1143 command_updater()->ExecuteCommand(IDC_EDIT_SEARCH_ENGINES); |
| 1174 break; | 1144 break; |
| 1175 | 1145 |
| 1176 default: | 1146 default: |
| 1177 NOTREACHED(); | 1147 NOTREACHED(); |
| 1178 break; | 1148 break; |
| 1179 } | 1149 } |
| 1180 OnAfterPossibleChange(); | 1150 OnAfterPossibleChange(); |
| 1181 } | 1151 } |
| 1182 | 1152 |
| 1183 // static | 1153 // static |
| (...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1353 string16 text(GetSelectedText()); | 1323 string16 text(GetSelectedText()); |
| 1354 if (text.empty()) | 1324 if (text.empty()) |
| 1355 return; | 1325 return; |
| 1356 | 1326 |
| 1357 CHARRANGE sel; | 1327 CHARRANGE sel; |
| 1358 GURL url; | 1328 GURL url; |
| 1359 bool write_url = false; | 1329 bool write_url = false; |
| 1360 GetSel(sel); | 1330 GetSel(sel); |
| 1361 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be | 1331 // GetSel() doesn't preserve selection direction, so sel.cpMin will always be |
| 1362 // the smaller value. | 1332 // the smaller value. |
| 1363 model_->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); | 1333 model()->AdjustTextForCopy(sel.cpMin, IsSelectAll(), &text, &url, &write_url); |
| 1364 ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), | 1334 ui::ScopedClipboardWriter scw(g_browser_process->clipboard(), |
| 1365 ui::Clipboard::BUFFER_STANDARD); | 1335 ui::Clipboard::BUFFER_STANDARD); |
| 1366 scw.WriteText(text); | 1336 scw.WriteText(text); |
| 1367 if (write_url) { | 1337 if (write_url) { |
| 1368 scw.WriteBookmark(text, url.spec()); | 1338 scw.WriteBookmark(text, url.spec()); |
| 1369 scw.WriteHyperlink(net::EscapeForHTML(text), url.spec()); | 1339 scw.WriteHyperlink(net::EscapeForHTML(text), url.spec()); |
| 1370 } | 1340 } |
| 1371 } | 1341 } |
| 1372 | 1342 |
| 1373 void OmniboxViewWin::OnCut() { | 1343 void OmniboxViewWin::OnCut() { |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1414 } | 1384 } |
| 1415 | 1385 |
| 1416 LRESULT OmniboxViewWin::OnImeNotify(UINT message, | 1386 LRESULT OmniboxViewWin::OnImeNotify(UINT message, |
| 1417 WPARAM wparam, | 1387 WPARAM wparam, |
| 1418 LPARAM lparam) { | 1388 LPARAM lparam) { |
| 1419 // Close the popup when the IME composition window is open, so they don't | 1389 // Close the popup when the IME composition window is open, so they don't |
| 1420 // overlap. | 1390 // overlap. |
| 1421 switch (wparam) { | 1391 switch (wparam) { |
| 1422 case IMN_OPENCANDIDATE: | 1392 case IMN_OPENCANDIDATE: |
| 1423 ime_candidate_window_open_ = true; | 1393 ime_candidate_window_open_ = true; |
| 1424 ClosePopup(); | 1394 CloseOmniboxPopup(); |
| 1425 break; | 1395 break; |
| 1426 case IMN_CLOSECANDIDATE: | 1396 case IMN_CLOSECANDIDATE: |
| 1427 ime_candidate_window_open_ = false; | 1397 ime_candidate_window_open_ = false; |
| 1428 | 1398 |
| 1429 // UpdatePopup assumes user input is in progress, so only call it if | 1399 // UpdatePopup assumes user input is in progress, so only call it if |
| 1430 // that's the case. Otherwise, autocomplete may run on an empty user | 1400 // that's the case. Otherwise, autocomplete may run on an empty user |
| 1431 // text. For example, Baidu Japanese IME sends IMN_CLOSECANDIDATE when | 1401 // text. For example, Baidu Japanese IME sends IMN_CLOSECANDIDATE when |
| 1432 // composition mode is entered, but the user may not have input anything | 1402 // composition mode is entered, but the user may not have input anything |
| 1433 // yet. | 1403 // yet. |
| 1434 if (model_->user_input_in_progress()) | 1404 if (model()->user_input_in_progress()) |
| 1435 UpdatePopup(); | 1405 UpdatePopup(); |
| 1436 | 1406 |
| 1437 break; | 1407 break; |
| 1438 default: | 1408 default: |
| 1439 break; | 1409 break; |
| 1440 } | 1410 } |
| 1441 return DefWindowProc(message, wparam, lparam); | 1411 return DefWindowProc(message, wparam, lparam); |
| 1442 } | 1412 } |
| 1443 | 1413 |
| 1444 LRESULT OmniboxViewWin::OnPointerDown(UINT message, | 1414 LRESULT OmniboxViewWin::OnPointerDown(UINT message, |
| 1445 WPARAM wparam, | 1415 WPARAM wparam, |
| 1446 LPARAM lparam) { | 1416 LPARAM lparam) { |
| 1447 if (!model_->has_focus()) | 1417 if (!model()->has_focus()) |
| 1448 SetFocus(); | 1418 SetFocus(); |
| 1449 | 1419 |
| 1450 if (IS_POINTER_FIRSTBUTTON_WPARAM(wparam)) { | 1420 if (IS_POINTER_FIRSTBUTTON_WPARAM(wparam)) { |
| 1451 TrackMousePosition(kLeft, CPoint(GET_X_LPARAM(lparam), | 1421 TrackMousePosition(kLeft, CPoint(GET_X_LPARAM(lparam), |
| 1452 GET_Y_LPARAM(lparam))); | 1422 GET_Y_LPARAM(lparam))); |
| 1453 } | 1423 } |
| 1454 | 1424 |
| 1455 SetMsgHandled(false); | 1425 SetMsgHandled(false); |
| 1456 | 1426 |
| 1457 return 0; | 1427 return 0; |
| (...skipping 26 matching lines...) Expand all Loading... |
| 1484 | 1454 |
| 1485 // CRichEditCtrl changes its text on WM_KEYDOWN instead of WM_CHAR for many | 1455 // CRichEditCtrl changes its text on WM_KEYDOWN instead of WM_CHAR for many |
| 1486 // different keys (backspace, ctrl-v, ...), so we call this in both cases. | 1456 // different keys (backspace, ctrl-v, ...), so we call this in both cases. |
| 1487 HandleKeystroke(GetCurrentMessage()->message, key, repeat_count, flags); | 1457 HandleKeystroke(GetCurrentMessage()->message, key, repeat_count, flags); |
| 1488 } | 1458 } |
| 1489 | 1459 |
| 1490 void OmniboxViewWin::OnKeyUp(TCHAR key, | 1460 void OmniboxViewWin::OnKeyUp(TCHAR key, |
| 1491 UINT repeat_count, | 1461 UINT repeat_count, |
| 1492 UINT flags) { | 1462 UINT flags) { |
| 1493 if (key == VK_CONTROL) | 1463 if (key == VK_CONTROL) |
| 1494 model_->OnControlKeyChanged(false); | 1464 model()->OnControlKeyChanged(false); |
| 1495 | 1465 |
| 1496 // On systems with RTL input languages, ctrl+shift toggles the reading order | 1466 // On systems with RTL input languages, ctrl+shift toggles the reading order |
| 1497 // (depending on which shift key is pressed). But by default the CRichEditCtrl | 1467 // (depending on which shift key is pressed). But by default the CRichEditCtrl |
| 1498 // only changes the current reading order, and as soon as the user deletes all | 1468 // only changes the current reading order, and as soon as the user deletes all |
| 1499 // the text, or we call SetWindowText(), it reverts to the "default" order. | 1469 // the text, or we call SetWindowText(), it reverts to the "default" order. |
| 1500 // To work around this, if the user hits ctrl+shift, we pass it to | 1470 // To work around this, if the user hits ctrl+shift, we pass it to |
| 1501 // DefWindowProc() while the edit is empty, which toggles the default reading | 1471 // DefWindowProc() while the edit is empty, which toggles the default reading |
| 1502 // order; then we restore the user's input. | 1472 // order; then we restore the user's input. |
| 1503 if (!(flags & KF_ALTDOWN) && | 1473 if (!(flags & KF_ALTDOWN) && |
| 1504 (((key == VK_CONTROL) && (GetKeyState(VK_SHIFT) < 0)) || | 1474 (((key == VK_CONTROL) && (GetKeyState(VK_SHIFT) < 0)) || |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1522 } | 1492 } |
| 1523 | 1493 |
| 1524 void OmniboxViewWin::OnKillFocus(HWND focus_wnd) { | 1494 void OmniboxViewWin::OnKillFocus(HWND focus_wnd) { |
| 1525 if (m_hWnd == focus_wnd) { | 1495 if (m_hWnd == focus_wnd) { |
| 1526 // Focus isn't actually leaving. | 1496 // Focus isn't actually leaving. |
| 1527 SetMsgHandled(false); | 1497 SetMsgHandled(false); |
| 1528 return; | 1498 return; |
| 1529 } | 1499 } |
| 1530 | 1500 |
| 1531 // This must be invoked before ClosePopup. | 1501 // This must be invoked before ClosePopup. |
| 1532 model_->OnWillKillFocus(focus_wnd); | 1502 model()->OnWillKillFocus(focus_wnd); |
| 1533 | 1503 |
| 1534 // Close the popup. | 1504 // Close the popup. |
| 1535 ClosePopup(); | 1505 CloseOmniboxPopup(); |
| 1536 | 1506 |
| 1537 // Save the user's existing selection to restore it later. | 1507 // Save the user's existing selection to restore it later. |
| 1538 GetSelection(saved_selection_for_focus_change_); | 1508 GetSelection(saved_selection_for_focus_change_); |
| 1539 | 1509 |
| 1540 // Tell the model to reset itself. | 1510 // Tell the model to reset itself. |
| 1541 model_->OnKillFocus(); | 1511 model()->OnKillFocus(); |
| 1542 | 1512 |
| 1543 // Let the CRichEditCtrl do its default handling. This will complete any | 1513 // Let the CRichEditCtrl do its default handling. This will complete any |
| 1544 // in-progress IME composition. We must do this after setting has_focus_ to | 1514 // in-progress IME composition. We must do this after setting has_focus_ to |
| 1545 // false so that UpdatePopup() will know not to rerun autocomplete. | 1515 // false so that UpdatePopup() will know not to rerun autocomplete. |
| 1546 ScopedFreeze freeze(this, GetTextObjectModel()); | 1516 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 1547 DefWindowProc(WM_KILLFOCUS, reinterpret_cast<WPARAM>(focus_wnd), 0); | 1517 DefWindowProc(WM_KILLFOCUS, reinterpret_cast<WPARAM>(focus_wnd), 0); |
| 1548 | 1518 |
| 1549 // Cancel any user selection and scroll the text back to the beginning of the | 1519 // Cancel any user selection and scroll the text back to the beginning of the |
| 1550 // URL. We have to do this after calling DefWindowProc() because otherwise | 1520 // URL. We have to do this after calling DefWindowProc() because otherwise |
| 1551 // an in-progress IME composition will be completed at the new caret position, | 1521 // an in-progress IME composition will be completed at the new caret position, |
| (...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1667 // First, give other handlers a chance to handle the message to see if we are | 1637 // First, give other handlers a chance to handle the message to see if we are |
| 1668 // actually going to activate and gain focus. | 1638 // actually going to activate and gain focus. |
| 1669 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, | 1639 LRESULT result = DefWindowProc(WM_MOUSEACTIVATE, |
| 1670 reinterpret_cast<WPARAM>(window), | 1640 reinterpret_cast<WPARAM>(window), |
| 1671 MAKELPARAM(hit_test, mouse_message)); | 1641 MAKELPARAM(hit_test, mouse_message)); |
| 1672 // Check if we're getting focus from a click. We have to do this here rather | 1642 // Check if we're getting focus from a click. We have to do this here rather |
| 1673 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be | 1643 // than in OnXButtonDown() since in many scenarios OnSetFocus() will be |
| 1674 // reached before OnXButtonDown(), preventing us from detecting this properly | 1644 // reached before OnXButtonDown(), preventing us from detecting this properly |
| 1675 // there. Also in those cases, we need to already know in OnSetFocus() that | 1645 // there. Also in those cases, we need to already know in OnSetFocus() that |
| 1676 // we should not restore the saved selection. | 1646 // we should not restore the saved selection. |
| 1677 if (!model_->has_focus() && | 1647 if (!model()->has_focus() && |
| 1678 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN || | 1648 ((mouse_message == WM_LBUTTONDOWN || mouse_message == WM_RBUTTONDOWN || |
| 1679 mouse_message == WM_POINTERDOWN)) && | 1649 mouse_message == WM_POINTERDOWN)) && |
| 1680 (result == MA_ACTIVATE)) { | 1650 (result == MA_ACTIVATE)) { |
| 1681 DCHECK(!gaining_focus_.get()); | 1651 DCHECK(!gaining_focus_.get()); |
| 1682 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); | 1652 gaining_focus_.reset(new ScopedFreeze(this, GetTextObjectModel())); |
| 1683 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not | 1653 // NOTE: Despite |mouse_message| being WM_XBUTTONDOWN here, we're not |
| 1684 // guaranteed to call OnXButtonDown() later! Specifically, if this is the | 1654 // guaranteed to call OnXButtonDown() later! Specifically, if this is the |
| 1685 // second click of a double click, we'll reach here but later call | 1655 // second click of a double click, we'll reach here but later call |
| 1686 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, | 1656 // OnXButtonDblClk(). Make sure |gaining_focus_| gets reset both places, |
| 1687 // or we'll have visual glitchiness and then DCHECK failures. | 1657 // or we'll have visual glitchiness and then DCHECK failures. |
| (...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1828 rect.left, rect.top, SRCCOPY); | 1798 rect.left, rect.top, SRCCOPY); |
| 1829 memory_dc.SelectBitmap(old_bitmap); | 1799 memory_dc.SelectBitmap(old_bitmap); |
| 1830 edit_hwnd = old_edit_hwnd; | 1800 edit_hwnd = old_edit_hwnd; |
| 1831 } | 1801 } |
| 1832 | 1802 |
| 1833 void OmniboxViewWin::OnPaste() { | 1803 void OmniboxViewWin::OnPaste() { |
| 1834 // Replace the selection if we have something to paste. | 1804 // Replace the selection if we have something to paste. |
| 1835 const string16 text(GetClipboardText()); | 1805 const string16 text(GetClipboardText()); |
| 1836 if (!text.empty()) { | 1806 if (!text.empty()) { |
| 1837 // Record this paste, so we can do different behavior. | 1807 // Record this paste, so we can do different behavior. |
| 1838 model_->on_paste(); | 1808 model()->on_paste(); |
| 1839 // Force a Paste operation to trigger the text_changed code in | 1809 // Force a Paste operation to trigger the text_changed code in |
| 1840 // OnAfterPossibleChange(), even if identical contents are pasted into the | 1810 // OnAfterPossibleChange(), even if identical contents are pasted into the |
| 1841 // text box. | 1811 // text box. |
| 1842 text_before_change_.clear(); | 1812 text_before_change_.clear(); |
| 1843 ReplaceSel(text.c_str(), true); | 1813 ReplaceSel(text.c_str(), true); |
| 1844 } | 1814 } |
| 1845 } | 1815 } |
| 1846 | 1816 |
| 1847 void OmniboxViewWin::OnRButtonDblClk(UINT /*keys*/, const CPoint& /*point*/) { | 1817 void OmniboxViewWin::OnRButtonDblClk(UINT /*keys*/, const CPoint& /*point*/) { |
| 1848 gaining_focus_.reset(); // See NOTE in OnMouseActivate(). | 1818 gaining_focus_.reset(); // See NOTE in OnMouseActivate(). |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1866 void OmniboxViewWin::OnSetFocus(HWND focus_wnd) { | 1836 void OmniboxViewWin::OnSetFocus(HWND focus_wnd) { |
| 1867 views::FocusManager* focus_manager = parent_view_->GetFocusManager(); | 1837 views::FocusManager* focus_manager = parent_view_->GetFocusManager(); |
| 1868 if (focus_manager) { | 1838 if (focus_manager) { |
| 1869 // Notify the FocusManager that the focused view is now the location bar | 1839 // Notify the FocusManager that the focused view is now the location bar |
| 1870 // (our parent view). | 1840 // (our parent view). |
| 1871 focus_manager->SetFocusedView(parent_view_); | 1841 focus_manager->SetFocusedView(parent_view_); |
| 1872 } else { | 1842 } else { |
| 1873 NOTREACHED(); | 1843 NOTREACHED(); |
| 1874 } | 1844 } |
| 1875 | 1845 |
| 1876 model_->OnSetFocus(GetKeyState(VK_CONTROL) < 0); | 1846 model()->OnSetFocus(GetKeyState(VK_CONTROL) < 0); |
| 1877 | 1847 |
| 1878 // Restore saved selection if available. | 1848 // Restore saved selection if available. |
| 1879 if (saved_selection_for_focus_change_.cpMin != -1) { | 1849 if (saved_selection_for_focus_change_.cpMin != -1) { |
| 1880 SetSelectionRange(saved_selection_for_focus_change_); | 1850 SetSelectionRange(saved_selection_for_focus_change_); |
| 1881 saved_selection_for_focus_change_.cpMin = -1; | 1851 saved_selection_for_focus_change_.cpMin = -1; |
| 1882 } | 1852 } |
| 1883 | 1853 |
| 1884 SetMsgHandled(false); | 1854 SetMsgHandled(false); |
| 1885 } | 1855 } |
| 1886 | 1856 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1978 switch (key) { | 1948 switch (key) { |
| 1979 case VK_RIGHT: | 1949 case VK_RIGHT: |
| 1980 // TODO(sky): figure out RTL. | 1950 // TODO(sky): figure out RTL. |
| 1981 if (base::i18n::IsRTL()) | 1951 if (base::i18n::IsRTL()) |
| 1982 return false; | 1952 return false; |
| 1983 { | 1953 { |
| 1984 CHARRANGE selection; | 1954 CHARRANGE selection; |
| 1985 GetSel(selection); | 1955 GetSel(selection); |
| 1986 return (selection.cpMin == selection.cpMax) && | 1956 return (selection.cpMin == selection.cpMax) && |
| 1987 (selection.cpMin == GetTextLength()) && | 1957 (selection.cpMin == GetTextLength()) && |
| 1988 model_->CommitSuggestedText(true); | 1958 model()->CommitSuggestedText(true); |
| 1989 } | 1959 } |
| 1990 | 1960 |
| 1991 case VK_RETURN: | 1961 case VK_RETURN: |
| 1992 model_->AcceptInput((flags & KF_ALTDOWN) ? | 1962 model()->AcceptInput((flags & KF_ALTDOWN) ? |
| 1993 NEW_FOREGROUND_TAB : CURRENT_TAB, false); | 1963 NEW_FOREGROUND_TAB : CURRENT_TAB, false); |
| 1994 return true; | 1964 return true; |
| 1995 | 1965 |
| 1996 case VK_PRIOR: | 1966 case VK_PRIOR: |
| 1997 case VK_NEXT: | 1967 case VK_NEXT: |
| 1998 count = model_->result().size(); | 1968 count = model()->result().size(); |
| 1999 // FALL THROUGH | 1969 // FALL THROUGH |
| 2000 case VK_UP: | 1970 case VK_UP: |
| 2001 case VK_DOWN: | 1971 case VK_DOWN: |
| 2002 // Ignore alt + numpad, but treat alt + (non-numpad) like (non-numpad). | 1972 // Ignore alt + numpad, but treat alt + (non-numpad) like (non-numpad). |
| 2003 if ((flags & KF_ALTDOWN) && !(flags & KF_EXTENDED)) | 1973 if ((flags & KF_ALTDOWN) && !(flags & KF_EXTENDED)) |
| 2004 return false; | 1974 return false; |
| 2005 | 1975 |
| 2006 model_->OnUpOrDownKeyPressed(((key == VK_PRIOR) || (key == VK_UP)) ? | 1976 model()->OnUpOrDownKeyPressed(((key == VK_PRIOR) || (key == VK_UP)) ? |
| 2007 -count : count); | 1977 -count : count); |
| 2008 return true; | 1978 return true; |
| 2009 | 1979 |
| 2010 // Hijacking Editing Commands | 1980 // Hijacking Editing Commands |
| 2011 // | 1981 // |
| 2012 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that | 1982 // We hijack the keyboard short-cuts for Cut, Copy, and Paste here so that |
| 2013 // they go through our clipboard routines. This allows us to be smarter | 1983 // they go through our clipboard routines. This allows us to be smarter |
| 2014 // about how we interact with the clipboard and avoid bugs in the | 1984 // about how we interact with the clipboard and avoid bugs in the |
| 2015 // CRichEditCtrl. If we didn't hijack here, the edit control would handle | 1985 // CRichEditCtrl. If we didn't hijack here, the edit control would handle |
| 2016 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. | 1986 // these internally with sending the WM_CUT, WM_COPY, or WM_PASTE messages. |
| (...skipping 25 matching lines...) Expand all Loading... |
| 2042 if (GetKeyState(VK_CONTROL) >= 0) { | 2012 if (GetKeyState(VK_CONTROL) >= 0) { |
| 2043 // Cut text if possible. | 2013 // Cut text if possible. |
| 2044 CHARRANGE selection; | 2014 CHARRANGE selection; |
| 2045 GetSel(selection); | 2015 GetSel(selection); |
| 2046 if (selection.cpMin != selection.cpMax) { | 2016 if (selection.cpMin != selection.cpMax) { |
| 2047 ScopedFreeze freeze(this, GetTextObjectModel()); | 2017 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2048 OnBeforePossibleChange(); | 2018 OnBeforePossibleChange(); |
| 2049 Cut(); | 2019 Cut(); |
| 2050 OnAfterPossibleChange(); | 2020 OnAfterPossibleChange(); |
| 2051 } else { | 2021 } else { |
| 2052 if (model_->popup_model()->IsOpen()) { | 2022 if (model()->popup_model()->IsOpen()) { |
| 2053 // This is a bit overloaded, but we hijack Shift-Delete in this | 2023 // This is a bit overloaded, but we hijack Shift-Delete in this |
| 2054 // case to delete the current item from the pop-up. We prefer | 2024 // case to delete the current item from the pop-up. We prefer |
| 2055 // cutting to this when possible since that's the behavior more | 2025 // cutting to this when possible since that's the behavior more |
| 2056 // people expect from Shift-Delete, and it's more commonly useful. | 2026 // people expect from Shift-Delete, and it's more commonly useful. |
| 2057 model_->popup_model()->TryDeletingCurrentItem(); | 2027 model()->popup_model()->TryDeletingCurrentItem(); |
| 2058 } | 2028 } |
| 2059 } | 2029 } |
| 2060 } | 2030 } |
| 2061 return true; | 2031 return true; |
| 2062 | 2032 |
| 2063 case 'X': | 2033 case 'X': |
| 2064 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) | 2034 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) |
| 2065 return false; | 2035 return false; |
| 2066 if (GetKeyState(VK_SHIFT) >= 0) { | 2036 if (GetKeyState(VK_SHIFT) >= 0) { |
| 2067 ScopedFreeze freeze(this, GetTextObjectModel()); | 2037 ScopedFreeze freeze(this, GetTextObjectModel()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2083 return false; | 2053 return false; |
| 2084 if (GetKeyState((key == 'V') ? VK_SHIFT : VK_CONTROL) >= 0) { | 2054 if (GetKeyState((key == 'V') ? VK_SHIFT : VK_CONTROL) >= 0) { |
| 2085 ScopedFreeze freeze(this, GetTextObjectModel()); | 2055 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2086 OnBeforePossibleChange(); | 2056 OnBeforePossibleChange(); |
| 2087 Paste(); | 2057 Paste(); |
| 2088 OnAfterPossibleChange(); | 2058 OnAfterPossibleChange(); |
| 2089 } | 2059 } |
| 2090 return true; | 2060 return true; |
| 2091 | 2061 |
| 2092 case VK_BACK: { | 2062 case VK_BACK: { |
| 2093 if ((flags & KF_ALTDOWN) || model_->is_keyword_hint() || | 2063 if ((flags & KF_ALTDOWN) || model()->is_keyword_hint() || |
| 2094 model_->keyword().empty()) | 2064 model()->keyword().empty()) |
| 2095 return false; | 2065 return false; |
| 2096 | 2066 |
| 2097 { | 2067 { |
| 2098 CHARRANGE selection; | 2068 CHARRANGE selection; |
| 2099 GetSel(selection); | 2069 GetSel(selection); |
| 2100 if ((selection.cpMin != selection.cpMax) || (selection.cpMin != 0)) | 2070 if ((selection.cpMin != selection.cpMax) || (selection.cpMin != 0)) |
| 2101 return false; | 2071 return false; |
| 2102 } | 2072 } |
| 2103 | 2073 |
| 2104 // We're showing a keyword and the user pressed backspace at the beginning | 2074 // We're showing a keyword and the user pressed backspace at the beginning |
| 2105 // of the text. Delete the selected keyword. | 2075 // of the text. Delete the selected keyword. |
| 2106 ScopedFreeze freeze(this, GetTextObjectModel()); | 2076 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2107 model_->ClearKeyword(GetText()); | 2077 model()->ClearKeyword(GetText()); |
| 2108 return true; | 2078 return true; |
| 2109 } | 2079 } |
| 2110 | 2080 |
| 2111 case VK_TAB: { | 2081 case VK_TAB: { |
| 2112 const bool shift_pressed = GetKeyState(VK_SHIFT) < 0; | 2082 const bool shift_pressed = GetKeyState(VK_SHIFT) < 0; |
| 2113 if (model_->is_keyword_hint() && !shift_pressed) { | 2083 if (model()->is_keyword_hint() && !shift_pressed) { |
| 2114 // Accept the keyword. | 2084 // Accept the keyword. |
| 2115 ScopedFreeze freeze(this, GetTextObjectModel()); | 2085 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2116 model_->AcceptKeyword(); | 2086 model()->AcceptKeyword(); |
| 2117 } else if (shift_pressed && | 2087 } else if (shift_pressed && |
| 2118 model_->popup_model()->selected_line_state() == | 2088 model()->popup_model()->selected_line_state() == |
| 2119 OmniboxPopupModel::KEYWORD) { | 2089 OmniboxPopupModel::KEYWORD) { |
| 2120 model_->ClearKeyword(GetText()); | 2090 model()->ClearKeyword(GetText()); |
| 2121 } else { | 2091 } else { |
| 2122 model_->OnUpOrDownKeyPressed(shift_pressed ? -count : count); | 2092 model()->OnUpOrDownKeyPressed(shift_pressed ? -count : count); |
| 2123 } | 2093 } |
| 2124 return true; | 2094 return true; |
| 2125 } | 2095 } |
| 2126 | 2096 |
| 2127 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). | 2097 case 0xbb: // Ctrl-'='. Triggers subscripting (even in plain text mode). |
| 2128 // We don't use VK_OEM_PLUS in case the macro isn't defined. | 2098 // We don't use VK_OEM_PLUS in case the macro isn't defined. |
| 2129 // (e.g., we don't have this symbol in embeded environment). | 2099 // (e.g., we don't have this symbol in embeded environment). |
| 2130 return true; | 2100 return true; |
| 2131 | 2101 |
| 2132 default: | 2102 default: |
| 2133 return false; | 2103 return false; |
| 2134 } | 2104 } |
| 2135 } | 2105 } |
| 2136 | 2106 |
| 2137 bool OmniboxViewWin::OnKeyDownAllModes(TCHAR key, | 2107 bool OmniboxViewWin::OnKeyDownAllModes(TCHAR key, |
| 2138 UINT repeat_count, | 2108 UINT repeat_count, |
| 2139 UINT flags) { | 2109 UINT flags) { |
| 2140 // See KF_ALTDOWN comment atop OnKeyDownOnlyWritable(). | 2110 // See KF_ALTDOWN comment atop OnKeyDownOnlyWritable(). |
| 2141 | 2111 |
| 2142 switch (key) { | 2112 switch (key) { |
| 2143 case VK_CONTROL: | 2113 case VK_CONTROL: |
| 2144 model_->OnControlKeyChanged(true); | 2114 model()->OnControlKeyChanged(true); |
| 2145 return false; | 2115 return false; |
| 2146 | 2116 |
| 2147 case VK_INSERT: | 2117 case VK_INSERT: |
| 2148 case 'C': | 2118 case 'C': |
| 2149 // See more detailed comments in OnKeyDownOnlyWritable(). | 2119 // See more detailed comments in OnKeyDownOnlyWritable(). |
| 2150 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) | 2120 if ((flags & KF_ALTDOWN) || (GetKeyState(VK_CONTROL) >= 0)) |
| 2151 return false; | 2121 return false; |
| 2152 if (GetKeyState(VK_SHIFT) >= 0) | 2122 if (GetKeyState(VK_SHIFT) >= 0) |
| 2153 Copy(); | 2123 Copy(); |
| 2154 return true; | 2124 return true; |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2254 // the end of the text, but triple-click will still work. | 2224 // the end of the text, but triple-click will still work. |
| 2255 if (x < left_bound) { | 2225 if (x < left_bound) { |
| 2256 return (is_triple_click && ltr_text_in_ltr_layout) ? left_bound - 1 : | 2226 return (is_triple_click && ltr_text_in_ltr_layout) ? left_bound - 1 : |
| 2257 left_bound; | 2227 left_bound; |
| 2258 } | 2228 } |
| 2259 if ((length == 0) || (x < right_bound)) | 2229 if ((length == 0) || (x < right_bound)) |
| 2260 return x; | 2230 return x; |
| 2261 return is_triple_click ? (right_bound - 1) : right_bound; | 2231 return is_triple_click ? (right_bound - 1) : right_bound; |
| 2262 } | 2232 } |
| 2263 | 2233 |
| 2234 int OmniboxViewWin::GetOmniboxTextLength() const { |
| 2235 return static_cast<int>(GetTextLength()); |
| 2236 } |
| 2237 |
| 2264 void OmniboxViewWin::EmphasizeURLComponents() { | 2238 void OmniboxViewWin::EmphasizeURLComponents() { |
| 2265 ITextDocument* const text_object_model = GetTextObjectModel(); | 2239 ITextDocument* const text_object_model = GetTextObjectModel(); |
| 2266 ScopedFreeze freeze(this, text_object_model); | 2240 ScopedFreeze freeze(this, text_object_model); |
| 2267 ScopedSuspendUndo suspend_undo(text_object_model); | 2241 ScopedSuspendUndo suspend_undo(text_object_model); |
| 2268 | 2242 |
| 2269 // Save the selection. | 2243 // Save the selection. |
| 2270 CHARRANGE saved_sel; | 2244 CHARRANGE saved_sel; |
| 2271 GetSelection(saved_sel); | 2245 GetSelection(saved_sel); |
| 2272 | 2246 |
| 2273 // See whether the contents are a URL with a non-empty host portion, which we | 2247 // See whether the contents are a URL with a non-empty host portion, which we |
| 2274 // should emphasize. To check for a URL, rather than using the type returned | 2248 // should emphasize. To check for a URL, rather than using the type returned |
| 2275 // by Parse(), ask the model, which will check the desired page transition for | 2249 // by Parse(), ask the model, which will check the desired page transition for |
| 2276 // this input. This can tell us whether an UNKNOWN input string is going to | 2250 // this input. This can tell us whether an UNKNOWN input string is going to |
| 2277 // be treated as a search or a navigation, and is the same method the Paste | 2251 // be treated as a search or a navigation, and is the same method the Paste |
| 2278 // And Go system uses. | 2252 // And Go system uses. |
| 2279 url_parse::Component scheme, host; | 2253 url_parse::Component scheme, host; |
| 2280 AutocompleteInput::ParseForEmphasizeComponents( | 2254 AutocompleteInput::ParseForEmphasizeComponents( |
| 2281 GetText(), model_->GetDesiredTLD(), &scheme, &host); | 2255 GetText(), model()->GetDesiredTLD(), &scheme, &host); |
| 2282 const bool emphasize = model_->CurrentTextIsURL() && (host.len > 0); | 2256 const bool emphasize = model()->CurrentTextIsURL() && (host.len > 0); |
| 2283 | 2257 |
| 2284 // Set the baseline emphasis. | 2258 // Set the baseline emphasis. |
| 2285 CHARFORMAT cf = {0}; | 2259 CHARFORMAT cf = {0}; |
| 2286 cf.dwMask = CFM_COLOR; | 2260 cf.dwMask = CFM_COLOR; |
| 2287 // If we're going to emphasize parts of the text, then the baseline state | 2261 // If we're going to emphasize parts of the text, then the baseline state |
| 2288 // should be "de-emphasized". If not, then everything should be rendered in | 2262 // should be "de-emphasized". If not, then everything should be rendered in |
| 2289 // the standard text color. | 2263 // the standard text color. |
| 2290 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( | 2264 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
| 2291 security_level_, | 2265 security_level_, |
| 2292 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); | 2266 emphasize ? LocationBarView::DEEMPHASIZED_TEXT : LocationBarView::TEXT)); |
| 2293 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the | 2267 // NOTE: Don't use SetDefaultCharFormat() instead of the below; that sets the |
| 2294 // format that will get applied to text added in the future, not to text | 2268 // format that will get applied to text added in the future, not to text |
| 2295 // already in the edit. | 2269 // already in the edit. |
| 2296 SelectAll(false); | 2270 SelectAll(false); |
| 2297 SetSelectionCharFormat(cf); | 2271 SetSelectionCharFormat(cf); |
| 2298 | 2272 |
| 2299 if (emphasize) { | 2273 if (emphasize) { |
| 2300 // We've found a host name, give it more emphasis. | 2274 // We've found a host name, give it more emphasis. |
| 2301 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( | 2275 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
| 2302 security_level_, LocationBarView::TEXT)); | 2276 security_level_, LocationBarView::TEXT)); |
| 2303 SetSelection(host.begin, host.end()); | 2277 SetSelection(host.begin, host.end()); |
| 2304 SetSelectionCharFormat(cf); | 2278 SetSelectionCharFormat(cf); |
| 2305 } | 2279 } |
| 2306 | 2280 |
| 2307 // Emphasize the scheme for security UI display purposes (if necessary). | 2281 // Emphasize the scheme for security UI display purposes (if necessary). |
| 2308 insecure_scheme_component_.reset(); | 2282 insecure_scheme_component_.reset(); |
| 2309 if (!model_->user_input_in_progress() && scheme.is_nonempty() && | 2283 if (!model()->user_input_in_progress() && scheme.is_nonempty() && |
| 2310 (security_level_ != ToolbarModel::NONE)) { | 2284 (security_level_ != ToolbarModel::NONE)) { |
| 2311 if (security_level_ == ToolbarModel::SECURITY_ERROR) { | 2285 if (security_level_ == ToolbarModel::SECURITY_ERROR) { |
| 2312 insecure_scheme_component_.begin = scheme.begin; | 2286 insecure_scheme_component_.begin = scheme.begin; |
| 2313 insecure_scheme_component_.len = scheme.len; | 2287 insecure_scheme_component_.len = scheme.len; |
| 2314 } | 2288 } |
| 2315 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( | 2289 cf.crTextColor = skia::SkColorToCOLORREF(LocationBarView::GetColor( |
| 2316 security_level_, LocationBarView::SECURITY_TEXT)); | 2290 security_level_, LocationBarView::SECURITY_TEXT)); |
| 2317 SetSelection(scheme.begin, scheme.end()); | 2291 SetSelection(scheme.begin, scheme.end()); |
| 2318 SetSelectionCharFormat(cf); | 2292 SetSelectionCharFormat(cf); |
| 2319 } | 2293 } |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2450 return; | 2424 return; |
| 2451 | 2425 |
| 2452 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0))); | 2426 HGDIOBJ last_pen = SelectObject(hdc, CreatePen(PS_SOLID, 1, RGB(0, 0, 0))); |
| 2453 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL); | 2427 MoveToEx(hdc, clip_rect.left, clip_rect.top, NULL); |
| 2454 LineTo(hdc, clip_rect.left, clip_rect.bottom); | 2428 LineTo(hdc, clip_rect.left, clip_rect.bottom); |
| 2455 DeleteObject(SelectObject(hdc, last_pen)); | 2429 DeleteObject(SelectObject(hdc, last_pen)); |
| 2456 } | 2430 } |
| 2457 | 2431 |
| 2458 void OmniboxViewWin::TextChanged() { | 2432 void OmniboxViewWin::TextChanged() { |
| 2459 ScopedFreeze freeze(this, GetTextObjectModel()); | 2433 ScopedFreeze freeze(this, GetTextObjectModel()); |
| 2460 EmphasizeURLComponents(); | 2434 OmniboxView::TextChanged(); |
| 2461 model_->OnChanged(); | |
| 2462 } | 2435 } |
| 2463 | 2436 |
| 2464 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { | 2437 ITextDocument* OmniboxViewWin::GetTextObjectModel() const { |
| 2465 if (!text_object_model_) { | 2438 if (!text_object_model_) { |
| 2466 // This is lazily initialized, instead of being initialized in the | 2439 // This is lazily initialized, instead of being initialized in the |
| 2467 // constructor, in order to avoid hurting startup performance. | 2440 // constructor, in order to avoid hurting startup performance. |
| 2468 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; | 2441 base::win::ScopedComPtr<IRichEditOle, NULL> ole_interface; |
| 2469 ole_interface.Attach(GetOleInterface()); | 2442 ole_interface.Attach(GetOleInterface()); |
| 2470 if (ole_interface) { | 2443 if (ole_interface) { |
| 2471 ole_interface.QueryInterface( | 2444 ole_interface.QueryInterface( |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2509 | 2482 |
| 2510 // |sel| was set by GetSelection(), which preserves selection direction, so | 2483 // |sel| was set by GetSelection(), which preserves selection direction, so |
| 2511 // sel.cpMin may not be the smaller value. | 2484 // sel.cpMin may not be the smaller value. |
| 2512 model()->AdjustTextForCopy(std::min(sel.cpMin, sel.cpMax), is_all_selected, | 2485 model()->AdjustTextForCopy(std::min(sel.cpMin, sel.cpMax), is_all_selected, |
| 2513 &text_to_write, &url, &write_url); | 2486 &text_to_write, &url, &write_url); |
| 2514 | 2487 |
| 2515 if (write_url) { | 2488 if (write_url) { |
| 2516 string16 title; | 2489 string16 title; |
| 2517 SkBitmap favicon; | 2490 SkBitmap favicon; |
| 2518 if (is_all_selected) | 2491 if (is_all_selected) |
| 2519 model_->GetDataForURLExport(&url, &title, &favicon); | 2492 model()->GetDataForURLExport(&url, &title, &favicon); |
| 2520 button_drag_utils::SetURLAndDragImage(url, title, favicon, &data, | 2493 button_drag_utils::SetURLAndDragImage(url, title, favicon, &data, |
| 2521 native_view_host_->GetWidget()); | 2494 native_view_host_->GetWidget()); |
| 2522 supported_modes |= DROPEFFECT_LINK; | 2495 supported_modes |= DROPEFFECT_LINK; |
| 2523 content::RecordAction(UserMetricsAction("Omnibox_DragURL")); | 2496 content::RecordAction(UserMetricsAction("Omnibox_DragURL")); |
| 2524 } else { | 2497 } else { |
| 2525 supported_modes |= DROPEFFECT_MOVE; | 2498 supported_modes |= DROPEFFECT_MOVE; |
| 2526 content::RecordAction(UserMetricsAction("Omnibox_DragString")); | 2499 content::RecordAction(UserMetricsAction("Omnibox_DragString")); |
| 2527 } | 2500 } |
| 2528 | 2501 |
| 2529 data.SetString(text_to_write); | 2502 data.SetString(text_to_write); |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2659 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2632 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
| 2660 } | 2633 } |
| 2661 | 2634 |
| 2662 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2635 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
| 2663 // Use font_.GetStringWidth() instead of | 2636 // Use font_.GetStringWidth() instead of |
| 2664 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2637 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
| 2665 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2638 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
| 2666 // PosFromChar(i) might return 0 when i is greater than 1. | 2639 // PosFromChar(i) might return 0 when i is greater than 1. |
| 2667 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2640 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
| 2668 } | 2641 } |
| 2669 | |
| 2670 bool OmniboxViewWin::IsCaretAtEnd() const { | |
| 2671 long length = GetTextLength(); | |
| 2672 CHARRANGE sel; | |
| 2673 GetSelection(sel); | |
| 2674 return sel.cpMin == sel.cpMax && sel.cpMin == length; | |
| 2675 } | |
| OLD | NEW |