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_ 7 8 #include <vector> 9 10 #include "build/build_config.h" 11 #include "ui/base/ui_export.h" 12 #include "ui/gfx/native_widget_types.h" 13 14 namespace ui { 15 16 enum DisplayLayout { 17 // The typical layout for e.g. Windows, Mac and Linux. 18 LAYOUT_DESKTOP, 19 20 // Layout optimized for touch. Used e.g. for Windows 8 Metro mode. 21 LAYOUT_TOUCH, 22 }; 23 24 // Returns the display layout that should be used. This could be used 25 // e.g. to tweak hard-coded padding that's layout specific, or choose 26 // the .pak file of theme resources to load. 27 // WARNING: this is deprecated and will be nuked as soon as aura is the default 28 // on windows. 29 UI_EXPORT DisplayLayout GetDisplayLayout(); 30 31 // Supported UI scale factors for the platform. This is used as an index 32 // into the array |kScaleFactorScales| which maps the enum value to a float. 33 // SCALE_FACTOR_NONE is used for density independent resources such as 34 // string, html/js files or an image that can be used for any scale factors 35 // (such as wallpapers). 36 enum ScaleFactor { 37 SCALE_FACTOR_NONE = 0, 38 SCALE_FACTOR_100P, 39 SCALE_FACTOR_133P, 40 SCALE_FACTOR_140P, 41 SCALE_FACTOR_150P, 42 SCALE_FACTOR_180P, 43 SCALE_FACTOR_200P, 44 45 NUM_SCALE_FACTORS // This always appears last. 46 }; 47 48 // Returns the float scale value for |scale_factor|. 49 UI_EXPORT float GetScaleFactorScale(ScaleFactor scale_factor); 50 51 // Returns the supported ScaleFactor which most closely matches |scale|. 52 // Converting from float to ScaleFactor is inefficient and should be done as 53 // little as possible. 54 // TODO(oshima): Make ScaleFactor a class and remove this. 55 UI_EXPORT ScaleFactor GetScaleFactorFromScale(float scale); 56 57 // Returns the ScaleFactor used by |view|. 58 UI_EXPORT ScaleFactor GetScaleFactorForNativeView(gfx::NativeView view); 59 60 // Returns the maximum device scale factor supported by this platform. 61 UI_EXPORT ScaleFactor GetMaxScaleFactor(); 62 63 // Returns a vector with the scale factors which are supported by this 64 // platform, in ascending order. 65 UI_EXPORT std::vector<ScaleFactor> GetSupportedScaleFactors(); 66 67 // Returns true if |scale_factor| is supported by this platform. 68 UI_EXPORT bool IsScaleFactorSupported(ScaleFactor scale_factor); 69 70 namespace test { 71 72 // Changes the value of GetSupportedScaleFactors() to |scale_factors|. 73 // Use ScopedSetSupportedScaleFactors for unit tests as not to affect the 74 // state of other tests. 75 UI_EXPORT void SetSupportedScaleFactors( 76 const std::vector<ScaleFactor>& scale_factors); 77 78 // Class which changes the value of GetSupportedScaleFactors() to 79 // |new_scale_factors| for the duration of its lifetime. 80 class UI_EXPORT ScopedSetSupportedScaleFactors { 81 public: 82 explicit ScopedSetSupportedScaleFactors( 83 const std::vector<ui::ScaleFactor>& new_scale_factors); 84 ~ScopedSetSupportedScaleFactors(); 85 86 private: 87 const std::vector<ui::ScaleFactor> original_scale_factors_; 88 89 DISALLOW_COPY_AND_ASSIGN(ScopedSetSupportedScaleFactors); 90 }; 91 92 } // namespace test 93 94 } // namespace ui 95 96 #endif // UI_BASE_LAYOUT_H_ 97