tablet_mode.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Copyright 2018 The Chromium 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. #ifndef ASH_PUBLIC_CPP_TABLET_MODE_H_
  5. #define ASH_PUBLIC_CPP_TABLET_MODE_H_
  6. #include "ash/public/cpp/ash_public_export.h"
  7. #include "ash/public/cpp/tablet_mode_observer.h"
  8. #include "base/run_loop.h"
  9. #include "third_party/abseil-cpp/absl/types/optional.h"
  10. namespace ash {
  11. // An interface implemented by Ash that allows Chrome to be informed of changes
  12. // to tablet mode state.
  13. class ASH_PUBLIC_EXPORT TabletMode {
  14. public:
  15. // Helper class to wait until the tablet mode transition is complete.
  16. class Waiter : public TabletModeObserver {
  17. public:
  18. explicit Waiter(bool enable);
  19. Waiter(const Waiter&) = delete;
  20. Waiter& operator=(const Waiter&) = delete;
  21. ~Waiter() override;
  22. void Wait();
  23. // TabletModeObserver:
  24. void OnTabletModeStarted() override;
  25. void OnTabletModeEnded() override;
  26. private:
  27. bool enable_;
  28. base::RunLoop run_loop_;
  29. };
  30. // Returns true if the device's board is tablet mode capable.
  31. static bool IsBoardTypeMarkedAsTabletCapable();
  32. // Returns the singleton instance.
  33. static TabletMode* Get();
  34. virtual void AddObserver(TabletModeObserver* observer) = 0;
  35. virtual void RemoveObserver(TabletModeObserver* observer) = 0;
  36. // Returns true if the system is in tablet mode.
  37. virtual bool InTabletMode() const = 0;
  38. // Returns true if TabletMode singleton exists and is in the tablet mode.
  39. static bool IsInTabletMode();
  40. // Force the tablet mode state for integration tests. The meaning of |enabled|
  41. // are as follows:
  42. // true: UI in the tablet mode
  43. // false: UI in the clamshell mode
  44. // nullopt: reset the forcing, UI in the default behavior (i.e. checking the
  45. // physical state).
  46. // Returns true if it actually initiates the change of the tablet mode state.
  47. virtual bool ForceUiTabletModeState(absl::optional<bool> enabled) = 0;
  48. // Enable/disable the tablet mode. Used only by test cases.
  49. virtual void SetEnabledForTest(bool enabled) = 0;
  50. protected:
  51. TabletMode();
  52. virtual ~TabletMode();
  53. };
  54. } // namespace ash
  55. #endif // ASH_PUBLIC_CPP_TABLET_MODE_H_