| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "mojo/services/view_manager/node.h" | 5 #include "mojo/services/view_manager/node.h" |
| 6 | 6 |
| 7 #include "mojo/services/view_manager/node_delegate.h" | 7 #include "mojo/services/view_manager/node_delegate.h" |
| 8 #include "mojo/services/view_manager/view.h" | 8 #include "mojo/services/view_manager/view.h" |
| 9 #include "ui/aura/window_property.h" | 9 #include "ui/aura/window_property.h" |
| 10 #include "ui/base/cursor/cursor.h" | |
| 11 #include "ui/base/hit_test.h" | |
| 12 #include "ui/gfx/canvas.h" | |
| 13 #include "ui/gfx/image/image_skia.h" | |
| 14 #include "ui/gfx/native_widget_types.h" | |
| 15 | 10 |
| 16 DECLARE_WINDOW_PROPERTY_TYPE(mojo::services::view_manager::Node*); | 11 DECLARE_WINDOW_PROPERTY_TYPE(mojo::services::view_manager::Node*); |
| 17 | 12 |
| 18 namespace mojo { | 13 namespace mojo { |
| 19 namespace services { | 14 namespace services { |
| 20 namespace view_manager { | 15 namespace view_manager { |
| 21 | 16 |
| 22 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL); | 17 DEFINE_WINDOW_PROPERTY_KEY(Node*, kNodeKey, NULL); |
| 23 | 18 |
| 24 Node::Node(NodeDelegate* delegate, const NodeId& id) | 19 Node::Node(NodeDelegate* delegate, const NodeId& id) |
| 25 : delegate_(delegate), | 20 : delegate_(delegate), |
| 26 id_(id), | 21 id_(id), |
| 27 view_(NULL), | 22 view_(NULL), |
| 28 window_(this) { | 23 window_(NULL) { |
| 29 DCHECK(delegate); // Must provide a delegate. | 24 DCHECK(delegate); // Must provide a delegate. |
| 30 window_.set_owned_by_parent(false); | 25 window_.set_owned_by_parent(false); |
| 31 window_.AddObserver(this); | 26 window_.AddObserver(this); |
| 32 window_.SetProperty(kNodeKey, this); | 27 window_.SetProperty(kNodeKey, this); |
| 33 window_.Init(aura::WINDOW_LAYER_TEXTURED); | |
| 34 | |
| 35 // TODO(sky): this likely needs to be false and add a visibility API. | |
| 36 window_.Show(); | |
| 37 } | 28 } |
| 38 | 29 |
| 39 Node::~Node() { | 30 Node::~Node() { |
| 40 SetView(NULL); | 31 SetView(NULL); |
| 41 } | 32 } |
| 42 | 33 |
| 43 Node* Node::GetParent() { | 34 Node* Node::GetParent() { |
| 44 if (!window_.parent()) | 35 if (!window_.parent()) |
| 45 return NULL; | 36 return NULL; |
| 46 return window_.parent()->GetProperty(kNodeKey); | 37 return window_.parent()->GetProperty(kNodeKey); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 view->set_node(this); | 73 view->set_node(this); |
| 83 } | 74 } |
| 84 delegate_->OnNodeViewReplaced(id_, view_id, old_view_id); | 75 delegate_->OnNodeViewReplaced(id_, view_id, old_view_id); |
| 85 } | 76 } |
| 86 | 77 |
| 87 void Node::OnWindowHierarchyChanged( | 78 void Node::OnWindowHierarchyChanged( |
| 88 const aura::WindowObserver::HierarchyChangeParams& params) { | 79 const aura::WindowObserver::HierarchyChangeParams& params) { |
| 89 if (params.target != &window_ || params.receiver != &window_) | 80 if (params.target != &window_ || params.receiver != &window_) |
| 90 return; | 81 return; |
| 91 NodeId new_parent_id; | 82 NodeId new_parent_id; |
| 92 if (params.new_parent && params.new_parent->GetProperty(kNodeKey)) | 83 if (params.new_parent) |
| 93 new_parent_id = params.new_parent->GetProperty(kNodeKey)->id(); | 84 new_parent_id = params.new_parent->GetProperty(kNodeKey)->id(); |
| 94 NodeId old_parent_id; | 85 NodeId old_parent_id; |
| 95 if (params.old_parent && params.old_parent->GetProperty(kNodeKey)) | 86 if (params.old_parent) |
| 96 old_parent_id = params.old_parent->GetProperty(kNodeKey)->id(); | 87 old_parent_id = params.old_parent->GetProperty(kNodeKey)->id(); |
| 97 delegate_->OnNodeHierarchyChanged(id_, new_parent_id, old_parent_id); | 88 delegate_->OnNodeHierarchyChanged(id_, new_parent_id, old_parent_id); |
| 98 } | 89 } |
| 99 | 90 |
| 100 gfx::Size Node::GetMinimumSize() const { | |
| 101 return gfx::Size(); | |
| 102 } | |
| 103 | |
| 104 gfx::Size Node::GetMaximumSize() const { | |
| 105 return gfx::Size(); | |
| 106 } | |
| 107 | |
| 108 void Node::OnBoundsChanged(const gfx::Rect& old_bounds, | |
| 109 const gfx::Rect& new_bounds) { | |
| 110 } | |
| 111 | |
| 112 gfx::NativeCursor Node::GetCursor(const gfx::Point& point) { | |
| 113 return gfx::kNullCursor; | |
| 114 } | |
| 115 | |
| 116 int Node::GetNonClientComponent(const gfx::Point& point) const { | |
| 117 return HTCAPTION; | |
| 118 } | |
| 119 | |
| 120 bool Node::ShouldDescendIntoChildForEventHandling( | |
| 121 aura::Window* child, | |
| 122 const gfx::Point& location) { | |
| 123 return true; | |
| 124 } | |
| 125 | |
| 126 bool Node::CanFocus() { | |
| 127 return true; | |
| 128 } | |
| 129 | |
| 130 void Node::OnCaptureLost() { | |
| 131 } | |
| 132 | |
| 133 void Node::OnPaint(gfx::Canvas* canvas) { | |
| 134 if (view_) { | |
| 135 canvas->DrawImageInt( | |
| 136 gfx::ImageSkia::CreateFrom1xBitmap(view_->bitmap()), 0, 0); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 void Node::OnDeviceScaleFactorChanged(float device_scale_factor) { | |
| 141 } | |
| 142 | |
| 143 void Node::OnWindowDestroying(aura::Window* window) { | |
| 144 } | |
| 145 | |
| 146 void Node::OnWindowDestroyed(aura::Window* window) { | |
| 147 } | |
| 148 | |
| 149 void Node::OnWindowTargetVisibilityChanged(bool visible) { | |
| 150 } | |
| 151 | |
| 152 bool Node::HasHitTestMask() const { | |
| 153 return false; | |
| 154 } | |
| 155 | |
| 156 void Node::GetHitTestMask(gfx::Path* mask) const { | |
| 157 } | |
| 158 | |
| 159 } // namespace view_manager | 91 } // namespace view_manager |
| 160 } // namespace services | 92 } // namespace services |
| 161 } // namespace mojo | 93 } // namespace mojo |
| OLD | NEW |