| Flutter Windows Embedder |

settings_plugin.h
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
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 FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_H_
6 #define FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_H_
7
8 #include <Windows.h>
9
10 #include <memory>
11
12 #include "flutter/fml/macros.h"
13 #include "flutter/shell/platform/common/client_wrapper/include/flutter/basic_message_channel.h"
14 #include "flutter/shell/platform/common/client_wrapper/include/flutter/binary_messenger.h"
15 #include "flutter/shell/platform/windows/event_watcher.h"
16 #include "flutter/shell/platform/windows/task_runner.h"
17 #include "rapidjson/document.h"
18
19 namespace flutter {
20
21 // Abstract settings plugin.
22 //
23 // Used to look up and notify Flutter of user-configured system settings.
24 // These are typically set in the control panel.
25 class SettingsPlugin {
26 public:
27 enum struct PlatformBrightness { kDark, kLight };
28
29 explicit SettingsPlugin(BinaryMessenger* messenger, TaskRunner* task_runner);
30
31 virtual ~SettingsPlugin();
32
33 // Sends settings (e.g., platform brightness) to the engine.
34 void SendSettings();
35
36 // Start watching settings changes and notify the engine of the update.
37 virtual void StartWatching();
38
39 // Stop watching settings change. The `SettingsPlugin` destructor will call
40 // this automatically.
41 virtual void StopWatching();
42
43 // Update the high contrast status of the system.
44 virtual void UpdateHighContrastMode(bool is_high_contrast);
45
46 protected:
47 // Returns `true` if the user uses 24 hour time.
48 virtual bool GetAlwaysUse24HourFormat();
49
50 // Returns the user-preferred text scale factor.
51 virtual float GetTextScaleFactor();
52
53 // Returns the user-preferred brightness.
54 virtual PlatformBrightness GetPreferredBrightness();
55
56 // Starts watching brightness changes.
57 virtual void WatchPreferredBrightnessChanged();
58
59 // Starts watching text scale factor changes.
60 virtual void WatchTextScaleFactorChanged();
61
62 bool is_high_contrast_ = false;
63
64 private:
65 std::unique_ptr<BasicMessageChannel<rapidjson::Document>> channel_;
66
67 HKEY preferred_brightness_reg_hkey_ = nullptr;
68 HKEY text_scale_factor_reg_hkey_ = nullptr;
69
70 std::unique_ptr<EventWatcher> preferred_brightness_changed_watcher_;
71 std::unique_ptr<EventWatcher> text_scale_factor_changed_watcher_;
72
73 TaskRunner* task_runner_;
74
75 FML_DISALLOW_COPY_AND_ASSIGN(SettingsPlugin);
76 };
77
78 } // namespace flutter
79
80 #endif // FLUTTER_SHELL_PLATFORM_WINDOWS_SETTINGS_PLUGIN_H_
basic_message_channel.h
binary_messenger.h
flutter::BinaryMessenger
Definition: binary_messenger.h:28
flutter::SettingsPlugin
Definition: settings_plugin.h:25
flutter::SettingsPlugin::PlatformBrightness
PlatformBrightness
Definition: settings_plugin.h:27
flutter::SettingsPlugin::PlatformBrightness::kDark
@ kDark
flutter::SettingsPlugin::PlatformBrightness::kLight
@ kLight
flutter::SettingsPlugin::~SettingsPlugin
virtual ~SettingsPlugin()
Definition: settings_plugin.cc:65
flutter::SettingsPlugin::is_high_contrast_
bool is_high_contrast_
Definition: settings_plugin.h:62
flutter::SettingsPlugin::StartWatching
virtual void StartWatching()
Definition: settings_plugin.cc:85
flutter::SettingsPlugin::UpdateHighContrastMode
virtual void UpdateHighContrastMode(bool is_high_contrast)
Definition: settings_plugin.cc:169
flutter::SettingsPlugin::WatchPreferredBrightnessChanged
virtual void WatchPreferredBrightnessChanged()
Definition: settings_plugin.cc:142
flutter::SettingsPlugin::GetAlwaysUse24HourFormat
virtual bool GetAlwaysUse24HourFormat()
Definition: settings_plugin.cc:112
flutter::SettingsPlugin::SendSettings
void SendSettings()
Definition: settings_plugin.cc:69
flutter::SettingsPlugin::GetPreferredBrightness
virtual PlatformBrightness GetPreferredBrightness()
Definition: settings_plugin.cc:131
flutter::SettingsPlugin::SettingsPlugin
SettingsPlugin(BinaryMessenger *messenger, TaskRunner *task_runner)
Definition: settings_plugin.cc:57
flutter::SettingsPlugin::WatchTextScaleFactorChanged
virtual void WatchTextScaleFactorChanged()
Definition: settings_plugin.cc:156
flutter::SettingsPlugin::GetTextScaleFactor
virtual float GetTextScaleFactor()
Definition: settings_plugin.cc:116
flutter::SettingsPlugin::StopWatching
virtual void StopWatching()
Definition: settings_plugin.cc:100
flutter::TaskRunner
Definition: task_runner.h:26
event_watcher.h
flutter
Definition: accessibility_bridge_windows.cc:11
task_runner.h