| Index: ui/aura_shell/image_grid.cc
|
| diff --git a/ui/aura_shell/image_grid.cc b/ui/aura_shell/image_grid.cc
|
| index 14d69ce83a2d8e88d1d303101ad12890bef24029..99f8d90a299c6967cd7fa1f87a68901a2c68e3cf 100644
|
| --- a/ui/aura_shell/image_grid.cc
|
| +++ b/ui/aura_shell/image_grid.cc
|
| @@ -13,6 +13,7 @@
|
| #include "third_party/skia/include/core/SkXfermode.h"
|
|
|
| using std::max;
|
| +using std::min;
|
|
|
| namespace aura_shell {
|
| namespace internal {
|
| @@ -92,45 +93,81 @@ void ImageGrid::SetSize(const gfx::Size& size) {
|
| float center_height = size.height() - top_row_height_ - bottom_row_height_;
|
|
|
| if (top_layer_.get()) {
|
| - ui::Transform transform;
|
| - transform.SetScaleX(center_width / top_layer_->bounds().width());
|
| - transform.ConcatTranslate(left_column_width_, 0);
|
| - top_layer_->SetTransform(transform);
|
| + if (center_width > 0) {
|
| + ui::Transform transform;
|
| + transform.SetScaleX(center_width / top_layer_->bounds().width());
|
| + transform.ConcatTranslate(left_column_width_, 0);
|
| + top_layer_->SetTransform(transform);
|
| + }
|
| + top_layer_->SetVisible(center_width > 0);
|
| }
|
| if (bottom_layer_.get()) {
|
| - ui::Transform transform;
|
| - transform.SetScaleX(center_width / bottom_layer_->bounds().width());
|
| - transform.ConcatTranslate(
|
| - left_column_width_, size.height() - bottom_layer_->bounds().height());
|
| - bottom_layer_->SetTransform(transform);
|
| + if (center_width > 0) {
|
| + ui::Transform transform;
|
| + transform.SetScaleX(center_width / bottom_layer_->bounds().width());
|
| + transform.ConcatTranslate(
|
| + left_column_width_, size.height() - bottom_layer_->bounds().height());
|
| + bottom_layer_->SetTransform(transform);
|
| + }
|
| + bottom_layer_->SetVisible(center_width > 0);
|
| }
|
| if (left_layer_.get()) {
|
| - ui::Transform transform;
|
| - transform.SetScaleY(center_height / left_layer_->bounds().height());
|
| - transform.ConcatTranslate(0, top_row_height_);
|
| - left_layer_->SetTransform(transform);
|
| + if (center_height > 0) {
|
| + ui::Transform transform;
|
| + transform.SetScaleY(center_height / left_layer_->bounds().height());
|
| + transform.ConcatTranslate(0, top_row_height_);
|
| + left_layer_->SetTransform(transform);
|
| + }
|
| + left_layer_->SetVisible(center_height > 0);
|
| }
|
| if (right_layer_.get()) {
|
| - ui::Transform transform;
|
| - transform.SetScaleY(center_height / right_layer_->bounds().height());
|
| - transform.ConcatTranslate(
|
| - size.width() - right_layer_->bounds().width(), top_row_height_);
|
| - right_layer_->SetTransform(transform);
|
| + if (center_height > 0) {
|
| + ui::Transform transform;
|
| + transform.SetScaleY(center_height / right_layer_->bounds().height());
|
| + transform.ConcatTranslate(
|
| + size.width() - right_layer_->bounds().width(), top_row_height_);
|
| + right_layer_->SetTransform(transform);
|
| + }
|
| + right_layer_->SetVisible(center_height > 0);
|
| }
|
|
|
| + // Calculate the available amount of space for corner images on all sides of
|
| + // the grid. If the images don't fit, we need to clip them.
|
| + const int left = min(left_column_width_, size_.width() / 2);
|
| + const int right = min(right_column_width_, size_.width() - left);
|
| + const int top = min(top_row_height_, size_.height() / 2);
|
| + const int bottom = min(bottom_row_height_, size_.height() - top);
|
| +
|
| if (top_left_layer_.get()) {
|
| // No transformation needed; it should be at (0, 0) and unscaled.
|
| + top_left_painter_->SetClipRect(
|
| + LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ?
|
| + gfx::Rect(gfx::Rect(0, 0, left, top)) :
|
| + gfx::Rect(),
|
| + top_left_layer_.get());
|
| }
|
| if (top_right_layer_.get()) {
|
| ui::Transform transform;
|
| transform.SetTranslateX(size.width() - top_right_layer_->bounds().width());
|
| top_right_layer_->SetTransform(transform);
|
| + top_right_painter_->SetClipRect(
|
| + LayerExceedsSize(top_right_layer_.get(), gfx::Size(right, top)) ?
|
| + gfx::Rect(top_right_layer_->bounds().width() - right, 0,
|
| + right, top) :
|
| + gfx::Rect(),
|
| + top_right_layer_.get());
|
| }
|
| if (bottom_left_layer_.get()) {
|
| ui::Transform transform;
|
| transform.SetTranslateY(
|
| size.height() - bottom_left_layer_->bounds().height());
|
| bottom_left_layer_->SetTransform(transform);
|
| + bottom_left_painter_->SetClipRect(
|
| + LayerExceedsSize(bottom_left_layer_.get(), gfx::Size(left, bottom)) ?
|
| + gfx::Rect(0, bottom_left_layer_->bounds().height() - bottom,
|
| + left, bottom) :
|
| + gfx::Rect(),
|
| + bottom_left_layer_.get());
|
| }
|
| if (bottom_right_layer_.get()) {
|
| ui::Transform transform;
|
| @@ -138,18 +175,38 @@ void ImageGrid::SetSize(const gfx::Size& size) {
|
| size.width() - bottom_right_layer_->bounds().width(),
|
| size.height() - bottom_right_layer_->bounds().height());
|
| bottom_right_layer_->SetTransform(transform);
|
| + bottom_right_painter_->SetClipRect(
|
| + LayerExceedsSize(bottom_right_layer_.get(), gfx::Size(right, bottom)) ?
|
| + gfx::Rect(bottom_right_layer_->bounds().width() - right,
|
| + bottom_right_layer_->bounds().height() - bottom,
|
| + right, bottom) :
|
| + gfx::Rect(),
|
| + bottom_right_layer_.get());
|
| }
|
|
|
| if (center_layer_.get()) {
|
| - ui::Transform transform;
|
| - transform.SetScale(center_width / center_layer_->bounds().width(),
|
| - center_height / center_layer_->bounds().height());
|
| - transform.ConcatTranslate(left_column_width_, top_row_height_);
|
| - center_layer_->SetTransform(transform);
|
| + if (center_width > 0 && center_height > 0) {
|
| + ui::Transform transform;
|
| + transform.SetScale(center_width / center_layer_->bounds().width(),
|
| + center_height / center_layer_->bounds().height());
|
| + transform.ConcatTranslate(left_column_width_, top_row_height_);
|
| + center_layer_->SetTransform(transform);
|
| + }
|
| + center_layer_->SetVisible(center_width > 0 && center_height > 0);
|
| + }
|
| +}
|
| +
|
| +void ImageGrid::ImagePainter::SetClipRect(const gfx::Rect& clip_rect,
|
| + ui::Layer* layer) {
|
| + if (clip_rect != clip_rect_) {
|
| + clip_rect_ = clip_rect;
|
| + layer->ScheduleDraw();
|
| }
|
| }
|
|
|
| void ImageGrid::ImagePainter::OnPaintLayer(gfx::Canvas* canvas) {
|
| + if (!clip_rect_.IsEmpty())
|
| + canvas->ClipRect(clip_rect_);
|
| canvas->DrawBitmapInt(*(image_->ToSkBitmap()), 0, 0);
|
| }
|
|
|
| @@ -160,6 +217,13 @@ gfx::Size ImageGrid::GetImageSize(const gfx::Image* image) {
|
| gfx::Size();
|
| }
|
|
|
| +// static
|
| +bool ImageGrid::LayerExceedsSize(const ui::Layer* layer,
|
| + const gfx::Size& size) {
|
| + return layer->bounds().width() > size.width() ||
|
| + layer->bounds().height() > size.height();
|
| +}
|
| +
|
| void ImageGrid::InitImage(const gfx::Image* image,
|
| scoped_ptr<ui::Layer>* layer_ptr,
|
| scoped_ptr<ImagePainter>* painter_ptr) {
|
|
|