| 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> | 7 #import <objc/runtime.h> |
| 8 | 8 |
| 9 #include "base/logging.h" | 9 #include "base/logging.h" |
| 10 #include "base/mac/mac_util.h" | 10 #include "base/mac/mac_util.h" |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 // set at all, the creator of the Widget is expected to call SetBounds() | 127 // set at all, the creator of the Widget is expected to call SetBounds() |
| 128 // before calling Widget::Show() to avoid a kWindowSizeDeterminedLater-sized | 128 // before calling Widget::Show() to avoid a kWindowSizeDeterminedLater-sized |
| 129 // (i.e. 1x1) window appearing. | 129 // (i.e. 1x1) window appearing. |
| 130 if (!params.bounds.IsEmpty()) { | 130 if (!params.bounds.IsEmpty()) { |
| 131 SetBounds(params.bounds); | 131 SetBounds(params.bounds); |
| 132 } else { | 132 } else { |
| 133 // If a position is set, but no size, complain. Otherwise, a 1x1 window | 133 // If a position is set, but no size, complain. Otherwise, a 1x1 window |
| 134 // would appear there, which might be unexpected. | 134 // would appear there, which might be unexpected. |
| 135 DCHECK(params.bounds.origin().IsOrigin()) | 135 DCHECK(params.bounds.origin().IsOrigin()) |
| 136 << "Zero-sized windows not supported on Mac."; | 136 << "Zero-sized windows not supported on Mac."; |
| 137 |
| 138 // Otherwise, bounds is all zeroes. Cocoa will currently have the window at |
| 139 // the bottom left of the screen. To support a client calling SetSize() only |
| 140 // (and for consistency across platforms) put it at the top-left instead. |
| 141 // Read back the current frame: it will be a 1x1 context rect but the frame |
| 142 // size also depends on the window style. |
| 143 NSRect frame_rect = [window_ frame]; |
| 144 SetBounds(gfx::Rect(gfx::Point(), |
| 145 gfx::Size(NSWidth(frame_rect), NSHeight(frame_rect)))); |
| 137 } | 146 } |
| 138 | 147 |
| 139 // Widgets for UI controls (usually layered above web contents) start visible. | 148 // Widgets for UI controls (usually layered above web contents) start visible. |
| 140 if (params.type == Widget::InitParams::TYPE_CONTROL) | 149 if (params.type == Widget::InitParams::TYPE_CONTROL) |
| 141 SetVisibilityState(SHOW_INACTIVE); | 150 SetVisibilityState(SHOW_INACTIVE); |
| 142 } | 151 } |
| 143 | 152 |
| 144 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { | 153 void BridgedNativeWidget::SetFocusManager(FocusManager* focus_manager) { |
| 145 if (focus_manager_ == focus_manager) | 154 if (focus_manager_ == focus_manager) |
| 146 return; | 155 return; |
| (...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 732 window_, &kWindowPropertiesKey); | 741 window_, &kWindowPropertiesKey); |
| 733 if (!properties) { | 742 if (!properties) { |
| 734 properties = [NSMutableDictionary dictionary]; | 743 properties = [NSMutableDictionary dictionary]; |
| 735 objc_setAssociatedObject(window_, &kWindowPropertiesKey, | 744 objc_setAssociatedObject(window_, &kWindowPropertiesKey, |
| 736 properties, OBJC_ASSOCIATION_RETAIN); | 745 properties, OBJC_ASSOCIATION_RETAIN); |
| 737 } | 746 } |
| 738 return properties; | 747 return properties; |
| 739 } | 748 } |
| 740 | 749 |
| 741 } // namespace views | 750 } // namespace views |
| OLD | NEW |