diff options
87 files changed, 552 insertions, 554 deletions
diff --git a/chrome/browser/chromeos/frame/browser_view.cc b/chrome/browser/chromeos/frame/browser_view.cc index b0c7f53..c9e3b88 100644 --- a/chrome/browser/chromeos/frame/browser_view.cc +++ b/chrome/browser/chromeos/frame/browser_view.cc @@ -89,7 +89,7 @@ class BrowserViewLayout : public ::BrowserViewLayout { gfx::Rect tabstrip_bounds( browser_view_->frame()->GetBoundsForTabStrip(tabstrip_)); gfx::Point tabstrip_origin = tabstrip_bounds.origin(); - views::View::ConvertPointToView(browser_view_->GetParent(), browser_view_, + views::View::ConvertPointToView(browser_view_->parent(), browser_view_, &tabstrip_origin); tabstrip_bounds.set_origin(tabstrip_origin); return browser_view_->UseVerticalTabs() ? @@ -115,7 +115,7 @@ class BrowserViewLayout : public ::BrowserViewLayout { virtual int NonClientHitTest(const gfx::Point& point) { gfx::Point point_in_browser_view_coords(point); views::View::ConvertPointToView( - browser_view_->GetParent(), browser_view_, + browser_view_->parent(), browser_view_, &point_in_browser_view_coords); return IsPointInViewsInTitleArea(point_in_browser_view_coords) ? HTCLIENT : ::BrowserViewLayout::NonClientHitTest(point); @@ -313,7 +313,7 @@ void BrowserView::ShowContextMenu(views::View* source, // - HTCAPTION: in title bar or unobscured part of tabstrip // - HTNOWHERE: as the name implies. gfx::Point point_in_parent_coords(p); - views::View::ConvertPointToView(NULL, GetParent(), &point_in_parent_coords); + views::View::ConvertPointToView(NULL, parent(), &point_in_parent_coords); int hit_test = NonClientHitTest(point_in_parent_coords); if (hit_test == HTCAPTION || hit_test == HTNOWHERE) system_menu_menu_->RunMenuAt(p, views::Menu2::ALIGN_TOPLEFT); diff --git a/chrome/browser/chromeos/input_method/candidate_window.cc b/chrome/browser/chromeos/input_method/candidate_window.cc index 4c2387f..fa3e003 100644 --- a/chrome/browser/chromeos/input_method/candidate_window.cc +++ b/chrome/browser/chromeos/input_method/candidate_window.cc @@ -866,7 +866,7 @@ void CandidateWindowView::ShowAuxiliaryText() { header_area_contents_.get() : footer_area_contents_.get()); - if (!target_area->HasChildView(target_contents)) { + if (target_contents->parent() != target_area) { // If contents not in display area, put it in. target_area->RemoveAllChildViews(false); // Don't delete child views. target_area->AddChildView(target_contents); diff --git a/chrome/browser/chromeos/login/background_view.cc b/chrome/browser/chromeos/login/background_view.cc index 6d88b19..3490e9b 100644 --- a/chrome/browser/chromeos/login/background_view.cc +++ b/chrome/browser/chromeos/login/background_view.cc @@ -196,7 +196,7 @@ void BackgroundView::CreateModalPopup(views::WindowDelegate* view) { gfx::NativeWindow BackgroundView::GetNativeWindow() const { return - GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); + GTK_WINDOW(static_cast<const WidgetGtk*>(GetWidget())->GetNativeView()); } void BackgroundView::SetStatusAreaVisible(bool visible) { diff --git a/chrome/browser/chromeos/login/eula_view.cc b/chrome/browser/chromeos/login/eula_view.cc index 31b2ffb..79ae7ff 100644 --- a/chrome/browser/chromeos/login/eula_view.cc +++ b/chrome/browser/chromeos/login/eula_view.cc @@ -75,7 +75,7 @@ enum kLayoutColumnsets { struct FillLayoutWithBorder : public views::LayoutManager { // Overridden from LayoutManager: virtual void Layout(views::View* host) { - DCHECK(host->GetChildViewCount()); + DCHECK(host->has_children()); host->GetChildViewAt(0)->SetBoundsRect(host->GetContentsBounds()); } virtual gfx::Size GetPreferredSize(views::View* host) { diff --git a/chrome/browser/chromeos/login/message_bubble.cc b/chrome/browser/chromeos/login/message_bubble.cc index 2f6f937..96a8a1c 100644 --- a/chrome/browser/chromeos/login/message_bubble.cc +++ b/chrome/browser/chromeos/login/message_bubble.cc @@ -115,7 +115,7 @@ MessageBubble* MessageBubble::Show(views::Widget* parent, MessageBubble* bubble = new MessageBubble( views::WidgetGtk::TYPE_WINDOW, parent, image, text, help, true, delegate); bubble->Init(parent, position_relative_to, arrow_location, - bubble->text_->GetParent(), delegate); + bubble->text_->parent(), delegate); return bubble; } @@ -132,7 +132,7 @@ MessageBubble* MessageBubble::ShowNoGrab( MessageBubble* bubble = new MessageBubble( views::WidgetGtk::TYPE_CHILD, parent, image, text, help, false, delegate); bubble->Init(parent, position_relative_to, arrow_location, - bubble->text_->GetParent(), delegate); + bubble->text_->parent(), delegate); return bubble; } diff --git a/chrome/browser/chromeos/login/network_selection_view.cc b/chrome/browser/chromeos/login/network_selection_view.cc index d2fce59..b1218e6 100644 --- a/chrome/browser/chromeos/login/network_selection_view.cc +++ b/chrome/browser/chromeos/login/network_selection_view.cc @@ -378,7 +378,8 @@ void NetworkSelectionView::OnLocaleChanged() { // NetworkSelectionView, public: gfx::NativeWindow NetworkSelectionView::GetNativeWindow() const { - return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); + return + GTK_WINDOW(static_cast<const WidgetGtk*>(GetWidget())->GetNativeView()); } views::View* NetworkSelectionView::GetNetworkControlView() const { diff --git a/chrome/browser/chromeos/login/new_user_view.cc b/chrome/browser/chromeos/login/new_user_view.cc index db3ba3b..3a62013 100644 --- a/chrome/browser/chromeos/login/new_user_view.cc +++ b/chrome/browser/chromeos/login/new_user_view.cc @@ -265,14 +265,14 @@ void NewUserView::AddChildView(View* view) { // so we restore their original position in layout. if (view == languages_menubutton_) { if (languages_menubutton_order_ < 0) { - languages_menubutton_order_ = GetChildViewCount(); + languages_menubutton_order_ = child_count(); } - views::View::AddChildView(languages_menubutton_order_, view); + views::View::AddChildViewAt(view, languages_menubutton_order_); } else if (view == sign_in_button_) { if (sign_in_button_order_ < 0) { - sign_in_button_order_ = GetChildViewCount(); + sign_in_button_order_ = child_count(); } - views::View::AddChildView(sign_in_button_order_, view); + views::View::AddChildViewAt(view, sign_in_button_order_); } else { views::View::AddChildView(view); } diff --git a/chrome/browser/chromeos/login/screen_locker.cc b/chrome/browser/chromeos/login/screen_locker.cc index 3223ac6..80d903b 100644 --- a/chrome/browser/chromeos/login/screen_locker.cc +++ b/chrome/browser/chromeos/login/screen_locker.cc @@ -275,7 +275,7 @@ class GrabWidgetRootView } screen_lock_view_ = screen_lock_view; if (screen_lock_view_) { - AddChildView(0, screen_lock_view_); + AddChildViewAt(screen_lock_view_, 0); } Layout(); } diff --git a/chrome/browser/chromeos/login/shutdown_button.cc b/chrome/browser/chromeos/login/shutdown_button.cc index 1723ef6..138467c 100644 --- a/chrome/browser/chromeos/login/shutdown_button.cc +++ b/chrome/browser/chromeos/login/shutdown_button.cc @@ -109,9 +109,9 @@ void ShutdownButton::LayoutIn(views::View* parent) { void ShutdownButton::OnLocaleChanged() { SetText(UTF8ToWide(l10n_util::GetStringUTF8(IDS_SHUTDOWN_BUTTON))); - if (GetParent()) { - GetParent()->Layout(); - GetParent()->SchedulePaint(); + if (parent()) { + parent()->Layout(); + parent()->SchedulePaint(); } } diff --git a/chrome/browser/chromeos/login/user_view.cc b/chrome/browser/chromeos/login/user_view.cc index a1d6162..3b07efd 100644 --- a/chrome/browser/chromeos/login/user_view.cc +++ b/chrome/browser/chromeos/login/user_view.cc @@ -201,8 +201,8 @@ class RemoveButton : public views::TextButton { origin.Offset(-size.width(), 0); SetBoundsRect(gfx::Rect(origin, size)); - if (GetParent()) - GetParent()->SchedulePaint(); + if (parent()) + parent()->SchedulePaint(); } SkBitmap icon_; diff --git a/chrome/browser/chromeos/login/wizard_controller.cc b/chrome/browser/chromeos/login/wizard_controller.cc index 8021d38..fcc8e36 100644 --- a/chrome/browser/chromeos/login/wizard_controller.cc +++ b/chrome/browser/chromeos/login/wizard_controller.cc @@ -159,7 +159,7 @@ class ContentView : public views::View { } virtual void Layout() { - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { views::View* cur = GetChildViewAt(i); if (cur->IsVisible()) cur->SetBounds(0, 0, width(), height()); diff --git a/chrome/browser/chromeos/notifications/notification_panel.cc b/chrome/browser/chromeos/notifications/notification_panel.cc index ddad9b41..508e43e 100644 --- a/chrome/browser/chromeos/notifications/notification_panel.cc +++ b/chrome/browser/chromeos/notifications/notification_panel.cc @@ -170,7 +170,7 @@ class BalloonSubContainer : public views::View { virtual void Layout() { // Layout bottom up int height = 0; - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { views::View* child = GetChildViewAt(i); child->SetBounds(0, height, child->width(), child->height()); height += child->height() + margin_; @@ -182,7 +182,7 @@ class BalloonSubContainer : public views::View { void UpdateBounds() { int height = 0; int max_width = 0; - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { views::View* child = GetChildViewAt(i); height += child->height() + margin_; max_width = std::max(max_width, child->width()); @@ -197,7 +197,7 @@ class BalloonSubContainer : public views::View { // Returns the bounds that covers new notifications. gfx::Rect GetNewBounds() { gfx::Rect rect; - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { BalloonViewImpl* view = static_cast<BalloonViewImpl*>(GetChildViewAt(i)); if (!view->stale()) { @@ -214,7 +214,7 @@ class BalloonSubContainer : public views::View { // Returns # of new notifications. int GetNewCount() { int count = 0; - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { BalloonViewImpl* view = static_cast<BalloonViewImpl*>(GetChildViewAt(i)); if (!view->stale()) @@ -225,7 +225,7 @@ class BalloonSubContainer : public views::View { // Make all notifications stale. void MakeAllStale() { - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { BalloonViewImpl* view = static_cast<BalloonViewImpl*>(GetChildViewAt(i)); view->set_stale(); @@ -233,7 +233,7 @@ class BalloonSubContainer : public views::View { } void DismissAll() { - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { BalloonViewImpl* view = static_cast<BalloonViewImpl*>(GetChildViewAt(i)); view->Close(true); @@ -241,7 +241,7 @@ class BalloonSubContainer : public views::View { } BalloonViewImpl* FindBalloonView(const Notification& notification) { - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { BalloonViewImpl* view = static_cast<BalloonViewImpl*>(GetChildViewAt(i)); if (view->IsFor(notification)) { @@ -254,7 +254,7 @@ class BalloonSubContainer : public views::View { BalloonViewImpl* FindBalloonView(const gfx::Point point) { gfx::Point copy(point); ConvertPointFromWidget(this, ©); - for (int i = GetChildViewCount() - 1; i >= 0; --i) { + for (int i = child_count() - 1; i >= 0; --i) { views::View* view = GetChildViewAt(i); if (view->bounds().Contains(copy)) return static_cast<BalloonViewImpl*>(view); @@ -287,8 +287,8 @@ class BalloonContainer : public views::View { // views::View overrides. virtual void Layout() { int margin = - (sticky_container_->GetChildViewCount() != 0 && - non_sticky_container_->GetChildViewCount() != 0) ? + (sticky_container_->child_count() != 0 && + non_sticky_container_->child_count() != 0) ? margin_ : 0; sticky_container_->SetBounds( 0, 0, width(), sticky_container_->height()); @@ -322,9 +322,9 @@ class BalloonContainer : public views::View { bool Update(Balloon* balloon) { BalloonViewImpl* view = GetBalloonViewOf(balloon); View* container = NULL; - if (sticky_container_->HasChildView(view)) { + if (view->parent() == sticky_container_) { container = sticky_container_; - } else if (non_sticky_container_->HasChildView(view)) { + } else if (view->parent() == non_sticky_container_) { container = non_sticky_container_; } if (container) { @@ -345,8 +345,8 @@ class BalloonContainer : public views::View { // Returns the number of notifications added to the panel. int GetNotificationCount() { - return sticky_container_->GetChildViewCount() + - non_sticky_container_->GetChildViewCount(); + return sticky_container_->child_count() + + non_sticky_container_->child_count(); } // Returns the # of new notifications. @@ -357,19 +357,19 @@ class BalloonContainer : public views::View { // Returns the # of sticky and new notifications. int GetStickyNewNotificationCount() { - return sticky_container_->GetChildViewCount() + + return sticky_container_->child_count() + non_sticky_container_->GetNewCount(); } // Returns the # of sticky notifications. int GetStickyNotificationCount() { - return sticky_container_->GetChildViewCount(); + return sticky_container_->child_count(); } // Returns true if the |view| is contained in the panel. bool HasBalloonView(View* view) { - return sticky_container_->HasChildView(view) || - non_sticky_container_->HasChildView(view); + return view->parent() == sticky_container_ || + view->parent() == non_sticky_container_; } // Updates the bounds so that all notifications are visible. diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc index 7bbbfe6..59c1d84 100644 --- a/chrome/browser/chromeos/options/network_config_view.cc +++ b/chrome/browser/chromeos/options/network_config_view.cc @@ -38,7 +38,8 @@ NetworkConfigView::NetworkConfigView() } gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { - return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); + return + GTK_WINDOW(static_cast<const WidgetGtk*>(GetWidget())->GetNativeView()); } std::wstring NetworkConfigView::GetDialogButtonLabel( diff --git a/chrome/browser/chromeos/panels/panel_scroller_container.cc b/chrome/browser/chromeos/panels/panel_scroller_container.cc index 653bf7b..e3b3caf 100644 --- a/chrome/browser/chromeos/panels/panel_scroller_container.cc +++ b/chrome/browser/chromeos/panels/panel_scroller_container.cc @@ -11,7 +11,7 @@ PanelScrollerContainer::PanelScrollerContainer(PanelScroller* scroller, : views::View(), scroller_(scroller), contents_(contents) { - AddChildView(0, contents_); + AddChildViewAt(contents_, 0); // TODO(brettw) figure out memory management. } diff --git a/chrome/browser/chromeos/status/status_area_view.cc b/chrome/browser/chromeos/status/status_area_view.cc index fbb2433..81dd39e 100644 --- a/chrome/browser/chromeos/status/status_area_view.cc +++ b/chrome/browser/chromeos/status/status_area_view.cc @@ -53,7 +53,7 @@ void StatusAreaView::Init() { gfx::Size StatusAreaView::GetPreferredSize() { int result_w = kSeparation; int result_h = 0; - for (int i = 0; i < GetChildViewCount(); i++) { + for (int i = 0; i < child_count(); i++) { views::View* cur = GetChildViewAt(i); if (cur->IsVisible()) { gfx::Size cur_size = cur->GetPreferredSize(); @@ -68,7 +68,7 @@ gfx::Size StatusAreaView::GetPreferredSize() { void StatusAreaView::Layout() { int cur_x = kSeparation; - for (int i = 0; i < GetChildViewCount(); i++) { + for (int i = 0; i < child_count(); i++) { views::View* cur = GetChildViewAt(i); if (cur->IsVisible()) { gfx::Size cur_size = cur->GetPreferredSize(); diff --git a/chrome/browser/chromeos/views/webui_menu_widget.cc b/chrome/browser/chromeos/views/webui_menu_widget.cc index 6f60db2..314877b 100644 --- a/chrome/browser/chromeos/views/webui_menu_widget.cc +++ b/chrome/browser/chromeos/views/webui_menu_widget.cc @@ -82,7 +82,7 @@ class InsetsLayout : public views::LayoutManager { private: // views::LayoutManager implementatios. virtual void Layout(views::View* host) { - if (host->GetChildViewCount() == 0) + if (!host->has_children()) return; gfx::Insets insets = host->GetInsets(); views::View* view = host->GetChildViewAt(0); @@ -93,7 +93,7 @@ class InsetsLayout : public views::LayoutManager { } virtual gfx::Size GetPreferredSize(views::View* host) { - DCHECK(host->GetChildViewCount() == 1); + DCHECK(host->child_count() == 1); gfx::Insets insets = host->GetInsets(); gfx::Size size = host->GetChildViewAt(0)->GetPreferredSize(); return gfx::Size(size.width() + insets.width(), @@ -157,7 +157,7 @@ void WebUIMenuWidget::Hide() { void WebUIMenuWidget::Close() { if (dom_view_ != NULL) { - dom_view_->GetParent()->RemoveChildView(dom_view_); + dom_view_->parent()->RemoveChildView(dom_view_); delete dom_view_; dom_view_ = NULL; } @@ -274,7 +274,7 @@ void WebUIMenuWidget::ShowAt(chromeos::MenuLocator* locator) { dom_view_->LoadURL(webui_menu_->menu_url()); } else { webui_menu_->UpdateStates(); - dom_view_->GetParent()->set_border(new RoundedBorder(locator)); + dom_view_->parent()->set_border(new RoundedBorder(locator)); menu_locator_->Move(this); } Show(); diff --git a/chrome/browser/ui/views/about_chrome_view.cc b/chrome/browser/ui/views/about_chrome_view.cc index 7a04958..7e79d3d 100644 --- a/chrome/browser/ui/views/about_chrome_view.cc +++ b/chrome/browser/ui/views/about_chrome_view.cc @@ -391,7 +391,7 @@ void AboutChromeView::Layout() { // Get the y-coordinate of our parent so we can position the text left of the // buttons at the bottom. - gfx::Rect parent_bounds = GetParent()->GetContentsBounds(); + gfx::Rect parent_bounds = parent()->GetContentsBounds(); sz = throbber_->GetPreferredSize(); int throbber_topleft_x = kPanelHorizMargin; @@ -825,8 +825,7 @@ void AboutChromeView::UpdateStatus(GoogleUpdateUpgradeResult result, throbber_->Stop(); // We have updated controls on the parent, so we need to update its layout. - View* parent = GetParent(); - parent->Layout(); + parent()->Layout(); // Check button may have appeared/disappeared. We cannot call this during // ViewHierarchyChanged because the |window()| pointer hasn't been set yet. diff --git a/chrome/browser/ui/views/accessibility_event_router_views.cc b/chrome/browser/ui/views/accessibility_event_router_views.cc index 854407b..b296cac 100644 --- a/chrome/browser/ui/views/accessibility_event_router_views.cc +++ b/chrome/browser/ui/views/accessibility_event_router_views.cc @@ -162,10 +162,10 @@ void AccessibilityEventRouterViews::SendMenuItemNotification( if (view->GetClassName() == views::MenuItemView::kViewClassName) has_submenu = static_cast<views::MenuItemView*>(view)->HasSubmenu(); - views::View* parent_menu = view->GetParent(); + views::View* parent_menu = view->parent(); while (parent_menu != NULL && parent_menu->GetClassName() != views::SubmenuView::kViewClassName) { - parent_menu = parent_menu->GetParent(); + parent_menu = parent_menu->parent(); } if (parent_menu) { count = 0; @@ -178,7 +178,7 @@ void AccessibilityEventRouterViews::SendMenuItemNotification( void AccessibilityEventRouterViews::RecursiveGetMenuItemIndexAndCount( views::View* menu, views::View* item, int* index, int* count) { - for (int i = 0; i < menu->GetChildViewCount(); ++i) { + for (int i = 0; i < menu->child_count(); ++i) { views::View* child = menu->GetChildViewAt(i); int previous_count = *count; RecursiveGetMenuItemIndexAndCount(child, item, index, count); @@ -207,7 +207,7 @@ bool AccessibilityEventRouterViews::IsMenuEvent( role == AccessibilityTypes::ROLE_MENUPOPUP) { return true; } - view = view->GetParent(); + view = view->parent(); } return false; diff --git a/chrome/browser/ui/views/accessible_pane_view.cc b/chrome/browser/ui/views/accessible_pane_view.cc index 9ed7c99..c6789bc 100644 --- a/chrome/browser/ui/views/accessible_pane_view.cc +++ b/chrome/browser/ui/views/accessible_pane_view.cc @@ -48,7 +48,7 @@ bool AccessiblePaneView::SetPaneFocus(int view_storage_id, // Use the provided initial focus if it's visible and enabled, otherwise // use the first focusable child. if (!initial_focus || - !IsParentOf(initial_focus) || + !Contains(initial_focus) || !initial_focus->IsVisible() || !initial_focus->IsEnabled()) { initial_focus = GetFirstFocusableChild(); @@ -216,7 +216,7 @@ void AccessiblePaneView::FocusWillChange(views::View* focused_before, &AccessiblePaneView::LocationBarSelectAll)); } - if (!IsParentOf(focused_now) || + if (!Contains(focused_now) || reason == views::FocusManager::kReasonDirectFocusChange) { // We should remove pane focus (i.e. make most of the controls // not focusable again) either because the focus is leaving the pane, diff --git a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc index 18a1566..19f2804 100644 --- a/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc +++ b/chrome/browser/ui/views/autocomplete/autocomplete_popup_contents_view.cc @@ -837,7 +837,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { // Update the match cached by each row, in the process of doing so make sure // we have enough row views. int total_child_height = 0; - size_t child_rv_count = GetChildViewCount(); + size_t child_rv_count = child_count(); if (opt_in_view_) { DCHECK(child_rv_count > 0); child_rv_count--; @@ -847,7 +847,7 @@ void AutocompletePopupContentsView::UpdatePopupAppearance() { if (i >= child_rv_count) { result_view = new AutocompleteResultView(this, i, result_font_, result_bold_font_); - AddChildView(static_cast<int>(i), result_view); + AddChildViewAt(result_view, static_cast<int>(i)); } else { result_view = static_cast<AutocompleteResultView*>(GetChildViewAt(i)); result_view->SetVisible(true); @@ -991,9 +991,8 @@ void AutocompletePopupContentsView::Layout() { // Size our children to the available content area. gfx::Rect contents_rect = GetContentsBounds(); - int child_count = GetChildViewCount(); int top = contents_rect.y(); - for (int i = 0; i < child_count; ++i) { + for (int i = 0; i < child_count(); ++i) { View* v = GetChildViewAt(i); if (v->IsVisible()) { v->SetBounds(contents_rect.x(), top, contents_rect.width(), @@ -1071,7 +1070,7 @@ views::View* AutocompletePopupContentsView::GetViewForPoint( views::View* child = views::View::GetViewForPoint(point); views::View* ancestor = child; while (ancestor && ancestor != opt_in_view_) - ancestor = ancestor->GetParent(); + ancestor = ancestor->parent(); return ancestor ? child : this; } @@ -1162,7 +1161,7 @@ size_t AutocompletePopupContentsView::GetIndexForPoint( return AutocompletePopupModel::kNoMatch; int nb_match = model_->result().size(); - DCHECK(nb_match <= GetChildViewCount()); + DCHECK(nb_match <= child_count()); for (int i = 0; i < nb_match; ++i) { views::View* child = GetChildViewAt(i); gfx::Point point_in_child_coords(point); diff --git a/chrome/browser/ui/views/bookmark_bar_instructions_view.cc b/chrome/browser/ui/views/bookmark_bar_instructions_view.cc index 4f5b27f..b4c3351 100644 --- a/chrome/browser/ui/views/bookmark_bar_instructions_view.cc +++ b/chrome/browser/ui/views/bookmark_bar_instructions_view.cc @@ -38,7 +38,7 @@ BookmarkBarInstructionsView::BookmarkBarInstructionsView(Delegate* delegate) gfx::Size BookmarkBarInstructionsView::GetPreferredSize() { int ascent = 0, descent = 0, height = 0, width = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { View* view = GetChildViewAt(i); gfx::Size pref = view->GetPreferredSize(); int baseline = view->GetBaseline(); @@ -50,7 +50,7 @@ gfx::Size BookmarkBarInstructionsView::GetPreferredSize() { } width += pref.width(); } - width += (GetChildViewCount() - 1) * kViewPadding; + width += (child_count() - 1) * kViewPadding; if (ascent != 0) height = std::max(ascent + descent, height); return gfx::Size(width, height); @@ -59,7 +59,7 @@ gfx::Size BookmarkBarInstructionsView::GetPreferredSize() { void BookmarkBarInstructionsView::Layout() { int remaining_width = width(); int x = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { View* view = GetChildViewAt(i); gfx::Size pref = view->GetPreferredSize(); int baseline = view->GetBaseline(); diff --git a/chrome/browser/ui/views/bookmark_bar_view.cc b/chrome/browser/ui/views/bookmark_bar_view.cc index 59c5eee..d0d9510 100644 --- a/chrome/browser/ui/views/bookmark_bar_view.cc +++ b/chrome/browser/ui/views/bookmark_bar_view.cc @@ -927,7 +927,7 @@ void BookmarkBarView::Loaded(BookmarkModel* model) { DCHECK(node && model_->other_node()); // Create a button for each of the children on the bookmark bar. for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) - AddChildView(i, CreateBookmarkButton(node->GetChild(i))); + AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); UpdateColors(); UpdateOtherBookmarksVisibility(); other_bookmarked_button_->SetEnabled(true); @@ -978,7 +978,7 @@ void BookmarkBarView::BookmarkNodeAddedImpl(BookmarkModel* model, if (!throbbing_view_ && sync_service_ && sync_service_->SetupInProgress()) { StartThrobbing(node, true); } - AddChildView(index, CreateBookmarkButton(node)); + AddChildViewAt(CreateBookmarkButton(node), index); UpdateColors(); Layout(); SchedulePaint(); @@ -1054,7 +1054,7 @@ void BookmarkBarView::BookmarkNodeChildrenReordered(BookmarkModel* model, // Create the new buttons. for (int i = 0, child_count = node->GetChildCount(); i < child_count; ++i) - AddChildView(i, CreateBookmarkButton(node->GetChild(i))); + AddChildViewAt(CreateBookmarkButton(node->GetChild(i)), i); UpdateColors(); Layout(); @@ -1147,7 +1147,7 @@ void BookmarkBarView::RunMenu(views::View* view, const gfx::Point& pt) { node = model_->GetBookmarkBarNode(); start_index = GetFirstHiddenNodeIndex(); } else { - int button_index = GetChildIndex(view); + int button_index = GetIndexOf(view); DCHECK_NE(-1, button_index); node = model_->GetBookmarkBarNode()->GetChild(button_index); } @@ -1172,7 +1172,7 @@ void BookmarkBarView::ButtonPressed(views::Button* sender, if (sender->tag() == kOtherFolderButtonTag) { node = model_->other_node(); } else { - int index = GetChildIndex(sender); + int index = GetIndexOf(sender); DCHECK_NE(-1, index); node = model_->GetBookmarkBarNode()->GetChild(index); } @@ -1210,7 +1210,7 @@ void BookmarkBarView::ShowContextMenu(View* source, } else if (source != this) { // User clicked on one of the bookmark buttons, find which one they // clicked on. - int bookmark_button_index = GetChildIndex(source); + int bookmark_button_index = GetIndexOf(source); DCHECK(bookmark_button_index != -1 && bookmark_button_index < GetBookmarkButtonCount()); const BookmarkNode* node = @@ -1522,7 +1522,7 @@ int BookmarkBarView::GetBookmarkButtonCount() { // We contain five non-bookmark button views: other bookmarks, bookmarks // separator, chevrons (for overflow), the instruction label and the sync // error button. - return GetChildViewCount() - 5; + return child_count() - 5; } void BookmarkBarView::StopThrobbing(bool immediate) { @@ -1593,7 +1593,7 @@ void BookmarkBarView::UpdateOtherBookmarksVisibility() { gfx::Size BookmarkBarView::LayoutItems(bool compute_bounds_only) { gfx::Size prefsize; - if (!GetParent() && !compute_bounds_only) + if (!parent() && !compute_bounds_only) return prefsize; int x = kLeftMargin; diff --git a/chrome/browser/ui/views/bookmark_bar_view_test.cc b/chrome/browser/ui/views/bookmark_bar_view_test.cc index e51a009..2dd5f79 100644 --- a/chrome/browser/ui/views/bookmark_bar_view_test.cc +++ b/chrome/browser/ui/views/bookmark_bar_view_test.cc @@ -820,9 +820,9 @@ class BookmarkBarViewTest9 : public BookmarkBarViewEventTestBase { start_y_ = menu_loc.y(); // Move the mouse over the scroll button. - views::View* scroll_container = menu->GetSubmenu()->GetParent(); + views::View* scroll_container = menu->GetSubmenu()->parent(); ASSERT_TRUE(scroll_container != NULL); - scroll_container = scroll_container->GetParent(); + scroll_container = scroll_container->parent(); ASSERT_TRUE(scroll_container != NULL); views::View* scroll_down_button = scroll_container->GetChildViewAt(1); ASSERT_TRUE(scroll_down_button); @@ -1172,7 +1172,7 @@ class BookmarkBarViewTest13 : public BookmarkBarViewEventTestBase { // Find the first separator. views::SubmenuView* submenu = menu->GetSubmenu(); views::View* separator_view = NULL; - for (int i = 0; i < submenu->GetChildViewCount(); ++i) { + for (int i = 0; i < submenu->child_count(); ++i) { if (submenu->GetChildViewAt(i)->GetID() != views::MenuItemView::kMenuItemViewID) { separator_view = submenu->GetChildViewAt(i); diff --git a/chrome/browser/ui/views/bookmark_editor_view.cc b/chrome/browser/ui/views/bookmark_editor_view.cc index ba4c5a9..05aae5b 100644 --- a/chrome/browser/ui/views/bookmark_editor_view.cc +++ b/chrome/browser/ui/views/bookmark_editor_view.cc @@ -139,7 +139,7 @@ void BookmarkEditorView::Layout() { // Manually lay out the New Folder button in the same row as the OK/Cancel // buttons... - gfx::Rect parent_bounds = GetParent()->GetContentsBounds(); + gfx::Rect parent_bounds = parent()->GetContentsBounds(); gfx::Size prefsize = new_group_button_->GetPreferredSize(); int button_y = parent_bounds.bottom() - prefsize.height() - views::kButtonVEdgeMargin; @@ -403,7 +403,7 @@ void BookmarkEditorView::BookmarkNodeChildrenReordered( void BookmarkEditorView::Reset() { if (!show_tree_) { - if (GetParent()) + if (parent()) UserInputChanged(); return; } @@ -422,7 +422,7 @@ void BookmarkEditorView::Reset() { context_menu_.reset(); - if (GetParent()) + if (parent()) ExpandAndSelect(); } GURL BookmarkEditorView::GetInputURL() const { diff --git a/chrome/browser/ui/views/bookmark_editor_view_unittest.cc b/chrome/browser/ui/views/bookmark_editor_view_unittest.cc index 966d8e4..11c64c9 100644 --- a/chrome/browser/ui/views/bookmark_editor_view_unittest.cc +++ b/chrome/browser/ui/views/bookmark_editor_view_unittest.cc @@ -86,7 +86,7 @@ class BookmarkEditorViewTest : public testing::Test { } bool URLTFHasParent() { - return editor_->url_tf_.GetParent(); + return editor_->url_tf_.parent(); } private: diff --git a/chrome/browser/ui/views/bookmark_menu_controller_views.cc b/chrome/browser/ui/views/bookmark_menu_controller_views.cc index 61af8fa..5c0d684 100644 --- a/chrome/browser/ui/views/bookmark_menu_controller_views.cc +++ b/chrome/browser/ui/views/bookmark_menu_controller_views.cc @@ -388,7 +388,7 @@ void BookmarkMenuController::WillRemoveBookmarksImpl( // be a menu. removed_menus->insert(menu); changed_parent_menus.insert(menu->GetParentMenuItem()); - menu->GetParent()->RemoveChildView(menu); + menu->parent()->RemoveChildView(menu); node_to_menu_id_map_.erase(node_to_menu); } } diff --git a/chrome/browser/ui/views/browser_actions_container.cc b/chrome/browser/ui/views/browser_actions_container.cc index 91f7ab2..8a2b9a1 100644 --- a/chrome/browser/ui/views/browser_actions_container.cc +++ b/chrome/browser/ui/views/browser_actions_container.cc @@ -170,7 +170,7 @@ void BrowserActionButton::UpdateState() { name = UTF8ToUTF16(extension()->name()); SetTooltipText(UTF16ToWideHack(name)); SetAccessibleName(name); - GetParent()->SchedulePaint(); + parent()->SchedulePaint(); } void BrowserActionButton::Observe(NotificationType type, @@ -505,7 +505,7 @@ void BrowserActionsContainer::OnBrowserActionExecuted( // We can get the execute event for browser actions that are not visible, // since buttons can be activated from the overflow menu (chevron). In that // case we show the popup as originating from the chevron. - View* reference_view = button->GetParent()->IsVisible() ? button : chevron_; + View* reference_view = button->parent()->IsVisible() ? button : chevron_; gfx::Point origin; View::ConvertPointToScreen(reference_view, &origin); gfx::Rect rect = reference_view->bounds(); @@ -912,7 +912,7 @@ void BrowserActionsContainer::BrowserActionAdded(const Extension* extension, index = model_->OriginalIndexToIncognito(index); BrowserActionView* view = new BrowserActionView(extension, this); browser_action_views_.insert(browser_action_views_.begin() + index, view); - AddChildView(index, view); + AddChildViewAt(view, index); // If we are still initializing the container, don't bother animating. if (!model_->extensions_initialized()) diff --git a/chrome/browser/ui/views/download_item_view.cc b/chrome/browser/ui/views/download_item_view.cc index aa022b8..ff2d44f 100644 --- a/chrome/browser/ui/views/download_item_view.cc +++ b/chrome/browser/ui/views/download_item_view.cc @@ -393,7 +393,7 @@ void DownloadItemView::OnDownloadUpdated(DownloadItem* download) { // We use the parent's (DownloadShelfView's) SchedulePaint, since there // are spaces between each DownloadItemView that the parent is responsible // for painting. - GetParent()->SchedulePaint(); + parent()->SchedulePaint(); } void DownloadItemView::OnDownloadOpened(DownloadItem* download) { @@ -961,7 +961,7 @@ void DownloadItemView::OpenDownload() { void DownloadItemView::OnExtractIconComplete(IconManager::Handle handle, SkBitmap* icon_bitmap) { if (icon_bitmap) - GetParent()->SchedulePaint(); + parent()->SchedulePaint(); } void DownloadItemView::LoadIcon() { diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc index 8007a8d..60e2f0b 100644 --- a/chrome/browser/ui/views/dropdown_bar_host.cc +++ b/chrome/browser/ui/views/dropdown_bar_host.cc @@ -131,8 +131,8 @@ void DropdownBarHost::FocusWillChange(views::View* focused_before, views::View* focused_now) { // First we need to determine if one or both of the views passed in are child // views of our view. - bool our_view_before = focused_before && view_->IsParentOf(focused_before); - bool our_view_now = focused_now && view_->IsParentOf(focused_now); + bool our_view_before = focused_before && view_->Contains(focused_before); + bool our_view_now = focused_now && view_->Contains(focused_now); // When both our_view_before and our_view_now are false, it means focus is // changing hands elsewhere in the application (and we shouldn't do anything). diff --git a/chrome/browser/ui/views/extensions/extension_view.cc b/chrome/browser/ui/views/extensions/extension_view.cc index d6ff1c4..077f4cd 100644 --- a/chrome/browser/ui/views/extensions/extension_view.cc +++ b/chrome/browser/ui/views/extensions/extension_view.cc @@ -33,9 +33,8 @@ ExtensionView::ExtensionView(ExtensionHost* host, Browser* browser) } ExtensionView::~ExtensionView() { - View* parent = GetParent(); - if (parent) - parent->RemoveChildView(this); + if (parent()) + parent()->RemoveChildView(this); CleanUp(); } diff --git a/chrome/browser/ui/views/frame/browser_frame_gtk.cc b/chrome/browser/ui/views/frame/browser_frame_gtk.cc index d3b7825..3f19fe6 100644 --- a/chrome/browser/ui/views/frame/browser_frame_gtk.cc +++ b/chrome/browser/ui/views/frame/browser_frame_gtk.cc @@ -90,7 +90,7 @@ views::View* BrowserFrameGtk::GetFrameView() const { } void BrowserFrameGtk::TabStripDisplayModeChanged() { - if (GetRootView()->GetChildViewCount() > 0) { + if (GetRootView()->has_children()) { // Make sure the child of the root view gets Layout again. GetRootView()->GetChildViewAt(0)->InvalidateLayout(); } diff --git a/chrome/browser/ui/views/frame/browser_frame_win.cc b/chrome/browser/ui/views/frame/browser_frame_win.cc index 37a9c80..e6d8017 100644 --- a/chrome/browser/ui/views/frame/browser_frame_win.cc +++ b/chrome/browser/ui/views/frame/browser_frame_win.cc @@ -124,7 +124,7 @@ views::View* BrowserFrameWin::GetFrameView() const { } void BrowserFrameWin::TabStripDisplayModeChanged() { - if (GetRootView()->GetChildViewCount() > 0) { + if (GetRootView()->has_children()) { // Make sure the child of the root view gets Layout again. GetRootView()->GetChildViewAt(0)->InvalidateLayout(); } diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index 274ff12..d4d5e9d 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -261,14 +261,13 @@ class ResizeCorner : public views::View { } virtual void Layout() { - views::View* parent_view = GetParent(); - if (parent_view) { + if (parent()) { gfx::Size ps = GetPreferredSize(); // No need to handle Right to left text direction here, // our parent must take care of it for us... // TODO(alekseys): fix it. - SetBounds(parent_view->width() - ps.width(), - parent_view->height() - ps.height(), ps.width(), ps.height()); + SetBounds(parent()->width() - ps.width(), + parent()->height() - ps.height(), ps.width(), ps.height()); } } @@ -477,7 +476,7 @@ BrowserView::~BrowserView() { // The TabStrip attaches a listener to the model. Make sure we shut down the // TabStrip first so that it can cleanly remove the listener. - tabstrip_->GetParent()->RemoveChildView(tabstrip_); + tabstrip_->parent()->RemoveChildView(tabstrip_); delete tabstrip_; tabstrip_ = NULL; @@ -560,7 +559,7 @@ gfx::Rect BrowserView::GetToolbarBounds() const { gfx::Rect BrowserView::GetClientAreaBounds() const { gfx::Rect container_bounds = contents_->bounds(); gfx::Point container_origin = container_bounds.origin(); - ConvertPointToView(this, GetParent(), &container_origin); + ConvertPointToView(this, parent(), &container_origin); container_bounds.set_origin(container_origin); return container_bounds; } @@ -963,7 +962,7 @@ void BrowserView::RotatePaneFocus(bool forwards) { if (focused_view) { for (int i = 0; i < count; ++i) { if (accessible_views[i] == focused_view || - accessible_views[i]->IsParentOf(focused_view)) { + accessible_views[i]->Contains(focused_view)) { index = i; break; } @@ -1819,7 +1818,7 @@ void BrowserView::InfoBarContainerSizeChanged(bool is_animating) { } bool BrowserView::SplitHandleMoved(views::SingleSplitView* view) { - for (int i = 0; i < view->GetChildViewCount(); ++i) + for (int i = 0; i < view->child_count(); ++i) view->GetChildViewAt(i)->InvalidateLayout(); SchedulePaint(); Layout(); @@ -1833,9 +1832,8 @@ views::LayoutManager* BrowserView::CreateLayoutManager() const { void BrowserView::InitTabStrip(TabStripModel* model) { // Throw away the existing tabstrip if we're switching display modes. scoped_ptr<BaseTabStrip> old_strip(tabstrip_); - if (tabstrip_) { - tabstrip_->GetParent()->RemoveChildView(tabstrip_); - } + if (tabstrip_) + tabstrip_->parent()->RemoveChildView(tabstrip_); BrowserTabStripController* tabstrip_controller = new BrowserTabStripController(browser_.get(), model); diff --git a/chrome/browser/ui/views/frame/browser_view_layout.cc b/chrome/browser/ui/views/frame/browser_view_layout.cc index 5a4405f..2429088 100644 --- a/chrome/browser/ui/views/frame/browser_view_layout.cc +++ b/chrome/browser/ui/views/frame/browser_view_layout.cc @@ -135,7 +135,7 @@ int BrowserViewLayout::NonClientHitTest( // area of the window. So we need to treat hit-tests in these regions as // hit-tests of the titlebar. - views::View* parent = browser_view_->GetParent(); + views::View* parent = browser_view_->parent(); gfx::Point point_in_browser_view_coords(point); views::View::ConvertPointToView( @@ -299,7 +299,7 @@ int BrowserViewLayout::LayoutTabStrip() { gfx::Rect tabstrip_bounds( browser_view_->frame()->GetBoundsForTabStrip(tabstrip_)); gfx::Point tabstrip_origin(tabstrip_bounds.origin()); - views::View::ConvertPointToView(browser_view_->GetParent(), browser_view_, + views::View::ConvertPointToView(browser_view_->parent(), browser_view_, &tabstrip_origin); tabstrip_bounds.set_origin(tabstrip_origin); @@ -383,7 +383,7 @@ void BrowserViewLayout::UpdateReservedContentsRect( gfx::Point resize_corner_origin(browser_reserved_rect.origin()); // Convert |resize_corner_origin| from browser_view_ to source's parent // coordinates. - views::View::ConvertPointToView(browser_view_, source->GetParent(), + views::View::ConvertPointToView(browser_view_, source->parent(), &resize_corner_origin); // Create |reserved_rect| in source's parent coordinates. gfx::Rect reserved_rect(resize_corner_origin, browser_reserved_rect.size()); diff --git a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc index af92a7c..b70715d 100644 --- a/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc +++ b/chrome/browser/ui/views/frame/opaque_browser_frame_view.cc @@ -395,7 +395,7 @@ bool OpaqueBrowserFrameView::HitTest(const gfx::Point& l) const { // completely. We need to do this since we're not a parent of the tabstrip, // meaning ConvertPointToView would otherwise return something bogus. gfx::Point browser_view_point(l); - View::ConvertPointToView(GetParent(), browser_view_, &browser_view_point); + View::ConvertPointToView(parent(), browser_view_, &browser_view_point); return browser_view_->IsPositionInWindowCaption(browser_view_point); } diff --git a/chrome/browser/ui/views/info_bubble.cc b/chrome/browser/ui/views/info_bubble.cc index 32fe0c1..aad0b38 100644 --- a/chrome/browser/ui/views/info_bubble.cc +++ b/chrome/browser/ui/views/info_bubble.cc @@ -438,7 +438,7 @@ void InfoBubble::Init(views::Widget* parent, arrow_location, false, contents->GetPreferredSize(), &contents_bounds, &window_bounds); // This new view must be added before |contents| so it will paint under it. - contents_view->AddChildView(0, border_contents_); + contents_view->AddChildViewAt(border_contents_, 0); // |contents_view| has no layout manager, so we have to explicitly position // its children. @@ -500,7 +500,7 @@ void InfoBubble::OnActivate(UINT action, BOOL minimized, HWND window) { if (action == WA_INACTIVE) { Close(); } else if (action == WA_ACTIVE) { - DCHECK_GT(GetRootView()->GetChildViewCount(), 0); + DCHECK(GetRootView()->has_children()); GetRootView()->GetChildViewAt(0)->RequestFocus(); } } diff --git a/chrome/browser/ui/views/infobars/infobar_container.cc b/chrome/browser/ui/views/infobars/infobar_container.cc index 4a2ed5c..f7148f1 100644 --- a/chrome/browser/ui/views/infobars/infobar_container.cc +++ b/chrome/browser/ui/views/infobars/infobar_container.cc @@ -60,7 +60,7 @@ void InfoBarContainer::RemoveDelegate(InfoBarDelegate* delegate) { void InfoBarContainer::PaintInfoBarArrows(gfx::Canvas* canvas, View* outer_view, int arrow_center_x) { - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); infobar->PaintArrow(canvas, outer_view, arrow_center_x); } @@ -71,14 +71,14 @@ gfx::Size InfoBarContainer::GetPreferredSize() { // of the delegate). Our preferred height is the sum of the preferred heights // of the InfoBars contained within us. int height = 0; - for (int i = 0; i < GetChildViewCount(); ++i) + for (int i = 0; i < child_count(); ++i) height += GetChildViewAt(i)->GetPreferredSize().height(); return gfx::Size(0, height); } void InfoBarContainer::Layout() { int top = 0; - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { View* child = GetChildViewAt(i); gfx::Size ps = child->GetPreferredSize(); child->SetBounds(0, top, width(), ps.height()); @@ -93,7 +93,7 @@ AccessibilityTypes::Role InfoBarContainer::GetAccessibleRole() { void InfoBarContainer::ViewHierarchyChanged(bool is_add, View* parent, View* child) { - if (parent == this && child->GetParent() == this) { + if (parent == this && child->parent() == this) { if (delegate_) { // An InfoBar child was added or removed. Tell the delegate it needs to // re-layout since our preferred size will have changed. @@ -147,7 +147,7 @@ void InfoBarContainer::RemoveInfoBar(InfoBarDelegate* delegate, // a child view until its close animation completes, which can result in // different number of infobars in container and infobar delegates in tab // contents. - for (int i = 0; i < GetChildViewCount(); ++i) { + for (int i = 0; i < child_count(); ++i) { InfoBarView* infobar = static_cast<InfoBarView*>(GetChildViewAt(i)); if (infobar->delegate() == delegate) { if (use_animation) { diff --git a/chrome/browser/ui/views/infobars/infobar_view.cc b/chrome/browser/ui/views/infobars/infobar_view.cc index ea80f87..8b63a8e 100644 --- a/chrome/browser/ui/views/infobars/infobar_view.cc +++ b/chrome/browser/ui/views/infobars/infobar_view.cc @@ -90,7 +90,7 @@ void InfoBarView::AnimateClose() { } void InfoBarView::Close() { - GetParent()->RemoveChildView(this); + parent()->RemoveChildView(this); // Note that we only tell the delegate we're closed here, and not when we're // simply destroyed (by virtue of a tab switch or being moved from window to // window), since this action can cause the delegate to destroy itself. @@ -104,7 +104,7 @@ void InfoBarView::PaintArrow(gfx::Canvas* canvas, View* outer_view, int arrow_center_x) { gfx::Point infobar_top(0, y()); - ConvertPointToView(GetParent(), outer_view, &infobar_top); + ConvertPointToView(parent(), outer_view, &infobar_top); int infobar_top_y = infobar_top.y(); SkPoint gradient_points[2] = { {SkIntToScalar(0), SkIntToScalar(infobar_top_y)}, @@ -194,8 +194,8 @@ void InfoBarView::ViewHierarchyChanged(bool is_add, View* parent, View* child) { // For accessibility, ensure the close button is the last child view. if ((parent == this) && (child != close_button_) && - HasChildView(close_button_) && - (GetChildViewAt(GetChildViewCount() - 1) != close_button_)) { + (close_button_->parent() == this) && + (GetChildViewAt(child_count() - 1) != close_button_)) { RemoveChildView(close_button_); AddChildView(close_button_); } @@ -245,8 +245,8 @@ gfx::Size InfoBarView::GetPreferredSize() { void InfoBarView::FocusWillChange(View* focused_before, View* focused_now) { // This will trigger some screen readers to read the entire contents of this // infobar. - if (focused_before && focused_now && !this->IsParentOf(focused_before) && - this->IsParentOf(focused_now)) + if (focused_before && focused_now && !this->Contains(focused_before) && + this->Contains(focused_now)) NotifyAccessibilityEvent(AccessibilityTypes::EVENT_ALERT); } diff --git a/chrome/browser/ui/views/location_bar/location_bar_view.cc b/chrome/browser/ui/views/location_bar/location_bar_view.cc index 9597e22..6634354 100644 --- a/chrome/browser/ui/views/location_bar/location_bar_view.cc +++ b/chrome/browser/ui/views/location_bar/location_bar_view.cc @@ -968,7 +968,7 @@ void LocationBarView::RefreshPageActionViews() { page_action_views_[i] = new PageActionWithBadgeView( new PageActionImageView(this, profile_, page_actions[i])); page_action_views_[i]->SetVisible(false); - AddChildView(GetChildIndex(star_view_), page_action_views_[i]); + AddChildViewAt(page_action_views_[i], GetIndexOf(star_view_)); } } diff --git a/chrome/browser/ui/views/location_bar/page_action_image_view.cc b/chrome/browser/ui/views/location_bar/page_action_image_view.cc index 86e2f4b..e867091 100644 --- a/chrome/browser/ui/views/location_bar/page_action_image_view.cc +++ b/chrome/browser/ui/views/location_bar/page_action_image_view.cc @@ -184,7 +184,7 @@ void PageActionImageView::OnImageLoaded( // During object construction (before the parent has been set) we are already // in a UpdatePageActions call, so we don't need to start another one (and // doing so causes crash described in http://crbug.com/57333). - if (GetParent()) + if (parent()) owner_->UpdatePageActions(); } diff --git a/chrome/browser/ui/views/options/advanced_contents_view.cc b/chrome/browser/ui/views/options/advanced_contents_view.cc index 0526412..2075b38 100644 --- a/chrome/browser/ui/views/options/advanced_contents_view.cc +++ b/chrome/browser/ui/views/options/advanced_contents_view.cc @@ -1473,9 +1473,9 @@ void CloudPrintProxySection::NotifyPrefChanged(const std::string* pref_name) { // possible that the section_description_label_ has changed // heights. And scroll us back to being visible in that case, to // be nice to the user. - views::View* view = section_description_label_->GetParent(); + views::View* view = section_description_label_->parent(); while (view && view->GetClassName() != views::ScrollView::kViewClassName) - view = view->GetParent(); + view = view->parent(); if (view) { gfx::Rect visible_bounds = GetVisibleBounds(); bool was_all_visible = (visible_bounds.size() == size()); @@ -1548,9 +1548,8 @@ int AdvancedContentsView::GetLineScrollIncrement( } void AdvancedContentsView::Layout() { - views::View* parent = GetParent(); - if (parent && parent->width()) { - const int width = parent->width(); + if (parent() && parent()->width()) { + const int width = parent()->width(); const int height = GetHeightForWidth(width); SetBounds(0, 0, width, height); } else { diff --git a/chrome/browser/ui/views/options/content_settings_window_view.cc b/chrome/browser/ui/views/options/content_settings_window_view.cc index 6cc1a64..30916cf 100644 --- a/chrome/browser/ui/views/options/content_settings_window_view.cc +++ b/chrome/browser/ui/views/options/content_settings_window_view.cc @@ -129,7 +129,7 @@ void ContentSettingsWindowView::Layout() { listbox_width, height() - (3 * kDialogPadding) - label_->height()); - if (pages_[current_page_]->GetParent()) { + if (pages_[current_page_]->parent()) { pages_[current_page_]->SetBounds( 2 * kDialogPadding + listbox_width, 2 * kDialogPadding + label_->height(), @@ -196,7 +196,7 @@ void ContentSettingsWindowView::Init() { } void ContentSettingsWindowView::ShowSettingsPage(int page) { - if (pages_[current_page_]->GetParent()) + if (pages_[current_page_]->parent()) RemoveChildView(pages_[current_page_]); current_page_ = page; AddChildView(pages_[current_page_]); diff --git a/chrome/browser/ui/views/options/cookies_view.cc b/chrome/browser/ui/views/options/cookies_view.cc index 278e964..7cb24b6 100644 --- a/chrome/browser/ui/views/options/cookies_view.cc +++ b/chrome/browser/ui/views/options/cookies_view.cc @@ -73,13 +73,12 @@ void CookiesTreeView::RemoveSelectedItems() { class CookiesView::InfoPanelView : public views::View { public: virtual void Layout() { - int child_count = GetChildViewCount(); - for (int i = 0; i < child_count; ++i) + for (int i = 0; i < child_count(); ++i) GetChildViewAt(i)->SetBounds(0, 0, width(), height()); } virtual gfx::Size GetPreferredSize() { - DCHECK(GetChildViewCount() > 0); + DCHECK(has_children()); return GetChildViewAt(0)->GetPreferredSize(); } }; @@ -177,7 +176,7 @@ views::View* CookiesView::GetContentsView() { void CookiesView::Layout() { // Lay out the Remove/Remove All buttons in the parent view. gfx::Size ps = remove_button_->GetPreferredSize(); - gfx::Rect parent_bounds = GetParent()->GetContentsBounds(); + gfx::Rect parent_bounds = parent()->GetContentsBounds(); int y_buttons = parent_bounds.bottom() - ps.height() - views::kButtonVEdgeMargin; @@ -362,9 +361,8 @@ void CookiesView::Init() { layout->AddView(info_panel_); // Add the Remove/Remove All buttons to the ClientView - View* parent = GetParent(); - parent->AddChildView(remove_button_); - parent->AddChildView(remove_all_button_); + parent()->AddChildView(remove_button_); + parent()->AddChildView(remove_all_button_); if (!cookies_tree_model_.get()->GetRoot()->GetChildCount()) { UpdateForEmptyState(); } else { diff --git a/chrome/browser/ui/views/options/exceptions_view.cc b/chrome/browser/ui/views/options/exceptions_view.cc index 54c9770..426e1c2 100644 --- a/chrome/browser/ui/views/options/exceptions_view.cc +++ b/chrome/browser/ui/views/options/exceptions_view.cc @@ -84,7 +84,7 @@ void ExceptionsView::Layout() { // The buttons are placed in the parent, but we need to lay them out. int max_y = - GetParent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; + parent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; int x = kPanelHorizMargin; for (size_t i = 0; i < arraysize(buttons); ++i) { @@ -196,11 +196,10 @@ void ExceptionsView::Init() { UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVEALL_BUTTON))); remove_all_button_->set_tag(IDS_EXCEPTIONS_REMOVEALL_BUTTON); - View* parent = GetParent(); - parent->AddChildView(add_button_); - parent->AddChildView(edit_button_); - parent->AddChildView(remove_button_); - parent->AddChildView(remove_all_button_); + parent()->AddChildView(add_button_); + parent()->AddChildView(edit_button_); + parent()->AddChildView(remove_button_); + parent()->AddChildView(remove_all_button_); GridLayout* layout = new GridLayout(this); layout->SetInsets(kExceptionsViewInsetSize, kExceptionsViewInsetSize, diff --git a/chrome/browser/ui/views/options/simple_content_exceptions_view.cc b/chrome/browser/ui/views/options/simple_content_exceptions_view.cc index 607bfde..b53bf4a 100644 --- a/chrome/browser/ui/views/options/simple_content_exceptions_view.cc +++ b/chrome/browser/ui/views/options/simple_content_exceptions_view.cc @@ -70,7 +70,7 @@ void SimpleContentExceptionsView::Layout() { // The buttons are placed in the parent, but we need to lay them out. int max_y = - GetParent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; + parent()->GetContentsBounds().bottom() - views::kButtonVEdgeMargin; int x = kPanelHorizMargin; for (size_t i = 0; i < arraysize(buttons); ++i) { @@ -143,9 +143,8 @@ void SimpleContentExceptionsView::Init() { UTF16ToWide(l10n_util::GetStringUTF16(IDS_EXCEPTIONS_REMOVEALL_BUTTON))); remove_all_button_->set_tag(IDS_EXCEPTIONS_REMOVEALL_BUTTON); - View* parent = GetParent(); - parent->AddChildView(remove_button_); - parent->AddChildView(remove_all_button_); + parent()->AddChildView(remove_button_); + parent()->AddChildView(remove_all_button_); GridLayout* layout = new GridLayout(this); layout->SetInsets(kExceptionsViewInsetSize, kExceptionsViewInsetSize, diff --git a/chrome/browser/ui/views/tabs/base_tab.cc b/chrome/browser/ui/views/tabs/base_tab.cc index 19045b2..e76a492 100644 --- a/chrome/browser/ui/views/tabs/base_tab.cc +++ b/chrome/browser/ui/views/tabs/base_tab.cc @@ -58,12 +58,12 @@ class TabCloseButton : public views::ImageButton { // fire before Enter events, so this works. virtual void OnMouseEntered(const views::MouseEvent& event) { CustomButton::OnMouseEntered(event); - GetParent()->OnMouseEntered(event); + parent()->OnMouseEntered(event); } virtual void OnMouseExited(const views::MouseEvent& event) { CustomButton::OnMouseExited(event); - GetParent()->OnMouseExited(event); + parent()->OnMouseExited(event); } private: diff --git a/chrome/browser/ui/views/tabs/base_tab_strip.cc b/chrome/browser/ui/views/tabs/base_tab_strip.cc index dbf90ec..1afbc1b 100644 --- a/chrome/browser/ui/views/tabs/base_tab_strip.cc +++ b/chrome/browser/ui/views/tabs/base_tab_strip.cc @@ -333,7 +333,7 @@ BaseTab* BaseTabStrip::GetTabAt(BaseTab* tab, // Walk up the view hierarchy until we find a tab, or the TabStrip. while (view && view != this && view->GetID() != VIEW_ID_TAB) - view = view->GetParent(); + view = view->parent(); return view && view->GetID() == VIEW_ID_TAB ? static_cast<BaseTab*>(view) : NULL; diff --git a/chrome/browser/ui/views/tabs/dragged_tab_view.cc b/chrome/browser/ui/views/tabs/dragged_tab_view.cc index 4019407..367019e 100644 --- a/chrome/browser/ui/views/tabs/dragged_tab_view.cc +++ b/chrome/browser/ui/views/tabs/dragged_tab_view.cc @@ -62,7 +62,7 @@ DraggedTabView::DraggedTabView(views::View* renderer, } DraggedTabView::~DraggedTabView() { - GetParent()->RemoveChildView(this); + parent()->RemoveChildView(this); container_->CloseNow(); } diff --git a/chrome/browser/ui/views/tabs/tab_strip.cc b/chrome/browser/ui/views/tabs/tab_strip.cc index 7a2ea04..e454f0e 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.cc +++ b/chrome/browser/ui/views/tabs/tab_strip.cc @@ -310,7 +310,7 @@ void TabStrip::PaintChildren(gfx::Canvas* canvas) { } // Overridden to support automation. See automation_proxy_uitest.cc. -views::View* TabStrip::GetViewByID(int view_id) const { +const views::View* TabStrip::GetViewByID(int view_id) const { if (tab_count() > 0) { if (view_id == VIEW_ID_TAB_LAST) { return GetTabAtTabDataIndex(tab_count() - 1); diff --git a/chrome/browser/ui/views/tabs/tab_strip.h b/chrome/browser/ui/views/tabs/tab_strip.h index 39d01a8..e50c779 100644 --- a/chrome/browser/ui/views/tabs/tab_strip.h +++ b/chrome/browser/ui/views/tabs/tab_strip.h @@ -69,7 +69,7 @@ class TabStrip : public BaseTabStrip, // views::View overrides: virtual void PaintChildren(gfx::Canvas* canvas); - virtual views::View* GetViewByID(int id) const; + virtual const views::View* GetViewByID(int id) const; virtual gfx::Size GetPreferredSize(); // NOTE: the drag and drop methods are invoked from FrameView. This is done to // allow for a drop region that extends outside the bounds of the TabStrip. diff --git a/chrome/browser/ui/views/task_manager_view.cc b/chrome/browser/ui/views/task_manager_view.cc index 1e2339a..156301e 100644 --- a/chrome/browser/ui/views/task_manager_view.cc +++ b/chrome/browser/ui/views/task_manager_view.cc @@ -518,7 +518,7 @@ void TaskManagerView::Layout() { height() - 2 * kPanelVertMargin - prefered_height); // y-coordinate of button top left. - gfx::Rect parent_bounds = GetParent()->GetContentsBounds(); + gfx::Rect parent_bounds = parent()->GetContentsBounds(); int y_buttons = parent_bounds.bottom() - prefered_height - views::kButtonVEdgeMargin; diff --git a/chrome/browser/ui/views/wrench_menu.cc b/chrome/browser/ui/views/wrench_menu.cc index 394ea83..8f769bd 100644 --- a/chrome/browser/ui/views/wrench_menu.cc +++ b/chrome/browser/ui/views/wrench_menu.cc @@ -235,9 +235,8 @@ class ScheduleAllView : public views::View { if (!IsVisible()) return; - if (GetParent()) { - GetParent()->SchedulePaint(GetMirroredBounds(), urgent); - } + if (parent()) + parent()->SchedulePaint(GetMirroredBounds(), urgent); } private: @@ -343,13 +342,13 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView { gfx::Size GetPreferredSize() { // Returned height doesn't matter as MenuItemView forces everything to the // height of the menuitemview. - return gfx::Size(GetMaxChildViewPreferredWidth() * GetChildViewCount(), 0); + return gfx::Size(GetMaxChildViewPreferredWidth() * child_count(), 0); } void Layout() { // All buttons are given the same width. int width = GetMaxChildViewPreferredWidth(); - for (int i = 0; i < GetChildViewCount(); ++i) + for (int i = 0; i < child_count(); ++i) GetChildViewAt(i)->SetBounds(i * width, 0, width, height()); } @@ -362,7 +361,7 @@ class WrenchMenu::CutCopyPasteView : public WrenchMenuView { // Returns the max preferred width of all the children. int GetMaxChildViewPreferredWidth() { int width = 0; - for (int i = 0; i < GetChildViewCount(); ++i) + for (int i = 0; i < child_count(); ++i) width = std::max(width, GetChildViewAt(i)->GetPreferredSize().width()); return width; } 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); } } |