| 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 #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/aura/dip_util.h" | |
| 10 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
| 11 #include "ui/gfx/image/image.h" | 10 #include "ui/gfx/image/image.h" |
| 12 #include "ui/gfx/rect.h" | 11 #include "ui/gfx/rect.h" |
| 13 #include "ui/gfx/transform.h" | 12 #include "ui/gfx/transform.h" |
| 14 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 15 #include "third_party/skia/include/core/SkXfermode.h" | 14 #include "third_party/skia/include/core/SkXfermode.h" |
| 16 | 15 |
| 17 using std::max; | 16 using std::max; |
| 18 using std::min; | 17 using std::min; |
| 19 | 18 |
| 20 namespace ash { | 19 namespace ash { |
| 21 namespace internal { | 20 namespace internal { |
| 22 | 21 |
| 23 gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds( | 22 gfx::Rect ImageGrid::TestAPI::GetTransformedLayerBounds( |
| 24 const ui::Layer& layer) { | 23 const ui::Layer& layer) { |
| 25 gfx::Rect bounds = layer.bounds(); | 24 gfx::Rect bounds = layer.bounds(); |
| 26 layer.transform().TransformRect(&bounds); | 25 layer.transform().TransformRect(&bounds); |
| 27 return bounds; | 26 return bounds; |
| 28 } | 27 } |
| 29 | 28 |
| 30 ImageGrid::ImageGrid(aura::Window* window) | 29 ImageGrid::ImageGrid() |
| 31 : window_(window), | 30 : layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), |
| 32 layer_(new ui::Layer(ui::LAYER_NOT_DRAWN)), | |
| 33 top_image_height_(0), | 31 top_image_height_(0), |
| 34 bottom_image_height_(0), | 32 bottom_image_height_(0), |
| 35 left_image_width_(0), | 33 left_image_width_(0), |
| 36 right_image_width_(0), | 34 right_image_width_(0), |
| 37 base_top_row_height_(0), | 35 base_top_row_height_(0), |
| 38 base_bottom_row_height_(0), | 36 base_bottom_row_height_(0), |
| 39 base_left_column_width_(0), | 37 base_left_column_width_(0), |
| 40 base_right_column_width_(0) { | 38 base_right_column_width_(0) { |
| 41 } | 39 } |
| 42 | 40 |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 123 transform.ConcatTranslate( | 121 transform.ConcatTranslate( |
| 124 left, size.height() - bottom_layer_->bounds().height()); | 122 left, size.height() - bottom_layer_->bounds().height()); |
| 125 bottom_layer_->SetTransform(transform); | 123 bottom_layer_->SetTransform(transform); |
| 126 } | 124 } |
| 127 bottom_layer_->SetVisible(center_width > 0); | 125 bottom_layer_->SetVisible(center_width > 0); |
| 128 } | 126 } |
| 129 if (left_layer_.get()) { | 127 if (left_layer_.get()) { |
| 130 if (center_height > 0) { | 128 if (center_height > 0) { |
| 131 ui::Transform transform; | 129 ui::Transform transform; |
| 132 transform.SetScaleY( | 130 transform.SetScaleY( |
| 133 static_cast<float>(center_height) / left_layer_->bounds().height()); | 131 (static_cast<float>(center_height) / left_layer_->bounds().height())); |
| 134 transform.ConcatTranslate(0, top); | 132 transform.ConcatTranslate(0, top); |
| 135 left_layer_->SetTransform(transform); | 133 left_layer_->SetTransform(transform); |
| 136 } | 134 } |
| 137 left_layer_->SetVisible(center_height > 0); | 135 left_layer_->SetVisible(center_height > 0); |
| 138 } | 136 } |
| 139 if (right_layer_.get()) { | 137 if (right_layer_.get()) { |
| 140 if (center_height > 0) { | 138 if (center_height > 0) { |
| 141 ui::Transform transform; | 139 ui::Transform transform; |
| 142 transform.SetScaleY( | 140 transform.SetScaleY( |
| 143 static_cast<float>(center_height) / right_layer_->bounds().height()); | 141 static_cast<float>(center_height) / right_layer_->bounds().height()); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 199 ui::Transform transform; | 197 ui::Transform transform; |
| 200 transform.SetScale(center_width / center_layer_->bounds().width(), | 198 transform.SetScale(center_width / center_layer_->bounds().width(), |
| 201 center_height / center_layer_->bounds().height()); | 199 center_height / center_layer_->bounds().height()); |
| 202 transform.ConcatTranslate(left, top); | 200 transform.ConcatTranslate(left, top); |
| 203 center_layer_->SetTransform(transform); | 201 center_layer_->SetTransform(transform); |
| 204 } | 202 } |
| 205 center_layer_->SetVisible(center_width > 0 && center_height > 0); | 203 center_layer_->SetVisible(center_width > 0 && center_height > 0); |
| 206 } | 204 } |
| 207 } | 205 } |
| 208 | 206 |
| 209 void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds_in_dip) { | 207 void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds) { |
| 210 #if defined(ENABLE_DIP) | |
| 211 // TODO(oshma): Scale the size of the shadow. | |
| 212 const gfx::Rect content_bounds = | |
| 213 aura::ConvertRectToPixel(window_, content_bounds_in_dip); | |
| 214 #else | |
| 215 const gfx::Rect& content_bounds = content_bounds_in_dip; | |
| 216 #endif | |
| 217 SetSize(gfx::Size( | 208 SetSize(gfx::Size( |
| 218 content_bounds.width() + left_image_width_ + right_image_width_, | 209 content_bounds.width() + left_image_width_ + right_image_width_, |
| 219 content_bounds.height() + top_image_height_ + bottom_image_height_)); | 210 content_bounds.height() + top_image_height_ + |
| 220 layer_->SetBounds(gfx::Rect(content_bounds.x() - left_image_width_, | 211 bottom_image_height_)); |
| 221 content_bounds.y() - top_image_height_, | 212 layer_->SetBounds( |
| 222 layer_->bounds().width(), | 213 gfx::Rect(content_bounds.x() - left_image_width_, |
| 223 layer_->bounds().height())); | 214 content_bounds.y() - top_image_height_, |
| 215 layer_->bounds().width(), |
| 216 layer_->bounds().height())); |
| 224 } | 217 } |
| 225 | 218 |
| 226 void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect, | 219 void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect, |
| 227 ui::Layer* layer) { | 220 ui::Layer* layer) { |
| 228 if (clip_rect != clip_rect_) { | 221 if (clip_rect != clip_rect_) { |
| 229 clip_rect_ = clip_rect; | 222 clip_rect_ = clip_rect; |
| 230 layer->SchedulePaint(layer->bounds()); | 223 layer->SchedulePaint(layer->bounds()); |
| 231 } | 224 } |
| 232 } | 225 } |
| 233 | 226 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 260 layer_ptr->reset(); | 253 layer_ptr->reset(); |
| 261 painter_ptr->reset(); | 254 painter_ptr->reset(); |
| 262 | 255 |
| 263 // If we're not using an image, we're done. | 256 // If we're not using an image, we're done. |
| 264 if (!image) | 257 if (!image) |
| 265 return; | 258 return; |
| 266 | 259 |
| 267 // Set up the new layer and painter. | 260 // Set up the new layer and painter. |
| 268 layer_ptr->reset(new ui::Layer(ui::LAYER_TEXTURED)); | 261 layer_ptr->reset(new ui::Layer(ui::LAYER_TEXTURED)); |
| 269 | 262 |
| 270 #if defined(ENABLE_DIP) | |
| 271 const gfx::Size size = | |
| 272 aura::ConvertSizeToPixel(window_, GetImageSize(image)); | |
| 273 #else | |
| 274 const gfx::Size size = GetImageSize(image); | 263 const gfx::Size size = GetImageSize(image); |
| 275 #endif | |
| 276 | |
| 277 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); | 264 layer_ptr->get()->SetBounds(gfx::Rect(0, 0, size.width(), size.height())); |
| 278 | 265 |
| 279 painter_ptr->reset(new ImagePainter(image)); | 266 painter_ptr->reset(new ImagePainter(image)); |
| 280 layer_ptr->get()->set_delegate(painter_ptr->get()); | 267 layer_ptr->get()->set_delegate(painter_ptr->get()); |
| 281 layer_ptr->get()->SetFillsBoundsOpaquely(false); | 268 layer_ptr->get()->SetFillsBoundsOpaquely(false); |
| 282 layer_ptr->get()->SetVisible(true); | 269 layer_ptr->get()->SetVisible(true); |
| 283 layer_->Add(layer_ptr->get()); | 270 layer_->Add(layer_ptr->get()); |
| 284 } | 271 } |
| 285 | 272 |
| 286 } // namespace internal | 273 } // namespace internal |
| 287 } // namespace ash | 274 } // namespace ash |
| OLD | NEW |