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

Side by Side Diff: views/controls/tabbed_pane/native_tabbed_pane_gtk.cc

Issue 7015051: Re-land: (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 9 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "views/controls/tabbed_pane/native_tabbed_pane_gtk.h" 5 #include "views/controls/tabbed_pane/native_tabbed_pane_gtk.h"
6 6
7 #include <gtk/gtk.h> 7 #include <gtk/gtk.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/stl_util-inl.h" 10 #include "base/stl_util-inl.h"
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 // We are the last tab, select the previous one. 70 // We are the last tab, select the previous one.
71 if (index > 0) { 71 if (index > 0) {
72 SelectTabAt(index - 1); 72 SelectTabAt(index - 1);
73 } else { 73 } else {
74 // last tab. nothing to select. 74 // last tab. nothing to select.
75 } 75 }
76 } 76 }
77 77
78 GtkWidget* page = 78 GtkWidget* page =
79 gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), index); 79 gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), index);
80 WidgetGtk* widget = 80 Widget* widget =
81 static_cast<WidgetGtk*>(NativeWidget::GetNativeWidgetForNativeView(page)); 81 NativeWidget::GetNativeWidgetForNativeView(page)->GetWidget();
82 82
83 // detach the content view from widget so that we can delete widget 83 // detach the content view from widget so that we can delete widget
84 // without destroying the content view. 84 // without destroying the content view.
85 View* removed_tab = GetTabViewAt(index); 85 View* removed_tab = GetTabViewAt(index);
86 widget->GetRootView()->RemoveChildView(removed_tab); 86 widget->GetRootView()->RemoveChildView(removed_tab);
87 87
88 // widget delete itself when native_view is deleted. 88 // widget delete itself when native_view is deleted.
89 gtk_notebook_remove_page(GTK_NOTEBOOK(native_view()), index); 89 gtk_notebook_remove_page(GTK_NOTEBOOK(native_view()), index);
90 90
91 // Removing a tab might change the size of the tabbed pane. 91 // Removing a tab might change the size of the tabbed pane.
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 147
148 //////////////////////////////////////////////////////////////////////////////// 148 ////////////////////////////////////////////////////////////////////////////////
149 // NativeTabbedPaneGtk, private: 149 // NativeTabbedPaneGtk, private:
150 void NativeTabbedPaneGtk::DoAddTabAtIndex(int index, 150 void NativeTabbedPaneGtk::DoAddTabAtIndex(int index,
151 const std::wstring& title, 151 const std::wstring& title,
152 View* contents, 152 View* contents,
153 bool select_if_first_tab) { 153 bool select_if_first_tab) {
154 int tab_count = GetTabCount(); 154 int tab_count = GetTabCount();
155 DCHECK(index <= tab_count); 155 DCHECK(index <= tab_count);
156 156
157 Widget* page_container = Widget::CreateWidget(); 157 Widget* page_container = new Widget;
158 page_container->Init( 158 page_container->Init(
159 Widget::InitParams(Widget::InitParams::TYPE_CONTROL)); 159 Widget::InitParams(Widget::InitParams::TYPE_CONTROL));
160 page_container->SetContentsView(contents); 160 page_container->SetContentsView(contents);
161 page_container->SetFocusTraversableParent(GetWidget()->GetFocusTraversable()); 161 page_container->SetFocusTraversableParent(GetWidget()->GetFocusTraversable());
162 page_container->SetFocusTraversableParentView(this); 162 page_container->SetFocusTraversableParentView(this);
163 page_container->Show(); 163 page_container->Show();
164 164
165 if (!contents->background()) { 165 if (!contents->background()) {
166 GtkStyle* window_style = 166 GtkStyle* window_style =
167 gtk_widget_get_style(page_container->GetNativeView()); 167 gtk_widget_get_style(page_container->GetNativeView());
(...skipping 20 matching lines...) Expand all
188 188
189 if (tab_count == 0 && select_if_first_tab) 189 if (tab_count == 0 && select_if_first_tab)
190 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), 0); 190 gtk_notebook_set_current_page(GTK_NOTEBOOK(native_view()), 0);
191 191
192 // Relayout the hierarchy, since the added tab might require more space. 192 // Relayout the hierarchy, since the added tab might require more space.
193 RootView* root_view = GetRootView(); 193 RootView* root_view = GetRootView();
194 if (root_view) 194 if (root_view)
195 GetRootView()->Layout(); 195 GetRootView()->Layout();
196 } 196 }
197 197
198 WidgetGtk* NativeTabbedPaneGtk::GetWidgetAt(int index) { 198 Widget* NativeTabbedPaneGtk::GetWidgetAt(int index) {
199 DCHECK(index <= GetTabCount()); 199 DCHECK(index <= GetTabCount());
200 GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()), 200 GtkWidget* page = gtk_notebook_get_nth_page(GTK_NOTEBOOK(native_view()),
201 index); 201 index);
202 WidgetGtk* widget = 202 Widget* widget =
203 static_cast<WidgetGtk*>(NativeWidget::GetNativeWidgetForNativeView(page)); 203 NativeWidget::GetNativeWidgetForNativeView(page)->GetWidget();
204 DCHECK(widget); 204 DCHECK(widget);
205 return widget; 205 return widget;
206 } 206 }
207 207
208 View* NativeTabbedPaneGtk::GetTabViewAt(int index) { 208 View* NativeTabbedPaneGtk::GetTabViewAt(int index) {
209 WidgetGtk* widget = GetWidgetAt(index); 209 Widget* widget = GetWidgetAt(index);
210 DCHECK(widget && widget->GetRootView()->child_count() == 1); 210 DCHECK(widget && widget->GetRootView()->child_count() == 1);
211 return widget->GetRootView()->GetChildViewAt(0); 211 return widget->GetRootView()->GetChildViewAt(0);
212 } 212 }
213 213
214 void NativeTabbedPaneGtk::OnSwitchPage(int selected_tab_index) { 214 void NativeTabbedPaneGtk::OnSwitchPage(int selected_tab_index) {
215 TabbedPaneListener* listener = tabbed_pane_->listener(); 215 TabbedPaneListener* listener = tabbed_pane_->listener();
216 if (listener != NULL) 216 if (listener != NULL)
217 listener->TabSelectedAt(selected_tab_index); 217 listener->TabSelectedAt(selected_tab_index);
218 } 218 }
219 219
220 // static 220 // static
221 void NativeTabbedPaneGtk::CallSwitchPage(GtkNotebook* widget, 221 void NativeTabbedPaneGtk::CallSwitchPage(GtkNotebook* widget,
222 GtkNotebookPage* page, 222 GtkNotebookPage* page,
223 guint selected_tab_index, 223 guint selected_tab_index,
224 NativeTabbedPaneGtk* tabbed_pane) { 224 NativeTabbedPaneGtk* tabbed_pane) {
225 tabbed_pane->OnSwitchPage(selected_tab_index); 225 tabbed_pane->OnSwitchPage(selected_tab_index);
226 } 226 }
227 227
228 //////////////////////////////////////////////////////////////////////////////// 228 ////////////////////////////////////////////////////////////////////////////////
229 // NativeTabbedPaneWrapper, public: 229 // NativeTabbedPaneWrapper, public:
230 230
231 // static 231 // static
232 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper( 232 NativeTabbedPaneWrapper* NativeTabbedPaneWrapper::CreateNativeWrapper(
233 TabbedPane* tabbed_pane) { 233 TabbedPane* tabbed_pane) {
234 return new NativeTabbedPaneGtk(tabbed_pane); 234 return new NativeTabbedPaneGtk(tabbed_pane);
235 } 235 }
236 236
237 } // namespace views 237 } // namespace views
OLDNEW
« no previous file with comments | « views/controls/tabbed_pane/native_tabbed_pane_gtk.h ('k') | views/controls/tabbed_pane/native_tabbed_pane_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698