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

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

Issue 1308553007: Convert MouseEvents from DIPS to Pixels before passing it to surfaces for hittesting. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressing comments Created 5 years, 1 month 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_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include <set> 7 #include <set>
8 8
9 #include "base/auto_reset.h" 9 #include "base/auto_reset.h"
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 #include "ui/compositor/compositor_vsync_manager.h" 73 #include "ui/compositor/compositor_vsync_manager.h"
74 #include "ui/compositor/dip_util.h" 74 #include "ui/compositor/dip_util.h"
75 #include "ui/events/blink/blink_event_util.h" 75 #include "ui/events/blink/blink_event_util.h"
76 #include "ui/events/event.h" 76 #include "ui/events/event.h"
77 #include "ui/events/event_utils.h" 77 #include "ui/events/event_utils.h"
78 #include "ui/events/gesture_detection/gesture_configuration.h" 78 #include "ui/events/gesture_detection/gesture_configuration.h"
79 #include "ui/events/gestures/gesture_recognizer.h" 79 #include "ui/events/gestures/gesture_recognizer.h"
80 #include "ui/gfx/canvas.h" 80 #include "ui/gfx/canvas.h"
81 #include "ui/gfx/color_profile.h" 81 #include "ui/gfx/color_profile.h"
82 #include "ui/gfx/display.h" 82 #include "ui/gfx/display.h"
83 #include "ui/gfx/geometry/dip_util.h"
83 #include "ui/gfx/geometry/rect_conversions.h" 84 #include "ui/gfx/geometry/rect_conversions.h"
84 #include "ui/gfx/geometry/size_conversions.h" 85 #include "ui/gfx/geometry/size_conversions.h"
85 #include "ui/gfx/screen.h" 86 #include "ui/gfx/screen.h"
86 #include "ui/gfx/skia_util.h" 87 #include "ui/gfx/skia_util.h"
87 #include "ui/touch_selection/touch_selection_controller.h" 88 #include "ui/touch_selection/touch_selection_controller.h"
88 #include "ui/wm/public/activation_client.h" 89 #include "ui/wm/public/activation_client.h"
89 #include "ui/wm/public/scoped_tooltip_disabler.h" 90 #include "ui/wm/public/scoped_tooltip_disabler.h"
90 #include "ui/wm/public/tooltip_client.h" 91 #include "ui/wm/public/tooltip_client.h"
91 #include "ui/wm/public/transient_window_client.h" 92 #include "ui/wm/public/transient_window_client.h"
92 #include "ui/wm/public/window_types.h" 93 #include "ui/wm/public/window_types.h"
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
468 cursor_visibility_state_in_renderer_(UNKNOWN), 469 cursor_visibility_state_in_renderer_(UNKNOWN),
469 #if defined(OS_WIN) 470 #if defined(OS_WIN)
470 legacy_render_widget_host_HWND_(NULL), 471 legacy_render_widget_host_HWND_(NULL),
471 legacy_window_destroyed_(false), 472 legacy_window_destroyed_(false),
472 showing_context_menu_(false), 473 showing_context_menu_(false),
473 #endif 474 #endif
474 has_snapped_to_boundary_(false), 475 has_snapped_to_boundary_(false),
475 is_guest_view_hack_(is_guest_view_hack), 476 is_guest_view_hack_(is_guest_view_hack),
476 begin_frame_observer_proxy_(this), 477 begin_frame_observer_proxy_(this),
477 set_focus_on_mouse_down_(false), 478 set_focus_on_mouse_down_(false),
479 device_scale_factor_(0.0f),
478 weak_ptr_factory_(this) { 480 weak_ptr_factory_(this) {
479 if (!is_guest_view_hack_) 481 if (!is_guest_view_hack_)
480 host_->SetView(this); 482 host_->SetView(this);
481 483
482 window_observer_.reset(new WindowObserver(this)); 484 window_observer_.reset(new WindowObserver(this));
483 485
484 aura::client::SetTooltipText(window_, &tooltip_); 486 aura::client::SetTooltipText(window_, &tooltip_);
485 aura::client::SetActivationDelegate(window_, this); 487 aura::client::SetActivationDelegate(window_, this);
486 aura::client::SetFocusChangeObserver(window_, this); 488 aura::client::SetFocusChangeObserver(window_, this);
487 window_->set_layer_owner_delegate(delegated_frame_host_.get()); 489 window_->set_layer_owner_delegate(delegated_frame_host_.get());
(...skipping 29 matching lines...) Expand all
517 IPC_END_MESSAGE_MAP() 519 IPC_END_MESSAGE_MAP()
518 return handled; 520 return handled;
519 } 521 }
520 522
521 void RenderWidgetHostViewAura::InitAsChild( 523 void RenderWidgetHostViewAura::InitAsChild(
522 gfx::NativeView parent_view) { 524 gfx::NativeView parent_view) {
523 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL); 525 window_->SetType(ui::wm::WINDOW_TYPE_CONTROL);
524 window_->Init(ui::LAYER_SOLID_COLOR); 526 window_->Init(ui::LAYER_SOLID_COLOR);
525 window_->SetName("RenderWidgetHostViewAura"); 527 window_->SetName("RenderWidgetHostViewAura");
526 window_->layer()->SetColor(background_color_); 528 window_->layer()->SetColor(background_color_);
529
530 const gfx::Display display =
531 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_);
sadrul 2015/11/04 19:03:44 I don't think |window_| is parented here yet. Bett
lfg 2015/11/04 19:39:09 Done.
532 device_scale_factor_ = display.device_scale_factor();
527 } 533 }
528 534
529 void RenderWidgetHostViewAura::InitAsPopup( 535 void RenderWidgetHostViewAura::InitAsPopup(
530 RenderWidgetHostView* parent_host_view, 536 RenderWidgetHostView* parent_host_view,
531 const gfx::Rect& bounds_in_screen) { 537 const gfx::Rect& bounds_in_screen) {
532 popup_parent_host_view_ = 538 popup_parent_host_view_ =
533 static_cast<RenderWidgetHostViewAura*>(parent_host_view); 539 static_cast<RenderWidgetHostViewAura*>(parent_host_view);
534 540
535 // TransientWindowClient may be NULL during tests. 541 // TransientWindowClient may be NULL during tests.
536 aura::client::TransientWindowClient* transient_window_client = 542 aura::client::TransientWindowClient* transient_window_client =
(...skipping 28 matching lines...) Expand all
565 571
566 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow(); 572 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow();
567 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen); 573 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen);
568 574
569 SetBounds(bounds_in_screen); 575 SetBounds(bounds_in_screen);
570 Show(); 576 Show();
571 if (NeedsMouseCapture()) 577 if (NeedsMouseCapture())
572 window_->SetCapture(); 578 window_->SetCapture();
573 579
574 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); 580 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this));
581
582 const gfx::Display display =
583 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_);
584 device_scale_factor_ = display.device_scale_factor();
575 } 585 }
576 586
577 void RenderWidgetHostViewAura::InitAsFullscreen( 587 void RenderWidgetHostViewAura::InitAsFullscreen(
578 RenderWidgetHostView* reference_host_view) { 588 RenderWidgetHostView* reference_host_view) {
579 is_fullscreen_ = true; 589 is_fullscreen_ = true;
580 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL); 590 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL);
581 window_->Init(ui::LAYER_SOLID_COLOR); 591 window_->Init(ui::LAYER_SOLID_COLOR);
582 window_->SetName("RenderWidgetHostViewAura"); 592 window_->SetName("RenderWidgetHostViewAura");
583 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); 593 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN);
584 window_->layer()->SetColor(background_color_); 594 window_->layer()->SetColor(background_color_);
585 595
586 aura::Window* parent = NULL; 596 aura::Window* parent = NULL;
587 gfx::Rect bounds; 597 gfx::Rect bounds;
588 if (reference_host_view) { 598 if (reference_host_view) {
589 aura::Window* reference_window = 599 aura::Window* reference_window =
590 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; 600 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_;
591 if (reference_window) { 601 if (reference_window) {
592 host_tracker_.reset(new aura::WindowTracker); 602 host_tracker_.reset(new aura::WindowTracker);
593 host_tracker_->Add(reference_window); 603 host_tracker_->Add(reference_window);
594 } 604 }
595 gfx::Display display = gfx::Screen::GetScreenFor(window_)-> 605 gfx::Display display = gfx::Screen::GetScreenFor(window_)->
596 GetDisplayNearestWindow(reference_window); 606 GetDisplayNearestWindow(reference_window);
597 parent = reference_window->GetRootWindow(); 607 parent = reference_window->GetRootWindow();
598 bounds = display.bounds(); 608 bounds = display.bounds();
599 } 609 }
600 aura::client::ParentWindowWithContext(window_, parent, bounds); 610 aura::client::ParentWindowWithContext(window_, parent, bounds);
601 Show(); 611 Show();
602 Focus(); 612 Focus();
613
614 const gfx::Display display =
615 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_);
616 device_scale_factor_ = display.device_scale_factor();
603 } 617 }
604 618
605 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { 619 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const {
606 return host_; 620 return host_;
607 } 621 }
608 622
609 void RenderWidgetHostViewAura::Show() { 623 void RenderWidgetHostViewAura::Show() {
610 window_->Show(); 624 window_->Show();
611 625
612 if (!host_->is_hidden()) 626 if (!host_->is_hidden())
(...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after
1876 NOTREACHED(); 1890 NOTREACHED();
1877 } 1891 }
1878 1892
1879 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( 1893 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged(
1880 float device_scale_factor) { 1894 float device_scale_factor) {
1881 if (!host_ || !window_->GetRootWindow()) 1895 if (!host_ || !window_->GetRootWindow())
1882 return; 1896 return;
1883 1897
1884 UpdateScreenInfo(window_); 1898 UpdateScreenInfo(window_);
1885 1899
1900 device_scale_factor_ = device_scale_factor;
1886 const gfx::Display display = gfx::Screen::GetScreenFor(window_)-> 1901 const gfx::Display display = gfx::Screen::GetScreenFor(window_)->
1887 GetDisplayNearestWindow(window_); 1902 GetDisplayNearestWindow(window_);
1888 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); 1903 DCHECK_EQ(device_scale_factor, display.device_scale_factor());
1889 current_cursor_.SetDisplayInfo(display); 1904 current_cursor_.SetDisplayInfo(display);
1890 SnapToPhysicalPixelBoundary(); 1905 SnapToPhysicalPixelBoundary();
1891 } 1906 }
1892 1907
1893 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) { 1908 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) {
1894 #if defined(OS_WIN) 1909 #if defined(OS_WIN)
1895 HWND parent = NULL; 1910 HWND parent = NULL;
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after
2167 window_->parent()->delegate()->OnMouseEvent(event); 2182 window_->parent()->delegate()->OnMouseEvent(event);
2168 } 2183 }
2169 2184
2170 if (!IsXButtonUpEvent(event)) 2185 if (!IsXButtonUpEvent(event))
2171 event->SetHandled(); 2186 event->SetHandled();
2172 } 2187 }
2173 2188
2174 uint32_t RenderWidgetHostViewAura::SurfaceIdNamespaceAtPoint( 2189 uint32_t RenderWidgetHostViewAura::SurfaceIdNamespaceAtPoint(
2175 const gfx::Point& point, 2190 const gfx::Point& point,
2176 gfx::Point* transformed_point) { 2191 gfx::Point* transformed_point) {
2177 cc::SurfaceId id = 2192 DCHECK(device_scale_factor_ != 0.0f);
2178 delegated_frame_host_->SurfaceIdAtPoint(point, transformed_point); 2193
2194 // The surface hittest happens in device pixels, so we need to convert the
2195 // |point| from DIPs to pixels before hittesting.
2196 gfx::Point point_in_pixels =
2197 gfx::ConvertPointToPixel(device_scale_factor_, point);
2198 cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint(point_in_pixels,
2199 transformed_point);
2200 *transformed_point =
2201 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point);
2202
2179 // It is possible that the renderer has not yet produced a surface, in which 2203 // It is possible that the renderer has not yet produced a surface, in which
2180 // case we return our current namespace. 2204 // case we return our current namespace.
2181 if (id.is_null()) 2205 if (id.is_null())
2182 return GetSurfaceIdNamespace(); 2206 return GetSurfaceIdNamespace();
2183 return cc::SurfaceIdAllocator::NamespaceForId(id); 2207 return cc::SurfaceIdAllocator::NamespaceForId(id);
2184 } 2208 }
2185 2209
2186 void RenderWidgetHostViewAura::ProcessMouseEvent( 2210 void RenderWidgetHostViewAura::ProcessMouseEvent(
2187 const blink::WebMouseEvent& event) { 2211 const blink::WebMouseEvent& event) {
2188 host_->ForwardMouseEvent(event); 2212 host_->ForwardMouseEvent(event);
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
2899 2923
2900 //////////////////////////////////////////////////////////////////////////////// 2924 ////////////////////////////////////////////////////////////////////////////////
2901 // RenderWidgetHostViewBase, public: 2925 // RenderWidgetHostViewBase, public:
2902 2926
2903 // static 2927 // static
2904 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { 2928 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) {
2905 GetScreenInfoForWindow(results, NULL); 2929 GetScreenInfoForWindow(results, NULL);
2906 } 2930 }
2907 2931
2908 } // namespace content 2932 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698