Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 #include "ui/android/resources/nine_patch_resource.h" | |
| 6 | |
| 7 #include "base/memory/ptr_util.h" | |
| 8 | |
| 9 namespace ui { | |
| 10 | |
| 11 // static | |
| 12 NinePatchResource* NinePatchResource::From(Resource* resource) { | |
| 13 DCHECK_EQ(Type::NINE_PATCH_BITMAP, resource->type()); | |
|
mdjones
2017/03/10 18:12:00
Where is type_ set for this class?
Khushal
2017/03/10 19:19:24
Woops. I didn't realize the code here was using th
| |
| 14 return static_cast<NinePatchResource*>(resource); | |
| 15 } | |
| 16 | |
| 17 NinePatchResource::NinePatchResource(gfx::Rect padding, gfx::Rect aperture) | |
| 18 : padding_(padding), aperture_(aperture) {} | |
| 19 | |
| 20 NinePatchResource::~NinePatchResource() = default; | |
| 21 | |
| 22 gfx::Rect NinePatchResource::Border(const gfx::Size& bounds) const { | |
| 23 return Border(bounds, gfx::InsetsF(1.f, 1.f, 1.f, 1.f)); | |
| 24 } | |
| 25 | |
| 26 gfx::Rect NinePatchResource::Border(const gfx::Size& bounds, | |
| 27 const gfx::InsetsF& scale) const { | |
| 28 // Calculate whether or not we need to scale down the border if the bounds of | |
| 29 // the layer are going to be smaller than the aperture padding. | |
| 30 float x_scale = std::min((float)bounds.width() / size().width(), 1.f); | |
| 31 float y_scale = std::min((float)bounds.height() / size().height(), 1.f); | |
| 32 | |
| 33 float left_scale = std::min(x_scale * scale.left(), 1.f); | |
| 34 float right_scale = std::min(x_scale * scale.right(), 1.f); | |
| 35 float top_scale = std::min(y_scale * scale.top(), 1.f); | |
| 36 float bottom_scale = std::min(y_scale * scale.bottom(), 1.f); | |
| 37 | |
| 38 return gfx::Rect(aperture_.x() * left_scale, aperture_.y() * top_scale, | |
| 39 (size().width() - aperture_.width()) * right_scale, | |
| 40 (size().height() - aperture_.height()) * bottom_scale); | |
| 41 } | |
| 42 | |
| 43 std::unique_ptr<Resource> NinePatchResource::CreateForCopy() { | |
| 44 return base::MakeUnique<NinePatchResource>(padding_, aperture_); | |
| 45 } | |
| 46 | |
| 47 } // namespace ui | |
| OLD | NEW |