Home | History | Annotate | Download | only in base
      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_base_export.h"
     12 #include "ui/gfx/native_widget_types.h"
     13 
     14 namespace ui {
     15 
     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 {
     22   SCALE_FACTOR_NONE = 0,
     23   SCALE_FACTOR_100P,
     24   SCALE_FACTOR_125P,
     25   SCALE_FACTOR_133P,
     26   SCALE_FACTOR_140P,
     27   SCALE_FACTOR_150P,
     28   SCALE_FACTOR_180P,
     29   SCALE_FACTOR_200P,
     30   SCALE_FACTOR_250P,
     31   SCALE_FACTOR_300P,
     32 
     33   NUM_SCALE_FACTORS  // This always appears last.
     34 };
     35 
     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);
     41 
     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();
     45 
     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);
     50 
     51 // Returns the ScaleFactor used by |view|.
     52 UI_BASE_EXPORT float GetScaleFactorForNativeView(gfx::NativeView view);
     53 
     54 // Returns the image scale for the scale factor passed in.
     55 UI_BASE_EXPORT float GetScaleForScaleFactor(ScaleFactor scale_factor);
     56 
     57 namespace test {
     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 {
     61  public:
     62   explicit ScopedSetSupportedScaleFactors(
     63       const std::vector<ui::ScaleFactor>& new_scale_factors);
     64   ~ScopedSetSupportedScaleFactors();
     65 
     66  private:
     67   std::vector<ui::ScaleFactor>* original_scale_factors_;
     68 
     69   DISALLOW_COPY_AND_ASSIGN(ScopedSetSupportedScaleFactors);
     70 };
     71 
     72 }  // namespace test
     73 
     74 }  // namespace ui
     75 
     76 #endif  // UI_BASE_LAYOUT_H_
     77