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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/android/resources/nine_patch_resource.cc
diff --git a/ui/android/resources/nine_patch_resource.cc b/ui/android/resources/nine_patch_resource.cc
new file mode 100644
index 0000000000000000000000000000000000000000..cf8055dd40c02741cabd49f5f0faecbcc03a2ec9
--- /dev/null
+++ b/ui/android/resources/nine_patch_resource.cc
@@ -0,0 +1,49 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/android/resources/nine_patch_resource.h"
+
+#include "base/memory/ptr_util.h"
+
+namespace ui {
+
+// static
+NinePatchResource* NinePatchResource::From(Resource* resource) {
+ DCHECK_EQ(Type::NINE_PATCH_BITMAP, resource->type());
+ return static_cast<NinePatchResource*>(resource);
+}
+
+NinePatchResource::NinePatchResource(gfx::Rect padding, gfx::Rect aperture)
+ : Resource(Type::NINE_PATCH_BITMAP),
+ padding_(padding),
+ aperture_(aperture) {}
+
+NinePatchResource::~NinePatchResource() = default;
+
+gfx::Rect NinePatchResource::Border(const gfx::Size& bounds) const {
+ return Border(bounds, gfx::InsetsF(1.f, 1.f, 1.f, 1.f));
+}
+
+gfx::Rect NinePatchResource::Border(const gfx::Size& bounds,
+ const gfx::InsetsF& scale) const {
+ // Calculate whether or not we need to scale down the border if the bounds of
+ // the layer are going to be smaller than the aperture padding.
+ float x_scale = std::min((float)bounds.width() / size().width(), 1.f);
+ float y_scale = std::min((float)bounds.height() / size().height(), 1.f);
+
+ float left_scale = std::min(x_scale * scale.left(), 1.f);
+ float right_scale = std::min(x_scale * scale.right(), 1.f);
+ float top_scale = std::min(y_scale * scale.top(), 1.f);
+ float bottom_scale = std::min(y_scale * scale.bottom(), 1.f);
+
+ return gfx::Rect(aperture_.x() * left_scale, aperture_.y() * top_scale,
+ (size().width() - aperture_.width()) * right_scale,
+ (size().height() - aperture_.height()) * bottom_scale);
+}
+
+std::unique_ptr<Resource> NinePatchResource::CreateForCopy() {
+ return base::MakeUnique<NinePatchResource>(padding_, aperture_);
+}
+
+} // namespace ui
« 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