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