| 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 22 matching lines...) Expand all Loading... |
| 33 #include "ui/accessibility/ax_view_state.h" | 33 #include "ui/accessibility/ax_view_state.h" |
| 34 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 34 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 35 #include "ui/base/dragdrop/drag_drop_types.h" | 35 #include "ui/base/dragdrop/drag_drop_types.h" |
| 36 #include "ui/base/dragdrop/os_exchange_data.h" | 36 #include "ui/base/dragdrop/os_exchange_data.h" |
| 37 #include "ui/base/ime/text_input_client.h" | 37 #include "ui/base/ime/text_input_client.h" |
| 38 #include "ui/base/ime/text_input_type.h" | 38 #include "ui/base/ime/text_input_type.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 39 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/models/simple_menu_model.h" | 40 #include "ui/base/models/simple_menu_model.h" |
| 41 #include "ui/base/resource/resource_bundle.h" | 41 #include "ui/base/resource/resource_bundle.h" |
| 42 #include "ui/events/event.h" | 42 #include "ui/events/event.h" |
| 43 #include "ui/gfx/animation/slide_animation.h" |
| 43 #include "ui/gfx/canvas.h" | 44 #include "ui/gfx/canvas.h" |
| 44 #include "ui/gfx/font_list.h" | 45 #include "ui/gfx/font_list.h" |
| 45 #include "ui/gfx/selection_model.h" | 46 #include "ui/gfx/selection_model.h" |
| 46 #include "ui/views/border.h" | 47 #include "ui/views/border.h" |
| 47 #include "ui/views/button_drag_utils.h" | 48 #include "ui/views/button_drag_utils.h" |
| 48 #include "ui/views/controls/textfield/textfield.h" | 49 #include "ui/views/controls/textfield/textfield.h" |
| 49 #include "ui/views/ime/input_method.h" | 50 #include "ui/views/ime/input_method.h" |
| 50 #include "ui/views/layout/fill_layout.h" | 51 #include "ui/views/layout/fill_layout.h" |
| 51 #include "ui/views/views_delegate.h" | 52 #include "ui/views/views_delegate.h" |
| 52 #include "ui/views/widget/widget.h" | 53 #include "ui/views/widget/widget.h" |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 172 SetReadOnly(true); | 173 SetReadOnly(true); |
| 173 | 174 |
| 174 // Initialize the popup view using the same font. | 175 // Initialize the popup view using the same font. |
| 175 popup_view_.reset(OmniboxPopupContentsView::Create( | 176 popup_view_.reset(OmniboxPopupContentsView::Create( |
| 176 GetFontList(), this, model(), location_bar_view_)); | 177 GetFontList(), this, model(), location_bar_view_)); |
| 177 | 178 |
| 178 #if defined(OS_CHROMEOS) | 179 #if defined(OS_CHROMEOS) |
| 179 chromeos::input_method::InputMethodManager::Get()-> | 180 chromeos::input_method::InputMethodManager::Get()-> |
| 180 AddCandidateWindowObserver(this); | 181 AddCandidateWindowObserver(this); |
| 181 #endif | 182 #endif |
| 183 |
| 184 fade_in_animation_.reset(new gfx::SlideAnimation(this)); |
| 185 fade_in_animation_->SetTweenType(gfx::Tween::LINEAR); |
| 186 fade_in_animation_->SetSlideDuration(300); |
| 187 } |
| 188 |
| 189 void OmniboxViewViews::FadeIn() { |
| 190 fade_in_animation_->Show(); |
| 182 } | 191 } |
| 183 | 192 |
| 184 //////////////////////////////////////////////////////////////////////////////// | 193 //////////////////////////////////////////////////////////////////////////////// |
| 185 // OmniboxViewViews, views::Textfield implementation: | 194 // OmniboxViewViews, views::Textfield implementation: |
| 186 | 195 |
| 187 const char* OmniboxViewViews::GetClassName() const { | 196 const char* OmniboxViewViews::GetClassName() const { |
| 188 return kViewClassName; | 197 return kViewClassName; |
| 189 } | 198 } |
| 190 | 199 |
| 200 void OmniboxViewViews::OnPaint(gfx::Canvas* canvas) { |
| 201 if (fade_in_animation_->is_animating()) { |
| 202 canvas->SaveLayerAlpha(static_cast<uint8>( |
| 203 fade_in_animation_->CurrentValueBetween(0, 255))); |
| 204 views::Textfield::OnPaint(canvas); |
| 205 canvas->Restore(); |
| 206 } else { |
| 207 views::Textfield::OnPaint(canvas); |
| 208 } |
| 209 } |
| 210 |
| 191 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { | 211 bool OmniboxViewViews::OnMousePressed(const ui::MouseEvent& event) { |
| 192 select_all_on_mouse_release_ = | 212 select_all_on_mouse_release_ = |
| 193 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && | 213 (event.IsOnlyLeftMouseButton() || event.IsOnlyRightMouseButton()) && |
| 194 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); | 214 (!HasFocus() || (model()->focus_state() == OMNIBOX_FOCUS_INVISIBLE)); |
| 195 if (select_all_on_mouse_release_) { | 215 if (select_all_on_mouse_release_) { |
| 196 // Restore caret visibility whenever the user clicks in the omnibox in a way | 216 // Restore caret visibility whenever the user clicks in the omnibox in a way |
| 197 // that would give it focus. We must handle this case separately here | 217 // that would give it focus. We must handle this case separately here |
| 198 // because if the omnibox currently has invisible focus, the mouse event | 218 // because if the omnibox currently has invisible focus, the mouse event |
| 199 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). | 219 // won't trigger either SetFocus() or OmniboxEditModel::OnSetFocus(). |
| 200 model()->SetCaretVisibility(true); | 220 model()->SetCaretVisibility(true); |
| (...skipping 541 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 742 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); | 762 IDS_PASTE_AND_SEARCH : IDS_PASTE_AND_GO); |
| 743 } | 763 } |
| 744 | 764 |
| 745 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { | 765 void OmniboxViewViews::ExecuteCommand(int command_id, int event_flags) { |
| 746 switch (command_id) { | 766 switch (command_id) { |
| 747 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). | 767 // These commands don't invoke the popup via OnBefore/AfterPossibleChange(). |
| 748 case IDS_PASTE_AND_GO: | 768 case IDS_PASTE_AND_GO: |
| 749 model()->PasteAndGo(GetClipboardText()); | 769 model()->PasteAndGo(GetClipboardText()); |
| 750 break; | 770 break; |
| 751 case IDS_SHOW_URL: | 771 case IDS_SHOW_URL: |
| 752 ShowURL(); | 772 controller()->ShowURL(); |
| 753 break; | 773 break; |
| 754 case IDC_EDIT_SEARCH_ENGINES: | 774 case IDC_EDIT_SEARCH_ENGINES: |
| 755 command_updater()->ExecuteCommand(command_id); | 775 command_updater()->ExecuteCommand(command_id); |
| 756 break; | 776 break; |
| 757 | 777 |
| 758 default: | 778 default: |
| 759 OnBeforePossibleChange(); | 779 OnBeforePossibleChange(); |
| 760 if (command_id == IDS_APP_PASTE) | 780 if (command_id == IDS_APP_PASTE) |
| 761 OnPaste(); | 781 OnPaste(); |
| 762 else if (Textfield::IsCommandIdEnabled(command_id)) | 782 else if (Textfield::IsCommandIdEnabled(command_id)) |
| 763 Textfield::ExecuteCommand(command_id, event_flags); | 783 Textfield::ExecuteCommand(command_id, event_flags); |
| 764 else | 784 else |
| 765 command_updater()->ExecuteCommand(command_id); | 785 command_updater()->ExecuteCommand(command_id); |
| 766 OnAfterPossibleChange(); | 786 OnAfterPossibleChange(); |
| 767 break; | 787 break; |
| 768 } | 788 } |
| 769 } | 789 } |
| 770 | 790 |
| 771 //////////////////////////////////////////////////////////////////////////////// | 791 //////////////////////////////////////////////////////////////////////////////// |
| 792 // OmniboxViewViews, gfx::AnimationDelegate implementation: |
| 793 |
| 794 void OmniboxViewViews::AnimationProgressed(const gfx::Animation* animation) { |
| 795 SchedulePaint(); |
| 796 } |
| 797 |
| 798 void OmniboxViewViews::AnimationEnded(const gfx::Animation* animation) { |
| 799 fade_in_animation_->Reset(); |
| 800 } |
| 801 |
| 802 //////////////////////////////////////////////////////////////////////////////// |
| 772 // OmniboxViewViews, views::TextfieldController implementation: | 803 // OmniboxViewViews, views::TextfieldController implementation: |
| 773 | 804 |
| 774 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, | 805 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, |
| 775 const base::string16& new_contents) { | 806 const base::string16& new_contents) { |
| 776 } | 807 } |
| 777 | 808 |
| 778 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, | 809 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, |
| 779 const ui::KeyEvent& event) { | 810 const ui::KeyEvent& event) { |
| 780 delete_at_end_pressed_ = false; | 811 delete_at_end_pressed_ = false; |
| 781 | 812 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1001 const base::string16 text(GetClipboardText()); | 1032 const base::string16 text(GetClipboardText()); |
| 1002 if (!text.empty()) { | 1033 if (!text.empty()) { |
| 1003 // Record this paste, so we can do different behavior. | 1034 // Record this paste, so we can do different behavior. |
| 1004 model()->OnPaste(); | 1035 model()->OnPaste(); |
| 1005 // Force a Paste operation to trigger the text_changed code in | 1036 // Force a Paste operation to trigger the text_changed code in |
| 1006 // OnAfterPossibleChange(), even if identical contents are pasted. | 1037 // OnAfterPossibleChange(), even if identical contents are pasted. |
| 1007 text_before_change_.clear(); | 1038 text_before_change_.clear(); |
| 1008 InsertOrReplaceText(text); | 1039 InsertOrReplaceText(text); |
| 1009 } | 1040 } |
| 1010 } | 1041 } |
| OLD | NEW |