platform_viewport_ozone.cc revision 6e8cce623b6e4fe0c9e4af605d675dd9d0338c38
1// Copyright 2014 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 "ui/events/event.h" 8#include "ui/events/platform/platform_event_dispatcher.h" 9#include "ui/events/platform/platform_event_source.h" 10#include "ui/ozone/public/cursor_factory_ozone.h" 11#include "ui/ozone/public/event_factory_ozone.h" 12#include "ui/ozone/public/ozone_platform.h" 13#include "ui/ozone/public/surface_factory_ozone.h" 14#include "ui/platform_window/platform_window.h" 15#include "ui/platform_window/platform_window_delegate.h" 16 17namespace mojo { 18 19// TODO(spang): Deduplicate with PlatformViewportX11.. but there's a hack 20// in there that prevents this. 21class PlatformViewportOzone : public PlatformViewport, 22 public ui::PlatformWindowDelegate { 23 public: 24 explicit PlatformViewportOzone(Delegate* delegate) : delegate_(delegate) { 25 ui::OzonePlatform::InitializeForUI(); 26 } 27 28 virtual ~PlatformViewportOzone() { 29 // Destroy the platform-window while |this| is still alive. 30 platform_window_.reset(); 31 } 32 33 private: 34 // Overridden from PlatformViewport: 35 virtual void Init(const gfx::Rect& bounds) OVERRIDE { 36 platform_window_ = 37 ui::OzonePlatform::GetInstance()->CreatePlatformWindow(this, bounds); 38 } 39 40 virtual void Show() OVERRIDE { platform_window_->Show(); } 41 42 virtual void Hide() OVERRIDE { platform_window_->Hide(); } 43 44 virtual void Close() OVERRIDE { platform_window_->Close(); } 45 46 virtual gfx::Size GetSize() OVERRIDE { 47 return platform_window_->GetBounds().size(); 48 } 49 50 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE { 51 platform_window_->SetBounds(bounds); 52 } 53 54 virtual void SetCapture() OVERRIDE { platform_window_->SetCapture(); } 55 56 virtual void ReleaseCapture() OVERRIDE { platform_window_->ReleaseCapture(); } 57 58 // ui::PlatformWindowDelegate: 59 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE { 60 delegate_->OnBoundsChanged(new_bounds); 61 } 62 63 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {} 64 65 virtual void DispatchEvent(ui::Event* event) OVERRIDE { 66 delegate_->OnEvent(event); 67 } 68 69 virtual void OnCloseRequest() OVERRIDE { platform_window_->Close(); } 70 71 virtual void OnClosed() OVERRIDE { delegate_->OnDestroyed(); } 72 73 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE {} 74 75 virtual void OnLostCapture() OVERRIDE {} 76 77 virtual void OnAcceleratedWidgetAvailable( 78 gfx::AcceleratedWidget widget) OVERRIDE { 79 delegate_->OnAcceleratedWidgetAvailable(widget); 80 } 81 82 virtual void OnActivationChanged(bool active) OVERRIDE {} 83 84 scoped_ptr<ui::PlatformWindow> platform_window_; 85 Delegate* delegate_; 86 87 DISALLOW_COPY_AND_ASSIGN(PlatformViewportOzone); 88}; 89 90// static 91scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) { 92 return scoped_ptr<PlatformViewport>( 93 new PlatformViewportOzone(delegate)).Pass(); 94} 95 96} // namespace mojo 97