Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_win.cc

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

Powered by Google App Engine
This is Rietveld 408576698