| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/android/composited_touch_handle_drawable.h" | 5 #include "content/browser/android/composited_touch_handle_drawable.h" |
| 6 | 6 |
| 7 #include "base/lazy_instance.h" | 7 #include "base/lazy_instance.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/trace_event/trace_event.h" | 9 #include "base/trace_event/trace_event.h" |
| 10 #include "cc/layers/ui_resource_layer.h" | 10 #include "cc/layers/ui_resource_layer.h" |
| (...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 } | 95 } |
| 96 | 96 |
| 97 void CompositedTouchHandleDrawable::SetEnabled(bool enabled) { | 97 void CompositedTouchHandleDrawable::SetEnabled(bool enabled) { |
| 98 layer_->SetIsDrawable(enabled); | 98 layer_->SetIsDrawable(enabled); |
| 99 // Force a position update in case the disabled layer's properties are stale. | 99 // Force a position update in case the disabled layer's properties are stale. |
| 100 if (enabled) | 100 if (enabled) |
| 101 UpdateLayerPosition(); | 101 UpdateLayerPosition(); |
| 102 } | 102 } |
| 103 | 103 |
| 104 void CompositedTouchHandleDrawable::SetOrientation( | 104 void CompositedTouchHandleDrawable::SetOrientation( |
| 105 ui::TouchHandleOrientation orientation) { | 105 ui::TouchHandleOrientation orientation, |
| 106 bool mirror_vertical, |
| 107 bool mirror_horizontal) { |
| 106 DCHECK(layer_->parent()); | 108 DCHECK(layer_->parent()); |
| 107 orientation_ = orientation; | 109 orientation_ = orientation; |
| 108 | 110 |
| 109 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); | 111 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); |
| 112 const int bitmap_height = bitmap.height(); |
| 113 const int bitmap_width = bitmap.width(); |
| 114 int focal_offset_x = 0; |
| 115 int focal_offset_y = mirror_vertical ? bitmap_height : 0; |
| 116 |
| 110 layer_->SetBitmap(bitmap); | 117 layer_->SetBitmap(bitmap); |
| 111 layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); | 118 layer_->SetBounds(gfx::Size(bitmap_width, bitmap_height)); |
| 119 |
| 120 // Invert about X and Y axis based on the mirror values |
| 121 gfx::Transform transform; |
| 122 float scale_x = mirror_horizontal ? -1.f : 1.f; |
| 123 float scale_y = mirror_vertical ? -1.f : 1.f; |
| 124 |
| 125 layer_->SetTransformOrigin( |
| 126 gfx::Point3F(bitmap_width * 0.5f, bitmap_height * 0.5f, 0)); |
| 127 transform.Scale(scale_x, scale_y); |
| 128 layer_->SetTransform(transform); |
| 112 | 129 |
| 113 switch (orientation_) { | 130 switch (orientation_) { |
| 114 case ui::TouchHandleOrientation::LEFT: | 131 case ui::TouchHandleOrientation::LEFT: |
| 115 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); | 132 focal_offset_x = |
| 133 mirror_horizontal ? bitmap_width * 0.25f : bitmap_width * 0.75f; |
| 134 focal_offset_from_origin_ = |
| 135 gfx::Vector2dF(focal_offset_x, focal_offset_y); |
| 116 break; | 136 break; |
| 117 case ui::TouchHandleOrientation::RIGHT: | 137 case ui::TouchHandleOrientation::RIGHT: |
| 118 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); | 138 focal_offset_x = |
| 139 mirror_horizontal ? bitmap_width * 0.75f : bitmap_width * 0.25f; |
| 140 focal_offset_from_origin_ = |
| 141 gfx::Vector2dF(focal_offset_x, focal_offset_y); |
| 119 break; | 142 break; |
| 120 case ui::TouchHandleOrientation::CENTER: | 143 case ui::TouchHandleOrientation::CENTER: |
| 121 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); | 144 focal_offset_x = bitmap_width * 0.5f; |
| 145 focal_offset_from_origin_ = |
| 146 gfx::Vector2dF(focal_offset_x, focal_offset_y); |
| 122 break; | 147 break; |
| 123 case ui::TouchHandleOrientation::UNDEFINED: | 148 case ui::TouchHandleOrientation::UNDEFINED: |
| 124 NOTREACHED() << "Invalid touch handle orientation."; | 149 NOTREACHED() << "Invalid touch handle orientation."; |
| 125 break; | 150 break; |
| 126 }; | 151 }; |
| 127 | 152 |
| 128 UpdateLayerPosition(); | 153 UpdateLayerPosition(); |
| 129 } | 154 } |
| 130 | 155 |
| 131 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { | 156 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 157 void CompositedTouchHandleDrawable::UpdateLayerPosition() { | 182 void CompositedTouchHandleDrawable::UpdateLayerPosition() { |
| 158 layer_->SetPosition(focal_position_ - focal_offset_from_origin_); | 183 layer_->SetPosition(focal_position_ - focal_offset_from_origin_); |
| 159 } | 184 } |
| 160 | 185 |
| 161 // static | 186 // static |
| 162 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) { | 187 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) { |
| 163 return RegisterNativesImpl(env); | 188 return RegisterNativesImpl(env); |
| 164 } | 189 } |
| 165 | 190 |
| 166 } // namespace content | 191 } // namespace content |
| OLD | NEW |