forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Android WebView] Implement WebSettings.setTextZoom for legacy layout…
… modes We rely on the fact that on Android, page scaling factor isn't used for page zooming, so text scaling can be used (unlike desktop Chrome). Review URL: https://chromiumcodereview.appspot.com/12220012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@182481 0039d316-1c4b-4281-b951-d872f2087c98
- Loading branch information
mnaganov@chromium.org
committed
Feb 14, 2013
1 parent
776936b
commit cbe55d2
Showing
17 changed files
with
274 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// 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), | ||
text_zoom_percent_(100) { | ||
} | ||
|
||
AwSettings::~AwSettings() { | ||
} | ||
|
||
void AwSettings::Destroy(JNIEnv* env, jobject obj) { | ||
delete this; | ||
} | ||
|
||
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::UpdateTextZoom() { | ||
if (!web_contents()) return; | ||
AwContents* contents = AwContents::FromWebContents(web_contents()); | ||
if (!contents) return; | ||
AwRenderViewHostExt* rvhe = contents->render_view_host_ext(); | ||
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) { | ||
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// 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. | ||
|
||
#ifndef ANDROID_WEBVIEW_NATIVE_AW_SETTINGS_H_ | ||
#define ANDROID_WEBVIEW_NATIVE_AW_SETTINGS_H_ | ||
|
||
#include <jni.h> | ||
|
||
#include "base/android/jni_helper.h" | ||
#include "base/android/scoped_java_ref.h" | ||
#include "content/public/browser/web_contents_observer.h" | ||
|
||
namespace android_webview { | ||
|
||
class AwSettings : public content::WebContentsObserver { | ||
public: | ||
AwSettings(JNIEnv* env, jobject obj); | ||
virtual ~AwSettings(); | ||
|
||
// Called from Java. | ||
void Destroy(JNIEnv* env, jobject obj); | ||
void SetTextZoom(JNIEnv* env, jobject obj, jint text_zoom_percent); | ||
void SetWebContents(JNIEnv* env, jobject obj, jint web_contents); | ||
|
||
private: | ||
void UpdateTextZoom(); | ||
|
||
// WebContentsObserver overrides: | ||
virtual void RenderViewCreated( | ||
content::RenderViewHost* render_view_host) OVERRIDE; | ||
|
||
JavaObjectWeakGlobalRef java_ref_; | ||
int text_zoom_percent_; | ||
}; | ||
|
||
bool RegisterAwSettings(JNIEnv* env); | ||
|
||
} // namespace android_webview | ||
|
||
#endif // ANDROID_WEBVIEW_NATIVE_AW_SETTINGS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.