Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(77)

Side by Side Diff: chrome/browser/ui/views/omnibox/omnibox_view_views.cc

Issue 10825254: Remove views::KeyEvent, replacing uses of it with ui::KeyEvent. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/logging.h" 7 #include "base/logging.h"
8 #include "base/property_bag.h" 8 #include "base/property_bag.h"
9 #include "base/string_util.h" 9 #include "base/string_util.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 17 matching lines...) Expand all
28 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
29 #include "grit/app_locale_settings.h" 29 #include "grit/app_locale_settings.h"
30 #include "grit/generated_resources.h" 30 #include "grit/generated_resources.h"
31 #include "grit/ui_strings.h" 31 #include "grit/ui_strings.h"
32 #include "net/base/escape.h" 32 #include "net/base/escape.h"
33 #include "third_party/skia/include/core/SkColor.h" 33 #include "third_party/skia/include/core/SkColor.h"
34 #include "ui/base/accessibility/accessible_view_state.h" 34 #include "ui/base/accessibility/accessible_view_state.h"
35 #include "ui/base/clipboard/scoped_clipboard_writer.h" 35 #include "ui/base/clipboard/scoped_clipboard_writer.h"
36 #include "ui/base/dragdrop/drag_drop_types.h" 36 #include "ui/base/dragdrop/drag_drop_types.h"
37 #include "ui/base/dragdrop/os_exchange_data.h" 37 #include "ui/base/dragdrop/os_exchange_data.h"
38 #include "ui/base/event.h"
38 #include "ui/base/ime/text_input_client.h" 39 #include "ui/base/ime/text_input_client.h"
39 #include "ui/base/ime/text_input_type.h" 40 #include "ui/base/ime/text_input_type.h"
40 #include "ui/base/l10n/l10n_util.h" 41 #include "ui/base/l10n/l10n_util.h"
41 #include "ui/base/models/simple_menu_model.h" 42 #include "ui/base/models/simple_menu_model.h"
42 #include "ui/base/resource/resource_bundle.h" 43 #include "ui/base/resource/resource_bundle.h"
43 #include "ui/gfx/canvas.h" 44 #include "ui/gfx/canvas.h"
44 #include "ui/gfx/font.h" 45 #include "ui/gfx/font.h"
45 #include "ui/gfx/render_text.h" 46 #include "ui/gfx/render_text.h"
46 #include "ui/views/border.h" 47 #include "ui/views/border.h"
47 #include "ui/views/controls/textfield/textfield.h" 48 #include "ui/views/controls/textfield/textfield.h"
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
81 virtual void OnFocus() OVERRIDE { 82 virtual void OnFocus() OVERRIDE {
82 views::Textfield::OnFocus(); 83 views::Textfield::OnFocus();
83 omnibox_view_->HandleFocusIn(); 84 omnibox_view_->HandleFocusIn();
84 } 85 }
85 86
86 virtual void OnBlur() OVERRIDE { 87 virtual void OnBlur() OVERRIDE {
87 views::Textfield::OnBlur(); 88 views::Textfield::OnBlur();
88 omnibox_view_->HandleFocusOut(); 89 omnibox_view_->HandleFocusOut();
89 } 90 }
90 91
91 virtual bool OnKeyPressed(const views::KeyEvent& event) OVERRIDE { 92 virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE {
92 bool handled = views::Textfield::OnKeyPressed(event); 93 bool handled = views::Textfield::OnKeyPressed(event);
93 return omnibox_view_->HandleAfterKeyEvent(event, handled) || handled; 94 return omnibox_view_->HandleAfterKeyEvent(event, handled) || handled;
94 } 95 }
95 96
96 virtual bool OnKeyReleased(const views::KeyEvent& event) OVERRIDE { 97 virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE {
97 return omnibox_view_->HandleKeyReleaseEvent(event); 98 return omnibox_view_->HandleKeyReleaseEvent(event);
98 } 99 }
99 100
100 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE { 101 virtual bool OnMousePressed(const views::MouseEvent& event) OVERRIDE {
101 // Pass through the views::Textfield's return value; we don't need to 102 // Pass through the views::Textfield's return value; we don't need to
102 // override its behavior. 103 // override its behavior.
103 bool result = views::Textfield::OnMousePressed(event); 104 bool result = views::Textfield::OnMousePressed(event);
104 omnibox_view_->HandleMousePressEvent(event); 105 omnibox_view_->HandleMousePressEvent(event);
105 return result; 106 return result;
106 } 107 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 299
299 int OmniboxViewViews::WidthOfTextAfterCursor() { 300 int OmniboxViewViews::WidthOfTextAfterCursor() {
300 ui::Range sel; 301 ui::Range sel;
301 textfield_->GetSelectedRange(&sel); 302 textfield_->GetSelectedRange(&sel);
302 // See comments in LocationBarView::Layout as to why this uses -1. 303 // See comments in LocationBarView::Layout as to why this uses -1.
303 const int start = std::max(0, static_cast<int>(sel.end()) - 1); 304 const int start = std::max(0, static_cast<int>(sel.end()) - 1);
304 // TODO: add horizontal margin. 305 // TODO: add horizontal margin.
305 return textfield_->font().GetStringWidth(GetText().substr(start)); 306 return textfield_->font().GetStringWidth(GetText().substr(start));
306 } 307 }
307 308
308 bool OmniboxViewViews::HandleAfterKeyEvent(const views::KeyEvent& event, 309 bool OmniboxViewViews::HandleAfterKeyEvent(const ui::KeyEvent& event,
309 bool handled) { 310 bool handled) {
310 if (event.key_code() == ui::VKEY_RETURN) { 311 if (event.key_code() == ui::VKEY_RETURN) {
311 bool alt_held = event.IsAltDown(); 312 bool alt_held = event.IsAltDown();
312 model()->AcceptInput(alt_held ? NEW_FOREGROUND_TAB : CURRENT_TAB, false); 313 model()->AcceptInput(alt_held ? NEW_FOREGROUND_TAB : CURRENT_TAB, false);
313 handled = true; 314 handled = true;
314 } else if (!handled && event.key_code() == ui::VKEY_ESCAPE) { 315 } else if (!handled && event.key_code() == ui::VKEY_ESCAPE) {
315 // We can handle the Escape key if textfield did not handle it. 316 // We can handle the Escape key if textfield did not handle it.
316 // If it's not handled by us, then we need to propagate it up to the parent 317 // If it's not handled by us, then we need to propagate it up to the parent
317 // widgets, so that Escape accelerator can still work. 318 // widgets, so that Escape accelerator can still work.
318 handled = model()->OnEscapeKeyPressed(); 319 handled = model()->OnEscapeKeyPressed();
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
361 } 362 }
362 363
363 // TODO(Oshima): handle instant 364 // TODO(Oshima): handle instant
364 } 365 }
365 } 366 }
366 // TODO(oshima): page up & down 367 // TODO(oshima): page up & down
367 368
368 return handled; 369 return handled;
369 } 370 }
370 371
371 bool OmniboxViewViews::HandleKeyReleaseEvent(const views::KeyEvent& event) { 372 bool OmniboxViewViews::HandleKeyReleaseEvent(const ui::KeyEvent& event) {
372 // Omnibox2 can switch its contents while pressing a control key. To switch 373 // Omnibox2 can switch its contents while pressing a control key. To switch
373 // the contents of omnibox2, we notify the OmniboxEditModel class when the 374 // the contents of omnibox2, we notify the OmniboxEditModel class when the
374 // control-key state is changed. 375 // control-key state is changed.
375 if (event.key_code() == ui::VKEY_CONTROL) { 376 if (event.key_code() == ui::VKEY_CONTROL) {
376 // TODO(oshima): investigate if we need to support keyboard with two 377 // TODO(oshima): investigate if we need to support keyboard with two
377 // controls. 378 // controls.
378 model()->OnControlKeyChanged(false); 379 model()->OnControlKeyChanged(false);
379 return true; 380 return true;
380 } 381 }
381 return false; 382 return false;
(...skipping 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 } 717 }
717 718
718 //////////////////////////////////////////////////////////////////////////////// 719 ////////////////////////////////////////////////////////////////////////////////
719 // OmniboxViewViews, views::TextfieldController implementation: 720 // OmniboxViewViews, views::TextfieldController implementation:
720 721
721 void OmniboxViewViews::ContentsChanged(views::Textfield* sender, 722 void OmniboxViewViews::ContentsChanged(views::Textfield* sender,
722 const string16& new_contents) { 723 const string16& new_contents) {
723 } 724 }
724 725
725 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield, 726 bool OmniboxViewViews::HandleKeyEvent(views::Textfield* textfield,
726 const views::KeyEvent& event) { 727 const ui::KeyEvent& event) {
727 delete_at_end_pressed_ = false; 728 delete_at_end_pressed_ = false;
728 729
729 if (event.key_code() == ui::VKEY_BACK) { 730 if (event.key_code() == ui::VKEY_BACK) {
730 // Checks if it's currently in keyword search mode. 731 // Checks if it's currently in keyword search mode.
731 if (model()->is_keyword_hint() || model()->keyword().empty()) 732 if (model()->is_keyword_hint() || model()->keyword().empty())
732 return false; 733 return false;
733 // If there is selection, let textfield handle the backspace. 734 // If there is selection, let textfield handle the backspace.
734 if (textfield_->HasSelection()) 735 if (textfield_->HasSelection())
735 return false; 736 return false;
736 // If not at the begining of the text, let textfield handle the backspace. 737 // If not at the begining of the text, let textfield handle the backspace.
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 const ui::Range& range) { 899 const ui::Range& range) {
899 if (text != GetText()) 900 if (text != GetText())
900 textfield_->SetText(text); 901 textfield_->SetText(text);
901 textfield_->SelectRange(range); 902 textfield_->SelectRange(range);
902 } 903 }
903 904
904 string16 OmniboxViewViews::GetSelectedText() const { 905 string16 OmniboxViewViews::GetSelectedText() const {
905 // TODO(oshima): Support instant, IME. 906 // TODO(oshima): Support instant, IME.
906 return textfield_->GetSelectedText(); 907 return textfield_->GetSelectedText();
907 } 908 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/omnibox/omnibox_view_views.h ('k') | chrome/browser/ui/views/omnibox/omnibox_view_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698