OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/options_window.h" | 5 #include "chrome/browser/options_window.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
9 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
10 #include "chrome/browser/browser_list.h" | 10 #include "chrome/browser/browser_list.h" |
(...skipping 17 matching lines...) Expand all Loading... |
28 #include "views/controls/tabbed_pane/tabbed_pane.h" | 28 #include "views/controls/tabbed_pane/tabbed_pane.h" |
29 #include "views/widget/root_view.h" | 29 #include "views/widget/root_view.h" |
30 #include "views/window/dialog_delegate.h" | 30 #include "views/window/dialog_delegate.h" |
31 #include "views/window/window.h" | 31 #include "views/window/window.h" |
32 #include "views/window/window_gtk.h" | 32 #include "views/window/window_gtk.h" |
33 | 33 |
34 | 34 |
35 namespace chromeos { | 35 namespace chromeos { |
36 | 36 |
37 /////////////////////////////////////////////////////////////////////////////// | 37 /////////////////////////////////////////////////////////////////////////////// |
| 38 // GtkPreferencePageHost |
| 39 // |
| 40 // Hosts a GTK preference page and takes care of sizing it appropriately. |
| 41 // |
| 42 class GtkPreferencePageHost : public views::NativeViewHost { |
| 43 public: |
| 44 explicit GtkPreferencePageHost(GtkWidget* widget); |
| 45 |
| 46 private: |
| 47 // views::View overrides: |
| 48 virtual void ViewHierarchyChanged(bool is_add, View* parent, View* child); |
| 49 virtual gfx::Size GetPreferredSize(); |
| 50 |
| 51 GtkWidget* widget_; |
| 52 |
| 53 DISALLOW_COPY_AND_ASSIGN(GtkPreferencePageHost); |
| 54 }; |
| 55 |
| 56 GtkPreferencePageHost::GtkPreferencePageHost(GtkWidget* widget) |
| 57 : widget_(widget) { |
| 58 set_background(views::Background::CreateSolidBackground(SK_ColorWHITE)); |
| 59 } |
| 60 |
| 61 void GtkPreferencePageHost::ViewHierarchyChanged(bool is_add, |
| 62 View* parent, |
| 63 View* child) { |
| 64 NativeViewHost::ViewHierarchyChanged(is_add, parent, child); |
| 65 if (is_add && child == this) |
| 66 Attach(widget_); |
| 67 } |
| 68 |
| 69 gfx::Size GtkPreferencePageHost::GetPreferredSize() { |
| 70 // We need to show the widget and its children since otherwise containers like |
| 71 // gtk_box don't compute the correct size. |
| 72 gtk_widget_show_all(widget_); |
| 73 GtkRequisition requisition = { 0, 0 }; |
| 74 gtk_widget_size_request(GTK_WIDGET(widget_), &requisition); |
| 75 GtkRequisition& size(widget_->requisition); |
| 76 return gfx::Size(size.width, size.height); |
| 77 } |
| 78 |
| 79 /////////////////////////////////////////////////////////////////////////////// |
38 // OptionsWindowView | 80 // OptionsWindowView |
39 // | 81 // |
40 // The contents of the Options dialog window. | 82 // The contents of the Options dialog window. |
41 // | 83 // |
42 class OptionsWindowView : public views::View, | 84 class OptionsWindowView : public views::View, |
43 public views::DialogDelegate, | 85 public views::DialogDelegate, |
44 public views::TabbedPane::Listener { | 86 public views::TabbedPane::Listener { |
45 public: | 87 public: |
46 static const int kDialogPadding; | 88 static const int kDialogPadding; |
47 static const SkColor kDialogBackground; | 89 static const SkColor kDialogBackground; |
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
207 /////////////////////////////////////////////////////////////////////////////// | 249 /////////////////////////////////////////////////////////////////////////////// |
208 // OptionsWindowView, views::View overrides: | 250 // OptionsWindowView, views::View overrides: |
209 | 251 |
210 void OptionsWindowView::Layout() { | 252 void OptionsWindowView::Layout() { |
211 tabs_->SetBounds(kDialogPadding, kDialogPadding, | 253 tabs_->SetBounds(kDialogPadding, kDialogPadding, |
212 width() - (2 * kDialogPadding), | 254 width() - (2 * kDialogPadding), |
213 height() - (2 * kDialogPadding)); | 255 height() - (2 * kDialogPadding)); |
214 } | 256 } |
215 | 257 |
216 gfx::Size OptionsWindowView::GetPreferredSize() { | 258 gfx::Size OptionsWindowView::GetPreferredSize() { |
217 return gfx::Size(views::Window::GetLocalizedContentsSize( | 259 gfx::Size size(tabs_->GetPreferredSize()); |
218 IDS_OPTIONS_DIALOG_WIDTH_CHARS, | 260 size.Enlarge(2 * kDialogPadding, 2 * kDialogPadding); |
219 IDS_OPTIONS_DIALOG_HEIGHT_LINES)); | 261 return size; |
220 } | 262 } |
221 | 263 |
222 void OptionsWindowView::ViewHierarchyChanged(bool is_add, | 264 void OptionsWindowView::ViewHierarchyChanged(bool is_add, |
223 views::View* parent, | 265 views::View* parent, |
224 views::View* child) { | 266 views::View* child) { |
225 // Can't init before we're inserted into a Container, because we require a | 267 // Can't init before we're inserted into a Container, because we require a |
226 // HWND to parent native child controls to. | 268 // HWND to parent native child controls to. |
227 if (is_add && child == this) | 269 if (is_add && child == this) |
228 Init(); | 270 Init(); |
229 } | 271 } |
(...skipping 26 matching lines...) Expand all Loading... |
256 l10n_util::GetString(IDS_OPTIONS_SYSTEM_TAB_LABEL), | 298 l10n_util::GetString(IDS_OPTIONS_SYSTEM_TAB_LABEL), |
257 system_page, false); | 299 system_page, false); |
258 | 300 |
259 InternetPageView* internet_page = new InternetPageView(profile_); | 301 InternetPageView* internet_page = new InternetPageView(profile_); |
260 internet_page->set_background(views::Background::CreateSolidBackground( | 302 internet_page->set_background(views::Background::CreateSolidBackground( |
261 SK_ColorWHITE)); | 303 SK_ColorWHITE)); |
262 tabs_->AddTabAtIndex(tab_index++, | 304 tabs_->AddTabAtIndex(tab_index++, |
263 l10n_util::GetString(IDS_OPTIONS_INTERNET_TAB_LABEL), | 305 l10n_util::GetString(IDS_OPTIONS_INTERNET_TAB_LABEL), |
264 internet_page, false); | 306 internet_page, false); |
265 | 307 |
266 views::NativeViewHost* general_page_view = new views::NativeViewHost(); | |
267 general_page_view->set_background(views::Background::CreateSolidBackground( | |
268 SK_ColorWHITE)); | |
269 tabs_->AddTabAtIndex(tab_index++, | 308 tabs_->AddTabAtIndex(tab_index++, |
270 l10n_util::GetString(IDS_OPTIONS_GENERAL_TAB_LABEL), | 309 l10n_util::GetString(IDS_OPTIONS_GENERAL_TAB_LABEL), |
271 general_page_view, false); | 310 new GtkPreferencePageHost( |
272 general_page_view->Attach(general_page_.get_page_widget()); | 311 general_page_.get_page_widget()), |
| 312 false); |
273 | 313 |
274 views::NativeViewHost* content_page_view = new views::NativeViewHost(); | |
275 content_page_view->set_background(views::Background::CreateSolidBackground( | |
276 SK_ColorWHITE)); | |
277 tabs_->AddTabAtIndex(tab_index++, | 314 tabs_->AddTabAtIndex(tab_index++, |
278 l10n_util::GetString(IDS_OPTIONS_CONTENT_TAB_LABEL), | 315 l10n_util::GetString(IDS_OPTIONS_CONTENT_TAB_LABEL), |
279 content_page_view, false); | 316 new GtkPreferencePageHost( |
280 content_page_view->Attach(content_page_.get_page_widget()); | 317 content_page_.get_page_widget()), |
| 318 false); |
281 | 319 |
282 views::NativeViewHost* advanced_page_view = new views::NativeViewHost(); | |
283 advanced_page_view->set_background(views::Background::CreateSolidBackground( | |
284 SK_ColorWHITE)); | |
285 tabs_->AddTabAtIndex(tab_index++, | 320 tabs_->AddTabAtIndex(tab_index++, |
286 l10n_util::GetString(IDS_OPTIONS_ADVANCED_TAB_LABEL), | 321 l10n_util::GetString(IDS_OPTIONS_ADVANCED_TAB_LABEL), |
287 advanced_page_view, false); | 322 new GtkPreferencePageHost( |
288 advanced_page_view->Attach(advanced_page_.get_page_widget()); | 323 advanced_page_.get_page_widget()), |
| 324 false); |
289 | 325 |
290 DCHECK(tabs_->GetTabCount() == OPTIONS_PAGE_COUNT); | 326 DCHECK(tabs_->GetTabCount() == OPTIONS_PAGE_COUNT); |
291 | 327 |
292 initialized_ = true; | 328 initialized_ = true; |
293 } | 329 } |
294 | 330 |
295 OptionsPageView* OptionsWindowView::GetCurrentOptionsPageView() const { | 331 OptionsPageView* OptionsWindowView::GetCurrentOptionsPageView() const { |
296 int selected_option_page = tabs_->GetSelectedTabIndex(); | 332 int selected_option_page = tabs_->GetSelectedTabIndex(); |
297 if (selected_option_page < OPTIONS_PAGE_GENERAL) { | 333 if (selected_option_page < OPTIONS_PAGE_GENERAL) { |
298 return static_cast<OptionsPageView*>(tabs_->GetSelectedTab()); | 334 return static_cast<OptionsPageView*>(tabs_->GetSelectedTab()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
337 // a new one for the current active browser. | 373 // a new one for the current active browser. |
338 chromeos::CloseOptionsWindow(); | 374 chromeos::CloseOptionsWindow(); |
339 | 375 |
340 OptionsWindowView::instance_ = new OptionsWindowView(profile); | 376 OptionsWindowView::instance_ = new OptionsWindowView(profile); |
341 views::Window::CreateChromeWindow(chromeos::GetOptionsViewParent(), | 377 views::Window::CreateChromeWindow(chromeos::GetOptionsViewParent(), |
342 gfx::Rect(), | 378 gfx::Rect(), |
343 OptionsWindowView::instance_); | 379 OptionsWindowView::instance_); |
344 | 380 |
345 OptionsWindowView::instance_->ShowOptionsPage(page, highlight_group); | 381 OptionsWindowView::instance_->ShowOptionsPage(page, highlight_group); |
346 } | 382 } |
347 | |
OLD | NEW |