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.
5 #ifndef UI_BASE_LAYOUT_H_
6 #define UI_BASE_LAYOUT_H_
10 #include "build/build_config.h"
11 #include "ui/base/ui_base_export.h"
12 #include "ui/gfx/native_widget_types.h"
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.
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).
21 enum ScaleFactor
: int {
22 SCALE_FACTOR_NONE
= 0,
33 NUM_SCALE_FACTORS
// This always appears last.
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.
39 UI_BASE_EXPORT
void SetSupportedScaleFactors(
40 const std::vector
<ScaleFactor
>& scale_factors
);
42 // Returns a vector with the scale factors which are supported by this
43 // platform, in ascending order.
44 UI_BASE_EXPORT
const std::vector
<ScaleFactor
>& GetSupportedScaleFactors();
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.
49 UI_BASE_EXPORT ScaleFactor
GetSupportedScaleFactor(float image_scale
);
51 // Returns the ScaleFactor used by |view|.
52 UI_BASE_EXPORT
float GetScaleFactorForNativeView(gfx::NativeView view
);
54 // Returns the image scale for the scale factor passed in.
55 UI_BASE_EXPORT
float GetScaleForScaleFactor(ScaleFactor scale_factor
);
58 // Class which changes the value of GetSupportedScaleFactors() to
59 // |new_scale_factors| for the duration of its lifetime.
60 class UI_BASE_EXPORT ScopedSetSupportedScaleFactors
{
62 explicit ScopedSetSupportedScaleFactors(
63 const std::vector
<ui::ScaleFactor
>& new_scale_factors
);
64 ~ScopedSetSupportedScaleFactors();
67 std::vector
<ui::ScaleFactor
>* original_scale_factors_
;
69 DISALLOW_COPY_AND_ASSIGN(ScopedSetSupportedScaleFactors
);
76 #endif // UI_BASE_LAYOUT_H_