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#include "base/memory/scoped_ptr.h" 8#include "ui/gfx/rect.h" 9#include "ui/platform_window/platform_window_delegate.h" 10#include "ui/platform_window/win/win_window.h" 11 12namespace mojo { 13 14class PlatformViewportWin : public PlatformViewport, 15 public ui::PlatformWindowDelegate { 16 public: 17 explicit PlatformViewportWin(Delegate* delegate) 18 : delegate_(delegate) { 19 } 20 21 virtual ~PlatformViewportWin() { 22 // Destroy the platform-window while |this| is still alive. 23 platform_window_.reset(); 24 } 25 26 private: 27 // Overridden from PlatformViewport: 28 virtual void Init(const gfx::Rect& bounds) OVERRIDE { 29 platform_window_.reset(new ui::WinWindow(this, bounds)); 30 } 31 32 virtual void Show() OVERRIDE { 33 platform_window_->Show(); 34 } 35 36 virtual void Hide() OVERRIDE { 37 platform_window_->Hide(); 38 } 39 40 virtual void Close() OVERRIDE { 41 platform_window_->Close(); 42 } 43 44 virtual gfx::Size GetSize() OVERRIDE { 45 return platform_window_->GetBounds().size(); 46 } 47 48 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { 49 platform_window_->SetBounds(bounds); 50 } 51 52 virtual void SetCapture() OVERRIDE { 53 platform_window_->SetCapture(); 54 } 55 56 virtual void ReleaseCapture() OVERRIDE { 57 platform_window_->ReleaseCapture(); 58 } 59 60 // ui::PlatformWindowDelegate: 61 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { 62 delegate_->OnBoundsChanged(new_bounds); 63 } 64 65 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE { 66 } 67 68 virtual void DispatchEvent(ui::Event* event) OVERRIDE { 69 delegate_->OnEvent(event); 70 } 71 72 virtual void OnCloseRequest() OVERRIDE { 73 platform_window_->Close(); 74 } 75 76 virtual void OnClosed() OVERRIDE { 77 delegate_->OnDestroyed(); 78 } 79 80 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE { 81 } 82 83 virtual void OnLostCapture() OVERRIDE { 84 } 85 86 virtual void OnAcceleratedWidgetAvailable( 87 gfx::AcceleratedWidget widget) OVERRIDE { 88 delegate_->OnAcceleratedWidgetAvailable(widget); 89 } 90 91 virtual void OnActivationChanged(bool active) OVERRIDE {} 92 93 scoped_ptr<ui::PlatformWindow> platform_window_; 94 Delegate* delegate_; 95 96 DISALLOW_COPY_AND_ASSIGN(PlatformViewportWin); 97}; 98 99// static 100scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { 101 return scoped_ptr<PlatformViewport>(new PlatformViewportWin(delegate)).Pass(); 102} 103 104} // namespace mojo 105