summaryrefslogtreecommitdiffstats
path: root/views
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-15 17:13:33 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-07-15 17:13:33 +0000
commitfe84b910e02f66451d9b746d03f761aedfa39032 (patch)
treeba31d5ff4ae9229366bb0675d6dc476fd55645f8 /views
parentce2d72c6918e9707ef3dc9987369241108ed239f (diff)
downloadchromium_src-fe84b910e02f66451d9b746d03f761aedfa39032.zip
chromium_src-fe84b910e02f66451d9b746d03f761aedfa39032.tar.gz
chromium_src-fe84b910e02f66451d9b746d03f761aedfa39032.tar.bz2
Convert some more view methods to the ui/views style.
BUG=72040 TEST=none Review URL: http://codereview.chromium.org/7349021 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@92705 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'views')
-rw-r--r--views/accessibility/native_view_accessibility_win.cc6
-rw-r--r--views/controls/menu/menu_controller.cc8
-rw-r--r--views/controls/menu/menu_item_view.cc14
-rw-r--r--views/controls/menu/menu_scroll_view_container.cc2
-rw-r--r--views/controls/menu/submenu_view.cc10
-rw-r--r--views/controls/scroll_view.cc2
-rw-r--r--views/controls/single_split_view.cc23
-rw-r--r--views/controls/single_split_view_unittest.cc14
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_gtk.cc2
-rw-r--r--views/controls/tabbed_pane/native_tabbed_pane_win.cc8
-rw-r--r--views/controls/textfield/native_textfield_win.cc2
-rw-r--r--views/examples/scroll_view_example.cc2
-rw-r--r--views/examples/throbber_example.cc2
-rw-r--r--views/examples/widget_example.cc2
-rw-r--r--views/focus/focus_search.cc10
-rw-r--r--views/layout/box_layout.cc4
-rw-r--r--views/layout/fill_layout.cc4
-rw-r--r--views/layout/grid_layout_unittest.cc6
-rw-r--r--views/view.cc59
-rw-r--r--views/view.h18
-rw-r--r--views/widget/root_view.cc2
21 files changed, 94 insertions, 106 deletions
diff --git a/views/accessibility/native_view_accessibility_win.cc b/views/accessibility/native_view_accessibility_win.cc
index c75cb07..12a0b46 100644
--- a/views/accessibility/native_view_accessibility_win.cc
+++ b/views/accessibility/native_view_accessibility_win.cc
@@ -127,7 +127,7 @@ STDMETHODIMP NativeViewAccessibilityWin::accNavigate(
if (nav_dir == NAVDIR_LASTCHILD)
child_id = view_->child_count() - 1;
- views::View* child = view_->GetChildViewAt(child_id);
+ views::View* child = view_->child_at(child_id);
end->vt = VT_DISPATCH;
end->pdispVal = child->GetNativeViewAccessible();
end->pdispVal->AddRef();
@@ -162,7 +162,7 @@ STDMETHODIMP NativeViewAccessibilityWin::accNavigate(
}
}
- views::View* child = parent->GetChildViewAt(view_index);
+ views::View* child = parent->child_at(view_index);
end->pdispVal = child->GetNativeViewAccessible();
end->vt = VT_DISPATCH;
end->pdispVal->AddRef();
@@ -224,7 +224,7 @@ STDMETHODIMP NativeViewAccessibilityWin::get_accChild(VARIANT var_child,
int child_id_as_index = child_id - 1;
if (child_id_as_index < view_->child_count()) {
// Note: child_id is a one based index when indexing children.
- child_view = view_->GetChildViewAt(child_id_as_index);
+ child_view = view_->child_at(child_id_as_index);
} else {
// Attempt to retrieve a child view with the specified id.
child_view = view_->GetViewByID(child_id);
diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc
index d5e3305..b2038da 100644
--- a/views/controls/menu/menu_controller.cc
+++ b/views/controls/menu/menu_controller.cc
@@ -82,7 +82,7 @@ static View* GetFirstHotTrackedView(View* view) {
return view;
for (int i = 0; i < view->child_count(); ++i) {
- View* hot_view = GetFirstHotTrackedView(view->GetChildViewAt(i));
+ View* hot_view = GetFirstHotTrackedView(view->child_at(i));
if (hot_view)
return hot_view;
}
@@ -97,15 +97,13 @@ static View* GetFirstHotTrackedView(View* view) {
static View* GetFirstFocusableView(View* view, int start, bool forward) {
if (forward) {
for (int i = start == -1 ? 0 : start; i < view->child_count(); ++i) {
- View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1,
- forward);
+ View* deepest = GetFirstFocusableView(view->child_at(i), -1, forward);
if (deepest)
return deepest;
}
} else {
for (int i = start == -1 ? view->child_count() - 1 : start; i >= 0; --i) {
- View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1,
- forward);
+ View* deepest = GetFirstFocusableView(view->child_at(i), -1, forward);
if (deepest)
return deepest;
}
diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc
index a20e725..6c70190 100644
--- a/views/controls/menu/menu_item_view.cc
+++ b/views/controls/menu/menu_item_view.cc
@@ -289,7 +289,7 @@ void MenuItemView::RemoveMenuItemAt(int index) {
DCHECK_LE(0, index);
DCHECK_GT(submenu_->child_count(), index);
- View* item = submenu_->GetChildViewAt(index);
+ View* item = submenu_->child_at(index);
DCHECK(item);
submenu_->RemoveChildView(item);
@@ -446,7 +446,7 @@ MenuItemView* MenuItemView::GetMenuItemByID(int id) {
if (!HasSubmenu())
return NULL;
for (int i = 0; i < GetSubmenu()->child_count(); ++i) {
- View* child = GetSubmenu()->GetChildViewAt(i);
+ View* child = GetSubmenu()->child_at(i);
if (child->id() == MenuItemView::kMenuItemViewID) {
MenuItemView* result = static_cast<MenuItemView*>(child)->
GetMenuItemByID(id);
@@ -487,7 +487,7 @@ void MenuItemView::Layout() {
if (child_count() == 1 && GetTitle().size() == 0) {
// We only have one child and no title so let the view take over all the
// space.
- View* child = GetChildViewAt(0);
+ View* child = child_at(0);
gfx::Size size = child->GetPreferredSize();
child->SetBounds(label_start_, GetTopMargin(), size.width(), size.height());
} else {
@@ -495,7 +495,7 @@ void MenuItemView::Layout() {
// right align start with the last view and progress to the first.
for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0;
--i) {
- View* child = GetChildViewAt(i);
+ View* child = child_at(i);
int width = child->GetPreferredSize().width();
child->SetBounds(x - width, 0, width, height());
x -= width - kChildXPadding;
@@ -667,7 +667,7 @@ void MenuItemView::RemoveEmptyMenus() {
// Iterate backwards as we may end up removing views, which alters the child
// view count.
for (int i = submenu_->child_count() - 1; i >= 0; --i) {
- View* child = submenu_->GetChildViewAt(i);
+ View* child = submenu_->child_at(i);
if (child->id() == MenuItemView::kMenuItemViewID) {
MenuItemView* menu_item = static_cast<MenuItemView*>(child);
if (menu_item->HasSubmenu())
@@ -745,7 +745,7 @@ gfx::Size MenuItemView::GetChildPreferredSize() {
return gfx::Size();
if (GetTitle().size() == 0 && child_count() == 1) {
- View* child = GetChildViewAt(0);
+ View* child = child_at(0);
return child->GetPreferredSize();
}
@@ -753,7 +753,7 @@ gfx::Size MenuItemView::GetChildPreferredSize() {
for (int i = 0; i < child_count(); ++i) {
if (i)
width += kChildXPadding;
- width += GetChildViewAt(i)->GetPreferredSize().width();
+ width += child_at(i)->GetPreferredSize().width();
}
// Return a height of 0 to indicate that we should use the title height
// instead.
diff --git a/views/controls/menu/menu_scroll_view_container.cc b/views/controls/menu/menu_scroll_view_container.cc
index 6aed7cf..5f1b94e 100644
--- a/views/controls/menu/menu_scroll_view_container.cc
+++ b/views/controls/menu/menu_scroll_view_container.cc
@@ -150,7 +150,7 @@ class MenuScrollViewContainer::MenuScrollView : public View {
// Returns the contents, which is the SubmenuView.
View* GetContents() {
- return GetChildViewAt(0);
+ return child_at(0);
}
private:
diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc
index 84e4cd1..987cf15 100644
--- a/views/controls/menu/submenu_view.cc
+++ b/views/controls/menu/submenu_view.cc
@@ -55,7 +55,7 @@ SubmenuView::~SubmenuView() {
int SubmenuView::GetMenuItemCount() {
int count = 0;
for (int i = 0; i < child_count(); ++i) {
- if (GetChildViewAt(i)->id() == MenuItemView::kMenuItemViewID)
+ if (child_at(i)->id() == MenuItemView::kMenuItemViewID)
count++;
}
return count;
@@ -63,9 +63,9 @@ int SubmenuView::GetMenuItemCount() {
MenuItemView* SubmenuView::GetMenuItemAt(int index) {
for (int i = 0, count = 0; i < child_count(); ++i) {
- if (GetChildViewAt(i)->id() == MenuItemView::kMenuItemViewID &&
+ if (child_at(i)->id() == MenuItemView::kMenuItemViewID &&
count++ == index) {
- return static_cast<MenuItemView*>(GetChildViewAt(i));
+ return static_cast<MenuItemView*>(child_at(i));
}
}
NOTREACHED();
@@ -91,7 +91,7 @@ void SubmenuView::Layout() {
int y = insets.top();
int menu_item_width = width() - insets.width();
for (int i = 0; i < child_count(); ++i) {
- View* child = GetChildViewAt(i);
+ View* child = child_at(i);
if (child->IsVisible()) {
gfx::Size child_pref_size = child->GetPreferredSize();
child->SetBounds(x, y, menu_item_width, child_pref_size.height());
@@ -108,7 +108,7 @@ gfx::Size SubmenuView::GetPreferredSize() {
int max_width = 0;
int height = 0;
for (int i = 0; i < child_count(); ++i) {
- View* child = GetChildViewAt(i);
+ View* child = child_at(i);
gfx::Size child_pref_size = child->IsVisible() ?
child->GetPreferredSize() : gfx::Size();
max_width = std::max(max_width, child_pref_size.width());
diff --git a/views/controls/scroll_view.cc b/views/controls/scroll_view.cc
index 6a2b912..dd2c650 100644
--- a/views/controls/scroll_view.cc
+++ b/views/controls/scroll_view.cc
@@ -22,7 +22,7 @@ class Viewport : public View {
if (!has_children() || !parent())
return;
- View* contents = GetChildViewAt(0);
+ View* contents = child_at(0);
gfx::Rect scroll_rect(rect);
scroll_rect.Offset(-contents->x(), -contents->y());
static_cast<ScrollView*>(parent())->ScrollContentsRegionToBeVisible(
diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc
index 0397810..5addbb9 100644
--- a/views/controls/single_split_view.cc
+++ b/views/controls/single_split_view.cc
@@ -49,11 +49,11 @@ void SingleSplitView::Layout() {
CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds);
if (has_children()) {
- if (GetChildViewAt(0)->IsVisible())
- GetChildViewAt(0)->SetBoundsRect(leading_bounds);
+ if (child_at(0)->IsVisible())
+ child_at(0)->SetBoundsRect(leading_bounds);
if (child_count() > 1) {
- if (GetChildViewAt(1)->IsVisible())
- GetChildViewAt(1)->SetBoundsRect(trailing_bounds);
+ if (child_at(1)->IsVisible())
+ child_at(1)->SetBoundsRect(trailing_bounds);
}
}
@@ -76,7 +76,7 @@ gfx::Size SingleSplitView::GetPreferredSize() {
int width = 0;
int height = 0;
for (int i = 0; i < 2 && i < child_count(); ++i) {
- View* view = GetChildViewAt(i);
+ View* view = child_at(i);
gfx::Size pref = view->GetPreferredSize();
if (is_horizontal_) {
width += pref.width();
@@ -110,9 +110,8 @@ void SingleSplitView::CalculateChildrenBounds(
const gfx::Rect& bounds,
gfx::Rect* leading_bounds,
gfx::Rect* trailing_bounds) const {
- bool is_leading_visible = has_children() && GetChildViewAt(0)->IsVisible();
- bool is_trailing_visible =
- child_count() > 1 && GetChildViewAt(1)->IsVisible();
+ bool is_leading_visible = has_children() && child_at(0)->IsVisible();
+ bool is_trailing_visible = child_count() > 1 && child_at(1)->IsVisible();
if (!is_leading_visible && !is_trailing_visible) {
*leading_bounds = gfx::Rect();
@@ -171,7 +170,7 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) {
if (is_horizontal_ && base::i18n::IsRTL())
delta_offset *= -1;
// Honor the minimum size when resizing.
- gfx::Size min = GetChildViewAt(0)->GetMinimumSize();
+ gfx::Size min = child_at(0)->GetMinimumSize();
int new_size = std::max(GetPrimaryAxisSize(min.width(), min.height()),
drag_info_.initial_divider_offset + delta_offset);
@@ -206,15 +205,15 @@ bool SingleSplitView::IsPointInDivider(const gfx::Point& p) {
if (child_count() < 2)
return false;
- if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible())
+ if (!child_at(0)->IsVisible() || !child_at(1)->IsVisible())
return false;
int divider_relative_offset;
if (is_horizontal_) {
divider_relative_offset =
- p.x() - GetChildViewAt(base::i18n::IsRTL() ? 1 : 0)->width();
+ p.x() - child_at(base::i18n::IsRTL() ? 1 : 0)->width();
} else {
- divider_relative_offset = p.y() - GetChildViewAt(0)->height();
+ divider_relative_offset = p.y() - child_at(0)->height();
}
return (divider_relative_offset >= 0 &&
divider_relative_offset < kDividerSize);
diff --git a/views/controls/single_split_view_unittest.cc b/views/controls/single_split_view_unittest.cc
index f880528..c3375d8 100644
--- a/views/controls/single_split_view_unittest.cc
+++ b/views/controls/single_split_view_unittest.cc
@@ -15,8 +15,8 @@ namespace {
static void VerifySplitViewLayout(const views::SingleSplitView& split) {
ASSERT_EQ(2, split.child_count());
- const views::View* leading = split.GetChildViewAt(0);
- const views::View* trailing = split.GetChildViewAt(1);
+ const views::View* leading = split.child_at(0);
+ const views::View* trailing = split.child_at(1);
if (split.bounds().IsEmpty()) {
EXPECT_TRUE(leading->bounds().IsEmpty());
@@ -113,16 +113,16 @@ TEST(SingleSplitViewTest, Resize) {
}
// Special cases, one of the child views is hidden.
- split.GetChildViewAt(0)->SetVisible(false);
+ split.child_at(0)->SetVisible(false);
split.Layout();
- EXPECT_EQ(split.size(), split.GetChildViewAt(1)->size());
+ EXPECT_EQ(split.size(), split.child_at(1)->size());
- split.GetChildViewAt(0)->SetVisible(true);
- split.GetChildViewAt(1)->SetVisible(false);
+ split.child_at(0)->SetVisible(true);
+ split.child_at(1)->SetVisible(false);
split.Layout();
- EXPECT_EQ(split.size(), split.GetChildViewAt(0)->size());
+ EXPECT_EQ(split.size(), split.child_at(0)->size());
}
}
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
index ac3ff19..37b24d1 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc
@@ -205,7 +205,7 @@ View* NativeTabbedPaneGtk::GetTabViewAt(int index) {
Widget* widget = GetWidgetAt(index);
DCHECK(widget);
DCHECK_EQ(1, widget->GetRootView()->child_count());
- return widget->GetRootView()->GetChildViewAt(0);
+ return widget->GetRootView()->child_at(0);
}
void NativeTabbedPaneGtk::OnSwitchPage(int selected_tab_index) {
diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
index 829d5a3..5499051 100644
--- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc
+++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc
@@ -57,7 +57,7 @@ class TabLayout : public LayoutManager {
// Switches to the tab page identified by the given index.
void SwitchToPage(View* host, View* page) {
for (int i = 0; i < host->child_count(); ++i) {
- View* child = host->GetChildViewAt(i);
+ View* child = host->child_at(i);
// The child might not have been laid out yet.
if (child == page)
child->SetBoundsRect(host->GetContentsBounds());
@@ -77,7 +77,7 @@ class TabLayout : public LayoutManager {
virtual void Layout(View* host) {
gfx::Rect bounds(host->GetContentsBounds());
for (int i = 0; i < host->child_count(); ++i) {
- View* child = host->GetChildViewAt(i);
+ View* child = host->child_at(i);
// We only layout visible children, since it may be expensive.
if (child->IsVisible() && child->bounds() != bounds)
child->SetBoundsRect(bounds);
@@ -88,7 +88,7 @@ class TabLayout : public LayoutManager {
// First, query the preferred sizes to determine a good width.
int width = 0;
for (int i = 0; i < host->child_count(); ++i) {
- View* page = host->GetChildViewAt(i);
+ View* page = host->child_at(i);
width = std::max(width, page->GetPreferredSize().width());
}
// After we know the width, decide on the height.
@@ -98,7 +98,7 @@ class TabLayout : public LayoutManager {
virtual int GetPreferredHeightForWidth(View* host, int width) {
int height = 0;
for (int i = 0; i < host->child_count(); ++i) {
- View* page = host->GetChildViewAt(i);
+ View* page = host->child_at(i);
height = std::max(height, page->GetHeightForWidth(width));
}
return height;
diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc
index c14fb4d..f53e67b 100644
--- a/views/controls/textfield/native_textfield_win.cc
+++ b/views/controls/textfield/native_textfield_win.cc
@@ -462,7 +462,7 @@ void NativeTextfieldWin::InitializeAccessibilityInfo() {
// Try to find the name of this text field.
// We expect it to be a Label preceeding this view (if it exists).
string16 name;
- View* label_view = parent->GetChildViewAt(label_index);
+ View* label_view = parent->child_at(label_index);
if (label_view->GetClassName() == Label::kViewClassName) {
ui::AccessibleViewState state;
label_view->GetAccessibleState(&state);
diff --git a/views/examples/scroll_view_example.cc b/views/examples/scroll_view_example.cc
index 29febeb..3f47a15 100644
--- a/views/examples/scroll_view_example.cc
+++ b/views/examples/scroll_view_example.cc
@@ -31,7 +31,7 @@ class ScrollViewExample::ScrollableView : public views::View {
}
void PlaceChildY(int index, int y) {
- views::View* view = GetChildViewAt(index);
+ views::View* view = child_at(index);
gfx::Size size = view->GetPreferredSize();
view->SetBounds(0, y, size.width(), size.height());
}
diff --git a/views/examples/throbber_example.cc b/views/examples/throbber_example.cc
index 9def3ce..495b71f 100644
--- a/views/examples/throbber_example.cc
+++ b/views/examples/throbber_example.cc
@@ -27,7 +27,7 @@ class ThrobberView : public views::View {
}
virtual void Layout() {
- views::View* child = GetChildViewAt(0);
+ views::View* child = child_at(0);
gfx::Size ps = child->GetPreferredSize();
child->SetBounds((width() - ps.width()) / 2,
(height() - ps.height()) / 2,
diff --git a/views/examples/widget_example.cc b/views/examples/widget_example.cc
index 07d21d1..a2c834c 100644
--- a/views/examples/widget_example.cc
+++ b/views/examples/widget_example.cc
@@ -21,7 +21,7 @@ class CenterLayout : public views::LayoutManager {
// Overridden from LayoutManager:
virtual void Layout(views::View* host) {
- views::View* child = host->GetChildViewAt(0);
+ views::View* child = host->child_at(0);
gfx::Size size = child->GetPreferredSize();
child->SetBounds((host->width() - size.width()) / 2,
(host->height() - size.height()) / 2,
diff --git a/views/focus/focus_search.cc b/views/focus/focus_search.cc
index eea5f48..cbb95c5 100644
--- a/views/focus/focus_search.cc
+++ b/views/focus/focus_search.cc
@@ -37,10 +37,8 @@ View* FocusSearch::FindNextFocusableView(View* starting_view,
if (!starting_view) {
// Default to the first/last child
- starting_view =
- reverse ?
- root_->GetChildViewAt(root_->child_count() - 1) :
- root_->GetChildViewAt(0);
+ starting_view = reverse ? root_->child_at(root_->child_count() - 1) :
+ root_->child_at(0);
// If there was no starting view, then the one we select is a potential
// focus candidate.
check_starting_view = true;
@@ -159,7 +157,7 @@ View* FocusSearch::FindNextFocusableViewImpl(
// First let's try the left child.
if (can_go_down) {
if (starting_view->has_children()) {
- View* v = FindNextFocusableViewImpl(starting_view->GetChildViewAt(0),
+ View* v = FindNextFocusableViewImpl(starting_view->child_at(0),
true, false, true, skip_group_id,
focus_traversable,
focus_traversable_view);
@@ -225,7 +223,7 @@ View* FocusSearch::FindPreviousFocusableViewImpl(
if (starting_view->has_children()) {
View* view =
- starting_view->GetChildViewAt(starting_view->child_count() - 1);
+ starting_view->child_at(starting_view->child_count() - 1);
View* v = FindPreviousFocusableViewImpl(view, true, false, true,
skip_group_id,
focus_traversable,
diff --git a/views/layout/box_layout.cc b/views/layout/box_layout.cc
index bc9f46a..5441e87 100644
--- a/views/layout/box_layout.cc
+++ b/views/layout/box_layout.cc
@@ -31,7 +31,7 @@ void BoxLayout::Layout(View* host) {
int x = child_area.x();
int y = child_area.y();
for (int i = 0; i < host->child_count(); ++i) {
- View* child = host->GetChildViewAt(i);
+ View* child = host->child_at(i);
if (child->IsVisible()) {
gfx::Rect bounds(x, y, child_area.width(), child_area.height());
gfx::Size size(child->GetPreferredSize());
@@ -52,7 +52,7 @@ gfx::Size BoxLayout::GetPreferredSize(View* host) {
gfx::Rect bounds;
int position = 0;
for (int i = 0; i < host->child_count(); ++i) {
- View* child = host->GetChildViewAt(i);
+ View* child = host->child_at(i);
if (child->IsVisible()) {
gfx::Size size(child->GetPreferredSize());
if (orientation_ == kHorizontal) {
diff --git a/views/layout/fill_layout.cc b/views/layout/fill_layout.cc
index 6fbfe4d..13fbcce 100644
--- a/views/layout/fill_layout.cc
+++ b/views/layout/fill_layout.cc
@@ -18,13 +18,13 @@ void FillLayout::Layout(View* host) {
if (!host->has_children())
return;
- View* frame_view = host->GetChildViewAt(0);
+ View* frame_view = host->child_at(0);
frame_view->SetBounds(0, 0, host->width(), host->height());
}
gfx::Size FillLayout::GetPreferredSize(View* host) {
DCHECK_EQ(1, host->child_count());
- return host->GetChildViewAt(0)->GetPreferredSize();
+ return host->child_at(0)->GetPreferredSize();
}
} // namespace views
diff --git a/views/layout/grid_layout_unittest.cc b/views/layout/grid_layout_unittest.cc
index c893d09..542d7c5 100644
--- a/views/layout/grid_layout_unittest.cc
+++ b/views/layout/grid_layout_unittest.cc
@@ -63,7 +63,7 @@ class GridLayoutTest : public testing::Test {
virtual void RemoveAll() {
for (int i = host.child_count() - 1; i >= 0; i--)
- host.RemoveChildView(host.GetChildViewAt(i));
+ host.RemoveChildView(host.child_at(i));
}
void GetPreferredSize() {
@@ -92,7 +92,7 @@ class GridLayoutAlignmentTest : public testing::Test {
virtual void RemoveAll() {
for (int i = host.child_count() - 1; i >= 0; i--)
- host.RemoveChildView(host.GetChildViewAt(i));
+ host.RemoveChildView(host.child_at(i));
}
void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) {
@@ -402,7 +402,7 @@ TEST_F(GridLayoutTest, FixedSize) {
for (int i = 0; i < column_count; ++i) {
for (int row = 0; row < row_count; ++row) {
- View* view = host.GetChildViewAt(row * column_count + i);
+ View* view = host.child_at(row * column_count + i);
ExpectViewBoundsEquals(
2 + title_width * i + (title_width - pref_width) / 2,
2 + pref_height * row,
diff --git a/views/view.cc b/views/view.cc
index 04cec8f..ace1fcd 100644
--- a/views/view.cc
+++ b/views/view.cc
@@ -223,15 +223,6 @@ void View::RemoveAllChildViews(bool delete_children) {
UpdateTooltip();
}
-const View* View::GetChildViewAt(int index) const {
- return index < child_count() ? children_[index] : NULL;
-}
-
-View* View::GetChildViewAt(int index) {
- return
- const_cast<View*>(const_cast<const View*>(this)->GetChildViewAt(index));
-}
-
bool View::Contains(const View* view) const {
for (const View* v = view; v; v = v->parent_) {
if (v == this)
@@ -540,7 +531,7 @@ void View::Layout() {
// just propagate the Layout() call down the hierarchy, so whoever receives
// the call can take appropriate action.
for (int i = 0, count = child_count(); i < count; ++i) {
- View* child = GetChildViewAt(i);
+ View* child = child_at(i);
if (child->needs_layout_ || !layout_manager_.get()) {
child->needs_layout_ = false;
child->Layout();
@@ -588,7 +579,7 @@ const View* View::GetViewByID(int id) const {
return const_cast<View*>(this);
for (int i = 0, count = child_count(); i < count; ++i) {
- const View* view = GetChildViewAt(i)->GetViewByID(id);
+ const View* view = child_at(i)->GetViewByID(id);
if (view)
return view;
}
@@ -618,7 +609,7 @@ void View::GetViewsInGroup(int group, Views* views) {
views->push_back(this);
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->GetViewsInGroup(group, views);
+ child_at(i)->GetViewsInGroup(group, views);
}
View* View::GetSelectedViewForGroup(int group) {
@@ -801,7 +792,7 @@ View* View::GetEventHandlerForPoint(const gfx::Point& point) {
// Walk the child Views recursively looking for the View that most
// tightly encloses the specified point.
for (int i = child_count() - 1; i >= 0; --i) {
- View* child = GetChildViewAt(i);
+ View* child = child_at(i);
if (!child->IsVisible())
continue;
@@ -1137,14 +1128,8 @@ void View::NativeViewHierarchyChanged(bool attached,
// Painting --------------------------------------------------------------------
void View::PaintChildren(gfx::Canvas* canvas) {
- for (int i = 0, count = child_count(); i < count; ++i) {
- View* child = GetChildViewAt(i);
- if (!child) {
- NOTREACHED() << "Should not have a NULL child View for index in bounds";
- continue;
- }
- child->Paint(canvas);
- }
+ for (int i = 0, count = child_count(); i < count; ++i)
+ child_at(i)->Paint(canvas);
}
void View::OnPaint(gfx::Canvas* canvas) {
@@ -1180,7 +1165,7 @@ void View::PaintComposite() {
}
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->PaintComposite();
+ child_at(i)->PaintComposite();
}
void View::SchedulePaintInternal(const gfx::Rect& rect) {
@@ -1205,7 +1190,7 @@ void View::PaintToLayer(const gfx::Rect& dirty_region) {
} else {
// Forward to all children as a descendant may be dirty and have a layer.
for (int i = child_count() - 1; i >= 0; --i) {
- View* child_view = GetChildViewAt(i);
+ View* child_view = child_at(i);
gfx::Rect child_dirty_rect = dirty_region;
child_dirty_rect.Offset(-child_view->GetMirroredX(), -child_view->y());
@@ -1214,7 +1199,7 @@ void View::PaintToLayer(const gfx::Rect& dirty_region) {
child_dirty_rect);
if (!child_dirty_rect.IsEmpty())
- GetChildViewAt(i)->PaintToLayer(child_dirty_rect);
+ child_at(i)->PaintToLayer(child_dirty_rect);
}
}
}
@@ -1292,7 +1277,7 @@ void View::CreateLayerIfNecessary() {
CreateLayer();
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->CreateLayerIfNecessary();
+ child_at(i)->CreateLayerIfNecessary();
}
void View::MoveLayerToParent(ui::Layer* parent_layer,
@@ -1306,13 +1291,13 @@ void View::MoveLayerToParent(ui::Layer* parent_layer,
gfx::Rect(local_point.x(), local_point.y(), width(), height()));
} else {
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->MoveLayerToParent(parent_layer, local_point);
+ child_at(i)->MoveLayerToParent(parent_layer, local_point);
}
}
void View::DestroyLayerRecurse() {
for (int i = child_count() - 1; i >= 0; --i)
- GetChildViewAt(i)->DestroyLayerRecurse();
+ child_at(i)->DestroyLayerRecurse();
DestroyLayer();
}
@@ -1324,7 +1309,7 @@ void View::UpdateLayerBounds(const gfx::Point& offset) {
} else {
gfx::Point new_offset(offset.x() + x(), offset.y() + y());
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->UpdateLayerBounds(new_offset);
+ child_at(i)->UpdateLayerBounds(new_offset);
}
}
@@ -1482,7 +1467,7 @@ void View::DoRemoveChildView(View* view,
void View::PropagateRemoveNotifications(View* parent) {
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->PropagateRemoveNotifications(parent);
+ child_at(i)->PropagateRemoveNotifications(parent);
for (View* v = this; v; v = v->parent_)
v->ViewHierarchyChangedImpl(true, false, parent, this);
@@ -1490,7 +1475,7 @@ void View::PropagateRemoveNotifications(View* parent) {
void View::PropagateAddNotifications(View* parent, View* child) {
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->PropagateAddNotifications(parent, child);
+ child_at(i)->PropagateAddNotifications(parent, child);
ViewHierarchyChangedImpl(true, true, parent, child);
}
@@ -1498,7 +1483,7 @@ void View::PropagateNativeViewHierarchyChanged(bool attached,
gfx::NativeView native_view,
internal::RootView* root_view) {
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->PropagateNativeViewHierarchyChanged(attached,
+ child_at(i)->PropagateNativeViewHierarchyChanged(attached,
native_view,
root_view);
NativeViewHierarchyChanged(attached, native_view, root_view);
@@ -1533,7 +1518,7 @@ void View::ViewHierarchyChangedImpl(bool register_accelerators,
void View::PropagateVisibilityNotifications(View* start, bool is_visible) {
for (int i = 0, count = child_count(); i < count; ++i)
- GetChildViewAt(i)->PropagateVisibilityNotifications(start, is_visible);
+ child_at(i)->PropagateVisibilityNotifications(start, is_visible);
VisibilityChangedImpl(start, is_visible);
}
@@ -1608,7 +1593,7 @@ void View::RegisterChildrenForVisibleBoundsNotification(View* view) {
if (view->NeedsNotificationWhenVisibleBoundsChange())
view->RegisterForVisibleBoundsNotification();
for (int i = 0; i < view->child_count(); ++i)
- RegisterChildrenForVisibleBoundsNotification(view->GetChildViewAt(i));
+ RegisterChildrenForVisibleBoundsNotification(view->child_at(i));
}
// static
@@ -1616,7 +1601,7 @@ void View::UnregisterChildrenForVisibleBoundsNotification(View* view) {
if (view->NeedsNotificationWhenVisibleBoundsChange())
view->UnregisterForVisibleBoundsNotification();
for (int i = 0; i < view->child_count(); ++i)
- UnregisterChildrenForVisibleBoundsNotification(view->GetChildViewAt(i));
+ UnregisterChildrenForVisibleBoundsNotification(view->child_at(i));
}
void View::RegisterForVisibleBoundsNotification() {
@@ -1958,13 +1943,13 @@ void View::InitFocusSiblings(View* v, int index) {
void View::PropagateThemeChanged() {
for (int i = child_count() - 1; i >= 0; --i)
- GetChildViewAt(i)->PropagateThemeChanged();
+ child_at(i)->PropagateThemeChanged();
OnThemeChanged();
}
void View::PropagateLocaleChanged() {
for (int i = child_count() - 1; i >= 0; --i)
- GetChildViewAt(i)->PropagateLocaleChanged();
+ child_at(i)->PropagateLocaleChanged();
OnLocaleChanged();
}
@@ -2042,7 +2027,7 @@ std::string View::PrintViewGraph(bool first) {
// Children.
for (int i = 0, count = child_count(); i < count; ++i)
- result.append(GetChildViewAt(i)->PrintViewGraph(false));
+ result.append(child_at(i)->PrintViewGraph(false));
if (first)
result.append("}\n");
diff --git a/views/view.h b/views/view.h
index 879242e..a277a69 100644
--- a/views/view.h
+++ b/views/view.h
@@ -13,6 +13,7 @@
#include <vector>
#include "base/i18n/rtl.h"
+#include "base/logging.h"
#include "base/memory/scoped_ptr.h"
#include "build/build_config.h"
#include "ui/base/dragdrop/os_exchange_data.h"
@@ -136,13 +137,20 @@ class View : public AcceleratorTarget {
// the views are deleted, unless marked as not parent owned.
void RemoveAllChildViews(bool delete_children);
- // Returns the child view at |index|.
- const View* GetChildViewAt(int index) const;
- View* GetChildViewAt(int index);
-
- // Returns the number of child views.
+ // STL-style accessors.
+ Views::const_iterator children_begin() { return children_.begin(); }
+ Views::const_iterator children_end() { return children_.end(); }
+ Views::const_reverse_iterator children_rbegin() { return children_.rbegin(); }
+ Views::const_reverse_iterator children_rend() { return children_.rend(); }
int child_count() const { return static_cast<int>(children_.size()); }
bool has_children() const { return !children_.empty(); }
+ View* child_at(int index) {
+ DCHECK_LT(index, child_count());
+ return children_[index];
+ }
+ const View* child_at(int index) const {
+ return const_cast<View*>(const_cast<const View*>(this))->child_at(index);
+ }
// Returns the parent view.
const View* parent() const { return parent_; }
diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc
index 83415a9..c3e0f12 100644
--- a/views/widget/root_view.cc
+++ b/views/widget/root_view.cc
@@ -72,7 +72,7 @@ void RootView::SetContentsView(View* contents_view) {
}
View* RootView::GetContentsView() {
- return child_count() > 0 ? GetChildViewAt(0) : NULL;
+ return child_count() > 0 ? child_at(0) : NULL;
}
void RootView::NotifyNativeViewHierarchyChanged(bool attached,