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/views/widget/widget_win.h" | 5 #include "chrome/views/widget/widget_win.h" |
6 | 6 |
7 #include "base/gfx/native_theme.h" | 7 #include "base/gfx/native_theme.h" |
8 #include "base/string_util.h" | 8 #include "base/string_util.h" |
9 #include "base/win_util.h" | 9 #include "base/win_util.h" |
10 #include "chrome/app/chrome_dll_resource.h" | 10 #include "chrome/app/chrome_dll_resource.h" |
(...skipping 502 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
513 KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags); | 513 KeyEvent event(Event::ET_KEY_PRESSED, c, rep_cnt, flags); |
514 SetMsgHandled(root_view_->ProcessKeyEvent(event)); | 514 SetMsgHandled(root_view_->ProcessKeyEvent(event)); |
515 } | 515 } |
516 | 516 |
517 void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) { | 517 void WidgetWin::OnKeyUp(TCHAR c, UINT rep_cnt, UINT flags) { |
518 KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags); | 518 KeyEvent event(Event::ET_KEY_RELEASED, c, rep_cnt, flags); |
519 SetMsgHandled(root_view_->ProcessKeyEvent(event)); | 519 SetMsgHandled(root_view_->ProcessKeyEvent(event)); |
520 } | 520 } |
521 | 521 |
522 void WidgetWin::OnLButtonDown(UINT flags, const CPoint& point) { | 522 void WidgetWin::OnLButtonDown(UINT flags, const CPoint& point) { |
523 ProcessMousePressed(point, flags | MK_LBUTTON, false); | 523 ProcessMousePressed(point, flags | MK_LBUTTON, false, false); |
524 } | 524 } |
525 | 525 |
526 void WidgetWin::OnLButtonUp(UINT flags, const CPoint& point) { | 526 void WidgetWin::OnLButtonUp(UINT flags, const CPoint& point) { |
527 ProcessMouseReleased(point, flags | MK_LBUTTON); | 527 ProcessMouseReleased(point, flags | MK_LBUTTON); |
528 } | 528 } |
529 | 529 |
530 void WidgetWin::OnLButtonDblClk(UINT flags, const CPoint& point) { | 530 void WidgetWin::OnLButtonDblClk(UINT flags, const CPoint& point) { |
531 ProcessMousePressed(point, flags | MK_LBUTTON, true); | 531 ProcessMousePressed(point, flags | MK_LBUTTON, true, false); |
532 } | 532 } |
533 | 533 |
534 void WidgetWin::OnMButtonDown(UINT flags, const CPoint& point) { | 534 void WidgetWin::OnMButtonDown(UINT flags, const CPoint& point) { |
535 ProcessMousePressed(point, flags | MK_MBUTTON, false); | 535 ProcessMousePressed(point, flags | MK_MBUTTON, false, false); |
536 } | 536 } |
537 | 537 |
538 void WidgetWin::OnMButtonUp(UINT flags, const CPoint& point) { | 538 void WidgetWin::OnMButtonUp(UINT flags, const CPoint& point) { |
539 ProcessMouseReleased(point, flags | MK_MBUTTON); | 539 ProcessMouseReleased(point, flags | MK_MBUTTON); |
540 } | 540 } |
541 | 541 |
542 void WidgetWin::OnMButtonDblClk(UINT flags, const CPoint& point) { | 542 void WidgetWin::OnMButtonDblClk(UINT flags, const CPoint& point) { |
543 ProcessMousePressed(point, flags | MK_MBUTTON, true); | 543 ProcessMousePressed(point, flags | MK_MBUTTON, true, false); |
544 } | 544 } |
545 | 545 |
546 LRESULT WidgetWin::OnMouseActivate(HWND window, UINT hittest_code, | 546 LRESULT WidgetWin::OnMouseActivate(HWND window, UINT hittest_code, |
547 UINT message) { | 547 UINT message) { |
548 SetMsgHandled(FALSE); | 548 SetMsgHandled(FALSE); |
549 return MA_ACTIVATE; | 549 return MA_ACTIVATE; |
550 } | 550 } |
551 | 551 |
552 void WidgetWin::OnMouseMove(UINT flags, const CPoint& point) { | 552 void WidgetWin::OnMouseMove(UINT flags, const CPoint& point) { |
553 ProcessMouseMoved(point, flags, false); | 553 ProcessMouseMoved(point, flags, false); |
(...skipping 21 matching lines...) Expand all Loading... |
575 return root_view_->ProcessMouseWheelEvent(e) ? 0 : 1; | 575 return root_view_->ProcessMouseWheelEvent(e) ? 0 : 1; |
576 } | 576 } |
577 | 577 |
578 LRESULT WidgetWin::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) { | 578 LRESULT WidgetWin::OnMouseRange(UINT msg, WPARAM w_param, LPARAM l_param) { |
579 tooltip_manager_->OnMouse(msg, w_param, l_param); | 579 tooltip_manager_->OnMouse(msg, w_param, l_param); |
580 SetMsgHandled(FALSE); | 580 SetMsgHandled(FALSE); |
581 return 0; | 581 return 0; |
582 } | 582 } |
583 | 583 |
584 void WidgetWin::OnNCLButtonDblClk(UINT flags, const CPoint& point) { | 584 void WidgetWin::OnNCLButtonDblClk(UINT flags, const CPoint& point) { |
585 SetMsgHandled(FALSE); | 585 SetMsgHandled(ProcessMousePressed(point, flags | MK_LBUTTON, true, true)); |
586 } | 586 } |
587 | 587 |
588 void WidgetWin::OnNCLButtonDown(UINT flags, const CPoint& point) { | 588 void WidgetWin::OnNCLButtonDown(UINT flags, const CPoint& point) { |
589 SetMsgHandled(FALSE); | 589 SetMsgHandled(ProcessMousePressed(point, flags | MK_LBUTTON, false, true)); |
590 } | 590 } |
591 | 591 |
592 void WidgetWin::OnNCLButtonUp(UINT flags, const CPoint& point) { | 592 void WidgetWin::OnNCLButtonUp(UINT flags, const CPoint& point) { |
593 SetMsgHandled(FALSE); | 593 SetMsgHandled(FALSE); |
594 } | 594 } |
595 | 595 |
596 void WidgetWin::OnNCMButtonDblClk(UINT flags, const CPoint& point) { | 596 void WidgetWin::OnNCMButtonDblClk(UINT flags, const CPoint& point) { |
597 SetMsgHandled(FALSE); | 597 SetMsgHandled(ProcessMousePressed(point, flags | MK_MBUTTON, true, true)); |
598 } | 598 } |
599 | 599 |
600 void WidgetWin::OnNCMButtonDown(UINT flags, const CPoint& point) { | 600 void WidgetWin::OnNCMButtonDown(UINT flags, const CPoint& point) { |
601 SetMsgHandled(FALSE); | 601 SetMsgHandled(ProcessMousePressed(point, flags | MK_MBUTTON, false, true)); |
602 } | 602 } |
603 | 603 |
604 void WidgetWin::OnNCMButtonUp(UINT flags, const CPoint& point) { | 604 void WidgetWin::OnNCMButtonUp(UINT flags, const CPoint& point) { |
605 SetMsgHandled(FALSE); | 605 SetMsgHandled(FALSE); |
606 } | 606 } |
607 | 607 |
608 LRESULT WidgetWin::OnNCMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param) { | 608 LRESULT WidgetWin::OnNCMouseLeave(UINT uMsg, WPARAM w_param, LPARAM l_param) { |
609 ProcessMouseExited(); | 609 ProcessMouseExited(); |
610 return 0; | 610 return 0; |
611 } | 611 } |
612 | 612 |
613 LRESULT WidgetWin::OnNCMouseMove(UINT flags, const CPoint& point) { | 613 LRESULT WidgetWin::OnNCMouseMove(UINT flags, const CPoint& point) { |
614 // NC points are in screen coordinates. | 614 // NC points are in screen coordinates. |
615 CPoint temp = point; | 615 CPoint temp = point; |
616 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1); | 616 MapWindowPoints(HWND_DESKTOP, GetNativeView(), &temp, 1); |
617 ProcessMouseMoved(temp, 0, true); | 617 ProcessMouseMoved(temp, 0, true); |
618 | 618 |
619 // We need to process this message to stop Windows from drawing the window | 619 // We need to process this message to stop Windows from drawing the window |
620 // controls as the mouse moves over the title bar area when the window is | 620 // controls as the mouse moves over the title bar area when the window is |
621 // maximized. | 621 // maximized. |
622 return 0; | 622 return 0; |
623 } | 623 } |
624 | 624 |
625 void WidgetWin::OnNCRButtonDblClk(UINT flags, const CPoint& point) { | 625 void WidgetWin::OnNCRButtonDblClk(UINT flags, const CPoint& point) { |
626 SetMsgHandled(FALSE); | 626 SetMsgHandled(ProcessMousePressed(point, flags | MK_RBUTTON, true, true)); |
627 } | 627 } |
628 | 628 |
629 void WidgetWin::OnNCRButtonDown(UINT flags, const CPoint& point) { | 629 void WidgetWin::OnNCRButtonDown(UINT flags, const CPoint& point) { |
630 SetMsgHandled(FALSE); | 630 SetMsgHandled(ProcessMousePressed(point, flags | MK_RBUTTON, false, true)); |
631 } | 631 } |
632 | 632 |
633 void WidgetWin::OnNCRButtonUp(UINT flags, const CPoint& point) { | 633 void WidgetWin::OnNCRButtonUp(UINT flags, const CPoint& point) { |
634 SetMsgHandled(FALSE); | 634 SetMsgHandled(FALSE); |
635 } | 635 } |
636 | 636 |
637 LRESULT WidgetWin::OnNotify(int w_param, NMHDR* l_param) { | 637 LRESULT WidgetWin::OnNotify(int w_param, NMHDR* l_param) { |
638 // We can be sent this message before the tooltip manager is created, if a | 638 // We can be sent this message before the tooltip manager is created, if a |
639 // subclass overrides OnCreate and creates some kind of Windows control there | 639 // subclass overrides OnCreate and creates some kind of Windows control there |
640 // that sends WM_NOTIFY messages. | 640 // that sends WM_NOTIFY messages. |
641 if (tooltip_manager_.get()) { | 641 if (tooltip_manager_.get()) { |
642 bool handled; | 642 bool handled; |
643 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); | 643 LRESULT result = tooltip_manager_->OnNotify(w_param, l_param, &handled); |
644 SetMsgHandled(handled); | 644 SetMsgHandled(handled); |
645 return result; | 645 return result; |
646 } | 646 } |
647 SetMsgHandled(FALSE); | 647 SetMsgHandled(FALSE); |
648 return 0; | 648 return 0; |
649 } | 649 } |
650 | 650 |
651 void WidgetWin::OnPaint(HDC dc) { | 651 void WidgetWin::OnPaint(HDC dc) { |
652 root_view_->OnPaint(GetNativeView()); | 652 root_view_->OnPaint(GetNativeView()); |
653 } | 653 } |
654 | 654 |
655 void WidgetWin::OnRButtonDown(UINT flags, const CPoint& point) { | 655 void WidgetWin::OnRButtonDown(UINT flags, const CPoint& point) { |
656 ProcessMousePressed(point, flags | MK_RBUTTON, false); | 656 ProcessMousePressed(point, flags | MK_RBUTTON, false, false); |
657 } | 657 } |
658 | 658 |
659 void WidgetWin::OnRButtonUp(UINT flags, const CPoint& point) { | 659 void WidgetWin::OnRButtonUp(UINT flags, const CPoint& point) { |
660 ProcessMouseReleased(point, flags | MK_RBUTTON); | 660 ProcessMouseReleased(point, flags | MK_RBUTTON); |
661 } | 661 } |
662 | 662 |
663 void WidgetWin::OnRButtonDblClk(UINT flags, const CPoint& point) { | 663 void WidgetWin::OnRButtonDblClk(UINT flags, const CPoint& point) { |
664 ProcessMousePressed(point, flags | MK_RBUTTON, true); | 664 ProcessMousePressed(point, flags | MK_RBUTTON, true, false); |
665 } | 665 } |
666 | 666 |
667 void WidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { | 667 void WidgetWin::OnSettingChange(UINT flags, const wchar_t* section) { |
668 if (toplevel_ && (flags == SPI_SETWORKAREA)) { | 668 if (toplevel_ && (flags == SPI_SETWORKAREA)) { |
669 AdjustWindowToFitScreenSize(); | 669 AdjustWindowToFitScreenSize(); |
670 SetMsgHandled(TRUE); | 670 SetMsgHandled(TRUE); |
671 } | 671 } |
672 } | 672 } |
673 | 673 |
674 void WidgetWin::OnSize(UINT param, const CSize& size) { | 674 void WidgetWin::OnSize(UINT param, const CSize& size) { |
(...skipping 30 matching lines...) Expand all Loading... |
705 tme.dwFlags = mouse_tracking_flags; | 705 tme.dwFlags = mouse_tracking_flags; |
706 tme.hwndTrack = GetNativeView(); | 706 tme.hwndTrack = GetNativeView(); |
707 tme.dwHoverTime = 0; | 707 tme.dwHoverTime = 0; |
708 TrackMouseEvent(&tme); | 708 TrackMouseEvent(&tme); |
709 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { | 709 } else if (mouse_tracking_flags != active_mouse_tracking_flags_) { |
710 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); | 710 TrackMouseEvents(active_mouse_tracking_flags_ | TME_CANCEL); |
711 TrackMouseEvents(mouse_tracking_flags); | 711 TrackMouseEvents(mouse_tracking_flags); |
712 } | 712 } |
713 } | 713 } |
714 | 714 |
715 bool WidgetWin::ProcessMousePressed(const CPoint& point, UINT flags, | 715 bool WidgetWin::ProcessMousePressed(const CPoint& point, |
716 bool dbl_click) { | 716 UINT flags, |
| 717 bool dbl_click, |
| 718 bool non_client) { |
717 last_mouse_event_was_move_ = false; | 719 last_mouse_event_was_move_ = false; |
718 // Windows gives screen coordinates for nonclient events, while the RootView | 720 // Windows gives screen coordinates for nonclient events, while the RootView |
719 // expects window coordinates; convert if necessary. | 721 // expects window coordinates; convert if necessary. |
720 gfx::Point converted_point(point); | 722 gfx::Point converted_point(point); |
| 723 if (non_client) |
| 724 View::ConvertPointToView(NULL, root_view_.get(), &converted_point); |
721 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, | 725 MouseEvent mouse_pressed(Event::ET_MOUSE_PRESSED, |
722 converted_point.x(), | 726 converted_point.x(), |
723 converted_point.y(), | 727 converted_point.y(), |
724 (dbl_click ? MouseEvent::EF_IS_DOUBLE_CLICK : 0) | | 728 (dbl_click ? MouseEvent::EF_IS_DOUBLE_CLICK : 0) | |
| 729 (non_client ? MouseEvent::EF_IS_NON_CLIENT : 0) | |
725 Event::ConvertWindowsFlags(flags)); | 730 Event::ConvertWindowsFlags(flags)); |
726 if (root_view_->OnMousePressed(mouse_pressed)) { | 731 if (root_view_->OnMousePressed(mouse_pressed)) { |
727 is_mouse_down_ = true; | 732 is_mouse_down_ = true; |
728 if (!has_capture_) { | 733 if (!has_capture_) { |
729 SetCapture(); | 734 SetCapture(); |
730 has_capture_ = true; | 735 has_capture_ = true; |
731 current_action_ = FA_FORWARDING; | 736 current_action_ = FA_FORWARDING; |
732 } | 737 } |
733 return true; | 738 return true; |
734 } | 739 } |
(...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
997 result = DefWindowProc(window, message, w_param, l_param); | 1002 result = DefWindowProc(window, message, w_param, l_param); |
998 if (message == WM_NCDESTROY) { | 1003 if (message == WM_NCDESTROY) { |
999 TRACK_HWND_DESTRUCTION(window); | 1004 TRACK_HWND_DESTRUCTION(window); |
1000 widget->hwnd_ = NULL; | 1005 widget->hwnd_ = NULL; |
1001 widget->OnFinalMessage(window); | 1006 widget->OnFinalMessage(window); |
1002 } | 1007 } |
1003 return result; | 1008 return result; |
1004 } | 1009 } |
1005 | 1010 |
1006 } // namespace views | 1011 } // namespace views |
OLD | NEW |