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_views.h" | 5 #include "chrome/browser/ui/views/omnibox/omnibox_view_views.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 36 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
37 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
38 #include "ui/base/dragdrop/os_exchange_data.h" | 38 #include "ui/base/dragdrop/os_exchange_data.h" |
39 #include "ui/base/ime/text_input_client.h" | 39 #include "ui/base/ime/text_input_client.h" |
40 #include "ui/base/ime/text_input_type.h" | 40 #include "ui/base/ime/text_input_type.h" |
41 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
42 #include "ui/base/models/simple_menu_model.h" | 42 #include "ui/base/models/simple_menu_model.h" |
43 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
44 #include "ui/compositor/layer.h" | 44 #include "ui/compositor/layer.h" |
45 #include "ui/events/event.h" | 45 #include "ui/events/event.h" |
46 #include "ui/gfx/animation/slide_animation.h" | |
47 #include "ui/gfx/canvas.h" | 46 #include "ui/gfx/canvas.h" |
48 #include "ui/gfx/font_list.h" | 47 #include "ui/gfx/font_list.h" |
49 #include "ui/gfx/selection_model.h" | 48 #include "ui/gfx/selection_model.h" |
50 #include "ui/views/border.h" | 49 #include "ui/views/border.h" |
51 #include "ui/views/button_drag_utils.h" | 50 #include "ui/views/button_drag_utils.h" |
52 #include "ui/views/controls/textfield/textfield.h" | 51 #include "ui/views/controls/textfield/textfield.h" |
53 #include "ui/views/ime/input_method.h" | 52 #include "ui/views/ime/input_method.h" |
54 #include "ui/views/layout/fill_layout.h" | 53 #include "ui/views/layout/fill_layout.h" |
55 #include "ui/views/views_delegate.h" | 54 #include "ui/views/views_delegate.h" |
56 #include "ui/views/widget/widget.h" | 55 #include "ui/views/widget/widget.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 SetReadOnly(true); | 169 SetReadOnly(true); |
171 | 170 |
172 // Initialize the popup view using the same font. | 171 // Initialize the popup view using the same font. |
173 popup_view_.reset(OmniboxPopupContentsView::Create( | 172 popup_view_.reset(OmniboxPopupContentsView::Create( |
174 GetFontList(), this, model(), location_bar_view_)); | 173 GetFontList(), this, model(), location_bar_view_)); |
175 | 174 |
176 #if defined(OS_CHROMEOS) | 175 #if defined(OS_CHROMEOS) |
177 chromeos::input_method::InputMethodManager::Get()-> | 176 chromeos::input_method::InputMethodManager::Get()-> |
178 AddCandidateWindowObserver(this); | 177 AddCandidateWindowObserver(this); |
179 #endif | 178 #endif |
180 | |
181 fade_in_animation_.reset(new gfx::SlideAnimation(this)); | |
182 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); | |
183 fade_in_animation_->SetSlideDuration(300); | |
184 } | |
185 | |
186 void OmniboxViewViews::FadeIn() { | |
187 fade_in_animation_->Show(); | |
188 } | 179 } |
189 | 180 |
190 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { | 181 void OmniboxViewViews::SaveStateToTab(content::WebContents* tab) { |
191 DCHECK(tab); | 182 DCHECK(tab); |
192 | 183 |
193 // We don't want to keep the IME status, so force quit the current | 184 // We don't want to keep the IME status, so force quit the current |
194 // session here. It may affect the selection status, so order is | 185 // session here. It may affect the selection status, so order is |
195 // also important. | 186 // also important. |
196 if (IsIMEComposing()) { | 187 if (IsIMEComposing()) { |
197 GetTextInputClient()->ConfirmCompositionText(); | 188 GetTextInputClient()->ConfirmCompositionText(); |
(...skipping 592 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
790 return true; | 781 return true; |
791 } | 782 } |
792 return Textfield::SkipDefaultKeyEventProcessing(event); | 783 return Textfield::SkipDefaultKeyEventProcessing(event); |
793 } | 784 } |
794 | 785 |
795 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { | 786 void OmniboxViewViews::GetAccessibleState(ui::AXViewState* state) { |
796 location_bar_view_->GetAccessibleState(state); | 787 location_bar_view_->GetAccessibleState(state); |
797 state->role = ui::AX_ROLE_TEXT_FIELD; | 788 state->role = ui::AX_ROLE_TEXT_FIELD; |
798 } | 789 } |
799 | 790 |
800 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { | |
801 if (fade_in_animation_->is_animating()) { | |
802 canvas->SaveLayerAlpha(static_cast<uint8>( | |
803 fade_in_animation_->CurrentValueBetween(0, 255))); | |
804 views::Textfield::OnPaint(canvas); | |
805 canvas->Restore(); | |
806 } else { | |
807 views::Textfield::OnPaint(canvas); | |
808 } | |
809 } | |
810 | |
811 void OmniboxViewViews::OnFocus() { | 791 void OmniboxViewViews::OnFocus() { |
812 views::Textfield::OnFocus(); | 792 views::Textfield::OnFocus(); |
813 // TODO(oshima): Get control key state. | 793 // TODO(oshima): Get control key state. |
814 model()->OnSetFocus(false); | 794 model()->OnSetFocus(false); |
815 // Don't call controller()->OnSetFocus, this view has already acquired focus. | 795 // Don't call controller()->OnSetFocus, this view has already acquired focus. |
816 | 796 |
817 // Restore the selection we saved in OnBlur() if it's still valid. | 797 // Restore the selection we saved in OnBlur() if it's still valid. |
818 if (saved_selection_for_focus_change_.IsValid()) { | 798 if (saved_selection_for_focus_change_.IsValid()) { |
819 SelectRange(saved_selection_for_focus_change_); | 799 SelectRange(saved_selection_for_focus_change_); |
820 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 800 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
859 return controller()->GetToolbarModel()->WouldReplaceURL(); | 839 return controller()->GetToolbarModel()->WouldReplaceURL(); |
860 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || | 840 return command_id == IDS_MOVE_DOWN || command_id == IDS_MOVE_UP || |
861 Textfield::IsCommandIdEnabled(command_id) || | 841 Textfield::IsCommandIdEnabled(command_id) || |
862 command_updater()->IsCommandEnabled(command_id); | 842 command_updater()->IsCommandEnabled(command_id); |
863 } | 843 } |
864 | 844 |
865 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { | 845 base::string16 OmniboxViewViews::GetSelectionClipboardText() const { |
866 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); | 846 return SanitizeTextForPaste(Textfield::GetSelectionClipboardText()); |
867 } | 847 } |
868 | 848 |
869 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) { | |
870 SchedulePaint(); | |
871 } | |
872 | |
873 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) { | |
874 fade_in_animation_->Reset(); | |
875 } | |
876 | |
877 #if defined(OS_CHROMEOS) | 849 #if defined(OS_CHROMEOS) |
878 void OmniboxViewViews::CandidateWindowOpened( | 850 void OmniboxViewViews::CandidateWindowOpened( |
879 chromeos::input_method::InputMethodManager* manager) { | 851 chromeos::input_method::InputMethodManager* manager) { |
880 ime_candidate_window_open_ = true; | 852 ime_candidate_window_open_ = true; |
881 } | 853 } |
882 | 854 |
883 void OmniboxViewViews::CandidateWindowClosed( | 855 void OmniboxViewViews::CandidateWindowClosed( |
884 chromeos::input_method::InputMethodManager* manager) { | 856 chromeos::input_method::InputMethodManager* manager) { |
885 ime_candidate_window_open_ = false; | 857 ime_candidate_window_open_ = false; |
886 } | 858 } |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1033 menu_contents->InsertItemWithStringIdAt( | 1005 menu_contents->InsertItemWithStringIdAt( |
1034 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1006 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
1035 } | 1007 } |
1036 | 1008 |
1037 // Minor note: We use IDC_ for command id here while the underlying textfield | 1009 // Minor note: We use IDC_ for command id here while the underlying textfield |
1038 // is using IDS_ for all its command ids. This is because views cannot depend | 1010 // is using IDS_ for all its command ids. This is because views cannot depend |
1039 // on IDC_ for now. | 1011 // on IDC_ for now. |
1040 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1012 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
1041 IDS_EDIT_SEARCH_ENGINES); | 1013 IDS_EDIT_SEARCH_ENGINES); |
1042 } | 1014 } |
OLD | NEW |