| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_WM_CORE_IMAGE_GRID_H_ | 5 #ifndef UI_WM_CORE_IMAGE_GRID_H_ |
| 6 #define UI_WM_CORE_IMAGE_GRID_H_ | 6 #define UI_WM_CORE_IMAGE_GRID_H_ |
| 7 | 7 |
| 8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
| 9 #include "base/gtest_prod_util.h" | 9 #include "base/gtest_prod_util.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| 11 #include "ui/compositor/layer.h" | 11 #include "ui/compositor/layer.h" |
| 12 #include "ui/compositor/layer_delegate.h" | 12 #include "ui/compositor/layer_delegate.h" |
| 13 #include "ui/gfx/image/image_skia.h" |
| 13 #include "ui/gfx/rect.h" | 14 #include "ui/gfx/rect.h" |
| 14 #include "ui/gfx/size.h" | 15 #include "ui/gfx/size.h" |
| 15 #include "ui/wm/wm_export.h" | 16 #include "ui/wm/wm_export.h" |
| 16 | 17 |
| 17 namespace gfx { | 18 namespace gfx { |
| 18 class Image; | 19 class Image; |
| 19 } // namespace gfx | 20 } // namespace gfx |
| 20 | 21 |
| 21 namespace wm { | 22 namespace wm { |
| 22 | 23 |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 void SetSize(const gfx::Size& size); | 122 void SetSize(const gfx::Size& size); |
| 122 | 123 |
| 123 // Sets the grid to a position and size such that the inner edges of the top, | 124 // Sets the grid to a position and size such that the inner edges of the top, |
| 124 // bottom, left and right images will be flush with |content_bounds_in_dip|. | 125 // bottom, left and right images will be flush with |content_bounds_in_dip|. |
| 125 void SetContentBounds(const gfx::Rect& content_bounds_in_dip); | 126 void SetContentBounds(const gfx::Rect& content_bounds_in_dip); |
| 126 | 127 |
| 127 private: | 128 private: |
| 128 // Delegate responsible for painting a specific image on a layer. | 129 // Delegate responsible for painting a specific image on a layer. |
| 129 class ImagePainter : public ui::LayerDelegate { | 130 class ImagePainter : public ui::LayerDelegate { |
| 130 public: | 131 public: |
| 131 ImagePainter(const gfx::Image* image) : image_(image) {} | 132 ImagePainter(const gfx::ImageSkia& image) : image_(image) {} |
| 132 virtual ~ImagePainter() {} | 133 virtual ~ImagePainter() {} |
| 133 | 134 |
| 134 // Clips |layer| to |clip_rect|. Triggers a repaint if the clipping | 135 // Clips |layer| to |clip_rect|. Triggers a repaint if the clipping |
| 135 // rectangle has changed. An empty rectangle disables clipping. | 136 // rectangle has changed. An empty rectangle disables clipping. |
| 136 void SetClipRect(const gfx::Rect& clip_rect, ui::Layer* layer); | 137 void SetClipRect(const gfx::Rect& clip_rect, ui::Layer* layer); |
| 137 | 138 |
| 138 // ui::LayerDelegate implementation: | 139 // ui::LayerDelegate implementation: |
| 139 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; | 140 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE; |
| 140 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; | 141 virtual void OnDeviceScaleFactorChanged(float device_scale_factor) OVERRIDE; |
| 141 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; | 142 virtual base::Closure PrepareForLayerBoundsChange() OVERRIDE; |
| 142 | 143 |
| 143 private: | 144 private: |
| 144 friend class TestAPI; | 145 friend class TestAPI; |
| 145 | 146 |
| 146 const gfx::Image* image_; // not owned | 147 const gfx::ImageSkia image_; |
| 147 | 148 |
| 148 gfx::Rect clip_rect_; | 149 gfx::Rect clip_rect_; |
| 149 | 150 |
| 150 DISALLOW_COPY_AND_ASSIGN(ImagePainter); | 151 DISALLOW_COPY_AND_ASSIGN(ImagePainter); |
| 151 }; | 152 }; |
| 152 | 153 |
| 153 // Returns the dimensions of |image| if non-NULL or gfx::Size(0, 0) otherwise. | 154 enum ImageType { |
| 154 static gfx::Size GetImageSize(const gfx::Image* image); | 155 HORIZONTAL, |
| 155 | 156 VERTICAL, |
| 156 // Returns true if |layer|'s bounds don't fit within |size|. | 157 NONE, |
| 157 static bool LayerExceedsSize(const ui::Layer* layer, const gfx::Size& size); | 158 }; |
| 158 | 159 |
| 159 // Sets |layer_ptr| and |painter_ptr| to display |image| and adds the | 160 // Sets |layer_ptr| and |painter_ptr| to display |image| and adds the |
| 160 // passed-in layer to |layer_|. If image is NULL resets |layer_ptr| and | 161 // passed-in layer to |layer_|. If image is NULL resets |layer_ptr| and |
| 161 // |painter_ptr| and removes any existing layer from |layer_|. | 162 // |painter_ptr| and removes any existing layer from |layer_|. |
| 163 // If |type| is either HORIZONTAL or VERTICAL, it may resize the image to |
| 164 // guarantee that it has minimum size in order for scaling work properly |
| 165 // with fractional device scale factors. crbug.com/376519. |
| 162 void SetImage(const gfx::Image* image, | 166 void SetImage(const gfx::Image* image, |
| 163 scoped_ptr<ui::Layer>* layer_ptr, | 167 scoped_ptr<ui::Layer>* layer_ptr, |
| 164 scoped_ptr<ImagePainter>* painter_ptr); | 168 scoped_ptr<ImagePainter>* painter_ptr, |
| 165 | 169 ImageType type); |
| 166 // Sets the scaling for the transform applied to a layer. The left, top, | |
| 167 // right and bottom layers are stretched to the height or width of the | |
| 168 // center image. | |
| 169 void ScaleWidth(gfx::Size center, | |
| 170 ui::Layer* layer, | |
| 171 gfx::Transform& transform); | |
| 172 void ScaleHeight(gfx::Size center, | |
| 173 ui::Layer* layer, | |
| 174 gfx::Transform& transform); | |
| 175 | 170 |
| 176 // Layer that contains all of the image layers. | 171 // Layer that contains all of the image layers. |
| 177 scoped_ptr<ui::Layer> layer_; | 172 scoped_ptr<ui::Layer> layer_; |
| 178 | 173 |
| 179 // The grid's dimensions. | 174 // The grid's dimensions. |
| 180 gfx::Size size_; | 175 gfx::Size size_; |
| 181 | 176 |
| 182 // Heights and widths of the images displayed by |top_layer_|, | 177 // Heights and widths of the images displayed by |top_layer_|, |
| 183 // |bottom_layer_|, |left_layer_|, and |right_layer_|. | 178 // |bottom_layer_|, |left_layer_|, and |right_layer_|. |
| 184 int top_image_height_; | 179 int top_image_height_; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 scoped_ptr<ImagePainter> bottom_left_painter_; | 212 scoped_ptr<ImagePainter> bottom_left_painter_; |
| 218 scoped_ptr<ImagePainter> bottom_painter_; | 213 scoped_ptr<ImagePainter> bottom_painter_; |
| 219 scoped_ptr<ImagePainter> bottom_right_painter_; | 214 scoped_ptr<ImagePainter> bottom_right_painter_; |
| 220 | 215 |
| 221 DISALLOW_COPY_AND_ASSIGN(ImageGrid); | 216 DISALLOW_COPY_AND_ASSIGN(ImageGrid); |
| 222 }; | 217 }; |
| 223 | 218 |
| 224 } // namespace wm | 219 } // namespace wm |
| 225 | 220 |
| 226 #endif // UI_WM_CORE_IMAGE_GRID_H_ | 221 #endif // UI_WM_CORE_IMAGE_GRID_H_ |
| OLD | NEW |