Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(768)

Side by Side Diff: ui/aura/image_grid.h

Issue 8555025: aura: Draw drop shadows under browsers and menus. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 9 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 2011 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_AURA_IMAGE_GRID_H_
6 #define UI_AURA_IMAGE_GRID_H_
7 #pragma once
8
9 #include "base/basictypes.h"
10 #include "base/gtest_prod_util.h"
11 #include "base/memory/scoped_ptr.h"
12 #include "ui/gfx/compositor/layer.h"
13 #include "ui/gfx/compositor/layer_delegate.h"
14 #include "ui/gfx/rect.h"
15 #include "ui/gfx/size.h"
16
17 namespace gfx {
18 class Image;
19 } // namespace gfx
20
21 namespace aura {
22 namespace internal {
23
24 // An ImageGrid is a 3x3 array of ui::Layers, each containing an image.
25 //
26 // As the grid is resized, its images fill the requested space:
27 // - corner images are not scaled
28 // - top and bottom images are scaled horizontally
29 // - left and right images are scaled vertically
30 // - the center image is scaled in both directions
31 //
32 // If one of the non-center images is smaller than the largest images in its
33 // row or column, it will be aligned with the outside of the grid. For
34 // example, given 4x4 top-left and top-right images and a 1x2 top images:
35 //
36 // +--------+---------------------+--------+
37 // | | top | |
38 // | top- +---------------------+ top- +
39 // | left | | right |
40 // +----+---+ +---+----+
41 // | | | |
42 // ...
43 //
44 // This may seem odd at first, but it lets ImageGrid be used to draw shadows
45 // with curved corners that extend inwards beyond a window's borders. In the
46 // below example, the top-left corner image is overlaid on top of the window's
47 // top-left corner:
48 //
49 // +---------+-----------------------
50 // | ..xxx|XXXXXXXXXXXXXXXXXX
51 // | .xXXXXX|XXXXXXXXXXXXXXXXXX_____
52 // | .xXX | ^ window's top edge
53 // | .xXX |
54 // +---------+
55 // | xXX|
56 // | xXX|< window's left edge
57 // | xXX|
58 // ...
59 //
60 class ImageGrid {
61 public:
62 // Helper class for use by tests.
63 class TestAPI {
64 public:
65 TestAPI(ImageGrid* grid) : grid_(grid) {}
66 ui::Layer* top_left_layer() const { return grid_->top_left_layer_.get(); }
67 ui::Layer* top_layer() const { return grid_->top_layer_.get(); }
68 ui::Layer* top_right_layer() const { return grid_->top_right_layer_.get(); }
69 ui::Layer* left_layer() const { return grid_->left_layer_.get(); }
70 ui::Layer* center_layer() const { return grid_->center_layer_.get(); }
71 ui::Layer* right_layer() const { return grid_->right_layer_.get(); }
72 ui::Layer* bottom_left_layer() const {
73 return grid_->bottom_left_layer_.get();
74 }
75 ui::Layer* bottom_layer() const { return grid_->bottom_layer_.get(); }
76 ui::Layer* bottom_right_layer() const {
77 return grid_->bottom_right_layer_.get();
78 }
79
80 // Returns |layer|'s bounds after applying the layer's current transform.
81 gfx::Rect GetTransformedLayerBounds(const ui::Layer& layer);
82
83 private:
84 ImageGrid* grid_; // not owned
85
86 DISALLOW_COPY_AND_ASSIGN(TestAPI);
87 };
88
89 ImageGrid();
90 ~ImageGrid();
91
92 ui::Layer* layer() { return layer_.get(); }
93 int top_image_height() const { return top_image_height_; }
94 int bottom_image_height() const { return bottom_image_height_; }
95 int left_image_width() const { return left_image_width_; }
96 int right_image_width() const { return right_image_width_; }
97
98 // Initializes the grid to display the passed-in images (any of which can be
99 // NULL). Ownership of the images remains with the caller.
100 void Init(const gfx::Image* top_left_image,
101 const gfx::Image* top_image,
102 const gfx::Image* top_right_image,
103 const gfx::Image* left_image,
104 const gfx::Image* center_image,
105 const gfx::Image* right_image,
106 const gfx::Image* bottom_left_image,
107 const gfx::Image* bottom_image,
108 const gfx::Image* bottom_right_image);
109
110 void SetSize(const gfx::Size& size);
111
112 private:
113 // Delegate responsible for painting a specific image on a layer.
114 class ImagePainter : public ui::LayerDelegate {
115 public:
116 ImagePainter(const gfx::Image* image) : image_(image) {}
117 virtual ~ImagePainter() {}
118
119 // ui::LayerDelegate implementation:
120 virtual void OnPaintLayer(gfx::Canvas* canvas) OVERRIDE;
121
122 private:
123 const gfx::Image* image_; // not owned
124
125 DISALLOW_COPY_AND_ASSIGN(ImagePainter);
126 };
127
128 // Returns the dimensions of |image| if non-NULL or gfx::Size(0, 0) otherwise.
129 static gfx::Size GetImageSize(const gfx::Image* image);
130
131 // Initializes |layer_ptr| and |painter_ptr| to display |image|.
132 // Also adds the passed-in layer to |layer_|.
133 void InitImage(const gfx::Image* image,
134 scoped_ptr<ui::Layer>* layer_ptr,
135 scoped_ptr<ImagePainter>* painter_ptr);
136
137 // Layer that contains all of the image layers.
138 scoped_ptr<ui::Layer> layer_;
139
140 // The grid's dimensions.
141 gfx::Size size_;
142
143 // Heights and widths of the images displayed by |top_layer_|,
144 // |bottom_layer_|, |left_layer_|, and |right_layer_|.
145 int top_image_height_;
146 int bottom_image_height_;
147 int left_image_width_;
148 int right_image_width_;
149
150 // Heights of the tallest images in the top and bottom rows and the widest
151 // images in the left and right columns.
152 int top_row_height_;
153 int bottom_row_height_;
154 int left_column_width_;
155 int right_column_width_;
156
157 // Layers used to display the various images. Children of |layer_|.
158 // Positions for which no images were supplied are NULL.
159 scoped_ptr<ui::Layer> top_left_layer_;
160 scoped_ptr<ui::Layer> top_layer_;
161 scoped_ptr<ui::Layer> top_right_layer_;
162 scoped_ptr<ui::Layer> left_layer_;
163 scoped_ptr<ui::Layer> center_layer_;
164 scoped_ptr<ui::Layer> right_layer_;
165 scoped_ptr<ui::Layer> bottom_left_layer_;
166 scoped_ptr<ui::Layer> bottom_layer_;
167 scoped_ptr<ui::Layer> bottom_right_layer_;
168
169 // Delegates responsible for painting the above layers.
170 // Positions for which no images were supplied are NULL.
171 scoped_ptr<ImagePainter> top_left_painter_;
172 scoped_ptr<ImagePainter> top_painter_;
173 scoped_ptr<ImagePainter> top_right_painter_;
174 scoped_ptr<ImagePainter> left_painter_;
175 scoped_ptr<ImagePainter> center_painter_;
176 scoped_ptr<ImagePainter> right_painter_;
177 scoped_ptr<ImagePainter> bottom_left_painter_;
178 scoped_ptr<ImagePainter> bottom_painter_;
179 scoped_ptr<ImagePainter> bottom_right_painter_;
180
181 DISALLOW_COPY_AND_ASSIGN(ImageGrid);
182 };
183
184 } // namespace internal
185 } // namespace aura
186
187 #endif // UI_AURA_IMAGE_GRID_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698