Chromium Code Reviews| 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/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 43 #include "ui/gfx/selection_model.h" | 43 #include "ui/gfx/selection_model.h" |
| 44 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 45 #include "ui/views/button_drag_utils.h" | 45 #include "ui/views/button_drag_utils.h" |
| 46 #include "ui/views/controls/textfield/textfield.h" | 46 #include "ui/views/controls/textfield/textfield.h" |
| 47 #include "ui/views/ime/input_method.h" | 47 #include "ui/views/ime/input_method.h" |
| 48 #include "ui/views/layout/fill_layout.h" | 48 #include "ui/views/layout/fill_layout.h" |
| 49 #include "ui/views/views_delegate.h" | 49 #include "ui/views/views_delegate.h" |
| 50 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
| 51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
| 52 | 52 |
| 53 #if defined(OS_WIN) | |
| 54 #include "base/win/metro.h" | |
| 55 #include "chrome/browser/browser_process.h" | |
| 56 #endif | |
| 57 | |
| 53 #if defined(USE_AURA) | 58 #if defined(USE_AURA) |
| 54 #include "ui/aura/focus_manager.h" | 59 #include "ui/aura/focus_manager.h" |
| 55 #include "ui/aura/root_window.h" | 60 #include "ui/aura/root_window.h" |
| 56 #include "ui/compositor/layer.h" | 61 #include "ui/compositor/layer.h" |
| 57 #endif | 62 #endif |
| 58 | 63 |
| 59 namespace { | 64 namespace { |
| 60 | 65 |
| 61 // Stores omnibox state for each tab. | 66 // Stores omnibox state for each tab. |
| 62 struct OmniboxState : public base::SupportsUserData::Data { | 67 struct OmniboxState : public base::SupportsUserData::Data { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 81 | 86 |
| 82 OmniboxState::~OmniboxState() {} | 87 OmniboxState::~OmniboxState() {} |
| 83 | 88 |
| 84 // This will write |url| and |text| to the clipboard as a well-formed URL. | 89 // This will write |url| and |text| to the clipboard as a well-formed URL. |
| 85 void DoCopyURL(const GURL& url, const string16& text) { | 90 void DoCopyURL(const GURL& url, const string16& text) { |
| 86 BookmarkNodeData data; | 91 BookmarkNodeData data; |
| 87 data.ReadFromTuple(url, text); | 92 data.ReadFromTuple(url, text); |
| 88 data.WriteToClipboard(); | 93 data.WriteToClipboard(); |
| 89 } | 94 } |
| 90 | 95 |
| 96 // The IME's input mode automatically falls into the Latin character mode if | |
| 97 // ui::TEXT_INPUT_TYPE_URL is specified on Windows TSF environment, and that is | |
| 98 // bad experience for IME users. However, software keyboards provide special | |
| 99 // layout when ui::TEXT_INPUT_TYPE_URL is specified, for example ".com" and "/" | |
| 100 // keys appear on English software keyboard. So we set | |
| 101 // ui::TEXT_INPUT_TYPE_SEARCH for those who are likely IME users, and | |
| 102 // ui::TEXT_INPUT_TYPE_URL for the rest who are likely non-IME users. | |
|
Peter Kasting
2013/09/13 17:16:37
Nit: This comment is pretty good, here's my attemp
Yuki
2013/09/17 08:33:39
Done.
| |
| 103 ui::TextInputType DetermineTextInputType() { | |
| 104 #if defined(OS_WIN) | |
| 105 if (base::win::IsTSFAwareRequired()) { | |
| 106 DCHECK(g_browser_process); | |
| 107 const std::string& locale = g_browser_process->GetApplicationLocale(); | |
| 108 const std::string& language = locale.substr(0, 2); | |
| 109 // Suppose CJK + Thai users are using an IME. | |
|
Peter Kasting
2013/09/13 17:16:37
Nit: Suppose -> Assume
Yuki
2013/09/17 08:33:39
Done.
| |
| 110 if (language == "ja" || | |
| 111 language == "ko" || | |
| 112 language == "th" || | |
| 113 language == "zh") | |
| 114 return ui::TEXT_INPUT_TYPE_SEARCH; | |
| 115 } | |
| 116 #endif | |
| 117 return ui::TEXT_INPUT_TYPE_URL; | |
| 118 } | |
| 119 | |
| 91 bool IsOmniboxAutoCompletionForImeEnabled() { | 120 bool IsOmniboxAutoCompletionForImeEnabled() { |
| 92 return !CommandLine::ForCurrentProcess()->HasSwitch( | 121 return !CommandLine::ForCurrentProcess()->HasSwitch( |
| 93 switches::kDisableOmniboxAutoCompletionForIme); | 122 switches::kDisableOmniboxAutoCompletionForIme); |
| 94 } | 123 } |
| 95 | 124 |
| 96 } // namespace | 125 } // namespace |
| 97 | 126 |
| 98 // static | 127 // static |
| 99 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; | 128 const char OmniboxViewViews::kViewClassName[] = "OmniboxViewViews"; |
| 100 | 129 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 130 // Explicitly teardown members which have a reference to us. Just to be safe | 159 // Explicitly teardown members which have a reference to us. Just to be safe |
| 131 // we want them to be destroyed before destroying any other internal state. | 160 // we want them to be destroyed before destroying any other internal state. |
| 132 popup_view_.reset(); | 161 popup_view_.reset(); |
| 133 } | 162 } |
| 134 | 163 |
| 135 //////////////////////////////////////////////////////////////////////////////// | 164 //////////////////////////////////////////////////////////////////////////////// |
| 136 // OmniboxViewViews public: | 165 // OmniboxViewViews public: |
| 137 | 166 |
| 138 void OmniboxViewViews::Init() { | 167 void OmniboxViewViews::Init() { |
| 139 SetController(this); | 168 SetController(this); |
| 140 SetTextInputType(ui::TEXT_INPUT_TYPE_URL); | 169 SetTextInputType(DetermineTextInputType()); |
| 141 SetBackgroundColor(location_bar_view_->GetColor( | 170 SetBackgroundColor(location_bar_view_->GetColor( |
| 142 ToolbarModel::NONE, LocationBarView::BACKGROUND)); | 171 ToolbarModel::NONE, LocationBarView::BACKGROUND)); |
| 143 | 172 |
| 144 if (popup_window_mode_) | 173 if (popup_window_mode_) |
| 145 SetReadOnly(true); | 174 SetReadOnly(true); |
| 146 | 175 |
| 147 // Initialize the popup view using the same font. | 176 // Initialize the popup view using the same font. |
| 148 popup_view_.reset(OmniboxPopupContentsView::Create( | 177 popup_view_.reset(OmniboxPopupContentsView::Create( |
| 149 font_list(), this, model(), location_bar_view_)); | 178 font_list(), this, model(), location_bar_view_)); |
| 150 | 179 |
| (...skipping 746 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 897 const string16 text(GetClipboardText()); | 926 const string16 text(GetClipboardText()); |
| 898 if (!text.empty()) { | 927 if (!text.empty()) { |
| 899 // Record this paste, so we can do different behavior. | 928 // Record this paste, so we can do different behavior. |
| 900 model()->on_paste(); | 929 model()->on_paste(); |
| 901 // Force a Paste operation to trigger the text_changed code in | 930 // Force a Paste operation to trigger the text_changed code in |
| 902 // OnAfterPossibleChange(), even if identical contents are pasted. | 931 // OnAfterPossibleChange(), even if identical contents are pasted. |
| 903 text_before_change_.clear(); | 932 text_before_change_.clear(); |
| 904 InsertOrReplaceText(text); | 933 InsertOrReplaceText(text); |
| 905 } | 934 } |
| 906 } | 935 } |
| OLD | NEW |