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