Avi Drissman | 3a215d1e | 2022-09-07 19:43:09 | [diff] [blame] | 1 | // Copyright 2013 The Chromium Authors |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ |
| 6 | #define ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ |
| 7 | |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 8 | #include <optional> |
| 9 | |
Avi Drissman | 4de6dab | 2023-01-06 23:17:35 | [diff] [blame] | 10 | #include "base/functional/callback.h" |
Cam Bickel | 43d91ef | 2024-04-05 20:56:16 | [diff] [blame] | 11 | #include "base/functional/callback_forward.h" |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 12 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 13 | namespace ash { |
| 14 | |
| 15 | // Delegate for controlling the brightness. |
| 16 | class BrightnessControlDelegate { |
| 17 | public: |
| 18 | virtual ~BrightnessControlDelegate() {} |
| 19 | |
| 20 | // Handles an accelerator-driven request to decrease or increase the screen |
| 21 | // brightness. |
Longbo Wei | 43df314 | 2022-09-14 21:19:11 | [diff] [blame] | 22 | virtual void HandleBrightnessDown() = 0; |
| 23 | virtual void HandleBrightnessUp() = 0; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 24 | |
Cam Bickel | 681b726 | 2024-04-17 16:28:46 | [diff] [blame] | 25 | // Enum to represent the source of a brightness change, i.e. what triggered |
| 26 | // the brightness change. |
| 27 | enum class BrightnessChangeSource { |
| 28 | kUnknown = 0, |
| 29 | kQuickSettings = 1, |
| 30 | kSettingsApp = 2, |
Cam Bickel | b42c677 | 2024-05-17 20:55:14 | [diff] [blame] | 31 | kRestoredFromUserPref = 3, |
| 32 | kMaxValue = kRestoredFromUserPref, |
Cam Bickel | 681b726 | 2024-04-17 16:28:46 | [diff] [blame] | 33 | }; |
| 34 | |
Longbo Wei | 8f2f4fde | 2024-07-26 17:04:33 | [diff] [blame] | 35 | // Enum to represent the source of a ambient light sensor change, |
| 36 | // Note that changing brightness can also disable the Ambient Light |
| 37 | // Sensor. This change is not directly made by calling the |
| 38 | // SetAmbientLightSensorEnabled function in the BrightnessControlDelegate in |
| 39 | // Chrome, it is handled in the platform. |
| 40 | enum class AmbientLightSensorEnabledChangeSource { |
| 41 | kSettingsApp = 0, |
| 42 | kRestoredFromUserPref = 1, |
Longbo Wei | 910863b3 | 2024-08-03 00:01:44 | [diff] [blame] | 43 | kSystemReenabled = 2, |
| 44 | kMaxValue = kSystemReenabled, |
Longbo Wei | 8f2f4fde | 2024-07-26 17:04:33 | [diff] [blame] | 45 | }; |
| 46 | |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 47 | // Requests that the brightness be set to |percent|, in the range |
| 48 | // [0.0, 100.0]. |gradual| specifies whether the transition to the new |
Cam Bickel | 681b726 | 2024-04-17 16:28:46 | [diff] [blame] | 49 | // brightness should be animated or instantaneous. |source| is required to |
| 50 | // indicate what is causing this brightness change. |
| 51 | virtual void SetBrightnessPercent(double percent, |
| 52 | bool gradual, |
| 53 | BrightnessChangeSource source) = 0; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 54 | |
| 55 | // Asynchronously invokes |callback| with the current brightness, in the range |
Hidehiko Abe | 181b297 | 2017-10-30 06:43:53 | [diff] [blame] | 56 | // [0.0, 100.0]. In case of error, it is called with nullopt. |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 57 | virtual void GetBrightnessPercent( |
Arthur Sonzogni | a98e443 | 2023-11-28 18:15:01 | [diff] [blame] | 58 | base::OnceCallback<void(std::optional<double>)> callback) = 0; |
Cam Bickel | 8d3cd2c | 2024-04-03 17:36:01 | [diff] [blame] | 59 | |
| 60 | // Sets whether the ambient light sensor should be used in brightness |
| 61 | // calculations. |
Longbo Wei | 8f2f4fde | 2024-07-26 17:04:33 | [diff] [blame] | 62 | virtual void SetAmbientLightSensorEnabled( |
| 63 | bool enabled, |
| 64 | AmbientLightSensorEnabledChangeSource source) = 0; |
Cam Bickel | 43d91ef | 2024-04-05 20:56:16 | [diff] [blame] | 65 | |
Cam Bickel | 1dd2293 | 2024-05-01 19:08:09 | [diff] [blame] | 66 | // Asynchronously invokes |callback| with true if the ambient light sensor is |
| 67 | // enabled (i.e. if the ambient light sensor is currently being used in |
| 68 | // brightness calculations). In case of error, |callback| will be run with |
| 69 | // nullopt. |
| 70 | virtual void GetAmbientLightSensorEnabled( |
| 71 | base::OnceCallback<void(std::optional<bool>)> callback) = 0; |
| 72 | |
Cam Bickel | 43d91ef | 2024-04-05 20:56:16 | [diff] [blame] | 73 | // Asynchronously invokes |callback| with true if the device has at least one |
| 74 | // ambient light sensor. In case of error, |callback| will be run with |
| 75 | // nullopt. |
| 76 | virtual void HasAmbientLightSensor( |
| 77 | base::OnceCallback<void(std::optional<bool>)> callback) = 0; |
James Cook | b0bf8e8 | 2017-04-09 17:01:44 | [diff] [blame] | 78 | }; |
| 79 | |
| 80 | } // namespace ash |
| 81 | |
| 82 | #endif // ASH_SYSTEM_BRIGHTNESS_CONTROL_DELEGATE_H_ |