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

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: jni 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
« no previous file with comments | « ui/android/resources/nine_patch_resource.h ('k') | ui/android/resources/resource.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
14 return static_cast<NinePatchResource*>(resource);
15 }
16
17 NinePatchResource::NinePatchResource(gfx::Rect padding, gfx::Rect aperture)
18 : Resource(Type::NINE_PATCH_BITMAP),
19 padding_(padding),
20 aperture_(aperture) {}
21
22 NinePatchResource::~NinePatchResource() = default;
23
24 gfx::Rect NinePatchResource::Border(const gfx::Size& bounds) const {
25 return Border(bounds, gfx::InsetsF(1.f, 1.f, 1.f, 1.f));
26 }
27
28 gfx::Rect NinePatchResource::Border(const gfx::Size& bounds,
29 const gfx::InsetsF& scale) const {
30 // Calculate whether or not we need to scale down the border if the bounds of
31 // the layer are going to be smaller than the aperture padding.
32 float x_scale = std::min((float)bounds.width() / size().width(), 1.f);
33 float y_scale = std::min((float)bounds.height() / size().height(), 1.f);
34
35 float left_scale = std::min(x_scale * scale.left(), 1.f);
36 float right_scale = std::min(x_scale * scale.right(), 1.f);
37 float top_scale = std::min(y_scale * scale.top(), 1.f);
38 float bottom_scale = std::min(y_scale * scale.bottom(), 1.f);
39
40 return gfx::Rect(aperture_.x() * left_scale, aperture_.y() * top_scale,
41 (size().width() - aperture_.width()) * right_scale,
42 (size().height() - aperture_.height()) * bottom_scale);
43 }
44
45 std::unique_ptr<Resource> NinePatchResource::CreateForCopy() {
46 return base::MakeUnique<NinePatchResource>(padding_, aperture_);
47 }
48
49 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/resources/nine_patch_resource.h ('k') | ui/android/resources/resource.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698