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

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: Address review comments 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 std::string& extension_name,
34 base::WeakPtr<file_manager::Volume> volume, 34 const std::string& volume_label,
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_name, volume_label, writable,
39 callback),
39 web_contents); 40 web_contents);
40 } 41 }
41 42
42 RequestFileSystemDialogView::~RequestFileSystemDialogView() { 43 RequestFileSystemDialogView::~RequestFileSystemDialogView() {}
43 }
44 44
45 base::string16 RequestFileSystemDialogView::GetAccessibleWindowTitle() const { 45 base::string16 RequestFileSystemDialogView::GetAccessibleWindowTitle() const {
46 return l10n_util::GetStringUTF16( 46 return l10n_util::GetStringUTF16(
47 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_TITLE); 47 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_TITLE);
48 } 48 }
49 49
50 int RequestFileSystemDialogView::GetDefaultDialogButton() const { 50 int RequestFileSystemDialogView::GetDefaultDialogButton() const {
51 return ui::DIALOG_BUTTON_CANCEL; 51 return ui::DIALOG_BUTTON_CANCEL;
52 } 52 }
53 53
54 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel( 54 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel(
55 ui::DialogButton button) const { 55 ui::DialogButton button) const {
56 switch (button) { 56 switch (button) {
57 case ui::DIALOG_BUTTON_OK: 57 case ui::DIALOG_BUTTON_OK:
58 return l10n_util::GetStringUTF16( 58 return l10n_util::GetStringUTF16(
59 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON); 59 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON);
60 case ui::DIALOG_BUTTON_CANCEL: 60 case ui::DIALOG_BUTTON_CANCEL:
61 return l10n_util::GetStringUTF16( 61 return l10n_util::GetStringUTF16(
62 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON); 62 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON);
63 default: 63 default:
64 NOTREACHED(); 64 NOTREACHED();
65 } 65 }
66 return base::string16(); 66 return base::string16();
67 } 67 }
68 68
69 ui::ModalType RequestFileSystemDialogView::GetModalType() const { 69 ui::ModalType RequestFileSystemDialogView::GetModalType() const {
70 return ui::MODAL_TYPE_CHILD; 70 return ui::MODAL_TYPE_CHILD;
71 } 71 }
72 72
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() { 73 bool RequestFileSystemDialogView::Cancel() {
86 callback_.Run(ui::DIALOG_BUTTON_CANCEL); 74 callback_.Run(ui::DIALOG_BUTTON_CANCEL);
87 return true; 75 return true;
88 } 76 }
89 77
90 bool RequestFileSystemDialogView::Accept() { 78 bool RequestFileSystemDialogView::Accept() {
91 callback_.Run(ui::DIALOG_BUTTON_OK); 79 callback_.Run(ui::DIALOG_BUTTON_OK);
92 return true; 80 return true;
93 } 81 }
94 82
83 gfx::Size RequestFileSystemDialogView::GetPreferredSize() const {
84 return gfx::Size(kDialogMaxWidth,
85 child_at(0)->GetHeightForWidth(kDialogMaxWidth));
86 }
87
88 gfx::Insets RequestFileSystemDialogView::GetInsets() const {
89 return ChromeLayoutProvider::Get()->GetInsetsMetric(views::INSETS_PANEL);
90 }
91
95 RequestFileSystemDialogView::RequestFileSystemDialogView( 92 RequestFileSystemDialogView::RequestFileSystemDialogView(
96 const extensions::Extension& extension, 93 const std::string& extension_name,
97 base::WeakPtr<file_manager::Volume> volume, 94 const std::string& volume_label,
98 bool writable, 95 bool writable,
99 const base::Callback<void(ui::DialogButton)>& callback) 96 const base::Callback<void(ui::DialogButton)>& callback)
100 : callback_(callback), contents_view_(new views::View) { 97 : callback_(callback), contents_view_(new views::View) {
101 DCHECK(!callback_.is_null()); 98 DCHECK(!callback_.is_null());
102 99
103 // If the volume is gone, then cancel the dialog. 100 const base::string16 app_name = base::UTF8ToUTF16(extension_name);
104 if (!volume.get()) {
105 base::ThreadTaskRunnerHandle::Get()->PostTask(
106 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_CANCEL));
107 return;
108 }
109
110 const base::string16 app_name = base::UTF8ToUTF16(extension.name());
111 // TODO(mtomasz): Improve the dialog contents, so it's easier for the user 101 // TODO(mtomasz): Improve the dialog contents, so it's easier for the user
112 // to understand what device is being requested. 102 // to understand what device is being requested.
113 const base::string16 volume_name = 103 const base::string16 volume_name = base::UTF8ToUTF16(volume_label);
114 base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() 104
115 : volume->volume_id());
116 std::vector<size_t> placeholder_offsets; 105 std::vector<size_t> placeholder_offsets;
117 const base::string16 message = l10n_util::GetStringFUTF16( 106 const base::string16 message = l10n_util::GetStringFUTF16(
118 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE 107 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE
119 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE, 108 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE,
120 app_name, volume_name, &placeholder_offsets); 109 app_name, volume_name, &placeholder_offsets);
121 110
122 views::StyledLabel* const label = new views::StyledLabel(message, nullptr); 111 views::StyledLabel* const label = new views::StyledLabel(message, nullptr);
123 views::StyledLabel::RangeStyleInfo bold_style; 112 views::StyledLabel::RangeStyleInfo bold_style;
124 bold_style.weight = gfx::Font::Weight::BOLD; 113 bold_style.weight = gfx::Font::Weight::BOLD;
125 114
126 DCHECK_EQ(2u, placeholder_offsets.size()); 115 DCHECK_EQ(2u, placeholder_offsets.size());
127 label->AddStyleRange(gfx::Range(placeholder_offsets[0], 116 label->AddStyleRange(gfx::Range(placeholder_offsets[0],
128 placeholder_offsets[0] + app_name.length()), 117 placeholder_offsets[0] + app_name.length()),
129 bold_style); 118 bold_style);
130 label->AddStyleRange( 119 label->AddStyleRange(
131 gfx::Range(placeholder_offsets[1], 120 gfx::Range(placeholder_offsets[1],
132 placeholder_offsets[1] + volume_name.length()), 121 placeholder_offsets[1] + volume_name.length()),
133 bold_style); 122 bold_style);
134 123
135 views::BoxLayout* const layout = new views::BoxLayout( 124 SetLayoutManager(new views::FillLayout());
136 views::BoxLayout::kHorizontal, views::kButtonHEdgeMarginNew,
137 views::kPanelVertMargin, 0);
138 contents_view_->SetLayoutManager(layout);
139 125
140 label->SizeToFit(kDialogMaxWidth - 2 * views::kButtonHEdgeMarginNew); 126 AddChildView(label);
141 contents_view_->AddChildView(label);
142 } 127 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/extensions/request_file_system_dialog_view.h ('k') | chrome/browser/ui/views/try_chrome_dialog_view.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698