OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "mojo/services/native_viewport/platform_viewport.h" | 5 #include "mojo/services/native_viewport/platform_viewport.h" |
6 | 6 |
7 #import <AppKit/NSApplication.h> | 7 #import <AppKit/NSApplication.h> |
8 #import <AppKit/NSView.h> | 8 #import <AppKit/NSView.h> |
9 #import <AppKit/NSWindow.h> | 9 #import <AppKit/NSWindow.h> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "base/bind.h" |
12 #include "ui/gfx/rect.h" | 12 #include "ui/gfx/rect.h" |
13 | 13 |
14 namespace mojo { | 14 namespace mojo { |
15 | 15 |
16 class PlatformViewportMac : public PlatformViewport { | 16 class PlatformViewportMac : public PlatformViewport { |
17 public: | 17 public: |
18 PlatformViewportMac(Delegate* delegate) | 18 PlatformViewportMac(Delegate* delegate) |
19 : delegate_(delegate), | 19 : delegate_(delegate), |
20 window_(nil) { | 20 window_(nil) { |
21 } | 21 } |
22 | 22 |
23 virtual ~PlatformViewportMac() { | 23 ~PlatformViewportMac() override { |
24 [window_ orderOut:nil]; | 24 [window_ orderOut:nil]; |
25 [window_ close]; | 25 [window_ close]; |
26 } | 26 } |
27 | 27 |
28 private: | 28 private: |
29 // Overridden from PlatformViewport: | 29 // Overridden from PlatformViewport: |
30 virtual void Init(const gfx::Rect& bounds) override { | 30 void Init(const gfx::Rect& bounds) override { |
31 [NSApplication sharedApplication]; | 31 [NSApplication sharedApplication]; |
32 | 32 |
33 rect_ = bounds; | 33 rect_ = bounds; |
34 window_ = [[NSWindow alloc] | 34 window_ = [[NSWindow alloc] |
35 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) | 35 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect()) |
36 styleMask:NSTitledWindowMask | 36 styleMask:NSTitledWindowMask |
37 backing:NSBackingStoreBuffered | 37 backing:NSBackingStoreBuffered |
38 defer:NO]; | 38 defer:NO]; |
39 delegate_->OnAcceleratedWidgetAvailable([window_ contentView]); | 39 delegate_->OnAcceleratedWidgetAvailable([window_ contentView]); |
40 delegate_->OnBoundsChanged(rect_); | 40 delegate_->OnBoundsChanged(rect_); |
41 } | 41 } |
42 | 42 |
43 virtual void Show() override { | 43 void Show() override { [window_ orderFront:nil]; } |
44 [window_ orderFront:nil]; | |
45 } | |
46 | 44 |
47 virtual void Hide() override { | 45 void Hide() override { [window_ orderOut:nil]; } |
48 [window_ orderOut:nil]; | |
49 } | |
50 | 46 |
51 virtual void Close() override { | 47 void Close() override { |
52 // TODO(beng): perform this in response to NSWindow destruction. | 48 // TODO(beng): perform this in response to NSWindow destruction. |
53 delegate_->OnDestroyed(); | 49 delegate_->OnDestroyed(); |
54 } | 50 } |
55 | 51 |
56 virtual gfx::Size GetSize() override { | 52 gfx::Size GetSize() override { return rect_.size(); } |
57 return rect_.size(); | |
58 } | |
59 | 53 |
60 virtual void SetBounds(const gfx::Rect& bounds) override { | 54 void SetBounds(const gfx::Rect& bounds) override { NOTIMPLEMENTED(); } |
61 NOTIMPLEMENTED(); | |
62 } | |
63 | 55 |
64 virtual void SetCapture() override { | 56 void SetCapture() override { NOTIMPLEMENTED(); } |
65 NOTIMPLEMENTED(); | |
66 } | |
67 | 57 |
68 virtual void ReleaseCapture() override { | 58 void ReleaseCapture() override { NOTIMPLEMENTED(); } |
69 NOTIMPLEMENTED(); | |
70 } | |
71 | 59 |
72 Delegate* delegate_; | 60 Delegate* delegate_; |
73 NSWindow* window_; | 61 NSWindow* window_; |
74 gfx::Rect rect_; | 62 gfx::Rect rect_; |
75 | 63 |
76 DISALLOW_COPY_AND_ASSIGN(PlatformViewportMac); | 64 DISALLOW_COPY_AND_ASSIGN(PlatformViewportMac); |
77 }; | 65 }; |
78 | 66 |
79 // static | 67 // static |
80 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 68 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
81 return scoped_ptr<PlatformViewport>(new PlatformViewportMac(delegate)).Pass(); | 69 return scoped_ptr<PlatformViewport>(new PlatformViewportMac(delegate)).Pass(); |
82 } | 70 } |
83 | 71 |
84 } // namespace mojo | 72 } // namespace mojo |
OLD | NEW |