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

Side by Side Diff: chrome/browser/views/tab_contents/tab_contents_view_win.cc

Issue 400012: Refactor the keyboard events handling code related to RenderViewHostDelegate:... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years 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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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/views/tab_contents/tab_contents_view_win.h" 5 #include "chrome/browser/views/tab_contents/tab_contents_view_win.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 8
9 #include "app/gfx/canvas_paint.h" 9 #include "app/gfx/canvas_paint.h"
10 #include "app/os_exchange_data.h" 10 #include "app/os_exchange_data.h"
(...skipping 29 matching lines...) Expand all
40 using WebKit::WebDragOperationsMask; 40 using WebKit::WebDragOperationsMask;
41 using WebKit::WebInputEvent; 41 using WebKit::WebInputEvent;
42 42
43 // static 43 // static
44 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 44 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
45 return new TabContentsViewWin(tab_contents); 45 return new TabContentsViewWin(tab_contents);
46 } 46 }
47 47
48 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents) 48 TabContentsViewWin::TabContentsViewWin(TabContents* tab_contents)
49 : TabContentsView(tab_contents), 49 : TabContentsView(tab_contents),
50 ignore_next_char_event_(false),
51 focus_manager_(NULL), 50 focus_manager_(NULL),
52 close_tab_after_drag_ends_(false), 51 close_tab_after_drag_ends_(false),
53 sad_tab_(NULL) { 52 sad_tab_(NULL) {
54 last_focused_view_storage_id_ = 53 last_focused_view_storage_id_ =
55 views::ViewStorage::GetSharedInstance()->CreateStorageID(); 54 views::ViewStorage::GetSharedInstance()->CreateStorageID();
56 } 55 }
57 56
58 TabContentsViewWin::~TabContentsViewWin() { 57 TabContentsViewWin::~TabContentsViewWin() {
59 // Makes sure to remove any stored view we may still have in the ViewStorage. 58 // Makes sure to remove any stored view we may still have in the ViewStorage.
60 // 59 //
(...skipping 294 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 views::FocusManager* focus_manager = 354 views::FocusManager* focus_manager =
356 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); 355 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
357 356
358 // We may not have a focus manager if the tab has been switched before this 357 // We may not have a focus manager if the tab has been switched before this
359 // message arrived. 358 // message arrived.
360 if (focus_manager) 359 if (focus_manager)
361 focus_manager->AdvanceFocus(reverse); 360 focus_manager->AdvanceFocus(reverse);
362 } 361 }
363 } 362 }
364 363
365 bool TabContentsViewWin::HandleKeyboardEvent(
366 const NativeWebKeyboardEvent& event) {
367 // Previous calls to TranslateMessage can generate CHAR events as well as
368 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these
369 // cases, we discard the CHAR events.
370 if (event.type == WebInputEvent::Char && ignore_next_char_event_) {
371 ignore_next_char_event_ = false;
372 return true;
373 }
374 ignore_next_char_event_ = false;
375
376 // The renderer returned a keyboard event it did not process. This may be
377 // a keyboard shortcut that we have to process.
378 if (event.type == WebInputEvent::RawKeyDown) {
379 views::FocusManager* focus_manager =
380 views::FocusManager::GetFocusManagerForNativeView(GetNativeView());
381 // We may not have a focus_manager at this point (if the tab has been
382 // switched by the time this message returned).
383 if (focus_manager) {
384 views::Accelerator accelerator(
385 win_util::WinToKeyboardCode(event.windowsKeyCode),
386 (event.modifiers & WebInputEvent::ShiftKey) ==
387 WebInputEvent::ShiftKey,
388 (event.modifiers & WebInputEvent::ControlKey) ==
389 WebInputEvent::ControlKey,
390 (event.modifiers & WebInputEvent::AltKey) ==
391 WebInputEvent::AltKey);
392
393 // This is tricky: we want to set ignore_next_char_event_ if
394 // ProcessAccelerator returns true. But ProcessAccelerator might delete
395 // |this| if the accelerator is a "close tab" one. So we speculatively
396 // set the flag and fix it if no event was handled.
397 ignore_next_char_event_ = true;
398 if (focus_manager->ProcessAccelerator(accelerator)) {
399 // DANGER: |this| could be deleted now!
400 return true;
401 } else {
402 // ProcessAccelerator didn't handle the accelerator, so we know both
403 // that |this| is still valid, and that we didn't want to set the flag.
404 ignore_next_char_event_ = false;
405 }
406 }
407 }
408
409 if (tab_contents()->delegate() &&
410 tab_contents()->delegate()->HandleKeyboardEvent(event)) {
411 // At this point the only tab contents delegate which handles a keyboard
412 // event is ChromeFrame. When the message comes back from ChromeFrame it
413 // is DefWindowProc'ed. We return false here on the same lines as below:-
414 return false;
415 }
416
417 // Any unhandled keyboard/character messages should be defproced.
418 // This allows stuff like Alt+F4, etc to work correctly.
419 DefWindowProc(event.os_event.hwnd, event.os_event.message,
420 event.os_event.wParam, event.os_event.lParam);
421
422 // DefWindowProc() always returns 0, which means it handled the event.
423 // But actually DefWindowProc() will only handle very few system key strokes,
424 // such as F10, Alt+Tab, Alt+F4, Alt+Esc, etc.
425 // So returning false here is just ok for most cases.
426 // Reference: http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx
427 return false;
428 }
429
430 views::FocusManager* TabContentsViewWin::GetFocusManager() { 364 views::FocusManager* TabContentsViewWin::GetFocusManager() {
431 views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); 365 views::FocusManager* focus_manager = WidgetWin::GetFocusManager();
432 if (focus_manager) { 366 if (focus_manager) {
433 // If focus_manager_ is non NULL, it means we have been reparented, in which 367 // If focus_manager_ is non NULL, it means we have been reparented, in which
434 // case its value may not be valid anymore. 368 // case its value may not be valid anymore.
435 focus_manager_ = NULL; 369 focus_manager_ = NULL;
436 return focus_manager; 370 return focus_manager;
437 } 371 }
438 // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be 372 // TODO(jcampan): we should DCHECK on focus_manager_, as it should not be
439 // NULL. We are not doing it as it breaks some unit-tests. We should 373 // NULL. We are not doing it as it breaks some unit-tests. We should
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
672 } 606 }
673 return false; 607 return false;
674 } 608 }
675 609
676 void TabContentsViewWin::WheelZoom(int distance) { 610 void TabContentsViewWin::WheelZoom(int distance) {
677 if (tab_contents()->delegate()) { 611 if (tab_contents()->delegate()) {
678 bool zoom_in = distance > 0; 612 bool zoom_in = distance > 0;
679 tab_contents()->delegate()->ContentsZoomChange(zoom_in); 613 tab_contents()->delegate()->ContentsZoomChange(zoom_in);
680 } 614 }
681 } 615 }
OLDNEW
« no previous file with comments | « chrome/browser/views/tab_contents/tab_contents_view_win.h ('k') | chrome/common/render_messages_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698