| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/autocomplete/autocomplete_edit_view_views.h" | 5 #include "chrome/browser/autocomplete/autocomplete_edit_view_views.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/app/chrome_command_ids.h" | 10 #include "chrome/app/chrome_command_ids.h" |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 NOTIMPLEMENTED(); | 158 NOTIMPLEMENTED(); |
| 159 } | 159 } |
| 160 | 160 |
| 161 bool AutocompleteEditViewViews::HandleAfterKeyEvent( | 161 bool AutocompleteEditViewViews::HandleAfterKeyEvent( |
| 162 const views::KeyEvent& event, | 162 const views::KeyEvent& event, |
| 163 bool handled) { | 163 bool handled) { |
| 164 handling_key_press_ = false; | 164 handling_key_press_ = false; |
| 165 if (content_maybe_changed_by_key_press_) | 165 if (content_maybe_changed_by_key_press_) |
| 166 OnAfterPossibleChange(); | 166 OnAfterPossibleChange(); |
| 167 | 167 |
| 168 if (event.GetKeyCode() == ui::VKEY_RETURN) { | 168 if (event.key_code() == ui::VKEY_RETURN) { |
| 169 bool alt_held = event.IsAltDown(); | 169 bool alt_held = event.IsAltDown(); |
| 170 model_->AcceptInput(alt_held ? NEW_FOREGROUND_TAB : CURRENT_TAB, false); | 170 model_->AcceptInput(alt_held ? NEW_FOREGROUND_TAB : CURRENT_TAB, false); |
| 171 handled = true; | 171 handled = true; |
| 172 } else if (!handled && event.GetKeyCode() == ui::VKEY_ESCAPE) { | 172 } else if (!handled && event.key_code() == ui::VKEY_ESCAPE) { |
| 173 // We can handle the Escape key if textfield did not handle it. | 173 // We can handle the Escape key if textfield did not handle it. |
| 174 // If it's not handled by us, then we need to propagate it up to the parent | 174 // If it's not handled by us, then we need to propagate it up to the parent |
| 175 // widgets, so that Escape accelerator can still work. | 175 // widgets, so that Escape accelerator can still work. |
| 176 handled = model_->OnEscapeKeyPressed(); | 176 handled = model_->OnEscapeKeyPressed(); |
| 177 } else if (event.GetKeyCode() == ui::VKEY_CONTROL) { | 177 } else if (event.key_code() == ui::VKEY_CONTROL) { |
| 178 // Omnibox2 can switch its contents while pressing a control key. To switch | 178 // Omnibox2 can switch its contents while pressing a control key. To switch |
| 179 // the contents of omnibox2, we notify the AutocompleteEditModel class when | 179 // the contents of omnibox2, we notify the AutocompleteEditModel class when |
| 180 // the control-key state is changed. | 180 // the control-key state is changed. |
| 181 model_->OnControlKeyChanged(true); | 181 model_->OnControlKeyChanged(true); |
| 182 } else if (!text_changed_ && event.GetKeyCode() == ui::VKEY_DELETE && | 182 } else if (!text_changed_ && event.key_code() == ui::VKEY_DELETE && |
| 183 event.IsShiftDown()) { | 183 event.IsShiftDown()) { |
| 184 // If shift+del didn't change the text, we let this delete an entry from | 184 // If shift+del didn't change the text, we let this delete an entry from |
| 185 // the popup. We can't check to see if the IME handled it because even if | 185 // the popup. We can't check to see if the IME handled it because even if |
| 186 // nothing is selected, the IME or the TextView still report handling it. | 186 // nothing is selected, the IME or the TextView still report handling it. |
| 187 AutocompletePopupModel* popup_model = popup_view_->GetModel(); | 187 AutocompletePopupModel* popup_model = popup_view_->GetModel(); |
| 188 if (popup_model->IsOpen()) | 188 if (popup_model->IsOpen()) |
| 189 popup_model->TryDeletingCurrentItem(); | 189 popup_model->TryDeletingCurrentItem(); |
| 190 } else if (!handled && event.GetKeyCode() == ui::VKEY_UP) { | 190 } else if (!handled && event.key_code() == ui::VKEY_UP) { |
| 191 model_->OnUpOrDownKeyPressed(-1); | 191 model_->OnUpOrDownKeyPressed(-1); |
| 192 handled = true; | 192 handled = true; |
| 193 } else if (!handled && event.GetKeyCode() == ui::VKEY_DOWN) { | 193 } else if (!handled && event.key_code() == ui::VKEY_DOWN) { |
| 194 model_->OnUpOrDownKeyPressed(1); | 194 model_->OnUpOrDownKeyPressed(1); |
| 195 handled = true; | 195 handled = true; |
| 196 } else if (!handled && | 196 } else if (!handled && |
| 197 event.GetKeyCode() == ui::VKEY_TAB && | 197 event.key_code() == ui::VKEY_TAB && |
| 198 !event.IsShiftDown() && | 198 !event.IsShiftDown() && |
| 199 !event.IsControlDown()) { | 199 !event.IsControlDown()) { |
| 200 if (model_->is_keyword_hint()) { | 200 if (model_->is_keyword_hint()) { |
| 201 handled = model_->AcceptKeyword(); | 201 handled = model_->AcceptKeyword(); |
| 202 } else { | 202 } else { |
| 203 string16::size_type start = 0; | 203 string16::size_type start = 0; |
| 204 string16::size_type end = 0; | 204 string16::size_type end = 0; |
| 205 size_t length = GetTextLength(); | 205 size_t length = GetTextLength(); |
| 206 GetSelectionBounds(&start, &end); | 206 GetSelectionBounds(&start, &end); |
| 207 if (start != end || start < length) { | 207 if (start != end || start < length) { |
| 208 OnBeforePossibleChange(); | 208 OnBeforePossibleChange(); |
| 209 SelectRange(length, length); | 209 SelectRange(length, length); |
| 210 OnAfterPossibleChange(); | 210 OnAfterPossibleChange(); |
| 211 handled = true; | 211 handled = true; |
| 212 } | 212 } |
| 213 | 213 |
| 214 // TODO(Oshima): handle instant | 214 // TODO(Oshima): handle instant |
| 215 } | 215 } |
| 216 } | 216 } |
| 217 // TODO(oshima): page up & down | 217 // TODO(oshima): page up & down |
| 218 | 218 |
| 219 return handled; | 219 return handled; |
| 220 } | 220 } |
| 221 | 221 |
| 222 bool AutocompleteEditViewViews::HandleKeyReleaseEvent( | 222 bool AutocompleteEditViewViews::HandleKeyReleaseEvent( |
| 223 const views::KeyEvent& event) { | 223 const views::KeyEvent& event) { |
| 224 // Omnibox2 can switch its contents while pressing a control key. To switch | 224 // Omnibox2 can switch its contents while pressing a control key. To switch |
| 225 // the contents of omnibox2, we notify the AutocompleteEditModel class when | 225 // the contents of omnibox2, we notify the AutocompleteEditModel class when |
| 226 // the control-key state is changed. | 226 // the control-key state is changed. |
| 227 if (event.GetKeyCode() == ui::VKEY_CONTROL) { | 227 if (event.key_code() == ui::VKEY_CONTROL) { |
| 228 // TODO(oshima): investigate if we need to support keyboard with two | 228 // TODO(oshima): investigate if we need to support keyboard with two |
| 229 // controls. See autocomplete_edit_view_gtk.cc. | 229 // controls. See autocomplete_edit_view_gtk.cc. |
| 230 model_->OnControlKeyChanged(false); | 230 model_->OnControlKeyChanged(false); |
| 231 return true; | 231 return true; |
| 232 } | 232 } |
| 233 return false; | 233 return false; |
| 234 } | 234 } |
| 235 | 235 |
| 236 void AutocompleteEditViewViews::HandleFocusIn() { | 236 void AutocompleteEditViewViews::HandleFocusIn() { |
| 237 // TODO(oshima): Get control key state. | 237 // TODO(oshima): Get control key state. |
| (...skipping 338 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 | 576 |
| 577 void AutocompleteEditViewViews::ContentsChanged(views::Textfield* sender, | 577 void AutocompleteEditViewViews::ContentsChanged(views::Textfield* sender, |
| 578 const string16& new_contents) { | 578 const string16& new_contents) { |
| 579 if (handling_key_press_) | 579 if (handling_key_press_) |
| 580 content_maybe_changed_by_key_press_ = true; | 580 content_maybe_changed_by_key_press_ = true; |
| 581 } | 581 } |
| 582 | 582 |
| 583 bool AutocompleteEditViewViews::HandleKeyEvent( | 583 bool AutocompleteEditViewViews::HandleKeyEvent( |
| 584 views::Textfield* textfield, | 584 views::Textfield* textfield, |
| 585 const views::KeyEvent& event) { | 585 const views::KeyEvent& event) { |
| 586 delete_was_pressed_ = event.GetKeyCode() == ui::VKEY_DELETE; | 586 delete_was_pressed_ = event.key_code() == ui::VKEY_DELETE; |
| 587 | 587 |
| 588 // Reset |text_changed_| before passing the key event on to the text view. | 588 // Reset |text_changed_| before passing the key event on to the text view. |
| 589 text_changed_ = false; | 589 text_changed_ = false; |
| 590 OnBeforePossibleChange(); | 590 OnBeforePossibleChange(); |
| 591 handling_key_press_ = true; | 591 handling_key_press_ = true; |
| 592 content_maybe_changed_by_key_press_ = false; | 592 content_maybe_changed_by_key_press_ = false; |
| 593 | 593 |
| 594 if (event.GetKeyCode() == ui::VKEY_BACK) { | 594 if (event.key_code() == ui::VKEY_BACK) { |
| 595 // Checks if it's currently in keyword search mode. | 595 // Checks if it's currently in keyword search mode. |
| 596 if (model_->is_keyword_hint() || model_->keyword().empty()) | 596 if (model_->is_keyword_hint() || model_->keyword().empty()) |
| 597 return false; | 597 return false; |
| 598 // If there is selection, let textfield handle the backspace. | 598 // If there is selection, let textfield handle the backspace. |
| 599 if (!textfield_->GetSelectedText().empty()) | 599 if (!textfield_->GetSelectedText().empty()) |
| 600 return false; | 600 return false; |
| 601 // If not at the begining of the text, let textfield handle the backspace. | 601 // If not at the begining of the text, let textfield handle the backspace. |
| 602 if (textfield_->GetCursorPosition()) | 602 if (textfield_->GetCursorPosition()) |
| 603 return false; | 603 return false; |
| 604 model_->ClearKeyword(GetText()); | 604 model_->ClearKeyword(GetText()); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 636 |
| 637 string16 AutocompleteEditViewViews::GetSelectedText() const { | 637 string16 AutocompleteEditViewViews::GetSelectedText() const { |
| 638 // TODO(oshima): Support instant, IME. | 638 // TODO(oshima): Support instant, IME. |
| 639 return textfield_->GetSelectedText(); | 639 return textfield_->GetSelectedText(); |
| 640 } | 640 } |
| 641 | 641 |
| 642 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) { | 642 void AutocompleteEditViewViews::SelectRange(size_t caret, size_t end) { |
| 643 const views::TextRange range(caret, end); | 643 const views::TextRange range(caret, end); |
| 644 textfield_->SelectRange(range); | 644 textfield_->SelectRange(range); |
| 645 } | 645 } |
| OLD | NEW |