OLD | NEW |
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 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 views::FocusManager* focus_manager = | 344 views::FocusManager* focus_manager = |
345 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); | 345 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
346 | 346 |
347 // We may not have a focus manager if the tab has been switched before this | 347 // We may not have a focus manager if the tab has been switched before this |
348 // message arrived. | 348 // message arrived. |
349 if (focus_manager) | 349 if (focus_manager) |
350 focus_manager->AdvanceFocus(reverse); | 350 focus_manager->AdvanceFocus(reverse); |
351 } | 351 } |
352 } | 352 } |
353 | 353 |
354 void TabContentsViewWin::HandleKeyboardEvent( | 354 bool TabContentsViewWin::HandleKeyboardEvent( |
355 const NativeWebKeyboardEvent& event) { | 355 const NativeWebKeyboardEvent& event) { |
356 // Previous calls to TranslateMessage can generate CHAR events as well as | 356 // Previous calls to TranslateMessage can generate CHAR events as well as |
357 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these | 357 // RAW_KEY_DOWN events, even if the latter triggered an accelerator. In these |
358 // cases, we discard the CHAR events. | 358 // cases, we discard the CHAR events. |
359 if (event.type == WebInputEvent::Char && ignore_next_char_event_) { | 359 if (event.type == WebInputEvent::Char && ignore_next_char_event_) { |
360 ignore_next_char_event_ = false; | 360 ignore_next_char_event_ = false; |
361 return; | 361 return true; |
362 } | 362 } |
363 ignore_next_char_event_ = false; | 363 ignore_next_char_event_ = false; |
364 | 364 |
365 // The renderer returned a keyboard event it did not process. This may be | 365 // The renderer returned a keyboard event it did not process. This may be |
366 // a keyboard shortcut that we have to process. | 366 // a keyboard shortcut that we have to process. |
367 if (event.type == WebInputEvent::RawKeyDown) { | 367 if (event.type == WebInputEvent::RawKeyDown) { |
368 views::FocusManager* focus_manager = | 368 views::FocusManager* focus_manager = |
369 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); | 369 views::FocusManager::GetFocusManagerForNativeView(GetNativeView()); |
370 // We may not have a focus_manager at this point (if the tab has been | 370 // We may not have a focus_manager at this point (if the tab has been |
371 // switched by the time this message returned). | 371 // switched by the time this message returned). |
372 if (focus_manager) { | 372 if (focus_manager) { |
373 views::Accelerator accelerator( | 373 views::Accelerator accelerator( |
374 win_util::WinToKeyboardCode(event.windowsKeyCode), | 374 win_util::WinToKeyboardCode(event.windowsKeyCode), |
375 (event.modifiers & WebInputEvent::ShiftKey) == | 375 (event.modifiers & WebInputEvent::ShiftKey) == |
376 WebInputEvent::ShiftKey, | 376 WebInputEvent::ShiftKey, |
377 (event.modifiers & WebInputEvent::ControlKey) == | 377 (event.modifiers & WebInputEvent::ControlKey) == |
378 WebInputEvent::ControlKey, | 378 WebInputEvent::ControlKey, |
379 (event.modifiers & WebInputEvent::AltKey) == | 379 (event.modifiers & WebInputEvent::AltKey) == |
380 WebInputEvent::AltKey); | 380 WebInputEvent::AltKey); |
381 | 381 |
382 // This is tricky: we want to set ignore_next_char_event_ if | 382 // This is tricky: we want to set ignore_next_char_event_ if |
383 // ProcessAccelerator returns true. But ProcessAccelerator might delete | 383 // ProcessAccelerator returns true. But ProcessAccelerator might delete |
384 // |this| if the accelerator is a "close tab" one. So we speculatively | 384 // |this| if the accelerator is a "close tab" one. So we speculatively |
385 // set the flag and fix it if no event was handled. | 385 // set the flag and fix it if no event was handled. |
386 ignore_next_char_event_ = true; | 386 ignore_next_char_event_ = true; |
387 if (focus_manager->ProcessAccelerator(accelerator)) { | 387 if (focus_manager->ProcessAccelerator(accelerator)) { |
388 // DANGER: |this| could be deleted now! | 388 // DANGER: |this| could be deleted now! |
389 return; | 389 return true; |
390 } else { | 390 } else { |
391 // ProcessAccelerator didn't handle the accelerator, so we know both | 391 // ProcessAccelerator didn't handle the accelerator, so we know both |
392 // that |this| is still valid, and that we didn't want to set the flag. | 392 // that |this| is still valid, and that we didn't want to set the flag. |
393 ignore_next_char_event_ = false; | 393 ignore_next_char_event_ = false; |
394 } | 394 } |
395 } | 395 } |
396 } | 396 } |
397 | 397 |
398 if (tab_contents()->delegate() && | 398 if (tab_contents()->delegate() && |
399 tab_contents()->delegate()->HandleKeyboardEvent(event)) { | 399 tab_contents()->delegate()->HandleKeyboardEvent(event)) { |
400 return; | 400 return true; |
401 } | 401 } |
402 | 402 |
403 // Any unhandled keyboard/character messages should be defproced. | 403 // Any unhandled keyboard/character messages should be defproced. |
404 // This allows stuff like Alt+F4, etc to work correctly. | 404 // This allows stuff like Alt+F4, etc to work correctly. |
405 DefWindowProc(event.os_event.hwnd, | 405 DefWindowProc(event.os_event.hwnd, event.os_event.message, |
406 event.os_event.message, | 406 event.os_event.wParam, event.os_event.lParam); |
407 event.os_event.wParam, | 407 |
408 event.os_event.lParam); | 408 // DefWindowProc() always returns 0, which means it handled the event. |
| 409 // But actually DefWindowProc() will only handle very few system key strokes, |
| 410 // such as F10, Alt+Tab, Alt+F4, Alt+Esc, etc. |
| 411 // So returning false here is just ok for most cases. |
| 412 // Reference: http://msdn.microsoft.com/en-us/library/ms646267(VS.85).aspx |
| 413 return false; |
409 } | 414 } |
410 | 415 |
411 views::FocusManager* TabContentsViewWin::GetFocusManager() { | 416 views::FocusManager* TabContentsViewWin::GetFocusManager() { |
412 views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); | 417 views::FocusManager* focus_manager = WidgetWin::GetFocusManager(); |
413 if (focus_manager) { | 418 if (focus_manager) { |
414 // If focus_manager_ is non NULL, it means we have been reparented, in which | 419 // If focus_manager_ is non NULL, it means we have been reparented, in which |
415 // case its value may not be valid anymore. | 420 // case its value may not be valid anymore. |
416 focus_manager_ = NULL; | 421 focus_manager_ = NULL; |
417 return focus_manager; | 422 return focus_manager; |
418 } | 423 } |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
646 } | 651 } |
647 return false; | 652 return false; |
648 } | 653 } |
649 | 654 |
650 void TabContentsViewWin::WheelZoom(int distance) { | 655 void TabContentsViewWin::WheelZoom(int distance) { |
651 if (tab_contents()->delegate()) { | 656 if (tab_contents()->delegate()) { |
652 bool zoom_in = distance > 0; | 657 bool zoom_in = distance > 0; |
653 tab_contents()->delegate()->ContentsZoomChange(zoom_in); | 658 tab_contents()->delegate()->ContentsZoomChange(zoom_in); |
654 } | 659 } |
655 } | 660 } |
OLD | NEW |