Chromium Code Reviews| 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 379 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 468 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; | 467 [background_layer_ setBackgroundColor:CGColorGetConstantColor(kCGColorWhite)]; |
| 469 [cocoa_view_ setLayer:background_layer_]; | 468 [cocoa_view_ setLayer:background_layer_]; |
| 470 [cocoa_view_ setWantsLayer:YES]; | 469 [cocoa_view_ setWantsLayer:YES]; |
| 471 | 470 |
| 472 cc::FrameSinkId frame_sink_id = | 471 cc::FrameSinkId frame_sink_id = |
| 473 render_widget_host_->AllocateFrameSinkId(is_guest_view_hack_); | 472 render_widget_host_->AllocateFrameSinkId(is_guest_view_hack_); |
| 474 browser_compositor_.reset( | 473 browser_compositor_.reset( |
| 475 new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(), | 474 new BrowserCompositorMac(this, this, render_widget_host_->is_hidden(), |
| 476 [cocoa_view_ window], frame_sink_id)); | 475 [cocoa_view_ window], frame_sink_id)); |
| 477 | 476 |
| 478 display::Screen::GetScreen()->AddObserver(this); | 477 display::Screen* screen = display::Screen::GetScreen(); |
| 478 device_scale_factor_ = | |
| 479 screen->GetDisplayNearestWindow(cocoa_view_).device_scale_factor(); | |
| 480 screen->AddObserver(this); | |
| 479 | 481 |
| 480 if (!is_guest_view_hack_) | 482 if (!is_guest_view_hack_) |
| 481 render_widget_host_->SetView(this); | 483 render_widget_host_->SetView(this); |
| 482 | 484 |
| 483 // Let the page-level input event router know about our surface ID | 485 // Let the page-level input event router know about our surface ID |
| 484 // namespace for surface-based hit testing. | 486 // namespace for surface-based hit testing. |
| 485 if (render_widget_host_->delegate() && | 487 if (render_widget_host_->delegate() && |
| 486 render_widget_host_->delegate()->GetInputEventRouter()) { | 488 render_widget_host_->delegate()->GetInputEventRouter()) { |
| 487 render_widget_host_->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner( | 489 render_widget_host_->delegate()->GetInputEventRouter()->AddFrameSinkIdOwner( |
| 488 GetFrameSinkId(), this); | 490 GetFrameSinkId(), this); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 682 pepper_fullscreen_window_.reset(); | 684 pepper_fullscreen_window_.reset(); |
| 683 } | 685 } |
| 684 | 686 |
| 685 int RenderWidgetHostViewMac::window_number() const { | 687 int RenderWidgetHostViewMac::window_number() const { |
| 686 NSWindow* window = [cocoa_view_ window]; | 688 NSWindow* window = [cocoa_view_ window]; |
| 687 if (!window) | 689 if (!window) |
| 688 return -1; | 690 return -1; |
| 689 return [window windowNumber]; | 691 return [window windowNumber]; |
| 690 } | 692 } |
| 691 | 693 |
| 692 float RenderWidgetHostViewMac::ViewScaleFactor() const { | |
| 693 return ui::GetScaleFactorForNativeView(cocoa_view_); | |
| 694 } | |
| 695 | |
| 696 void RenderWidgetHostViewMac::UpdateDisplayLink() { | 694 void RenderWidgetHostViewMac::UpdateDisplayLink() { |
| 697 static bool is_vsync_disabled = | 695 static bool is_vsync_disabled = |
| 698 base::CommandLine::ForCurrentProcess()->HasSwitch( | 696 base::CommandLine::ForCurrentProcess()->HasSwitch( |
| 699 switches::kDisableGpuVsync); | 697 switches::kDisableGpuVsync); |
| 700 if (is_vsync_disabled) | 698 if (is_vsync_disabled) |
| 701 return; | 699 return; |
| 702 | 700 |
| 703 NSScreen* screen = [[cocoa_view_ window] screen]; | 701 NSScreen* screen = [[cocoa_view_ window] screen]; |
| 704 NSDictionary* screen_description = [screen deviceDescription]; | 702 NSDictionary* screen_description = [screen deviceDescription]; |
| 705 NSNumber* screen_number = [screen_description objectForKey:@"NSScreenNumber"]; | 703 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() { | 1514 cc::FrameSinkId RenderWidgetHostViewMac::GetFrameSinkId() { |
| 1517 return browser_compositor_->GetDelegatedFrameHost()->GetFrameSinkId(); | 1515 return browser_compositor_->GetDelegatedFrameHost()->GetFrameSinkId(); |
| 1518 } | 1516 } |
| 1519 | 1517 |
| 1520 cc::FrameSinkId RenderWidgetHostViewMac::FrameSinkIdAtPoint( | 1518 cc::FrameSinkId RenderWidgetHostViewMac::FrameSinkIdAtPoint( |
| 1521 cc::SurfaceHittestDelegate* delegate, | 1519 cc::SurfaceHittestDelegate* delegate, |
| 1522 const gfx::Point& point, | 1520 const gfx::Point& point, |
| 1523 gfx::Point* transformed_point) { | 1521 gfx::Point* transformed_point) { |
| 1524 // The surface hittest happens in device pixels, so we need to convert the | 1522 // The surface hittest happens in device pixels, so we need to convert the |
| 1525 // |point| from DIPs to pixels before hittesting. | 1523 // |point| from DIPs to pixels before hittesting. |
| 1526 float scale_factor = display::Screen::GetScreen() | 1524 gfx::Point point_in_pixels = |
| 1527 ->GetDisplayNearestWindow(cocoa_view_) | 1525 gfx::ConvertPointToPixel(device_scale_factor_, point); |
| 1528 .device_scale_factor(); | |
| 1529 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | |
| 1530 cc::SurfaceId id = | 1526 cc::SurfaceId id = |
| 1531 browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint( | 1527 browser_compositor_->GetDelegatedFrameHost()->SurfaceIdAtPoint( |
| 1532 delegate, point_in_pixels, transformed_point); | 1528 delegate, point_in_pixels, transformed_point); |
| 1533 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1529 *transformed_point = |
| 1530 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | |
| 1534 | 1531 |
| 1535 // It is possible that the renderer has not yet produced a surface, in which | 1532 // It is possible that the renderer has not yet produced a surface, in which |
| 1536 // case we return our current namespace. | 1533 // case we return our current namespace. |
| 1537 if (!id.is_valid()) | 1534 if (!id.is_valid()) |
| 1538 return GetFrameSinkId(); | 1535 return GetFrameSinkId(); |
| 1539 return id.frame_sink_id(); | 1536 return id.frame_sink_id(); |
| 1540 } | 1537 } |
| 1541 | 1538 |
| 1542 bool RenderWidgetHostViewMac::ShouldRouteEvent( | 1539 bool RenderWidgetHostViewMac::ShouldRouteEvent( |
| 1543 const WebInputEvent& event) const { | 1540 const WebInputEvent& event) const { |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 1573 const ui::LatencyInfo& latency) { | 1570 const ui::LatencyInfo& latency) { |
| 1574 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); | 1571 render_widget_host_->ForwardGestureEventWithLatencyInfo(event, latency); |
| 1575 } | 1572 } |
| 1576 | 1573 |
| 1577 bool RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( | 1574 bool RenderWidgetHostViewMac::TransformPointToLocalCoordSpace( |
| 1578 const gfx::Point& point, | 1575 const gfx::Point& point, |
| 1579 const cc::SurfaceId& original_surface, | 1576 const cc::SurfaceId& original_surface, |
| 1580 gfx::Point* transformed_point) { | 1577 gfx::Point* transformed_point) { |
| 1581 // Transformations use physical pixels rather than DIP, so conversion | 1578 // Transformations use physical pixels rather than DIP, so conversion |
| 1582 // is necessary. | 1579 // is necessary. |
| 1583 float scale_factor = display::Screen::GetScreen() | 1580 gfx::Point point_in_pixels = |
| 1584 ->GetDisplayNearestWindow(cocoa_view_) | 1581 gfx::ConvertPointToPixel(device_scale_factor_, point); |
| 1585 .device_scale_factor(); | |
| 1586 gfx::Point point_in_pixels = gfx::ConvertPointToPixel(scale_factor, point); | |
| 1587 if (!browser_compositor_->GetDelegatedFrameHost() | 1582 if (!browser_compositor_->GetDelegatedFrameHost() |
| 1588 ->TransformPointToLocalCoordSpace(point_in_pixels, original_surface, | 1583 ->TransformPointToLocalCoordSpace(point_in_pixels, original_surface, |
| 1589 transformed_point)) | 1584 transformed_point)) |
| 1590 return false; | 1585 return false; |
| 1591 *transformed_point = gfx::ConvertPointToDIP(scale_factor, *transformed_point); | 1586 *transformed_point = |
| 1587 gfx::ConvertPointToDIP(device_scale_factor_, *transformed_point); | |
| 1592 return true; | 1588 return true; |
| 1593 } | 1589 } |
| 1594 | 1590 |
| 1595 bool RenderWidgetHostViewMac::TransformPointToCoordSpaceForView( | 1591 bool RenderWidgetHostViewMac::TransformPointToCoordSpaceForView( |
| 1596 const gfx::Point& point, | 1592 const gfx::Point& point, |
| 1597 RenderWidgetHostViewBase* target_view, | 1593 RenderWidgetHostViewBase* target_view, |
| 1598 gfx::Point* transformed_point) { | 1594 gfx::Point* transformed_point) { |
| 1599 if (target_view == this) { | 1595 if (target_view == this) { |
| 1600 *transformed_point = point; | 1596 *transformed_point = point; |
| 1601 return true; | 1597 return true; |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1726 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( | 1722 void RenderWidgetHostViewMac::OnDisplayMetricsChanged( |
| 1727 const display::Display& display, | 1723 const display::Display& display, |
| 1728 uint32_t changed_metrics) { | 1724 uint32_t changed_metrics) { |
| 1729 display::Screen* screen = display::Screen::GetScreen(); | 1725 display::Screen* screen = display::Screen::GetScreen(); |
| 1730 if (display.id() != screen->GetDisplayNearestWindow(cocoa_view_).id()) | 1726 if (display.id() != screen->GetDisplayNearestWindow(cocoa_view_).id()) |
| 1731 return; | 1727 return; |
| 1732 | 1728 |
| 1733 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { | 1729 if (changed_metrics & DisplayObserver::DISPLAY_METRIC_DEVICE_SCALE_FACTOR) { |
| 1734 RenderWidgetHostImpl* host = | 1730 RenderWidgetHostImpl* host = |
| 1735 RenderWidgetHostImpl::From(GetRenderWidgetHost()); | 1731 RenderWidgetHostImpl::From(GetRenderWidgetHost()); |
| 1732 device_scale_factor_ = display.device_scale_factor(); | |
|
tapted
2017/03/13 00:02:33
This isn't quite the same. OnDisplayMetricsChanged
Jinsuk Kim
2017/03/13 00:25:01
Reverted the change. Removed an unused method only
| |
| 1736 if (host && host->delegate()) | 1733 if (host && host->delegate()) |
| 1737 host->delegate()->UpdateDeviceScaleFactor(display.device_scale_factor()); | 1734 host->delegate()->UpdateDeviceScaleFactor(device_scale_factor_); |
| 1738 } | 1735 } |
| 1739 | 1736 |
| 1740 UpdateScreenInfo(cocoa_view_); | 1737 UpdateScreenInfo(cocoa_view_); |
| 1741 } | 1738 } |
| 1742 | 1739 |
| 1743 } // namespace content | 1740 } // namespace content |
| 1744 | 1741 |
| 1745 // RenderWidgetHostViewCocoa --------------------------------------------------- | 1742 // RenderWidgetHostViewCocoa --------------------------------------------------- |
| 1746 | 1743 |
| 1747 @implementation RenderWidgetHostViewCocoa | 1744 @implementation RenderWidgetHostViewCocoa |
| (...skipping 1744 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3492 | 3489 |
| 3493 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3490 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3494 // regions that are not draggable. (See ControlRegionView in | 3491 // regions that are not draggable. (See ControlRegionView in |
| 3495 // native_app_window_cocoa.mm). This requires the render host view to be | 3492 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3496 // draggable by default. | 3493 // draggable by default. |
| 3497 - (BOOL)mouseDownCanMoveWindow { | 3494 - (BOOL)mouseDownCanMoveWindow { |
| 3498 return YES; | 3495 return YES; |
| 3499 } | 3496 } |
| 3500 | 3497 |
| 3501 @end | 3498 @end |
| OLD | NEW |