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

Side by Side Diff: android_webview/native/aw_settings.cc

Issue 12567020: [android] Resize the android_webview if it's 0x0 initially. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | Annotate | Revision Log
OLDNEW
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 "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
9 #include "jni/AwSettings_jni.h" 11 #include "jni/AwSettings_jni.h"
10 #include "webkit/glue/webkit_glue.h" 12 #include "webkit/glue/webkit_glue.h"
11 13
12 namespace android_webview { 14 namespace android_webview {
13 15
14 AwSettings::AwSettings(JNIEnv* env, jobject obj) 16 AwSettings::AwSettings(JNIEnv* env, jobject obj)
15 : java_ref_(env, obj), 17 : java_ref_(env, obj),
16 enable_fixed_layout_(false), 18 enable_fixed_layout_(false),
17 initial_page_scale_percent_(0), 19 initial_page_scale_percent_(0),
18 text_zoom_percent_(100) { 20 text_zoom_percent_(100) {
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 initial_page_scale_percent_ = page_scale_percent; 53 initial_page_scale_percent_ = page_scale_percent;
52 UpdateInitialPageScale(); 54 UpdateInitialPageScale();
53 } 55 }
54 56
55 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) { 57 void AwSettings::SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent) {
56 if (text_zoom_percent_ == text_zoom_percent) return; 58 if (text_zoom_percent_ == text_zoom_percent) return;
57 text_zoom_percent_ = text_zoom_percent; 59 text_zoom_percent_ = text_zoom_percent;
58 UpdateTextZoom(); 60 UpdateTextZoom();
59 } 61 }
60 62
61 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint web_contents) { 63 void AwSettings::SetWebContents(JNIEnv* env, jobject obj, jint jweb_contents) {
62 Observe(reinterpret_cast<content::WebContents*>(web_contents)); 64 content::WebContents* web_contents =
65 reinterpret_cast<content::WebContents*>(jweb_contents);
66 Observe(web_contents);
67
68 UpdateRenderViewHostExtSettings();
69 if (web_contents->GetRenderViewHost()) {
70 UpdateRenderViewHostSettings(web_contents->GetRenderViewHost());
71 }
63 } 72 }
64 73
65
66 void AwSettings::UpdateEnableFixedLayoutMode() { 74 void AwSettings::UpdateEnableFixedLayoutMode() {
67 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); 75 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt();
68 if (!rvhe) return; 76 if (!rvhe) return;
69 rvhe->SetEnableFixedLayoutMode(enable_fixed_layout_); 77 rvhe->SetEnableFixedLayoutMode(enable_fixed_layout_);
70 } 78 }
71 79
72 void AwSettings::UpdateInitialPageScale() { 80 void AwSettings::UpdateInitialPageScale() {
73 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); 81 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt();
74 if (!rvhe) return; 82 if (!rvhe) return;
75 if (initial_page_scale_percent_ == 0) { 83 if (initial_page_scale_percent_ == 0) {
76 rvhe->SetInitialPageScale(-1); 84 rvhe->SetInitialPageScale(-1);
77 } else { 85 } else {
78 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f); 86 rvhe->SetInitialPageScale(initial_page_scale_percent_ / 100.0f);
79 } 87 }
80 } 88 }
81 89
82 void AwSettings::UpdateTextZoom() { 90 void AwSettings::UpdateTextZoom() {
83 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt(); 91 AwRenderViewHostExt* rvhe = GetAwRenderViewHostExt();
84 if (!rvhe) return; 92 if (!rvhe) return;
85 if (text_zoom_percent_ > 0) { 93 if (text_zoom_percent_ > 0) {
86 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel( 94 rvhe->SetTextZoomLevel(webkit_glue::ZoomFactorToZoomLevel(
87 text_zoom_percent_ / 100.0f)); 95 text_zoom_percent_ / 100.0f));
88 } else { 96 } else {
89 // Use the default zoom level value when Text Autosizer is turned on. 97 // Use the default zoom level value when Text Autosizer is turned on.
90 rvhe->SetTextZoomLevel(0); 98 rvhe->SetTextZoomLevel(0);
91 } 99 }
92 } 100 }
93 101
94 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) { 102 void AwSettings::UpdatePreferredSizeMode(
103 content::RenderViewHost* render_view_host) {
104 render_view_host->EnablePreferredSizeMode();
105 }
106
107 void AwSettings::UpdateRenderViewHostExtSettings() {
95 UpdateEnableFixedLayoutMode(); 108 UpdateEnableFixedLayoutMode();
96 UpdateInitialPageScale(); 109 UpdateInitialPageScale();
97 UpdateTextZoom(); 110 UpdateTextZoom();
98 } 111 }
99 112
113 void AwSettings::UpdateRenderViewHostSettings(
114 content::RenderViewHost* render_view_host) {
115 UpdatePreferredSizeMode(render_view_host);
116 }
117
118 void AwSettings::RenderViewCreated(content::RenderViewHost* render_view_host) {
119 // TODO(mkosiba): This is a bit contrived since there is only one
120 // RenderViewHostExt instance per WebContents, while the RenderViewHost
121 // associated with the WebContents can change over time (and there can be
122 // more than one of them associated with a WebContents).
123 // This means the RenderViewHostExt needs to be pinged to make it update the
124 // RenderViewHost settings every time the RenderViewHost changes. That
125 // code in turn depends on the fact that the newly-created RenderViewHost
126 // immediately becomes the current RenderViewHost for the given WebContents,
127 // which is documented by the following DCHECK:
128 DCHECK(web_contents()->GetRenderViewHost() == render_view_host);
mkosiba (inactive) 2013/03/28 14:20:37 this fails on some tests, which most likely means
joth 2013/03/28 22:51:08 There's a tricky dance that happens on cross site
mkosiba (inactive) 2013/04/03 16:25:28 So the way I see it is that we've got an actual pr
129
130 UpdateRenderViewHostExtSettings();
131 UpdateRenderViewHostSettings(render_view_host);
132 }
133
100 static jint Init(JNIEnv* env, 134 static jint Init(JNIEnv* env,
101 jobject obj, 135 jobject obj,
102 jint web_contents) { 136 jint web_contents) {
103 AwSettings* settings = new AwSettings(env, obj); 137 AwSettings* settings = new AwSettings(env, obj);
104 settings->SetWebContents(env, obj, web_contents); 138 settings->SetWebContents(env, obj, web_contents);
105 return reinterpret_cast<jint>(settings); 139 return reinterpret_cast<jint>(settings);
106 } 140 }
107 141
108 bool RegisterAwSettings(JNIEnv* env) { 142 bool RegisterAwSettings(JNIEnv* env) {
109 return RegisterNativesImpl(env) >= 0; 143 return RegisterNativesImpl(env) >= 0;
110 } 144 }
111 145
112 } // namespace android_webview 146 } // namespace android_webview
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698