| 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 <Carbon/Carbon.h> | 7 #import <Carbon/Carbon.h> |
| 8 #import <objc/runtime.h> | 8 #import <objc/runtime.h> |
| 9 #include <OpenGL/gl.h> | 9 #include <OpenGL/gl.h> |
| 10 #include <QuartzCore/QuartzCore.h> | 10 #include <QuartzCore/QuartzCore.h> |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 #include "media/base/video_frame.h" | 68 #include "media/base/video_frame.h" |
| 69 #include "skia/ext/platform_canvas.h" | 69 #include "skia/ext/platform_canvas.h" |
| 70 #include "skia/ext/skia_utils_mac.h" | 70 #include "skia/ext/skia_utils_mac.h" |
| 71 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 71 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 72 #import "ui/base/clipboard/clipboard_util_mac.h" | 72 #import "ui/base/clipboard/clipboard_util_mac.h" |
| 73 #include "ui/base/cocoa/animation_utils.h" | 73 #include "ui/base/cocoa/animation_utils.h" |
| 74 #import "ui/base/cocoa/appkit_utils.h" | 74 #import "ui/base/cocoa/appkit_utils.h" |
| 75 #include "ui/base/cocoa/cocoa_base_utils.h" | 75 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 76 #import "ui/base/cocoa/fullscreen_window_manager.h" | 76 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 77 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 77 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 78 #include "ui/base/layout.h" | |
| 79 #include "ui/compositor/compositor.h" | 78 #include "ui/compositor/compositor.h" |
| 80 #include "ui/compositor/layer.h" | 79 #include "ui/compositor/layer.h" |
| 81 #include "ui/display/display.h" | 80 #include "ui/display/display.h" |
| 82 #include "ui/display/screen.h" | 81 #include "ui/display/screen.h" |
| 83 #include "ui/events/base_event_utils.h" | 82 #include "ui/events/base_event_utils.h" |
| 84 #include "ui/events/event_utils.h" | 83 #include "ui/events/event_utils.h" |
| 85 #include "ui/events/keycodes/keyboard_codes.h" | 84 #include "ui/events/keycodes/keyboard_codes.h" |
| 86 #include "ui/gfx/geometry/dip_util.h" | 85 #include "ui/gfx/geometry/dip_util.h" |
| 87 #include "ui/gfx/geometry/point.h" | 86 #include "ui/gfx/geometry/point.h" |
| 88 #include "ui/gfx/geometry/rect_conversions.h" | 87 #include "ui/gfx/geometry/rect_conversions.h" |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 pepper_fullscreen_window_.reset(); | 681 pepper_fullscreen_window_.reset(); |
| 683 } | 682 } |
| 684 | 683 |
| 685 int RenderWidgetHostViewMac::window_number() const { | 684 int RenderWidgetHostViewMac::window_number() const { |
| 686 NSWindow* window = [cocoa_view_ window]; | 685 NSWindow* window = [cocoa_view_ window]; |
| 687 if (!window) | 686 if (!window) |
| 688 return -1; | 687 return -1; |
| 689 return [window windowNumber]; | 688 return [window windowNumber]; |
| 690 } | 689 } |
| 691 | 690 |
| 692 float RenderWidgetHostViewMac::ViewScaleFactor() const { | |
| 693 return ui::GetScaleFactorForNativeView(cocoa_view_); | |
| 694 } | |
| 695 | |
| 696 void RenderWidgetHostViewMac::UpdateDisplayLink() { | 691 void RenderWidgetHostViewMac::UpdateDisplayLink() { |
| 697 static bool is_vsync_disabled = | 692 static bool is_vsync_disabled = |
| 698 base::CommandLine::ForCurrentProcess()->HasSwitch( | 693 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 699 switches::kDisableGpuVsync); | 694 switches::kDisableGpuVsync); |
| 700 if (is_vsync_disabled) | 695 if (is_vsync_disabled) |
| 701 return; | 696 return; |
| 702 | 697 |
| 703 NSScreen* screen = [[cocoa_view_ window] screen]; | 698 NSScreen* screen = [[cocoa_view_ window] screen]; |
| 704 NSDictionary* screen_description = [screen deviceDescription]; | 699 NSDictionary* screen_description = [screen deviceDescription]; |
| 705 NSNumber* screen_number = [screen_description objectForKey:@"NSScreenNumber"]; | 700 NSNumber* screen_number = [screen_description objectForKey:@"NSScreenNumber"]; |
| (...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1516 cc::FrameSinkId RenderWidgetHostViewMac::GetFrameSinkId() { | 1511 cc::FrameSinkId RenderWidgetHostViewMac::GetFrameSinkId() { |
| 1517 return browser_compositor_->GetDelegatedFrameHost()->GetFrameSinkId(); | 1512 return browser_compositor_->GetDelegatedFrameHost()->GetFrameSinkId(); |
| 1518 } | 1513 } |
| 1519 | 1514 |
| 1520 cc::FrameSinkId RenderWidgetHostViewMac::FrameSinkIdAtPoint( | 1515 cc::FrameSinkId RenderWidgetHostViewMac::FrameSinkIdAtPoint( |
| 1521 cc::SurfaceHittestDelegate* delegate, | 1516 cc::SurfaceHittestDelegate* delegate, |
| 1522 const gfx::Point& point, | 1517 const gfx::Point& point, |
| 1523 gfx::Point* transformed_point) { | 1518 gfx::Point* transformed_point) { |
| 1524 // The surface hittest happens in device pixels, so we need to convert the | 1519 // The surface hittest happens in device pixels, so we need to convert the |
| 1525 // |point| from DIPs to pixels before hittesting. | 1520 // |point| from DIPs to pixels before hittesting. |
| 1526 float scale_factor = display::Screen::GetScreen() | 1521 float scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_); |
| 1527 ->GetDisplayNearestWindow(cocoa_view_) | |
| 1528 .device_scale_factor(); | |
| 1529 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1522 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1530 cc::SurfaceId id = | 1523 cc::SurfaceId id = |
| 1531 browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint( | 1524 browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint( |
| 1532 delegate, point_in_pixels, transformed_point); | 1525 delegate, point_in_pixels, transformed_point); |
| 1533 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1526 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1534 | 1527 |
| 1535 // It is possible that the renderer has not yet produced a surface, in which | 1528 // It is possible that the renderer has not yet produced a surface, in which |
| 1536 // case we return our current namespace. | 1529 // case we return our current namespace. |
| 1537 if (!id.is_valid()) | 1530 if (!id.is_valid()) |
| 1538 return GetFrameSinkId(); | 1531 return GetFrameSinkId(); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1573 const ui::LatencyInfo& latency) { | 1566 const ui::LatencyInfo& latency) { |
| 1574 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); | 1567 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); |
| 1575 } | 1568 } |
| 1576 | 1569 |
| 1577 bool RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( | 1570 bool RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( |
| 1578 const gfx::Point& point, | 1571 const gfx::Point& point, |
| 1579 const cc::SurfaceId& original_surface, | 1572 const cc::SurfaceId& original_surface, |
| 1580 gfx::Point* transformed_point) { | 1573 gfx::Point* transformed_point) { |
| 1581 // Transformations use physical pixels rather than DIP, so conversion | 1574 // Transformations use physical pixels rather than DIP, so conversion |
| 1582 // is necessary. | 1575 // is necessary. |
| 1583 float scale_factor = display::Screen::GetScreen() | 1576 float scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_); |
| 1584 ->GetDisplayNearestWindow(cocoa_view_) | |
| 1585 .device_scale_factor(); | |
| 1586 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | 1577 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); |
| 1587 if (!browser_compositor_->GetDelegatedFrameHost() | 1578 if (!browser_compositor_->GetDelegatedFrameHost() |
| 1588 ->TransformPointToLocalCoordSpace(point_in_pixels, original_surface, | 1579 ->TransformPointToLocalCoordSpace(point_in_pixels, original_surface, |
| 1589 transformed_point)) | 1580 transformed_point)) |
| 1590 return false; | 1581 return false; |
| 1591 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1582 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); |
| 1592 return true; | 1583 return true; |
| 1593 } | 1584 } |
| 1594 | 1585 |
| 1595 bool RenderWidgetHostViewMac::TransformPointToCoordSpaceForView( | 1586 bool RenderWidgetHostViewMac::TransformPointToCoordSpaceForView( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1720 | 1711 |
| 1721 void RenderWidgetHostViewMac::OnDisplayAdded(const display::Display& display) {} | 1712 void RenderWidgetHostViewMac::OnDisplayAdded(const display::Display& display) {} |
| 1722 | 1713 |
| 1723 void RenderWidgetHostViewMac::OnDisplayRemoved( | 1714 void RenderWidgetHostViewMac::OnDisplayRemoved( |
| 1724 const display::Display& display) {} | 1715 const display::Display& display) {} |
| 1725 | 1716 |
| 1726 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( | 1717 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
| 1727 const display::Display& display, | 1718 const display::Display& display, |
| 1728 uint32_t changed_metrics) { | 1719 uint32_t changed_metrics) { |
| 1729 display::Screen* screen = display::Screen::GetScreen(); | 1720 display::Screen* screen = display::Screen::GetScreen(); |
| 1730 if (display.id() != screen->GetDisplayNearestWindow(cocoa_view_).id()) | 1721 if (display.id() != screen->GetDisplayNearestView(cocoa_view_).id()) |
| 1731 return; | 1722 return; |
| 1732 | 1723 |
| 1733 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { | 1724 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { |
| 1734 RenderWidgetHostImpl* host = | 1725 RenderWidgetHostImpl* host = |
| 1735 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 1726 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
| 1736 if (host && host->delegate()) | 1727 if (host && host->delegate()) |
| 1737 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); | 1728 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); |
| 1738 } | 1729 } |
| 1739 | 1730 |
| 1740 UpdateScreenInfo(cocoa_view_); | 1731 UpdateScreenInfo(cocoa_view_); |
| (...skipping 1751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3492 | 3483 |
| 3493 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3484 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3494 // regions that are not draggable. (See ControlRegionView in | 3485 // regions that are not draggable. (See ControlRegionView in |
| 3495 // native_app_window_cocoa.mm). This requires the render host view to be | 3486 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3496 // draggable by default. | 3487 // draggable by default. |
| 3497 - (BOOL)mouseDownCanMoveWindow { | 3488 - (BOOL)mouseDownCanMoveWindow { |
| 3498 return YES; | 3489 return YES; |
| 3499 } | 3490 } |
| 3500 | 3491 |
| 3501 @end | 3492 @end |
| OLD | NEW |