layout.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Copyright (c) 2012 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 UI_BASE_LAYOUT_H_
  5. #define UI_BASE_LAYOUT_H_
  6. #include <vector>
  7. #include "base/component_export.h"
  8. #include "base/memory/raw_ptr.h"
  9. #include "build/build_config.h"
  10. #include "ui/base/resource/resource_scale_factor.h"
  11. #include "ui/gfx/native_widget_types.h"
  12. namespace ui {
  13. // Changes the value of GetSupportedScaleFactors() to |scale_factors|.
  14. // Use ScopedSetSupportedScaleFactors for unit tests as not to affect the
  15. // state of other tests.
  16. COMPONENT_EXPORT(UI_BASE)
  17. void SetSupportedResourceScaleFactors(
  18. const std::vector<ResourceScaleFactor>& scale_factors);
  19. // Returns a vector with the scale factors which are supported by this
  20. // platform, in ascending order.
  21. COMPONENT_EXPORT(UI_BASE)
  22. const std::vector<ResourceScaleFactor>& GetSupportedResourceScaleFactors();
  23. // Returns the supported ResourceScaleFactor which most closely matches |scale|.
  24. // Converting from float to ResourceScaleFactor is inefficient and should be
  25. // done as little as possible.
  26. COMPONENT_EXPORT(UI_BASE)
  27. ResourceScaleFactor GetSupportedResourceScaleFactor(float image_scale);
  28. // Returns the ResourceScaleFactor used by |view|.
  29. COMPONENT_EXPORT(UI_BASE)
  30. float GetScaleFactorForNativeView(gfx::NativeView view);
  31. // Returns true if the scale passed in is the list of supported scales for
  32. // the platform.
  33. // TODO(oshima): Deprecate this.
  34. COMPONENT_EXPORT(UI_BASE) bool IsSupportedScale(float scale);
  35. namespace test {
  36. // Class which changes the value of GetSupportedResourceScaleFactors() to
  37. // |new_scale_factors| for the duration of its lifetime.
  38. class COMPONENT_EXPORT(UI_BASE) ScopedSetSupportedResourceScaleFactors {
  39. public:
  40. explicit ScopedSetSupportedResourceScaleFactors(
  41. const std::vector<ResourceScaleFactor>& new_scale_factors);
  42. ScopedSetSupportedResourceScaleFactors(
  43. const ScopedSetSupportedResourceScaleFactors&) = delete;
  44. ScopedSetSupportedResourceScaleFactors& operator=(
  45. const ScopedSetSupportedResourceScaleFactors&) = delete;
  46. ~ScopedSetSupportedResourceScaleFactors();
  47. private:
  48. raw_ptr<std::vector<ResourceScaleFactor>> original_scale_factors_;
  49. };
  50. } // namespace test
  51. } // namespace ui
  52. #endif // UI_BASE_LAYOUT_H_