OLD | NEW |
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 "content/browser/renderer_host/render_widget_host_view_win.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_win.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <map> | 8 #include <map> |
9 #include <peninputpanel_i.c> | 9 #include <peninputpanel_i.c> |
10 | 10 |
(...skipping 569 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
580 track_mouse_leave_(false), | 580 track_mouse_leave_(false), |
581 ime_notification_(false), | 581 ime_notification_(false), |
582 capture_enter_key_(false), | 582 capture_enter_key_(false), |
583 is_hidden_(false), | 583 is_hidden_(false), |
584 about_to_validate_and_paint_(false), | 584 about_to_validate_and_paint_(false), |
585 close_on_deactivate_(false), | 585 close_on_deactivate_(false), |
586 being_destroyed_(false), | 586 being_destroyed_(false), |
587 tooltip_hwnd_(NULL), | 587 tooltip_hwnd_(NULL), |
588 tooltip_showing_(false), | 588 tooltip_showing_(false), |
589 weak_factory_(this), | 589 weak_factory_(this), |
590 parent_hwnd_(NULL), | |
591 is_loading_(false), | 590 is_loading_(false), |
592 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), | 591 text_input_type_(ui::TEXT_INPUT_TYPE_NONE), |
593 is_fullscreen_(false), | 592 is_fullscreen_(false), |
594 ignore_mouse_movement_(true), | 593 ignore_mouse_movement_(true), |
595 composition_range_(ui::Range::InvalidRange()), | 594 composition_range_(ui::Range::InvalidRange()), |
596 ALLOW_THIS_IN_INITIALIZER_LIST( | 595 ALLOW_THIS_IN_INITIALIZER_LIST( |
597 touch_state_(new WebTouchState(this))), | 596 touch_state_(new WebTouchState(this))), |
598 pointer_down_context_(false), | 597 pointer_down_context_(false), |
599 focus_on_editable_field_(false), | 598 focus_on_editable_field_(false), |
600 received_focus_change_after_pointer_down_(false), | 599 received_focus_change_after_pointer_down_(false), |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
633 } | 632 } |
634 } | 633 } |
635 #endif | 634 #endif |
636 } | 635 } |
637 | 636 |
638 /////////////////////////////////////////////////////////////////////////////// | 637 /////////////////////////////////////////////////////////////////////////////// |
639 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: | 638 // RenderWidgetHostViewWin, RenderWidgetHostView implementation: |
640 | 639 |
641 void RenderWidgetHostViewWin::InitAsChild( | 640 void RenderWidgetHostViewWin::InitAsChild( |
642 gfx::NativeView parent_view) { | 641 gfx::NativeView parent_view) { |
643 parent_hwnd_ = parent_view; | |
644 CreateWnd(parent_view); | 642 CreateWnd(parent_view); |
645 } | 643 } |
646 | 644 |
647 void RenderWidgetHostViewWin::InitAsPopup( | 645 void RenderWidgetHostViewWin::InitAsPopup( |
648 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { | 646 RenderWidgetHostView* parent_host_view, const gfx::Rect& pos) { |
649 close_on_deactivate_ = true; | 647 close_on_deactivate_ = true; |
650 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos, | 648 DoPopupOrFullscreenInit(parent_host_view->GetNativeView(), pos, |
651 WS_EX_TOOLWINDOW); | 649 WS_EX_TOOLWINDOW); |
652 } | 650 } |
653 | 651 |
(...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
932 bool RenderWidgetHostViewWin::HasFocus() const { | 930 bool RenderWidgetHostViewWin::HasFocus() const { |
933 return ::GetFocus() == m_hWnd; | 931 return ::GetFocus() == m_hWnd; |
934 } | 932 } |
935 | 933 |
936 bool RenderWidgetHostViewWin::IsSurfaceAvailableForCopy() const { | 934 bool RenderWidgetHostViewWin::IsSurfaceAvailableForCopy() const { |
937 return !!render_widget_host_->GetBackingStore(false) || | 935 return !!render_widget_host_->GetBackingStore(false) || |
938 !!accelerated_surface_.get(); | 936 !!accelerated_surface_.get(); |
939 } | 937 } |
940 | 938 |
941 void RenderWidgetHostViewWin::Show() { | 939 void RenderWidgetHostViewWin::Show() { |
942 if (!is_fullscreen_) { | |
943 DCHECK(parent_hwnd_); | |
944 DCHECK(parent_hwnd_ != ui::GetWindowToParentTo(true)); | |
945 SetParent(parent_hwnd_); | |
946 } | |
947 ShowWindow(SW_SHOW); | 940 ShowWindow(SW_SHOW); |
948 | |
949 WasRestored(); | 941 WasRestored(); |
950 } | 942 } |
951 | 943 |
952 void RenderWidgetHostViewWin::Hide() { | 944 void RenderWidgetHostViewWin::Hide() { |
953 if (!is_fullscreen_ && GetParent() == ui::GetWindowToParentTo(true)) { | 945 if (!is_fullscreen_ && GetParent() == ui::GetWindowToParentTo(true)) { |
954 LOG(WARNING) << "Hide() called twice in a row: " << this << ":" << | 946 LOG(WARNING) << "Hide() called twice in a row: " << this << ":" |
955 parent_hwnd_ << ":" << GetParent(); | 947 << GetParent(); |
956 return; | 948 return; |
957 } | 949 } |
958 | 950 |
959 if (::GetFocus() == m_hWnd) | 951 if (::GetFocus() == m_hWnd) |
960 ::SetFocus(NULL); | 952 ::SetFocus(NULL); |
961 ShowWindow(SW_HIDE); | 953 ShowWindow(SW_HIDE); |
962 | 954 |
963 if (!is_fullscreen_) { | |
964 // Cache the old parent, then orphan the window so we stop receiving | |
965 // messages. | |
966 parent_hwnd_ = GetParent(); | |
967 SetParent(NULL); | |
968 } | |
969 | |
970 WasHidden(); | 955 WasHidden(); |
971 } | 956 } |
972 | 957 |
973 bool RenderWidgetHostViewWin::IsShowing() { | 958 bool RenderWidgetHostViewWin::IsShowing() { |
974 return !!IsWindowVisible(); | 959 return !!IsWindowVisible(); |
975 } | 960 } |
976 | 961 |
977 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { | 962 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { |
978 CRect window_rect; | 963 CRect window_rect; |
979 GetWindowRect(&window_rect); | 964 GetWindowRect(&window_rect); |
(...skipping 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1946 } | 1931 } |
1947 | 1932 |
1948 // If we are a pop-up, forward tab related messages to our parent HWND, so | 1933 // If we are a pop-up, forward tab related messages to our parent HWND, so |
1949 // that we are dismissed appropriately and so that the focus advance in our | 1934 // that we are dismissed appropriately and so that the focus advance in our |
1950 // parent. | 1935 // parent. |
1951 // TODO(jcampan): http://b/issue?id=1192881 Could be abstracted in the | 1936 // TODO(jcampan): http://b/issue?id=1192881 Could be abstracted in the |
1952 // FocusManager. | 1937 // FocusManager. |
1953 if (close_on_deactivate_ && | 1938 if (close_on_deactivate_ && |
1954 (((message == WM_KEYDOWN || message == WM_KEYUP) && (wparam == VK_TAB)) || | 1939 (((message == WM_KEYDOWN || message == WM_KEYUP) && (wparam == VK_TAB)) || |
1955 (message == WM_CHAR && wparam == L'\t'))) { | 1940 (message == WM_CHAR && wparam == L'\t'))) { |
1956 DCHECK(parent_hwnd_); | |
1957 // First close the pop-up. | 1941 // First close the pop-up. |
1958 SendMessage(WM_CANCELMODE); | 1942 SendMessage(WM_CANCELMODE); |
1959 // Then move the focus by forwarding the tab key to the parent. | 1943 // Then move the focus by forwarding the tab key to the parent. |
1960 return ::SendMessage(parent_hwnd_, message, wparam, lparam); | 1944 return ::SendMessage(GetParent(), message, wparam, lparam); |
1961 } | 1945 } |
1962 | 1946 |
1963 if (!render_widget_host_) | 1947 if (!render_widget_host_) |
1964 return 0; | 1948 return 0; |
1965 | 1949 |
1966 // Bug 1845: we need to update the text direction when a user releases | 1950 // Bug 1845: we need to update the text direction when a user releases |
1967 // either a right-shift key or a right-control key after pressing both of | 1951 // either a right-shift key or a right-control key after pressing both of |
1968 // them. So, we just update the text direction while a user is pressing the | 1952 // them. So, we just update the text direction while a user is pressing the |
1969 // keys, and we notify the text direction when a user releases either of them. | 1953 // keys, and we notify the text direction when a user releases either of them. |
1970 // Bug 9718: http://crbug.com/9718 To investigate IE and notepad, this | 1954 // Bug 9718: http://crbug.com/9718 To investigate IE and notepad, this |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2963 void RenderWidgetHostViewWin::ShutdownHost() { | 2947 void RenderWidgetHostViewWin::ShutdownHost() { |
2964 weak_factory_.InvalidateWeakPtrs(); | 2948 weak_factory_.InvalidateWeakPtrs(); |
2965 if (render_widget_host_) | 2949 if (render_widget_host_) |
2966 render_widget_host_->Shutdown(); | 2950 render_widget_host_->Shutdown(); |
2967 // Do not touch any members at this point, |this| has been deleted. | 2951 // Do not touch any members at this point, |this| has been deleted. |
2968 } | 2952 } |
2969 | 2953 |
2970 void RenderWidgetHostViewWin::DoPopupOrFullscreenInit(HWND parent_hwnd, | 2954 void RenderWidgetHostViewWin::DoPopupOrFullscreenInit(HWND parent_hwnd, |
2971 const gfx::Rect& pos, | 2955 const gfx::Rect& pos, |
2972 DWORD ex_style) { | 2956 DWORD ex_style) { |
2973 parent_hwnd_ = parent_hwnd; | 2957 Create(parent_hwnd, NULL, NULL, WS_POPUP, ex_style); |
2974 Create(parent_hwnd_, NULL, NULL, WS_POPUP, ex_style); | |
2975 MoveWindow(pos.x(), pos.y(), pos.width(), pos.height(), TRUE); | 2958 MoveWindow(pos.x(), pos.y(), pos.width(), pos.height(), TRUE); |
2976 ShowWindow(IsActivatable() ? SW_SHOW : SW_SHOWNA); | 2959 ShowWindow(IsActivatable() ? SW_SHOW : SW_SHOWNA); |
2977 } | 2960 } |
2978 | 2961 |
2979 CPoint RenderWidgetHostViewWin::GetClientCenter() const { | 2962 CPoint RenderWidgetHostViewWin::GetClientCenter() const { |
2980 CRect rect; | 2963 CRect rect; |
2981 GetClientRect(&rect); | 2964 GetClientRect(&rect); |
2982 return rect.CenterPoint(); | 2965 return rect.CenterPoint(); |
2983 } | 2966 } |
2984 | 2967 |
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3165 void RenderWidgetHostViewWin::ResetPointerDownContext() { | 3148 void RenderWidgetHostViewWin::ResetPointerDownContext() { |
3166 // If the default focus on the page is on an edit field and we did not | 3149 // If the default focus on the page is on an edit field and we did not |
3167 // receive a focus change in the context of a pointer down message, it means | 3150 // receive a focus change in the context of a pointer down message, it means |
3168 // that the pointer down message occurred on the edit field and we should | 3151 // that the pointer down message occurred on the edit field and we should |
3169 // display the on screen keyboard | 3152 // display the on screen keyboard |
3170 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) | 3153 if (!received_focus_change_after_pointer_down_ && virtual_keyboard_) |
3171 DisplayOnScreenKeyboardIfNeeded(); | 3154 DisplayOnScreenKeyboardIfNeeded(); |
3172 received_focus_change_after_pointer_down_ = false; | 3155 received_focus_change_after_pointer_down_ = false; |
3173 pointer_down_context_ = false; | 3156 pointer_down_context_ = false; |
3174 } | 3157 } |
OLD | NEW |