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

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

Issue 2856883002: Revert of Description: Replace layout constants in chrome/browser/extensions and (...) (Closed)
Patch Set: 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "chrome/browser/ui/views/extensions/request_file_system_dialog_view.h"
6
7 #include <stddef.h>
8
9 #include <cstdlib>
10
11 #include "base/strings/utf_string_conversions.h"
12 #include "base/threading/thread_task_runner_handle.h"
13 #include "chrome/browser/ui/views/harmony/chrome_layout_provider.h"
14 #include "chrome/grit/generated_resources.h"
15 #include "components/constrained_window/constrained_window_views.h"
16 #include "content/public/browser/web_contents.h"
17 #include "ui/base/l10n/l10n_util.h"
18 #include "ui/gfx/font.h"
19 #include "ui/gfx/range/range.h"
20 #include "ui/views/controls/styled_label.h"
21 #include "ui/views/layout/fill_layout.h"
22
23 namespace {
24
25 // Maximum width of the dialog in pixels.
26 const int kDialogMaxWidth = 320;
27
28 } // namespace
29
30 // static
31 void RequestFileSystemDialogView::ShowDialog(
32 content::WebContents* web_contents,
33 const std::string& extension_name,
34 const std::string& volume_label,
35 bool writable,
36 const base::Callback<void(ui::DialogButton)>& callback) {
37 constrained_window::ShowWebModalDialogViews(
38 new RequestFileSystemDialogView(extension_name, volume_label, writable,
39 callback),
40 web_contents);
41 }
42
43 RequestFileSystemDialogView::~RequestFileSystemDialogView() {}
44
45 base::string16 RequestFileSystemDialogView::GetAccessibleWindowTitle() const {
46 return l10n_util::GetStringUTF16(
47 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_TITLE);
48 }
49
50 int RequestFileSystemDialogView::GetDefaultDialogButton() const {
51 return ui::DIALOG_BUTTON_CANCEL;
52 }
53
54 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel(
55 ui::DialogButton button) const {
56 switch (button) {
57 case ui::DIALOG_BUTTON_OK:
58 return l10n_util::GetStringUTF16(
59 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON);
60 case ui::DIALOG_BUTTON_CANCEL:
61 return l10n_util::GetStringUTF16(
62 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON);
63 default:
64 NOTREACHED();
65 }
66 return base::string16();
67 }
68
69 ui::ModalType RequestFileSystemDialogView::GetModalType() const {
70 return ui::MODAL_TYPE_CHILD;
71 }
72
73 bool RequestFileSystemDialogView::Cancel() {
74 callback_.Run(ui::DIALOG_BUTTON_CANCEL);
75 return true;
76 }
77
78 bool RequestFileSystemDialogView::Accept() {
79 callback_.Run(ui::DIALOG_BUTTON_OK);
80 return true;
81 }
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
92 RequestFileSystemDialogView::RequestFileSystemDialogView(
93 const std::string& extension_name,
94 const std::string& volume_label,
95 bool writable,
96 const base::Callback<void(ui::DialogButton)>& callback)
97 : callback_(callback), contents_view_(new views::View) {
98 DCHECK(!callback_.is_null());
99
100 const base::string16 app_name = base::UTF8ToUTF16(extension_name);
101 // TODO(mtomasz): Improve the dialog contents, so it's easier for the user
102 // to understand what device is being requested.
103 const base::string16 volume_name = base::UTF8ToUTF16(volume_label);
104
105 std::vector<size_t> placeholder_offsets;
106 const base::string16 message = l10n_util::GetStringFUTF16(
107 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE
108 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE,
109 app_name, volume_name, &placeholder_offsets);
110
111 views::StyledLabel* const label = new views::StyledLabel(message, nullptr);
112 views::StyledLabel::RangeStyleInfo bold_style;
113 bold_style.weight = gfx::Font::Weight::BOLD;
114
115 DCHECK_EQ(2u, placeholder_offsets.size());
116 label->AddStyleRange(gfx::Range(placeholder_offsets[0],
117 placeholder_offsets[0] + app_name.length()),
118 bold_style);
119 label->AddStyleRange(
120 gfx::Range(placeholder_offsets[1],
121 placeholder_offsets[1] + volume_name.length()),
122 bold_style);
123
124 SetLayoutManager(new views::FillLayout());
125
126 AddChildView(label);
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