| 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 13 matching lines...) Expand all Loading... |
| 24 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" | 24 #include "chrome/browser/ui/views/settings_api_bubble_helper_views.h" |
| 25 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" | 25 #include "chrome/browser/ui/views/website_settings/website_settings_popup_view.h
" |
| 26 #include "content/public/browser/web_contents.h" | 26 #include "content/public/browser/web_contents.h" |
| 27 #include "extensions/common/constants.h" | 27 #include "extensions/common/constants.h" |
| 28 #include "grit/app_locale_settings.h" | 28 #include "grit/app_locale_settings.h" |
| 29 #include "grit/generated_resources.h" | 29 #include "grit/generated_resources.h" |
| 30 #include "grit/ui_strings.h" | 30 #include "grit/ui_strings.h" |
| 31 #include "net/base/escape.h" | 31 #include "net/base/escape.h" |
| 32 #include "third_party/skia/include/core/SkColor.h" | 32 #include "third_party/skia/include/core/SkColor.h" |
| 33 #include "ui/accessibility/ax_view_state.h" | 33 #include "ui/accessibility/ax_view_state.h" |
| 34 #include "ui/aura/client/focus_client.h" |
| 35 #include "ui/aura/window_event_dispatcher.h" |
| 34 #include "ui/base/clipboard/scoped_clipboard_writer.h" | 36 #include "ui/base/clipboard/scoped_clipboard_writer.h" |
| 35 #include "ui/base/dragdrop/drag_drop_types.h" | 37 #include "ui/base/dragdrop/drag_drop_types.h" |
| 36 #include "ui/base/dragdrop/os_exchange_data.h" | 38 #include "ui/base/dragdrop/os_exchange_data.h" |
| 37 #include "ui/base/ime/text_input_client.h" | 39 #include "ui/base/ime/text_input_client.h" |
| 38 #include "ui/base/ime/text_input_type.h" | 40 #include "ui/base/ime/text_input_type.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 41 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/models/simple_menu_model.h" | 42 #include "ui/base/models/simple_menu_model.h" |
| 41 #include "ui/base/resource/resource_bundle.h" | 43 #include "ui/base/resource/resource_bundle.h" |
| 44 #include "ui/compositor/layer.h" |
| 42 #include "ui/events/event.h" | 45 #include "ui/events/event.h" |
| 43 #include "ui/gfx/animation/slide_animation.h" | 46 #include "ui/gfx/animation/slide_animation.h" |
| 44 #include "ui/gfx/canvas.h" | 47 #include "ui/gfx/canvas.h" |
| 45 #include "ui/gfx/font_list.h" | 48 #include "ui/gfx/font_list.h" |
| 46 #include "ui/gfx/selection_model.h" | 49 #include "ui/gfx/selection_model.h" |
| 47 #include "ui/views/border.h" | 50 #include "ui/views/border.h" |
| 48 #include "ui/views/button_drag_utils.h" | 51 #include "ui/views/button_drag_utils.h" |
| 49 #include "ui/views/controls/textfield/textfield.h" | 52 #include "ui/views/controls/textfield/textfield.h" |
| 50 #include "ui/views/ime/input_method.h" | 53 #include "ui/views/ime/input_method.h" |
| 51 #include "ui/views/layout/fill_layout.h" | 54 #include "ui/views/layout/fill_layout.h" |
| 52 #include "ui/views/views_delegate.h" | 55 #include "ui/views/views_delegate.h" |
| 53 #include "ui/views/widget/widget.h" | 56 #include "ui/views/widget/widget.h" |
| 54 #include "url/gurl.h" | 57 #include "url/gurl.h" |
| 55 | 58 |
| 56 #if defined(OS_WIN) | 59 #if defined(OS_WIN) |
| 57 #include "chrome/browser/browser_process.h" | 60 #include "chrome/browser/browser_process.h" |
| 58 #endif | 61 #endif |
| 59 | 62 |
| 60 #if defined(USE_AURA) | |
| 61 #include "ui/aura/client/focus_client.h" | |
| 62 #include "ui/aura/window_event_dispatcher.h" | |
| 63 #include "ui/compositor/layer.h" | |
| 64 #endif | |
| 65 | |
| 66 namespace { | 63 namespace { |
| 67 | 64 |
| 68 // Stores omnibox state for each tab. | 65 // Stores omnibox state for each tab. |
| 69 struct OmniboxState : public base::SupportsUserData::Data { | 66 struct OmniboxState : public base::SupportsUserData::Data { |
| 70 static const char kKey[]; | 67 static const char kKey[]; |
| 71 | 68 |
| 72 OmniboxState(const OmniboxEditModel::State& model_state, | 69 OmniboxState(const OmniboxEditModel::State& model_state, |
| 73 const gfx::Range& selection, | 70 const gfx::Range& selection, |
| 74 const gfx::Range& saved_selection_for_focus_change); | 71 const gfx::Range& saved_selection_for_focus_change); |
| 75 virtual ~OmniboxState(); | 72 virtual ~OmniboxState(); |
| (...skipping 757 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 833 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); | 830 saved_selection_for_focus_change_ = gfx::Range::InvalidRange(); |
| 834 } | 831 } |
| 835 } | 832 } |
| 836 | 833 |
| 837 void OmniboxViewViews::OnBlur() { | 834 void OmniboxViewViews::OnBlur() { |
| 838 // Save the user's existing selection to restore it later. | 835 // Save the user's existing selection to restore it later. |
| 839 saved_selection_for_focus_change_ = GetSelectedRange(); | 836 saved_selection_for_focus_change_ = GetSelectedRange(); |
| 840 | 837 |
| 841 views::Textfield::OnBlur(); | 838 views::Textfield::OnBlur(); |
| 842 gfx::NativeView native_view = NULL; | 839 gfx::NativeView native_view = NULL; |
| 843 #if defined(USE_AURA) | |
| 844 views::Widget* widget = GetWidget(); | 840 views::Widget* widget = GetWidget(); |
| 845 if (widget) { | 841 if (widget) { |
| 846 aura::client::FocusClient* client = | 842 aura::client::FocusClient* client = |
| 847 aura::client::GetFocusClient(widget->GetNativeView()); | 843 aura::client::GetFocusClient(widget->GetNativeView()); |
| 848 if (client) | 844 if (client) |
| 849 native_view = client->GetFocusedWindow(); | 845 native_view = client->GetFocusedWindow(); |
| 850 } | 846 } |
| 851 #endif | |
| 852 model()->OnWillKillFocus(native_view); | 847 model()->OnWillKillFocus(native_view); |
| 853 // Close the popup. | 848 // Close the popup. |
| 854 CloseOmniboxPopup(); | 849 CloseOmniboxPopup(); |
| 855 | 850 |
| 856 // Tell the model to reset itself. | 851 // Tell the model to reset itself. |
| 857 model()->OnKillFocus(); | 852 model()->OnKillFocus(); |
| 858 | 853 |
| 859 // Ignore loss of focus if we lost focus because the website settings popup | 854 // Ignore loss of focus if we lost focus because the website settings popup |
| 860 // is open. When the popup is destroyed, focus will return to the Omnibox. | 855 // is open. When the popup is destroyed, focus will return to the Omnibox. |
| 861 if (!WebsiteSettingsPopupView::IsPopupShowing()) | 856 if (!WebsiteSettingsPopupView::IsPopupShowing()) |
| (...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1048 menu_contents->InsertItemWithStringIdAt( | 1043 menu_contents->InsertItemWithStringIdAt( |
| 1049 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); | 1044 select_all_position + 1, IDS_SHOW_URL, IDS_SHOW_URL); |
| 1050 } | 1045 } |
| 1051 | 1046 |
| 1052 // Minor note: We use IDC_ for command id here while the underlying textfield | 1047 // Minor note: We use IDC_ for command id here while the underlying textfield |
| 1053 // is using IDS_ for all its command ids. This is because views cannot depend | 1048 // is using IDS_ for all its command ids. This is because views cannot depend |
| 1054 // on IDC_ for now. | 1049 // on IDC_ for now. |
| 1055 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, | 1050 menu_contents->AddItemWithStringId(IDC_EDIT_SEARCH_ENGINES, |
| 1056 IDS_EDIT_SEARCH_ENGINES); | 1051 IDS_EDIT_SEARCH_ENGINES); |
| 1057 } | 1052 } |
| OLD | NEW |