| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/views/cocoa/bridged_native_widget.h" | 5 #import "ui/views/cocoa/bridged_native_widget.h" |
| 6 | 6 |
| 7 #import <objc/runtime.h> |
| 8 |
| 7 #include "base/logging.h" | 9 #include "base/logging.h" |
| 8 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| 9 #import "base/mac/sdk_forward_declarations.h" | 11 #import "base/mac/sdk_forward_declarations.h" |
| 10 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 11 #include "ui/base/ime/input_method.h" | 13 #include "ui/base/ime/input_method.h" |
| 12 #include "ui/base/ime/input_method_factory.h" | 14 #include "ui/base/ime/input_method_factory.h" |
| 13 #include "ui/base/ui_base_switches_util.h" | 15 #include "ui/base/ui_base_switches_util.h" |
| 14 #include "ui/gfx/display.h" | 16 #include "ui/gfx/display.h" |
| 15 #include "ui/gfx/geometry/dip_util.h" | 17 #include "ui/gfx/geometry/dip_util.h" |
| 16 #import "ui/gfx/mac/coordinate_conversion.h" | 18 #import "ui/gfx/mac/coordinate_conversion.h" |
| 17 #include "ui/gfx/screen.h" | 19 #include "ui/gfx/screen.h" |
| 18 #import "ui/views/cocoa/cocoa_mouse_capture.h" | 20 #import "ui/views/cocoa/cocoa_mouse_capture.h" |
| 19 #import "ui/views/cocoa/bridged_content_view.h" | 21 #import "ui/views/cocoa/bridged_content_view.h" |
| 20 #import "ui/views/cocoa/views_nswindow_delegate.h" | 22 #import "ui/views/cocoa/views_nswindow_delegate.h" |
| 21 #include "ui/views/widget/native_widget_mac.h" | 23 #include "ui/views/widget/native_widget_mac.h" |
| 22 #include "ui/views/ime/input_method_bridge.h" | 24 #include "ui/views/ime/input_method_bridge.h" |
| 23 #include "ui/views/ime/null_input_method.h" | 25 #include "ui/views/ime/null_input_method.h" |
| 24 #include "ui/views/view.h" | 26 #include "ui/views/view.h" |
| 25 #include "ui/views/views_delegate.h" | 27 #include "ui/views/views_delegate.h" |
| 26 #include "ui/views/widget/widget.h" | 28 #include "ui/views/widget/widget.h" |
| 27 | 29 |
| 28 namespace { | 30 namespace { |
| 29 | 31 |
| 32 int kWindowPropertiesKey; |
| 33 |
| 30 float GetDeviceScaleFactorFromView(NSView* view) { | 34 float GetDeviceScaleFactorFromView(NSView* view) { |
| 31 gfx::Display display = | 35 gfx::Display display = |
| 32 gfx::Screen::GetScreenFor(view)->GetDisplayNearestWindow(view); | 36 gfx::Screen::GetScreenFor(view)->GetDisplayNearestWindow(view); |
| 33 DCHECK(display.is_valid()); | 37 DCHECK(display.is_valid()); |
| 34 return display.device_scale_factor(); | 38 return display.device_scale_factor(); |
| 35 } | 39 } |
| 36 | 40 |
| 37 } // namespace | 41 } // namespace |
| 38 | 42 |
| 39 namespace views { | 43 namespace views { |
| (...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 } | 205 } |
| 202 | 206 |
| 203 void BridgedNativeWidget::ReleaseCapture() { | 207 void BridgedNativeWidget::ReleaseCapture() { |
| 204 mouse_capture_.reset(); | 208 mouse_capture_.reset(); |
| 205 } | 209 } |
| 206 | 210 |
| 207 bool BridgedNativeWidget::HasCapture() { | 211 bool BridgedNativeWidget::HasCapture() { |
| 208 return mouse_capture_ && mouse_capture_->IsActive(); | 212 return mouse_capture_ && mouse_capture_->IsActive(); |
| 209 } | 213 } |
| 210 | 214 |
| 215 void BridgedNativeWidget::SetNativeWindowProperty(const char* name, |
| 216 void* value) { |
| 217 NSString* key = [NSString stringWithUTF8String:name]; |
| 218 if (value) { |
| 219 [GetWindowProperties() setObject:[NSValue valueWithPointer:value] |
| 220 forKey:key]; |
| 221 } else { |
| 222 [GetWindowProperties() removeObjectForKey:key]; |
| 223 } |
| 224 } |
| 225 |
| 226 void* BridgedNativeWidget::GetNativeWindowProperty(const char* name) const { |
| 227 NSString* key = [NSString stringWithUTF8String:name]; |
| 228 return [[GetWindowProperties() objectForKey:key] pointerValue]; |
| 229 } |
| 230 |
| 211 void BridgedNativeWidget::OnWindowWillClose() { | 231 void BridgedNativeWidget::OnWindowWillClose() { |
| 212 if (parent_) | 232 if (parent_) |
| 213 parent_->RemoveChildWindow(this); | 233 parent_->RemoveChildWindow(this); |
| 214 [window_ setDelegate:nil]; | 234 [window_ setDelegate:nil]; |
| 215 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; | 235 [[NSNotificationCenter defaultCenter] removeObserver:window_delegate_]; |
| 216 native_widget_mac_->OnWindowWillClose(); | 236 native_widget_mac_->OnWindowWillClose(); |
| 217 } | 237 } |
| 218 | 238 |
| 219 void BridgedNativeWidget::OnFullscreenTransitionStart( | 239 void BridgedNativeWidget::OnFullscreenTransitionStart( |
| 220 bool target_fullscreen_state) { | 240 bool target_fullscreen_state) { |
| (...skipping 381 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 602 DCHECK(layer()); | 622 DCHECK(layer()); |
| 603 DCHECK(compositor_superview_); | 623 DCHECK(compositor_superview_); |
| 604 gfx::Size size_in_dip = GetClientAreaSize(); | 624 gfx::Size size_in_dip = GetClientAreaSize(); |
| 605 layer()->SetBounds(gfx::Rect(size_in_dip)); | 625 layer()->SetBounds(gfx::Rect(size_in_dip)); |
| 606 | 626 |
| 607 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); | 627 float scale_factor = GetDeviceScaleFactorFromView(compositor_superview_); |
| 608 compositor_->SetScaleAndSize(scale_factor, | 628 compositor_->SetScaleAndSize(scale_factor, |
| 609 ConvertSizeToPixel(scale_factor, size_in_dip)); | 629 ConvertSizeToPixel(scale_factor, size_in_dip)); |
| 610 } | 630 } |
| 611 | 631 |
| 632 NSMutableDictionary* BridgedNativeWidget::GetWindowProperties() const { |
| 633 NSMutableDictionary* properties = objc_getAssociatedObject( |
| 634 window_, &kWindowPropertiesKey); |
| 635 if (!properties) { |
| 636 properties = [NSMutableDictionary dictionary]; |
| 637 objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
| 638 properties, OBJC_ASSOCIATION_RETAIN); |
| 639 } |
| 640 return properties; |
| 641 } |
| 642 |
| 612 } // namespace views | 643 } // namespace views |
| OLD | NEW |