Chromium Code Reviews| 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 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 94 DetachLayer(); | 94 DetachLayer(); |
| 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::SetLayout( |
| 105 ui::TouchHandleOrientation orientation) { | 105 const gfx::PointF& position, |
| 106 ui::TouchHandleOrientation orientation, | |
| 107 bool mirror_vertical, | |
| 108 bool mirror_horizontal, | |
| 109 bool mirror_changed) { | |
| 106 DCHECK(layer_->parent()); | 110 DCHECK(layer_->parent()); |
| 111 bool orientation_changed = orientation_ != orientation; | |
| 112 focal_position_ = gfx::ScalePoint(position, dpi_scale_); | |
| 113 | |
| 107 orientation_ = orientation; | 114 orientation_ = orientation; |
| 108 | 115 |
| 109 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); | 116 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); |
|
jdduke (slow)
2015/06/03 18:59:00
Can we move the bitmap/bitmap_height/bitmap_width
AviD
2015/06/08 08:51:37
Done.
| |
| 110 layer_->SetBitmap(bitmap); | 117 const int bitmap_height = bitmap.height(); |
| 111 layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); | 118 const int bitmap_width = bitmap.width(); |
| 112 | 119 |
| 120 if (orientation_changed) { | |
| 121 layer_->SetBitmap(bitmap); | |
| 122 layer_->SetBounds(gfx::Size(bitmap_width, bitmap_height)); | |
| 123 } | |
| 124 | |
| 125 // Invert about X and Y axis based on the mirror values | |
| 126 if (mirror_changed) { | |
| 127 gfx::Transform transform; | |
| 128 float scale_x = mirror_horizontal ? -1.f : 1.f; | |
| 129 float scale_y = mirror_vertical ? -1.f : 1.f; | |
| 130 | |
| 131 layer_->SetTransformOrigin( | |
| 132 gfx::Point3F(bitmap_width * 0.5f, bitmap_height * 0.5f, 0)); | |
| 133 transform.Scale(scale_x, scale_y); | |
| 134 layer_->SetTransform(transform); | |
| 135 } | |
| 136 | |
| 137 // Set the Focal offsets for the composited handle layer | |
| 138 // based on the orientation | |
| 139 int focal_offset_x = 0; | |
| 140 int focal_offset_y = mirror_vertical ? bitmap_height : 0; | |
| 113 switch (orientation_) { | 141 switch (orientation_) { |
| 114 case ui::TouchHandleOrientation::LEFT: | 142 case ui::TouchHandleOrientation::LEFT: |
| 115 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); | 143 focal_offset_x = |
| 144 mirror_horizontal ? bitmap_width * 0.25f : bitmap_width * 0.75f; | |
| 116 break; | 145 break; |
| 117 case ui::TouchHandleOrientation::RIGHT: | 146 case ui::TouchHandleOrientation::RIGHT: |
| 118 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); | 147 focal_offset_x = |
| 148 mirror_horizontal ? bitmap_width * 0.75f : bitmap_width * 0.25f; | |
| 119 break; | 149 break; |
| 120 case ui::TouchHandleOrientation::CENTER: | 150 case ui::TouchHandleOrientation::CENTER: |
| 121 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); | 151 focal_offset_x = bitmap_width * 0.5f; |
| 122 break; | 152 break; |
| 123 case ui::TouchHandleOrientation::UNDEFINED: | 153 case ui::TouchHandleOrientation::UNDEFINED: |
| 124 NOTREACHED() << "Invalid touch handle orientation."; | 154 NOTREACHED() << "Invalid touch handle orientation."; |
| 125 break; | 155 break; |
| 126 }; | 156 }; |
| 127 | 157 |
| 158 focal_offset_from_origin_ = gfx::Vector2dF(focal_offset_x, focal_offset_y); | |
| 128 UpdateLayerPosition(); | 159 UpdateLayerPosition(); |
| 129 } | 160 } |
| 130 | 161 |
| 131 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { | 162 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { |
| 132 DCHECK(layer_->parent()); | 163 DCHECK(layer_->parent()); |
| 133 alpha = std::max(0.f, std::min(1.f, alpha)); | 164 alpha = std::max(0.f, std::min(1.f, alpha)); |
| 134 bool hidden = alpha <= 0; | 165 bool hidden = alpha <= 0; |
| 135 layer_->SetOpacity(alpha); | 166 layer_->SetOpacity(alpha); |
| 136 layer_->SetHideLayerAndSubtree(hidden); | 167 layer_->SetHideLayerAndSubtree(hidden); |
| 137 } | 168 } |
| 138 | 169 |
| 139 void CompositedTouchHandleDrawable::SetFocus(const gfx::PointF& position) { | |
| 140 DCHECK(layer_->parent()); | |
| 141 focal_position_ = gfx::ScalePoint(position, dpi_scale_); | |
| 142 UpdateLayerPosition(); | |
| 143 } | |
| 144 | |
| 145 gfx::RectF CompositedTouchHandleDrawable::GetVisibleBounds() const { | 170 gfx::RectF CompositedTouchHandleDrawable::GetVisibleBounds() const { |
| 146 return gfx::ScaleRect(gfx::RectF(layer_->position().x(), | 171 return gfx::ScaleRect(gfx::RectF(layer_->position().x(), |
| 147 layer_->position().y(), | 172 layer_->position().y(), |
| 148 layer_->bounds().width(), | 173 layer_->bounds().width(), |
| 149 layer_->bounds().height()), | 174 layer_->bounds().height()), |
| 150 1.f / dpi_scale_); | 175 1.f / dpi_scale_); |
| 151 } | 176 } |
| 152 | 177 |
| 153 void CompositedTouchHandleDrawable::DetachLayer() { | 178 void CompositedTouchHandleDrawable::DetachLayer() { |
| 154 layer_->RemoveFromParent(); | 179 layer_->RemoveFromParent(); |
| 155 } | 180 } |
| 156 | 181 |
| 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 |