| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/tab_modal_confirm_dialog_views.h" | 5 #include "chrome/browser/ui/views/tab_modal_confirm_dialog_views.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" |
| 7 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
| 8 #include "chrome/browser/ui/browser_dialogs.h" | 9 #include "chrome/browser/ui/browser_dialogs.h" |
| 9 #include "chrome/browser/ui/browser_list.h" | 10 #include "chrome/browser/ui/browser_list.h" |
| 10 #include "chrome/browser/ui/browser_window.h" | 11 #include "chrome/browser/ui/browser_window.h" |
| 11 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 12 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 12 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" | 13 #include "chrome/browser/ui/tab_modal_confirm_dialog_delegate.h" |
| 13 #include "chrome/browser/ui/views/constrained_window_views.h" | 14 #include "chrome/browser/ui/views/constrained_window_views.h" |
| 15 #include "chrome/common/chrome_switches.h" |
| 14 #include "grit/generated_resources.h" | 16 #include "grit/generated_resources.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 17 #include "ui/base/l10n/l10n_util.h" |
| 16 #include "ui/views/controls/message_box_view.h" | 18 #include "ui/views/controls/message_box_view.h" |
| 19 #include "ui/views/window/dialog_client_view.h" |
| 17 | 20 |
| 18 // static | 21 // static |
| 19 TabModalConfirmDialog* TabModalConfirmDialog::Create( | 22 TabModalConfirmDialog* TabModalConfirmDialog::Create( |
| 20 TabModalConfirmDialogDelegate* delegate, | 23 TabModalConfirmDialogDelegate* delegate, |
| 21 TabContents* tab_contents) { | 24 TabContents* tab_contents) { |
| 22 return new TabModalConfirmDialogViews(delegate, tab_contents); | 25 return new TabModalConfirmDialogViews(delegate, tab_contents); |
| 23 } | 26 } |
| 24 | 27 |
| 28 namespace { |
| 29 const int kChromeStyleUniformInset = 0; |
| 30 const int kChromeStyleInterRowVerticalSpacing = 20; |
| 31 |
| 32 const int kChromeStyleButtonVEdgeMargin = 0; |
| 33 const int kChromeStyleButtonHEdgeMargin = 0; |
| 34 const int kChromeStyleDialogButtonLabelSpacing = 24; |
| 35 |
| 36 views::MessageBoxView::InitParams CreateMessageBoxViewInitParams( |
| 37 const string16& message) |
| 38 { |
| 39 views::MessageBoxView::InitParams params(message); |
| 40 |
| 41 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 42 if (command_line->HasSwitch(switches::kEnableFramelessConstrainedDialogs)) { |
| 43 params.top_inset = kChromeStyleUniformInset; |
| 44 params.bottom_inset = kChromeStyleUniformInset; |
| 45 params.left_inset = kChromeStyleUniformInset; |
| 46 params.right_inset = kChromeStyleUniformInset; |
| 47 |
| 48 params.inter_row_vertical_spacing = kChromeStyleInterRowVerticalSpacing; |
| 49 } |
| 50 |
| 51 return params; |
| 52 } |
| 53 } // namespace |
| 54 |
| 25 ////////////////////////////////////////////////////////////////////////////// | 55 ////////////////////////////////////////////////////////////////////////////// |
| 26 // TabModalConfirmDialogViews, constructor & destructor: | 56 // TabModalConfirmDialogViews, constructor & destructor: |
| 27 | 57 |
| 28 TabModalConfirmDialogViews::TabModalConfirmDialogViews( | 58 TabModalConfirmDialogViews::TabModalConfirmDialogViews( |
| 29 TabModalConfirmDialogDelegate* delegate, | 59 TabModalConfirmDialogDelegate* delegate, |
| 30 TabContents* tab_contents) | 60 TabContents* tab_contents) |
| 31 : delegate_(delegate), | 61 : delegate_(delegate), |
| 32 message_box_view_(new views::MessageBoxView( | 62 message_box_view_(new views::MessageBoxView( |
| 33 views::MessageBoxView::InitParams(delegate->GetMessage()))) { | 63 CreateMessageBoxViewInitParams(delegate->GetMessage()))) { |
| 34 delegate_->set_window(new ConstrainedWindowViews(tab_contents->web_contents(), | 64 delegate_->set_window(new ConstrainedWindowViews(tab_contents->web_contents(), |
| 35 this)); | 65 this)); |
| 36 } | 66 } |
| 37 | 67 |
| 38 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { | 68 TabModalConfirmDialogViews::~TabModalConfirmDialogViews() { |
| 39 } | 69 } |
| 40 | 70 |
| 41 void TabModalConfirmDialogViews::AcceptTabModalDialog() { | 71 void TabModalConfirmDialogViews::AcceptTabModalDialog() { |
| 42 GetDialogClientView()->AcceptWindow(); | 72 GetDialogClientView()->AcceptWindow(); |
| 43 } | 73 } |
| (...skipping 21 matching lines...) Expand all Loading... |
| 65 bool TabModalConfirmDialogViews::Cancel() { | 95 bool TabModalConfirmDialogViews::Cancel() { |
| 66 delegate_->Cancel(); | 96 delegate_->Cancel(); |
| 67 return true; | 97 return true; |
| 68 } | 98 } |
| 69 | 99 |
| 70 bool TabModalConfirmDialogViews::Accept() { | 100 bool TabModalConfirmDialogViews::Accept() { |
| 71 delegate_->Accept(); | 101 delegate_->Accept(); |
| 72 return true; | 102 return true; |
| 73 } | 103 } |
| 74 | 104 |
| 105 views::ClientView* TabModalConfirmDialogViews::CreateClientView( |
| 106 views::Widget* widget) { |
| 107 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 108 if (command_line->HasSwitch(switches::kEnableFramelessConstrainedDialogs)) { |
| 109 views::DialogClientView::StyleParams params; |
| 110 params.button_vedge_margin = kChromeStyleButtonVEdgeMargin; |
| 111 params.button_hedge_margin = kChromeStyleButtonHEdgeMargin; |
| 112 params.button_label_spacing = kChromeStyleDialogButtonLabelSpacing; |
| 113 params.text_button_factory = |
| 114 &views::DialogClientView::CreateChromeStyleDialogButton; |
| 115 |
| 116 return new views::DialogClientView(widget, GetContentsView(), params); |
| 117 } |
| 118 |
| 119 return DialogDelegate::CreateClientView(widget); |
| 120 } |
| 121 |
| 75 /////////////////////////////////////////////////////////////////////////////// | 122 /////////////////////////////////////////////////////////////////////////////// |
| 76 // TabModalConfirmDialogViews, views::WidgetDelegate implementation: | 123 // TabModalConfirmDialogViews, views::WidgetDelegate implementation: |
| 77 | 124 |
| 78 views::View* TabModalConfirmDialogViews::GetContentsView() { | 125 views::View* TabModalConfirmDialogViews::GetContentsView() { |
| 79 return message_box_view_; | 126 return message_box_view_; |
| 80 } | 127 } |
| 81 | 128 |
| 82 views::Widget* TabModalConfirmDialogViews::GetWidget() { | 129 views::Widget* TabModalConfirmDialogViews::GetWidget() { |
| 83 return message_box_view_->GetWidget(); | 130 return message_box_view_->GetWidget(); |
| 84 } | 131 } |
| 85 | 132 |
| 86 const views::Widget* TabModalConfirmDialogViews::GetWidget() const { | 133 const views::Widget* TabModalConfirmDialogViews::GetWidget() const { |
| 87 return message_box_view_->GetWidget(); | 134 return message_box_view_->GetWidget(); |
| 88 } | 135 } |
| 89 | 136 |
| 90 void TabModalConfirmDialogViews::DeleteDelegate() { | 137 void TabModalConfirmDialogViews::DeleteDelegate() { |
| 91 delete this; | 138 delete this; |
| 92 } | 139 } |
| OLD | NEW |