| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 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 "android_webview/native/aw_settings.h" | 5 #include "android_webview/native/aw_settings.h" |
| 6 | 6 |
| 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" | 7 #include "android_webview/browser/renderer_host/aw_render_view_host_ext.h" |
| 8 #include "android_webview/native/aw_contents.h" | 8 #include "android_webview/native/aw_contents.h" |
| 9 #include "jni/AwSettings_jni.h" | 9 #include "jni/AwSettings_jni.h" |
| 10 #include "webkit/glue/webkit_glue.h" | 10 #include "webkit/glue/webkit_glue.h" |
| 11 | 11 |
| 12 namespace android_webview { | 12 namespace android_webview { |
| 13 | 13 |
| 14 AwSettings::AwSettings(JNIEnv* env, jobject obj) | 14 AwSettings::AwSettings(JNIEnv* env, jobject obj) |
| 15 : java_ref_(env, obj), | 15 : java_ref_(env, obj), |
| 16 enable_fixed_layout_(false), | |
| 17 initial_page_scale_percent_(0), | 16 initial_page_scale_percent_(0), |
| 18 text_zoom_percent_(100) { | 17 text_zoom_percent_(100) { |
| 19 } | 18 } |
| 20 | 19 |
| 21 AwSettings::~AwSettings() { | 20 AwSettings::~AwSettings() { |
| 22 } | 21 } |
| 23 | 22 |
| 24 void AwSettings::Destroy(JNIEnv* env, jobject obj) { | 23 void AwSettings::Destroy(JNIEnv* env, jobject obj) { |
| 25 delete this; | 24 delete this; |
| 26 } | 25 } |
| 27 | 26 |
| 28 AwRenderViewHostExt* AwSettings::GetAwRenderViewHostExt() { | 27 AwRenderViewHostExt* AwSettings::GetAwRenderViewHostExt() { |
| 29 if (!web_contents()) return NULL; | 28 if (!web_contents()) return NULL; |
| 30 AwContents* contents = AwContents::FromWebContents(web_contents()); | 29 AwContents* contents = AwContents::FromWebContents(web_contents()); |
| 31 if (!contents) return NULL; | 30 if (!contents) return NULL; |
| 32 return contents->render_view_host_ext(); | 31 return contents->render_view_host_ext(); |
| 33 } | 32 } |
| 34 | 33 |
| 35 void AwSettings::ResetScrollAndScaleState(JNIEnv* env, jobject obj) { | 34 void AwSettings::ResetScrollAndScaleState(JNIEnv* env, jobject obj) { |
| 36 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | 35 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); |
| 37 if (!rvhe) return; | 36 if (!rvhe) return; |
| 38 rvhe->ResetScrollAndScaleState(); | 37 rvhe->ResetScrollAndScaleState(); |
| 39 } | 38 } |
| 40 | 39 |
| 41 void AwSettings::SetEnableFixedLayoutMode( | |
| 42 JNIEnv* env, jobject obj, jboolean enabled) { | |
| 43 if (enable_fixed_layout_ == enabled) return; | |
| 44 enable_fixed_layout_ = enabled; | |
| 45 UpdateEnableFixedLayoutMode(); | |
| 46 } | |
| 47 | |
| 48 void AwSettings::SetInitialPageScale( | 40 void AwSettings::SetInitialPageScale( |
| 49 JNIEnv* env, jobject obj, jfloat page_scale_percent) { | 41 JNIEnv* env, jobject obj, jfloat page_scale_percent) { |
| 50 if (initial_page_scale_percent_ == page_scale_percent) return; | 42 if (initial_page_scale_percent_ == page_scale_percent) return; |
| 51 initial_page_scale_percent_ = page_scale_percent; | 43 initial_page_scale_percent_ = page_scale_percent; |
| 52 UpdateInitialPageScale(); | 44 UpdateInitialPageScale(); |
| 53 } | 45 } |
| 54 | 46 |
| 55 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) { | 47 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) { |
| 56 if (text_zoom_percent_ == text_zoom_percent) return; | 48 if (text_zoom_percent_ == text_zoom_percent) return; |
| 57 text_zoom_percent_ = text_zoom_percent; | 49 text_zoom_percent_ = text_zoom_percent; |
| 58 UpdateTextZoom(); | 50 UpdateTextZoom(); |
| 59 } | 51 } |
| 60 | 52 |
| 61 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint web_contents) { | 53 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint web_contents) { |
| 62 Observe(reinterpret_cast<content::WebContents*>(web_contents)); | 54 Observe(reinterpret_cast<content::WebContents*>(web_contents)); |
| 63 } | 55 } |
| 64 | 56 |
| 65 | |
| 66 void AwSettings::UpdateEnableFixedLayoutMode() { | |
| 67 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | |
| 68 if (!rvhe) return; | |
| 69 rvhe->SetEnableFixedLayoutMode(enable_fixed_layout_); | |
| 70 } | |
| 71 | |
| 72 void AwSettings::UpdateInitialPageScale() { | 57 void AwSettings::UpdateInitialPageScale() { |
| 73 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | 58 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); |
| 74 if (!rvhe) return; | 59 if (!rvhe) return; |
| 75 if (initial_page_scale_percent_ == 0) { | 60 if (initial_page_scale_percent_ == 0) { |
| 76 rvhe->SetInitialPageScale(-1); | 61 rvhe->SetInitialPageScale(-1); |
| 77 } else { | 62 } else { |
| 78 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f); | 63 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f); |
| 79 } | 64 } |
| 80 } | 65 } |
| 81 | 66 |
| 82 void AwSettings::UpdateTextZoom() { | 67 void AwSettings::UpdateTextZoom() { |
| 83 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); | 68 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); |
| 84 if (!rvhe) return; | 69 if (!rvhe) return; |
| 85 if (text_zoom_percent_ > 0) { | 70 if (text_zoom_percent_ > 0) { |
| 86 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel( | 71 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel( |
| 87 text_zoom_percent_ / 100.0f)); | 72 text_zoom_percent_ / 100.0f)); |
| 88 } else { | 73 } else { |
| 89 // Use the default zoom level value when Text Autosizer is turned on. | 74 // Use the default zoom level value when Text Autosizer is turned on. |
| 90 rvhe->SetTextZoomLevel(0); | 75 rvhe->SetTextZoomLevel(0); |
| 91 } | 76 } |
| 92 } | 77 } |
| 93 | 78 |
| 94 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) { | 79 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) { |
| 95 UpdateEnableFixedLayoutMode(); | |
| 96 UpdateInitialPageScale(); | 80 UpdateInitialPageScale(); |
| 97 UpdateTextZoom(); | 81 UpdateTextZoom(); |
| 98 } | 82 } |
| 99 | 83 |
| 100 static jint Init(JNIEnv* env, | 84 static jint Init(JNIEnv* env, |
| 101 jobject obj, | 85 jobject obj, |
| 102 jint web_contents) { | 86 jint web_contents) { |
| 103 AwSettings* settings = new AwSettings(env, obj); | 87 AwSettings* settings = new AwSettings(env, obj); |
| 104 settings->SetWebContents(env, obj, web_contents); | 88 settings->SetWebContents(env, obj, web_contents); |
| 105 return reinterpret_cast<jint>(settings); | 89 return reinterpret_cast<jint>(settings); |
| 106 } | 90 } |
| 107 | 91 |
| 108 bool RegisterAwSettings(JNIEnv* env) { | 92 bool RegisterAwSettings(JNIEnv* env) { |
| 109 return RegisterNativesImpl(env) >= 0; | 93 return RegisterNativesImpl(env) >= 0; |
| 110 } | 94 } |
| 111 | 95 |
| 112 } // namespace android_webview | 96 } // namespace android_webview |
| OLD | NEW |