[email protected] | cef15da | 2012-04-26 13:38:10 | [diff] [blame] | 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 | |
| 5 | #ifndef UI_BASE_LAYOUT_H_ |
| 6 | #define UI_BASE_LAYOUT_H_ |
[email protected] | cef15da | 2012-04-26 13:38:10 | [diff] [blame] | 7 | |
[email protected] | b1a9930 | 2012-06-25 17:43:31 | [diff] [blame] | 8 | #include <vector> |
| 9 | |
[email protected] | 2cd6edd9 | 2012-06-25 19:45:48 | [diff] [blame] | 10 | #include "build/build_config.h" |
[email protected] | 9552c2d | 2014-01-06 02:05:32 | [diff] [blame] | 11 | #include "ui/base/ui_base_export.h" |
[email protected] | 509e5aa | 2012-08-03 01:35:55 | [diff] [blame] | 12 | #include "ui/gfx/native_widget_types.h" |
[email protected] | cef15da | 2012-04-26 13:38:10 | [diff] [blame] | 13 | |
| 14 | namespace ui { |
| 15 | |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 16 | // Supported UI scale factors for the platform. This is used as an index |
| 17 | // into the array |kScaleFactorScales| which maps the enum value to a float. |
[email protected] | 0a4cf45 | 2012-11-14 07:28:40 | [diff] [blame] | 18 | // SCALE_FACTOR_NONE is used for density independent resources such as |
| 19 | // string, html/js files or an image that can be used for any scale factors |
| 20 | // (such as wallpapers). |
thakis | b8fbe31 | 2014-10-29 01:30:42 | [diff] [blame] | 21 | enum ScaleFactor : int { |
[email protected] | 0a4cf45 | 2012-11-14 07:28:40 | [diff] [blame] | 22 | SCALE_FACTOR_NONE = 0, |
| 23 | SCALE_FACTOR_100P, |
[email protected] | 07d69467 | 2013-08-23 11:53:14 | [diff] [blame] | 24 | SCALE_FACTOR_125P, |
[email protected] | 3e59458 | 2013-02-04 21:03:36 | [diff] [blame] | 25 | SCALE_FACTOR_133P, |
[email protected] | a27ef62 | 2012-09-10 17:52:02 | [diff] [blame] | 26 | SCALE_FACTOR_140P, |
[email protected] | 276e8a32 | 2013-01-24 01:50:11 | [diff] [blame] | 27 | SCALE_FACTOR_150P, |
[email protected] | a27ef62 | 2012-09-10 17:52:02 | [diff] [blame] | 28 | SCALE_FACTOR_180P, |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 29 | SCALE_FACTOR_200P, |
[email protected] | e416a9b | 2014-06-12 06:42:24 | [diff] [blame] | 30 | SCALE_FACTOR_250P, |
[email protected] | f9ff27b | 2013-12-10 21:53:46 | [diff] [blame] | 31 | SCALE_FACTOR_300P, |
[email protected] | a27ef62 | 2012-09-10 17:52:02 | [diff] [blame] | 32 | |
| 33 | NUM_SCALE_FACTORS // This always appears last. |
[email protected] | c49201a | 2012-05-24 11:04:57 | [diff] [blame] | 34 | }; |
| 35 | |
[email protected] | 421ce19f | 2013-01-31 18:06:41 | [diff] [blame] | 36 | // Changes the value of GetSupportedScaleFactors() to |scale_factors|. |
| 37 | // Use ScopedSetSupportedScaleFactors for unit tests as not to affect the |
| 38 | // state of other tests. |
[email protected] | 9552c2d | 2014-01-06 02:05:32 | [diff] [blame] | 39 | UI_BASE_EXPORT void SetSupportedScaleFactors( |
[email protected] | b1a9930 | 2012-06-25 17:43:31 | [diff] [blame] | 40 | const std::vector<ScaleFactor>& scale_factors); |
| 41 | |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 42 | // Returns a vector with the scale factors which are supported by this |
| 43 | // platform, in ascending order. |
[email protected] | 9552c2d | 2014-01-06 02:05:32 | [diff] [blame] | 44 | UI_BASE_EXPORT const std::vector<ScaleFactor>& GetSupportedScaleFactors(); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 45 | |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 46 | // Returns the supported ScaleFactor which most closely matches |scale|. |
| 47 | // Converting from float to ScaleFactor is inefficient and should be done as |
| 48 | // little as possible. |
[email protected] | 9552c2d | 2014-01-06 02:05:32 | [diff] [blame] | 49 | UI_BASE_EXPORT ScaleFactor GetSupportedScaleFactor(float image_scale); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 50 | |
| 51 | // Returns the ScaleFactor used by |view|. |
[email protected] | 1e76b50 | 2014-05-20 06:25:29 | [diff] [blame] | 52 | UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view); |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 53 | |
[email protected] | b82b38f7 | 2014-03-28 20:16:27 | [diff] [blame] | 54 | // Returns the image scale for the scale factor passed in. |
| 55 | UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor); |
| 56 | |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 57 | namespace test { |
[email protected] | 421ce19f | 2013-01-31 18:06:41 | [diff] [blame] | 58 | // Class which changes the value of GetSupportedScaleFactors() to |
| 59 | // |new_scale_factors| for the duration of its lifetime. |
[email protected] | 9552c2d | 2014-01-06 02:05:32 | [diff] [blame] | 60 | class UI_BASE_EXPORT ScopedSetSupportedScaleFactors { |
[email protected] | 421ce19f | 2013-01-31 18:06:41 | [diff] [blame] | 61 | public: |
| 62 | explicit ScopedSetSupportedScaleFactors( |
| 63 | const std::vector<ui::ScaleFactor>& new_scale_factors); |
| 64 | ~ScopedSetSupportedScaleFactors(); |
| 65 | |
| 66 | private: |
[email protected] | 50b6626 | 2013-09-24 03:25:48 | [diff] [blame] | 67 | std::vector<ui::ScaleFactor>* original_scale_factors_; |
[email protected] | 421ce19f | 2013-01-31 18:06:41 | [diff] [blame] | 68 | |
| 69 | DISALLOW_COPY_AND_ASSIGN(ScopedSetSupportedScaleFactors); |
| 70 | }; |
| 71 | |
[email protected] | b1a9930 | 2012-06-25 17:43:31 | [diff] [blame] | 72 | } // namespace test |
| 73 | |
[email protected] | cef15da | 2012-04-26 13:38:10 | [diff] [blame] | 74 | } // namespace ui |
| 75 | |
| 76 | #endif // UI_BASE_LAYOUT_H_ |