Chromium Code Reviews| 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 #if defined(ENABLE_HIDPI) | |
| 310 results->deviceScaleFactor = ui::win::GetDeviceScaleFactor(); | |
| 
 
darin (slow to review)
2013/01/30 21:39:12
Wouldn't it be better to provide ui::win::GetDevic
 
kevers
2013/01/30 22:27:01
Removed the #ifdef, as GetDeviceScaleFactor always
 
 | |
| 311 #else | |
| 312 results->deviceScaleFactor = 1; | |
| 313 #endif | |
| 314 } | |
| 315 | |
| 303 } // namespace | 316 } // namespace | 
| 304 | 317 | 
| 305 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; | 318 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; | 
| 306 | 319 | 
| 307 // Wrapper for maintaining touchstate associated with a WebTouchEvent. | 320 // Wrapper for maintaining touchstate associated with a WebTouchEvent. | 
| 308 class WebTouchState { | 321 class WebTouchState { | 
| 309 public: | 322 public: | 
| 310 explicit WebTouchState(const RenderWidgetHostViewWin* window); | 323 explicit WebTouchState(const RenderWidgetHostViewWin* window); | 
| 311 | 324 | 
| 312 // Updates the current touchpoint state with the supplied touches. | 325 // 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(); | 470 render_widget_host_->WasHidden(); | 
| 458 | 471 | 
| 459 if (accelerated_surface_.get()) | 472 if (accelerated_surface_.get()) | 
| 460 accelerated_surface_->WasHidden(); | 473 accelerated_surface_->WasHidden(); | 
| 461 | 474 | 
| 462 if (GetBrowserAccessibilityManager()) | 475 if (GetBrowserAccessibilityManager()) | 
| 463 GetBrowserAccessibilityManager()->WasHidden(); | 476 GetBrowserAccessibilityManager()->WasHidden(); | 
| 464 } | 477 } | 
| 465 | 478 | 
| 466 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) { | 479 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) { | 
| 467 SetBounds(gfx::Rect(GetViewBounds().origin(), size)); | 480 SetBounds(gfx::Rect(GetPixelBounds().origin(), size)); | 
| 468 } | 481 } | 
| 469 | 482 | 
| 470 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) { | 483 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) { | 
| 471 if (is_hidden_) | 484 if (is_hidden_) | 
| 472 return; | 485 return; | 
| 473 | 486 | 
| 474 // No SWP_NOREDRAW as autofill popups can move and the underneath window | 487 // No SWP_NOREDRAW as autofill popups can move and the underneath window | 
| 475 // should redraw in that case. | 488 // should redraw in that case. | 
| 476 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 489 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | | 
| 477 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 490 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; | 
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 590 ShowWindow(SW_HIDE); | 603 ShowWindow(SW_HIDE); | 
| 591 | 604 | 
| 592 WasHidden(); | 605 WasHidden(); | 
| 593 } | 606 } | 
| 594 | 607 | 
| 595 bool RenderWidgetHostViewWin::IsShowing() { | 608 bool RenderWidgetHostViewWin::IsShowing() { | 
| 596 return !!IsWindowVisible(); | 609 return !!IsWindowVisible(); | 
| 597 } | 610 } | 
| 598 | 611 | 
| 599 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { | 612 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { | 
| 613 return ui::win::ScreenToDIPRect(GetPixelBounds()); | |
| 614 } | |
| 615 | |
| 616 gfx::Rect RenderWidgetHostViewWin::GetPixelBounds() const { | |
| 600 CRect window_rect; | 617 CRect window_rect; | 
| 601 GetWindowRect(&window_rect); | 618 GetWindowRect(&window_rect); | 
| 602 return gfx::Rect(window_rect); | 619 return gfx::Rect(window_rect); | 
| 603 } | 620 } | 
| 604 | 621 | 
| 605 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { | 622 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { | 
| 606 current_cursor_ = cursor; | 623 current_cursor_ = cursor; | 
| 607 UpdateCursorIfOverSelf(); | 624 UpdateCursorIfOverSelf(); | 
| 608 } | 625 } | 
| 609 | 626 | 
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 690 // | 707 // | 
| 691 // We paint this window synchronously, however child windows (i.e. plugins) | 708 // We paint this window synchronously, however child windows (i.e. plugins) | 
| 692 // are painted asynchronously. By avoiding synchronous cross-process window | 709 // are painted asynchronously. By avoiding synchronous cross-process window | 
| 693 // message dispatching we allow scrolling to be smooth, and also avoid the | 710 // message dispatching we allow scrolling to be smooth, and also avoid the | 
| 694 // browser process locking up if the plugin process is hung. | 711 // browser process locking up if the plugin process is hung. | 
| 695 // | 712 // | 
| 696 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); | 713 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); | 
| 697 | 714 | 
| 698 // Send the invalid rect in screen coordinates. | 715 // Send the invalid rect in screen coordinates. | 
| 699 gfx::Rect invalid_screen_rect(damage_bounds); | 716 gfx::Rect invalid_screen_rect(damage_bounds); | 
| 700 invalid_screen_rect.Offset(GetViewBounds().OffsetFromOrigin()); | 717 invalid_screen_rect.Offset(GetPixelBounds().OffsetFromOrigin()); | 
| 701 | 718 | 
| 702 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); | 719 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); | 
| 703 } | 720 } | 
| 704 | 721 | 
| 705 void RenderWidgetHostViewWin::DidUpdateBackingStore( | 722 void RenderWidgetHostViewWin::DidUpdateBackingStore( | 
| 706 const gfx::Rect& scroll_rect, | 723 const gfx::Rect& scroll_rect, | 
| 707 const gfx::Vector2d& scroll_delta, | 724 const gfx::Vector2d& scroll_delta, | 
| 708 const std::vector<gfx::Rect>& copy_rects) { | 725 const std::vector<gfx::Rect>& copy_rects) { | 
| 709 if (is_hidden_) | 726 if (is_hidden_) | 
| 710 return; | 727 return; | 
| (...skipping 1645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2356 } | 2373 } | 
| 2357 } | 2374 } | 
| 2358 | 2375 | 
| 2359 void RenderWidgetHostViewWin::AcceleratedPaint(HDC dc) { | 2376 void RenderWidgetHostViewWin::AcceleratedPaint(HDC dc) { | 
| 2360 if (render_widget_host_) | 2377 if (render_widget_host_) | 
| 2361 render_widget_host_->ScheduleComposite(); | 2378 render_widget_host_->ScheduleComposite(); | 
| 2362 if (accelerated_surface_.get()) | 2379 if (accelerated_surface_.get()) | 
| 2363 accelerated_surface_->Present(dc); | 2380 accelerated_surface_->Present(dc); | 
| 2364 } | 2381 } | 
| 2365 | 2382 | 
| 2383 void RenderWidgetHostViewWin::GetScreenInfo(WebKit::WebScreenInfo* results) { | |
| 2384 GetScreenInfoForWindow(results, GetNativeViewId()); | |
| 2385 } | |
| 2386 | |
| 2366 gfx::Rect RenderWidgetHostViewWin::GetBoundsInRootWindow() { | 2387 gfx::Rect RenderWidgetHostViewWin::GetBoundsInRootWindow() { | 
| 2367 RECT window_rect = {0}; | 2388 RECT window_rect = {0}; | 
| 2368 HWND root_window = GetAncestor(m_hWnd, GA_ROOT); | 2389 HWND root_window = GetAncestor(m_hWnd, GA_ROOT); | 
| 2369 ::GetWindowRect(root_window, &window_rect); | 2390 ::GetWindowRect(root_window, &window_rect); | 
| 2370 gfx::Rect rect(window_rect); | 2391 gfx::Rect rect(window_rect); | 
| 2371 | 2392 | 
| 2372 // Maximized windows are outdented from the work area by the frame thickness | 2393 // 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) | 2394 // 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. | 2395 // that think of a maximized window as corresponding exactly to the work area. | 
| 2375 // Correct for this by subtracting the frame thickness back off. | 2396 // Correct for this by subtracting the frame thickness back off. | 
| 2376 if (::IsZoomed(root_window)) { | 2397 if (::IsZoomed(root_window)) { | 
| 2377 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME), | 2398 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME), | 
| 2378 GetSystemMetrics(SM_CYSIZEFRAME)); | 2399 GetSystemMetrics(SM_CYSIZEFRAME)); | 
| 2379 } | 2400 } | 
| 2380 return rect; | 2401 | 
| 2402 // Convert to DIP | |
| 2403 return ui::win::ScreenToDIPRect(rect); | |
| 2381 } | 2404 } | 
| 2382 | 2405 | 
| 2383 // Creates a HWND within the RenderWidgetHostView that will serve as a host | 2406 // 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 | 2407 // 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. | 2408 // to Z-position the GPU's window relative to other plugin windows. | 
| 2386 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { | 2409 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { | 
| 2387 // If the window has been created, don't recreate it a second time | 2410 // If the window has been created, don't recreate it a second time | 
| 2388 if (compositor_host_window_) | 2411 if (compositor_host_window_) | 
| 2389 return gfx::GLSurfaceHandle(compositor_host_window_, true); | 2412 return gfx::GLSurfaceHandle(compositor_host_window_, true); | 
| 2390 | 2413 | 
| (...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2715 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, | 2738 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, | 
| 2716 WPARAM wparam, | 2739 WPARAM wparam, | 
| 2717 LPARAM lparam) { | 2740 LPARAM lparam) { | 
| 2718 TRACE_EVENT0("browser", | 2741 TRACE_EVENT0("browser", | 
| 2719 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); | 2742 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); | 
| 2720 if (!render_widget_host_) { | 2743 if (!render_widget_host_) { | 
| 2721 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); | 2744 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); | 
| 2722 return; | 2745 return; | 
| 2723 } | 2746 } | 
| 2724 | 2747 | 
| 2748 #if defined(ENABLE_HIDPI) | |
| 
 
darin (slow to review)
2013/01/30 21:39:12
Why do we need ENABLE_HIDPI?  Why not just have al
 
kevers
2013/01/30 22:27:01
The ScreenToDPIPoint is an identity function when
 
 | |
| 2749 // Convert to DIP | |
| 2750 gfx::Point point = ui::win::ScreenToDIPPoint( | |
| 2751 gfx::Point(static_cast<short>(LOWORD(lparam)), | |
| 2752 static_cast<short>(HIWORD(lparam)))); | |
| 2753 lparam = (point.y() << 16) + point.x(); | |
| 2754 #endif | |
| 2755 | |
| 2725 WebMouseEvent event( | 2756 WebMouseEvent event( | 
| 2726 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); | 2757 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); | 
| 2727 | 2758 | 
| 2728 if (mouse_locked_) { | 2759 if (mouse_locked_) { | 
| 2729 event.movementX = event.globalX - last_mouse_position_.locked_global.x(); | 2760 event.movementX = event.globalX - last_mouse_position_.locked_global.x(); | 
| 2730 event.movementY = event.globalY - last_mouse_position_.locked_global.y(); | 2761 event.movementY = event.globalY - last_mouse_position_.locked_global.y(); | 
| 2731 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY); | 2762 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY); | 
| 2732 | 2763 | 
| 2733 event.x = last_mouse_position_.unlocked.x(); | 2764 event.x = last_mouse_position_.unlocked.x(); | 
| 2734 event.y = last_mouse_position_.unlocked.y(); | 2765 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, | 2998 // 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, | 2999 // use the caret rect. This behavior is the same to RichEdit. In fact, | 
| 2969 // CUAS (Cicero Unaware Application Support) relies on this behavior to | 3000 // CUAS (Cicero Unaware Application Support) relies on this behavior to | 
| 2970 // implement ITfContextView::GetTextExt on top of IMM32-based applications. | 3001 // implement ITfContextView::GetTextExt on top of IMM32-based applications. | 
| 2971 target_rect = caret_rect_.ToRECT(); | 3002 target_rect = caret_rect_.ToRECT(); | 
| 2972 } else { | 3003 } else { | 
| 2973 return 0; | 3004 return 0; | 
| 2974 } | 3005 } | 
| 2975 ClientToScreen(&target_rect); | 3006 ClientToScreen(&target_rect); | 
| 2976 | 3007 | 
| 2977 RECT document_rect = GetViewBounds().ToRECT(); | 3008 RECT document_rect = GetPixelBounds().ToRECT(); | 
| 2978 ClientToScreen(&document_rect); | 3009 ClientToScreen(&document_rect); | 
| 2979 | 3010 | 
| 2980 position->pt.x = target_rect.left; | 3011 position->pt.x = target_rect.left; | 
| 2981 position->pt.y = target_rect.top; | 3012 position->pt.y = target_rect.top; | 
| 2982 position->cLineHeight = target_rect.bottom - target_rect.top; | 3013 position->cLineHeight = target_rect.bottom - target_rect.top; | 
| 2983 position->rcDocument = document_rect; | 3014 position->rcDocument = document_rect; | 
| 2984 return 1; | 3015 return 1; | 
| 2985 } | 3016 } | 
| 2986 | 3017 | 
| 2987 void RenderWidgetHostViewWin::UpdateIMEState() { | 3018 void RenderWidgetHostViewWin::UpdateIMEState() { | 
| (...skipping 23 matching lines...) Expand all Loading... | |
| 3011 | 3042 | 
| 3012 //////////////////////////////////////////////////////////////////////////////// | 3043 //////////////////////////////////////////////////////////////////////////////// | 
| 3013 // RenderWidgetHostView, public: | 3044 // RenderWidgetHostView, public: | 
| 3014 | 3045 | 
| 3015 // static | 3046 // static | 
| 3016 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 3047 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( | 
| 3017 RenderWidgetHost* widget) { | 3048 RenderWidgetHost* widget) { | 
| 3018 return new RenderWidgetHostViewWin(widget); | 3049 return new RenderWidgetHostViewWin(widget); | 
| 3019 } | 3050 } | 
| 3020 | 3051 | 
| 3052 // static | |
| 3053 void RenderWidgetHostViewPort::GetDefaultScreenInfo( | |
| 3054 WebKit::WebScreenInfo* results) { | |
| 3055 GetScreenInfoForWindow(results, 0); | |
| 3056 } | |
| 3057 | |
| 3021 } // namespace content | 3058 } // namespace content | 
| OLD | NEW |