| 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_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 Loading... |
| 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 Loading... |
| 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 Loading... |
| 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 if (parent_view) |
| 531 parent_view->AddChild(GetNativeView()); |
| 532 |
| 533 const gfx::Display display = |
| 534 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_); |
| 535 device_scale_factor_ = display.device_scale_factor(); |
| 527 } | 536 } |
| 528 | 537 |
| 529 void RenderWidgetHostViewAura::InitAsPopup( | 538 void RenderWidgetHostViewAura::InitAsPopup( |
| 530 RenderWidgetHostView* parent_host_view, | 539 RenderWidgetHostView* parent_host_view, |
| 531 const gfx::Rect& bounds_in_screen) { | 540 const gfx::Rect& bounds_in_screen) { |
| 532 popup_parent_host_view_ = | 541 popup_parent_host_view_ = |
| 533 static_cast<RenderWidgetHostViewAura*>(parent_host_view); | 542 static_cast<RenderWidgetHostViewAura*>(parent_host_view); |
| 534 | 543 |
| 535 // TransientWindowClient may be NULL during tests. | 544 // TransientWindowClient may be NULL during tests. |
| 536 aura::client::TransientWindowClient* transient_window_client = | 545 aura::client::TransientWindowClient* transient_window_client = |
| (...skipping 28 matching lines...) Expand all Loading... |
| 565 | 574 |
| 566 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow(); | 575 aura::Window* root = popup_parent_host_view_->window_->GetRootWindow(); |
| 567 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen); | 576 aura::client::ParentWindowWithContext(window_, root, bounds_in_screen); |
| 568 | 577 |
| 569 SetBounds(bounds_in_screen); | 578 SetBounds(bounds_in_screen); |
| 570 Show(); | 579 Show(); |
| 571 if (NeedsMouseCapture()) | 580 if (NeedsMouseCapture()) |
| 572 window_->SetCapture(); | 581 window_->SetCapture(); |
| 573 | 582 |
| 574 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); | 583 event_filter_for_popup_exit_.reset(new EventFilterForPopupExit(this)); |
| 584 |
| 585 const gfx::Display display = |
| 586 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_); |
| 587 device_scale_factor_ = display.device_scale_factor(); |
| 575 } | 588 } |
| 576 | 589 |
| 577 void RenderWidgetHostViewAura::InitAsFullscreen( | 590 void RenderWidgetHostViewAura::InitAsFullscreen( |
| 578 RenderWidgetHostView* reference_host_view) { | 591 RenderWidgetHostView* reference_host_view) { |
| 579 is_fullscreen_ = true; | 592 is_fullscreen_ = true; |
| 580 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL); | 593 window_->SetType(ui::wm::WINDOW_TYPE_NORMAL); |
| 581 window_->Init(ui::LAYER_SOLID_COLOR); | 594 window_->Init(ui::LAYER_SOLID_COLOR); |
| 582 window_->SetName("RenderWidgetHostViewAura"); | 595 window_->SetName("RenderWidgetHostViewAura"); |
| 583 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); | 596 window_->SetProperty(aura::client::kShowStateKey, ui::SHOW_STATE_FULLSCREEN); |
| 584 window_->layer()->SetColor(background_color_); | 597 window_->layer()->SetColor(background_color_); |
| 585 | 598 |
| 586 aura::Window* parent = NULL; | 599 aura::Window* parent = NULL; |
| 587 gfx::Rect bounds; | 600 gfx::Rect bounds; |
| 588 if (reference_host_view) { | 601 if (reference_host_view) { |
| 589 aura::Window* reference_window = | 602 aura::Window* reference_window = |
| 590 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; | 603 static_cast<RenderWidgetHostViewAura*>(reference_host_view)->window_; |
| 591 if (reference_window) { | 604 if (reference_window) { |
| 592 host_tracker_.reset(new aura::WindowTracker); | 605 host_tracker_.reset(new aura::WindowTracker); |
| 593 host_tracker_->Add(reference_window); | 606 host_tracker_->Add(reference_window); |
| 594 } | 607 } |
| 595 gfx::Display display = gfx::Screen::GetScreenFor(window_)-> | 608 gfx::Display display = gfx::Screen::GetScreenFor(window_)-> |
| 596 GetDisplayNearestWindow(reference_window); | 609 GetDisplayNearestWindow(reference_window); |
| 597 parent = reference_window->GetRootWindow(); | 610 parent = reference_window->GetRootWindow(); |
| 598 bounds = display.bounds(); | 611 bounds = display.bounds(); |
| 599 } | 612 } |
| 600 aura::client::ParentWindowWithContext(window_, parent, bounds); | 613 aura::client::ParentWindowWithContext(window_, parent, bounds); |
| 601 Show(); | 614 Show(); |
| 602 Focus(); | 615 Focus(); |
| 616 |
| 617 const gfx::Display display = |
| 618 gfx::Screen::GetScreenFor(window_)->GetDisplayNearestWindow(window_); |
| 619 device_scale_factor_ = display.device_scale_factor(); |
| 603 } | 620 } |
| 604 | 621 |
| 605 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { | 622 RenderWidgetHost* RenderWidgetHostViewAura::GetRenderWidgetHost() const { |
| 606 return host_; | 623 return host_; |
| 607 } | 624 } |
| 608 | 625 |
| 609 void RenderWidgetHostViewAura::Show() { | 626 void RenderWidgetHostViewAura::Show() { |
| 610 window_->Show(); | 627 window_->Show(); |
| 611 | 628 |
| 612 if (!host_->is_hidden()) | 629 if (!host_->is_hidden()) |
| (...skipping 1263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 NOTREACHED(); | 1893 NOTREACHED(); |
| 1877 } | 1894 } |
| 1878 | 1895 |
| 1879 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( | 1896 void RenderWidgetHostViewAura::OnDeviceScaleFactorChanged( |
| 1880 float device_scale_factor) { | 1897 float device_scale_factor) { |
| 1881 if (!host_ || !window_->GetRootWindow()) | 1898 if (!host_ || !window_->GetRootWindow()) |
| 1882 return; | 1899 return; |
| 1883 | 1900 |
| 1884 UpdateScreenInfo(window_); | 1901 UpdateScreenInfo(window_); |
| 1885 | 1902 |
| 1903 device_scale_factor_ = device_scale_factor; |
| 1886 const gfx::Display display = gfx::Screen::GetScreenFor(window_)-> | 1904 const gfx::Display display = gfx::Screen::GetScreenFor(window_)-> |
| 1887 GetDisplayNearestWindow(window_); | 1905 GetDisplayNearestWindow(window_); |
| 1888 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); | 1906 DCHECK_EQ(device_scale_factor, display.device_scale_factor()); |
| 1889 current_cursor_.SetDisplayInfo(display); | 1907 current_cursor_.SetDisplayInfo(display); |
| 1890 SnapToPhysicalPixelBoundary(); | 1908 SnapToPhysicalPixelBoundary(); |
| 1891 } | 1909 } |
| 1892 | 1910 |
| 1893 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) { | 1911 void RenderWidgetHostViewAura::OnWindowDestroying(aura::Window* window) { |
| 1894 #if defined(OS_WIN) | 1912 #if defined(OS_WIN) |
| 1895 HWND parent = NULL; | 1913 HWND parent = NULL; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2167 window_->parent()->delegate()->OnMouseEvent(event); | 2185 window_->parent()->delegate()->OnMouseEvent(event); |
| 2168 } | 2186 } |
| 2169 | 2187 |
| 2170 if (!IsXButtonUpEvent(event)) | 2188 if (!IsXButtonUpEvent(event)) |
| 2171 event->SetHandled(); | 2189 event->SetHandled(); |
| 2172 } | 2190 } |
| 2173 | 2191 |
| 2174 uint32_t RenderWidgetHostViewAura::SurfaceIdNamespaceAtPoint( | 2192 uint32_t RenderWidgetHostViewAura::SurfaceIdNamespaceAtPoint( |
| 2175 const gfx::Point& point, | 2193 const gfx::Point& point, |
| 2176 gfx::Point* transformed_point) { | 2194 gfx::Point* transformed_point) { |
| 2177 cc::SurfaceId id = | 2195 DCHECK(device_scale_factor_ != 0.0f); |
| 2178 delegated_frame_host_->SurfaceIdAtPoint(point, transformed_point); | 2196 |
| 2197 // The surface hittest happens in device pixels, so we need to convert the |
| 2198 // |point| from DIPs to pixels before hittesting. |
| 2199 gfx::Point point_in_pixels = |
| 2200 gfx::ConvertPointToPixel(device_scale_factor_, point); |
| 2201 cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint(point_in_pixels, |
| 2202 transformed_point); |
| 2203 *transformed_point = |
| 2204 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); |
| 2205 |
| 2179 // It is possible that the renderer has not yet produced a surface, in which | 2206 // It is possible that the renderer has not yet produced a surface, in which |
| 2180 // case we return our current namespace. | 2207 // case we return our current namespace. |
| 2181 if (id.is_null()) | 2208 if (id.is_null()) |
| 2182 return GetSurfaceIdNamespace(); | 2209 return GetSurfaceIdNamespace(); |
| 2183 return cc::SurfaceIdAllocator::NamespaceForId(id); | 2210 return cc::SurfaceIdAllocator::NamespaceForId(id); |
| 2184 } | 2211 } |
| 2185 | 2212 |
| 2186 void RenderWidgetHostViewAura::ProcessMouseEvent( | 2213 void RenderWidgetHostViewAura::ProcessMouseEvent( |
| 2187 const blink::WebMouseEvent& event) { | 2214 const blink::WebMouseEvent& event) { |
| 2188 host_->ForwardMouseEvent(event); | 2215 host_->ForwardMouseEvent(event); |
| (...skipping 724 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2913 | 2940 |
| 2914 //////////////////////////////////////////////////////////////////////////////// | 2941 //////////////////////////////////////////////////////////////////////////////// |
| 2915 // RenderWidgetHostViewBase, public: | 2942 // RenderWidgetHostViewBase, public: |
| 2916 | 2943 |
| 2917 // static | 2944 // static |
| 2918 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { | 2945 void RenderWidgetHostViewBase::GetDefaultScreenInfo(WebScreenInfo* results) { |
| 2919 GetScreenInfoForWindow(results, NULL); | 2946 GetScreenInfoForWindow(results, NULL); |
| 2920 } | 2947 } |
| 2921 | 2948 |
| 2922 } // namespace content | 2949 } // namespace content |
| OLD | NEW |