| 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 "ui/views/corewm/image_grid.h" | 5 #include "ui/views/corewm/image_grid.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "third_party/skia/include/core/SkColor.h" | 9 #include "third_party/skia/include/core/SkColor.h" |
| 10 #include "third_party/skia/include/core/SkXfermode.h" | 10 #include "third_party/skia/include/core/SkXfermode.h" |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 const int top = min(base_top_row_height_, size_.height() / 2); | 100 const int top = min(base_top_row_height_, size_.height() / 2); |
| 101 const int bottom = min(base_bottom_row_height_, size_.height() - top); | 101 const int bottom = min(base_bottom_row_height_, size_.height() - top); |
| 102 | 102 |
| 103 // The remaining space goes to the center image. | 103 // The remaining space goes to the center image. |
| 104 int center_width = std::max(size.width() - left - right, 0); | 104 int center_width = std::max(size.width() - left - right, 0); |
| 105 int center_height = std::max(size.height() - top - bottom, 0); | 105 int center_height = std::max(size.height() - top - bottom, 0); |
| 106 | 106 |
| 107 if (top_layer_.get()) { | 107 if (top_layer_.get()) { |
| 108 if (center_width > 0) { | 108 if (center_width > 0) { |
| 109 gfx::Transform transform; | 109 gfx::Transform transform; |
| 110 transform.SetScaleX( | 110 transform.Translate(left, 0); |
| 111 static_cast<float>(center_width) / top_layer_->bounds().width()); | 111 transform.Scale( |
| 112 transform.ConcatTranslate(left, 0); | 112 static_cast<float>(center_width) / top_layer_->bounds().width(), 1); |
| 113 top_layer_->SetTransform(transform); | 113 top_layer_->SetTransform(transform); |
| 114 } | 114 } |
| 115 top_layer_->SetVisible(center_width > 0); | 115 top_layer_->SetVisible(center_width > 0); |
| 116 } | 116 } |
| 117 if (bottom_layer_.get()) { | 117 if (bottom_layer_.get()) { |
| 118 if (center_width > 0) { | 118 if (center_width > 0) { |
| 119 gfx::Transform transform; | 119 gfx::Transform transform; |
| 120 transform.SetScaleX( | 120 transform.Translate( |
| 121 static_cast<float>(center_width) / bottom_layer_->bounds().width()); | |
| 122 transform.ConcatTranslate( | |
| 123 left, size.height() - bottom_layer_->bounds().height()); | 121 left, size.height() - bottom_layer_->bounds().height()); |
| 122 transform.Scale( |
| 123 static_cast<float>(center_width) / bottom_layer_->bounds().width(), |
| 124 1.0); |
| 124 bottom_layer_->SetTransform(transform); | 125 bottom_layer_->SetTransform(transform); |
| 125 } | 126 } |
| 126 bottom_layer_->SetVisible(center_width > 0); | 127 bottom_layer_->SetVisible(center_width > 0); |
| 127 } | 128 } |
| 128 if (left_layer_.get()) { | 129 if (left_layer_.get()) { |
| 129 if (center_height > 0) { | 130 if (center_height > 0) { |
| 130 gfx::Transform transform; | 131 gfx::Transform transform; |
| 131 transform.SetScaleY( | 132 transform.Translate(0, top); |
| 133 transform.Scale( |
| 134 1.0, |
| 132 (static_cast<float>(center_height) / left_layer_->bounds().height())); | 135 (static_cast<float>(center_height) / left_layer_->bounds().height())); |
| 133 transform.ConcatTranslate(0, top); | |
| 134 left_layer_->SetTransform(transform); | 136 left_layer_->SetTransform(transform); |
| 135 } | 137 } |
| 136 left_layer_->SetVisible(center_height > 0); | 138 left_layer_->SetVisible(center_height > 0); |
| 137 } | 139 } |
| 138 if (right_layer_.get()) { | 140 if (right_layer_.get()) { |
| 139 if (center_height > 0) { | 141 if (center_height > 0) { |
| 140 gfx::Transform transform; | 142 gfx::Transform transform; |
| 141 transform.SetScaleY( | 143 transform.Translate( |
| 144 size.width() - right_layer_->bounds().width(), top); |
| 145 transform.Scale( |
| 146 1.0, |
| 142 static_cast<float>(center_height) / right_layer_->bounds().height()); | 147 static_cast<float>(center_height) / right_layer_->bounds().height()); |
| 143 transform.ConcatTranslate( | |
| 144 size.width() - right_layer_->bounds().width(), top); | |
| 145 right_layer_->SetTransform(transform); | 148 right_layer_->SetTransform(transform); |
| 146 } | 149 } |
| 147 right_layer_->SetVisible(center_height > 0); | 150 right_layer_->SetVisible(center_height > 0); |
| 148 } | 151 } |
| 149 | 152 |
| 150 if (top_left_layer_.get()) { | 153 if (top_left_layer_.get()) { |
| 151 // No transformation needed; it should be at (0, 0) and unscaled. | 154 // No transformation needed; it should be at (0, 0) and unscaled. |
| 152 top_left_painter_->SetClipRect( | 155 top_left_painter_->SetClipRect( |
| 153 LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ? | 156 LayerExceedsSize(top_left_layer_.get(), gfx::Size(left, top)) ? |
| 154 gfx::Rect(gfx::Rect(0, 0, left, top)) : | 157 gfx::Rect(gfx::Rect(0, 0, left, top)) : |
| 155 gfx::Rect(), | 158 gfx::Rect(), |
| 156 top_left_layer_.get()); | 159 top_left_layer_.get()); |
| 157 } | 160 } |
| 158 if (top_right_layer_.get()) { | 161 if (top_right_layer_.get()) { |
| 159 gfx::Transform transform; | 162 gfx::Transform transform; |
| 160 transform.SetTranslateX(size.width() - top_right_layer_->bounds().width()); | 163 transform.Translate(size.width() - top_right_layer_->bounds().width(), 0.0); |
| 161 top_right_layer_->SetTransform(transform); | 164 top_right_layer_->SetTransform(transform); |
| 162 top_right_painter_->SetClipRect( | 165 top_right_painter_->SetClipRect( |
| 163 LayerExceedsSize(top_right_layer_.get(), gfx::Size(right, top)) ? | 166 LayerExceedsSize(top_right_layer_.get(), gfx::Size(right, top)) ? |
| 164 gfx::Rect(top_right_layer_->bounds().width() - right, 0, | 167 gfx::Rect(top_right_layer_->bounds().width() - right, 0, |
| 165 right, top) : | 168 right, top) : |
| 166 gfx::Rect(), | 169 gfx::Rect(), |
| 167 top_right_layer_.get()); | 170 top_right_layer_.get()); |
| 168 } | 171 } |
| 169 if (bottom_left_layer_.get()) { | 172 if (bottom_left_layer_.get()) { |
| 170 gfx::Transform transform; | 173 gfx::Transform transform; |
| 171 transform.SetTranslateY( | 174 transform.Translate( |
| 172 size.height() - bottom_left_layer_->bounds().height()); | 175 0.0, size.height() - bottom_left_layer_->bounds().height()); |
| 173 bottom_left_layer_->SetTransform(transform); | 176 bottom_left_layer_->SetTransform(transform); |
| 174 bottom_left_painter_->SetClipRect( | 177 bottom_left_painter_->SetClipRect( |
| 175 LayerExceedsSize(bottom_left_layer_.get(), gfx::Size(left, bottom)) ? | 178 LayerExceedsSize(bottom_left_layer_.get(), gfx::Size(left, bottom)) ? |
| 176 gfx::Rect(0, bottom_left_layer_->bounds().height() - bottom, | 179 gfx::Rect(0, bottom_left_layer_->bounds().height() - bottom, |
| 177 left, bottom) : | 180 left, bottom) : |
| 178 gfx::Rect(), | 181 gfx::Rect(), |
| 179 bottom_left_layer_.get()); | 182 bottom_left_layer_.get()); |
| 180 } | 183 } |
| 181 if (bottom_right_layer_.get()) { | 184 if (bottom_right_layer_.get()) { |
| 182 gfx::Transform transform; | 185 gfx::Transform transform; |
| 183 transform.SetTranslate( | 186 transform.Translate( |
| 184 size.width() - bottom_right_layer_->bounds().width(), | 187 size.width() - bottom_right_layer_->bounds().width(), |
| 185 size.height() - bottom_right_layer_->bounds().height()); | 188 size.height() - bottom_right_layer_->bounds().height()); |
| 186 bottom_right_layer_->SetTransform(transform); | 189 bottom_right_layer_->SetTransform(transform); |
| 187 bottom_right_painter_->SetClipRect( | 190 bottom_right_painter_->SetClipRect( |
| 188 LayerExceedsSize(bottom_right_layer_.get(), gfx::Size(right, bottom)) ? | 191 LayerExceedsSize(bottom_right_layer_.get(), gfx::Size(right, bottom)) ? |
| 189 gfx::Rect(bottom_right_layer_->bounds().width() - right, | 192 gfx::Rect(bottom_right_layer_->bounds().width() - right, |
| 190 bottom_right_layer_->bounds().height() - bottom, | 193 bottom_right_layer_->bounds().height() - bottom, |
| 191 right, bottom) : | 194 right, bottom) : |
| 192 gfx::Rect(), | 195 gfx::Rect(), |
| 193 bottom_right_layer_.get()); | 196 bottom_right_layer_.get()); |
| 194 } | 197 } |
| 195 | 198 |
| 196 if (center_layer_.get()) { | 199 if (center_layer_.get()) { |
| 197 if (center_width > 0 && center_height > 0) { | 200 if (center_width > 0 && center_height > 0) { |
| 198 gfx::Transform transform; | 201 gfx::Transform transform; |
| 199 transform.SetScale(center_width / center_layer_->bounds().width(), | 202 transform.Translate(left, top); |
| 200 center_height / center_layer_->bounds().height()); | 203 transform.Scale(center_width / center_layer_->bounds().width(), |
| 201 transform.ConcatTranslate(left, top); | 204 center_height / center_layer_->bounds().height()); |
| 202 center_layer_->SetTransform(transform); | 205 center_layer_->SetTransform(transform); |
| 203 } | 206 } |
| 204 center_layer_->SetVisible(center_width > 0 && center_height > 0); | 207 center_layer_->SetVisible(center_width > 0 && center_height > 0); |
| 205 } | 208 } |
| 206 } | 209 } |
| 207 | 210 |
| 208 void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds) { | 211 void ImageGrid::SetContentBounds(const gfx::Rect& content_bounds) { |
| 209 SetSize(gfx::Size( | 212 SetSize(gfx::Size( |
| 210 content_bounds.width() + left_image_width_ + right_image_width_, | 213 content_bounds.width() + left_image_width_ + right_image_width_, |
| 211 content_bounds.height() + top_image_height_ + | 214 content_bounds.height() + top_image_height_ + |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 275 | 278 |
| 276 painter_ptr->reset(new ImagePainter(image)); | 279 painter_ptr->reset(new ImagePainter(image)); |
| 277 layer_ptr->get()->set_delegate(painter_ptr->get()); | 280 layer_ptr->get()->set_delegate(painter_ptr->get()); |
| 278 layer_ptr->get()->SetFillsBoundsOpaquely(false); | 281 layer_ptr->get()->SetFillsBoundsOpaquely(false); |
| 279 layer_ptr->get()->SetVisible(true); | 282 layer_ptr->get()->SetVisible(true); |
| 280 layer_->Add(layer_ptr->get()); | 283 layer_->Add(layer_ptr->get()); |
| 281 } | 284 } |
| 282 | 285 |
| 283 } // namespace corewm | 286 } // namespace corewm |
| 284 } // namespace views | 287 } // namespace views |
| OLD | NEW |