OLD | NEW |
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/extensions/api/file_system/request_file_system_dialog_v
iew.h" |
6 | 6 |
7 #include <cstdlib> | 7 #include <cstdlib> |
8 | 8 |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "base/thread_task_runner_handle.h" | 10 #include "base/thread_task_runner_handle.h" |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 int RequestFileSystemDialogView::GetDefaultDialogButton() const { | 48 int RequestFileSystemDialogView::GetDefaultDialogButton() const { |
49 return ui::DIALOG_BUTTON_CANCEL; | 49 return ui::DIALOG_BUTTON_CANCEL; |
50 } | 50 } |
51 | 51 |
52 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel( | 52 base::string16 RequestFileSystemDialogView::GetDialogButtonLabel( |
53 ui::DialogButton button) const { | 53 ui::DialogButton button) const { |
54 switch (button) { | 54 switch (button) { |
55 case ui::DIALOG_BUTTON_OK: | 55 case ui::DIALOG_BUTTON_OK: |
56 return l10n_util::GetStringUTF16( | 56 return l10n_util::GetStringUTF16( |
57 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_YES_BUTTON); | 57 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_ALLOW_BUTTON); |
58 case ui::DIALOG_BUTTON_CANCEL: | 58 case ui::DIALOG_BUTTON_CANCEL: |
59 return l10n_util::GetStringUTF16( | 59 return l10n_util::GetStringUTF16( |
60 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_NO_BUTTON); | 60 IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_DENY_BUTTON); |
61 default: | 61 default: |
62 NOTREACHED(); | 62 NOTREACHED(); |
63 } | 63 } |
64 return base::string16(); | 64 return base::string16(); |
65 } | 65 } |
66 | 66 |
67 ui::ModalType RequestFileSystemDialogView::GetModalType() const { | 67 ui::ModalType RequestFileSystemDialogView::GetModalType() const { |
68 return ui::MODAL_TYPE_CHILD; | 68 return ui::MODAL_TYPE_CHILD; |
69 } | 69 } |
70 | 70 |
(...skipping 27 matching lines...) Expand all Loading... |
98 : callback_(callback), contents_view_(new views::View) { | 98 : callback_(callback), contents_view_(new views::View) { |
99 DCHECK(!callback_.is_null()); | 99 DCHECK(!callback_.is_null()); |
100 | 100 |
101 // If the volume is gone, then cancel the dialog. | 101 // If the volume is gone, then cancel the dialog. |
102 if (!volume.get()) { | 102 if (!volume.get()) { |
103 base::ThreadTaskRunnerHandle::Get()->PostTask( | 103 base::ThreadTaskRunnerHandle::Get()->PostTask( |
104 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_CANCEL)); | 104 FROM_HERE, base::Bind(callback, ui::DIALOG_BUTTON_CANCEL)); |
105 return; | 105 return; |
106 } | 106 } |
107 | 107 |
| 108 const base::string16 app_name = base::UTF8ToUTF16(extension.name()); |
108 // TODO(mtomasz): Improve the dialog contents, so it's easier for the user | 109 // TODO(mtomasz): Improve the dialog contents, so it's easier for the user |
109 // to understand what device is being requested. | 110 // to understand what device is being requested. |
110 const base::string16 display_name = | 111 const base::string16 volume_name = |
111 base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() | 112 base::UTF8ToUTF16(!volume->volume_label().empty() ? volume->volume_label() |
112 : volume->volume_id()); | 113 : volume->volume_id()); |
| 114 std::vector<size_t> placeholder_offsets; |
113 const base::string16 message = l10n_util::GetStringFUTF16( | 115 const base::string16 message = l10n_util::GetStringFUTF16( |
114 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE | 116 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE |
115 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE, | 117 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE, |
116 display_name); | 118 app_name, volume_name, &placeholder_offsets); |
117 | |
118 // Find location of the placeholder by comparing message and message_host | |
119 // strings in order to apply the bold style on the display name. | |
120 const base::string16 message_host = l10n_util::GetStringFUTF16( | |
121 writable ? IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_WRITABLE_MESSAGE | |
122 : IDS_FILE_SYSTEM_REQUEST_FILE_SYSTEM_DIALOG_MESSAGE, | |
123 base::string16()); | |
124 | |
125 size_t placeholder_start = 0; | |
126 while (placeholder_start < message.size() && | |
127 message[placeholder_start] == message_host[placeholder_start]) { | |
128 ++placeholder_start; | |
129 } | |
130 | 119 |
131 views::StyledLabel* const label = new views::StyledLabel(message, nullptr); | 120 views::StyledLabel* const label = new views::StyledLabel(message, nullptr); |
132 views::StyledLabel::RangeStyleInfo bold_style; | 121 views::StyledLabel::RangeStyleInfo bold_style; |
133 bold_style.font_style = gfx::Font::BOLD; | 122 bold_style.font_style = gfx::Font::BOLD; |
134 | 123 |
| 124 DCHECK_EQ(2u, placeholder_offsets.size()); |
| 125 label->AddStyleRange(gfx::Range(placeholder_offsets[0], |
| 126 placeholder_offsets[0] + app_name.length()), |
| 127 bold_style); |
135 label->AddStyleRange( | 128 label->AddStyleRange( |
136 gfx::Range(placeholder_start, placeholder_start + display_name.size()), | 129 gfx::Range(placeholder_offsets[1], |
| 130 placeholder_offsets[1] + volume_name.length()), |
137 bold_style); | 131 bold_style); |
138 | 132 |
139 views::BoxLayout* const layout = new views::BoxLayout( | 133 views::BoxLayout* const layout = new views::BoxLayout( |
140 views::BoxLayout::kHorizontal, views::kButtonHEdgeMarginNew, | 134 views::BoxLayout::kHorizontal, views::kButtonHEdgeMarginNew, |
141 views::kPanelVertMargin, 0); | 135 views::kPanelVertMargin, 0); |
142 contents_view_->SetLayoutManager(layout); | 136 contents_view_->SetLayoutManager(layout); |
143 | 137 |
144 label->SizeToFit(kDialogMaxWidth - 2 * views::kButtonHEdgeMarginNew); | 138 label->SizeToFit(kDialogMaxWidth - 2 * views::kButtonHEdgeMarginNew); |
145 contents_view_->AddChildView(label); | 139 contents_view_->AddChildView(label); |
146 } | 140 } |
OLD | NEW |