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

Side by Side 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: cleanup Created 5 years, 7 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 unified diff | Download patch
OLDNEW
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
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) {
106 DCHECK(layer_->parent()); 109 DCHECK(layer_->parent());
110 focal_position_ = gfx::ScalePoint(position, dpi_scale_);
111
107 orientation_ = orientation; 112 orientation_ = orientation;
108 113
109 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation); 114 const SkBitmap& bitmap = g_selection_resources.Get().GetBitmap(orientation);
115 const int bitmap_height = bitmap.height();
116 const int bitmap_width = bitmap.width();
117 int focal_offset_x = 0;
118 int focal_offset_y = mirror_vertical ? bitmap_height : 0;
119
110 layer_->SetBitmap(bitmap); 120 layer_->SetBitmap(bitmap);
jdduke (slow) 2015/05/11 15:40:15 Hmm, it looks like UIResourceLayer doesn't cache t
AviD 2015/05/19 16:26:27 Done. We save orientation_ here, I have used that
111 layer_->SetBounds(gfx::Size(bitmap.width(), bitmap.height())); 121 layer_->SetBounds(gfx::Size(bitmap_width, bitmap_height));
122
123 // Invert about X and Y axis based on the mirror values
124 gfx::Transform transform;
125 float scale_x = mirror_horizontal ? -1.f : 1.f;
126 float scale_y = mirror_vertical ? -1.f : 1.f;
127
128 layer_->SetTransformOrigin(
129 gfx::Point3F(bitmap_width * 0.5f, bitmap_height * 0.5f, 0));
130 transform.Scale(scale_x, scale_y);
131 layer_->SetTransform(transform);
112 132
113 switch (orientation_) { 133 switch (orientation_) {
jdduke (slow) 2015/05/11 15:40:15 Hmm, to save on code can you do: focal_offset_x =
AviD 2015/05/19 16:26:27 Done.
114 case ui::TouchHandleOrientation::LEFT: 134 case ui::TouchHandleOrientation::LEFT:
115 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.75f, 0); 135 focal_offset_x =
136 mirror_horizontal ? bitmap_width * 0.25f : bitmap_width * 0.75f;
137 focal_offset_from_origin_ =
138 gfx::Vector2dF(focal_offset_x, focal_offset_y);
116 break; 139 break;
117 case ui::TouchHandleOrientation::RIGHT: 140 case ui::TouchHandleOrientation::RIGHT:
118 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.25f, 0); 141 focal_offset_x =
142 mirror_horizontal ? bitmap_width * 0.75f : bitmap_width * 0.25f;
143 focal_offset_from_origin_ =
144 gfx::Vector2dF(focal_offset_x, focal_offset_y);
119 break; 145 break;
120 case ui::TouchHandleOrientation::CENTER: 146 case ui::TouchHandleOrientation::CENTER:
121 focal_offset_from_origin_ = gfx::Vector2dF(bitmap.width() * 0.5f, 0); 147 focal_offset_x = bitmap_width * 0.5f;
148 focal_offset_from_origin_ =
149 gfx::Vector2dF(focal_offset_x, focal_offset_y);
122 break; 150 break;
123 case ui::TouchHandleOrientation::UNDEFINED: 151 case ui::TouchHandleOrientation::UNDEFINED:
124 NOTREACHED() << "Invalid touch handle orientation."; 152 NOTREACHED() << "Invalid touch handle orientation.";
125 break; 153 break;
126 }; 154 };
127 155
128 UpdateLayerPosition(); 156 UpdateLayerPosition();
129 } 157 }
130 158
131 void CompositedTouchHandleDrawable::SetAlpha(float alpha) { 159 void CompositedTouchHandleDrawable::SetAlpha(float alpha) {
132 DCHECK(layer_->parent()); 160 DCHECK(layer_->parent());
133 alpha = std::max(0.f, std::min(1.f, alpha)); 161 alpha = std::max(0.f, std::min(1.f, alpha));
134 bool hidden = alpha <= 0; 162 bool hidden = alpha <= 0;
135 layer_->SetOpacity(alpha); 163 layer_->SetOpacity(alpha);
136 layer_->SetHideLayerAndSubtree(hidden); 164 layer_->SetHideLayerAndSubtree(hidden);
137 } 165 }
138 166
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 { 167 gfx::RectF CompositedTouchHandleDrawable::GetVisibleBounds() const {
146 return gfx::ScaleRect(gfx::RectF(layer_->position().x(), 168 return gfx::ScaleRect(gfx::RectF(layer_->position().x(),
147 layer_->position().y(), 169 layer_->position().y(),
148 layer_->bounds().width(), 170 layer_->bounds().width(),
149 layer_->bounds().height()), 171 layer_->bounds().height()),
150 1.f / dpi_scale_); 172 1.f / dpi_scale_);
151 } 173 }
152 174
153 void CompositedTouchHandleDrawable::DetachLayer() { 175 void CompositedTouchHandleDrawable::DetachLayer() {
154 layer_->RemoveFromParent(); 176 layer_->RemoveFromParent();
155 } 177 }
156 178
157 void CompositedTouchHandleDrawable::UpdateLayerPosition() { 179 void CompositedTouchHandleDrawable::UpdateLayerPosition() {
158 layer_->SetPosition(focal_position_ - focal_offset_from_origin_); 180 layer_->SetPosition(focal_position_ - focal_offset_from_origin_);
jdduke (slow) 2015/05/11 15:40:15 Since this is only called in one place now, I'd be
AviD 2015/05/19 16:26:27 It is currently being called from SetEnabled() too
159 } 181 }
160 182
161 // static 183 // static
162 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) { 184 bool CompositedTouchHandleDrawable::RegisterHandleViewResources(JNIEnv* env) {
163 return RegisterNativesImpl(env); 185 return RegisterNativesImpl(env);
164 } 186 }
165 187
166 } // namespace content 188 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698