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 106 107 108 109 110 111 112
|
// Copyright 2014 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_VIEWS_WEB_APPS_CREATE_SHORTCUT_CONFIRMATION_VIEW_H_
#define CHROME_BROWSER_UI_VIEWS_WEB_APPS_CREATE_SHORTCUT_CONFIRMATION_VIEW_H_
#include <memory>
#include <string>
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/web_applications/web_app_install_info.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/base/mojom/dialog_button.mojom.h"
#include "ui/views/controls/textfield/textfield_controller.h"
#include "ui/views/metadata/view_factory.h"
#include "ui/views/window/dialog_delegate.h"
namespace views {
class Checkbox;
class Textfield;
class RadioButton;
} // namespace views
namespace webapps {
class MlInstallOperationTracker;
} // namespace webapps
// CreateShortcutConfirmationView provides views for editing the details to
// create a "shortcut" web app with (More tools > Create Shortcut).
class CreateShortcutConfirmationView : public views::DialogDelegateView,
public views::TextfieldController {
METADATA_HEADER(CreateShortcutConfirmationView, views::DialogDelegateView)
public:
static CreateShortcutConfirmationView* GetDialogForTesting();
CreateShortcutConfirmationView(
std::unique_ptr<web_app::WebAppInstallInfo> web_app_info,
std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker,
web_app::AppInstallationAcceptanceCallback callback);
CreateShortcutConfirmationView(const CreateShortcutConfirmationView&) =
delete;
CreateShortcutConfirmationView& operator=(
const CreateShortcutConfirmationView&) = delete;
~CreateShortcutConfirmationView() override;
views::Checkbox* GetOpenAsWindowCheckboxForTesting() {
return open_as_window_checkbox_.get();
}
views::RadioButton* GetOpenAsTabRadioForTesting() {
return open_as_tab_radio_.get();
}
views::RadioButton* GetOpenAsWindowRadioForTesting() {
return open_as_window_radio_.get();
}
views::RadioButton* GetOpenAsTabbedWindowRadioForTesting() {
return open_as_tabbed_window_radio_.get();
}
private:
// Overridden from views::WidgetDelegate:
views::View* GetInitiallyFocusedView() override;
bool ShouldShowCloseButton() const override;
// Overridden from views::DialogDelegateView:
bool IsDialogButtonEnabled(ui::mojom::DialogButton button) const override;
// Overridden from views::TextfieldController:
void ContentsChanged(views::Textfield* sender,
const std::u16string& new_contents) override;
// Get the trimmed contents of the title text field.
std::u16string GetTrimmedTitle() const;
void OnAccept();
void OnClose();
void OnCancel();
void RunCloseCallbackIfExists();
// The WebAppInstallInfo that the user is editing.
// Cleared when the dialog completes (Accept/WindowClosing).
std::unique_ptr<web_app::WebAppInstallInfo> web_app_info_;
std::unique_ptr<webapps::MlInstallOperationTracker> install_tracker_;
// The callback to be invoked when the dialog is completed.
web_app::AppInstallationAcceptanceCallback callback_;
// Checkbox to launch as a window.
raw_ptr<views::Checkbox> open_as_window_checkbox_ = nullptr;
// Radio buttons to launch as a tab, window or tabbed window.
raw_ptr<views::RadioButton> open_as_tab_radio_ = nullptr;
raw_ptr<views::RadioButton> open_as_window_radio_ = nullptr;
raw_ptr<views::RadioButton> open_as_tabbed_window_radio_ = nullptr;
// Textfield showing the title of the app.
raw_ptr<views::Textfield> title_tf_ = nullptr;
base::WeakPtrFactory<CreateShortcutConfirmationView> weak_ptr_factory_{this};
};
BEGIN_VIEW_BUILDER(, CreateShortcutConfirmationView, views::DialogDelegateView)
END_VIEW_BUILDER
DEFINE_VIEW_BUILDER(, CreateShortcutConfirmationView)
#endif // CHROME_BROWSER_UI_VIEWS_WEB_APPS_CREATE_SHORTCUT_CONFIRMATION_VIEW_H_
|