| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 Java_HandleViewResources_getCenterHandleBitmap(env, context)); | 46 Java_HandleViewResources_getCenterHandleBitmap(env, context)); |
| 47 | 47 |
| 48 left_bitmap_.setImmutable(); | 48 left_bitmap_.setImmutable(); |
| 49 right_bitmap_.setImmutable(); | 49 right_bitmap_.setImmutable(); |
| 50 center_bitmap_.setImmutable(); | 50 center_bitmap_.setImmutable(); |
| 51 } | 51 } |
| 52 | 52 |
| 53 const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { | 53 const SkBitmap& GetBitmap(ui::TouchHandleOrientation orientation) { |
| 54 DCHECK(loaded_); | 54 DCHECK(loaded_); |
| 55 switch (orientation) { | 55 switch (orientation) { |
| 56 case ui::TOUCH_HANDLE_LEFT: | 56 case ui::TouchHandleOrientation::LEFT: |
| 57 return left_bitmap_; | 57 return left_bitmap_; |
| 58 case ui::TOUCH_HANDLE_RIGHT: | 58 case ui::TouchHandleOrientation::RIGHT: |
| 59 return right_bitmap_; | 59 return right_bitmap_; |
| 60 case ui::TOUCH_HANDLE_CENTER: | 60 case ui::TouchHandleOrientation::CENTER: |
| 61 return center_bitmap_; | 61 return center_bitmap_; |
| 62 case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: | 62 case ui::TouchHandleOrientation::UNDEFINED: |
| 63 NOTREACHED() << "Invalid touch handle orientation."; | 63 NOTREACHED() << "Invalid touch handle orientation."; |
| 64 }; | 64 }; |
| 65 return center_bitmap_; | 65 return center_bitmap_; |
| 66 } | 66 } |
| 67 | 67 |
| 68 private: | 68 private: |
| 69 SkBitmap left_bitmap_; | 69 SkBitmap left_bitmap_; |
| 70 SkBitmap right_bitmap_; | 70 SkBitmap right_bitmap_; |
| 71 SkBitmap center_bitmap_; | 71 SkBitmap center_bitmap_; |
| 72 bool loaded_; | 72 bool loaded_; |
| 73 | 73 |
| 74 DISALLOW_COPY_AND_ASSIGN(HandleResources); | 74 DISALLOW_COPY_AND_ASSIGN(HandleResources); |
| 75 }; | 75 }; |
| 76 | 76 |
| 77 base::LazyInstance<HandleResources>::Leaky g_selection_resources; | 77 base::LazyInstance<HandleResources>::Leaky g_selection_resources; |
| 78 | 78 |
| 79 } // namespace | 79 } // namespace |
| 80 | 80 |
| 81 CompositedTouchHandleDrawable::CompositedTouchHandleDrawable( | 81 CompositedTouchHandleDrawable::CompositedTouchHandleDrawable( |
| 82 cc::Layer* root_layer, | 82 cc::Layer* root_layer, |
| 83 float dpi_scale, | 83 float dpi_scale, |
| 84 jobject context) | 84 jobject context) |
| 85 : dpi_scale_(dpi_scale), | 85 : dpi_scale_(dpi_scale), |
| 86 orientation_(ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED), | 86 orientation_(ui::TouchHandleOrientation::UNDEFINED), |
| 87 layer_(cc::UIResourceLayer::Create()) { | 87 layer_(cc::UIResourceLayer::Create()) { |
| 88 g_selection_resources.Get().LoadIfNecessary(context); | 88 g_selection_resources.Get().LoadIfNecessary(context); |
| 89 DCHECK(root_layer); | 89 DCHECK(root_layer); |
| 90 root_layer->AddChild(layer_.get()); | 90 root_layer->AddChild(layer_.get()); |
| 91 } | 91 } |
| 92 | 92 |
| 93 CompositedTouchHandleDrawable::~CompositedTouchHandleDrawable() { | 93 CompositedTouchHandleDrawable::~CompositedTouchHandleDrawable() { |
| 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::SetOrientation( |
| 105 ui::TouchHandleOrientation orientation) { | 105 ui::TouchHandleOrientation orientation) { |
| 106 DCHECK(layer_->parent()); | 106 DCHECK(layer_->parent()); |
| 107 orientation_ = orientation; | 107 orientation_ = orientation; |
| 108 | 108 |
| 109 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); | 109 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); |
| 110 layer_->SetBitmap(bitmap); | 110 layer_->SetBitmap(bitmap); |
| 111 layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); | 111 layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); |
| 112 | 112 |
| 113 switch (orientation_) { | 113 switch (orientation_) { |
| 114 case ui::TOUCH_HANDLE_LEFT: | 114 case ui::TouchHandleOrientation::LEFT: |
| 115 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); | 115 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); |
| 116 break; | 116 break; |
| 117 case ui::TOUCH_HANDLE_RIGHT: | 117 case ui::TouchHandleOrientation::RIGHT: |
| 118 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); | 118 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); |
| 119 break; | 119 break; |
| 120 case ui::TOUCH_HANDLE_CENTER: | 120 case ui::TouchHandleOrientation::CENTER: |
| 121 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); | 121 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); |
| 122 break; | 122 break; |
| 123 case ui::TOUCH_HANDLE_ORIENTATION_UNDEFINED: | 123 case ui::TouchHandleOrientation::UNDEFINED: |
| 124 NOTREACHED() << "Invalid touch handle orientation."; | 124 NOTREACHED() << "Invalid touch handle orientation."; |
| 125 break; | 125 break; |
| 126 }; | 126 }; |
| 127 | 127 |
| 128 UpdateLayerPosition(); | 128 UpdateLayerPosition(); |
| 129 } | 129 } |
| 130 | 130 |
| 131 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { | 131 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { |
| 132 DCHECK(layer_->parent()); | 132 DCHECK(layer_->parent()); |
| 133 alpha = std::max(0.f, std::min(1.f, alpha)); | 133 alpha = std::max(0.f, std::min(1.f, alpha)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 void CompositedTouchHandleDrawable::UpdateLayerPosition() { | 157 void CompositedTouchHandleDrawable::UpdateLayerPosition() { |
| 158 layer_->SetPosition(focal_position_ - focal_offset_from_origin_); | 158 layer_->SetPosition(focal_position_ - focal_offset_from_origin_); |
| 159 } | 159 } |
| 160 | 160 |
| 161 // static | 161 // static |
| 162 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) { | 162 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) { |
| 163 return RegisterNativesImpl(env); | 163 return RegisterNativesImpl(env); |
| 164 } | 164 } |
| 165 | 165 |
| 166 } // namespace content | 166 } // namespace content |
| OLD | NEW |