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 448 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
459 command_updater), | 459 command_updater), |
460 popup_view_(OmniboxPopupContentsView::Create( | 460 popup_view_(OmniboxPopupContentsView::Create( |
461 parent_view->font(), this, model(), location_bar)), | 461 parent_view->font(), this, model(), location_bar)), |
462 parent_view_(parent_view), | 462 parent_view_(parent_view), |
463 popup_window_mode_(popup_window_mode), | 463 popup_window_mode_(popup_window_mode), |
464 force_hidden_(false), | 464 force_hidden_(false), |
465 tracking_click_(), | 465 tracking_click_(), |
466 tracking_double_click_(false), | 466 tracking_double_click_(false), |
467 double_click_time_(0), | 467 double_click_time_(0), |
468 can_discard_mousemove_(false), | 468 can_discard_mousemove_(false), |
469 caret_height_(0), | |
Peter Kasting
2012/12/01 01:48:31
Probably unnecessary, see below.
Mathieu
2012/12/03 02:29:04
Done.
| |
469 ignore_ime_messages_(false), | 470 ignore_ime_messages_(false), |
470 delete_at_end_pressed_(false), | 471 delete_at_end_pressed_(false), |
471 font_(parent_view->font()), | 472 font_(parent_view->font()), |
472 possible_drag_(false), | 473 possible_drag_(false), |
473 in_drag_(false), | 474 in_drag_(false), |
474 initiated_drag_(false), | 475 initiated_drag_(false), |
475 drop_highlight_position_(-1), | 476 drop_highlight_position_(-1), |
476 ime_candidate_window_open_(false), | 477 ime_candidate_window_open_(false), |
477 background_color_(skia::SkColorToCOLORREF(parent_view->GetColor( | 478 background_color_(skia::SkColorToCOLORREF(parent_view->GetColor( |
478 ToolbarModel::NONE, LocationBarView::BACKGROUND))), | 479 ToolbarModel::NONE, LocationBarView::BACKGROUND))), |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
599 if (tab_for_state_restoring) { | 600 if (tab_for_state_restoring) { |
600 // Make sure we reset our own state first. The new tab may not have any | 601 // Make sure we reset our own state first. The new tab may not have any |
601 // saved state, or it may not have had input in progress, in which case we | 602 // saved state, or it may not have had input in progress, in which case we |
602 // won't overwrite all our local state. | 603 // won't overwrite all our local state. |
603 RevertAll(); | 604 RevertAll(); |
604 | 605 |
605 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( | 606 const AutocompleteEditState* state = static_cast<AutocompleteEditState*>( |
606 tab_for_state_restoring->GetUserData(&kAutocompleteEditStateKey)); | 607 tab_for_state_restoring->GetUserData(&kAutocompleteEditStateKey)); |
607 if (state) { | 608 if (state) { |
608 model()->RestoreState(state->model_state); | 609 model()->RestoreState(state->model_state); |
610 ApplyFocusVisibility(); | |
609 | 611 |
610 // Restore user's selection. We do this after restoring the user_text | 612 // Restore user's selection. We do this after restoring the user_text |
611 // above so we're selecting in the correct string. | 613 // above so we're selecting in the correct string. |
612 SetSelectionRange(state->view_state.selection); | 614 SetSelectionRange(state->view_state.selection); |
613 saved_selection_for_focus_change_ = | 615 saved_selection_for_focus_change_ = |
614 state->view_state.saved_selection_for_focus_change; | 616 state->view_state.saved_selection_for_focus_change; |
615 } | 617 } |
616 } else if (visibly_changed_permanent_text) { | 618 } else if (visibly_changed_permanent_text) { |
617 // Not switching tabs, just updating the permanent text. (In the case where | 619 // Not switching tabs, just updating the permanent text. (In the case where |
618 // we _were_ switching tabs, the RevertAll() above already drew the new | 620 // we _were_ switching tabs, the RevertAll() above already drew the new |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
753 // * The user has just pasted in something that replaced all the text | 755 // * The user has just pasted in something that replaced all the text |
754 // * The user is trying to compose something in an IME | 756 // * The user is trying to compose something in an IME |
755 CHARRANGE sel; | 757 CHARRANGE sel; |
756 GetSel(sel); | 758 GetSel(sel); |
757 model()->StartAutocomplete(sel.cpMax != sel.cpMin, | 759 model()->StartAutocomplete(sel.cpMax != sel.cpMin, |
758 (sel.cpMax < GetTextLength()) || IsImeComposing()); | 760 (sel.cpMax < GetTextLength()) || IsImeComposing()); |
759 } | 761 } |
760 | 762 |
761 void OmniboxViewWin::SetFocus() { | 763 void OmniboxViewWin::SetFocus() { |
762 ::SetFocus(m_hWnd); | 764 ::SetFocus(m_hWnd); |
765 model()->set_is_focus_visible(true); | |
766 ApplyFocusVisibility(); | |
Peter Kasting
2012/12/01 01:48:31
Rather than calling this unconditionally, we shoul
Mathieu
2012/12/03 02:29:04
Good idea. Done.
| |
767 } | |
768 | |
769 void OmniboxViewWin::SetInvisibleFocus() { | |
770 ::SetFocus(m_hWnd); | |
771 model()->set_is_focus_visible(false); | |
772 ApplyFocusVisibility(); | |
763 } | 773 } |
764 | 774 |
765 void OmniboxViewWin::SetDropHighlightPosition(int position) { | 775 void OmniboxViewWin::SetDropHighlightPosition(int position) { |
766 if (drop_highlight_position_ != position) { | 776 if (drop_highlight_position_ != position) { |
767 RepaintDropHighlight(drop_highlight_position_); | 777 RepaintDropHighlight(drop_highlight_position_); |
768 drop_highlight_position_ = position; | 778 drop_highlight_position_ = position; |
769 RepaintDropHighlight(drop_highlight_position_); | 779 RepaintDropHighlight(drop_highlight_position_); |
770 } | 780 } |
771 } | 781 } |
772 | 782 |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
837 TextChanged(); | 847 TextChanged(); |
838 return true; | 848 return true; |
839 } | 849 } |
840 | 850 |
841 void OmniboxViewWin::OnRevertTemporaryText() { | 851 void OmniboxViewWin::OnRevertTemporaryText() { |
842 SetSelectionRange(original_selection_); | 852 SetSelectionRange(original_selection_); |
843 TextChanged(); | 853 TextChanged(); |
844 } | 854 } |
845 | 855 |
846 void OmniboxViewWin::OnBeforePossibleChange() { | 856 void OmniboxViewWin::OnBeforePossibleChange() { |
857 model()->set_is_focus_visible(true); | |
858 ApplyFocusVisibility(); | |
847 // Record our state. | 859 // Record our state. |
848 text_before_change_ = GetText(); | 860 text_before_change_ = GetText(); |
849 GetSelection(sel_before_change_); | 861 GetSelection(sel_before_change_); |
850 } | 862 } |
851 | 863 |
852 bool OmniboxViewWin::OnAfterPossibleChange() { | 864 bool OmniboxViewWin::OnAfterPossibleChange() { |
853 return OnAfterPossibleChangeInternal(false); | 865 return OnAfterPossibleChangeInternal(false); |
854 } | 866 } |
855 | 867 |
856 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) { | 868 bool OmniboxViewWin::OnAfterPossibleChangeInternal(bool force_text_changed) { |
(...skipping 1030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1887 | 1899 |
1888 // Draw the drop highlight. | 1900 // Draw the drop highlight. |
1889 if (drop_highlight_position_ != -1) | 1901 if (drop_highlight_position_ != -1) |
1890 DrawDropHighlight(memory_dc, rect, paint_clip_rect); | 1902 DrawDropHighlight(memory_dc, rect, paint_clip_rect); |
1891 | 1903 |
1892 // Blit the memory DC to the actual paint DC and clean up. | 1904 // Blit the memory DC to the actual paint DC and clean up. |
1893 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc, | 1905 BitBlt(paint_dc, rect.left, rect.top, rect.Width(), rect.Height(), memory_dc, |
1894 rect.left, rect.top, SRCCOPY); | 1906 rect.left, rect.top, SRCCOPY); |
1895 memory_dc.SelectBitmap(old_bitmap); | 1907 memory_dc.SelectBitmap(old_bitmap); |
1896 edit_hwnd = old_edit_hwnd; | 1908 edit_hwnd = old_edit_hwnd; |
1909 | |
1910 // Determine the caret height and apply the current focus visibility. This is | |
1911 // done in every paint event to account for window resizes that repaint the | |
1912 // Omnibox. | |
1913 caret_height_ = rect.Height() - 3; | |
1914 ApplyFocusVisibility(); | |
1897 } | 1915 } |
1898 | 1916 |
1899 void OmniboxViewWin::OnPaste() { | 1917 void OmniboxViewWin::OnPaste() { |
1900 // Replace the selection if we have something to paste. | 1918 // Replace the selection if we have something to paste. |
1901 const string16 text(GetClipboardText()); | 1919 const string16 text(GetClipboardText()); |
1902 if (!text.empty()) { | 1920 if (!text.empty()) { |
1903 // Record this paste, so we can do different behavior. | 1921 // Record this paste, so we can do different behavior. |
1904 model()->on_paste(); | 1922 model()->on_paste(); |
1905 // Force a Paste operation to trigger the text_changed code in | 1923 // Force a Paste operation to trigger the text_changed code in |
1906 // OnAfterPossibleChange(), even if identical contents are pasted into the | 1924 // OnAfterPossibleChange(), even if identical contents are pasted into the |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2746 return (rect.left - client_rect.left) + (client_rect.right - rect.right); | 2764 return (rect.left - client_rect.left) + (client_rect.right - rect.right); |
2747 } | 2765 } |
2748 | 2766 |
2749 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { | 2767 int OmniboxViewWin::WidthNeededToDisplay(const string16& text) const { |
2750 // Use font_.GetStringWidth() instead of | 2768 // Use font_.GetStringWidth() instead of |
2751 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is | 2769 // PosFromChar(location_entry_->GetTextLength()) because PosFromChar() is |
2752 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, | 2770 // apparently buggy. In both LTR UI and RTL UI with left-to-right layout, |
2753 // PosFromChar(i) might return 0 when i is greater than 1. | 2771 // PosFromChar(i) might return 0 when i is greater than 1. |
2754 return font_.GetStringWidth(text) + GetHorizontalMargin(); | 2772 return font_.GetStringWidth(text) + GetHorizontalMargin(); |
2755 } | 2773 } |
2774 | |
2775 void OmniboxViewWin::ApplyFocusVisibility() { | |
2776 if (!chrome::search::IsInstantExtendedAPIEnabled(parent_view_->profile())) | |
2777 return; | |
2778 HideCaret(); | |
Peter Kasting
2012/12/01 01:48:31
Why are we hiding the caret unconditionally instea
Mathieu
2012/12/03 02:29:04
Ah, the Windows API... If DestroyCaret is called a
| |
2779 ::DestroyCaret(); | |
Peter Kasting
2012/12/01 01:48:31
Do we have to DestroyCaret() and later CreateCaret
Mathieu
2012/12/03 02:29:04
The Hide/Show Windows API is broken in this way: w
Peter Kasting
2012/12/03 23:03:32
Interesting. You should add comments about this.
Mathieu
2012/12/03 23:23:32
I've now added comments where I felt appropriate.
| |
2780 if (model()->is_focus_visible()) { | |
2781 ::CreateCaret(m_hWnd, (HBITMAP) NULL, 1, caret_height_); | |
2782 ShowCaret(); | |
2783 } | |
2784 } | |
OLD | NEW |