diff options
Diffstat (limited to 'views')
35 files changed, 402 insertions, 395 deletions
diff --git a/views/accessibility/view_accessibility.cc b/views/accessibility/view_accessibility.cc index 4e7d8a5..c7ab6cc 100644 --- a/views/accessibility/view_accessibility.cc +++ b/views/accessibility/view_accessibility.cc @@ -108,25 +108,12 @@ STDMETHODIMP ViewAccessibility::accLocation( if (!view_) return E_FAIL; - gfx::Rect view_bounds; - // Retrieving the parent View to be used for converting from view-to-screen - // coordinates. - views::View* parent = view_->GetParent(); - - if (parent == NULL) { - // If no parent, remain within the same View. - parent = view_; - } - - // Retrieve active View's bounds. - view_bounds = view_->bounds(); - - if (!view_bounds.IsEmpty()) { - *width = view_bounds.width(); - *height = view_bounds.height(); - - gfx::Point topleft(view_bounds.origin()); - views::View::ConvertPointToScreen(parent, &topleft); + if (!view_->bounds().IsEmpty()) { + *width = view_->width(); + *height = view_->height(); + gfx::Point topleft(view_->bounds().origin()); + views::View::ConvertPointToScreen(view_->parent() ? view_->parent() : view_, + &topleft); *x_left = topleft.x(); *y_top = topleft.y(); } else { @@ -149,16 +136,15 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start, if (start.lVal != CHILDID_SELF) { // Start of navigation must be on the View itself. return E_INVALIDARG; - } else if (view_->GetChildViewCount() == 0) { + } else if (!view_->has_children()) { // No children found. return S_FALSE; } // Set child_id based on first or last child. int child_id = 0; - if (nav_dir == NAVDIR_LASTCHILD) { - child_id = view_->GetChildViewCount() - 1; - } + if (nav_dir == NAVDIR_LASTCHILD) + child_id = view_->child_count() - 1; views::View* child = view_->GetChildViewAt(child_id); end->vt = VT_DISPATCH; @@ -173,17 +159,17 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start, case NAVDIR_DOWN: case NAVDIR_NEXT: { // Retrieve parent to access view index and perform bounds checking. - views::View* parent = view_->GetParent(); + views::View* parent = view_->parent(); if (!parent) { return E_FAIL; } if (start.lVal == CHILDID_SELF) { - int view_index = parent->GetChildIndex(view_); + int view_index = parent->GetIndexOf(view_); // Check navigation bounds, adjusting for View child indexing (MSAA // child indexing starts with 1, whereas View indexing starts with 0). if (!IsValidNav(nav_dir, view_index, -1, - parent->GetChildViewCount() - 1)) { + parent->child_count() - 1)) { // Navigation attempted to go out-of-bounds. end->vt = VT_EMPTY; return S_FALSE; @@ -203,8 +189,7 @@ STDMETHODIMP ViewAccessibility::accNavigate(LONG nav_dir, VARIANT start, } else { // Check navigation bounds, adjusting for MSAA child indexing (MSAA // child indexing starts with 1, whereas View indexing starts with 0). - if (!IsValidNav(nav_dir, start.lVal, 0, - parent->GetChildViewCount() + 1)) { + if (!IsValidNav(nav_dir, start.lVal, 0, parent->child_count() + 1)) { // Navigation attempted to go out-of-bounds. end->vt = VT_EMPTY; return S_FALSE; @@ -255,9 +240,10 @@ STDMETHODIMP ViewAccessibility::get_accChild(VARIANT var_child, views::View* child_view = NULL; if (child_id > 0) { - if (child_id <= view_->GetChildViewCount()) { + 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 - 1); + child_view = view_->GetChildViewAt(child_id_as_index); } else { // Attempt to retrieve a child view with the specified id. child_view = view_->GetViewByID(child_id); @@ -287,7 +273,7 @@ STDMETHODIMP ViewAccessibility::get_accChildCount(LONG* child_count) { if (!view_) return E_FAIL; - *child_count = view_->GetChildViewCount(); + *child_count = view_->child_count(); return S_OK; } @@ -344,7 +330,7 @@ STDMETHODIMP ViewAccessibility::get_accFocus(VARIANT* focus_child) { // This view has focus. focus_child->vt = VT_I4; focus_child->lVal = CHILDID_SELF; - } else if (focus && view_->IsParentOf(focus)) { + } else if (focus && view_->Contains(focus)) { // Return the child object that has the keyboard focus. focus_child->pdispVal = GetAccessibleForView(focus); focus_child->pdispVal->AddRef(); @@ -404,7 +390,7 @@ STDMETHODIMP ViewAccessibility::get_accParent(IDispatch** disp_parent) { if (!view_) return E_FAIL; - views::View* parent_view = view_->GetParent(); + views::View* parent_view = view_->parent(); if (!parent_view) { // This function can get called during teardown of WidetWin so we @@ -528,21 +514,14 @@ void ViewAccessibility::SetState(VARIANT* msaa_state, views::View* view) { if (!view) return; - if (!view->IsEnabled()) { + if (!view->IsEnabled()) msaa_state->lVal |= STATE_SYSTEM_UNAVAILABLE; - } - if (!view->IsVisible()) { + if (!view->IsVisible()) msaa_state->lVal |= STATE_SYSTEM_INVISIBLE; - } - if (view->IsHotTracked()) { + if (view->IsHotTracked()) msaa_state->lVal |= STATE_SYSTEM_HOTTRACKED; - } - if (view->IsPushed()) { + if (view->IsPushed()) msaa_state->lVal |= STATE_SYSTEM_PRESSED; - } - // Check both for actual View focus, as well as accessibility focus. - views::View* parent = view->GetParent(); - if (view->HasFocus()) msaa_state->lVal |= STATE_SYSTEM_FOCUSED; diff --git a/views/animation/bounds_animator.cc b/views/animation/bounds_animator.cc index d65dbd7..a517854 100644 --- a/views/animation/bounds_animator.cc +++ b/views/animation/bounds_animator.cc @@ -39,7 +39,7 @@ BoundsAnimator::~BoundsAnimator() { void BoundsAnimator::AnimateViewTo(View* view, const gfx::Rect& target) { DCHECK(view); - DCHECK_EQ(view->GetParent(), parent_); + DCHECK_EQ(view->parent(), parent_); Data existing_data; diff --git a/views/controls/button/native_button_gtk.cc b/views/controls/button/native_button_gtk.cc index d49f38b..7659f48 100644 --- a/views/controls/button/native_button_gtk.cc +++ b/views/controls/button/native_button_gtk.cc @@ -233,14 +233,14 @@ void NativeRadioButtonGtk::SetGroupFrom(NativeButtonWrapper* wrapper) { //////////////////////////////////////////////////////////////////////////////// // NativeRadioButtonGtk, NativeControlGtk overrides: void NativeRadioButtonGtk::ViewHierarchyChanged(bool is_add, - View *parent, View *child) { + View* parent, View* child) { NativeControlGtk::ViewHierarchyChanged(is_add, parent, child); // look for the same group and update if (is_add && child == this) { - View* container = GetParent(); - while (container && container->GetParent()) - container = container->GetParent(); + View* container = parent; + while (container && container->parent()) + container = container->parent(); if (container) { std::vector<View*> other; container->GetViewsWithGroup(native_button_->GetGroup(), &other); diff --git a/views/controls/button/radio_button.cc b/views/controls/button/radio_button.cc index b189aa6..4074da4 100644 --- a/views/controls/button/radio_button.cc +++ b/views/controls/button/radio_button.cc @@ -34,9 +34,9 @@ void RadioButton::SetChecked(bool checked) { // We can't just get the root view here because sometimes the radio // button isn't attached to a root view (e.g., if it's part of a tab page // that is currently not active). - View* container = GetParent(); - while (container && container->GetParent()) - container = container->GetParent(); + View* container = parent(); + while (container && container->parent()) + container = container->parent(); if (container) { std::vector<View*> other; container->GetViewsWithGroup(GetGroup(), &other); diff --git a/views/controls/menu/menu_controller.cc b/views/controls/menu/menu_controller.cc index 72c6ca4..660f8ef 100644 --- a/views/controls/menu/menu_controller.cc +++ b/views/controls/menu/menu_controller.cc @@ -81,7 +81,7 @@ static View* GetFirstHotTrackedView(View* view) { if (view->IsHotTracked()) return view; - for (int i = 0; i < view->GetChildViewCount(); ++i) { + for (int i = 0; i < view->child_count(); ++i) { View* hot_view = GetFirstHotTrackedView(view->GetChildViewAt(i)); if (hot_view) return hot_view; @@ -96,15 +96,14 @@ static View* GetFirstHotTrackedView(View* view) { // to first. static View* GetFirstFocusableView(View* view, int start, bool forward) { if (forward) { - for (int i = start == -1 ? 0 : start; i < view->GetChildViewCount(); ++i) { + for (int i = start == -1 ? 0 : start; i < view->child_count(); ++i) { View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, forward); if (deepest) return deepest; } } else { - for (int i = start == -1 ? view->GetChildViewCount() - 1 : start; - i >= 0; --i) { + for (int i = start == -1 ? view->child_count() - 1 : start; i >= 0; --i) { View* deepest = GetFirstFocusableView(view->GetChildViewAt(i), -1, forward); if (deepest) @@ -124,11 +123,11 @@ static View* GetInitialFocusableView(View* start, bool forward) { static View* GetNextFocusableView(View* ancestor, View* start_at, bool forward) { - DCHECK(ancestor->IsParentOf(start_at)); + DCHECK(ancestor->Contains(start_at)); View* parent = start_at; do { - View* new_parent = parent->GetParent(); - int index = new_parent->GetChildIndex(parent); + View* new_parent = parent->parent(); + int index = new_parent->GetIndexOf(parent); index += forward ? 1 : -1; if (forward || index != -1) { View* next = GetFirstFocusableView(new_parent, index, forward); @@ -1098,7 +1097,7 @@ MenuItemView* MenuController::GetMenuItemAt(View* source, int x, int y) { View* child_under_mouse = source->GetViewForPoint(gfx::Point(x, y)); while (child_under_mouse && child_under_mouse->GetID() != MenuItemView::kMenuItemViewID) { - child_under_mouse = child_under_mouse->GetParent(); + child_under_mouse = child_under_mouse->parent(); } if (child_under_mouse && child_under_mouse->IsEnabled() && child_under_mouse->GetID() == MenuItemView::kMenuItemViewID) { @@ -1493,7 +1492,7 @@ void MenuController::IncrementSelection(int delta) { } } - if (item->GetChildViewCount()) { + if (item->has_children()) { View* hot_view = GetFirstHotTrackedView(item); if (hot_view) { hot_view->SetHotTracked(false); @@ -1766,7 +1765,7 @@ void MenuController::UpdateActiveMouseView(SubmenuView* event_source, View* target_menu) { View* target = NULL; gfx::Point target_menu_loc(event.location()); - if (target_menu && target_menu->GetChildViewCount()) { + if (target_menu && target_menu->has_children()) { // Locate the deepest child view to send events to. This code assumes we // don't have to walk up the tree to find a view interested in events. This // is currently true for the cases we are embedding views, but if we embed diff --git a/views/controls/menu/menu_item_view.cc b/views/controls/menu/menu_item_view.cc index 04f59bc..f35d0db 100644 --- a/views/controls/menu/menu_item_view.cc +++ b/views/controls/menu/menu_item_view.cc @@ -400,7 +400,7 @@ MenuItemView* MenuItemView::GetMenuItemByID(int id) { return this; if (!HasSubmenu()) return NULL; - for (int i = 0; i < GetSubmenu()->GetChildViewCount(); ++i) { + for (int i = 0; i < GetSubmenu()->child_count(); ++i) { View* child = GetSubmenu()->GetChildViewAt(i); if (child->GetID() == MenuItemView::kMenuItemViewID) { MenuItemView* result = static_cast<MenuItemView*>(child)-> @@ -435,13 +435,13 @@ void MenuItemView::ChildrenChanged() { } void MenuItemView::Layout() { - int child_count = GetChildViewCount(); - if (child_count == 0) + if (!has_children()) return; - // Child views are layed out right aligned and given the full height. To right + // Child views are laid out right aligned and given the full height. To 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) { + for (int i = child_count() - 1, x = width() - item_right_margin_; i >= 0; + --i) { View* child = GetChildViewAt(i); int width = child->GetPreferredSize().width(); child->SetBounds(x - width, 0, width, height()); @@ -581,8 +581,8 @@ int MenuItemView::GetDrawStringFlags() { void MenuItemView::AddEmptyMenus() { DCHECK(HasSubmenu()); - if (submenu_->GetChildViewCount() == 0) { - submenu_->AddChildView(0, new EmptyMenuMenuItem(this)); + if (!submenu_->has_children()) { + submenu_->AddChildViewAt(new EmptyMenuMenuItem(this), 0); } else { for (int i = 0, item_count = submenu_->GetMenuItemCount(); i < item_count; ++i) { @@ -597,7 +597,7 @@ void MenuItemView::RemoveEmptyMenus() { DCHECK(HasSubmenu()); // Iterate backwards as we may end up removing views, which alters the child // view count. - for (int i = submenu_->GetChildViewCount() - 1; i >= 0; --i) { + for (int i = submenu_->child_count() - 1; i >= 0; --i) { View* child = submenu_->GetChildViewAt(i); if (child->GetID() == MenuItemView::kMenuItemViewID) { MenuItemView* menu_item = static_cast<MenuItemView*>(child); @@ -664,12 +664,11 @@ int MenuItemView::GetBottomMargin() { } int MenuItemView::GetChildPreferredWidth() { - int child_count = GetChildViewCount(); - if (child_count == 0) + if (!has_children()) return 0; int width = 0; - for (int i = 0; i < child_count; ++i) { + for (int i = 0; i < child_count(); ++i) { if (i) width += kChildXPadding; width += GetChildViewAt(i)->GetPreferredSize().width(); diff --git a/views/controls/menu/menu_item_view_gtk.cc b/views/controls/menu/menu_item_view_gtk.cc index e912964..c995c19 100644 --- a/views/controls/menu/menu_item_view_gtk.cc +++ b/views/controls/menu/menu_item_view_gtk.cc @@ -41,7 +41,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { bool render_selection = (!for_drag && IsSelected() && parent_menu_item_->GetSubmenu()->GetShowSelection(this) && - GetChildViewCount() == 0); + !has_children()); int icon_x = config.item_left_margin; int top_margin = GetTopMargin(); diff --git a/views/controls/menu/menu_item_view_win.cc b/views/controls/menu/menu_item_view_win.cc index c0cd309..cf8ab974 100644 --- a/views/controls/menu/menu_item_view_win.cc +++ b/views/controls/menu/menu_item_view_win.cc @@ -30,7 +30,7 @@ void MenuItemView::Paint(gfx::Canvas* canvas, bool for_drag) { bool render_selection = (!for_drag && IsSelected() && parent_menu_item_->GetSubmenu()->GetShowSelection(this) && - GetChildViewCount() == 0); + !has_children()); int state = render_selection ? MPI_HOT : (IsEnabled() ? MPI_NORMAL : MPI_DISABLED); HDC dc = canvas->BeginPlatformPaint(); diff --git a/views/controls/menu/submenu_view.cc b/views/controls/menu/submenu_view.cc index a3428f7..56bd103 100644 --- a/views/controls/menu/submenu_view.cc +++ b/views/controls/menu/submenu_view.cc @@ -47,7 +47,7 @@ SubmenuView::~SubmenuView() { int SubmenuView::GetMenuItemCount() { int count = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID) count++; } @@ -55,7 +55,7 @@ int SubmenuView::GetMenuItemCount() { } MenuItemView* SubmenuView::GetMenuItemAt(int index) { - for (int i = 0, count = 0; i < GetChildViewCount(); ++i) { + for (int i = 0, count = 0; i < child_count(); ++i) { if (GetChildViewAt(i)->GetID() == MenuItemView::kMenuItemViewID && count++ == index) { return static_cast<MenuItemView*>(GetChildViewAt(i)); @@ -67,24 +67,23 @@ MenuItemView* SubmenuView::GetMenuItemAt(int index) { void SubmenuView::Layout() { // We're in a ScrollView, and need to set our width/height ourselves. - View* parent = GetParent(); - if (!parent) + if (!parent()) return; // Use our current y, unless it means part of the menu isn't visible anymore. int pref_height = GetPreferredSize().height(); int new_y; - if (pref_height > parent->height()) - new_y = std::max(parent->height() - pref_height, y()); + if (pref_height > parent()->height()) + new_y = std::max(parent()->height() - pref_height, y()); else new_y = 0; - SetBounds(x(), new_y, parent->width(), pref_height); + SetBounds(x(), new_y, parent()->width(), pref_height); gfx::Insets insets = GetInsets(); int x = insets.left(); int y = insets.top(); int menu_item_width = width() - insets.width(); - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { View* child = GetChildViewAt(i); if (child->IsVisible()) { gfx::Size child_pref_size = child->GetPreferredSize(); @@ -95,13 +94,13 @@ void SubmenuView::Layout() { } gfx::Size SubmenuView::GetPreferredSize() { - if (GetChildViewCount() == 0) + if (!has_children()) return gfx::Size(); max_accelerator_width_ = 0; int max_width = 0; int height = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { View* child = GetChildViewAt(i); gfx::Size child_pref_size = child->IsVisible() ? child->GetPreferredSize() : gfx::Size(); diff --git a/views/controls/native_control.cc b/views/controls/native_control.cc index caea8c1..f00ab84 100644 --- a/views/controls/native_control.cc +++ b/views/controls/native_control.cc @@ -146,7 +146,7 @@ class NativeControlContainer : public CWindowImpl<NativeControlContainer, if (brush) return reinterpret_cast<LRESULT>(brush); } - ancestor = ancestor->GetParent(); + ancestor = ancestor->parent(); } // COLOR_BTNFACE is the default for dialog box backgrounds. diff --git a/views/controls/native_control_gtk.cc b/views/controls/native_control_gtk.cc index e0ce2f0..eb97394 100644 --- a/views/controls/native_control_gtk.cc +++ b/views/controls/native_control_gtk.cc @@ -67,13 +67,13 @@ void NativeControlGtk::Focus() { DCHECK(native_view()); gtk_widget_grab_focus(native_view()); - GetParent()->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_FOCUS); + parent()->NotifyAccessibilityEvent(AccessibilityTypes::EVENT_FOCUS); } void NativeControlGtk::NativeControlCreated(GtkWidget* native_control) { Attach(native_control); - // Update the newly created GtkWdigetwith any resident enabled state. + // Update the newly created GtkWidget with any resident enabled state. gtk_widget_set_sensitive(native_view(), IsEnabled()); // Listen for focus change event to update the FocusManager focused view. diff --git a/views/controls/native_control_win.cc b/views/controls/native_control_win.cc index b81b2ea..9eaf25e 100644 --- a/views/controls/native_control_win.cc +++ b/views/controls/native_control_win.cc @@ -102,7 +102,7 @@ void NativeControlWin::Focus() { // Since we are being wrapped by a view, accessibility should receive // the super class as the focused view. - View* parent_view = GetParent(); + View* parent_view = parent(); // Due to some controls not behaving as expected without having // a native win32 control, we don't always send a native (MSAA) @@ -184,7 +184,7 @@ LRESULT NativeControlWin::GetControlColor(UINT message, HDC dc, HWND sender) { if (brush) return reinterpret_cast<LRESULT>(brush); } - ancestor = ancestor->GetParent(); + ancestor = ancestor->parent(); } // COLOR_BTNFACE is the default for dialog box backgrounds. diff --git a/views/controls/scroll_view.cc b/views/controls/scroll_view.cc index 79183da..05ab89f 100644 --- a/views/controls/scroll_view.cc +++ b/views/controls/scroll_view.cc @@ -19,13 +19,13 @@ class Viewport : public View { virtual ~Viewport() {} virtual void ScrollRectToVisible(const gfx::Rect& rect) { - if (!GetChildViewCount() || !GetParent()) + if (!has_children() || !parent()) return; View* contents = GetChildViewAt(0); gfx::Rect scroll_rect(rect); scroll_rect.Offset(-contents->x(), -contents->y()); - static_cast<ScrollView*>(GetParent())->ScrollContentsRegionToBeVisible( + static_cast<ScrollView*>(parent())->ScrollContentsRegionToBeVisible( scroll_rect); } @@ -46,17 +46,14 @@ ScrollView::ScrollView(ScrollBar* horizontal_scrollbar, ScrollView::~ScrollView() { // If scrollbars are currently not used, delete them - if (!horiz_sb_->GetParent()) { + if (!horiz_sb_->parent()) delete horiz_sb_; - } - if (!vert_sb_->GetParent()) { + if (!vert_sb_->parent()) delete vert_sb_; - } - if (resize_corner_ && !resize_corner_->GetParent()) { + if (resize_corner_ && !resize_corner_->parent()) delete resize_corner_; - } } void ScrollView::SetContents(View* a_view) { @@ -449,7 +446,7 @@ int VariableRowHeightScrollHelper::GetPageScrollIncrement( return 0; // y coordinate is most likely negative. int y = abs(scroll_view->GetContents()->y()); - int vis_height = scroll_view->GetContents()->GetParent()->height(); + int vis_height = scroll_view->GetContents()->parent()->height(); if (is_positive) { // Align the bottom most row to the top of the view. int bottom = std::min(scroll_view->GetContents()->height() - 1, diff --git a/views/controls/single_split_view.cc b/views/controls/single_split_view.cc index 3936ad6..ad2a59a 100644 --- a/views/controls/single_split_view.cc +++ b/views/controls/single_split_view.cc @@ -39,7 +39,8 @@ SingleSplitView::SingleSplitView(View* leading, } void SingleSplitView::OnBoundsChanged() { - divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_, bounds()); + divider_offset_ = CalculateDividerOffset(divider_offset_, previous_bounds_, + bounds()); View::OnBoundsChanged(); previous_bounds_ = bounds(); } @@ -49,10 +50,10 @@ void SingleSplitView::Layout() { gfx::Rect trailing_bounds; CalculateChildrenBounds(bounds(), &leading_bounds, &trailing_bounds); - if (GetChildViewCount() > 0) { + if (has_children()) { if (GetChildViewAt(0)->IsVisible()) GetChildViewAt(0)->SetBoundsRect(leading_bounds); - if (GetChildViewCount() > 1) { + if (child_count() > 1) { if (GetChildViewAt(1)->IsVisible()) GetChildViewAt(1)->SetBoundsRect(trailing_bounds); } @@ -71,7 +72,7 @@ AccessibilityTypes::Role SingleSplitView::GetAccessibleRole() { gfx::Size SingleSplitView::GetPreferredSize() { int width = 0; int height = 0; - for (int i = 0; i < 2 && i < GetChildViewCount(); ++i) { + for (int i = 0; i < 2 && i < child_count(); ++i) { View* view = GetChildViewAt(i); gfx::Size pref = view->GetPreferredSize(); if (is_horizontal_) { @@ -110,10 +111,9 @@ void SingleSplitView::CalculateChildrenBounds( const gfx::Rect& bounds, gfx::Rect* leading_bounds, gfx::Rect* trailing_bounds) const { - bool is_leading_visible = - GetChildViewCount() > 0 && GetChildViewAt(0)->IsVisible(); + bool is_leading_visible = has_children() && GetChildViewAt(0)->IsVisible(); bool is_trailing_visible = - GetChildViewCount() > 1 && GetChildViewAt(1)->IsVisible(); + child_count() > 1 && GetChildViewAt(1)->IsVisible(); if (!is_leading_visible && !is_trailing_visible) { *leading_bounds = gfx::Rect(); @@ -160,7 +160,7 @@ bool SingleSplitView::OnMousePressed(const MouseEvent& event) { } bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { - if (GetChildViewCount() < 2) + if (child_count() < 2) return false; int delta_offset = GetPrimaryAxisSize(event.x(), event.y()) - @@ -184,7 +184,7 @@ bool SingleSplitView::OnMouseDragged(const MouseEvent& event) { } void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) { - if (GetChildViewCount() < 2) + if (child_count() < 2) return; if (canceled && drag_info_.initial_divider_offset != divider_offset_) { @@ -195,7 +195,7 @@ void SingleSplitView::OnMouseReleased(const MouseEvent& event, bool canceled) { } bool SingleSplitView::IsPointInDivider(const gfx::Point& p) { - if (GetChildViewCount() < 2) + if (child_count() < 2) return false; if (!GetChildViewAt(0)->IsVisible() || !GetChildViewAt(1)->IsVisible()) diff --git a/views/controls/single_split_view_unittest.cc b/views/controls/single_split_view_unittest.cc index 3d84bd7..a42e3b8 100644 --- a/views/controls/single_split_view_unittest.cc +++ b/views/controls/single_split_view_unittest.cc @@ -13,10 +13,10 @@ using ::testing::Return; namespace { static void VerifySplitViewLayout(const views::SingleSplitView& split) { - ASSERT_EQ(2, split.GetChildViewCount()); + ASSERT_EQ(2, split.child_count()); - views::View* leading = split.GetChildViewAt(0); - views::View* trailing = split.GetChildViewAt(1); + const views::View* leading = split.GetChildViewAt(0); + const views::View* trailing = split.GetChildViewAt(1); if (split.bounds().IsEmpty()) { EXPECT_TRUE(leading->bounds().IsEmpty()); diff --git a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc index 5172191..a82e893 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_gtk.cc @@ -201,7 +201,7 @@ WidgetGtk* NativeTabbedPaneGtk::GetWidgetAt(int index) { View* NativeTabbedPaneGtk::GetTabViewAt(int index) { WidgetGtk* widget = GetWidgetAt(index); - DCHECK(widget && widget->GetRootView()->GetChildViewCount() == 1); + DCHECK(widget && widget->GetRootView()->child_count() == 1); return widget->GetRootView()->GetChildViewAt(0); } diff --git a/views/controls/tabbed_pane/native_tabbed_pane_win.cc b/views/controls/tabbed_pane/native_tabbed_pane_win.cc index c727437..aa651ac 100644 --- a/views/controls/tabbed_pane/native_tabbed_pane_win.cc +++ b/views/controls/tabbed_pane/native_tabbed_pane_win.cc @@ -53,7 +53,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->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* child = host->GetChildViewAt(i); // The child might not have been laid out yet. if (child == page) @@ -64,8 +64,8 @@ class TabLayout : public LayoutManager { FocusManager* focus_manager = page->GetFocusManager(); DCHECK(focus_manager); View* focused_view = focus_manager->GetFocusedView(); - if (focused_view && host->IsParentOf(focused_view) && - !page->IsParentOf(focused_view)) + if (focused_view && host->Contains(focused_view) && + !page->Contains(focused_view)) focus_manager->SetFocusedView(page); } @@ -73,7 +73,7 @@ class TabLayout : public LayoutManager { // LayoutManager overrides: virtual void Layout(View* host) { gfx::Rect bounds(host->GetContentsBounds()); - for (int i = 0; i < host->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* child = host->GetChildViewAt(i); // We only layout visible children, since it may be expensive. if (child->IsVisible() && child->bounds() != bounds) @@ -84,7 +84,7 @@ class TabLayout : public LayoutManager { virtual gfx::Size GetPreferredSize(View* host) { // First, query the preferred sizes to determine a good width. int width = 0; - for (int i = 0; i < host->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* page = host->GetChildViewAt(i); width = std::max(width, page->GetPreferredSize().width()); } @@ -94,7 +94,7 @@ class TabLayout : public LayoutManager { virtual int GetPreferredHeightForWidth(View* host, int width) { int height = 0; - for (int i = 0; i < host->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* page = host->GetChildViewAt(i); height = std::max(height, page->GetHeightForWidth(width)); } diff --git a/views/controls/textfield/native_textfield_win.cc b/views/controls/textfield/native_textfield_win.cc index 222f722..681b15f 100644 --- a/views/controls/textfield/native_textfield_win.cc +++ b/views/controls/textfield/native_textfield_win.cc @@ -436,8 +436,8 @@ void NativeTextfieldWin::InitializeAccessibilityInfo() { CHILDID_SELF, PROPID_ACC_ROLE, var); // Set the accessible name by getting the label text. - View* parent = textfield_->GetParent(); - int label_index = parent->GetChildIndex(textfield_) - 1; + View* parent = textfield_->parent(); + int label_index = parent->GetIndexOf(textfield_) - 1; if (label_index >= 0) { // Try to find the name of this text field. // We expect it to be a Label preceeding this view (if it exists). diff --git a/views/debug_utils.cc b/views/debug_utils.cc new file mode 100644 index 0000000..1a6cda2 --- /dev/null +++ b/views/debug_utils.cc @@ -0,0 +1,76 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "views/debug_utils.h" + +#include "base/logging.h" +#include "base/utf_string_conversions.h" +#include "views/view.h" + +#ifndef NDEBUG +#include <iostream> +#endif + +namespace views { + +#ifndef NDEBUG + +namespace { +void PrintViewHierarchyImp(const View* view, int indent) { + std::wostringstream buf; + int ind = indent; + while (ind-- > 0) + buf << L' '; + buf << UTF8ToWide(view->GetClassName()); + buf << L' '; + buf << view->GetID(); + buf << L' '; + buf << view->x() << L"," << view->y() << L","; + buf << view->bounds().right() << L"," << view->bounds().bottom(); + buf << L' '; + buf << view; + + VLOG(1) << buf.str(); + std::cout << buf.str() << std::endl; + + for (int i = 0, count = view->child_count(); i < count; ++i) + PrintViewHierarchyImp(view->GetChildViewAt(i), indent + 2); +} + +void PrintFocusHierarchyImp(const View* view, int indent) { + std::wostringstream buf; + int ind = indent; + while (ind-- > 0) + buf << L' '; + buf << UTF8ToWide(view->GetClassName()); + buf << L' '; + buf << view->GetID(); + buf << L' '; + buf << view->GetClassName().c_str(); + buf << L' '; + buf << view; + + VLOG(1) << buf.str(); + std::cout << buf.str() << std::endl; + + if (view->child_count() > 0) + PrintFocusHierarchyImp(view->GetChildViewAt(0), indent + 2); + + const View* next_focusable = view->GetNextFocusableView(); + if (next_focusable) + PrintFocusHierarchyImp(next_focusable, indent); +} +} // namespace + +void PrintViewHierarchy(const View* view) { + PrintViewHierarchyImp(view, 0); +} + +void PrintFocusHierarchy(const View* view) { + PrintFocusHierarchyImp(view, 0); +} + +} // namespace views + +#endif // NDEBUG diff --git a/views/debug_utils.h b/views/debug_utils.h new file mode 100644 index 0000000..ca82711 --- /dev/null +++ b/views/debug_utils.h @@ -0,0 +1,24 @@ +// Copyright (c) 2011 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef VIEWS_DEBUG_UTILS_H_ +#define VIEWS_DEBUG_UTILS_H_ + +namespace views { + +class View; + +#ifndef NDEBUG + +// Log the view hierarchy. +void PrintViewHierarchy(const View* view); + +// Log the focus traversal hierarchy. +void PrintFocusHierarchy(const View* view); + +#endif // NDEBUG + +} // namespace views + +#endif // VIEWS_DEBUG_UTILS_H_ diff --git a/views/focus/external_focus_tracker.cc b/views/focus/external_focus_tracker.cc index 0787359..6af74d6 100644 --- a/views/focus/external_focus_tracker.cc +++ b/views/focus/external_focus_tracker.cc @@ -30,7 +30,7 @@ ExternalFocusTracker::~ExternalFocusTracker() { void ExternalFocusTracker::FocusWillChange(View* focused_before, View* focused_now) { - if (focused_now && !parent_view_->IsParentOf(focused_now) && + if (focused_now && !parent_view_->Contains(focused_now) && parent_view_ != focused_now) { // Store the newly focused view. StoreLastFocusedView(focused_now); diff --git a/views/focus/focus_manager.cc b/views/focus/focus_manager.cc index faaf4c5..d217e63 100644 --- a/views/focus/focus_manager.cc +++ b/views/focus/focus_manager.cc @@ -126,8 +126,8 @@ bool FocusManager::OnKeyEvent(const KeyEvent& event) { key_code == ui::VKEY_LEFT || key_code == ui::VKEY_RIGHT)) { bool next = (key_code == ui::VKEY_RIGHT || key_code == ui::VKEY_DOWN); std::vector<View*> views; - focused_view_->GetParent()->GetViewsWithGroup(focused_view_->GetGroup(), - &views); + focused_view_->parent()->GetViewsWithGroup(focused_view_->GetGroup(), + &views); std::vector<View*>::const_iterator iter = std::find(views.begin(), views.end(), focused_view_); @@ -224,7 +224,7 @@ View* FocusManager::GetNextFocusableView(View* original_starting_view, starting_view = original_starting_view; break; } - pane_search = pane_search->GetParent(); + pane_search = pane_search->parent(); } if (!focus_traversable) { diff --git a/views/focus/focus_search.cc b/views/focus/focus_search.cc index f3fac86..eea5f48 100644 --- a/views/focus/focus_search.cc +++ b/views/focus/focus_search.cc @@ -24,7 +24,7 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, *focus_traversable = NULL; *focus_traversable_view = NULL; - if (root_->GetChildViewCount() == 0) { + if (!root_->has_children()) { NOTREACHED(); // Nothing to focus on here. return NULL; @@ -39,14 +39,14 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, // Default to the first/last child starting_view = reverse ? - root_->GetChildViewAt(root_->GetChildViewCount() - 1) : + root_->GetChildViewAt(root_->child_count() - 1) : root_->GetChildViewAt(0); // If there was no starting view, then the one we select is a potential // focus candidate. check_starting_view = true; } else { // The starting view should be a direct or indirect child of the root. - DCHECK(root_->IsParentOf(starting_view)); + DCHECK(root_->Contains(starting_view)); } View* v = NULL; @@ -70,7 +70,7 @@ View* FocusSearch::FindNextFocusableView(View* starting_view, } // Don't set the focus to something outside of this view hierarchy. - if (v && v != root_ && !root_->IsParentOf(v)) + if (v && v != root_ && !root_->Contains(v)) v = NULL; // If |cycle_| is true, prefer to keep cycling rather than returning NULL. @@ -121,11 +121,7 @@ View* FocusSearch::FindSelectedViewForGroup(View* view) { } View* FocusSearch::GetParent(View* v) { - if (root_->IsParentOf(v)) { - return v->GetParent(); - } else { - return NULL; - } + return root_->Contains(v) ? v->parent() : NULL; } // Strategy for finding the next focusable view: @@ -162,7 +158,7 @@ View* FocusSearch::FindNextFocusableViewImpl( // First let's try the left child. if (can_go_down) { - if (starting_view->GetChildViewCount() > 0) { + if (starting_view->has_children()) { View* v = FindNextFocusableViewImpl(starting_view->GetChildViewAt(0), true, false, true, skip_group_id, focus_traversable, @@ -227,9 +223,9 @@ View* FocusSearch::FindPreviousFocusableViewImpl( return NULL; } - if (starting_view->GetChildViewCount() > 0) { + if (starting_view->has_children()) { View* view = - starting_view->GetChildViewAt(starting_view->GetChildViewCount() - 1); + starting_view->GetChildViewAt(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 a9aa227..bc9f46a 100644 --- a/views/layout/box_layout.cc +++ b/views/layout/box_layout.cc @@ -30,7 +30,7 @@ void BoxLayout::Layout(View* host) { inside_border_vertical_spacing_); int x = child_area.x(); int y = child_area.y(); - for (int i = 0; i < host->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* child = host->GetChildViewAt(i); if (child->IsVisible()) { gfx::Rect bounds(x, y, child_area.width(), child_area.height()); @@ -51,7 +51,7 @@ void BoxLayout::Layout(View* host) { gfx::Size BoxLayout::GetPreferredSize(View* host) { gfx::Rect bounds; int position = 0; - for (int i = 0; i < host->GetChildViewCount(); ++i) { + for (int i = 0; i < host->child_count(); ++i) { View* child = host->GetChildViewAt(i); if (child->IsVisible()) { gfx::Size size(child->GetPreferredSize()); diff --git a/views/layout/fill_layout.cc b/views/layout/fill_layout.cc index cc636ad..921f27b 100644 --- a/views/layout/fill_layout.cc +++ b/views/layout/fill_layout.cc @@ -15,7 +15,7 @@ FillLayout::~FillLayout() { } void FillLayout::Layout(View* host) { - if (host->GetChildViewCount() == 0) + if (!host->has_children()) return; View* frame_view = host->GetChildViewAt(0); @@ -23,7 +23,7 @@ void FillLayout::Layout(View* host) { } gfx::Size FillLayout::GetPreferredSize(View* host) { - DCHECK(host->GetChildViewCount() == 1); + DCHECK(host->child_count() == 1); return host->GetChildViewAt(0)->GetPreferredSize(); } diff --git a/views/layout/grid_layout.cc b/views/layout/grid_layout.cc index 971a033..bedbd79 100644 --- a/views/layout/grid_layout.cc +++ b/views/layout/grid_layout.cc @@ -960,9 +960,9 @@ void GridLayout::CalculateMasterColumnsIfNecessary() { } void GridLayout::AddViewState(ViewState* view_state) { - DCHECK(view_state->view && (view_state->view->GetParent() == NULL || - view_state->view->GetParent() == host_)); - if (!view_state->view->GetParent()) { + DCHECK(view_state->view && (view_state->view->parent() == NULL || + view_state->view->parent() == host_)); + if (!view_state->view->parent()) { adding_view_ = true; host_->AddChildView(view_state->view); adding_view_ = false; diff --git a/views/layout/grid_layout_unittest.cc b/views/layout/grid_layout_unittest.cc index 4cd2eae..c893d09 100644 --- a/views/layout/grid_layout_unittest.cc +++ b/views/layout/grid_layout_unittest.cc @@ -62,9 +62,8 @@ class GridLayoutTest : public testing::Test { } virtual void RemoveAll() { - for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { + for (int i = host.child_count() - 1; i >= 0; i--) host.RemoveChildView(host.GetChildViewAt(i)); - } } void GetPreferredSize() { @@ -92,9 +91,8 @@ class GridLayoutAlignmentTest : public testing::Test { } virtual void RemoveAll() { - for (int i = host.GetChildViewCount() - 1; i >= 0; i--) { + for (int i = host.child_count() - 1; i >= 0; i--) host.RemoveChildView(host.GetChildViewAt(i)); - } } void TestAlignment(GridLayout::Alignment alignment, gfx::Rect* bounds) { diff --git a/views/view.cc b/views/view.cc index 0770aafe..f63f08f 100644 --- a/views/view.cc +++ b/views/view.cc @@ -5,9 +5,6 @@ #include "views/view.h" #include <algorithm> -#ifndef NDEBUG -#include <iostream> -#endif #include "base/logging.h" #include "base/message_loop.h" @@ -81,11 +78,11 @@ View::~View() { if (parent_) parent_->RemoveChildView(this); - int c = static_cast<int>(child_views_.size()); + int c = static_cast<int>(children_.size()); while (--c >= 0) { - child_views_[c]->SetParent(NULL); - if (child_views_[c]->IsParentOwned()) - delete child_views_[c]; + children_[c]->SetParent(NULL); + if (children_[c]->IsParentOwned()) + delete children_[c]; } #if defined(OS_WIN) @@ -96,114 +93,109 @@ View::~View() { // Tree operations ------------------------------------------------------------- -void View::AddChildView(View* v) { - AddChildView(static_cast<int>(child_views_.size()), v); +const Widget* View::GetWidget() const { + // The root view holds a reference to this view hierarchy's Widget. + return parent_ ? parent_->GetWidget() : NULL; +} + +Widget* View::GetWidget() { + return const_cast<Widget*>(const_cast<const View*>(this)->GetWidget()); } -void View::AddChildView(int index, View* v) { - CHECK(v != this) << "You cannot add a view as its own child"; +void View::AddChildView(View* view) { + AddChildViewAt(view, child_count()); +} + +void View::AddChildViewAt(View* view, int index) { + CHECK(view != this) << "You cannot add a view as its own child"; // Remove the view from its current parent if any. - if (v->GetParent()) - v->GetParent()->RemoveChildView(v); + if (view->parent()) + view->parent()->RemoveChildView(view); // Sets the prev/next focus views. - InitFocusSiblings(v, index); + InitFocusSiblings(view, index); // Let's insert the view. - child_views_.insert(child_views_.begin() + index, v); - v->SetParent(this); + children_.insert(children_.begin() + index, view); + view->SetParent(this); - for (View* p = this; p; p = p->GetParent()) - p->ViewHierarchyChangedImpl(false, true, this, v); + for (View* p = this; p; p = p->parent()) + p->ViewHierarchyChangedImpl(false, true, this, view); - v->PropagateAddNotifications(this, v); + view->PropagateAddNotifications(this, view); UpdateTooltip(); RootView* root = GetRootView(); if (root) - RegisterChildrenForVisibleBoundsNotification(root, v); + RegisterChildrenForVisibleBoundsNotification(root, view); if (layout_manager_.get()) - layout_manager_->ViewAdded(this, v); -} - -View* View::GetChildViewAt(int index) const { - return index < GetChildViewCount() ? child_views_[index] : NULL; + layout_manager_->ViewAdded(this, view); } -void View::RemoveChildView(View* a_view) { - DoRemoveChildView(a_view, true, true, false); +void View::RemoveChildView(View* view) { + DoRemoveChildView(view, true, true, false); } void View::RemoveAllChildViews(bool delete_views) { - ViewList::iterator iter; - while ((iter = child_views_.begin()) != child_views_.end()) { + ViewVector::iterator iter; + while ((iter = children_.begin()) != children_.end()) DoRemoveChildView(*iter, false, false, delete_views); - } UpdateTooltip(); } -int View::GetChildViewCount() const { - return static_cast<int>(child_views_.size()); +const View* View::GetChildViewAt(int index) const { + return index < child_count() ? children_[index] : NULL; } -bool View::HasChildView(View* a_view) { - return find(child_views_.begin(), - child_views_.end(), - a_view) != child_views_.end(); +View* View::GetChildViewAt(int index) { + return + const_cast<View*>(const_cast<const View*>(this)->GetChildViewAt(index)); } -Widget* View::GetWidget() const { - // The root view holds a reference to this view hierarchy's Widget. - return parent_ ? parent_->GetWidget() : NULL; +bool View::Contains(const View* view) const { + const View* child = view; + while (child) { + if (child == this) + return true; + child = child->parent(); + } + return false; } -Window* View::GetWindow() const { - Widget* widget = GetWidget(); +int View::GetIndexOf(const View* view) const { + ViewVector::const_iterator it = std::find(children_.begin(), children_.end(), + view); + return it != children_.end() ? it - children_.begin() : -1; +} + +// TODO(beng): remove +const Window* View::GetWindow() const { + const Widget* widget = GetWidget(); return widget ? widget->GetWindow() : NULL; } +// TODO(beng): remove +Window* View::GetWindow() { + return const_cast<Window*>(const_cast<const View*>(this)->GetWindow()); +} + +// TODO(beng): remove bool View::ContainsNativeView(gfx::NativeView native_view) const { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) { + for (int i = 0, count = child_count(); i < count; ++i) { if (GetChildViewAt(i)->ContainsNativeView(native_view)) return true; } return false; } -// Get the containing RootView +// TODO(beng): remove RootView* View::GetRootView() { Widget* widget = GetWidget(); return widget ? widget->GetRootView() : NULL; } -int View::GetChildIndex(const View* v) const { - for (int i = 0, count = GetChildViewCount(); i < count; i++) { - if (v == GetChildViewAt(i)) - return i; - } - return -1; -} - -bool View::IsParentOf(View* v) const { - DCHECK(v); - View* parent = v->GetParent(); - while (parent) { - if (this == parent) - return true; - parent = parent->GetParent(); - } - return false; -} - #ifndef NDEBUG -void View::PrintViewHierarchy() { - PrintViewHierarchyImp(0); -} - -void View::PrintFocusHierarchy() { - PrintFocusHierarchyImp(0); -} #endif // Size and disposition -------------------------------------------------------- @@ -289,7 +281,7 @@ gfx::Rect View::GetVisibleBounds() { root_x += view->GetMirroredX(); root_y += view->y(); vis_bounds.Offset(view->GetMirroredX(), view->y()); - View* ancestor = view->GetParent(); + View* ancestor = view->parent(); if (ancestor != NULL) { ancestor_bounds.SetRect(0, 0, ancestor->width(), ancestor->height()); @@ -348,7 +340,7 @@ void View::SetVisible(bool flag) { is_visible_ = flag; - // This notifies all subviews recursively. + // This notifies all sub-views recursively. PropagateVisibilityNotifications(this, flag); // If we are newly visible, schedule paint. @@ -358,11 +350,7 @@ void View::SetVisible(bool flag) { } bool View::IsVisibleInRootView() const { - View* parent = GetParent(); - if (IsVisible() && parent) - return parent->IsVisibleInRootView(); - else - return false; + return IsVisible() && parent() ? parent()->IsVisibleInRootView() : false; } void View::SetEnabled(bool state) { @@ -389,8 +377,7 @@ gfx::Point View::GetMirroredPosition() const { } int View::GetMirroredX() const { - View* parent = GetParent(); - return parent ? parent->GetMirroredXForRect(bounds_) : x(); + return parent() ? parent()->GetMirroredXForRect(bounds_) : x(); } int View::GetMirroredXForRect(const gfx::Rect& bounds) const { @@ -423,7 +410,7 @@ void View::Layout() { // weren't changed by the layout manager. If there is no layout manager, we // just propagate the Layout() call down the hierarchy, so whoever receives // the call can take appropriate action. - for (int i = 0, count = GetChildViewCount(); i < count; ++i) { + for (int i = 0, count = child_count(); i < count; ++i) { View* child = GetChildViewAt(i); if (child->needs_layout_ || !layout_manager_.get()) { child->needs_layout_ = false; @@ -460,26 +447,29 @@ std::string View::GetClassName() const { } View* View::GetAncestorWithClassName(const std::string& name) { - for (View* view = this; view; view = view->GetParent()) { + for (View* view = this; view; view = view->parent()) { if (view->GetClassName() == name) return view; } return NULL; } -View* View::GetViewByID(int id) const { +const View* View::GetViewByID(int id) const { if (id == id_) return const_cast<View*>(this); - for (int i = 0, count = GetChildViewCount(); i < count; ++i) { - View* child = GetChildViewAt(i); - View* view = child->GetViewByID(id); + for (int i = 0, count = child_count(); i < count; ++i) { + const View* view = GetChildViewAt(i)->GetViewByID(id); if (view) return view; } return NULL; } +View* View::GetViewByID(int id) { + return const_cast<View*>(const_cast<const View*>(this)->GetViewByID(id)); +} + void View::SetID(int id) { id_ = id; } @@ -502,7 +492,7 @@ void View::GetViewsWithGroup(int group_id, std::vector<View*>* out) { if (group_ == group_id) out->push_back(this); - for (int i = 0, count = GetChildViewCount(); i < count; ++i) + for (int i = 0, count = child_count(); i < count; ++i) GetChildViewAt(i)->GetViewsWithGroup(group_id, out); } @@ -530,7 +520,7 @@ void View::ConvertPointToWidget(const View* src, gfx::Point* p) { DCHECK(p); gfx::Point offset; - for (const View* v = src; v; v = v->GetParent()) { + for (const View* v = src; v; v = v->parent()) { offset.set_x(offset.x() + v->GetMirroredX()); offset.set_y(offset.y() + v->y()); } @@ -550,7 +540,7 @@ void View::ConvertPointToScreen(const View* src, gfx::Point* p) { DCHECK(p); // If the view is not connected to a tree, there's nothing we can do. - Widget* widget = src->GetWidget(); + const Widget* widget = src->GetWidget(); if (widget) { ConvertPointToWidget(src, p); gfx::Rect r; @@ -603,9 +593,8 @@ void View::PaintNow() { if (!IsVisible()) return; - View* view = GetParent(); - if (view) - view->PaintNow(); + if (parent()) + parent()->PaintNow(); } void View::ProcessPaint(gfx::Canvas* canvas) { @@ -650,7 +639,7 @@ void View::ProcessPaint(gfx::Canvas* canvas) { } void View::PaintChildren(gfx::Canvas* canvas) { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) { + 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"; @@ -661,7 +650,7 @@ void View::PaintChildren(gfx::Canvas* canvas) { } ThemeProvider* View::GetThemeProvider() const { - Widget* widget = GetWidget(); + const Widget* widget = GetWidget(); return widget ? widget->GetThemeProvider() : NULL; } @@ -670,7 +659,7 @@ ThemeProvider* View::GetThemeProvider() const { View* View::GetViewForPoint(const gfx::Point& point) { // Walk the child Views recursively looking for the View that most // tightly encloses the specified point. - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { View* child = GetChildViewAt(i); if (!child->IsVisible()) continue; @@ -819,6 +808,10 @@ View* View::GetNextFocusableView() { return next_focusable_view_; } +const View* View::GetNextFocusableView() const { + return next_focusable_view_; +} + View* View::GetPreviousFocusableView() { return previous_focusable_view_; } @@ -955,14 +948,12 @@ void View::SetAccessibleName(const string16& name) { // Scrolling ------------------------------------------------------------------- void View::ScrollRectToVisible(const gfx::Rect& rect) { - View* parent = GetParent(); - // We must take RTL UI mirroring into account when adjusting the position of // the region. - if (parent) { + if (parent()) { gfx::Rect scroll_rect(rect); scroll_rect.Offset(GetMirroredX(), y()); - parent->ScrollRectToVisible(scroll_rect); + parent()->ScrollRectToVisible(scroll_rect); } } @@ -1034,7 +1025,7 @@ void View::NativeViewHierarchyChanged(bool attached, #ifndef NDEBUG bool View::IsProcessingPaint() const { - return GetParent() && GetParent()->IsProcessingPaint(); + return parent() && parent()->IsProcessingPaint(); } #endif @@ -1121,7 +1112,7 @@ void View::DragInfo::PossibleDrag(const gfx::Point& p) { // Tree operations ------------------------------------------------------------- -void View::DoRemoveChildView(View* a_view, +void View::DoRemoveChildView(View* view, bool update_focus_cycle, bool update_tool_tip, bool delete_removed_view) { @@ -1130,16 +1121,14 @@ void View::DoRemoveChildView(View* a_view, "during a paint, this will seriously " << "mess things up!"; #endif - DCHECK(a_view); - const ViewList::iterator i = find(child_views_.begin(), - child_views_.end(), - a_view); + DCHECK(view); + const ViewVector::iterator i = find(children_.begin(), children_.end(), view); scoped_ptr<View> view_to_be_deleted; - if (i != child_views_.end()) { + if (i != children_.end()) { if (update_focus_cycle) { // Let's remove the view from the focus traversal. - View* next_focusable = a_view->next_focusable_view_; - View* prev_focusable = a_view->previous_focusable_view_; + View* next_focusable = view->next_focusable_view_; + View* prev_focusable = view->previous_focusable_view_; if (prev_focusable) prev_focusable->next_focusable_view_ = next_focusable; if (next_focusable) @@ -1148,21 +1137,21 @@ void View::DoRemoveChildView(View* a_view, RootView* root = GetRootView(); if (root) - UnregisterChildrenForVisibleBoundsNotification(root, a_view); - a_view->PropagateRemoveNotifications(this); - a_view->SetParent(NULL); + UnregisterChildrenForVisibleBoundsNotification(root, view); + view->PropagateRemoveNotifications(this); + view->SetParent(NULL); - if (delete_removed_view && a_view->IsParentOwned()) - view_to_be_deleted.reset(a_view); + if (delete_removed_view && view->IsParentOwned()) + view_to_be_deleted.reset(view); - child_views_.erase(i); + children_.erase(i); } if (update_tool_tip) UpdateTooltip(); if (layout_manager_.get()) - layout_manager_->ViewRemoved(this, a_view); + layout_manager_->ViewRemoved(this, view); } void View::SetParent(View* parent) { @@ -1171,15 +1160,15 @@ void View::SetParent(View* parent) { } void View::PropagateRemoveNotifications(View* parent) { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) + for (int i = 0, count = child_count(); i < count; ++i) GetChildViewAt(i)->PropagateRemoveNotifications(parent); - for (View* v = this; v; v = v->GetParent()) + for (View* v = this; v; v = v->parent()) v->ViewHierarchyChangedImpl(true, false, parent, this); } void View::PropagateAddNotifications(View* parent, View* child) { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) + for (int i = 0, count = child_count(); i < count; ++i) GetChildViewAt(i)->PropagateAddNotifications(parent, child); ViewHierarchyChangedImpl(true, true, parent, child); } @@ -1187,7 +1176,7 @@ void View::PropagateAddNotifications(View* parent, View* child) { void View::PropagateNativeViewHierarchyChanged(bool attached, gfx::NativeView native_view, RootView* root_view) { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) + for (int i = 0, count = child_count(); i < count; ++i) GetChildViewAt(i)->PropagateNativeViewHierarchyChanged(attached, native_view, root_view); @@ -1219,57 +1208,10 @@ void View::ViewHierarchyChangedImpl(bool register_accelerators, parent->needs_layout_ = true; } -#ifndef NDEBUG -void View::PrintViewHierarchyImp(int indent) { - std::wostringstream buf; - int ind = indent; - while (ind-- > 0) - buf << L' '; - buf << UTF8ToWide(GetClassName()); - buf << L' '; - buf << GetID(); - buf << L' '; - buf << bounds_.x() << L"," << bounds_.y() << L","; - buf << bounds_.right() << L"," << bounds_.bottom(); - buf << L' '; - buf << this; - - VLOG(1) << buf.str(); - std::cout << buf.str() << std::endl; - - for (int i = 0, count = GetChildViewCount(); i < count; ++i) - GetChildViewAt(i)->PrintViewHierarchyImp(indent + 2); -} - -void View::PrintFocusHierarchyImp(int indent) { - std::wostringstream buf; - int ind = indent; - while (ind-- > 0) - buf << L' '; - buf << UTF8ToWide(GetClassName()); - buf << L' '; - buf << GetID(); - buf << L' '; - buf << GetClassName().c_str(); - buf << L' '; - buf << this; - - VLOG(1) << buf.str(); - std::cout << buf.str() << std::endl; - - if (GetChildViewCount() > 0) - GetChildViewAt(0)->PrintFocusHierarchyImp(indent + 2); - - View* v = GetNextFocusableView(); - if (v) - v->PrintFocusHierarchyImp(indent); -} -#endif - // Size and disposition -------------------------------------------------------- void View::PropagateVisibilityNotifications(View* start, bool is_visible) { - for (int i = 0, count = GetChildViewCount(); i < count; ++i) + for (int i = 0, count = child_count(); i < count; ++i) GetChildViewAt(i)->PropagateVisibilityNotifications(start, is_visible); VisibilityChangedImpl(start, is_visible); } @@ -1288,7 +1230,7 @@ void View::RegisterChildrenForVisibleBoundsNotification( DCHECK(root && view); if (view->GetNotifyWhenVisibleBoundsInRootChanges()) root->RegisterViewForVisibleBoundsNotification(view); - for (int i = 0; i < view->GetChildViewCount(); ++i) + for (int i = 0; i < view->child_count(); ++i) RegisterChildrenForVisibleBoundsNotification(root, view->GetChildViewAt(i)); } @@ -1298,7 +1240,7 @@ void View::UnregisterChildrenForVisibleBoundsNotification( DCHECK(root && view); if (view->GetNotifyWhenVisibleBoundsInRootChanges()) root->UnregisterViewForVisibleBoundsNotification(view); - for (int i = 0; i < view->GetChildViewCount(); ++i) + for (int i = 0; i < view->child_count(); ++i) UnregisterChildrenForVisibleBoundsNotification(root, view->GetChildViewAt(i)); } @@ -1306,15 +1248,15 @@ void View::UnregisterChildrenForVisibleBoundsNotification( void View::AddDescendantToNotify(View* view) { DCHECK(view); if (!descendants_to_notify_.get()) - descendants_to_notify_.reset(new ViewList()); + descendants_to_notify_.reset(new ViewVector); descendants_to_notify_->push_back(view); } void View::RemoveDescendantToNotify(View* view) { DCHECK(view && descendants_to_notify_.get()); - ViewList::iterator i = find(descendants_to_notify_->begin(), - descendants_to_notify_->end(), - view); + ViewVector::iterator i = find(descendants_to_notify_->begin(), + descendants_to_notify_->end(), + view); DCHECK(i != descendants_to_notify_->end()); descendants_to_notify_->erase(i); if (descendants_to_notify_->empty()) @@ -1335,7 +1277,7 @@ void View::ConvertPointToView(const View* src, const View* v; gfx::Point offset; - for (v = dst; v && v != src; v = v->GetParent()) + for (v = dst; v && v != src; v = v->parent()) offset.SetPoint(offset.x() + v->GetMirroredX(), offset.y() + v->y()); // The source was not found. The caller wants a conversion @@ -1353,7 +1295,7 @@ void View::ConvertPointToView(const View* src, // If src is NULL, sp is in the screen coordinate system if (src == NULL) { - Widget* widget = dst->GetWidget(); + const Widget* widget = dst->GetWidget(); if (widget) { gfx::Rect b; widget->GetBounds(&b, false); @@ -1494,7 +1436,7 @@ void View::UnregisterAccelerators(bool leave_data_intact) { // Focus ----------------------------------------------------------------------- void View::InitFocusSiblings(View* v, int index) { - int child_count = static_cast<int>(child_views_.size()); + int child_count = static_cast<int>(children_.size()); if (child_count == 0) { v->next_focusable_view_ = NULL; @@ -1505,8 +1447,8 @@ void View::InitFocusSiblings(View* v, int index) { // the last focusable element. Let's try to find an element with no next // focusable element to link to. View* last_focusable_view = NULL; - for (std::vector<View*>::iterator iter = child_views_.begin(); - iter != child_views_.end(); ++iter) { + for (std::vector<View*>::iterator iter = children_.begin(); + iter != children_.end(); ++iter) { if (!(*iter)->next_focusable_view_) { last_focusable_view = *iter; break; @@ -1515,7 +1457,7 @@ void View::InitFocusSiblings(View* v, int index) { if (last_focusable_view == NULL) { // Hum... there is a cycle in the focus list. Let's just insert ourself // after the last child. - View* prev = child_views_[index - 1]; + View* prev = children_[index - 1]; v->previous_focusable_view_ = prev; v->next_focusable_view_ = prev->next_focusable_view_; prev->next_focusable_view_->previous_focusable_view_ = v; @@ -1526,12 +1468,12 @@ void View::InitFocusSiblings(View* v, int index) { v->previous_focusable_view_ = last_focusable_view; } } else { - View* prev = child_views_[index]->GetPreviousFocusableView(); + View* prev = children_[index]->GetPreviousFocusableView(); v->previous_focusable_view_ = prev; - v->next_focusable_view_ = child_views_[index]; + v->next_focusable_view_ = children_[index]; if (prev) prev->next_focusable_view_ = v; - child_views_[index]->previous_focusable_view_ = v; + children_[index]->previous_focusable_view_ = v; } } } @@ -1539,13 +1481,13 @@ void View::InitFocusSiblings(View* v, int index) { // System events --------------------------------------------------------------- void View::PropagateThemeChanged() { - for (int i = GetChildViewCount() - 1; i >= 0; --i) + for (int i = child_count() - 1; i >= 0; --i) GetChildViewAt(i)->PropagateThemeChanged(); OnThemeChanged(); } void View::PropagateLocaleChanged() { - for (int i = GetChildViewCount() - 1; i >= 0; --i) + for (int i = child_count() - 1; i >= 0; --i) GetChildViewAt(i)->PropagateLocaleChanged(); OnLocaleChanged(); } diff --git a/views/view.h b/views/view.h index 4712ede..7205b4f32 100644 --- a/views/view.h +++ b/views/view.h @@ -1,4 +1,4 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -191,63 +191,58 @@ class View : public AcceleratorTarget { // Tree operations ----------------------------------------------------------- - // Add a child View. - void AddChildView(View* v); - - // Adds a child View at the specified position. - void AddChildView(int index, View* v); + // Get the Widget that hosts this View, if any. + virtual const Widget* GetWidget() const; + virtual Widget* GetWidget(); - // Get the child View at the specified index. - View* GetChildViewAt(int index) const; + // Add a child View, optionally at |index|. + void AddChildView(View* view); + void AddChildViewAt(View* view, int index); - // Remove a child view from this view. v's parent will change to NULL - void RemoveChildView(View *v); + // Remove a child view from this view. The view's parent will change to NULL. + void RemoveChildView(View* views); // Remove all child view from this view. If |delete_views| is true, the views // are deleted, unless marked as not parent owned. void RemoveAllChildViews(bool delete_views); + // Returns the View at the specified |index|. + const View* GetChildViewAt(int index) const; + View* GetChildViewAt(int index); + // Get the number of child Views. - int GetChildViewCount() const; + int child_count() const { return static_cast<int>(children_.size()); } + bool has_children() const { return !children_.empty(); } - // Tests if this view has a given view as direct child. - bool HasChildView(View* a_view); + // Get the parent View + const View* parent() const { return parent_; } + View* parent() { return parent_; } - // Get the Widget that hosts this View, if any. - virtual Widget* GetWidget() const; + // Returns true if |child| is contained within this View's hierarchy, even as + // an indirect descendant. Will return true if child is also this View. + bool Contains(const View* view) const; + // Returns the index of the specified |view| in this view's children, or -1 + // if the specified view is not a child of this view. + int GetIndexOf(const View* view) const; + + // TODO(beng): REMOVE (Views need not know about Window). // Gets the Widget that most closely contains this View, if any. // NOTE: almost all views displayed on screen have a Widget, but not // necessarily a Window. This is due to widgets being able to create top // level windows (as is done for popups, bubbles and menus). - virtual Window* GetWindow() const; + virtual const Window* GetWindow() const; + virtual Window* GetWindow(); + // TODO(beng): REMOVE (TBD) // Returns true if the native view |native_view| is contained in the view // hierarchy beneath this view. virtual bool ContainsNativeView(gfx::NativeView native_view) const; + // TODO(beng): REMOVE (RootView->internal API) // Get the containing RootView virtual RootView* GetRootView(); - // Get the parent View - View* GetParent() const { return parent_; } - - // Returns the index of the specified |view| in this view's children, or -1 - // if the specified view is not a child of this view. - int GetChildIndex(const View* v) const; - - // Returns true if the specified view is a direct or indirect child of this - // view. - bool IsParentOf(View* v) const; - -#ifndef NDEBUG - // Debug method that logs the view hierarchy to the output. - void PrintViewHierarchy(); - - // Debug method that logs the focus traversal hierarchy to the output. - void PrintFocusHierarchy(); -#endif - // Size and disposition ------------------------------------------------------ // Methods for obtaining and modifying the position and size of the view. // Position is in the coordinate system of the view's parent. @@ -417,7 +412,8 @@ class View : public AcceleratorTarget { // Recursively descends the view tree starting at this view, and returns // the first child that it encounters that has the given ID. // Returns NULL if no matching child view is found. - virtual View* GetViewByID(int id) const; + virtual const View* GetViewByID(int id) const; + virtual View* GetViewByID(int id); // Sets and gets the ID for this view. ID should be unique within the subtree // that you intend to search for it. 0 is the default ID for views. @@ -704,6 +700,7 @@ class View : public AcceleratorTarget { // Returns the view that should be selected next when pressing Tab. View* GetNextFocusableView(); + const View* GetNextFocusableView() const; // Returns the view that should be selected next when pressing Shift-Tab. View* GetPreviousFocusableView(); @@ -1194,10 +1191,6 @@ class View : public AcceleratorTarget { View* parent, View* child); - // Actual implementation of PrintFocusHierarchy. - void PrintViewHierarchyImp(int indent); - void PrintFocusHierarchyImp(int indent); - // Size and disposition ------------------------------------------------------ // Call VisibilityChanged() recursively for all children. @@ -1305,8 +1298,8 @@ class View : public AcceleratorTarget { View* parent_; // This view's children. - typedef std::vector<View*> ViewList; - ViewList child_views_; + typedef std::vector<View*> ViewVector; + ViewVector children_; // Size and disposition ------------------------------------------------------ @@ -1324,7 +1317,7 @@ class View : public AcceleratorTarget { bool registered_for_visible_bounds_notification_; // List of descendants wanting notification when their visible bounds change. - scoped_ptr<ViewList> descendants_to_notify_; + scoped_ptr<ViewVector> descendants_to_notify_; // Layout -------------------------------------------------------------------- diff --git a/views/views.gyp b/views/views.gyp index 01bea92..268abed 100644 --- a/views/views.gyp +++ b/views/views.gyp @@ -251,6 +251,8 @@ 'controls/throbber.h', 'controls/tree/tree_view.cc', 'controls/tree/tree_view.h', + 'debug_utils.cc', + 'debug_utils.h', 'drag_utils.cc', 'drag_utils.h', 'drag_utils_gtk.cc', diff --git a/views/widget/drop_helper.cc b/views/widget/drop_helper.cc index f15134b..29cca1c 100644 --- a/views/widget/drop_helper.cc +++ b/views/widget/drop_helper.cc @@ -96,7 +96,7 @@ View* DropHelper::CalculateTargetViewImpl( // drop. while (view && view != target_view_ && (!view->IsEnabled() || !view->CanDrop(data))) { - view = view->GetParent(); + view = view->parent(); } #else int formats = 0; @@ -111,7 +111,7 @@ View* DropHelper::CalculateTargetViewImpl( } formats = 0; custom_formats.clear(); - view = view->GetParent(); + view = view->parent(); } #endif return view; diff --git a/views/widget/root_view.cc b/views/widget/root_view.cc index e6c11b1..6010d99 100644 --- a/views/widget/root_view.cc +++ b/views/widget/root_view.cc @@ -104,7 +104,7 @@ RootView::RootView(Widget* widget) RootView::~RootView() { // If we have children remove them explicitly so to make sure a remove // notification is sent for each one of them. - if (!child_views_.empty()) + if (has_children()) RemoveAllChildViews(true); if (pending_paint_task_) @@ -117,7 +117,7 @@ void RootView::SetContentsView(View* contents_view) { // The ContentsView must be set up _after_ the window is created so that its // Widget pointer is valid. SetLayoutManager(new FillLayout); - if (GetChildViewCount() != 0) + if (has_children()) RemoveAllChildViews(true); AddChildView(contents_view); @@ -252,10 +252,14 @@ gfx::Rect RootView::GetScheduledPaintRectConstrainedToSize() { // ///////////////////////////////////////////////////////////////////////////// -Widget* RootView::GetWidget() const { +const Widget* RootView::GetWidget() const { return widget_; } +Widget* RootView::GetWidget() { + return const_cast<Widget*>(const_cast<const RootView*>(this)->GetWidget()); +} + void RootView::NotifyThemeChanged() { View::PropagateThemeChanged(); } @@ -332,7 +336,7 @@ View::TouchStatus RootView::OnTouchEvent(const TouchEvent& e) { // Walk up the tree until we find a view that wants the touch event. for (touch_pressed_handler_ = GetViewForPoint(e.location()); touch_pressed_handler_ && (touch_pressed_handler_ != this); - touch_pressed_handler_ = touch_pressed_handler_->GetParent()) { + touch_pressed_handler_ = touch_pressed_handler_->parent()) { if (!touch_pressed_handler_->IsEnabled()) { // Disabled views eat events but are treated as not handled by the // the GestureManager. @@ -407,7 +411,7 @@ bool RootView::OnMousePressed(const MouseEvent& e) { // Walk up the tree until we find a view that wants the mouse event. for (mouse_pressed_handler_ = GetViewForPoint(e.location()); mouse_pressed_handler_ && (mouse_pressed_handler_ != this); - mouse_pressed_handler_ = mouse_pressed_handler_->GetParent()) { + mouse_pressed_handler_ = mouse_pressed_handler_->parent()) { if (!mouse_pressed_handler_->IsEnabled()) { // Disabled views should eat events instead of propagating them upwards. hit_disabled_view = true; @@ -547,7 +551,7 @@ void RootView::OnMouseMoved(const MouseEvent& e) { // disabled while handling moves, it's wrong to suddenly send ET_MOUSE_EXITED // and ET_MOUSE_ENTERED events, because the mouse hasn't actually exited yet. while (v && !v->IsEnabled() && (v != mouse_move_handler_)) - v = v->GetParent(); + v = v->parent(); if (v && v != this) { if (v != mouse_move_handler_) { if (mouse_move_handler_ != NULL) { @@ -681,7 +685,7 @@ bool RootView::ProcessKeyEvent(const KeyEvent& event) { v->ShowContextMenu(v->GetKeyboardContextMenuLocation(), false); return true; } - for (; v && v != this && !consumed; v = v->GetParent()) { + for (; v && v != this && !consumed; v = v->parent()) { consumed = (event.GetType() == Event::ET_KEY_PRESSED) ? v->OnKeyPressed(event) : v->OnKeyReleased(event); } @@ -699,10 +703,8 @@ bool RootView::ProcessMouseWheelEvent(const MouseWheelEvent& e) { View* v; bool consumed = false; if (GetFocusedView()) { - for (v = GetFocusedView(); - v && v != this && !consumed; v = v->GetParent()) { + for (v = GetFocusedView(); v && v != this && !consumed; v = v->parent()) consumed = v->OnMouseWheel(e); - } } if (!consumed && default_keyboard_handler_) { @@ -736,10 +738,10 @@ void RootView::RegisterViewForVisibleBoundsNotification(View* view) { if (view->registered_for_visible_bounds_notification_) return; view->registered_for_visible_bounds_notification_ = true; - View* ancestor = view->GetParent(); + View* ancestor = view->parent(); while (ancestor) { ancestor->AddDescendantToNotify(view); - ancestor = ancestor->GetParent(); + ancestor = ancestor->parent(); } } @@ -748,10 +750,10 @@ void RootView::UnregisterViewForVisibleBoundsNotification(View* view) { if (!view->registered_for_visible_bounds_notification_) return; view->registered_for_visible_bounds_notification_ = false; - View* ancestor = view->GetParent(); + View* ancestor = view->parent(); while (ancestor) { ancestor->RemoveDescendantToNotify(view); - ancestor = ancestor->GetParent(); + ancestor = ancestor->parent(); } } diff --git a/views/widget/root_view.h b/views/widget/root_view.h index 0bbdea8..aabf339 100644 --- a/views/widget/root_view.h +++ b/views/widget/root_view.h @@ -80,7 +80,8 @@ class RootView : public View, // Tree functions // Get the Widget that hosts this View. - virtual Widget* GetWidget() const; + virtual const Widget* GetWidget() const; + virtual Widget* GetWidget(); // Public API for broadcasting theme change notifications to this View // hierarchy. diff --git a/views/window/client_view.cc b/views/window/client_view.cc index 312424c..de198ed 100644 --- a/views/window/client_view.cc +++ b/views/window/client_view.cc @@ -52,7 +52,7 @@ void ClientView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { DCHECK(contents_view_); // |contents_view_| must be valid now! // Insert |contents_view_| at index 0 so it is first in the focus chain. // (the OK/Cancel buttons are inserted before contents_view_) - AddChildView(0, contents_view_); + AddChildViewAt(contents_view_, 0); } } diff --git a/views/window/non_client_view.cc b/views/window/non_client_view.cc index f759d31..c31dda6 100644 --- a/views/window/non_client_view.cc +++ b/views/window/non_client_view.cc @@ -44,8 +44,8 @@ void NonClientView::SetFrameView(NonClientFrameView* frame_view) { if (frame_view_.get()) RemoveChildView(frame_view_.get()); frame_view_.reset(frame_view); - if (GetParent()) - AddChildView(kFrameViewIndex, frame_view_.get()); + if (parent()) + AddChildViewAt(frame_view_.get(), kFrameViewIndex); } bool NonClientView::CanClose() { @@ -153,8 +153,8 @@ void NonClientView::ViewHierarchyChanged(bool is_add, View* parent, // are subsequently resized all the parent-child relationships are // established. if (is_add && GetWidget() && child == this) { - AddChildView(kFrameViewIndex, frame_view_.get()); - AddChildView(kClientViewIndex, client_view_); + AddChildViewAt(frame_view_.get(), kFrameViewIndex); + AddChildViewAt(client_view_, kClientViewIndex); } } |