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.
5 #include "mojo/services/native_viewport/native_viewport.h"
7 #import <AppKit/NSApplication.h>
8 #import <AppKit/NSView.h>
9 #import <AppKit/NSWindow.h>
11 #include "base/bind.h"
12 #include "ui/gfx/rect.h"
17 class NativeViewportMac : public NativeViewport {
19 NativeViewportMac(NativeViewportDelegate* delegate)
20 : delegate_(delegate),
24 virtual ~NativeViewportMac() {
25 [window_ orderOut:nil];
30 // Overridden from NativeViewport:
31 virtual void Init(const gfx::Rect& bounds) OVERRIDE {
32 [NSApplication sharedApplication];
35 window_ = [[NSWindow alloc]
36 initWithContentRect:NSRectFromCGRect(rect_.ToCGRect())
37 styleMask:NSTitledWindowMask
38 backing:NSBackingStoreBuffered
40 delegate_->OnAcceleratedWidgetAvailable([window_ contentView]);
41 delegate_->OnBoundsChanged(rect_);
44 virtual void Show() OVERRIDE {
45 [window_ orderFront:nil];
48 virtual void Hide() OVERRIDE {
49 [window_ orderOut:nil];
52 virtual void Close() OVERRIDE {
53 // TODO(beng): perform this in response to NSWindow destruction.
54 delegate_->OnDestroyed();
57 virtual gfx::Size GetSize() OVERRIDE {
61 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE {
65 virtual void SetCapture() OVERRIDE {
69 virtual void ReleaseCapture() OVERRIDE {
73 NativeViewportDelegate* delegate_;
77 DISALLOW_COPY_AND_ASSIGN(NativeViewportMac);
81 scoped_ptr<NativeViewport> NativeViewport::Create(
82 shell::Context* context,
83 NativeViewportDelegate* delegate) {
84 return scoped_ptr<NativeViewport>(new NativeViewportMac(delegate)).Pass();
87 } // namespace services