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

Side by Side Diff: chrome/browser/ui/views/extensions/request_file_system_dialog_view.cc

Issue 2816293002: Description: Replace layout constants in chrome/browser/extensions and chrome/browser/first_run (Closed)
Patch Set: Fix dumb error Created 3 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/extensions/api/file_system/request_file_system_dialog_v iew.h" 5 #include "chrome/browser/ui/views/extensions/request_file_system_dialog_view.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <cstdlib> 9 #include <cstdlib>
10 10
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h" 12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
13 #include "chrome/grit/generated_resources.h" 14 #include "chrome/grit/generated_resources.h"
14 #include "components/constrained_window/constrained_window_views.h" 15 #include "components/constrained_window/constrained_window_views.h"
15 #include "content/public/browser/web_contents.h" 16 #include "content/public/browser/web_contents.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/gfx/font.h" 18 #include "ui/gfx/font.h"
18 #include "ui/gfx/range/range.h" 19 #include "ui/gfx/range/range.h"
19 #include "ui/views/controls/styled_label.h" 20 #include "ui/views/controls/styled_label.h"
20 #include "ui/views/layout/box_layout.h" 21 #include "ui/views/layout/fill_layout.h"
21 #include "ui/views/layout/layout_constants.h"
22 22
23 namespace { 23 namespace {
24 24
25 // Maximum width of the dialog in pixels. 25 // Maximum width of the dialog in pixels.
26 const int kDialogMaxWidth = 320; 26 const int kDialogMaxWidth = 320;
27 27
28 } // namespace 28 } // namespace
29 29
30 // static 30 // static
31 void RequestFileSystemDialogView::ShowDialog( 31 void RequestFileSystemDialogView::ShowDialog(
32 content::WebContents* web_contents, 32 content::WebContents* web_contents,
33 const extensions::Extension& extension, 33 const extensions::Extension& extension,
34 base::WeakPtr<file_manager::Volume> volume, 34 base::WeakPtr<file_manager::Volume> volume,
35 bool writable, 35 bool writable,
36 const base::Callback<void(ui::DialogButton)>& callback) { 36 const base::Callback<void(ui::DialogButton)>& callback) {
37 constrained_window::ShowWebModalDialogViews( 37 constrained_window::ShowWebModalDialogViews(
38 new RequestFileSystemDialogView(extension, volume, writable, callback), 38 new RequestFileSystemDialogView(extension, volume, writable, callback),
39 web_contents); 39 web_contents);
40 } 40 }
41 41
42 RequestFileSystemDialogView::~RequestFileSystemDialogView() { 42 RequestFileSystemDialogView::~RequestFileSystemDialogView() {}
43 }
44 43
45 base::string16 RequestFileSystemDialogView::GetAccessibleWindowTitle() const { 44 base::string16 RequestFileSystemDialogView::GetAccessibleWindowTitle() const {
46 return l10n_util::GetStringUTF16( 45 return l10n_util::GetStringUTF16(
47 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_TITLE); 46 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_TITLE);
48 } 47 }
49 48
50 int RequestFileSystemDialogView::GetDefaultDialogButton() const { 49 int RequestFileSystemDialogView::GetDefaultDialogButton() const {
51 return ui::DIALOG_BUTTON_CANCEL; 50 return ui::DIALOG_BUTTON_CANCEL;
52 } 51 }
53 52
54 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel( 53 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel(
55 ui::DialogButton button) const { 54 ui::DialogButton button) const {
56 switch (button) { 55 switch (button) {
57 case ui::DIALOG_BUTTON_OK: 56 case ui::DIALOG_BUTTON_OK:
58 return l10n_util::GetStringUTF16( 57 return l10n_util::GetStringUTF16(
59 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON); 58 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON);
60 case ui::DIALOG_BUTTON_CANCEL: 59 case ui::DIALOG_BUTTON_CANCEL:
61 return l10n_util::GetStringUTF16( 60 return l10n_util::GetStringUTF16(
62 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON); 61 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON);
63 default: 62 default:
64 NOTREACHED(); 63 NOTREACHED();
65 } 64 }
66 return base::string16(); 65 return base::string16();
67 } 66 }
68 67
69 ui::ModalType RequestFileSystemDialogView::GetModalType() const { 68 ui::ModalType RequestFileSystemDialogView::GetModalType() const {
70 return ui::MODAL_TYPE_CHILD; 69 return ui::MODAL_TYPE_CHILD;
71 } 70 }
72 71
73 views::View* RequestFileSystemDialogView::GetContentsView() {
74 return contents_view_;
75 }
76
77 views::Widget* RequestFileSystemDialogView::GetWidget() {
78 return contents_view_->GetWidget();
79 }
80
81 const views::Widget* RequestFileSystemDialogView::GetWidget() const {
82 return contents_view_->GetWidget();
83 }
84
85 bool RequestFileSystemDialogView::Cancel() { 72 bool RequestFileSystemDialogView::Cancel() {
86 callback_.Run(ui::DIALOG_BUTTON_CANCEL); 73 callback_.Run(ui::DIALOG_BUTTON_CANCEL);
87 return true; 74 return true;
88 } 75 }
89 76
90 bool RequestFileSystemDialogView::Accept() { 77 bool RequestFileSystemDialogView::Accept() {
91 callback_.Run(ui::DIALOG_BUTTON_OK); 78 callback_.Run(ui::DIALOG_BUTTON_OK);
92 return true; 79 return true;
93 } 80 }
94 81
82 gfx::Size RequestFileSystemDialogView::GetPreferredSize() const {
83 return gfx::Size(kDialogMaxWidth,
84 child_at(0)->GetHeightForWidth(kDialogMaxWidth));
85 }
86
87 gfx::Insets RequestFileSystemDialogView::GetInsets() const {
88 return ChromeLayoutProvider::Get()->GetInsetsMetric(views::INSETS_PANEL);
89 }
90
95 RequestFileSystemDialogView::RequestFileSystemDialogView( 91 RequestFileSystemDialogView::RequestFileSystemDialogView(
96 const extensions::Extension& extension, 92 const extensions::Extension& extension,
97 base::WeakPtr<file_manager::Volume> volume, 93 base::WeakPtr<file_manager::Volume> volume,
98 bool writable, 94 bool writable,
99 const base::Callback<void(ui::DialogButton)>& callback) 95 const base::Callback<void(ui::DialogButton)>& callback)
100 : callback_(callback), contents_view_(new views::View) { 96 : callback_(callback), contents_view_(new views::View) {
101 DCHECK(!callback_.is_null()); 97 DCHECK(!callback_.is_null());
102 98
103 // If the volume is gone, then cancel the dialog. 99 // If the volume is gone, then cancel the dialog.
104 if (!volume.get()) { 100 if (!volume.get()) {
(...skipping 20 matching lines...) Expand all
125 121
126 DCHECK_EQ(2u, placeholder_offsets.size()); 122 DCHECK_EQ(2u, placeholder_offsets.size());
127 label->AddStyleRange(gfx::Range(placeholder_offsets[0], 123 label->AddStyleRange(gfx::Range(placeholder_offsets[0],
128 placeholder_offsets[0] + app_name.length()), 124 placeholder_offsets[0] + app_name.length()),
129 bold_style); 125 bold_style);
130 label->AddStyleRange( 126 label->AddStyleRange(
131 gfx::Range(placeholder_offsets[1], 127 gfx::Range(placeholder_offsets[1],
132 placeholder_offsets[1] + volume_name.length()), 128 placeholder_offsets[1] + volume_name.length()),
133 bold_style); 129 bold_style);
134 130
135 views::BoxLayout* const layout = new views::BoxLayout( 131 views::FillLayout* const layout = new views::FillLayout();
Peter Kasting 2017/04/26 18:26:25 Nit: Or just inline into next line.
ananta 2017/04/26 19:42:20 Done.
136 views::BoxLayout::kHorizontal, views::kButtonHEdgeMarginNew, 132 SetLayoutManager(layout);
137 views::kPanelVertMargin, 0);
138 contents_view_->SetLayoutManager(layout);
139 133
140 label->SizeToFit(kDialogMaxWidth - 2 * views::kButtonHEdgeMarginNew); 134 AddChildView(label);
141 contents_view_->AddChildView(label);
142 } 135 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698