OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/options/passwords_exceptions_window_view.h" | |
6 | |
7 #include "base/utf_string_conversions.h" | |
8 #include "chrome/browser/ui/views/options/exceptions_page_view.h" | |
9 #include "chrome/browser/ui/views/options/passwords_page_view.h" | |
10 #include "grit/generated_resources.h" | |
11 #include "grit/locale_settings.h" | |
12 #include "ui/base/l10n/l10n_util.h" | |
13 #include "views/controls/tabbed_pane/tabbed_pane.h" | |
14 #include "views/window/window.h" | |
15 | |
16 // static | |
17 PasswordsExceptionsWindowView* PasswordsExceptionsWindowView::instance_ = NULL; | |
18 | |
19 static const int kDialogPadding = 7; | |
20 | |
21 namespace browser { | |
22 | |
23 // Declared in browser_dialogs.h so others don't have to depend on our header. | |
24 void ShowPasswordsExceptionsWindowView(Profile* profile) { | |
25 PasswordsExceptionsWindowView::Show(profile); | |
26 } | |
27 | |
28 } // namespace browser | |
29 | |
30 /////////////////////////////////////////////////////////////////////////////// | |
31 // PasswordsExceptionsWindowView, public | |
32 | |
33 PasswordsExceptionsWindowView::PasswordsExceptionsWindowView(Profile* profile) | |
34 : tabs_(NULL), | |
35 passwords_page_view_(NULL), | |
36 exceptions_page_view_(NULL), | |
37 profile_(profile) { | |
38 } | |
39 | |
40 // static | |
41 void PasswordsExceptionsWindowView::Show(Profile* profile) { | |
42 DCHECK(profile); | |
43 if (!instance_) { | |
44 instance_ = new PasswordsExceptionsWindowView(profile); | |
45 | |
46 // |instance_| will get deleted once Close() is called. | |
47 views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); | |
48 } | |
49 if (!instance_->window()->IsVisible()) { | |
50 instance_->window()->Show(); | |
51 } else { | |
52 instance_->window()->Activate(); | |
53 } | |
54 } | |
55 | |
56 ///////////////////////////////////////////////////////////////////////////// | |
57 // PasswordsExceptionsWindowView, views::View implementations | |
58 | |
59 void PasswordsExceptionsWindowView::Layout() { | |
60 tabs_->SetBounds(kDialogPadding, kDialogPadding, | |
61 width() - (2 * kDialogPadding), | |
62 height() - (2 * kDialogPadding)); | |
63 } | |
64 | |
65 gfx::Size PasswordsExceptionsWindowView::GetPreferredSize() { | |
66 return gfx::Size(views::Window::GetLocalizedContentsSize( | |
67 IDS_PASSWORDS_DIALOG_WIDTH_CHARS, | |
68 IDS_PASSWORDS_DIALOG_HEIGHT_LINES)); | |
69 } | |
70 | |
71 void PasswordsExceptionsWindowView::ViewHierarchyChanged( | |
72 bool is_add, views::View* parent, views::View* child) { | |
73 if (is_add && child == this) | |
74 Init(); | |
75 } | |
76 | |
77 ///////////////////////////////////////////////////////////////////////////// | |
78 // PasswordsExceptionsWindowView, views::DisloagDelegate implementations | |
79 | |
80 int PasswordsExceptionsWindowView::GetDialogButtons() const { | |
81 return MessageBoxFlags::DIALOGBUTTON_CANCEL; | |
82 } | |
83 | |
84 std::wstring PasswordsExceptionsWindowView::GetWindowTitle() const { | |
85 return UTF16ToWide( | |
86 l10n_util::GetStringUTF16(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE)); | |
87 } | |
88 | |
89 void PasswordsExceptionsWindowView::WindowClosing() { | |
90 // |instance_| is deleted once the window is closed, so we just have to set | |
91 // it to NULL. | |
92 instance_ = NULL; | |
93 } | |
94 | |
95 views::View* PasswordsExceptionsWindowView::GetContentsView() { | |
96 return this; | |
97 } | |
98 | |
99 ///////////////////////////////////////////////////////////////////////////// | |
100 // PasswordsExceptionsWindowView, private | |
101 | |
102 void PasswordsExceptionsWindowView::Init() { | |
103 tabs_ = new views::TabbedPane(); | |
104 AddChildView(tabs_); | |
105 | |
106 passwords_page_view_ = new PasswordsPageView(profile_); | |
107 tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( | |
108 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE)), passwords_page_view_); | |
109 | |
110 exceptions_page_view_ = new ExceptionsPageView(profile_); | |
111 tabs_->AddTab(UTF16ToWide(l10n_util::GetStringUTF16( | |
112 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE)), exceptions_page_view_); | |
113 } | |
OLD | NEW |