window_tree_host_mojo.cc revision f8ee788a64d60abd8f2d742a5fdedde054ecd910
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/aura/window_tree_host_mojo.h" 6 7#include <vector> 8 9#include "mojo/aura/window_tree_host_mojo_delegate.h" 10#include "ui/aura/env.h" 11#include "ui/aura/window.h" 12#include "ui/aura/window_event_dispatcher.h" 13#include "ui/events/event.h" 14#include "ui/events/event_constants.h" 15 16namespace mojo { 17namespace { 18 19const char kTreeHostsKey[] = "tree_hosts"; 20 21typedef std::vector<WindowTreeHostMojo*> Managers; 22 23class TreeHosts : public base::SupportsUserData::Data { 24 public: 25 TreeHosts() {} 26 virtual ~TreeHosts() {} 27 28 static TreeHosts* Get() { 29 TreeHosts* hosts = static_cast<TreeHosts*>( 30 aura::Env::GetInstance()->GetUserData(kTreeHostsKey)); 31 if (!hosts) { 32 hosts = new TreeHosts; 33 aura::Env::GetInstance()->SetUserData(kTreeHostsKey, hosts); 34 } 35 return hosts; 36 } 37 38 void Add(WindowTreeHostMojo* manager) { 39 managers_.push_back(manager); 40 } 41 42 void Remove(WindowTreeHostMojo* manager) { 43 Managers::iterator i = std::find(managers_.begin(), managers_.end(), 44 manager); 45 DCHECK(i != managers_.end()); 46 managers_.erase(i); 47 } 48 49 const std::vector<WindowTreeHostMojo*> managers() const { 50 return managers_; 51 } 52 53 private: 54 Managers managers_; 55 56 DISALLOW_COPY_AND_ASSIGN(TreeHosts); 57}; 58 59} // namespace 60 61//////////////////////////////////////////////////////////////////////////////// 62// WindowTreeHostMojo, public: 63 64WindowTreeHostMojo::WindowTreeHostMojo(const gfx::Rect& bounds, 65 WindowTreeHostMojoDelegate* delegate) 66 : bounds_(bounds), 67 delegate_(delegate) { 68 CreateCompositor(GetAcceleratedWidget()); 69 70 TreeHosts::Get()->Add(this); 71} 72 73WindowTreeHostMojo::~WindowTreeHostMojo() { 74 TreeHosts::Get()->Remove(this); 75 DestroyCompositor(); 76 DestroyDispatcher(); 77} 78 79// static 80WindowTreeHostMojo* WindowTreeHostMojo::ForCompositor( 81 ui::Compositor* compositor) { 82 const Managers& managers = TreeHosts::Get()->managers(); 83 for (size_t i = 0; i < managers.size(); ++i) { 84 if (managers[i]->compositor() == compositor) 85 return managers[i]; 86 } 87 return NULL; 88} 89 90void WindowTreeHostMojo::SetContents(const SkBitmap& contents) { 91 delegate_->CompositorContentsChanged(contents); 92} 93 94//////////////////////////////////////////////////////////////////////////////// 95// WindowTreeHostMojo, aura::WindowTreeHost implementation: 96 97ui::EventSource* WindowTreeHostMojo::GetEventSource() { 98 return this; 99} 100 101gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() { 102 return gfx::kNullAcceleratedWidget; 103} 104 105void WindowTreeHostMojo::Show() { 106 window()->Show(); 107} 108 109void WindowTreeHostMojo::Hide() { 110} 111 112gfx::Rect WindowTreeHostMojo::GetBounds() const { 113 return bounds_; 114} 115 116void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { 117 window()->SetBounds(gfx::Rect(bounds.size())); 118} 119 120gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { 121 return gfx::Point(0, 0); 122} 123 124void WindowTreeHostMojo::SetCapture() { 125 NOTIMPLEMENTED(); 126} 127 128void WindowTreeHostMojo::ReleaseCapture() { 129 NOTIMPLEMENTED(); 130} 131 132void WindowTreeHostMojo::PostNativeEvent( 133 const base::NativeEvent& native_event) { 134 NOTIMPLEMENTED(); 135} 136 137void WindowTreeHostMojo::OnDeviceScaleFactorChanged( 138 float device_scale_factor) { 139 NOTIMPLEMENTED(); 140} 141 142void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) { 143 NOTIMPLEMENTED(); 144} 145 146void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) { 147 NOTIMPLEMENTED(); 148} 149 150void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) { 151 NOTIMPLEMENTED(); 152} 153 154//////////////////////////////////////////////////////////////////////////////// 155// WindowTreeHostMojo, ui::EventSource implementation: 156 157ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() { 158 return dispatcher(); 159} 160 161} // namespace mojo 162