Chromium Code Reviews| OLD | NEW |
|---|---|
| 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> |
| 11 #include <memory> | 11 #include <memory> |
| 12 #include <utility> | 12 #include <utility> |
| 13 | 13 |
| 14 #include "base/containers/adapters.h" | |
| 14 #include "base/logging.h" | 15 #include "base/logging.h" |
| 15 #include "base/macros.h" | 16 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 17 #include "base/memory/ptr_util.h" |
| 17 #include "base/message_loop/message_loop.h" | 18 #include "base/message_loop/message_loop.h" |
| 18 #include "base/stl_util.h" | 19 #include "base/stl_util.h" |
| 19 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 20 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 21 #include "base/trace_event/trace_event.h" | 22 #include "base/trace_event/trace_event.h" |
| 22 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 23 #include "third_party/skia/include/core/SkRect.h" | 24 #include "third_party/skia/include/core/SkRect.h" |
| (...skipping 523 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 547 // If we have a layout manager, let it handle the layout for us. | 548 // If we have a layout manager, let it handle the layout for us. |
| 548 if (layout_manager_.get()) | 549 if (layout_manager_.get()) |
| 549 layout_manager_->Layout(this); | 550 layout_manager_->Layout(this); |
| 550 | 551 |
| 551 // Make sure to propagate the Layout() call to any children that haven't | 552 // Make sure to propagate the Layout() call to any children that haven't |
| 552 // received it yet through the layout manager and need to be laid out. This | 553 // received it yet through the layout manager and need to be laid out. This |
| 553 // is needed for the case when the child requires a layout but its bounds | 554 // is needed for the case when the child requires a layout but its bounds |
| 554 // weren't changed by the layout manager. If there is no layout manager, we | 555 // weren't changed by the layout manager. If there is no layout manager, we |
| 555 // just propagate the Layout() call down the hierarchy, so whoever receives | 556 // just propagate the Layout() call down the hierarchy, so whoever receives |
| 556 // the call can take appropriate action. | 557 // the call can take appropriate action. |
| 557 for (int i = 0, count = child_count(); i < count; ++i) { | 558 for (auto child : children_) { |
|
sadrul
2016/12/20 17:35:25
auto* child
So it's obvious when reading the code
varkha
2016/12/20 18:48:47
Done.
| |
| 558 View* child = child_at(i); | |
| 559 if (child->needs_layout_ || !layout_manager_.get()) { | 559 if (child->needs_layout_ || !layout_manager_.get()) { |
| 560 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName()); | 560 TRACE_EVENT1("views", "View::Layout", "class", child->GetClassName()); |
| 561 child->needs_layout_ = false; | 561 child->needs_layout_ = false; |
| 562 child->Layout(); | 562 child->Layout(); |
| 563 } | 563 } |
| 564 } | 564 } |
| 565 } | 565 } |
| 566 | 566 |
| 567 void View::InvalidateLayout() { | 567 void View::InvalidateLayout() { |
| 568 // Always invalidate up. This is needed to handle the case of us already being | 568 // Always invalidate up. This is needed to handle the case of us already being |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 614 | 614 |
| 615 View* View::GetAncestorWithClassName(const std::string& name) { | 615 View* View::GetAncestorWithClassName(const std::string& name) { |
| 616 return const_cast<View*>(const_cast<const View*>(this)-> | 616 return const_cast<View*>(const_cast<const View*>(this)-> |
| 617 GetAncestorWithClassName(name)); | 617 GetAncestorWithClassName(name)); |
| 618 } | 618 } |
| 619 | 619 |
| 620 const View* View::GetViewByID(int id) const { | 620 const View* View::GetViewByID(int id) const { |
| 621 if (id == id_) | 621 if (id == id_) |
| 622 return const_cast<View*>(this); | 622 return const_cast<View*>(this); |
| 623 | 623 |
| 624 for (int i = 0, count = child_count(); i < count; ++i) { | 624 for (auto child : children_) { |
|
sadrul
2016/12/20 17:35:25
ditto
varkha
2016/12/20 18:48:47
Done.
| |
| 625 const View* view = child_at(i)->GetViewByID(id); | 625 const View* view = child->GetViewByID(id); |
| 626 if (view) | 626 if (view) |
| 627 return view; | 627 return view; |
| 628 } | 628 } |
| 629 return NULL; | 629 return NULL; |
| 630 } | 630 } |
| 631 | 631 |
| 632 View* View::GetViewByID(int id) { | 632 View* View::GetViewByID(int id) { |
| 633 return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id)); | 633 return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id)); |
| 634 } | 634 } |
| 635 | 635 |
| 636 void View::SetGroup(int gid) { | 636 void View::SetGroup(int gid) { |
| 637 // Don't change the group id once it's set. | 637 // Don't change the group id once it's set. |
| 638 DCHECK(group_ == -1 || group_ == gid); | 638 DCHECK(group_ == -1 || group_ == gid); |
| 639 group_ = gid; | 639 group_ = gid; |
| 640 } | 640 } |
| 641 | 641 |
| 642 int View::GetGroup() const { | 642 int View::GetGroup() const { |
| 643 return group_; | 643 return group_; |
| 644 } | 644 } |
| 645 | 645 |
| 646 bool View::IsGroupFocusTraversable() const { | 646 bool View::IsGroupFocusTraversable() const { |
| 647 return true; | 647 return true; |
| 648 } | 648 } |
| 649 | 649 |
| 650 void View::GetViewsInGroup(int group, Views* views) { | 650 void View::GetViewsInGroup(int group, Views* views) { |
| 651 if (group_ == group) | 651 if (group_ == group) |
| 652 views->push_back(this); | 652 views->push_back(this); |
| 653 | 653 |
| 654 for (int i = 0, count = child_count(); i < count; ++i) | 654 for (auto child : children_) |
|
sadrul
2016/12/20 17:35:25
same
varkha
2016/12/20 18:48:47
Done.
| |
| 655 child_at(i)->GetViewsInGroup(group, views); | 655 child->GetViewsInGroup(group, views); |
| 656 } | 656 } |
| 657 | 657 |
| 658 View* View::GetSelectedViewForGroup(int group) { | 658 View* View::GetSelectedViewForGroup(int group) { |
| 659 Views views; | 659 Views views; |
| 660 GetWidget()->GetRootView()->GetViewsInGroup(group, &views); | 660 GetWidget()->GetRootView()->GetViewsInGroup(group, &views); |
| 661 return views.empty() ? NULL : views[0]; | 661 return views.empty() ? NULL : views[0]; |
| 662 } | 662 } |
| 663 | 663 |
| 664 // Coordinate conversion ------------------------------------------------------- | 664 // Coordinate conversion ------------------------------------------------------- |
| 665 | 665 |
| (...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 910 return true; | 910 return true; |
| 911 } | 911 } |
| 912 | 912 |
| 913 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { | 913 View* View::GetTooltipHandlerForPoint(const gfx::Point& point) { |
| 914 // TODO(tdanderson): Move this implementation into ViewTargetDelegate. | 914 // TODO(tdanderson): Move this implementation into ViewTargetDelegate. |
| 915 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree()) | 915 if (!HitTestPoint(point) || !CanProcessEventsWithinSubtree()) |
| 916 return NULL; | 916 return NULL; |
| 917 | 917 |
| 918 // Walk the child Views recursively looking for the View that most | 918 // Walk the child Views recursively looking for the View that most |
| 919 // tightly encloses the specified point. | 919 // tightly encloses the specified point. |
| 920 for (int i = child_count() - 1; i >= 0; --i) { | 920 for (auto child : base::Reversed(children_)) { |
| 921 View* child = child_at(i); | |
| 922 if (!child->visible()) | 921 if (!child->visible()) |
| 923 continue; | 922 continue; |
| 924 | 923 |
| 925 gfx::Point point_in_child_coords(point); | 924 gfx::Point point_in_child_coords(point); |
| 926 ConvertPointToTarget(this, child, &point_in_child_coords); | 925 ConvertPointToTarget(this, child, &point_in_child_coords); |
| 927 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords); | 926 View* handler = child->GetTooltipHandlerForPoint(point_in_child_coords); |
| 928 if (handler) | 927 if (handler) |
| 929 return handler; | 928 return handler; |
| 930 } | 929 } |
| 931 return this; | 930 return this; |
| (...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1430 | 1429 |
| 1431 if (focus_manager) | 1430 if (focus_manager) |
| 1432 RegisterPendingAccelerators(); | 1431 RegisterPendingAccelerators(); |
| 1433 } | 1432 } |
| 1434 } | 1433 } |
| 1435 | 1434 |
| 1436 // Painting -------------------------------------------------------------------- | 1435 // Painting -------------------------------------------------------------------- |
| 1437 | 1436 |
| 1438 void View::PaintChildren(const ui::PaintContext& context) { | 1437 void View::PaintChildren(const ui::PaintContext& context) { |
| 1439 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); | 1438 TRACE_EVENT1("views", "View::PaintChildren", "class", GetClassName()); |
| 1440 for (int i = 0, count = child_count(); i < count; ++i) | 1439 for (auto child : children_) |
|
sadrul
2016/12/20 17:35:25
I think we should have {} here
varkha
2016/12/20 18:48:47
Done.
| |
| 1441 if (!child_at(i)->layer()) | 1440 if (!child->layer()) |
| 1442 child_at(i)->Paint(context); | 1441 child->Paint(context); |
| 1443 } | 1442 } |
| 1444 | 1443 |
| 1445 void View::OnPaint(gfx::Canvas* canvas) { | 1444 void View::OnPaint(gfx::Canvas* canvas) { |
| 1446 TRACE_EVENT1("views", "View::OnPaint", "class", GetClassName()); | 1445 TRACE_EVENT1("views", "View::OnPaint", "class", GetClassName()); |
| 1447 OnPaintBackground(canvas); | 1446 OnPaintBackground(canvas); |
| 1448 OnPaintBorder(canvas); | 1447 OnPaintBorder(canvas); |
| 1449 } | 1448 } |
| 1450 | 1449 |
| 1451 void View::OnPaintBackground(gfx::Canvas* canvas) { | 1450 void View::OnPaintBackground(gfx::Canvas* canvas) { |
| 1452 if (background_.get()) { | 1451 if (background_.get()) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1498 void View::MoveLayerToParent(ui::Layer* parent_layer, | 1497 void View::MoveLayerToParent(ui::Layer* parent_layer, |
| 1499 const gfx::Point& point) { | 1498 const gfx::Point& point) { |
| 1500 gfx::Point local_point(point); | 1499 gfx::Point local_point(point); |
| 1501 if (parent_layer != layer()) | 1500 if (parent_layer != layer()) |
| 1502 local_point.Offset(GetMirroredX(), y()); | 1501 local_point.Offset(GetMirroredX(), y()); |
| 1503 if (layer() && parent_layer != layer()) { | 1502 if (layer() && parent_layer != layer()) { |
| 1504 parent_layer->Add(layer()); | 1503 parent_layer->Add(layer()); |
| 1505 SetLayerBounds(gfx::Rect(local_point.x(), local_point.y(), | 1504 SetLayerBounds(gfx::Rect(local_point.x(), local_point.y(), |
| 1506 width(), height())); | 1505 width(), height())); |
| 1507 } else { | 1506 } else { |
| 1508 for (int i = 0, count = child_count(); i < count; ++i) | 1507 for (auto child : children_) |
| 1509 child_at(i)->MoveLayerToParent(parent_layer, local_point); | 1508 child->MoveLayerToParent(parent_layer, local_point); |
| 1510 } | 1509 } |
| 1511 } | 1510 } |
| 1512 | 1511 |
| 1513 void View::UpdateLayerVisibility() { | 1512 void View::UpdateLayerVisibility() { |
| 1514 bool visible = visible_; | 1513 bool visible = visible_; |
| 1515 for (const View* v = parent_; visible && v && !v->layer(); v = v->parent_) | 1514 for (const View* v = parent_; visible && v && !v->layer(); v = v->parent_) |
| 1516 visible = v->visible(); | 1515 visible = v->visible(); |
| 1517 | 1516 |
| 1518 UpdateChildLayerVisibility(visible); | 1517 UpdateChildLayerVisibility(visible); |
| 1519 } | 1518 } |
| 1520 | 1519 |
| 1521 void View::UpdateChildLayerVisibility(bool ancestor_visible) { | 1520 void View::UpdateChildLayerVisibility(bool ancestor_visible) { |
| 1522 if (layer()) { | 1521 if (layer()) { |
| 1523 layer()->SetVisible(ancestor_visible && visible_); | 1522 layer()->SetVisible(ancestor_visible && visible_); |
| 1524 } else { | 1523 } else { |
| 1525 for (int i = 0, count = child_count(); i < count; ++i) | 1524 for (auto child : children_) |
| 1526 child_at(i)->UpdateChildLayerVisibility(ancestor_visible && visible_); | 1525 child->UpdateChildLayerVisibility(ancestor_visible && visible_); |
| 1527 } | 1526 } |
| 1528 } | 1527 } |
| 1529 | 1528 |
| 1530 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { | 1529 void View::UpdateChildLayerBounds(const gfx::Vector2d& offset) { |
| 1531 if (layer()) { | 1530 if (layer()) { |
| 1532 SetLayerBounds(GetLocalBounds() + offset); | 1531 SetLayerBounds(GetLocalBounds() + offset); |
| 1533 } else { | 1532 } else { |
| 1534 for (int i = 0, count = child_count(); i < count; ++i) { | 1533 for (auto child : children_) { |
| 1535 View* child = child_at(i); | |
| 1536 child->UpdateChildLayerBounds( | 1534 child->UpdateChildLayerBounds( |
| 1537 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); | 1535 offset + gfx::Vector2d(child->GetMirroredX(), child->y())); |
| 1538 } | 1536 } |
| 1539 } | 1537 } |
| 1540 } | 1538 } |
| 1541 | 1539 |
| 1542 void View::OnPaintLayer(const ui::PaintContext& context) { | 1540 void View::OnPaintLayer(const ui::PaintContext& context) { |
| 1543 Paint(context); | 1541 Paint(context); |
| 1544 } | 1542 } |
| 1545 | 1543 |
| (...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1758 | 1756 |
| 1759 base::snprintf(pp, kMaxPointerStringLength, "%p", parent_); | 1757 base::snprintf(pp, kMaxPointerStringLength, "%p", parent_); |
| 1760 result.append(" N"); | 1758 result.append(" N"); |
| 1761 result.append(pp + 2); | 1759 result.append(pp + 2); |
| 1762 result.append(" -> N"); | 1760 result.append(" -> N"); |
| 1763 result.append(p + 2); | 1761 result.append(p + 2); |
| 1764 result.append("\n"); | 1762 result.append("\n"); |
| 1765 } | 1763 } |
| 1766 | 1764 |
| 1767 // Children. | 1765 // Children. |
| 1768 for (int i = 0, count = view_with_children->child_count(); i < count; ++i) | 1766 for (auto child : view_with_children->children_) |
| 1769 result.append(view_with_children->child_at(i)->PrintViewGraph(false)); | 1767 result.append(child->PrintViewGraph(false)); |
| 1770 | 1768 |
| 1771 if (first) | 1769 if (first) |
| 1772 result.append("}\n"); | 1770 result.append("}\n"); |
| 1773 | 1771 |
| 1774 return result; | 1772 return result; |
| 1775 } | 1773 } |
| 1776 #endif | 1774 #endif |
| 1777 | 1775 |
| 1778 //////////////////////////////////////////////////////////////////////////////// | 1776 //////////////////////////////////////////////////////////////////////////////// |
| 1779 // View, private: | 1777 // View, private: |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1868 UpdateTooltip(); | 1866 UpdateTooltip(); |
| 1869 | 1867 |
| 1870 if (layout_manager_) | 1868 if (layout_manager_) |
| 1871 layout_manager_->ViewRemoved(this, view); | 1869 layout_manager_->ViewRemoved(this, view); |
| 1872 | 1870 |
| 1873 for (ViewObserver& observer : observers_) | 1871 for (ViewObserver& observer : observers_) |
| 1874 observer.OnChildViewRemoved(view, this); | 1872 observer.OnChildViewRemoved(view, this); |
| 1875 } | 1873 } |
| 1876 | 1874 |
| 1877 void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) { | 1875 void View::PropagateRemoveNotifications(View* old_parent, View* new_parent) { |
| 1878 for (int i = 0, count = child_count(); i < count; ++i) | 1876 for (auto child : children_) |
| 1879 child_at(i)->PropagateRemoveNotifications(old_parent, new_parent); | 1877 child->PropagateRemoveNotifications(old_parent, new_parent); |
| 1880 | 1878 |
| 1881 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent); | 1879 ViewHierarchyChangedDetails details(false, old_parent, this, new_parent); |
| 1882 for (View* v = this; v; v = v->parent_) | 1880 for (View* v = this; v; v = v->parent_) |
| 1883 v->ViewHierarchyChangedImpl(true, details); | 1881 v->ViewHierarchyChangedImpl(true, details); |
| 1884 } | 1882 } |
| 1885 | 1883 |
| 1886 void View::PropagateAddNotifications( | 1884 void View::PropagateAddNotifications( |
| 1887 const ViewHierarchyChangedDetails& details) { | 1885 const ViewHierarchyChangedDetails& details) { |
| 1888 for (int i = 0, count = child_count(); i < count; ++i) | 1886 for (auto child : children_) |
| 1889 child_at(i)->PropagateAddNotifications(details); | 1887 child->PropagateAddNotifications(details); |
| 1890 ViewHierarchyChangedImpl(true, details); | 1888 ViewHierarchyChangedImpl(true, details); |
| 1891 } | 1889 } |
| 1892 | 1890 |
| 1893 void View::PropagateNativeViewHierarchyChanged() { | 1891 void View::PropagateNativeViewHierarchyChanged() { |
| 1894 for (int i = 0, count = child_count(); i < count; ++i) | 1892 for (auto child : children_) |
| 1895 child_at(i)->PropagateNativeViewHierarchyChanged(); | 1893 child->PropagateNativeViewHierarchyChanged(); |
| 1896 NativeViewHierarchyChanged(); | 1894 NativeViewHierarchyChanged(); |
| 1897 } | 1895 } |
| 1898 | 1896 |
| 1899 void View::ViewHierarchyChangedImpl( | 1897 void View::ViewHierarchyChangedImpl( |
| 1900 bool register_accelerators, | 1898 bool register_accelerators, |
| 1901 const ViewHierarchyChangedDetails& details) { | 1899 const ViewHierarchyChangedDetails& details) { |
| 1902 if (register_accelerators) { | 1900 if (register_accelerators) { |
| 1903 if (details.is_add) { | 1901 if (details.is_add) { |
| 1904 // If you get this registration, you are part of a subtree that has been | 1902 // If you get this registration, you are part of a subtree that has been |
| 1905 // added to the view hierarchy. | 1903 // added to the view hierarchy. |
| 1906 if (GetFocusManager()) | 1904 if (GetFocusManager()) |
| 1907 RegisterPendingAccelerators(); | 1905 RegisterPendingAccelerators(); |
| 1908 } else { | 1906 } else { |
| 1909 if (details.child == this) | 1907 if (details.child == this) |
| 1910 UnregisterAccelerators(true); | 1908 UnregisterAccelerators(true); |
| 1911 } | 1909 } |
| 1912 } | 1910 } |
| 1913 | 1911 |
| 1914 ViewHierarchyChanged(details); | 1912 ViewHierarchyChanged(details); |
| 1915 details.parent->needs_layout_ = true; | 1913 details.parent->needs_layout_ = true; |
| 1916 } | 1914 } |
| 1917 | 1915 |
| 1918 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { | 1916 void View::PropagateNativeThemeChanged(const ui::NativeTheme* theme) { |
| 1919 for (int i = 0, count = child_count(); i < count; ++i) | 1917 for (auto child : children_) |
| 1920 child_at(i)->PropagateNativeThemeChanged(theme); | 1918 child->PropagateNativeThemeChanged(theme); |
| 1921 OnNativeThemeChanged(theme); | 1919 OnNativeThemeChanged(theme); |
| 1922 } | 1920 } |
| 1923 | 1921 |
| 1924 // Size and disposition -------------------------------------------------------- | 1922 // Size and disposition -------------------------------------------------------- |
| 1925 | 1923 |
| 1926 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { | 1924 void View::PropagateVisibilityNotifications(View* start, bool is_visible) { |
| 1927 for (int i = 0, count = child_count(); i < count; ++i) | 1925 for (auto child : children_) |
| 1928 child_at(i)->PropagateVisibilityNotifications(start, is_visible); | 1926 child->PropagateVisibilityNotifications(start, is_visible); |
| 1929 VisibilityChangedImpl(start, is_visible); | 1927 VisibilityChangedImpl(start, is_visible); |
| 1930 } | 1928 } |
| 1931 | 1929 |
| 1932 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { | 1930 void View::VisibilityChangedImpl(View* starting_from, bool is_visible) { |
| 1933 VisibilityChanged(starting_from, is_visible); | 1931 VisibilityChanged(starting_from, is_visible); |
| 1934 } | 1932 } |
| 1935 | 1933 |
| 1936 void View::BoundsChanged(const gfx::Rect& previous_bounds) { | 1934 void View::BoundsChanged(const gfx::Rect& previous_bounds) { |
| 1937 if (visible_) { | 1935 if (visible_) { |
| 1938 // Paint the new bounds. | 1936 // Paint the new bounds. |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2099 bool result = GetTransformRelativeTo(ancestor, &trans); | 2097 bool result = GetTransformRelativeTo(ancestor, &trans); |
| 2100 trans.TransformRectReverse(rect); | 2098 trans.TransformRectReverse(rect); |
| 2101 return result; | 2099 return result; |
| 2102 } | 2100 } |
| 2103 | 2101 |
| 2104 // Accelerated painting -------------------------------------------------------- | 2102 // Accelerated painting -------------------------------------------------------- |
| 2105 | 2103 |
| 2106 void View::CreateLayer() { | 2104 void View::CreateLayer() { |
| 2107 // A new layer is being created for the view. So all the layers of the | 2105 // A new layer is being created for the view. So all the layers of the |
| 2108 // sub-tree can inherit the visibility of the corresponding view. | 2106 // sub-tree can inherit the visibility of the corresponding view. |
| 2109 for (int i = 0, count = child_count(); i < count; ++i) | 2107 for (auto child : children_) |
| 2110 child_at(i)->UpdateChildLayerVisibility(true); | 2108 child->UpdateChildLayerVisibility(true); |
| 2111 | 2109 |
| 2112 SetLayer(base::MakeUnique<ui::Layer>()); | 2110 SetLayer(base::MakeUnique<ui::Layer>()); |
| 2113 layer()->set_delegate(this); | 2111 layer()->set_delegate(this); |
| 2114 layer()->set_name(GetClassName()); | 2112 layer()->set_name(GetClassName()); |
| 2115 | 2113 |
| 2116 UpdateParentLayers(); | 2114 UpdateParentLayers(); |
| 2117 UpdateLayerVisibility(); | 2115 UpdateLayerVisibility(); |
| 2118 | 2116 |
| 2119 // The new layer needs to be ordered in the layer tree according | 2117 // The new layer needs to be ordered in the layer tree according |
| 2120 // to the view tree. Children of this layer were added in order | 2118 // to the view tree. Children of this layer were added in order |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 2138 if (layer()) { | 2136 if (layer()) { |
| 2139 if (!layer()->parent()) { | 2137 if (!layer()->parent()) { |
| 2140 UpdateParentLayer(); | 2138 UpdateParentLayer(); |
| 2141 return true; | 2139 return true; |
| 2142 } | 2140 } |
| 2143 // The layers of any child views are already in place, so we can stop | 2141 // The layers of any child views are already in place, so we can stop |
| 2144 // iterating here. | 2142 // iterating here. |
| 2145 return false; | 2143 return false; |
| 2146 } | 2144 } |
| 2147 bool result = false; | 2145 bool result = false; |
| 2148 for (int i = 0, count = child_count(); i < count; ++i) { | 2146 for (auto child : children_) { |
| 2149 if (child_at(i)->UpdateParentLayers()) | 2147 if (child->UpdateParentLayers()) |
| 2150 result = true; | 2148 result = true; |
| 2151 } | 2149 } |
| 2152 return result; | 2150 return result; |
| 2153 } | 2151 } |
| 2154 | 2152 |
| 2155 void View::OrphanLayers() { | 2153 void View::OrphanLayers() { |
| 2156 if (layer()) { | 2154 if (layer()) { |
| 2157 if (layer()->parent()) | 2155 if (layer()->parent()) |
| 2158 layer()->parent()->Remove(layer()); | 2156 layer()->parent()->Remove(layer()); |
| 2159 | 2157 |
| 2160 // The layer belonging to this View has already been orphaned. It is not | 2158 // The layer belonging to this View has already been orphaned. It is not |
| 2161 // necessary to orphan the child layers. | 2159 // necessary to orphan the child layers. |
| 2162 return; | 2160 return; |
| 2163 } | 2161 } |
| 2164 for (int i = 0, count = child_count(); i < count; ++i) | 2162 for (auto child : children_) |
| 2165 child_at(i)->OrphanLayers(); | 2163 child->OrphanLayers(); |
| 2166 } | 2164 } |
| 2167 | 2165 |
| 2168 void View::ReparentLayer(const gfx::Vector2d& offset, ui::Layer* parent_layer) { | 2166 void View::ReparentLayer(const gfx::Vector2d& offset, ui::Layer* parent_layer) { |
| 2169 layer()->SetBounds(GetLocalBounds() + offset); | 2167 layer()->SetBounds(GetLocalBounds() + offset); |
| 2170 DCHECK_NE(layer(), parent_layer); | 2168 DCHECK_NE(layer(), parent_layer); |
| 2171 if (parent_layer) | 2169 if (parent_layer) |
| 2172 parent_layer->Add(layer()); | 2170 parent_layer->Add(layer()); |
| 2173 layer()->SchedulePaint(GetLocalBounds()); | 2171 layer()->SchedulePaint(GetLocalBounds()); |
| 2174 MoveLayerToParent(layer(), gfx::Point()); | 2172 MoveLayerToParent(layer(), gfx::Point()); |
| 2175 } | 2173 } |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2384 return; | 2382 return; |
| 2385 | 2383 |
| 2386 FocusManager* focus_manager = GetFocusManager(); | 2384 FocusManager* focus_manager = GetFocusManager(); |
| 2387 if (focus_manager) | 2385 if (focus_manager) |
| 2388 focus_manager->AdvanceFocusIfNecessary(); | 2386 focus_manager->AdvanceFocusIfNecessary(); |
| 2389 } | 2387 } |
| 2390 | 2388 |
| 2391 // System events --------------------------------------------------------------- | 2389 // System events --------------------------------------------------------------- |
| 2392 | 2390 |
| 2393 void View::PropagateThemeChanged() { | 2391 void View::PropagateThemeChanged() { |
| 2394 for (int i = child_count() - 1; i >= 0; --i) | 2392 for (auto child : base::Reversed(children_)) |
| 2395 child_at(i)->PropagateThemeChanged(); | 2393 child->PropagateThemeChanged(); |
| 2396 OnThemeChanged(); | 2394 OnThemeChanged(); |
| 2397 } | 2395 } |
| 2398 | 2396 |
| 2399 void View::PropagateLocaleChanged() { | 2397 void View::PropagateLocaleChanged() { |
| 2400 for (int i = child_count() - 1; i >= 0; --i) | 2398 for (auto child : base::Reversed(children_)) |
| 2401 child_at(i)->PropagateLocaleChanged(); | 2399 child->PropagateLocaleChanged(); |
| 2402 OnLocaleChanged(); | 2400 OnLocaleChanged(); |
| 2403 } | 2401 } |
| 2404 | 2402 |
| 2405 void View::PropagateDeviceScaleFactorChanged(float device_scale_factor) { | 2403 void View::PropagateDeviceScaleFactorChanged(float device_scale_factor) { |
| 2406 for (int i = child_count() - 1; i >= 0; --i) | 2404 for (auto child : base::Reversed(children_)) |
| 2407 child_at(i)->PropagateDeviceScaleFactorChanged(device_scale_factor); | 2405 child->PropagateDeviceScaleFactorChanged(device_scale_factor); |
|
sadrul
2016/12/20 17:35:25
I wonder why these last three are iterated in reve
varkha
2016/12/20 18:48:47
Not sure. I guess the desire was to go in visibili
| |
| 2408 | 2406 |
| 2409 // If the view is drawing to the layer, OnDeviceScaleFactorChanged() is called | 2407 // If the view is drawing to the layer, OnDeviceScaleFactorChanged() is called |
| 2410 // through LayerDelegate callback. | 2408 // through LayerDelegate callback. |
| 2411 if (!layer()) | 2409 if (!layer()) |
| 2412 OnDeviceScaleFactorChanged(device_scale_factor); | 2410 OnDeviceScaleFactorChanged(device_scale_factor); |
| 2413 } | 2411 } |
| 2414 | 2412 |
| 2415 // Tooltips -------------------------------------------------------------------- | 2413 // Tooltips -------------------------------------------------------------------- |
| 2416 | 2414 |
| 2417 void View::UpdateTooltip() { | 2415 void View::UpdateTooltip() { |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 2448 // Message the RootView to do the drag and drop. That way if we're removed | 2446 // 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. | 2447 // the RootView can detect it and avoid calling us back. |
| 2450 gfx::Point widget_location(event.location()); | 2448 gfx::Point widget_location(event.location()); |
| 2451 ConvertPointToWidget(this, &widget_location); | 2449 ConvertPointToWidget(this, &widget_location); |
| 2452 widget->RunShellDrag(this, data, widget_location, drag_operations, source); | 2450 widget->RunShellDrag(this, data, widget_location, drag_operations, source); |
| 2453 // WARNING: we may have been deleted. | 2451 // WARNING: we may have been deleted. |
| 2454 return true; | 2452 return true; |
| 2455 } | 2453 } |
| 2456 | 2454 |
| 2457 } // namespace views | 2455 } // namespace views |
| OLD | NEW |