| 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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> | 7 #import <objc/runtime.h> |
| 8 #include <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 72 #include "third_party/WebKit/public/web/WebInputEvent.h" | 72 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 73 #import "ui/base/clipboard/clipboard_util_mac.h" | 73 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 74 #include "ui/base/cocoa/animation_utils.h" | 74 #include "ui/base/cocoa/animation_utils.h" |
| 75 #import "ui/base/cocoa/appkit_utils.h" | 75 #import "ui/base/cocoa/appkit_utils.h" |
| 76 #include "ui/base/cocoa/cocoa_base_utils.h" | 76 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 77 #import "ui/base/cocoa/fullscreen_window_manager.h" | 77 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 78 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 78 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 79 #include "ui/base/layout.h" | 79 #include "ui/base/layout.h" |
| 80 #include "ui/compositor/compositor.h" | 80 #include "ui/compositor/compositor.h" |
| 81 #include "ui/compositor/layer.h" | 81 #include "ui/compositor/layer.h" |
| 82 #include "ui/display/display.h" |
| 83 #include "ui/display/screen.h" |
| 82 #include "ui/events/keycodes/keyboard_codes.h" | 84 #include "ui/events/keycodes/keyboard_codes.h" |
| 83 #include "ui/gfx/color_profile.h" | 85 #include "ui/gfx/color_profile.h" |
| 84 #include "ui/gfx/display.h" | |
| 85 #include "ui/gfx/geometry/dip_util.h" | 86 #include "ui/gfx/geometry/dip_util.h" |
| 86 #include "ui/gfx/geometry/point.h" | 87 #include "ui/gfx/geometry/point.h" |
| 87 #include "ui/gfx/geometry/rect_conversions.h" | 88 #include "ui/gfx/geometry/rect_conversions.h" |
| 88 #include "ui/gfx/geometry/size_conversions.h" | 89 #include "ui/gfx/geometry/size_conversions.h" |
| 89 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" | 90 #include "ui/gfx/scoped_ns_graphics_context_save_gstate_mac.h" |
| 90 #include "ui/gfx/screen.h" | |
| 91 #include "ui/gl/gl_switches.h" | 91 #include "ui/gl/gl_switches.h" |
| 92 | 92 |
| 93 using content::BrowserAccessibility; | 93 using content::BrowserAccessibility; |
| 94 using content::BrowserAccessibilityManager; | 94 using content::BrowserAccessibilityManager; |
| 95 using content::EditCommand; | 95 using content::EditCommand; |
| 96 using content::FrameTreeNode; | 96 using content::FrameTreeNode; |
| 97 using content::NativeWebKeyboardEvent; | 97 using content::NativeWebKeyboardEvent; |
| 98 using content::RenderFrameHost; | 98 using content::RenderFrameHost; |
| 99 using content::RenderViewHost; | 99 using content::RenderViewHost; |
| 100 using content::RenderViewHostImpl; | 100 using content::RenderViewHostImpl; |
| (...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 NSWindow* ancestor_window = [enclosing_window parentWindow]; | 372 NSWindow* ancestor_window = [enclosing_window parentWindow]; |
| 373 if (ancestor_window && (NSWidth([enclosing_window frame]) == | 373 if (ancestor_window && (NSWidth([enclosing_window frame]) == |
| 374 NSWidth([ancestor_window frame]))) { | 374 NSWidth([ancestor_window frame]))) { |
| 375 enclosing_window = ancestor_window; | 375 enclosing_window = ancestor_window; |
| 376 } | 376 } |
| 377 | 377 |
| 378 return enclosing_window; | 378 return enclosing_window; |
| 379 } | 379 } |
| 380 | 380 |
| 381 blink::WebScreenInfo GetWebScreenInfo(NSView* view) { | 381 blink::WebScreenInfo GetWebScreenInfo(NSView* view) { |
| 382 gfx::Display display = | 382 display::Display display = |
| 383 gfx::Screen::GetScreen()->GetDisplayNearestWindow(view); | 383 display::Screen::GetScreen()->GetDisplayNearestWindow(view); |
| 384 | 384 |
| 385 NSScreen* screen = [NSScreen deepestScreen]; | 385 NSScreen* screen = [NSScreen deepestScreen]; |
| 386 | 386 |
| 387 blink::WebScreenInfo results; | 387 blink::WebScreenInfo results; |
| 388 | 388 |
| 389 results.deviceScaleFactor = static_cast<int>(display.device_scale_factor()); | 389 results.deviceScaleFactor = static_cast<int>(display.device_scale_factor()); |
| 390 results.depth = NSBitsPerPixelFromDepth([screen depth]); | 390 results.depth = NSBitsPerPixelFromDepth([screen depth]); |
| 391 results.depthPerComponent = NSBitsPerSampleFromDepth([screen depth]); | 391 results.depthPerComponent = NSBitsPerSampleFromDepth([screen depth]); |
| 392 results.isMonochrome = | 392 results.isMonochrome = |
| 393 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel; | 393 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel; |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 557 background_layer_.reset([[CALayer alloc] init]); | 557 background_layer_.reset([[CALayer alloc] init]); |
| 558 // Set the default color to be white. This is the wrong thing to do, but many | 558 // Set the default color to be white. This is the wrong thing to do, but many |
| 559 // UI components expect this view to be opaque. | 559 // UI components expect this view to be opaque. |
| 560 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 560 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| 561 [cocoa_view_ setLayer:background_layer_]; | 561 [cocoa_view_ setLayer:background_layer_]; |
| 562 [cocoa_view_ setWantsLayer:YES]; | 562 [cocoa_view_ setWantsLayer:YES]; |
| 563 | 563 |
| 564 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); | 564 root_layer_.reset(new ui::Layer(ui::LAYER_SOLID_COLOR)); |
| 565 delegated_frame_host_.reset(new DelegatedFrameHost(this)); | 565 delegated_frame_host_.reset(new DelegatedFrameHost(this)); |
| 566 | 566 |
| 567 gfx::Screen::GetScreen()->AddObserver(this); | 567 display::Screen::GetScreen()->AddObserver(this); |
| 568 | 568 |
| 569 if (!is_guest_view_hack_) | 569 if (!is_guest_view_hack_) |
| 570 render_widget_host_->SetView(this); | 570 render_widget_host_->SetView(this); |
| 571 | 571 |
| 572 // Let the page-level input event router know about our surface ID | 572 // Let the page-level input event router know about our surface ID |
| 573 // namespace for surface-based hit testing. | 573 // namespace for surface-based hit testing. |
| 574 if (render_widget_host_->delegate() && | 574 if (render_widget_host_->delegate() && |
| 575 render_widget_host_->delegate()->GetInputEventRouter()) { | 575 render_widget_host_->delegate()->GetInputEventRouter()) { |
| 576 render_widget_host_->delegate() | 576 render_widget_host_->delegate() |
| 577 ->GetInputEventRouter() | 577 ->GetInputEventRouter() |
| 578 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); | 578 ->AddSurfaceIdNamespaceOwner(GetSurfaceIdNamespace(), this); |
| 579 } | 579 } |
| 580 } | 580 } |
| 581 | 581 |
| 582 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 582 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 583 gfx::Screen::GetScreen()->RemoveObserver(this); | 583 display::Screen::GetScreen()->RemoveObserver(this); |
| 584 | 584 |
| 585 // This is being called from |cocoa_view_|'s destructor, so invalidate the | 585 // This is being called from |cocoa_view_|'s destructor, so invalidate the |
| 586 // pointer. | 586 // pointer. |
| 587 cocoa_view_ = nil; | 587 cocoa_view_ = nil; |
| 588 | 588 |
| 589 UnlockMouse(); | 589 UnlockMouse(); |
| 590 | 590 |
| 591 // Ensure that the browser compositor is destroyed in a safe order. | 591 // Ensure that the browser compositor is destroyed in a safe order. |
| 592 ShutdownBrowserCompositor(); | 592 ShutdownBrowserCompositor(); |
| 593 | 593 |
| (...skipping 983 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1577 DCHECK(delegated_frame_host_); | 1577 DCHECK(delegated_frame_host_); |
| 1578 return delegated_frame_host_->GetSurfaceIdNamespace(); | 1578 return delegated_frame_host_->GetSurfaceIdNamespace(); |
| 1579 } | 1579 } |
| 1580 | 1580 |
| 1581 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint( | 1581 uint32_t RenderWidgetHostViewMac::SurfaceIdNamespaceAtPoint( |
| 1582 cc::SurfaceHittestDelegate* delegate, | 1582 cc::SurfaceHittestDelegate* delegate, |
| 1583 const gfx::Point& point, | 1583 const gfx::Point& point, |
| 1584 gfx::Point* transformed_point) { | 1584 gfx::Point* transformed_point) { |
| 1585 // The surface hittest happens in device pixels, so we need to convert the | 1585 // The surface hittest happens in device pixels, so we need to convert the |
| 1586 // |point| from DIPs to pixels before hittesting. | 1586 // |point| from DIPs to pixels before hittesting. |
| 1587 float scale_factor = gfx::Screen::GetScreen() | 1587 float scale_factor = display::Screen::GetScreen() |
| 1588 ->GetDisplayNearestWindow(cocoa_view_) | 1588 ->GetDisplayNearestWindow(cocoa_view_) |
| 1589 .device_scale_factor(); | 1589 .device_scale_factor(); |
| 1590 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1590 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1591 cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint( | 1591 cc::SurfaceId id = delegated_frame_host_->SurfaceIdAtPoint( |
| 1592 delegate, point_in_pixels, transformed_point); | 1592 delegate, point_in_pixels, transformed_point); |
| 1593 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1593 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1594 | 1594 |
| 1595 // It is possible that the renderer has not yet produced a surface, in which | 1595 // It is possible that the renderer has not yet produced a surface, in which |
| 1596 // case we return our current namespace. | 1596 // case we return our current namespace. |
| 1597 if (id.is_null()) | 1597 if (id.is_null()) |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1631 const ui::LatencyInfo& latency) { | 1631 const ui::LatencyInfo& latency) { |
| 1632 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); | 1632 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); |
| 1633 } | 1633 } |
| 1634 | 1634 |
| 1635 void RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( | 1635 void RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( |
| 1636 const gfx::Point& point, | 1636 const gfx::Point& point, |
| 1637 cc::SurfaceId original_surface, | 1637 cc::SurfaceId original_surface, |
| 1638 gfx::Point* transformed_point) { | 1638 gfx::Point* transformed_point) { |
| 1639 // Transformations use physical pixels rather than DIP, so conversion | 1639 // Transformations use physical pixels rather than DIP, so conversion |
| 1640 // is necessary. | 1640 // is necessary. |
| 1641 float scale_factor = gfx::Screen::GetScreen() | 1641 float scale_factor = display::Screen::GetScreen() |
| 1642 ->GetDisplayNearestWindow(cocoa_view_) | 1642 ->GetDisplayNearestWindow(cocoa_view_) |
| 1643 .device_scale_factor(); | 1643 .device_scale_factor(); |
| 1644 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1644 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1645 delegated_frame_host_->TransformPointToLocalCoordSpace( | 1645 delegated_frame_host_->TransformPointToLocalCoordSpace( |
| 1646 point_in_pixels, original_surface, transformed_point); | 1646 point_in_pixels, original_surface, transformed_point); |
| 1647 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1647 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1648 } | 1648 } |
| 1649 | 1649 |
| 1650 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { | 1650 bool RenderWidgetHostViewMac::Send(IPC::Message* message) { |
| 1651 if (render_widget_host_) | 1651 if (render_widget_host_) |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1753 // Pausing for one view prevents others from receiving frames. | 1753 // Pausing for one view prevents others from receiving frames. |
| 1754 // This may lead to large delays, causing overlaps. See crbug.com/352020. | 1754 // This may lead to large delays, causing overlaps. See crbug.com/352020. |
| 1755 if (!allow_pause_for_resize_or_repaint_) | 1755 if (!allow_pause_for_resize_or_repaint_) |
| 1756 return; | 1756 return; |
| 1757 | 1757 |
| 1758 // Wait for a frame of the right size to come in. | 1758 // Wait for a frame of the right size to come in. |
| 1759 render_widget_host_->PauseForPendingResizeOrRepaints(); | 1759 render_widget_host_->PauseForPendingResizeOrRepaints(); |
| 1760 } | 1760 } |
| 1761 | 1761 |
| 1762 //////////////////////////////////////////////////////////////////////////////// | 1762 //////////////////////////////////////////////////////////////////////////////// |
| 1763 // gfx::DisplayObserver, public: | 1763 // display::DisplayObserver, public: |
| 1764 | 1764 |
| 1765 void RenderWidgetHostViewMac::OnDisplayAdded(const gfx::Display& display) { | 1765 void RenderWidgetHostViewMac::OnDisplayAdded(const display::Display& display) {} |
| 1766 } | |
| 1767 | 1766 |
| 1768 void RenderWidgetHostViewMac::OnDisplayRemoved(const gfx::Display& display) { | 1767 void RenderWidgetHostViewMac::OnDisplayRemoved( |
| 1769 } | 1768 const display::Display& display) {} |
| 1770 | 1769 |
| 1771 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( | 1770 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
| 1772 const gfx::Display& display, uint32_t metrics) { | 1771 const display::Display& display, |
| 1773 gfx::Screen* screen = gfx::Screen::GetScreen(); | 1772 uint32_t metrics) { |
| 1773 display::Screen* screen = display::Screen::GetScreen(); |
| 1774 if (display.id() != screen->GetDisplayNearestWindow(cocoa_view_).id()) | 1774 if (display.id() != screen->GetDisplayNearestWindow(cocoa_view_).id()) |
| 1775 return; | 1775 return; |
| 1776 | 1776 |
| 1777 UpdateScreenInfo(cocoa_view_); | 1777 UpdateScreenInfo(cocoa_view_); |
| 1778 } | 1778 } |
| 1779 | 1779 |
| 1780 } // namespace content | 1780 } // namespace content |
| 1781 | 1781 |
| 1782 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1782 // RenderWidgetHostViewCocoa --------------------------------------------------- |
| 1783 | 1783 |
| (...skipping 1618 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3402 | 3402 |
| 3403 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3403 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3404 // regions that are not draggable. (See ControlRegionView in | 3404 // regions that are not draggable. (See ControlRegionView in |
| 3405 // native_app_window_cocoa.mm). This requires the render host view to be | 3405 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3406 // draggable by default. | 3406 // draggable by default. |
| 3407 - (BOOL)mouseDownCanMoveWindow { | 3407 - (BOOL)mouseDownCanMoveWindow { |
| 3408 return YES; | 3408 return YES; |
| 3409 } | 3409 } |
| 3410 | 3410 |
| 3411 @end | 3411 @end |
| OLD | NEW |