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

Side by Side Diff: ui/android/resources/nine_patch_resource.cc

Issue 2746483003: ui/android: Fix Resource meta-data sharing with ResourceManager. (Closed)
Patch Set: Created 3 years, 9 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
OLDNEW
(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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698