File: folder_upload_confirmation_view.cc

package info (click to toggle)
chromium-browser 70.0.3538.110-1~deb9u1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,619,476 kB
  • sloc: cpp: 13,024,755; ansic: 1,349,823; python: 916,672; xml: 314,489; java: 280,047; asm: 276,936; perl: 75,771; objc: 66,634; sh: 45,860; cs: 28,354; php: 11,064; makefile: 10,911; yacc: 9,109; tcl: 8,403; ruby: 4,065; lex: 1,779; pascal: 1,411; lisp: 1,055; awk: 41; jsp: 39; sed: 17; sql: 3
file content (105 lines) | stat: -rw-r--r-- 4,125 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/ui/views/folder_upload_confirmation_view.h"

#include "base/files/file_path.h"
#include "base/numerics/safe_conversions.h"
#include "chrome/browser/file_select_helper.h"
#include "chrome/browser/ui/views/chrome_layout_provider.h"
#include "chrome/browser/ui/views/chrome_typography.h"
#include "chrome/grit/generated_resources.h"
#include "components/constrained_window/constrained_window_views.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/controls/button/label_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/window/dialog_client_view.h"

FolderUploadConfirmationView::FolderUploadConfirmationView(
    const base::FilePath& path,
    base::OnceCallback<void(const std::vector<ui::SelectedFileInfo>&)> callback,
    std::vector<ui::SelectedFileInfo> selected_files)
    : callback_(std::move(callback)),
      selected_files_(std::move(selected_files)) {
  SetLayoutManager(std::make_unique<views::FillLayout>());
  auto label = std::make_unique<views::Label>(
      l10n_util::GetStringFUTF16(IDS_CONFIRM_FILE_UPLOAD_TEXT,
                                 path.BaseName().LossyDisplayName()),
      CONTEXT_BODY_TEXT_LARGE, STYLE_SECONDARY);
  label->SetMultiLine(true);
  label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
  AddChildView(label.release());
  set_margins(ChromeLayoutProvider::Get()->GetDialogInsetsForContentType(
      views::TEXT, views::TEXT));
}

FolderUploadConfirmationView::~FolderUploadConfirmationView() {
  // Make sure the dialog ends up calling the callback no matter what as
  // FileSelectHelper keeps itself alive until it sends the result.
  if (!callback_.is_null())
    Cancel();
}

views::Widget* FolderUploadConfirmationView::ShowDialog(
    const base::FilePath& path,
    base::OnceCallback<void(const std::vector<ui::SelectedFileInfo>&)> callback,
    std::vector<ui::SelectedFileInfo> selected_files,
    content::WebContents* web_contents) {
  auto delegate = std::make_unique<FolderUploadConfirmationView>(
      path, std::move(callback), std::move(selected_files));
  return constrained_window::ShowWebModalDialogViews(delegate.release(),
                                                     web_contents);
}

base::string16 FolderUploadConfirmationView::GetWindowTitle() const {
  return l10n_util::GetPluralStringFUTF16(
      IDS_CONFIRM_FILE_UPLOAD_TITLE,
      base::saturated_cast<int>(selected_files_.size()));
}

base::string16 FolderUploadConfirmationView::GetDialogButtonLabel(
    ui::DialogButton button) const {
  if (button == ui::DIALOG_BUTTON_OK)
    return l10n_util::GetStringUTF16(IDS_CONFIRM_FILE_UPLOAD_OK_BUTTON);
  return DialogDelegateView::GetDialogButtonLabel(button);
}

views::View* FolderUploadConfirmationView::GetInitiallyFocusedView() {
  return GetDialogClientView()->cancel_button();
}

bool FolderUploadConfirmationView::ShouldShowCloseButton() const {
  return false;
}

bool FolderUploadConfirmationView::Accept() {
  std::move(callback_).Run(selected_files_);
  return true;
}

bool FolderUploadConfirmationView::Cancel() {
  std::move(callback_).Run(std::vector<ui::SelectedFileInfo>());
  return true;
}

gfx::Size FolderUploadConfirmationView::CalculatePreferredSize() const {
  const int width = ChromeLayoutProvider::Get()->GetDistanceMetric(
                        DISTANCE_MODAL_DIALOG_PREFERRED_WIDTH) -
                    margins().width();
  return gfx::Size(width, GetHeightForWidth(width));
}

ui::ModalType FolderUploadConfirmationView::GetModalType() const {
  return ui::MODAL_TYPE_CHILD;
}

void ShowFolderUploadConfirmationDialog(
    const base::FilePath& path,
    base::OnceCallback<void(const std::vector<ui::SelectedFileInfo>&)> callback,
    std::vector<ui::SelectedFileInfo> selected_files,
    content::WebContents* web_contents) {
  FolderUploadConfirmationView::ShowDialog(
      path, std::move(callback), std::move(selected_files), web_contents);
}