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 virtual ~PlatformViewportMac() { |
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 virtual 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 virtual void Show() override { |
44 [window_ orderFront:nil]; | 44 [window_ orderFront:nil]; |
45 } | 45 } |
46 | 46 |
47 virtual void Hide() OVERRIDE { | 47 virtual void Hide() override { |
48 [window_ orderOut:nil]; | 48 [window_ orderOut:nil]; |
49 } | 49 } |
50 | 50 |
51 virtual void Close() OVERRIDE { | 51 virtual void Close() override { |
52 // TODO(beng): perform this in response to NSWindow destruction. | 52 // TODO(beng): perform this in response to NSWindow destruction. |
53 delegate_->OnDestroyed(); | 53 delegate_->OnDestroyed(); |
54 } | 54 } |
55 | 55 |
56 virtual gfx::Size GetSize() OVERRIDE { | 56 virtual gfx::Size GetSize() override { |
57 return rect_.size(); | 57 return rect_.size(); |
58 } | 58 } |
59 | 59 |
60 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { | 60 virtual void SetBounds(const gfx::Rect& bounds) override { |
61 NOTIMPLEMENTED(); | 61 NOTIMPLEMENTED(); |
62 } | 62 } |
63 | 63 |
64 virtual void SetCapture() OVERRIDE { | 64 virtual void SetCapture() override { |
65 NOTIMPLEMENTED(); | 65 NOTIMPLEMENTED(); |
66 } | 66 } |
67 | 67 |
68 virtual void ReleaseCapture() OVERRIDE { | 68 virtual void ReleaseCapture() override { |
69 NOTIMPLEMENTED(); | 69 NOTIMPLEMENTED(); |
70 } | 70 } |
71 | 71 |
72 Delegate* delegate_; | 72 Delegate* delegate_; |
73 NSWindow* window_; | 73 NSWindow* window_; |
74 gfx::Rect rect_; | 74 gfx::Rect rect_; |
75 | 75 |
76 DISALLOW_COPY_AND_ASSIGN(PlatformViewportMac); | 76 DISALLOW_COPY_AND_ASSIGN(PlatformViewportMac); |
77 }; | 77 }; |
78 | 78 |
79 // static | 79 // static |
80 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { | 80 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { |
81 return scoped_ptr<PlatformViewport>(new PlatformViewportMac(delegate)).Pass(); | 81 return scoped_ptr<PlatformViewport>(new PlatformViewportMac(delegate)).Pass(); |
82 } | 82 } |
83 | 83 |
84 } // namespace mojo | 84 } // namespace mojo |
OLD | NEW |