Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(190)

Side by Side Diff: components/view_manager/public/cpp/lib/view.cc

Issue 1314953002: Rename ViewManagerService,ViewManagerClient -> ViewTree,ViewTreeClient (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: . Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "components/view_manager/public/cpp/view.h" 5 #include "components/view_manager/public/cpp/view.h"
6 6
7 #include <set> 7 #include <set>
8 #include <string> 8 #include <string>
9 9
10 #include "components/view_manager/public/cpp/lib/view_manager_client_impl.h"
11 #include "components/view_manager/public/cpp/lib/view_private.h" 10 #include "components/view_manager/public/cpp/lib/view_private.h"
11 #include "components/view_manager/public/cpp/lib/view_tree_client_impl.h"
12 #include "components/view_manager/public/cpp/view_observer.h" 12 #include "components/view_manager/public/cpp/view_observer.h"
13 #include "components/view_manager/public/cpp/view_tracker.h" 13 #include "components/view_manager/public/cpp/view_tracker.h"
14 #include "mojo/application/public/cpp/service_provider_impl.h" 14 #include "mojo/application/public/cpp/service_provider_impl.h"
15 15
16 namespace mojo { 16 namespace mojo {
17 17
18 namespace { 18 namespace {
19 19
20 void NotifyViewTreeChangeAtReceiver( 20 void NotifyViewTreeChangeAtReceiver(
21 View* receiver, 21 View* receiver,
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 View* view_; 167 View* view_;
168 const Rect old_bounds_; 168 const Rect old_bounds_;
169 const Rect new_bounds_; 169 const Rect new_bounds_;
170 170
171 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier); 171 MOJO_DISALLOW_COPY_AND_ASSIGN(ScopedSetBoundsNotifier);
172 }; 172 };
173 173
174 // Some operations are only permitted in the connection that created the view. 174 // Some operations are only permitted in the connection that created the view.
175 bool OwnsView(ViewManager* manager, View* view) { 175 bool OwnsView(ViewManager* manager, View* view) {
176 return !manager || 176 return !manager ||
177 static_cast<ViewManagerClientImpl*>(manager)->OwnsView(view->id()); 177 static_cast<ViewTreeClientImpl*>(manager)->OwnsView(view->id());
178 } 178 }
179 179
180 } // namespace 180 } // namespace
181 181
182 //////////////////////////////////////////////////////////////////////////////// 182 ////////////////////////////////////////////////////////////////////////////////
183 // View, public: 183 // View, public:
184 184
185 void View::Destroy() { 185 void View::Destroy() {
186 if (!OwnsView(manager_, this)) 186 if (!OwnsView(manager_, this))
187 return; 187 return;
188 188
189 if (manager_) 189 if (manager_)
190 static_cast<ViewManagerClientImpl*>(manager_)->DestroyView(id_); 190 static_cast<ViewTreeClientImpl*>(manager_)->DestroyView(id_);
191 while (!children_.empty()) { 191 while (!children_.empty()) {
192 View* child = children_.front(); 192 View* child = children_.front();
193 if (!OwnsView(manager_, child)) { 193 if (!OwnsView(manager_, child)) {
194 ViewPrivate(child).ClearParent(); 194 ViewPrivate(child).ClearParent();
195 children_.erase(children_.begin()); 195 children_.erase(children_.begin());
196 } else { 196 } else {
197 child->Destroy(); 197 child->Destroy();
198 DCHECK(std::find(children_.begin(), children_.end(), child) == 198 DCHECK(std::find(children_.begin(), children_.end(), child) ==
199 children_.end()); 199 children_.end());
200 } 200 }
201 } 201 }
202 LocalDestroy(); 202 LocalDestroy();
203 } 203 }
204 204
205 void View::SetBounds(const Rect& bounds) { 205 void View::SetBounds(const Rect& bounds) {
206 if (!OwnsView(manager_, this)) 206 if (!OwnsView(manager_, this))
207 return; 207 return;
208 208
209 if (bounds_.Equals(bounds)) 209 if (bounds_.Equals(bounds))
210 return; 210 return;
211 211
212 if (manager_) 212 if (manager_)
213 static_cast<ViewManagerClientImpl*>(manager_)->SetBounds(id_, bounds); 213 static_cast<ViewTreeClientImpl*>(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)
219 return; 219 return;
220 220
221 if (manager_) 221 if (manager_)
222 static_cast<ViewManagerClientImpl*>(manager_)->SetVisible(id_, value); 222 static_cast<ViewTreeClientImpl*>(manager_)->SetVisible(id_, value);
223 LocalSetVisible(value); 223 LocalSetVisible(value);
224 } 224 }
225 225
226 void View::SetSharedProperty(const std::string& name, 226 void View::SetSharedProperty(const std::string& name,
227 const std::vector<uint8_t>* value) { 227 const std::vector<uint8_t>* value) {
228 std::vector<uint8_t> old_value; 228 std::vector<uint8_t> old_value;
229 std::vector<uint8_t>* old_value_ptr = nullptr; 229 std::vector<uint8_t>* old_value_ptr = nullptr;
230 auto it = properties_.find(name); 230 auto it = properties_.find(name);
231 if (it != properties_.end()) { 231 if (it != properties_.end()) {
232 old_value = it->second; 232 old_value = it->second;
(...skipping 14 matching lines...) Expand all
247 } 247 }
248 248
249 // TODO: add test coverage of this (450303). 249 // TODO: add test coverage of this (450303).
250 if (manager_) { 250 if (manager_) {
251 Array<uint8_t> transport_value; 251 Array<uint8_t> transport_value;
252 if (value) { 252 if (value) {
253 transport_value.resize(value->size()); 253 transport_value.resize(value->size());
254 if (value->size()) 254 if (value->size())
255 memcpy(&transport_value.front(), &(value->front()), value->size()); 255 memcpy(&transport_value.front(), &(value->front()), value->size());
256 } 256 }
257 static_cast<ViewManagerClientImpl*>(manager_)->SetProperty( 257 static_cast<ViewTreeClientImpl*>(manager_)->SetProperty(
258 id_, name, transport_value.Pass()); 258 id_, name, transport_value.Pass());
259 } 259 }
260 260
261 FOR_EACH_OBSERVER( 261 FOR_EACH_OBSERVER(
262 ViewObserver, observers_, 262 ViewObserver, observers_,
263 OnViewSharedPropertyChanged(this, name, old_value_ptr, value)); 263 OnViewSharedPropertyChanged(this, name, old_value_ptr, value));
264 } 264 }
265 265
266 bool View::IsDrawn() const { 266 bool View::IsDrawn() const {
267 if (!visible_) 267 if (!visible_)
(...skipping 16 matching lines...) Expand all
284 return root; 284 return root;
285 } 285 }
286 286
287 void View::AddChild(View* child) { 287 void View::AddChild(View* child) {
288 // TODO(beng): not necessarily valid to all connections, but possibly to the 288 // TODO(beng): not necessarily valid to all connections, but possibly to the
289 // embeddee in an embedder-embeddee relationship. 289 // embeddee in an embedder-embeddee relationship.
290 if (manager_) 290 if (manager_)
291 CHECK_EQ(child->view_manager(), manager_); 291 CHECK_EQ(child->view_manager(), manager_);
292 LocalAddChild(child); 292 LocalAddChild(child);
293 if (manager_) 293 if (manager_)
294 static_cast<ViewManagerClientImpl*>(manager_)->AddChild(child->id(), id_); 294 static_cast<ViewTreeClientImpl*>(manager_)->AddChild(child->id(), id_);
295 } 295 }
296 296
297 void View::RemoveChild(View* child) { 297 void View::RemoveChild(View* child) {
298 // TODO(beng): not necessarily valid to all connections, but possibly to the 298 // TODO(beng): not necessarily valid to all connections, but possibly to the
299 // embeddee in an embedder-embeddee relationship. 299 // embeddee in an embedder-embeddee relationship.
300 if (manager_) 300 if (manager_)
301 CHECK_EQ(child->view_manager(), manager_); 301 CHECK_EQ(child->view_manager(), manager_);
302 LocalRemoveChild(child); 302 LocalRemoveChild(child);
303 if (manager_) { 303 if (manager_) {
304 static_cast<ViewManagerClientImpl*>(manager_)->RemoveChild(child->id(), 304 static_cast<ViewTreeClientImpl*>(manager_)->RemoveChild(child->id(), id_);
305 id_);
306 } 305 }
307 } 306 }
308 307
309 void View::MoveToFront() { 308 void View::MoveToFront() {
310 if (!parent_ || parent_->children_.back() == this) 309 if (!parent_ || parent_->children_.back() == this)
311 return; 310 return;
312 Reorder(parent_->children_.back(), ORDER_DIRECTION_ABOVE); 311 Reorder(parent_->children_.back(), ORDER_DIRECTION_ABOVE);
313 } 312 }
314 313
315 void View::MoveToBack() { 314 void View::MoveToBack() {
316 if (!parent_ || parent_->children_.front() == this) 315 if (!parent_ || parent_->children_.front() == this)
317 return; 316 return;
318 Reorder(parent_->children_.front(), ORDER_DIRECTION_BELOW); 317 Reorder(parent_->children_.front(), ORDER_DIRECTION_BELOW);
319 } 318 }
320 319
321 void View::Reorder(View* relative, OrderDirection direction) { 320 void View::Reorder(View* relative, OrderDirection direction) {
322 if (!LocalReorder(relative, direction)) 321 if (!LocalReorder(relative, direction))
323 return; 322 return;
324 if (manager_) { 323 if (manager_) {
325 static_cast<ViewManagerClientImpl*>(manager_)->Reorder(id_, 324 static_cast<ViewTreeClientImpl*>(manager_)->Reorder(id_, relative->id(),
326 relative->id(), 325 direction);
327 direction);
328 } 326 }
329 } 327 }
330 328
331 bool View::Contains(View* child) const { 329 bool View::Contains(View* child) const {
332 if (!child) 330 if (!child)
333 return false; 331 return false;
334 if (child == this) 332 if (child == this)
335 return true; 333 return true;
336 if (manager_) 334 if (manager_)
337 CHECK_EQ(child->view_manager(), manager_); 335 CHECK_EQ(child->view_manager(), manager_);
(...skipping 12 matching lines...) Expand all
350 for (; it != children_.end(); ++it) { 348 for (; it != children_.end(); ++it) {
351 View* view = (*it)->GetChildById(id); 349 View* view = (*it)->GetChildById(id);
352 if (view) 350 if (view)
353 return view; 351 return view;
354 } 352 }
355 return NULL; 353 return NULL;
356 } 354 }
357 355
358 void View::SetSurfaceId(SurfaceIdPtr id) { 356 void View::SetSurfaceId(SurfaceIdPtr id) {
359 if (manager_) { 357 if (manager_) {
360 static_cast<ViewManagerClientImpl*>(manager_)->SetSurfaceId(id_, id.Pass()); 358 static_cast<ViewTreeClientImpl*>(manager_)->SetSurfaceId(id_, id.Pass());
361 } 359 }
362 } 360 }
363 361
364 void View::SetTextInputState(TextInputStatePtr state) { 362 void View::SetTextInputState(TextInputStatePtr state) {
365 if (manager_) { 363 if (manager_) {
366 static_cast<ViewManagerClientImpl*>(manager_) 364 static_cast<ViewTreeClientImpl*>(manager_)
367 ->SetViewTextInputState(id_, state.Pass()); 365 ->SetViewTextInputState(id_, state.Pass());
368 } 366 }
369 } 367 }
370 368
371 void View::SetImeVisibility(bool visible, TextInputStatePtr state) { 369 void View::SetImeVisibility(bool visible, TextInputStatePtr state) {
372 // SetImeVisibility() shouldn't be used if the view is not editable. 370 // SetImeVisibility() shouldn't be used if the view is not editable.
373 DCHECK(state.is_null() || state->type != TEXT_INPUT_TYPE_NONE); 371 DCHECK(state.is_null() || state->type != TEXT_INPUT_TYPE_NONE);
374 if (manager_) { 372 if (manager_) {
375 static_cast<ViewManagerClientImpl*>(manager_) 373 static_cast<ViewTreeClientImpl*>(manager_)
376 ->SetImeVisibility(id_, visible, state.Pass()); 374 ->SetImeVisibility(id_, visible, state.Pass());
377 } 375 }
378 } 376 }
379 377
380 void View::SetFocus() { 378 void View::SetFocus() {
381 if (manager_) 379 if (manager_)
382 static_cast<ViewManagerClientImpl*>(manager_)->SetFocus(id_); 380 static_cast<ViewTreeClientImpl*>(manager_)->SetFocus(id_);
383 } 381 }
384 382
385 bool View::HasFocus() const { 383 bool View::HasFocus() const {
386 return manager_ && manager_->GetFocusedView() == this; 384 return manager_ && manager_->GetFocusedView() == this;
387 } 385 }
388 386
389 void View::Embed(ViewManagerClientPtr client) { 387 void View::Embed(ViewTreeClientPtr client) {
390 if (PrepareForEmbed()) 388 if (PrepareForEmbed())
391 static_cast<ViewManagerClientImpl*>(manager_)->Embed(id_, client.Pass()); 389 static_cast<ViewTreeClientImpl*>(manager_)->Embed(id_, client.Pass());
392 } 390 }
393 391
394 void View::EmbedAllowingReembed(mojo::URLRequestPtr request) { 392 void View::EmbedAllowingReembed(mojo::URLRequestPtr request) {
395 if (PrepareForEmbed()) { 393 if (PrepareForEmbed()) {
396 static_cast<ViewManagerClientImpl*>(manager_) 394 static_cast<ViewTreeClientImpl*>(manager_)
397 ->EmbedAllowingReembed(request.Pass(), id_); 395 ->EmbedAllowingReembed(request.Pass(), id_);
398 } 396 }
399 } 397 }
400 398
401 //////////////////////////////////////////////////////////////////////////////// 399 ////////////////////////////////////////////////////////////////////////////////
402 // View, protected: 400 // View, protected:
403 401
404 namespace { 402 namespace {
405 403
406 ViewportMetricsPtr CreateEmptyViewportMetrics() { 404 ViewportMetricsPtr CreateEmptyViewportMetrics() {
(...skipping 22 matching lines...) Expand all
429 427
430 // We may still have children. This can happen if the embedder destroys the 428 // We may still have children. This can happen if the embedder destroys the
431 // root while we're still alive. 429 // root while we're still alive.
432 while (!children_.empty()) { 430 while (!children_.empty()) {
433 View* child = children_.front(); 431 View* child = children_.front();
434 LocalRemoveChild(child); 432 LocalRemoveChild(child);
435 DCHECK(children_.empty() || children_.front() != child); 433 DCHECK(children_.empty() || children_.front() != child);
436 } 434 }
437 435
438 // TODO(beng): It'd be better to do this via a destruction observer in the 436 // TODO(beng): It'd be better to do this via a destruction observer in the
439 // ViewManagerClientImpl. 437 // ViewTreeClientImpl.
440 if (manager_) 438 if (manager_)
441 static_cast<ViewManagerClientImpl*>(manager_)->RemoveView(id_); 439 static_cast<ViewTreeClientImpl*>(manager_)->RemoveView(id_);
442 440
443 // Clear properties. 441 // Clear properties.
444 for (auto& pair : prop_map_) { 442 for (auto& pair : prop_map_) {
445 if (pair.second.deallocator) 443 if (pair.second.deallocator)
446 (*pair.second.deallocator)(pair.second.value); 444 (*pair.second.deallocator)(pair.second.value);
447 } 445 }
448 prop_map_.clear(); 446 prop_map_.clear();
449 447
450 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this)); 448 FOR_EACH_OBSERVER(ViewObserver, observers_, OnViewDestroyed(this));
451 449
452 if (manager_ && manager_->GetRoot() == this) 450 if (manager_ && manager_->GetRoot() == this)
453 static_cast<ViewManagerClientImpl*>(manager_)->OnRootDestroyed(this); 451 static_cast<ViewTreeClientImpl*>(manager_)->OnRootDestroyed(this);
454 } 452 }
455 453
456 //////////////////////////////////////////////////////////////////////////////// 454 ////////////////////////////////////////////////////////////////////////////////
457 // View, private: 455 // View, private:
458 456
459 View::View(ViewManager* manager, Id id) 457 View::View(ViewManager* manager, Id id)
460 : manager_(manager), 458 : manager_(manager),
461 id_(id), 459 id_(id),
462 parent_(nullptr), 460 parent_(nullptr),
463 viewport_metrics_(CreateEmptyViewportMetrics()), 461 viewport_metrics_(CreateEmptyViewportMetrics()),
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 // Start with the parent as we already notified |this| 599 // Start with the parent as we already notified |this|
602 // in NotifyViewVisibilityChangedDown. 600 // in NotifyViewVisibilityChangedDown.
603 for (View* view = parent(); view; view = view->parent()) { 601 for (View* view = parent(); view; view = view->parent()) {
604 bool ret = view->NotifyViewVisibilityChangedAtReceiver(target); 602 bool ret = view->NotifyViewVisibilityChangedAtReceiver(target);
605 DCHECK(ret); 603 DCHECK(ret);
606 } 604 }
607 } 605 }
608 606
609 bool View::PrepareForEmbed() { 607 bool View::PrepareForEmbed() {
610 if (!OwnsView(manager_, this) && 608 if (!OwnsView(manager_, this) &&
611 !static_cast<ViewManagerClientImpl*>(manager_)->is_embed_root()) { 609 !static_cast<ViewTreeClientImpl*>(manager_)->is_embed_root()) {
612 return false; 610 return false;
613 } 611 }
614 612
615 while (!children_.empty()) 613 while (!children_.empty())
616 RemoveChild(children_[0]); 614 RemoveChild(children_[0]);
617 return true; 615 return true;
618 } 616 }
619 617
620 } // namespace mojo 618 } // namespace mojo
OLDNEW
« no previous file with comments | « components/view_manager/public/cpp/BUILD.gn ('k') | components/view_manager/public/cpp/lib/view_manager_client_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698