blob: 71280627b3233348110ebc665be5cff03bebefe0 [file] [log] [blame]
Joel Hockey18f767a2024-08-20 03:23:441// Copyright 2024 The Chromium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
William Liu7e940dd2024-09-12 13:16:445#ifndef UI_ANDROID_MODAL_DIALOG_WRAPPER_H_
6#define UI_ANDROID_MODAL_DIALOG_WRAPPER_H_
Joel Hockey18f767a2024-08-20 03:23:447
8#include <memory>
9
10#include "base/android/jni_string.h"
11#include "base/android/scoped_java_ref.h"
William Liu7e940dd2024-09-12 13:16:4412#include "base/gtest_prod_util.h"
13#include "base/memory/raw_ptr.h"
Joel Hockey18f767a2024-08-20 03:23:4414#include "ui/android/ui_android_export.h"
15#include "ui/base/models/dialog_model_host.h"
16
17namespace ui {
18class DialogModel;
19class WindowAndroid;
20} // namespace ui
21
22namespace ui {
23
24// Allows dialogs defined by ui::DialogModel() to be shown in android.
25// This makes a best effort to map between ui::DialogModel() and Java
26// PropertyModel.
27//
28// Maps title, an optional single paragraph, and ok and cancel buttons.
29// Default labels for IDS_APP_OK and IDS_APP_CANCEL will be used for buttons
30// if labels are not specified.
31// Replacements (if any) are performed in paragraph text, but any emphasis is
32// not included since it is not supported in android dialogs.
William Liu7e940dd2024-09-12 13:16:4433class UI_ANDROID_EXPORT ModalDialogWrapper : public DialogModelHost {
Joel Hockey18f767a2024-08-20 03:23:4434 public:
Charles Hagerde93b2e52025-01-29 23:20:1835 // Mirrors Java's `ModalDialogProperties#ButtonStyles`.
36 // TODO(crbug.com/392977703): IntDef that enum in C++.
37 enum class ModalDialogButtonStyles {
38 kPrimaryOutlineNegativeOutline = 0,
39 kPrimaryFilledNegativeOutline = 1,
40 kPrimaryOutlineNegativeFilled = 2,
41 kPrimaryFilledNoNegative = 3,
42 };
43
Joel Hockey18f767a2024-08-20 03:23:4444 static void ShowTabModal(std::unique_ptr<ui::DialogModel> dialog_model,
William Liu7e940dd2024-09-12 13:16:4445 ui::WindowAndroid* window);
Joel Hockey18f767a2024-08-20 03:23:4446
William Liu7e940dd2024-09-12 13:16:4447 static ModalDialogWrapper* GetDialogForTesting();
48
49 ModalDialogWrapper(const ModalDialogWrapper&) = delete;
50 ModalDialogWrapper& operator=(const ModalDialogWrapper&) = delete;
51 virtual ~ModalDialogWrapper();
Joel Hockey18f767a2024-08-20 03:23:4452
53 // JNI methods.
54 void PositiveButtonClicked(JNIEnv* env);
55 void NegativeButtonClicked(JNIEnv* env);
56 void Dismissed(JNIEnv* env);
57 void Destroy(JNIEnv* env);
58
59 private:
William Liu7e940dd2024-09-12 13:16:4460 FRIEND_TEST_ALL_PREFIXES(ModalDialogWrapperTest, CloseDialogFromNative);
61
62 ModalDialogWrapper(std::unique_ptr<ui::DialogModel> dialog_model,
63 ui::WindowAndroid* window_android);
64
65 // `DialogModelHost`:
Joel Hockey18f767a2024-08-20 03:23:4466 void Close() override;
67 void OnDialogButtonChanged() override;
68
69 // Build java PropertyModel from ui::DialogModel.
70 void BuildPropertyModel();
71
William Liu7e940dd2024-09-12 13:16:4472 const std::unique_ptr<ui::DialogModel> dialog_model_;
Joel Hockey18f767a2024-08-20 03:23:4473
William Liu7e940dd2024-09-12 13:16:4474 const raw_ptr<WindowAndroid> window_android_;
Joel Hockey18f767a2024-08-20 03:23:4475
Joel Hockey18f767a2024-08-20 03:23:4476 base::android::ScopedJavaGlobalRef<jobject> java_obj_;
77};
78
79} // namespace ui
80
William Liu7e940dd2024-09-12 13:16:4481#endif // UI_ANDROID_MODAL_DIALOG_WRAPPER_H_