Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(569)

Side by Side Diff: ui/views/widget/native_widget_mac.mm

Issue 353643002: MacViews: Implement Set/Get*Bounds for NativeWidgetMac (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: import Foundation.h for NSRect Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/mac/coordinate_conversion.mm ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ui/views/widget/native_widget_mac.h" 5 #include "ui/views/widget/native_widget_mac.h"
6 6
7 #import <Cocoa/Cocoa.h> 7 #import <Cocoa/Cocoa.h>
8 8
9 #include "base/mac/foundation_util.h" 9 #include "base/mac/foundation_util.h"
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
11 #include "ui/gfx/font_list.h" 11 #include "ui/gfx/font_list.h"
12 #import "ui/gfx/mac/coordinate_conversion.h"
12 #include "ui/native_theme/native_theme.h" 13 #include "ui/native_theme/native_theme.h"
13 #import "ui/views/cocoa/bridged_content_view.h" 14 #import "ui/views/cocoa/bridged_content_view.h"
14 #import "ui/views/cocoa/bridged_native_widget.h" 15 #import "ui/views/cocoa/bridged_native_widget.h"
15 #import "ui/views/cocoa/views_nswindow_delegate.h" 16 #import "ui/views/cocoa/views_nswindow_delegate.h"
16 17
17 namespace views { 18 namespace views {
19 namespace {
20
21 NSInteger StyleMaskForParams(const Widget::InitParams& params) {
22 // TODO(tapted): Determine better masks when there are use cases for it.
23 if (params.type == Widget::InitParams::TYPE_WINDOW) {
24 return NSTitledWindowMask | NSClosableWindowMask |
25 NSMiniaturizableWindowMask | NSResizableWindowMask;
26 }
27 return NSBorderlessWindowMask;
28 }
29
30 NSRect ValidateContentRect(NSRect content_rect) {
31 // A contentRect with zero width or height is a banned practice in Chrome, due
32 // to unpredictable OSX treatment. For now, silently give a minimum dimension.
33 // TODO(tapted): Add a DCHECK, or add emulation logic (e.g. to auto-hide).
34 if (NSWidth(content_rect) == 0)
35 content_rect.size.width = 1;
36
37 if (NSHeight(content_rect) == 0)
38 content_rect.size.height = 1;
39
40 return content_rect;
41 }
42
43 } // namespace
18 44
19 //////////////////////////////////////////////////////////////////////////////// 45 ////////////////////////////////////////////////////////////////////////////////
20 // NativeWidgetMac, public: 46 // NativeWidgetMac, public:
21 47
22 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate) 48 NativeWidgetMac::NativeWidgetMac(internal::NativeWidgetDelegate* delegate)
23 : delegate_(delegate), 49 : delegate_(delegate),
24 bridge_(new BridgedNativeWidget(this)), 50 bridge_(new BridgedNativeWidget(this)),
25 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) { 51 ownership_(Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) {
26 } 52 }
27 53
(...skipping 13 matching lines...) Expand all
41 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET) 67 if (ownership_ == Widget::InitParams::NATIVE_WIDGET_OWNS_WIDGET)
42 delete this; 68 delete this;
43 } 69 }
44 70
45 //////////////////////////////////////////////////////////////////////////////// 71 ////////////////////////////////////////////////////////////////////////////////
46 // NativeWidgetMac, internal::NativeWidgetPrivate implementation: 72 // NativeWidgetMac, internal::NativeWidgetPrivate implementation:
47 73
48 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) { 74 void NativeWidgetMac::InitNativeWidget(const Widget::InitParams& params) {
49 ownership_ = params.ownership; 75 ownership_ = params.ownership;
50 76
51 // TODO(tapted): Convert position into Cocoa's flipped coordinate space. 77 NSInteger style_mask = StyleMaskForParams(params);
52 NSRect content_rect = 78 NSRect content_rect = ValidateContentRect(
53 NSMakeRect(0, 0, params.bounds.width(), params.bounds.height()); 79 [NSWindow contentRectForFrameRect:gfx::ScreenRectToNSRect(params.bounds)
54 // TODO(tapted): Determine a good initial style mask from |params|. 80 styleMask:style_mask]);
55 NSInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | 81
56 NSMiniaturizableWindowMask | NSResizableWindowMask;
57 base::scoped_nsobject<NSWindow> window( 82 base::scoped_nsobject<NSWindow> window(
58 [[NSWindow alloc] initWithContentRect:content_rect 83 [[NSWindow alloc] initWithContentRect:content_rect
59 styleMask:style_mask 84 styleMask:style_mask
60 backing:NSBackingStoreBuffered 85 backing:NSBackingStoreBuffered
61 defer:NO]); 86 defer:NO]);
62 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject. 87 [window setReleasedWhenClosed:NO]; // Owned by scoped_nsobject.
63 bridge_->Init(window, params); 88 bridge_->Init(window, params);
64 89
65 delegate_->OnNativeWidgetCreated(true); 90 delegate_->OnNativeWidgetCreated(true);
66 91
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 void NativeWidgetMac::SetWindowIcons(const gfx::ImageSkia& window_icon, 211 void NativeWidgetMac::SetWindowIcons(const gfx::ImageSkia& window_icon,
187 const gfx::ImageSkia& app_icon) { 212 const gfx::ImageSkia& app_icon) {
188 NOTIMPLEMENTED(); 213 NOTIMPLEMENTED();
189 } 214 }
190 215
191 void NativeWidgetMac::InitModalType(ui::ModalType modal_type) { 216 void NativeWidgetMac::InitModalType(ui::ModalType modal_type) {
192 NOTIMPLEMENTED(); 217 NOTIMPLEMENTED();
193 } 218 }
194 219
195 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const { 220 gfx::Rect NativeWidgetMac::GetWindowBoundsInScreen() const {
196 NOTIMPLEMENTED(); 221 return gfx::ScreenRectFromNSRect([GetNativeWindow() frame]);
197 return gfx::Rect();
198 } 222 }
199 223
200 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const { 224 gfx::Rect NativeWidgetMac::GetClientAreaBoundsInScreen() const {
201 NOTIMPLEMENTED(); 225 NSWindow* window = GetNativeWindow();
202 return gfx::Rect(); 226 return gfx::ScreenRectFromNSRect(
227 [window contentRectForFrameRect:[window frame]]);
203 } 228 }
204 229
205 gfx::Rect NativeWidgetMac::GetRestoredBounds() const { 230 gfx::Rect NativeWidgetMac::GetRestoredBounds() const {
206 NOTIMPLEMENTED(); 231 NOTIMPLEMENTED();
207 return gfx::Rect(); 232 return gfx::Rect();
208 } 233 }
209 234
210 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) { 235 void NativeWidgetMac::SetBounds(const gfx::Rect& bounds) {
211 NOTIMPLEMENTED(); 236 [GetNativeWindow() setFrame:gfx::ScreenRectToNSRect(bounds)
237 display:YES
238 animate:NO];
212 } 239 }
213 240
214 void NativeWidgetMac::SetSize(const gfx::Size& size) { 241 void NativeWidgetMac::SetSize(const gfx::Size& size) {
215 [GetNativeWindow() setContentSize:NSMakeSize(size.width(), size.height())]; 242 // Ensure the top-left corner stays in-place (rather than the bottom-left,
243 // which -[NSWindow setContentSize:] would do).
244 SetBounds(gfx::Rect(GetWindowBoundsInScreen().origin(), size));
216 } 245 }
217 246
218 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) { 247 void NativeWidgetMac::StackAbove(gfx::NativeView native_view) {
219 NOTIMPLEMENTED(); 248 NOTIMPLEMENTED();
220 } 249 }
221 250
222 void NativeWidgetMac::StackAtTop() { 251 void NativeWidgetMac::StackAtTop() {
223 NOTIMPLEMENTED(); 252 NOTIMPLEMENTED();
224 } 253 }
225 254
226 void NativeWidgetMac::StackBelow(gfx::NativeView native_view) { 255 void NativeWidgetMac::StackBelow(gfx::NativeView native_view) {
227 NOTIMPLEMENTED(); 256 NOTIMPLEMENTED();
228 } 257 }
229 258
230 void NativeWidgetMac::SetShape(gfx::NativeRegion shape) { 259 void NativeWidgetMac::SetShape(gfx::NativeRegion shape) {
231 NOTIMPLEMENTED(); 260 NOTIMPLEMENTED();
232 } 261 }
233 262
234 void NativeWidgetMac::Close() { 263 void NativeWidgetMac::Close() {
235 // Calling performClose: will momentarily highlight the close button. 264 NSWindow* window = GetNativeWindow();
236 [GetNativeWindow() performSelector:@selector(performClose:) 265 // Calling performClose: will momentarily highlight the close button, but
237 withObject:nil 266 // AppKit will reject it if there is no close button.
238 afterDelay:0]; 267 SEL close_selector = ([window styleMask] & NSClosableWindowMask)
268 ? @selector(performClose:)
269 : @selector(close);
270 [window performSelector:close_selector withObject:nil afterDelay:0];
239 } 271 }
240 272
241 void NativeWidgetMac::CloseNow() { 273 void NativeWidgetMac::CloseNow() {
242 // Reset |bridge_| to NULL before destroying it. 274 // Reset |bridge_| to NULL before destroying it.
243 scoped_ptr<BridgedNativeWidget> bridge(bridge_.Pass()); 275 scoped_ptr<BridgedNativeWidget> bridge(bridge_.Pass());
244 } 276 }
245 277
246 void NativeWidgetMac::Show() { 278 void NativeWidgetMac::Show() {
247 NOTIMPLEMENTED(); 279 NOTIMPLEMENTED();
248 } 280 }
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
488 } 520 }
489 521
490 // static 522 // static
491 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() { 523 gfx::FontList NativeWidgetPrivate::GetWindowTitleFontList() {
492 NOTIMPLEMENTED(); 524 NOTIMPLEMENTED();
493 return gfx::FontList(); 525 return gfx::FontList();
494 } 526 }
495 527
496 } // namespace internal 528 } // namespace internal
497 } // namespace views 529 } // namespace views
OLDNEW
« no previous file with comments | « ui/gfx/mac/coordinate_conversion.mm ('k') | ui/views/widget/widget_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698