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

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: Remove experimental changes to resource handling. 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 <algorithm> 7 #include <algorithm>
8 #include <map> 8 #include <map>
9 #include <stack> 9 #include <stack>
10 10
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
43 #include "content/public/browser/notification_service.h" 43 #include "content/public/browser/notification_service.h"
44 #include "content/public/browser/notification_types.h" 44 #include "content/public/browser/notification_types.h"
45 #include "content/public/common/content_switches.h" 45 #include "content/public/common/content_switches.h"
46 #include "content/public/common/page_zoom.h" 46 #include "content/public/common/page_zoom.h"
47 #include "content/public/common/process_type.h" 47 #include "content/public/common/process_type.h"
48 #include "skia/ext/skia_utils_win.h" 48 #include "skia/ext/skia_utils_win.h"
49 #include "third_party/skia/include/core/SkRegion.h" 49 #include "third_party/skia/include/core/SkRegion.h"
50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h" 50 #include "third_party/WebKit/Source/WebKit/chromium/public/WebCompositionUnderli ne.h"
51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h" 51 #include "third_party/WebKit/Source/WebKit/chromium/public/WebInputEvent.h"
52 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h" 52 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebInputEventFact ory.h"
53 #include "third_party/WebKit/Source/WebKit/chromium/public/win/WebScreenInfoFact ory.h"
53 #include "ui/base/events/event.h" 54 #include "ui/base/events/event.h"
54 #include "ui/base/events/event_utils.h" 55 #include "ui/base/events/event_utils.h"
55 #include "ui/base/ime/composition_text.h" 56 #include "ui/base/ime/composition_text.h"
56 #include "ui/base/l10n/l10n_util_win.h" 57 #include "ui/base/l10n/l10n_util_win.h"
57 #include "ui/base/text/text_elider.h" 58 #include "ui/base/text/text_elider.h"
58 #include "ui/base/ui_base_switches.h" 59 #include "ui/base/ui_base_switches.h"
59 #include "ui/base/view_prop.h" 60 #include "ui/base/view_prop.h"
61 #include "ui/base/win/dpi.h"
60 #include "ui/base/win/hwnd_util.h" 62 #include "ui/base/win/hwnd_util.h"
61 #include "ui/base/win/mouse_wheel_util.h" 63 #include "ui/base/win/mouse_wheel_util.h"
62 #include "ui/gfx/canvas.h" 64 #include "ui/gfx/canvas.h"
63 #include "ui/gfx/rect.h" 65 #include "ui/gfx/rect.h"
64 #include "ui/gfx/screen.h" 66 #include "ui/gfx/screen.h"
65 #include "webkit/glue/webcursor.h" 67 #include "webkit/glue/webcursor.h"
66 #include "webkit/plugins/npapi/plugin_constants_win.h" 68 #include "webkit/plugins/npapi/plugin_constants_win.h"
67 #include "webkit/plugins/npapi/webplugin.h" 69 #include "webkit/plugins/npapi/webplugin.h"
68 #include "webkit/plugins/npapi/webplugin_delegate_impl.h" 70 #include "webkit/plugins/npapi/webplugin_delegate_impl.h"
69 #include "win8/util/win8_util.h" 71 #include "win8/util/win8_util.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
289 private: 291 private:
290 DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint); 292 DISALLOW_COPY_AND_ASSIGN(TouchEventFromWebTouchPoint);
291 }; 293 };
292 294
293 bool ShouldSendPinchGesture() { 295 bool ShouldSendPinchGesture() {
294 static bool pinch_allowed = 296 static bool pinch_allowed =
295 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch); 297 CommandLine::ForCurrentProcess()->HasSwitch(switches::kEnablePinch);
296 return pinch_allowed; 298 return pinch_allowed;
297 } 299 }
298 300
301 void GetScreenInfoForWindow(WebKit::WebScreenInfo* results, HWND window) {
302
pkotwicz 2013/01/23 19:39:23 Pass in NativeViewId here instead of HWND Nit: Ge
kevers 2013/01/23 21:37:00 Done.
303 *results = WebKit::WebScreenInfoFactory::screenInfo(window);
304 #if defined(ENABLE_HIDPI)
305 results->deviceScaleFactor = gfx::Display::GetForcedDeviceScaleFactor();
306 #else
307 results->deviceScaleFactor = 1;
308 #endif
309 }
310
299 } // namespace 311 } // namespace
300 312
301 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND"; 313 const wchar_t kRenderWidgetHostHWNDClass[] = L"Chrome_RenderWidgetHostHWND";
302 314
303 // Wrapper for maintaining touchstate associated with a WebTouchEvent. 315 // Wrapper for maintaining touchstate associated with a WebTouchEvent.
304 class WebTouchState { 316 class WebTouchState {
305 public: 317 public:
306 explicit WebTouchState(const RenderWidgetHostViewWin* window); 318 explicit WebTouchState(const RenderWidgetHostViewWin* window);
307 319
308 // Updates the current touchpoint state with the supplied touches. 320 // Updates the current touchpoint state with the supplied touches.
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 render_widget_host_->WasHidden(); 465 render_widget_host_->WasHidden();
454 466
455 if (accelerated_surface_.get()) 467 if (accelerated_surface_.get())
456 accelerated_surface_->WasHidden(); 468 accelerated_surface_->WasHidden();
457 469
458 if (GetBrowserAccessibilityManager()) 470 if (GetBrowserAccessibilityManager())
459 GetBrowserAccessibilityManager()->WasHidden(); 471 GetBrowserAccessibilityManager()->WasHidden();
460 } 472 }
461 473
462 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) { 474 void RenderWidgetHostViewWin::SetSize(const gfx::Size& size) {
463 SetBounds(gfx::Rect(GetViewBounds().origin(), size)); 475 SetBounds(gfx::Rect(GetPixelBounds().origin(), size));
464 } 476 }
465 477
466 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) { 478 void RenderWidgetHostViewWin::SetBounds(const gfx::Rect& rect) {
467 if (is_hidden_) 479 if (is_hidden_)
468 return; 480 return;
469 481
470 // No SWP_NOREDRAW as autofill popups can move and the underneath window 482 // No SWP_NOREDRAW as autofill popups can move and the underneath window
471 // should redraw in that case. 483 // should redraw in that case.
472 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS | 484 UINT swp_flags = SWP_NOSENDCHANGING | SWP_NOOWNERZORDER | SWP_NOCOPYBITS |
473 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE; 485 SWP_NOZORDER | SWP_NOACTIVATE | SWP_DEFERERASE;
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 ShowWindow(SW_HIDE); 598 ShowWindow(SW_HIDE);
587 599
588 WasHidden(); 600 WasHidden();
589 } 601 }
590 602
591 bool RenderWidgetHostViewWin::IsShowing() { 603 bool RenderWidgetHostViewWin::IsShowing() {
592 return !!IsWindowVisible(); 604 return !!IsWindowVisible();
593 } 605 }
594 606
595 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const { 607 gfx::Rect RenderWidgetHostViewWin::GetViewBounds() const {
608 return ui::win::ScreenToDIPRect(GetPixelBounds());
609 }
610
611 gfx::Rect RenderWidgetHostViewWin::GetPixelBounds() const {
596 CRect window_rect; 612 CRect window_rect;
597 GetWindowRect(&window_rect); 613 GetWindowRect(&window_rect);
598 return gfx::Rect(window_rect); 614 return gfx::Rect(window_rect);
599 } 615 }
600 616
601 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) { 617 void RenderWidgetHostViewWin::UpdateCursor(const WebCursor& cursor) {
602 current_cursor_ = cursor; 618 current_cursor_ = cursor;
603 UpdateCursorIfOverSelf(); 619 UpdateCursorIfOverSelf();
604 } 620 }
605 621
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
683 // 699 //
684 // We paint this window synchronously, however child windows (i.e. plugins) 700 // We paint this window synchronously, however child windows (i.e. plugins)
685 // are painted asynchronously. By avoiding synchronous cross-process window 701 // are painted asynchronously. By avoiding synchronous cross-process window
686 // message dispatching we allow scrolling to be smooth, and also avoid the 702 // message dispatching we allow scrolling to be smooth, and also avoid the
687 // browser process locking up if the plugin process is hung. 703 // browser process locking up if the plugin process is hung.
688 // 704 //
689 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN); 705 RedrawWindow(NULL, damage_region, RDW_UPDATENOW | RDW_NOCHILDREN);
690 706
691 // Send the invalid rect in screen coordinates. 707 // Send the invalid rect in screen coordinates.
692 gfx::Rect invalid_screen_rect(damage_bounds); 708 gfx::Rect invalid_screen_rect(damage_bounds);
693 invalid_screen_rect.Offset(GetViewBounds().OffsetFromOrigin()); 709 invalid_screen_rect.Offset(GetPixelBounds().OffsetFromOrigin());
694 710
695 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect); 711 PaintPluginWindowsHelper(m_hWnd, invalid_screen_rect);
696 } 712 }
697 713
698 void RenderWidgetHostViewWin::DidUpdateBackingStore( 714 void RenderWidgetHostViewWin::DidUpdateBackingStore(
699 const gfx::Rect& scroll_rect, 715 const gfx::Rect& scroll_rect,
700 const gfx::Vector2d& scroll_delta, 716 const gfx::Vector2d& scroll_delta,
701 const std::vector<gfx::Rect>& copy_rects) { 717 const std::vector<gfx::Rect>& copy_rects) {
702 if (is_hidden_) 718 if (is_hidden_)
703 return; 719 return;
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
804 return; 820 return;
805 821
806 scoped_callback_runner.Release(); 822 scoped_callback_runner.Release();
807 accelerated_surface_->AsyncCopyTo( 823 accelerated_surface_->AsyncCopyTo(
808 src_subrect, 824 src_subrect,
809 dst_size, 825 dst_size,
810 output->GetBitmap().getPixels(), 826 output->GetBitmap().getPixels(),
811 callback); 827 callback);
812 } 828 }
813 829
830 void RenderWidgetHostViewWin::GetScreenInfo(WebKit::WebScreenInfo* results) {
831 GetScreenInfoForWindow(results, 0);
pkotwicz 2013/01/23 19:39:23 This should be GetNativeViewId() instead of 0.
kevers 2013/01/23 21:37:00 Done.
832 }
833
834 // static
835 void RenderWidgetHostViewPort::GetDefaultScreenInfo(
836 WebKit::WebScreenInfo* results) {
837 GetScreenInfoForWindow(results, NULL);
pkotwicz 2013/01/23 19:39:23 This should probably be 0 instead of NULL.
kevers 2013/01/23 21:37:00 Done.
838 }
839
814 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) { 840 void RenderWidgetHostViewWin::SetBackground(const SkBitmap& background) {
815 RenderWidgetHostViewBase::SetBackground(background); 841 RenderWidgetHostViewBase::SetBackground(background);
816 render_widget_host_->SetBackground(background); 842 render_widget_host_->SetBackground(background);
817 } 843 }
818 844
819 void RenderWidgetHostViewWin::ProcessAckedTouchEvent( 845 void RenderWidgetHostViewWin::ProcessAckedTouchEvent(
820 const WebKit::WebTouchEvent& touch, InputEventAckState ack_result) { 846 const WebKit::WebTouchEvent& touch, InputEventAckState ack_result) {
821 DCHECK(touch_events_enabled_); 847 DCHECK(touch_events_enabled_);
822 848
823 ScopedVector<ui::TouchEvent> events; 849 ScopedVector<ui::TouchEvent> events;
(...skipping 1536 matching lines...) Expand 10 before | Expand all | Expand 10 after
2360 gfx::Rect rect(window_rect); 2386 gfx::Rect rect(window_rect);
2361 2387
2362 // Maximized windows are outdented from the work area by the frame thickness 2388 // Maximized windows are outdented from the work area by the frame thickness
2363 // even though this "frame" is not painted. This confuses code (and people) 2389 // even though this "frame" is not painted. This confuses code (and people)
2364 // that think of a maximized window as corresponding exactly to the work area. 2390 // that think of a maximized window as corresponding exactly to the work area.
2365 // Correct for this by subtracting the frame thickness back off. 2391 // Correct for this by subtracting the frame thickness back off.
2366 if (::IsZoomed(root_window)) { 2392 if (::IsZoomed(root_window)) {
2367 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME), 2393 rect.Inset(GetSystemMetrics(SM_CXSIZEFRAME),
2368 GetSystemMetrics(SM_CYSIZEFRAME)); 2394 GetSystemMetrics(SM_CYSIZEFRAME));
2369 } 2395 }
2370 return rect; 2396
2397 // Convert to DIP
2398 return ui::win::ScreenToDIPRect(rect);
2371 } 2399 }
2372 2400
2373 // 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
2374 // 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
2375 // 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.
2376 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() { 2404 gfx::GLSurfaceHandle RenderWidgetHostViewWin::GetCompositingSurface() {
2377 // 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
2378 if (compositor_host_window_) 2406 if (compositor_host_window_)
2379 return gfx::GLSurfaceHandle(compositor_host_window_, true); 2407 return gfx::GLSurfaceHandle(compositor_host_window_, true);
2380 2408
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after
2705 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message, 2733 void RenderWidgetHostViewWin::ForwardMouseEventToRenderer(UINT message,
2706 WPARAM wparam, 2734 WPARAM wparam,
2707 LPARAM lparam) { 2735 LPARAM lparam) {
2708 TRACE_EVENT0("browser", 2736 TRACE_EVENT0("browser",
2709 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer"); 2737 "RenderWidgetHostViewWin::ForwardMouseEventToRenderer");
2710 if (!render_widget_host_) { 2738 if (!render_widget_host_) {
2711 TRACE_EVENT0("browser", "EarlyOut_NoRWH"); 2739 TRACE_EVENT0("browser", "EarlyOut_NoRWH");
2712 return; 2740 return;
2713 } 2741 }
2714 2742
2743 #if defined(ENABLE_HIDPI)
2744 // Convert to DIP
2745 gfx::Point point = ui::win::ScreenToDIPPoint(
2746 gfx::Point(static_cast<short>(LOWORD(lparam)),
2747 static_cast<short>(HIWORD(lparam))));
2748 lparam = (point.y() << 16) + point.x();
2749 #endif
2750
2715 WebMouseEvent event( 2751 WebMouseEvent event(
2716 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam)); 2752 WebInputEventFactory::mouseEvent(m_hWnd, message, wparam, lparam));
2717 2753
2718 if (mouse_locked_) { 2754 if (mouse_locked_) {
2719 event.movementX = event.globalX - last_mouse_position_.locked_global.x(); 2755 event.movementX = event.globalX - last_mouse_position_.locked_global.x();
2720 event.movementY = event.globalY - last_mouse_position_.locked_global.y(); 2756 event.movementY = event.globalY - last_mouse_position_.locked_global.y();
2721 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY); 2757 last_mouse_position_.locked_global.SetPoint(event.globalX, event.globalY);
2722 2758
2723 event.x = last_mouse_position_.unlocked.x(); 2759 event.x = last_mouse_position_.unlocked.x();
2724 event.y = last_mouse_position_.unlocked.y(); 2760 event.y = last_mouse_position_.unlocked.y();
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
2957 // When there is no on-going composition but |position->dwCharPos| is 0, 2993 // When there is no on-going composition but |position->dwCharPos| is 0,
2958 // use the caret rect. This behavior is the same to RichEdit. In fact, 2994 // use the caret rect. This behavior is the same to RichEdit. In fact,
2959 // CUAS (Cicero Unaware Application Support) relies on this behavior to 2995 // CUAS (Cicero Unaware Application Support) relies on this behavior to
2960 // implement ITfContextView::GetTextExt on top of IMM32-based applications. 2996 // implement ITfContextView::GetTextExt on top of IMM32-based applications.
2961 target_rect = caret_rect_.ToRECT(); 2997 target_rect = caret_rect_.ToRECT();
2962 } else { 2998 } else {
2963 return 0; 2999 return 0;
2964 } 3000 }
2965 ClientToScreen(&target_rect); 3001 ClientToScreen(&target_rect);
2966 3002
2967 RECT document_rect = GetViewBounds().ToRECT(); 3003 RECT document_rect = GetPixelBounds().ToRECT();
2968 ClientToScreen(&document_rect); 3004 ClientToScreen(&document_rect);
2969 3005
2970 position->pt.x = target_rect.left; 3006 position->pt.x = target_rect.left;
2971 position->pt.y = target_rect.top; 3007 position->pt.y = target_rect.top;
2972 position->cLineHeight = target_rect.bottom - target_rect.top; 3008 position->cLineHeight = target_rect.bottom - target_rect.top;
2973 position->rcDocument = document_rect; 3009 position->rcDocument = document_rect;
2974 return 1; 3010 return 1;
2975 } 3011 }
2976 3012
2977 void RenderWidgetHostViewWin::UpdateIMEState() { 3013 void RenderWidgetHostViewWin::UpdateIMEState() {
(...skipping 13 matching lines...) Expand all
2991 //////////////////////////////////////////////////////////////////////////////// 3027 ////////////////////////////////////////////////////////////////////////////////
2992 // RenderWidgetHostView, public: 3028 // RenderWidgetHostView, public:
2993 3029
2994 // static 3030 // static
2995 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget( 3031 RenderWidgetHostView* RenderWidgetHostView::CreateViewForWidget(
2996 RenderWidgetHost* widget) { 3032 RenderWidgetHost* widget) {
2997 return new RenderWidgetHostViewWin(widget); 3033 return new RenderWidgetHostViewWin(widget);
2998 } 3034 }
2999 3035
3000 } // namespace content 3036 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698