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

Side by Side Diff: ash/wm/image_grid.cc

Issue 9414028: Aura: New window shadows, desktop background debug toggle (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix clang Created 8 years, 10 months 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
« no previous file with comments | « ash/wm/image_grid.h ('k') | ash/wm/image_grid_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "ash/wm/image_grid.h" 5 #include "ash/wm/image_grid.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ui/gfx/canvas.h" 9 #include "ui/gfx/canvas.h"
10 #include "ui/gfx/image/image.h" 10 #include "ui/gfx/image/image.h"
11 #include "ui/gfx/transform.h" 11 #include "ui/gfx/transform.h"
12 #include "third_party/skia/include/core/SkColor.h" 12 #include "third_party/skia/include/core/SkColor.h"
13 #include "third_party/skia/include/core/SkXfermode.h" 13 #include "third_party/skia/include/core/SkXfermode.h"
14 14
15 using std::max; 15 using std::max;
16 using std::min; 16 using std::min;
17 17
18 namespace ash { 18 namespace ash {
19 namespace internal { 19 namespace internal {
20 20
21 gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds( 21 gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds(
22 const ui::Layer& layer) { 22 const ui::Layer& layer) {
23 gfx::Rect bounds = layer.bounds(); 23 gfx::Rect bounds = layer.bounds();
24 layer.transform().TransformRect(&bounds); 24 layer.transform().TransformRect(&bounds);
25 return bounds; 25 return bounds;
26 } 26 }
27 27
28 ImageGrid::ImageGrid() 28 ImageGrid::ImageGrid()
29 : top_image_height_(0), 29 : layer_(new ui::Layer(ui::Layer::LAYER_NOT_DRAWN)),
30 top_image_height_(0),
30 bottom_image_height_(0), 31 bottom_image_height_(0),
31 left_image_width_(0), 32 left_image_width_(0),
32 right_image_width_(0), 33 right_image_width_(0),
33 top_row_height_(0), 34 top_row_height_(0),
34 bottom_row_height_(0), 35 bottom_row_height_(0),
35 left_column_width_(0), 36 left_column_width_(0),
36 right_column_width_(0) { 37 right_column_width_(0) {
37 } 38 }
38 39
39 ImageGrid::~ImageGrid() { 40 ImageGrid::~ImageGrid() {
40 } 41 }
41 42
42 void ImageGrid::Init(const gfx::Image* top_left_image, 43 void ImageGrid::SetImages(const gfx::Image* top_left_image,
43 const gfx::Image* top_image, 44 const gfx::Image* top_image,
44 const gfx::Image* top_right_image, 45 const gfx::Image* top_right_image,
45 const gfx::Image* left_image, 46 const gfx::Image* left_image,
46 const gfx::Image* center_image, 47 const gfx::Image* center_image,
47 const gfx::Image* right_image, 48 const gfx::Image* right_image,
48 const gfx::Image* bottom_left_image, 49 const gfx::Image* bottom_left_image,
49 const gfx::Image* bottom_image, 50 const gfx::Image* bottom_image,
50 const gfx::Image* bottom_right_image) { 51 const gfx::Image* bottom_right_image) {
51 layer_.reset(new ui::Layer(ui::Layer::LAYER_NOT_DRAWN)); 52 SetImage(top_left_image, &top_left_layer_, &top_left_painter_);
52 53 SetImage(top_image, &top_layer_, &top_painter_);
53 InitImage(top_left_image, &top_left_layer_, &top_left_painter_); 54 SetImage(top_right_image, &top_right_layer_, &top_right_painter_);
54 InitImage(top_image, &top_layer_, &top_painter_); 55 SetImage(left_image, &left_layer_, &left_painter_);
55 InitImage(top_right_image, &top_right_layer_, &top_right_painter_); 56 SetImage(center_image, &center_layer_, &center_painter_);
56 InitImage(left_image, &left_layer_, &left_painter_); 57 SetImage(right_image, &right_layer_, &right_painter_);
57 InitImage(center_image, &center_layer_, &center_painter_); 58 SetImage(bottom_left_image, &bottom_left_layer_, &bottom_left_painter_);
58 InitImage(right_image, &right_layer_, &right_painter_); 59 SetImage(bottom_image, &bottom_layer_, &bottom_painter_);
59 InitImage(bottom_left_image, &bottom_left_layer_, &bottom_left_painter_); 60 SetImage(bottom_right_image, &bottom_right_layer_, &bottom_right_painter_);
60 InitImage(bottom_image, &bottom_layer_, &bottom_painter_);
61 InitImage(bottom_right_image, &bottom_right_layer_, &bottom_right_painter_);
62 61
63 top_image_height_ = GetImageSize(top_image).height(); 62 top_image_height_ = GetImageSize(top_image).height();
64 bottom_image_height_ = GetImageSize(bottom_image).height(); 63 bottom_image_height_ = GetImageSize(bottom_image).height();
65 left_image_width_ = GetImageSize(left_image).width(); 64 left_image_width_ = GetImageSize(left_image).width();
66 right_image_width_ = GetImageSize(right_image).width(); 65 right_image_width_ = GetImageSize(right_image).width();
67 66
68 top_row_height_ = max(GetImageSize(top_left_image).height(), 67 top_row_height_ = max(GetImageSize(top_left_image).height(),
69 max(GetImageSize(top_image).height(), 68 max(GetImageSize(top_image).height(),
70 GetImageSize(top_right_image).height())); 69 GetImageSize(top_right_image).height()));
71 bottom_row_height_ = max(GetImageSize(bottom_left_image).height(), 70 bottom_row_height_ = max(GetImageSize(bottom_left_image).height(),
72 max(GetImageSize(bottom_image).height(), 71 max(GetImageSize(bottom_image).height(),
73 GetImageSize(bottom_right_image).height())); 72 GetImageSize(bottom_right_image).height()));
74 left_column_width_ = max(GetImageSize(top_left_image).width(), 73 left_column_width_ = max(GetImageSize(top_left_image).width(),
75 max(GetImageSize(left_image).width(), 74 max(GetImageSize(left_image).width(),
76 GetImageSize(bottom_left_image).width())); 75 GetImageSize(bottom_left_image).width()));
77 right_column_width_ = max(GetImageSize(top_right_image).width(), 76 right_column_width_ = max(GetImageSize(top_right_image).width(),
78 max(GetImageSize(right_image).width(), 77 max(GetImageSize(right_image).width(),
79 GetImageSize(bottom_right_image).width())); 78 GetImageSize(bottom_right_image).width()));
79
80 // Invalidate previous |size_| so calls to SetSize() will recompute it.
81 size_.SetSize(0, 0);
80 } 82 }
81 83
82 void ImageGrid::SetSize(const gfx::Size& size) { 84 void ImageGrid::SetSize(const gfx::Size& size) {
83 if (size_ == size) 85 if (size_ == size)
84 return; 86 return;
85 87
86 size_ = size; 88 size_ = size;
87 89
88 gfx::Rect updated_bounds = layer_->bounds(); 90 gfx::Rect updated_bounds = layer_->bounds();
89 updated_bounds.set_size(size); 91 updated_bounds.set_size(size);
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 gfx::Size(); 219 gfx::Size();
218 } 220 }
219 221
220 // static 222 // static
221 bool ImageGrid::LayerExceedsSize(const ui::Layer* layer, 223 bool ImageGrid::LayerExceedsSize(const ui::Layer* layer,
222 const gfx::Size& size) { 224 const gfx::Size& size) {
223 return layer->bounds().width() > size.width() || 225 return layer->bounds().width() > size.width() ||
224 layer->bounds().height() > size.height(); 226 layer->bounds().height() > size.height();
225 } 227 }
226 228
227 void ImageGrid::InitImage(const gfx::Image* image, 229 void ImageGrid::SetImage(const gfx::Image* image,
228 scoped_ptr<ui::Layer>* layer_ptr, 230 scoped_ptr<ui::Layer>* layer_ptr,
229 scoped_ptr<ImagePainter>* painter_ptr) { 231 scoped_ptr<ImagePainter>* painter_ptr) {
232 // Clean out old layers and painters.
233 if (layer_ptr->get())
234 layer_->Remove(layer_ptr->get());
235 layer_ptr->reset();
236 painter_ptr->reset();
237
238 // If we're not using an image, we're done.
230 if (!image) 239 if (!image)
231 return; 240 return;
232 241
242 // Set up the new layer and painter.
233 layer_ptr->reset(new ui::Layer(ui::Layer::LAYER_TEXTURED)); 243 layer_ptr->reset(new ui::Layer(ui::Layer::LAYER_TEXTURED));
234 244
235 const gfx::Size size = GetImageSize(image); 245 const gfx::Size size = GetImageSize(image);
236 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); 246 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height()));
237 247
238 painter_ptr->reset(new ImagePainter(image)); 248 painter_ptr->reset(new ImagePainter(image));
239 layer_ptr->get()->set_delegate(painter_ptr->get()); 249 layer_ptr->get()->set_delegate(painter_ptr->get());
240 layer_ptr->get()->SetFillsBoundsOpaquely(false); 250 layer_ptr->get()->SetFillsBoundsOpaquely(false);
241 layer_ptr->get()->SetVisible(true); 251 layer_ptr->get()->SetVisible(true);
242 layer_->Add(layer_ptr->get()); 252 layer_->Add(layer_ptr->get());
243 } 253 }
244 254
245 } // namespace internal 255 } // namespace internal
246 } // namespace ash 256 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/image_grid.h ('k') | ash/wm/image_grid_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698