| 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/public/cpp/view.h" | 5 #include "mojo/services/view_manager/public/cpp/view.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 | 8 |
| 9 #include "mojo/public/cpp/application/service_provider_impl.h" | 9 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 10 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h" | 10 #include "mojo/services/view_manager/public/cpp/lib/view_manager_client_impl.h" |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 bool OwnsView(ViewManager* manager, View* view) { | 174 bool OwnsView(ViewManager* manager, View* view) { |
| 175 return !manager || | 175 return !manager || |
| 176 static_cast<ViewManagerClientImpl*>(manager)->OwnsView(view->id()); | 176 static_cast<ViewManagerClientImpl*>(manager)->OwnsView(view->id()); |
| 177 } | 177 } |
| 178 | 178 |
| 179 } // namespace | 179 } // namespace |
| 180 | 180 |
| 181 //////////////////////////////////////////////////////////////////////////////// | 181 //////////////////////////////////////////////////////////////////////////////// |
| 182 // View, public: | 182 // View, public: |
| 183 | 183 |
| 184 // static | |
| 185 View* View::Create(ViewManager* view_manager) { | |
| 186 View* view = new View(view_manager); | |
| 187 static_cast<ViewManagerClientImpl*>(view_manager)->AddView(view); | |
| 188 return view; | |
| 189 } | |
| 190 | |
| 191 void View::Destroy() { | 184 void View::Destroy() { |
| 192 if (!OwnsView(manager_, this)) | 185 if (!OwnsView(manager_, this)) |
| 193 return; | 186 return; |
| 194 | 187 |
| 195 if (manager_) | 188 if (manager_) |
| 196 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); | 189 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); |
| 197 while (!children_.empty()) { | 190 while (!children_.empty()) { |
| 198 View* child = children_.front(); | 191 View* child = children_.front(); |
| 199 if (!OwnsView(manager_, child)) { | 192 if (!OwnsView(manager_, child)) { |
| 200 ViewPrivate(child).ClearParent(); | 193 ViewPrivate(child).ClearParent(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 const View* root = this; | 270 const View* root = this; |
| 278 for (const View* parent = this; parent; parent = parent->parent()) | 271 for (const View* parent = this; parent; parent = parent->parent()) |
| 279 root = parent; | 272 root = parent; |
| 280 return root; | 273 return root; |
| 281 } | 274 } |
| 282 | 275 |
| 283 void View::AddChild(View* child) { | 276 void View::AddChild(View* child) { |
| 284 // TODO(beng): not necessarily valid to all connections, but possibly to the | 277 // TODO(beng): not necessarily valid to all connections, but possibly to the |
| 285 // embeddee in an embedder-embeddee relationship. | 278 // embeddee in an embedder-embeddee relationship. |
| 286 if (manager_) | 279 if (manager_) |
| 287 CHECK_EQ(ViewPrivate(child).view_manager(), manager_); | 280 CHECK_EQ(child->view_manager(), manager_); |
| 288 LocalAddChild(child); | 281 LocalAddChild(child); |
| 289 if (manager_) | 282 if (manager_) |
| 290 static_cast<ViewManagerClientImpl*>(manager_)->AddChild(child->id(), id_); | 283 static_cast<ViewManagerClientImpl*>(manager_)->AddChild(child->id(), id_); |
| 291 } | 284 } |
| 292 | 285 |
| 293 void View::RemoveChild(View* child) { | 286 void View::RemoveChild(View* child) { |
| 294 // TODO(beng): not necessarily valid to all connections, but possibly to the | 287 // TODO(beng): not necessarily valid to all connections, but possibly to the |
| 295 // embeddee in an embedder-embeddee relationship. | 288 // embeddee in an embedder-embeddee relationship. |
| 296 if (manager_) | 289 if (manager_) |
| 297 CHECK_EQ(ViewPrivate(child).view_manager(), manager_); | 290 CHECK_EQ(child->view_manager(), manager_); |
| 298 LocalRemoveChild(child); | 291 LocalRemoveChild(child); |
| 299 if (manager_) { | 292 if (manager_) { |
| 300 static_cast<ViewManagerClientImpl*>(manager_)->RemoveChild(child->id(), | 293 static_cast<ViewManagerClientImpl*>(manager_)->RemoveChild(child->id(), |
| 301 id_); | 294 id_); |
| 302 } | 295 } |
| 303 } | 296 } |
| 304 | 297 |
| 305 void View::MoveToFront() { | 298 void View::MoveToFront() { |
| 306 if (!parent_ || parent_->children_.back() == this) | 299 if (!parent_ || parent_->children_.back() == this) |
| 307 return; | 300 return; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 323 direction); | 316 direction); |
| 324 } | 317 } |
| 325 } | 318 } |
| 326 | 319 |
| 327 bool View::Contains(View* child) const { | 320 bool View::Contains(View* child) const { |
| 328 if (!child) | 321 if (!child) |
| 329 return false; | 322 return false; |
| 330 if (child == this) | 323 if (child == this) |
| 331 return true; | 324 return true; |
| 332 if (manager_) | 325 if (manager_) |
| 333 CHECK_EQ(ViewPrivate(child).view_manager(), manager_); | 326 CHECK_EQ(child->view_manager(), manager_); |
| 334 for (View* p = child->parent(); p; p = p->parent()) { | 327 for (View* p = child->parent(); p; p = p->parent()) { |
| 335 if (p == this) | 328 if (p == this) |
| 336 return true; | 329 return true; |
| 337 } | 330 } |
| 338 return false; | 331 return false; |
| 339 } | 332 } |
| 340 | 333 |
| 341 View* View::GetChildById(Id id) { | 334 View* View::GetChildById(Id id) { |
| 342 if (id == id_) | 335 if (id == id_) |
| 343 return this; | 336 return this; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 (*pair.second.deallocator)(pair.second.value); | 409 (*pair.second.deallocator)(pair.second.value); |
| 417 } | 410 } |
| 418 prop_map_.clear(); | 411 prop_map_.clear(); |
| 419 | 412 |
| 420 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); | 413 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); |
| 421 } | 414 } |
| 422 | 415 |
| 423 //////////////////////////////////////////////////////////////////////////////// | 416 //////////////////////////////////////////////////////////////////////////////// |
| 424 // View, private: | 417 // View, private: |
| 425 | 418 |
| 426 View::View(ViewManager* manager) | 419 View::View(ViewManager* manager, Id id) |
| 427 : manager_(manager), | 420 : manager_(manager), |
| 428 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateView()), | 421 id_(id), |
| 429 parent_(NULL), | 422 parent_(nullptr), |
| 430 visible_(false), | 423 visible_(false), |
| 431 drawn_(false) { | 424 drawn_(false) { |
| 432 } | 425 } |
| 433 | 426 |
| 434 int64 View::SetLocalPropertyInternal(const void* key, | 427 int64 View::SetLocalPropertyInternal(const void* key, |
| 435 const char* name, | 428 const char* name, |
| 436 PropertyDeallocator deallocator, | 429 PropertyDeallocator deallocator, |
| 437 int64 value, | 430 int64 value, |
| 438 int64 default_value) { | 431 int64 default_value) { |
| 439 int64 old = GetLocalPropertyInternal(key, default_value); | 432 int64 old = GetLocalPropertyInternal(key, default_value); |
| (...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 548 void View::NotifyViewVisibilityChangedUp(View* target) { | 541 void View::NotifyViewVisibilityChangedUp(View* target) { |
| 549 // Start with the parent as we already notified |this| | 542 // Start with the parent as we already notified |this| |
| 550 // in NotifyViewVisibilityChangedDown. | 543 // in NotifyViewVisibilityChangedDown. |
| 551 for (View* view = parent(); view; view = view->parent()) { | 544 for (View* view = parent(); view; view = view->parent()) { |
| 552 bool ret = view->NotifyViewVisibilityChangedAtReceiver(target); | 545 bool ret = view->NotifyViewVisibilityChangedAtReceiver(target); |
| 553 DCHECK(ret); | 546 DCHECK(ret); |
| 554 } | 547 } |
| 555 } | 548 } |
| 556 | 549 |
| 557 } // namespace mojo | 550 } // namespace mojo |
| OLD | NEW |