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

Unified Diff: content/browser/android/composited_touch_handle_drawable.cc

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 8 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
Index: content/browser/android/composited_touch_handle_drawable.cc
diff --git a/content/browser/android/composited_touch_handle_drawable.cc b/content/browser/android/composited_touch_handle_drawable.cc
index 91a019eba89157780bd68ed5d82c979b050d0c88..ad8faad3f9d1fd28d87a51ae25c5f027d3848945 100644
--- a/content/browser/android/composited_touch_handle_drawable.cc
+++ b/content/browser/android/composited_touch_handle_drawable.cc
@@ -10,6 +10,7 @@
#include "cc/layers/ui_resource_layer.h"
#include "jni/HandleViewResources_jni.h"
#include "ui/gfx/android/java_bitmap.h"
+#include "ui/gfx/skbitmap_operations.h"
namespace content {
@@ -44,21 +45,62 @@ class HandleResources {
Java_HandleViewResources_getRightHandleBitmap(env, context));
center_bitmap_ = CreateSkBitmapFromJavaBitmap(
Java_HandleViewResources_getCenterHandleBitmap(env, context));
+ left_inverted_bitmap_ = SkBitmapOperations::Rotate(
jdduke (slow) 2015/04/14 00:00:32 There's no need to create new assets for a transfo
AviD 2015/04/23 14:45:16 Done.
+ right_bitmap_, SkBitmapOperations::ROTATION_180_CW);
+ right_inverted_bitmap_ = SkBitmapOperations::Rotate(
+ left_bitmap_, SkBitmapOperations::ROTATION_180_CW);
+ center_inverted_bitmap_ = SkBitmapOperations::Rotate(
+ center_bitmap_, SkBitmapOperations::ROTATION_180_CW);
left_bitmap_.setImmutable();
right_bitmap_.setImmutable();
center_bitmap_.setImmutable();
+ left_inverted_bitmap_.setImmutable();
+ right_inverted_bitmap_.setImmutable();
+ center_inverted_bitmap_.setImmutable();
}
- const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) {
+ const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation,
+ bool mirror_vertical,
+ bool mirror_horizontal) {
DCHECK(loaded_);
switch (orientation) {
case ui::TouchHandleOrientation::LEFT:
- return left_bitmap_;
+ if (mirror_vertical && mirror_horizontal) {
+ // Inverted about both X and Y axes
+ return right_inverted_bitmap_;
+ } else if (mirror_vertical) {
+ // Inverted about X axis only
+ return left_inverted_bitmap_;
+ } else if (mirror_horizontal) {
+ // Inverted about Y axis only
+ return right_bitmap_;
+ } else {
+ // Normal Case
+ return left_bitmap_;
+ }
case ui::TouchHandleOrientation::RIGHT:
- return right_bitmap_;
+ if (mirror_vertical && mirror_horizontal) {
+ // Inverted about both X and Y axes
+ return left_inverted_bitmap_;
+ } else if (mirror_vertical) {
+ // Inverted about X axis only
+ return right_inverted_bitmap_;
+ } else if (mirror_horizontal) {
+ // Inverted about Y axis only
+ return left_bitmap_;
+ } else {
+ // Normal Case
+ return right_bitmap_;
+ }
case ui::TouchHandleOrientation::CENTER:
- return center_bitmap_;
+ if (mirror_vertical) {
+ // Inverted about X axis
+ return center_inverted_bitmap_;
+ } else {
+ // Normal Case
+ return center_bitmap_;
+ }
case ui::TouchHandleOrientation::UNDEFINED:
NOTREACHED() << "Invalid touch handle orientation.";
};
@@ -69,6 +111,9 @@ class HandleResources {
SkBitmap left_bitmap_;
SkBitmap right_bitmap_;
SkBitmap center_bitmap_;
+ SkBitmap left_inverted_bitmap_;
+ SkBitmap right_inverted_bitmap_;
+ SkBitmap center_inverted_bitmap_;
bool loaded_;
DISALLOW_COPY_AND_ASSIGN(HandleResources);
@@ -102,23 +147,39 @@ void CompositedTouchHandleDrawable::SetEnabled(bool enabled) {
}
void CompositedTouchHandleDrawable::SetOrientation(
- ui::TouchHandleOrientation orientation) {
+ ui::TouchHandleOrientation orientation,
+ bool mirror_vertical,
+ bool mirror_horizontal) {
DCHECK(layer_->parent());
orientation_ = orientation;
- const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation);
+ const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(
+ orientation, mirror_vertical, mirror_horizontal);
+ const int bitmap_height = bitmap.height();
jdduke (slow) 2015/04/14 00:00:32 To set the layer transform, you can use an approac
AviD 2015/04/23 14:45:16 Done.
+ const int bitmap_width = bitmap.width();
+ int focal_offset_x = 0;
+ int focal_offset_y = mirror_vertical ? bitmap_height : 0;
+
layer_->SetBitmap(bitmap);
- layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height()));
+ layer_->SetBounds(gfx::Size(bitmap_width, bitmap_height));
switch (orientation_) {
case ui::TouchHandleOrientation::LEFT:
- focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0);
+ focal_offset_x =
+ mirror_horizontal ? bitmap_width * 0.25f : bitmap_width * 0.75f;
+ focal_offset_from_origin_ =
+ gfx::Vector2dF(focal_offset_x, focal_offset_y);
break;
case ui::TouchHandleOrientation::RIGHT:
- focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0);
+ focal_offset_x =
+ mirror_horizontal ? bitmap_width * 0.75f : bitmap_width * 0.25f;
+ focal_offset_from_origin_ =
+ gfx::Vector2dF(focal_offset_x, focal_offset_y);
break;
case ui::TouchHandleOrientation::CENTER:
- focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0);
+ focal_offset_x = bitmap_width * 0.5f;
+ focal_offset_from_origin_ =
+ gfx::Vector2dF(focal_offset_x, focal_offset_y);
break;
case ui::TouchHandleOrientation::UNDEFINED:
NOTREACHED() << "Invalid touch handle orientation.";

Powered by Google App Engine
This is Rietveld 408576698