[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / mojo / aura / window_tree_host_mojo.cc
blob0b67e54f5c9520c5f1ef4b722a070c66e2a8fb35
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.
5 #include "mojo/aura/window_tree_host_mojo.h"
7 #include <vector>
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"
16 namespace mojo {
17 namespace {
19 const char kTreeHostsKey[] = "tree_hosts";
21 typedef std::vector<WindowTreeHostMojo*> Managers;
23 class TreeHosts : public base::SupportsUserData::Data {
24 public:
25 TreeHosts() {}
26 virtual ~TreeHosts() {}
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);
35 return hosts;
38 void Add(WindowTreeHostMojo* manager) {
39 managers_.push_back(manager);
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);
49 const std::vector<WindowTreeHostMojo*> managers() const {
50 return managers_;
53 private:
54 Managers managers_;
56 DISALLOW_COPY_AND_ASSIGN(TreeHosts);
59 } // namespace
61 ////////////////////////////////////////////////////////////////////////////////
62 // WindowTreeHostMojo, public:
64 WindowTreeHostMojo::WindowTreeHostMojo(view_manager::Node* node,
65 WindowTreeHostMojoDelegate* delegate)
66 : node_(node),
67 bounds_(node->bounds()),
68 delegate_(delegate) {
69 node_->AddObserver(this);
70 CreateCompositor(GetAcceleratedWidget());
72 TreeHosts::Get()->Add(this);
75 WindowTreeHostMojo::~WindowTreeHostMojo() {
76 node_->RemoveObserver(this);
77 TreeHosts::Get()->Remove(this);
78 DestroyCompositor();
79 DestroyDispatcher();
82 // static
83 WindowTreeHostMojo* WindowTreeHostMojo::ForCompositor(
84 ui::Compositor* compositor) {
85 const Managers& managers = TreeHosts::Get()->managers();
86 for (size_t i = 0; i < managers.size(); ++i) {
87 if (managers[i]->compositor() == compositor)
88 return managers[i];
90 return NULL;
93 void WindowTreeHostMojo::SetContents(const SkBitmap& contents) {
94 delegate_->CompositorContentsChanged(contents);
97 ////////////////////////////////////////////////////////////////////////////////
98 // WindowTreeHostMojo, aura::WindowTreeHost implementation:
100 ui::EventSource* WindowTreeHostMojo::GetEventSource() {
101 return this;
104 gfx::AcceleratedWidget WindowTreeHostMojo::GetAcceleratedWidget() {
105 return gfx::kNullAcceleratedWidget;
108 void WindowTreeHostMojo::Show() {
109 window()->Show();
112 void WindowTreeHostMojo::Hide() {
115 gfx::Rect WindowTreeHostMojo::GetBounds() const {
116 return bounds_;
119 void WindowTreeHostMojo::SetBounds(const gfx::Rect& bounds) {
120 window()->SetBounds(gfx::Rect(bounds.size()));
123 gfx::Point WindowTreeHostMojo::GetLocationOnNativeScreen() const {
124 return gfx::Point(0, 0);
127 void WindowTreeHostMojo::SetCapture() {
128 NOTIMPLEMENTED();
131 void WindowTreeHostMojo::ReleaseCapture() {
132 NOTIMPLEMENTED();
135 void WindowTreeHostMojo::PostNativeEvent(
136 const base::NativeEvent& native_event) {
137 NOTIMPLEMENTED();
140 void WindowTreeHostMojo::SetCursorNative(gfx::NativeCursor cursor) {
141 NOTIMPLEMENTED();
144 void WindowTreeHostMojo::MoveCursorToNative(const gfx::Point& location) {
145 NOTIMPLEMENTED();
148 void WindowTreeHostMojo::OnCursorVisibilityChangedNative(bool show) {
149 NOTIMPLEMENTED();
152 ////////////////////////////////////////////////////////////////////////////////
153 // WindowTreeHostMojo, ui::EventSource implementation:
155 ui::EventProcessor* WindowTreeHostMojo::GetEventProcessor() {
156 return dispatcher();
159 ////////////////////////////////////////////////////////////////////////////////
160 // WindowTreeHostMojo, view_manager::NodeObserver implementation:
162 void WindowTreeHostMojo::OnNodeBoundsChanged(
163 view_manager::Node* node,
164 const gfx::Rect& old_bounds,
165 const gfx::Rect& new_bounds) {
166 bounds_ = new_bounds;
167 if (old_bounds.origin() != new_bounds.origin())
168 OnHostMoved(bounds_.origin());
169 if (old_bounds.size() != new_bounds.size())
170 OnHostResized(bounds_.size());
173 } // namespace mojo