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

Side by Side Diff: ui/views/view.cc

Issue 2561253002: [ash-md] Adds support for Z-order iteration in views::View (Closed)
Patch Set: [ash-md] Adds support for Z-order iteration in views::View (using GetChildrenOrderedByVisualOrder) Created 4 years 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first. 5 #define _USE_MATH_DEFINES // For VC++ to get M_PI. This has to be first.
6 6
7 #include "ui/views/view.h" 7 #include "ui/views/view.h"
8 8
9 #include <algorithm> 9 #include <algorithm>
10 #include <cmath> 10 #include <cmath>
(...skipping 443 matching lines...) Expand 10 before | Expand all | Expand 10 after
454 454
455 for (ViewObserver& observer : observers_) 455 for (ViewObserver& observer : observers_)
456 observer.OnViewEnabledChanged(this); 456 observer.OnViewEnabledChanged(this);
457 } 457 }
458 } 458 }
459 459
460 void View::OnEnabledChanged() { 460 void View::OnEnabledChanged() {
461 SchedulePaint(); 461 SchedulePaint();
462 } 462 }
463 463
464 View::Views View::GetChildrenOrderedByVisualOrder() {
465 return children_;
466 }
467
464 // Transformations ------------------------------------------------------------- 468 // Transformations -------------------------------------------------------------
465 469
466 gfx::Transform View::GetTransform() const { 470 gfx::Transform View::GetTransform() const {
467 if (!layer()) 471 if (!layer())
468 return gfx::Transform(); 472 return gfx::Transform();
469 473
470 gfx::Transform transform = layer()->transform(); 474 gfx::Transform transform = layer()->transform();
471 gfx::ScrollOffset scroll_offset = layer()->CurrentScrollOffset(); 475 gfx::ScrollOffset scroll_offset = layer()->CurrentScrollOffset();
472 transform.Translate(-scroll_offset.x(), -scroll_offset.y()); 476 transform.Translate(-scroll_offset.x(), -scroll_offset.y());
473 return transform; 477 return transform;
(...skipping 436 matching lines...) Expand 10 before | Expand all | Expand 10 after
910 return true; 914 return true;
911 } 915 }
912 916
913 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { 917 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) {
914 // TODO(tdanderson): Move this implementation into ViewTargetDelegate. 918 // TODO(tdanderson): Move this implementation into ViewTargetDelegate.
915 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree()) 919 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree())
916 return NULL; 920 return NULL;
917 921
918 // Walk the child Views recursively looking for the View that most 922 // Walk the child Views recursively looking for the View that most
919 // tightly encloses the specified point. 923 // tightly encloses the specified point.
920 for (int i = child_count() - 1; i >= 0; --i) { 924 View::Views children = GetChildrenOrderedByVisualOrder();
921 View* child = child_at(i); 925 DCHECK_EQ(child_count(), static_cast<int>(children.size()));
926 for (int i = children.size() - 1; i >= 0; --i) {
927 View* child = children[i];
922 if (!child->visible()) 928 if (!child->visible())
923 continue; 929 continue;
924 930
925 gfx::Point point_in_child_coords(point); 931 gfx::Point point_in_child_coords(point);
926 ConvertPointToTarget(this, child, &point_in_child_coords); 932 ConvertPointToTarget(this, child, &point_in_child_coords);
927 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords); 933 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords);
928 if (handler) 934 if (handler)
929 return handler; 935 return handler;
930 } 936 }
931 return this; 937 return this;
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after
1430 1436
1431 if (focus_manager) 1437 if (focus_manager)
1432 RegisterPendingAccelerators(); 1438 RegisterPendingAccelerators();
1433 } 1439 }
1434 } 1440 }
1435 1441
1436 // Painting -------------------------------------------------------------------- 1442 // Painting --------------------------------------------------------------------
1437 1443
1438 void View::PaintChildren(const ui::PaintContext& context) { 1444 void View::PaintChildren(const ui::PaintContext& context) {
1439 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); 1445 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName());
1440 for (int i = 0, count = child_count(); i < count; ++i) 1446 View::Views children = GetChildrenOrderedByVisualOrder();
1441 if (!child_at(i)->layer()) 1447 DCHECK_EQ(child_count(), static_cast<int>(children.size()));
1442 child_at(i)->Paint(context); 1448 for (int i = 0, count = children.size(); i < count; ++i) {
sky 2016/12/13 23:40:56 Use range based for-loop?
varkha 2016/12/19 20:35:44 Done. I will try to get the rest of the similar it
varkha 2016/12/19 20:56:15 Posted https://codereview.chromium.org/2583343003
1449 View* child = children[i];
1450 if (!child->layer())
1451 child->Paint(context);
1452 }
1443 } 1453 }
1444 1454
1445 void View::OnPaint(gfx::Canvas* canvas) { 1455 void View::OnPaint(gfx::Canvas* canvas) {
1446 TRACE_EVENT1("views", "View::OnPaint", "class", GetClassName()); 1456 TRACE_EVENT1("views", "View::OnPaint", "class", GetClassName());
1447 OnPaintBackground(canvas); 1457 OnPaintBackground(canvas);
1448 OnPaintBorder(canvas); 1458 OnPaintBorder(canvas);
1449 } 1459 }
1450 1460
1451 void View::OnPaintBackground(gfx::Canvas* canvas) { 1461 void View::OnPaintBackground(gfx::Canvas* canvas) {
1452 if (background_.get()) { 1462 if (background_.get()) {
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
1581 } 1591 }
1582 1592
1583 void View::ReorderChildLayers(ui::Layer* parent_layer) { 1593 void View::ReorderChildLayers(ui::Layer* parent_layer) {
1584 if (layer() && layer() != parent_layer) { 1594 if (layer() && layer() != parent_layer) {
1585 DCHECK_EQ(parent_layer, layer()->parent()); 1595 DCHECK_EQ(parent_layer, layer()->parent());
1586 parent_layer->StackAtBottom(layer()); 1596 parent_layer->StackAtBottom(layer());
1587 } else { 1597 } else {
1588 // Iterate backwards through the children so that a child with a layer 1598 // Iterate backwards through the children so that a child with a layer
1589 // which is further to the back is stacked above one which is further to 1599 // which is further to the back is stacked above one which is further to
1590 // the front. 1600 // the front.
1591 for (Views::reverse_iterator it(children_.rbegin()); 1601 View::Views children = GetChildrenOrderedByVisualOrder();
1592 it != children_.rend(); ++it) { 1602 DCHECK_EQ(child_count(), static_cast<int>(children.size()));
1593 (*it)->ReorderChildLayers(parent_layer); 1603 for (int i = children.size() - 1; i >= 0; --i)
sky 2016/12/13 23:40:56 I think a reverse iterator is safer here.
varkha 2016/12/19 20:35:44 Done.
1594 } 1604 children[i]->ReorderChildLayers(parent_layer);
1595 } 1605 }
1596 } 1606 }
1597 1607
1598 // Input ----------------------------------------------------------------------- 1608 // Input -----------------------------------------------------------------------
1599 1609
1600 View::DragInfo* View::GetDragInfo() { 1610 View::DragInfo* View::GetDragInfo() {
1601 return parent_ ? parent_->GetDragInfo() : NULL; 1611 return parent_ ? parent_->GetDragInfo() : NULL;
1602 } 1612 }
1603 1613
1604 // Focus ----------------------------------------------------------------------- 1614 // Focus -----------------------------------------------------------------------
(...skipping 843 matching lines...) Expand 10 before | Expand all | Expand 10 after
2448 // Message the RootView to do the drag and drop. That way if we're removed 2458 // Message the RootView to do the drag and drop. That way if we're removed
2449 // the RootView can detect it and avoid calling us back. 2459 // the RootView can detect it and avoid calling us back.
2450 gfx::Point widget_location(event.location()); 2460 gfx::Point widget_location(event.location());
2451 ConvertPointToWidget(this, &widget_location); 2461 ConvertPointToWidget(this, &widget_location);
2452 widget->RunShellDrag(this, data, widget_location, drag_operations, source); 2462 widget->RunShellDrag(this, data, widget_location, drag_operations, source);
2453 // WARNING: we may have been deleted. 2463 // WARNING: we may have been deleted.
2454 return true; 2464 return true;
2455 } 2465 }
2456 2466
2457 } // namespace views 2467 } // namespace views
OLDNEW
« ui/views/view.h ('K') | « ui/views/view.h ('k') | ui/views/view_targeter_delegate.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698