| 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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #import "content/browser/web_contents/web_contents_view_mac.h" | 7 #import "content/browser/web_contents/web_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 #include "ui/display/screen.h" | 33 #include "ui/display/screen.h" |
| 34 #include "ui/gfx/image/image_skia_util_mac.h" | 34 #include "ui/gfx/image/image_skia_util_mac.h" |
| 35 | 35 |
| 36 using blink::WebDragOperation; | 36 using blink::WebDragOperation; |
| 37 using blink::WebDragOperationsMask; | 37 using blink::WebDragOperationsMask; |
| 38 using content::DropData; | 38 using content::DropData; |
| 39 using content::PopupMenuHelper; | 39 using content::PopupMenuHelper; |
| 40 using content::RenderViewHostFactory; | 40 using content::RenderViewHostFactory; |
| 41 using content::RenderWidgetHostView; | 41 using content::RenderWidgetHostView; |
| 42 using content::RenderWidgetHostViewMac; | 42 using content::RenderWidgetHostViewMac; |
| 43 using content::ScreenInfo; |
| 43 using content::WebContents; | 44 using content::WebContents; |
| 44 using content::WebContentsImpl; | 45 using content::WebContentsImpl; |
| 45 using content::WebContentsViewMac; | 46 using content::WebContentsViewMac; |
| 46 | 47 |
| 47 // Ensure that the blink::WebDragOperation enum values stay in sync with | 48 // Ensure that the blink::WebDragOperation enum values stay in sync with |
| 48 // NSDragOperation constants, since the code below static_casts between 'em. | 49 // NSDragOperation constants, since the code below static_casts between 'em. |
| 49 #define STATIC_ASSERT_ENUM(a, b) \ | 50 #define STATIC_ASSERT_ENUM(a, b) \ |
| 50 static_assert(static_cast<int>(a) == static_cast<int>(b), \ | 51 static_assert(static_cast<int>(a) == static_cast<int>(b), \ |
| 51 "enum mismatch: " #a) | 52 "enum mismatch: " #a) |
| 52 STATIC_ASSERT_ENUM(NSDragOperationNone, blink::WebDragOperationNone); | 53 STATIC_ASSERT_ENUM(NSDragOperationNone, blink::WebDragOperationNone); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 70 - (void)cancelDeferredClose; | 71 - (void)cancelDeferredClose; |
| 71 - (void)clearWebContentsView; | 72 - (void)clearWebContentsView; |
| 72 - (void)closeTabAfterEvent; | 73 - (void)closeTabAfterEvent; |
| 73 - (void)updateWebContentsVisibility; | 74 - (void)updateWebContentsVisibility; |
| 74 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; | 75 - (void)viewDidBecomeFirstResponder:(NSNotification*)notification; |
| 75 - (content::WebContentsImpl*)webContents; | 76 - (content::WebContentsImpl*)webContents; |
| 76 @end | 77 @end |
| 77 | 78 |
| 78 namespace { | 79 namespace { |
| 79 | 80 |
| 80 blink::WebScreenInfo GetWebScreenInfo(NSView* view) { | 81 content::ScreenInfo GetNSViewScreenInfo(NSView* view) { |
| 81 display::Display display = | 82 display::Display display = |
| 82 display::Screen::GetScreen()->GetDisplayNearestWindow(view); | 83 display::Screen::GetScreen()->GetDisplayNearestWindow(view); |
| 83 | 84 |
| 84 NSScreen* screen = [NSScreen deepestScreen]; | 85 NSScreen* screen = [NSScreen deepestScreen]; |
| 85 | 86 |
| 86 blink::WebScreenInfo results; | 87 content::ScreenInfo results; |
| 87 | 88 |
| 88 results.deviceScaleFactor = static_cast<int>(display.device_scale_factor()); | 89 results.device_scale_factor = static_cast<int>(display.device_scale_factor()); |
| 89 results.depth = NSBitsPerPixelFromDepth([screen depth]); | 90 results.depth = NSBitsPerPixelFromDepth([screen depth]); |
| 90 results.depthPerComponent = NSBitsPerSampleFromDepth([screen depth]); | 91 results.depth_per_component = NSBitsPerSampleFromDepth([screen depth]); |
| 91 results.isMonochrome = | 92 results.is_monochrome = |
| 92 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel; | 93 [[screen colorSpace] colorSpaceModel] == NSGrayColorSpaceModel; |
| 93 results.rect = display.bounds(); | 94 results.rect = display.bounds(); |
| 94 results.availableRect = display.work_area(); | 95 results.available_rect = display.work_area(); |
| 95 results.orientationAngle = display.RotationAsDegree(); | 96 results.orientation_angle = display.RotationAsDegree(); |
| 96 results.orientationType = | 97 results.orientation_type = |
| 97 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display); | 98 content::RenderWidgetHostViewBase::GetOrientationTypeForDesktop(display); |
| 98 | 99 |
| 99 return results; | 100 return results; |
| 100 } | 101 } |
| 101 | 102 |
| 102 } // namespace | 103 } // namespace |
| 103 | 104 |
| 104 namespace content { | 105 namespace content { |
| 105 | 106 |
| 106 // static | 107 // static |
| 107 void WebContentsView::GetDefaultScreenInfo( | 108 void WebContentsView::GetDefaultScreenInfo(ScreenInfo* results) { |
| 108 blink::WebScreenInfo* results) { | 109 *results = GetNSViewScreenInfo(nil); |
| 109 *results = GetWebScreenInfo(NULL); | |
| 110 } | 110 } |
| 111 | 111 |
| 112 WebContentsView* CreateWebContentsView( | 112 WebContentsView* CreateWebContentsView( |
| 113 WebContentsImpl* web_contents, | 113 WebContentsImpl* web_contents, |
| 114 WebContentsViewDelegate* delegate, | 114 WebContentsViewDelegate* delegate, |
| 115 RenderViewHostDelegateView** render_view_host_delegate_view) { | 115 RenderViewHostDelegateView** render_view_host_delegate_view) { |
| 116 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); | 116 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); |
| 117 *render_view_host_delegate_view = rv; | 117 *render_view_host_delegate_view = rv; |
| 118 return rv; | 118 return rv; |
| 119 } | 119 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 143 if (!rwhv) | 143 if (!rwhv) |
| 144 return NULL; | 144 return NULL; |
| 145 return rwhv->GetNativeView(); | 145 return rwhv->GetNativeView(); |
| 146 } | 146 } |
| 147 | 147 |
| 148 gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeWindow() const { | 148 gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeWindow() const { |
| 149 NSWindow* window = [cocoa_view_.get() window]; | 149 NSWindow* window = [cocoa_view_.get() window]; |
| 150 return window ? window : delegate_->GetNativeWindow(); | 150 return window ? window : delegate_->GetNativeWindow(); |
| 151 } | 151 } |
| 152 | 152 |
| 153 void WebContentsViewMac::GetScreenInfo(blink::WebScreenInfo* results) const { | 153 void WebContentsViewMac::GetScreenInfo(ScreenInfo* results) const { |
| 154 *results = GetWebScreenInfo(GetNativeView()); | 154 *results = GetNSViewScreenInfo(GetNativeView()); |
| 155 } | 155 } |
| 156 | 156 |
| 157 void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const { | 157 void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const { |
| 158 NSWindow* window = [cocoa_view_.get() window]; | 158 NSWindow* window = [cocoa_view_.get() window]; |
| 159 NSRect bounds = [cocoa_view_.get() bounds]; | 159 NSRect bounds = [cocoa_view_.get() bounds]; |
| 160 if (window) { | 160 if (window) { |
| 161 // Convert bounds to window coordinate space. | 161 // Convert bounds to window coordinate space. |
| 162 bounds = [cocoa_view_.get() convertRect:bounds toView:nil]; | 162 bounds = [cocoa_view_.get() convertRect:bounds toView:nil]; |
| 163 | 163 |
| 164 // Convert bounds to screen coordinate space. | 164 // Convert bounds to screen coordinate space. |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 714 | 714 |
| 715 - (void)viewDidHide { | 715 - (void)viewDidHide { |
| 716 [self updateWebContentsVisibility]; | 716 [self updateWebContentsVisibility]; |
| 717 } | 717 } |
| 718 | 718 |
| 719 - (void)viewDidUnhide { | 719 - (void)viewDidUnhide { |
| 720 [self updateWebContentsVisibility]; | 720 [self updateWebContentsVisibility]; |
| 721 } | 721 } |
| 722 | 722 |
| 723 @end | 723 @end |
| OLD | NEW |