OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/web_contents/web_contents_android.h" | 5 #include "content/browser/web_contents/web_contents_android.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_array.h" | 8 #include "base/android/jni_array.h" |
9 #include "base/android/jni_string.h" | 9 #include "base/android/jni_string.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
55 const base::Value* result) { | 55 const base::Value* result) { |
56 JNIEnv* env = base::android::AttachCurrentThread(); | 56 JNIEnv* env = base::android::AttachCurrentThread(); |
57 std::string json; | 57 std::string json; |
58 base::JSONWriter::Write(*result, &json); | 58 base::JSONWriter::Write(*result, &json); |
59 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); | 59 ScopedJavaLocalRef<jstring> j_json = ConvertUTF8ToJavaString(env, json); |
60 Java_WebContentsImpl_onEvaluateJavaScriptResult( | 60 Java_WebContentsImpl_onEvaluateJavaScriptResult( |
61 env, j_json.obj(), callback.obj()); | 61 env, j_json.obj(), callback.obj()); |
62 } | 62 } |
63 | 63 |
64 ScopedJavaLocalRef<jobject> WalkAXTreeDepthFirst(JNIEnv* env, | 64 ScopedJavaLocalRef<jobject> WalkAXTreeDepthFirst(JNIEnv* env, |
65 BrowserAccessibilityAndroid* node, float scale_factor) { | 65 BrowserAccessibilityAndroid* node, float scale_factor, |
| 66 float y_offset, float x_scroll) { |
66 ScopedJavaLocalRef<jstring> j_text = | 67 ScopedJavaLocalRef<jstring> j_text = |
67 ConvertUTF16ToJavaString(env, node->GetText()); | 68 ConvertUTF16ToJavaString(env, node->GetText()); |
68 ScopedJavaLocalRef<jstring> j_class = | 69 ScopedJavaLocalRef<jstring> j_class = |
69 ConvertUTF8ToJavaString(env, node->GetClassName()); | 70 ConvertUTF8ToJavaString(env, node->GetClassName()); |
70 const gfx::Rect& location = node->GetLocalBoundsRect(); | 71 const gfx::Rect& location = node->GetLocalBoundsRect(); |
71 // The style attributes exists and valid if size attribute exists. Otherwise, | 72 // The style attributes exists and valid if size attribute exists. Otherwise, |
72 // they are not. Use a negative size information to indicate the existence | 73 // they are not. Use a negative size information to indicate the existence |
73 // of style information. | 74 // of style information. |
74 float size = -1.0; | 75 float size = -1.0; |
75 int color = 0; | 76 int color = 0; |
76 int bgcolor = 0; | 77 int bgcolor = 0; |
77 int text_style = 0; | 78 int text_style = 0; |
78 if (node->HasFloatAttribute(ui::AX_ATTR_FONT_SIZE)) { | 79 if (node->HasFloatAttribute(ui::AX_ATTR_FONT_SIZE)) { |
79 color = node->GetIntAttribute(ui::AX_ATTR_COLOR); | 80 color = node->GetIntAttribute(ui::AX_ATTR_COLOR); |
80 bgcolor = node->GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR); | 81 bgcolor = node->GetIntAttribute(ui::AX_ATTR_BACKGROUND_COLOR); |
81 size = node->GetFloatAttribute(ui::AX_ATTR_FONT_SIZE); | 82 size = node->GetFloatAttribute(ui::AX_ATTR_FONT_SIZE); |
82 text_style = node->GetIntAttribute(ui::AX_ATTR_TEXT_STYLE); | 83 text_style = node->GetIntAttribute(ui::AX_ATTR_TEXT_STYLE); |
83 } | 84 } |
84 ScopedJavaLocalRef<jobject> j_node = | 85 ScopedJavaLocalRef<jobject> j_node = |
85 Java_WebContentsImpl_createAccessibilitySnapshotNode(env, | 86 Java_WebContentsImpl_createAccessibilitySnapshotNode(env, |
86 scale_factor * location.x(), scale_factor * location.y(), | 87 scale_factor * (location.x() - x_scroll), |
| 88 scale_factor * location.y() + y_offset, |
87 scale_factor * node->GetScrollX(), scale_factor * node->GetScrollY(), | 89 scale_factor * node->GetScrollX(), scale_factor * node->GetScrollY(), |
88 scale_factor * location.width(), scale_factor * location.height(), | 90 scale_factor * location.width(), scale_factor * location.height(), |
89 j_text.obj(), color, bgcolor, scale_factor * size, text_style, | 91 j_text.obj(), color, bgcolor, scale_factor * size, text_style, |
90 j_class.obj()); | 92 j_class.obj()); |
91 | 93 |
92 for(uint32 i = 0; i < node->PlatformChildCount(); i++) { | 94 for(uint32 i = 0; i < node->PlatformChildCount(); i++) { |
93 BrowserAccessibilityAndroid* child = | 95 BrowserAccessibilityAndroid* child = |
94 static_cast<BrowserAccessibilityAndroid*>( | 96 static_cast<BrowserAccessibilityAndroid*>( |
95 node->PlatformGetChild(i)); | 97 node->PlatformGetChild(i)); |
96 Java_WebContentsImpl_addAccessibilityNodeAsChild(env, | 98 Java_WebContentsImpl_addAccessibilityNodeAsChild(env, |
97 j_node.obj(), WalkAXTreeDepthFirst(env, child, scale_factor).obj()); | 99 j_node.obj(), WalkAXTreeDepthFirst(env, child, scale_factor, y_offset, |
| 100 x_scroll).obj()); |
98 } | 101 } |
99 return j_node; | 102 return j_node; |
100 } | 103 } |
101 | 104 |
102 // Walks over the AXTreeUpdate and creates a light weight snapshot. | 105 // Walks over the AXTreeUpdate and creates a light weight snapshot. |
103 void AXTreeSnapshotCallback(const ScopedJavaGlobalRef<jobject>& callback, | 106 void AXTreeSnapshotCallback(const ScopedJavaGlobalRef<jobject>& callback, |
104 float scale_factor, | 107 float scale_factor, |
| 108 float y_offset, |
| 109 float x_scroll, |
105 const ui::AXTreeUpdate& result) { | 110 const ui::AXTreeUpdate& result) { |
106 JNIEnv* env = base::android::AttachCurrentThread(); | 111 JNIEnv* env = base::android::AttachCurrentThread(); |
107 if (result.nodes.empty()) { | 112 if (result.nodes.empty()) { |
108 Java_WebContentsImpl_onAccessibilitySnapshot(env, nullptr, callback.obj()); | 113 Java_WebContentsImpl_onAccessibilitySnapshot(env, nullptr, callback.obj()); |
109 return; | 114 return; |
110 } | 115 } |
111 scoped_ptr<BrowserAccessibilityManagerAndroid> manager( | 116 scoped_ptr<BrowserAccessibilityManagerAndroid> manager( |
112 static_cast<BrowserAccessibilityManagerAndroid*>( | 117 static_cast<BrowserAccessibilityManagerAndroid*>( |
113 BrowserAccessibilityManager::Create(result, nullptr))); | 118 BrowserAccessibilityManager::Create(result, nullptr))); |
114 manager->set_prune_tree_for_screen_reader(false); | 119 manager->set_prune_tree_for_screen_reader(false); |
115 BrowserAccessibilityAndroid* root = | 120 BrowserAccessibilityAndroid* root = |
116 static_cast<BrowserAccessibilityAndroid*>(manager->GetRoot()); | 121 static_cast<BrowserAccessibilityAndroid*>(manager->GetRoot()); |
117 ScopedJavaLocalRef<jobject> j_root = | 122 ScopedJavaLocalRef<jobject> j_root = |
118 WalkAXTreeDepthFirst(env, root, scale_factor); | 123 WalkAXTreeDepthFirst(env, root, scale_factor, y_offset, x_scroll); |
119 Java_WebContentsImpl_onAccessibilitySnapshot( | 124 Java_WebContentsImpl_onAccessibilitySnapshot( |
120 env, j_root.obj(), callback.obj()); | 125 env, j_root.obj(), callback.obj()); |
121 } | 126 } |
122 | 127 |
123 void ReleaseAllMediaPlayers(WebContents* web_contents, | 128 void ReleaseAllMediaPlayers(WebContents* web_contents, |
124 RenderFrameHost* render_frame_host) { | 129 RenderFrameHost* render_frame_host) { |
125 BrowserMediaPlayerManager* manager = | 130 BrowserMediaPlayerManager* manager = |
126 static_cast<WebContentsImpl*>(web_contents)-> | 131 static_cast<WebContentsImpl*>(web_contents)-> |
127 media_web_contents_observer()->GetMediaPlayerManager( | 132 media_web_contents_observer()->GetMediaPlayerManager( |
128 render_frame_host); | 133 render_frame_host); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
453 return static_cast<WebContentsImpl*>(web_contents_)-> | 458 return static_cast<WebContentsImpl*>(web_contents_)-> |
454 HasAccessedInitialDocument(); | 459 HasAccessedInitialDocument(); |
455 } | 460 } |
456 | 461 |
457 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, jobject obj) { | 462 jint WebContentsAndroid::GetThemeColor(JNIEnv* env, jobject obj) { |
458 return web_contents_->GetThemeColor(); | 463 return web_contents_->GetThemeColor(); |
459 } | 464 } |
460 | 465 |
461 void WebContentsAndroid::RequestAccessibilitySnapshot(JNIEnv* env, | 466 void WebContentsAndroid::RequestAccessibilitySnapshot(JNIEnv* env, |
462 jobject obj, | 467 jobject obj, |
463 jobject callback) { | 468 jobject callback, |
| 469 jfloat y_offset, |
| 470 jfloat x_scroll) { |
464 // Secure the Java callback in a scoped object and give ownership of it to the | 471 // Secure the Java callback in a scoped object and give ownership of it to the |
465 // base::Callback. | 472 // base::Callback. |
466 ScopedJavaGlobalRef<jobject> j_callback; | 473 ScopedJavaGlobalRef<jobject> j_callback; |
467 j_callback.Reset(env, callback); | 474 j_callback.Reset(env, callback); |
468 gfx::DeviceDisplayInfo device_info; | 475 gfx::DeviceDisplayInfo device_info; |
469 ContentViewCoreImpl* contentViewCore = | 476 ContentViewCoreImpl* contentViewCore = |
470 ContentViewCoreImpl::FromWebContents(web_contents_); | 477 ContentViewCoreImpl::FromWebContents(web_contents_); |
471 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = | 478 WebContentsImpl::AXTreeSnapshotCallback snapshot_callback = |
472 base::Bind(&AXTreeSnapshotCallback, j_callback, | 479 base::Bind(&AXTreeSnapshotCallback, j_callback, |
473 contentViewCore->GetScaleFactor()); | 480 contentViewCore->GetScaleFactor(), y_offset, x_scroll); |
474 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( | 481 static_cast<WebContentsImpl*>(web_contents_)->RequestAXTreeSnapshot( |
475 snapshot_callback); | 482 snapshot_callback); |
476 } | 483 } |
477 | 484 |
478 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { | 485 void WebContentsAndroid::ResumeMediaSession(JNIEnv* env, jobject obj) { |
479 web_contents_->ResumeMediaSession(); | 486 web_contents_->ResumeMediaSession(); |
480 } | 487 } |
481 | 488 |
482 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { | 489 void WebContentsAndroid::SuspendMediaSession(JNIEnv* env, jobject obj) { |
483 web_contents_->SuspendMediaSession(); | 490 web_contents_->SuspendMediaSession(); |
484 } | 491 } |
485 | 492 |
486 } // namespace content | 493 } // namespace content |
OLD | NEW |