Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / mojo / services / native_viewport / platform_viewport_win.cc
blob222711222c042846266d3a89731f940539339fb4
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/platform_viewport.h"
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"
12 namespace mojo {
14 class PlatformViewportWin : public PlatformViewport,
15 public ui::PlatformWindowDelegate {
16 public:
17 explicit PlatformViewportWin(Delegate* delegate)
18 : delegate_(delegate) {
21 virtual ~PlatformViewportWin() {
22 // Destroy the platform-window while |this| is still alive.
23 platform_window_.reset();
26 private:
27 // Overridden from PlatformViewport:
28 virtual void Init(const gfx::Rect& bounds) OVERRIDE {
29 platform_window_.reset(new ui::WinWindow(this, bounds));
32 virtual void Show() OVERRIDE {
33 platform_window_->Show();
36 virtual void Hide() OVERRIDE {
37 platform_window_->Hide();
40 virtual void Close() OVERRIDE {
41 platform_window_->Close();
44 virtual gfx::Size GetSize() OVERRIDE {
45 return platform_window_->GetBounds().size();
48 virtual void SetBounds(const gfx::Rect& bounds) OVERRIDE {
49 platform_window_->SetBounds(bounds);
52 virtual void SetCapture() OVERRIDE {
53 platform_window_->SetCapture();
56 virtual void ReleaseCapture() OVERRIDE {
57 platform_window_->ReleaseCapture();
60 // ui::PlatformWindowDelegate:
61 virtual void OnBoundsChanged(const gfx::Rect& new_bounds) OVERRIDE {
62 delegate_->OnBoundsChanged(new_bounds);
65 virtual void OnDamageRect(const gfx::Rect& damaged_region) OVERRIDE {
68 virtual void DispatchEvent(ui::Event* event) OVERRIDE {
69 delegate_->OnEvent(event);
72 virtual void OnCloseRequest() OVERRIDE {
73 platform_window_->Close();
76 virtual void OnClosed() OVERRIDE {
77 delegate_->OnDestroyed();
80 virtual void OnWindowStateChanged(ui::PlatformWindowState state) OVERRIDE {
83 virtual void OnLostCapture() OVERRIDE {
86 virtual void OnAcceleratedWidgetAvailable(
87 gfx::AcceleratedWidget widget) OVERRIDE {
88 delegate_->OnAcceleratedWidgetAvailable(widget);
91 virtual void OnActivationChanged(bool active) OVERRIDE {}
93 scoped_ptr<ui::PlatformWindow> platform_window_;
94 Delegate* delegate_;
96 DISALLOW_COPY_AND_ASSIGN(PlatformViewportWin);
99 // static
100 scoped_ptr<PlatformViewport> PlatformViewport::Create(Delegate* delegate) {
101 return scoped_ptr<PlatformViewport>(new PlatformViewportWin(delegate)).Pass();
104 } // namespace mojo