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/public/cpp/view_manager/view.h" | 5 #include "mojo/services/public/cpp/view_manager/view.h" |
6 | 6 |
7 #include "mojo/public/cpp/application/connect.h" | 7 #include "mojo/public/cpp/application/connect.h" |
8 #include "mojo/public/cpp/application/service_provider_impl.h" | 8 #include "mojo/public/cpp/application/service_provider_impl.h" |
9 #include "mojo/public/interfaces/application/shell.mojom.h" | 9 #include "mojo/public/interfaces/application/shell.mojom.h" |
10 #include "mojo/services/public/cpp/view_manager/lib/bitmap_uploader.h" | 10 #include "mojo/services/public/cpp/view_manager/lib/bitmap_uploader.h" |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 void View::SetBounds(const gfx::Rect& bounds) { | 214 void View::SetBounds(const gfx::Rect& bounds) { |
215 if (!OwnsView(manager_, this)) | 215 if (!OwnsView(manager_, this)) |
216 return; | 216 return; |
217 | 217 |
218 if (manager_) | 218 if (manager_) |
219 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds); | 219 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds); |
220 LocalSetBounds(bounds_, bounds); | 220 LocalSetBounds(bounds_, bounds); |
221 } | 221 } |
222 | 222 |
223 void View::SetVisible(bool value) { | 223 void View::SetVisible(bool value) { |
| 224 if (visible_ == value) |
| 225 return; |
| 226 |
224 if (manager_) | 227 if (manager_) |
225 static_cast<ViewManagerClientImpl*>(manager_)->SetVisible(id_, value); | 228 static_cast<ViewManagerClientImpl*>(manager_)->SetVisible(id_, value); |
| 229 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanging(this)); |
| 230 visible_ = value; |
| 231 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewVisibilityChanged(this)); |
| 232 } |
| 233 |
| 234 bool View::IsDrawn() const { |
| 235 if (!visible_) |
| 236 return false; |
| 237 return parent_ ? parent_->IsDrawn() : drawn_; |
226 } | 238 } |
227 | 239 |
228 void View::AddObserver(ViewObserver* observer) { | 240 void View::AddObserver(ViewObserver* observer) { |
229 observers_.AddObserver(observer); | 241 observers_.AddObserver(observer); |
230 } | 242 } |
231 | 243 |
232 void View::RemoveObserver(ViewObserver* observer) { | 244 void View::RemoveObserver(ViewObserver* observer) { |
233 observers_.RemoveObserver(observer); | 245 observers_.RemoveObserver(observer); |
234 } | 246 } |
235 | 247 |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 static_cast<ViewManagerClientImpl*>(manager_)->Embed(url, id_, sp.Pass()); | 359 static_cast<ViewManagerClientImpl*>(manager_)->Embed(url, id_, sp.Pass()); |
348 return imported_services.Pass(); | 360 return imported_services.Pass(); |
349 } | 361 } |
350 | 362 |
351 //////////////////////////////////////////////////////////////////////////////// | 363 //////////////////////////////////////////////////////////////////////////////// |
352 // View, protected: | 364 // View, protected: |
353 | 365 |
354 View::View() | 366 View::View() |
355 : manager_(NULL), | 367 : manager_(NULL), |
356 id_(static_cast<Id>(-1)), | 368 id_(static_cast<Id>(-1)), |
357 parent_(NULL) {} | 369 parent_(NULL), |
| 370 visible_(true), |
| 371 drawn_(false) { |
| 372 } |
358 | 373 |
359 View::~View() { | 374 View::~View() { |
360 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); | 375 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroying(this)); |
361 if (parent_) | 376 if (parent_) |
362 parent_->LocalRemoveChild(this); | 377 parent_->LocalRemoveChild(this); |
363 // TODO(beng): It'd be better to do this via a destruction observer in the | 378 // TODO(beng): It'd be better to do this via a destruction observer in the |
364 // ViewManagerClientImpl. | 379 // ViewManagerClientImpl. |
365 if (manager_) | 380 if (manager_) |
366 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); | 381 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); |
367 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); | 382 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); |
368 } | 383 } |
369 | 384 |
370 //////////////////////////////////////////////////////////////////////////////// | 385 //////////////////////////////////////////////////////////////////////////////// |
371 // View, private: | 386 // View, private: |
372 | 387 |
373 View::View(ViewManager* manager) | 388 View::View(ViewManager* manager) |
374 : manager_(manager), | 389 : manager_(manager), |
375 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateView()), | 390 id_(static_cast<ViewManagerClientImpl*>(manager_)->CreateView()), |
376 parent_(NULL) {} | 391 parent_(NULL), |
| 392 visible_(true), |
| 393 drawn_(false) { |
| 394 } |
377 | 395 |
378 void View::LocalDestroy() { | 396 void View::LocalDestroy() { |
379 delete this; | 397 delete this; |
380 } | 398 } |
381 | 399 |
382 void View::LocalAddChild(View* child) { | 400 void View::LocalAddChild(View* child) { |
383 ScopedTreeNotifier notifier(child, child->parent(), this); | 401 ScopedTreeNotifier notifier(child, child->parent(), this); |
384 if (child->parent()) | 402 if (child->parent()) |
385 RemoveChildImpl(child, &child->parent_->children_); | 403 RemoveChildImpl(child, &child->parent_->children_); |
386 children_.push_back(child); | 404 children_.push_back(child); |
(...skipping 10 matching lines...) Expand all Loading... |
397 return ReorderImpl(&parent_->children_, this, relative, direction); | 415 return ReorderImpl(&parent_->children_, this, relative, direction); |
398 } | 416 } |
399 | 417 |
400 void View::LocalSetBounds(const gfx::Rect& old_bounds, | 418 void View::LocalSetBounds(const gfx::Rect& old_bounds, |
401 const gfx::Rect& new_bounds) { | 419 const gfx::Rect& new_bounds) { |
402 DCHECK(old_bounds == bounds_); | 420 DCHECK(old_bounds == bounds_); |
403 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 421 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
404 bounds_ = new_bounds; | 422 bounds_ = new_bounds; |
405 } | 423 } |
406 | 424 |
| 425 void View::LocalSetDrawn(bool value) { |
| 426 if (drawn_ == value) |
| 427 return; |
| 428 |
| 429 // As IsDrawn() is derived from |visible_| and |drawn_|, only send drawn |
| 430 // notification is the value of IsDrawn() is really changing. |
| 431 if (IsDrawn() == value) { |
| 432 drawn_ = value; |
| 433 return; |
| 434 } |
| 435 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); |
| 436 drawn_ = value; |
| 437 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); |
| 438 } |
| 439 |
407 void View::CreateBitmapUploader() { | 440 void View::CreateBitmapUploader() { |
408 ViewManagerClientImpl* vmci = static_cast<ViewManagerClientImpl*>(manager_); | 441 ViewManagerClientImpl* vmci = static_cast<ViewManagerClientImpl*>(manager_); |
409 SurfacesServicePtr surfaces_service; | 442 SurfacesServicePtr surfaces_service; |
410 InterfacePtr<ServiceProvider> surfaces_service_provider; | 443 InterfacePtr<ServiceProvider> surfaces_service_provider; |
411 vmci->shell()->ConnectToApplication("mojo:mojo_surfaces_service", | 444 vmci->shell()->ConnectToApplication("mojo:mojo_surfaces_service", |
412 Get(&surfaces_service_provider)); | 445 Get(&surfaces_service_provider)); |
413 ConnectToService(surfaces_service_provider.get(), &surfaces_service); | 446 ConnectToService(surfaces_service_provider.get(), &surfaces_service); |
414 GpuPtr gpu_service; | 447 GpuPtr gpu_service; |
415 InterfacePtr<ServiceProvider> gpu_service_provider; | 448 InterfacePtr<ServiceProvider> gpu_service_provider; |
416 vmci->shell()->ConnectToApplication("mojo:mojo_native_viewport_service", | 449 vmci->shell()->ConnectToApplication("mojo:mojo_native_viewport_service", |
417 Get(&gpu_service_provider)); | 450 Get(&gpu_service_provider)); |
418 ConnectToService(gpu_service_provider.get(), &gpu_service); | 451 ConnectToService(gpu_service_provider.get(), &gpu_service); |
419 bitmap_uploader_.reset(new BitmapUploader( | 452 bitmap_uploader_.reset(new BitmapUploader( |
420 vmci, id_, surfaces_service.Pass(), gpu_service.Pass())); | 453 vmci, id_, surfaces_service.Pass(), gpu_service.Pass())); |
421 } | 454 } |
422 | 455 |
423 } // namespace mojo | 456 } // namespace mojo |
OLD | NEW |