OLD | NEW |
(Empty) | |
| 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 |
| 16 namespace mojo { |
| 17 namespace { |
| 18 |
| 19 const char kTreeHostsKey[] = "tree_hosts"; |
| 20 |
| 21 typedef std::vector<WindowTreeHostMojo*> Managers; |
| 22 |
| 23 class 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 |
| 64 WindowTreeHostMojo::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 |
| 73 WindowTreeHostMojo::~WindowTreeHostMojo() { |
| 74 TreeHosts::Get()->Remove(this); |
| 75 DestroyCompositor(); |
| 76 DestroyDispatcher(); |
| 77 } |
| 78 |
| 79 // static |
| 80 WindowTreeHostMojo* 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 |
| 90 void WindowTreeHostMojo::SetContents(const SkBitmap& contents) { |
| 91 delegate_->CompositorContentsChanged(contents); |
| 92 } |
| 93 |
| 94 //////////////////////////////////////////////////////////////////////////////// |
| 95 // WindowTreeHostMojo, aura::WindowTreeHost implementation: |
| 96 |
| 97 ui::EventSource* WindowTreeHostMojo::GetEventSource() { |
| 98 return this; |
| 99 } |
| 100 |
| 101 gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() { |
| 102 NOTIMPLEMENTED() << "GetAcceleratedWidget"; |
| 103 return gfx::kNullAcceleratedWidget; |
| 104 } |
| 105 |
| 106 void WindowTreeHostMojo::Show() { |
| 107 window()->Show(); |
| 108 } |
| 109 |
| 110 void WindowTreeHostMojo::Hide() { |
| 111 } |
| 112 |
| 113 gfx::Rect WindowTreeHostMojo::GetBounds() const { |
| 114 return bounds_; |
| 115 } |
| 116 |
| 117 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) { |
| 118 } |
| 119 |
| 120 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const { |
| 121 return gfx::Point(0, 0); |
| 122 } |
| 123 |
| 124 void WindowTreeHostMojo::SetCapture() { |
| 125 NOTIMPLEMENTED(); |
| 126 } |
| 127 |
| 128 void WindowTreeHostMojo::ReleaseCapture() { |
| 129 NOTIMPLEMENTED(); |
| 130 } |
| 131 |
| 132 void WindowTreeHostMojo::PostNativeEvent( |
| 133 const base::NativeEvent& native_event) { |
| 134 NOTIMPLEMENTED(); |
| 135 } |
| 136 |
| 137 void WindowTreeHostMojo::OnDeviceScaleFactorChanged( |
| 138 float device_scale_factor) { |
| 139 NOTIMPLEMENTED(); |
| 140 } |
| 141 |
| 142 void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) { |
| 143 NOTIMPLEMENTED(); |
| 144 } |
| 145 |
| 146 void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) { |
| 147 NOTIMPLEMENTED(); |
| 148 } |
| 149 |
| 150 void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) { |
| 151 NOTIMPLEMENTED(); |
| 152 } |
| 153 |
| 154 //////////////////////////////////////////////////////////////////////////////// |
| 155 // WindowTreeHostMojo, ui::EventSource implementation: |
| 156 |
| 157 ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() { |
| 158 return dispatcher(); |
| 159 } |
| 160 |
| 161 } // namespace mojo |
OLD | NEW |