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

Side by Side Diff: ui/android/view_android.cc

Issue 2682593002: Refactor ContentViewClient (4/6) (Closed)
Patch Set: shell vad Created 3 years, 10 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
« no previous file with comments | « ui/android/view_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "ui/android/view_android.h" 5 #include "ui/android/view_android.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "base/android/jni_android.h" 9 #include "base/android/jni_android.h"
10 #include "base/android/jni_string.h"
10 #include "cc/layers/layer.h" 11 #include "cc/layers/layer.h"
11 #include "jni/ViewAndroidDelegate_jni.h" 12 #include "jni/ViewAndroidDelegate_jni.h"
12 #include "ui/android/window_android.h" 13 #include "ui/android/window_android.h"
13 #include "ui/display/display.h" 14 #include "ui/display/display.h"
14 #include "ui/display/screen.h" 15 #include "ui/display/screen.h"
16 #include "url/gurl.h"
15 17
16 namespace ui { 18 namespace ui {
17 19
20 using base::android::ConvertUTF8ToJavaString;
18 using base::android::JavaRef; 21 using base::android::JavaRef;
19 using base::android::ScopedJavaLocalRef; 22 using base::android::ScopedJavaLocalRef;
20 23
21 // ViewAndroid::ScopedAndroidView 24 // ViewAndroid::ScopedAndroidView
22 ViewAndroid::ScopedAnchorView::ScopedAnchorView( 25 ViewAndroid::ScopedAnchorView::ScopedAnchorView(
23 JNIEnv* env, 26 JNIEnv* env,
24 const JavaRef<jobject>& jview, 27 const JavaRef<jobject>& jview,
25 const JavaRef<jobject>& jdelegate) 28 const JavaRef<jobject>& jdelegate)
26 : view_(env, jview.obj()), delegate_(env, jdelegate.obj()) { 29 : view_(env, jview.obj()), delegate_(env, jdelegate.obj()) {
27 // If there's a view, then we need a delegate to remove it. 30 // If there's a view, then we need a delegate to remove it.
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 bool ViewAndroid::IsViewRoot() { 211 bool ViewAndroid::IsViewRoot() {
209 return GetViewRoot() == this; 212 return GetViewRoot() == this;
210 } 213 }
211 214
212 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext, 215 bool ViewAndroid::StartDragAndDrop(const JavaRef<jstring>& jtext,
213 const JavaRef<jobject>& jimage) { 216 const JavaRef<jobject>& jimage) {
214 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate()); 217 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
215 if (delegate.is_null()) 218 if (delegate.is_null())
216 return false; 219 return false;
217 JNIEnv* env = base::android::AttachCurrentThread(); 220 JNIEnv* env = base::android::AttachCurrentThread();
218 return Java_ViewAndroidDelegate_startDragAndDrop(env, delegate, jtext, 221 return Java_ViewAndroidDelegate_startDragAndDrop(env,
222 delegate,
223 jtext,
219 jimage); 224 jimage);
220 } 225 }
221 226
222 bool ViewAndroid::OnTouchEventInternal(const MotionEventData& event) { 227 bool ViewAndroid::OnTouchEventInternal(const MotionEventData& event) {
223 if (!children_.empty()) { 228 if (!children_.empty()) {
224 const MotionEventData& e = 229 const MotionEventData& e =
225 origin_.IsOrigin() ? event : event.Offset(-origin_.x(), -origin_.y()); 230 origin_.IsOrigin() ? event : event.Offset(-origin_.x(), -origin_.y());
226 231
227 for (auto it = children_.rbegin(); it != children_.rend(); ++it) { 232 for (auto it = children_.rbegin(); it != children_.rend(); ++it) {
228 bool matched = (*it)->match_parent_; 233 bool matched = (*it)->match_parent_;
229 if (!matched) { 234 if (!matched) {
230 gfx::Rect bound((*it)->origin_, (*it)->size_); 235 gfx::Rect bound((*it)->origin_, (*it)->size_);
231 matched = bound.Contains(e.GetX(), e.GetY()); 236 matched = bound.Contains(e.GetX(), e.GetY());
232 } 237 }
233 if (matched && (*it)->OnTouchEventInternal(e)) 238 if (matched && (*it)->OnTouchEventInternal(e))
234 return true; 239 return true;
235 } 240 }
236 } 241 }
237 242
238 if (client_ && client_->OnTouchEvent(event)) 243 if (client_ && client_->OnTouchEvent(event))
239 return true; 244 return true;
240 245
241 return false; 246 return false;
242 } 247 }
243 248
249 void ViewAndroid::OnBackgroundColorChanged(unsigned int color) {
250 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
251 if (delegate.is_null())
252 return;
253 JNIEnv* env = base::android::AttachCurrentThread();
254 Java_ViewAndroidDelegate_onBackgroundColorChanged(env,
255 delegate,
256 color);
257 }
258
259 void ViewAndroid::OnTopControlsChanged(float top_controls_offset,
260 float top_content_offset) {
261 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
262 if (delegate.is_null())
263 return;
264 JNIEnv* env = base::android::AttachCurrentThread();
265 Java_ViewAndroidDelegate_onTopControlsChanged(env,
266 delegate,
267 top_controls_offset,
268 top_content_offset);
269 }
270
271 void ViewAndroid::OnBottomControlsChanged(float bottom_controls_offset,
272 float bottom_content_offset) {
273 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
274 if (delegate.is_null())
275 return;
276 JNIEnv* env = base::android::AttachCurrentThread();
277 Java_ViewAndroidDelegate_onBottomControlsChanged(env,
278 delegate,
279 bottom_controls_offset,
280 bottom_content_offset);
281 }
282
283 void ViewAndroid::StartContentIntent(const GURL& content_url,
284 bool is_main_frame) {
285 ScopedJavaLocalRef<jobject> delegate(GetViewAndroidDelegate());
286 if (delegate.is_null())
287 return;
288 JNIEnv* env = base::android::AttachCurrentThread();
289 ScopedJavaLocalRef<jstring> jcontent_url =
290 ConvertUTF8ToJavaString(env, content_url.spec());
291 Java_ViewAndroidDelegate_onStartContentIntent(env,
292 delegate,
293 jcontent_url,
294 is_main_frame);
295
296 }
244 } // namespace ui 297 } // namespace ui
OLDNEW
« no previous file with comments | « ui/android/view_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698