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

Side by Side Diff: webkit/glue/webview_impl.cc

Issue 20046: Home and End keys should not be processed by the autocomplete popup (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 10 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
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2007 Google Inc. All Rights Reserved. 2 * Copyright 2007 Google Inc. All Rights Reserved.
3 * 3 *
4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved. 4 * Portions Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
5 * 5 *
6 * ***** BEGIN LICENSE BLOCK ***** 6 * ***** BEGIN LICENSE BLOCK *****
7 * 7 *
8 * Redistribution and use in source and binary forms, with or without 8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions 9 * modification, are permitted provided that the following conditions
10 * are met: 10 * are met:
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
71 #endif 71 #endif
72 #include "RenderView.h" 72 #include "RenderView.h"
73 #include "ResourceHandle.h" 73 #include "ResourceHandle.h"
74 #include "SelectionController.h" 74 #include "SelectionController.h"
75 #include "Settings.h" 75 #include "Settings.h"
76 #include "TypingCommand.h" 76 #include "TypingCommand.h"
77 MSVC_POP_WARNING(); 77 MSVC_POP_WARNING();
78 #undef LOG 78 #undef LOG
79 79
80 #include "base/gfx/rect.h" 80 #include "base/gfx/rect.h"
81 #include "base/keyboard_codes.h"
81 #include "base/logging.h" 82 #include "base/logging.h"
82 #include "base/message_loop.h" 83 #include "base/message_loop.h"
83 #include "base/string_util.h" 84 #include "base/string_util.h"
84 #include "webkit/glue/chrome_client_impl.h" 85 #include "webkit/glue/chrome_client_impl.h"
85 #include "webkit/glue/clipboard_conversion.h" 86 #include "webkit/glue/clipboard_conversion.h"
86 #include "webkit/glue/context_menu_client_impl.h" 87 #include "webkit/glue/context_menu_client_impl.h"
87 #include "webkit/glue/dragclient_impl.h" 88 #include "webkit/glue/dragclient_impl.h"
88 #include "webkit/glue/editor_client_impl.h" 89 #include "webkit/glue/editor_client_impl.h"
89 #include "webkit/glue/event_conversion.h" 90 #include "webkit/glue/event_conversion.h"
90 #include "webkit/glue/glue_serialize.h" 91 #include "webkit/glue/glue_serialize.h"
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
130 const std::vector<std::wstring>& suggestions, 131 const std::vector<std::wstring>& suggestions,
131 int default_suggestion_index) 132 int default_suggestion_index)
132 : text_field_(text_field), 133 : text_field_(text_field),
133 selected_index_(default_suggestion_index), 134 selected_index_(default_suggestion_index),
134 webview_(webview) { 135 webview_(webview) {
135 SetSuggestions(suggestions); 136 SetSuggestions(suggestions);
136 } 137 }
137 virtual ~AutocompletePopupMenuClient() { 138 virtual ~AutocompletePopupMenuClient() {
138 } 139 }
139 140
141 // WebCore::PopupMenuClient implementation.
140 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) { 142 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) {
141 text_field_->setValue(suggestions_[listIndex]); 143 text_field_->setValue(suggestions_[listIndex]);
142 } 144 }
143 145
144 virtual WebCore::String itemText(unsigned list_index) const { 146 virtual WebCore::String itemText(unsigned list_index) const {
145 return suggestions_[list_index]; 147 return suggestions_[list_index];
146 } 148 }
147 149
148 virtual bool itemIsEnabled(unsigned listIndex) const { 150 virtual bool itemIsEnabled(unsigned listIndex) const {
149 return true; 151 return true;
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 virtual PassRefPtr<Scrollbar> createScrollbar( 225 virtual PassRefPtr<Scrollbar> createScrollbar(
224 ScrollbarClient* client, 226 ScrollbarClient* client,
225 ScrollbarOrientation orientation, 227 ScrollbarOrientation orientation,
226 ScrollbarControlSize size) { 228 ScrollbarControlSize size) {
227 RefPtr<Scrollbar> widget = Scrollbar::createNativeScrollbar(client, 229 RefPtr<Scrollbar> widget = Scrollbar::createNativeScrollbar(client,
228 orientation, 230 orientation,
229 size); 231 size);
230 return widget.release(); 232 return widget.release();
231 } 233 }
232 234
235 // AutocompletePopupMenuClient specific methods:
233 void SetSuggestions(const std::vector<std::wstring>& suggestions) { 236 void SetSuggestions(const std::vector<std::wstring>& suggestions) {
234 suggestions_.clear(); 237 suggestions_.clear();
235 for (std::vector<std::wstring>::const_iterator iter = suggestions.begin(); 238 for (std::vector<std::wstring>::const_iterator iter = suggestions.begin();
236 iter != suggestions.end(); ++iter) { 239 iter != suggestions.end(); ++iter) {
237 suggestions_.push_back(webkit_glue::StdWStringToString(*iter)); 240 suggestions_.push_back(webkit_glue::StdWStringToString(*iter));
238 } 241 }
239 // Try to preserve selection if possible. 242 // Try to preserve selection if possible.
240 if (selected_index_ >= static_cast<int>(suggestions.size())) 243 if (selected_index_ >= static_cast<int>(suggestions.size()))
241 selected_index_ = -1; 244 selected_index_ = -1;
242 } 245 }
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
444 447
445 // Please refer to the comments explaining the suppress_next_keypress_event_ 448 // Please refer to the comments explaining the suppress_next_keypress_event_
446 // member. 449 // member.
447 // The suppress_next_keypress_event_ is set if the KeyDown is handled by 450 // The suppress_next_keypress_event_ is set if the KeyDown is handled by
448 // Webkit. A keyDown event is typically associated with a keyPress(char) 451 // Webkit. A keyDown event is typically associated with a keyPress(char)
449 // event and a keyUp event. We reset this flag here as this is a new keyDown 452 // event and a keyUp event. We reset this flag here as this is a new keyDown
450 // event. 453 // event.
451 suppress_next_keypress_event_ = false; 454 suppress_next_keypress_event_ = false;
452 455
453 // Give autocomplete a chance to consume the key events it is interested in. 456 // Give autocomplete a chance to consume the key events it is interested in.
454 if (autocomplete_popup_ && 457 if (AutocompleteHandleKeyEvent(event))
455 autocomplete_popup_->isInterestedInEventForKey(event.key_code)) { 458 return true;
456 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) {
457 #if defined(OS_WIN)
458 // We need to ignore the next CHAR event after this otherwise pressing
459 // enter when selecting an item in the menu will go to the page.
460 if (WebInputEvent::KEY_DOWN == event.type)
461 suppress_next_keypress_event_ = true;
462 #endif
463 return true;
464 }
465 }
466 459
467 Frame* frame = GetFocusedWebCoreFrame(); 460 Frame* frame = GetFocusedWebCoreFrame();
468 if (!frame) 461 if (!frame)
469 return false; 462 return false;
470 463
471 EventHandler* handler = frame->eventHandler(); 464 EventHandler* handler = frame->eventHandler();
472 if (!handler) 465 if (!handler)
473 return KeyEventDefault(event); 466 return KeyEventDefault(event);
474 467
475 #if defined(OS_WIN) 468 #if defined(OS_WIN)
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 // that we'll know that this is the only time we'll have the event and that 500 // that we'll know that this is the only time we'll have the event and that
508 // we need to do our thing. 501 // we need to do our thing.
509 if (handler->keyEvent(evt)) { 502 if (handler->keyEvent(evt)) {
510 return true; 503 return true;
511 } 504 }
512 #endif 505 #endif
513 506
514 return KeyEventDefault(event); 507 return KeyEventDefault(event);
515 } 508 }
516 509
510 bool WebViewImpl::AutocompleteHandleKeyEvent(const WebKeyboardEvent& event) {
511 if (!autocomplete_popup_ ||
512 // Home and End should be left to the text field to process.
513 event.key_code == base::VKEY_HOME || event.key_code == base::VKEY_END) {
514 return false;
515 }
516
517 if (!autocomplete_popup_->isInterestedInEventForKey(event.key_code))
518 return false;
519
520 if (autocomplete_popup_->handleKeyEvent(MakePlatformKeyboardEvent(event))) {
521 #if defined(OS_WIN)
522 // We need to ignore the next CHAR event after this otherwise pressing
523 // enter when selecting an item in the menu will go to the page.
524 if (WebInputEvent::KEY_DOWN == event.type)
525 suppress_next_keypress_event_ = true;
526 #endif
527 return true;
528 }
529
530 return false;
531 }
532
517 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) { 533 bool WebViewImpl::CharEvent(const WebKeyboardEvent& event) {
518 DCHECK(event.type == WebInputEvent::CHAR); 534 DCHECK(event.type == WebInputEvent::CHAR);
519 535
520 // Please refer to the comments explaining the suppress_next_keypress_event_ 536 // Please refer to the comments explaining the suppress_next_keypress_event_
521 // member. 537 // member.
522 // The suppress_next_keypress_event_ is set if the KeyDown is handled by 538 // The suppress_next_keypress_event_ is set if the KeyDown is handled by
523 // Webkit. A keyDown event is typically associated with a keyPress(char) 539 // Webkit. A keyDown event is typically associated with a keyPress(char)
524 // event and a keyUp event. We reset this flag here as it only applies 540 // event and a keyUp event. We reset this flag here as it only applies
525 // to the current keyPress event. 541 // to the current keyPress event.
526 if (suppress_next_keypress_event_) { 542 if (suppress_next_keypress_event_) {
(...skipping 1105 matching lines...) Expand 10 before | Expand all | Expand 10 after
1632 Frame* frame = page_->focusController()->focusedFrame(); 1648 Frame* frame = page_->focusController()->focusedFrame();
1633 if (!frame) 1649 if (!frame)
1634 return NULL; 1650 return NULL;
1635 1651
1636 Document* document = frame->document(); 1652 Document* document = frame->document();
1637 if (!document) 1653 if (!document)
1638 return NULL; 1654 return NULL;
1639 1655
1640 return document->focusedNode(); 1656 return document->focusedNode();
1641 } 1657 }
OLDNEW
« no previous file with comments | « webkit/glue/webview_impl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698