| 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/service_provider_impl.h" | 7 #include "mojo/public/cpp/application/service_provider_impl.h" |
| 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" | 8 #include "mojo/services/public/cpp/view_manager/lib/view_manager_client_impl.h" |
| 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" | 9 #include "mojo/services/public/cpp/view_manager/lib/view_private.h" |
| 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" | 10 #include "mojo/services/public/cpp/view_manager/view_observer.h" |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 137 : (child_i < target_i ? target_i - 1 : target_i); | 137 : (child_i < target_i ? target_i - 1 : target_i); |
| 138 children->erase(children->begin() + child_i); | 138 children->erase(children->begin() + child_i); |
| 139 children->insert(children->begin() + dest_i, view); | 139 children->insert(children->begin() + dest_i, view); |
| 140 | 140 |
| 141 return true; | 141 return true; |
| 142 } | 142 } |
| 143 | 143 |
| 144 class ScopedSetBoundsNotifier { | 144 class ScopedSetBoundsNotifier { |
| 145 public: | 145 public: |
| 146 ScopedSetBoundsNotifier(View* view, | 146 ScopedSetBoundsNotifier(View* view, |
| 147 const gfx::Rect& old_bounds, | 147 const Rect& old_bounds, |
| 148 const gfx::Rect& new_bounds) | 148 const Rect& new_bounds) |
| 149 : view_(view), | 149 : view_(view), |
| 150 old_bounds_(old_bounds), | 150 old_bounds_(old_bounds), |
| 151 new_bounds_(new_bounds) { | 151 new_bounds_(new_bounds) { |
| 152 FOR_EACH_OBSERVER(ViewObserver, | 152 FOR_EACH_OBSERVER(ViewObserver, |
| 153 *ViewPrivate(view_).observers(), | 153 *ViewPrivate(view_).observers(), |
| 154 OnViewBoundsChanging(view_, old_bounds_, new_bounds_)); | 154 OnViewBoundsChanging(view_, old_bounds_, new_bounds_)); |
| 155 } | 155 } |
| 156 ~ScopedSetBoundsNotifier() { | 156 ~ScopedSetBoundsNotifier() { |
| 157 FOR_EACH_OBSERVER(ViewObserver, | 157 FOR_EACH_OBSERVER(ViewObserver, |
| 158 *ViewPrivate(view_).observers(), | 158 *ViewPrivate(view_).observers(), |
| 159 OnViewBoundsChanged(view_, old_bounds_, new_bounds_)); | 159 OnViewBoundsChanged(view_, old_bounds_, new_bounds_)); |
| 160 } | 160 } |
| 161 | 161 |
| 162 private: | 162 private: |
| 163 View* view_; | 163 View* view_; |
| 164 const gfx::Rect old_bounds_; | 164 const Rect old_bounds_; |
| 165 const gfx::Rect new_bounds_; | 165 const Rect new_bounds_; |
| 166 | 166 |
| 167 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); | 167 DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); |
| 168 }; | 168 }; |
| 169 | 169 |
| 170 // Some operations are only permitted in the connection that created the view. | 170 // Some operations are only permitted in the connection that created the view. |
| 171 bool OwnsView(ViewManager* manager, View* view) { | 171 bool OwnsView(ViewManager* manager, View* view) { |
| 172 return !manager || | 172 return !manager || |
| 173 static_cast<ViewManagerClientImpl*>(manager)->OwnsView(view->id()); | 173 static_cast<ViewManagerClientImpl*>(manager)->OwnsView(view->id()); |
| 174 } | 174 } |
| 175 | 175 |
| (...skipping 22 matching lines...) Expand all Loading... |
| 198 children_.erase(children_.begin()); | 198 children_.erase(children_.begin()); |
| 199 } else { | 199 } else { |
| 200 child->Destroy(); | 200 child->Destroy(); |
| 201 DCHECK(std::find(children_.begin(), children_.end(), child) == | 201 DCHECK(std::find(children_.begin(), children_.end(), child) == |
| 202 children_.end()); | 202 children_.end()); |
| 203 } | 203 } |
| 204 } | 204 } |
| 205 LocalDestroy(); | 205 LocalDestroy(); |
| 206 } | 206 } |
| 207 | 207 |
| 208 void View::SetBounds(const gfx::Rect& bounds) { | 208 void View::SetBounds(const Rect& bounds) { |
| 209 if (!OwnsView(manager_, this)) | 209 if (!OwnsView(manager_, this)) |
| 210 return; | 210 return; |
| 211 | 211 |
| 212 if (manager_) | 212 if (manager_) |
| 213 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds); | 213 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds); |
| 214 LocalSetBounds(bounds_, bounds); | 214 LocalSetBounds(bounds_, bounds); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void View::SetVisible(bool value) { | 217 void View::SetVisible(bool value) { |
| 218 if (visible_ == value) | 218 if (visible_ == value) |
| (...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 void View::LocalRemoveChild(View* child) { | 384 void View::LocalRemoveChild(View* child) { |
| 385 DCHECK_EQ(this, child->parent()); | 385 DCHECK_EQ(this, child->parent()); |
| 386 ScopedTreeNotifier notifier(child, this, NULL); | 386 ScopedTreeNotifier notifier(child, this, NULL); |
| 387 RemoveChildImpl(child, &children_); | 387 RemoveChildImpl(child, &children_); |
| 388 } | 388 } |
| 389 | 389 |
| 390 bool View::LocalReorder(View* relative, OrderDirection direction) { | 390 bool View::LocalReorder(View* relative, OrderDirection direction) { |
| 391 return ReorderImpl(&parent_->children_, this, relative, direction); | 391 return ReorderImpl(&parent_->children_, this, relative, direction); |
| 392 } | 392 } |
| 393 | 393 |
| 394 void View::LocalSetBounds(const gfx::Rect& old_bounds, | 394 void View::LocalSetBounds(const Rect& old_bounds, |
| 395 const gfx::Rect& new_bounds) { | 395 const Rect& new_bounds) { |
| 396 DCHECK(old_bounds == bounds_); | 396 DCHECK(old_bounds.x == bounds_.x); |
| 397 DCHECK(old_bounds.y == bounds_.y); |
| 398 DCHECK(old_bounds.width == bounds_.width); |
| 399 DCHECK(old_bounds.height == bounds_.height); |
| 397 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); | 400 ScopedSetBoundsNotifier notifier(this, old_bounds, new_bounds); |
| 398 bounds_ = new_bounds; | 401 bounds_ = new_bounds; |
| 399 } | 402 } |
| 400 | 403 |
| 401 void View::LocalSetDrawn(bool value) { | 404 void View::LocalSetDrawn(bool value) { |
| 402 if (drawn_ == value) | 405 if (drawn_ == value) |
| 403 return; | 406 return; |
| 404 | 407 |
| 405 // As IsDrawn() is derived from |visible_| and |drawn_|, only send drawn | 408 // As IsDrawn() is derived from |visible_| and |drawn_|, only send drawn |
| 406 // notification is the value of IsDrawn() is really changing. | 409 // notification is the value of IsDrawn() is really changing. |
| 407 if (IsDrawn() == value) { | 410 if (IsDrawn() == value) { |
| 408 drawn_ = value; | 411 drawn_ = value; |
| 409 return; | 412 return; |
| 410 } | 413 } |
| 411 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); | 414 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanging(this)); |
| 412 drawn_ = value; | 415 drawn_ = value; |
| 413 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); | 416 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDrawnChanged(this)); |
| 414 } | 417 } |
| 415 | 418 |
| 416 } // namespace mojo | 419 } // namespace mojo |
| OLD | NEW |