| OLD | NEW |
| (Empty) | |
| 1 // Copyright (c) 2009 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/views/options/passwords_exceptions_window_view.h" |
| 6 |
| 7 #include "chrome/browser/views/options/passwords_page_view.h" |
| 8 #include "chrome/browser/views/options/exceptions_page_view.h" |
| 9 #include "chrome/common/l10n_util.h" |
| 10 #include "grit/generated_resources.h" |
| 11 |
| 12 // static |
| 13 PasswordsExceptionsWindowView* PasswordsExceptionsWindowView::instance_ = NULL; |
| 14 |
| 15 static const int kDefaultWindowWidth = 530; |
| 16 static const int kDefaultWindowHeight = 240; |
| 17 static const int kDialogPadding = 7; |
| 18 |
| 19 /////////////////////////////////////////////////////////////////////////////// |
| 20 // PasswordsExceptionsWindowView, public |
| 21 |
| 22 PasswordsExceptionsWindowView::PasswordsExceptionsWindowView(Profile* profile) |
| 23 : tabs_(NULL), |
| 24 passwords_page_view_(NULL), |
| 25 exceptions_page_view_(NULL), |
| 26 profile_(profile) { |
| 27 } |
| 28 |
| 29 // static |
| 30 void PasswordsExceptionsWindowView::Show(Profile* profile) { |
| 31 DCHECK(profile); |
| 32 if (!instance_) { |
| 33 instance_ = new PasswordsExceptionsWindowView(profile); |
| 34 |
| 35 // instances_ will get deleted once Close() is called. |
| 36 views::Window::CreateChromeWindow(NULL, gfx::Rect(), instance_); |
| 37 } |
| 38 if (!instance_->window()->IsVisible()) { |
| 39 instance_->window()->Show(); |
| 40 } else { |
| 41 instance_->window()->Activate(); |
| 42 } |
| 43 } |
| 44 |
| 45 ///////////////////////////////////////////////////////////////////////////// |
| 46 // PasswordsExceptionsWindowView, views::View implementations |
| 47 |
| 48 void PasswordsExceptionsWindowView::Layout() { |
| 49 tabs_->SetBounds(kDialogPadding, kDialogPadding, |
| 50 width() - (2 * kDialogPadding), |
| 51 height() - (2 * kDialogPadding)); |
| 52 } |
| 53 |
| 54 gfx::Size PasswordsExceptionsWindowView::GetPreferredSize() { |
| 55 return gfx::Size(kDefaultWindowWidth, kDefaultWindowHeight); |
| 56 } |
| 57 |
| 58 void PasswordsExceptionsWindowView::ViewHierarchyChanged( |
| 59 bool is_add, views::View* parent, views::View* child) { |
| 60 if (is_add && child == this) |
| 61 Init(); |
| 62 } |
| 63 |
| 64 ///////////////////////////////////////////////////////////////////////////// |
| 65 // PasswordsExceptionsWindowView, views::DisloagDelegate implementations |
| 66 |
| 67 int PasswordsExceptionsWindowView::GetDialogButtons() const { |
| 68 return DIALOGBUTTON_CANCEL; |
| 69 } |
| 70 |
| 71 std::wstring PasswordsExceptionsWindowView::GetWindowTitle() const { |
| 72 return l10n_util::GetString(IDS_PASSWORDS_EXCEPTIONS_WINDOW_TITLE); |
| 73 } |
| 74 |
| 75 void PasswordsExceptionsWindowView::WindowClosing() { |
| 76 // |instnace_| is deleted once the window is closed, so we just have to set |
| 77 // it to NULL. |
| 78 instance_ = NULL; |
| 79 } |
| 80 |
| 81 views::View* PasswordsExceptionsWindowView::GetContentsView() { |
| 82 return this; |
| 83 } |
| 84 |
| 85 ///////////////////////////////////////////////////////////////////////////// |
| 86 // PasswordsExceptionsWindowView, private |
| 87 |
| 88 void PasswordsExceptionsWindowView::Init() { |
| 89 tabs_ = new views::TabbedPane(); |
| 90 AddChildView(tabs_); |
| 91 |
| 92 passwords_page_view_ = new PasswordsPageView(profile_); |
| 93 tabs_->AddTab(l10n_util::GetString( |
| 94 IDS_PASSWORDS_SHOW_PASSWORDS_TAB_TITLE), passwords_page_view_); |
| 95 |
| 96 exceptions_page_view_ = new ExceptionsPageView(profile_); |
| 97 tabs_->AddTab(l10n_util::GetString( |
| 98 IDS_PASSWORDS_EXCEPTIONS_TAB_TITLE), exceptions_page_view_); |
| 99 } |
| OLD | NEW |