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 <InputScope.h> | 7 #include <InputScope.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 #include <map> | 10 #include <map> |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 #include "content/public/browser/notification_service.h" | 45 #include "content/public/browser/notification_service.h" |
46 #include "content/public/browser/notification_types.h" | 46 #include "content/public/browser/notification_types.h" |
47 #include "content/public/common/content_switches.h" | 47 #include "content/public/common/content_switches.h" |
48 #include "content/public/common/page_zoom.h" | 48 #include "content/public/common/page_zoom.h" |
49 #include "content/public/common/process_type.h" | 49 #include "content/public/common/process_type.h" |
50 #include "skia/ext/skia_utils_win.h" | 50 #include "skia/ext/skia_utils_win.h" |
51 #include "third_party/skia/include/core/SkRegion.h" | 51 #include "third_party/skia/include/core/SkRegion.h" |
52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" | 52 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli
ne.h" |
53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" | 53 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" |
54 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" | 54 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact
ory.h" |
| 55 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact
ory.h" |
55 #include "ui/base/events/event.h" | 56 #include "ui/base/events/event.h" |
56 #include "ui/base/events/event_utils.h" | 57 #include "ui/base/events/event_utils.h" |
57 #include "ui/base/ime/composition_text.h" | 58 #include "ui/base/ime/composition_text.h" |
58 #include "ui/base/ime/win/tsf_input_scope.h" | 59 #include "ui/base/ime/win/tsf_input_scope.h" |
59 #include "ui/base/l10n/l10n_util_win.h" | 60 #include "ui/base/l10n/l10n_util_win.h" |
60 #include "ui/base/text/text_elider.h" | 61 #include "ui/base/text/text_elider.h" |
61 #include "ui/base/touch/touch_device_win.h" | 62 #include "ui/base/touch/touch_device_win.h" |
62 #include "ui/base/ui_base_switches.h" | 63 #include "ui/base/ui_base_switches.h" |
63 #include "ui/base/view_prop.h" | 64 #include "ui/base/view_prop.h" |
| 65 #include "ui/base/win/dpi.h" |
64 #include "ui/base/win/hwnd_util.h" | 66 #include "ui/base/win/hwnd_util.h" |
65 #include "ui/base/win/mouse_wheel_util.h" | 67 #include "ui/base/win/mouse_wheel_util.h" |
66 #include "ui/gfx/canvas.h" | 68 #include "ui/gfx/canvas.h" |
67 #include "ui/gfx/rect.h" | 69 #include "ui/gfx/rect.h" |
68 #include "ui/gfx/screen.h" | 70 #include "ui/gfx/screen.h" |
69 #include "webkit/glue/webcursor.h" | 71 #include "webkit/glue/webcursor.h" |
70 #include "webkit/plugins/npapi/plugin_constants_win.h" | 72 #include "webkit/plugins/npapi/plugin_constants_win.h" |
71 #include "webkit/plugins/npapi/webplugin.h" | 73 #include "webkit/plugins/npapi/webplugin.h" |
72 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" | 74 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" |
73 #include "win8/util/win8_util.h" | 75 #include "win8/util/win8_util.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
293 private: | 295 private: |
294 DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint); | 296 DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint); |
295 }; | 297 }; |
296 | 298 |
297 bool ShouldSendPinchGesture() { | 299 bool ShouldSendPinchGesture() { |
298 static bool pinch_allowed = | 300 static bool pinch_allowed = |
299 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch); | 301 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch); |
300 return pinch_allowed; | 302 return pinch_allowed; |
301 } | 303 } |
302 | 304 |
| 305 void GetScreenInfoForWindow(WebKit::WebScreenInfo* results, |
| 306 gfx::NativeViewId id) { |
| 307 *results = WebKit::WebScreenInfoFactory::screenInfo( |
| 308 gfx::NativeViewFromId(id)); |
| 309 results->deviceScaleFactor = ui::win::GetDeviceScaleFactor(); |
| 310 } |
| 311 |
303 } // namespace | 312 } // namespace |
304 | 313 |
305 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; | 314 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; |
306 | 315 |
307 // Wrapper for maintaining touchstate associated with a WebTouchEvent. | 316 // Wrapper for maintaining touchstate associated with a WebTouchEvent. |
308 class WebTouchState { | 317 class WebTouchState { |
309 public: | 318 public: |
310 explicit WebTouchState(const RenderWidgetHostViewWin* window); | 319 explicit WebTouchState(const RenderWidgetHostViewWin* window); |
311 | 320 |
312 // Updates the current touchpoint state with the supplied touches. | 321 // Updates the current touchpoint state with the supplied touches. |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
457 render_widget_host_->WasHidden(); | 466 render_widget_host_->WasHidden(); |
458 | 467 |
459 if (accelerated_surface_.get()) | 468 if (accelerated_surface_.get()) |
460 accelerated_surface_->WasHidden(); | 469 accelerated_surface_->WasHidden(); |
461 | 470 |
462 if (GetBrowserAccessibilityManager()) | 471 if (GetBrowserAccessibilityManager()) |
463 GetBrowserAccessibilityManager()->WasHidden(); | 472 GetBrowserAccessibilityManager()->WasHidden(); |
464 } | 473 } |
465 | 474 |
466 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) { | 475 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) { |
467 SetBounds(gfx::Rect(GetViewBounds().origin(), size)); | 476 SetBounds(gfx::Rect(GetPixelBounds().origin(), size)); |
468 } | 477 } |
469 | 478 |
470 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) { | 479 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) { |
471 if (is_hidden_) | 480 if (is_hidden_) |
472 return; | 481 return; |
473 | 482 |
474 // No SWP_NOREDRAW as autofill popups can move and the underneath window | 483 // No SWP_NOREDRAW as autofill popups can move and the underneath window |
475 // should redraw in that case. | 484 // should redraw in that case. |
476 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 485 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | |
477 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 486 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 ShowWindow(SW_HIDE); | 599 ShowWindow(SW_HIDE); |
591 | 600 |
592 WasHidden(); | 601 WasHidden(); |
593 } | 602 } |
594 | 603 |
595 bool RenderWidgetHostViewWin::IsShowing() { | 604 bool RenderWidgetHostViewWin::IsShowing() { |
596 return !!IsWindowVisible(); | 605 return !!IsWindowVisible(); |
597 } | 606 } |
598 | 607 |
599 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { | 608 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { |
| 609 return ui::win::ScreenToDIPRect(GetPixelBounds()); |
| 610 } |
| 611 |
| 612 gfx::Rect RenderWidgetHostViewWin::GetPixelBounds() const { |
600 CRect window_rect; | 613 CRect window_rect; |
601 GetWindowRect(&window_rect); | 614 GetWindowRect(&window_rect); |
602 return gfx::Rect(window_rect); | 615 return gfx::Rect(window_rect); |
603 } | 616 } |
604 | 617 |
605 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { | 618 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { |
606 current_cursor_ = cursor; | 619 current_cursor_ = cursor; |
607 UpdateCursorIfOverSelf(); | 620 UpdateCursorIfOverSelf(); |
608 } | 621 } |
609 | 622 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
690 // | 703 // |
691 // We paint this window synchronously, however child windows (i.e. plugins) | 704 // We paint this window synchronously, however child windows (i.e. plugins) |
692 // are painted asynchronously. By avoiding synchronous cross-process window | 705 // are painted asynchronously. By avoiding synchronous cross-process window |
693 // message dispatching we allow scrolling to be smooth, and also avoid the | 706 // message dispatching we allow scrolling to be smooth, and also avoid the |
694 // browser process locking up if the plugin process is hung. | 707 // browser process locking up if the plugin process is hung. |
695 // | 708 // |
696 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); | 709 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); |
697 | 710 |
698 // Send the invalid rect in screen coordinates. | 711 // Send the invalid rect in screen coordinates. |
699 gfx::Rect invalid_screen_rect(damage_bounds); | 712 gfx::Rect invalid_screen_rect(damage_bounds); |
700 invalid_screen_rect.Offset(GetViewBounds().OffsetFromOrigin()); | 713 invalid_screen_rect.Offset(GetPixelBounds().OffsetFromOrigin()); |
701 | 714 |
702 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); | 715 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); |
703 } | 716 } |
704 | 717 |
705 void RenderWidgetHostViewWin::DidUpdateBackingStore( | 718 void RenderWidgetHostViewWin::DidUpdateBackingStore( |
706 const gfx::Rect& scroll_rect, | 719 const gfx::Rect& scroll_rect, |
707 const gfx::Vector2d& scroll_delta, | 720 const gfx::Vector2d& scroll_delta, |
708 const std::vector<gfx::Rect>& copy_rects) { | 721 const std::vector<gfx::Rect>& copy_rects) { |
709 if (is_hidden_) | 722 if (is_hidden_) |
710 return; | 723 return; |
(...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2356 } | 2369 } |
2357 } | 2370 } |
2358 | 2371 |
2359 void RenderWidgetHostViewWin::AcceleratedPaint(HDC dc) { | 2372 void RenderWidgetHostViewWin::AcceleratedPaint(HDC dc) { |
2360 if (render_widget_host_) | 2373 if (render_widget_host_) |
2361 render_widget_host_->ScheduleComposite(); | 2374 render_widget_host_->ScheduleComposite(); |
2362 if (accelerated_surface_.get()) | 2375 if (accelerated_surface_.get()) |
2363 accelerated_surface_->Present(dc); | 2376 accelerated_surface_->Present(dc); |
2364 } | 2377 } |
2365 | 2378 |
| 2379 void RenderWidgetHostViewWin::GetScreenInfo(WebKit::WebScreenInfo* results) { |
| 2380 GetScreenInfoForWindow(results, GetNativeViewId()); |
| 2381 } |
| 2382 |
2366 gfx::Rect RenderWidgetHostViewWin::GetBoundsInRootWindow() { | 2383 gfx::Rect RenderWidgetHostViewWin::GetBoundsInRootWindow() { |
2367 RECT window_rect = {0}; | 2384 RECT window_rect = {0}; |
2368 HWND root_window = GetAncestor(m_hWnd, GA_ROOT); | 2385 HWND root_window = GetAncestor(m_hWnd, GA_ROOT); |
2369 ::GetWindowRect(root_window, &window_rect); | 2386 ::GetWindowRect(root_window, &window_rect); |
2370 gfx::Rect rect(window_rect); | 2387 gfx::Rect rect(window_rect); |
2371 | 2388 |
2372 // Maximized windows are outdented from the work area by the frame thickness | 2389 // Maximized windows are outdented from the work area by the frame thickness |
2373 // even though this "frame" is not painted. This confuses code (and people) | 2390 // even though this "frame" is not painted. This confuses code (and people) |
2374 // that think of a maximized window as corresponding exactly to the work area. | 2391 // that think of a maximized window as corresponding exactly to the work area. |
2375 // Correct for this by subtracting the frame thickness back off. | 2392 // Correct for this by subtracting the frame thickness back off. |
2376 if (::IsZoomed(root_window)) { | 2393 if (::IsZoomed(root_window)) { |
2377 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME), | 2394 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME), |
2378 GetSystemMetrics(SM_CYSIZEFRAME)); | 2395 GetSystemMetrics(SM_CYSIZEFRAME)); |
2379 } | 2396 } |
2380 return rect; | 2397 |
| 2398 return ui::win::ScreenToDIPRect(rect); |
2381 } | 2399 } |
2382 | 2400 |
2383 // Creates a HWND within the RenderWidgetHostView that will serve as a host | 2401 // Creates a HWND within the RenderWidgetHostView that will serve as a host |
2384 // for a HWND that the GPU process will create. The host window is used | 2402 // for a HWND that the GPU process will create. The host window is used |
2385 // to Z-position the GPU's window relative to other plugin windows. | 2403 // to Z-position the GPU's window relative to other plugin windows. |
2386 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { | 2404 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { |
2387 // If the window has been created, don't recreate it a second time | 2405 // If the window has been created, don't recreate it a second time |
2388 if (compositor_host_window_) | 2406 if (compositor_host_window_) |
2389 return gfx::GLSurfaceHandle(compositor_host_window_, true); | 2407 return gfx::GLSurfaceHandle(compositor_host_window_, true); |
2390 | 2408 |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2715 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, | 2733 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, |
2716 WPARAM wparam, | 2734 WPARAM wparam, |
2717 LPARAM lparam) { | 2735 LPARAM lparam) { |
2718 TRACE_EVENT0("browser", | 2736 TRACE_EVENT0("browser", |
2719 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); | 2737 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); |
2720 if (!render_widget_host_) { | 2738 if (!render_widget_host_) { |
2721 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); | 2739 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); |
2722 return; | 2740 return; |
2723 } | 2741 } |
2724 | 2742 |
| 2743 gfx::Point point = ui::win::ScreenToDIPPoint( |
| 2744 gfx::Point(static_cast<short>(LOWORD(lparam)), |
| 2745 static_cast<short>(HIWORD(lparam)))); |
| 2746 lparam = (point.y() << 16) + point.x(); |
| 2747 |
2725 WebMouseEvent event( | 2748 WebMouseEvent event( |
2726 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); | 2749 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); |
2727 | 2750 |
2728 if (mouse_locked_) { | 2751 if (mouse_locked_) { |
2729 event.movementX = event.globalX - last_mouse_position_.locked_global.x(); | 2752 event.movementX = event.globalX - last_mouse_position_.locked_global.x(); |
2730 event.movementY = event.globalY - last_mouse_position_.locked_global.y(); | 2753 event.movementY = event.globalY - last_mouse_position_.locked_global.y(); |
2731 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY); | 2754 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY); |
2732 | 2755 |
2733 event.x = last_mouse_position_.unlocked.x(); | 2756 event.x = last_mouse_position_.unlocked.x(); |
2734 event.y = last_mouse_position_.unlocked.y(); | 2757 event.y = last_mouse_position_.unlocked.y(); |
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2967 // When there is no on-going composition but |position->dwCharPos| is 0, | 2990 // When there is no on-going composition but |position->dwCharPos| is 0, |
2968 // use the caret rect. This behavior is the same to RichEdit. In fact, | 2991 // use the caret rect. This behavior is the same to RichEdit. In fact, |
2969 // CUAS (Cicero Unaware Application Support) relies on this behavior to | 2992 // CUAS (Cicero Unaware Application Support) relies on this behavior to |
2970 // implement ITfContextView::GetTextExt on top of IMM32-based applications. | 2993 // implement ITfContextView::GetTextExt on top of IMM32-based applications. |
2971 target_rect = caret_rect_.ToRECT(); | 2994 target_rect = caret_rect_.ToRECT(); |
2972 } else { | 2995 } else { |
2973 return 0; | 2996 return 0; |
2974 } | 2997 } |
2975 ClientToScreen(&target_rect); | 2998 ClientToScreen(&target_rect); |
2976 | 2999 |
2977 RECT document_rect = GetViewBounds().ToRECT(); | 3000 RECT document_rect = GetPixelBounds().ToRECT(); |
2978 ClientToScreen(&document_rect); | 3001 ClientToScreen(&document_rect); |
2979 | 3002 |
2980 position->pt.x = target_rect.left; | 3003 position->pt.x = target_rect.left; |
2981 position->pt.y = target_rect.top; | 3004 position->pt.y = target_rect.top; |
2982 position->cLineHeight = target_rect.bottom - target_rect.top; | 3005 position->cLineHeight = target_rect.bottom - target_rect.top; |
2983 position->rcDocument = document_rect; | 3006 position->rcDocument = document_rect; |
2984 return 1; | 3007 return 1; |
2985 } | 3008 } |
2986 | 3009 |
2987 void RenderWidgetHostViewWin::UpdateIMEState() { | 3010 void RenderWidgetHostViewWin::UpdateIMEState() { |
(...skipping 23 matching lines...) Expand all Loading... |
3011 | 3034 |
3012 //////////////////////////////////////////////////////////////////////////////// | 3035 //////////////////////////////////////////////////////////////////////////////// |
3013 // RenderWidgetHostView, public: | 3036 // RenderWidgetHostView, public: |
3014 | 3037 |
3015 // static | 3038 // static |
3016 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 3039 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( |
3017 RenderWidgetHost* widget) { | 3040 RenderWidgetHost* widget) { |
3018 return new RenderWidgetHostViewWin(widget); | 3041 return new RenderWidgetHostViewWin(widget); |
3019 } | 3042 } |
3020 | 3043 |
| 3044 // static |
| 3045 void RenderWidgetHostViewPort::GetDefaultScreenInfo( |
| 3046 WebKit::WebScreenInfo* results) { |
| 3047 GetScreenInfoForWindow(results, 0); |
| 3048 } |
| 3049 |
3021 } // namespace content | 3050 } // namespace content |
OLD | NEW |